summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-ocserv/luasrc/controller/ocserv.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-12-03 15:17:05 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-08 16:26:20 +0100
commit1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch)
tree35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-ocserv/luasrc/controller/ocserv.lua
parent9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff)
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names * Make each LuCI module its own standalone package * Deploy a shared luci.mk which is used by each module Makefile Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-ocserv/luasrc/controller/ocserv.lua')
-rw-r--r--applications/luci-app-ocserv/luasrc/controller/ocserv.lua88
1 files changed, 88 insertions, 0 deletions
diff --git a/applications/luci-app-ocserv/luasrc/controller/ocserv.lua b/applications/luci-app-ocserv/luasrc/controller/ocserv.lua
new file mode 100644
index 0000000000..229102da64
--- /dev/null
+++ b/applications/luci-app-ocserv/luasrc/controller/ocserv.lua
@@ -0,0 +1,88 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+module("luci.controller.ocserv", package.seeall)
+
+function index()
+ if not nixio.fs.access("/etc/config/ocserv") then
+ return
+ end
+
+ local page
+
+ page = entry({"admin", "services", "ocserv"}, alias("admin", "services", "ocserv", "main"),
+ _("OpenConnect VPN"))
+ page.dependent = true
+
+ page = entry({"admin", "services", "ocserv", "main"},
+ cbi("ocserv/main"),
+ _("Server Settings"), 200)
+ page.dependent = true
+
+ page = entry({"admin", "services", "ocserv", "users"},
+ cbi("ocserv/users"),
+ _("User Settings"), 300)
+ page.dependent = true
+
+ entry({"admin", "services", "ocserv", "status"},
+ call("ocserv_status")).leaf = true
+
+ entry({"admin", "services", "ocserv", "disconnect"},
+ call("ocserv_disconnect")).leaf = true
+
+end
+
+function ocserv_status()
+ local ipt = io.popen("/usr/bin/occtl show users");
+
+ if ipt then
+
+ local fwd = { }
+ while true do
+
+ local ln = ipt:read("*l")
+ if not ln then break end
+
+ local id, user, group, vpn_ip, ip, device, time, cipher, status =
+ ln:match("^%s*(%d+)%s+([-_%w]+)%s+([%.%*-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+)%s+([%:%.-_%w]+).*")
+ if id then
+ fwd[#fwd+1] = {
+ id = id,
+ user = user,
+ group = group,
+ vpn_ip = vpn_ip,
+ ip = ip,
+ device = device,
+ time = time,
+ cipher = cipher,
+ status = status
+ }
+ end
+ end
+ ipt:close()
+ luci.http.prepare_content("application/json")
+ luci.http.write_json(fwd)
+ end
+end
+
+function ocserv_disconnect(num)
+ local idx = tonumber(num)
+
+ if idx and idx > 0 then
+ luci.sys.call("/usr/bin/occtl disconnect id %d" % idx)
+ luci.http.status(200, "OK")
+
+ return
+ end
+ luci.http.status(400, "Bad request")
+end