1312b4c16d4616cb14ccbbaf7bc49c8894cbda4c
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / iface_overview.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 -%>
12
13 <%-
14 local ntm = require "luci.model.network".init()
15 local fwm = require "luci.model.firewall".init()
16
17 local net
18 local ifaces = { }
19 local netlist = { }
20 for _, net in ipairs(ntm:get_networks()) do
21 if net:name() ~= "loopback" then
22 local z = fwm:get_zone_by_network(net:name())
23 ifaces[#ifaces+1] = net:name()
24 netlist[#netlist+1] = {
25 net:name(), z and z:name() or "-", z
26 }
27 end
28 end
29
30 table.sort(netlist,
31 function(a, b)
32 if a[2] ~= b[2] then
33 return a[2] < b[2]
34 else
35 return a[1] < b[1]
36 end
37 end)
38 -%>
39
40 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
41 <script type="text/javascript">//<![CDATA[
42 function iface_shutdown(id, reconnect) {
43 if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
44 return;
45
46 var d = document.getElementById(id + '-ifc-description');
47 if (d)
48 d.innerHTML = reconnect
49 ? '<em><%:Interface is reconnecting...%></em>'
50 : '<em><%:Interface is shutting down...%></em>';
51
52 var s = document.getElementById('ifc-rc-status');
53 if (s)
54 {
55 s.parentNode.style.display = 'block';
56 s.innerHTML = '<%:Waiting for changes to be applied...%>';
57 }
58
59 XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
60 function(x)
61 {
62 if (s)
63 {
64 s.innerHTML = reconnect
65 ? '<%:Interface reconnected%>'
66 : '<%:Interface shut down%>';
67
68 window.setTimeout(function() {
69 s.parentNode.style.display = 'none';
70 }, 1000);
71 }
72 }
73 );
74 }
75
76
77 var iwxhr = new XHR();
78 var wifidevs = <%=luci.http.write_json(netdevs)%>;
79 var arptable = <%=luci.http.write_json(arpcache)%>;
80
81 XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(ifaces, ","))%>', null,
82 function(x, ifcs)
83 {
84 if (ifcs)
85 {
86 for (var idx = 0; idx < ifcs.length; idx++)
87 {
88 var ifc = ifcs[idx];
89 var html = '';
90
91 var s = document.getElementById(ifc.id + '-ifc-devices');
92 if (s)
93 {
94 var stat = String.format(
95 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
96 ifc.type,
97 ifc.is_up ? '' : '_disabled'
98 );
99
100 if (ifc.subdevices && ifc.subdevices.length)
101 {
102 stat += ' <strong>(';
103
104 for (var j = 0; j < ifc.subdevices.length; j++)
105 {
106 var sif = ifc.subdevices[j];
107
108 stat += String.format(
109 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
110 sif.type,
111 sif.is_up ? '' : '_disabled',
112 sif.name
113 );
114 }
115
116 stat += ')</strong>';
117 }
118
119 stat += String.format(
120 '<br /><small>%h</small>',
121 ifc.name
122 );
123
124 s.innerHTML = stat;
125 }
126
127 var d = document.getElementById(ifc.id + '-ifc-description');
128 if (d && ifc.proto && ifc.ifname)
129 {
130 if (ifc.is_up)
131 {
132 html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
133 }
134
135 if (ifc.type != 'tunnel')
136 {
137 html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
138 }
139
140 html += String.format(
141 '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
142 '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
143 ifc.rx_bytes, ifc.rx_packets,
144 ifc.tx_bytes, ifc.tx_packets
145 );
146
147 if (ifc.ipaddrs && ifc.ipaddrs.length)
148 {
149 html += '<strong><%:IPv4%>: </strong>';
150
151 for (var i = 0; i < ifc.ipaddrs.length; i++)
152 html += String.format(
153 '%s%s/%d',
154 i ? ', ' : '',
155 ifc.ipaddrs[i].addr,
156 ifc.ipaddrs[i].prefix
157 );
158
159 html += '<br />';
160 }
161
162 if (ifc.ip6addrs && ifc.ip6addrs.length)
163 {
164 html += '<strong><%:IPv6%>: </strong>';
165
166 for (var i = 0; i < ifc.ip6addrs.length; i++)
167 html += String.format(
168 '%s%s/%d',
169 i ? ', ' : '',
170 ifc.ip6addrs[i].addr.toUpperCase(),
171 ifc.ip6addrs[i].prefix
172 );
173
174 html += '<br />';
175 }
176
177 d.innerHTML = html;
178 }
179 else if (d && !ifc.ifname)
180 {
181 d.innerHTML = String.format(
182 '<em><%:Network without interfaces.%></em><br />' +
183 '<a href="<%=luci.dispatcher.build_url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
184 ifc.name, ifc.name
185 );
186 }
187 else if (d && !ifc.proto)
188 {
189 var e = document.getElementById(ifc.id + '-ifc-edit');
190 if (e)
191 e.disabled = true;
192
193 d.innerHTML = String.format(
194 '<em><%:Unsupported protocol type.%></em><br />' +
195 '<a href="%h"><%:Install protocol extensions...%></a>',
196 '<%=luci.dispatcher.build_url("admin/system/packages")%>?query=luci-proto&display=available'
197 );
198 }
199 else if (d)
200 {
201 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
202 }
203 }
204 }
205 }
206 );
207 //]]></script>
208
209 <fieldset class="cbi-section" style="display:none">
210 <legend><%:Reconnecting interface%></legend>
211 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
212 <span id="ifc-rc-status"><%:Waiting for changes to be applied...%></span>
213 </fieldset>
214
215 <div class="cbi-map">
216 <fieldset class="cbi-section">
217 <legend><%:Interface Overview%></legend>
218
219 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
220 <tr class="cbi-section-table-titles">
221 <th class="cbi-section-table-cell"><%:Network%></th>
222 <th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
223 <th class="cbi-section-table-cell"><%:Actions%></th>
224 </tr>
225 <%
226 for i, net in ipairs(netlist) do
227 local z = net[3]
228 local c = z and z:get_color() or "#EEEEEE"
229 local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
230 %>
231 <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
232 <td class="cbi-value-field" style="padding:3px">
233 <div class="ifacebox">
234 <div class="ifacebox-head" style="background-color:<%=c%>" title="<%=pcdata(t)%>">
235 <strong><%=net[1]:upper()%></strong>
236 </div>
237 <div class="ifacebox-body" id="<%=net[1]%>-ifc-devices">
238 <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
239 <small>?</small>
240 </div>
241 </div>
242 </td>
243 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net[1]%>-ifc-description">
244 <em><%:Collecting data...%></em>
245 </td>
246 <td style="width:420px">
247 <input type="button" class="cbi-button cbi-button-reload" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
248 <input type="button" class="cbi-button cbi-button-reset" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
249 <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/network", net[1])%>'" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit" />
250 <input type="button" class="cbi-button cbi-button-remove" style="width:100px" onclick="if (confirm('<%:Really delete this interface? The deletion cannot be undone!\nYou might lose access to this device if you are connected via this interface.%>')) location.href='<%=luci.dispatcher.build_url("admin/network/iface_delete", net[1])%>'" title="<%:Delete this interface%>" value="<%:Delete%>" />
251 </td>
252 </tr>
253 <% end %>
254 </table>
255
256 <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/iface_add")%>'" />
257 </fieldset>
258 </div>