summaryrefslogtreecommitdiff
path: root/luci2/htdocs/luci2/view/network.diagnostics.js
blob: 16492640fc1c540f2e0440e2bc4430be073cf038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
L.ui.view.extend({
	title: L.tr('Diagnostics'),

	runPing: L.rpc.declare({
		object: 'luci2.network',
		method: 'ping',
		params: [ 'data' ],
		expect: { '': { code: -1 } }
	}),

	runPing6: L.rpc.declare({
		object: 'luci2.network',
		method: 'ping6',
		params: [ 'data' ],
		expect: { '': { code: -1 } }
	}),

	runTraceroute: L.rpc.declare({
		object: 'luci2.network',
		method: 'traceroute',
		params: [ 'data' ],
		expect: { '': { code: -1 } }
	}),

	runTraceroute6: L.rpc.declare({
		object: 'luci2.network',
		method: 'traceroute6',
		params: [ 'data' ],
		expect: { '': { code: -1 } }
	}),

	runNslookup: L.rpc.declare({
		object: 'luci2.network',
		method: 'nslookup',
		params: [ 'data' ],
		expect: { '': { code: -1 } }
	}),

	execute: function() {
		var self = this;
		var tools = [ ];

		$.when(
			self.runPing('?').then(function(rv) {
				if (rv.code != -1) tools.push(['runPing', L.tr('IPv4 Ping')]);
			}),
			self.runPing6('?').then(function(rv) {
				if (rv.code != -1) tools.push(['runPing6', L.tr('IPv6 Ping')]);
			}),
			self.runTraceroute('?').then(function(rv) {
				if (rv.code != -1) tools.push(['runTraceroute', L.tr('IPv4 Traceroute')]);
			}),
			self.runTraceroute6('?').then(function(rv) {
				if (rv.code != -1) tools.push(['runTraceroute6', L.tr('IPv6 Tracroute')]);
			}),
			self.runNslookup('?').then(function(rv) {
				if (rv.code != -1) tools.push(['runNslookup', L.tr('DNS Lookup')]);
			})
		).then(function() {
			tools.sort(function(a, b) {
				if (a[0] < b[0])
					return -1;
				else if (a[0] > b[0])
					return 1;
				else
					return 0;
			});

			for (var i = 0; i < tools.length; i++)
				$('#tool').append($('<option />').attr('value', tools[i][0]).text(tools[i][1]));

			$('#tool').val('runPing');

			$('#run').click(function() {
				L.ui.loading(true);
				self[$('#tool').val()]($('#host').val()).then(function(rv) {
					$('#output').empty().show();

					if (rv.stdout)
						$('#output').text(rv.stdout);

					if (rv.stderr)
						$('#output').append($('<span />').css('color', 'red').text(rv.stderr));

					L.ui.loading(false);
				});
			});
		});
	}
});