mirror of
https://github.com/openwrt/luci.git
synced 2026-04-15 10:51:51 +00:00
luci-app-sshtunnel: js linting fixes / ES6 treatment
Prevent variable bleed, and unused variables. Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@ LUCI_TITLE:=LuCI support for SSH Tunnels (sshtunnel package)
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_MAINTAINER:=Sergey Ponomarev <stokito@gmail.com>
|
||||
LUCI_DEPENDS:=+luci-base +sshtunnel
|
||||
PKG_VERSION:=1.1.0
|
||||
PKG_VERSION:=1.1.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
include ../../luci.mk
|
||||
|
||||
@@ -10,16 +10,14 @@ return view.extend({
|
||||
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>.')
|
||||
@@ -34,14 +32,14 @@ return view.extend({
|
||||
});
|
||||
|
||||
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'}, [
|
||||
@@ -54,14 +52,14 @@ function _renderKnownHosts(knownHosts) {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -4,25 +4,25 @@
|
||||
'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));
|
||||
}
|
||||
@@ -30,11 +30,11 @@ return view.extend({
|
||||
});
|
||||
},
|
||||
|
||||
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>.')
|
||||
@@ -49,12 +49,12 @@ return view.extend({
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -62,7 +62,7 @@ function _findAllPossibleIdKeys(entries) {
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
@@ -71,11 +71,11 @@ function _findAllPossibleIdKeys(entries) {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -83,17 +83,17 @@ function _splitSshKeys(sshFiles) {
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -131,7 +131,7 @@ function _renderSshKeys(sshKeys) {
|
||||
|
||||
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;
|
||||
@@ -160,8 +160,8 @@ function _handleKeyGenSubmit(event) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ function _loadPublicKey(sshPubKeyName) {
|
||||
.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);
|
||||
|
||||
@@ -6,15 +6,14 @@
|
||||
'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');
|
||||
}
|
||||
@@ -54,7 +53,7 @@ return view.extend({
|
||||
_manSshConfig('IdentityFile')
|
||||
);
|
||||
o.value('');
|
||||
for (var sshKeyName of sshKeyNames) {
|
||||
for (let sshKeyName of sshKeyNames) {
|
||||
o.value('/root/.ssh/' + sshKeyName, sshKeyName);
|
||||
}
|
||||
o.optional = true;
|
||||
@@ -140,12 +139,12 @@ return view.extend({
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -153,7 +152,7 @@ function _findAllPossibleIdKeys(entries) {
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
'require view';
|
||||
|
||||
return view.extend({
|
||||
load: function () {
|
||||
load() {
|
||||
return Promise.all([
|
||||
uci.load('sshtunnel'),
|
||||
]);
|
||||
},
|
||||
|
||||
render: function (data) {
|
||||
render() {
|
||||
let m, s, o;
|
||||
|
||||
m = new form.Map('sshtunnel', _('SSH Tunnels'),
|
||||
@@ -154,7 +154,7 @@ return view.extend({
|
||||
});
|
||||
|
||||
function _addServerOption(s) {
|
||||
var o = s.option(form.ListValue, 'server', _('Server'));
|
||||
const o = s.option(form.ListValue, 'server', _('Server'));
|
||||
o.datatype = 'uciname';
|
||||
o.rmempty = false;
|
||||
uci.sections('sshtunnel', 'server', function (s, sectionName) {
|
||||
|
||||
Reference in New Issue
Block a user