#include #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 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()); } } } }