2
0

admin.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.parse(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. Map.parse(map)
  32. end
  33. if fs.access("/etc/config/dropbear") then
  34. m2 = Map("dropbear", translate("SSH Access"),
  35. translate("Dropbear offers <abbr title=\"Secure Shell\">SSH</abbr> network shell access and an integrated <abbr title=\"Secure Copy\">SCP</abbr> server"))
  36. s = m2:section(TypedSection, "dropbear", translate("Dropbear Instance"))
  37. s.anonymous = true
  38. s.addremove = true
  39. ni = s:option(Value, "Interface", translate("Interface"),
  40. translate("Listen only on the given interface or, if unspecified, on all"))
  41. ni.template = "cbi/network_netlist"
  42. ni.nocreate = true
  43. ni.unspecified = true
  44. pt = s:option(Value, "Port", translate("Port"),
  45. translate("Specifies the listening port of this <em>Dropbear</em> instance"))
  46. pt.datatype = "port"
  47. pt.default = 22
  48. pa = s:option(Flag, "PasswordAuth", translate("Password authentication"),
  49. translate("Allow <abbr title=\"Secure Shell\">SSH</abbr> password authentication"))
  50. pa.enabled = "on"
  51. pa.disabled = "off"
  52. pa.default = pa.enabled
  53. pa.rmempty = false
  54. ra = s:option(Flag, "RootPasswordAuth", translate("Allow root logins with password"),
  55. translate("Allow the <em>root</em> user to login with password"))
  56. ra.enabled = "on"
  57. ra.disabled = "off"
  58. ra.default = ra.enabled
  59. gp = s:option(Flag, "GatewayPorts", translate("Gateway ports"),
  60. translate("Allow remote hosts to connect to local SSH forwarded ports"))
  61. gp.enabled = "on"
  62. gp.disabled = "off"
  63. gp.default = gp.disabled
  64. s2 = m2:section(TypedSection, "_dummy", translate("SSH-Keys"),
  65. translate("Here you can paste public SSH-Keys (one per line) for SSH public-key authentication."))
  66. s2.addremove = false
  67. s2.anonymous = true
  68. s2.template = "cbi/tblsection"
  69. function s2.cfgsections()
  70. return { "_keys" }
  71. end
  72. keys = s2:option(TextValue, "_data", "")
  73. keys.wrap = "off"
  74. keys.rows = 3
  75. keys.rmempty = false
  76. function keys.cfgvalue()
  77. return fs.readfile("/etc/dropbear/authorized_keys") or ""
  78. end
  79. function keys.write(self, section, value)
  80. if value then
  81. fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
  82. end
  83. end
  84. end
  85. return m, m2