#1 added if else with DROPBEAR_SSH and OPENSSH_SSH

This commit is contained in:
wt
2024-12-28 01:41:05 +07:00
parent bc17587a15
commit 03f14739cb
5 changed files with 48 additions and 8 deletions
+1 -1
View File
@@ -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
{
+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);
+14 -1
View File
@@ -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
View File
@@ -3,6 +3,9 @@
#include <httplib.h>
#define DROPBEAR_SSH "dropbear"
#define OPENSSH_SSH "openssh"
namespace api
{
namespace settings
+16 -4
View File
@@ -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);