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
@@ -16,100 +16,103 @@ namespace api
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
void get_wifi_channel(const httplib::Request &request, httplib::Response &response)
|
||||
namespace wifi
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
void get_wifi_channel(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 wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
||||
{
|
||||
if (wifisettingsbuffer.find("channel=") == 0)
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
if (!check_body(request))
|
||||
{
|
||||
wifi_channel = wifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
|
||||
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;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
||||
{
|
||||
if (wifisettingsbuffer.find("channel=") == 0)
|
||||
if (!authenticate(json_body["token"]))
|
||||
{
|
||||
old_channel = wifisettingsbuffer;
|
||||
old_channel.erase(0, 8);
|
||||
break;
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
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;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI channel changed to " + new_channel;
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer))
|
||||
{
|
||||
if (changedwifisettingsbuffer.find("channel=") == 0)
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
||||
{
|
||||
wifi_channel = changedwifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
if (wifisettingsbuffer.find("channel=") == 0)
|
||||
{
|
||||
wifi_channel = wifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
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;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
||||
{
|
||||
if (wifisettingsbuffer.find("channel=") == 0)
|
||||
{
|
||||
old_channel = wifisettingsbuffer;
|
||||
old_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
system(systemrequest.str().c_str());
|
||||
system("rc restart hostapd");
|
||||
std::string syslogstring = "WIFI channel changed to " + new_channel;
|
||||
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
||||
|
||||
std::ifstream changedwifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_channel;
|
||||
std::string changedwifisettingsbuffer;
|
||||
while (std::getline(changedwifisettingsfile, changedwifisettingsbuffer))
|
||||
{
|
||||
if (changedwifisettingsbuffer.find("channel=") == 0)
|
||||
{
|
||||
wifi_channel = changedwifisettingsbuffer;
|
||||
wifi_channel.erase(0, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
changedwifisettingsfile.close();
|
||||
std::stringstream responsedata;
|
||||
responsedata << R"({"channel":")" << wifi_channel << R"("})";
|
||||
response.set_content(responsedata.str(), JSON_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user