refactorings
This commit is contained in:
1 parent
71da3eea03
commit
f5aff2ca7b
37 files changed
+1427
-1340
No files matched your search
@@ -28,10 +28,12 @@ add_executable(
|
||||
|
||||
src/settings/ftp/ftp.cpp
|
||||
|
||||
src/reboot/reboot.cpp
|
||||
src/system/reboot/reboot.cpp
|
||||
|
||||
src/syslog/syslog.cpp
|
||||
src/uptime/uptime.cpp
|
||||
src/system/syslog/syslog.cpp
|
||||
src/system/uptime/uptime.cpp
|
||||
|
||||
src/OpenRouter/OpenRouter.cpp
|
||||
|
||||
src/libs/QR-Code-generator/qrcodegen.cpp
|
||||
src/libs/QR-Code-generator/qrtosvg.cpp
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "OpenRouter.hpp"
|
||||
|
||||
OpenRouter::OpenRouter() {
|
||||
this->srv.Post("/api/settings/telnet/get", settings::get_telnet);
|
||||
this->srv.Post("/api/settings/telnet/set", settings::set_telnet);
|
||||
this->srv.Post("/api/settings/telnet/port/get", settings::get_telnet_port);
|
||||
this->srv.Post("/api/settings/telnet/port/set", settings::set_telnet_port);
|
||||
|
||||
this->srv.Post("/api/settings/ssh/status/get", settings::get_ssh_status);
|
||||
this->srv.Post("/api/settings/ssh/status/set", settings::set_ssh_status);
|
||||
this->srv.Post("/api/settings/ssh/keys/get", settings::get_ssh_keys);
|
||||
this->srv.Post("/api/settings/ssh/keys/set", settings::set_ssh_keys);
|
||||
this->srv.Post("/api/settings/ssh/port/get", settings::get_ssh_port);
|
||||
this->srv.Post("/api/settings/ssh/port/set", settings::set_ssh_port);
|
||||
|
||||
this->srv.Post("/api/settings/dns/get", settings::get_dns);
|
||||
this->srv.Post("/api/settings/dns/set", settings::set_dns);
|
||||
this->srv.Post("/api/settings/dns/servers/get", settings::get_dns_servers);
|
||||
this->srv.Post("/api/settings/dns/servers/set", settings::set_dns_servers);
|
||||
this->srv.Post("/api/settings/dns/domains/get", settings::get_local_domains);
|
||||
this->srv.Post("/api/settings/dns/domains/set", settings::set_local_domains);
|
||||
|
||||
this->srv.Post("/api/settings/ftp/get", settings::get_ftp);
|
||||
this->srv.Post("/api/settings/ftp/set", settings::set_ftp);
|
||||
|
||||
this->srv.Post("/api/settings/wifi/status/get", settings::get_wifi_status);
|
||||
this->srv.Post("/api/settings/wifi/status/set", settings::set_wifi_status);
|
||||
this->srv.Post("/api/settings/wifi/name/get", settings::get_wifi_name);
|
||||
this->srv.Post("/api/settings/wifi/name/set", settings::set_wifi_name);
|
||||
this->srv.Post("/api/settings/wifi/password/get", settings::get_wifi_password);
|
||||
this->srv.Post("/api/settings/wifi/password/set", settings::set_wifi_password);
|
||||
this->srv.Post("/api/settings/wifi/qr/get", settings::get_wifi_qr);
|
||||
this->srv.Post("/api/settings/wifi/channel/get", settings::get_wifi_channel);
|
||||
this->srv.Post("/api/settings/wifi/channel/set", settings::set_wifi_channel);
|
||||
|
||||
this->srv.Post("/api/reboot", systemfuncs::reboot);
|
||||
|
||||
this->srv.Get("/api/syslog", systemfuncs::get_syslog);
|
||||
this->srv.Get("/api/uptime", systemfuncs::get_uptime);
|
||||
|
||||
this->srv.Options("/(.*)", set_cors_headers);
|
||||
|
||||
this->srv.set_mount_point("/" , "../src/web");
|
||||
this->srv.set_mount_point("/js", "../src/web/js");
|
||||
this->srv.set_mount_point("/css", "../src/web/css");
|
||||
}
|
||||
|
||||
OpenRouter::~OpenRouter() {
|
||||
|
||||
}
|
||||
|
||||
int OpenRouter::serve(const std::string ip, int port, int socket_flags) {
|
||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
||||
|
||||
syslog(LOG_INFO, "openrouter administration software started.");
|
||||
srv.listen("127.0.0.1", 43244);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef OPENROUTER_HPP
|
||||
#define OPENROUTER_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <httplib.h>
|
||||
#include <colors.h>
|
||||
#include "../settings/settings.hpp"
|
||||
#include "../system/system.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define CORS_ENABLE
|
||||
#include "../security/cors.hpp"
|
||||
|
||||
class OpenRouter {
|
||||
private:
|
||||
httplib::Server srv;
|
||||
|
||||
public:
|
||||
OpenRouter();
|
||||
~OpenRouter();
|
||||
int serve(const std::string ip, int port, int socket_flags = 0);
|
||||
};
|
||||
|
||||
#endif // OPENROUTER_HPP
|
||||
@@ -1,69 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <httplib.h>
|
||||
#include <colors.h>
|
||||
#include "settings/telnet/telnet.hpp"
|
||||
#include "settings/ssh/ssh.hpp"
|
||||
#include "settings/dns/dns.hpp"
|
||||
#include "settings/ftp/ftp.hpp"
|
||||
#include "settings/wifi/wifi.hpp"
|
||||
#include "reboot/reboot.hpp"
|
||||
#include "syslog/syslog.hpp"
|
||||
#include "uptime/uptime.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#define CORS_ENABLE
|
||||
#include "security/cors.hpp"
|
||||
#include "OpenRouter/OpenRouter.hpp"
|
||||
|
||||
int main() {
|
||||
httplib::Server srv;
|
||||
|
||||
srv.Post("/api/settings/telnet/get", get_telnet);
|
||||
srv.Post("/api/settings/telnet/set", set_telnet);
|
||||
srv.Post("/api/settings/telnet/port/get", get_telnet_port);
|
||||
srv.Post("/api/settings/telnet/port/set", set_telnet_port);
|
||||
|
||||
srv.Post("/api/settings/ssh/status/get", get_ssh_status);
|
||||
srv.Post("/api/settings/ssh/status/set", set_ssh_status);
|
||||
srv.Post("/api/settings/ssh/keys/get", get_ssh_keys);
|
||||
srv.Post("/api/settings/ssh/keys/set", set_ssh_keys);
|
||||
srv.Post("/api/settings/ssh/port/get", get_ssh_port);
|
||||
srv.Post("/api/settings/ssh/port/set", set_ssh_port);
|
||||
|
||||
srv.Post("/api/settings/dns/get", get_dns);
|
||||
srv.Post("/api/settings/dns/set", set_dns);
|
||||
srv.Post("/api/settings/dns/servers/get", get_dns_servers);
|
||||
srv.Post("/api/settings/dns/servers/set", set_dns_servers);
|
||||
srv.Post("/api/settings/dns/domains/get", get_local_domains);
|
||||
srv.Post("/api/settings/dns/domains/set", set_local_domains);
|
||||
|
||||
srv.Post("/api/settings/ftp/get", get_ftp);
|
||||
srv.Post("/api/settings/ftp/set", set_ftp);
|
||||
|
||||
srv.Post("/api/settings/wifi/status/get", get_wifi_status);
|
||||
srv.Post("/api/settings/wifi/status/set", set_wifi_status);
|
||||
srv.Post("/api/settings/wifi/name/get", get_wifi_name);
|
||||
srv.Post("/api/settings/wifi/name/set", set_wifi_name);
|
||||
srv.Post("/api/settings/wifi/password/get", get_wifi_password);
|
||||
srv.Post("/api/settings/wifi/password/set", set_wifi_password);
|
||||
srv.Post("/api/settings/wifi/qr/get", get_wifi_qr);
|
||||
srv.Post("/api/settings/wifi/channel/get", get_wifi_channel);
|
||||
srv.Post("/api/settings/wifi/channel/set", set_wifi_channel);
|
||||
|
||||
srv.Post("/api/reboot", reboot);
|
||||
|
||||
srv.Get("/api/syslog", get_syslog);
|
||||
srv.Get("/api/uptime", get_uptime);
|
||||
|
||||
srv.Options("/(.*)", set_cors_headers);
|
||||
|
||||
srv.set_mount_point("/" , "../src/web");
|
||||
srv.set_mount_point("/js", "../src/web/js");
|
||||
srv.set_mount_point("/css", "../src/web/css");
|
||||
|
||||
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
|
||||
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
|
||||
|
||||
syslog(LOG_INFO, "openrouter administration software started.");
|
||||
srv.listen("127.0.0.1", 43244);
|
||||
return 0;
|
||||
OpenRouter router;
|
||||
return router.serve("127.0.0.1", 43244, 0);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "reboot.hpp"
|
||||
#include <json.hpp>
|
||||
#include "../routes.hpp"
|
||||
#include <colors.h>
|
||||
#include "../types.hpp"
|
||||
|
||||
void reboot(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;
|
||||
}
|
||||
system("reboot");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef REBOOT_HPP
|
||||
#define REBOOT_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void reboot(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // REBOOT_HPP
|
||||
@@ -3,13 +3,15 @@
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_dns(const httplib::Request &request, httplib::Response &response);
|
||||
void set_dns(const httplib::Request &request, httplib::Response &response);
|
||||
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_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);
|
||||
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
|
||||
@@ -7,92 +7,94 @@
|
||||
|
||||
#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);
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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, "DNS is disabled");
|
||||
} else {
|
||||
system("rc restart dnsmasq");
|
||||
system("rc add dnsmasq");
|
||||
syslog(LOG_INFO, "DNS is enabled");
|
||||
|
||||
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("rc stop dnsmasq");
|
||||
system("rc del dnsmasq");
|
||||
syslog(LOG_INFO, "DNS is disabled");
|
||||
} else {
|
||||
system("rc restart dnsmasq");
|
||||
system("rc add dnsmasq");
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -5,96 +5,98 @@
|
||||
#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);
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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;
|
||||
|
||||
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;
|
||||
}
|
||||
responsedata << R"({"ip":")" << ip_string << R"(","domain":")" << domain_string << R"("},)";
|
||||
ip_string = "";
|
||||
domain_string = "";
|
||||
iter++;
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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;
|
||||
}
|
||||
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";
|
||||
|
||||
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("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "DNS local domains changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
domainsfile.close();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "DNS local domains changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -7,92 +7,94 @@
|
||||
|
||||
// #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);
|
||||
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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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;
|
||||
|
||||
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;
|
||||
}
|
||||
dnsserversfile << "nameserver " << srv << "\n";
|
||||
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("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
dnsserversfile.close();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -7,92 +7,94 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream ftpfileout("/etc/openrouter/ftp");
|
||||
std::string new_ftp_enabled = json_body["enabled"];
|
||||
if (new_ftp_enabled == "0") {
|
||||
system("rc stop ftp");
|
||||
system("rc del ftp");
|
||||
syslog(LOG_INFO, "Ftp is disabled");
|
||||
} else {
|
||||
system("rc start ftp");
|
||||
system("rc add ftp");
|
||||
syslog(LOG_INFO, "Ftp is enabled");
|
||||
|
||||
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("rc stop ftp");
|
||||
system("rc del ftp");
|
||||
syslog(LOG_INFO, "Ftp is disabled");
|
||||
} else {
|
||||
system("rc start ftp");
|
||||
system("rc add ftp");
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
namespace settings {
|
||||
void get_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
|
||||
#endif // FTP_HPP
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef SETTINGS_HPP
|
||||
#define SETTINGS_HPP
|
||||
|
||||
#include "wifi/wifi.hpp"
|
||||
#include "telnet/telnet.hpp"
|
||||
#include "ssh/ssh.hpp"
|
||||
#include "ftp/ftp.hpp"
|
||||
#include "dns/dns.hpp"
|
||||
|
||||
#endif // SETTINGS_HPP
|
||||
@@ -7,89 +7,91 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
responsedata << R"(")" << key_string << R"(",)";
|
||||
key_string = "";
|
||||
iter++;
|
||||
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);
|
||||
}
|
||||
if (iter != 0) {
|
||||
responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}");
|
||||
} else {
|
||||
responsedata << "]}";
|
||||
}
|
||||
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("rc restart ssh");
|
||||
syslog(LOG_INFO, "SSH keys changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
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("rc restart ssh");
|
||||
syslog(LOG_INFO, "SSH keys changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -12,93 +12,95 @@
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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("rc restart ssh");
|
||||
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);
|
||||
|
||||
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("rc restart ssh");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,15 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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_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);
|
||||
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
|
||||
@@ -7,91 +7,93 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream sshfileout("/etc/openrouter/ssh/status");
|
||||
std::string new_ssh_status = json_body["status"];
|
||||
if (new_ssh_status == "0") {
|
||||
system("rc stop ssh");
|
||||
system("rc del ssh");
|
||||
syslog(LOG_INFO, "SSH is disabled");
|
||||
} else {
|
||||
system("rc start ssh");
|
||||
system("rc add ssh");
|
||||
syslog(LOG_INFO, "SSH is enabled");
|
||||
|
||||
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("rc stop ssh");
|
||||
system("rc del ssh");
|
||||
syslog(LOG_INFO, "SSH is disabled");
|
||||
} else {
|
||||
system("rc start ssh");
|
||||
system("rc add ssh");
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -11,92 +11,94 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
|
||||
std::string new_telnet_enabled = json_body["enabled"];
|
||||
if (new_telnet_enabled == "0") {
|
||||
system("rc stop telnet");
|
||||
system("rc del telnet");
|
||||
syslog(LOG_INFO, "Telnet is disabled");
|
||||
} else {
|
||||
system("rc start telnet");
|
||||
system("rc add telnet");
|
||||
syslog(LOG_INFO, "Telnet is enabled");
|
||||
|
||||
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("rc stop telnet");
|
||||
system("rc del telnet");
|
||||
syslog(LOG_INFO, "Telnet is disabled");
|
||||
} else {
|
||||
system("rc start telnet");
|
||||
system("rc add telnet");
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -11,86 +11,88 @@
|
||||
|
||||
#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);
|
||||
namespace settings {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, 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("rc restart telnet");
|
||||
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);
|
||||
|
||||
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("rc restart telnet");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
void set_telnet(const httplib::Request &request, httplib::Response &response);
|
||||
namespace settings {
|
||||
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);
|
||||
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
|
||||
@@ -11,113 +11,115 @@
|
||||
|
||||
#define WIFI_CHANNEL_REQUIRED_STRING R"({"required":"[token,channel]"})"
|
||||
|
||||
void get_wifi_channel(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);
|
||||
namespace settings {
|
||||
void get_wifi_channel(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;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("channel=") == 0) {
|
||||
wifi_channel = wifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_channel(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["channel"] == nullptr) {
|
||||
response.set_content(WIFI_CHANNEL_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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("channel=") == 0) {
|
||||
old_channel = wifisettingsbuffer;
|
||||
old_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string new_channel = json_body["channel"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/channel=" << old_channel << "/s//channel=" << new_channel << "/\" /etc/hostapd/hostapd.conf";
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI channel changed to " + new_channel;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer)) {
|
||||
if (changedwifisettingsbuffer.find("channel=") == 0) {
|
||||
wifi_channel = changedwifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("channel=") == 0) {
|
||||
wifi_channel = wifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_channel(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["channel"] == nullptr) {
|
||||
response.set_content(WIFI_CHANNEL_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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("channel=") == 0) {
|
||||
old_channel = wifisettingsbuffer;
|
||||
old_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string new_channel = json_body["channel"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/channel=" << old_channel << "/s//channel=" << new_channel << "/\" /etc/hostapd/hostapd.conf";
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI channel changed to " + new_channel;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer)) {
|
||||
if (changedwifisettingsbuffer.find("channel=") == 0) {
|
||||
wifi_channel = changedwifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -11,113 +11,115 @@
|
||||
|
||||
#define WIFI_NAME_REQUIRED_STRING R"({"required":"[token,name]"})"
|
||||
|
||||
void get_wifi_name(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);
|
||||
namespace settings {
|
||||
void get_wifi_name(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;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = wifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_name(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["name"] == nullptr) {
|
||||
response.set_content(WIFI_NAME_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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_wifi_name;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
old_wifi_name = wifisettingsbuffer;
|
||||
old_wifi_name.erase(0, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string new_wifi_name = json_body["name"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/ssid=" << old_wifi_name << "/s//ssid=" << new_wifi_name << "/\" /etc/hostapd/hostapd.conf";
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI name changed to " + new_wifi_name;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer)) {
|
||||
if (changedwifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = changedwifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
break;
|
||||
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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = wifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_name(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["name"] == nullptr) {
|
||||
response.set_content(WIFI_NAME_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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_wifi_name;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
old_wifi_name = wifisettingsbuffer;
|
||||
old_wifi_name.erase(0, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string new_wifi_name = json_body["name"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/ssid=" << old_wifi_name << "/s//ssid=" << new_wifi_name << "/\" /etc/hostapd/hostapd.conf";
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI name changed to " + new_wifi_name;
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer)) {
|
||||
if (changedwifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = changedwifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,110 +11,112 @@
|
||||
|
||||
#define WIFI_PASSWORD_REQUIRED_STRING R"({"required":"[token,password,newpassword]"})"
|
||||
|
||||
void get_wifi_password(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);
|
||||
namespace settings {
|
||||
void get_wifi_password(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;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
wifi_password = wifisettingsbuffer;
|
||||
wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"password":")" << wifi_password << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_password(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;
|
||||
}
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
if (json_body["password"] == nullptr) {
|
||||
response.set_content(WIFI_PASSWORD_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
wifi_password = wifisettingsbuffer;
|
||||
wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"password":")" << wifi_password << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
if (json_body["newpassword"] == nullptr) {
|
||||
response.set_content(WIFI_PASSWORD_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
void set_wifi_password(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;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
if (json_body["password"] == nullptr) {
|
||||
response.set_content(WIFI_PASSWORD_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
if (json_body["newpassword"] == nullptr) {
|
||||
response.set_content(WIFI_PASSWORD_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
old_wifi_password = wifisettingsbuffer;
|
||||
old_wifi_password.erase(0, 15);
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string req_old_password = json_body["password"];
|
||||
if (old_wifi_password != req_old_password) {
|
||||
response.set_content(R"({"status":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
old_wifi_password = wifisettingsbuffer;
|
||||
old_wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::string req_old_password = json_body["password"];
|
||||
if (old_wifi_password != req_old_password) {
|
||||
response.set_content(R"({"status":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::string new_wifi_password = json_body["newpassword"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/wpa_passphrase=" << old_wifi_password << "/s//wpa_passphrase=" << new_wifi_password << "/\" /etc/hostapd/hostapd.conf";
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI password changed";
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"success":"ok"})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
std::string new_wifi_password = json_body["newpassword"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"/wpa_passphrase=" << old_wifi_password << "/s//wpa_passphrase=" << new_wifi_password << "/\" /etc/hostapd/hostapd.conf";
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI password changed";
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"success":"ok"})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -6,55 +6,57 @@
|
||||
#include <QR-Code-generator/qrcodegen.hpp>
|
||||
#include <QR-Code-generator/qrtosvg.hpp>
|
||||
|
||||
void get_wifi_qr(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);
|
||||
namespace settings {
|
||||
void get_wifi_qr(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;
|
||||
}
|
||||
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = wifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
}
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
wifi_password = wifisettingsbuffer;
|
||||
wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
|
||||
std::stringstream toqrstring;
|
||||
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
||||
std::string responsedata = toSvgString(qr0, 4);
|
||||
response.set_content(responsedata, SVG_TYPE);
|
||||
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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = wifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
}
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
wifi_password = wifisettingsbuffer;
|
||||
wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
|
||||
std::stringstream toqrstring;
|
||||
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
||||
|
||||
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
||||
std::string responsedata = toSvgString(qr0, 4);
|
||||
response.set_content(responsedata, SVG_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,93 +6,94 @@
|
||||
#include <syslog.h>
|
||||
|
||||
#define WIFI_REQUIRED_STRING R"({"required":"[token,status]"})"
|
||||
|
||||
void get_wifi_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);
|
||||
namespace settings {
|
||||
void get_wifi_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;
|
||||
}
|
||||
std::ifstream wifistatusfile("/etc/openrouter/wifi/status");
|
||||
int wifi_status;
|
||||
wifistatusfile >> wifi_status;
|
||||
wifistatusfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_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(WIFI_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);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream wififileout("/etc/openrouter/wifi/status");
|
||||
std::string new_wifi_status = json_body["status"];
|
||||
if (new_wifi_status == "0") {
|
||||
system("rc stop hostapd");
|
||||
system("rc del hostapd");
|
||||
syslog(LOG_INFO, "WIFI is disabled");
|
||||
} else {
|
||||
system("rc start hostapd");
|
||||
system("rc add hostapd");
|
||||
syslog(LOG_INFO, "WIFI is enabled");
|
||||
|
||||
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 wifistatusfile("/etc/openrouter/wifi/status");
|
||||
int wifi_status;
|
||||
wifistatusfile >> wifi_status;
|
||||
wifistatusfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_wifi_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(WIFI_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 wififileout("/etc/openrouter/wifi/status");
|
||||
std::string new_wifi_status = json_body["status"];
|
||||
if (new_wifi_status == "0") {
|
||||
system("rc stop hostapd");
|
||||
system("rc del hostapd");
|
||||
syslog(LOG_INFO, "WIFI is disabled");
|
||||
} else {
|
||||
system("rc start hostapd");
|
||||
system("rc add hostapd");
|
||||
syslog(LOG_INFO, "WIFI is enabled");
|
||||
}
|
||||
wififileout << stoi(new_wifi_status);
|
||||
wififileout.close();
|
||||
std::ifstream wififile("/etc/openrouter/wifi/status");
|
||||
int wifi_status;
|
||||
wififile >> wifi_status;
|
||||
wififile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
wififileout << stoi(new_wifi_status);
|
||||
wififileout.close();
|
||||
std::ifstream wififile("/etc/openrouter/wifi/status");
|
||||
int wifi_status;
|
||||
wififile >> wifi_status;
|
||||
wififile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,20 @@
|
||||
|
||||
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||
|
||||
void get_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
namespace settings {
|
||||
void get_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_wifi_name(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_name(const httplib::Request &request, httplib::Response &response);
|
||||
void get_wifi_name(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_name(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_wifi_qr(const httplib::Request &request, httplib::Response &response);
|
||||
void get_wifi_qr(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
||||
void get_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_channel(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
|
||||
#endif // WIFI_HPP
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "syslog.hpp"
|
||||
#include <colors.h>
|
||||
#include "../types.hpp"
|
||||
#include "../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#define SYSLOG_FILE "/var/log/messages"
|
||||
|
||||
void get_syslog(const httplib::Request &request, httplib::Response &response) {
|
||||
std::stringstream responsedata;
|
||||
std::ifstream syslogfile(SYSLOG_FILE);
|
||||
responsedata << syslogfile.rdbuf();
|
||||
syslogfile.close();
|
||||
response.set_content(responsedata.str(), PLAIN_TEXT_TYPE);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef SYSLOG_HPP
|
||||
#define SYSLOG_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_syslog(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif //SYSLOG_HPP
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "reboot.hpp"
|
||||
#include <json.hpp>
|
||||
#include "../routes.hpp"
|
||||
#include <colors.h>
|
||||
#include "../types.hpp"
|
||||
|
||||
namespace systemfuncs {
|
||||
void reboot(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;
|
||||
}
|
||||
system("reboot");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef REBOOT_HPP
|
||||
#define REBOOT_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
namespace systemfuncs {
|
||||
void reboot(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
|
||||
#endif // REBOOT_HPP
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "syslog.hpp"
|
||||
#include <colors.h>
|
||||
#include "../types.hpp"
|
||||
#include "../routes.hpp"
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#define SYSLOG_FILE "/var/log/messages"
|
||||
namespace systemfuncs {
|
||||
void get_syslog(const httplib::Request &request, httplib::Response &response) {
|
||||
std::stringstream responsedata;
|
||||
std::ifstream syslogfile(SYSLOG_FILE);
|
||||
responsedata << syslogfile.rdbuf();
|
||||
syslogfile.close();
|
||||
response.set_content(responsedata.str(), PLAIN_TEXT_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef SYSLOG_HPP
|
||||
#define SYSLOG_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
namespace systemfuncs {
|
||||
void get_syslog(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
|
||||
#endif //SYSLOG_HPP
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef SYSTEM_HPP
|
||||
#define SYSTEM_HPP
|
||||
|
||||
#include "uptime/uptime.hpp"
|
||||
#include "syslog/syslog.hpp"
|
||||
#include "reboot/reboot.hpp"
|
||||
|
||||
#endif // SYSTEM_HPP
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "uptime.hpp"
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sstream>
|
||||
#include "../types.hpp"
|
||||
|
||||
namespace systemfuncs {
|
||||
void get_uptime(const httplib::Request &request, httplib::Response &response) {
|
||||
struct sysinfo x;
|
||||
if (sysinfo(&x) == 0)
|
||||
{
|
||||
// std::cout << static_cast<unsigned long long>(x.uptime)/3600ULL << "h "
|
||||
// << static_cast<unsigned long long>(x.uptime)/60ULL%60ULL << "m "
|
||||
// << static_cast<unsigned long long>(x.uptime)%60ULL << "s "
|
||||
// << std::endl;
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"uptime":{"hour":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)/3600ULL
|
||||
<< R"(","minute":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)/60ULL%60ULL
|
||||
<< R"(","second":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)%60ULL
|
||||
<< R"("}})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
response.set_content(R"({"error":"unknown"})", JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef UPTIME_HPP
|
||||
#define UPTIME_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
namespace systemfuncs {
|
||||
void get_uptime(const httplib::Request &request, httplib::Response &response);
|
||||
}
|
||||
|
||||
#endif // UPTIME_HPP
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "uptime.hpp"
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sstream>
|
||||
#include "../types.hpp"
|
||||
|
||||
void get_uptime(const httplib::Request &request, httplib::Response &response) {
|
||||
struct sysinfo x;
|
||||
if (sysinfo(&x) == 0)
|
||||
{
|
||||
// std::cout << static_cast<unsigned long long>(x.uptime)/3600ULL << "h "
|
||||
// << static_cast<unsigned long long>(x.uptime)/60ULL%60ULL << "m "
|
||||
// << static_cast<unsigned long long>(x.uptime)%60ULL << "s "
|
||||
// << std::endl;
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"uptime":{"hour":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)/3600ULL
|
||||
<< R"(","minute":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)/60ULL%60ULL
|
||||
<< R"(","second":")"
|
||||
<< static_cast<unsigned long long>(x.uptime)%60ULL
|
||||
<< R"("}})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
response.set_content(R"({"error":"unknown"})", JSON_TYPE);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef UPTIME_HPP
|
||||
#define UPTIME_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_uptime(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // UPTIME_HPP
|
||||
Reference in new issue
Block a user