build: split into luci and luci-addons packages
[project/luci.git] / modules / niu / luasrc / view / niu / traffic.htm
1 <%
2 local uci = require "luci.model.uci"
3 local fs = require "nixio.fs"
4
5 local wanon = uci.inst_state:get("network", "wan", "up") == "1"
6 local wanif = wanon and uci.inst_state:get("network", "wan", "ifname")
7 local lanif = uci.inst_state:get("network", "lan", "ifname")
8 local wanul, wandl, lanul, landl
9 local devstats = fs.readfile("/proc/net/dev")
10
11 local fwav = fs.access("/etc/config/firewall", "r")
12 local fwon = uci.inst_state:get("firewall", "core", "loaded") == "1"
13
14 if lanif then
15         local rx, tx = devstats:match("%s*"..lanif..
16         ":%s*([0-9]+)%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+"..
17         "[0-9]+%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+([0-9]+)")
18         lanul = tx and (tonumber(tx) / 1000000000)
19         landl = rx and (tonumber(rx) / 1000000000)
20 end
21
22 if wanif then
23         local rx, tx = devstats:match("%s*"..wanif..
24         ":%s*([0-9]+)%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+"..
25         "[0-9]+%s+[0-9]+%s+[0-9]+%s+[0-9]+%s+([0-9]+)")
26         wanul = tx and (tonumber(tx) / 1000000000)
27         wandl = rx and (tonumber(rx) / 1000000000)
28 end
29
30 %>
31
32 <table class="dbstattbl">
33 <% if wanul and wandl then %>
34 <tr>
35 <th>Uplink Traffic: </th><td>
36 <%=("%.2f"):format(wandl)%> GB&#8659; <%=("%.2f"):format(wanul)%> GB&#8657;
37 </td>
38 </tr>
39 <% end %> 
40
41 <% if lanul and landl then %>
42 <tr>
43 <th>Local Traffic: </th><td>
44 <%=("%.2f"):format(landl)%> GB&#8659; <%=("%.2f"):format(lanul)%> GB&#8657;
45 </td>
46 </tr>
47 <% end %>
48
49 <% if fwav then %>
50 <tr>
51 <th>Firewall: </th><td>
52 <%=fwon and translate("active") or translate("inactive")%>
53 </td>
54 </tr>
55 <% end %>
56
57 </table>
58 <br />