rootfs added and auth service in
This commit is contained in:
1 parent
35bd73b894
commit
1bea37deb2
113 files changed
+1369
-24
No files matched your search
@@ -1,15 +0,0 @@
|
||||
#ifndef DNS_HPP
|
||||
#define DNS_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
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
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "dns.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), 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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["enabled"] == nullptr) {
|
||||
response.set_content(DNS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream dnsfileout("/etc/openrouter/dns");
|
||||
std::string new_dns_enabled = json_body["enabled"];
|
||||
if (new_dns_enabled == "0") {
|
||||
system("/etc/init.d/dnsmasq stop");
|
||||
system("rm /etc/rc.d/60dnsmasq");
|
||||
syslog(LOG_INFO, "DNS is disabled");
|
||||
} else {
|
||||
system("/etc/init.d/dnsmasq restart");
|
||||
system("ln -sv /etc/init.d/dnsmasq /etc/rc.d/60dnsmasq");
|
||||
syslog(LOG_INFO, "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);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
#include "dns.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), 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 == "") {
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), 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("/etc/init.d/dnsmasq restart");
|
||||
syslog(LOG_INFO, "DNS local domains changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "dns.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
// #define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), 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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||
nlohmann::json servers = json_body["servers"];
|
||||
for (nlohmann::json_abi_v3_11_3::json server : servers) {
|
||||
std::string srv = server;
|
||||
if (server == "") {
|
||||
continue;
|
||||
}
|
||||
dnsserversfile << "nameserver " << srv << "\n";
|
||||
}
|
||||
dnsserversfile.close();
|
||||
system("/etc/init.d/dnsmasq restart");
|
||||
syslog(LOG_INFO, "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
#include "ftp.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
void get_ftp(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream ftpfile("/etc/openrouter/ftp");
|
||||
int ftp_enabled;
|
||||
ftpfile >> ftp_enabled;
|
||||
ftpfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_ftp(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["enabled"] == nullptr) {
|
||||
response.set_content(FTP_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream ftpfileout("/etc/openrouter/ftp");
|
||||
std::string new_ftp_enabled = json_body["enabled"];
|
||||
if (new_ftp_enabled == "0") {
|
||||
system("/etc/init.d/ftp stop");
|
||||
system("rm /etc/rc.d/90ftp");
|
||||
syslog(LOG_INFO, "Ftp is disabled");
|
||||
} else {
|
||||
system("/etc/init.d/ftp start");
|
||||
system("ln -sv /etc/init.d/ftp /etc/rc.d/90ftp");
|
||||
syslog(LOG_INFO, "Ftp is enabled");
|
||||
}
|
||||
ftpfileout << stoi(new_ftp_enabled);
|
||||
ftpfileout.close();
|
||||
std::ifstream ftpfile("/etc/openrouter/ftp");
|
||||
int ftp_enabled;
|
||||
ftpfile >> ftp_enabled;
|
||||
ftpfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#ifndef FTP_HPP
|
||||
#define FTP_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // FTP_HPP
|
||||
@@ -1,95 +0,0 @@
|
||||
#include "ssh.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define KEYS_PATH "/root/.ssh/authorized_keys"
|
||||
|
||||
void get_ssh_keys(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream keysfile(KEYS_PATH);
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"keys":[)";
|
||||
std::string key_string = "";
|
||||
int iter = 0;
|
||||
while (std::getline(keysfile, key_string)) {
|
||||
if (key_string == "") {
|
||||
continue;
|
||||
}
|
||||
responsedata << R"(")" << key_string << R"(",)";
|
||||
key_string = "";
|
||||
iter++;
|
||||
}
|
||||
if (iter != 0) {
|
||||
responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}");
|
||||
} else {
|
||||
responsedata << "]}";
|
||||
}
|
||||
keysfile.close();
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
void set_ssh_keys(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream keysfile(KEYS_PATH);
|
||||
nlohmann::json keys = json_body["keys"];
|
||||
for (std::string key : keys) {
|
||||
keysfile << key << "\n";
|
||||
}
|
||||
keysfile.close();
|
||||
system("/etc/init.d/ssh restart");
|
||||
syslog(LOG_INFO, "SSH keys changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
#include "ssh.hpp"
|
||||
#include <colors.h>
|
||||
#include "../../types.hpp"
|
||||
#include "../../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
|
||||
#define SSH_PORT_PATH "/etc/openrouter/ssh/port"
|
||||
|
||||
void get_ssh_port(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream sshportfile(SSH_PORT_PATH);
|
||||
int ssh_port;
|
||||
sshportfile >> ssh_port;
|
||||
sshportfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << ssh_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
void set_ssh_port(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["port"] == nullptr) {
|
||||
response.set_content(SSH_PORT_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream oldsshportfile(SSH_PORT_PATH);
|
||||
int old_ssh_port;
|
||||
oldsshportfile >> old_ssh_port;
|
||||
oldsshportfile.close();
|
||||
std::ofstream sshportfileout(SSH_PORT_PATH);
|
||||
std::string new_ssh_port = json_body["port"];
|
||||
sshportfileout << stoi(new_ssh_port);
|
||||
sshportfileout.close();
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("/etc/init.d/ssh restart");
|
||||
std::string syslogstring = "SSH port changed to " + new_ssh_port;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
std::ifstream sshportfile(SSH_PORT_PATH);
|
||||
int ssh_port;
|
||||
sshportfile >> ssh_port;
|
||||
sshportfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << ssh_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef SSH_HPP
|
||||
#define SSH_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ssh_status(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_ssh_keys(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ssh_keys(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_ssh_port(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ssh_port(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // SSH_HPP
|
||||
@@ -1,97 +0,0 @@
|
||||
#include "ssh.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})"
|
||||
|
||||
void get_ssh_status(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream sshstatusfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshstatusfile >> ssh_status;
|
||||
sshstatusfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << ssh_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
void set_ssh_status(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["status"] == nullptr) {
|
||||
response.set_content(SSH_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream sshfileout("/etc/openrouter/ssh/status");
|
||||
std::string new_ssh_status = json_body["status"];
|
||||
if (new_ssh_status == "0") {
|
||||
system("/etc/init.d/ssh stop");
|
||||
system("rm /etc/rc.d/75ssh");
|
||||
syslog(LOG_INFO, "SSH is disabled");
|
||||
} else {
|
||||
system("/etc/init.d/ssh start");
|
||||
system("ln -sv /etc/init.d/ssh /etc/rc.d/75ssh");
|
||||
syslog(LOG_INFO, "SSH is enabled");
|
||||
}
|
||||
sshfileout << stoi(new_ssh_status);
|
||||
sshfileout.close();
|
||||
std::ifstream sshfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshfile >> ssh_status;
|
||||
sshfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << ssh_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
#include "telnet.hpp"
|
||||
#include <colors.h>
|
||||
#include "../../types.hpp"
|
||||
#include "../../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
void get_telnet(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
|
||||
int telnet_enabled;
|
||||
telnetfile >> telnet_enabled;
|
||||
telnetfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_telnet(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["enabled"] == nullptr) {
|
||||
response.set_content(TELNET_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
|
||||
std::string new_telnet_enabled = json_body["enabled"];
|
||||
if (new_telnet_enabled == "0") {
|
||||
system("/etc/init.d/telnet stop");
|
||||
system("rm /etc/rc.d/70telnet");
|
||||
syslog(LOG_INFO, "Telnet is disabled");
|
||||
} else {
|
||||
system("/etc/init.d/telnet start");
|
||||
system("ln -sv /etc/init.d/telnet /etc/rc.d/70telnet");
|
||||
syslog(LOG_INFO, "Telnet is enabled");
|
||||
}
|
||||
telnetfileout << stoi(new_telnet_enabled);
|
||||
telnetfileout.close();
|
||||
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
|
||||
int telnet_enabled;
|
||||
telnetfile >> telnet_enabled;
|
||||
telnetfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
#include "telnet.hpp"
|
||||
#include <colors.h>
|
||||
#include "../../types.hpp"
|
||||
#include "../../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
#define TELNET_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
|
||||
|
||||
void get_telnet_port(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream telnetportfile("/etc/openrouter/telnet/port");
|
||||
int telnet_port;
|
||||
telnetportfile >> telnet_port;
|
||||
telnetportfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << telnet_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_telnet_port(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["port"] == nullptr) {
|
||||
response.set_content(TELNET_PORT_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream telnetportfileout("/etc/openrouter/telnet/port");
|
||||
std::string new_telnet_port = json_body["port"];
|
||||
telnetportfileout << stoi(new_telnet_port);
|
||||
telnetportfileout.close();
|
||||
system("/etc/init.d/telnet restart");
|
||||
std::string syslogstring = "Telnet port changed to " + new_telnet_port;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
std::ifstream telnetportfile("/etc/openrouter/telnet/port");
|
||||
int telnet_port;
|
||||
telnetportfile >> telnet_port;
|
||||
telnetportfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << telnet_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef SETTINGS_TELNET_HPP
|
||||
#define SETTINGS_TELNET_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
void set_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_telnet_port(const httplib::Request &request, httplib::Response &response);
|
||||
void set_telnet_port(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // SETTINGS_TELNET_HPP
|
||||
Reference in new issue
Block a user