summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Donald2026-02-16 01:15:30 +0000
committerPaul Donald2026-02-20 02:56:04 +0000
commitc25c0be66d47c3190070d586a901bba57cd62b32 (patch)
tree2653cc9e2244f216666f2a211b22a0a4282495e8
parent9e21e74888a4504729f0c375ab831eb69f8d255c (diff)
downloadluci-c25c0be66d47c3190070d586a901bba57cd62b32.tar.gz
luci-app-sshtunnel: js linting fixes / ES6 treatment
Prevent variable bleed, and unused variables. Signed-off-by: Paul Donald <newtwen+github@gmail.com>
-rw-r--r--applications/luci-app-sshtunnel/Makefile2
-rw-r--r--applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_hosts.js22
-rw-r--r--applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js52
-rw-r--r--applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_servers.js19
-rw-r--r--applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_tunnels.js6
5 files changed, 49 insertions, 52 deletions
diff --git a/applications/luci-app-sshtunnel/Makefile b/applications/luci-app-sshtunnel/Makefile
index ad537155b0..5dc875c160 100644
--- a/applications/luci-app-sshtunnel/Makefile
+++ b/applications/luci-app-sshtunnel/Makefile
@@ -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
diff --git a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_hosts.js b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_hosts.js
index 0313e8024a..9ed9e491cb 100644
--- a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_hosts.js
+++ b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_hosts.js
@@ -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;
diff --git a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js
index 54576b8bff..9d9af5fb1d 100644
--- a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js
+++ b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js
@@ -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);
diff --git a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_servers.js b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_servers.js
index a21868f1ee..c7a88831d1 100644
--- a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_servers.js
+++ b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_servers.js
@@ -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);
}
}
diff --git a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_tunnels.js b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_tunnels.js
index 9f1ad83094..3ccd4969ef 100644
--- a/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_tunnels.js
+++ b/applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_tunnels.js
@@ -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) {