1 -- Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
4 local dsp = require "luci.dispatcher"
5 local nixio = require "nixio"
7 m = Map("ocserv", translate("OpenConnect VPN"))
9 if m.uci:get("ocserv", "config", "auth") == "plain" then
13 function m.on_commit(map)
14 luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
17 s = m:section(TypedSection, "ocservusers", translate("Available users"))
20 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"))
27 function pwd.write(self, section, value)
29 if string.match(value, "^\$%d\$.*") then
32 local t = tonumber(nixio.getpid()*os.time())
33 local salt = "$5$" .. t .. "$"
34 pass = nixio.crypt(value, salt)
36 Value.write(self, section, pass)
43 local fd = io.popen("/usr/bin/occtl show users", "r")
47 if not ln then break end
49 local id, user, group, vpn_ip, ip, device, time, cipher, status =
50 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%(%)%:%.-_%w]+)%s+([%:%.-_%w]+).*")
52 table.insert(lusers, {id, user, group, vpn_ip, ip, device, time, cipher, status})
61 local s = m:section(Table, lusers, translate("Active users"))
63 s.template = "cbi/tblsection"
65 s:option(DummyValue, 1, translate("ID"))
66 s:option(DummyValue, 2, translate("Username"))
67 s:option(DummyValue, 3, translate("Group"))
68 s:option(DummyValue, 4, translate("IP"))
69 s:option(DummyValue, 5, translate("VPN IP"))
70 s:option(DummyValue, 6, translate("Device"))
71 s:option(DummyValue, 7, translate("Time"))
72 s:option(DummyValue, 8, translate("Cipher"))
73 s:option(DummyValue, 9, translate("Status"))