From 0a0d0b9ea7b0f44ee3ab57803f959b5ac4478b21 Mon Sep 17 00:00:00 2001 From: iranl Date: Tue, 11 Feb 2025 17:00:56 +0100 Subject: [PATCH] No TOTP if not time synced --- src/NukiNetwork.cpp | 2 +- src/WebCfgServer.cpp | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index a010aee..8dfd06e 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -1093,7 +1093,7 @@ void NukiNetwork::onMqttDataReceived(const char* topic, byte* payload, const uns { if(_preferences->getBool(preference_cred_duo_approval, false) && (_importExport->getTOTPEnabled() || _importExport->getDuoEnabled())) { - if(_importExport->getTOTPEnabled() && !doc["totp"].isNull()) + if(timeSynced && _importExport->getTOTPEnabled() && !doc["totp"].isNull()) { String jsonTotp = doc["totp"]; diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 3598eb2..80bba13 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -629,7 +629,7 @@ void WebCfgServer::initialize() _importExport->_sessionsOpts[request->client()->localIP().toString() + "approve"] = false; return sendSettings(request, resp); } - else if(request->hasParam("totpkey") && _importExport->getTOTPEnabled()) + else if(timeSynced && request->hasParam("totpkey") && _importExport->getTOTPEnabled()) { const PsychicWebParameter* pass = request->getParam("totpkey"); if(pass->value() != "") @@ -853,7 +853,7 @@ void WebCfgServer::initialize() if(!_importExport->_sessionsOpts[request->client()->localIP().toString() + "approve"]) { bool approved = false; - if(request->hasParam("totpkey") && _importExport->getTOTPEnabled()) + if(timeSynced && request->hasParam("totpkey") && _importExport->getTOTPEnabled()) { const PsychicWebParameter* pass = request->getParam("totpkey"); if(pass->value() != "") @@ -1880,18 +1880,15 @@ esp_err_t WebCfgServer::buildLoginHtml(PsychicRequest *request, PsychicResponse* esp_err_t WebCfgServer::buildTOTPHtml(PsychicRequest *request, PsychicResponse* resp, int type) { + if (!timeSynced) + { + return buildConfirmHtml(request, resp, "NTP time not synced yet, TOTP not available, please wait for NTP to sync", 3, true); + } + PsychicStreamResponse response(resp, "text/html"); response.beginSend(); response.print(""); response.print(""); - /* - if (!timeSynced) - { - char millis[20]; - itoa(espMillis(), millis, 10); - response.print((String)""); - } - */ response.print("

Nuki Hub TOTP

"); String typeText = "Login"; @@ -1931,12 +1928,6 @@ esp_err_t WebCfgServer::buildTOTPHtml(PsychicRequest *request, PsychicResponse* response.print("
"); response.print(""); - /* - if (!timeSynced) - { - response.print(""); - } - */ response.print("