2010-11-15 22:08:42 +00:00
< %#
2015-01-16 22:46:42 +00:00
Copyright 2010 Jo-Philipp Wich < jow @ openwrt . org >
2015-01-16 22:38:38 +00:00
Licensed to the public under the Apache License 2.0.
2010-11-15 22:08:42 +00:00
-%>
< %-
local ntm = require "luci.model.network".init()
2011-09-24 01:03:06 +00:00
local fwm = require "luci.model.firewall".init()
2010-11-15 22:08:42 +00:00
local net
2012-06-27 10:12:20 +00:00
local ifaces = { }
2010-11-15 22:08:42 +00:00
local netlist = { }
for _, net in ipairs(ntm:get_networks()) do
if net:name() ~= "loopback" then
2012-06-27 10:12:20 +00:00
local z = fwm:get_zone_by_network(net:name())
ifaces[#ifaces+1] = net:name()
netlist[#netlist+1] = {
net:name(), z and z:name() or "-", z
}
2010-11-15 22:08:42 +00:00
end
end
2012-06-27 10:12:20 +00:00
table.sort(netlist,
function(a, b)
if a[2] ~= b[2] then
return a[2] < b [ 2 ]
else
return a[1] < b [ 1 ]
end
end)
2010-11-15 22:08:42 +00:00
-%>
< script type = "text/javascript" src = "<%=resource%>/cbi.js" > < / script >
2010-11-18 01:34:56 +00:00
< script type = "text/javascript" > / / < ! [ C D A T A [
2010-11-15 22:08:42 +00:00
function iface_shutdown(id, reconnect) {
2012-07-01 20:05:05 +00:00
if (!reconnect & & !confirm(String.format('< %_Really shutdown interface "%s" ?\nYou might lose access to this device if you are connected via this interface.%>', id)))
2010-11-15 22:08:42 +00:00
return;
2011-09-24 01:03:06 +00:00
var d = document.getElementById(id + '-ifc-description');
if (d)
d.innerHTML = reconnect
2010-11-15 22:08:42 +00:00
? '< 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';
2012-07-01 20:05:05 +00:00
s.innerHTML = '< %:Waiting for changes to be applied...%>';
2010-11-15 22:08:42 +00:00
}
2015-10-20 20:17:23 +00:00
(new XHR()).post('< %=url('admin/network')%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '< %=token%>' },
2010-11-15 22:08:42 +00:00
function(x)
{
if (s)
{
s.innerHTML = reconnect
? '< %:Interface reconnected%>'
: '< %:Interface shut down%>';
window.setTimeout(function() {
s.parentNode.style.display = 'none';
}, 1000);
}
}
);
}
2015-10-20 20:17:23 +00:00
function iface_delete(id) {
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.%>'))
return;
(new XHR()).post('< %=url('admin/network/iface_delete')%>/' + id, { token: '< %=token%>' },
function(x) {
location.href = '< %=url('admin/network/network')%>';
}
);
}
2010-11-15 22:08:42 +00:00
var iwxhr = new XHR();
var wifidevs = < %=luci.http.write_json(netdevs)%>;
var arptable = < %=luci.http.write_json(arpcache)%>;
2015-10-07 17:07:36 +00:00
XHR.poll(5, '< %=url('admin/network/iface_status', table.concat(ifaces, ","))%>', null,
2011-09-26 00:24:34 +00:00
function(x, ifcs)
{
if (ifcs)
2010-11-15 22:08:42 +00:00
{
2011-09-26 00:24:34 +00:00
for (var idx = 0; idx < ifcs.length ; idx + + )
2010-11-15 22:08:42 +00:00
{
2011-09-26 00:24:34 +00:00
var ifc = ifcs[idx];
var html = '';
var s = document.getElementById(ifc.id + '-ifc-devices');
if (s)
2010-11-15 22:08:42 +00:00
{
2011-09-26 00:24:34 +00:00
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'
);
2010-11-15 22:08:42 +00:00
2011-09-26 00:24:34 +00:00
if (ifc.subdevices & & ifc.subdevices.length)
2010-11-15 22:08:42 +00:00
{
2011-09-26 00:24:34 +00:00
stat += ' < strong > (';
2010-11-15 22:08:42 +00:00
2011-09-26 00:24:34 +00:00
for (var j = 0; j < ifc.subdevices.length ; j + + )
2011-09-24 01:03:06 +00:00
{
2011-09-26 00:24:34 +00:00
var sif = ifc.subdevices[j];
stat += String.format(
2011-11-08 23:12:38 +00:00
'< img src = "<%=resource%>/icons/%s%s.png" style = "width:16px; height:16px; vertical-align:middle" title = "%h" / > ',
2011-09-26 00:24:34 +00:00
sif.type,
sif.is_up ? '' : '_disabled',
sif.name
);
}
2011-09-24 01:03:06 +00:00
2011-09-26 00:24:34 +00:00
stat += ')< / strong > ';
}
2011-09-24 01:03:06 +00:00
2011-09-26 00:24:34 +00:00
stat += String.format(
2011-11-08 22:35:24 +00:00
'< br / > < small > %h< / small > ',
2011-09-26 00:24:34 +00:00
ifc.name
);
2011-09-24 01:03:06 +00:00
2011-09-26 00:24:34 +00:00
s.innerHTML = stat;
}
2011-09-24 01:03:06 +00:00
2011-09-26 00:24:34 +00:00
var d = document.getElementById(ifc.id + '-ifc-description');
2011-10-18 13:20:43 +00:00
if (d & & ifc.proto & & ifc.ifname)
2011-09-26 00:24:34 +00:00
{
if (ifc.is_up)
{
html += String.format('< strong > < %:Uptime%>:< / strong > %t< br / > ', ifc.uptime);
2010-11-15 22:08:42 +00:00
}
2015-11-17 16:42:22 +00:00
if (ifc.macaddr)
2010-11-15 22:08:42 +00:00
{
2012-08-14 13:08:18 +00:00
html += String.format('< strong > < %:MAC-Address%>:< / strong > %s< br / > ', ifc.macaddr);
2011-09-26 00:24:34 +00:00
}
2010-11-15 22:08:42 +00:00
2011-09-26 00:24:34 +00:00
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
);
2010-11-15 22:08:42 +00:00
2011-09-26 00:24:34 +00:00
if (ifc.ipaddrs & & ifc.ipaddrs.length)
{
for (var i = 0; i < ifc.ipaddrs.length ; i + + )
html += String.format(
2015-12-08 18:20:11 +00:00
'< strong > < %:IPv4%>:< / strong > %s< br / > ',
2015-11-17 16:42:22 +00:00
ifc.ipaddrs[i]
2011-09-26 00:24:34 +00:00
);
}
2011-09-24 01:03:06 +00:00
2011-09-26 00:24:34 +00:00
if (ifc.ip6addrs & & ifc.ip6addrs.length)
{
for (var i = 0; i < ifc.ip6addrs.length ; i + + )
html += String.format(
2015-12-08 18:20:11 +00:00
'< strong > < %:IPv6%>:< / strong > %s< br / > ',
ifc.ip6addrs[i]
2011-09-26 00:24:34 +00:00
);
2010-11-15 22:08:42 +00:00
}
mod-admin-full: Add IPv6 Prefix Delegation information to Status Pages
The Overview page and Network>Interfaces page currently do not give much information about IPv6, particularly with Prefix Delegated setups. In these setups, ISP will delegate a prefix to the router. Currently LuCI doesn't display this Prefix Delegation from the ISP anywhere. A number of changes was added to this commit:
1) self:_ubus("ipv6-prefix") was extracted and put into protocol.ip6prefix.
2) Network>Interfaces page, if a .ip6prefix is present, show it under Status. (IPv6-PD).
3) On the Overview page, "Type" and "Prefix Delegated" has been added to the IPv6 Network Overview Status:
- Type will display the .proto, similar to the IPv4 case. If a .ip6prefix is present, it'll display a "-pd" at the end of the Type: i.e. dhcpv6-pd vs. dhcpv6.
- If no .ip6prefix is present, it'll do what it does currently, and just show Address, or :: if no address is present.
- If .ip6prefix is present, it'll show the "Prefix Delegated", it'll also hide "Address" if no address is present, else it'll show ifc6.ip6addr as well.
Signed-off-by: Cody R. Brown <dev@codybrown.ca>
2017-01-28 09:38:06 +00:00
if (ifc.ip6prefix)
{
html += String.format('< strong > < %:IPv6-PD%>:< / strong > %s< br / > ', ifc.ip6prefix);
}
2011-09-26 00:24:34 +00:00
d.innerHTML = html;
}
2011-10-18 13:20:43 +00:00
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 > ',
2015-10-07 17:07:36 +00:00
'< %=url("admin/system/packages")%>?query=luci-proto& display=available'
2011-10-18 13:20:43 +00:00
);
}
2012-12-19 10:11:03 +00:00
else if (d & & !ifc.ifname)
{
d.innerHTML = String.format(
'< em > < %:Network without interfaces.%>< / em > < br / > ' +
2015-10-07 17:07:36 +00:00
'< a href = "<%=url(" admin / network / network / % s " ) % > ?tab.network.%s=physical">< %:Assign interfaces...%>< / a > ',
2012-12-19 10:11:03 +00:00
ifc.name, ifc.name
);
}
2011-09-26 00:24:34 +00:00
else if (d)
{
d.innerHTML = '< em > < %:Interface not present or not connected yet.%>< / em > ';
2010-11-15 22:08:42 +00:00
}
}
}
2011-09-26 00:24:34 +00:00
}
);
2010-11-18 01:34:56 +00:00
//]]>< / script >
2010-11-15 22:08:42 +00:00
< fieldset class = "cbi-section" style = "display:none" >
< legend > < %:Reconnecting interface%>< / legend >
< img src = "<%=resource%>/icons/loading.gif" alt = "<%:Loading%>" style = "vertical-align:middle" / >
2012-07-01 20:05:05 +00:00
< span id = "ifc-rc-status" > < %:Waiting for changes to be applied...%>< / span >
2010-11-15 22:08:42 +00:00
< / fieldset >
< div class = "cbi-map" >
< fieldset class = "cbi-section" >
2010-11-15 23:00:53 +00:00
< legend > < %:Interface Overview%>< / legend >
2010-11-15 22:08:42 +00:00
< table class = "cbi-section-table" style = "margin:10px; empty-cells:hide" >
< tr class = "cbi-section-table-titles" >
2011-09-24 01:03:06 +00:00
< 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 >
2010-11-15 22:08:42 +00:00
< / tr >
2011-09-24 01:03:06 +00:00
< %
for i, net in ipairs(netlist) do
2012-06-27 10:12:20 +00:00
local z = net[3]
2011-09-24 01:03:06 +00:00
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")
%>
2010-11-15 22:08:42 +00:00
< tr class = "cbi-section-table-row cbi-rowstyle-<%=i % 2 + 1%>" >
2011-09-24 01:03:06 +00:00
< td class = "cbi-value-field" style = "padding:3px" >
2012-02-15 16:01:07 +00:00
< div class = "ifacebox" >
< div class = "ifacebox-head" style = "background-color:<%=c%>" title = "<%=pcdata(t)%>" >
2012-06-27 10:12:20 +00:00
< strong > < %=net[1]:upper()%>< / strong >
2011-09-24 01:03:06 +00:00
< / div >
2012-06-27 10:12:20 +00:00
< div class = "ifacebox-body" id = "<%=net[1]%>-ifc-devices" >
2011-09-24 01:03:06 +00:00
< img src = "<%=resource%>/icons/ethernet_disabled.png" style = "width:16px; height:16px" / > < br / >
< small > ?< / small >
< / div >
< / div >
2010-11-15 22:08:42 +00:00
< / td >
2012-06-27 10:12:20 +00:00
< td class = "cbi-value-field" style = "vertical-align:middle; text-align:left; padding:3px" id = "<%=net[1]%>-ifc-description" >
2011-09-24 01:03:06 +00:00
< em > < %:Collecting data...%>< / em >
2010-11-15 22:08:42 +00:00
< / td >
2011-10-02 11:37:44 +00:00
< td style = "width:420px" >
2012-06-27 10:12:20 +00:00
< input type = "button" class = "cbi-button cbi-button-reload" style = "width:100px" onclick = "iface_shutdown('<%=net[1]%>', true)" title = "<%:Reconnect this interface%>" value = "<%:Connect%>" / >
< input type = "button" class = "cbi-button cbi-button-reset" style = "width:100px" onclick = "iface_shutdown('<%=net[1]%>', false)" title = "<%:Shutdown this interface%>" value = "<%:Stop%>" / >
2015-10-07 17:07:36 +00:00
< input type = "button" class = "cbi-button cbi-button-edit" style = "width:100px" onclick = "location.href='<%=url(" admin / network / network " , net [ 1 ] ) % > '" title="< %:Edit this interface%>" value="< %:Edit%>" id="< %=net[1]%>-ifc-edit" />
2015-11-19 09:02:41 +00:00
< input type = "button" class = "cbi-button cbi-button-remove" style = "width:100px" onclick = "iface_delete('<%=net[1]%>')" value = "<%:Delete%>" / >
2010-11-15 22:08:42 +00:00
< / td >
< / tr >
< % end %>
< / table >
2015-10-07 17:07:36 +00:00
< input type = "button" class = "cbi-button cbi-button-add" value = "<%:Add new interface...%>" onclick = "location.href='<%=url(" admin / network / iface_add " ) % > '" />
2010-11-15 23:00:53 +00:00
< / fieldset >
2010-11-15 22:08:42 +00:00
< / div >