Merge pull request 'config-file' (#12) from config-file 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/12
This commit was merged in pull request #12.
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"settings": {
|
||||
"dns": {
|
||||
"enabled": false,
|
||||
"localdomains": [
|
||||
{
|
||||
"domain": "localhost",
|
||||
"ip": "127.0.0.1"
|
||||
},
|
||||
{
|
||||
"domain": "openrouter.local.com",
|
||||
"ip": "192.168.200.1"
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
"8.8.8.8"
|
||||
]
|
||||
},
|
||||
"ftp": {
|
||||
"enabled": false
|
||||
},
|
||||
"ssh": {
|
||||
"enabled": false,
|
||||
"keys": [
|
||||
"key1",
|
||||
"key2"
|
||||
],
|
||||
"port": 22,
|
||||
"server": "dropbear"
|
||||
},
|
||||
"telnet": {
|
||||
"enabled": false,
|
||||
"port": 23
|
||||
},
|
||||
"wifi": {
|
||||
"channel": 6,
|
||||
"enabled": false,
|
||||
"name": "OpenRouterWifi",
|
||||
"password": "OpenRouterPassword"
|
||||
}
|
||||
},
|
||||
"static": {
|
||||
"css": "../src/web/css",
|
||||
"js": "../src/web/js",
|
||||
"root": "../src/web"
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <system/system.hpp>
|
||||
#include <syslog.h>
|
||||
#include <security/cors.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
OpenRouter::OpenRouter()
|
||||
{
|
||||
@@ -50,9 +51,9 @@ OpenRouter::OpenRouter()
|
||||
|
||||
this->srv.Options("/(.*)", api::security::set_cors_headers);
|
||||
|
||||
this->srv.set_mount_point("/", "../src/web");
|
||||
this->srv.set_mount_point("/js", "../src/web/js");
|
||||
this->srv.set_mount_point("/css", "../src/web/css");
|
||||
this->srv.set_mount_point("/", config::config.getConfig()["static"]["root"]);
|
||||
this->srv.set_mount_point("/js", config::config.getConfig()["static"]["js"]);
|
||||
this->srv.set_mount_point("/css", config::config.getConfig()["static"]["css"]);
|
||||
}
|
||||
|
||||
OpenRouter::~OpenRouter() = default;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <ConfigManager.hpp>
|
||||
|
||||
namespace config {
|
||||
static ConfigManager config(std::string("../config.json"));
|
||||
}
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -61,9 +59,8 @@ 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")
|
||||
bool new_dns_enabled = json_body["enabled"];
|
||||
if (!new_dns_enabled)
|
||||
{
|
||||
system("rc stop dnsmasq");
|
||||
system("rc del dnsmasq");
|
||||
@@ -75,12 +72,12 @@ 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();
|
||||
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"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -28,34 +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;
|
||||
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":)";
|
||||
responsedata << config::config.getConfig()["settings"]["dns"]["localdomains"];
|
||||
responsedata << "}";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
@@ -84,6 +61,11 @@ 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);
|
||||
config::config.saveConfig();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS local domains changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -28,27 +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":[)";
|
||||
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();
|
||||
responsedata << R"({"servers":)";
|
||||
responsedata << config::config.getConfig()["settings"]["dns"]["servers"];
|
||||
responsedata << "}";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
@@ -80,6 +64,11 @@ 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);
|
||||
config::config.saveConfig();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
|
||||
+10
-13
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -61,9 +59,8 @@ 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")
|
||||
bool new_ftp_enabled = json_body["enabled"];
|
||||
if (!new_ftp_enabled)
|
||||
{
|
||||
system("rc stop ftp");
|
||||
system("rc del ftp");
|
||||
@@ -75,12 +72,12 @@ 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);
|
||||
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);
|
||||
|
||||
@@ -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,10 @@ namespace api
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
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"];
|
||||
responsedata << "}";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
@@ -80,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"})";
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -93,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);
|
||||
|
||||
@@ -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,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 ssh_server;
|
||||
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)
|
||||
|
||||
+10
-13
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -61,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)
|
||||
{
|
||||
@@ -87,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);
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -65,9 +63,8 @@ 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")
|
||||
bool new_telnet_enabled = json_body["enabled"];
|
||||
if (!new_telnet_enabled)
|
||||
{
|
||||
system("rc stop telnet");
|
||||
system("rc del telnet");
|
||||
@@ -79,12 +76,12 @@ 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();
|
||||
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"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -65,18 +63,17 @@ 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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -95,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);
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -109,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);
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -80,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)
|
||||
{
|
||||
@@ -106,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);
|
||||
|
||||
@@ -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,8 @@ 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;
|
||||
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
||||
|
||||
|
||||
@@ -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,7 @@ 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"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
@@ -61,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");
|
||||
@@ -75,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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user