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
41 lines
1.4 KiB
C++
41 lines
1.4 KiB
C++
#include <settings/wifi/wifi.hpp>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <fstream>
|
|
#include <syslog.h>
|
|
|
|
#define WIFI_NAME_REQUIRED_STRING R"({"required":"[token,name]"})"
|
|
|
|
namespace api
|
|
{
|
|
namespace settings
|
|
{
|
|
namespace wifi
|
|
{
|
|
void set_wifi_name(std::string new_wifi_name)
|
|
{
|
|
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
|
std::string old_wifi_name;
|
|
std::string wifisettingsbuffer;
|
|
while (std::getline(wifisettingsfile, wifisettingsbuffer))
|
|
{
|
|
if (wifisettingsbuffer.find("ssid=") == 0)
|
|
{
|
|
old_wifi_name = wifisettingsbuffer;
|
|
old_wifi_name.erase(0, 5);
|
|
break;
|
|
}
|
|
}
|
|
wifisettingsfile.close();
|
|
std::stringstream systemrequest;
|
|
systemrequest << "sed -i \"/ssid=" << old_wifi_name << "/s//ssid=" << new_wifi_name << "/\" /etc/hostapd/hostapd.conf";
|
|
std::cout << systemrequest.str() << std::endl;
|
|
system(systemrequest.str().c_str());
|
|
system("rc restart hostapd");
|
|
std::string syslogstring = "WIFI name changed to " + new_wifi_name;
|
|
syslog(LOG_INFO, "%s", syslogstring.c_str());
|
|
}
|
|
}
|
|
}
|
|
}
|