% local uci = require "luci.model.uci" local fs = require "nixio.fs" local nws = {} uci.inst_state:foreach("network", "interface", function(s) nws[#nws+1] = s end) if uci.inst_state:get("network", "lan", "_ipchanged") and uci.inst_state:revert("network", "lan", "_ipchanged") then include("niu/network/warn_ip_change") end local wanon = uci.inst_state:get("network", "wan", "proto") local wanup = uci.inst_state:get("network", "wan", "up") local wanip = uci.inst_state:get("network", "wan", "ipaddr") local wanif = uci.inst_state:get("network", "wan", "ifname") local wanul, wandl if wanif then local devstats = fs.readfile("/proc/net/dev") local rx, tx = devstats:match("%s*"..wanif.. ":%s*([0-9]+)%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+".. "[0-9]+%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+([0-9]+)") wanul = tx and (tonumber(tx) / 1000000000) wandl = rx and (tonumber(rx) / 1000000000) end local leasefn uci.inst:foreach("dhcp", "dnsmasq", function(section) leasefn = section.leasefile end ) if leasefn then local ln = fs.access(leasefn, "r") and io.lines(leasefn) leasefn = 0 while ln and ln() do leasefn = leasefn + 1 end end local arps if fs.access("/proc/net/arp", "r") then local ln = io.lines("/proc/net/arp") arps = -1 while ln and ln() do arps = arps + 1 end arps = arps >= 0 and arps end %>
Uplink Address | <%=wanip%> | <% else %>Uplink | offline | <% end %>
---|---|---|---|
Uplink Traffic | <%=("%.2f"):format(wandl)%> GB⇓ <%=("%.2f"):format(wanul)%> GB⇑ | ||
Local Address | <%=uci.inst_state:get("network", "lan", "ipaddr")%> | ||
Active IP-Devices | <%=arps%><% if leasefn then %> (<%=leasefn%> assigned) <% end %> |