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