wifiqr added
This commit is contained in:
1 parent
3427b5ec95
commit
646c0ef32d
9 files changed
+87
-2
No files matched your search
@@ -23,10 +23,14 @@ add_executable(
|
||||
src/settings/wifi/status.cpp
|
||||
src/settings/wifi/name.cpp
|
||||
src/settings/wifi/password.cpp
|
||||
src/settings/wifi/qr.cpp
|
||||
|
||||
src/settings/ftp/ftp.cpp
|
||||
|
||||
src/reboot/reboot.cpp
|
||||
|
||||
src/syslog/syslog.cpp
|
||||
|
||||
src/libs/QR-Code-generator/qrcodegen.cpp
|
||||
src/libs/QR-Code-generator/qrtosvg.cpp
|
||||
)
|
||||
@@ -44,6 +44,7 @@ int main() {
|
||||
srv.Post("/api/settings/wifi/name/set", set_wifi_name);
|
||||
srv.Post("/api/settings/wifi/password/get", get_wifi_password);
|
||||
srv.Post("/api/settings/wifi/password/set", set_wifi_password);
|
||||
srv.Post("/api/settings/wifi/qr/get", get_wifi_qr);
|
||||
|
||||
srv.Post("/api/reboot", reboot);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||
#define WIFI_NAME_REQUIRED_STRING R"({"required":"[token,name]"})"
|
||||
|
||||
void get_wifi_name(const httplib::Request &request, httplib::Response &response) {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <string>
|
||||
#include <syslog.h>
|
||||
|
||||
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||
#define WIFI_PASSWORD_REQUIRED_STRING R"({"required":"[token,password,newpassword]"})"
|
||||
|
||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response) {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "wifi.hpp"
|
||||
#include <colors.h>
|
||||
#include <json.hpp>
|
||||
#include "../../routes.hpp"
|
||||
#include "../../types.hpp"
|
||||
#include <QR-Code-generator/qrcodegen.hpp>
|
||||
#include <QR-Code-generator/qrtosvg.hpp>
|
||||
|
||||
void get_wifi_qr(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 (request.body.empty()) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
if (json_body["token"] == nullptr) {
|
||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
httplib::Client cli(AUTH_SERVICE);
|
||||
|
||||
std::stringstream body;
|
||||
body << R"({"token":)" << json_body["token"] << R"(})";
|
||||
|
||||
httplib::Result res = cli.Post("/api/access", body.str().c_str(), JSON_TYPE);
|
||||
if (res->status == httplib::OK_200) {
|
||||
nlohmann::json resjson = nlohmann::json::parse(res->body);
|
||||
if (resjson["access"] == "reject") {
|
||||
response.set_content(resjson.dump().c_str(), JSON_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream wifisettingsfile(WIFI_SETTINGS_PATH);
|
||||
std::string wifi_name;
|
||||
std::string wifi_password;
|
||||
std::string wifisettingsbuffer;
|
||||
while (std::getline(wifisettingsfile, wifisettingsbuffer)) {
|
||||
if (wifisettingsbuffer.find("ssid=") == 0) {
|
||||
wifi_name = wifisettingsbuffer;
|
||||
wifi_name.erase(0, 5);
|
||||
}
|
||||
if (wifisettingsbuffer.find("wpa_passphrase=") == 0) {
|
||||
wifi_password = wifisettingsbuffer;
|
||||
wifi_password.erase(0, 15);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wifisettingsfile.close();
|
||||
|
||||
std::stringstream toqrstring;
|
||||
toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";";
|
||||
|
||||
std::cout << toqrstring.str() << std::endl;
|
||||
|
||||
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(toqrstring.str().c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
||||
std::string responsedata = toSvgString(qr0, 4);
|
||||
response.set_content(responsedata, SVG_TYPE);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <httplib.h>
|
||||
|
||||
#define WIFI_SETTINGS_PATH "/etc/hostapd/hostapd.conf"
|
||||
|
||||
void get_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_status(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
@@ -12,4 +14,6 @@ void set_wifi_name(const httplib::Request &request, httplib::Response &response)
|
||||
void get_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
void set_wifi_password(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
void get_wifi_qr(const httplib::Request &request, httplib::Response &response);
|
||||
|
||||
#endif // WIFI_HPP
|
||||
@@ -7,5 +7,6 @@
|
||||
#define STRING403 R"({"status":"403"})"
|
||||
#define JSON_TYPE "application/json"
|
||||
#define PLAIN_TEXT_TYPE "text/plain"
|
||||
#define SVG_TYPE "image/svg"
|
||||
|
||||
#endif // TYPES_H
|
||||
@@ -206,6 +206,17 @@ tbody>tr>th {
|
||||
justify-content: space-between; */
|
||||
}
|
||||
|
||||
#wifiqrimg {
|
||||
width: 0;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#wifiqrimg.active {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1200px) {
|
||||
.settingrect {
|
||||
width: 50%;
|
||||
|
||||
@@ -153,6 +153,10 @@
|
||||
<button id="shownewpasswordbutton">Show</button>
|
||||
<input type="password" id="newwifipassword" class="forminput">
|
||||
</div>
|
||||
<div class="checkbox-wrapper-2">
|
||||
<input type="checkbox" class="sc-gJwTLC ikxBAC" id="wifiqr">
|
||||
</div>
|
||||
<img src="" alt="qr to connect" id="wifiqrimg">
|
||||
</div>
|
||||
<div class="settingrectfooter onebutton">
|
||||
<button class="settingrectfooterbutton" id="setwifisettings">Confirm</button>
|
||||
|
||||
Reference in new issue
Block a user