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
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:
1 parent
c376868513
commit
cedc9cd995
38 files changed
+313
-1364
No files matched your search
@@ -1,11 +1,6 @@
|
||||
#include <settings/ftp/ftp.hpp>
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include <types.hpp>
|
||||
#include <syslog.h>
|
||||
#include <auth/auth.hpp>
|
||||
#include <helpers.hpp>
|
||||
#include <config/config.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define FTP_REQUIRED_STRING R"({"required":"[token,enabled]"})"
|
||||
|
||||
@@ -15,52 +10,8 @@ namespace api
|
||||
{
|
||||
namespace ftp
|
||||
{
|
||||
void get_ftp(const httplib::Request& request, httplib::Response& response)
|
||||
void set_ftp(bool new_ftp_enabled)
|
||||
{
|
||||
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 ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
|
||||
void set_ftp(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["enabled"] == nullptr)
|
||||
{
|
||||
response.set_content(FTP_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
bool new_ftp_enabled = json_body["enabled"];
|
||||
if (!new_ftp_enabled)
|
||||
{
|
||||
system("rc stop ftp");
|
||||
@@ -73,15 +24,6 @@ namespace api
|
||||
system("rc add ftp");
|
||||
syslog(LOG_INFO, "%s", "Ftp is enabled");
|
||||
}
|
||||
config::config.setConfig(std::string("../config.json"));
|
||||
nlohmann::json new_config = config::config.getConfig();
|
||||
new_config["settings"]["ftp"]["enabled"] = new_ftp_enabled;
|
||||
config::config.setConfig(new_config);
|
||||
config::config.saveConfig();
|
||||
int ftp_enabled = config::config.getConfig()["settings"]["ftp"]["enabled"];
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"enabled":")" << ftp_enabled << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user