Merge pull request 'fully upgrade to using config file as config.json and fixed css' (#15) from auth_service_config_file into main
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/openrouter/pulls/15
This commit was merged in pull request #15.
This commit is contained in:
+14
-11
@@ -1,14 +1,17 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project(openrouter)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
include_directories(./src/libs/ ./src)
|
||||
|
||||
add_executable(
|
||||
openrouter
|
||||
src/openrouter.cpp
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
project(openrouter)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
include_directories(./src/libs/ ./src)
|
||||
|
||||
add_executable(
|
||||
openrouter
|
||||
src/openrouter.cpp
|
||||
src/security/cors.cpp
|
||||
|
||||
|
||||
src/settings/settings.cpp
|
||||
src/settings/backup.cpp
|
||||
|
||||
src/settings/telnet/enabled.cpp
|
||||
src/settings/telnet/port.cpp
|
||||
|
||||
@@ -41,7 +44,7 @@ add_executable(
|
||||
|
||||
src/libs/QR-Code-generator/qrcodegen.cpp
|
||||
src/libs/QR-Code-generator/qrtosvg.cpp
|
||||
)
|
||||
)
|
||||
|
||||
install(TARGETS openrouter DESTINATION /usr/bin)
|
||||
install(DIRECTORY src/web DESTINATION /usr/share/openrouter/web)
|
||||
|
||||
@@ -3,6 +3,8 @@ STRIP=strip
|
||||
CXXFLAGS=-Wall -I src/libs -I src -std=c++20
|
||||
SOURCES=src/openrouter.cpp \
|
||||
src/security/cors.cpp \
|
||||
src/settings/settings.cpp \
|
||||
src/settings/backup.cpp \
|
||||
src/settings/telnet/enabled.cpp \
|
||||
src/settings/telnet/port.cpp \
|
||||
src/settings/ssh/status.cpp \
|
||||
|
||||
+10
-5
@@ -1,4 +1,9 @@
|
||||
{
|
||||
"auth_service": "http://127.0.0.1:43243",
|
||||
"server": {
|
||||
"ip": "0.0.0.0",
|
||||
"port": 43244
|
||||
},
|
||||
"settings": {
|
||||
"dns": {
|
||||
"enabled": false,
|
||||
@@ -25,17 +30,17 @@
|
||||
"key1",
|
||||
"key2"
|
||||
],
|
||||
"port": 22,
|
||||
"port": "22",
|
||||
"server": "dropbear"
|
||||
},
|
||||
"telnet": {
|
||||
"enabled": false,
|
||||
"port": 23
|
||||
"port": "23"
|
||||
},
|
||||
"wifi": {
|
||||
"channel": 6,
|
||||
"channel": "11",
|
||||
"enabled": false,
|
||||
"name": "OpenRouterWifi",
|
||||
"name": "home",
|
||||
"password": "OpenRouterPassword"
|
||||
}
|
||||
},
|
||||
@@ -44,4 +49,4 @@
|
||||
"js": "../src/web/js",
|
||||
"root": "../src/web"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"auth_service": "http://127.0.0.1:43243",
|
||||
"server": {
|
||||
"ip": "0.0.0.0",
|
||||
"port": 43244
|
||||
},
|
||||
"settings": {
|
||||
"dns": {
|
||||
"enabled": false,
|
||||
"localdomains": [
|
||||
{
|
||||
"domain": "localhost",
|
||||
"ip": "127.0.0.1"
|
||||
},
|
||||
{
|
||||
"domain": "openrouter.local.com",
|
||||
"ip": "192.168.200.1"
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
"8.8.8.8"
|
||||
]
|
||||
},
|
||||
"ftp": {
|
||||
"enabled": false
|
||||
},
|
||||
"ssh": {
|
||||
"enabled": false,
|
||||
"keys": [
|
||||
"key1",
|
||||
"key2"
|
||||
],
|
||||
"port": "22",
|
||||
"server": "dropbear"
|
||||
},
|
||||
"telnet": {
|
||||
"enabled": false,
|
||||
"port": "23"
|
||||
},
|
||||
"wifi": {
|
||||
"channel": "11",
|
||||
"enabled": false,
|
||||
"name": "home",
|
||||
"password": "OpenRouterPassword"
|
||||
}
|
||||
},
|
||||
"static": {
|
||||
"css": "../src/web/css",
|
||||
"js": "../src/web/js",
|
||||
"root": "../src/web"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ executable(
|
||||
'src/openrouter.cpp',
|
||||
'src/security/cors.cpp',
|
||||
|
||||
'src/settings/settings.cpp',
|
||||
'src/settings/backup.cpp',
|
||||
|
||||
'src/settings/telnet/enabled.cpp',
|
||||
'src/settings/telnet/port.cpp',
|
||||
|
||||
|
||||
@@ -8,39 +8,14 @@
|
||||
|
||||
OpenRouter::OpenRouter()
|
||||
{
|
||||
this->srv.Post("/api/settings/telnet/get", api::settings::telnet::get_telnet);
|
||||
this->srv.Post("/api/settings/telnet/set", api::settings::telnet::set_telnet);
|
||||
this->srv.Post("/api/settings/telnet/port/get", api::settings::telnet::get_telnet_port);
|
||||
this->srv.Post("/api/settings/telnet/port/set", api::settings::telnet::set_telnet_port);
|
||||
|
||||
this->srv.Post("/api/settings/ssh/status/get", api::settings::ssh::get_ssh_status);
|
||||
this->srv.Post("/api/settings/ssh/status/set", api::settings::ssh::set_ssh_status);
|
||||
this->srv.Post("/api/settings/ssh/keys/get", api::settings::ssh::get_ssh_keys);
|
||||
this->srv.Post("/api/settings/ssh/keys/set", api::settings::ssh::set_ssh_keys);
|
||||
this->srv.Post("/api/settings/ssh/port/get", api::settings::ssh::get_ssh_port);
|
||||
this->srv.Post("/api/settings/ssh/port/set", api::settings::ssh::set_ssh_port);
|
||||
this->srv.Post("/api/settings/ssh/server/get", api::settings::ssh::get_ssh_server_http);
|
||||
this->srv.Post("/api/settings/ssh/server/set", api::settings::ssh::set_ssh_server_http);
|
||||
|
||||
this->srv.Post("/api/settings/dns/get", api::settings::dns::get_dns);
|
||||
this->srv.Post("/api/settings/dns/set", api::settings::dns::set_dns);
|
||||
this->srv.Post("/api/settings/dns/servers/get", api::settings::dns::get_dns_servers);
|
||||
this->srv.Post("/api/settings/dns/servers/set", api::settings::dns::set_dns_servers);
|
||||
this->srv.Post("/api/settings/dns/domains/get", api::settings::dns::get_local_domains);
|
||||
this->srv.Post("/api/settings/dns/domains/set", api::settings::dns::set_local_domains);
|
||||
|
||||
this->srv.Post("/api/settings/ftp/get", api::settings::ftp::get_ftp);
|
||||
this->srv.Post("/api/settings/ftp/set", api::settings::ftp::set_ftp);
|
||||
|
||||
this->srv.Post("/api/settings/wifi/status/get", api::settings::wifi::get_wifi_status);
|
||||
this->srv.Post("/api/settings/wifi/status/set", api::settings::wifi::set_wifi_status);
|
||||
this->srv.Post("/api/settings/wifi/name/get", api::settings::wifi::get_wifi_name);
|
||||
this->srv.Post("/api/settings/wifi/name/set", api::settings::wifi::set_wifi_name);
|
||||
this->srv.Post("/api/settings/wifi/password/get", api::settings::wifi::get_wifi_password);
|
||||
this->srv.Post("/api/settings/wifi/password/set", api::settings::wifi::set_wifi_password);
|
||||
this->srv.Post("/api/settings/wifi/qr/get", api::settings::wifi::get_wifi_qr);
|
||||
this->srv.Post("/api/settings/wifi/channel/get", api::settings::wifi::get_wifi_channel);
|
||||
this->srv.Post("/api/settings/wifi/channel/set", api::settings::wifi::set_wifi_channel);
|
||||
|
||||
this->srv.Post("/api/settings/get", api::settings::get);
|
||||
this->srv.Post("/api/settings/set", api::settings::set);
|
||||
this->srv.Get("/api/settings/backup", api::settings::backup);
|
||||
this->srv.Post("/api/settings/restore", api::settings::restore);
|
||||
this->srv.Post("/api/settings/restore/defaults", api::settings::restore_defaults);
|
||||
|
||||
this->srv.Post("/api/reboot", api::system::reboot);
|
||||
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#include <auth/auth.hpp>
|
||||
#include <httplib.h>
|
||||
#include <routes.hpp>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
bool authenticate(const std::string &token)
|
||||
{
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
httplib::Client cli(config::config.getConfig()["auth_service"]);
|
||||
|
||||
std::string body = R"({"token":")" + token + R"("})";
|
||||
// body << R"({"token":")" << token << R"("})";
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
namespace config {
|
||||
static ConfigManager config(std::string("../config.json"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,9 @@ public:
|
||||
this->config = nullptr;
|
||||
this->configfile.close();
|
||||
}
|
||||
std::string getConfigFileName() {
|
||||
return this->configFileName;
|
||||
}
|
||||
nlohmann::json getConfig()
|
||||
{
|
||||
return this->config;
|
||||
|
||||
+1269
-612
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -1,4 +1,5 @@
|
||||
#include <OpenRouter/OpenRouter.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -6,6 +7,6 @@ int main()
|
||||
#ifdef TEST
|
||||
return 0;
|
||||
#else
|
||||
return router.serve("0.0.0.0", 43244);
|
||||
return router.serve(config::config.getConfig()["server"]["ip"], config::config.getConfig()["server"]["port"]);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef ROUTES_HPP
|
||||
#define ROUTES_HPP
|
||||
|
||||
#define AUTH_SERVICE "http://localhost:43243"
|
||||
|
||||
#endif // ROUTES_HPP
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <settings/settings.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <types.hpp>
|
||||
#include <filesystem>
|
||||
#include <colors.h>
|
||||
#include <helpers.hpp>
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void backup(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::ifstream backup_file(config::config.getConfigFileName());
|
||||
std::stringstream backup_file_buffer;
|
||||
backup_file_buffer << backup_file.rdbuf();
|
||||
backup_file.close();
|
||||
response.set_content(backup_file_buffer.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void restore(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::size_t size = request.files.size();
|
||||
std::cout << "file size::" << size << std::endl;
|
||||
bool ret = request.has_file("restore_settings");
|
||||
std::cout << "file ret::" << ret << std::endl;
|
||||
const httplib::MultipartFormData& file = request.get_file_value("restore_settings");
|
||||
if (file.content_type == JSON_TYPE) {
|
||||
nlohmann::json new_config = nlohmann::json::parse(file.content);
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
set_all_settings(config::config.getConfig());
|
||||
response.set_content(R"({"status":true})", JSON_TYPE);
|
||||
system("rc restart auth_service");
|
||||
system("rc restart openrouter");
|
||||
return;
|
||||
}
|
||||
response.set_content(R"({"status":false})", JSON_TYPE);
|
||||
}
|
||||
|
||||
void restore_defaults(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
if (std::filesystem::exists(config::config.getConfigFileName())) {
|
||||
std::filesystem::remove(config::config.getConfigFileName());
|
||||
std::filesystem::copy("../config_default.json", config::config.getConfigFileName());
|
||||
usleep(300);
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
set_all_settings(config::config.getConfig());
|
||||
response.set_content(R"({"status":true})", JSON_TYPE);
|
||||
system("rc restart auth_service");
|
||||
system("rc restart openrouter");
|
||||
return;
|
||||
}
|
||||
response.set_content(R"({"status":false})", JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef DNS_HPP
|
||||
#define DNS_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
#include <json.hpp>
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -9,14 +9,9 @@ namespace api
|
||||
{
|
||||
namespace dns
|
||||
{
|
||||
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);
|
||||
void set_dns(bool new_dns_enabled);
|
||||
void set_dns_servers(nlohmann::json servers);
|
||||
void set_local_domains(nlohmann::json domains);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
#include <settings/dns/dns.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define DNS_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -15,52 +7,8 @@ namespace api
|
||||
{
|
||||
namespace dns
|
||||
{
|
||||
void get_dns(const httplib::Request& request, httplib::Response& response)
|
||||
void set_dns(bool new_dns_enabled)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int dns_enabled = config::config.getConfig()["settings"]["dns"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void set_dns(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["enabled"] == nullptr)
|
||||
{
|
||||
response.set_content(DNS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_dns_enabled = json_body["enabled"];
|
||||
if (!new_dns_enabled)
|
||||
{
|
||||
system("rc stop dnsmasq");
|
||||
@@ -73,15 +21,6 @@ namespace api
|
||||
system("rc add dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS is enabled");
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["dns"]["enabled"] = new_dns_enabled;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int dns_enabled = config::config.getConfig()["settings"]["dns"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << dns_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#include <settings/dns/dns.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <fstream>
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -13,48 +8,9 @@ namespace api
|
||||
{
|
||||
namespace dns
|
||||
{
|
||||
void get_local_domains(const httplib::Request& request, httplib::Response& response)
|
||||
void set_local_domains(nlohmann::json domains)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"domains":)";
|
||||
responsedata << config::config.getConfig()["settings"]["dns"]["localdomains"];
|
||||
responsedata << "}";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void set_local_domains(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream domainsfile("/etc/dnsmasq.conf.d/hosts");
|
||||
nlohmann::json domains = json_body["domains"];
|
||||
for (nlohmann::json_abi_v3_11_3::json domain : domains)
|
||||
{
|
||||
std::string ip = domain["ip"];
|
||||
@@ -62,15 +18,8 @@ namespace api
|
||||
domainsfile << ip << " " << dom << "\n";
|
||||
}
|
||||
domainsfile.close();
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["dns"]["localdomains"] = json_body["domains"];
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS local domains changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#include <settings/dns/dns.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <fstream>
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -13,48 +8,9 @@ namespace api
|
||||
{
|
||||
namespace dns
|
||||
{
|
||||
void get_dns_servers(const httplib::Request& request, httplib::Response& response)
|
||||
void set_dns_servers(nlohmann::json servers)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"servers":)";
|
||||
responsedata << config::config.getConfig()["settings"]["dns"]["servers"];
|
||||
responsedata << "}";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void set_dns_servers(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream dnsserversfile("/etc/dnsmasq.conf.d/resolv.conf");
|
||||
nlohmann::json servers = json_body["servers"];
|
||||
for (const nlohmann::json_abi_v3_11_3::json& server : servers)
|
||||
{
|
||||
std::string srv = server;
|
||||
@@ -65,15 +21,8 @@ namespace api
|
||||
dnsserversfile << "nameserver " << srv << "\n";
|
||||
}
|
||||
dnsserversfile.close();
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["dns"]["servers"] = json_body["servers"];
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
system("rc restart dnsmasq");
|
||||
syslog(LOG_INFO, "%s", "DNS servers changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#include <settings/ftp/ftp.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
@@ -15,52 +10,8 @@ namespace api
|
||||
{
|
||||
namespace ftp
|
||||
{
|
||||
void get_ftp(const httplib::Request& request, httplib::Response& response)
|
||||
void set_ftp(bool new_ftp_enabled)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["enabled"] == nullptr)
|
||||
{
|
||||
response.set_content(FTP_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_ftp_enabled = json_body["enabled"];
|
||||
if (!new_ftp_enabled)
|
||||
{
|
||||
system("rc stop ftp");
|
||||
@@ -73,15 +24,6 @@ namespace api
|
||||
system("rc add ftp");
|
||||
syslog(LOG_INFO, "%s", "Ftp is enabled");
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ftp"]["enabled"] = new_ftp_enabled;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#ifndef FTP_HPP
|
||||
#define FTP_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
namespace ftp
|
||||
{
|
||||
void get_ftp(const httplib::Request& request, httplib::Response& response);
|
||||
void set_ftp(const httplib::Request& request, httplib::Response& response);
|
||||
void set_ftp(bool new_ftp_enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#include <settings/settings.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define SETTINGS_REQUIRED_STRING R"({"required":"[settings]"})"
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void set_all_settings(nlohmann::json json_body)
|
||||
{
|
||||
api::settings::wifi::set_wifi_status(json_body["settings"]["wifi"]["enabled"]);
|
||||
std::string wifichannel = json_body["settings"]["wifi"]["channel"];
|
||||
api::settings::wifi::set_wifi_channel(std::stoi(wifichannel));
|
||||
api::settings::wifi::set_wifi_name(json_body["settings"]["wifi"]["name"]);
|
||||
|
||||
api::settings::telnet::set_telnet(json_body["settings"]["telnet"]["enabled"]);
|
||||
std::string telnetport = json_body["settings"]["telnet"]["port"];
|
||||
api::settings::telnet::set_telnet_port(std::stoi(telnetport));
|
||||
|
||||
api::settings::ssh::set_ssh_status(json_body["settings"]["ssh"]["enabled"]);
|
||||
api::settings::ssh::set_ssh_server(json_body["settings"]["ssh"]["server"]);
|
||||
std::string sshport = json_body["settings"]["ssh"]["port"];
|
||||
api::settings::ssh::set_ssh_port(std::stoi(sshport));
|
||||
api::settings::ssh::set_ssh_keys(json_body["settings"]["ssh"]["keys"]);
|
||||
|
||||
api::settings::ftp::set_ftp(json_body["settings"]["ftp"]["enabled"]);
|
||||
|
||||
api::settings::dns::set_dns(json_body["settings"]["dns"]["enabled"]);
|
||||
api::settings::dns::set_dns_servers(json_body["settings"]["dns"]["servers"]);
|
||||
api::settings::dns::set_local_domains(json_body["settings"]["dns"]["localdomains"]);
|
||||
}
|
||||
|
||||
void get(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
std::string responsedata = R"({"settings":)" + config::config.getConfig()["settings"].dump() + R"(})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
|
||||
void set(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["settings"] == nullptr)
|
||||
{
|
||||
response.set_content(SETTINGS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
usleep(300);
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"] = json_body["settings"];
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
|
||||
set_all_settings(json_body);
|
||||
|
||||
// api::settings::wifi::set_wifi_status(json_body["settings"]["wifi"]["enabled"]);
|
||||
// std::string wifichannel = json_body["settings"]["wifi"]["channel"];
|
||||
// api::settings::wifi::set_wifi_channel(std::stoi(wifichannel));
|
||||
// api::settings::wifi::set_wifi_name(json_body["settings"]["wifi"]["name"]);
|
||||
|
||||
// api::settings::telnet::set_telnet(json_body["settings"]["telnet"]["enabled"]);
|
||||
// std::string telnetport = json_body["settings"]["telnet"]["port"];
|
||||
// api::settings::telnet::set_telnet_port(std::stoi(telnetport));
|
||||
|
||||
// api::settings::ssh::set_ssh_status(json_body["settings"]["ssh"]["enabled"]);
|
||||
// api::settings::ssh::set_ssh_server(json_body["settings"]["ssh"]["server"]);
|
||||
// std::string sshport = json_body["settings"]["ssh"]["port"];
|
||||
// api::settings::ssh::set_ssh_port(std::stoi(sshport));
|
||||
// api::settings::ssh::set_ssh_keys(json_body["settings"]["ssh"]["keys"]);
|
||||
|
||||
// api::settings::ftp::set_ftp(json_body["settings"]["ftp"]["enabled"]);
|
||||
|
||||
// api::settings::dns::set_dns(json_body["settings"]["dns"]["enabled"]);
|
||||
// api::settings::dns::set_dns_servers(json_body["settings"]["dns"]["servers"]);
|
||||
// api::settings::dns::set_local_domains(json_body["settings"]["dns"]["localdomains"]);
|
||||
|
||||
std::string responsedata = R"({"settings":)" + config::config.getConfig()["settings"].dump() + R"(})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,17 @@
|
||||
#include <settings/ftp/ftp.hpp>
|
||||
#include <settings/dns/dns.hpp>
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void set_all_settings(nlohmann::json json_body);
|
||||
void backup(const httplib::Request& request, httplib::Response& response);
|
||||
void restore(const httplib::Request& request, httplib::Response& response);
|
||||
void restore_defaults(const httplib::Request& request, httplib::Response& response);
|
||||
void get(const httplib::Request& request, httplib::Response& response);
|
||||
void set(const httplib::Request& request, httplib::Response& response);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SETTINGS_HPP
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#include <settings/ssh/ssh.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define KEYS_PATH "~/.ssh/authorized_keys"
|
||||
@@ -15,62 +13,16 @@ namespace api
|
||||
{
|
||||
namespace ssh
|
||||
{
|
||||
void get_ssh_keys(const httplib::Request& request, httplib::Response& response)
|
||||
void set_ssh_keys(nlohmann::json keys)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"keys":)";
|
||||
responsedata << config::config.getConfig()["settings"]["ssh"]["keys"];
|
||||
responsedata << "}";
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream keysfile(KEYS_PATH);
|
||||
nlohmann::json keys = json_body["keys"];
|
||||
for (std::string key : keys)
|
||||
{
|
||||
keysfile << key << "\n";
|
||||
}
|
||||
keysfile.close();
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ssh"]["keys"] = json_body["keys"];
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
system("rc restart ssh");
|
||||
syslog(LOG_INFO, "%s", "SSH keys changed");
|
||||
std::string responsedata = R"({"success":"true"})";
|
||||
response.set_content(responsedata, JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
#include <settings/ssh/ssh.hpp>
|
||||
#include <colors.h>
|
||||
#include <types.hpp>
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
|
||||
#define SSH_PORT_PATH "/etc/openrouter/ssh/port"
|
||||
#define DROPBEAR_DEFAULT_FILE "/etc/default/dropbear"
|
||||
#define SSHD_CONFIG_FILE "/etc/ssh/sshd_config"
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -20,67 +16,17 @@ namespace api
|
||||
{
|
||||
namespace ssh
|
||||
{
|
||||
void get_ssh_port(const httplib::Request& request, httplib::Response& response)
|
||||
void set_ssh_port(int new_ssh_port)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["port"] == nullptr)
|
||||
{
|
||||
response.set_content(SSH_PORT_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", 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::string old_ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
|
||||
std::stringstream systemrequest;
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
{
|
||||
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear";
|
||||
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" " << DROPBEAR_DEFAULT_FILE;
|
||||
}
|
||||
else if (get_ssh_server() == OPENSSH_SSH)
|
||||
{
|
||||
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
|
||||
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" " << SSHD_CONFIG_FILE;
|
||||
}
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
@@ -94,15 +40,6 @@ namespace api
|
||||
}
|
||||
std::string syslogstring = "SSH port changed to " + new_ssh_port;
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ssh"]["port"] = std::stoi(new_ssh_port);
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int ssh_port = config::config.getConfig()["settings"]["ssh"]["port"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"port":")" << ssh_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
#include <settings/ssh/ssh.hpp>
|
||||
#include <fstream>
|
||||
#include <json.hpp>
|
||||
#include <colors.h>
|
||||
#include <helpers.hpp>
|
||||
#include <types.hpp>
|
||||
#include <auth/auth.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define SSH_SERVER_REQUIRED_STRING R"({"required":"[token,server]"})"
|
||||
@@ -17,65 +11,12 @@ namespace api
|
||||
{
|
||||
std::string get_ssh_server()
|
||||
{
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
return config::config.getConfig()["settings"]["ssh"]["server"];
|
||||
}
|
||||
|
||||
std::string set_ssh_server(std::string& server)
|
||||
void set_ssh_server(std::string new_server)
|
||||
{
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ssh"]["server"] = server;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
return config::config.getConfig()["settings"]["ssh"]["server"];
|
||||
}
|
||||
|
||||
void get_ssh_server_http(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"server":")" << get_ssh_server() << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
void set_ssh_server_http(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["server"] == nullptr)
|
||||
{
|
||||
response.set_content(SSH_SERVER_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::stringstream responsedata;
|
||||
std::string server = json_body["server"];
|
||||
std::string new_server = set_ssh_server(server);
|
||||
if (new_server == DROPBEAR_SSH)
|
||||
{
|
||||
system("rc stop ssh");
|
||||
@@ -89,8 +30,6 @@ namespace api
|
||||
system("rc start ssh");
|
||||
system("rc add ssh");
|
||||
}
|
||||
responsedata << R"({"server":")" << new_server << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef SSH_HPP
|
||||
#define SSH_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
#include <json.hpp>
|
||||
|
||||
#define DROPBEAR_SSH "dropbear"
|
||||
#define OPENSSH_SSH "openssh"
|
||||
@@ -13,19 +13,10 @@ namespace api
|
||||
namespace ssh
|
||||
{
|
||||
std::string get_ssh_server();
|
||||
std::string set_ssh_server(std::string& server);
|
||||
|
||||
void get_ssh_server_http(const httplib::Request& request, httplib::Response& response);
|
||||
void set_ssh_server_http(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
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);
|
||||
void set_ssh_server(std::string new_server);
|
||||
void set_ssh_status(bool new_ssh_status);
|
||||
void set_ssh_keys(nlohmann::json keys);
|
||||
void set_ssh_port(int port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
#include <settings/ssh/ssh.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})"
|
||||
|
||||
@@ -15,52 +9,8 @@ namespace api
|
||||
{
|
||||
namespace ssh
|
||||
{
|
||||
void get_ssh_status(const httplib::Request& request, httplib::Response& response)
|
||||
void set_ssh_status(bool new_ssh_status)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["status"] == nullptr)
|
||||
{
|
||||
response.set_content(SSH_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_ssh_status = json_body["status"];
|
||||
if (!new_ssh_status)
|
||||
{
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
@@ -87,15 +37,6 @@ namespace api
|
||||
}
|
||||
syslog(LOG_INFO, "%s", "SSH is enabled");
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ssh"]["enabled"] = new_ssh_status;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << ssh_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
#include <settings/telnet/telnet.hpp>
|
||||
#include <colors.h>
|
||||
#include <types.hpp>
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
@@ -19,52 +10,8 @@ namespace api
|
||||
{
|
||||
namespace telnet
|
||||
{
|
||||
void get_telnet(const httplib::Request& request, httplib::Response& response)
|
||||
void set_telnet(bool new_telnet_enabled)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int telnet_enabled = config::config.getConfig()["settings"]["telnet"]["enabled"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["enabled"] == nullptr)
|
||||
{
|
||||
response.set_content(TELNET_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_telnet_enabled = json_body["enabled"];
|
||||
if (!new_telnet_enabled)
|
||||
{
|
||||
system("rc stop telnet");
|
||||
@@ -77,15 +24,6 @@ namespace api
|
||||
system("rc add telnet");
|
||||
syslog(LOG_INFO, "%s", "Telnet is enabled");
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["telnet"]["enabled"] = new_telnet_enabled;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int telnet_enabled = config::config.getConfig()["settings"]["telnet"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
#include <settings/telnet/telnet.hpp>
|
||||
#include <colors.h>
|
||||
#include <types.hpp>
|
||||
#include <json.hpp>
|
||||
#include <syslog.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define TELNET_PORT_REQUIRED_STRING R"({"required":"[token,port]"})"
|
||||
#define TELNET_PORT_FILE "/etc/default/telnet"
|
||||
|
||||
namespace api
|
||||
{
|
||||
@@ -19,64 +12,16 @@ namespace api
|
||||
{
|
||||
namespace telnet
|
||||
{
|
||||
void get_telnet_port(const httplib::Request& request, httplib::Response& response)
|
||||
void set_telnet_port(int new_telnet_port)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int telnet_port = config::config.getConfig()["settings"]["telnet"]["port"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["port"] == nullptr)
|
||||
{
|
||||
response.set_content(TELNET_PORT_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::string new_telnet_port = json_body["port"];
|
||||
std::string old_telnet_port = config::config.getConfig()["settings"]["telnet"]["port"];
|
||||
std::stringstream systemrequest;
|
||||
systemrequest << "sed -i \"s/TELNET_PORT=" << old_telnet_port << "/TELNET_PORT=" << new_telnet_port << "/g\" " << TELNET_PORT_FILE;
|
||||
std::cout << systemrequest.str() << std::endl;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart telnet");
|
||||
std::string syslogstring = "Telnet port changed to " + new_telnet_port;
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
std::stringstream responsedata;
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["telnet"]["port"] = stoi(new_telnet_port);
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int telnet_port = config::config.getConfig()["settings"]["telnet"]["port"];
|
||||
responsedata << R"({"port":")" << telnet_port << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
#ifndef SETTINGS_TELNET_HPP
|
||||
#define SETTINGS_TELNET_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
namespace telnet
|
||||
{
|
||||
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 set_telnet(bool new_telnet_enabled);
|
||||
void set_telnet_port(int new_telnet_port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
#include <settings/wifi/wifi.hpp>
|
||||
#include <colors.h>
|
||||
#include <types.hpp>
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define WIFI_CHANNEL_REQUIRED_STRING R"({"required":"[token,channel]"})"
|
||||
|
||||
@@ -19,51 +12,8 @@ namespace api
|
||||
{
|
||||
namespace wifi
|
||||
{
|
||||
void get_wifi_channel(const httplib::Request& request, httplib::Response& response)
|
||||
void set_wifi_channel(int new_channel)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["channel"] == nullptr)
|
||||
{
|
||||
response.set_content(WIFI_CHANNEL_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
@@ -77,7 +27,6 @@ namespace api
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -85,16 +34,6 @@ namespace api
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI channel changed to " + new_channel;
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
sleep(1);
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["wifi"]["channel"] = std::stoi(new_channel);
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
#include <settings/wifi/wifi.hpp>
|
||||
#include <colors.h>
|
||||
#include <types.hpp>
|
||||
#include <json.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define WIFI_NAME_REQUIRED_STRING R"({"required":"[token,name]"})"
|
||||
|
||||
@@ -19,51 +12,8 @@ namespace api
|
||||
{
|
||||
namespace wifi
|
||||
{
|
||||
void get_wifi_name(const httplib::Request& request, httplib::Response& response)
|
||||
void set_wifi_name(std::string new_wifi_name)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["name"] == nullptr)
|
||||
{
|
||||
response.set_content(WIFI_NAME_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string old_wifi_name;
|
||||
std::string wifisettingsbuffer;
|
||||
@@ -77,7 +27,6 @@ namespace api
|
||||
}
|
||||
}
|
||||
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;
|
||||
@@ -85,29 +34,6 @@ namespace api
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI name changed to " + new_wifi_name;
|
||||
syslog(LOG_INFO, "%s", 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();
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["wifi"]["name"] = new_wifi_name;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"name":")" << wifi_name << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,29 +19,6 @@ namespace api
|
||||
{
|
||||
namespace wifi
|
||||
{
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
|
||||
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;
|
||||
@@ -84,8 +61,8 @@ namespace api
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI password changed";
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
sleep(1);
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
usleep(500);
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["wifi"]["password"] = new_wifi_password;
|
||||
config::config.setConfig(new_config);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace api
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
config::config.setConfig(config::config.getConfigFileName());
|
||||
std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"];
|
||||
std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"];
|
||||
std::stringstream toqrstring;
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
#include <settings/wifi/wifi.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
|
||||
#define WIFI_REQUIRED_STRING R"({"required":"[token,status]"})"
|
||||
|
||||
@@ -15,52 +9,8 @@ namespace api
|
||||
{
|
||||
namespace wifi
|
||||
{
|
||||
void get_wifi_status(const httplib::Request& request, httplib::Response& response)
|
||||
void set_wifi_status(bool new_wifi_status)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
int wifi_status = config::config.getConfig()["settings"]["wifi"]["enabled"];
|
||||
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 (!check_body(request))
|
||||
{
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (json_body["status"] == nullptr)
|
||||
{
|
||||
response.set_content(WIFI_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_wifi_status = json_body["status"];
|
||||
if (!new_wifi_status)
|
||||
{
|
||||
system("rc stop hostapd");
|
||||
@@ -73,16 +23,6 @@ namespace api
|
||||
system("rc add hostapd");
|
||||
syslog(LOG_INFO, "%s", "WIFI is enabled");
|
||||
}
|
||||
sleep(1);
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["wifi"]["enabled"] = new_wifi_status;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int wifi_status = config::config.getConfig()["settings"]["wifi"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << wifi_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,19 +11,11 @@ namespace api
|
||||
{
|
||||
namespace wifi
|
||||
{
|
||||
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_password(const httplib::Request& request, httplib::Response& response);
|
||||
void set_wifi_status(bool new_wifi_status);
|
||||
void set_wifi_name(std::string new_wifi_name);
|
||||
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_channel(const httplib::Request& request, httplib::Response& response);
|
||||
void set_wifi_channel(const httplib::Request& request, httplib::Response& response);
|
||||
void set_wifi_channel(int new_channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
.forminputbody {
|
||||
width: 50%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.forminputbody.confirmform {
|
||||
@@ -92,6 +92,7 @@
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
transition: 0.3s;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.formbutton:hover {
|
||||
@@ -110,6 +111,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
.forminputbody {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
.formbody {
|
||||
width: 100%;
|
||||
|
||||
@@ -2,7 +2,6 @@ header {
|
||||
width: 100vw;
|
||||
height: 50px;
|
||||
padding: 10px;
|
||||
margin: 5px;
|
||||
display: grid;
|
||||
grid-template-columns: 32% 32% 32%;
|
||||
align-items: center;
|
||||
|
||||
+10
-4
@@ -9,17 +9,21 @@
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.adminpanel {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
height: 100vh;
|
||||
transform: scale(0.5);
|
||||
opacity: 0;
|
||||
transition: 0.3s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.adminpanel.active {
|
||||
@@ -29,6 +33,8 @@ body {
|
||||
|
||||
.section {
|
||||
position: relative;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
height: calc(100vh - 50px);
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
+20
-15
@@ -192,6 +192,22 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- Wi-Fi settings -->
|
||||
<!-- backup settings -->
|
||||
<div class="settingrect ">
|
||||
<div class="settingrectheader">
|
||||
<h2>Backup settings</h2>
|
||||
</div>
|
||||
<div class="settingrectfooter" style="flex-direction: column;">
|
||||
<a id="backup_settings" class="settingrectfooterbutton" href="" download="backup_settings.json">
|
||||
<button class="settingrectfooterbutton">Backup settings</button>
|
||||
</a>
|
||||
<input type="file" name="" id="restore_settings_input" hidden>
|
||||
<button class="settingrectfooterbutton" id="restore_settings">Restore settings</button>
|
||||
<button class="settingrectfooterbutton" id="start_restore_settings">Start restore settings</button>
|
||||
<button class="settingrectfooterbutton" id="restore_default_settings">Rrestore default settings</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- backup settings -->
|
||||
</section>
|
||||
<!-- syslog block -->
|
||||
<section class="syslogsection">
|
||||
@@ -209,7 +225,7 @@
|
||||
<section class="infosection">
|
||||
<div class="inforect">
|
||||
<label for="infoversion">Version: </label>
|
||||
<p id="version">0.1.1</p>
|
||||
<p id="version">0.1.1</p>
|
||||
</div>
|
||||
<div class="inforect">
|
||||
<label for="infouptime">Uptime: </label>
|
||||
@@ -241,17 +257,6 @@
|
||||
</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 -->
|
||||
<!-- loader -->
|
||||
<div class="loader">
|
||||
<h1 id="loaderheader">Reboting</h1>
|
||||
@@ -265,13 +270,13 @@
|
||||
<script src="js/notification.js"></script>
|
||||
<script src="js/loader.js"></script>
|
||||
|
||||
<script src="js/settings/confirm.js"></script>
|
||||
<script src="js/settings/settings.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/wifi.js"></script>
|
||||
<script src="js/settings/settings.js"></script>
|
||||
<script src="js/settings/backup.js"></script>
|
||||
|
||||
<script src="js/reboot.js"></script>
|
||||
<script src="js/syslog.js"></script>
|
||||
@@ -279,4 +284,4 @@
|
||||
<script src="js/login.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -4,10 +4,8 @@ const syslogsection = document.querySelector('.syslogsection')
|
||||
const syslogbutton = document.querySelector('#syslogbutton')
|
||||
const infobutton = document.querySelector('#infobutton')
|
||||
const infosection = document.querySelector('.infosection')
|
||||
|
||||
const headermenubutton = document.querySelector('#headermenubutton')
|
||||
const headerlinks = document.querySelector('.links')
|
||||
// const header = document.querySelector('.header')
|
||||
|
||||
let uptimeintervalid
|
||||
|
||||
@@ -47,9 +45,3 @@ infobutton.addEventListener('click', () => {
|
||||
infosection.classList.add('active')
|
||||
uptimeintervalid = setInterval(get_uptime, 1000)
|
||||
})
|
||||
|
||||
// if (window.screenX > 600) {
|
||||
// header.removeChild(headermenubutton)
|
||||
// } else {
|
||||
// header.prepend(headermenubutton)
|
||||
// }
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ const login = async (username, password) => {
|
||||
notification("Успешно", "success")
|
||||
loginform.classList.remove("active")
|
||||
localStorage.setItem("token", response.token)
|
||||
get_all_settings()
|
||||
await get_all_settings()
|
||||
adminpanelsection.classList.add('active')
|
||||
await get_user_data()
|
||||
loginusername.value = ""
|
||||
|
||||
+9
-34
@@ -2,44 +2,19 @@ const host = window.location.origin
|
||||
const prefix = 'api'
|
||||
|
||||
const routes = {
|
||||
login: () => [host, prefix, 'token'].join('/'),
|
||||
user: () => [host, prefix, 'users', 'user'].join('/'),
|
||||
login: () => ["http://localhost:43243", prefix, 'token'].join('/'),
|
||||
user: () => ["http://localhost:43243", 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('/'),
|
||||
ssh_server_get: () => [host, prefix, 'settings', 'ssh', 'server', 'get'].join('/'),
|
||||
ssh_server_set: () => [host, prefix, 'settings', 'ssh', 'server', '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('/'),
|
||||
|
||||
wifi_status_get: () => [host, prefix, 'settings', 'wifi', 'status', 'get'].join('/'),
|
||||
wifi_status_set: () => [host, prefix, 'settings', 'wifi', 'status', 'set'].join('/'),
|
||||
wifi_name_get: () => [host, prefix, 'settings', 'wifi', 'name', 'get'].join('/'),
|
||||
wifi_name_set: () => [host, prefix, 'settings', 'wifi', 'name', 'set'].join('/'),
|
||||
wifi_password_get: () => [host, prefix, 'settings', 'wifi', 'password', 'get'].join('/'),
|
||||
wifi_password_set: () => [host, prefix, 'settings', 'wifi', 'password', 'set'].join('/'),
|
||||
wifi_qr_get: () => [host, prefix, 'settings', 'wifi', 'qr', 'get'].join('/'),
|
||||
wifi_channel_get: () => [host, prefix, 'settings', 'wifi', 'channel', 'get'].join('/'),
|
||||
wifi_channel_set: () => [host, prefix, 'settings', 'wifi', 'channel', 'set'].join('/'),
|
||||
|
||||
settings_get: () => [host, prefix, 'settings', 'get'].join('/'),
|
||||
settings_set: () => [host, prefix, 'settings', 'set'].join('/'),
|
||||
settings_backup: () => [host, prefix, 'settings', 'backup'].join('/'),
|
||||
settings_restore: () => [host, prefix, 'settings', 'restore'].join('/'),
|
||||
restore_defaults: () => [host, prefix, 'settings', 'restore', 'defaults'].join('/'),
|
||||
|
||||
reboot: () => [host, prefix, 'reboot'].join('/'),
|
||||
syslog: () => [host, prefix, 'syslog'].join('/'),
|
||||
uptime: () => [host, prefix, 'uptime'].join('/'),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
const backup_settings_button = document.querySelector('#backup_settings')
|
||||
const restore_setings_button = document.querySelector('#restore_settings')
|
||||
const restore_settings_input = document.querySelector('#restore_settings_input')
|
||||
const start_restore_settings = document.querySelector('#start_restore_settings')
|
||||
const restore_default_settings = document.querySelector('#restore_default_settings')
|
||||
|
||||
backup_settings_button.href = routes.settings_backup()
|
||||
|
||||
restore_setings_button.addEventListener('click', () => restore_settings_input.click())
|
||||
|
||||
start_restore_settings.addEventListener('click', () => {
|
||||
let restore_file = restore_settings_input.files[0]
|
||||
console.log(restore_file)
|
||||
let formData = new FormData()
|
||||
formData.append('restore_settings', restore_file)
|
||||
fetch(routes.settings_restore(), {method:"POST", body: formData})
|
||||
.then(data => data.json())
|
||||
.then(jsondata => {
|
||||
console.log(jsondata)
|
||||
if (jsondata.status) {
|
||||
notification('Настройки применены', 'success')
|
||||
get_all_settings()
|
||||
} else {
|
||||
notification('Некорректный файл', 'error')
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
})
|
||||
|
||||
restore_default_settings.addEventListener('click', () => {
|
||||
fetch(routes.restore_defaults(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
if (jsondata.status) {
|
||||
notification(`Настройки успешно сохранены`, "success");
|
||||
get_all_settings()
|
||||
} else {
|
||||
notification(`Неизвестная ошибка`, "error");
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
})
|
||||
|
||||
// restore_settings_input.addEventListener('click', () => {
|
||||
|
||||
// })
|
||||
@@ -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'))
|
||||
}
|
||||
+43
-114
@@ -2,9 +2,7 @@ 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 localdomainstablebody = document.querySelector('#domainsstablebody')
|
||||
const addlocaldomainbutton = document.querySelector('#add_local_domain_button')
|
||||
|
||||
@@ -12,46 +10,27 @@ 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}}`
|
||||
}).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")
|
||||
})
|
||||
dnsenabled.checked = settings.dns.enabled
|
||||
if (settings.dns.enabled) {
|
||||
dnssettingbody.classList.add('active')
|
||||
adddnsserverbutton.classList.add('active')
|
||||
addlocaldomainbutton.classList.add('active')
|
||||
} else {
|
||||
adddnsserverbutton.parentElement.classList.add('onebutton')
|
||||
dnssettingbody.classList.remove('active')
|
||||
adddnsserverbutton.classList.remove('active')
|
||||
addlocaldomainbutton.classList.remove('active')
|
||||
}
|
||||
}
|
||||
|
||||
const set_dns_settings = () => {
|
||||
set_dns_enabled_status()
|
||||
if (dnsenabled.checked) {
|
||||
set_dns_server()
|
||||
set_local_domains()
|
||||
}
|
||||
settings.dns.enabled = dnsenabled.checked
|
||||
settings.dns.servers = dnsservers
|
||||
settings.dns.localdomains = localdomains
|
||||
set_all_settings()
|
||||
dnsenabled.checked = settings.dns.enabled
|
||||
get_dns_server()
|
||||
get_local_domains()
|
||||
}
|
||||
|
||||
setdnssettingsbutton.addEventListener('click', () => {
|
||||
@@ -76,41 +55,16 @@ dnsenabled.addEventListener('click', () => {
|
||||
})
|
||||
|
||||
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")
|
||||
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")
|
||||
})
|
||||
dnsservers = settings.dns.servers
|
||||
dnsserverstablebody.innerHTML = ""
|
||||
for (const server in settings.dns.servers) {
|
||||
dnsserverstablebody.innerHTML += `<tr>
|
||||
<th class="one">
|
||||
${settings.dns.servers[server]}
|
||||
<button class="deldnsserverbutton" id="${settings.dns.servers[server]}">Del</button>
|
||||
</th>
|
||||
</tr>`
|
||||
}
|
||||
}
|
||||
|
||||
adddnsserverbutton.addEventListener('click', () => {
|
||||
@@ -118,7 +72,7 @@ adddnsserverbutton.addEventListener('click', () => {
|
||||
if (dnsserver === null) return
|
||||
if (confirm('Confirm DNS settings? (add DNS server)')) {
|
||||
dnsservers.push(dnsserver)
|
||||
set_dns_server()
|
||||
set_dns_settings()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -126,7 +80,7 @@ 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()
|
||||
set_dns_settings()
|
||||
}
|
||||
get_dns_server()
|
||||
}
|
||||
@@ -135,42 +89,17 @@ dnsserverstablebody.addEventListener('click', (e) => {
|
||||
// ---------------------- 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")
|
||||
})
|
||||
localdomains = settings.dns.localdomains
|
||||
localdomainstablebody.innerHTML = ""
|
||||
for (const domain in settings.dns.localdomains) {
|
||||
localdomainstablebody.innerHTML += `<tr>
|
||||
<th class="three">${settings.dns.localdomains[domain].ip}</th>
|
||||
<th class="three" style="display:flex;align-items:center;justify-content:space-between;width:100%">
|
||||
${settings.dns.localdomains[domain].domain}
|
||||
<button class="deldomain" id="${settings.dns.localdomains[domain].domain}">Del</button>
|
||||
</th>
|
||||
</tr>`
|
||||
}
|
||||
}
|
||||
|
||||
addlocaldomainbutton.addEventListener('click', () => {
|
||||
@@ -180,7 +109,7 @@ addlocaldomainbutton.addEventListener('click', () => {
|
||||
if (domainip === null || domain === null) return
|
||||
if (confirm(`Confirm DNS settings? (Add Local Domain: ${domainip} ${domain})`)) {
|
||||
localdomains.push({ "ip": domainip, "domain": domain })
|
||||
set_local_domains()
|
||||
set_dns_settings()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -188,7 +117,7 @@ localdomainstablebody.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()
|
||||
set_dns_settings()
|
||||
}
|
||||
get_local_domains()
|
||||
}
|
||||
|
||||
@@ -2,33 +2,13 @@ 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")
|
||||
})
|
||||
ftpenabled.checked = settings.ftp.enabled
|
||||
}
|
||||
|
||||
const set_ftp_enabled_status = () => {
|
||||
fetch(routes.ftp_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":${ftpenabled.checked}}`
|
||||
}).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")
|
||||
})
|
||||
settings.ftp.enabled = ftpenabled.checked
|
||||
set_all_settings()
|
||||
ftpenabled.checked = settings.ftp.enabled
|
||||
}
|
||||
|
||||
setftpsettingsbutton.addEventListener('click', () => {
|
||||
|
||||
@@ -1,20 +1,42 @@
|
||||
const get_all_settings = () => {
|
||||
get_dns_enabled_status()
|
||||
get_dns_server()
|
||||
get_local_domains()
|
||||
let settings = {}
|
||||
|
||||
get_ftp_enabled_status()
|
||||
|
||||
get_telnet_enabled_status()
|
||||
get_telnet_port()
|
||||
const get_all_settings = async () => {
|
||||
settings = await fetch(routes.settings_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
return jsondata.settings
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
|
||||
get_ssh_status()
|
||||
get_ssh_keys()
|
||||
get_ssh_port()
|
||||
get_ssh_server()
|
||||
|
||||
get_telnet_enabled_status()
|
||||
get_telnet_port()
|
||||
|
||||
get_ftp_enabled_status()
|
||||
|
||||
get_dns_enabled_status()
|
||||
get_dns_server()
|
||||
get_local_domains()
|
||||
|
||||
get_wifi_status()
|
||||
get_wifi_name()
|
||||
get_wifi_channel()
|
||||
// get_wifi_password()
|
||||
}
|
||||
|
||||
const set_all_settings = async () => {
|
||||
settings = await fetch(routes.settings_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","settings":${JSON.stringify(settings)}}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
notification("Настройки сохранены", "success")
|
||||
return jsondata.settings
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
+38
-108
@@ -10,42 +10,38 @@ 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")
|
||||
})
|
||||
sshenable.checked = settings.ssh.enabled
|
||||
if (settings.ssh.enabled) {
|
||||
sshsettingsbody.classList.add('active')
|
||||
add_ssh_key_button.classList.add('active')
|
||||
add_ssh_key_button.parentElement.classList.remove('onebutton')
|
||||
} else {
|
||||
sshsettingsbody.classList.remove('active')
|
||||
add_ssh_key_button.classList.remove('active')
|
||||
add_ssh_key_button.parentElement.classList.add('onebutton')
|
||||
}
|
||||
}
|
||||
|
||||
const set_ssh_status = () => {
|
||||
fetch(routes.ssh_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","status":${sshenable.checked}}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
if (jsondata.status === '1') {
|
||||
sshenable.checked = true
|
||||
// telnetsettingbody.classList.add('active')
|
||||
const set_ssh_settings_func = () => {
|
||||
settings.ssh.enabled = sshenable.checked
|
||||
settings.ssh.keys = sshkeys
|
||||
settings.ssh.port = sshportinput.value
|
||||
settings.ssh.server = sshserverinput.options[sshserverinput.selectedIndex].value
|
||||
set_all_settings()
|
||||
sshenable.checked = settings.ssh.enabled
|
||||
get_ssh_keys()
|
||||
sshportinput.value = settings.ssh.port
|
||||
for (let i = 0; i < sshserverinput.options.length; i++) {
|
||||
if (sshserverinput.options[i].value === settings.ssh.server) {
|
||||
sshserverinput.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
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()
|
||||
set_ssh_server()
|
||||
set_ssh_settings_func()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -63,41 +59,16 @@ sshenable.addEventListener('click', () => {
|
||||
|
||||
// -------------------- SSH keys ---------------------------------
|
||||
const get_ssh_keys = () => {
|
||||
fetch(routes.ssh_keys_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
sshkeys = jsondata.keys
|
||||
sshkeystablebody.innerHTML = ""
|
||||
for (const key in sshkeys) {
|
||||
sshkeystablebody.innerHTML += `<tr>
|
||||
sshkeys = settings.ssh.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 ------------------------------
|
||||
|
||||
@@ -105,7 +76,7 @@ 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()
|
||||
set_ssh_settings_func()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -115,63 +86,22 @@ add_ssh_key_button.addEventListener('click', () => {
|
||||
if (sshkey === null) return
|
||||
if (confirm('Confirm SSH settings? (add SSH key)')) {
|
||||
sshkeys.push(sshkey)
|
||||
set_ssh_keys()
|
||||
set_ssh_settings_func()
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------- 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")
|
||||
})
|
||||
sshportinput.value = settings.ssh.port
|
||||
}
|
||||
// ------------------- end SSH port -------------------
|
||||
|
||||
|
||||
const get_ssh_server = () => {
|
||||
fetch(routes.ssh_server_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
for (let i = 0; i < sshserverinput.options.length; i++) {
|
||||
if (sshserverinput.options[i].value === jsondata.server) {
|
||||
sshserverinput.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
for (let i = 0; i < sshserverinput.options.length; i++) {
|
||||
if (sshserverinput.options[i].value === settings.ssh.server) {
|
||||
sshserverinput.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
const set_ssh_server = () => {
|
||||
fetch(routes.ssh_server_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","server":"${sshserverinput.options[sshserverinput.selectedIndex].value}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
for (let i = 0; i < sshserverinput.options.length; i++) {
|
||||
if (sshserverinput.options[i].value === jsondata.server) {
|
||||
sshserverinput.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,33 @@
|
||||
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}}`
|
||||
}).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.checked = settings.telnet.enabled
|
||||
if (settings.telnet.enabled) {
|
||||
telnetsettingbody.classList.add('active')
|
||||
} else {
|
||||
telnetsettingbody.classList.remove('active')
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
start_loader()
|
||||
settings.telnet.enabled = telnetenabled.checked
|
||||
settings.telnet.port = telnetportinput.value
|
||||
set_all_settings()
|
||||
telnetenabled.checked = settings.telnet.enabled
|
||||
telnetportinput.value = settings.telnet.port
|
||||
stop_loader()
|
||||
}
|
||||
|
||||
settelnetsettingsbutton.addEventListener('click', () => {
|
||||
@@ -65,26 +37,5 @@ settelnetsettingsbutton.addEventListener('click', () => {
|
||||
})
|
||||
|
||||
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")
|
||||
})
|
||||
telnetportinput.value = settings.telnet.port
|
||||
}
|
||||
|
||||
+21
-92
@@ -13,74 +13,17 @@ const channelselect = document.querySelector('#wifichannel')
|
||||
let old_wifi_name = ""
|
||||
|
||||
const get_wifi_status = () => {
|
||||
fetch(routes.wifi_status_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
if (jsondata.status == "1") {
|
||||
wifistatus.checked = true
|
||||
wifisettingsbody.classList.add('active')
|
||||
} else {
|
||||
wifistatus.checked = false
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
const set_wifi_status = () => {
|
||||
fetch(routes.wifi_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}","status":${wifistatus.checked}}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
if (jsondata.status === "1") {
|
||||
wifistatus.checked = true
|
||||
wifisettingsbody.classList.add('active')
|
||||
notification("Настройки WIFI оспешно сорранены", "success")
|
||||
return
|
||||
}
|
||||
wifistatus.checked = false
|
||||
wifistatus.checked = settings.wifi.enabled
|
||||
if (settings.wifi.enabled) {
|
||||
wifisettingsbody.classList.add('active')
|
||||
} else {
|
||||
wifisettingsbody.classList.remove('active')
|
||||
notification("Настройки WIFI оспешно сорранены", "success")
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const get_wifi_name = () => {
|
||||
fetch(routes.wifi_name_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
wifissid.value = jsondata.name
|
||||
old_wifi_name = jsondata.name
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
const set_wifi_name = () => {
|
||||
fetch(routes.wifi_name_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}","name":"${wifissid.value}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
wifissid.value = jsondata.name
|
||||
old_wifi_name = jsondata.name
|
||||
notification("Имя WIFI оспешно сорранено", "success")
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
const get_wifi_password = () => {
|
||||
fetch(routes.wifi_password_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
wifipassword.value = jsondata.password
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
wifissid.value = settings.wifi.name
|
||||
old_wifi_name = settings.wifi.name
|
||||
}
|
||||
|
||||
const set_wifi_password = () => {
|
||||
@@ -103,15 +46,19 @@ const set_wifi_password = () => {
|
||||
const set_wifi_settings = () => {
|
||||
if (confirm("Confirm wifi settings?")) {
|
||||
start_loader()
|
||||
set_wifi_status()
|
||||
if (wifistatus.checked) {
|
||||
set_wifi_channel()
|
||||
if (old_wifi_name !== wifissid.value) {
|
||||
set_wifi_name()
|
||||
}
|
||||
if (wifipassword.value !== "" && newwifipassword.value !== "") {
|
||||
set_wifi_password()
|
||||
}
|
||||
settings.wifi.enabled = wifistatus.checked
|
||||
settings.wifi.name = wifissid.value
|
||||
settings.wifi.channel = channelselect.value
|
||||
set_all_settings()
|
||||
wifistatus.checked = settings.wifi.enabled
|
||||
if (settings.wifi.enabled) {
|
||||
wifisettingsbody.classList.add('active')
|
||||
}
|
||||
wifissid.value = settings.wifi.name
|
||||
old_wifi_name = settings.wifi.name
|
||||
channelselect.value = settings.wifi.channel
|
||||
if (wifipassword.value !== "" && newwifipassword.value !== "") {
|
||||
set_wifi_password()
|
||||
}
|
||||
stop_loader()
|
||||
}
|
||||
@@ -166,23 +113,5 @@ wifiqr.addEventListener('click', () => {
|
||||
})
|
||||
|
||||
const get_wifi_channel = () => {
|
||||
fetch(routes.wifi_channel_get(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
channelselect.value = jsondata.channel
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
channelselect.value = settings.wifi.channel
|
||||
}
|
||||
|
||||
const set_wifi_channel = () => {
|
||||
fetch(routes.wifi_channel_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem('token')}","channel":"${channelselect.value}"}`
|
||||
}).then(data => data.json()).then(jsondata => {
|
||||
channelselect.value = jsondata.channel
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user