luci-mod-admin-full: add arp-scan to network diagnostic
authorPaul Spooren <[email protected]>
Tue, 28 Sep 2021 19:44:47 +0000 (09:44 -1000)
committerPaul Spooren <[email protected]>
Mon, 11 Oct 2021 21:15:17 +0000 (11:15 -1000)
This is a JavaScript rewrite of the PR#5152

It adds the ability to perform ARP scans if the tool `arp-scan` is
installed.

Signed-off-by: Paul Spooren <[email protected]>
modules/luci-mod-network/htdocs/luci-static/resources/view/network/diagnostics.js
modules/luci-mod-network/root/usr/share/rpcd/acl.d/luci-mod-network.json

index 992bb99395bce1e8914e02d43c6c476470af78b0..af61390220c33eaf41ef2927db81b50486740205 100644 (file)
@@ -47,12 +47,19 @@ return view.extend({
                return this.handleCommand('nslookup', [ addr ]);
        },
 
+       handleArpScan: function(ev, cmd) {
+               var addr = ev.currentTarget.parentNode.previousSibling.value;
+
+               return this.handleCommand('arp-scan', [ '-l', '-I', addr]);
+       },
+
        load: function() {
                return Promise.all([
                        L.resolveDefault(fs.stat('/bin/ping6'), {}),
                        L.resolveDefault(fs.stat('/usr/bin/ping6'), {}),
                        L.resolveDefault(fs.stat('/bin/traceroute6'), {}),
                        L.resolveDefault(fs.stat('/usr/bin/traceroute6'), {}),
+                       L.resolveDefault(fs.stat('/usr/bin/arp-scan'), {}),
                        uci.load('luci')
                ]);
        },
@@ -60,6 +67,7 @@ return view.extend({
        render: function(res) {
                var has_ping6 = res[0].path || res[1].path,
                    has_traceroute6 = res[2].path || res[3].path,
+                   has_arpscan = res[4].path,
                        dns_host = uci.get('luci', 'diag', 'dns') || 'openwrt.org',
                        ping_host = uci.get('luci', 'diag', 'ping') || 'openwrt.org',
                        route_host = uci.get('luci', 'diag', 'route') || 'openwrt.org';
@@ -68,7 +76,7 @@ return view.extend({
                        E('h2', {}, [ _('Network Utilities') ]),
                        E('table', { 'class': 'table' }, [
                                E('tr', { 'class': 'tr' }, [
-                                       E('td', { 'class': 'td left' }, [
+                                       E('td', { 'class': 'td left', 'width': '25%' }, [
                                                E('input', {
                                                        'style': 'margin:5px 0',
                                                        'type': 'text',
@@ -91,7 +99,7 @@ return view.extend({
                                                ])
                                        ]),
 
-                                       E('td', { 'class': 'td left' }, [
+                                       E('td', { 'class': 'td left', 'width': '25%' }, [
                                                E('input', {
                                                        'style': 'margin:5px 0',
                                                        'type': 'text',
@@ -114,7 +122,7 @@ return view.extend({
                                                ])
                                        ]),
 
-                                       E('td', { 'class': 'td left' }, [
+                                       E('td', { 'class': 'td left', 'width': '25%' }, [
                                                E('input', {
                                                        'style': 'margin:5px 0',
                                                        'type': 'text',
@@ -126,7 +134,26 @@ return view.extend({
                                                                'click': ui.createHandlerFn(this, 'handleNslookup')
                                                        }, [ _('Nslookup') ])
                                                ])
-                                       ])
+                                       ]),
+
+                                       E('td', { 'class': 'td left', 'width': '25%' }, has_arpscan ? [
+                                               E('input', {
+                                                       'style': 'margin:5px 0',
+                                                       'type': 'text',
+                                                       'value': 'br-lan'
+                                               }),
+                                               E('span', { 'class': 'diag-action' }, [
+                                                       E('button', {
+                                                               'class': 'cbi-button cbi-button-action',
+                                                               'click': ui.createHandlerFn(this, 'handleArpScan')
+                                                       }, [ _('Arp-scan') ])
+                                               ])] : E('p', {}, [
+                                                       E('em', _('Missing ARP scan')), E('br'),
+                                                       E('a', {
+                                                               href: L.url('admin/system/opkg') + '?query=arp-scan'
+                                                       }, _('Install `arp-scan`...'))
+                                               ])
+                                       ),
                                ])
                        ]),
                        E('pre', { 'class': 'command-output', 'style': 'display:none' })
index 6943d9563778f4b9543f508887bcb88dd1fda705..1c553f39924b88210f1be84bf5224f33026eea68 100644 (file)
@@ -58,7 +58,8 @@
                                "/usr/bin/ping": [ "exec" ],
                                "/usr/bin/ping6": [ "exec", "list" ],
                                "/usr/bin/traceroute": [ "exec" ],
-                               "/usr/bin/traceroute6": [ "exec", "list" ]
+                               "/usr/bin/traceroute6": [ "exec", "list" ],
+                               "/usr/bin/arp-scan": [ "exec", "list" ]
                        },
                        "ubus": {
                                "file": [ "exec", "stat" ]