collectd: unbreak collectd-mod-sensors
[feed/packages.git] / net / luci-app-ocserv / files / usr / lib / lua / luci / controller / ocserv.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 module("luci.controller.ocserv", package.seeall)
16
17 function index()
18 if not nixio.fs.access("/etc/config/ocserv") then
19 return
20 end
21
22 local page
23
24 page = entry({"admin", "services", "ocserv"}, alias("admin", "services", "ocserv", "main"),
25 _("OpenConnect VPN"))
26 page.dependent = true
27
28 page = entry({"admin", "services", "ocserv", "main"},
29 cbi("ocserv/main"),
30 _("Server Settings"), 200)
31 page.dependent = true
32
33 page = entry({"admin", "services", "ocserv", "users"},
34 cbi("ocserv/users"),
35 _("User Settings"), 300)
36 page.dependent = true
37
38 entry({"admin", "services", "ocserv", "status"},
39 call("ocserv_status")).leaf = true
40
41 entry({"admin", "services", "ocserv", "disconnect"},
42 call("ocserv_disconnect")).leaf = true
43
44 end
45
46 function ocserv_status()
47 local ipt = io.popen("/usr/bin/occtl show users");
48
49 if ipt then
50
51 local fwd = { }
52 while true do
53
54 local ln = ipt:read("*l")
55 if not ln then break end
56
57 local id, user, group, vpn_ip, ip, device, time, cipher, status =
58 ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+).*")
59 if id then
60 fwd[#fwd+1] = {
61 id = id,
62 user = user,
63 group = group,
64 vpn_ip = vpn_ip,
65 ip = ip,
66 device = device,
67 time = time,
68 cipher = cipher,
69 status = status
70 }
71 end
72 end
73 ipt:close()
74 luci.http.prepare_content("application/json")
75 luci.http.write_json(fwd)
76 end
77 end
78
79 function ocserv_disconnect(num)
80 local idx = tonumber(num)
81 local uci = luci.model.uci.cursor()
82
83 if idx and idx > 0 then
84 luci.sys.call("/usr/bin/occtl disconnect id %d" % idx)
85 luci.http.status(200, "OK")
86
87 return
88 end
89 luci.http.status(400, "Bad request")
90 end