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
|
'use strict';
'require view';
'require rpc';
'require form';
'require poll';
var callLibreswanStatus = rpc.declare({
object: 'libreswan',
method: 'status',
expect: { },
});
function secondsToString(seconds) {
const numdays = Math.floor(seconds / 86400);
seconds %= 86400;
const numhours = Math.floor(seconds / 3600);
seconds %= 3600;
const numminutes = Math.floor(seconds / 60);
const numseconds = seconds % 60;
return [
numdays ? `${numdays}d` : '',
numhours ? `${numhours}h` : '',
numminutes ? `${numminutes}m` : '',
`${numseconds}s`
].filter(Boolean).join(' ');
}
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
});
|