luci-app-sshtunnel: generate a new key
authorSergey Ponomarev <stokito@gmail.com>
Sun, 17 Dec 2023 10:55:29 +0000 (12:55 +0200)
committerPaul Donald <newtwen@gmail.com>
Wed, 27 Dec 2023 20:29:19 +0000 (20:29 +0000)
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 <stokito@gmail.com>
(cherry picked from commit 3933633dd0de84b1c13af5d8f62b6b2431bf1ca7)

applications/luci-app-sshtunnel/htdocs/luci-static/resources/view/sshtunnel/ssh_keys.js

index 6c83454b0ded2211e93dc3ce675416be64b7f9df..4001404aadbc1ad9a1095bfd516e16d4197a7e94 100644 (file)
@@ -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 <a %s>System / Administration / SSH-Keys</a>')
                                .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'));