delete-sstream #18

Merged
wt merged 2 commits from delete-sstream into main 2025-02-28 09:13:01 +00:00
10 changed files with 67 additions and 44 deletions

No files matched your search

+1
View File
@@ -3,3 +3,4 @@ bin
cmake-build-debug cmake-build-debug
.idea .idea
.vscode .vscode
.cache
+1 -1
View File
@@ -41,7 +41,7 @@
"channel": "11", "channel": "11",
"enabled": false, "enabled": false,
"name": "home", "name": "home",
"password": "OpenRouterPassword" "password": "11111111"
} }
}, },
"static": { "static": {
+1 -1
View File
@@ -1,6 +1,6 @@
#include <settings/ftp/ftp.hpp> #include <settings/ftp/ftp.hpp>
#include <syslog.h> #include <syslog.h>
#include <iostream> #include <stdlib.h>
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})" #define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
+19 -9
View File
@@ -1,7 +1,6 @@
#include <settings/ssh/ssh.hpp> #include <settings/ssh/ssh.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <string>
#include <fstream>
#include <string> #include <string>
#include <syslog.h> #include <syslog.h>
#include <config/config.hpp> #include <config/config.hpp>
@@ -18,18 +17,29 @@ namespace api
{ {
void set_ssh_port(int new_ssh_port) void set_ssh_port(int new_ssh_port)
{ {
std::string old_ssh_port = config::config.getConfig()["settings"]["ssh"]["port"]; std::string old_ssh_port_string = config::config.getConfig()["settings"]["ssh"]["port"];
std::stringstream systemrequest; int old_ssh_port = std::stoi(old_ssh_port_string);
std::string systemrequest;
if (get_ssh_server() == DROPBEAR_SSH) 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) 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; std::cout << systemrequest << std::endl;
system(systemrequest.str().c_str()); system(systemrequest.c_str());
if (get_ssh_server() == OPENSSH_SSH) if (get_ssh_server() == OPENSSH_SSH)
{ {
system("rc restart ssh"); system("rc restart ssh");
@@ -38,7 +48,7 @@ namespace api
{ {
system("rc restart dropbear"); 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()); syslog(LOG_INFO, "%s", syslogstring.c_str());
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
#include <settings/telnet/telnet.hpp> #include <settings/telnet/telnet.hpp>
#include <syslog.h> #include <syslog.h>
#include <iostream> #include <stdlib.h>
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})" #define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
+12 -7
View File
@@ -1,7 +1,6 @@
#include <settings/telnet/telnet.hpp> #include <settings/telnet/telnet.hpp>
#include <syslog.h> #include <syslog.h>
#include <iostream> #include <iostream>
#include <sstream>
#include <config/config.hpp> #include <config/config.hpp>
#define TELNET_PORT_FILE "/etc/default/telnet" #define TELNET_PORT_FILE "/etc/default/telnet"
@@ -14,13 +13,19 @@ namespace api
{ {
void set_telnet_port(int new_telnet_port) void set_telnet_port(int new_telnet_port)
{ {
std::string old_telnet_port = config::config.getConfig()["settings"]["telnet"]["port"]; std::string old_telnet_port_string = config::config.getConfig()["settings"]["telnet"]["port"];
std::stringstream systemrequest; int old_telnet_port = std::stoi(old_telnet_port_string);
systemrequest << "sed -i \"s/TELNET_PORT=" << old_telnet_port << "/TELNET_PORT=" << new_telnet_port << "/g\" " << TELNET_PORT_FILE; std::string systemrequest;
std::cout << systemrequest.str() << std::endl; systemrequest += "sed -i \"s/TELNET_PORT=" \
system(systemrequest.str().c_str()); + 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"); 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()); syslog(LOG_INFO, "%s", syslogstring.c_str());
} }
} }
+14 -9
View File
@@ -1,6 +1,5 @@
#include <settings/wifi/wifi.hpp> #include <settings/wifi/wifi.hpp>
#include <iostream> #include <iostream>
#include <sstream>
#include <fstream> #include <fstream>
#include <syslog.h> #include <syslog.h>
@@ -15,24 +14,30 @@ namespace api
void set_wifi_channel(int new_channel) void set_wifi_channel(int new_channel)
{ {
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH); std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
std::string old_channel; std::string old_channel_string;
std::string wifisettingsbuffer; std::string wifisettingsbuffer;
while (std::getline(wifisettingsfile, wifisettingsbuffer)) while (std::getline(wifisettingsfile, wifisettingsbuffer))
{ {
if (wifisettingsbuffer.find("channel=") == 0) if (wifisettingsbuffer.find("channel=") == 0)
{ {
old_channel = wifisettingsbuffer; old_channel_string = wifisettingsbuffer;
old_channel.erase(0, 8); old_channel_string.erase(0, 8);
break; break;
} }
} }
wifisettingsfile.close(); wifisettingsfile.close();
std::stringstream systemrequest; std::cout << old_channel_string << std::endl;
systemrequest << "sed -i \"/channel=" << old_channel << "/s//channel=" << new_channel << "/\" /etc/hostapd/hostapd.conf"; int old_channel = std::stoi(old_channel_string);
std::cout << systemrequest.str() << std::endl; std::string systemrequest;
system(systemrequest.str().c_str()); 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"); 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()); syslog(LOG_INFO, "%s", syslogstring.c_str());
} }
} }
+4 -5
View File
@@ -1,6 +1,5 @@
#include <settings/wifi/wifi.hpp> #include <settings/wifi/wifi.hpp>
#include <iostream> #include <iostream>
#include <sstream>
#include <fstream> #include <fstream>
#include <syslog.h> #include <syslog.h>
@@ -27,10 +26,10 @@ namespace api
} }
} }
wifisettingsfile.close(); wifisettingsfile.close();
std::stringstream systemrequest; std::string systemrequest;
systemrequest << "sed -i \"/ssid=" << old_wifi_name << "/s//ssid=" << new_wifi_name << "/\" /etc/hostapd/hostapd.conf"; systemrequest += "sed -i \"/ssid=" + old_wifi_name + "/s//ssid=" + new_wifi_name + "/\" /etc/hostapd/hostapd.conf";
std::cout << systemrequest.str() << std::endl; std::cout << systemrequest << std::endl;
system(systemrequest.str().c_str()); system(systemrequest.c_str());
system("rc restart hostapd"); system("rc restart hostapd");
std::string syslogstring = "WIFI name changed to " + new_wifi_name; std::string syslogstring = "WIFI name changed to " + new_wifi_name;
syslog(LOG_INFO, "%s", syslogstring.c_str()); syslog(LOG_INFO, "%s", syslogstring.c_str());
+11 -7
View File
@@ -4,7 +4,6 @@
#include <json.hpp> #include <json.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream>
#include <string> #include <string>
#include <syslog.h> #include <syslog.h>
#include <auth/auth.hpp> #include <auth/auth.hpp>
@@ -55,9 +54,14 @@ namespace api
return; return;
} }
std::string new_wifi_password = json_body["newpassword"]; std::string new_wifi_password = json_body["newpassword"];
std::stringstream systemrequest; std::string systemrequest;
systemrequest << "sed -i \"/wpa_passphrase=" << old_wifi_password << "/s//wpa_passphrase=" << new_wifi_password << "/\" /etc/hostapd/hostapd.conf"; systemrequest += "sed -i \"/wpa_passphrase=" \
system(systemrequest.str().c_str()); + 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"); system("rc restart hostapd");
std::string syslogstring = "WIFI password changed"; std::string syslogstring = "WIFI password changed";
syslog(LOG_INFO, "%s", syslogstring.c_str()); syslog(LOG_INFO, "%s", syslogstring.c_str());
@@ -67,9 +71,9 @@ namespace api
new_config["settings"]["wifi"]["password"] = new_wifi_password; new_config["settings"]["wifi"]["password"] = new_wifi_password;
config::config.setConfig(new_config); config::config.setConfig(new_config);
config::config.saveConfig(); config::config.saveConfig();
std::stringstream responsedata; std::string responsedata;
responsedata << R"({"success":"ok"})"; responsedata = R"({"success":"ok"})";
response.set_content(responsedata.str(), JSON_TYPE); response.set_content(responsedata, JSON_TYPE);
} }
} }
} }
+3 -4
View File
@@ -33,10 +33,9 @@ namespace api
config::config.setConfig(config::config.getConfigFileName()); config::config.setConfig(config::config.getConfigFileName());
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"]; std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"]; std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
std::stringstream toqrstring; std::string toqrstring;
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";"; toqrstring += "WIFI:T:WPA;P:" + wifi_password + ";S:" + wifi_name + ";";
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
std::string responsedata = toSvgString(qr0, 4); std::string responsedata = toSvgString(qr0, 4);
response.set_content(responsedata, SVG_TYPE); response.set_content(responsedata, SVG_TYPE);
} }