#1 added if else with DROPBEAR_SSH and OPENSSH_SSH

This commit is contained in:
wt committed 2024-12-28 01:41:05 +07:00
1 parent bc17587a15
commit 03f14739cb
5 files changed
+48 -8

No files matched your search

+14 -2
View File
@@ -73,10 +73,22 @@ namespace api
sshportfileout << stoi(new_ssh_port);
sshportfileout.close();
std::stringstream systemrequest;
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
if (get_ssh_server() == DROPBEAR_SSH)
{
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear";
} else if (get_ssh_server() == OPENSSH_SSH)
{
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
}
std::cout << systemrequest.str() << std::endl;
system(systemrequest.str().c_str());
system("rc restart ssh");
if (get_ssh_server() == OPENSSH_SSH)
{
system("rc restart ssh");
} else if (get_ssh_server() == DROPBEAR_SSH)
{
system("rc restart dropbear");
}
std::string syslogstring = "SSH port changed to " + new_ssh_port;
syslog(LOG_INFO, "%s", syslogstring.c_str());
std::ifstream sshportfile(SSH_PORT_PATH);