[SYS] Password management improvements (#1787)
* Use one single password for Access point, OTA and WebUI access * Enable to change the password during WM onboarding, with the WebUI, and MQTT command * Remove the default password during the first configuration to connect to the AP * When using the last 8 digits of the MAC as the password, it can now be changed * Remove gateway password sending to client
This commit is contained in:
1 parent
7c48129f37
commit
99de6ef4a6
8 files changed
+129
-41
No files matched your search
+73
-3
@@ -768,18 +768,18 @@ void handleMQ() {
|
||||
|
||||
# ifndef ESPWifiManualSetup
|
||||
if (update) {
|
||||
Log.warning(F("[WebUI] Save MQTT and Restart" CR));
|
||||
Log.warning(F("[WebUI] Save MQTT and Reconnect" CR));
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save MQTT and Restart").c_str());
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save MQTT and Reconnect").c_str());
|
||||
String response = String(buffer);
|
||||
response += String(restart_script);
|
||||
response += String(script);
|
||||
response += String(style);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save MQTT and Restart");
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save MQTT and Reconnect");
|
||||
response += String(buffer);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||
response += String(buffer);
|
||||
@@ -816,6 +816,75 @@ void handleMQ() {
|
||||
server.send(200, "text/html", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief /CG - Configure Gateway Page
|
||||
* T: handleCG: uri: /gw, args: 2, method: 1
|
||||
* T: handleCG Arg: 0, gp=1234
|
||||
* T: handleCG Arg: 1, save=
|
||||
*/
|
||||
|
||||
void handleCG() {
|
||||
WEBUI_TRACE_LOG(F("handleCG: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
WEBUI_SECURE
|
||||
bool update = false;
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||
JsonObject WEBtoSYS = jsonBuffer.to<JsonObject>();
|
||||
|
||||
if (server.args()) {
|
||||
for (uint8_t i = 0; i < server.args(); i++) {
|
||||
WEBUI_TRACE_LOG(F("handleCG Arg: %d, %s=%s" CR), i, server.argName(i).c_str(), server.arg(i).c_str());
|
||||
}
|
||||
if (server.hasArg("save") && server.hasArg("gp") && strcmp(ota_pass, server.arg("gp").c_str())) {
|
||||
strncpy(ota_pass, server.arg("gp").c_str(), parameters_size);
|
||||
WEBtoSYS["gw_pass"] = ota_pass;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (update) {
|
||||
Log.warning(F("[WebUI] Save Password and Restart" CR));
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Save Password and Restart").c_str());
|
||||
String response = String(buffer);
|
||||
response += String(restart_script);
|
||||
response += String(script);
|
||||
response += String(style);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, reset_body, jsonChar, gateway_name, "Save Password and Restart");
|
||||
response += String(buffer);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||
response += String(buffer);
|
||||
server.send(200, "text/html", response);
|
||||
|
||||
delay(2000); // Wait for web page to be sent before
|
||||
String topic = String(mqtt_topic) + String(gateway_name) + String(subjectMQTTtoSYSset);
|
||||
String output;
|
||||
serializeJson(WEBtoSYS, output);
|
||||
Log.notice(F("[WebUI] MQTTtoSYS %s" CR), output.c_str());
|
||||
MQTTtoSYS((char*)topic.c_str(), WEBtoSYS);
|
||||
} else {
|
||||
Log.warning(F("[WebUI] No changes" CR));
|
||||
}
|
||||
|
||||
char jsonChar[100];
|
||||
serializeJson(modules, jsonChar, measureJson(modules) + 1);
|
||||
|
||||
char buffer[WEB_TEMPLATE_BUFFER_MAX_SIZE];
|
||||
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, header_html, (String(gateway_name) + " - Configure Gateway").c_str());
|
||||
String response = String(buffer);
|
||||
response += String(script);
|
||||
response += String(style);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, config_gateway_body, jsonChar, gateway_name, ota_pass);
|
||||
response += String(buffer);
|
||||
snprintf(buffer, WEB_TEMPLATE_BUFFER_MAX_SIZE, footer, OMG_VERSION);
|
||||
response += String(buffer);
|
||||
server.send(200, "text/html", response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief /LO - Configure Logging Page
|
||||
* T: handleLO: uri: /lo, args: 2, method: 1
|
||||
@@ -1419,6 +1488,7 @@ void WebUISetup() {
|
||||
server.on("/cn", handleCN); // Configuration
|
||||
server.on("/wi", handleWI); // Configure Wifi
|
||||
server.on("/mq", handleMQ); // Configure MQTT
|
||||
server.on("/cg", handleCG); // Configure Gateway"
|
||||
server.on("/wu", handleWU); // Configure WebUI
|
||||
# ifdef ZgatewayLORA
|
||||
server.on("/la", handleLA); // Configure LORA
|
||||
|
||||
Reference in new issue
Block a user