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 module("luci.controller.ocserv", package.seeall)
17 if not nixio.fs.access("/etc/config/ocserv") then
23 page = entry({"admin", "services", "ocserv"}, alias("admin", "services", "ocserv", "main"),
27 page = entry({"admin", "services", "ocserv", "main"},
29 _("Server Settings"), 200)
32 page = entry({"admin", "services", "ocserv", "users"},
34 _("User Settings"), 300)
37 entry({"admin", "services", "ocserv", "status"},
38 call("ocserv_status")).leaf = true
40 entry({"admin", "services", "ocserv", "disconnect"},
41 call("ocserv_disconnect")).leaf = true
45 function ocserv_status()
46 local ipt = io.popen("/usr/bin/occtl show users");
53 local ln = ipt:read("*l")
54 if not ln then break end
56 local id, user, group, vpn_ip, ip, device, time, cipher, status =
57 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+).*")
73 luci.http.prepare_content("application/json")
74 luci.http.write_json(fwd)
78 function ocserv_disconnect(num)
79 local idx = tonumber(num)
81 if idx and idx > 0 then
82 luci.sys.call("/usr/bin/occtl disconnect id %d" % idx)
83 luci.http.status(200, "OK")
87 luci.http.status(400, "Bad request")