passwdchange.lua 914 B

12345678910111213141516171819202122232425262728293031323334353637
  1. local fs = require "nixio.fs"
  2. m = Map("system", translate("Router Password"),
  3. translate("Changes the administrator password for accessing the device"))
  4. s = m:section(TypedSection, "_dummy", "")
  5. s.addremove = false
  6. s.anonymous = true
  7. pw1 = s:option(Value, "pw1", translate("Password"))
  8. pw1.password = true
  9. pw2 = s:option(Value, "pw2", translate("Confirmation"))
  10. pw2.password = true
  11. function s.cfgsections()
  12. return { "_pass" }
  13. end
  14. function m.on_commit(map)
  15. local v1 = pw1:formvalue("_pass")
  16. local v2 = pw2:formvalue("_pass")
  17. if v1 and v2 and #v1 > 0 and #v2 > 0 then
  18. if v1 == v2 then
  19. if luci.sys.user.setpasswd("root", v1) == 0 then
  20. m.message = translate("Password successfully changed!")
  21. else
  22. m.message = translate("Unknown Error, password not changed!")
  23. end
  24. else
  25. m.message = translate("Given password confirmation did not match, password not changed!")
  26. end
  27. end
  28. end
  29. return m