From 7535d7a9286ecc8976ad07e9569039639627edb5 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 19 Feb 2025 01:35:53 +0000 Subject: [PATCH] Update 'root/usr/lib/lua/luci/model/cbi/torguard/tgopenvpn.lua' --- .../lua/luci/model/cbi/torguard/tgopenvpn.lua | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/root/usr/lib/lua/luci/model/cbi/torguard/tgopenvpn.lua b/root/usr/lib/lua/luci/model/cbi/torguard/tgopenvpn.lua index a88d275..c8fb000 100644 --- a/root/usr/lib/lua/luci/model/cbi/torguard/tgopenvpn.lua +++ b/root/usr/lib/lua/luci/model/cbi/torguard/tgopenvpn.lua @@ -9,6 +9,21 @@ local function is_vpn_connected() return (status == 0) and "Connected" or "Disconnected" end +-- Function to get RX and TX statistics for tun0 +local function get_vpn_traffic() + local rx, tx = "N/A", "N/A" + local f = io.popen("ifconfig tun0 | 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("tgopenvpn_cfg", "TorGuard OpenVPN Setup") @@ -20,6 +35,14 @@ 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 OpenVPN settings s = m:section(TypedSection, "ovpnconfig", "OpenVPN Settings") s.anonymous = true