auth in config mode
This commit is contained in:
@ -7,6 +7,8 @@ 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":"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"},
|
||||
@ -25,8 +27,17 @@ configItems = [
|
||||
|
||||
|
||||
magic = 0xC0DE0002
|
||||
appName = "ESP8266 based TouchSwitch"
|
||||
confWifiSsid = "espconfig"
|
||||
|
||||
h_file = Template(file="configuration_h.tmpl", searchList=[{"magic":magic, "configItems":configItems}])
|
||||
params = {
|
||||
"magic":magic,
|
||||
"appName":appName,
|
||||
"confWifiSsid":confWifiSsid,
|
||||
"configItems":configItems
|
||||
}
|
||||
|
||||
h_file = Template(file="configuration_h.tmpl", searchList=[params])
|
||||
open('configuration.h','w').write(str(h_file))
|
||||
c_file = Template(file="configuration_c.tmpl", searchList=[{"magic":magic, "configItems":configItems}])
|
||||
c_file = Template(file="configuration_c.tmpl", searchList=[params])
|
||||
open('configuration.cpp','w').write(str(c_file))
|
||||
|
@ -12,11 +12,22 @@
|
||||
|
||||
tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = $magic;
|
||||
const char* CONFIG_SSID = "$confWifiSsid";
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
bool configSaved = false;
|
||||
|
||||
|
||||
static bool checkAuthentication() {
|
||||
return webServer.authenticate(configBlock.confUser, configBlock.confPasswd);
|
||||
}
|
||||
|
||||
void configServeIndex() {
|
||||
if (! checkAuthentication()) {
|
||||
return webServer.requestAuthentication();
|
||||
}
|
||||
|
||||
|
||||
bool configValid = (configBlock.magic == MAGIC);
|
||||
|
||||
if (! configValid) {
|
||||
@ -35,10 +46,10 @@ void configServeIndex() {
|
||||
"<!doctype html"
|
||||
"<html lang=\"en\">"
|
||||
" <head>"
|
||||
" <title>ESP8266 Thermometer Configuration Page</title>"
|
||||
" <title>$appName</title>"
|
||||
" </head>"
|
||||
" <body>"
|
||||
" <h1>ESP8266 Configuration Page</h1>";
|
||||
" <h1>$appName - ESP8266 Configuration Page</h1>";
|
||||
|
||||
if (configSaved) {
|
||||
configSaved = false;
|
||||
@ -92,6 +103,10 @@ void configServeIndex() {
|
||||
}
|
||||
|
||||
void configServeGetConfiguration() {
|
||||
if (! checkAuthentication()) {
|
||||
return webServer.requestAuthentication();
|
||||
}
|
||||
|
||||
String arg;
|
||||
|
||||
#for $configItem in $configItems
|
||||
|
@ -10,6 +10,7 @@ typedef struct {
|
||||
|
||||
extern const uint32_t MAGIC;
|
||||
extern tConfigBlock configBlock;
|
||||
extern const char* CONFIG_SSID;
|
||||
|
||||
void configServeIndex();
|
||||
void configServeGetConfiguration();
|
||||
|
Reference in New Issue
Block a user