9 handleCommand: function(exec, args) {
10 var buttons = document.querySelectorAll('.diag-action > .cbi-button');
12 for (var i = 0; i < buttons.length; i++)
13 buttons[i].setAttribute('disabled', 'true');
15 return fs.exec(exec, args).then(function(res) {
16 var out = document.querySelector('.command-output');
17 out.style.display = '';
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') ? [ '-c', '5', '-W', '1', addr ] : [ '-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') ? [ '-q', '1', '-w', '1', '-n', 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 ]);
52 L.resolveDefault(fs.stat('/bin/ping6'), {}),
53 L.resolveDefault(fs.stat('/usr/bin/ping6'), {}),
54 L.resolveDefault(fs.stat('/bin/traceroute6'), {}),
55 L.resolveDefault(fs.stat('/usr/bin/traceroute6'), {}),
60 render: function(res) {
61 var has_ping6 = res[0].path || res[1].path,
62 has_traceroute6 = res[2].path || res[3].path,
63 dns_host = uci.get('luci', 'diag', 'dns') || 'openwrt.org',
64 ping_host = uci.get('luci', 'diag', 'ping') || 'openwrt.org',
65 route_host = uci.get('luci', 'diag', 'route') || 'openwrt.org';
68 E('h2', {}, [ _('Network Utilities') ]),
69 E('div', { 'class': 'table' }, [
70 E('div', { 'class': 'tr' }, [
71 E('div', { 'class': 'td left' }, [
73 'style': 'margin:5px 0',
77 E('span', { 'class': 'diag-action' }, [
78 has_ping6 ? new ui.ComboButton('ping', {
79 'ping': '%s %s'.format(_('IPv4'), _('Ping')),
80 'ping6': '%s %s'.format(_('IPv6'), _('Ping')),
82 'click': ui.createHandlerFn(this, 'handlePing'),
84 'ping': 'cbi-button cbi-button-action',
85 'ping6': 'cbi-button cbi-button-action'
87 }).render() : E('button', {
88 'class': 'cbi-button cbi-button-action',
89 'click': ui.createHandlerFn(this, 'handlePing')
94 E('div', { 'class': 'td left' }, [
96 'style': 'margin:5px 0',
100 E('span', { 'class': 'diag-action' }, [
101 has_traceroute6 ? new ui.ComboButton('traceroute', {
102 'traceroute': '%s %s'.format(_('IPv4'), _('Traceroute')),
103 'traceroute6': '%s %s'.format(_('IPv6'), _('Traceroute')),
105 'click': ui.createHandlerFn(this, 'handleTraceroute'),
107 'traceroute': 'cbi-button cbi-button-action',
108 'traceroute6': 'cbi-button cbi-button-action'
110 }).render() : E('button', {
111 'class': 'cbi-button cbi-button-action',
112 'click': ui.createHandlerFn(this, 'handleTraceroute')
113 }, [ _('Traceroute') ])
117 E('div', { 'class': 'td left' }, [
119 'style': 'margin:5px 0',
123 E('span', { 'class': 'diag-action' }, [
125 'class': 'cbi-button cbi-button-action',
126 'click': ui.createHandlerFn(this, 'handleNslookup')
127 }, [ _('Nslookup') ])
132 E('pre', { 'class': 'command-output', 'style': 'display:none' })
136 handleSaveApply: null,