diff --git a/src/settings/ssh/keys.cpp b/src/settings/ssh/keys.cpp index 3724f76..c183e6d 100644 --- a/src/settings/ssh/keys.cpp +++ b/src/settings/ssh/keys.cpp @@ -6,7 +6,7 @@ #include #include -#define KEYS_PATH "/root/.ssh/authorized_keys" +#define KEYS_PATH "~/.ssh/authorized_keys" namespace api { diff --git a/src/settings/ssh/port.cpp b/src/settings/ssh/port.cpp index b8c7a93..f51ca8b 100644 --- a/src/settings/ssh/port.cpp +++ b/src/settings/ssh/port.cpp @@ -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); diff --git a/src/settings/ssh/server.cpp b/src/settings/ssh/server.cpp index 1d4601d..ff48465 100644 --- a/src/settings/ssh/server.cpp +++ b/src/settings/ssh/server.cpp @@ -73,7 +73,20 @@ namespace api } std::stringstream responsedata; std::string server = json_body["server"]; - responsedata << R"({"server":")" << set_ssh_server(server) << R"("})"; + std::string new_server = set_ssh_server(server); + if (new_server == DROPBEAR_SSH) + { + system("rc stop ssh"); + system("rc del ssh"); + system("rc start dropbear"); + system("rc add dropbear"); + } else if (new_server == OPENSSH_SSH) { + system("rc stop dropbear"); + system("rc del dropbear"); + system("rc start ssh"); + system("rc add ssh"); + } + responsedata << R"({"server":")" << new_server << R"("})"; response.set_content(responsedata.str(), JSON_TYPE); } } diff --git a/src/settings/ssh/ssh.hpp b/src/settings/ssh/ssh.hpp index cd0ecdb..f79b04f 100644 --- a/src/settings/ssh/ssh.hpp +++ b/src/settings/ssh/ssh.hpp @@ -3,6 +3,9 @@ #include +#define DROPBEAR_SSH "dropbear" +#define OPENSSH_SSH "openssh" + namespace api { namespace settings diff --git a/src/settings/ssh/status.cpp b/src/settings/ssh/status.cpp index a54a71a..8f2cd48 100644 --- a/src/settings/ssh/status.cpp +++ b/src/settings/ssh/status.cpp @@ -63,14 +63,26 @@ namespace api std::string new_ssh_status = json_body["status"]; if (new_ssh_status == "0") { - system("rc stop ssh"); - system("rc del ssh"); + if (get_ssh_server() == DROPBEAR_SSH) + { + system("rc stop dropbear"); + system("rc del dropbear"); + } else if (get_ssh_server() == OPENSSH_SSH) { + system("rc stop ssh"); + system("rc del ssh"); + } syslog(LOG_INFO, "%s", "SSH is disabled"); } else { - system("rc start ssh"); - system("rc add ssh"); + if (get_ssh_server() == DROPBEAR_SSH) + { + system("rc start dropbear"); + system("rc add dropbear"); + } else if (get_ssh_server() == OPENSSH_SSH) { + system("rc start ssh"); + system("rc add ssh"); + } syslog(LOG_INFO, "%s", "SSH is enabled"); } sshfileout << stoi(new_ssh_status);