You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

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