mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Fix hostname and save Password to NVS
This commit is contained in:
parent
f31a06cb0a
commit
57e512da7b
@ -1111,13 +1111,14 @@ static void webHandleMqttConfig()
|
|||||||
// Node Name
|
// Node Name
|
||||||
httpMessage +=
|
httpMessage +=
|
||||||
F("<div class='row'><div class='col-25'><label class='required' for='name'>Plate Name</label></div>");
|
F("<div class='row'><div class='col-25'><label class='required' for='name'>Plate Name</label></div>");
|
||||||
httpMessage += F("<div class='col-75'><input required type='text' id='name' name='name' maxlength=15 "
|
httpMessage += F("<div class='col-75'><input required type='text' id='name' name='name' maxlength= ");
|
||||||
"pattern='[a-z0-9_]*' placeholder='Plate Name' value=''></div></div>");
|
httpMessage += STR_LEN_HOSTNAME - 1;
|
||||||
|
httpMessage += F("pattern='[a-z0-9_]*' placeholder='Plate Name' value=''></div></div>");
|
||||||
|
|
||||||
// Group Name
|
// Group Name
|
||||||
httpMessage += F("<div class='row gap'><div class='col-25'><label for='group'>Group Name</label></div>");
|
httpMessage += F("<div class='row gap'><div class='col-25'><label for='group'>Group Name</label></div>");
|
||||||
httpMessage +=
|
httpMessage +=
|
||||||
F("<div class='col-75'><input type='text' id='group' name='group' maxlength=15 pattern='[a-z0-9_]*' "
|
F("<div class='col-75'><input type='text' id='group' name='group' maxlength=15 pattern='[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9]' "
|
||||||
"placeholder='Group Name' value=''></div></div>");
|
"placeholder='Group Name' value=''></div></div>");
|
||||||
|
|
||||||
// Broker
|
// Broker
|
||||||
@ -2193,6 +2194,12 @@ static inline void webStartConfigPortal()
|
|||||||
|
|
||||||
void httpSetup()
|
void httpSetup()
|
||||||
{
|
{
|
||||||
|
Preferences preferences;
|
||||||
|
preferences.begin("http", true);
|
||||||
|
String password = preferences.getString(FP_CONFIG_PASS, HTTP_PASSWORD);
|
||||||
|
strncpy(http_config.password, password.c_str(), sizeof(http_config.password));
|
||||||
|
LOG_DEBUG(TAG_HTTP, F(D_BULLET "Read %s => %s (%d bytes)"), FP_CONFIG_PASS, password.c_str(), password.length());
|
||||||
|
|
||||||
// ask server to track these headers
|
// ask server to track these headers
|
||||||
const char* headerkeys[] = {"Content-Length"}; // "Authentication"
|
const char* headerkeys[] = {"Content-Length"}; // "Authentication"
|
||||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
|
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
|
||||||
@ -2313,8 +2320,10 @@ bool httpGetConfig(const JsonObject& settings)
|
|||||||
if(strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
if(strcmp(http_config.username, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_USER)] = http_config.username;
|
settings[FPSTR(FP_CONFIG_USER)] = http_config.username;
|
||||||
|
|
||||||
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
// if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||||
settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
// settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
|
||||||
|
if(strcmp(D_PASSWORD_MASK, settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||||
|
settings[FPSTR(FP_CONFIG_PASS)] = D_PASSWORD_MASK;
|
||||||
|
|
||||||
if(changed) configOutput(settings, TAG_HTTP);
|
if(changed) configOutput(settings, TAG_HTTP);
|
||||||
return changed;
|
return changed;
|
||||||
@ -2330,6 +2339,9 @@ bool httpGetConfig(const JsonObject& settings)
|
|||||||
**/
|
**/
|
||||||
bool httpSetConfig(const JsonObject& settings)
|
bool httpSetConfig(const JsonObject& settings)
|
||||||
{
|
{
|
||||||
|
Preferences preferences;
|
||||||
|
preferences.begin("http", false);
|
||||||
|
|
||||||
configOutput(settings, TAG_HTTP);
|
configOutput(settings, TAG_HTTP);
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
@ -2342,8 +2354,9 @@ bool httpSetConfig(const JsonObject& settings)
|
|||||||
|
|
||||||
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
|
if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
|
||||||
settings[FPSTR(FP_CONFIG_PASS)].as<String>() != String(FPSTR(D_PASSWORD_MASK))) {
|
settings[FPSTR(FP_CONFIG_PASS)].as<String>() != String(FPSTR(D_PASSWORD_MASK))) {
|
||||||
changed |= strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
|
changed |= strcmp(FP_CONFIG_PASS, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
|
||||||
strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password));
|
strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password));
|
||||||
|
nvsUpdateString(preferences, FP_CONFIG_PASS, settings[FPSTR(FP_CONFIG_PASS)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user