uptime added
This commit is contained in:
1 parent
fdbdda37e3
commit
06d0c573cd
10 files changed
+65
-9
No files matched your search
@@ -31,6 +31,7 @@ add_executable(
|
|||||||
src/reboot/reboot.cpp
|
src/reboot/reboot.cpp
|
||||||
|
|
||||||
src/syslog/syslog.cpp
|
src/syslog/syslog.cpp
|
||||||
|
src/uptime/uptime.cpp
|
||||||
|
|
||||||
src/libs/QR-Code-generator/qrcodegen.cpp
|
src/libs/QR-Code-generator/qrcodegen.cpp
|
||||||
src/libs/QR-Code-generator/qrtosvg.cpp
|
src/libs/QR-Code-generator/qrtosvg.cpp
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "settings/wifi/wifi.hpp"
|
#include "settings/wifi/wifi.hpp"
|
||||||
#include "reboot/reboot.hpp"
|
#include "reboot/reboot.hpp"
|
||||||
#include "syslog/syslog.hpp"
|
#include "syslog/syslog.hpp"
|
||||||
|
#include "uptime/uptime.hpp"
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#define CORS_ENABLE
|
#define CORS_ENABLE
|
||||||
@@ -51,6 +52,7 @@ int main() {
|
|||||||
srv.Post("/api/reboot", reboot);
|
srv.Post("/api/reboot", reboot);
|
||||||
|
|
||||||
srv.Get("/api/syslog", get_syslog);
|
srv.Get("/api/syslog", get_syslog);
|
||||||
|
srv.Get("/api/uptime", get_uptime);
|
||||||
|
|
||||||
srv.Options("/(.*)", set_cors_headers);
|
srv.Options("/(.*)", set_cors_headers);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "uptime.hpp"
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include "../types.hpp"
|
||||||
|
|
||||||
|
void get_uptime(const httplib::Request &request, httplib::Response &response) {
|
||||||
|
struct sysinfo x;
|
||||||
|
if (sysinfo(&x) == 0)
|
||||||
|
{
|
||||||
|
std::cout << static_cast<unsigned long long>(x.uptime)/3600ULL << "h "
|
||||||
|
<< static_cast<unsigned long long>(x.uptime)/60ULL%60ULL << "m "
|
||||||
|
<< static_cast<unsigned long long>(x.uptime)%60ULL << "s "
|
||||||
|
<< std::endl;
|
||||||
|
std::stringstream responsedata;
|
||||||
|
responsedata << R"({"uptime":{"hour":")"
|
||||||
|
<< static_cast<unsigned long long>(x.uptime)/3600ULL
|
||||||
|
<< R"(","minute":")"
|
||||||
|
<< static_cast<unsigned long long>(x.uptime)/60ULL%60ULL
|
||||||
|
<< R"(","second":")"
|
||||||
|
<< static_cast<unsigned long long>(x.uptime)%60ULL
|
||||||
|
<< R"("}})";
|
||||||
|
response.set_content(responsedata.str(), JSON_TYPE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
response.set_content(R"({"error":"unknown"})", JSON_TYPE);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef UPTIME_HPP
|
||||||
|
#define UPTIME_HPP
|
||||||
|
|
||||||
|
#include <httplib.h>
|
||||||
|
|
||||||
|
void get_uptime(const httplib::Request &request, httplib::Response &response);
|
||||||
|
|
||||||
|
#endif // UPTIME_HPP
|
||||||
@@ -36,6 +36,8 @@ header {
|
|||||||
|
|
||||||
header>h1 {
|
header>h1 {
|
||||||
justify-self: center;
|
justify-self: center;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 400px) {
|
@media screen and (max-width: 400px) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<button class="linkbutton" id="settingsbutton">Settings</button>
|
<button class="linkbutton" id="settingsbutton">Settings</button>
|
||||||
<button class="linkbutton" id="rebootbutton">Reboot</button>
|
<button class="linkbutton" id="rebootbutton">Reboot</button>
|
||||||
</div>
|
</div>
|
||||||
<h1>Openrouter Admin</h1>
|
<h1>Openrouter Admin Uptime: <p id="uptime"></p></h1>
|
||||||
<div class="userbuttons">
|
<div class="userbuttons">
|
||||||
<h1 class="headerusername"></h1>
|
<h1 class="headerusername"></h1>
|
||||||
<button class="exitbutton">Exit</button>
|
<button class="exitbutton">Exit</button>
|
||||||
@@ -279,6 +279,7 @@
|
|||||||
|
|
||||||
<script src="js/reboot.js"></script>
|
<script src="js/reboot.js"></script>
|
||||||
<script src="js/syslog.js"></script>
|
<script src="js/syslog.js"></script>
|
||||||
|
<script src="js/uptime.js"></script>
|
||||||
<script src="js/login.js"></script>
|
<script src="js/login.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -39,10 +39,5 @@ const routes = {
|
|||||||
|
|
||||||
reboot: () => [host, prefix, 'reboot'].join('/'),
|
reboot: () => [host, prefix, 'reboot'].join('/'),
|
||||||
syslog: () => [host, prefix, 'syslog'].join('/'),
|
syslog: () => [host, prefix, 'syslog'].join('/'),
|
||||||
// all_users: () => [host, prefix, 'users', 'all'].join('/'),
|
uptime: () => [host, prefix, 'uptime'].join('/'),
|
||||||
// access: () => [host, prefix, 'access'].join('/'),
|
|
||||||
// adduser: () => [host, prefix, 'users', 'add'].join('/'),
|
|
||||||
// deluser: () => [host, prefix, 'users', 'del'].join('/'),
|
|
||||||
// change_password_url: () => [host, prefix, 'users', 'user', 'password', 'change'].join('/'),
|
|
||||||
// change_user: () => [host, prefix, 'users', 'user', 'change'].join('/')
|
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,6 @@ const set_wifi_status = () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: `{"token":"${localStorage.getItem('token')}","status":"${wifistatus.checked?"1":"0"}"}`
|
body: `{"token":"${localStorage.getItem('token')}","status":"${wifistatus.checked?"1":"0"}"}`
|
||||||
}).then(data => data.json()).then(jsondata => {
|
}).then(data => data.json()).then(jsondata => {
|
||||||
console.log(jsondata)
|
|
||||||
if (jsondata.status === "1") {
|
if (jsondata.status === "1") {
|
||||||
wifistatus.checked = true
|
wifistatus.checked = true
|
||||||
wifisettingsbody.classList.add('active')
|
wifisettingsbody.classList.add('active')
|
||||||
@@ -65,7 +64,6 @@ const set_wifi_name = () => {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: `{"token":"${localStorage.getItem('token')}","name":"${wifissid.value}"}`
|
body: `{"token":"${localStorage.getItem('token')}","name":"${wifissid.value}"}`
|
||||||
}).then(data => data.json()).then(jsondata => {
|
}).then(data => data.json()).then(jsondata => {
|
||||||
console.log(jsondata)
|
|
||||||
wifissid.value = jsondata.name
|
wifissid.value = jsondata.name
|
||||||
old_wifi_name = jsondata.name
|
old_wifi_name = jsondata.name
|
||||||
notification("Имя WIFI оспешно сорранено", "success")
|
notification("Имя WIFI оспешно сорранено", "success")
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
const uptime = document.querySelector('#uptime')
|
||||||
|
|
||||||
|
const get_uptime = () => {
|
||||||
|
fetch(routes.uptime()).then(data => data.json()).then(jsondata => {
|
||||||
|
if (jsondata.uptime.hour === '0' && jsondata.uptime.minute === '0') {
|
||||||
|
uptime.innerHTML = jsondata.uptime.second + "s "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (jsondata.uptime.hour === '0') {
|
||||||
|
uptime.innerHTML = jsondata.uptime.minute + "m " + jsondata.uptime.second + "s "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uptime.innerHTML = jsondata.uptime.hour + "h " + jsondata.uptime.minute + "m " + jsondata.uptime.second + "s "
|
||||||
|
}).catch((error) => {
|
||||||
|
notification(`Ошибка на сервере: ${error}`, "error")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(get_uptime, 1000)
|
||||||
@@ -16,6 +16,10 @@ server {
|
|||||||
proxy_pass http://127.0.0.1:43244/api/syslog;
|
proxy_pass http://127.0.0.1:43244/api/syslog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/uptime {
|
||||||
|
proxy_pass http://127.0.0.1:43244/api/uptime;
|
||||||
|
}
|
||||||
|
|
||||||
location /api/reboot {
|
location /api/reboot {
|
||||||
proxy_pass http://127.0.0.1:43244/api/reboot;
|
proxy_pass http://127.0.0.1:43244/api/reboot;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user