some hot fixes
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

This commit is contained in:
wt committed 2025-02-08 18:37:21 +07:00
1 parent 84733a2644
commit ad266d0332
23 files changed
+1126 -1067

No files matched your search

+70 -67
View File
@@ -10,82 +10,85 @@ namespace api
{
namespace settings
{
void get_local_domains(const httplib::Request &request, httplib::Response &response)
namespace dns
{
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (!check_body(request))
void get_local_domains(const httplib::Request &request, httplib::Response &response)
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (!authenticate(json_body["token"]))
{
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())
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (!check_body(request))
{
continue;
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
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);
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
void set_local_domains(const httplib::Request &request, httplib::Response &response)
{
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (!check_body(request))
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
if (!authenticate(json_body["token"]))
{
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();
response.set_content(responsedata.str(), JSON_TYPE);
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (!authenticate(json_body["token"]))
void set_local_domains(const httplib::Request &request, httplib::Response &response)
{
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (!check_body(request))
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (!authenticate(json_body["token"]))
{
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ofstream domainsfile("/etc/dnsmasq.conf.d/hosts");
nlohmann::json domains = json_body["domains"];
for (nlohmann::json_abi_v3_11_3::json domain : domains)
{
std::string ip = domain["ip"];
std::string dom = domain["domain"];
domainsfile << ip << " " << dom << "\n";
}
domainsfile.close();
system("rc restart dnsmasq");
syslog(LOG_INFO, "%s", "DNS local domains changed");
std::string responsedata = R"({"success":"true"})";
response.set_content(responsedata, JSON_TYPE);
}
std::ofstream domainsfile("/etc/dnsmasq.conf.d/hosts");
nlohmann::json domains = json_body["domains"];
for (nlohmann::json_abi_v3_11_3::json domain : domains)
{
std::string ip = domain["ip"];
std::string dom = domain["domain"];
domainsfile << ip << " " << dom << "\n";
}
domainsfile.close();
system("rc restart dnsmasq");
syslog(LOG_INFO, "%s", "DNS local domains changed");
std::string responsedata = R"({"success":"true"})";
response.set_content(responsedata, JSON_TYPE);
}
}
}