Browse Source

webui: fix password webMode

make sure the form name is used, not the panel one
also clean-up the api, so it's only mentioned once for both handlers
fix #2461
pull/2471/head
Maxim Prokhorov 2 years ago
parent
commit
2d1528d856
22 changed files with 12976 additions and 12969 deletions
  1. +4
    -0
      ci_script.sh
  2. BIN
      code/espurna/data/index.all.html.gz
  3. BIN
      code/espurna/data/index.curtain.html.gz
  4. BIN
      code/espurna/data/index.garland.html.gz
  5. BIN
      code/espurna/data/index.light.html.gz
  6. BIN
      code/espurna/data/index.lightfox.html.gz
  7. BIN
      code/espurna/data/index.rfbridge.html.gz
  8. BIN
      code/espurna/data/index.rfm69.html.gz
  9. BIN
      code/espurna/data/index.sensor.html.gz
  10. BIN
      code/espurna/data/index.small.html.gz
  11. BIN
      code/espurna/data/index.thermostat.html.gz
  12. +1685
    -1684
      code/espurna/static/index.all.html.gz.h
  13. +1360
    -1359
      code/espurna/static/index.curtain.html.gz.h
  14. +1317
    -1316
      code/espurna/static/index.garland.html.gz.h
  15. +1893
    -1893
      code/espurna/static/index.light.html.gz.h
  16. +1320
    -1320
      code/espurna/static/index.lightfox.html.gz.h
  17. +897
    -896
      code/espurna/static/index.rfbridge.html.gz.h
  18. +1358
    -1357
      code/espurna/static/index.rfm69.html.gz.h
  19. +1393
    -1393
      code/espurna/static/index.sensor.html.gz.h
  20. +846
    -846
      code/espurna/static/index.small.html.gz.h
  21. +879
    -878
      code/espurna/static/index.thermostat.html.gz.h
  22. +24
    -27
      code/html/custom.js

+ 4
- 0
ci_script.sh View File

@ -18,6 +18,10 @@ case "$1" in
npm exec --no html-validate html/index.html
# checks whether the webui can be built
./build.sh -f environments
# TODO: gzip inserts an OS-dependant byte in the header, ref.
# - https://datatracker.ietf.org/doc/html/rfc1952
# - https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/deps/zlib/deflate.c#L901
# - windowBits description in the https://zlib.net/manual.html#Advanced
git --no-pager diff --stat
;;
("build")


BIN
code/espurna/data/index.all.html.gz View File


BIN
code/espurna/data/index.curtain.html.gz View File


BIN
code/espurna/data/index.garland.html.gz View File


BIN
code/espurna/data/index.light.html.gz View File


BIN
code/espurna/data/index.lightfox.html.gz View File


BIN
code/espurna/data/index.rfbridge.html.gz View File


BIN
code/espurna/data/index.rfm69.html.gz View File


BIN
code/espurna/data/index.sensor.html.gz View File


BIN
code/espurna/data/index.small.html.gz View File


BIN
code/espurna/data/index.thermostat.html.gz View File


+ 1685
- 1684
code/espurna/static/index.all.html.gz.h
File diff suppressed because it is too large
View File


+ 1360
- 1359
code/espurna/static/index.curtain.html.gz.h
File diff suppressed because it is too large
View File


+ 1317
- 1316
code/espurna/static/index.garland.html.gz.h
File diff suppressed because it is too large
View File


+ 1893
- 1893
code/espurna/static/index.light.html.gz.h
File diff suppressed because it is too large
View File


+ 1320
- 1320
code/espurna/static/index.lightfox.html.gz.h
File diff suppressed because it is too large
View File


+ 897
- 896
code/espurna/static/index.rfbridge.html.gz.h
File diff suppressed because it is too large
View File


+ 1358
- 1357
code/espurna/static/index.rfm69.html.gz.h
File diff suppressed because it is too large
View File


+ 1393
- 1393
code/espurna/static/index.sensor.html.gz.h
File diff suppressed because it is too large
View File


+ 846
- 846
code/espurna/static/index.small.html.gz.h
File diff suppressed because it is too large
View File


+ 879
- 878
code/espurna/static/index.thermostat.html.gz.h
File diff suppressed because it is too large
View File


+ 24
- 27
code/html/custom.js View File

@ -197,9 +197,8 @@ function validatePassword(password) {
}
// Try to validate 'adminPass{0,1}', searching the first form containing both.
// In case we on normal settings page, avoid checking things when both fields were not changed
// Allow to enforce validation for the setup page
function validateFormPasswords(forms, required) {
// In case it's default webMode, avoid checking things when both fields are empty (`required === false`)
function validateFormsPasswords(forms, required) {
let [passwords] = Array.from(forms).filter(
form => form.elements.adminPass0 && form.elements.adminPass1);
@ -230,7 +229,7 @@ function validateFormPasswords(forms, required) {
// Same as above, but only applies to the general settings page.
// Find the first available form that contains 'hostname' input
function validateFormHostname(forms) {
function validateFormsHostname(forms) {
// per. [RFC1035](https://datatracker.ietf.org/doc/html/rfc1035)
// Hostname may contain:
// - the ASCII letters 'a' through 'z' (case-insensitive),
@ -257,7 +256,7 @@ function validateFormHostname(forms) {
}
function validateForms(forms) {
return validateFormPasswords(forms) && validateFormHostname(forms);
return validateFormsPasswords(forms) && validateFormsHostname(forms);
}
// Right now, group additions happen from:
@ -730,10 +729,8 @@ function toggleVisiblePassword(event) {
}
}
function generatePasswordsForForm(name) {
let value = generatePassword();
let form = document.forms[name];
function generatePasswordsForForm(form) {
const value = generatePassword();
for (let elem of [form.elements.adminPass0, form.elements.adminPass1]) {
setChangedElement(elem);
elem.type = "text";
@ -741,6 +738,20 @@ function generatePasswordsForForm(name) {
}
}
function initSetupPassword(form) {
elementSelectorOnClick(".button-setup-password", (event) => {
event.preventDefault();
const forms = [form];
if (validateFormsPasswords(forms, true)) {
sendConfig(getData(forms, true, false));
}
});
elementSelectorOnClick(".button-generate-password", (event) => {
event.preventDefault();
generatePasswordsForForm(form);
});
}
function moduleVisible(module) {
const elems = document.getElementsByClassName(`module-${module}`);
for (let elem of elems) {
@ -1118,14 +1129,6 @@ function handleFirmwareUpgrade(event) {
});
}
// Initial page, when webMode only allows to change the password
function sendPasswordConfig(name) {
let forms = [document.forms[name]];
if (validateFormPasswords(forms, true)) {
sendConfig(getData(forms, true, false));
}
}
function afterSaved() {
var response;
@ -2544,16 +2547,8 @@ function main() {
initExternalLinks();
createCheckboxes(document);
// Password handling for the initial screen and the rest of inputs that are supposed to be 'secret'
elementSelectorOnClick(".password-reveal", toggleVisiblePassword);
elementSelectorOnClick(".button-setup-password", (event) => {
event.preventDefault();
sendPasswordConfig("panel-password");
});
elementSelectorOnClick(".button-generate-password", (event) => {
event.preventDefault();
generatePasswordsForForm("panel-password");
});
// Initial page, when webMode only allows to change the password
initSetupPassword(document.forms["form-setup-password"]);
// Sidebar menu & buttons
elementSelectorOnClick(".menu-link", toggleMenu);
@ -2645,6 +2640,8 @@ function main() {
}
}
elementSelectorOnClick(".password-reveal", toggleVisiblePassword);
elementSelectorOnClick(".button-dbg-clear", (event) => {
event.preventDefault();
document.getElementById("weblog").textContent = "";


Loading…
Cancel
Save