diff --git a/lib/nuki_ble b/lib/nuki_ble index 90e482b..8e79820 160000 --- a/lib/nuki_ble +++ b/lib/nuki_ble @@ -1 +1 @@ -Subproject commit 90e482b3d45d4cc1d585569b669ab92052a4008c +Subproject commit 8e79820f90904a4ca7c8f8f953a8cfda19632f59 diff --git a/src/Config.h b/src/Config.h index 5f6a10d..914b0d0 100644 --- a/src/Config.h +++ b/src/Config.h @@ -5,7 +5,7 @@ #define NUKI_HUB_VERSION "9.06" #define NUKI_HUB_VERSION_INT (uint32_t)906 #define NUKI_HUB_BUILD "unknownbuildnr" -#define NUKI_HUB_DATE "2024-12-21" +#define NUKI_HUB_DATE "2024-12-22" #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 6370f78..a0c972a 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -96,7 +96,6 @@ void WebCfgServer::initialize() } #endif }); - _psychicServer->on("/style.css", HTTP_GET, [&](PsychicRequest *request) { if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) @@ -113,37 +112,7 @@ void WebCfgServer::initialize() } return sendFavicon(request); }); - _psychicServer->on("/reboot", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - - 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; - }); - + if(_network->isApOpen()) { #ifndef CONFIG_IDF_TARGET_ESP32H2 @@ -173,247 +142,13 @@ void WebCfgServer::initialize() } return res; }); -#endif - } - else - { -#ifndef NUKI_HUB_UPDATER - _psychicServer->on("/import", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - String message = ""; - bool restart = processImport(request, message); - return buildConfirmHtml(request, message, 3, true); - }); - _psychicServer->on("/export", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return sendSettings(request); - }); - _psychicServer->on("/impexpcfg", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildImportExportHtml(request); - }); - _psychicServer->on("/status", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildStatusHtml(request); - }); - _psychicServer->on("/acclvl", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildAccLvlHtml(request); - }); - _psychicServer->on("/custntw", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildCustomNetworkConfigHtml(request); - }); - _psychicServer->on("/advanced", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildAdvancedConfigHtml(request); - }); - _psychicServer->on("/cred", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildCredHtml(request); - }); - _psychicServer->on("/ntwconfig", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildNetworkConfigHtml(request); - }); - _psychicServer->on("/mqttconfig", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildMqttConfigHtml(request); - }); - _psychicServer->on("/nukicfg", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildNukiConfigHtml(request); - }); - _psychicServer->on("/gpiocfg", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildGpioConfigHtml(request); - }); -#ifndef CONFIG_IDF_TARGET_ESP32H2 - _psychicServer->on("/wifi", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildConfigureWifiHtml(request); - }); - _psychicServer->on("/wifimanager", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - 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("/"); - } - if(!_allowRestartToPortal) - { - return buildConfirmHtml(request, "Can't reset WiFi when network device is Ethernet", 3, true); - } - esp_err_t res = buildConfirmHtml(request, "Restarting. Connect to ESP access point (\"NukiHub\" with password \"NukiHubESP32\") to reconfigure Wi-Fi.", 0); - waitAndProcess(false, 1000); - _network->reconfigureDevice(); - return res; - }); -#endif - _psychicServer->on("/unpairlock", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return processUnpair(request, false); - }); - _psychicServer->on("/unpairopener", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return processUnpair(request, true); - }); - _psychicServer->on("/factoryreset", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return processFactoryReset(request); - }); - _psychicServer->on("/info", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildInfoHtml(request); - }); - _psychicServer->on("/debugon", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - _preferences->putBool(preference_publish_debug_info, true); - return buildConfirmHtml(request, "Debug On", 3, true); - }); - _psychicServer->on("/debugoff", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - _preferences->putBool(preference_publish_debug_info, false); - return buildConfirmHtml(request, "Debug Off", 3, true); - }); - _psychicServer->on("/savecfg", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - String message = ""; - bool restart = processArgs(request, message); - return buildConfirmHtml(request, message, 3, true); - }); - _psychicServer->on("/savegpiocfg", HTTP_POST, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - processGpioArgs(request); - esp_err_t res = buildConfirmHtml(request, "Saving GPIO configuration. Restarting.", 3, true); - Log->println(F("Restarting")); - waitAndProcess(true, 1000); - restartEsp(RestartReason::GpioConfigurationUpdated); - return res; - }); -#endif - _psychicServer->on("/ota", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildOtaHtml(request); - }); - _psychicServer->on("/otadebug", HTTP_GET, [&](PsychicRequest *request) - { - if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) - { - return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); - } - return buildOtaHtml(request, true); - }); - _psychicServer->on("/reboottoota", HTTP_GET, [&](PsychicRequest *request) + _psychicServer->on("/reboot", HTTP_GET, [&](PsychicRequest *request) { if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) { return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); } + String value = ""; if(request->hasParam("CONFIRMTOKEN")) { @@ -432,23 +167,301 @@ void WebCfgServer::initialize() { return request->redirect("/"); } - esp_err_t res = buildConfirmHtml(request, "Rebooting to other partition...", 2, true); + esp_err_t res = buildConfirmHtml(request, "Rebooting...", 2, true); waitAndProcess(true, 1000); - esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)); - restartEsp(RestartReason::OTAReboot); + restartEsp(RestartReason::RequestedViaWebServer); return res; }); - _psychicServer->on("/autoupdate", HTTP_GET, [&](PsychicRequest *request) +#endif + } + else + { + _psychicServer->on("/get", HTTP_GET, [&](PsychicRequest *request) { if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) { return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); } -#ifndef NUKI_HUB_UPDATER - return processUpdate(request); -#else - return request->redirect("/"); -#endif + + String value = ""; + if(request->hasParam("page")) + { + const PsychicWebParameter* p = request->getParam("page"); + if(p->value() != "") + { + value = p->value(); + } + } + + if (value == "reboot") + { + 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; + } + #ifndef NUKI_HUB_UPDATER + else if (value == "info") + { + return buildInfoHtml(request); + } + else if (value == "debugon") + { + _preferences->putBool(preference_publish_debug_info, true); + return buildConfirmHtml(request, "Debug On", 3, true); + } + else if (value == "debugoff") + { + _preferences->putBool(preference_publish_debug_info, false); + return buildConfirmHtml(request, "Debug Off", 3, true); + } + else if (value == "export") + { + return sendSettings(request); + } + else if (value == "impexpcfg") + { + return buildImportExportHtml(request); + } + else if (value == "status") + { + return buildStatusHtml(request); + } + else if (value == "acclvl") + { + return buildAccLvlHtml(request); + } + else if (value == "custntw") + { + return buildCustomNetworkConfigHtml(request); + } + else if (value == "advanced") + { + return buildAdvancedConfigHtml(request); + } + else if (value == "cred") + { + return buildCredHtml(request); + } + else if (value == "ntwconfig") + { + return buildNetworkConfigHtml(request); + } + else if (value == "mqttconfig") + { + return buildMqttConfigHtml(request); + } + else if (value == "mqttcaconfig") + { + return buildMqttSSLConfigHtml(request, 0); + } + else if (value == "mqttcrtconfig") + { + return buildMqttSSLConfigHtml(request, 1); + } + else if (value == "mqttkeyconfig") + { + return buildMqttSSLConfigHtml(request, 2); + } + else if (value == "nukicfg") + { + return buildNukiConfigHtml(request); + } + else if (value == "gpiocfg") + { + return buildGpioConfigHtml(request); + } + #ifndef CONFIG_IDF_TARGET_ESP32H2 + else if (value == "wifi") + { + return buildConfigureWifiHtml(request); + } + else if (value == "wifimanager") + { + 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("/"); + } + if(!_allowRestartToPortal) + { + return buildConfirmHtml(request, "Can't reset WiFi when network device is Ethernet", 3, true); + } + esp_err_t res = buildConfirmHtml(request, "Restarting. Connect to ESP access point (\"NukiHub\" with password \"NukiHubESP32\") to reconfigure Wi-Fi.", 0); + waitAndProcess(false, 1000); + _network->reconfigureDevice(); + return res; + } + #endif + #endif + else if (value == "ota") + { + return buildOtaHtml(request); + } + else if (value == "otadebug") + { + return buildOtaHtml(request, true); + } + else if (value == "reboottoota") + { + 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); + return res; + } + else if (value == "autoupdate") + { + #ifndef NUKI_HUB_UPDATER + return processUpdate(request); + #else + return request->redirect("/"); + #endif + } + else + { + if(!_network->isApOpen()) + { + #ifndef NUKI_HUB_UPDATER + return buildHtml(request); + #else + return buildOtaHtml(request); + #endif + } + #ifndef CONFIG_IDF_TARGET_ESP32H2 + else + { + return buildWifiConnectHtml(request); + } + #endif + } + }); + _psychicServer->on("/post", HTTP_POST, [&](PsychicRequest *request) + { + if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword)) + { + return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in."); + } + + String value = ""; + if(request->hasParam("page")) + { + const PsychicWebParameter* p = request->getParam("page"); + if(p->value() != "") + { + value = p->value(); + } + } + + #ifndef NUKI_HUB_UPDATER + if (value == "savecfg") + { + String message = ""; + bool restart = processArgs(request, message); + if(request->hasParam("mqttssl")) + { + return buildConfirmHtml(request, message, 3, true, "/get?page=mqttconfig"); + } + else + { + return buildConfirmHtml(request, message, 3, true); + } + } + else if (value == "savegpiocfg") + { + processGpioArgs(request); + esp_err_t res = buildConfirmHtml(request, "Saving GPIO configuration. Restarting.", 3, true); + Log->println(F("Restarting")); + waitAndProcess(true, 1000); + restartEsp(RestartReason::GpioConfigurationUpdated); + return res; + } + else if (value == "unpairlock") + { + return processUnpair(request, false); + } + else if (value == "unpairopener") + { + return processUnpair(request, true); + } + else if (value == "factoryreset") + { + return processFactoryReset(request); + } + else if (value == "import") + { + String message = ""; + bool restart = processImport(request, message); + return buildConfirmHtml(request, message, 3, true); + } + else + #else + if (1 == 1) + #endif + { + if(!_network->isApOpen()) + { + #ifndef NUKI_HUB_UPDATER + return buildHtml(request); + #else + return buildOtaHtml(request); + #endif + } + #ifndef CONFIG_IDF_TARGET_ESP32H2 + else + { + return buildWifiConnectHtml(request); + } + #endif + } }); PsychicUploadHandler *updateHandler = new PsychicUploadHandler(); @@ -823,9 +836,9 @@ esp_err_t WebCfgServer::buildOtaHtml(PsychicRequest *request, bool debug) #else String build_type = "debug"; #endif - response.print("
"); - response.print(""); - response.print(""); + response.print(""); + response.print(""); + response.print(""); response.print("