modules/admin-full: Fix typo, #304
[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 $Id$
12
13 -%>
14
15 <%-
16 local ntm = require "luci.model.network".init()
17
18 local net
19 local netlist = { }
20 for _, net in ipairs(ntm:get_networks()) do
21 if net:name() ~= "loopback" then
22 netlist[#netlist+1] = net:name()
23 end
24 end
25 -%>
26
27 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
28 <script type="text/javascript">//<![CDATA[
29 function iface_shutdown(id, reconnect) {
30 if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this router if you are connected via this interface.%>', id)))
31 return;
32
33 var a = document.getElementById(id + '-ifc-addrs');
34 if (a)
35 a.innerHTML = reconnect
36 ? '<em><%:Interface is reconnecting...%></em>'
37 : '<em><%:Interface is shutting down...%></em>';
38
39 var s = document.getElementById('ifc-rc-status');
40 if (s)
41 {
42 s.parentNode.style.display = 'block';
43 s.innerHTML = '<%:Waiting for router...%>';
44 }
45
46 var rcxhr = new XHR();
47 rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
48 function(x)
49 {
50 if (s)
51 {
52 s.innerHTML = reconnect
53 ? '<%:Interface reconnected%>'
54 : '<%:Interface shut down%>';
55
56 window.setTimeout(function() {
57 s.parentNode.style.display = 'none';
58 }, 1000);
59 }
60 }
61 );
62 }
63
64
65 var iwxhr = new XHR();
66 var wifidevs = <%=luci.http.write_json(netdevs)%>;
67 var arptable = <%=luci.http.write_json(arpcache)%>;
68
69 var update_status = function() {
70 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(netlist, ","))%>', null,
71 function(x, ifcs)
72 {
73 if (ifcs)
74 {
75 for (var i = 0; i < ifcs.length; i++)
76 {
77 var ifc = ifcs[i];
78 var is_up = (ifc.flags && ifc.flags.up);
79 var rxb = ifc.stats ? ifc.stats["rx_bytes"] : 0;
80 var txb = ifc.stats ? ifc.stats["tx_bytes"] : 0;
81 var rxp = ifc.stats ? ifc.stats["rx_packets"] : 0;
82 var txp = ifc.stats ? ifc.stats["tx_packets"] : 0;
83 var mac = ifc.macaddr ? ifc.macaddr : '00:00:00:00:00:00';
84 var upt = '-';
85
86 var icon;
87 if (is_up)
88 {
89 if (ifc.uptime)
90 upt = String.format('%t', ifc.uptime);
91
92 icon = "<%=resource%>/icons/ethernet.png";
93 }
94 else
95 {
96 icon = "<%=resource%>/icons/ethernet_disabled.png";
97 }
98
99 var s = document.getElementById(ifc.id + '-ifc-signal');
100 if (s)
101 {
102 s.innerHTML = String.format(
103 '<img src="%s" style="width:16px; height:16px" /><br />' +
104 '<small>%s</small>',
105 icon, ifc.ifname ? ifc.ifname : '?'
106 );
107 }
108
109 var u = document.getElementById(ifc.id + '-ifc-uptime');
110 if (u)
111 {
112 u.innerHTML = upt;
113 }
114
115 var m = document.getElementById(ifc.id + '-ifc-mac');
116 if (m)
117 {
118 m.innerHTML = mac.toUpperCase();
119 }
120
121 var a = document.getElementById(ifc.id + '-ifc-addrs');
122 if (a)
123 {
124 if (ifc.ifname)
125 {
126 a.innerHTML = '';
127
128 if (ifc.ipaddrs && ifc.ipaddrs.length)
129 {
130 a.innerHTML += '<strong><%:IPv4%>: </strong>';
131
132 for (var j = 0; j < ifc.ipaddrs.length; j++)
133 a.innerHTML += String.format(
134 '%s%s/%d',
135 j ? ', ' : '',
136 ifc.ipaddrs[j].addr,
137 ifc.ipaddrs[j].prefix
138 );
139
140 a.innerHTML += '<br />';
141 }
142
143 if (ifc.ip6addrs && ifc.ip6addrs.length)
144 {
145 a.innerHTML += '<strong><%:IPv6%>: </strong>';
146
147 for (var j = 0; j < ifc.ip6addrs.length; j++)
148 a.innerHTML += String.format(
149 '%s%s/%d',
150 j ? ', ' : '',
151 ifc.ip6addrs[j].addr.toUpperCase(),
152 ifc.ip6addrs[j].prefix
153 );
154
155 a.innerHTML += '<br />';
156 }
157
158 if (!a.innerHTML)
159 a.innerHTML = '<em><%:No address configured on this interface.%></em>'
160 }
161 else
162 {
163 a.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
164 }
165 }
166
167 var t = document.getElementById(ifc.id + '-ifc-transfer');
168 if (t)
169 {
170 t.innerHTML = String.format(
171 '<strong><%:RX%></strong>: %1024.2mB (%d <%:Pkts.%>)<br />' +
172 '<strong><%:TX%></strong>: %1024.2mB (%d <%:Pkts.%>)<br />',
173 rxb, rxp, txb, txp
174 );
175 }
176 }
177 }
178
179 window.setTimeout(update_status, 5000);
180 }
181 )
182 };
183
184 update_status();
185 //]]></script>
186
187 <fieldset class="cbi-section" style="display:none">
188 <legend><%:Reconnecting interface%></legend>
189 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
190 <span id="ifc-rc-status"><%:Waiting for router...%></span>
191 </fieldset>
192
193 <div class="cbi-map">
194 <fieldset class="cbi-section">
195 <legend><%:Interface Overview%></legend>
196
197 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
198 <tr class="cbi-section-table-titles">
199 <th class="cbi-section-table-cell">&#160;</th>
200 <th class="cbi-section-table-cell"><%:Interface%></th>
201 <th class="cbi-section-table-cell"><%:Uptime%></th>
202 <th class="cbi-section-table-cell"><%:MAC%></th>
203 <th class="cbi-section-table-cell" style="text-align:left"><%:Addresses%></th>
204 <th class="cbi-section-table-cell" style="text-align:left"><%:Transfer%></th>
205 <th class="cbi-section-table-cell" colspan="2"><%:Actions%></th>
206 </tr>
207 <% for i, net in ipairs(netlist) do %>
208 <tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
209 <td>
210 <span style="background-color:#FFFFFF; border:1px solid #CCCCCC; padding:2px"><%=net%></span>
211 </td>
212 <td class="cbi-value-field" style="min-width:16px; padding:3px; text-align:center" id="<%=net%>-ifc-signal">
213 <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
214 <small>?</small>
215 </td>
216 <td class="cbi-value-field" id="<%=net%>-ifc-uptime">?</td>
217 <td class="cbi-value-field" id="<%=net%>-ifc-mac">?</td>
218 <td class="cbi-value-field" style="text-align:left; padding:3px" id="<%=net%>-ifc-addrs"><em><%:Collecting data...%></em></td>
219 <td class="cbi-value-field" style="text-align:left; padding:3px" id="<%=net%>-ifc-transfer">
220 <strong><%:RX%></strong>: 0 <%:KB%> (0 <%:Pkts.%>)<br />
221 <strong><%:TX%></strong>: 0 <%:KB%> (0 <%:Pkts.%>)<br />
222 </td>
223 <td>
224 <a href="#" onclick="iface_shutdown('<%=net%>', true)"><img style="border:none" src="<%=resource%>/cbi/reload.gif" alt="<%:Reconnect this interface%>" title="<%:Reconnect this interface%>" /></a>
225 <a href="#" onclick="iface_shutdown('<%=net%>', false)"><img style="border:none" src="<%=resource%>/cbi/reset.gif" alt="<%:Shutdown this interface%>" title="<%:Shutdown this interface%>" /></a>
226 </td>
227 <td>
228 <a href="<%=luci.dispatcher.build_url("admin/network/network", net)%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit this interface%>" title="<%:Edit this interface%>" /></a>
229 <a href="<%=luci.dispatcher.build_url("admin/network/iface_delete", net)%>" onclick="return confirm('<%:Really delete this interface? The deletion cannot be undone!\nYou might lose access to this router if you are connected via this interface.%>')"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="<%:Delete this interface%>" title="<%:Delete this interface%>" /></a>
230 </td>
231 </tr>
232 <% end %>
233 </table>
234
235 <input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/iface_add")%>'" />
236 </fieldset>
237 </div>