added ftp and auto update
This commit is contained in:
@@ -11,6 +11,7 @@ add_executable(
|
||||
|
||||
src/settings/telnet/telnet.cpp
|
||||
src/settings/dns/dns.cpp
|
||||
src/settings/ftp/ftp.cpp
|
||||
|
||||
src/reboot/reboot.cpp
|
||||
)
|
||||
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
Green='\033[0;32m'
|
||||
Color_off='\033[0m'
|
||||
Red='\033[0;31m'
|
||||
|
||||
if [ ! -f IP ]; then
|
||||
printf "[$Red ERR $Color_off] Cant't find IP file\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <colors.h>
|
||||
#include "settings/telnet/telnet.hpp"
|
||||
#include "settings/dns/dns.hpp"
|
||||
#include "settings/ftp/ftp.hpp"
|
||||
#include "reboot/reboot.hpp"
|
||||
|
||||
#define CORS_ENABLE
|
||||
@@ -15,6 +16,8 @@ int main() {
|
||||
srv.Post("/api/settings/telnet/set", set_telnet);
|
||||
srv.Post("/api/settings/dns/get", get_dns);
|
||||
srv.Post("/api/settings/dns/set", set_dns);
|
||||
srv.Post("/api/settings/ftp/get", get_ftp);
|
||||
srv.Post("/api/settings/ftp/set", set_ftp);
|
||||
|
||||
srv.Post("/api/reboot", reboot);
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "ftp.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
|
||||
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
void get_ftp(const httplib::Request &request, httplib::Response &response) {
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ifstream ftpfile("/etc/openrouter/ftp");
|
||||
int ftp_enabled;
|
||||
ftpfile >> ftp_enabled;
|
||||
ftpfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
void set_ftp(const httplib::Request &request, httplib::Response &response) {
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (json_body["enabled"] == nullptr) {
|
||||
response.set_content(FTP_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
std::ofstream ftpfileout("/etc/openrouter/ftp");
|
||||
std::string new_ftp_enabled = json_body["enabled"];
|
||||
if (new_ftp_enabled == "0") {
|
||||
system("/etc/init.d/ftp stop");
|
||||
system("rm /etc/rc.d/90ftp");
|
||||
} else {
|
||||
system("/etc/init.d/ftp start");
|
||||
system("ln -sv /etc/init.d/ftp /etc/rc.d/90ftp");
|
||||
}
|
||||
ftpfileout << stoi(new_ftp_enabled);
|
||||
ftpfileout.close();
|
||||
std::ifstream ftpfile("/etc/openrouter/ftp");
|
||||
int ftp_enabled;
|
||||
ftpfile >> ftp_enabled;
|
||||
ftpfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef FTP_HPP
|
||||
#define FTP_HPP
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
void get_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
void set_ftp(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // FTP_HPP
|
||||
+40
-31
@@ -14,6 +14,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<section class="adminpanel">
|
||||
<!-- header -->
|
||||
<header class="header">
|
||||
<div class="links">
|
||||
<button class="linkbutton">Settings</button>
|
||||
@@ -25,8 +26,10 @@
|
||||
<button class="exitbutton">Exit</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- header -->
|
||||
<!-- settings block -->
|
||||
<section class="settingssection">
|
||||
<!-- telnet settings -->
|
||||
<div class="settingrect">
|
||||
<div class="settingrectheader">
|
||||
<h2>Telnet</h2>
|
||||
@@ -56,6 +59,8 @@
|
||||
<button id="set_telnet_settings">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- telnet settings -->
|
||||
<!-- dns settings -->
|
||||
<div class="settingrect">
|
||||
<div class="settingrectheader">
|
||||
<h2>Dns</h2>
|
||||
@@ -68,15 +73,33 @@
|
||||
<button id="set_dns_settings">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- dns settings -->
|
||||
<!-- ftp settings -->
|
||||
<div class="settingrect">
|
||||
<div class="settingrectheader">
|
||||
<h2>Ftp</h2>
|
||||
<div class="checkbox-wrapper-2">
|
||||
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="ftpenable">
|
||||
</div>
|
||||
</div>
|
||||
<div class="settingrectfooter">
|
||||
<!-- <button>Add Ftp server</button> -->
|
||||
<button id="set_ftp_settings">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ftp settings -->
|
||||
</section>
|
||||
<!-- settings block -->
|
||||
</section>
|
||||
|
||||
<!-- notification block -->
|
||||
<div class="notification">
|
||||
<div class="notificationtextbox">
|
||||
<h3 class="notificationtext"></h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- notification block -->
|
||||
<!-- login form -->
|
||||
<div class="form loginform">
|
||||
<form class="formbody loginformbody">
|
||||
<h1 class="formheader">OpenRouter Login</h1>
|
||||
@@ -93,49 +116,35 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<!-- 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>
|
||||
|
||||
<div class="form confirmtelnetform">
|
||||
<div class="formbody confirmtelnetformbody">
|
||||
<h1 class="formheader">Confirm telnet settings?</h1>
|
||||
<div class="forminputbody confirmform">
|
||||
<button class="formbutton" id="canceltelnet">Cancel</button>
|
||||
<button class="formbutton" id="confirmtelnet">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form confirmdnsform">
|
||||
<div class="formbody confirmdnsformbody">
|
||||
<h1 class="formheader">Confirm dns settings?</h1>
|
||||
<div class="forminputbody confirmform">
|
||||
<button class="formbutton" id="canceldns">Cancel</button>
|
||||
<button class="formbutton" id="confirmdns">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- confirm form -->
|
||||
<!-- loader -->
|
||||
<div class="loader">
|
||||
<h1>Reboting</h1>
|
||||
<div class="loadertip">
|
||||
<div class="progress"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- loader -->
|
||||
<script src="js/routes.js"></script>
|
||||
<script src="js/notification.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
|
||||
<script src="js/settings/confirm.js"></script>
|
||||
<script src="js/settings/telnet.js"></script>
|
||||
<script src="js/settings/dns.js"></script>
|
||||
<script src="js/settings/ftp.js"></script>
|
||||
|
||||
<script src="js/reboot.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+2
-14
@@ -1,11 +1,8 @@
|
||||
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')
|
||||
get_confirm_form("Confirm reboot?", reboot)
|
||||
})
|
||||
|
||||
const reboot = () => {
|
||||
@@ -16,20 +13,11 @@ const reboot = () => {
|
||||
}).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()
|
||||
setTimeout(waitreboot, 2000)
|
||||
})
|
||||
}
|
||||
|
||||
cancelrebootbutton.addEventListener('click', () => {
|
||||
confirmrebootform.classList.remove('active')
|
||||
})
|
||||
|
||||
confirmrebootbutton.addEventListener('click', reboot)
|
||||
|
||||
const waitreboot = () => {
|
||||
fetch(routes.telnet_status(), {
|
||||
method: 'POST',
|
||||
|
||||
@@ -9,6 +9,9 @@ const routes = {
|
||||
telnet_status_set: () => [host, prefix, 'settings', 'telnet', 'set'].join('/'),
|
||||
dns_status: () => [host, prefix, 'settings', 'dns', 'get'].join('/'),
|
||||
dns_status_set: () => [host, prefix, 'settings', 'dns', 'set'].join('/'),
|
||||
ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'),
|
||||
ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'),
|
||||
|
||||
reboot: () => [host, prefix, 'reboot'].join('/')
|
||||
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
|
||||
// access: () => [host, prefix, 'access'].join('/'),
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
const confirmform = document.querySelector('#confirmform')
|
||||
const confirmformheader = document.querySelector('#confirmformheader')
|
||||
const cancelbutton = document.querySelector('#cancel')
|
||||
const confirmformbuttons = document.querySelector('#confirmformbuttons')
|
||||
|
||||
const get_confirm_form = (header, reqfunc) => {
|
||||
console.log("confirmform")
|
||||
confirmformheader.innerHTML = header
|
||||
console.log("confirmformheader")
|
||||
confirmform.classList.add('active')
|
||||
console.log("activeconfirmform")
|
||||
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'))
|
||||
}
|
||||
|
||||
cancelbutton.addEventListener('click', () => {
|
||||
confirmform.classList.remove('active')
|
||||
})
|
||||
@@ -1,14 +1,12 @@
|
||||
const dnsenabled = document.querySelector('#dnsenable')
|
||||
const setdnssettingsbutton = document.querySelector('#set_dns_settings')
|
||||
const confirmdnsform = document.querySelector('.confirmdnsform')
|
||||
const canceldnsbutton = document.querySelector('#canceldns')
|
||||
const confirmdnsbutton = document.querySelector('#confirmdns')
|
||||
|
||||
const get_dns_enabled_status = () => {
|
||||
fetch(routes.dns_status(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
console.log(jsondata)
|
||||
if (jsondata.enabled === '1') {
|
||||
dnsenabled.checked = true
|
||||
// dnssettingbody.classList.add('active')
|
||||
@@ -21,10 +19,10 @@ const get_dns_enabled_status = () => {
|
||||
|
||||
get_dns_enabled_status()
|
||||
|
||||
const set_dns_enabled_status = (status) => {
|
||||
const set_dns_enabled_status = () => {
|
||||
fetch(routes.dns_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":"${status?1:0}"}`
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":"${dnsenabled.checked?1:0}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
if (jsondata.enabled === '1') {
|
||||
dnsenabled.checked = true
|
||||
@@ -37,13 +35,5 @@ const set_dns_enabled_status = (status) => {
|
||||
}
|
||||
|
||||
setdnssettingsbutton.addEventListener('click', () =>{
|
||||
confirmdnsform.classList.add('active')
|
||||
})
|
||||
canceldnsbutton.addEventListener('click', () => {
|
||||
confirmdnsform.classList.remove('active')
|
||||
})
|
||||
|
||||
confirmdnsbutton.addEventListener('click', () => {
|
||||
set_dns_enabled_status(dnsenabled.checked)
|
||||
confirmdnsform.classList.remove('active')
|
||||
get_confirm_form("Confirm dns settings?", set_dns_enabled_status)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
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 => {
|
||||
console.log(jsondata)
|
||||
if (jsondata.enabled === '1') {
|
||||
ftpenabled.checked = true
|
||||
// ftpsettingbody.classList.add('active')
|
||||
return;
|
||||
}
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
get_ftp_enabled_status()
|
||||
|
||||
const set_ftp_enabled_status = () => {
|
||||
fetch(routes.ftp_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":"${ftpenabled.checked?1:0}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
if (jsondata.enabled === '1') {
|
||||
ftpenabled.checked = true
|
||||
// ftpsettingbody.classList.add('active')
|
||||
}
|
||||
notification("Настройки ftp сохранены", "success")
|
||||
}).catch((error) => {
|
||||
notification(`Ошибка на сервере: ${error}`, "error")
|
||||
})
|
||||
}
|
||||
|
||||
setftpsettingsbutton.addEventListener('click', () =>{
|
||||
get_confirm_form("Confirm ftp settings?", set_ftp_enabled_status)
|
||||
})
|
||||
@@ -1,15 +1,13 @@
|
||||
const telnetenabled = document.querySelector('#telnetenable')
|
||||
const telnetsettingbody = document.querySelector('.telnetsettingbody')
|
||||
const settelnetsettingsbutton = document.querySelector('#set_telnet_settings')
|
||||
const confirmtelnetform = document.querySelector('.confirmtelnetform')
|
||||
const canceltelnetbutton = document.querySelector('#canceltelnet')
|
||||
const confirmtelnetbutton = document.querySelector('#confirmtelnet')
|
||||
|
||||
const get_telnet_enabled_status = () => {
|
||||
fetch(routes.telnet_status(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
console.log(jsondata)
|
||||
if (jsondata.enabled === '1') {
|
||||
telnetenabled.checked = true
|
||||
// telnetsettingbody.classList.add('active')
|
||||
@@ -20,10 +18,12 @@ const get_telnet_enabled_status = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const set_telnet_enabled_status = (status) => {
|
||||
get_telnet_enabled_status()
|
||||
|
||||
const set_telnet_enabled_status = () => {
|
||||
fetch(routes.telnet_status_set(), {
|
||||
method: 'POST',
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":"${status?1:0}"}`
|
||||
body: `{"token":"${localStorage.getItem("token")}","enabled":"${telnetenabled.checked?1:0}"}`
|
||||
}).then(res => res.json()).then(jsondata => {
|
||||
if (jsondata.enabled === '1') {
|
||||
telnetenabled.checked = true
|
||||
@@ -35,8 +35,6 @@ const set_telnet_enabled_status = (status) => {
|
||||
})
|
||||
}
|
||||
|
||||
get_telnet_enabled_status()
|
||||
|
||||
telnetenabled.addEventListener('click', () => {
|
||||
if (telnetenabled.checked) {
|
||||
// telnetsettingbody.classList.add('active')
|
||||
@@ -46,14 +44,5 @@ telnetenabled.addEventListener('click', () => {
|
||||
})
|
||||
|
||||
settelnetsettingsbutton.addEventListener('click', () => {
|
||||
confirmtelnetform.classList.add('active')
|
||||
})
|
||||
|
||||
canceltelnetbutton.addEventListener('click', () => {
|
||||
confirmtelnetform.classList.remove('active')
|
||||
})
|
||||
|
||||
confirmtelnetbutton.addEventListener('click', () => {
|
||||
set_telnet_enabled_status(telnetenabled.checked)
|
||||
confirmtelnetform.classList.remove('active')
|
||||
get_confirm_form("Confirm telnet settings?", set_telnet_enabled_status)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user