luci-mod-status: 29_ports.js: attempt to use getBuiltinEthernetPorts
Try to use the new luci/getBuiltinEthernetPorts RPC call to enumerate known ports and fall back to manual board.json parsing if the call is unavailable yet. The fallback code will be dropped in a while when everything settled. Ref: #6534, #6538 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
98e37433e7
commit
ed059e4cd3
1 changed files with 32 additions and 16 deletions
|
@ -3,9 +3,16 @@
|
||||||
'require fs';
|
'require fs';
|
||||||
'require ui';
|
'require ui';
|
||||||
'require uci';
|
'require uci';
|
||||||
|
'require rpc';
|
||||||
'require network';
|
'require network';
|
||||||
'require firewall';
|
'require firewall';
|
||||||
|
|
||||||
|
var callGetBuiltinEthernetPorts = rpc.declare({
|
||||||
|
object: 'luci',
|
||||||
|
method: 'getBuiltinEthernetPorts',
|
||||||
|
expect: { result: [] }
|
||||||
|
});
|
||||||
|
|
||||||
function isString(v)
|
function isString(v)
|
||||||
{
|
{
|
||||||
return typeof(v) === 'string' && v !== '';
|
return typeof(v) === 'string' && v !== '';
|
||||||
|
@ -284,6 +291,7 @@ return baseclass.extend({
|
||||||
|
|
||||||
load: function() {
|
load: function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
L.resolveDefault(callGetBuiltinEthernetPorts(), []),
|
||||||
L.resolveDefault(fs.read('/etc/board.json'), '{}'),
|
L.resolveDefault(fs.read('/etc/board.json'), '{}'),
|
||||||
firewall.getZones(),
|
firewall.getZones(),
|
||||||
network.getNetworks(),
|
network.getNetworks(),
|
||||||
|
@ -295,28 +303,36 @@ return baseclass.extend({
|
||||||
if (L.hasSystemFeature('swconfig'))
|
if (L.hasSystemFeature('swconfig'))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var board = JSON.parse(data[0]),
|
var board = JSON.parse(data[1]),
|
||||||
known_ports = [],
|
known_ports = [],
|
||||||
port_map = buildInterfaceMapping(data[1], data[2]);
|
port_map = buildInterfaceMapping(data[2], data[3]);
|
||||||
|
|
||||||
if (L.isObject(board) && L.isObject(board.network)) {
|
if (Array.isArray(data[0]) && data[0].length > 0) {
|
||||||
for (var k = 'lan'; k != null; k = (k == 'lan') ? 'wan' : null) {
|
known_ports = data[0].map(port => ({
|
||||||
if (!L.isObject(board.network[k]))
|
...port,
|
||||||
continue;
|
netdev: network.instantiateDevice(port.device)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (L.isObject(board) && L.isObject(board.network)) {
|
||||||
|
for (var k = 'lan'; k != null; k = (k == 'lan') ? 'wan' : null) {
|
||||||
|
if (!L.isObject(board.network[k]))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (Array.isArray(board.network[k].ports))
|
if (Array.isArray(board.network[k].ports))
|
||||||
for (let i = 0; i < board.network[k].ports.length; i++)
|
for (let i = 0; i < board.network[k].ports.length; i++)
|
||||||
|
known_ports.push({
|
||||||
|
role: k,
|
||||||
|
device: board.network[k].ports[i],
|
||||||
|
netdev: network.instantiateDevice(board.network[k].ports[i])
|
||||||
|
});
|
||||||
|
else if (typeof(board.network[k].device) == 'string')
|
||||||
known_ports.push({
|
known_ports.push({
|
||||||
role: k,
|
role: k,
|
||||||
device: board.network[k].ports[i],
|
device: board.network[k].device,
|
||||||
netdev: network.instantiateDevice(board.network[k].ports[i])
|
netdev: network.instantiateDevice(board.network[k].device)
|
||||||
});
|
});
|
||||||
else if (typeof(board.network[k].device) == 'string')
|
}
|
||||||
known_ports.push({
|
|
||||||
role: k,
|
|
||||||
device: board.network[k].device,
|
|
||||||
netdev: network.instantiateDevice(board.network[k].device)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue