e49c93065737768934424414220befb2dae827e6
[project/luci.git] / modules / niu / luasrc / view / niu / network.htm
1 <%
2 local uci = require "luci.model.uci"
3 local fs = require "nixio.fs"
4
5 local nws = {}
6 uci.inst_state:foreach("network", "interface", function(s)
7         nws[#nws+1] = s
8 end)
9
10 if uci.inst_state:get("network", "lan", "_ipchanged") and
11 uci.inst_state:revert("network", "lan", "_ipchanged") then
12         include("niu/network/warn_ip_change")
13 end
14
15 local wanon = uci.inst_state:get("network", "wan", "proto")
16 local wanup = uci.inst_state:get("network", "wan", "up")
17 local wanip = uci.inst_state:get("network", "wan", "ipaddr")
18 local wanif = uci.inst_state:get("network", "wan", "ifname")
19 local wanul, wandl
20
21 if wanif then
22         local devstats = fs.readfile("/proc/net/dev")
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 local leasefn
31 uci.inst:foreach("dhcp", "dnsmasq",
32  function(section)
33         leasefn = section.leasefile
34  end
35 )
36
37 if leasefn then
38         local ln = fs.access(leasefn, "r") and io.lines(leasefn)
39         leasefn = 0
40         while ln and ln() do
41                 leasefn = leasefn + 1
42         end
43 end
44
45 local arps
46 if fs.access("/proc/net/arp", "r") then
47         local ln = io.lines("/proc/net/arp")
48         arps = -1
49         while ln and ln() do
50                 arps = arps + 1
51         end
52         arps = arps >= 0 and arps
53 end
54 %>
55
56 <table class="dbstattbl">
57 <% if wanon and wanon ~= "none" then %>
58 <tr>
59 <% if wanup then %>
60 <th>Uplink Address</th>
61 <td><%=wanip%></td>
62 <% else %>
63 <th>Uplink</th>
64 <td><span style="color: darkred"><em>offline</em></span>
65 </td>
66 <% end %>
67
68 </tr>
69 <% end %>
70
71 <% if wanul and wandl then %>
72 <tr>
73 <th>Uplink Traffic</th><td>
74 <%=("%.2f"):format(wandl)%> GB&#8659; <%=("%.2f"):format(wanul)%> GB&#8657;
75 </td>
76 </tr>
77 <% end %> 
78
79 <tr>
80 <th>Local Address</th><td>
81 <%=uci.inst_state:get("network", "lan", "ipaddr")%>
82 </td>
83 </tr>
84
85 <% if arps then %>
86 <tr>
87 <th>Active IP-Devices</th><td><%=arps%><% if leasefn then %>
88 (<%=leasefn%> assigned)
89 <% end %></td>
90 </tr>
91 <% end %>
92
93 </table>
94 <br />