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

+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);