diff options
author | Jo-Philipp Wich <jo@mein.io> | 2023-08-24 16:46:02 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2023-08-24 16:49:30 +0200 |
commit | ed059e4cd3ee9b15aabcc974b4e66b0090b920ae (patch) | |
tree | 11e92ad7b40b2d450490981edb4a84189d46e1e3 /modules/luci-mod-status/htdocs/luci-static/resources | |
parent | 98e37433e7f33b3e2ee751250e04b194a0aa6a0b (diff) |
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>
Diffstat (limited to 'modules/luci-mod-status/htdocs/luci-static/resources')
-rw-r--r-- | modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js index b226e4f3c6..1351ab935a 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js @@ -3,9 +3,16 @@ 'require fs'; 'require ui'; 'require uci'; +'require rpc'; 'require network'; 'require firewall'; +var callGetBuiltinEthernetPorts = rpc.declare({ + object: 'luci', + method: 'getBuiltinEthernetPorts', + expect: { result: [] } +}); + function isString(v) { return typeof(v) === 'string' && v !== ''; @@ -284,6 +291,7 @@ return baseclass.extend({ load: function() { return Promise.all([ + L.resolveDefault(callGetBuiltinEthernetPorts(), []), L.resolveDefault(fs.read('/etc/board.json'), '{}'), firewall.getZones(), network.getNetworks(), @@ -295,28 +303,36 @@ return baseclass.extend({ if (L.hasSystemFeature('swconfig')) return null; - var board = JSON.parse(data[0]), + var board = JSON.parse(data[1]), known_ports = [], - port_map = buildInterfaceMapping(data[1], data[2]); - - 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; + port_map = buildInterfaceMapping(data[2], data[3]); - if (Array.isArray(board.network[k].ports)) - for (let i = 0; i < board.network[k].ports.length; i++) + if (Array.isArray(data[0]) && data[0].length > 0) { + known_ports = data[0].map(port => ({ + ...port, + 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)) + 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({ role: k, - device: board.network[k].ports[i], - netdev: network.instantiateDevice(board.network[k].ports[i]) + device: board.network[k].device, + 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) - }); + } } } |