#1 added if else with DROPBEAR_SSH and OPENSSH_SSH
This commit is contained in:
1 parent
bc17587a15
commit
03f14739cb
5 files changed
+48
-8
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
#include <auth/auth.hpp>
|
#include <auth/auth.hpp>
|
||||||
#include <helpers.hpp>
|
#include <helpers.hpp>
|
||||||
|
|
||||||
#define KEYS_PATH "/root/.ssh/authorized_keys"
|
#define KEYS_PATH "~/.ssh/authorized_keys"
|
||||||
|
|
||||||
namespace api
|
namespace api
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,10 +73,22 @@ namespace api
|
|||||||
sshportfileout << stoi(new_ssh_port);
|
sshportfileout << stoi(new_ssh_port);
|
||||||
sshportfileout.close();
|
sshportfileout.close();
|
||||||
std::stringstream systemrequest;
|
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;
|
std::cout << systemrequest.str() << std::endl;
|
||||||
system(systemrequest.str().c_str());
|
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;
|
std::string syslogstring = "SSH port changed to " + new_ssh_port;
|
||||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||||
std::ifstream sshportfile(SSH_PORT_PATH);
|
std::ifstream sshportfile(SSH_PORT_PATH);
|
||||||
|
|||||||
@@ -73,7 +73,20 @@ namespace api
|
|||||||
}
|
}
|
||||||
std::stringstream responsedata;
|
std::stringstream responsedata;
|
||||||
std::string server = json_body["server"];
|
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);
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
|
|
||||||
|
#define DROPBEAR_SSH "dropbear"
|
||||||
|
#define OPENSSH_SSH "openssh"
|
||||||
|
|
||||||
namespace api
|
namespace api
|
||||||
{
|
{
|
||||||
namespace settings
|
namespace settings
|
||||||
|
|||||||
@@ -63,14 +63,26 @@ namespace api
|
|||||||
std::string new_ssh_status = json_body["status"];
|
std::string new_ssh_status = json_body["status"];
|
||||||
if (new_ssh_status == "0")
|
if (new_ssh_status == "0")
|
||||||
{
|
{
|
||||||
system("rc stop ssh");
|
if (get_ssh_server() == DROPBEAR_SSH)
|
||||||
system("rc del 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");
|
syslog(LOG_INFO, "%s", "SSH is disabled");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
system("rc start ssh");
|
if (get_ssh_server() == DROPBEAR_SSH)
|
||||||
system("rc add 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");
|
syslog(LOG_INFO, "%s", "SSH is enabled");
|
||||||
}
|
}
|
||||||
sshfileout << stoi(new_ssh_status);
|
sshfileout << stoi(new_ssh_status);
|
||||||
|
|||||||
Reference in new issue
Block a user