|
|
|
@ -3,9 +3,46 @@ local uci = require("luci.model.uci").cursor()
|
|
|
|
|
local sys = require("luci.sys")
|
|
|
|
|
local util = require("luci.util")
|
|
|
|
|
|
|
|
|
|
-- Function to check if AnyConnect (openconnect-vpn) is active
|
|
|
|
|
local function is_vpn_connected()
|
|
|
|
|
local status = sys.call("ip link show openconnect-vpn >/dev/null 2>&1")
|
|
|
|
|
return (status == 0) and "Connected" or "Disconnected"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Function to get RX and TX statistics for openconnect-vpn
|
|
|
|
|
local function get_vpn_traffic()
|
|
|
|
|
local rx, tx = "N/A", "N/A"
|
|
|
|
|
local f = io.popen("ifconfig openconnect-vpn | grep 'RX bytes' 2>/dev/null")
|
|
|
|
|
if f then
|
|
|
|
|
local output = f:read("*a")
|
|
|
|
|
f:close()
|
|
|
|
|
if output then
|
|
|
|
|
rx = output:match("RX bytes:(%d+)") or "N/A"
|
|
|
|
|
tx = output:match("TX bytes:(%d+)") or "N/A"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return rx, tx
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Define the model
|
|
|
|
|
m = Map("tganyconnect_cfg", "TorGuard AnyConnect VPN Setup")
|
|
|
|
|
|
|
|
|
|
-- VPN Status Section
|
|
|
|
|
status_section = m:section(TypedSection, "anyconnectconfig", "AnyConnect VPN Status")
|
|
|
|
|
status_section.anonymous = true
|
|
|
|
|
status_section.addremove = false
|
|
|
|
|
|
|
|
|
|
status = status_section:option(DummyValue, "_vpn_status", translate("VPN Status"))
|
|
|
|
|
status.value = is_vpn_connected()
|
|
|
|
|
|
|
|
|
|
-- VPN Traffic Stats
|
|
|
|
|
rx, tx = get_vpn_traffic()
|
|
|
|
|
rx_stat = status_section:option(DummyValue, "_vpn_rx", translate("RX Bytes"))
|
|
|
|
|
rx_stat.value = rx .. " Bytes"
|
|
|
|
|
|
|
|
|
|
tx_stat = status_section:option(DummyValue, "_vpn_tx", translate("TX Bytes"))
|
|
|
|
|
tx_stat.value = tx .. " Bytes"
|
|
|
|
|
|
|
|
|
|
-- Define the section for the AnyConnect settings
|
|
|
|
|
s = m:section(TypedSection, "anyconnectconfig", "AnyConnect VPN Settings")
|
|
|
|
|
s.anonymous = true
|
|
|
|
@ -14,6 +51,7 @@ s.addremove = false
|
|
|
|
|
-- Define the input fields for the AnyConnect settings
|
|
|
|
|
user = s:option(Value, "username", translate("VPN Username"))
|
|
|
|
|
pass = s:option(Value, "password", translate("VPN Password"))
|
|
|
|
|
pass.password = true
|
|
|
|
|
|
|
|
|
|
svr = s:option(ListValue, "server", translate("VPN Server"))
|
|
|
|
|
-- Add all servers here
|
|
|
|
@ -25,6 +63,7 @@ svr:value("nl.anyconnect.host", "Netherlands")
|
|
|
|
|
svr:value("pl.anyconnect.host", "Poland")
|
|
|
|
|
svr:value("sg.anyconnect.host", "Singapore")
|
|
|
|
|
svr:value("uk.anyconnect.host", "United Kingdom")
|
|
|
|
|
svr:value("ukr.anyconnect.host", "Ukraine")
|
|
|
|
|
svr:value("la.usa.anyconnect.host", "USA LA")
|
|
|
|
|
svr:value("ny.usa.anyconnect.host", "USA NY")
|
|
|
|
|
|
|
|
|
|