deleted rootfs and auth_service
This commit is contained in:
1 parent
b694830190
commit
85652a4e99
156 files changed
-2051
No files matched your search
@@ -0,0 +1,21 @@
|
||||
#ifndef DNS_HPP
|
||||
#define DNS_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void get_dns(const httplib::Request &request, httplib::Response &response);
|
||||
void set_dns(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_dns_servers(const httplib::Request &request, httplib::Response &response);
|
||||
void set_dns_servers(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_local_domains(const httplib::Request &request, httplib::Response &response);
|
||||
void set_local_domains(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DNS_HPP
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "dns.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
#include "../../auth/auth.hpp"
|
||||
#include "../../helpers.hpp"
|
||||
|
||||
#define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void get_dns(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 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);
|
||||
}
|
||||
|
||||
void set_dns(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 (json_body["enabled"] == nullptr)
|
||||
{
|
||||
response.set_content(DNS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream dnsfileout("/etc/openrouter/dns");
|
||||
std::string new_dns_enabled = json_body["enabled"];
|
||||
if (new_dns_enabled == "0")
|
||||
{
|
||||
system("rc stop dnsmasq");
|
||||
system("rc del dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS is disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
system("rc restart dnsmasq");
|
||||
system("rc add dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS is 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#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_dns_servers(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 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 << "]}";
|
||||
}
|
||||
dnsserversfile.close();
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void set_dns_servers(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 dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||
nlohmann::json servers = json_body["servers"];
|
||||
for (const nlohmann::json_abi_v3_11_3::json &server : servers)
|
||||
{
|
||||
std::string srv = server;
|
||||
if (server == "")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
dnsserversfile << "nameserver " << srv << "\n";
|
||||
}
|
||||
dnsserversfile.close();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user