diff --git a/platformio.ini b/platformio.ini index fc7ad65..13655fa 100644 --- a/platformio.ini +++ b/platformio.ini @@ -42,7 +42,7 @@ build_flags = build_unflags = -std=gnu++11 -custom_version = 0.2.0 +custom_version = 0.1.1 custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev|RELEASE=1.0.0 [env:obpkp61] diff --git a/src/hash.cpp b/src/hash.cpp index 728fd8c..cac118a 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -22,16 +22,5 @@ String get_sha256(String payload) { buffer[i*2+1] = hexmap[shaResult[i] & 0x0F]; } buffer[sizeof(buffer) - 1] = '\0'; - String hash = String(buffer); - - ESP_LOGI(TAG, "SHA256 payload: %s", payload); - ESP_LOGI(TAG, "SHA256 hash: %s", hash.c_str()); - //Serial.print("SHA256 payload: "); - //Serial.print(payload); - //Serial.println(); - //Serial.print("SHA256-Hash: "); - //Serial.print(hash); - //Serial.println(); - - return hash; + return String(buffer); } diff --git a/src/main.cpp b/src/main.cpp index 439c0a4..d621468 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include "config.h" #include "webserver.h" #include "led.h" -#include "hash.h" #include #include #include @@ -481,9 +480,6 @@ void setup() { sht_available = (stat == 0x8010); LOGI(TAG, "SHT31 state=0x%X", stat); - // Additional tests - String passhash = get_sha256("secretTEST"); - xTaskCreatePinnedToCore( ledTask, // Task function "LEDTask", // Task name diff --git a/src/webserver.cpp b/src/webserver.cpp index 558d39d..90325c7 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -1,6 +1,7 @@ #include "main.h" #include "config.h" #include "webserver.h" +#include "hash.h" #include "led.h" #include #include @@ -96,11 +97,14 @@ void webserver_init() { }); server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request) { + // hash has to be in sha256 format LOGD(TAG, "checkpass called"); + String hash = request->arg("hash"); StaticJsonDocument<100> doc; - // TODO _hash überprüfen! - // LOGD(TAG, "check hash: %s", hash); - doc["status"] = "OK"; + String passhash = get_sha256(config.getString("adminPassword")); + LOGD(TAG, "check hash: %s", hash.c_str()); + LOGD(TAG, "check against: %s", passhash.c_str()); + doc["status"] = hash == passhash ? "OK" : "FAILED"; String out; serializeJson(doc, out); request->send(200, "application/json", out); @@ -245,7 +249,7 @@ void webserver_init() { LOGD(TAG, "POST %s=%s; key not found!", p->name(), p->value()); continue; } - LOGD(TAG, "POST %s=%s", p->name(), p->value()); + LOGD(TAG, "POST %s=%s", p->name(), p->value().c_str()); // get old value for comparison ConfigValue oldval = config.get(p->name().c_str()); config.setValue(p->name().c_str(), p->value().c_str()); @@ -273,11 +277,15 @@ void webserver_init() { server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) { // the request handler is triggered after the upload has finished... // create the response, add header, and send response - LOGI(TAG, "update called"); + LOGD(TAG, "Firmware update finished"); StaticJsonDocument<100> doc; if (updateSuccess) { doc["status"] = "OK"; doc["message"] = "Update sucessfull, rebooting..."; + // Wait for TCP ACK to ensure response is received completely + request->client()->onAck([](void* arg, AsyncClient* c, size_t len, uint32_t time) { + ESP.restart(); + }); } else { doc["status"] = "FAILED"; doc["message"] = updateError; @@ -285,14 +293,10 @@ void webserver_init() { String out; serializeJson(doc, out); request->send(200, "application/json", out); - if (updateSuccess) { - delay(100); // Ensure response is sent - ESP.restart(); - } }, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { // this is the new image upload part if (index == 0) { - LOGI(TAG, "Retrieving firmware image named: %s", filename); + LOGI(TAG, "Retrieving firmware image named: %s", filename.c_str()); if (! Update.begin(UPDATE_SIZE_UNKNOWN)) { Update.printError(Serial); updateError = "Update.begin() failed"; diff --git a/web/index.html b/web/index.html index baa4677..e6c6546 100644 --- a/web/index.html +++ b/web/index.html @@ -135,7 +135,7 @@ if (!window.isSecureContext) {
- + Details