summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-libreswan/htdocs/luci-static/resources/view/libreswan/overview.js
blob: 61a2e4cbccce1f150f419c341962bd92b194e0d2 (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
'use strict';
'require view';
'require rpc';
'require form';
'require poll';

var callLibreswanStatus = rpc.declare({
	object: 'libreswan',
	method: 'status',
	expect: {  },
});

function secondsToString(seconds) {
	var str = '';
	var numdays = Math.floor(seconds / 86400);
	var numhours = Math.floor((seconds % 86400) / 3600);
	var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
	var numseconds = ((seconds % 86400) % 3600) % 60;

	str = (numdays ? numdays + 'd ' : '') + (numhours ? numhours + 'h ' : '') + (numminutes ? numminutes + 'm ' : '') +  numseconds + 's';
	return str;
}

return view.extend({
	render: function() {
		var table =
			E('table', { 'class': 'table lases' }, [
				E('tr', { 'class': 'tr table-titles' }, [
					E('th', { 'class': 'th' }, _('Name')),
					E('th', { 'class': 'th' }, _('Remote')),
					E('th', { 'class': 'th' }, _('Local Subnet')),
					E('th', { 'class': 'th' }, _('Remote Subnet')),
					E('th', { 'class': 'th' }, _('Tx')),
					E('th', { 'class': 'th' }, _('Rx')),
					E('th', { 'class': 'th' }, _('Phase1')),
					E('th', { 'class': 'th' }, _('Phase2')),
					E('th', { 'class': 'th' }, _('Status')),
					E('th', { 'class': 'th' }, _('Uptime')),
					E([])
				])
			]);

		poll.add(function() {
			return callLibreswanStatus().then(function(tunnelsInfo) {
				var tunnels = Array.isArray(tunnelsInfo.tunnels) ? tunnelsInfo.tunnels : [];

				cbi_update_table(table,
					tunnels.map(function(tunnel) {
						return  [
							tunnel.name,
							tunnel.right,
							tunnel.leftsubnet,
							tunnel.rightsubnet,
							tunnel.tx,
							tunnel.rx,
							tunnel.phase1 ? _('Up') : _('Down'),
							tunnel.phase2 ? _('Up') : _('Down'),
							tunnel.connected ? _('Up') : _('Down'),
							secondsToString(tunnel.uptime),
						];
					}),
					E('em', _('There are no active Tunnels'))
				);
			});
		});

		return E([
			E('h3', _('IPSec Tunnels Summary')),
			E('br'),
			table
		]);
	},

	handleSave: null,
	handleSaveApply:null,
	handleReset: null
});