From 49c5091847577416bbbb6cfd0840aef96d59c837 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 17 Dec 2023 12:55:29 +0200 Subject: [PATCH] luci-app-sshtunnel: generate a new key Make the Generate a new key as a separate section and move to bottom. Extend the key name pattern to be an email address so allow symbols @ - +. Force the id_ prefix for key names. Signed-off-by: Sergey Ponomarev (cherry picked from commit 3933633dd0de84b1c13af5d8f62b6b2431bf1ca7) --- .../luci-static/resources/view/sshtunnel/ssh_keys.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 6c83454b0d..4001404aad 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 @@ -67,16 +67,17 @@ function _renderSshKeys(sshKeys) { cbi_update_table(table, rows, null); var keyGenBtn = E('div', {}, [ + E('h4', _('Generate a new key')), E('form', { 'submit': _handleKeyGenSubmit, }, [ - E('label', {}, _('Generate a new key') + ': '), + E('label', {}, _('Name') + ': '), E('span', {'class': 'control-group'}, [ E('input', { 'type': 'text', 'name': 'keyName', 'value': 'id_ed25519', - 'pattern': '^[a-zA-Z][a-zA-Z0-9_\.]+', + 'pattern': '^[a-zA-Z][a-zA-Z0-9_.@\\-+]+', 'required': 'required', 'maxsize': '35', 'autocomplete': 'off', @@ -97,13 +98,14 @@ function _renderSshKeys(sshKeys) { _('In LuCI you can do that with System / Administration / SSH-Keys') .format('href="/cgi-bin/luci/admin/system/admin/sshkeys"') ), - keyGenBtn, table + table, keyGenBtn, ]); } function _handleKeyGenSubmit(event) { event.preventDefault(); var keyName = document.querySelector('input[name="keyName"]').value; + keyName = keyName.startsWith('id_') ? keyName : 'id_' + keyName; if (allSshKeys[keyName]) { document.body.scrollTop = document.documentElement.scrollTop = 0; ui.addNotification(null, E('p', _('A key with that name already exists.'), 'error')); -- 2.30.2