2 Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
3 Licensed to the public under the Apache License 2.0.
7 local ntm = require "luci.model.network".init()
8 local fwm = require "luci.model.firewall".init()
13 for _, net in ipairs(ntm:get_networks()) do
14 if net:name() ~= "loopback" then
15 local z = fwm:get_zone_by_network(net:name())
16 ifaces[#ifaces+1] = net:name()
17 netlist[#netlist+1] = {
18 net:name(), z and z:name() or "-", z
33 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
34 <script type="text/javascript">//<![CDATA[
35 function iface_shutdown(id, reconnect) {
36 if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
39 var d = document.getElementById(id + '-ifc-description');
41 d.innerHTML = reconnect
42 ? '<em><%:Interface is reconnecting...%></em>'
43 : '<em><%:Interface is shutting down...%></em>';
45 var s = document.getElementById('ifc-rc-status');
48 s.parentNode.style.display = 'block';
49 s.innerHTML = '<%:Waiting for changes to be applied...%>';
52 XHR.get('<%=url('admin/network')%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
57 s.innerHTML = reconnect
58 ? '<%:Interface reconnected%>'
59 : '<%:Interface shut down%>';
61 window.setTimeout(function() {
62 s.parentNode.style.display = 'none';
70 var iwxhr = new XHR();
71 var wifidevs = <%=luci.http.write_json(netdevs)%>;
72 var arptable = <%=luci.http.write_json(arpcache)%>;
74 XHR.poll(5, '<%=url('admin/network/iface_status', table.concat(ifaces, ","))%>', null,
79 for (var idx = 0; idx < ifcs.length; idx++)
84 var s = document.getElementById(ifc.id + '-ifc-devices');
87 var stat = String.format(
88 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
90 ifc.is_up ? '' : '_disabled'
93 if (ifc.subdevices && ifc.subdevices.length)
97 for (var j = 0; j < ifc.subdevices.length; j++)
99 var sif = ifc.subdevices[j];
101 stat += String.format(
102 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
104 sif.is_up ? '' : '_disabled',
109 stat += ')</strong>';
112 stat += String.format(
113 '<br /><small>%h</small>',
120 var d = document.getElementById(ifc.id + '-ifc-description');
121 if (d && ifc.proto && ifc.ifname)
125 html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
128 if (ifc.type != 'tunnel')
130 html += String.format('<strong><%:MAC-Address%>:</strong> %s<br />', ifc.macaddr);
133 html += String.format(
134 '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
135 '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
136 ifc.rx_bytes, ifc.rx_packets,
137 ifc.tx_bytes, ifc.tx_packets
140 if (ifc.ipaddrs && ifc.ipaddrs.length)
142 html += '<strong><%:IPv4%>: </strong>';
144 for (var i = 0; i < ifc.ipaddrs.length; i++)
145 html += String.format(
149 ifc.ipaddrs[i].prefix
155 if (ifc.ip6addrs && ifc.ip6addrs.length)
157 html += '<strong><%:IPv6%>: </strong>';
159 for (var i = 0; i < ifc.ip6addrs.length; i++)
160 html += String.format(
163 ifc.ip6addrs[i].addr.toUpperCase(),
164 ifc.ip6addrs[i].prefix
172 else if (d && !ifc.proto)
174 var e = document.getElementById(ifc.id + '-ifc-edit');
178 d.innerHTML = String.format(
179 '<em><%:Unsupported protocol type.%></em><br />' +
180 '<a href="%h"><%:Install protocol extensions...%></a>',
181 '<%=url("admin/system/packages")%>?query=luci-proto&display=available'
184 else if (d && !ifc.ifname)
186 d.innerHTML = String.format(
187 '<em><%:Network without interfaces.%></em><br />' +
188 '<a href="<%=url("admin/network/network/%s")%>?tab.network.%s=physical"><%:Assign interfaces...%></a>',
194 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
202 <fieldset class="cbi-section" style="display:none">
203 <legend><%:Reconnecting interface%></legend>
204 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
205 <span id="ifc-rc-status"><%:Waiting for changes to be applied...%></span>
208 <div class="cbi-map">
209 <fieldset class="cbi-section">
210 <legend><%:Interface Overview%></legend>
212 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
213 <tr class="cbi-section-table-titles">
214 <th class="cbi-section-table-cell"><%:Network%></th>
215 <th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
216 <th class="cbi-section-table-cell"><%:Actions%></th>
219 for i, net in ipairs(netlist) do
221 local c = z and z:get_color() or "#EEEEEE"
222 local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
224 <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
225 <td class="cbi-value-field" style="padding:3px">
226 <div class="ifacebox">
227 <div class="ifacebox-head" style="background-color:<%=c%>" title="<%=pcdata(t)%>">
228 <strong><%=net[1]:upper()%></strong>
230 <div class="ifacebox-body" id="<%=net[1]%>-ifc-devices">
231 <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
236 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net[1]%>-ifc-description">
237 <em><%:Collecting data...%></em>
239 <td style="width:420px">
240 <input type="button" class="cbi-button cbi-button-reload" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
241 <input type="button" class="cbi-button cbi-button-reset" style="width:100px" onclick="iface_shutdown('<%=net[1]%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
242 <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=url("admin/network/network", net[1])%>'" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit" />
243 <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='<%=url("admin/network/iface_delete", net[1])%>'" title="<%:Delete this interface%>" value="<%:Delete%>" />
249 <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=url("admin/network/iface_add")%>'" />