rootfs added and auth service in

This commit is contained in:
wt committed 2024-07-03 14:16:25 +07:00
1 parent 35bd73b894
commit 1bea37deb2
113 files changed
+1369 -24

No files matched your search

-6
View File
@@ -1,6 +0,0 @@
#ifndef HELPERS_HPP
#define HELPERS_HPP
#endif // HELPERS_HPP
-77
View File
@@ -1,77 +0,0 @@
#ifndef C_COLORS_H
#define C_COLORS_H
// reset
#define RESET "\033[0m"
// regular colrs
#define GREEN "\033[0;32m" // GREEN
#define BLUE "\033[0;34m" // BLUE
#define YELLOW "\033[1;33m" // YELLOW
#define RED "\033[0;31m" // RED
#define BLACK "\033[0;30m" // BLACK
#define PURPLE "\033[0;35m" // PURPLE
#define CYAN "\033[0;36m" // CYAN
#define WHITE "\033[0;37m" // WHITE
// bold
#define BBLACK "\033[1;30m" // BLACK
#define BRED "\033[1;31m" // RED
#define BGREEN "\033[1;32m" // GREEN
#define BYELLOW "\033[1;33m" // YELLOW
#define BBLUE "\033[1;34m" // BLUE
#define BPURPLE "\033[1;35m" // PURPLE
#define BCYAN "\033[1;36m" // CYAN
#define BWHITE "\033[1;37m" // WHITE
// Underline
#define UBLACK "\033[4;30m" // BLACK
#define URED "\033[4;31m" // RED
#define UGREEN "\033[4;32m" // GREEN
#define UYELLOW "\033[4;33m" // YELLOW
#define UBLUE "\033[4;34m" // BLUE
#define UPURPLE "\033[4;35m" // PURPLE
#define UCYAN "\033[4;36m" // CYAN
#define UWHITE "\033[4;37m" // WHITE
// Background
#define ON_BLACK "\033[40m" // BLACK
#define ON_RED "\033[41m" // RED
#define ON_GREEN "\033[42m" // GREEN
#define ON_YELLOW "\033[43m" // YELLOW
#define ON_BLUE "\033[44m" // BLUE
#define ON_PURPLE "\033[45m" // PURPLE
#define ON_CYAN "\033[46m" // CYAN
#define ON_WHITE "\033[47m" // WHITE
// High Intensity
#define IBLACK "\033[0;90m" // BLACK
#define IRED "\033[0;91m" // RED
#define IGREEN "\033[0;92m" // GREEN
#define IYELLOW "\033[0;93m" // YELLOW
#define IBLUE "\033[0;94m" // BLUE
#define IPURPLE "\033[0;95m" // PURPLE
#define ICYAN "\033[0;96m" // CYAN
#define IWHITE "\033[0;97m" // WHITE
// Bold High Intensity
#define BIBLACK "\033[1;90m" // BLACK
#define BIRED "\033[1;91m" // RED
#define BIGREEN "\033[1;92m" // GREEN
#define BIYELLOW "\033[1;93m" // YELLOW
#define BIBLUE "\033[1;94m" // BLUE
#define BIPURPLE "\033[1;95m" // PURPLE
#define BICYAN "\033[1;96m" // CYAN
#define BIWHITE "\033[1;97m" // WHITE
// High Intensity backgrounds
#define ON_IBLACK "\033[0;100m" // BLACK
#define ON_IRED "\033[0;101m" // RED
#define ON_IGREEN "\033[0;102m" // GREEN
#define ON_IYELLOW "\033[0;103m" // YELLOW
#define ON_IBLUE "\033[0;104m" // BLUE
#define ON_IPURPLE "\033[0;105m" // PURPLE
#define ON_ICYAN "\033[0;106m" // CYAN
#define ON_IWHITE "\033[0;107m" // WHITE
#endif // C_COLORS_H
-9788
View File
File diff suppressed because it is too large. Load diff
-24766
View File
File diff suppressed because it is too large. Load diff
-56
View File
@@ -1,56 +0,0 @@
#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 "reboot/reboot.hpp"
#include "syslog/syslog.hpp"
#include <syslog.h>
#define CORS_ENABLE
#include "security/cors.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/reboot", reboot);
srv.Get("/api/syslog", get_syslog);
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("0.0.0.0", 80);
return 0;
}
-35
View File
@@ -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");
}
}
-8
View File
@@ -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
-6
View File
@@ -1,6 +0,0 @@
#ifndef ROUTES_HPP
#define ROUTES_HPP
#define AUTH_SERVICE "http://localhost:43243"
#endif // ROUTES_HPP
-9
View File
@@ -1,9 +0,0 @@
#include "cors.hpp"
#include <colors.h>
void set_cors_headers(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << " " << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
response.set_header("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
response.set_header("Access-Control-Allow-Headers", "Authorization,X-Custom,Content-Type");
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef CORS_HPP
#define CORS_HPP
#include <httplib.h>
#ifdef CORS_ENABLE
// function to set cors headers
void set_cors_headers(const httplib::Request& request, httplib::Response& response);
#endif // CORS_ENABLE
#endif // CORS_HPP
-15
View File
@@ -1,15 +0,0 @@
#ifndef DNS_HPP
#define DNS_HPP
#include <httplib.h>
void get_dns(const httplib::Request &request, httplib::Response &response);
void set_dns(const httplib::Request &request, httplib::Response &response);
void get_dns_servers(const httplib::Request &request, httplib::Response &response);
void set_dns_servers(const httplib::Request &request, httplib::Response &response);
void get_local_domains(const httplib::Request &request, httplib::Response &response);
void set_local_domains(const httplib::Request &request, httplib::Response &response);
#endif // DNS_HPP
-98
View File
@@ -1,98 +0,0 @@
#include "dns.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
#define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
void get_dns(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream dnsfile("/etc/openrouter/dns");
int dns_enabled;
dnsfile >> dns_enabled;
dnsfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_dns(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["enabled"] == nullptr) {
response.set_content(DNS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream dnsfileout("/etc/openrouter/dns");
std::string new_dns_enabled = json_body["enabled"];
if (new_dns_enabled == "0") {
system("/etc/init.d/dnsmasq stop");
system("rm /etc/rc.d/60dnsmasq");
syslog(LOG_INFO, "DNS is disabled");
} else {
system("/etc/init.d/dnsmasq restart");
system("ln -sv /etc/init.d/dnsmasq /etc/rc.d/60dnsmasq");
syslog(LOG_INFO, "DNS is enabled");
}
dnsfileout << stoi(new_dns_enabled);
dnsfileout.close();
std::ifstream dnsfile("/etc/openrouter/dns");
int dns_enabled;
dnsfile >> dns_enabled;
dnsfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-100
View File
@@ -1,100 +0,0 @@
#include "dns.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
void get_local_domains(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream domainsfile("/etc/dnsmasq.conf.d/hosts");
std::stringstream responsedata;
responsedata << R"({"domains":[)";
std::string ip_string = "";
std::string domain_string = "";
int iter = 0;
while (!domainsfile.eof()) {
domainsfile >> ip_string;
domainsfile >> domain_string;
if (domain_string == "") {
continue;
}
responsedata << R"({"ip":")" << ip_string << R"(","domain":")" << domain_string << R"("},)";
ip_string = "";
domain_string = "";
iter++;
}
if (iter != 0) {
responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}");
} else {
responsedata << "]}";
}
domainsfile.close();
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_local_domains(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream domainsfile("/etc/dnsmasq.conf.d/hosts");
nlohmann::json domains = json_body["domains"];
for (nlohmann::json_abi_v3_11_3::json domain : domains) {
std::string ip = domain["ip"];
std::string dom = domain["domain"];
domainsfile << ip << " " << dom << "\n";
}
domainsfile.close();
system("/etc/init.d/dnsmasq restart");
syslog(LOG_INFO, "DNS local domains changed");
std::string responsedata = R"({"success":"true"})";
response.set_content(responsedata, JSON_TYPE);
}
}
-98
View File
@@ -1,98 +0,0 @@
#include "dns.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
// #define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
void get_dns_servers(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
std::stringstream responsedata;
responsedata << R"({"servers":[)";
std::string dns_server_string = "";
int iter = 0;
while (std::getline(dnsserversfile, dns_server_string)) {
dns_server_string.erase(0, 11);
responsedata << "\"" << dns_server_string << R"(",)";
dns_server_string = "";
iter++;
}
if (iter != 0) {
responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}");
} else {
responsedata << "]}";
}
dnsserversfile.close();
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_dns_servers(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
nlohmann::json servers = json_body["servers"];
for (nlohmann::json_abi_v3_11_3::json server : servers) {
std::string srv = server;
if (server == "") {
continue;
}
dnsserversfile << "nameserver " << srv << "\n";
}
dnsserversfile.close();
system("/etc/init.d/dnsmasq restart");
syslog(LOG_INFO, "DNS servers changed");
std::string responsedata = R"({"success":"true"})";
response.set_content(responsedata, JSON_TYPE);
}
}
-98
View File
@@ -1,98 +0,0 @@
#include "ftp.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
void get_ftp(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream ftpfile("/etc/openrouter/ftp");
int ftp_enabled;
ftpfile >> ftp_enabled;
ftpfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_ftp(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["enabled"] == nullptr) {
response.set_content(FTP_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream ftpfileout("/etc/openrouter/ftp");
std::string new_ftp_enabled = json_body["enabled"];
if (new_ftp_enabled == "0") {
system("/etc/init.d/ftp stop");
system("rm /etc/rc.d/90ftp");
syslog(LOG_INFO, "Ftp is disabled");
} else {
system("/etc/init.d/ftp start");
system("ln -sv /etc/init.d/ftp /etc/rc.d/90ftp");
syslog(LOG_INFO, "Ftp is enabled");
}
ftpfileout << stoi(new_ftp_enabled);
ftpfileout.close();
std::ifstream ftpfile("/etc/openrouter/ftp");
int ftp_enabled;
ftpfile >> ftp_enabled;
ftpfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-9
View File
@@ -1,9 +0,0 @@
#ifndef FTP_HPP
#define FTP_HPP
#include <httplib.h>
void get_ftp(const httplib::Request &request, httplib::Response &response);
void set_ftp(const httplib::Request &request, httplib::Response &response);
#endif // FTP_HPP
-95
View File
@@ -1,95 +0,0 @@
#include "ssh.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
#define KEYS_PATH "/root/.ssh/authorized_keys"
void get_ssh_keys(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream keysfile(KEYS_PATH);
std::stringstream responsedata;
responsedata << R"({"keys":[)";
std::string key_string = "";
int iter = 0;
while (std::getline(keysfile, key_string)) {
if (key_string == "") {
continue;
}
responsedata << R"(")" << key_string << R"(",)";
key_string = "";
iter++;
}
if (iter != 0) {
responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}");
} else {
responsedata << "]}";
}
keysfile.close();
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_ssh_keys(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream keysfile(KEYS_PATH);
nlohmann::json keys = json_body["keys"];
for (std::string key : keys) {
keysfile << key << "\n";
}
keysfile.close();
system("/etc/init.d/ssh restart");
syslog(LOG_INFO, "SSH keys changed");
std::string responsedata = R"({"success":"true"})";
response.set_content(responsedata, JSON_TYPE);
}
}
-104
View File
@@ -1,104 +0,0 @@
#include "ssh.hpp"
#include <colors.h>
#include "../../types.hpp"
#include "../../routes.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <syslog.h>
#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
#define SSH_PORT_PATH "/etc/openrouter/ssh/port"
void get_ssh_port(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream sshportfile(SSH_PORT_PATH);
int ssh_port;
sshportfile >> ssh_port;
sshportfile.close();
std::stringstream responsedata;
responsedata << R"({"port":")" << ssh_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_ssh_port(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["port"] == nullptr) {
response.set_content(SSH_PORT_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream oldsshportfile(SSH_PORT_PATH);
int old_ssh_port;
oldsshportfile >> old_ssh_port;
oldsshportfile.close();
std::ofstream sshportfileout(SSH_PORT_PATH);
std::string new_ssh_port = json_body["port"];
sshportfileout << stoi(new_ssh_port);
sshportfileout.close();
std::stringstream systemrequest;
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
std::cout << systemrequest.str() << std::endl;
system(systemrequest.str().c_str());
system("/etc/init.d/ssh restart");
std::string syslogstring = "SSH port changed to " + new_ssh_port;
syslog(LOG_INFO, syslogstring.c_str());
std::ifstream sshportfile(SSH_PORT_PATH);
int ssh_port;
sshportfile >> ssh_port;
sshportfile.close();
std::stringstream responsedata;
responsedata << R"({"port":")" << ssh_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-15
View File
@@ -1,15 +0,0 @@
#ifndef SSH_HPP
#define SSH_HPP
#include <httplib.h>
void get_ssh_status(const httplib::Request &request, httplib::Response &response);
void set_ssh_status(const httplib::Request &request, httplib::Response &response);
void get_ssh_keys(const httplib::Request &request, httplib::Response &response);
void set_ssh_keys(const httplib::Request &request, httplib::Response &response);
void get_ssh_port(const httplib::Request &request, httplib::Response &response);
void set_ssh_port(const httplib::Request &request, httplib::Response &response);
#endif // SSH_HPP
-97
View File
@@ -1,97 +0,0 @@
#include "ssh.hpp"
#include <colors.h>
#include <json.hpp>
#include "../../routes.hpp"
#include "../../types.hpp"
#include <syslog.h>
#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})"
void get_ssh_status(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream sshstatusfile("/etc/openrouter/ssh/status");
int ssh_status;
sshstatusfile >> ssh_status;
sshstatusfile.close();
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_ssh_status(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["status"] == nullptr) {
response.set_content(SSH_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream sshfileout("/etc/openrouter/ssh/status");
std::string new_ssh_status = json_body["status"];
if (new_ssh_status == "0") {
system("/etc/init.d/ssh stop");
system("rm /etc/rc.d/75ssh");
syslog(LOG_INFO, "SSH is disabled");
} else {
system("/etc/init.d/ssh start");
system("ln -sv /etc/init.d/ssh /etc/rc.d/75ssh");
syslog(LOG_INFO, "SSH is enabled");
}
sshfileout << stoi(new_ssh_status);
sshfileout.close();
std::ifstream sshfile("/etc/openrouter/ssh/status");
int ssh_status;
sshfile >> ssh_status;
sshfile.close();
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-102
View File
@@ -1,102 +0,0 @@
#include "telnet.hpp"
#include <colors.h>
#include "../../types.hpp"
#include "../../routes.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <syslog.h>
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
void get_telnet(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
int telnet_enabled;
telnetfile >> telnet_enabled;
telnetfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_telnet(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["enabled"] == nullptr) {
response.set_content(TELNET_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream telnetfileout("/etc/openrouter/telnet/enabled");
std::string new_telnet_enabled = json_body["enabled"];
if (new_telnet_enabled == "0") {
system("/etc/init.d/telnet stop");
system("rm /etc/rc.d/70telnet");
syslog(LOG_INFO, "Telnet is disabled");
} else {
system("/etc/init.d/telnet start");
system("ln -sv /etc/init.d/telnet /etc/rc.d/70telnet");
syslog(LOG_INFO, "Telnet is enabled");
}
telnetfileout << stoi(new_telnet_enabled);
telnetfileout.close();
std::ifstream telnetfile("/etc/openrouter/telnet/enabled");
int telnet_enabled;
telnetfile >> telnet_enabled;
telnetfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-96
View File
@@ -1,96 +0,0 @@
#include "telnet.hpp"
#include <colors.h>
#include "../../types.hpp"
#include "../../routes.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <syslog.h>
#define TELNET_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
void get_telnet_port(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream telnetportfile("/etc/openrouter/telnet/port");
int telnet_port;
telnetportfile >> telnet_port;
telnetportfile.close();
std::stringstream responsedata;
responsedata << R"({"port":")" << telnet_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_telnet_port(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["port"] == nullptr) {
response.set_content(TELNET_PORT_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream telnetportfileout("/etc/openrouter/telnet/port");
std::string new_telnet_port = json_body["port"];
telnetportfileout << stoi(new_telnet_port);
telnetportfileout.close();
system("/etc/init.d/telnet restart");
std::string syslogstring = "Telnet port changed to " + new_telnet_port;
syslog(LOG_INFO, syslogstring.c_str());
std::ifstream telnetportfile("/etc/openrouter/telnet/port");
int telnet_port;
telnetportfile >> telnet_port;
telnetportfile.close();
std::stringstream responsedata;
responsedata << R"({"port":")" << telnet_port << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
-12
View File
@@ -1,12 +0,0 @@
#ifndef SETTINGS_TELNET_HPP
#define SETTINGS_TELNET_HPP
#include <httplib.h>
void get_telnet(const httplib::Request &request, httplib::Response &response);
void set_telnet(const httplib::Request &request, httplib::Response &response);
void get_telnet_port(const httplib::Request &request, httplib::Response &response);
void set_telnet_port(const httplib::Request &request, httplib::Response &response);
#endif // SETTINGS_TELNET_HPP
-19
View File
@@ -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);
}
-8
View File
@@ -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
-11
View File
@@ -1,11 +0,0 @@
#ifndef TYPES_H
#define TYPES_H
#define ACCESS_REQUIRED_STRING R"({"required":"[token]"})"
#define JWT_SECRET_KEY "secret"
#define STRING403 R"({"status":"403"})"
#define JSON_TYPE "application/json"
#define PLAIN_TEXT_TYPE "text/plain"
#endif // TYPES_H
-19
View File
@@ -1,19 +0,0 @@
button {
padding: 10px;
border-radius: 10px;
border: none;
transition: 0.3s;
cursor: pointer;
}
button:hover {
opacity: 0.6;
}
.linkbutton {
background: transparent;
}
.linkbutton:hover {
text-decoration: underline;
}
-125
View File
@@ -1,125 +0,0 @@
.form {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
padding: 10px;
transform: scale(0.5);
opacity: 0;
transition: 0.3s;
position: absolute;
margin: auto;
}
.form.active {
pointer-events: all;
opacity: 1;
transform: scale(1);
}
.form.active>.formbody {
transform: scale(1);
}
.formbody {
width: 50%;
height: 50%;
display: flex;
flex-direction: column;
gap: 10px;
align-items: center;
justify-content: center;
background-color: gray;
/* opacity: 0.7; */
border-radius: 20px;
padding: 10px;
}
.formheader {
width: 100%;
text-align: center;
}
.forminputbody {
width: 50%;
display: flex;
flex-direction: column;
}
.forminputbody.confirmform {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
.forminputbody.confirmform>button {
width: 100%;
}
.forminputlabel {
text-align: center;
font-style: normal;
font-size: 20px;
margin: 5px 0;
}
.forminput {
padding: 10px;
border-radius: 10px;
border: 2px solid;
transition: 0.2s;
background-color: inherit;
}
.forminput:focus {
border: 5px solid;
}
.formbutton {
padding: 10px;
border-radius: 10px;
border: none;
cursor: pointer;
transition: 0.3s;
}
.formbutton:hover {
opacity: 0.6;
}
@media screen and (max-width: 800px) {
.forminputbody {
width: 100%;
}
}
@media screen and (max-width: 800px) {
.formbody {
height: 60%;
}
}
@media screen and (max-width: 500px) {
.formbody {
width: 100%;
}
}
@media screen and (max-width: 300px) {
.formbody {
height: 60%;
width: 100%;
}
}
@media screen and (max-width: 500px) {
.formheader {
font-size: 20px;
}
}
-70
View File
@@ -1,70 +0,0 @@
header {
width: 100vw;
height: 50px;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.links {
display: flex;
align-items: center;
gap: 10px;
}
#headermenubutton {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
overflow: hidden;
padding: 0;
margin: 0;
transition: 0.3s;
}
.userbuttons {
display: flex;
align-items: center;
gap: 10px;
}
@media screen and (max-width: 400px) {
header>h1 {
font-size: 15px;
}
.userbuttons>h1 {
font-size: 15px;
}
}
@media screen and (max-width: 600px) {
.links {
position: absolute;
top: 10px;
left: 10;
height: 0;
overflow: hidden;
flex-direction: column;
transition: 0.3s;
}
.links.active {
height: max-content;
background-color: gray;
z-index: 10;
border-radius: 10px;
}
#headermenubutton {
position: relative;
width: fit-content;
height: fit-content;
overflow: hidden;
padding: 10px;
/* margin: 0; */
}
}
-32
View File
@@ -1,32 +0,0 @@
:root {
color-scheme: light dark;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
}
.adminpanel {
position: relative;
width: 100%;
height: 100%;
transform: scale(0.5);
opacity: 0;
transition: 0.3s;
}
.adminpanel.active {
transform: scale(1);
opacity: 1;
}
.section {
position: relative;
}
-64
View File
@@ -1,64 +0,0 @@
.loader {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 0;
pointer-events: none;
display: grid;
z-index: 12;
backdrop-filter: blur(5px);
transition: 0.3s;
}
.loader>h1 {
opacity: 0;
width: 100%;
padding: 10px;
text-align: center;
}
.loadertip {
width: 0;
height: 0;
padding: 0;
margin: 0;
border-radius: 50%;
place-self: center;
z-index: 12;
position: relative;
transition: 0.3s;
}
.progress {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-top: 5px solid #56C1F9;
border-radius: 50%;
animation: loading 2s infinite ease-in-out;
}
.loader.active {
width: 100vw;
height: 100vh;
}
.loader.active > .loadertip {
width: 100px;
height: 100px;
border-bottom: 5px solid gray;
animation: loading 2s infinite ease-in-out;
}
.loader.active>h1 {
opacity: 1;
}
@keyframes loading {
100% {
transform: rotate(360deg);
}
}
-53
View File
@@ -1,53 +0,0 @@
.notificationsection {
width: max-content;
height: 100vh;
position: fixed;
top: 0;
right: 0;
pointer-events: none;
z-index: 1;
}
.notification {
width: max-content;
height: 0;
overflow: hidden;
pointer-events: none;
z-index: 10;
border-radius: 10px;
/* position: fixed; */
top: 0;
right: 0;
transition: 0.3s;
cursor: pointer;
opacity: 0.8;
margin: 10px;
padding: 0 10px;
}
.notificationtextbox {
width: 100%;
height: 100%;
display: grid;
justify-items: center;
align-items: center;
pointer-events: none;
}
.notificationtext {
width: 100%;
text-align: center;
pointer-events: none;
}
.notification.active.error {
pointer-events: all;
height: 10%;
background-color: rgb(233, 70, 70);
}
.notification.active.success {
pointer-events: all;
height: 10%;
background-color: rgb(76, 209, 76);
}
-223
View File
@@ -1,223 +0,0 @@
.checkbox-wrapper-2 .ikxBAC {
appearance: none;
background-color: #dfe1e4;
border-radius: 72px;
border-style: none;
flex-shrink: 0;
height: 20px;
margin: 0;
position: relative;
width: 30px;
transition: 0.3s;
}
.checkbox-wrapper-2 .ikxBAC::before {
bottom: -6px;
content: "";
left: -6px;
position: absolute;
right: -6px;
top: -6px;
transition: 0.3s;
cursor: pointer;
}
.checkbox-wrapper-2 .ikxBAC,
.checkbox-wrapper-2 .ikxBAC::after {
transition: 300ms;
}
.checkbox-wrapper-2 .ikxBAC::after {
background-color: #fff;
border-radius: 50%;
content: "";
height: 14px;
left: 3px;
position: absolute;
top: 3px;
width: 14px;
cursor: pointer;
}
.checkbox-wrapper-2 input[type=checkbox] {
cursor: default;
}
.checkbox-wrapper-2 .ikxBAC:hover {
background-color: #c9cbcd;
transition-duration: 0s;
}
.checkbox-wrapper-2 .ikxBAC:checked {
background-color: green;
}
.checkbox-wrapper-2 .ikxBAC:checked::after {
background-color: #fff;
left: 13px;
}
.checkbox-wrapper-2 :focus:not(.focus-visible) {
outline: 0;
}
.checkbox-wrapper-2 .ikxBAC:checked:hover {
background-color: hsl(from green h s 20%);
}
.settingssection {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 10px;
display: flex;
/* flex-direction: column; */
gap: 10px;
transition: 0.3s;
opacity: 0;
pointer-events: none;
}
.settingssection.active {
opacity: 1;
pointer-events: all;
}
.settingrect {
width: 25%;
height: max-content;
background-color: gray;
padding: 20px;
border-radius: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
}
.settingrectheader {
width: 100%;
display: flex;
justify-content: space-between;
}
.settingrectbody {
width: 100%;
max-height: 0;
overflow: auto;
transition: 0.3s;
}
.settingrectbody.active {
max-height: 500px;
overflow-y: auto;
}
.settingrectbody>table {
position: relative;
width: 100%;
text-align: left;
transition: 0.3s;
}
.settingrectfooter {
width: 100%;
display: flex;
align-items: center;
gap: 10px;
}
.settingrectfooter.onebutton {
gap: 0;
}
.settingrectfooterbutton {
width: 100%;
}
.hiddenbutton {
width: 0;
overflow: hidden;
padding: 0;
margin: 0;
}
.hiddenbutton.active {
position: relative;
width: 100%;
padding: 10px;
}
table {
position: relative;
width: 100%;
border: 2px solid ;
border-radius: 10px;
margin: 10px 0;
}
thead>tr>th {
border-bottom: 2px solid;
padding: 10px;
width: 50%;
}
.one {
border: 2px solid;
padding: 10px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.three {
width: 33%;
}
/* tbody>tr>th.one {
border: 2px solid;
padding: 10px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: space-between;
} */
tbody>tr>th {
border: 2px solid;
padding: 10px;
border-radius: 10px;
width: 50%;
max-width:425px;
overflow-x: auto;
/* display: flex;
align-items: center;
justify-content: space-between; */
}
@media screen and (max-width: 1200px) {
.settingrect {
width: 50%;
}
.settingssection {
flex-direction: column;
align-items: center;
}
}
@media screen and (max-width: 600px) {
.settingrect {
width: 75%;
}
}
@media screen and (max-width: 400px) {
.settingrect {
width: 100%;
}
}
-32
View File
@@ -1,32 +0,0 @@
.syslogsection {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
pointer-events: none;
transition: 0.3s;
padding: 10px;
}
.syslogsection.active {
opacity: 1;
pointer-events: all;
}
.syslogheader {
display: flex;
align-items: center;
gap: 10px;
}
.syslogdata {
width: 100%;
max-height: 85vh;
padding: 10px;
border-radius: 10px;
/* background-color: rgb(175, 175, 175); */
margin: 10px 0;
overflow-y: auto;
}
-254
View File
@@ -1,254 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/form.css">
<link rel="stylesheet" href="css/settings.css">
<link rel="stylesheet" href="css/notification.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/button.css">
<link rel="stylesheet" href="css/loader.css">
<link rel="stylesheet" href="css/syslog.css">
<title>Openrouter Admin</title>
</head>
<body>
<section class="adminpanel">
<!-- header -->
<header class="header">
<button id="headermenubutton">&#9636;</button>
<div class="links">
<button class="linkbutton" id="syslogbutton">Syslog</button>
<button class="linkbutton" id="settingsbutton">Settings</button>
<button class="linkbutton" id="rebootbutton">Reboot</button>
</div>
<h1>Openrouter Admin</h1>
<div class="userbuttons">
<h1 class="headerusername"></h1>
<button class="exitbutton">Exit</button>
</div>
</header>
<!-- header -->
<!-- settings block -->
<div class="section">
<section class="settingssection">
<!-- telnet settings -->
<div class="settingrect">
<div class="settingrectheader">
<h2>Telnet</h2>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="telnetenable">
</div>
</div>
<div class="settingrectbody telnetsettingbody">
<div style="display:flex;align-items:center;justify-content:space-between;">
<label for="telnetportinput" class="forminputlabel">Port</label>
<input type="text" id="telnetportinput" class="forminput">
</div>
<table class="telnetuserstable">
<thead>
<tr>
<th>username</th>
<th>password</th>
</tr>
</thead>
<tbody>
<tr><th>No users</th></tr>
<!-- <tr>
<th>root</th>
<th>2808</th>
</tr> -->
</tbody>
</table>
</div>
<div class="settingrectfooter">
<button class="settingrectfooterbutton hiddenbutton" id="add_telnet_user_button">Add telnet user</button>
<button class="settingrectfooterbutton" id="set_telnet_settings">Confirm</button>
</div>
</div>
<!-- telnet settings -->
<!-- DNS settings -->
<div class="settingrect">
<div class="settingrectheader">
<h2>DNS</h2>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="dnsenable">
</div>
</div>
<div class="settingrectbody" id="dnssettingsbody">
<table class="dnsservers">
<thead>
<tr><th>DNS servers</th></tr>
</thead>
<tbody id="dnsserverstablebody">
</tbody>
</table>
<h3>Domains Table</h3>
<table class="domains">
<thead>
<tr>
<th class="three">IP</th>
<th class="three">Domain</th>
<!-- <th class="three">Del</th> -->
</tr>
</thead>
<tbody id="domainsstablebody">
</tbody>
</table>
</div>
<div class="settingrectfooter">
<button id="add_local_domain_button" class="hiddenbutton settingrectfooterbutton">Add Local Domain</button>
<button id="add_dns_server_button" class="hiddenbutton settingrectfooterbutton">Add DNS server</button>
<button class="settingrectfooterbutton" id="set_dns_settings">Confirm</button>
</div>
</div>
<!-- DNS settings -->
<!-- ftp settings -->
<div class="settingrect">
<div class="settingrectheader">
<h2>Ftp</h2>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="ftpenable">
</div>
</div>
<div class="settingrectfooter">
<!-- <button>Add Ftp server</button> -->
<button class="settingrectfooterbutton" id="set_ftp_settings">Confirm</button>
</div>
</div>
<!-- ftp settings -->
<!-- ssh settings -->
<div class="settingrect">
<div class="settingrectheader">
<h2>SSH</h2>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="sshenable">
</div>
</div>
<div class="settingrectbody" id="sshsettingsbody">
<div style="display:flex;align-items:center;justify-content:space-between;">
<label for="sshportinput" class="forminputlabel">Port</label>
<input type="text" id="sshportinput" class="forminput">
</div>
<table class="sshkeys">
<thead>
<tr><th>SSH keys</th></tr>
</thead>
<tbody id="sshkeystablebody">
</tbody>
</table>
</div>
<div class="settingrectfooter onebutton">
<button id="add_ssh_key" class="hiddenbutton settingrectfooterbutton">Add SSH key</button>
<button class="settingrectfooterbutton" id="set_ssh_settings">Confirm</button>
</div>
</div>
<!-- ssh settings -->
</section>
<!-- syslog block -->
<section class="syslogsection">
<div class="syslogheader">
<h2 class="syslogheader">Syslog</h2>
<button id="openrouterfilter">openrouter</button>
<button id="authservicefilter">auth_service</button>
<button id="refreshbutton">&#8634;</button>
</div>
<div class="syslogdata"></div>
</section>
<!-- syslog block -->
</div>
<!-- settings block -->
</section>
<!-- notification block -->
<div class="notificationsection"></div>
<!-- notification block -->
<!-- login form -->
<div class="form loginform">
<form class="formbody loginformbody">
<h1 class="formheader">OpenRouter Login</h1>
<div class="forminputbody">
<label for="loginusernameinput" class="forminputlabel">Username</label>
<input type="text" required id="loginusernameinput" class="forminput">
</div>
<div class="forminputbody">
<label for="loginpasswordinput" class="forminputlabel">Username</label>
<input type="password" required id="loginpasswordinput" class="forminput">
</div>
<div class="forminputbody">
<button class="formbutton">Login</button>
</div>
</form>
</div>
<!-- login form -->
<!-- confirm form -->
<div class="form" id="confirmform">
<div class="formbody confirmformbody">
<h1 class="formheader" id="confirmformheader">Confirm DNS settings?</h1>
<div class="forminputbody confirmform" id="confirmformbuttons">
<button class="formbutton" id="cancel">Cancel</button>
<button class="formbutton" id="confirm">Confirm</button>
</div>
</div>
</div>
<!-- confirm form -->
<!-- add DNS server form -->
<div class="form" id="adddnsserverform">
<div class="formbody adddnsserverformbody">
<h1 class="formheader" id="adddnsserverform">Add DNS server</h1>
<div class="forminputbody adddnsserverform">
<label for="adddnsserverinput" class="forminputlabel">Server IP</label>
<input required type="text" class="forminput" id="adddnsserverinput">
</div>
<div class="forminputbody confirmform">
<button class="formbutton" id="adddnsservercancel">Cancel</button>
<button class="formbutton" id="adddnsserverconfirm">Add</button>
</div>
</div>
</div>
<!-- add DNS server form -->
<!-- add local domain form -->
<div class="form" id="addlocaldomainform">
<div class="formbody addlocaldomainformbody">
<h1 class="formheader" id="addlocaldomainform">Add Local Domain</h1>
<div class="forminputbody addlocaldomainform">
<label for="ipinput" class="forminputlabel">IP</label>
<input required type="text" class="forminput" id="ipinput">
</div>
<div class="forminputbody addlocaldomainform">
<label for="domaininput" class="forminputlabel">Domain</label>
<input required type="text" class="forminput" id="domaininput">
</div>
<div class="forminputbody confirmform">
<button class="formbutton" id="addlocaldomaincancel">Cancel</button>
<button class="formbutton" id="addlocaldomainconfirm">Add</button>
</div>
</div>
</div>
<!-- add local domain form -->
<!-- loader -->
<div class="loader">
<h1 id="loaderheader">Reboting</h1>
<div class="loadertip">
<div class="progress"></div>
</div>
</div>
<!-- loader -->
<script src="js/header.js"></script>
<script src="js/routes.js"></script>
<script src="js/notification.js"></script>
<script src="js/loader.js"></script>
<script src="js/settings/confirm.js"></script>
<script src="js/settings/telnet.js"></script>
<script src="js/settings/dns.js"></script>
<script src="js/settings/ftp.js"></script>
<script src="js/settings/ssh.js"></script>
<script src="js/settings/settings.js"></script>
<script src="js/reboot.js"></script>
<script src="js/syslog.js"></script>
<script src="js/login.js"></script>
</body>
</html>
-39
View File
@@ -1,39 +0,0 @@
const settingssection = document.querySelector('.settingssection')
const settingsbutton = document.querySelector('#settingsbutton')
const syslogsection = document.querySelector('.syslogsection')
const syslogbutton = document.querySelector('#syslogbutton')
const headermenubutton = document.querySelector('#headermenubutton')
const headerlinks = document.querySelector('.links')
// const header = document.querySelector('.header')
settingsbutton.addEventListener('click', () => {
settingssection.classList.add('active')
syslogsection.classList.remove('active')
})
syslogbutton.addEventListener('click', () => {
syslogsection.classList.add('active')
settingssection.classList.remove('active')
get_syslog_data()
})
headermenubutton.addEventListener('click', () => {
if (headerlinks.classList.contains('active')){
headerlinks.classList.remove('active')
return
}
headerlinks.classList.add('active')
})
window.addEventListener('click', (e) => {
if (e.target.id !== "headermenubutton" && !e.target.classList.contains('links')) {
headerlinks.classList.remove('active')
}
})
// if (window.screenX > 600) {
// header.removeChild(headermenubutton)
// } else {
// header.prepend(headermenubutton)
// }
-13
View File
@@ -1,13 +0,0 @@
const loader = document.querySelector('.loader')
const loaderheader = document.querySelector('#loaderheader')
const defaultloaderheader = ""
const start_loader = (header = defaultloaderheader) => {
loaderheader.innerHTML = header
loader.classList.add('active')
}
const stop_loader = () => {
loader.classList.remove('active')
}
-68
View File
@@ -1,68 +0,0 @@
const loginform = document.querySelector('.loginform')
const loginformbody = document.querySelector('.loginformbody')
const loginusername = document.querySelector("#loginusernameinput")
const loginpassword = document.querySelector("#loginpasswordinput")
const exitbutton = document.querySelector('.exitbutton')
const adminpanelsection = document.querySelector('.adminpanel')
const headerusername = document.querySelector('.headerusername')
if (localStorage.getItem("token") === null) {
adminpanelsection.classList.remove('active')
loginform.classList.add('active')
} else {
get_all_settings()
adminpanelsection.classList.add('active')
settingssection.classList.add('active')
headerusername.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
}
loginformbody.addEventListener('submit', (e) => {
e.preventDefault()
login(loginusername.value, loginpassword.value)
})
const login = async (username, password) => {
const response = await fetch(routes.login(), {
method: 'POST',
body: `{"username":"${username}","password":"${password}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
if (error.message === "Unexpected end of JSON input") {
notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error")
} else {
notification(`Ошибка на сервере: ${error}`, "error")
}
})
if (response.status === "403") {
notification("Неправильный логин или пароль", "error")
}
if (response.token) {
notification("Успешно", "success")
loginform.classList.remove("active")
localStorage.setItem("token", response.token)
get_all_settings()
adminpanelsection.classList.add('active')
await get_user_data()
loginusername.value = ""
loginpassword.value = ""
}
}
const get_user_data = async () => {
const response = await fetch(routes.user(), {
method: "POST",
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
if (response.id) {
headerusername.innerHTML = response.username
localStorage.setItem("userdata", JSON.stringify(response))
}
}
exitbutton.addEventListener('click', () => {
localStorage.clear()
loginform.classList.add('active')
notification('Вы вышли', "success")
adminpanelsection.classList.remove('active')
})
-40
View File
@@ -1,40 +0,0 @@
const notificationsection = document.querySelector('.notificationsection')
// const notificationtext = document.querySelector('.notificationtext')
const notification = (text, type) => {
const notificationbox = document.createElement('div')
const notificationtextbox = document.createElement('div')
const notificationtext = document.createElement('h3')
notificationtext.classList.add('notificationtext')
notificationtextbox.append(notificationtext)
notificationtextbox.classList.add('notificationtextbox')
notificationbox.append(notificationtextbox)
notificationbox.classList.add('notification')
notificationbox.addEventListener('click', () => {
notificationbox.classList.remove('active')
})
notificationsection.append(notificationbox)
if (type === "error") {
notificationbox.classList.remove('success')
notificationbox.classList.add('error')
} else {
notificationbox.classList.remove('error')
notificationbox.classList.add('success')
}
notificationtext.innerHTML = text
setTimeout(() => {
notificationbox.classList.add('active')
}, 300)
setTimeout(() => {
notificationbox.classList.remove('active')
setTimeout(() => {
notificationsection.removeChild(notificationbox)
}, 200)
}, 3000)
}
// const closenotification = () => {
// notificationbox.classList.remove('active')
// }
// notificationbox.addEventListener('click', closenotification)
-31
View File
@@ -1,31 +0,0 @@
const rebootbutton = document.querySelector('#rebootbutton')
rebootbutton.addEventListener('click', () => {
if (confirm("Confirm reboot?")) {
reboot()
}
})
const reboot = () => {
loader.classList.add('active')
fetch(routes.reboot(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
}).catch((error) => {
start_loader("Rebooting")
setTimeout(waitreboot, 2000)
})
}
const waitreboot = () => {
fetch(routes.telnet_status(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
stop_loader()
}).catch((error) => {
waitreboot()
})
}
-39
View File
@@ -1,39 +0,0 @@
const authhost = 'http://172.20.10.2:43243'
const host = window.location.origin
const prefix = 'api'
const routes = {
login: () => [authhost, prefix, 'token'].join('/'),
user: () => [authhost, prefix, 'users', 'user'].join('/'),
telnet_status: () => [host, prefix, 'settings', 'telnet', 'get'].join('/'),
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
telnet_port_get: () => [host, prefix, 'settings', 'telnet', 'port', 'get'].join('/'),
telnet_port_set: () => [host, prefix, 'settings', 'telnet', 'port', 'set'].join('/'),
ssh_status_get: () => [host, prefix, 'settings', 'ssh', 'status', 'get'].join('/'),
ssh_status_set: () => [host, prefix, 'settings', 'ssh', 'status', 'set'].join('/'),
ssh_keys_get: () => [host, prefix, 'settings', 'ssh', 'keys', 'get'].join('/'),
ssh_keys_set: () => [host, prefix, 'settings', 'ssh', 'keys', 'set'].join('/'),
ssh_port_get: () => [host, prefix, 'settings', 'ssh', 'port', 'get'].join('/'),
ssh_port_set: () => [host, prefix, 'settings', 'ssh', 'port', 'set'].join('/'),
dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'),
dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'),
dns_servers_get: () => [host, prefix, 'settings', 'dns', 'servers', 'get'].join('/'),
dns_servers_set: () => [host, prefix, 'settings', 'dns', 'servers', 'set'].join('/'),
dns_local_domains_get: () => [host, prefix, 'settings', 'dns', 'domains', 'get'].join('/'),
dns_local_domains_set: () => [host, prefix, 'settings', 'dns', 'domains', 'set'].join('/'),
ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'),
ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'),
reboot: () => [host, prefix, 'reboot'].join('/'),
syslog: () => [host, prefix, 'syslog'].join('/'),
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
// access: () => [host, prefix, 'access'].join('/'),
// adduser: () => [host, prefix, 'users', 'add'].join('/'),
// deluser: () => [host, prefix, 'users', 'del'].join('/'),
// change_password_url: () => [host, prefix, 'users', 'user', 'password', 'change'].join('/'),
// change_user: () => [host, prefix, 'users', 'user', 'change'].join('/')
}
-33
View File
@@ -1,33 +0,0 @@
const confirmform = document.querySelector('#confirmform')
const confirmformheader = document.querySelector('#confirmformheader')
const cancelbutton = document.querySelector('#cancel')
const confirmformbuttons = document.querySelector('#confirmformbuttons')
const defaultcancelreqfunc = () => {
confirmform.classList.remove('active')
}
const get_confirm_form = (header, reqfunc = defaultcancelreqfunc, cancelreqfunc = defaultcancelreqfunc) => {
confirmformheader.innerHTML = header
confirmform.classList.add('active')
var confirmbutton = document.createElement('button')
confirmbutton.classList.add('formbutton')
confirmbutton.id = "confirm"
confirmbutton.innerHTML = "Confirm"
confirmbutton.addEventListener('click', () => {
reqfunc()
confirmform.classList.remove('active')
})
confirmformbuttons.replaceChild(confirmbutton, document.querySelector('#confirm'))
var cancelbutton = document.createElement('button')
cancelbutton.classList.add('formbutton')
cancelbutton.id = "cancel"
cancelbutton.innerHTML = "Cancel"
cancelbutton.addEventListener('click', () => {
cancelreqfunc()
confirmform.classList.remove('active')
})
confirmformbuttons.replaceChild(cancelbutton, document.querySelector('#cancel'))
}
-245
View File
@@ -1,245 +0,0 @@
const dnsenabled = document.querySelector('#dnsenable')
const setdnssettingsbutton = document.querySelector('#set_dns_settings')
const dnssettingbody = document.querySelector('#dnssettingsbody')
const dnsserverstablebody = document.querySelector('#dnsserverstablebody')
const adddnsserverbutton = document.querySelector('#add_dns_server_button')
const adddnsserverform = document.querySelector('#adddnsserverform')
const adddnsservercancelbutton = document.querySelector('#adddnsservercancel')
const adddnsserverconfirmbutton = document.querySelector('#adddnsserverconfirm')
const adddnsserverinput = document.querySelector('#adddnsserverinput')
const localdomainstablebody = document.querySelector('#domainsstablebody')
const addlocaldomainbutton = document.querySelector('#add_local_domain_button')
const addlocaldomainform = document.querySelector('#addlocaldomainform')
const addlocaldomaincancelbutton = document.querySelector('#addlocaldomaincancel')
const addlocaldomainconfirmbutton = document.querySelector('#addlocaldomainconfirm')
const domaininput = document.querySelector('#domaininput')
const ipinput = document.querySelector('#ipinput')
const domainstablebody = document.querySelector('#domainsstablebody')
let dnsservers = []
let localdomains = []
const get_dns_enabled_status = () => {
fetch(routes.dns_status(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
dnsenabled.checked = true
dnssettingbody.classList.add('active')
adddnsserverbutton.classList.add('active')
addlocaldomainbutton.classList.add('active')
return;
} else {
adddnsserverbutton.parentElement.classList.add('onebutton')
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_dns_enabled_status = () => {
fetch(routes.dns_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${dnsenabled.checked?1:0}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
dnsenabled.checked = true
dnssettingbody.classList.add('active')
adddnsserverbutton.classList.add('active')
}
notification("Настройки dns сохранены", "success")
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_dns_settings = () => {
set_dns_enabled_status()
if (dnsenabled.checked) {
set_dns_server()
set_local_domains()
}
}
setdnssettingsbutton.addEventListener('click', () =>{
if (confirm("Confirm DNS settings?")) {
set_dns_settings()
}
})
dnsenabled.addEventListener('click', () => {
if (dnsenabled.checked) {
dnssettingbody.classList.add('active')
adddnsserverbutton.classList.add('active')
addlocaldomainbutton.classList.add('active')
adddnsserverbutton.parentElement.classList.remove('onebutton')
get_dns_server()
} else {
dnssettingbody.classList.remove('active')
adddnsserverbutton.classList.remove('active')
addlocaldomainbutton.classList.remove('active')
adddnsserverbutton.parentElement.classList.add('onebutton')
}
})
const get_dns_server = () => {
fetch(routes.dns_servers_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
dnsservers = jsondata.servers
dnsserverstablebody.innerHTML = ""
for (const server in jsondata.servers) {
dnsserverstablebody.innerHTML += `<tr>
<th class="one">
${jsondata.servers[server]}
<button class="deldnsserverbutton" id="${jsondata.servers[server]}">Del</button>
</th>
</tr>`
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_dns_server = () => {
start_loader("Load DNS")
dnsservers.push(adddnsserverinput.value)
fetch(routes.dns_servers_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem('token')}","servers":${JSON.stringify(dnsservers)}}`
}).then(data => data.json()).then(jsondata => {
stop_loader()
if (jsondata.success) {
get_dns_server()
notification("Настройки dns сохранены", "success")
} else {
notification("Неизвестная ошибка", "error")
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
adddnsserverinput.value = ""
}
const cancel_add_dns_server = () => {
adddnsserverform.classList.remove('active')
adddnsserverinput.value = ""
}
const cancel_confirm_add_dns_server = () => {
confirmform.classList.remove('active')
adddnsserverform.classList.add('active')
}
adddnsserverbutton.addEventListener('click', () => {
adddnsserverform.classList.add('active')
})
adddnsservercancelbutton.addEventListener('click', cancel_add_dns_server)
adddnsserverconfirmbutton.addEventListener('click', () => {
adddnsserverform.classList.remove('active')
if (adddnsserverinput.value === "") {
return
}
if (confirm(`Confirm DNS settings? (Add DNS server: ${adddnsserverinput.value})`)) {
set_dns_server()
} else {
cancel_confirm_add_dns_server
}
})
dnsserverstablebody.addEventListener('click', (e) => {
if (e.target.classList.contains('deldnsserverbutton')) {
dnsservers.splice(dnsservers.indexOf(e.target.id), 1)
if (confirm(`Confirm DNS settings? (delete DNS server: ${e.target.id})`)) {
set_dns_server()
}
get_dns_server()
}
})
// ---------------------- local domains ---------------------------
const get_local_domains = () => {
fetch(routes.dns_local_domains_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem('token')}"}`
}).then(data => data.json()).then(jsondata => {
localdomains = jsondata.domains
localdomainstablebody.innerHTML = ""
for (const domain in jsondata.domains) {
localdomainstablebody.innerHTML += `<tr>
<th class="three">${jsondata.domains[domain].ip}</th>
<th class="three" style="display:flex;align-items:center;justify-content:space-between;width:100%">
${jsondata.domains[domain].domain}
<button class="deldomain" id="${jsondata.domains[domain].domain}">Del</button>
</th>
</tr>`
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_local_domains = (domains = localdomains) => {
start_loader()
fetch(routes.dns_local_domains_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem('token')}","domains":${JSON.stringify(domains)}}`
}).then(data => data.json()).then(jsondata => {
stop_loader()
if (jsondata.success) {
get_local_domains()
notification("Настройки dns сохранены", "success")
} else {
notification("Неизвестная ошибка", "error")
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const cancel_confirm_add_localdomain = () => {
confirmform.classList.remove('active')
addlocaldomainform.classList.add('active')
}
addlocaldomainbutton.addEventListener('click', () => {
addlocaldomainform.classList.add('active')
})
addlocaldomaincancelbutton.addEventListener('click', () => {
addlocaldomainform.classList.remove('active')
domaininput.value = "";
ipinput.value = "";
})
addlocaldomainconfirmbutton.addEventListener('click', () => {
addlocaldomainform.classList.remove('active')
if (confirm(`Confirm DNS settings? (Add Local Domain: ${ipinput.value} ${domaininput.value})`)) {
localdomains.push({"ip": ipinput.value, "domain": domaininput.value});
set_local_domains()
ipinput.value = ""
domaininput.value = ""
} else {
cancel_confirm_add_localdomain()
}
})
domainstablebody.addEventListener('click', (e) => {
if (e.target.classList.contains('deldomain')) {
localdomains.splice(localdomains.indexOf(localdomains.find(dom => dom.domain === e.target.id)), 1)
if (confirm(`Confirm DNS settings? (delete Local Domain: ${e.target.id})`)) {
set_local_domains()
}
get_local_domains()
}
})
// ------------------------- local domains end --------------------
-38
View File
@@ -1,38 +0,0 @@
const ftpenabled = document.querySelector('#ftpenable')
const setftpsettingsbutton = document.querySelector('#set_ftp_settings')
const get_ftp_enabled_status = () => {
fetch(routes.ftp_status(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
ftpenabled.checked = true
// ftpsettingbody.classList.add('active')
return;
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_ftp_enabled_status = () => {
fetch(routes.ftp_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${ftpenabled.checked?1:0}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
ftpenabled.checked = true
// ftpsettingbody.classList.add('active')
}
notification("Настройки ftp сохранены", "success")
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
setftpsettingsbutton.addEventListener('click', () =>{
if (confirm("Confirm ftp settings?")) {
set_ftp_enabled_status()
}
})
-14
View File
@@ -1,14 +0,0 @@
const get_all_settings = () => {
get_dns_enabled_status()
get_dns_server()
get_local_domains()
get_ftp_enabled_status()
get_telnet_enabled_status()
get_telnet_port()
get_ssh_status()
get_ssh_keys()
get_ssh_port()
}
-142
View File
@@ -1,142 +0,0 @@
const sshenable = document.querySelector('#sshenable')
const set_ssh_settings = document.querySelector('#set_ssh_settings')
const sshsettingsbody = document.querySelector('#sshsettingsbody')
const sshkeystablebody = document.querySelector('#sshkeystablebody')
const sshportinput = document.querySelector('#sshportinput')
const add_ssh_key_button = document.querySelector('#add_ssh_key')
let sshkeys = []
// -------------------- SSH status --------------------------------
const get_ssh_status = () => {
fetch(routes.ssh_status_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
if (jsondata.status === '1') {
sshenable.checked = true
sshsettingsbody.classList.add('active')
add_ssh_key_button.classList.add('active')
add_ssh_key_button.parentElement.classList.remove('onebutton')
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_ssh_status = () => {
fetch(routes.ssh_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","status":"${sshenable.checked?1:0}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.status === '1') {
sshenable.checked = true
// telnetsettingbody.classList.add('active')
}
notification("Настройки SSH сохранены", "success")
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
// -------------------------------- end SSH status ---------------------------------------
set_ssh_settings.addEventListener('click', () => {
if (confirm("Confirm SSH settings?")) {
set_ssh_status()
set_ssh_port()
}
})
sshenable.addEventListener('click', () => {
if (sshenable.checked) {
sshsettingsbody.classList.add('active')
add_ssh_key_button.classList.add('active')
add_ssh_key_button.parentElement.classList.remove('onebutton')
return
}
sshsettingsbody.classList.remove('active')
add_ssh_key_button.classList.remove('active')
add_ssh_key_button.parentElement.classList.add('onebutton')
})
// -------------------- SSH keys ---------------------------------
const get_ssh_keys = () => {
fetch(routes.ssh_keys_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
console.log(jsondata.keys)
sshkeys = jsondata.keys
sshkeystablebody.innerHTML = ""
for (const key in sshkeys) {
sshkeystablebody.innerHTML += `<tr>
<td class="one" style="flex-direction:column;align-items:start;">
${sshkeys[key]}
<button class="delsshkeybutton" id="${key}">Del</button>
</td>
</tr>`
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_ssh_keys = () => {
start_loader()
fetch(routes.ssh_keys_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","keys":${JSON.stringify(sshkeys)}}`
}).then(data => data.json()).then(jsondata => {
stop_loader()
if (jsondata.success) {
get_ssh_keys()
notification("Настройки SSH сохранены", "success")
} else {
notification("Неизвестная ошибка", "error")
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
// ------------------- end SSH keys ------------------------------
sshkeystablebody.addEventListener('click', (e) => {
if (e.target.classList.contains('delsshkeybutton')) {
if (confirm(`Confirm SSH settings?: (delete SSH key)`)) {
sshkeys.splice(e.target.id)
set_ssh_keys()
}
}
})
add_ssh_key_button.addEventListener('click', () => {
const sshkey = prompt('Get your SSH key:')
if (confirm('Confirm SSH settings? (add SSH key)')) {
sshkeys.push(sshkey)
set_ssh_keys()
}
})
// -------------------- SSH port ----------------------
const get_ssh_port = () => {
fetch(routes.ssh_port_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
sshportinput.value = jsondata.port
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_ssh_port = () => {
fetch(routes.ssh_port_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","port":"${sshportinput.value}"}`
}).then(data => data.json()).then(jsondata => {
sshportinput.value = jsondata.port
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
// ------------------- end SSH port -------------------
-90
View File
@@ -1,90 +0,0 @@
const telnetenabled = document.querySelector('#telnetenable')
const telnetsettingbody = document.querySelector('.telnetsettingbody')
const settelnetsettingsbutton = document.querySelector('#set_telnet_settings')
const addtelnetuserbutton = document.querySelector('#add_telnet_user_button')
const telnetportinput = document.querySelector('#telnetportinput')
const get_telnet_enabled_status = () => {
fetch(routes.telnet_status(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
telnetenabled.checked = true
addtelnetuserbutton.classList.add('active')
addtelnetuserbutton.parentElement.classList.remove('onebutton')
telnetsettingbody.classList.add('active')
return;
} else {
addtelnetuserbutton.parentElement.classList.add('onebutton')
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_telnet_enabled_status = () => {
fetch(routes.telnet_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${telnetenabled.checked?1:0}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
telnetenabled.checked = true
// telnetsettingbody.classList.add('active')
}
notification("Настройки telnet сохранены", "success")
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
telnetenabled.addEventListener('click', () => {
if (telnetenabled.checked) {
addtelnetuserbutton.classList.add('active')
addtelnetuserbutton.parentElement.classList.remove('onebutton')
telnetsettingbody.classList.add('active')
} else {
telnetsettingbody.classList.remove('active')
addtelnetuserbutton.classList.remove('active')
addtelnetuserbutton.parentElement.classList.add('onebutton')
}
})
const set_telnet_settings = () => {
set_telnet_enabled_status()
if (telnetenabled.checked) {
set_telnet_port()
}
}
settelnetsettingsbutton.addEventListener('click', () => {
if (confirm("Confirm telnet settings?")) {
set_telnet_settings()
}
})
const get_telnet_port = () => {
fetch(routes.telnet_port_get(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
telnetportinput.value = jsondata.port
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_telnet_port = () => {
start_loader()
fetch(routes.telnet_port_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","port":"${telnetportinput.value}"}`
}).then(data => data.json()).then(jsondata => {
stop_loader()
telnetportinput.value = jsondata.port
}).catch((error) => {
stop_loader()
notification(`Ошибка на сервере: ${error}`, "error")
})
}
-72
View File
@@ -1,72 +0,0 @@
const syslogdata = document.querySelector('.syslogdata')
const refreshbutton = document.querySelector('#refreshbutton')
const openrouterfilter = document.querySelector('#openrouterfilter')
const authservicefilter = document.querySelector('#authservicefilter')
let openrouterfilterenable = false
let authservicefilerenable = false
const get_syslog_data = () => {
console.log("get_syslog_data")
fetch(routes.syslog(), {
method: 'GET',
// body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.text()).then(textdata => {
if (openrouterfilterenable) {
openrouterfilterfunc(textdata)
return
}
if (authservicefilerenable) {
authservicefilterfunc(textdata)
return
}
syslogdata.innerHTML = textdata.replace(/\n/g,'<br>')
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
refreshbutton.addEventListener('click', () => {
openrouterfilterenable = false
authservicefilerenable = false
get_syslog_data()
})
openrouterfilter.addEventListener('click', () => {
openrouterfilterenable = true
get_syslog_data()
})
authservicefilter.addEventListener('click', () => {
authservicefilerenable = true
openrouterfilterenable = false
get_syslog_data()
})
const openrouterfilterfunc = (textdata) => {
let syslogalldata = textdata.replace(/\n/g,'<br>')
syslogalldata = syslogalldata.split("<br>")
syslogalldata = syslogalldata.filter(data => {
return data.includes("openrouter:")
})
console.log(syslogalldata)
syslogdata.innerHTML = ""
for (const data in syslogalldata) {
syslogdata.innerHTML += syslogalldata[data] + "<br>"
}
return
}
const authservicefilterfunc = (textdata) => {
let syslogalldata = textdata.replace(/\n/g,'<br>')
syslogalldata = syslogalldata.split("<br>")
syslogalldata = syslogalldata.filter(data => {
return data.includes("auth_service:")
})
console.log(syslogalldata)
syslogdata.innerHTML = ""
for (const data in syslogalldata) {
syslogdata.innerHTML += syslogalldata[data] + "<br>"
}
return
}