admin.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. local fs = require "nixio.fs"
  5. m = Map("system", translate("Router Password"),
  6. translate("Changes the administrator password for accessing the device"))
  7. s = m:section(TypedSection, "_dummy", "")
  8. s.addremove = false
  9. s.anonymous = true
  10. pw1 = s:option(Value, "pw1", translate("Password"))
  11. pw1.password = true
  12. pw2 = s:option(Value, "pw2", translate("Confirmation"))
  13. pw2.password = true
  14. function s.cfgsections()
  15. return { "_pass" }
  16. end
  17. function m.on_commit(map)
  18. local v1 = pw1:formvalue("_pass")
  19. local v2 = pw2:formvalue("_pass")
  20. if v1 and v2 and #v1 > 0 and #v2 > 0 then
  21. if v1 == v2 then
  22. if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
  23. m.message = translate("Password successfully changed!")
  24. else
  25. m.message = translate("Unknown Error, password not changed!")
  26. end
  27. else
  28. m.message = translate("Given password confirmation did not match, password not changed!")
  29. end
  30. end
  31. end
  32. if fs.access("/etc/config/dropbear") then
  33. m2 = Map("dropbear", translate("SSH Access"),
  34. translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
  35. s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
  36. s.anonymous = true
  37. s.addremove = true
  38. ni = s:option(Value, "Interface", translate("Interface"),
  39. translate("Listen only on the given interface or, if unspecified, on all"))
  40. ni.template = "cbi/network_netlist"
  41. ni.nocreate = true
  42. ni.unspecified = true
  43. pt = s:option(Value, "Port", translate("Port"),
  44. translate("Specifies the listening port of this <em>Dropbear</em> instance"))
  45. pt.datatype = "port"
  46. pt.default = 22
  47. pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
  48. translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
  49. pa.enabled = "on"
  50. pa.disabled = "off"
  51. pa.default = pa.enabled
  52. pa.rmempty = false
  53. ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
  54. translate("Allow the <em>root</em> user to login with password"))
  55. ra.enabled = "on"
  56. ra.disabled = "off"
  57. ra.default = ra.enabled
  58. gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
  59. translate("Allow remote hosts to connect to local SSH forwarded ports"))
  60. gp.enabled = "on"
  61. gp.disabled = "off"
  62. gp.default = gp.disabled
  63. s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
  64. translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
  65. s2.addremove = false
  66. s2.anonymous = true
  67. s2.template = "cbi/tblsection"
  68. function s2.cfgsections()
  69. return { "_keys" }
  70. end
  71. keys = s2:option(TextValue, "_data", "")
  72. keys.wrap = "off"
  73. keys.rows = 3
  74. keys.rmempty = false
  75. function keys.cfgvalue()
  76. return fs.readfile("/etc/dropbear/authorized_keys") or ""
  77. end
  78. function keys.write(self, section, value)
  79. if value then
  80. fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
  81. end
  82. end
  83. end
  84. return m, m2