From 42614437429aa50989f5a45edf0aea37ca1047a6 Mon Sep 17 00:00:00 2001 From: BERENYI Balazs Date: Wed, 16 Dec 2020 17:22:37 +0000 Subject: [PATCH] Add basic SoftEther status page --- applications/luci-app-softether/Makefile | 15 ++++ .../luasrc/view/softether.htm | 74 +++++++++++++++++++ .../share/luci/menu.d/luci-app-softether.json | 10 +++ 3 files changed, 99 insertions(+) create mode 100644 applications/luci-app-softether/Makefile create mode 100644 applications/luci-app-softether/luasrc/view/softether.htm create mode 100644 applications/luci-app-softether/root/usr/share/luci/menu.d/luci-app-softether.json diff --git a/applications/luci-app-softether/Makefile b/applications/luci-app-softether/Makefile new file mode 100644 index 000000000000..4abce2eb5c92 --- /dev/null +++ b/applications/luci-app-softether/Makefile @@ -0,0 +1,15 @@ +# +# This is free software, licensed under the Apache License, Version 2.0 . +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:=SoftEther Status +LUCI_DEPENDS:=+softethervpn5-client +LUCI_PKGARCH:=all + +PKG_LICENSE:=Apache-2.0 + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-softether/luasrc/view/softether.htm b/applications/luci-app-softether/luasrc/view/softether.htm new file mode 100644 index 000000000000..b02819a3f4a2 --- /dev/null +++ b/applications/luci-app-softether/luasrc/view/softether.htm @@ -0,0 +1,74 @@ +<%+header%> +

SoftEther Status

+<% + local function table_merge(table1, table2) + for k,v in pairs(table2) do + table1[k] = v + end + return table1 + end + + local function get_account_list() + local accounts = {} + local ac_list = io.popen("vpncmd localhost /client /csv /cmd:accountlist | tail -n +4 2> /dev/null ") + if ac_list then + local line + for line in ac_list:lines() do + local line = string.split(line, ",") + local d = {} + d["Status"] = line[2] + accounts[line[1]] = d + end + end + return accounts + end + + local function get_account_status(ac_name) + local t = {} + local csv = io.popen("vpncmd localhost /client /csv /cmd:accountstatusget " .. ac_name .. " | tail -n +4 2> /dev/null ") + if csv then + local line + for line in csv:lines() do + local line = string.split(line, ",") + if table.getn(line) == 2 then + t[line[1]] = line[2] + end + end + end + return t + end + + + local function dump_account(account, properties) + luci.http.write("
") + luci.http.write("
Account: " .. account .. "
") + luci.http.write("
") + for i,v in pairs(properties) do + luci.http.write("" .. i .. ": " .. v .. "
") + end + luci.http.write("
") -- td + luci.http.write("
") -- tr + end + + +-- Gather stuff + local accounts = get_account_list() + for acc_name, acc_properties in pairs(accounts) do + local acc_status = get_account_status(acc_name) + table_merge(acc_properties, acc_status) + end + +-- Render stuff + luci.http.write("
") + luci.http.write("
") + luci.http.write("
") + + for acc_name, acc_properties in pairs(accounts) do + dump_account(acc_name, acc_properties) + end + luci.http.write("
") -- table + luci.http.write("
") -- section-node + luci.http.write("
") -- section + + %> +<%+footer%> diff --git a/applications/luci-app-softether/root/usr/share/luci/menu.d/luci-app-softether.json b/applications/luci-app-softether/root/usr/share/luci/menu.d/luci-app-softether.json new file mode 100644 index 000000000000..7c663ea75cf0 --- /dev/null +++ b/applications/luci-app-softether/root/usr/share/luci/menu.d/luci-app-softether.json @@ -0,0 +1,10 @@ +{ + "admin/status/softether": { + "title": "SoftEther Status", + "order": 94, + "action": { + "type": "template", + "path": "softether" + } + } +} \ No newline at end of file