diff --git a/openrouter/CMakeLists.txt b/openrouter/CMakeLists.txt index eae0018..2cce541 100644 --- a/openrouter/CMakeLists.txt +++ b/openrouter/CMakeLists.txt @@ -31,6 +31,7 @@ add_executable( src/reboot/reboot.cpp src/syslog/syslog.cpp + src/uptime/uptime.cpp src/libs/QR-Code-generator/qrcodegen.cpp src/libs/QR-Code-generator/qrtosvg.cpp diff --git a/openrouter/src/openrouter.cpp b/openrouter/src/openrouter.cpp index a4f4206..4531aed 100644 --- a/openrouter/src/openrouter.cpp +++ b/openrouter/src/openrouter.cpp @@ -8,6 +8,7 @@ #include "settings/wifi/wifi.hpp" #include "reboot/reboot.hpp" #include "syslog/syslog.hpp" +#include "uptime/uptime.hpp" #include #define CORS_ENABLE @@ -51,6 +52,7 @@ int main() { srv.Post("/api/reboot", reboot); srv.Get("/api/syslog", get_syslog); + srv.Get("/api/uptime", get_uptime); srv.Options("/(.*)", set_cors_headers); diff --git a/openrouter/src/uptime/uptime.cpp b/openrouter/src/uptime/uptime.cpp new file mode 100644 index 0000000..0902c6b --- /dev/null +++ b/openrouter/src/uptime/uptime.cpp @@ -0,0 +1,26 @@ +#include "uptime.hpp" +#include +#include +#include "../types.hpp" + +void get_uptime(const httplib::Request &request, httplib::Response &response) { + struct sysinfo x; + if (sysinfo(&x) == 0) + { + std::cout << static_cast(x.uptime)/3600ULL << "h " + << static_cast(x.uptime)/60ULL%60ULL << "m " + << static_cast(x.uptime)%60ULL << "s " + << std::endl; + std::stringstream responsedata; + responsedata << R"({"uptime":{"hour":")" + << static_cast(x.uptime)/3600ULL + << R"(","minute":")" + << static_cast(x.uptime)/60ULL%60ULL + << R"(","second":")" + << static_cast(x.uptime)%60ULL + << R"("}})"; + response.set_content(responsedata.str(), JSON_TYPE); + return; + } + response.set_content(R"({"error":"unknown"})", JSON_TYPE); +} diff --git a/openrouter/src/uptime/uptime.hpp b/openrouter/src/uptime/uptime.hpp new file mode 100644 index 0000000..fc532a0 --- /dev/null +++ b/openrouter/src/uptime/uptime.hpp @@ -0,0 +1,8 @@ +#ifndef UPTIME_HPP +#define UPTIME_HPP + +#include + +void get_uptime(const httplib::Request &request, httplib::Response &response); + +#endif // UPTIME_HPP \ No newline at end of file diff --git a/openrouter/src/web/css/header.css b/openrouter/src/web/css/header.css index 783f6b1..b1302ee 100644 --- a/openrouter/src/web/css/header.css +++ b/openrouter/src/web/css/header.css @@ -36,6 +36,8 @@ header { header>h1 { justify-self: center; + display: flex; + align-items: center; } @media screen and (max-width: 400px) { diff --git a/openrouter/src/web/index.html b/openrouter/src/web/index.html index c1df79b..727a7a6 100644 --- a/openrouter/src/web/index.html +++ b/openrouter/src/web/index.html @@ -23,7 +23,7 @@ -

Openrouter Admin

+

Openrouter Admin Uptime:

@@ -279,6 +279,7 @@ + \ No newline at end of file diff --git a/openrouter/src/web/js/routes.js b/openrouter/src/web/js/routes.js index a9d4afd..2cc2620 100644 --- a/openrouter/src/web/js/routes.js +++ b/openrouter/src/web/js/routes.js @@ -39,10 +39,5 @@ const routes = { reboot: () => [host, prefix, 'reboot'].join('/'), syslog: () => [host, prefix, 'syslog'].join('/'), - // all_users: () => [host, prefix, 'users', 'all'].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('/') + uptime: () => [host, prefix, 'uptime'].join('/'), } \ No newline at end of file diff --git a/openrouter/src/web/js/settings/wifi.js b/openrouter/src/web/js/settings/wifi.js index 1fdefc5..6d64c5b 100644 --- a/openrouter/src/web/js/settings/wifi.js +++ b/openrouter/src/web/js/settings/wifi.js @@ -33,7 +33,6 @@ const set_wifi_status = () => { method: 'POST', body: `{"token":"${localStorage.getItem('token')}","status":"${wifistatus.checked?"1":"0"}"}` }).then(data => data.json()).then(jsondata => { - console.log(jsondata) if (jsondata.status === "1") { wifistatus.checked = true wifisettingsbody.classList.add('active') @@ -65,7 +64,6 @@ const set_wifi_name = () => { method: 'POST', body: `{"token":"${localStorage.getItem('token')}","name":"${wifissid.value}"}` }).then(data => data.json()).then(jsondata => { - console.log(jsondata) wifissid.value = jsondata.name old_wifi_name = jsondata.name notification("Имя WIFI оспешно сорранено", "success") diff --git a/openrouter/src/web/js/uptime.js b/openrouter/src/web/js/uptime.js new file mode 100644 index 0000000..44a7405 --- /dev/null +++ b/openrouter/src/web/js/uptime.js @@ -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) diff --git a/rootfs/usr/conf/openrouter/openrouter.conf b/rootfs/usr/conf/openrouter/openrouter.conf index aac6fbb..e1754e2 100644 --- a/rootfs/usr/conf/openrouter/openrouter.conf +++ b/rootfs/usr/conf/openrouter/openrouter.conf @@ -16,6 +16,10 @@ server { 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 { proxy_pass http://127.0.0.1:43244/api/reboot; }