diff --git a/src/Config.h b/src/Config.h index fd8bfc4..75661ba 100644 --- a/src/Config.h +++ b/src/Config.h @@ -4,7 +4,7 @@ #define NUKI_HUB_VERSION "9.02" #define NUKI_HUB_BUILD "unknownbuildnr" -#define NUKI_HUB_DATE "2024-10-18" +#define NUKI_HUB_DATE "2024-10-19" #define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest" #define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json" diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index ed4d76a..7aed68c 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -104,7 +104,23 @@ void WebCfgServer::initialize() }); _psychicServer->on("/reboot", HTTP_GET, [&](PsychicRequest *request){ if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - esp_err_t res = buildConfirmHtml(request, "Rebooting", 2, true); + + String value = ""; + if(request->hasParam("CONFIRMTOKEN")) + { + const PsychicWebParameter* p = request->getParam("CONFIRMTOKEN"); + if(p->value() != "") value = p->value(); + } + else + { + return buildConfirmHtml(request, "No confirm code set.", 3, true); + } + + if(value != _confirmCode) + { + return request->redirect("/"); + } + esp_err_t res = buildConfirmHtml(request, "Rebooting...", 2, true); waitAndProcess(true, 1000); restartEsp(RestartReason::RequestedViaWebServer); return res; @@ -251,7 +267,22 @@ void WebCfgServer::initialize() }); _psychicServer->on("/reboottoota", HTTP_GET, [&](PsychicRequest *request){ if(strlen(_credUser) > 0 && strlen(_credPassword) > 0) if(!request->authenticate(_credUser, _credPassword)) return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - esp_err_t res = buildConfirmHtml(request, "Rebooting to other partition", 2, true); + String value = ""; + if(request->hasParam("CONFIRMTOKEN")) + { + const PsychicWebParameter* p = request->getParam("CONFIRMTOKEN"); + if(p->value() != "") value = p->value(); + } + else + { + return buildConfirmHtml(request, "No confirm code set.", 3, true); + } + + if(value != _confirmCode) + { + return request->redirect("/"); + } + esp_err_t res = buildConfirmHtml(request, "Rebooting to other partition...", 2, true); waitAndProcess(true, 1000); esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)); restartEsp(RestartReason::OTAReboot); @@ -409,7 +440,9 @@ esp_err_t WebCfgServer::buildWifiConnectHtml(PsychicRequest *request) response.print(""); response.print("
"); response.print(""); - response.print("

"); + response.print("

"); response.print(""); return response.endSend(); } @@ -668,7 +701,9 @@ esp_err_t WebCfgServer::buildOtaHtml(PsychicRequest *request, bool debug) response.print("

Manually update Nuki Hub

"); response.print("

Reboot to Nuki Hub Updater

"); response.print("Click on the button to reboot to the Nuki Hub updater, where you can select the latest Nuki Hub binary to update"); - response.print("



"); + response.print("



"); response.print("

Update Nuki Hub Updater

"); response.print("Select the latest Nuki Hub updater binary to update the Nuki Hub updater"); response.print("
Choose the nuki_hub_updater.bin file to upload:
"); @@ -678,7 +713,9 @@ esp_err_t WebCfgServer::buildOtaHtml(PsychicRequest *request, bool debug) response.print("
"); response.print("

Reboot to Nuki Hub

"); response.print("Click on the button to reboot to Nuki Hub"); - response.print("


"); + response.print("



"); response.print("

Update Nuki Hub

"); response.print("Select the latest Nuki Hub binary to update Nuki Hub"); response.print("
Choose the nuki_hub.bin file to upload:
"); @@ -2991,7 +3028,8 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request) buildNavigationMenuEntry(&response, "Configure Wi-Fi", "/wifi"); } #endif - buildNavigationMenuEntry(&response, "Reboot Nuki Hub", "/reboot"); + String rebooturl = "/reboot?CONFIRMTOKEN=" + _confirmCode; + buildNavigationMenuEntry(&response, "Reboot Nuki Hub", rebooturl.c_str()); response.print(""); return response.endSend(); }