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