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
|
'use strict';
'require form';
'require fs';
'require ui';
'require view';
return view.extend({
handleSaveApply: null,
handleSave: null,
handleReset: null,
load() {
return Promise.all([
fs.lines('/root/.ssh/known_hosts'),
]);
},
render([knownHosts]) {
let m, s;
m = new form.Map('sshtunnel', _('SSH Tunnels'),
_('This configures <a %s>SSH Tunnels</a>.')
.format('href="https://openwrt.org/docs/guide-user/services/ssh/sshtunnel"')
);
s = m.section(form.GridSection, '_known_hosts');
s.render = L.bind(_renderKnownHosts, this, knownHosts);
return m.render();
},
});
function _renderKnownHosts(knownHosts) {
const table = E('table', {'class': 'table cbi-section-table', 'id': 'known_hosts'}, [
E('tr', {'class': 'tr table-titles'}, [
E('th', {'class': 'th'}, _('Hostname')),
E('th', {'class': 'th'}, _('Public Key')),
])
]);
const rows = _splitKnownHosts(knownHosts);
cbi_update_table(table, rows);
return E('div', {'class': 'cbi-section cbi-tblsection'}, [
E('h3', _('Known hosts ')),
E('div', {'class': 'cbi-section-descr'},
_('Keys of SSH servers found in %s.').format('<code>/root/.ssh/known_hosts</code>')
),
table
]);
}
function _splitKnownHosts(knownHosts) {
const knownHostsMap = [];
for (let kh of knownHosts) {
const sp = kh.indexOf(' ');
if (sp < 0) {
continue;
}
const hostname = kh.substring(0, sp);
const pub = kh.substring(sp + 1);
knownHostsMap.push([hostname, '<small><code>' + pub + '</code></small>']);
}
return knownHostsMap;
}
|