저자: Michael Slusarz (slusarz@horde.org)
예제 #1
0
파일: Ui.php 프로젝트: horde/horde
 /**
  * Return a list of valid encrypt HTML option tags.
  *
  * @param string $default      The default encrypt option.
  * @param boolean $returnList  Whether to return a hash with options
  *                             instead of the options tag.
  *
  * @return mixed  The list of option tags. This is empty if no encryption
  *                is available.
  */
 public function encryptList($default = null, $returnList = false)
 {
     global $injector, $prefs;
     if (is_null($default)) {
         $default = $prefs->getValue('default_encrypt');
     }
     $enc_opts = array();
     $output = '';
     if (IMP_Pgp::enabled()) {
         $enc_opts += $injector->getInstance('IMP_Pgp')->encryptList();
     }
     if (IMP_Smime::enabled()) {
         $enc_opts += $injector->getInstance('IMP_Smime')->encryptList();
     }
     if (!empty($enc_opts)) {
         $enc_opts = array_merge(array(IMP::ENCRYPT_NONE => _("None")), $enc_opts);
     }
     if ($returnList) {
         return $enc_opts;
     }
     foreach ($enc_opts as $key => $val) {
         $output .= '<option value="' . $key . '"' . ($default == $key ? ' selected="selected"' : '') . '>' . $val . "</option>\n";
     }
     return $output;
 }
예제 #2
0
파일: Compose.php 프로젝트: horde/horde
 /**
  * Constructor.
  */
 public function __construct()
 {
     global $page_output, $prefs, $registry;
     $this->_files[] = new Horde_Script_File_JsDir('compose.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('draghandler.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('editor.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('imp.js', 'imp');
     if (!$prefs->isLocked('default_encrypt') && (IMP_Pgp::enabled() || IMP_Smime::enabled())) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
         $this->_files[] = new Horde_Script_File_JsDir('passphrase.js', 'imp');
     }
     if (!IMP_Compose::canHtmlCompose()) {
         return;
     }
     switch ($registry->getView()) {
         case $registry::VIEW_BASIC:
         case $registry::VIEW_DYNAMIC:
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/imageupload.js', 'imp');
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/images.js', 'imp');
             $page_output->addInlineJsVars(array('ImpCkeditorImgs.related_attr' => IMP_Compose::RELATED_ATTR));
             $js = new Horde_Script_File_JsDir('ckeditor/pasteattachment.js', 'imp');
             $upload_url = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachmentCkeditor';
             $page_output->addInlineScript(array('if (window.CKEDITOR) { CKEDITOR.on("loaded", function(e) {' . 'CKEDITOR.plugins.addExternal("pasteattachment", "' . $js->url->url . '", "");' . 'CKEDITOR.config.filebrowserImageUploadUrl = "' . $upload_url . '";' . '}); };'), true);
             break;
     }
 }
예제 #3
0
파일: Pgp.php 프로젝트: horde/horde
 /**
  * Print PGP Key information.
  *
  * @param string $key  The PGP key.
  */
 protected function _printKeyInfo($key = '')
 {
     try {
         $key_info = $this->_pgp->prettyKey($key);
     } catch (Horde_Crypt_Exception $e) {
         Horde::log($e, 'INFO');
         $key_info = $e->getMessage();
     }
     $this->_textWindowOutput('PGP Key Information', $key_info);
 }
예제 #4
0
파일: Pgp.php 프로젝트: raz0rsdge/horde
 /**
  * Generates HTML output for 'multipart/signed' MIME parts.
  *
  * @return string  The HTML output.
  */
 protected function _outputPGPSigned()
 {
     global $injector, $prefs, $session;
     $iterator = $this->_mimepart->partIterator();
     $iterator->rewind();
     $base_id = $iterator->current()->getMimeId();
     $iterator->next();
     $signed_id = $iterator->current()->getMimeId();
     $id_ob = new Horde_Mime_Id($signed_id);
     $sig_id = $id_ob->idArithmetic($id_ob::ID_NEXT);
     if (!IMP_Pgp::enabled()) {
         return array($sig_id => null);
     }
     $status = new IMP_Mime_Status($this->_mimepart);
     $status->addText(_("The data in this part has been digitally signed via PGP."));
     $status->icon('mime/encryption.png', 'PGP');
     $ret = array($base_id => array('data' => '', 'nosummary' => true, 'status' => array($status), 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap'), $sig_id => null);
     if ($prefs->getValue('pgp_verify') || $injector->getInstance('Horde_Variables')->pgp_verify_msg) {
         $imp_contents = $this->getConfigParam('imp_contents');
         $sig_part = $imp_contents->getMimePart($sig_id);
         $status2 = new IMP_Mime_Status($this->_mimepart);
         if (!$sig_part) {
             $status2->action(IMP_Mime_Status::ERROR);
             $sig_text = _("This digitally signed message is broken.");
             $ret[$base_id]['wrap'] = 'mimePartWrapInvalid';
         } else {
             /* Close session, since this may be a long-running
              * operation. */
             $session->close();
             try {
                 $imp_pgp = $injector->getInstance('IMP_Pgp');
                 if ($sig_raw = $sig_part->getMetadata(Horde_Crypt_Pgp_Parse::SIG_RAW)) {
                     $sig_result = $imp_pgp->verifySignature($sig_raw, $this->_getSender()->bare_address, null, $sig_part->getMetadata(Horde_Crypt_Pgp_Parse::SIG_CHARSET));
                 } else {
                     $stream = $imp_contents->isEmbedded($signed_id) ? $this->_mimepart->getMetadata(self::PGP_SIGN_ENC) : $imp_contents->getBodyPart($signed_id, array('mimeheaders' => true, 'stream' => true))->data;
                     rewind($stream);
                     stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
                     $filter = stream_filter_append($stream, 'horde_eol', STREAM_FILTER_READ, array('eol' => Horde_Mime_Part::RFC_EOL));
                     $sig_result = $imp_pgp->verifySignature(stream_get_contents($stream), $this->_getSender()->bare_address, $sig_part->getContents());
                     stream_filter_remove($filter);
                 }
                 $status2->action(IMP_Mime_Status::SUCCESS);
                 $sig_text = $sig_result->message;
                 $ret[$base_id]['wrap'] = 'mimePartWrapValid';
             } catch (Horde_Exception $e) {
                 $status2->action(IMP_Mime_Status::ERROR);
                 $sig_text = $e->getMessage();
                 $ret[$base_id]['wrap'] = 'mimePartWrapInvalid';
             }
         }
         $status2->addText($this->_textFilter($sig_text, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::NOHTML)));
         $ret[$base_id]['status'][] = $status2;
     } else {
         $status->addMimeAction('pgpVerifyMsg', _("Click to verify the message."));
     }
     return $ret;
 }
예제 #5
0
파일: Common.php 프로젝트: horde/horde
 /**
  */
 protected function _compose($base, $view, $args)
 {
     global $injector, $registry, $page_output, $prefs;
     $view->title = $args['title'];
     /* Load Identity. */
     $identity = $injector->getInstance('IMP_Identity');
     $selected_identity = intval($identity->getDefault());
     /* Generate identities list. */
     $this->_addIdentityJs();
     if (IMP_Compose::canHtmlCompose()) {
         $view->compose_html = !empty($args['show_editor']);
         $view->rte = true;
         $page_output->addScriptPackage('IMP_Script_Package_Editor');
         $page_output->addScriptFile('external/base64.js');
     }
     /* Create list for sent-mail selection. */
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS) && !$prefs->isLocked('save_sent_mail')) {
         $view->save_sent_mail = true;
         $view->save_sent_mail_select = !$prefs->isLocked(IMP_Mailbox::MBOX_SENT);
     }
     $view->drafts = $imp_imap->access(IMP_Imap::ACCESS_DRAFTS) && ($draft = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)) && !$draft->readonly;
     $view->compose_link = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachment';
     $view->resume = !empty($args['resume']);
     $view->is_template = !empty($args['template']);
     $view->read_receipt_set = strcasecmp($prefs->getValue('request_mdn'), 'always') === 0;
     $view->user = $registry->getAuth();
     if (IMP_Compose::canUploadAttachment()) {
         $view->attach = true;
         $view->max_size = IMP_Compose::maxAttachmentSize();
         $view->save_attach_set = strcasecmp($prefs->getValue('save_attachments'), 'always') === 0;
     } else {
         $view->attach = false;
     }
     if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) {
         $view->pgp_pubkey = $prefs->getValue('pgp_attach_pubkey');
     }
     if ($registry->hasMethod('contacts/ownVCard')) {
         $view->vcard_attach = true;
     }
     $view->priority = $prefs->getValue('set_priority');
     if (!$prefs->isLocked('default_encrypt') && (IMP_Pgp::enabled() || IMP_Smime::enabled())) {
         $view->encrypt = $prefs->getValue('default_encrypt');
     }
     $from_list = array();
     foreach ($identity->getSelectList() as $id => $from) {
         $from_list[] = array('label' => $from, 'sel' => $id == $selected_identity, 'val' => $id);
     }
     $view->from_list = $from_list;
     $view->signature = $identity->hasSignature(true);
     $view->sigExpanded = $prefs->getValue('signature_expanded');
 }
예제 #6
0
파일: Compose.php 프로젝트: raz0rsdge/horde
 /**
  * Encrypt an outgoing message.
  *
  * @param Horde_Mime_Part $msg             Outgoing message.
  * @param integer $encrypt                 Encryption type.
  * @param Horde_Mail_Rfc822_List $recip    Recipient list.
  * @param Horde_Mail_Rfc822_Address $from  Sending address.
  *
  * @return Horde_Mime_Part $msg  Processed outgoing message.
  */
 protected function _encryptMessage(Horde_Mime_Part $msg, $encrypt, Horde_Mail_Rfc822_List $recip, Horde_Mail_Rfc822_Address $from)
 {
     global $injector;
     /* Add personal address to encrypted message. */
     switch ($encrypt) {
         case IMP_Pgp::ENCRYPT:
         case IMP_Pgp::SIGNENC:
         case IMP_Pgp::SYM_ENCRYPT:
         case IMP_Pgp::SYM_SIGNENC:
         case IMP_Smime::ENCRYPT:
         case IMP_Smime::SIGNENC:
             $recip2 = clone $recip;
             $recip2->add($from);
             break;
     }
     switch ($encrypt) {
         case IMP_Pgp::ENCRYPT:
         case IMP_Pgp::SIGN:
         case IMP_Pgp::SIGNENC:
         case IMP_Pgp::SYM_ENCRYPT:
         case IMP_Pgp::SYM_SIGNENC:
             if (IMP_Pgp::enabled()) {
                 break;
             }
             $imp_pgp = $injector->getInstance('IMP_Pgp');
             switch ($encrypt) {
                 case IMP_Pgp::SIGN:
                 case IMP_Pgp::SIGNENC:
                 case IMP_Pgp::SYM_SIGNENC:
                     /* Check to see if we have the user's passphrase yet. */
                     $passphrase = $imp_pgp->getPassphrase('personal');
                     if (empty($passphrase)) {
                         $e = new IMP_Compose_Exception(_("PGP: Need passphrase for personal private key."));
                         $e->encrypt = 'pgp_passphrase_dialog';
                         throw $e;
                     }
                     break;
                 case IMP_Pgp::SYM_ENCRYPT:
                 case IMP_Pgp::SYM_SIGNENC:
                     /* Check to see if we have the user's symmetric passphrase
                      * yet. */
                     $symmetric_passphrase = $imp_pgp->getPassphrase('symmetric', 'imp_compose_' . $this->_cacheid);
                     if (empty($symmetric_passphrase)) {
                         $e = new IMP_Compose_Exception(_("PGP: Need passphrase to encrypt your message with."));
                         $e->encrypt = 'pgp_symmetric_passphrase_dialog';
                         throw $e;
                     }
                     break;
             }
             /* Do the encryption/signing requested. */
             try {
                 switch ($encrypt) {
                     case IMP_Pgp::SIGN:
                         $msg2 = $imp_pgp->signMimePart($msg);
                         $this->_setMetadata('encrypt_sign', true);
                         return $msg2;
                     case IMP_Pgp::ENCRYPT:
                     case IMP_Pgp::SYM_ENCRYPT:
                         return $imp_pgp->encryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_ENCRYPT ? $symmetric_passphrase : null);
                     case IMP_Pgp::SIGNENC:
                     case IMP_Pgp::SYM_SIGNENC:
                         return $imp_pgp->signAndEncryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_SIGNENC ? $symmetric_passphrase : null);
                         break;
                 }
             } catch (Horde_Exception $e) {
                 throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
             }
             break;
         case IMP_Smime::ENCRYPT:
         case IMP_Smime::SIGN:
         case IMP_Smime::SIGNENC:
             if (!IMP_Smime::enabled()) {
                 break;
             }
             $imp_smime = $injector->getInstance('IMP_Smime');
             /* Check to see if we have the user's passphrase yet. */
             switch ($encrypt) {
                 case IMP_Smime::SIGN:
                 case IMP_Smime::SIGNENC:
                     if (($passphrase = $imp_smime->getPassphrase()) === false) {
                         $e = new IMP_Compose_Exception(_("S/MIME Error: Need passphrase for personal private key."));
                         $e->encrypt = 'smime_passphrase_dialog';
                         throw $e;
                     }
                     break;
             }
             /* Do the encryption/signing requested. */
             try {
                 switch ($encrypt) {
                     case IMP_Smime::SIGN:
                         $msg2 = $imp_smime->signMimePart($msg);
                         $this->_setMetadata('encrypt_sign', true);
                         return $msg2;
                     case IMP_Smime::ENCRYPT:
                         return $imp_smime->encryptMimePart($msg, $recip2);
                     case IMP_Smime::SIGNENC:
                         return $imp_smime->signAndEncryptMimePart($msg, $recip2);
                 }
             } catch (Horde_Exception $e) {
                 throw new IMP_Compose_Exception(_("S/MIME Error: ") . $e->getMessage(), $e->getCode());
             }
             break;
     }
     return $msg;
 }