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 -62
View File
@@ -1,15 +1,8 @@
#include <settings/wifi/wifi.hpp>
#include <colors.h>
#include <types.hpp>
#include <json.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <syslog.h>
#include <auth/auth.hpp>
#include <helpers.hpp>
#include <config/config.hpp>
#define WIFI_CHANNEL_REQUIRED_STRING R"({"required":"[token,channel]"})"
@@ -19,51 +12,8 @@ namespace api
{
namespace wifi
{
void get_wifi_channel(const httplib::Request& request, httplib::Response& response)
void set_wifi_channel(int new_channel)
{
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 wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
std::stringstream responsedata;
responsedata << R"({"channel":")" << wifi_channel << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
void set_wifi_channel(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["channel"] == nullptr)
{
response.set_content(WIFI_CHANNEL_REQUIRED_STRING, JSON_TYPE);
return;
}
if (!authenticate(json_body["token"]))
{
response.set_content(R"({"access":"reject"})", JSON_TYPE);
return;
}
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
std::string old_channel;
std::string wifisettingsbuffer;
@@ -77,7 +27,6 @@ namespace api
}
}
wifisettingsfile.close();
std::string new_channel = json_body["channel"];
std::stringstream systemrequest;
systemrequest << "sed -i \"/channel=" << old_channel << "/s//channel=" << new_channel << "/\" /etc/hostapd/hostapd.conf";
std::cout << systemrequest.str() << std::endl;
@@ -85,16 +34,6 @@ namespace api
system("rc restart hostapd");
std::string syslogstring = "WIFI channel changed to " + new_channel;
syslog(LOG_INFO, "%s", syslogstring.c_str());
sleep(1);
config::config.setConfig(std::string("../config.json"));
nlohmann::json new_config = config::config.getConfig();
new_config["settings"]["wifi"]["channel"] = std::stoi(new_channel);
config::config.setConfig(new_config);
config::config.saveConfig();
int wifi_channel = config::config.getConfig()["settings"]["wifi"]["channel"];
std::stringstream responsedata;
responsedata << R"({"channel":")" << wifi_channel << R"("})";
response.set_content(responsedata.str(), JSON_TYPE);
}
}
}