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()
19 for _, net in ipairs(ntm:get_networks()) do
20 if net:name() ~=
"loopback" then
21 netlist[#netlist+
1] = net:name()
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)))
32 var d = document.getElementById(id + '-ifc-description');
34 d.innerHTML = reconnect
35 ? '
<em><%:Interface is reconnecting...%
></em>'
36 : '
<em><%:Interface is shutting down...%
></em>';
38 var s = document.getElementById('ifc-rc-status');
41 s.parentNode.style.display = 'block';
42 s.innerHTML = '<%:Waiting for router...%
>';
45 XHR.get('<%=luci.dispatcher.build_url(
"admin",
"network")%
>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
50 s.innerHTML = reconnect
51 ? '<%:Interface reconnected%
>'
52 : '<%:Interface shut down%
>';
54 window.setTimeout(function() {
55 s.parentNode.style.display = 'none';
63 var iwxhr = new XHR();
64 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
65 var arptable = <%=luci.http.write_json(arpcache)%
>;
67 XHR.poll(
5, '<%=luci.dispatcher.build_url(
"admin",
"network",
"iface_status", table.concat(netlist,
","))%
>', null,
72 for (var idx =
0; idx < ifcs.length; idx++)
77 var s = document.getElementById(ifc.id + '-ifc-devices');
80 var stat = String.format(
81 '
<img src=
"<%=resource%>/icons/%s%s.png" style=
"width:16px; height:16px; vertical-align:middle" />',
83 ifc.is_up ? '' : '_disabled'
86 if (ifc.subdevices && ifc.subdevices.length)
90 for (var j =
0; j < ifc.subdevices.length; j++)
92 var sif = ifc.subdevices[j];
94 stat += String.format(
95 '
<img src=
"<%=resource%>/icons/%s%s.png" style=
"width:16px; height:16px; vertical-align:middle" title=
"%h" />',
97 sif.is_up ? '' : '_disabled',
102 stat += ')
</strong>';
105 stat += String.format(
106 '
<br /><small>%h
</small>',
113 var d = document.getElementById(ifc.id + '-ifc-description');
114 if (d && ifc.proto && ifc.ifname)
118 html += String.format('
<strong><%:Uptime%
>:
</strong> %t
<br />', ifc.uptime);
121 if (ifc.type != 'tunnel')
123 html += String.format('
<strong><%:MAC Address%
>:
</strong> %s
<br />', ifc.macaddr);
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
133 if (ifc.ipaddrs && ifc.ipaddrs.length)
135 html += '
<strong><%:IPv4%
>:
</strong>';
137 for (var i =
0; i < ifc.ipaddrs.length; i++)
138 html += String.format(
142 ifc.ipaddrs[i].prefix
148 if (ifc.ip6addrs && ifc.ip6addrs.length)
150 html += '
<strong><%:IPv6%
>:
</strong>';
152 for (var i =
0; i < ifc.ip6addrs.length; i++)
153 html += String.format(
156 ifc.ip6addrs[i].addr.toUpperCase(),
157 ifc.ip6addrs[i].prefix
165 else if (d && !ifc.ifname)
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>',
173 else if (d && !ifc.proto)
175 var e = document.getElementById(ifc.id + '-ifc-edit');
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'
187 d.innerHTML = '
<em><%:Interface not present or not connected yet.%
></em>';
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>
201 <div class=
"cbi-map">
202 <fieldset class=
"cbi-section">
203 <legend><%:Interface Overview%
></legend>
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>
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")
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>
223 <div class=
"ifacebox-body" id=
"<%=net%>-ifc-devices">
224 <img src=
"<%=resource%>/icons/ethernet_disabled.png" style=
"width:16px; height:16px" /><br />
229 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net%>-ifc-description">
230 <em><%:Collecting data...%
></em>
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%>" />
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
")%>'" />