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>
|
||||
|
||||
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"})";
|
||||
|
||||
Reference in new issue
Block a user