From 6e6a8d9b73128ab6a166abc26bd2edd04b51bdc5 Mon Sep 17 00:00:00 2001 From: Andreas Breitschopp Date: Mon, 1 Jan 2024 16:03:50 +0100 Subject: [PATCH 1/8] Added setCustomTopBodyElement allowing to define custom HTML to be added at the top of the "" tag. --- WiFiManager.cpp | 11 +++++++++++ WiFiManager.h | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c36f46d8..f58718fc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1289,6 +1289,7 @@ String WiFiManager::getHTTPHead(String title){ page += FPSTR(HTTP_HEAD_END); } + page += _customTopBodyElement; return page; } @@ -2895,6 +2896,16 @@ void WiFiManager::setCustomHeadElement(const char* html) { _customHeadElement = html; } +/** + * set custom top body html + * custom element will be added to shortly after body tag opened, eg. to show a logo etc. + * @access public + * @param char element + */ +void WiFiManager::setCustomTopBodyElement(const char* html) { + _customTopBodyElement = html; +} + /** * set custom menu html * custom element will be added to menu under custom menu item. diff --git a/WiFiManager.h b/WiFiManager.h index f911beb0..ab70242d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -373,6 +373,9 @@ class WiFiManager //add custom html at inside for all pages void setCustomHeadElement(const char* html); + //add custom html at start of for all pages + void setCustomTopBodyElement(const char* html); + //if this is set, customise style void setCustomMenuHTML(const char* html); @@ -595,8 +598,9 @@ class WiFiManager boolean _disableConfigPortal = true; // FOR autoconnect - stop config portal if cp wifi save String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS - const char* _customHeadElement = ""; // store custom head element html from user isnide - const char* _customMenuHTML = ""; // store custom head element html from user inside <> + const char* _customHeadElement = ""; // store custom head element html from user inside + const char* _customTopBodyElement = ""; // store custom top body element html from user inside + const char* _customMenuHTML = ""; // store custom menu html from user String _bodyClass = ""; // class to add to body String _title = FPSTR(S_brand); // app title - default WiFiManager From 5f02005ca4b27a5bb3e6e7fba2d55b7d55b61850 Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 22 Oct 2024 23:34:08 -0400 Subject: [PATCH 2/8] Change custom top body element to 'header' This will make more sense once a footer is added. No functional changes. --- WiFiManager.cpp | 10 +++++----- WiFiManager.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f58718fc..9e2c1f7c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1289,7 +1289,7 @@ String WiFiManager::getHTTPHead(String title){ page += FPSTR(HTTP_HEAD_END); } - page += _customTopBodyElement; + page += _customBodyHeader; return page; } @@ -2897,13 +2897,13 @@ void WiFiManager::setCustomHeadElement(const char* html) { } /** - * set custom top body html - * custom element will be added to shortly after body tag opened, eg. to show a logo etc. + * set custom html at the top of the body + * custom element will be added immediately after the body tag is opened, eg. to show a logo etc. * @access public * @param char element */ -void WiFiManager::setCustomTopBodyElement(const char* html) { - _customTopBodyElement = html; +void WiFiManager::setCustomBodyHeader(const char* html) { + _customBodyHeader = html; } /** diff --git a/WiFiManager.h b/WiFiManager.h index ab70242d..9fdf02a0 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -374,7 +374,7 @@ class WiFiManager void setCustomHeadElement(const char* html); //add custom html at start of for all pages - void setCustomTopBodyElement(const char* html); + void setCustomBodyHeader(const char* html); //if this is set, customise style void setCustomMenuHTML(const char* html); @@ -599,7 +599,7 @@ class WiFiManager String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS const char* _customHeadElement = ""; // store custom head element html from user inside - const char* _customTopBodyElement = ""; // store custom top body element html from user inside + const char* _customBodyHeader = ""; // store custom top body element html from user inside const char* _customMenuHTML = ""; // store custom menu html from user String _bodyClass = ""; // class to add to body String _title = FPSTR(S_brand); // app title - default WiFiManager From 25fbfacd79119147027f31b78690272350465fd6 Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 22 Oct 2024 23:39:28 -0400 Subject: [PATCH 3/8] Make custom header concat conditional Matching the _bodyClass comparison above --- WiFiManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9e2c1f7c..812d5cfc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1289,7 +1289,10 @@ String WiFiManager::getHTTPHead(String title){ page += FPSTR(HTTP_HEAD_END); } - page += _customBodyHeader; + if (_customBodyHeader) { + page += _customBodyHeader; + } + return page; } From 40efe60eda969077b9774affe0118d85120f7f7b Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 22 Oct 2024 23:41:51 -0400 Subject: [PATCH 4/8] Create getHTTPEnd function --- WiFiManager.cpp | 24 ++++++++++++++---------- WiFiManager.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 812d5cfc..84e38c46 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1296,6 +1296,10 @@ String WiFiManager::getHTTPHead(String title){ return page; } +String WiFiManager::getHTTPEnd() { + return FPSTR(HTTP_END); +} + void WiFiManager::HTTPSend(const String &content){ server->send(200, FPSTR(HTTP_HEAD_CT), content); } @@ -1344,7 +1348,7 @@ void WiFiManager::handleRoot() { page += FPSTR(HTTP_PORTAL_OPTIONS); page += getMenuOut(); reportStatus(page); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); if(_preloadwifiscan) WiFi_scanNetworks(_scancachetime,true); // preload wifiscan throttled, async @@ -1400,7 +1404,7 @@ void WiFiManager::handleWifi(boolean scan) { page += FPSTR(HTTP_SCAN_LINK); if(_showBack) page += FPSTR(HTTP_BACKBTN); reportStatus(page); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -1429,7 +1433,7 @@ void WiFiManager::handleParam(){ page += FPSTR(HTTP_FORM_END); if(_showBack) page += FPSTR(HTTP_BACKBTN); reportStatus(page); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -1891,7 +1895,7 @@ void WiFiManager::handleWifiSave() { } if(_showBack) page += FPSTR(HTTP_BACKBTN); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); // @HTTPHEAD send cors HTTPSend(page); @@ -1918,7 +1922,7 @@ void WiFiManager::handleParamSave() { String page = getHTTPHead(FPSTR(S_titleparamsaved)); // @token titleparamsaved page += FPSTR(HTTP_PARAMSAVED); if(_showBack) page += FPSTR(HTTP_BACKBTN); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -2075,7 +2079,7 @@ void WiFiManager::handleInfo() { if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN); if(_showBack) page += FPSTR(HTTP_BACKBTN); page += FPSTR(HTTP_HELP); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -2345,7 +2349,7 @@ void WiFiManager::handleReset() { handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset page += FPSTR(S_resetting); //@token resetting - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -2380,7 +2384,7 @@ void WiFiManager::handleErase(boolean opt) { #endif } - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); if(ret){ @@ -3895,7 +3899,7 @@ void WiFiManager::handleUpdate() { page += str; page += FPSTR(HTTP_UPDATE); - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); @@ -4017,7 +4021,7 @@ void WiFiManager::handleUpdateDone() { page += FPSTR(HTTP_UPDATE_SUCCESS); DEBUG_WM(F("[OTA] update ok")); } - page += FPSTR(HTTP_END); + page += getHTTPEnd(); HTTPSend(page); diff --git a/WiFiManager.h b/WiFiManager.h index 9fdf02a0..4f1708cb 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -756,6 +756,7 @@ class WiFiManager String getScanItemOut(); String getStaticOut(); String getHTTPHead(String title); + String getHTTPEnd(); String getMenuOut(); //helpers boolean isIp(String str); From 82c074afdc785b297901792cbdf3b0f619f4b3a8 Mon Sep 17 00:00:00 2001 From: David Madison Date: Tue, 22 Oct 2024 23:48:15 -0400 Subject: [PATCH 5/8] Add custom body footer functionality --- WiFiManager.cpp | 18 +++++++++++++++++- WiFiManager.h | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 84e38c46..2057289f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1297,7 +1297,13 @@ String WiFiManager::getHTTPHead(String title){ } String WiFiManager::getHTTPEnd() { - return FPSTR(HTTP_END); + String end = FPSTR(HTTP_END); + + if (_customBodyFooter) { + end = String(_customBodyFooter) + end; + } + + return end; } void WiFiManager::HTTPSend(const String &content){ @@ -2913,6 +2919,16 @@ void WiFiManager::setCustomBodyHeader(const char* html) { _customBodyHeader = html; } +/** + * set custom html at the bottom of the body + * custom element will be added immediately before the body tag is closed + * @access public + * @param char element + */ +void WiFiManager::setCustomBodyFooter(const char* html) { + _customBodyFooter = html; +} + /** * set custom menu html * custom element will be added to menu under custom menu item. diff --git a/WiFiManager.h b/WiFiManager.h index 4f1708cb..8e19653e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -376,6 +376,9 @@ class WiFiManager //add custom html at start of for all pages void setCustomBodyHeader(const char* html); + //add custom html at end of for all pages + void setCustomBodyFooter(const char* html); + //if this is set, customise style void setCustomMenuHTML(const char* html); @@ -600,6 +603,7 @@ class WiFiManager const char* _customHeadElement = ""; // store custom head element html from user inside const char* _customBodyHeader = ""; // store custom top body element html from user inside + const char* _customBodyFooter = ""; // store custom bottom body element html from user inside const char* _customMenuHTML = ""; // store custom menu html from user String _bodyClass = ""; // class to add to body String _title = FPSTR(S_brand); // app title - default WiFiManager From b253e11ed41e3f7a00fd7e398392836e54cba20e Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 23 Oct 2024 00:11:01 -0400 Subject: [PATCH 6/8] Fix close tag on update page --- wm_strings_en.h | 2 +- wm_strings_es.h | 2 +- wm_strings_fr.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wm_strings_en.h b/wm_strings_en.h index 4b531603..c08d2183 100644 --- a/wm_strings_en.h +++ b/wm_strings_en.h @@ -149,7 +149,7 @@ const char HTTP_HELP[] PROGMEM = const char HTTP_HELP[] PROGMEM = ""; #endif -const char HTTP_UPDATE[] PROGMEM = "Upload new firmware
* May not function inside captive portal, open in browser http://192.168.4.1"; +const char HTTP_UPDATE[] PROGMEM = "Upload new firmware
* May not function inside captive portal, open in browser http://192.168.4.1"; const char HTTP_UPDATE_FAIL[] PROGMEM = "
Update failed!
Reboot device and try again
"; const char HTTP_UPDATE_SUCCESS[] PROGMEM = "
Update successful.
Device rebooting now...
"; diff --git a/wm_strings_es.h b/wm_strings_es.h index 781d0553..fab0ab9d 100644 --- a/wm_strings_es.h +++ b/wm_strings_es.h @@ -157,7 +157,7 @@ const char HTTP_HELP[] PROGMEM = const char HTTP_HELP[] PROGMEM = ""; #endif -const char HTTP_UPDATE[] PROGMEM = "Upload New Firmware
* May not function inside captive portal, Open in browser http://192.168.4.1"; +const char HTTP_UPDATE[] PROGMEM = "Upload New Firmware
* May not function inside captive portal, Open in browser http://192.168.4.1"; const char HTTP_UPDATE_FAIL[] PROGMEM = "
Update Failed!
Reboot device and try again
"; const char HTTP_UPDATE_SUCCESS[] PROGMEM = "
Update Successful.
Device Rebooting now...
"; diff --git a/wm_strings_fr.h b/wm_strings_fr.h index ba92323b..093143c2 100644 --- a/wm_strings_fr.h +++ b/wm_strings_fr.h @@ -150,7 +150,7 @@ const char HTTP_HELP[] PROGMEM = const char HTTP_HELP[] PROGMEM = ""; #endif -const char HTTP_UPDATE[] PROGMEM = "Charger le nouveau firmware
* Peut ne pas fonctionner à l'intérieur du portail captif, ouvrir dans le navigateur http://192.168.4.1"; +const char HTTP_UPDATE[] PROGMEM = "Charger le nouveau firmware
* Peut ne pas fonctionner à l'intérieur du portail captif, ouvrir dans le navigateur http://192.168.4.1"; const char HTTP_UPDATE_FAIL[] PROGMEM = "
Echec de la mise à jour !
Redémarrer l'appareil et réessayer
"; const char HTTP_UPDATE_SUCCESS[] PROGMEM = "
Mise à jour réussie.
L'appareil redémarre maintenant...
"; From 5d804f07fd71d2e00535d33daf97e94ae319b5cb Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 23 Oct 2024 00:11:34 -0400 Subject: [PATCH 7/8] Add missing HTTP ends to exit and close --- WiFiManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 2057289f..add43be4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2338,6 +2338,7 @@ void WiFiManager::handleExit() { handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit page += FPSTR(S_exiting); // @token exiting + page += getHTTPEnd(); // ('Logout', 401, {'WWW-Authenticate': 'Basic realm="Login required"'}) server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache HTTPSend(page); @@ -2485,6 +2486,7 @@ void WiFiManager::handleClose(){ handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose page += FPSTR(S_closing); // @token closing + page += getHTTPEnd(); HTTPSend(page); } From e2a287f57a07249ed39a005e30a21020394413a3 Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 23 Oct 2024 00:16:25 -0400 Subject: [PATCH 8/8] Remove 'immediately' from header/footer desc It's not immediate, the 'wrap' div is added before/after. --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index add43be4..dfdf4e7c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2913,7 +2913,7 @@ void WiFiManager::setCustomHeadElement(const char* html) { /** * set custom html at the top of the body - * custom element will be added immediately after the body tag is opened, eg. to show a logo etc. + * custom element will be added after the body tag is opened, eg. to show a logo etc. * @access public * @param char element */ @@ -2923,7 +2923,7 @@ void WiFiManager::setCustomBodyHeader(const char* html) { /** * set custom html at the bottom of the body - * custom element will be added immediately before the body tag is closed + * custom element will be added before the body tag is closed * @access public * @param char element */