added telnet and reboot control, openrouterinit script

This commit is contained in:
wt committed 2024-06-26 15:59:10 +07:00
1 parent 0937112f04
commit 5279a9a6a6
23 files changed
+839 -26

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"format": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"semaphore": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"text_encoding": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
}
}
+3 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 2.6)
project(openrouter)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
include_directories(./src/libs/)
@@ -8,4 +8,6 @@ add_executable(
openrouter
src/openrouter.cpp
src/security/cors.cpp
src/settings/telnet/telnet.cpp
src/reboot/reboot.cpp
)
+35
View File
@@ -0,0 +1,35 @@
#!/bin/sh
Green='\033[0;32m'
Color_Off='\033[0m'
Red='\033[0;31m'
case "$1" in
start)
printf "Starting openrouter software "
cd /srv/ftpd/auth_service_router/bin && ./auth_service &> /dev/null &
cd /srv/ftpd/openrouter_adminpanel/bin && ./openrouter &> /dev/null &
if [[ "$?" == "0" ]]; then
printf "[$Green OK $Color_Off]\n"
else
printf "[$Red ERR $Cpolor_Off]\n"
fi
;;
stop)
printf "Stopping openrouter software "
killall openrouter
killall auth_service
if [[ "$?" == "0" ]]; then
printf "[$Green OK $Color_Off]\n"
else
printf "[$Red ERR $Color_Off]\n"
fi
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "httpd init script usage: $0 {start|stop|restart}"
return 1
esac
return $?
+8 -2
View File
@@ -1,6 +1,8 @@
#include <iostream>
#include <httplib.h>
#include <colors.h>
#include "settings/telnet/telnet.hpp"
#include "reboot/reboot.hpp"
#define CORS_ENABLE
#include "security/cors.hpp"
@@ -8,6 +10,10 @@
int main() {
httplib::Server srv;
srv.Post("/api/settings/telnet/get", get_telnet);
srv.Post("/api/settings/telnet/set", set_telnet);
srv.Post("/api/reboot", reboot);
srv.Options("/(.*)", set_cors_headers);
srv.set_mount_point("/" , "../src/web");
@@ -15,8 +21,8 @@ int main() {
srv.set_mount_point("/css", "../src/web/css");
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW
<< "localhost" << RESET << ":" << CYAN << "43243" << RESET << " ]" << std::endl;
<< "0.0.0.0" << RESET << ":" << CYAN << "43244" << RESET << " ]" << std::endl;
srv.listen("localhost", 43244);
srv.listen("0.0.0.0", 43244);
return 0;
}
+35
View File
@@ -0,0 +1,35 @@
#include "reboot.hpp"
#include <json.hpp>
#include "../routes.hpp"
#include <colors.h>
#include "../types.hpp"
void reboot(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
system("reboot");
}
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef REBOOT_HPP
#define REBOOT_HPP
#include <httplib.h>
void reboot(const httplib::Request &request, httplib::Response &response);
#endif // REBOOT_HPP
+6
View File
@@ -0,0 +1,6 @@
#ifndef ROUTES_HPP
#define ROUTES_HPP
#define AUTH_SERVICE "http://localhost:43243"
#endif // ROUTES_HPP
+99
View File
@@ -0,0 +1,99 @@
#include "telnet.hpp"
#include <colors.h>
#include "../../types.hpp"
#include "../../routes.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#define TELNET_REQUIRED_STRING R"({"required":"[token,enabled]"})"
void get_telnet(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ifstream telnetfile("/etc/openrouter/telnet");
int telnet_enabled;
telnetfile >> telnet_enabled;
telnetfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
void set_telnet(const httplib::Request &request, httplib::Response &response) {
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty()) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr) {
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (json_body["enabled"] == nullptr) {
response.set_content(TELNET_REQUIRED_STRING, JSON_TYPE);
return;
}
httplib::Client cli(AUTH_SERVICE);
std::stringstream body;
body << R"({"token":)" << json_body["token"] << R"(})";
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
if (res->status == httplib::OK_200) {
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject") {
response.set_content(resjson.dump().c_str(), JSON_TYPE);
return;
}
std::ofstream telnetfileout("/etc/openrouter/telnet");
std::string new_telnet_enabled = json_body["enabled"];
if (new_telnet_enabled == "0") {
system("/etc/init.d/telnet stop");
system("rm /etc/rc.d/70telnet");
} else {
system("/etc/init.d/telnet start");
system("ln -sv /etc/init.d/telnet /etc/rc.d/70telnet");
}
telnetfileout << stoi(new_telnet_enabled);
telnetfileout.close();
std::ifstream telnetfile("/etc/openrouter/telnet");
int telnet_enabled;
telnetfile >> telnet_enabled;
telnetfile.close();
std::stringstream responsedata;
responsedata << R"({"enabled":")" << telnet_enabled << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef SETTINGS_TELNET_HPP
#define SETTINGS_TELNET_HPP
#include <httplib.h>
void get_telnet(const httplib::Request &request, httplib::Response &response);
void set_telnet(const httplib::Request &request, httplib::Response &response);
#endif // SETTINGS_TELNET_HPP
+10
View File
@@ -0,0 +1,10 @@
#ifndef TYPES_H
#define TYPES_H
#define ACCESS_REQUIRED_STRING R"({"required":"[token]"})"
#define JWT_SECRET_KEY "secret"
#define STRING403 R"({"status":"403"})"
#define JSON_TYPE "application/json"
#endif // TYPES_H
+19
View File
@@ -0,0 +1,19 @@
button {
padding: 10px;
border-radius: 10px;
border: none;
transition: 0.3s;
cursor: pointer;
}
button:hover {
opacity: 0.6;
}
.linkbutton {
background: transparent;
}
.linkbutton:hover {
text-decoration: underline;
}
+18
View File
@@ -1,4 +1,7 @@
.form {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
@@ -19,6 +22,10 @@
transform: scale(1);
}
.form.active>.formbody {
transform: scale(1);
}
.formbody {
width: 50%;
height: 50%;
@@ -44,6 +51,17 @@
flex-direction: column;
}
.forminputbody.confirmform {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
.forminputbody.confirmform>button {
width: 100%;
}
.forminputlabel {
text-align: center;
font-style: normal;
+20
View File
@@ -0,0 +1,20 @@
header {
width: 100vw;
height: 50px;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.links {
display: flex;
align-items: center;
gap: 10px;
}
.userbuttons {
display: flex;
align-items: center;
gap: 10px;
}
+13 -2
View File
@@ -1,6 +1,5 @@
:root {
color-scheme: light dark;
/* --font-color: light-dark(black, white); */
}
* {
@@ -12,5 +11,17 @@
body {
width: 100vw;
height: 100vh;
/* background-color: light-dark(white, black); */
}
.adminpanel {
width: 100%;
height: 100%;
transform: scale(0.5);
opacity: 0;
transition: 0.3s;
}
.adminpanel.active {
transform: scale(1);
opacity: 1;
}
+64
View File
@@ -0,0 +1,64 @@
.loader {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 0;
pointer-events: none;
display: grid;
z-index: 12;
backdrop-filter: blur(5px);
transition: 0.3s;
}
.loader>h1 {
opacity: 0;
width: 100%;
padding: 10px;
text-align: center;
}
.loadertip {
width: 0;
height: 0;
padding: 0;
margin: 0;
border-radius: 50%;
place-self: center;
z-index: 12;
position: relative;
transition: 0.3s;
}
.progress {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-top: 5px solid #56C1F9;
border-radius: 50%;
animation: loading 2s infinite ease-in-out;
}
.loader.active {
width: 100vw;
height: 100vh;
}
.loader.active > .loadertip {
width: 100px;
height: 100px;
border-bottom: 5px solid gray;
animation: loading 2s infinite ease-in-out;
}
.loader.active>h1 {
opacity: 1;
}
@keyframes loading {
100% {
transform: rotate(360deg);
}
}
+43
View File
@@ -0,0 +1,43 @@
.notification {
width: max-content;
height: 0;
overflow: hidden;
pointer-events: none;
z-index: 10;
border-radius: 10px;
position: fixed;
top: 0;
right: 0;
transition: 0.3s;
cursor: pointer;
opacity: 0.8;
margin: 10px;
padding: 0 10px;
}
.notificationtextbox {
width: 100%;
height: 100%;
display: grid;
justify-items: center;
align-items: center;
pointer-events: none;
}
.notificationtext {
width: 100%;
text-align: center;
pointer-events: none;
}
.notification.active.error {
pointer-events: all;
height: 10%;
background-color: rgb(233, 70, 70);
}
.notification.active.success {
pointer-events: all;
height: 10%;
background-color: rgb(76, 209, 76);
}
+146
View File
@@ -0,0 +1,146 @@
.checkbox-wrapper-2 .ikxBAC {
appearance: none;
background-color: #dfe1e4;
border-radius: 72px;
border-style: none;
flex-shrink: 0;
height: 20px;
margin: 0;
position: relative;
width: 30px;
transition: 0.3s;
}
.checkbox-wrapper-2 .ikxBAC::before {
bottom: -6px;
content: "";
left: -6px;
position: absolute;
right: -6px;
top: -6px;
transition: 0.3s;
cursor: pointer;
}
.checkbox-wrapper-2 .ikxBAC,
.checkbox-wrapper-2 .ikxBAC::after {
transition: 300ms;
}
.checkbox-wrapper-2 .ikxBAC::after {
background-color: #fff;
border-radius: 50%;
content: "";
height: 14px;
left: 3px;
position: absolute;
top: 3px;
width: 14px;
cursor: pointer;
}
.checkbox-wrapper-2 input[type=checkbox] {
cursor: default;
}
.checkbox-wrapper-2 .ikxBAC:hover {
background-color: #c9cbcd;
transition-duration: 0s;
}
.checkbox-wrapper-2 .ikxBAC:checked {
background-color: green;
}
.checkbox-wrapper-2 .ikxBAC:checked::after {
background-color: #fff;
left: 13px;
}
.checkbox-wrapper-2 :focus:not(.focus-visible) {
outline: 0;
}
.checkbox-wrapper-2 .ikxBAC:checked:hover {
background-color: hsl(from green h s 20%);
}
.settingrect {
width: 25%;
height: max-content;
background-color: hsl(from black h s 20%);
padding: 20px;
border-radius: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
}
.settingrectheader {
width: 100%;
display: flex;
justify-content: space-between;
}
.settingrectbody {
width: 100%;
height: 0;
overflow: hidden;
transition: 0.3s;
}
.settingrectbody.active {
height: max-content;
}
.settingrectbody>table {
width: 100%;
text-align: left;
}
.settingrectfooter {
width: 100%;
display: flex;
align-items: center;
gap: 10px;
}
.settingrectfooter>button {
width: 100%;
}
table {
border: 2px solid ;
border-radius: 10px;
}
thead>tr>th {
border-bottom: 2px solid;
padding: 10px;
}
tbody>tr>th {
border: 2px solid;
padding: 10px;
border-radius: 10px;
}
@media screen and (max-width: 1200px) {
.settingrect {
width: 50%;
}
}
@media screen and (max-width: 600px) {
.settingrect {
width: 75%;
}
}
@media screen and (max-width: 400px) {
.settingrect {
width: 100%;
}
}
+77 -1
View File
@@ -5,9 +5,66 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/form.css">
<link rel="stylesheet" href="css/settings.css">
<link rel="stylesheet" href="css/notification.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/button.css">
<link rel="stylesheet" href="css/loader.css">
<title>Openrouter Admin</title>
</head>
<body>
<section class="adminpanel">
<header class="header">
<div class="links">
<button class="linkbutton">Settings</button>
<button class="linkbutton" id="rebootbutton">Reboot</button>
</div>
<h1>Openrouter Admin</h1>
<div class="userbuttons">
<h1 class="headerusername"></h1>
<button class="exitbutton">Exit</button>
</div>
</header>
<section class="settingssection">
<div class="settingrect">
<div class="settingrectheader">
<h2>Telnet</h2>
<div class="checkbox-wrapper-2">
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="telnetenable">
</div>
</div>
<div class="settingrectbody telnetsettingbody">
<table class="telnetuserstable">
<thead>
<tr>
<th>username</th>
<th>password</th>
</tr>
</thead>
<tbody>
<tr><th>No users</th></tr>
<!-- <tr>
<th>root</th>
<th>2808</th>
</tr> -->
</tbody>
</table>
</div>
<div class="settingrectfooter">
<button>Add telnet user</button>
<button id="set_telnet_settings">Confirm</button>
</div>
</div>
</section>
</section>
<div class="notification">
<div class="notificationtextbox">
<h3 class="notificationtext"></h3>
</div>
</div>
<div class="form loginform">
<form class="formbody loginformbody">
<h1 class="formheader">OpenRouter Login</h1>
@@ -24,9 +81,28 @@
</div>
</form>
</div>
<button class="exitbutton">exit</button>
<div class="form confirmrebootform">
<div class="formbody confirmrebootformbody">
<h1 class="formheader">Confirm reboot?</h1>
<div class="forminputbody confirmform">
<button class="formbutton" id="cancelreboot">Cancel</button>
<button class="formbutton" id="confirmreboot">Confirm</button>
</div>
</div>
</div>
<div class="loader">
<h1>Reboting</h1>
<div class="loadertip">
<div class="progress"></div>
</div>
</div>
<script src="js/routes.js"></script>
<script src="js/notification.js"></script>
<script src="js/login.js"></script>
<script src="js/settings/telnet.js"></script>
<script src="js/reboot.js"></script>
</body>
</html>
+28 -17
View File
@@ -3,12 +3,15 @@ const loginformbody = document.querySelector('.loginformbody')
const loginusername = document.querySelector("#loginusernameinput")
const loginpassword = document.querySelector("#loginpasswordinput")
const exitbutton = document.querySelector('.exitbutton')
console.log(localStorage.getItem("token"))
const adminpanelsection = document.querySelector('.adminpanel')
const headerusername = document.querySelector('.headerusername')
if (localStorage.getItem("token") === null) {
adminpanelsection.classList.remove('active')
loginform.classList.add('active')
// loginform.style.background = "initial"
} else {
adminpanelsection.classList.add('active')
headerusername.innerHTML = JSON.parse(localStorage.getItem('userdata')).username
}
loginformbody.addEventListener('submit', (e) => {
@@ -19,39 +22,47 @@ loginformbody.addEventListener('submit', (e) => {
const login = async (username, password) => {
const response = await fetch(routes.login(), {
method: 'POST',
headers: {
Accept: 'application/json',
// 'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
// mode: 'no-cors',
body: `{"username":"${username}","password":"${password}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
if (error.message === "Unexpected end of JSON input") {
console.log("error")
// notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error")
notification(`Ошибка на сервере: Создайте файл users.json и запишите в него первого пользователя`, "error")
} else {
console.log("error")
// notification(`Ошибка на сервере: ${error}`, "error")
notification(`Ошибка на сервере: ${error}`, "error")
}
})
if (response.status === "403") {
console.log("Неправильный логин или пароль")
// notification("Неправильный логин или пароль", "error")
notification("Неправильный логин или пароль", "error")
}
if (response.token) {
// notification("Успешно", "success")
notification("Успешно", "success")
loginform.classList.remove("active")
localStorage.setItem("token", response.token)
adminpanelsection.classList.add('active')
await get_user_data()
loginforminputusername.value = ""
loginforminputpassword.value = ""
loginusername.value = ""
loginpassword.value = ""
}
}
const get_user_data = async () => {
const response = await fetch(routes.user(), {
method: "POST",
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => jsondata).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
if (response.id) {
headerusername.innerHTML = response.username
localStorage.setItem("userdata", JSON.stringify(response))
}
}
exitbutton.addEventListener('click', () => {
localStorage.clear()
loginform.classList.add('active')
loginusername.value = ""
loginpassword = ""
notification('Вы вышли', "success")
adminpanelsection.classList.remove('active')
})
+23
View File
@@ -0,0 +1,23 @@
const notificationbox = document.querySelector('.notification')
const notificationtext = document.querySelector('.notificationtext')
const notification = (text, type) => {
if (type === "error") {
notificationbox.classList.remove('success')
notificationbox.classList.add('error')
} else {
notificationbox.classList.remove('error')
notificationbox.classList.add('success')
}
notificationtext.innerHTML = text
notificationbox.classList.add('active')
setTimeout(() => {
notificationbox.classList.remove('active')
}, 2000)
}
const closenotification = () => {
notificationbox.classList.remove('active')
}
notificationbox.addEventListener('click', closenotification)
+42
View File
@@ -0,0 +1,42 @@
const rebootbutton = document.querySelector('#rebootbutton')
const confirmrebootform = document.querySelector('.confirmrebootform')
const cancelrebootbutton = document.querySelector('#cancelreboot')
const confirmrebootbutton = document.querySelector('#confirmreboot')
const loader = document.querySelector('.loader')
rebootbutton.addEventListener('click', () => {
confirmrebootform.classList.add('active')
})
const reboot = () => {
loader.classList.add('active')
fetch(routes.reboot(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(data => data.json()).then(jsondata => {
}).catch((error) => {
// notification(`Перезагрузка`, "success")
confirmrebootform.classList.remove('active')
// window.location.replace(window.location.origin)
loader.classList.add('active')
waitreboot()
})
}
cancelrebootbutton.addEventListener('click', () => {
confirmrebootform.classList.remove('active')
})
confirmrebootbutton.addEventListener('click', reboot)
const waitreboot = () => {
fetch(routes.telnet_status(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}"}`
}).then(res => res.json()).then(jsondata => {
loader.classList.remove('active')
}).catch((error) => {
waitreboot()
})
}
+7 -3
View File
@@ -1,9 +1,13 @@
const host = 'http://localhost:43243'
const authhost = 'http://192.168.122.76:43243'
const host = 'http://192.168.122.76:43244'
const prefix = 'api'
const routes = {
login: () => [host, prefix, 'token'].join('/'),
// user: () => [host, prefix, 'users', 'user'].join('/'),
login: () => [authhost, prefix, 'token'].join('/'),
user: () => [authhost, prefix, 'users', 'user'].join('/'),
telnet_status: () => [host, prefix, 'settings', 'telnet', 'get'].join('/'),
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
reboot: () => [host, prefix, 'reboot'].join('/')
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
// access: () => [host, prefix, 'access'].join('/'),
// adduser: () => [host, prefix, 'users', 'add'].join('/'),
+47
View File
@@ -0,0 +1,47 @@
const telnetenabled = document.querySelector('#telnetenable')
const telnetsettingbody = document.querySelector('.telnetsettingbody')
const settelnetsettingsbutton = document.querySelector('#set_telnet_settings')
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
// telnetsettingbody.classList.add('active')
return;
}
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
const set_telnet_enabled_status = (status) => {
fetch(routes.telnet_status_set(), {
method: 'POST',
body: `{"token":"${localStorage.getItem("token")}","enabled":"${status?1:0}"}`
}).then(res => res.json()).then(jsondata => {
if (jsondata.enabled === '1') {
telnetenabled.checked = true
// telnetsettingbody.classList.add('active')
}
notification("Настройки telnet сохранены", "success")
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}
get_telnet_enabled_status()
telnetenabled.addEventListener('click', () => {
if (telnetenabled.checked) {
// telnetsettingbody.classList.add('active')
} else {
telnetsettingbody.classList.remove('active')
}
})
settelnetsettingsbutton.addEventListener('click', () => {
set_telnet_enabled_status(telnetenabled.checked)
})