little fixes #32

Merged
wt merged 1 commits from little-patch-fix into main 2025-05-17 21:40:28 +07:00
6 changed files with 41 additions and 53 deletions
+16 -18
View File
@@ -21,17 +21,16 @@ namespace api
void Settings::restore(const httplib::Request& request, httplib::Response& response)
{
const httplib::MultipartFormData& file = request.get_file_value("restore_settings");
if (file.content_type == JSON_TYPE) {
nlohmann::json new_config = nlohmann::json::parse(file.content);
config::config.setConfig(new_config);
config::config.saveConfig();
set_all_settings(config::config.getConfig());
response.set_content(R"({"status":true})", JSON_TYPE);
system("rc restart auth_service");
system("rc restart openrouter");
if (!file.content_type.compare(JSON_TYPE)) {
response.set_content(R"({"status":false})", JSON_TYPE);
return;
}
response.set_content(R"({"status":false})", JSON_TYPE);
nlohmann::json new_config = nlohmann::json::parse(file.content);
config::config.setConfig(new_config);
config::config.saveConfig();
set_all_settings(config::config.getConfig());
response.set_content(R"({"status":true})", JSON_TYPE);
system("rc restart openrouter");
}
void Settings::restore_defaults(const httplib::Request& request, httplib::Response& response)
@@ -39,17 +38,16 @@ namespace api
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
check_body_empty(request, response, ACCESS_REQUIRED_STRING);
if (std::filesystem::exists(config::config.getConfigFileName())) {
std::filesystem::remove(config::config.getConfigFileName());
std::filesystem::copy("../config_default.json", config::config.getConfigFileName());
config::config.setConfig(config::config.getConfigFileName());
set_all_settings(config::config.getConfig());
response.set_content(R"({"status":true})", JSON_TYPE);
system("rc restart auth_service");
system("rc restart openrouter");
if (!std::filesystem::exists(config::config.getConfigFileName())) {
response.set_content(R"({"status":false})", JSON_TYPE);
return;
}
response.set_content(R"({"status":false})", JSON_TYPE);
std::filesystem::remove(config::config.getConfigFileName());
std::filesystem::copy("../config_default.json", config::config.getConfigFileName());
config::config.setConfig(config::config.getConfigFileName());
set_all_settings(config::config.getConfig());
response.set_content(R"({"status":true})", JSON_TYPE);
system("rc restart openrouter");
}
}
}
+4 -6
View File
@@ -14,13 +14,11 @@ namespace api
system("rc stop dnsmasq");
system("rc del dnsmasq");
syslog(LOG_INFO, "%s", "DNS is disabled");
return;
}
else
{
system("rc restart dnsmasq");
system("rc add dnsmasq");
syslog(LOG_INFO, "%s", "DNS is enabled");
}
system("rc restart dnsmasq");
system("rc add dnsmasq");
syslog(LOG_INFO, "%s", "DNS is enabled");
}
}
}
+4 -6
View File
@@ -17,13 +17,11 @@ namespace api
system("rc stop ftpd");
system("rc del ftpd");
syslog(LOG_INFO, "%s", "Ftp is disabled");
return;
}
else
{
system("rc start ftpd");
system("rc add ftpd");
syslog(LOG_INFO, "%s", "Ftp is enabled");
}
system("rc start ftpd");
system("rc add ftpd");
syslog(LOG_INFO, "%s", "Ftp is enabled");
}
}
}
+9 -11
View File
@@ -24,20 +24,18 @@ namespace api
system("rc del ssh");
}
syslog(LOG_INFO, "%s", "SSH is disabled");
return;
}
else
if (ssh_server == DROPBEAR_SSH)
{
if (ssh_server == DROPBEAR_SSH)
{
system("rc start dropbear");
system("rc add dropbear");
}
else if (ssh_server == OPENSSH_SSH) {
system("rc start ssh");
system("rc add ssh");
}
syslog(LOG_INFO, "%s", "SSH is enabled");
system("rc start dropbear");
system("rc add dropbear");
}
else if (ssh_server == OPENSSH_SSH) {
system("rc start ssh");
system("rc add ssh");
}
syslog(LOG_INFO, "%s", "SSH is enabled");
}
}
}
+4 -6
View File
@@ -17,13 +17,11 @@ namespace api
system("rc stop telnetd");
system("rc del telnetd");
syslog(LOG_INFO, "%s", "Telnet is disabled");
return;
}
else
{
system("rc start telnetd");
system("rc add telnetd");
syslog(LOG_INFO, "%s", "Telnet is enabled");
}
system("rc start telnetd");
system("rc add telnetd");
syslog(LOG_INFO, "%s", "Telnet is enabled");
}
}
}
+4 -6
View File
@@ -16,13 +16,11 @@ namespace api
system("rc stop hostapd");
system("rc del hostapd");
syslog(LOG_INFO, "%s", "WIFI is disabled");
return;
}
else
{
system("rc start hostapd");
system("rc add hostapd");
syslog(LOG_INFO, "%s", "WIFI is enabled");
}
system("rc start hostapd");
system("rc add hostapd");
syslog(LOG_INFO, "%s", "WIFI is enabled");
}
}
}