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
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:
1 parent
ee517632e4
commit
0c4183843f
21 files changed
+282
-203
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user