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", "vpn", "ocserv"}, alias("admin", "vpn", "ocserv", "main"),
16 page.acl_depends = { "luci-app-ocserv" }
18 page = entry({"admin", "vpn", "ocserv", "main"},
20 _("Server Settings"), 200)
23 page = entry({"admin", "vpn", "ocserv", "users"},
25 _("User Settings"), 300)
28 entry({"admin", "vpn", "ocserv", "status"},
29 call("ocserv_status")).leaf = true
31 entry({"admin", "vpn", "ocserv", "disconnect"},
32 post("ocserv_disconnect")).leaf = true
36 function ocserv_status()
37 local ipt = io.popen("/usr/bin/occtl show users");
44 local ln = ipt:read("*l")
45 if not ln then break end
47 local id, user, group, vpn_ip, ip, device, time, cipher, status =
48 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%(%)%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%(%)%:%.-_%w]+)%s+([%:%.-_%w]+).*")
64 luci.http.prepare_content("application/json")
65 luci.http.write_json(fwd)
69 function ocserv_disconnect(num)
70 local idx = tonumber(num)
72 if idx and idx > 0 then
73 luci.sys.call("/usr/bin/occtl disconnect id %d" % idx)
74 luci.http.status(200, "OK")
78 luci.http.status(400, "Bad request")