remote.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. --[[
  2. LuCI - Lua Configuration Interface
  3. Copyright 2008 Steven Barth <steven@midlink.org>
  4. Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
  5. Copyright 2013 Nils Schneider <nils@nilsschneider.net>
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. $Id$
  11. ]]--
  12. local fs = require "nixio.fs"
  13. local m = Map("system", translate("SSH keys"))
  14. m.pageaction = false
  15. m.template = "admin/expertmode"
  16. if fs.access("/etc/config/dropbear") then
  17. local s = m:section(TypedSection, "_dummy1", nil,
  18. translate("You can provide your SSH keys here (one per line):"))
  19. s.addremove = false
  20. s.anonymous = true
  21. function s.cfgsections()
  22. return { "_keys" }
  23. end
  24. local keys
  25. keys = s:option(TextValue, "_data", "")
  26. keys.wrap = "off"
  27. keys.rows = 5
  28. keys.rmempty = true
  29. function keys.cfgvalue()
  30. return fs.readfile("/etc/dropbear/authorized_keys") or ""
  31. end
  32. function keys.write(self, section, value)
  33. if value then
  34. fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"):trim() .. "\n")
  35. end
  36. end
  37. function keys.remove(self, section)
  38. if keys:formvalue("_keys") then
  39. fs.remove("/etc/dropbear/authorized_keys")
  40. end
  41. end
  42. end
  43. local m2 = Map("system", translate("Password"))
  44. m2.reset = false
  45. m2.pageaction = false
  46. m2.template = "admin/expertmode"
  47. local s = m2:section(TypedSection, "_dummy2", nil, translate(
  48. "Alternatively, you can set a password to access you node. Please choose a secure password you don't use anywhere else.<br /><br />"
  49. .. "If you set an empty password, login via password will be disabled. This is the default."))
  50. s.addremove = false
  51. s.anonymous = true
  52. local pw1 = s:option(Value, "pw1", translate("Password"))
  53. pw1.password = true
  54. local pw2 = s:option(Value, "pw2", translate("Confirmation"))
  55. pw2.password = true
  56. function s.cfgsections()
  57. return { "_pass" }
  58. end
  59. function m2.on_commit(map)
  60. local v1 = pw1:formvalue("_pass")
  61. local v2 = pw2:formvalue("_pass")
  62. if v1 and v2 then
  63. if v1 == v2 then
  64. if #v1 > 0 then
  65. if luci.sys.user.setpasswd('root', v1) == 0 then
  66. m2.message = translate("Password changed.")
  67. else
  68. m2.errmessage = translate("Unable to change the password.")
  69. end
  70. else
  71. -- We don't check the return code here as the error 'password for root is already locked' is normal...
  72. os.execute('passwd -l root >/dev/null')
  73. m2.message = translate("Password removed.")
  74. end
  75. else
  76. m2.errmessage = translate("The password and the confirmation differ.")
  77. end
  78. end
  79. end
  80. local c = Compound(m, m2)
  81. c.pageaction = false
  82. return c