deleted rootfs and auth_service

This commit is contained in:
wt committed 2024-12-15 01:58:36 +07:00
1 parent b694830190
commit 85652a4e99
156 files changed
-2051

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
#include "dns.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../types.hpp"
#include <syslog.h>
#include "../../auth/auth.hpp"
#include "../../helpers.hpp"
namespace api
{
namespace settings
{
void get_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;
}
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())
{
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);
}
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;
}
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);
}
}
}