added config mangager
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-10 18:13:51 +07:00
1 parent ee517632e4
commit 0c4183843f
21 files changed
+282 -203

No files matched your search

+15 -6
View File
@@ -3,8 +3,14 @@
"dns": {
"enabled": true,
"localdomains": [
{"ip": "127.0.0.1", "domain": "localhost"},
{"ip": "192.168.200.1", "domain": "openrouter.local.com"}
{
"domain": "localhost",
"ip": "127.0.0.1"
},
{
"domain": "openrouter.local.com",
"ip": "192.168.200.1"
}
],
"servers": [
"8.8.8.8"
@@ -15,19 +21,22 @@
},
"ssh": {
"enabled": true,
"keys": [
"key1",
"key2"
],
"port": 22,
"server": "dropbear",
"keys": []
"server": "openssh"
},
"telnet": {
"enabled": true,
"port": 23
},
"wifi": {
"channel": 6,
"enabled": true,
"name": "OpenRouterWifi",
"password": "OpenRouterPassword",
"channel": 6
"password": "OpenRouterPassword"
}
}
}
+2
View File
@@ -4,9 +4,11 @@
#include <system/system.hpp>
#include <syslog.h>
#include <security/cors.hpp>
#include <config/config.hpp>
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);
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <ConfigManager.hpp>
namespace config {
static ConfigManager config(std::string("../config.json"));
}
+21 -13
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
@@ -30,10 +31,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
@@ -61,9 +63,9 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream dnsfileout("/etc/openrouter/dns");
std::string new_dns_enabled = json_body["enabled"];
if (new_dns_enabled == "0")
// std::ofstream dnsfileout("/etc/openrouter/dns");
bool new_dns_enabled = json_body["enabled"];
if (!new_dns_enabled)
{
system("rc stop dnsmasq");
system("rc del dnsmasq");
@@ -75,12 +77,18 @@ namespace api
system("rc add dnsmasq");
syslog(LOG_INFO, "%s", "DNS is enabled");
}
dnsfileout << stoi(new_dns_enabled);
dnsfileout.close();
std::ifstream dnsfile("/etc/openrouter/dns");
int dns_enabled;
dnsfile >> dns_enabled;
dnsfile.close();
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);
+36 -27
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
namespace api
{
@@ -28,34 +29,38 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ifstream domainsfile("/etc/dnsmasq.conf.d/hosts");
// 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;
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 << 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();
response.set_content(responsedata.str(), JSON_TYPE);
}
@@ -84,6 +89,10 @@ namespace api
domainsfile << ip << " " << dom << "\n";
}
domainsfile.close();
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["dns"]["localdomains"] = json_body["domains"];
config::config.setConfig(new_config);
config::config.saveConfig();
system("rc restart dnsmasq");
syslog(LOG_INFO, "%s", "DNS local domains changed");
std::string responsedata = R"({"success":"true"})";
+24 -18
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
namespace api
{
@@ -30,24 +31,25 @@ namespace api
}
std::ifstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
std::stringstream responsedata;
responsedata << R"({"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 << "]}";
}
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);
}
@@ -80,6 +82,10 @@ namespace api
dnsserversfile << "nameserver " << srv << "\n";
}
dnsserversfile.close();
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["dns"]["servers"] = json_body["servers"];
config::config.setConfig(new_config);
config::config.saveConfig();
system("rc restart dnsmasq");
syslog(LOG_INFO, "%s", "DNS servers changed");
std::string responsedata = R"({"success":"true"})";
+20 -13
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
@@ -30,10 +31,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
@@ -61,9 +63,9 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream ftpfileout("/etc/openrouter/ftp");
std::string new_ftp_enabled = json_body["enabled"];
if (new_ftp_enabled == "0")
// std::ofstream ftpfileout("/etc/openrouter/ftp");
bool new_ftp_enabled = json_body["enabled"];
if (!new_ftp_enabled)
{
system("rc stop ftp");
system("rc del ftp");
@@ -75,12 +77,17 @@ 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();
// ftpfileout << stoi(new_ftp_enabled);
// ftpfileout.close();
// std::ifstream ftpfile("/etc/openrouter/ftp");
// int ftp_enabled;
// ftpfile >> ftp_enabled;
// ftpfile.close();
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ftp"]["enabled"] = new_ftp_enabled;
config::config.setConfig(new_config);
config::config.saveConfig();
int ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+25 -23
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define KEYS_PATH "~/.ssh/authorized_keys"
@@ -30,30 +31,31 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ifstream keysfile(KEYS_PATH);
// std::ifstream keysfile(KEYS_PATH);
std::stringstream responsedata;
responsedata << R"({"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();
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);
}
+6 -4
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
#define SSH_PORT_PATH "/etc/openrouter/ssh/port"
@@ -35,10 +36,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+6 -5
View File
@@ -5,6 +5,7 @@
#include <helpers.hpp>
#include <types.hpp>
#include <auth/auth.hpp>
#include <config/config.hpp>
#define SSH_SERVER_REQUIRED_STRING R"({"required":"[token,server]"})"
@@ -16,11 +17,11 @@ namespace api
{
std::string get_ssh_server()
{
std::ifstream serverfile("/etc/openrouter/ssh/server");
std::string ssh_server = "";
serverfile >> ssh_server;
serverfile.close();
return 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)
+6 -4
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})"
@@ -30,10 +31,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+20 -13
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
@@ -34,10 +35,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
@@ -65,9 +67,9 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
std::string new_telnet_enabled = json_body["enabled"];
if (new_telnet_enabled == "0")
// std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
bool new_telnet_enabled = json_body["enabled"];
if (!new_telnet_enabled)
{
system("rc stop telnet");
system("rc del telnet");
@@ -79,12 +81,17 @@ namespace api
system("rc add telnet");
syslog(LOG_INFO, "%s", "Telnet is enabled");
}
telnetfileout << stoi(new_telnet_enabled);
telnetfileout.close();
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
int telnet_enabled;
telnetfile >> telnet_enabled;
telnetfile.close();
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);
+18 -11
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define TELNET_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
@@ -34,10 +35,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
@@ -65,18 +67,23 @@ namespace api
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream telnetportfileout("/etc/openrouter/telnet/port");
// std::ofstream telnetportfileout("/etc/openrouter/telnet/port");
std::string new_telnet_port = json_body["port"];
telnetportfileout << stoi(new_telnet_port);
telnetportfileout.close();
// 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::ifstream telnetportfile("/etc/openrouter/telnet/port");
// int telnet_port;
// telnetportfile >> telnet_port;
// telnetportfile.close();
std::stringstream responsedata;
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["telnet"]["port"] = stoi(new_telnet_port);
config::config.setConfig(new_config);
config::config.saveConfig();
int telnet_port = config::config.getConfig()["settings"]["telnet"]["port"];
responsedata << R"({"port":")" << telnet_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
+15 -13
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define WIFI_CHANNEL_REQUIRED_STRING R"({"required":"[token,channel]"})"
@@ -34,19 +35,20 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+15 -13
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define WIFI_NAME_REQUIRED_STRING R"({"required":"[token,name]"})"
@@ -34,19 +35,20 @@ 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::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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+15 -13
View File
@@ -9,6 +9,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define WIFI_PASSWORD_REQUIRED_STRING R"({"required":"[token,password,newpassword]"})"
@@ -34,19 +35,20 @@ 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::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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+23 -20
View File
@@ -6,6 +6,7 @@
#include <QR-Code-generator/qrtosvg.hpp>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
namespace api
{
@@ -29,26 +30,28 @@ 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::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;
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
+6 -4
View File
@@ -5,6 +5,7 @@
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define WIFI_REQUIRED_STRING R"({"required":"[token,status]"})"
@@ -30,10 +31,11 @@ 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();
// 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"("})";
response.set_content(responsedata.str(), JSON_TYPE);
+1 -1
View File
@@ -33,7 +33,7 @@ const get_dns_enabled_status = () => {
const set_dns_enabled_status = () => {
fetch(routes.dns_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${dnsenabled.checked ? 1 : 0}"}`
body: `{"token":"${localStorage.getItem("token")}","enabled":${dnsenabled.checked}}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
dnsenabled.checked = true
+1 -1
View File
@@ -19,7 +19,7 @@ const get_ftp_enabled_status = () => {
const set_ftp_enabled_status = () => {
fetch(routes.ftp_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${ftpenabled.checked ? 1 : 0}"}`
body: `{"token":"${localStorage.getItem("token")}","enabled":${ftpenabled.checked}}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
ftpenabled.checked = true
+1 -1
View File
@@ -27,7 +27,7 @@ const get_telnet_enabled_status = () => {
const set_telnet_enabled_status = () => {
fetch(routes.telnet_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${telnetenabled.checked ? 1 : 0}"}`
body: `{"token":"${localStorage.getItem("token")}","enabled":${telnetenabled.checked}}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
telnetenabled.checked = true