| [ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * $Horde: imp/pgp.php,v 2.79.6.9 2007/01/02 13:54:54 jan Exp $ 4 * 5 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 6 * 7 * See the enclosed file COPYING for license information (GPL). If you 8 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 9 */ 10 11 function _printKeyInfo($key = '') 12 { 13 $key_info = $GLOBALS['imp_pgp']->pgpPrettyKey($key); 14 15 if (empty($key_info)) { 16 _textWindowOutput('PGP Key Information', _("Invalid key")); 17 } else { 18 _textWindowOutput('PGP Key Information', $key_info); 19 } 20 } 21 22 function _outputPassphraseDialog() 23 { 24 global $notification, $prefs, $registry, $secure_check, $selfURL; 25 26 if (is_a($secure_check, 'PEAR_Error')) { 27 $notification->push($secure_check, 'horde.warning'); 28 } 29 30 $title = _("PGP Passphrase Input"); 31 require IMP_TEMPLATES . '/common-header.inc'; 32 $submit_url = Util::addParameter($selfURL, 'actionID', 'process_passphrase_dialog'); 33 IMP::status(); 34 require IMP_TEMPLATES . '/pgp/passphrase.inc'; 35 } 36 37 function _importKeyDialog($target) 38 { 39 global $actionID, $notification, $prefs, $registry, $selfURL; 40 41 $title = _("Import PGP Key"); 42 require IMP_TEMPLATES . '/common-header.inc'; 43 IMP::status(); 44 require IMP_TEMPLATES . '/pgp/import_key.inc'; 45 } 46 47 function _actionWindow() 48 { 49 $oid = Util::getFormData('passphrase_action'); 50 require_once 'Horde/SessionObjects.php'; 51 $cacheSess = &Horde_SessionObjects::singleton(); 52 $cacheSess->setPruneFlag($oid, true); 53 Util::closeWindowJS($cacheSess->query($oid)); 54 } 55 56 function _reloadWindow() 57 { 58 Util::closeWindowJS('opener.focus();opener.location.href="' . Util::getFormData('reload') . '";'); 59 } 60 61 function _getImportKey() 62 { 63 $key = Util::getFormData('import_key'); 64 if (!empty($key)) { 65 return $key; 66 } 67 68 $res = Browser::wasFileUploaded('upload_key', _("key")); 69 if (!is_a($res, 'PEAR_Error')) { 70 return file_get_contents($_FILES['upload_key']['tmp_name']); 71 } else { 72 $GLOBALS['notification']->push($res, 'horde.error'); 73 return; 74 } 75 } 76 77 function _textWindowOutput($filename, $msg) 78 { 79 $GLOBALS['browser']->downloadHeaders($filename, 'text/plain; charset=' . NLS::getCharset(), true, strlen($msg)); 80 echo $msg; 81 } 82 83 84 @define('IMP_BASE', dirname(__FILE__)); 85 $authentication = OP_HALFOPEN; 86 require_once IMP_BASE . '/lib/base.php'; 87 require_once IMP_BASE . '/lib/Crypt/PGP.php'; 88 89 $imp_pgp = &new IMP_PGP(); 90 $secure_check = $imp_pgp->requireSecureConnection(); 91 $selfURL = Horde::applicationUrl('pgp.php'); 92 93 /* Run through the action handlers */ 94 $actionID = Util::getFormData('actionID'); 95 switch ($actionID) { 96 case 'generate_key': 97 /* Check that fields are filled out (except for Comment) and that the 98 passphrases match. */ 99 $realname = Util::getFormData('generate_realname'); 100 $email = Util::getFormData('generate_email'); 101 $comment = Util::getFormData('generate_comment'); 102 $keylength = Util::getFormData('generate_keylength'); 103 $passphrase1 = Util::getFormData('generate_passphrase1'); 104 $passphrase2 = Util::getFormData('generate_passphrase2'); 105 106 if (empty($realname) || empty($email)) { 107 $notification->push(_("Name and/or email cannot be empty"), 'horde.error'); 108 } elseif (empty($passphrase1) || empty($passphrase2)) { 109 $notification->push(_("Passphrases cannot be empty"), 'horde.error'); 110 } elseif ($passphrase1 !== $passphrase2) { 111 $notification->push(_("Passphrases do not match"), 'horde.error'); 112 } else { 113 $result = $imp_pgp->generatePersonalKeys($realname, $email, $passphrase1, $comment, $keylength); 114 if (is_a($result, 'PEAR_Error')) { 115 $notification->push($result, $result->getCode()); 116 } else { 117 $notification->push(_("Personal PGP keypair generated successfully."), 'horde.success'); 118 } 119 } 120 break; 121 122 case 'delete_key': 123 $imp_pgp->deletePersonalKeys(); 124 $notification->push(_("Personal PGP keys deleted successfully."), 'horde.success'); 125 break; 126 127 case 'import_public_key': 128 _importKeyDialog('process_import_public_key'); 129 exit; 130 131 case 'process_import_public_key': 132 $publicKey = _getImportKey(); 133 if (empty($publicKey)) { 134 $notification->push(_("No PGP public key imported."), 'horde.error'); 135 $actionID = 'import_public_key'; 136 _importKeyDialog('process_import_public_key'); 137 } else { 138 /* Add the public key to the storage system. */ 139 $key_info = $imp_pgp->addPublicKey($publicKey); 140 if (is_a($key_info, 'PEAR_Error')) { 141 $notification->push($key_info, 'horde.error'); 142 $actionID = 'import_public_key'; 143 _importKeyDialog('process_import_public_key'); 144 } else { 145 foreach ($key_info['signature'] as $sig) { 146 $notification->push(sprintf(_("PGP Public Key for \"%s (%s)\" was successfully added."), $sig['name'], $sig['email']), 'horde.success'); 147 } 148 _reloadWindow(); 149 } 150 } 151 exit; 152 153 case 'import_personal_public_key': 154 _importKeyDialog('process_import_personal_public_key'); 155 exit; 156 157 case 'process_import_personal_public_key': 158 $actionID = 'import_personal_public_key'; 159 /* Check the public key. */ 160 if (!($publicKey = _getImportKey())) { 161 /* No public key imported - Redo public key import screen. */ 162 $notification->push(_("No personal PGP public key imported."), 'horde.error'); 163 _importKeyDialog('process_import_personal_public_key'); 164 } else { 165 if (!($key_info = $imp_pgp->pgpPacketInformation($publicKey)) || 166 !isset($key_info['public_key'])) { 167 /* Invalid public key imported - Redo public key import screen. */ 168 $notification->push(_("Invalid personal PGP public key."), 'horde.error'); 169 _importKeyDialog('process_import_personal_public_key'); 170 } else { 171 /* Success in importing public key - Move on to private key 172 * now. */ 173 $imp_pgp->addPersonalPublicKey($publicKey); 174 $notification->push(_("PGP public key successfully added."), 'horde.success'); 175 $actionID = 'import_personal_private_key'; 176 _importKeyDialog('process_import_personal_private_key'); 177 } 178 } 179 exit; 180 181 case 'process_import_personal_private_key': 182 $actionID = 'import_personal_private_key'; 183 /* Check the private key. */ 184 if (!($privateKey = _getImportKey())) { 185 /* No private key imported - Redo private key import screen. */ 186 $notification->push(_("No personal PGP private key imported."), 'horde.error'); 187 _importKeyDialog('process_import_personal_private_key'); 188 } else { 189 if (!($key_info = $imp_pgp->pgpPacketInformation($privateKey)) || 190 !isset($key_info['secret_key'])) { 191 /* Invalid private key imported - Redo private key import 192 * screen. */ 193 $notification->push(_("Invalid personal PGP private key."), 'horde.error'); 194 _importKeyDialog('process_import_personal_private_key'); 195 } else { 196 /* Personal public and private keys have been imported 197 * successfully - close the import popup window. */ 198 $imp_pgp->addPersonalPrivateKey($privateKey); 199 $notification->push(_("PGP private key successfully added."), 'horde.success'); 200 _reloadWindow(); 201 } 202 } 203 exit; 204 205 case 'view_public_key': 206 $key = $imp_pgp->getPublicKey(Util::getFormData('email')); 207 if (is_a($key, 'PEAR_Error')) { 208 $key = $key->getMessage(); 209 } 210 _textWindowOutput('PGP Public Key', $key); 211 exit; 212 213 case 'view_personal_public_key': 214 _textWindowOutput('PGP Personal Public Key', $imp_pgp->getPersonalPublicKey()); 215 exit; 216 217 case 'info_public_key': 218 $key = $imp_pgp->getPublicKey(Util::getFormData('email')); 219 if (is_a($key, 'PEAR_Error')) { 220 $key = $key->getMessage(); 221 } 222 _printKeyInfo($key); 223 exit; 224 225 case 'info_personal_public_key': 226 _printKeyInfo($imp_pgp->getPersonalPublicKey()); 227 exit; 228 229 case 'view_personal_private_key': 230 _textWindowOutput('PGP Personal Private Key', $imp_pgp->getPersonalPrivateKey()); 231 exit; 232 233 case 'info_personal_private_key': 234 _printKeyInfo($imp_pgp->getPersonalPrivateKey()); 235 exit; 236 237 case 'delete_public_key': 238 $result = $imp_pgp->deletePublicKey(Util::getFormData('email')); 239 if (is_a($result, 'PEAR_Error')) { 240 $notification->push($result, $result->getCode()); 241 } else { 242 $notification->push(sprintf(_("PGP Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success'); 243 } 244 break; 245 246 case 'pgp_enable': 247 $prefs->setValue('use_pgp', Util::getFormData('use_pgp')); 248 break; 249 250 case 'save_options': 251 $prefs->setValue('use_pgp', Util::getFormData('use_pgp')); 252 $prefs->setValue('pgp_attach_pubkey', Util::getFormData('pgp_attach_pubkey')); 253 $prefs->setValue('pgp_scan_body', Util::getFormData('pgp_scan_body')); 254 $notification->push(_("Preferences successfully updated."), 'horde.success'); 255 break; 256 257 case 'save_attachment_public_key': 258 require_once 'Horde/SessionObjects.php'; 259 require_once 'Horde/MIME/Part.php'; 260 261 /* Retrieve the key from the cache. */ 262 $cache = &Horde_SessionObjects::singleton(); 263 $mime_part = $cache->query(Util::getFormData('mimecache')); 264 $mime_part->transferDecodeContents(); 265 266 /* Add the public key to the storage system. */ 267 $key_info = $imp_pgp->addPublicKey($mime_part->getContents()); 268 if (is_a($key_info, 'PEAR_Error')) { 269 $notification->push($key_info, $key_info->getCode()); 270 } else { 271 Util::closeWindowJS(); 272 } 273 exit; 274 275 case 'open_passphrase_dialog': 276 if ($imp_pgp->getPassphrase()) { 277 Util::closeWindowJS(); 278 } else { 279 _outputPassphraseDialog(); 280 } 281 exit; 282 283 case 'process_passphrase_dialog': 284 if (is_a($secure_check, 'PEAR_Error')) { 285 _outputPassphraseDialog(); 286 } elseif (Util::getFormData('passphrase')) { 287 if ($imp_pgp->storePassphrase(Util::getFormData('passphrase'))) { 288 if (Util::getFormData('passphrase_action')) { 289 _actionWindow(); 290 } elseif (Util::getFormData('reload')) { 291 _reloadWindow(); 292 } else { 293 Util::closeWindowJS(); 294 } 295 } else { 296 $notification->push("Invalid passphrase entered.", 'horde.error'); 297 _outputPassphraseDialog(); 298 } 299 } else { 300 $notification->push("No passphrase entered.", 'horde.error'); 301 _outputPassphraseDialog(); 302 } 303 exit; 304 305 case 'unset_passphrase': 306 $imp_pgp->unsetPassphrase(); 307 $notification->push(_("Passphrase successfully unloaded."), 'horde.success'); 308 break; 309 310 case 'send_public_key': 311 $result = $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey()); 312 if (is_a($result, 'PEAR_Error')) { 313 $notification->push($result, $result->getCode()); 314 } else { 315 $notification->push(_("Key successfully sent to the public keyserver."), 'horde.success'); 316 } 317 break; 318 } 319 320 /* Get list of Public Keys on keyring. */ 321 $pubkey_list = $imp_pgp->listPublicKeys(); 322 if (is_a($pubkey_list, 'PEAR_Error')) { 323 $notification->push($pubkey_list, $pubkey_list->getCode()); 324 } 325 326 /* Get passphrase (if available). */ 327 $passphrase = $imp_pgp->getPassphrase(); 328 329 require IMP_BASE . '/config/prefs.php'; 330 require_once 'Horde/Prefs/UI.php'; 331 $app = 'imp'; 332 Prefs_UI::generateHeader('pgp'); 333 334 /* If PGP preference not active, do NOT show PGP Admin screen. */ 335 if ($prefs->getValue('use_pgp')) { 336 $openpgpwin = $imp_pgp->getJSOpenWinCode('open_passphrase_dialog'); 337 Horde::addScriptFile('popup.js'); 338 require IMP_TEMPLATES . '/pgp/pgp.inc'; 339 } else { 340 require IMP_TEMPLATES . '/pgp/notactive.inc'; 341 } 342 343 require $registry->get('templates', 'horde') . '/common-footer.inc';
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
|