diff --git a/localization/en_US.inc b/localization/en_US.inc index dce76ee..b3a08f2 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -20,6 +20,8 @@ $labels['authentication_cancelled'] = 'Authentication cancelled'; $labels['test_key'] = 'Test key'; $labels['key_checked'] = 'Successfully checked key'; $labels['request_key_name'] = 'Please enter a name for this key'; +$labels['edit_key_name'] = 'Please enter a new name for key'; +$labels['key_renamed'] = 'Key renamed to'; // Messages used for the different portions of the plugin $messages = array(); diff --git a/localization/nl_NL.inc b/localization/nl_NL.inc index ab2e02f..7b7275a 100644 --- a/localization/nl_NL.inc +++ b/localization/nl_NL.inc @@ -20,6 +20,8 @@ $labels['authentication_cancelled'] = 'Authenticatie geannuleerd'; $labels['test_key'] = 'Sleutel testen'; $labels['key_checked'] = 'Sleutel gecontroleerd met ID'; $labels['request_key_name'] = 'Voer een naam in voor deze sleutel'; +$labels['edit_key_name'] = 'Voer een nieuwe naam in voor sleutel'; +$labels['key_renamed'] = 'Sleutel hernoemd naar'; // Messages used for the different portions of the plugin $messages = array(); diff --git a/settings.css b/settings.css index 5b51e36..750516a 100644 --- a/settings.css +++ b/settings.css @@ -1 +1,3 @@ -#twofactor_webauthn_keylist SPAN { font-size: 16px; color: red; cursor: pointer; margin-left: 5px; } +#twofactor_webauthn_keylist SPAN { font-size: 16px; cursor: pointer; margin-left: 5px; } +#twofactor_webauthn_keylist SPAN.rename { color: orange; } +#twofactor_webauthn_keylist SPAN.delete { color: red; } diff --git a/twofactor_webauthn.js b/twofactor_webauthn.js index bea82ff..d76da4d 100644 --- a/twofactor_webauthn.js +++ b/twofactor_webauthn.js @@ -1,6 +1,7 @@ if (window.rcmail) { rcmail.addEventListener('init', function(evt) { rcmail.register_command('plugin.twofactor_webauthn_prepare', twofactor_webauthn_prepare, true); + rcmail.register_command('plugin.twofactor_webauthn_rename', twofactor_webauthn_rename, true); rcmail.register_command('plugin.twofactor_webauthn_delete', twofactor_webauthn_delete, true); rcmail.register_command('plugin.twofactor_webauthn_save', twofactor_webauthn_save, true); rcmail.register_command('plugin.twofactor_webauthn_test', twofactor_webauthn_test); @@ -14,6 +15,9 @@ if (window.rcmail) { function twofactor_webauthn_prepare() { rcmail.http_post('plugin.twofactor_webauthn_prepare'); } +function twofactor_webauthn_rename(id, name) { + rcmail.http_post('plugin.twofactor_webauthn_rename', { id: id, name: name }); +} function twofactor_webauthn_delete(id) { rcmail.http_post('plugin.twofactor_webauthn_delete', { id: id }); } @@ -55,8 +59,11 @@ function twofactor_webauthn_list(data) { rcmail.enable_command('plugin.twofactor_webauthn_test', true); for (key of data) { ul.append('
  • ' + (key.name??key.id) + - ' '); + ' ' + + '' + ); } } diff --git a/twofactor_webauthn.php b/twofactor_webauthn.php index 5a667a4..1f6518d 100644 --- a/twofactor_webauthn.php +++ b/twofactor_webauthn.php @@ -27,6 +27,7 @@ function init() { $this->register_action('plugin.twofactor_webauthn_save', array($this, 'twofactor_webauthn_save')); $this->register_action('plugin.twofactor_webauthn_prepare', array($this, 'twofactor_webauthn_prepare')); $this->register_action('plugin.twofactor_webauthn_register', array($this, 'twofactor_webauthn_register')); + $this->register_action('plugin.twofactor_webauthn_rename', array($this, 'twofactor_webauthn_rename')); $this->register_action('plugin.twofactor_webauthn_delete', array($this, 'twofactor_webauthn_delete')); $this->register_action('plugin.twofactor_webauthn_test', array($this, 'twofactor_webauthn_test')); $this->register_action('plugin.twofactor_webauthn_check', array($this, 'twofactor_webauthn_check')); @@ -158,6 +159,31 @@ function twofactor_webauthn_register() { $rcmail->output->command('plugin.twofactor_webauthn_list', $this->getList($config)); } + function twofactor_webauthn_rename() { + $id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST); + if (empty($id)) { + error_log('Received empty id on webauthn rename'); + return; + } + $name = rcube_utils::get_input_value('name', rcube_utils::INPUT_POST); + if (empty($name)) { + error_log('Received empty name on webauthn rename'); + return; + } + $rcmail = rcmail::get_instance(); + $config = $this->getConfig(); + $keys = json_decode($config['keys']); + foreach ($keys as &$key) { + if (dechex(crc32(implode('', $key->id))) === $id) { + $key->name = $name; + } + } + $config['keys'] = json_encode($keys); + $this->saveConfig($config); + $rcmail->output->show_message($this->gettext('key_renamed') . ' ' . $name, 'confirmation'); + $rcmail->output->command('plugin.twofactor_webauthn_list', $this->getList($config)); + } + function twofactor_webauthn_delete() { $id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST); if (empty($id)) {