From 69f4c2e1eacc113ba6038377cbe118ad6ef2628a Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Tue, 2 Jul 2024 18:45:18 +0700 Subject: [PATCH] syslog added --- CMakeLists.txt | 2 + src/openrouter.cpp | 3 + src/syslog/syslog.cpp | 19 ++++ src/syslog/syslog.hpp | 8 ++ src/types.hpp | 1 + src/web/css/index.css | 5 + src/web/css/settings.css | 13 +++ src/web/css/syslog.css | 26 +++++ src/web/index.html | 224 +++++++++++++++++++++------------------ src/web/js/header.js | 15 +++ src/web/js/routes.js | 3 +- src/web/js/syslog.js | 13 +++ 12 files changed, 225 insertions(+), 107 deletions(-) create mode 100644 src/syslog/syslog.cpp create mode 100644 src/syslog/syslog.hpp create mode 100644 src/web/css/syslog.css create mode 100644 src/web/js/header.js create mode 100644 src/web/js/syslog.js diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ff2a12..0327a98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,4 +23,6 @@ add_executable( src/settings/ftp/ftp.cpp src/reboot/reboot.cpp + + src/syslog/syslog.cpp ) diff --git a/src/openrouter.cpp b/src/openrouter.cpp index 273b1a5..ace1a18 100644 --- a/src/openrouter.cpp +++ b/src/openrouter.cpp @@ -6,6 +6,7 @@ #include "settings/dns/dns.hpp" #include "settings/ftp/ftp.hpp" #include "reboot/reboot.hpp" +#include "syslog/syslog.hpp" #define CORS_ENABLE #include "security/cors.hpp" @@ -37,6 +38,8 @@ int main() { srv.Post("/api/reboot", reboot); + srv.Get("/api/syslog", syslog); + srv.Options("/(.*)", set_cors_headers); srv.set_mount_point("/" , "../src/web"); diff --git a/src/syslog/syslog.cpp b/src/syslog/syslog.cpp new file mode 100644 index 0000000..1807fa3 --- /dev/null +++ b/src/syslog/syslog.cpp @@ -0,0 +1,19 @@ +#include "syslog.hpp" +#include +#include "../types.hpp" +#include "../routes.hpp" +#include +#include +#include +#include +#include + +#define SYSLOG_FILE "/var/log/messages" + +void syslog(const httplib::Request &request, httplib::Response &response) { + std::stringstream responsedata; + std::ifstream syslogfile(SYSLOG_FILE); + responsedata << syslogfile.rdbuf(); + syslogfile.close(); + response.set_content(responsedata.str(), PLAIN_TEXT_TYPE); +} diff --git a/src/syslog/syslog.hpp b/src/syslog/syslog.hpp new file mode 100644 index 0000000..1c9f18b --- /dev/null +++ b/src/syslog/syslog.hpp @@ -0,0 +1,8 @@ +#ifndef SYSLOG_HPP +#define SYSLOG_HPP + +#include + +void syslog(const httplib::Request &request, httplib::Response &response); + +#endif //SYSLOG_HPP \ No newline at end of file diff --git a/src/types.hpp b/src/types.hpp index 2d638f6..ba5b9bb 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -6,5 +6,6 @@ #define JWT_SECRET_KEY "secret" #define STRING403 R"({"status":"403"})" #define JSON_TYPE "application/json" +#define PLAIN_TEXT_TYPE "text/plain" #endif // TYPES_H \ No newline at end of file diff --git a/src/web/css/index.css b/src/web/css/index.css index 20e6f51..39be9e0 100644 --- a/src/web/css/index.css +++ b/src/web/css/index.css @@ -14,6 +14,7 @@ body { } .adminpanel { + position: relative; width: 100%; height: 100%; transform: scale(0.5); @@ -25,3 +26,7 @@ body { transform: scale(1); opacity: 1; } + +.section { + position: relative; +} diff --git a/src/web/css/settings.css b/src/web/css/settings.css index 5ab5d13..e3ee9f6 100644 --- a/src/web/css/settings.css +++ b/src/web/css/settings.css @@ -66,10 +66,23 @@ } .settingssection { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; padding: 10px; display: flex; /* flex-direction: column; */ gap: 10px; + transition: 0.3s; + opacity: 0; + pointer-events: none; +} + +.settingssection.active { + opacity: 1; + pointer-events: all; } .settingrect { diff --git a/src/web/css/syslog.css b/src/web/css/syslog.css new file mode 100644 index 0000000..9364167 --- /dev/null +++ b/src/web/css/syslog.css @@ -0,0 +1,26 @@ +.syslogsection { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + opacity: 0; + pointer-events: none; + transition: 0.3s; + padding: 10px; +} + +.syslogsection.active { + opacity: 1; + pointer-events: all; +} + +.syslogdata { + width: 100%; + max-height: 85vh; + padding: 10px; + border-radius: 10px; + /* background-color: rgb(175, 175, 175); */ + margin: 10px 0; + overflow-y: auto; +} diff --git a/src/web/index.html b/src/web/index.html index ea1316b..87afea8 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -10,6 +10,7 @@ + Openrouter Admin @@ -17,7 +18,8 @@

Openrouter Admin

@@ -28,120 +30,128 @@
-
- -
-
-

Telnet

-
- +
+
+ +
+
+

Telnet

+
+ +
+
+
+
+ + +
+ + + + + + + + + + + +
usernamepassword
No users
+
+
+ +
-
-
- - + + +
+
+

DNS

+
+ +
- - - - - - - - - - - -
usernamepassword
No users
-
-
- - -
-
- - -
-
-

DNS

-
- +
+ + + + + + +
DNS servers
+

Domains Table

+ + + + + + + + + + +
IPDomain
+
+
+ + +
-
- - - - - - -
DNS servers
-

Domains Table

- - - - - - - - - - -
IPDomain
-
-
- - - -
-
- - -
-
-

Ftp

-
- + + +
+
+

Ftp

+
+ +
+
+
+ +
-
- - -
-
- - -
-
-

SSH

-
- + + +
+
+

SSH

+
+ +
+
+
+
+ + +
+ + + + + + +
SSH keys
+
+
+ +
-
-
- - -
- - - - - - -
SSH keys
-
-
- - -
-
- -
+ +
+ +
+

Syslog

+
+
+ + @@ -219,6 +229,7 @@ + @@ -231,6 +242,7 @@ + \ No newline at end of file diff --git a/src/web/js/header.js b/src/web/js/header.js new file mode 100644 index 0000000..1d9ed88 --- /dev/null +++ b/src/web/js/header.js @@ -0,0 +1,15 @@ +const settingssection = document.querySelector('.settingssection') +const settingsbutton = document.querySelector('#settingsbutton') +const syslogsection = document.querySelector('.syslogsection') +const syslogbutton = document.querySelector('#syslogbutton') + +settingsbutton.addEventListener('click', () => { + settingssection.classList.add('active') + syslogsection.classList.remove('active') +}) + +syslogbutton.addEventListener('click', () => { + syslogsection.classList.add('active') + settingssection.classList.remove('active') + get_syslog_data() +}) diff --git a/src/web/js/routes.js b/src/web/js/routes.js index 22c871a..c7b7b28 100644 --- a/src/web/js/routes.js +++ b/src/web/js/routes.js @@ -28,7 +28,8 @@ const routes = { ftp_status: () => [host, prefix, 'settings', 'ftp', 'get'].join('/'), ftp_status_set: () => [host, prefix, 'settings', 'ftp', 'set'].join('/'), - reboot: () => [host, prefix, 'reboot'].join('/') + 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('/'), diff --git a/src/web/js/syslog.js b/src/web/js/syslog.js new file mode 100644 index 0000000..952a5fc --- /dev/null +++ b/src/web/js/syslog.js @@ -0,0 +1,13 @@ +const syslogdata = document.querySelector('.syslogdata') + +const get_syslog_data = () => { + console.log("get_syslog_data") + fetch(routes.syslog(), { + method: 'GET', + // body: `{"token":"${localStorage.getItem("token")}"}` + }).then(data => data.text()).then(textdata => { + syslogdata.innerHTML = textdata.replace('/\n/g','
') + }).catch((error) => { + notification(`Ошибка на сервере: ${error}`, "error") + }) +}