2 LuCI - Lua Configuration Interface
3 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
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
9 http://www.apache.org/licenses/LICENSE-2.0
16 local ntm = require "luci.model.network".init()
17 local fwm = require "luci.model.firewall".init()
21 for _, net in ipairs(ntm:get_networks()) do
22 if net:name() ~= "loopback" then
23 netlist[#netlist+1] = net:name()
28 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
29 <script type="text/javascript">//<![CDATA[
30 function iface_shutdown(id, reconnect) {
31 if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this router if you are connected via this interface.%>', id)))
34 var d = document.getElementById(id + '-ifc-description');
36 d.innerHTML = reconnect
37 ? '<em><%:Interface is reconnecting...%></em>'
38 : '<em><%:Interface is shutting down...%></em>';
40 var s = document.getElementById('ifc-rc-status');
43 s.parentNode.style.display = 'block';
44 s.innerHTML = '<%:Waiting for router...%>';
47 var rcxhr = new XHR();
48 rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
53 s.innerHTML = reconnect
54 ? '<%:Interface reconnected%>'
55 : '<%:Interface shut down%>';
57 window.setTimeout(function() {
58 s.parentNode.style.display = 'none';
66 var iwxhr = new XHR();
67 var wifidevs = <%=luci.http.write_json(netdevs)%>;
68 var arptable = <%=luci.http.write_json(arpcache)%>;
71 var func = arguments.callee;
72 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(netlist, ","))%>', null,
77 for (var idx = 0; idx < ifcs.length; idx++)
82 var s = document.getElementById(ifc.id + '-ifc-devices');
85 var stat = String.format(
86 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
88 ifc.is_up ? '' : '_disabled'
91 if (ifc.subdevices && ifc.subdevices.length)
95 for (var j = 0; j < ifc.subdevices.length; j++)
97 var sif = ifc.subdevices[j];
99 stat += String.format(
100 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%q" />',
102 sif.is_up ? '' : '_disabled',
107 stat += ')</strong>';
110 stat += String.format(
111 '<br /><small>%s</small>',
118 var d = document.getElementById(ifc.id + '-ifc-description');
123 html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
126 if (ifc.type != 'tunnel')
128 html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr);
131 html += String.format(
132 '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
133 '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
134 ifc.rx_bytes, ifc.rx_packets,
135 ifc.tx_bytes, ifc.tx_packets
138 if (ifc.ipaddrs && ifc.ipaddrs.length)
140 html += '<strong><%:IPv4%>: </strong>';
142 for (var i = 0; i < ifc.ipaddrs.length; i++)
143 html += String.format(
147 ifc.ipaddrs[i].prefix
153 if (ifc.ip6addrs && ifc.ip6addrs.length)
155 html += '<strong><%:IPv6%>: </strong>';
157 for (var i = 0; i < ifc.ip6addrs.length; i++)
158 html += String.format(
161 ifc.ip6addrs[i].addr.toUpperCase(),
162 ifc.ip6addrs[i].prefix
172 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
177 window.setTimeout(func, 5000);
183 <fieldset class="cbi-section" style="display:none">
184 <legend><%:Reconnecting interface%></legend>
185 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
186 <span id="ifc-rc-status"><%:Waiting for router...%></span>
189 <div class="cbi-map">
190 <fieldset class="cbi-section">
191 <legend><%:Interface Overview%></legend>
193 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
194 <tr class="cbi-section-table-titles">
195 <th class="cbi-section-table-cell"><%:Network%></th>
196 <th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
197 <th class="cbi-section-table-cell"><%:Actions%></th>
200 for i, net in ipairs(netlist) do
201 local z = fwm:get_zone_by_network(net)
202 local c = z and z:get_color() or "#EEEEEE"
203 local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
205 <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
206 <td class="cbi-value-field" style="padding:3px">
207 <div style="background-color:#FFFFFF; border:1px solid #CCCCCC; margin:0 10px">
208 <div style="border-bottom:1px solid #CCCCCC; padding:2px; background-color:<%=c%>" title="<%=pcdata(t)%>">
209 <strong><%=net:upper()%></strong>
211 <div style="padding:2px" id="<%=net%>-ifc-devices">
212 <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
217 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net%>-ifc-description">
218 <em><%:Collecting data...%></em>
220 <td style="width:340px">
221 <input type="button" class="cbi-button cbi-button-add" style="width:80px; background-image:url(<%=resource%>/cbi/reload.gif)" onclick="iface_shutdown('<%=net%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
222 <input type="button" class="cbi-button cbi-button-add" style="width:80px; background-image:url(<%=resource%>/cbi/reset.gif)" onclick="iface_shutdown('<%=net%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
223 <input type="button" class="cbi-button cbi-button-add" style="width:80px; background-image:url(<%=resource%>/cbi/edit.gif)" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/network", net)%>'" title="<%:Edit this interface%>" value="<%:Edit%>" />
224 <input type="button" class="cbi-button cbi-button-add" style="width:80px; background-image:url(<%=resource%>/cbi/remove.gif)" 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%>" />
230 <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/iface_add")%>'" />