remote.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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", "SSH-Keys")
  14. m.submit = "Speichern"
  15. m.reset = "Zurücksetzen"
  16. m.pageaction = false
  17. m.template = "admin/expertmode"
  18. if fs.access("/etc/config/dropbear") then
  19. local s = m:section(TypedSection, "_dummy1", nil,
  20. "Hier hast du die Möglichkeit SSH-Keys (einen pro Zeile) zu hinterlegen:")
  21. s.addremove = false
  22. s.anonymous = true
  23. function s.cfgsections()
  24. return { "_keys" }
  25. end
  26. local keys
  27. keys = s:option(TextValue, "_data", "")
  28. keys.wrap = "off"
  29. keys.rows = 5
  30. keys.rmempty = true
  31. function keys.cfgvalue()
  32. return fs.readfile("/etc/dropbear/authorized_keys") or ""
  33. end
  34. function keys.write(self, section, value)
  35. if value then
  36. fs.writefile("/etc/dropbear/authorized_keys", value:gsub("\r\n", "\n"))
  37. end
  38. end
  39. function keys.remove(self, section)
  40. if keys:formvalue("_keys") then
  41. fs.remove("/etc/dropbear/authorized_keys")
  42. end
  43. end
  44. end
  45. local m2 = Map("system", "Passwort")
  46. m2.submit = "Speichern"
  47. m2.reset = false
  48. m2.pageaction = false
  49. m2.template = "admin/expertmode"
  50. local s = m2:section(TypedSection, "_dummy2", nil,
  51. [[Alternativ kannst du auch ein Passwort setzen. Wähle bitte ein sicheres Passwort, das du nirgendwo anders verwendest.<br /><br />
  52. Beim Setzen eines leeren Passworts wird der Login per Passwort gesperrt (dies ist die Standard-Einstellung).]])
  53. s.addremove = false
  54. s.anonymous = true
  55. local pw1 = s:option(Value, "pw1", "Passwort")
  56. pw1.password = true
  57. local pw2 = s:option(Value, "pw2", "Wiederholung")
  58. pw2.password = true
  59. function s.cfgsections()
  60. return { "_pass" }
  61. end
  62. function m2.on_commit(map)
  63. local v1 = pw1:formvalue("_pass")
  64. local v2 = pw2:formvalue("_pass")
  65. if v1 and v2 then
  66. if v1 == v2 then
  67. if #v1 > 0 then
  68. if luci.sys.user.setpasswd(luci.dispatcher.context.authuser, v1) == 0 then
  69. m2.message = "Passwort geändert."
  70. else
  71. m2.errmessage = "Das Passwort konnte nicht geändert werden."
  72. end
  73. else
  74. -- We don't check the return code here as the error 'password for root is already locked' is normal...
  75. os.execute('passwd -l root >/dev/null')
  76. m2.message = "Passwort gelöscht."
  77. end
  78. else
  79. m2.errmessage = "Die beiden Passwörter stimmen nicht überein."
  80. end
  81. end
  82. end
  83. local c = Compound(m, m2)
  84. c.pageaction = false
  85. return c