Web updater improved
This commit is contained in:
@@ -42,7 +42,7 @@ build_flags =
|
|||||||
build_unflags =
|
build_unflags =
|
||||||
-std=gnu++11
|
-std=gnu++11
|
||||||
|
|
||||||
custom_version = 0.2.0
|
custom_version = 0.1.1
|
||||||
custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev<yyyymmdd>|RELEASE=1.0.0
|
custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev<yyyymmdd>|RELEASE=1.0.0
|
||||||
|
|
||||||
[env:obpkp61]
|
[env:obpkp61]
|
||||||
|
|||||||
13
src/hash.cpp
13
src/hash.cpp
@@ -22,16 +22,5 @@ String get_sha256(String payload) {
|
|||||||
buffer[i*2+1] = hexmap[shaResult[i] & 0x0F];
|
buffer[i*2+1] = hexmap[shaResult[i] & 0x0F];
|
||||||
}
|
}
|
||||||
buffer[sizeof(buffer) - 1] = '\0';
|
buffer[sizeof(buffer) - 1] = '\0';
|
||||||
String hash = String(buffer);
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "webserver.h"
|
#include "webserver.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "hash.h"
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
@@ -481,9 +480,6 @@ void setup() {
|
|||||||
sht_available = (stat == 0x8010);
|
sht_available = (stat == 0x8010);
|
||||||
LOGI(TAG, "SHT31 state=0x%X", stat);
|
LOGI(TAG, "SHT31 state=0x%X", stat);
|
||||||
|
|
||||||
// Additional tests
|
|
||||||
String passhash = get_sha256("secretTEST");
|
|
||||||
|
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
ledTask, // Task function
|
ledTask, // Task function
|
||||||
"LEDTask", // Task name
|
"LEDTask", // Task name
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "webserver.h"
|
#include "webserver.h"
|
||||||
|
#include "hash.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
@@ -96,11 +97,14 @@ void webserver_init() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
|
// hash has to be in sha256 format
|
||||||
LOGD(TAG, "checkpass called");
|
LOGD(TAG, "checkpass called");
|
||||||
|
String hash = request->arg("hash");
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
// TODO _hash überprüfen!
|
String passhash = get_sha256(config.getString("adminPassword"));
|
||||||
// LOGD(TAG, "check hash: %s", hash);
|
LOGD(TAG, "check hash: %s", hash.c_str());
|
||||||
doc["status"] = "OK";
|
LOGD(TAG, "check against: %s", passhash.c_str());
|
||||||
|
doc["status"] = hash == passhash ? "OK" : "FAILED";
|
||||||
String out;
|
String out;
|
||||||
serializeJson(doc, out);
|
serializeJson(doc, out);
|
||||||
request->send(200, "application/json", 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());
|
LOGD(TAG, "POST %s=%s; key not found!", p->name(), p->value());
|
||||||
continue;
|
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
|
// get old value for comparison
|
||||||
ConfigValue oldval = config.get(p->name().c_str());
|
ConfigValue oldval = config.get(p->name().c_str());
|
||||||
config.setValue(p->name().c_str(), p->value().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) {
|
server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
// the request handler is triggered after the upload has finished...
|
// the request handler is triggered after the upload has finished...
|
||||||
// create the response, add header, and send response
|
// create the response, add header, and send response
|
||||||
LOGI(TAG, "update called");
|
LOGD(TAG, "Firmware update finished");
|
||||||
StaticJsonDocument<100> doc;
|
StaticJsonDocument<100> doc;
|
||||||
if (updateSuccess) {
|
if (updateSuccess) {
|
||||||
doc["status"] = "OK";
|
doc["status"] = "OK";
|
||||||
doc["message"] = "Update sucessfull, rebooting...";
|
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 {
|
} else {
|
||||||
doc["status"] = "FAILED";
|
doc["status"] = "FAILED";
|
||||||
doc["message"] = updateError;
|
doc["message"] = updateError;
|
||||||
@@ -285,14 +293,10 @@ void webserver_init() {
|
|||||||
String out;
|
String out;
|
||||||
serializeJson(doc, out);
|
serializeJson(doc, out);
|
||||||
request->send(200, "application/json", 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) {
|
}, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
// this is the new image upload part
|
// this is the new image upload part
|
||||||
if (index == 0) {
|
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)) {
|
if (! Update.begin(UPDATE_SIZE_UNKNOWN)) {
|
||||||
Update.printError(Serial);
|
Update.printError(Serial);
|
||||||
updateError = "Update.begin() failed";
|
updateError = "Update.begin() failed";
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ if (!window.isSecureContext) {
|
|||||||
<input type="file" name="file1" id="uploadFile">
|
<input type="file" name="file1" id="uploadFile">
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<span class="label"></span>
|
<span class="label">Details</span>
|
||||||
<span id="imageProperties" class="value"></span>
|
<span id="imageProperties" class="value"></span>
|
||||||
</div>
|
</div>
|
||||||
<div id="uploadProgress">
|
<div id="uploadProgress">
|
||||||
|
|||||||
Reference in New Issue
Block a user