firmware wip - changed webhandlers - working now with redirects instead setting handlers

This commit is contained in:
Marcus 2024-04-17 02:03:45 +02:00
parent af9847ceb7
commit b3c0959521

View file

@ -945,16 +945,27 @@ void WebHandler() {
*
* WebHandler_unconfigured() and WebHandler_configured()
*/
// generic handler
// style.css
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// Web root
webserver.on("/", HTTP_GET, WEBroot);
// WiFi Stuff
webserver.on("/wifiSettings", HTTP_GET, WEBwifiSettings);
webserver.on("/wifiSettings/save", HTTP_POST, POSTwifiSettings);
webserver.on("/style.css", HTTP_GET, WEBstyleCSS);
// System stuff
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
// Grow stuff
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
// help
webserver.on("/help", HTTP_GET, WEBhelp);
// does not work atm TODO
webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); });
//webserver.on("/logout", [](){ webserver.send(401, "text/html", "logged out!"); });
// 404 handling
// favicon.ico is a special one, because its requested everytime and i dont wont to deliver the
@ -962,39 +973,6 @@ void WebHandler() {
webserver.on("/favicon.ico", [](){ webserver.send(404, "text/html", "404 - not found"); });
webserver.onNotFound(WEB404);
// when wifi is unconfigured (WIFIssid <1) then root are Wifi settings
if(strlen(WIFIssid) < 1) {
webserver.on("/", HTTP_GET, WEBwifiSettings);
webserver.on("/systemSettings", HTTP_GET, WEBwifiSettings);
webserver.on("/growSettings", HTTP_GET, WEBwifiSettings);
} else {
// now we need to receive systemSettings
webserver.on("/systemSettings/save", HTTP_POST, POSTsystemSettings);
// when system settings are unconfigured , then system settings are root
if(configured == false) {
webserver.on("/", HTTP_GET, WEBsystemSettings);
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
webserver.on("/growSettings", HTTP_GET, WEBsystemSettings);
} else {
webserver.on("/systemSettings", HTTP_GET, WEBsystemSettings);
}
webserver.on("/growSettings", HTTP_GET, WEBgrowSettings);
// now we need to receive growSettings
webserver.on("/growSettings/save", HTTP_POST, POSTgrowSettings);
// when grow is unconfigured (GrowStart <1) then Grow settings are root
if(GrowStart < 1) {
webserver.on("/", HTTP_GET, WEBgrowSettings);
} else {
webserver.on("/", HTTP_GET, WEBroot);
}
}
}
@ -1101,7 +1079,18 @@ void WEBhelp() {
*/
void WEBroot() {
if(strlen(WIFIssid) < 1) {
webserver.sendHeader("Location", String("/wifiSettings"), true);
webserver.send(302, "text/plain", "please configure wifiSettings first");
} else if(configured == false){
webserver.sendHeader("Location", String("/systemSettings"), true);
webserver.send(302, "text/plain", "please configure systemSettings first");
} else if(strlen(GrowName) < 1){
webserver.sendHeader("Location", String("/growSettings"), true);
webserver.send(302, "text/plain", "please configure growSettings first");
} else {
String body = FPSTR(HTMLheader);
body += "<h1>configured!</h1>";
body += "<p>";
body += timeClient.getFormattedTime();
@ -1109,6 +1098,7 @@ void WEBroot() {
body += returnHTMLfooter();
webserver.send(200, "text/html", body);
}
}
/*
@ -1163,6 +1153,12 @@ void WEBwifiSettings() {
}
void WEBsystemSettings() {
// if wifi settings are unconfigured, we cannot proceed with systemSettings
if(strlen(WIFIssid) < 1) {
webserver.sendHeader("Location", String("/wifiSettings"), true);
webserver.send(302, "text/plain", "please configure wifiSettings first");
} else {
String body = FPSTR(HTMLheader);
if(configured == false) {
@ -1233,12 +1229,19 @@ void WEBsystemSettings() {
body += returnHTMLfooter();
webserver.send(200, "text/html", body);
}
}
/*
* Grow pages
*/
void WEBgrowSettings() {
// if system settings are unconfigured, we cannot proceed with growSettings
if(configured == false) {
webserver.sendHeader("Location", String("/systemSettings"), true);
webserver.send(302, "text/plain", "please configure systemSettings first");
} else {
String body = FPSTR(HTMLheader);
if(strlen(GrowName) < 1) {
@ -1300,6 +1303,7 @@ void WEBgrowSettings() {
body += returnHTMLfooter();
webserver.send(200, "text/html", body);
}
}