#1 added if else with DROPBEAR_SSH and OPENSSH_SSH
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
|
||||
#define KEYS_PATH "/root/.ssh/authorized_keys"
|
||||
#define KEYS_PATH "~/.ssh/authorized_keys"
|
||||
|
||||
namespace api
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
#define DROPBEAR_SSH "dropbear"
|
||||
#define OPENSSH_SSH "openssh"
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user