From 04ed5ae77dc0d0fecfd6e71887713f089e0ec9ed Mon Sep 17 00:00:00 2001
From: Chrome Legion
Use 24 Hour Clock (military time)
" - "Flip display?
" + "Flip display orientation
" "Clock Sync / Weather Refresh (minutes)
" "Theme Color
" "Use Security Credentials for Configuration Changes
" "" "" ""; @@ -374,8 +375,15 @@ void getUpdateTime() { digitalWrite(externalLight, HIGH); // turn off the LED } +boolean authentication() { + if (IS_BASIC_AUTH && (strlen(www_username) >= 1 && strlen(www_password) >= 1)) { + return server.authenticate(www_username, www_password); + } + return true; // Authentication not required +} + void handleSystemReset() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } Serial.println("Reset System Configuration"); @@ -386,7 +394,7 @@ void handleSystemReset() { } void handleUpdateWeather() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } DISPLAYWEATHER = server.hasArg("isWeatherEnabled"); @@ -402,7 +410,7 @@ void handleUpdateWeather() { void handleUpdateConfig() { boolean flipOld = INVERT_DISPLAY; - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } OctoPrintApiKey = server.arg("octoPrintApiKey"); @@ -436,7 +444,7 @@ void handleUpdateConfig() { } void handleWifiReset() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } //WiFiManager @@ -448,7 +456,7 @@ void handleWifiReset() { } void handleWeatherConfigure() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } digitalWrite(externalLight, LOW); @@ -488,7 +496,7 @@ void handleWeatherConfigure() { } void handleConfigure() { - if (!server.authenticate(www_username, www_password)) { + if (!authentication()) { return server.requestAuthentication(); } digitalWrite(externalLight, LOW); @@ -533,6 +541,11 @@ void handleConfigure() { themeOptions.replace(">"+String(themeColor)+"<", " selected>"+String(themeColor)+"<"); form.replace("%THEME_OPTIONS%", themeOptions); form.replace("%UTCOFFSET%", String(UtcOffset)); + String isUseSecurityChecked = ""; + if (IS_BASIC_AUTH) { + isUseSecurityChecked = "checked='checked'"; + } + form.replace("%IS_BASICAUTH_CHECKED%", isUseSecurityChecked); form.replace("%USERID%", String(www_username)); form.replace("%STATIONPASSWORD%", String(www_password)); @@ -947,6 +960,7 @@ void writeSettings() { f.println("octoPass=" + OctoAuthPass); f.println("refreshRate=" + String(minutesBetweenDataRefresh)); f.println("themeColor=" + themeColor); + f.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH)); f.println("www_username=" + String(www_username)); f.println("www_password=" + String(www_password)); f.println("DISPLAYCLOCK=" + String(DISPLAYCLOCK)); @@ -1015,6 +1029,10 @@ void readSettings() { themeColor.trim(); Serial.println("themeColor=" + themeColor); } + if (line.indexOf("IS_BASIC_AUTH=") >= 0) { + IS_BASIC_AUTH = line.substring(line.lastIndexOf("IS_BASIC_AUTH=") + 14).toInt(); + Serial.println("IS_BASIC_AUTH=" + String(IS_BASIC_AUTH)); + } if (line.indexOf("www_username=") >= 0) { String temp = line.substring(line.lastIndexOf("www_username=") + 13); temp.trim(); @@ -1148,4 +1166,4 @@ void enableDisplay(boolean enable) { Serial.println("Display was turned OFF: " + timeClient.getFormattedTime()); displayOffEpoch = lastEpoch; } -} +}