Skip to content

Commit

Permalink
Add basic SoftEther status page
Browse files Browse the repository at this point in the history
  • Loading branch information
BERENYI Balazs committed Dec 16, 2020
1 parent a650949 commit 4261443
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
15 changes: 15 additions & 0 deletions applications/luci-app-softether/Makefile
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions applications/luci-app-softether/luasrc/view/softether.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<%+header%>
<h2>SoftEther Status</h2>
<%
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("<div class=\"tr cbi-section-table-row\">")
luci.http.write("<div class=\"td\" style=\"width: 20%;vertical-align: top;\"><strong>Account:</strong> " .. account .. "</div>")
luci.http.write("<div class=\"td\">")
for i,v in pairs(properties) do
luci.http.write("<strong>" .. i .. ":</strong> " .. v .. "</br>")
end
luci.http.write("</div>") -- td
luci.http.write("</div>") -- 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("<div class=\"cbi-section\">")
luci.http.write("<div class=\"cbi-section-node\">")
luci.http.write("<div class=\"table cbi-section-table\">")

for acc_name, acc_properties in pairs(accounts) do
dump_account(acc_name, acc_properties)
end
luci.http.write("</div>") -- table
luci.http.write("</div>") -- section-node
luci.http.write("</div>") -- section

%>
<%+footer%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"admin/status/softether": {
"title": "SoftEther Status",
"order": 94,
"action": {
"type": "template",
"path": "softether"
}
}
}

0 comments on commit 4261443

Please sign in to comment.