1 -- Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.controller.ocserv", package.seeall)
7 if not nixio.fs.access("/etc/config/ocserv") then
13 page = entry({"admin", "services", "ocserv"}, alias("admin", "services", "ocserv", "main"),
17 page = entry({"admin", "services", "ocserv", "main"},
19 _("Server Settings"), 200)
22 page = entry({"admin", "services", "ocserv", "users"},
24 _("User Settings"), 300)
27 entry({"admin", "services", "ocserv", "status"},
28 call("ocserv_status")).leaf = true
30 entry({"admin", "services", "ocserv", "disconnect"},
31 post("ocserv_disconnect")).leaf = true
35 function ocserv_status()
36 local ipt = io.popen("/usr/bin/occtl show users");
43 local ln = ipt:read("*l")
44 if not ln then break end
46 local id, user, group, vpn_ip, ip, device, time, cipher, status =
47 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%(%)%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%(%)%:%.-_%w]+)%s+([%:%.-_%w]+).*")
63 luci.http.prepare_content("application/json")
64 luci.http.write_json(fwd)
68 function ocserv_disconnect(num)
69 local idx = tonumber(num)
71 if idx and idx > 0 then
72 luci.sys.call("/usr/bin/occtl disconnect id %d" % idx)
73 luci.http.status(200, "OK")
77 luci.http.status(400, "Bad request")