This commit is contained in:
Wolfgang Hottgenroth
2018-02-02 19:20:17 +01:00
parent 2e34cfe5b5
commit 1c83e1b7d6
8 changed files with 49 additions and 43 deletions

View File

@ -7,11 +7,11 @@ from Cheetah.Template import Template
configItems = [
{"label":"_", "key":"magic", "type":"I", "default": ""},
{"label":"Config Username", "key":"confUser", "type":"C", "length":32, "default":"admin"},
{"label":"Config Password", "key":"confPasswd", "type":"C", "length":32, "default":"geheim123"},
{"label":"Config Username", "key":"confUser", "type":"C", "length":16, "default":"admin"},
{"label":"Config Password", "key":"confPasswd", "type":"C", "length":16, "default":"geheim123"},
{"label":"Wifi SSID", "key":"wifiSsid", "type":"C", "length":32, "default":"test"},
{"label":"Wifi Key", "key":"wifiKey", "type":"C", "length":64, "default":"geheim"},
{"label":"MQTT Broker", "key":"mqttBroker", "type":"C", "length":64, "default":"broker.hottis.de"},
{"label":"MQTT Broker", "key":"mqttBroker", "type":"C", "length":32, "default":"broker.hottis.de"},
{"label":"MQTT Username", "key":"mqttUser", "type":"C", "length":32, "default":"TouchSwitch"},
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim123"},
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"TouchSwitch"},
@ -26,7 +26,7 @@ configItems = [
]
magic = 0xC0DE0002
magic = 0xC0DE0003
appName = "ESP8266 based TouchSwitch"
confWifiSsid = "espconfig"

View File

@ -19,18 +19,16 @@ bool configSaved = false;
static bool checkAuthentication() {
Serial.print("User: "); Serial.println(configBlock.confUser);
Serial.print("Pass: "); Serial.println(configBlock.confPasswd);
return webServer.authenticate(configBlock.confUser, configBlock.confPasswd);
}
void configServeIndex() {
if (! checkAuthentication()) {
return webServer.requestAuthentication();
}
bool configValid = (configBlock.magic == MAGIC);
if (! configValid) {
configBlock.magic = MAGIC;
#for $configItem in $configItems
#if $configItem.label != "_"
#if $configItem.type == "C"
@ -41,7 +39,12 @@ void configServeIndex() {
#end if
#end for
}
if (! checkAuthentication()) {
return webServer.requestAuthentication();
}
String buffer =
"<!doctype html"
"<html lang=\"en\">"