making easy
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run

This commit is contained in:
wt committed 2025-02-20 18:07:59 +07:00
1 parent c376868513
commit cedc9cd995
38 files changed
+313 -1364

No files matched your search

+1 -60
View File
@@ -1,11 +1,5 @@
#include <settings/ssh/ssh.hpp>
#include <colors.h>
#include <json.hpp>
#include <types.hpp>
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define SSH_REQUIRED_STRING R"({"required":"[token,status]"})"
@@ -15,52 +9,8 @@ namespace api
{
namespace ssh
{
void get_ssh_status(const httplib::Request& request, httplib::Response& response)
void set_ssh_status(bool new_ssh_status)
{
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
if (!check_body(request))
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (!authenticate(json_body["token"]))
{
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
config::config.setConfig(std::string("../config.json"));
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
void set_ssh_status(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 (!check_body(request))
{
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
return;
}
nlohmann::json json_body = nlohmann::json::parse(request.body);
if (json_body["status"] == nullptr)
{
response.set_content(SSH_REQUIRED_STRING, JSON_TYPE);
return;
}
if (!authenticate(json_body["token"]))
{
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
bool new_ssh_status = json_body["status"];
if (!new_ssh_status)
{
if (get_ssh_server() == DROPBEAR_SSH)
@@ -87,15 +37,6 @@ namespace api
}
syslog(LOG_INFO, "%s", "SSH is enabled");
}
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["ssh"]["enabled"] = new_ssh_status;
config::config.setConfig(new_config);
config::config.saveConfig();
int ssh_status = config::config.getConfig()["settings"]["ssh"]["enabled"];
std::stringstream responsedata;
responsedata << R"({"status":")" << ssh_status << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
}