Merge pull request #2140 from kristrev/multiple-upstream-interfaces-status
luci-base: Show multiple upstream interface
This commit is contained in:
commit
1a0316bbba
2 changed files with 121 additions and 89 deletions
|
@ -813,6 +813,7 @@ function del_wifinet(self, net)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_status_by_route(self, addr, mask)
|
function get_status_by_route(self, addr, mask)
|
||||||
|
local route_statuses = { }
|
||||||
local _, object
|
local _, object
|
||||||
for _, object in ipairs(utl.ubus()) do
|
for _, object in ipairs(utl.ubus()) do
|
||||||
local net = object:match("^network%.interface%.(.+)")
|
local net = object:match("^network%.interface%.(.+)")
|
||||||
|
@ -822,12 +823,14 @@ function get_status_by_route(self, addr, mask)
|
||||||
local rt
|
local rt
|
||||||
for _, rt in ipairs(s.route) do
|
for _, rt in ipairs(s.route) do
|
||||||
if not rt.table and rt.target == addr and rt.mask == mask then
|
if not rt.table and rt.target == addr and rt.mask == mask then
|
||||||
return net, s
|
route_statuses[net] = s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return route_statuses
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_status_by_address(self, addr)
|
function get_status_by_address(self, addr)
|
||||||
|
@ -856,24 +859,28 @@ function get_status_by_address(self, addr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_wannet(self)
|
function get_wan_networks(self)
|
||||||
local net, stat = self:get_status_by_route("0.0.0.0", 0)
|
local k, v
|
||||||
return net and network(net, stat.proto)
|
local wan_nets = { }
|
||||||
|
local route_statuses = self:get_status_by_route("0.0.0.0", 0)
|
||||||
|
|
||||||
|
for k, v in pairs(route_statuses) do
|
||||||
|
wan_nets[#wan_nets+1] = network(k, v.proto)
|
||||||
|
end
|
||||||
|
|
||||||
|
return wan_nets
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_wandev(self)
|
function get_wan6_networks(self)
|
||||||
local _, stat = self:get_status_by_route("0.0.0.0", 0)
|
local k, v
|
||||||
return stat and interface(stat.l3_device or stat.device)
|
local wan6_nets = { }
|
||||||
end
|
local route_statuses = self:get_status_by_route("::", 0)
|
||||||
|
|
||||||
function get_wan6net(self)
|
for k, v in pairs(route_statuses) do
|
||||||
local net, stat = self:get_status_by_route("::", 0)
|
wan6_nets[#wan6_nets+1] = network(k, v.proto)
|
||||||
return net and network(net, stat.proto)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function get_wan6dev(self)
|
return wan6_nets
|
||||||
local _, stat = self:get_status_by_route("::", 0)
|
|
||||||
return stat and interface(stat.l3_device or stat.device)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_switch_topologies(self)
|
function get_switch_topologies(self)
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
|
|
||||||
if luci.http.formvalue("status") == "1" then
|
if luci.http.formvalue("status") == "1" then
|
||||||
local ntm = require "luci.model.network".init()
|
local ntm = require "luci.model.network".init()
|
||||||
local wan = ntm:get_wannet()
|
local wan_nets = ntm:get_wan_networks()
|
||||||
local wan6 = ntm:get_wan6net()
|
local wan6_nets = ntm:get_wan6_networks()
|
||||||
|
|
||||||
local conn_count = tonumber(
|
local conn_count = tonumber(
|
||||||
fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
|
fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
|
||||||
|
@ -56,45 +56,62 @@
|
||||||
wifinets = stat.wifi_networks()
|
wifinets = stat.wifi_networks()
|
||||||
}
|
}
|
||||||
|
|
||||||
if wan then
|
if #wan_nets > 0 then
|
||||||
local dev = wan:get_interface()
|
local k, v
|
||||||
local link = dev and ipc.link(dev:name())
|
|
||||||
rv.wan = {
|
rv.wan = { }
|
||||||
ipaddr = wan:ipaddr(),
|
|
||||||
gwaddr = wan:gwaddr(),
|
for k, v in pairs(wan_nets) do
|
||||||
netmask = wan:netmask(),
|
local dev = v:get_interface()
|
||||||
dns = wan:dnsaddrs(),
|
local link = dev and ipc.link(dev:name())
|
||||||
expires = wan:expires(),
|
|
||||||
uptime = wan:uptime(),
|
local wan_info = {
|
||||||
proto = wan:proto(),
|
ipaddr = v:ipaddr(),
|
||||||
i18n = wan:get_i18n(),
|
gwaddr = v:gwaddr(),
|
||||||
ifname = wan:ifname(),
|
netmask = v:netmask(),
|
||||||
link = wan:adminlink(),
|
dns = v:dnsaddrs(),
|
||||||
mac = dev and dev:mac(),
|
expires = v:expires(),
|
||||||
type = dev and dev:type(),
|
uptime = v:uptime(),
|
||||||
name = dev and dev:get_i18n(),
|
proto = v:proto(),
|
||||||
ether = link and link.type == 1
|
i18n = v:get_i18n(),
|
||||||
}
|
ifname = v:ifname(),
|
||||||
|
link = v:adminlink(),
|
||||||
|
mac = dev and dev:mac(),
|
||||||
|
type = dev and dev:type(),
|
||||||
|
name = dev and dev:get_i18n(),
|
||||||
|
ether = link and link.type == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
rv.wan[#rv.wan+1] = wan_info
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if wan6 then
|
if #wan6_nets > 0 then
|
||||||
local dev = wan6:get_interface()
|
local k, v
|
||||||
local link = dev and ipc.link(dev:name())
|
|
||||||
rv.wan6 = {
|
rv.wan6 = { }
|
||||||
ip6addr = wan6:ip6addr(),
|
|
||||||
gw6addr = wan6:gw6addr(),
|
for k, v in pairs(wan6_nets) do
|
||||||
dns = wan6:dns6addrs(),
|
local dev = v:get_interface()
|
||||||
ip6prefix = wan6:ip6prefix(),
|
local link = dev and ipc.link(dev:name())
|
||||||
uptime = wan6:uptime(),
|
local wan6_info = {
|
||||||
proto = wan6:proto(),
|
ip6addr = v:ip6addr(),
|
||||||
i18n = wan6:get_i18n(),
|
gw6addr = v:gw6addr(),
|
||||||
ifname = wan6:ifname(),
|
dns = v:dns6addrs(),
|
||||||
link = wan6:adminlink(),
|
ip6prefix = v:ip6prefix(),
|
||||||
mac = dev and dev:mac(),
|
uptime = v:uptime(),
|
||||||
type = dev and dev:type(),
|
proto = v:proto(),
|
||||||
name = dev and dev:get_i18n(),
|
i18n = v:get_i18n(),
|
||||||
ether = link and link.type == 1
|
ifname = v:ifname(),
|
||||||
}
|
link = v:adminlink(),
|
||||||
|
mac = dev and dev:mac(),
|
||||||
|
type = dev and dev:type(),
|
||||||
|
name = dev and dev:get_i18n(),
|
||||||
|
ether = link and link.type == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
rv.wan6[#rv.wan6+1] = wan6_info
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if has_dsl then
|
if has_dsl then
|
||||||
|
@ -177,47 +194,55 @@
|
||||||
while (us.lastElementChild)
|
while (us.lastElementChild)
|
||||||
us.removeChild(us.lastElementChild);
|
us.removeChild(us.lastElementChild);
|
||||||
|
|
||||||
var ifc = info.wan || {};
|
var wan_list = info.wan || [];
|
||||||
|
|
||||||
us.appendChild(renderBox(
|
for (var i = 0; i < wan_list.length; i++) {
|
||||||
'<%:IPv4 Upstream%>',
|
var ifc = wan_list[i];
|
||||||
(ifc.ifname && ifc.proto != 'none'),
|
|
||||||
[ E('div', {}, renderBadge(
|
us.appendChild(renderBox(
|
||||||
'<%=resource%>/icons/%s.png'.format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
|
'<%:IPv4 Upstream%>',
|
||||||
|
(ifc.ifname && ifc.proto != 'none'),
|
||||||
|
[ E('div', {}, renderBadge(
|
||||||
|
'<%=resource%>' + '/icons/%s.png'.format((ifc && ifc.type) ? ifc.type : 'ethernet_disabled'), null,
|
||||||
'<%:Device%>', ifc ? (ifc.name || ifc.ifname || '-') : '-',
|
'<%:Device%>', ifc ? (ifc.name || ifc.ifname || '-') : '-',
|
||||||
'<%:MAC-Address%>', (ifc && ifc.ether) ? ifc.mac : null)) ],
|
'<%:MAC-Address%>', (ifc && ifc.ether) ? ifc.mac : null)) ],
|
||||||
'<%:Protocol%>', ifc.i18n || E('em', '<%:Not connected%>'),
|
'<%:Protocol%>', ifc.i18n || E('em', '<%:Not connected%>'),
|
||||||
'<%:Address%>', (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
|
'<%:Address%>', (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
|
||||||
'<%:Netmask%>', (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
|
'<%:Netmask%>', (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
|
||||||
'<%:Gateway%>', (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
|
'<%:Gateway%>', (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0',
|
||||||
'<%:DNS%> 1', (ifc.dns) ? ifc.dns[0] : null,
|
'<%:DNS%> 1', (ifc.dns) ? ifc.dns[0] : null,
|
||||||
'<%:DNS%> 2', (ifc.dns) ? ifc.dns[1] : null,
|
'<%:DNS%> 2', (ifc.dns) ? ifc.dns[1] : null,
|
||||||
'<%:DNS%> 3', (ifc.dns) ? ifc.dns[2] : null,
|
'<%:DNS%> 3', (ifc.dns) ? ifc.dns[2] : null,
|
||||||
'<%:DNS%> 4', (ifc.dns) ? ifc.dns[3] : null,
|
'<%:DNS%> 4', (ifc.dns) ? ifc.dns[3] : null,
|
||||||
'<%:DNS%> 5', (ifc.dns) ? ifc.dns[4] : null,
|
'<%:DNS%> 5', (ifc.dns) ? ifc.dns[4] : null,
|
||||||
'<%:Expires%>', (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
|
'<%:Expires%>', (ifc.expires > -1) ? '%t'.format(ifc.expires) : null,
|
||||||
'<%:Connected%>', (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
|
'<%:Connected%>', (ifc.uptime > 0) ? '%t'.format(ifc.uptime) : null));
|
||||||
|
}
|
||||||
|
|
||||||
<% if has_ipv6 then %>
|
<% if has_ipv6 then %>
|
||||||
var ifc6 = info.wan6 || {};
|
var wan6_list = info.wan6 || [];
|
||||||
|
|
||||||
us.appendChild(renderBox(
|
for (var i = 0; i < wan6_list.length; i++) {
|
||||||
'<%:IPv6 Upstream%>',
|
var ifc6 = wan6_list[i];
|
||||||
(ifc6.ifname && ifc6.proto != 'none'),
|
|
||||||
[ E('div', {}, renderBadge(
|
us.appendChild(renderBox(
|
||||||
'<%=resource%>/icons/%s.png'.format(ifc6.type || 'ethernet_disabled'), null,
|
'<%:IPv6 Upstream%>',
|
||||||
'<%:Device%>', ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
|
(ifc6.ifname && ifc6.proto != 'none'),
|
||||||
'<%:MAC-Address%>', (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
|
[ E('div', {}, renderBadge(
|
||||||
'<%:Protocol%>', ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', '<%:Not connected%>'),
|
'<%=resource%>/icons/%s.png'.format(ifc6.type || 'ethernet_disabled'), null,
|
||||||
'<%:Prefix Delegated%>', ifc6.ip6prefix,
|
'<%:Device%>', ifc6 ? (ifc6.name || ifc6.ifname || '-') : '-',
|
||||||
'<%:Address%>', (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ipaddr || '::'),
|
'<%:MAC-Address%>', (ifc6 && ifc6.ether) ? ifc6.mac : null)) ],
|
||||||
'<%:Gateway%>', (ifc6.gw6addr) ? ifc6.gw6addr : '::',
|
'<%:Protocol%>', ifc6.i18n ? (ifc6.i18n + (ifc6.proto === 'dhcp' && ifc6.ip6prefix ? '-PD' : '')) : E('em', '<%:Not connected%>'),
|
||||||
'<%:DNS%> 1', (ifc6.dns) ? ifc6.dns[0] : null,
|
'<%:Prefix Delegated%>', ifc6.ip6prefix,
|
||||||
'<%:DNS%> 2', (ifc6.dns) ? ifc6.dns[1] : null,
|
'<%:Address%>', (ifc6.ip6prefix) ? (ifc6.ip6addr || null) : (ifc6.ipaddr || '::'),
|
||||||
'<%:DNS%> 3', (ifc6.dns) ? ifc6.dns[2] : null,
|
'<%:Gateway%>', (ifc6.gw6addr) ? ifc6.gw6addr : '::',
|
||||||
'<%:DNS%> 4', (ifc6.dns) ? ifc6.dns[3] : null,
|
'<%:DNS%> 1', (ifc6.dns) ? ifc6.dns[0] : null,
|
||||||
'<%:DNS%> 5', (ifc6.dns) ? ifc6.dns[4] : null,
|
'<%:DNS%> 2', (ifc6.dns) ? ifc6.dns[1] : null,
|
||||||
'<%:Connected%>', (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
|
'<%:DNS%> 3', (ifc6.dns) ? ifc6.dns[2] : null,
|
||||||
|
'<%:DNS%> 4', (ifc6.dns) ? ifc6.dns[3] : null,
|
||||||
|
'<%:DNS%> 5', (ifc6.dns) ? ifc6.dns[4] : null,
|
||||||
|
'<%:Connected%>', (ifc6.uptime > 0) ? '%t'.format(ifc6.uptime) : null));
|
||||||
|
}
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if has_dsl then %>
|
<% if has_dsl then %>
|
||||||
|
|
Loading…
Reference in a new issue