From 6b1ad887207be4130afdaab70a992589d729d328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Hedberg?= Date: Mon, 5 Dec 2022 13:54:31 +0100 Subject: [PATCH 1/4] Using named cookies --- sd-card/html/index.html | 24 ++++++++++++++++++++---- sd-card/html/ota_page.html | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sd-card/html/index.html b/sd-card/html/index.html index c13577acc..1533c8210 100644 --- a/sd-card/html/index.html +++ b/sd-card/html/index.html @@ -28,6 +28,22 @@ el.style.visibility = 'visible'; }); } + + function getCookie(cname) { + let name = cname + "="; + let decodedCookie = decodeURIComponent(document.cookie); + let ca = decodedCookie.split(';'); + for(let i = 0; i @@ -88,11 +104,11 @@

An ESP32 all inclusive neural network recognition system for meter digitaliz LoadFwVersion(); LoadWebUiVersion(); - if (document.cookie == "" || document.cookie == "reboot_page.html") { - document.cookie = "overview.html"; + if (getCookie("page") == "" || getCookie("page") == "reboot_page.html") { + document.cookie = "page=overview.html"; } - console.log("Loading page: " + document.cookie); - document.getElementById('maincontent').src = document.cookie; + console.log("Loading page: " + getCookie(page)); + document.getElementById('maincontent').src = getCookie("page"); diff --git a/sd-card/html/ota_page.html b/sd-card/html/ota_page.html index 5a87d44e7..eb58743d1 100644 --- a/sd-card/html/ota_page.html +++ b/sd-card/html/ota_page.html @@ -210,7 +210,7 @@

Status: idle

document.getElementById("status").innerText = "Status: Update completed!"; document.getElementById("doUpdate").disabled = true; document.getElementById("newfile").disabled = false; - document.cookie = "overview.html"; // Make sure after the reboot we go to the overview page + document.cookie = "page=overview.html"; // Make sure after the reboot we go to the overview page if (xhttp.responseText.startsWith("reboot")) { From 901b6998b6461e1014c49bd1023366c93c1ad662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Hedberg?= Date: Mon, 5 Dec 2022 14:28:55 +0100 Subject: [PATCH 2/4] Prevent from deleting wlan.ini file --- code/components/jomjol_fileserver_ota/server_file.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index 2aaa8dfd7..4f8657b75 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -829,6 +829,12 @@ static esp_err_t delete_post_handler(httpd_req_t *req) return ESP_FAIL; } + if (filename == 'wlan.ini') { + ESP_LOGE(TAG, "Trying to delete protected file : %s", filename); + httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Not allowed to delete wlan.ini"); + return ESP_FAIL; + } + if (stat(filepath, &file_stat) == -1) { ESP_LOGE(TAG, "File does not exist : %s", filename); /* Respond with 400 Bad Request */ From 1473a599793826b8b029c4548e5a12904aeb24c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Hedberg?= Date: Mon, 5 Dec 2022 16:37:13 +0100 Subject: [PATCH 3/4] Missed " --- sd-card/html/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/index.html b/sd-card/html/index.html index 1533c8210..fa8baf89b 100644 --- a/sd-card/html/index.html +++ b/sd-card/html/index.html @@ -107,7 +107,7 @@

An ESP32 all inclusive neural network recognition system for meter digitaliz if (getCookie("page") == "" || getCookie("page") == "reboot_page.html") { document.cookie = "page=overview.html"; } - console.log("Loading page: " + getCookie(page)); + console.log("Loading page: " + getCookie("page")); document.getElementById('maincontent').src = getCookie("page"); From e6227d373e742694a49d53e4b2d739d525195aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Hedberg?= Date: Mon, 5 Dec 2022 16:41:13 +0100 Subject: [PATCH 4/4] Revert "Prevent from deleting wlan.ini file" This reverts commit 901b6998b6461e1014c49bd1023366c93c1ad662. --- code/components/jomjol_fileserver_ota/server_file.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index 4f8657b75..2aaa8dfd7 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -829,12 +829,6 @@ static esp_err_t delete_post_handler(httpd_req_t *req) return ESP_FAIL; } - if (filename == 'wlan.ini') { - ESP_LOGE(TAG, "Trying to delete protected file : %s", filename); - httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Not allowed to delete wlan.ini"); - return ESP_FAIL; - } - if (stat(filepath, &file_stat) == -1) { ESP_LOGE(TAG, "File does not exist : %s", filename); /* Respond with 400 Bad Request */