ssh_hosts.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. 'require form';
  3. 'require fs';
  4. 'require ui';
  5. 'require view';
  6. return view.extend({
  7. handleSaveApply: null,
  8. handleSave: null,
  9. handleReset: null,
  10. load: function () {
  11. return Promise.all([
  12. fs.lines('/root/.ssh/known_hosts'),
  13. ]);
  14. },
  15. render: function (data) {
  16. var knownHosts = data[0];
  17. var m, s, o;
  18. m = new form.Map('sshtunnel', _('SSH Tunnels'),
  19. _('This configures <a %s>SSH Tunnels</a>.')
  20. .format('href="https://openwrt.org/docs/guide-user/services/ssh/sshtunnel"')
  21. );
  22. s = m.section(form.GridSection, '_known_hosts');
  23. s.render = L.bind(_renderKnownHosts, this, knownHosts);
  24. return m.render();
  25. },
  26. });
  27. function _renderKnownHosts(knownHosts) {
  28. var table = E('table', {'class': 'table cbi-section-table', 'id': 'known_hosts'}, [
  29. E('tr', {'class': 'tr table-titles'}, [
  30. E('th', {'class': 'th'}, _('Hostname')),
  31. E('th', {'class': 'th'}, _('Public Key')),
  32. ])
  33. ]);
  34. var rows = _splitKnownHosts(knownHosts);
  35. cbi_update_table(table, rows);
  36. return E('div', {'class': 'cbi-section cbi-tblsection'}, [
  37. E('h3', _('Known hosts ')),
  38. E('div', {'class': 'cbi-section-descr'},
  39. _('Keys of SSH servers found in %s.').format('<code>/root/.ssh/known_hosts</code>')
  40. ),
  41. table
  42. ]);
  43. }
  44. function _splitKnownHosts(knownHosts) {
  45. var knownHostsMap = [];
  46. for (var i = 0; i < knownHosts.length; i++) {
  47. var sp = knownHosts[i].indexOf(' ');
  48. if (sp < 0) {
  49. continue;
  50. }
  51. var hostname = knownHosts[i].substring(0, sp);
  52. var pub = knownHosts[i].substring(sp + 1);
  53. knownHostsMap.push([hostname, '<small><code>' + pub + '</code></small>']);
  54. }
  55. return knownHostsMap;
  56. }