From 0f05518140ae69262b3c5140beb5bdbd4d00373b Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Fri, 28 Feb 2025 16:14:34 +0700 Subject: [PATCH 1/2] deleted sstream --- .gitignore | 1 + config.json | 4 ++-- src/settings/ftp/ftp.cpp | 2 +- src/settings/ssh/port.cpp | 28 +++++++++++++++++++--------- src/settings/telnet/port.cpp | 19 ++++++++++++------- src/settings/wifi/channel.cpp | 23 ++++++++++++++--------- src/settings/wifi/name.cpp | 9 ++++----- src/settings/wifi/password.cpp | 18 +++++++++++------- src/settings/wifi/qr.cpp | 7 +++---- 9 files changed, 67 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index d55db2c..e101edd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin cmake-build-debug .idea .vscode +.cache diff --git a/config.json b/config.json index bfe0702..c6671d3 100644 --- a/config.json +++ b/config.json @@ -41,7 +41,7 @@ "channel": "11", "enabled": false, "name": "home", - "password": "OpenRouterPassword" + "password": "11111111" } }, "static": { @@ -49,4 +49,4 @@ "js": "../src/web/js", "root": "../src/web" } -} +} \ No newline at end of file diff --git a/src/settings/ftp/ftp.cpp b/src/settings/ftp/ftp.cpp index 33c0026..48b7062 100644 --- a/src/settings/ftp/ftp.cpp +++ b/src/settings/ftp/ftp.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})" diff --git a/src/settings/ssh/port.cpp b/src/settings/ssh/port.cpp index ef21eb6..c3b0cbd 100644 --- a/src/settings/ssh/port.cpp +++ b/src/settings/ssh/port.cpp @@ -1,7 +1,6 @@ #include #include -#include -#include +#include #include #include #include @@ -18,18 +17,29 @@ namespace api { void set_ssh_port(int new_ssh_port) { - std::string old_ssh_port = config::config.getConfig()["settings"]["ssh"]["port"]; - std::stringstream systemrequest; + 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; if (get_ssh_server() == DROPBEAR_SSH) { - systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" " << DROPBEAR_DEFAULT_FILE; + 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 (get_ssh_server() == OPENSSH_SSH) { - systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" " << SSHD_CONFIG_FILE; + systemrequest += "sed -i \"/Port " \ + + std::to_string(old_ssh_port) \ + + "/s//Port " \ + + std::to_string(new_ssh_port) \ + + "/\" " \ + + SSHD_CONFIG_FILE; } - std::cout << systemrequest.str() << std::endl; - system(systemrequest.str().c_str()); + std::cout << systemrequest << std::endl; + system(systemrequest.c_str()); if (get_ssh_server() == OPENSSH_SSH) { system("rc restart ssh"); @@ -38,7 +48,7 @@ namespace api { system("rc restart dropbear"); } - std::string syslogstring = "SSH port changed to " + new_ssh_port; + std::string syslogstring = "SSH port changed to " + std::to_string(new_ssh_port); syslog(LOG_INFO, "%s", syslogstring.c_str()); } } diff --git a/src/settings/telnet/port.cpp b/src/settings/telnet/port.cpp index a4e6154..d256db5 100644 --- a/src/settings/telnet/port.cpp +++ b/src/settings/telnet/port.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #define TELNET_PORT_FILE "/etc/default/telnet" @@ -14,13 +13,19 @@ namespace api { void set_telnet_port(int new_telnet_port) { - std::string old_telnet_port = config::config.getConfig()["settings"]["telnet"]["port"]; - std::stringstream systemrequest; - systemrequest << "sed -i \"s/TELNET_PORT=" << old_telnet_port << "/TELNET_PORT=" << new_telnet_port << "/g\" " << TELNET_PORT_FILE; - std::cout << systemrequest.str() << std::endl; - system(systemrequest.str().c_str()); + std::string old_telnet_port_string = config::config.getConfig()["settings"]["telnet"]["port"]; + int old_telnet_port = std::stoi(old_telnet_port_string); + std::string systemrequest; + systemrequest += "sed -i \"s/TELNET_PORT=" \ + + std::to_string(old_telnet_port) \ + + "/TELNET_PORT=" \ + + std::to_string(new_telnet_port) \ + + "/g\" " \ + + TELNET_PORT_FILE; + std::cout << systemrequest << std::endl; + system(systemrequest.c_str()); system("rc restart telnet"); - std::string syslogstring = "Telnet port changed to " + new_telnet_port; + std::string syslogstring = "Telnet port changed to " + std::to_string(new_telnet_port); syslog(LOG_INFO, "%s", syslogstring.c_str()); } } diff --git a/src/settings/wifi/channel.cpp b/src/settings/wifi/channel.cpp index 001d40b..9608cd8 100644 --- a/src/settings/wifi/channel.cpp +++ b/src/settings/wifi/channel.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -15,24 +14,30 @@ namespace api void set_wifi_channel(int new_channel) { std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH); - std::string old_channel; + std::string old_channel_string; std::string wifisettingsbuffer; while (std::getline(wifisettingsfile, wifisettingsbuffer)) { if (wifisettingsbuffer.find("channel=") == 0) { - old_channel = wifisettingsbuffer; - old_channel.erase(0, 8); + old_channel_string = wifisettingsbuffer; + old_channel_string.erase(0, 8); break; } } wifisettingsfile.close(); - std::stringstream systemrequest; - systemrequest << "sed -i \"/channel=" << old_channel << "/s//channel=" << new_channel << "/\" /etc/hostapd/hostapd.conf"; - std::cout << systemrequest.str() << std::endl; - system(systemrequest.str().c_str()); + std::cout << old_channel_string << std::endl; + int old_channel = std::stoi(old_channel_string); + std::string systemrequest; + systemrequest += "sed -i \"/channel=" \ + + std::to_string(old_channel) \ + + "/s//channel=" \ + + std::to_string(new_channel) \ + + "/\" /etc/hostapd/hostapd.conf"; + std::cout << systemrequest << std::endl; + system(systemrequest.c_str()); system("rc restart hostapd"); - std::string syslogstring = "WIFI channel changed to " + new_channel; + std::string syslogstring = "WIFI channel changed to " + std::to_string(new_channel); syslog(LOG_INFO, "%s", syslogstring.c_str()); } } diff --git a/src/settings/wifi/name.cpp b/src/settings/wifi/name.cpp index c386f65..bb948cd 100644 --- a/src/settings/wifi/name.cpp +++ b/src/settings/wifi/name.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -27,10 +26,10 @@ namespace api } } wifisettingsfile.close(); - std::stringstream systemrequest; - systemrequest << "sed -i \"/ssid=" << old_wifi_name << "/s//ssid=" << new_wifi_name << "/\" /etc/hostapd/hostapd.conf"; - std::cout << systemrequest.str() << std::endl; - system(systemrequest.str().c_str()); + std::string systemrequest; + systemrequest += "sed -i \"/ssid=" + old_wifi_name + "/s//ssid=" + new_wifi_name + "/\" /etc/hostapd/hostapd.conf"; + std::cout << systemrequest << std::endl; + system(systemrequest.c_str()); system("rc restart hostapd"); std::string syslogstring = "WIFI name changed to " + new_wifi_name; syslog(LOG_INFO, "%s", syslogstring.c_str()); diff --git a/src/settings/wifi/password.cpp b/src/settings/wifi/password.cpp index 2a18af9..fa23546 100644 --- a/src/settings/wifi/password.cpp +++ b/src/settings/wifi/password.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -55,9 +54,14 @@ namespace api return; } std::string new_wifi_password = json_body["newpassword"]; - std::stringstream systemrequest; - systemrequest << "sed -i \"/wpa_passphrase=" << old_wifi_password << "/s//wpa_passphrase=" << new_wifi_password << "/\" /etc/hostapd/hostapd.conf"; - system(systemrequest.str().c_str()); + std::string systemrequest; + systemrequest += "sed -i \"/wpa_passphrase=" \ + + old_wifi_password \ + + "/s//wpa_passphrase=" \ + + new_wifi_password \ + + "/\" /etc/hostapd/hostapd.conf"; + std::cout << systemrequest << std::endl; + system(systemrequest.c_str()); system("rc restart hostapd"); std::string syslogstring = "WIFI password changed"; syslog(LOG_INFO, "%s", syslogstring.c_str()); @@ -67,9 +71,9 @@ namespace api new_config["settings"]["wifi"]["password"] = new_wifi_password; config::config.setConfig(new_config); config::config.saveConfig(); - std::stringstream responsedata; - responsedata << R"({"success":"ok"})"; - response.set_content(responsedata.str(), JSON_TYPE); + std::string responsedata; + responsedata = R"({"success":"ok"})"; + response.set_content(responsedata, JSON_TYPE); } } } diff --git a/src/settings/wifi/qr.cpp b/src/settings/wifi/qr.cpp index 9796448..7ddc2be 100644 --- a/src/settings/wifi/qr.cpp +++ b/src/settings/wifi/qr.cpp @@ -33,10 +33,9 @@ namespace api config::config.setConfig(config::config.getConfigFileName()); std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"]; std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"]; - std::stringstream toqrstring; - toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";"; - - qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM); + std::string toqrstring; + toqrstring += "WIFI:T:WPA;P:" + wifi_password + ";S:" + wifi_name + ";"; + qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.c_str(), qrcodegen::QrCode::Ecc::MEDIUM); std::string responsedata = toSvgString(qr0, 4); response.set_content(responsedata, SVG_TYPE); } -- 2.54.0 From 6087407df49aeb4b5b2e86fc192b8d0c3d1a72bb Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Fri, 28 Feb 2025 16:16:28 +0700 Subject: [PATCH 2/2] deleted sstream --- src/settings/telnet/enabled.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings/telnet/enabled.cpp b/src/settings/telnet/enabled.cpp index eadfb80..592237f 100644 --- a/src/settings/telnet/enabled.cpp +++ b/src/settings/telnet/enabled.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})" -- 2.54.0