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
14 local ntm = require
"luci.model.network".init()
15 local fwm = require
"luci.model.firewall".init()
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
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)))
46 var d = document.getElementById(id + '-ifc-description');
48 d.innerHTML = reconnect
49 ? '
<em><%:Interface is reconnecting...%
></em>'
50 : '
<em><%:Interface is shutting down...%
></em>';
52 var s = document.getElementById('ifc-rc-status');
55 s.parentNode.style.display = 'block';
56 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
59 XHR.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
64 s.innerHTML = reconnect
65 ? '<%:Interface reconnected%
>'
66 : '<%:Interface shut down%
>';
68 window.setTimeout(function() {
69 s.parentNode.style.display = 'none';
77 var iwxhr = new XHR();
78 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
79 var arptable = <%=luci.http.write_json(arpcache)%
>;
81 XHR.poll(
5, '<%=luci.dispatcher.build_url(
"admin",
"network",
"iface_status", table.concat(ifaces,
","))%
>', null,
86 for (var idx =
0; idx < ifcs.length; idx++)
91 var s = document.getElementById(ifc.id + '-ifc-devices');
94 var stat = String.format(
95 '
<img src=
"<%=resource%>/icons/%s%s.png" style=
"width:16px; height:16px; vertical-align:middle" />',
97 ifc.is_up ? '' : '_disabled'
100 if (ifc.subdevices && ifc.subdevices.length)
102 stat += '
<strong>(';
104 for (var j =
0; j < ifc.subdevices.length; j++)
106 var sif = ifc.subdevices[j];
108 stat += String.format(
109 '
<img src=
"<%=resource%>/icons/%s%s.png" style=
"width:16px; height:16px; vertical-align:middle" title=
"%h" />',
111 sif.is_up ? '' : '_disabled',
116 stat += ')
</strong>';
119 stat += String.format(
120 '
<br /><small>%h
</small>',
127 var d = document.getElementById(ifc.id + '-ifc-description');
128 if (d && ifc.proto && ifc.ifname)
132 html += String.format('
<strong><%:Uptime%
>:
</strong> %t
<br />', ifc.uptime);
135 if (ifc.type != 'tunnel')
137 html += String.format('
<strong><%:MAC-Address%
>:
</strong> %s
<br />', ifc.macaddr);
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
147 if (ifc.ipaddrs && ifc.ipaddrs.length)
149 html += '
<strong><%:IPv4%
>:
</strong>';
151 for (var i =
0; i < ifc.ipaddrs.length; i++)
152 html += String.format(
156 ifc.ipaddrs[i].prefix
162 if (ifc.ip6addrs && ifc.ip6addrs.length)
164 html += '
<strong><%:IPv6%
>:
</strong>';
166 for (var i =
0; i < ifc.ip6addrs.length; i++)
167 html += String.format(
170 ifc.ip6addrs[i].addr.toUpperCase(),
171 ifc.ip6addrs[i].prefix
179 else if (d && !ifc.proto)
181 var e = document.getElementById(ifc.id + '-ifc-edit');
185 d.innerHTML = String.format(
186 '
<em><%:Unsupported protocol type.%
></em><br />' +
187 '
<a href=
"%h"><%:Install protocol extensions...%
></a>',
188 '<%=luci.dispatcher.build_url(
"admin/system/packages")%
>?query=luci-proto&display=available'
191 else if (d && !ifc.ifname)
193 d.innerHTML = String.format(
194 '
<em><%:Network without interfaces.%
></em><br />' +
195 '
<a href=
"<%=luci.dispatcher.build_url("admin/network/network/%s
")%>?tab.network.%s=physical"><%:Assign interfaces...%
></a>',
201 d.innerHTML = '
<em><%:Interface not present or not connected yet.%
></em>';
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>
215 <div class=
"cbi-map">
216 <fieldset class=
"cbi-section">
217 <legend><%:Interface Overview%
></legend>
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>
226 for i, net in ipairs(netlist) do
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")
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>
237 <div class=
"ifacebox-body" id=
"<%=net[1]%>-ifc-devices">
238 <img src=
"<%=resource%>/icons/ethernet_disabled.png" style=
"width:16px; height:16px" /><br />
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>
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%>" />
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
")%>'" />