users.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. -- Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local dsp = require "luci.dispatcher"
  4. local nixio = require "nixio"
  5. m = Map("ocserv", translate("OpenConnect VPN"))
  6. if m.uci:get("ocserv", "config", "auth") == "plain" then
  7. --[[Users]]--
  8. function m.on_commit(map)
  9. luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
  10. end
  11. s = m:section(TypedSection, "ocservusers", translate("Available users"))
  12. s.anonymous = true
  13. s.addremove = true
  14. s.template = "cbi/tblsection"
  15. s:option(Value, "name", translate("Name")).rmempty = true
  16. s:option(DummyValue, "group", translate("Group")).rmempty = true
  17. pwd = s:option(Value, "password", translate("Password"))
  18. pwd.password = false
  19. function pwd.write(self, section, value)
  20. local pass
  21. if string.match(value, "^\$%d\$.*") then
  22. pass = value
  23. else
  24. local t = tonumber(nixio.getpid()*os.time())
  25. local salt = "$1$" .. t .. "$"
  26. pass = nixio.crypt(value, salt)
  27. end
  28. Value.write(self, section, pass)
  29. end
  30. --[[if plain]]--
  31. end
  32. local lusers = { }
  33. local fd = io.popen("/usr/bin/occtl show users", "r")
  34. if fd then local ln
  35. repeat
  36. ln = fd:read("*l")
  37. if not ln then break end
  38. local id, user, group, vpn_ip, ip, device, time, cipher, status =
  39. ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%(%)%:%.-_%w]+)%s+([%:%.-_%w]+).*")
  40. if id then
  41. table.insert(lusers, {id, user, group, vpn_ip, ip, device, time, cipher, status})
  42. end
  43. until not ln
  44. fd:close()
  45. end
  46. --[[Active Users]]--
  47. local s = m:section(Table, lusers, translate("Active users"))
  48. s.anonymous = true
  49. s.template = "cbi/tblsection"
  50. s:option(DummyValue, 1, translate("ID"))
  51. s:option(DummyValue, 2, translate("Username"))
  52. s:option(DummyValue, 3, translate("Group"))
  53. s:option(DummyValue, 4, translate("IP"))
  54. s:option(DummyValue, 5, translate("VPN IP"))
  55. s:option(DummyValue, 6, translate("Device"))
  56. s:option(DummyValue, 7, translate("Time"))
  57. s:option(DummyValue, 8, translate("Cipher"))
  58. s:option(DummyValue, 9, translate("Status"))
  59. return m