From 5fbd56ef7abec021424b493470031c1b56ebba75 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Tue, 2 Jul 2024 17:28:25 +0700 Subject: [PATCH] added sshkeys and ssh port --- CMakeLists.txt | 4 + src/openrouter.cpp | 8 ++ src/settings/ssh/keys.cpp | 93 +++++++++++++++++++++ src/settings/ssh/port.cpp | 101 +++++++++++++++++++++++ src/settings/ssh/ssh.hpp | 15 ++++ src/settings/ssh/status.cpp | 94 +++++++++++++++++++++ src/web/css/settings.css | 6 +- src/web/index.html | 28 +++++++ src/web/js/reboot.js | 4 +- src/web/js/routes.js | 7 ++ src/web/js/settings/dns.js | 27 ++++-- src/web/js/settings/ftp.js | 4 +- src/web/js/settings/settings.js | 4 + src/web/js/settings/ssh.js | 142 ++++++++++++++++++++++++++++++++ src/web/js/settings/telnet.js | 4 +- 15 files changed, 528 insertions(+), 13 deletions(-) create mode 100644 src/settings/ssh/keys.cpp create mode 100644 src/settings/ssh/port.cpp create mode 100644 src/settings/ssh/ssh.hpp create mode 100644 src/settings/ssh/status.cpp create mode 100644 src/web/js/settings/ssh.js diff --git a/CMakeLists.txt b/CMakeLists.txt index d9a02b5..0ff2a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,10 @@ add_executable( src/settings/telnet/enabled.cpp src/settings/telnet/port.cpp + src/settings/ssh/status.cpp + src/settings/ssh/keys.cpp + src/settings/ssh/port.cpp + src/settings/dns/enabled.cpp src/settings/dns/servers.cpp src/settings/dns/local_domains.cpp diff --git a/src/openrouter.cpp b/src/openrouter.cpp index f9f0a7d..273b1a5 100644 --- a/src/openrouter.cpp +++ b/src/openrouter.cpp @@ -2,6 +2,7 @@ #include #include #include "settings/telnet/telnet.hpp" +#include "settings/ssh/ssh.hpp" #include "settings/dns/dns.hpp" #include "settings/ftp/ftp.hpp" #include "reboot/reboot.hpp" @@ -17,6 +18,13 @@ int main() { srv.Post("/api/settings/telnet/port/get", get_telnet_port); srv.Post("/api/settings/telnet/port/set", set_telnet_port); + srv.Post("/api/settings/ssh/status/get", get_ssh_status); + srv.Post("/api/settings/ssh/status/set", set_ssh_status); + srv.Post("/api/settings/ssh/keys/get", get_ssh_keys); + srv.Post("/api/settings/ssh/keys/set", set_ssh_keys); + srv.Post("/api/settings/ssh/port/get", get_ssh_port); + srv.Post("/api/settings/ssh/port/set", set_ssh_port); + srv.Post("/api/settings/dns/get", get_dns); srv.Post("/api/settings/dns/set", set_dns); srv.Post("/api/settings/dns/servers/get", get_dns_servers); diff --git a/src/settings/ssh/keys.cpp b/src/settings/ssh/keys.cpp new file mode 100644 index 0000000..1e4f7e6 --- /dev/null +++ b/src/settings/ssh/keys.cpp @@ -0,0 +1,93 @@ +#include "ssh.hpp" +#include +#include +#include "../../routes.hpp" +#include "../../types.hpp" + +#define KEYS_PATH "/root/.ssh/authorized_keys" + +void get_ssh_keys(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ifstream keysfile(KEYS_PATH); + std::stringstream responsedata; + responsedata << R"({"keys":[)"; + std::string key_string = ""; + int iter = 0; + while (std::getline(keysfile, key_string)) { + if (key_string == "") { + continue; + } + responsedata << R"(")" << key_string << R"(",)"; + key_string = ""; + iter++; + } + if (iter != 0) { + responsedata.str(responsedata.str().erase(responsedata.str().size()-1, 1) + "]}"); + } else { + responsedata << "]}"; + } + keysfile.close(); + response.set_content(responsedata.str(), JSON_TYPE); + } +} +void set_ssh_keys(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ofstream keysfile(KEYS_PATH); + nlohmann::json keys = json_body["keys"]; + for (std::string key : keys) { + keysfile << key << "\n"; + } + keysfile.close(); + system("/etc/init.d/ssh restart"); + std::string responsedata = R"({"success":"true"})"; + response.set_content(responsedata, JSON_TYPE); + } +} \ No newline at end of file diff --git a/src/settings/ssh/port.cpp b/src/settings/ssh/port.cpp new file mode 100644 index 0000000..0e89975 --- /dev/null +++ b/src/settings/ssh/port.cpp @@ -0,0 +1,101 @@ +#include "ssh.hpp" +#include +#include "../../types.hpp" +#include "../../routes.hpp" +#include +#include +#include +#include +#include + +#define SSH_PORT_REQUIRED_STRING R"({"required":"[token,port]"})" +#define SSH_PORT_PATH "/etc/openrouter/ssh/port" + +void get_ssh_port(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ifstream sshportfile(SSH_PORT_PATH); + int ssh_port; + sshportfile >> ssh_port; + sshportfile.close(); + std::stringstream responsedata; + responsedata << R"({"port":")" << ssh_port << R"("})"; + response.set_content(responsedata.str(), JSON_TYPE); + } +} +void set_ssh_port(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + if (json_body["port"] == nullptr) { + response.set_content(SSH_PORT_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ifstream oldsshportfile(SSH_PORT_PATH); + int old_ssh_port; + oldsshportfile >> old_ssh_port; + oldsshportfile.close(); + std::ofstream sshportfileout(SSH_PORT_PATH); + std::string new_ssh_port = json_body["port"]; + sshportfileout << stoi(new_ssh_port); + sshportfileout.close(); + std::stringstream systemrequest; + systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config"; + std::cout << systemrequest.str() << std::endl; + system(systemrequest.str().c_str()); + system("/etc/init.d/ssh restart"); + std::ifstream sshportfile(SSH_PORT_PATH); + int ssh_port; + sshportfile >> ssh_port; + sshportfile.close(); + std::stringstream responsedata; + responsedata << R"({"port":")" << ssh_port << R"("})"; + response.set_content(responsedata.str(), JSON_TYPE); + } +} diff --git a/src/settings/ssh/ssh.hpp b/src/settings/ssh/ssh.hpp new file mode 100644 index 0000000..d6671fb --- /dev/null +++ b/src/settings/ssh/ssh.hpp @@ -0,0 +1,15 @@ +#ifndef SSH_HPP +#define SSH_HPP + +#include + +void get_ssh_status(const httplib::Request &request, httplib::Response &response); +void set_ssh_status(const httplib::Request &request, httplib::Response &response); + +void get_ssh_keys(const httplib::Request &request, httplib::Response &response); +void set_ssh_keys(const httplib::Request &request, httplib::Response &response); + +void get_ssh_port(const httplib::Request &request, httplib::Response &response); +void set_ssh_port(const httplib::Request &request, httplib::Response &response); + +#endif // SSH_HPP diff --git a/src/settings/ssh/status.cpp b/src/settings/ssh/status.cpp new file mode 100644 index 0000000..27e12ed --- /dev/null +++ b/src/settings/ssh/status.cpp @@ -0,0 +1,94 @@ +#include "ssh.hpp" +#include +#include +#include "../../routes.hpp" +#include "../../types.hpp" + +#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})" + +void get_ssh_status(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ifstream sshstatusfile("/etc/openrouter/ssh/status"); + int ssh_status; + sshstatusfile >> ssh_status; + sshstatusfile.close(); + std::stringstream responsedata; + responsedata << R"({"status":")" << ssh_status << R"("})"; + response.set_content(responsedata.str(), JSON_TYPE); + } +} +void set_ssh_status(const httplib::Request &request, httplib::Response &response) { + std::cout << GREEN << request.path << RESET << " " << request.method << std::endl; + response.set_header("Access-Control-Allow-Origin", "*"); + if (request.body.empty()) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + nlohmann::json json_body = nlohmann::json::parse(request.body); + if (json_body["token"] == nullptr) { + response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE); + return; + } + + if (json_body["status"] == nullptr) { + response.set_content(SSH_REQUIRED_STRING, JSON_TYPE); + return; + } + + httplib::Client cli(AUTH_SERVICE); + + std::stringstream body; + body << R"({"token":)" << json_body["token"] << R"(})"; + + httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE); + if (res->status == httplib::OK_200) { + nlohmann::json resjson = nlohmann::json::parse(res->body); + if (resjson["access"] == "reject") { + response.set_content(resjson.dump().c_str(), JSON_TYPE); + return; + } + std::ofstream sshfileout("/etc/openrouter/ssh/status"); + std::string new_ssh_status = json_body["status"]; + if (new_ssh_status == "0") { + system("/etc/init.d/ssh stop"); + system("rm /etc/rc.d/75ssh"); + } else { + system("/etc/init.d/ssh start"); + system("ln -sv /etc/init.d/ssh /etc/rc.d/75ssh"); + } + sshfileout << stoi(new_ssh_status); + sshfileout.close(); + std::ifstream sshfile("/etc/openrouter/ssh/status"); + int ssh_status; + sshfile >> ssh_status; + sshfile.close(); + std::stringstream responsedata; + responsedata << R"({"status":")" << ssh_status << R"("})"; + response.set_content(responsedata.str(), JSON_TYPE); + } +} diff --git a/src/web/css/settings.css b/src/web/css/settings.css index f830117..5ab5d13 100644 --- a/src/web/css/settings.css +++ b/src/web/css/settings.css @@ -66,6 +66,7 @@ } .settingssection { + padding: 10px; display: flex; /* flex-direction: column; */ gap: 10px; @@ -93,7 +94,7 @@ .settingrectbody { width: 100%; max-height: 0; - overflow: hidden; + overflow: auto; transition: 0.3s; } @@ -103,6 +104,7 @@ } .settingrectbody>table { + position: relative; width: 100%; text-align: left; transition: 0.3s; @@ -178,6 +180,8 @@ tbody>tr>th { padding: 10px; border-radius: 10px; width: 50%; + max-width:425px; + overflow-x: auto; /* display: flex; align-items: center; justify-content: space-between; */ diff --git a/src/web/index.html b/src/web/index.html index 0f75944..ea1316b 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -114,6 +114,33 @@ + +
+
+

SSH

+
+ +
+
+
+
+ + +
+ + + + + + +
SSH keys
+
+
+ + +
+
+ @@ -200,6 +227,7 @@ + diff --git a/src/web/js/reboot.js b/src/web/js/reboot.js index c64ec4b..e61835e 100644 --- a/src/web/js/reboot.js +++ b/src/web/js/reboot.js @@ -1,7 +1,9 @@ const rebootbutton = document.querySelector('#rebootbutton') rebootbutton.addEventListener('click', () => { - get_confirm_form("Confirm reboot?", reboot) + if (confirm("Confirm reboot?")) { + reboot() + } }) const reboot = () => { diff --git a/src/web/js/routes.js b/src/web/js/routes.js index 7560c54..22c871a 100644 --- a/src/web/js/routes.js +++ b/src/web/js/routes.js @@ -11,6 +11,13 @@ const routes = { telnet_port_get: () => [host, prefix, 'settings', 'telnet', 'port', 'get'].join('/'), telnet_port_set: () => [host, prefix, 'settings', 'telnet', 'port', 'set'].join('/'), + ssh_status_get: () => [host, prefix, 'settings', 'ssh', 'status', 'get'].join('/'), + ssh_status_set: () => [host, prefix, 'settings', 'ssh', 'status', 'set'].join('/'), + ssh_keys_get: () => [host, prefix, 'settings', 'ssh', 'keys', 'get'].join('/'), + ssh_keys_set: () => [host, prefix, 'settings', 'ssh', 'keys', 'set'].join('/'), + ssh_port_get: () => [host, prefix, 'settings', 'ssh', 'port', 'get'].join('/'), + ssh_port_set: () => [host, prefix, 'settings', 'ssh', 'port', 'set'].join('/'), + dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'), dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'), dns_servers_get: () => [host, prefix, 'settings', 'dns', 'servers', 'get'].join('/'), diff --git a/src/web/js/settings/dns.js b/src/web/js/settings/dns.js index f30efaf..7c924b9 100644 --- a/src/web/js/settings/dns.js +++ b/src/web/js/settings/dns.js @@ -65,7 +65,9 @@ const set_dns_settings = () => { } setdnssettingsbutton.addEventListener('click', () =>{ - get_confirm_form("Confirm DNS settings?", set_dns_settings) + if (confirm("Confirm DNS settings?")) { + set_dns_settings() + } }) dnsenabled.addEventListener('click', () => { @@ -144,13 +146,19 @@ adddnsserverconfirmbutton.addEventListener('click', () => { if (adddnsserverinput.value === "") { return } - get_confirm_form(`Confirm DNS settings? (Add DNS server: ${adddnsserverinput.value})`, set_dns_server, cancel_confirm_add_dns_server) + if (confirm(`Confirm DNS settings? (Add DNS server: ${adddnsserverinput.value})`)) { + set_dns_server() + } else { + cancel_confirm_add_dns_server + } }) dnsserverstablebody.addEventListener('click', (e) => { if (e.target.classList.contains('deldnsserverbutton')) { dnsservers.splice(dnsservers.indexOf(e.target.id), 1) - set_dns_server() + if (confirm(`Confirm DNS settings? (delete DNS server: ${e.target.id})`)) { + set_dns_server() + } get_dns_server() } }) @@ -213,21 +221,22 @@ addlocaldomaincancelbutton.addEventListener('click', () => { addlocaldomainconfirmbutton.addEventListener('click', () => { addlocaldomainform.classList.remove('active') - get_confirm_form(`Confirm DNS settings? (Add Local Domain: ${ipinput.value} ${domaininput.value})`, () => { + if (confirm(`Confirm DNS settings? (Add Local Domain: ${ipinput.value} ${domaininput.value})`)) { localdomains.push({"ip": ipinput.value, "domain": domaininput.value}); set_local_domains() ipinput.value = "" domaininput.value = "" - }, cancel_confirm_add_localdomain) + } else { + cancel_confirm_add_localdomain() + } }) domainstablebody.addEventListener('click', (e) => { if (e.target.classList.contains('deldomain')) { - // const delel = localdomains.find(dom => dom.domain === e.target.id) - // delete localdomains.domains[localdomains.indexOf(delel)] localdomains.splice(localdomains.indexOf(localdomains.find(dom => dom.domain === e.target.id)), 1) - // get_confirm_form(`Confirm DNS settings? (delete Local Domain: ${e.target.id})`, () => set_local_domains(localdomains)) - set_local_domains() + if (confirm(`Confirm DNS settings? (delete Local Domain: ${e.target.id})`)) { + set_local_domains() + } get_local_domains() } }) diff --git a/src/web/js/settings/ftp.js b/src/web/js/settings/ftp.js index d7a3ca1..cb8ae9e 100644 --- a/src/web/js/settings/ftp.js +++ b/src/web/js/settings/ftp.js @@ -32,5 +32,7 @@ const set_ftp_enabled_status = () => { } setftpsettingsbutton.addEventListener('click', () =>{ - get_confirm_form("Confirm ftp settings?", set_ftp_enabled_status) + if (confirm("Confirm ftp settings?")) { + set_ftp_enabled_status() + } }) diff --git a/src/web/js/settings/settings.js b/src/web/js/settings/settings.js index bc027ae..5cc4a55 100644 --- a/src/web/js/settings/settings.js +++ b/src/web/js/settings/settings.js @@ -7,4 +7,8 @@ const get_all_settings = () => { get_telnet_enabled_status() get_telnet_port() + + get_ssh_status() + get_ssh_keys() + get_ssh_port() } diff --git a/src/web/js/settings/ssh.js b/src/web/js/settings/ssh.js new file mode 100644 index 0000000..8f170bb --- /dev/null +++ b/src/web/js/settings/ssh.js @@ -0,0 +1,142 @@ +const sshenable = document.querySelector('#sshenable') +const set_ssh_settings = document.querySelector('#set_ssh_settings') +const sshsettingsbody = document.querySelector('#sshsettingsbody') +const sshkeystablebody = document.querySelector('#sshkeystablebody') +const sshportinput = document.querySelector('#sshportinput') +const add_ssh_key_button = document.querySelector('#add_ssh_key') + +let sshkeys = [] + +// -------------------- SSH status -------------------------------- +const get_ssh_status = () => { + fetch(routes.ssh_status_get(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}"}` + }).then(data => data.json()).then(jsondata => { + if (jsondata.status === '1') { + sshenable.checked = true + sshsettingsbody.classList.add('active') + add_ssh_key_button.classList.add('active') + add_ssh_key_button.parentElement.classList.remove('onebutton') + } + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} + +const set_ssh_status = () => { + fetch(routes.ssh_status_set(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}","status":"${sshenable.checked?1:0}"}` + }).then(res => res.json()).then(jsondata => { + if (jsondata.status === '1') { + sshenable.checked = true + // telnetsettingbody.classList.add('active') + } + notification("Настройки SSH сохранены", "success") + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} +// -------------------------------- end SSH status --------------------------------------- + +set_ssh_settings.addEventListener('click', () => { + if (confirm("Confirm SSH settings?")) { + set_ssh_status() + set_ssh_port() + } +}) + +sshenable.addEventListener('click', () => { + if (sshenable.checked) { + sshsettingsbody.classList.add('active') + add_ssh_key_button.classList.add('active') + add_ssh_key_button.parentElement.classList.remove('onebutton') + return + } + sshsettingsbody.classList.remove('active') + add_ssh_key_button.classList.remove('active') + add_ssh_key_button.parentElement.classList.add('onebutton') +}) + +// -------------------- SSH keys --------------------------------- +const get_ssh_keys = () => { + fetch(routes.ssh_keys_get(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}"}` + }).then(data => data.json()).then(jsondata => { + console.log(jsondata.keys) + sshkeys = jsondata.keys + sshkeystablebody.innerHTML = "" + for (const key in sshkeys) { + sshkeystablebody.innerHTML += ` + + ${sshkeys[key]} + + + ` + } + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} + +const set_ssh_keys = () => { + start_loader() + fetch(routes.ssh_keys_set(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}","keys":${JSON.stringify(sshkeys)}}` + }).then(data => data.json()).then(jsondata => { + stop_loader() + if (jsondata.success) { + get_ssh_keys() + notification("Настройки SSH сохранены", "success") + } else { + notification("Неизвестная ошибка", "error") + } + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} +// ------------------- end SSH keys ------------------------------ + +sshkeystablebody.addEventListener('click', (e) => { + if (e.target.classList.contains('delsshkeybutton')) { + if (confirm(`Confirm SSH settings?: (delete SSH key)`)) { + sshkeys.splice(e.target.id) + set_ssh_keys() + } + } +}) + +add_ssh_key_button.addEventListener('click', () => { + const sshkey = prompt('Get your SSH key:') + if (confirm('Confirm SSH settings? (add SSH key)')) { + sshkeys.push(sshkey) + set_ssh_keys() + } +}) + +// -------------------- SSH port ---------------------- +const get_ssh_port = () => { + fetch(routes.ssh_port_get(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}"}` + }).then(data => data.json()).then(jsondata => { + sshportinput.value = jsondata.port + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} + +const set_ssh_port = () => { + fetch(routes.ssh_port_set(), { + method: 'POST', + body: `{"token":"${localStorage.getItem("token")}","port":"${sshportinput.value}"}` + }).then(data => data.json()).then(jsondata => { + sshportinput.value = jsondata.port + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +} +// ------------------- end SSH port ------------------- diff --git a/src/web/js/settings/telnet.js b/src/web/js/settings/telnet.js index d80fb78..b5bba63 100644 --- a/src/web/js/settings/telnet.js +++ b/src/web/js/settings/telnet.js @@ -59,7 +59,9 @@ const set_telnet_settings = () => { } settelnetsettingsbutton.addEventListener('click', () => { - get_confirm_form("Confirm telnet settings?", set_telnet_settings) + if (confirm("Confirm telnet settings?")) { + set_telnet_settings() + } }) const get_telnet_port = () => {