From 9a06c748c01223f034e6d52d0f5a9fabdc41429c Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sun, 20 Nov 2016 01:47:15 +0100 Subject: [PATCH] implement OTA lock / security do not reboot after settings set -> add reboot button ota not really working yet --- TODO.txt | 7 ++++--- wled00/data/index.htm | 2 +- wled00/data/settings.htm | 7 ++----- wled00/data/settingssaved.htm | 24 ++++++++++++++++++++++++ wled00/wled00.ino | 3 ++- wled00/wled01_eeprom.ino | 33 +++++++++++++++++++++++++++++---- wled00/wled02_xml.ino | 6 ++++-- wled00/wled03_set.ino | 21 +++++++++++++++++++++ wled00/wled05_init.ino | 24 ++++++++++++++++++++---- 9 files changed, 107 insertions(+), 20 deletions(-) create mode 100644 wled00/data/settingssaved.htm diff --git a/TODO.txt b/TODO.txt index d4930924c..b9f0c3203 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,19 +3,20 @@ sequence simple slide transition additional color picker field implement all settings setters -implement OTA lock / security implement HSB slider option implement ranges implement discrete range color setter implement discrete single color setter -do not reboot after settings set -> add reboot button svg icons in html notifier function -> send get request nightlight function -> turns off after set time (+implement fading) add preferred colors to settings -> quickly t. UI, button select, use iframe for settings, seperate tabs for wifi and application confg +use iframe for all adv. features? +/dumpeeprom and /pusheeprom BUGS static ip disables mdns -XXX authentification for security relevant areas (/edit, /update (!!!), /list, /down, [/settings, /reset, /cleareeprom]) +? authentification for security relevant areas ([/settings, /reset]) (Unverified) led_amount does nothing (is always 16) because NeoPixelBus is initiated before EEPROM read +notifier wrong ips diff --git a/wled00/data/index.htm b/wled00/data/index.htm index 32858b263..d272bd3a5 100644 --- a/wled00/data/index.htm +++ b/wled00/data/index.htm @@ -188,7 +188,7 @@
- +
diff --git a/wled00/data/settings.htm b/wled00/data/settings.htm index a2bb4ebcf..e4f104fdb 100644 --- a/wled00/data/settings.htm +++ b/wled00/data/settings.htm @@ -47,9 +47,7 @@ document.S_form.NORAP.checked = (this.responseXML.getElementsByTagName('norap')[0].innerHTML)!=0?true:false; document.getElementsByClassName("sip")[0].innerHTML = this.responseXML.getElementsByTagName('sip')[0].innerHTML; document.getElementsByClassName("sip")[1].innerHTML = this.responseXML.getElementsByTagName('sip')[1].innerHTML; - document.getElementsByClassName("otastat")[0].innerHTML = this.responseXML.getElementsByTagName('otastat')[0].innerHTML; document.getElementsByClassName("msg")[0].innerHTML = this.responseXML.getElementsByTagName('msg')[0].innerHTML; - if (S_form.NOOTA.checked) {document.S_form.NOOTA.disabled="disabled";} } } } @@ -124,12 +122,11 @@ Hosts to send notifications to: (1 IP per line)

Security

- OTA enabled:
+ OTA locked:
Passphrase:
To enable OTA, for security reasons you need to also enter the correct password!
The password may/should be changed when OTA is enabled.
- Disable OTA when not in use, otherwise an attacker could reflash device software!
- Current status: Unknown

+ Disable OTA when not in use, otherwise an attacker could reflash device software!

Disable recovery AP (Not implemented):
In case of a connection error there will be no wireless recovery possible!
Completely disables all Access Point functions.

diff --git a/wled00/data/settingssaved.htm b/wled00/data/settingssaved.htm new file mode 100644 index 000000000..af0f6bf05 --- /dev/null +++ b/wled00/data/settingssaved.htm @@ -0,0 +1,24 @@ + + + + Saved Settings + + +
+

Settings saved.

+

If you made changes to WiFi configuration, please reboot.


+ + +
+ + \ No newline at end of file diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 4978fd2ec..218abf9c0 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -30,7 +30,8 @@ byte col[]{255, 127, 0}; boolean fadeTransition = true; boolean seqTransition = false; uint16_t transitionDelay = 1500; -boolean ota_lock = false; +boolean ota_lock = true; +String otapass = "wledota"; boolean only_ap = false; uint8_t led_amount = 16; uint8_t buttonPin = 3; //needs pull-up diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index ad3a42947..1e6314cb3 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -1,6 +1,6 @@ void clearEEPROM() { - for (int i = 0; i < 256; i++) + for (int i = 0; i < 1024; i++) { EEPROM.write(i, 0); } @@ -36,10 +36,14 @@ void saveSettingsToEEPROM() } EEPROM.write(224, nightlightDelayMins); EEPROM.write(225, nightlightFade); - EEPROM.write(228, aphide); + EEPROM.write(226, notifyDirect); EEPROM.write(227, apchannel); + EEPROM.write(228, aphide); EEPROM.write(229, led_amount); + EEPROM.write(230, notifyButton); + EEPROM.write(231, notifyForward); EEPROM.write(232, buttonEnabled); + //233 reserved for first boot flag EEPROM.write(234, staticip[0]); EEPROM.write(235, staticip[1]); EEPROM.write(236, staticip[2]); @@ -56,9 +60,17 @@ void saveSettingsToEEPROM() EEPROM.write(247, col[1]); EEPROM.write(248, col[2]); EEPROM.write(249, bri); + EEPROM.write(250, receiveNotifications); EEPROM.write(251, fadeTransition); EEPROM.write(253, (transitionDelay >> 0) & 0xFF); EEPROM.write(254, (transitionDelay >> 8) & 0xFF); + EEPROM.write(255, bri_n); + //255,250,231,230,226 notifier bytes + for (int i = 256; i < 288; ++i) + { + EEPROM.write(i, otapass.charAt(i-256)); + } + EEPROM.write(289, ota_lock); EEPROM.commit(); } @@ -99,11 +111,16 @@ void loadSettingsFromEEPROM() if (EEPROM.read(i) == 0) break; appass += char(EEPROM.read(i)); } - aphide = EEPROM.read(228); - if (aphide > 1) aphide = 1; + nightlightDelayMins = EEPROM.read(224); + nightlightFade = EEPROM.read(225); + notifyDirect = EEPROM.read(226); apchannel = EEPROM.read(227); if (apchannel > 13 || apchannel < 1) apchannel = 1; + aphide = EEPROM.read(228); + if (aphide > 1) aphide = 1; led_amount = EEPROM.read(229); + notifyButton = EEPROM.read(230); + notifyForward = EEPROM.read(231); buttonEnabled = EEPROM.read(232); staticip[0] = EEPROM.read(234); staticip[1] = EEPROM.read(235); @@ -121,6 +138,14 @@ void loadSettingsFromEEPROM() col[1] = EEPROM.read(247); col[2] = EEPROM.read(248); bri = EEPROM.read(249); + receiveNotifications = EEPROM.read(250); fadeTransition = EEPROM.read(251); transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00); + bri_n = EEPROM.read(255); + for (int i = 256; i < 288; ++i) + { + if (EEPROM.read(i) == 0) break; + otapass += char(EEPROM.read(i)); + } + ota_lock = EEPROM.read(289); } diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 130551126..373b4a0b6 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -102,7 +102,9 @@ void XML_response_settings() resp = resp + "\n"; } resp = resp + ""; - resp = resp + "0"; //NI + resp = resp + ""; + resp = resp + bool2int(ota_lock); + resp = resp +""; resp = resp + "0"; //NI resp = resp + ""; if (!WiFi.localIP()[0] == 0) @@ -132,7 +134,7 @@ void XML_response_settings() { resp = resp + "Not active"; } - resp = resp + "Not implemented"; + resp = resp + "LS"; resp = resp + "WLED 0.3pd OK"; resp = resp + ""; Serial.println(resp); diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index daea976af..adcef2fe1 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -105,6 +105,12 @@ void handleSettingsSet() int i = server.arg("TDLAY").toInt(); if (i > 0) transitionDelay = i; } + if (server.hasArg("TLDUR")) + { + int i = server.arg("TLDUR").toInt(); + if (i > 0) nightlightDelayMins = i; + } + nightlightFade = server.hasArg("TLFDE"); receiveNotifications = server.hasArg("NRCVE"); if (server.hasArg("NRBRI")) { @@ -118,6 +124,21 @@ void handleSettingsSet() { notifier_ips_raw = server.arg("NSIPS"); } + if (server.hasArg("OPASS")) + { + if (!ota_lock) + { + if (server.arg("OPASS").length() > 0) + otapass = server.arg("OPASS"); + } else if (!server.hasArg("NOOTA")) + { + if (otapass.equals(server.arg("OPASS"))) + { + ota_lock = false; + } + } + } + if (server.hasArg("NOOTA")) ota_lock = true; saveSettingsToEEPROM(); } diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 231882c7c..fdbed1ea6 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -20,7 +20,7 @@ void wledInit() Serial.printf("\n"); } Serial.println("Init EEPROM"); - EEPROM.begin(256); + EEPROM.begin(1024); loadSettingsFromEEPROM(); Serial.print("CC: SSID: "); @@ -77,11 +77,13 @@ void wledInit() server.on("/", HTTP_GET, [](){ if(!handleFileRead("/index.htm")) server.send(404, "text/plain", "FileNotFound"); }); - server.on("/reset", HTTP_GET, reset); + server.on("/reset", HTTP_GET, [](){ + server.send(200, "text/plain", "Rebooting... Go to main page when lights turn on."); + reset(); + }); server.on("/set-settings", HTTP_POST, [](){ handleSettingsSet(); - server.send(200, "text/plain", "Settings saved. Please wait for light to turn back on, then go to main page..."); - reset(); + if(!handleFileRead("/settingssaved.htm")) server.send(404, "text/plain", "SettingsSaved"); }); if (!ota_lock){ server.on("/edit", HTTP_GET, [](){ @@ -94,6 +96,20 @@ void wledInit() server.on("/cleareeprom", HTTP_GET, clearEEPROM); //init ota page httpUpdater.setup(&server); + } else + { + server.on("/edit", HTTP_GET, [](){ + server.send(500, "text/plain", "OTA lock active"); + }); + server.on("/down", HTTP_GET, [](){ + server.send(500, "text/plain", "OTA lock active"); + }); + server.on("/cleareeprom", HTTP_GET, [](){ + server.send(500, "text/plain", "OTA lock active"); + }); + server.on("/update", HTTP_GET, [](){ + server.send(500, "text/plain", "OTA lock active"); + }); } //called when the url is not defined here, ajax-in; get-settings server.onNotFound([](){