added full support for config file
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run

This commit is contained in:
wt committed 2025-02-11 03:24:55 +07:00
1 parent 0c4183843f
commit 6e85d8e922
21 files changed
+209 -254

No files matched your search

+14 -9
View File
@@ -1,7 +1,7 @@
{
"settings": {
"dns": {
"enabled": true,
"enabled": false,
"localdomains": [
{
"domain": "localhost",
@@ -10,33 +10,38 @@
{
"domain": "openrouter.local.com",
"ip": "192.168.200.1"
},
{
"domain": "asdf",
"ip": "1.2.3.4"
}
],
"servers": [
"8.8.8.8"
"8.8.8.8",
"1.2.3.4"
]
},
"ftp": {
"enabled": true
"enabled": false
},
"ssh": {
"enabled": true,
"enabled": false,
"keys": [
"key1",
"key2"
],
"port": 22,
"server": "openssh"
"server": "dropbear"
},
"telnet": {
"enabled": true,
"port": 23
"enabled": false,
"port": 25
},
"wifi": {
"channel": 6,
"enabled": true,
"enabled": false,
"name": "OpenRouterWifi",
"password": "OpenRouterPassword"
"password": "Simba28082020"
}
}
}
-1
View File
@@ -8,7 +8,6 @@
OpenRouter::OpenRouter()
{
std::cout << config::config.getConfig() << std::endl;
this->srv.Post("/api/settings/telnet/get", api::settings::telnet::get_telnet);
this->srv.Post("/api/settings/telnet/set", api::settings::telnet::set_telnet);
this->srv.Post("/api/settings/telnet/port/get", api::settings::telnet::get_telnet_port);
+133
View File
@@ -0,0 +1,133 @@
#ifndef CONFIG_MANAGER_HPP
#define CONFIG_MANAGER_HPP
#include <iostream>
#include <fstream>
#include <string>
#include <json.hpp>
class ConfigManager
{
private:
nlohmann::json config;
std::fstream configfile;
std::string configFileName;
public:
ConfigManager()
{
this->config = nullptr;
}
ConfigManager(nlohmann::json object)
{
this->config = object;
}
ConfigManager(std::string filename)
{
this->configfile.open(filename);
this->config = nlohmann::json::parse(this->configfile);
this->configfile.close();
this->configFileName = filename;
}
ConfigManager(nlohmann::json object, std::string filename)
{
this->config = object;
this->configFileName = filename;
}
~ConfigManager()
{
this->config = nullptr;
this->configfile.close();
}
nlohmann::json getConfig()
{
return this->config;
}
int setConfig(nlohmann::json object)
{
this->config = object;
return 0;
}
int setConfig(std::string filename)
{
this->configfile.open(filename);
this->config = nlohmann::json::parse(this->configfile);
this->configFileName = filename;
this->configfile.close();
return 0;
}
int setConfigFile(std::string filename)
{
this->configFileName = filename;
return 0;
}
std::string getParameterAsString(std::string paramName)
{
return this->config[paramName];
}
int getParameterAsInt(std::string paramName)
{
return this->config[paramName];
}
double getParameterAsDouble(std::string paramName)
{
return this->config[paramName];
}
float getParameterAsFloat(std::string paramName)
{
return this->config[paramName];
}
bool getParameterAsBool(std::string paramName)
{
return this->config[paramName];
}
int setParameter(std::string name, int value)
{
this->config[name] = value;
return 0;
}
int setParameter(std::string name, double value)
{
this->config[name] = value;
return 0;
}
int setParameter(std::string name, float value)
{
this->config[name] = value;
return 0;
}
int setParameterAsNull(std::string name)
{
this->config[name] = nullptr;
return 0;
}
int setParameter(std::string name, std::string value)
{
this->config[name] = value;
return 0;
}
int setParameter(std::string name, bool value)
{
this->config[name] = value;
return 0;
}
int saveConfig()
{
this->configfile.open(this->configFileName, std::ios::trunc | std::ios::out | std::ios::in);
this->configfile << this->config.dump(4);
this->configfile.close();
return 0;
}
int saveConfig(std::string filename)
{
this->configfile.open(filename, std::ios::trunc | std::ios::out | std::ios::in);
this->configfile << this->config.dump(4);
this->configfile.close();
return 0;
}
friend std::ostream& operator<<(std::ostream& out, const ConfigManager& manager)
{
return out << manager.config;
}
};
#endif // CONFIG_MANAGER_HPP
+1 -1
View File
@@ -6,6 +6,6 @@ int main()
#ifdef TEST
return 0;
#else
return router.serve("127.0.0.1", 43244);
return router.serve("0.0.0.0", 43244);
#endif
}
+1 -12
View File
@@ -31,10 +31,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream dnsfile("/etc/openrouter/dns");
// int dns_enabled;
// dnsfile >> dns_enabled;
// dnsfile.close();
int dns_enabled = config::config.getConfig()["settings"]["dns"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
@@ -63,7 +59,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ofstream dnsfileout("/etc/openrouter/dns");
bool new_dns_enabled = json_body["enabled"];
if (!new_dns_enabled)
{
@@ -77,18 +72,12 @@ namespace api
system("rc add dnsmasq");
syslog(LOG_INFO, "%s", "DNS is enabled");
}
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["dns"]["enabled"] = new_dns_enabled;
config::config.setConfig(new_config);
config::config.saveConfig();
int dns_enabled = config::config.getConfig()["settings"]["dns"]["enabled"];
// dnsfileout << stoi(new_dns_enabled);
// dnsfileout.close();
// std::ifstream dnsfile("/etc/openrouter/dns");
// int dns_enabled;
// dnsfile >> dns_enabled;
// dnsfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+2 -29
View File
@@ -29,38 +29,10 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream domainsfile("/etc/dnsmasq.conf.d/hosts");
std::stringstream responsedata;
responsedata << R"({"domains":)";
// std::string ip_string = "";
// std::string domain_string = "";
// int iter = 0;
responsedata << config::config.getConfig()["settings"]["dns"]["localdomains"];
// for (nlohmann::json domains : config::config.getConfig()["setttings"]["dns"]["localdomains"]) {
// responsedata <<
// }
// while (!domainsfile.eof())
// {
// domainsfile >> ip_string;
// domainsfile >> domain_string;
// if (domain_string.empty())
// {
// continue;
// }
// responsedata << R"({"ip":")" << ip_string << R"(","domain":")" << domain_string << R"("},)";
// ip_string = "";
// domain_string = "";
// iter++;
// }
// if (iter != 0)
// {
// responsedata.str(responsedata.str().erase(responsedata.str().size() - 1, 1) + "]}");
// }
// else
// {
responsedata << "}";
// }
// domainsfile.close();
responsedata << "}";
response.set_content(responsedata.str(), JSON_TYPE);
}
@@ -89,6 +61,7 @@ namespace api
domainsfile << ip << " " << dom << "\n";
}
domainsfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["dns"]["localdomains"] = json_body["domains"];
config::config.setConfig(new_config);
+1 -18
View File
@@ -29,28 +29,10 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ifstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
std::stringstream responsedata;
responsedata << R"({"servers":)";
responsedata << config::config.getConfig()["settings"]["dns"]["servers"];
// std::string dns_server_string = "";
// int iter = 0;
// while (std::getline(dnsserversfile, dns_server_string))
// {
// dns_server_string.erase(0, 11);
// responsedata << "\"" << dns_server_string << R"(",)";
// dns_server_string = "";
// iter++;
// }
// if (iter != 0)
// {
// responsedata.str(responsedata.str().erase(responsedata.str().size() - 1, 1) + "]}");
// }
// else
// {
responsedata << "}";
// }
dnsserversfile.close();
response.set_content(responsedata.str(), JSON_TYPE);
}
@@ -82,6 +64,7 @@ namespace api
dnsserversfile << "nameserver " << srv << "\n";
}
dnsserversfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["dns"]["servers"] = json_body["servers"];
config::config.setConfig(new_config);
+1 -11
View File
@@ -31,10 +31,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream ftpfile("/etc/openrouter/ftp");
// int ftp_enabled;
// ftpfile >> ftp_enabled;
// ftpfile.close();
int ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
@@ -63,7 +59,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ofstream ftpfileout("/etc/openrouter/ftp");
bool new_ftp_enabled = json_body["enabled"];
if (!new_ftp_enabled)
{
@@ -77,12 +72,7 @@ namespace api
system("rc add ftp");
syslog(LOG_INFO, "%s", "Ftp is enabled");
}
// ftpfileout << stoi(new_ftp_enabled);
// ftpfileout.close();
// std::ifstream ftpfile("/etc/openrouter/ftp");
// int ftp_enabled;
// ftpfile >> ftp_enabled;
// ftpfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ftp"]["enabled"] = new_ftp_enabled;
config::config.setConfig(new_config);
+5 -21
View File
@@ -31,31 +31,10 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream keysfile(KEYS_PATH);
std::stringstream responsedata;
responsedata << R"({"keys":)";
responsedata << config::config.getConfig()["settings"]["ssh"]["keys"];
// std::string key_string = "";
// int iter = 0;
// while (std::getline(keysfile, key_string))
// {
// if (key_string.empty())
// {
// continue;
// }
// responsedata << R"(")" << key_string << R"(",)";
// key_string = "";
// iter++;
// }
// if (iter != 0)
// {
// responsedata.str(responsedata.str().erase(responsedata.str().size() - 1, 1) + "]}");
// }
// else
// {
responsedata << "}";
// }
// keysfile.close();
response.set_content(responsedata.str(), JSON_TYPE);
}
@@ -82,6 +61,11 @@ namespace api
keysfile << key << "\n";
}
keysfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ssh"]["keys"] = json_body["keys"];
config::config.setConfig(new_config);
config::config.saveConfig();
system("rc restart ssh");
syslog(LOG_INFO, "%s", "SSH keys changed");
std::string responsedata = R"({"success":"true"})";
+6 -8
View File
@@ -36,10 +36,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream sshportfile(SSH_PORT_PATH);
// int ssh_port;
// sshportfile >> ssh_port;
// sshportfile.close();
int ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
std::stringstream responsedata;
responsedata << R"({"port":")" << ssh_port << R"("})";
@@ -95,10 +91,12 @@ namespace api
}
std::string syslogstring = "SSH port changed to " + new_ssh_port;
syslog(LOG_INFO, "%s", syslogstring.c_str());
std::ifstream sshportfile(SSH_PORT_PATH);
int ssh_port;
sshportfile >> ssh_port;
sshportfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ssh"]["port"] = std::stoi(new_ssh_port);
config::config.setConfig(new_config);
config::config.saveConfig();
int ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
std::stringstream responsedata;
responsedata << R"({"port":")" << ssh_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+6 -8
View File
@@ -17,19 +17,17 @@ namespace api
{
std::string get_ssh_server()
{
// std::ifstream serverfile("/etc/openrouter/ssh/server");
// std::string ssh_server = "";
// serverfile >> ssh_server;
// serverfile.close();
return config::config.getConfig()["settings"]["ssh"]["server"];
}
std::string set_ssh_server(std::string &server)
{
std::ofstream serverfile("/etc/openrouter/ssh/server");
serverfile << server;
serverfile.close();
return get_ssh_server();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ssh"]["server"] = server;
config::config.setConfig(new_config);
config::config.saveConfig();
return config::config.getConfig()["settings"]["ssh"]["server"];
}
void get_ssh_server_http(const httplib::Request &request, httplib::Response &response)
+8 -13
View File
@@ -31,10 +31,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream sshstatusfile("/etc/openrouter/ssh/status");
// int ssh_status;
// sshstatusfile >> ssh_status;
// sshstatusfile.close();
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
@@ -63,9 +59,8 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream sshfileout("/etc/openrouter/ssh/status");
std::string new_ssh_status = json_body["status"];
if (new_ssh_status == "0")
bool new_ssh_status = json_body["status"];
if (!new_ssh_status)
{
if (get_ssh_server() == DROPBEAR_SSH)
{
@@ -89,12 +84,12 @@ namespace api
}
syslog(LOG_INFO, "%s", "SSH is enabled");
}
sshfileout << stoi(new_ssh_status);
sshfileout.close();
std::ifstream sshfile("/etc/openrouter/ssh/status");
int ssh_status;
sshfile >> ssh_status;
sshfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ssh"]["enabled"] = new_ssh_status;
config::config.setConfig(new_config);
config::config.saveConfig();
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+1 -11
View File
@@ -35,10 +35,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
// int telnet_enabled;
// telnetfile >> telnet_enabled;
// telnetfile.close();
int telnet_enabled = config::config.getConfig()["settings"]["telnet"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
@@ -67,7 +63,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
bool new_telnet_enabled = json_body["enabled"];
if (!new_telnet_enabled)
{
@@ -81,17 +76,12 @@ namespace api
system("rc add telnet");
syslog(LOG_INFO, "%s", "Telnet is enabled");
}
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["telnet"]["enabled"] = new_telnet_enabled;
config::config.setConfig(new_config);
config::config.saveConfig();
int telnet_enabled = config::config.getConfig()["settings"]["telnet"]["enabled"];
// telnetfileout << stoi(new_telnet_enabled);
// telnetfileout.close();
// std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
// int telnet_enabled;
// telnetfile >> telnet_enabled;
// telnetfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+1 -11
View File
@@ -35,10 +35,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream telnetportfile("/etc/openrouter/telnet/port");
// int telnet_port;
// telnetportfile >> telnet_port;
// telnetportfile.close();
int telnet_port = config::config.getConfig()["settings"]["telnet"]["port"];
std::stringstream responsedata;
responsedata << R"({"port":")" << telnet_port << R"("})";
@@ -67,18 +63,12 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ofstream telnetportfileout("/etc/openrouter/telnet/port");
std::string new_telnet_port = json_body["port"];
// telnetportfileout << stoi(new_telnet_port);
// telnetportfileout.close();
system("rc restart telnet");
std::string syslogstring = "Telnet port changed to " + new_telnet_port;
syslog(LOG_INFO, "%s", syslogstring.c_str());
// std::ifstream telnetportfile("/etc/openrouter/telnet/port");
// int telnet_port;
// telnetportfile >> telnet_port;
// telnetportfile.close();
std::stringstream responsedata;
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["telnet"]["port"] = stoi(new_telnet_port);
config::config.setConfig(new_config);
+6 -27
View File
@@ -35,19 +35,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
// std::string wifi_channel;
// std::string wifisettingsbuffer;
// while (std::getline(wifisettingsfile, wifisettingsbuffer))
// {
// if (wifisettingsbuffer.find("channel=") == 0)
// {
// wifi_channel = wifisettingsbuffer;
// wifi_channel.erase(0, 8);
// break;
// }
// }
// wifisettingsfile.close();
int wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
std::stringstream responsedata;
responsedata << R"({"channel":")" << wifi_channel << R"("})";
@@ -97,20 +84,12 @@ namespace api
system("rc restart hostapd");
std::string syslogstring = "WIFI channel changed to " + new_channel;
syslog(LOG_INFO, "%s", syslogstring.c_str());
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
std::string wifi_channel;
std::string changedwifisettingsbuffer;
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer))
{
if (changedwifisettingsbuffer.find("channel=") == 0)
{
wifi_channel = changedwifisettingsbuffer;
wifi_channel.erase(0, 8);
break;
}
}
changedwifisettingsfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["wifi"]["channel"] = std::stoi(new_channel);
config::config.setConfig(new_config);
config::config.saveConfig();
int wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
std::stringstream responsedata;
responsedata << R"({"channel":")" << wifi_channel << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+6 -13
View File
@@ -35,19 +35,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
// std::string wifi_name;
// std::string wifisettingsbuffer;
// while (std::getline(wifisettingsfile, wifisettingsbuffer))
// {
// if (wifisettingsbuffer.find("ssid=") == 0)
// {
// wifi_name = wifisettingsbuffer;
// wifi_name.erase(0, 5);
// break;
// }
// }
// wifisettingsfile.close();
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
std::stringstream responsedata;
responsedata << R"({"name":")" << wifi_name << R"("})";
@@ -111,6 +98,12 @@ namespace api
}
}
changedwifisettingsfile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["wifi"]["name"] = new_wifi_name;
config::config.setConfig(new_config);
config::config.saveConfig();
wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
std::stringstream responsedata;
responsedata << R"({"name":")" << wifi_name << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+7 -26
View File
@@ -35,19 +35,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
// std::string wifi_password;
// std::string wifisettingsbuffer;
// while (std::getline(wifisettingsfile, wifisettingsbuffer))
// {
// if (wifisettingsbuffer.find("wpa_passphrase=") == 0)
// {
// wifi_password = wifisettingsbuffer;
// wifi_password.erase(0, 15);
// break;
// }
// }
// wifisettingsfile.close();
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
std::stringstream responsedata;
responsedata << R"({"password":")" << wifi_password << R"("})";
@@ -82,19 +69,7 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
std::string old_wifi_password;
std::string wifisettingsbuffer;
while (std::getline(wifisettingsfile, wifisettingsbuffer))
{
if (wifisettingsbuffer.find("wpa_passphrase=") == 0)
{
old_wifi_password = wifisettingsbuffer;
old_wifi_password.erase(0, 15);
break;
}
}
wifisettingsfile.close();
std::string old_wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
std::string req_old_password = json_body["password"];
if (old_wifi_password != req_old_password)
{
@@ -108,6 +83,12 @@ namespace api
system("rc restart hostapd");
std::string syslogstring = "WIFI password changed";
syslog(LOG_INFO, "%s", syslogstring.c_str());
sleep(1);
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
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);
-20
View File
@@ -30,26 +30,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
// std::string wifi_name;
// std::string wifi_password;
// std::string wifisettingsbuffer;
// while (std::getline(wifisettingsfile, wifisettingsbuffer))
// {
// if (wifisettingsbuffer.find("ssid=") == 0)
// {
// wifi_name = wifisettingsbuffer;
// wifi_name.erase(0, 5);
// }
// if (wifisettingsbuffer.find("wpa_passphrase=") == 0)
// {
// wifi_password = wifisettingsbuffer;
// wifi_password.erase(0, 15);
// break;
// }
// }
// wifisettingsfile.close();
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
std::stringstream toqrstring;
+8 -13
View File
@@ -31,10 +31,6 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
// std::ifstream wifistatusfile("/etc/openrouter/wifi/status");
// int wifi_status;
// wifistatusfile >> wifi_status;
// wifistatusfile.close();
int wifi_status = config::config.getConfig()["settings"]["wifi"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << wifi_status << R"("})";
@@ -63,9 +59,8 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream wififileout("/etc/openrouter/wifi/status");
std::string new_wifi_status = json_body["status"];
if (new_wifi_status == "0")
bool new_wifi_status = json_body["status"];
if (!new_wifi_status)
{
system("rc stop hostapd");
system("rc del hostapd");
@@ -77,12 +72,12 @@ namespace api
system("rc add hostapd");
syslog(LOG_INFO, "%s", "WIFI is enabled");
}
wififileout << stoi(new_wifi_status);
wififileout.close();
std::ifstream wififile("/etc/openrouter/wifi/status");
int wifi_status;
wififile >> wifi_status;
wififile.close();
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["wifi"]["enabled"] = new_wifi_status;
config::config.setConfig(new_config);
config::config.saveConfig();
int wifi_status = config::config.getConfig()["settings"]["wifi"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << wifi_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+1 -1
View File
@@ -28,7 +28,7 @@ const get_ssh_status = () => {
const set_ssh_status = () => {
fetch(routes.ssh_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","status":"${sshenable.checked ? 1 : 0}"}`
body: `{"token":"${localStorage.getItem("token")}","status":${sshenable.checked}}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.status === '1') {
sshenable.checked = true
+1 -1
View File
@@ -31,7 +31,7 @@ const get_wifi_status = () => {
const set_wifi_status = () => {
fetch(routes.wifi_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem('token')}","status":"${wifistatus.checked ? "1" : "0"}"}`
body: `{"token":"${localStorage.getItem('token')}","status":${wifistatus.checked}}`
}).then(data => data.json()).then(jsondata => {
if (jsondata.status === "1") {
wifistatus.checked = true