1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
<%#
LuCI - Lua Configuration Interface
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
-%>
<%-
local ntm = require "luci.model.network".init()
local fwm = require "luci.model.firewall".init()
local net
local netlist = { }
for _, net in ipairs(ntm:get_networks()) do
if net:name() ~= "loopback" then
netlist[#netlist+1] = net:name()
end
end
-%>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<script type="text/javascript">//<![CDATA[
function iface_shutdown(id, reconnect) {
if (!reconnect && !confirm(String.format('<%_Really shutdown interface "%s" ?\nYou might lose access to this router if you are connected via this interface.%>', id)))
return;
var d = document.getElementById(id + '-ifc-description');
if (d)
d.innerHTML = reconnect
? '<em><%:Interface is reconnecting...%></em>'
: '<em><%:Interface is shutting down...%></em>';
var s = document.getElementById('ifc-rc-status');
if (s)
{
s.parentNode.style.display = 'block';
s.innerHTML = '<%:Waiting for router...%>';
}
XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
function(x)
{
if (s)
{
s.innerHTML = reconnect
? '<%:Interface reconnected%>'
: '<%:Interface shut down%>';
window.setTimeout(function() {
s.parentNode.style.display = 'none';
}, 1000);
}
}
);
}
var iwxhr = new XHR();
var wifidevs = <%=luci.http.write_json(netdevs)%>;
var arptable = <%=luci.http.write_json(arpcache)%>;
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(netlist, ","))%>', null,
function(x, ifcs)
{
if (ifcs)
{
for (var idx = 0; idx < ifcs.length; idx++)
{
var ifc = ifcs[idx];
var html = '';
var s = document.getElementById(ifc.id + '-ifc-devices');
if (s)
{
var stat = String.format(
'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />',
ifc.type,
ifc.is_up ? '' : '_disabled'
);
if (ifc.subdevices && ifc.subdevices.length)
{
stat += ' <strong>(';
for (var j = 0; j < ifc.subdevices.length; j++)
{
var sif = ifc.subdevices[j];
stat += String.format(
'<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%h" />',
sif.type,
sif.is_up ? '' : '_disabled',
sif.name
);
}
stat += ')</strong>';
}
stat += String.format(
'<br /><small>%h</small>',
ifc.name
);
s.innerHTML = stat;
}
var d = document.getElementById(ifc.id + '-ifc-description');
if (d && ifc.proto && ifc.ifname)
{
if (ifc.is_up)
{
html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
}
if (ifc.type != 'tunnel')
{
html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr);
}
html += String.format(
'<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
'<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
ifc.rx_bytes, ifc.rx_packets,
ifc.tx_bytes, ifc.tx_packets
);
if (ifc.ipaddrs && ifc.ipaddrs.length)
{
html += '<strong><%:IPv4%>: </strong>';
for (var i = 0; i < ifc.ipaddrs.length; i++)
html += String.format(
'%s%s/%d',
i ? ', ' : '',
ifc.ipaddrs[i].addr,
ifc.ipaddrs[i].prefix
);
html += '<br />';
}
if (ifc.ip6addrs && ifc.ip6addrs.length)
{
html += '<strong><%:IPv6%>: </strong>';
for (var i = 0; i < ifc.ip6addrs.length; i++)
html += String.format(
'%s%s/%d',
i ? ', ' : '',
ifc.ip6addrs[i].addr.toUpperCase(),
ifc.ip6addrs[i].prefix
);
html += '<br />';
}
d.innerHTML = html;
}
else if (d && !ifc.proto)
{
var e = document.getElementById(ifc.id + '-ifc-edit');
if (e)
e.disabled = true;
d.innerHTML = String.format(
'<em><%:Unsupported protocol type.%></em><br />' +
'<a href="%h"><%:Install protocol extensions...%></a>',
'<%=luci.dispatcher.build_url("admin/system/packages")%>?query=luci-proto&display=available'
);
}
else if (d)
{
d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
}
}
}
}
);
//]]></script>
<fieldset class="cbi-section" style="display:none">
<legend><%:Reconnecting interface%></legend>
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
<span id="ifc-rc-status"><%:Waiting for router...%></span>
</fieldset>
<div class="cbi-map">
<fieldset class="cbi-section">
<legend><%:Interface Overview%></legend>
<table class="cbi-section-table" style="margin:10px; empty-cells:hide">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"><%:Network%></th>
<th class="cbi-section-table-cell" style="text-align:left"><%:Status%></th>
<th class="cbi-section-table-cell"><%:Actions%></th>
</tr>
<%
for i, net in ipairs(netlist) do
local z = fwm:get_zone_by_network(net)
local c = z and z:get_color() or "#EEEEEE"
local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned")
%>
<tr class="cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>">
<td class="cbi-value-field" style="padding:3px">
<div style="background-color:#FFFFFF; border:1px solid #CCCCCC; margin:0 10px">
<div style="border-bottom:1px solid #CCCCCC; padding:2px; background-color:<%=c%>" title="<%=pcdata(t)%>">
<strong><%=net:upper()%></strong>
</div>
<div style="padding:2px" id="<%=net%>-ifc-devices">
<img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
<small>?</small>
</div>
</div>
</td>
<td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net%>-ifc-description">
<em><%:Collecting data...%></em>
</td>
<td style="width:420px">
<input type="button" class="cbi-button cbi-button-add" style="width:100px; background-image:url(<%=resource%>/cbi/reload.gif)" onclick="iface_shutdown('<%=net%>', true)" title="<%:Reconnect this interface%>" value="<%:Connect%>" />
<input type="button" class="cbi-button cbi-button-add" style="width:100px; background-image:url(<%=resource%>/cbi/reset.gif)" onclick="iface_shutdown('<%=net%>', false)" title="<%:Shutdown this interface%>" value="<%:Stop%>" />
<input type="button" class="cbi-button cbi-button-add" style="width:100px; background-image:url(<%=resource%>/cbi/edit.gif)" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/network", net)%>'" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net%>-ifc-edit" />
<input type="button" class="cbi-button cbi-button-add" style="width:100px; 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%>" />
</td>
</tr>
<% end %>
</table>
<input type="button" class="cbi-button cbi-button-add" value="<%:Add new interface...%>" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/iface_add")%>'" />
</fieldset>
</div>
|