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