uptime added
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "settings/wifi/wifi.hpp"
|
||||
#include "reboot/reboot.hpp"
|
||||
#include "syslog/syslog.hpp"
|
||||
#include "uptime/uptime.hpp"
|
||||
#include <syslog.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
justify-self: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 400px) {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<button class="linkbutton" id="settingsbutton">Settings</button>
|
||||
<button class="linkbutton" id="rebootbutton">Reboot</button>
|
||||
</div>
|
||||
<h1>Openrouter Admin</h1>
|
||||
<h1>Openrouter Admin Uptime: <p id="uptime"></p></h1>
|
||||
<div class="userbuttons">
|
||||
<h1 class="headerusername"></h1>
|
||||
<button class="exitbutton">Exit</button>
|
||||
@@ -279,6 +279,7 @@
|
||||
|
||||
<script src="js/reboot.js"></script>
|
||||
<script src="js/syslog.js"></script>
|
||||
<script src="js/uptime.js"></script>
|
||||
<script src="js/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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('/'),
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user