syslog added

This commit is contained in:
wt
2024-07-02 18:45:18 +07:00
parent 5fbd56ef7a
commit 69f4c2e1ea
12 changed files with 225 additions and 107 deletions
+2
View File
@@ -23,4 +23,6 @@ add_executable(
src/settings/ftp/ftp.cpp
src/reboot/reboot.cpp
src/syslog/syslog.cpp
)
+3
View File
@@ -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");
+19
View File
@@ -0,0 +1,19 @@
#include "syslog.hpp"
#include <colors.h>
#include "../types.hpp"
#include "../routes.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#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);
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef SYSLOG_HPP
#define SYSLOG_HPP
#include <httplib.h>
void syslog(const httplib::Request &request, httplib::Response &response);
#endif //SYSLOG_HPP
+1
View File
@@ -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
+5
View File
@@ -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;
}
+13
View File
@@ -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 {
+26
View File
@@ -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;
}
+13 -1
View File
@@ -10,6 +10,7 @@
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/button.css">
<link rel="stylesheet" href="css/loader.css">
<link rel="stylesheet" href="css/syslog.css">
<title>Openrouter Admin</title>
</head>
<body>
@@ -17,7 +18,8 @@
<!-- header -->
<header class="header">
<div class="links">
<button class="linkbutton">Settings</button>
<button class="linkbutton" id="syslogbutton">Syslog</button>
<button class="linkbutton" id="settingsbutton">Settings</button>
<button class="linkbutton" id="rebootbutton">Reboot</button>
</div>
<h1>Openrouter Admin</h1>
@@ -28,6 +30,7 @@
</header>
<!-- header -->
<!-- settings block -->
<div class="section">
<section class="settingssection">
<!-- telnet settings -->
<div class="settingrect">
@@ -142,6 +145,13 @@
</div>
<!-- ssh settings -->
</section>
<!-- syslog block -->
<section class="syslogsection">
<h2 class="syslogheader">Syslog</h2>
<div class="syslogdata"></div>
</section>
<!-- syslog block -->
</div>
<!-- settings block -->
</section>
@@ -219,6 +229,7 @@
</div>
</div>
<!-- loader -->
<script src="js/header.js"></script>
<script src="js/routes.js"></script>
<script src="js/notification.js"></script>
<script src="js/loader.js"></script>
@@ -231,6 +242,7 @@
<script src="js/settings/settings.js"></script>
<script src="js/reboot.js"></script>
<script src="js/syslog.js"></script>
<script src="js/login.js"></script>
</body>
</html>
+15
View File
@@ -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()
})
+2 -1
View File
@@ -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('/'),
+13
View File
@@ -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','<br>')
}).catch((error) => {
notification(`Ошибка на сервере: ${error}`, "error")
})
}