Merge pull request 'delete-sstream' (#18) from delete-sstream into main
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
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
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/openrouter/pulls/18 #3
This commit was merged in pull request #18.
This commit is contained in:
@@ -3,3 +3,4 @@ bin
|
||||
cmake-build-debug
|
||||
.idea
|
||||
.vscode
|
||||
.cache
|
||||
|
||||
+2
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <settings/ftp/ftp.hpp>
|
||||
#include <syslog.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <settings/ssh/ssh.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <config/config.hpp>
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <settings/telnet/telnet.hpp>
|
||||
#include <syslog.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <settings/telnet/telnet.hpp>
|
||||
#include <syslog.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <settings/wifi/wifi.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <settings/wifi/wifi.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <syslog.h>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user