some hot fixes
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
This commit is contained in:
1 parent
84733a2644
commit
ad266d0332
23 files changed
+1126
-1067
No files matched your search
+78
-75
@@ -12,88 +12,91 @@ namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response)
|
||||
namespace ssh
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
void get_ssh_status(const httplib::Request &request, httplib::Response &response)
|
||||
{
|
||||
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;
|
||||
}
|
||||
std::ifstream sshstatusfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshstatusfile >> ssh_status;
|
||||
sshstatusfile.close();
|
||||
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;
|
||||
}
|
||||
std::ofstream sshfileout("/etc/openrouter/ssh/status");
|
||||
std::string new_ssh_status = json_body["status"];
|
||||
if (new_ssh_status == "0")
|
||||
{
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
system("rc stop dropbear");
|
||||
system("rc del dropbear");
|
||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
||||
system("rc stop ssh");
|
||||
system("rc del ssh");
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
syslog(LOG_INFO, "%s", "SSH is disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
system("rc start dropbear");
|
||||
system("rc add dropbear");
|
||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
||||
system("rc start ssh");
|
||||
system("rc add ssh");
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
syslog(LOG_INFO, "%s", "SSH is enabled");
|
||||
std::ifstream sshstatusfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshstatusfile >> ssh_status;
|
||||
sshstatusfile.close();
|
||||
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;
|
||||
}
|
||||
std::ofstream sshfileout("/etc/openrouter/ssh/status");
|
||||
std::string new_ssh_status = json_body["status"];
|
||||
if (new_ssh_status == "0")
|
||||
{
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
{
|
||||
system("rc stop dropbear");
|
||||
system("rc del dropbear");
|
||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
||||
system("rc stop ssh");
|
||||
system("rc del ssh");
|
||||
}
|
||||
syslog(LOG_INFO, "%s", "SSH is disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (get_ssh_server() == DROPBEAR_SSH)
|
||||
{
|
||||
system("rc start dropbear");
|
||||
system("rc add dropbear");
|
||||
} else if (get_ssh_server() == OPENSSH_SSH) {
|
||||
system("rc start ssh");
|
||||
system("rc add ssh");
|
||||
}
|
||||
syslog(LOG_INFO, "%s", "SSH is enabled");
|
||||
}
|
||||
sshfileout << stoi(new_ssh_status);
|
||||
sshfileout.close();
|
||||
std::ifstream sshfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshfile >> ssh_status;
|
||||
sshfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << ssh_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
sshfileout << stoi(new_ssh_status);
|
||||
sshfileout.close();
|
||||
std::ifstream sshfile("/etc/openrouter/ssh/status");
|
||||
int ssh_status;
|
||||
sshfile >> ssh_status;
|
||||
sshfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"status":")" << ssh_status << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user