firmware wip - improve factory reset (wipe) from WebUI

This commit is contained in:
Marcus 2024-06-17 02:23:26 +02:00
parent 0354a7cfbf
commit 806aa2d057
2 changed files with 27 additions and 16 deletions

View file

@ -1,5 +1,5 @@
/* CanGrow_Version.h gets generated from cangrow.sh */
const char* CanGrowVer = "0.1-dev";
const char* CanGrowBuild = "37e0b33-20240617014909";
const char* CanGrowBuild = "0354a7c-20240617022027";

View file

@ -180,23 +180,17 @@ void SysRestart() {
void SysWipe() {
String body = returnHTMLheader();
// TODO only debug and development solution, remove this later
if(webserver.hasArg("confirmed")) {
body += "<div class='warnmsg'><h2>!! Wiping CanGrow's EEPROM !!</h2><br>Device will restart in a few seconds.<br>After restart a new WiFi 'CanGrow-unconfigured' will be created. To access the WebUI visit <a href='http://192.168.4.20'>http://192.168.4.20</a></div>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
wipeEEPROM();
} else {
body += "<h1>&#10071;&#10071; Wiping EEPROM</h1>";
body += "<div class='warnmsg'>All settings will be removed!!<br>";
body += "<br>Please confirm wiping the EEPROM";
body += "<form action='/system/wipe'><input type='hidden' name='confirmed' value='true' /><input type='submit' value='Confirm wiping' /></form>";
body += "</div>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
}
body += "<h1>&#10071;&#10071; Wiping EEPROM</h1>";
body += "<div class='warnmsg'>All settings will be removed!!<br>";
body += "<br>Please confirm wiping the EEPROM";
body += "<form action='/system/wipeConfirm' method='post'><br>Please confirm: <input type='checkbox' id='confirm' name='confirm' required /><br><input type='submit' value='Confirm wiping' /></form>";
body += "</div>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
}
void Sys404() {
String body = returnHTMLheader();
body += "<div class='warnmsg'><h1>&#10071; &#65039; 404 - not found</h1></div>";
@ -1032,6 +1026,21 @@ void POSTsetPumpManual() {
webserver.send(302, "text/plain", "switch: success!\n");
}
void POSTwipeConfirm() {
String body = returnHTMLheader();
// TODO only debug and development solution, remove this later
String confirm = webserver.arg("confirm");
if(confirm == "on") {
body += "<div class='warnmsg'><h2>!! Wiping CanGrow's EEPROM !!</h2><br>Device will restart in a few seconds.<br>After restart a new WiFi 'CanGrow-unconfigured' will be created. To access the WebUI visit <a href='http://192.168.4.20'>http://192.168.4.20</a></div>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);
wipeEEPROM();
} else {
webserver.send(400, "text/html", String("Error, 'confirm' missing nor wrong"));
}
}
/*
* API section
@ -1177,6 +1186,8 @@ void WebHandler() {
webserver.on("/system/restart", HTTP_GET, SysRestart);
// wipe eeprom triggered from WebGui
webserver.on("/system/wipe", HTTP_GET, SysWipe);
// confirm wiping the device
webserver.on("/system/wipeConfirm", HTTP_POST, POSTwipeConfirm);
// Maintenance mode
webserver.on("/system/maintenance", HTTP_GET, SysMaintenance);
// system update with binary