handleSave: null,
handleReset: null,
- load: function () {
+ load() {
return Promise.all([
fs.lines('/root/.ssh/known_hosts'),
]);
},
- render: function (data) {
- var knownHosts = data[0];
-
- let m, s, o;
+ render([knownHosts]) {
+ let m, s;
m = new form.Map('sshtunnel', _('SSH Tunnels'),
_('This configures <a %s>SSH Tunnels</a>.')
});
function _renderKnownHosts(knownHosts) {
- var table = E('table', {'class': 'table cbi-section-table', 'id': 'known_hosts'}, [
+ 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')),
])
]);
- var rows = _splitKnownHosts(knownHosts);
+ const rows = _splitKnownHosts(knownHosts);
cbi_update_table(table, rows);
return E('div', {'class': 'cbi-section cbi-tblsection'}, [
}
function _splitKnownHosts(knownHosts) {
- var knownHostsMap = [];
- for (var i = 0; i < knownHosts.length; i++) {
- var sp = knownHosts[i].indexOf(' ');
+ const knownHostsMap = [];
+ for (let kh of knownHosts) {
+ const sp = kh.indexOf(' ');
if (sp < 0) {
continue;
}
- var hostname = knownHosts[i].substring(0, sp);
- var pub = knownHosts[i].substring(sp + 1);
+ const hostname = kh.substring(0, sp);
+ const pub = kh.substring(sp + 1);
knownHostsMap.push([hostname, '<small><code>' + pub + '</code></small>']);
}
return knownHostsMap;
'require ui';
'require view';
-var allSshKeys = {};
-var hasSshKeygen = false;
+let allSshKeys = {};
+let hasSshKeygen = false;
return view.extend({
handleSaveApply: null,
handleSave: null,
handleReset: null,
- load: function () {
+ load() {
return L.resolveDefault(fs.list('/root/.ssh/'), []).then(function (entries) {
- var tasks = [
+ const tasks = [
// detect if OpenSSH ssh-keygen is installed
L.resolveDefault(fs.stat('/usr/bin/ssh-keygen'), {}),
];
- var sshKeyNames = _findAllPossibleIdKeys(entries);
+ const sshKeyNames = _findAllPossibleIdKeys(entries);
// read pub keys
- for (var sshKeyName of sshKeyNames) {
- var sshPubKeyName = sshKeyName + '.pub';
+ for (let sshKeyName of sshKeyNames) {
+ const sshPubKeyName = sshKeyName + '.pub';
tasks.push(Promise.resolve(sshKeyName));
tasks.push(_loadPublicKey(sshPubKeyName));
}
});
},
- render: function (data) {
+ render(data) {
hasSshKeygen = data[0].type === 'file';
- var sshKeys = _splitSshKeys(data.splice(1));
+ const sshKeys = _splitSshKeys(data.splice(1));
- let m, s, o;
+ let m, s;
m = new form.Map('sshtunnel', _('SSH Tunnels'),
_('This configures <a %s>SSH Tunnels</a>.')
});
function _findAllPossibleIdKeys(entries) {
- var sshKeyNames = new Set();
- var fileNames = entries.filter(item => item.type === 'file').map(item => item.name);
- for (var fileName of fileNames) {
+ const sshKeyNames = new Set();
+ const fileNames = entries.filter(item => item.type === 'file').map(item => item.name);
+ for (let fileName of fileNames) {
// a key file should have a corresponding .pub file
if (fileName.endsWith('.pub')) {
- var sshKeyName = fileName.slice(0, -4);
+ const sshKeyName = fileName.slice(0, -4);
// if such a key exists then add it
if (fileNames.includes(sshKeyName)) {
sshKeyNames.add(sshKeyName);
} else {
// or at least it should start with id_ e.g. id_dropbear
if (fileName.startsWith('id_')) {
- var sshKeyName = fileName;
+ const sshKeyName = fileName;
sshKeyNames.add(sshKeyName);
}
}
}
function _splitSshKeys(sshFiles) {
- var sshKeys = {};
- for (var i = 0; i < sshFiles.length; i++) {
- var sshKeyName = sshFiles[i];
+ const sshKeys = {};
+ for (let i = 0; i < sshFiles.length; i++) {
+ const sshKeyName = sshFiles[i];
i++; // next is a .pub content
- var sshPub = sshFiles[i];
+ const sshPub = sshFiles[i];
sshKeys[sshKeyName] = '<small><code>' + sshPub + '</code></small>';
}
allSshKeys = sshKeys;
}
function _renderSshKeys(sshKeys) {
- var table = E('table', {'class': 'table cbi-section-table', 'id': 'keys_table'}, [
+ const table = E('table', {'class': 'table cbi-section-table', 'id': 'keys_table'}, [
E('tr', {'class': 'tr table-titles'}, [
E('th', {'class': 'th'}, _('Name')),
E('th', {'class': 'th'}, _('Public Key')),
])
]);
- var rows = Object.entries(sshKeys);
+ const rows = Object.entries(sshKeys);
cbi_update_table(table, rows, null);
- var keyGenBtn = E('div', {}, [
+ const keyGenBtn = E('div', {}, [
E('h4', _('Generate a new key')),
E('form', {
'submit': _handleKeyGenSubmit,
function _handleKeyGenSubmit(event) {
event.preventDefault();
- var keyName = document.querySelector('input[name="keyName"]').value;
+ let keyName = document.querySelector('input[name="keyName"]').value;
keyName = keyName.startsWith('id_') ? keyName : 'id_' + keyName;
if (allSshKeys[keyName]) {
document.body.scrollTop = document.documentElement.scrollTop = 0;
}
function _extractPubKeyFromOutput(res) {
- var lines = res.stdout.split('\n');
- for (var line of lines) {
+ const lines = res.stdout.split('\n');
+ for (let line of lines) {
if (line.startsWith('ssh-')) {
return line;
}
.catch(() => {
// If there is no the .pub file then this is probably a Dropbear key e.g. id_dropbear.
// We can extract it's public key by executing: dropbearkey -y -f /root/.ssh/id_dropbear
- var sshKeyName = sshPubKeyName.substring(0, sshPubKeyName.length - 4);
+ const sshKeyName = sshPubKeyName.substring(0, sshPubKeyName.length - 4);
return fs.exec('/usr/bin/dropbearkey', ['-y', '-f', '/root/.ssh/' + sshKeyName]).then((res) => {
if (res.code === 0) {
return _extractPubKeyFromOutput(res);
'require view';
return view.extend({
- load: function () {
+ load() {
return L.resolveDefault(fs.list('/root/.ssh/'), []).then(function (entries) {
- var sshKeyNames = _findAllPossibleIdKeys(entries);
+ const sshKeyNames = _findAllPossibleIdKeys(entries);
return Promise.resolve(sshKeyNames);
});
},
- render: function (data) {
- var sshKeyNames = data;
+ render([sshKeyNames]) {
if (sshKeyNames.length === 0) {
ui.addNotification(null, E('p', _('No SSH keys found, <a %s>generate a new one</a>').format('href="./ssh_keys"')), 'warning');
}
_manSshConfig('IdentityFile')
);
o.value('');
- for (var sshKeyName of sshKeyNames) {
+ for (let sshKeyName of sshKeyNames) {
o.value('/root/.ssh/' + sshKeyName, sshKeyName);
}
o.optional = true;
});
function _findAllPossibleIdKeys(entries) {
- var sshKeyNames = new Set();
- var fileNames = entries.filter(item => item.type === 'file').map(item => item.name);
- for (var fileName of fileNames) {
+ const sshKeyNames = new Set();
+ const fileNames = entries.filter(item => item.type === 'file').map(item => item.name);
+ for (let fileName of fileNames) {
// a key file should have a corresponding .pub file
if (fileName.endsWith('.pub')) {
- var sshKeyName = fileName.slice(0, -4);
+ let sshKeyName = fileName.slice(0, -4);
// if such a key exists then add it
if (fileNames.includes(sshKeyName)) {
sshKeyNames.add(sshKeyName);
} else {
// or at least it should start with id_ e.g. id_dropbear
if (fileName.startsWith('id_')) {
- var sshKeyName = fileName;
+ let sshKeyName = fileName;
sshKeyNames.add(sshKeyName);
}
}