diff options
| author | Carson Fleming <[email protected]> | 2024-12-30 20:40:48 -0800 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2024-12-30 20:40:48 -0800 |
| commit | 2a3c067a8595082558172ddf8e42414c32e7a688 (patch) | |
| tree | 1124165c93bab209cc5d1444ac92e8ec98874a95 | |
| parent | ac3f002d0e30add5067a381e8e82fb504e47ca11 (diff) | |
| download | rc-inbox-settings-2a3c067a8595082558172ddf8e42414c32e7a688.tar.gz | |
this seems sketchy but we ball
| -rw-r--r-- | config.inc.php.dist | 11 | ||||
| -rw-r--r-- | inbox_settings.php | 19 | ||||
| -rw-r--r-- | keys.js | 53 | ||||
| -rw-r--r-- | localization/en_US.inc | 2 |
4 files changed, 81 insertions, 4 deletions
diff --git a/config.inc.php.dist b/config.inc.php.dist index 394086b..20fe0e6 100644 --- a/config.inc.php.dist +++ b/config.inc.php.dist @@ -72,4 +72,15 @@ $config['inbox_settings_update_forwarder_query'] = 'UPDATE forwarders SET fwd_ad // %d - the domain part of the username // (in case the username is an email address) $config['inbox_settings_keys_query'] = 'SELECT id, fingerprint, comment FROM pgp_keys WHERE username = %u'; + +// The SQL query used to delete or deactivate a subset of a user's PGP keys. +// Supported replacement variables: +// %h - user's IMAP hostname +// %u - the username (from the session info) +// %l - the local part of the username +// (in case the username is an email address) +// %d - the domain part of the username +// (in case the username is an email address) +// %k - the key IDs being deleted +$config['inbox_settings_delete_keys_query'] = 'DELETE FROM pgp_keys WHERE id IN (%k) AND username = %u'; ?> diff --git a/inbox_settings.php b/inbox_settings.php index 2a720d1..a0b36b5 100644 --- a/inbox_settings.php +++ b/inbox_settings.php @@ -17,6 +17,7 @@ class inbox_settings extends rcube_plugin { $this->register_action('plugin.inbox_settings', [$this, 'render_settings_ui']); $this->register_action('plugin.inbox_keys', [$this, 'render_keys_ui']); + $this->register_action('plugin.inbox_keys_delete', [$this, 'delete_selected_keys']); } function scrub_encryption_preference($params) { @@ -90,6 +91,9 @@ class inbox_settings extends rcube_plugin { // info the js needs access to $this->rcmail->output->add_gui_object('keyslist', $attrib['id']); + $this->rcmail->output->add_label( + 'inbox_settings.confirm_delete_key', 'inbox_settings.deleting_key'); + // the js in question $this->rcmail->output->include_script('list.js'); $this->include_script('keys.js'); @@ -175,6 +179,12 @@ class inbox_settings extends rcube_plugin { return $page_content; } + function delete_selected_keys() { + run_query('delete_keys', $_POST['keys']); + $this->rcmail->output->set_pagetitle($this->gettext('deleting_key')); + $this->rcmail->output->send('plugin'); + } + private static function label_assoc_2d($data) { $labeled_data = []; foreach ($data as $row) { @@ -242,7 +252,7 @@ class inbox_settings extends rcube_plugin { $sql = str_replace('%h', $db->quote($host, 'text'), $sql); foreach ($substitutions as $key => $value) { - $sql = str_replace($key, $db->quote($value, 'text'), $sql); + $sql = str_replace($key, self::quote_replacement($db, $value), $sql); } $result = $db->query($sql); @@ -259,6 +269,13 @@ class inbox_settings extends rcube_plugin { return $ndresult; } + private static function quote_replacement($db, $value) { + if (!is_array($value)) return $db->quote($value, 'text'); + return '(' . implode(', ', array_map(function ($inner) { + return self::quote_replacement($db, $inner); + }, $value)) . ')'; + } + private static function parse_dsn($dsn) { if (strpos($dsn, '%')) { // parse DSN and replace variables in hostname @@ -6,13 +6,60 @@ window.rcmail && window.rcmail.addEventListener('init', function () { rcmail.gui_objects.keyslist, {multiselect: true, draggable: false, keyboard: true}); rcmail.inbox_keys_list - .addEventListener('select', - list => rcmail.enable_command( - 'plugin.inbox_keys_delete', list.get_selection().length > 0)) + .addEventListener('select', rcmail.inbox_keys_select) .addEventListener('keypress', list => rcmail.list_keypress(list, {del: 'plugin.inbox_keys_delete'})) .init() .focus(); } + + rcmail.register_command('plugin.inbox_keys_generate', rcmail.inbox_keys_generate); + rcmail.register_command('plugin.inbox_keys_import', rcmail.inbox_keys_import); + rcmail.register_command('plugin.inbox_keys_delete', rcmail.inbox_keys_delete); } }); + +rcube_webmail.prototype.inbox_keys_select = function (list) { + this.enable_command('plugin.inbox_keys_delete', list.get_selection().length > 0); +}; + +rcube_webmail.prototype.inbox_keys_generate = function () { + this.inbox_keys_reload('&_action=plugin.inbox_keys_generate'); +}; + +rcube_webmail.prototype.inbox_keys_import = function () { + this.inbox_keys_reload('&_action=plugin.inbox_keys_import'); +}; + +rcube_webmail.prototype.inbox_keys_delete = function () { + var keys = this.inbox_keys_list.get_selection(); + if (!keys.length) return; + + this.confirm_dialog( + this.get_label('inbox_settings.confirm_delete_key'), + 'delete', + function (_evt, ref) { + var lock = ref.display_message( + ref.get_label('inbox_settings.deleting_key', 'loading')); + ref.http_post('plugin.inbox_keys_delete', {keys}, lock); + // TODO: maybe reload + }); +}; + +rcube_webmail.prototype.inbox_keys_reload = function(url) { + var win; + if (win = this.get_frame_window(this.env.contentframe)) { + if (!url) { + if (win.location && win.location.href.indexOf(this.env.blankpage) < 0) { + win.location.href = this.env.blankpage; + } + if (this.env.frame_lock) { + this.set_busy(false, null, this.env.frame_lock); + } + return; + } + + this.env.frame_lock = this.set_busy(true, 'loading'); + win.location.href = this.env.comm_path + '&_framed=1' + url; + } +}; diff --git a/localization/en_US.inc b/localization/en_US.inc index 92be566..7acf909 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -15,4 +15,6 @@ $labels['key_delete'] = 'Delete Key'; $labels['no_keys'] = 'There are no encryption keys associated with your account yet.'; $labels['fingerprint'] = 'Key Fingerprint'; $labels['comment'] = 'Comment'; +$labels['confirm_delete_key'] = 'Are you sure you want to remove this encryption key from your account?'; +$labels['deleting_key'] = 'Removing encryption key...'; ?> |
