luci2: move most RPC proxy function declarations into the views using them to reduce...
[project/luci2/ui.git] / luci2 / htdocs / luci2 / view / network.diagnostics.js
1 L.ui.view.extend({
2 title: L.tr('Diagnostics'),
3
4 runPing: L.rpc.declare({
5 object: 'luci2.network',
6 method: 'ping',
7 params: [ 'data' ],
8 expect: { '': { code: -1 } }
9 }),
10
11 runPing6: L.rpc.declare({
12 object: 'luci2.network',
13 method: 'ping6',
14 params: [ 'data' ],
15 expect: { '': { code: -1 } }
16 }),
17
18 runTraceroute: L.rpc.declare({
19 object: 'luci2.network',
20 method: 'traceroute',
21 params: [ 'data' ],
22 expect: { '': { code: -1 } }
23 }),
24
25 runTraceroute6: L.rpc.declare({
26 object: 'luci2.network',
27 method: 'traceroute6',
28 params: [ 'data' ],
29 expect: { '': { code: -1 } }
30 }),
31
32 runNslookup: L.rpc.declare({
33 object: 'luci2.network',
34 method: 'nslookup',
35 params: [ 'data' ],
36 expect: { '': { code: -1 } }
37 }),
38
39 execute: function() {
40 var self = this;
41 var tools = [ ];
42
43 $.when(
44 self.runPing('?').then(function(rv) {
45 if (rv.code != -1) tools.push(['runPing', L.tr('IPv4 Ping')]);
46 }),
47 self.runPing6('?').then(function(rv) {
48 if (rv.code != -1) tools.push(['runPing6', L.tr('IPv6 Ping')]);
49 }),
50 self.runTraceroute('?').then(function(rv) {
51 if (rv.code != -1) tools.push(['runTraceroute', L.tr('IPv4 Traceroute')]);
52 }),
53 self.runTraceroute6('?').then(function(rv) {
54 if (rv.code != -1) tools.push(['runTraceroute6', L.tr('IPv6 Tracroute')]);
55 }),
56 self.runNslookup('?').then(function(rv) {
57 if (rv.code != -1) tools.push(['runNslookup', L.tr('DNS Lookup')]);
58 })
59 ).then(function() {
60 tools.sort(function(a, b) {
61 if (a[0] < b[0])
62 return -1;
63 else if (a[0] > b[0])
64 return 1;
65 else
66 return 0;
67 });
68
69 for (var i = 0; i < tools.length; i++)
70 $('#tool').append($('<option />').attr('value', tools[i][0]).text(tools[i][1]));
71
72 $('#tool').val('runPing');
73
74 $('#run').click(function() {
75 L.ui.loading(true);
76 self[$('#tool').val()]($('#host').val()).then(function(rv) {
77 $('#output').empty().show();
78
79 if (rv.stdout)
80 $('#output').text(rv.stdout);
81
82 if (rv.stderr)
83 $('#output').append($('<span />').css('color', 'red').text(rv.stderr));
84
85 L.ui.loading(false);
86 });
87 });
88 });
89 }
90 });