2 LuCI - Lua Configuration Interface
4 Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
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
10 http://www.apache.org/licenses/LICENSE-2.0
14 local dsp = require "luci.dispatcher"
15 local nixio = require "nixio"
17 m = Map("ocserv", translate("OpenConnect VPN"))
19 if m.uci:get("ocserv", "config", "auth") == "plain" then
23 function m.on_commit(map)
24 luci.sys.call("/etc/init.d/ocserv restart >/dev/null 2>&1")
27 s = m:section(TypedSection, "ocservusers", translate("Available users"))
30 s.template = "cbi/tblsection"
32 s:option(Value, "name", translate("Name")).rmempty = true
33 s:option(DummyValue, "group", translate("Group")).rmempty = true
34 pwd = s:option(Value, "password", translate("Password"))
37 function pwd.write(self, section, value)
39 if string.match(value, "^\$%d\$.*") then
42 local t = tonumber(nixio.getpid()*os.time())
43 local salt = "$5$" .. t .. "$"
44 pass = nixio.crypt(value, salt)
46 Value.write(self, section, pass)
53 local fd = io.popen("/usr/bin/occtl show users", "r")
57 if not ln then break end
59 local id, user, group, vpn_ip, ip, device, time, cipher, status =
60 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+).*")
62 table.insert(lusers, {id, user, group, vpn_ip, ip, device, time, cipher, status})
71 local s = m:section(Table, lusers, translate("Active users"))
73 s.template = "cbi/tblsection"
75 s:option(DummyValue, 1, translate("ID"))
76 s:option(DummyValue, 2, translate("Username"))
77 s:option(DummyValue, 3, translate("Group"))
78 s:option(DummyValue, 4, translate("IP"))
79 s:option(DummyValue, 5, translate("VPN IP"))
80 s:option(DummyValue, 6, translate("Device"))
81 s:option(DummyValue, 7, translate("Time"))
82 s:option(DummyValue, 8, translate("Cipher"))
83 s:option(DummyValue, 9, translate("Status"))