Skip to content

Commit

Permalink
Using named cookies to get a correct redirect (#1492)
Browse files Browse the repository at this point in the history
* Using named cookies

* Prevent from deleting wlan.ini file

* Missed "

* Revert "Prevent from deleting wlan.ini file"

This reverts commit 901b699.

Co-authored-by: Pär Hedberg <[email protected]>
  • Loading branch information
parhedberg and Pär Hedberg authored Dec 5, 2022
1 parent 5867e90 commit 1ca54f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions sd-card/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
</script>

</head>
Expand Down Expand Up @@ -88,11 +104,11 @@ <h2>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");
</script>

</div>
Expand Down
2 changes: 1 addition & 1 deletion sd-card/html/ota_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ <h3><span id="status">Status: idle</span> <span id="progress"></span></h3>
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"))
{
Expand Down

0 comments on commit 1ca54f3

Please sign in to comment.