Files
openrouter/src/settings/ssh/port.cpp
T
wt 4b2d425d13
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
added backup restore settings and updated config #3
2025-02-21 12:23:24 +07:00

47 lines
1.6 KiB
C++

#include <settings/ssh/ssh.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <syslog.h>
#include <config/config.hpp>
#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
#define DROPBEAR_DEFAULT_FILE "/etc/default/dropbear"
#define SSHD_CONFIG_FILE "/etc/ssh/sshd_config"
namespace api
{
namespace settings
{
namespace ssh
{
void set_ssh_port(int new_ssh_port)
{
std::string old_ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
std::stringstream systemrequest;
if (get_ssh_server() == DROPBEAR_SSH)
{
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" " << DROPBEAR_DEFAULT_FILE;
}
else if (get_ssh_server() == OPENSSH_SSH)
{
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" " << SSHD_CONFIG_FILE;
}
std::cout << systemrequest.str() << std::endl;
system(systemrequest.str().c_str());
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());
}
}
}
}