From: Michael M Slusarz Date: Wed, 3 Mar 2010 20:15:30 +0000 (-0700) Subject: Move passphrase dialog processing to Imple X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=394db44eac3455025e4b6c95b5637a5cbf8eefb9;p=horde.git Move passphrase dialog processing to Imple --- diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 70752ef85..5f08e10de 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1256,123 +1256,6 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base } /** - * AJAX action: Process a user-supplied PGP symmetric passphrase. - * - * Variables used: - *
-     * 'dialog_input' - (string) Input from the dialog screen.
-     * 'symmetricid' - (string) The symmetric ID to process.
-     * 
- * - * @return object An object with the following entries: - *
-     * 'error' - (string) An error message.
-     * 'success' - (integer) 1 on success, 0 on failure.
-     * 
- */ - public function pgpSymmetric() - { - $result = new stdClass; - $result->success = 0; - - try { - $imp_pgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); - Horde::requireSecureConnection(); - if ($this->_vars->dialog_input) { - if ($imp_pgp->storePassphrase('symmetric', $this->_vars->dialog_input, $this->_vars->symmetricid)) { - $result->success = 1; - } else { - $result->error = _("Invalid passphrase entered."); - } - } else { - $result->error = _("No passphrase entered."); - } - } catch (Horde_Exception $e) { - $result->error = $e->getMessage(); - } - - return $result; - } - - /** - * AJAX action: Process a user-supplied passphrase for the PGP personal - * key. - * - * Variables used: - *
-     * 'dialog_input' - (string) Input from the dialog screen.
-     * 
- * - * @return object An object with the following entries: - *
-     * 'error' - (string) An error message.
-     * 'success' - (integer) 1 on success, 0 on failure.
-     * 
- */ - public function pgpPersonal() - { - $result = new stdClass; - $result->success = false; - - try { - $imp_pgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); - Horde::requireSecureConnection(); - if ($this->_vars->dialog_input) { - if ($imp_pgp->storePassphrase('personal', $this->_vars->dialog_input)) { - $result->success = 1; - } else { - $result->error = _("Invalid passphrase entered."); - } - } else { - $result->error = _("No passphrase entered."); - } - } catch (Horde_Exception $e) { - $result->error = $e->getMessage(); - } - - return $result; - } - - /** - * AJAX action: Process a user-supplied passphrase for the S/MIME - * personal key. - * - * Variables used: - *
-     * 'dialog_input' - (string) Input from the dialog screen.
-     * 
- * - * @return object An object with the following entries: - *
-     * 'error' - (string) An error message.
-     * 'success' - (integer) 1 on success, 0 on failure.
-     * 
- */ - public function smimePersonal() - { - $result = new stdClass; - $result->success = false; - - try { - $imp_smime = Horde_Crypt::singleton(array('IMP', 'Smime')); - Horde::requireSecureConnection(); - if ($this->_vars->dialog_input) { - if ($imp_smime->storePassphrase($this->_vars->dialog_input)) { - $result->success = 1; - } else { - $result->error = _("Invalid passphrase entered."); - } - } else { - $result->error = _("No passphrase entered."); - } - } catch (Horde_Exception $e) { - $result->error = $e->getMessage(); - } - - return $result; - } - - /** * AJAX action: Add an attachment to a compose message. * * Variables used: diff --git a/imp/lib/Ajax/Imple/PassphraseDialog.php b/imp/lib/Ajax/Imple/PassphraseDialog.php new file mode 100644 index 000000000..43e5b09f7 --- /dev/null +++ b/imp/lib/Ajax/Imple/PassphraseDialog.php @@ -0,0 +1,180 @@ + + * @package IMP + */ +class IMP_Ajax_Imple_PassphraseDialog extends Horde_Ajax_Imple_Base +{ + /** + * Passphrase DOM ID counter. + * + * @var integer + */ + static protected $_passphraseId = 0; + + /** + * The passphrase ID used by this instance. + * + * @var string + */ + protected $_domid; + + /** + * Constructor. + * + * @param array $params Configuration parameters. + *
+     * 'id' - [OPTIONAL] The DOM ID to attach to.
+     * 'onload' - (boolean) [OPTIONAL] If set, will trigger action on page
+     *            load.
+     * 'params' - (array) [OPTIONAL] Any additional parameters to pass.
+     * 'type' - (string) The dialog type.
+     * 
+ */ + public function __construct($params) + { + if (!isset($params['id'])) { + $params['id'] = 'imp_passphrase_' . ++self::$_passphraseId; + } + + $this->_domid = $params['id']; + + parent::__construct($params); + } + + /** + * Attach the object to a javascript event. + */ + public function attach() + { + $params = isset($this->_params['params']) + ? $this->_params['params'] + : array(); + $params['type'] = $this->_params['type']; + + switch ($this->_params['type']) { + case 'pgpPersonal': + $text = _("Enter your personal PGP passphrase."); + break; + + case 'pgpSymmetric': + $text = _("Enter the passphrase used to encrypt this message."); + break; + + case 'smimePersonal': + $text = _("Enter your personal S/MIME passphrase."); + break; + } + + if (defined('SID')) { + parse_str(SID, $sid); + $params = array_merge($params, $sid); + } + + $js_params = array( + 'cancel_text' => _("Cancel"), + 'ok_text' => _("OK"), + 'params' => $params, + 'password' => true, + 'text' => $text, + 'type' => $this->_params['type'], + 'uri' => strval($this->_getUrl('PassphraseDialog', 'imp')) + ); + + Horde::addScriptFile('effects.js', 'horde'); + Horde::addScriptFile('redbox.js', 'horde'); + Horde::addScriptFile('dialog.js', 'imp'); + + $js = 'IMPDialog.display(' . Horde::escapeJson($js_params, array('urlencode' => true)) . ');'; + + if (empty($this->_params['onload'])) { + $js = '$("' . $this->_domid . '").observe("click", function(e) { ' . $js . 'e.stop(); })'; + } + + Horde::addInlineScript(array($js), 'dom'); + } + + /** + * Perform the given action. + * + * Variables required in form input: + *
+     * 'dialog_input' - (string) Input from the dialog screen.
+     * 'symmetricid' - (string) The symmetric ID to process.
+     * 
+ * + * @param array $args Not used. + * @param array $post Not used. + * + * @return object An object with the following entries: + *
+     * 'error' - (string) An error message.
+     * 'success' - (integer) 1 on success, 0 on failure.
+     * 
+ */ + public function handle($args, $post) + { + $result = new stdClass; + $result->success = 0; + + $vars = Horde_Variables::getDefaultVariables(); + + try { + Horde::requireSecureConnection(); + + switch ($vars->type) { + case 'pgpPersonal': + case 'pgpSymmetric': + if ($this->_vars->dialog_input) { + $imp_pgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); + if ((($vars->type == 'pgpPersonal') && + $imp_pgp->storePassphrase('personal', $this->_vars->dialog_input)) || + (($vars->type == 'pgpSymmeetric') && + $imp_pgp->storePassphrase('symmetric', $this->_vars->dialog_input, $this->_vars->symmetricid))) { + $result->success = 1; + } else { + $result->error = _("Invalid passphrase entered."); + } + } else { + $result->error = _("No passphrase entered."); + } + break; + + case 'smimePersonal': + if ($this->_vars->dialog_input) { + $imp_smime = Horde_Crypt::singleton(array('IMP', 'Smime')); + if ($imp_smime->storePassphrase($this->_vars->dialog_input)) { + $result->success = 1; + } else { + $result->error = _("Invalid passphrase entered."); + } + } else { + $result->error = _("No passphrase entered."); + } + break; + } + } catch (Horde_Exception $e) { + $result->error = $e->getMessage(); + } + + return $result; + } + + /** + * Generates a unique DOM ID. + * + * @return string A unique DOM ID. + */ + public function getPassphraseId() + { + return $this->_domid; + } + +} diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 59c45a514..ebdbfc5f4 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1051,53 +1051,6 @@ class IMP } /** - * Generate the JS code necessary to open a passphrase dialog. Adds the - * necessary JS files to open the dialog. - * - * @param string $type The dialog type. - * @param array $params Any additional parameters to pass. - * - * @return string The generated JS code. - */ - static public function passphraseDialogJS($type, $params = array()) - { - Horde::addScriptFile('effects.js', 'horde'); - Horde::addScriptFile('redbox.js', 'horde'); - Horde::addScriptFile('dialog.js', 'imp'); - - switch ($type) { - case 'pgpPersonal': - $text = _("Enter your personal PGP passphrase."); - break; - - case 'pgpSymmetric': - $text = _("Enter the passphrase used to encrypt this message."); - break; - - case 'smimePersonal': - $text = _("Enter your personal S/MIME passphrase."); - break; - } - - if (defined('SID')) { - parse_str(SID, $sid); - $params = array_merge($params, $sid); - } - - $js_params = array( - 'cancel_text' => _("Cancel"), - 'ok_text' => _("OK"), - 'params' => $params, - 'password' => true, - 'text' => $text, - 'type' => $type, - 'uri' => Horde::getServiceLink('ajax', 'imp') . '/' . $type - ); - - return 'IMPDialog.display(' . Horde::escapeJson($js_params, array('urlencode' => true)) . ')'; - } - - /** * Return a selfURL that has had index/mailbox/actionID information * removed/altered based on an action that has occurred on the present * page. @@ -1190,5 +1143,4 @@ class IMP return 'RedBox.overlay = false; RedBox.showHtml(\'' . addcslashes($t_html, "'/") . '\');'; } - } diff --git a/imp/lib/Mime/Viewer/Pgp.php b/imp/lib/Mime/Viewer/Pgp.php index 5ec351d11..3d2311f51 100644 --- a/imp/lib/Mime/Viewer/Pgp.php +++ b/imp/lib/Mime/Viewer/Pgp.php @@ -222,8 +222,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver /* Ask for the correct passphrase if this is encrypted * symmetrically. */ - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('pgpSymmetric', array('symmetricid' => $symmetric_id)) . ';return false;') . _("You must enter the passphrase used to encrypt this message to view it.") . ''; - + $imple = Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('params' => array('symmetricid' => $symmetric_id), 'type' => 'pgpSymmetric')); + $imple->attach(); + $status[] = Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getPassphraseId())) . _("You must enter the passphrase used to encrypt this message to view it.") . ''; return null; } } @@ -252,7 +253,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver if (is_null($personal_pass)) { /* Ask for the private key's passphrase if this is * encrypted asymmetrically. */ - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('pgpPersonal') . ';return false;') . _("You must enter the passphrase for your PGP private key to view this message.") . ''; + $imple = Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('type' => 'pgpPersonal')); + $imple->attach(); + $status[] = Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getPassphraseId())) . _("You must enter the passphrase for your PGP private key to view this message.") . ''; return null; } } else { diff --git a/imp/lib/Mime/Viewer/Smime.php b/imp/lib/Mime/Viewer/Smime.php index b3cc1f377..8f0704b5c 100644 --- a/imp/lib/Mime/Viewer/Smime.php +++ b/imp/lib/Mime/Viewer/Smime.php @@ -195,7 +195,9 @@ class IMP_Horde_Mime_Viewer_Smime extends Horde_Mime_Viewer_Driver /* Make sure we have a passphrase. */ $passphrase = $this->_impsmime->getPassphrase(); if (is_null($passphrase)) { - $status[] = Horde::link('#', '', '', '', IMP::passphraseDialogJS('smimePersonal') . ';return false;') . _("You must enter the passphrase for your S/MIME private key to view this data.") . ''; + $imple = Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('type' => 'smimePersonal')); + $imple->attach(); + $status[] = Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getPassphraseId())) . _("You must enter the passphrase for your S/MIME private key to view this data.") . ''; return null; } diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index fa794b263..5dc5b8def 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -301,21 +301,24 @@ class IMP_Ui_Compose */ public function passphraseDialog($type, $cacheid = null) { + $params = array('onload' => true); + switch ($type) { case 'pgp': - $js = IMP::passphraseDialogJS('pgpPersonal'); + $type = 'pgpPersonal'; break; case 'pgp_symm': - $js = IMP::passphraseDialogJS('pgpSymmetric', array('symmetricid' => 'imp_compose_' . $cacheid)); + $params = array('symmetricid' => 'imp_compose_' . $cacheid); + $type = 'pgpSymmetric'; break; case 'smime': - $js = IMP::passphraseDialogJS('smimePersonal'); + $type = 'smimePersonal'; break; } - Horde::addInlineScript(array($js), 'dom'); + Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('params' => $params, 'type' => $type))->attach(); } /** diff --git a/imp/pgp.php b/imp/pgp.php index f8bdd4e28..74102917d 100644 --- a/imp/pgp.php +++ b/imp/pgp.php @@ -291,8 +291,12 @@ if ($prefs->getValue('use_pgp')) { $t->set('infopublic', Horde::link($selfURL->copy()->add('actionID', 'info_personal_public_key'), _("Information on Personal Public Key"), null, 'info_key')); $t->set('sendkey', Horde::link($selfURL->copy()->add('actionID', 'send_public_key'), _("Send Key to Public Keyserver"))); $t->set('personalkey-public-help', Horde_Help::link('imp', 'pgp-personalkey-public')); + + $imple = Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('type' => 'pgpPersonal')); + $imple->attach(); $passphrase = $imp_pgp->getPassphrase('personal'); - $t->set('passphrase', (empty($passphrase)) ? Horde::link('#', _("Enter Passphrase"), null, null, IMP::passphraseDialogJS('pgpPersonal') . ';return false;') . _("Enter Passphrase") : Horde::link($selfURL->copy()->add('actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase")); + $t->set('passphrase', (empty($passphrase)) ? Horde::link('#', _("Enter Passphrase"), null, null, null, null, null, array('id' => $imple->getPassphraseId())) . _("Enter Passphrase") : Horde::link($selfURL->copy()->add('actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase")); + $t->set('viewprivate', Horde::link($selfURL->copy()->add('actionID', 'view_personal_private_key'), _("View Personal Private Key"), null, 'view_key')); $t->set('infoprivate', Horde::link($selfURL->copy()->add('actionID', 'info_personal_private_key'), _("Information on Personal Private Key"), null, 'info_key')); $t->set('personalkey-private-help', Horde_Help::link('imp', 'pgp-personalkey-private')); diff --git a/imp/smime.php b/imp/smime.php index 74f7ff5cb..c8737d1e5 100644 --- a/imp/smime.php +++ b/imp/smime.php @@ -202,8 +202,11 @@ if ($openssl_check && $prefs->getValue('use_smime')) { if ($t->get('has_key')) { $t->set('viewpublic', Horde::link($selfURL->copy()->add('actionID', 'view_personal_public_key'), _("View Personal Public Key"), null, 'view_key')); $t->set('infopublic', Horde::link($selfURL->copy()->add('actionID', 'info_personal_public_key'), _("Information on Personal Public Key"), null, 'info_key')); + $imple = Horde_Ajax_Imple::factory(array('imp', 'PassphraseDialog'), array('type' => 'smimePersonal')); + $imple->attach(); $passphrase = $imp_smime->getPassphrase(); - $t->set('passphrase', empty($passphrase) ? Horde::link('#', _("Enter Passphrase"), null, null, IMP::passphraseDialogJS('smimePersonal') . ';return false;') . _("Enter Passphrase") : Horde::link($selfURL->copy()->add('actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase")); + $t->set('passphrase', (empty($passphrase)) ? Horde::link('#', _("Enter Passphrase"), null, null, null, null, null, array('id' => $imple->getPassphraseId())) . _("Enter Passphrase") : Horde::link($selfURL->copy()->add('actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase")); + $t->set('viewprivate', Horde::link($selfURL->copy()->add('actionID', 'view_personal_private_key'), _("View Personal Private Key"), null, 'view_key')); $t->set('deletekeypair', addslashes(_("Are you sure you want to delete your keypair? (This is NOT recommended!)"))); $t->set('personalkey-delete-help', Horde_Help::link('imp', 'smime-delete-personal-certs'));