#include #include #include #include #include #include #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 Ssh::set_ssh_port(int new_ssh_port) { std::string old_ssh_port_string = config::config.getConfig()["settings"]["ssh"]["port"]; int old_ssh_port = std::stoi(old_ssh_port_string); std::string systemrequest; std::string ssh_server = get_ssh_server(); if (ssh_server == DROPBEAR_SSH) { systemrequest += "sed -i \"s/DROPBEAR_PORT=" \ + std::to_string(old_ssh_port) \ + "/DROPBEAR_PORT=" \ + std::to_string(new_ssh_port) \ + "/g\" " \ + DROPBEAR_DEFAULT_FILE; } else if (ssh_server == OPENSSH_SSH) { systemrequest += "sed -i \"/Port " \ + std::to_string(old_ssh_port) \ + "/s//Port " \ + std::to_string(new_ssh_port) \ + "/\" " \ + SSHD_CONFIG_FILE; } std::cout << systemrequest << std::endl; system(systemrequest.c_str()); if (ssh_server == OPENSSH_SSH) { system("rc restart ssh"); } else if (ssh_server == DROPBEAR_SSH) { system("rc restart dropbear"); } std::string syslogstring = "SSH port changed to " + std::to_string(new_ssh_port); syslog(LOG_INFO, "%s", syslogstring.c_str()); } } } }