From 75ebd04d1239887744bed9adeab74de0044994e8 Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 26 Jan 2016 11:50:02 +0800 Subject: [PATCH] Allow to disable FW web update when compiling New compilation directive to enable/disable feature //WEB_UPDATE_FEATURE: allow to flash fw using web UI #define WEB_UPDATE_FEATURE --- .gitignore | 3 ++- esp8266/config.cpp | 6 ++++++ esp8266/config.h | 3 +++ esp8266/data/system.tpl | 2 +- esp8266/webinterface.cpp | 16 ++++++++++++---- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index aafa7683..4978394a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -Thumbs.db \ No newline at end of file +Thumbs.db +*.orig \ No newline at end of file diff --git a/esp8266/config.cpp b/esp8266/config.cpp index 9069d724..2a47cdb5 100644 --- a/esp8266/config.cpp +++ b/esp8266/config.cpp @@ -435,5 +435,11 @@ void CONFIG::print_config() Serial.println(F("Enabled")); #else Serial.println(F("Disabled")); +#endif + Serial.print(F("Web update: ")); +#ifdef WEB_UPDATE_FEATURE + Serial.println(F("Enabled")); +#else + Serial.println(F("Disabled")); #endif } diff --git a/esp8266/config.h b/esp8266/config.h index f4ae1344..9c977701 100644 --- a/esp8266/config.h +++ b/esp8266/config.h @@ -32,6 +32,9 @@ //AUTHENTICATION_FEATURE: protect pages by login password #define AUTHENTICATION_FEATURE +//WEB_UPDATE_FEATURE: allow to flash fw using web UI +#define WEB_UPDATE_FEATURE + #ifndef CONFIG_h #define CONFIG_h diff --git a/esp8266/data/system.tpl b/esp8266/data/system.tpl index 81cd3b6b..2e1c983a 100644 --- a/esp8266/data/system.tpl +++ b/esp8266/data/system.tpl @@ -38,7 +38,7 @@ $SUCCESS_MSG$ -
+
Firmware Update
diff --git a/esp8266/webinterface.cpp b/esp8266/webinterface.cpp index 9ab6a2b7..b875adba 100644 --- a/esp8266/webinterface.cpp +++ b/esp8266/webinterface.cpp @@ -204,6 +204,7 @@ const char KEY_RETURN [] PROGMEM = "$RETURN$"; const char VALUE_CHANGE_PASSWORD [] PROGMEM = "Change Password"; const char MISSING_DATA [] PROGMEM = "Error: Missing data"; const char EEPROM_NOWRITE [] PROGMEM = "Error: Cannot write to EEPROM"; +const char KEY_WEB_UPDATE [] PROGMEM = "$WEB_UPDATE_VISIBILITY$"; bool WEBINTERFACE_CLASS::isHostnameValid(const char * hostname) { @@ -1183,7 +1184,12 @@ void handle_web_interface_configSys() { ProcessNoAlert(KeysList, ValuesList); } - + KeysList.add(FPSTR(KEY_WEB_UPDATE)); +#ifdef WEB_UPDATE_FEATURE + ValuesList.add(FPSTR(VALUE_ITEM_VISIBLE)); +#else + ValuesList.add(FPSTR(VALUE_ITEM_HIDDEN)); +#endif //Firmware and Free Mem, at the end to reflect situation GetFreeMem(KeysList, ValuesList); @@ -2378,6 +2384,7 @@ void SPIFFSFileupload() } } +#ifdef WEB_UPDATE_FEATURE void WebUpdateUpload() { HTTPUpload& upload = (web_interface->WebServer).upload(); @@ -2404,7 +2411,6 @@ void WebUpdateUpload() yield(); } - void handleUpdate() { web_interface->is_authenticated(); @@ -2419,6 +2425,7 @@ void handleUpdate() web_interface->restartmodule=true; } } +#endif void handleFileList() { @@ -2679,6 +2686,7 @@ void handle_login() KeysList.clear(); ValuesList.clear(); } + void handle_restart() { if (SPIFFS.exists("/restart.tpl")) { @@ -2746,7 +2754,6 @@ void handle_web_command() } } - #ifdef SSDP_FEATURE void handle_SSDP() { @@ -2791,7 +2798,6 @@ void WEBINTERFACE_CLASS::urldecode( String & dst, const char *src) } } - //constructor WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) { @@ -2805,7 +2811,9 @@ WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port) WebServer.on("/PRINTER",HTTP_ANY, handle_web_interface_printer); WebServer.on("/CMD",HTTP_ANY, handle_web_command); WebServer.on("/RESTART",HTTP_GET, handle_restart); +#ifdef WEB_UPDATE_FEATURE WebServer.on("/UPDATE",HTTP_ANY, handleUpdate,WebUpdateUpload); +#endif WebServer.on("/FILES", HTTP_ANY, handleFileList,SPIFFSFileupload); WebServer.on("/SDFILES", HTTP_ANY, handleSDFileList); WebServer.on("/LOGIN", HTTP_ANY, handle_login);