10 handleCommand: function(exec
, args
) {
11 var buttons
= document
.querySelectorAll('.diag-action > .cbi-button');
13 for (var i
= 0; i
< buttons
.length
; i
++)
14 buttons
[i
].setAttribute('disabled', 'true');
16 return fs
.exec(exec
, args
).then(function(res
) {
17 var out
= document
.querySelector('textarea');
19 dom
.content(out
, [ res
.stdout
|| '', res
.stderr
|| '' ]);
20 }).catch(function(err
) {
21 ui
.addNotification(null, E('p', [ err
]))
22 }).finally(function() {
23 for (var i
= 0; i
< buttons
.length
; i
++)
24 buttons
[i
].removeAttribute('disabled');
28 handlePing: function(ev
, cmd
) {
29 var exec
= cmd
|| 'ping',
30 addr
= ev
.currentTarget
.parentNode
.previousSibling
.value
,
31 args
= (exec
== 'ping') ? [ '-4', '-c', '5', '-W', '1', addr
] : [ '-6', '-c', '5', addr
];
33 return this.handleCommand(exec
, args
);
36 handleTraceroute: function(ev
, cmd
) {
37 var exec
= cmd
|| 'traceroute',
38 addr
= ev
.currentTarget
.parentNode
.previousSibling
.value
,
39 args
= (exec
== 'traceroute') ? [ '-4', '-q', '1', '-w', '1', '-n', '-m', String(L
.env
.rpctimeout
|| 20), addr
] : [ '-q', '1', '-w', '2', '-n', addr
];
41 return this.handleCommand(exec
, args
);
44 handleNslookup: function(ev
, cmd
) {
45 var addr
= ev
.currentTarget
.parentNode
.previousSibling
.value
;
47 return this.handleCommand('nslookup', [ addr
]);
50 handleArpScan: function(ev
, cmd
) {
51 var addr
= ev
.currentTarget
.parentNode
.previousSibling
.value
;
53 return this.handleCommand('arp-scan', [ '-l', '-I', addr
]);
58 L
.resolveDefault(fs
.stat('/bin/ping6'), {}),
59 L
.resolveDefault(fs
.stat('/usr/bin/ping6'), {}),
60 L
.resolveDefault(fs
.stat('/bin/traceroute6'), {}),
61 L
.resolveDefault(fs
.stat('/usr/bin/traceroute6'), {}),
62 L
.resolveDefault(fs
.stat('/usr/bin/arp-scan'), {}),
68 render: function(res
) {
69 var has_ping6
= res
[0].path
|| res
[1].path
,
70 has_traceroute6
= res
[2].path
|| res
[3].path
,
71 has_arpscan
= res
[4].path
,
73 dns_host
= uci
.get('luci', 'diag', 'dns') || 'openwrt.org',
74 ping_host
= uci
.get('luci', 'diag', 'ping') || 'openwrt.org',
75 route_host
= uci
.get('luci', 'diag', 'route') || 'openwrt.org';
77 var table
= E('table', { 'class': 'table' }, [
78 E('tr', { 'class': 'tr' }, [
79 E('td', { 'class': 'td left' }, [
81 'style': 'margin:5px 0',
85 E('span', { 'class': 'diag-action' }, [
86 has_ping6
? new ui
.ComboButton('ping', {
87 'ping': '%s %s'.format(_('IPv4'), _('Ping')),
88 'ping6': '%s %s'.format(_('IPv6'), _('Ping')),
90 'click': ui
.createHandlerFn(this, 'handlePing'),
92 'ping': 'btn cbi-button cbi-button-action',
93 'ping6': 'btn cbi-button cbi-button-action'
95 }).render() : E('button', {
96 'class': 'cbi-button cbi-button-action',
97 'click': ui
.createHandlerFn(this, 'handlePing')
102 E('td', { 'class': 'td left' }, [
104 'style': 'margin:5px 0',
108 E('span', { 'class': 'diag-action' }, [
109 has_traceroute6
? new ui
.ComboButton('traceroute', {
110 'traceroute': '%s %s'.format(_('IPv4'), _('Traceroute')),
111 'traceroute6': '%s %s'.format(_('IPv6'), _('Traceroute')),
113 'click': ui
.createHandlerFn(this, 'handleTraceroute'),
115 'traceroute': 'btn cbi-button cbi-button-action',
116 'traceroute6': 'btn cbi-button cbi-button-action'
118 }).render() : E('button', {
119 'class': 'cbi-button cbi-button-action',
120 'click': ui
.createHandlerFn(this, 'handleTraceroute')
121 }, [ _('Traceroute') ])
125 E('td', { 'class': 'td left' }, [
127 'style': 'margin:5px 0',
131 E('span', { 'class': 'diag-action' }, [
133 'class': 'cbi-button cbi-button-action',
134 'click': ui
.createHandlerFn(this, 'handleNslookup')
135 }, [ _('Nslookup') ])
139 has_arpscan
? E('td', { 'class': 'td left' }, [
141 'style': 'margin:5px 0'
142 }, devices
.map(function(device
) {
146 return E('option', { 'value': device
.getName() }, [ device
.getI18n() ]);
148 E('span', { 'class': 'diag-action' }, [
150 'class': 'cbi-button cbi-button-action',
151 'click': ui
.createHandlerFn(this, 'handleArpScan')
152 }, [ _('Arp-scan') ])
158 var view
= E('div', { 'class': 'cbi-map'}, [
159 E('h2', {}, [ _('Diagnostics') ]),
160 E('div', { 'class': 'cbi-map-descr'}, _('Execution of various network commands to check the connection and name resolution to other systems.')),
162 E('div', {'class': 'cbi-section'}, [
163 E('div', { 'id' : 'command-output'},
165 'id': 'widget.command-output',
166 'style': 'width: 100%',
178 handleSaveApply
: null,