deleted rootfs and auth_service

This commit is contained in:
wt committed 2024-12-15 01:58:36 +07:00
1 parent b694830190
commit 85652a4e99
156 files changed
-2051

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
#include "reboot.hpp"
#include <json.hpp>
#include <colors.h>
#include "../types.hpp"
#include "../../auth/auth.hpp"
namespace api
{
namespace system
{
void reboot(const httplib::Request &request, httplib::Response &response)
{
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (request.body.empty())
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["token"] == nullptr)
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
if (authenticate(json_body["token"]))
{
std::system("reboot");
}
response.set_content(R"({"access":"reject"})", JSON_TYPE);
}
}
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef REBOOT_HPP
#define REBOOT_HPP
#include <httplib.h>
namespace api
{
namespace system
{
void reboot(const httplib::Request &request, httplib::Response &response);
}
}
#endif // REBOOT_HPP
+23
View File
@@ -0,0 +1,23 @@
#include "syslog.hpp"
#include "../types.hpp"
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#define SYSLOG_FILE "/var/log/messages"
namespace api
{
namespace system
{
void get_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);
}
}
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef SYSLOG_HPP
#define SYSLOG_HPP
#include <httplib.h>
namespace api
{
namespace system
{
void get_syslog(const httplib::Request &request, httplib::Response &response);
}
}
#endif // SYSLOG_HPP
+10
View File
@@ -0,0 +1,10 @@
#ifndef SYSTEM_HPP
#define SYSTEM_HPP
#ifdef __linux__
#include "uptime/uptime.hpp"
#endif // __linux__
#include "syslog/syslog.hpp"
#include "reboot/reboot.hpp"
#endif // SYSTEM_HPP
+37
View File
@@ -0,0 +1,37 @@
#include "uptime.hpp"
#ifdef __linux__
#include <sys/sysinfo.h>
#endif // __linux__
#include <sstream>
#include "../types.hpp"
namespace api
{
namespace system
{
void get_uptime(const httplib::Request &request, httplib::Response &response)
{
#ifdef __linux__
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);
#endif // __linux__
}
}
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef UPTIME_HPP
#define UPTIME_HPP
#include <httplib.h>
namespace api
{
namespace system
{
void get_uptime(const httplib::Request &request, httplib::Response &response);
}
}
#endif // UPTIME_HPP