#include #include #include #include #include #include #include #include #include namespace api { namespace settings { namespace wifi { 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 (!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; } std::string wifi_password = config::config.getConfig()["settings"]["wifi"]["password"]; std::string wifi_name = config::config.getConfig()["settings"]["wifi"]["name"]; std::stringstream toqrstring; toqrstring << "WIFI:T:WPA;P:" << wifi_password << ";S:" << wifi_name << ";"; 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); } } } }