'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 SSH Tunnels.') .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('/root/.ssh/known_hosts') ), 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, '' + pub + '']); } return knownHostsMap; }