[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * $Horde: imp/smime.php,v 2.48.4.8 2007/01/02 13:54:54 jan Exp $ 4 * 5 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 6 * Copyright 2002-2007 Mike Cochrane <mike@graftonhall.co.nz> 7 * 8 * See the enclosed file COPYING for license information (GPL). If you 9 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 10 */ 11 12 function _importKeyDialog($target) 13 { 14 global $actionID, $notification, $prefs, $registry, $selfURL; 15 16 $title = _("Import S/MIME Key"); 17 require IMP_TEMPLATES . '/common-header.inc'; 18 IMP::status(); 19 require IMP_TEMPLATES . '/smime/import_key.inc'; 20 } 21 22 function _getImportKey() 23 { 24 $key = Util::getFormData('import_key'); 25 if (!empty($key)) { 26 return $key; 27 } 28 29 $res = Browser::wasFileUploaded('upload_key', _("key")); 30 if (!is_a($res, 'PEAR_Error')) { 31 return file_get_contents($_FILES['upload_key']['tmp_name']); 32 } else { 33 $GLOBALS['notification']->push($res, 'horde.error'); 34 return; 35 } 36 } 37 38 function _outputPassphraseDialog() 39 { 40 global $notification, $prefs, $registry, $secure_check, $selfURL; 41 42 if (is_a($secure_check, 'PEAR_Error')) { 43 $notification->push($secure_check, 'horde.error'); 44 } 45 46 $title = _("S/MIME Passphrase Input"); 47 require IMP_TEMPLATES . '/common-header.inc'; 48 $submit_url = Util::addParameter($selfURL, 'actionID', 'process_passphrase_dialog'); 49 IMP::status(); 50 require IMP_TEMPLATES . '/smime/passphrase.inc'; 51 } 52 53 function _actionWindow() 54 { 55 require_once 'Horde/SessionObjects.php'; 56 $oid = Util::getFormData('passphrase_action'); 57 $cacheSess = &Horde_SessionObjects::singleton(); 58 $cacheSess->setPruneFlag($oid, true); 59 Util::closeWindowJS($cacheSess->query($oid)); 60 } 61 62 function _reloadWindow() 63 { 64 Util::closeWindowJS('opener.focus();opener.location.href="' . Util::getFormData('reload') . '";'); 65 } 66 67 function _textWindowOutput($filename, $msg, $html = false) 68 { 69 $type = ($html ? 'text/html' : 'text/plain') . '; charset=' . NLS::getCharset(); 70 $GLOBALS['browser']->downloadHeaders($filename, $type, true, strlen($msg)); 71 echo $msg; 72 } 73 74 function _printKeyInfo($cert) 75 { 76 $key_info = $GLOBALS['imp_smime']->certToHTML($cert); 77 if (empty($key_info)) { 78 _textWindowOutput('S/MIME Key Information', _("Invalid key")); 79 } else { 80 _textWindowOutput('S/MIME Key Information', $key_info, true); 81 } 82 } 83 84 85 @define('IMP_BASE', dirname(__FILE__)); 86 $authentication = OP_HALFOPEN; 87 require_once IMP_BASE . '/lib/base.php'; 88 require_once IMP_BASE . '/lib/Crypt/SMIME.php'; 89 90 $imp_smime = &new IMP_SMIME(); 91 $secure_check = $imp_smime->requireSecureConnection(); 92 $selfURL = Horde::applicationUrl('smime.php'); 93 94 /* Run through the action handlers */ 95 $actionID = Util::getFormData('actionID'); 96 switch ($actionID) { 97 case 'open_passphrase_dialog': 98 if ($imp_smime->getPassphrase() !== false) { 99 Util::closeWindowJS(); 100 } else { 101 _outputPassphraseDialog(); 102 } 103 exit; 104 105 case 'process_passphrase_dialog': 106 if (is_a($secure_check, 'PEAR_Error')) { 107 _outputPassphraseDialog(); 108 } elseif (Util::getFormData('passphrase')) { 109 if ($imp_smime->storePassphrase(Util::getFormData('passphrase'))) { 110 if (Util::getFormData('passphrase_action')) { 111 _actionWindow(); 112 } elseif (Util::getFormData('reload')) { 113 _reloadWindow(); 114 } else { 115 Util::closeWindowJS(); 116 } 117 } else { 118 $notification->push("Invalid passphrase entered.", 'horde.error'); 119 _outputPassphraseDialog(); 120 } 121 } else { 122 $notification->push("No passphrase entered.", 'horde.error'); 123 _outputPassphraseDialog(); 124 } 125 exit; 126 127 case 'delete_key': 128 $imp_smime->deletePersonalKeys(); 129 $notification->push(_("Personal S/MIME keys deleted successfully."), 'horde.success'); 130 break; 131 132 case 'delete_public_key': 133 $result = $imp_smime->deletePublicKey(Util::getFormData('email')); 134 if (is_a($result, 'PEAR_Error')) { 135 $notification->push($result, $result->getCode()); 136 } else { 137 $notification->push(sprintf(_("S/MIME Public Key for \"%s\" was successfully deleted."), Util::getFormData('email')), 'horde.success'); 138 } 139 break; 140 141 case 'import_public_key': 142 _importKeyDialog('process_import_public_key'); 143 exit; 144 145 case 'process_import_public_key': 146 $publicKey = _getImportKey(); 147 if (empty($publicKey)) { 148 $notification->push(_("No S/MIME public key imported."), 'horde.error'); 149 $actionID = 'import_public_key'; 150 _importKeyDialog('process_import_public_key'); 151 } else { 152 /* Add the public key to the storage system. */ 153 $key_info = $imp_smime->addPublicKey($publicKey); 154 if (is_a($key_info, 'PEAR_Error')) { 155 $notification->push($key_info, 'horde.error'); 156 $actionID = 'import_public_key'; 157 _importKeyDialog('process_import_public_key'); 158 } else { 159 $notification->push(_("S/MIME Public Key successfully added."), 'horde.success'); 160 _reloadWindow(); 161 } 162 } 163 exit; 164 165 case 'view_public_key': 166 $key = $imp_smime->getPublicKey(Util::getFormData('email')); 167 if (is_a($key, 'PEAR_Error')) { 168 $key = $key->getMessage(); 169 } 170 _textWindowOutput('S/MIME Public Key', $key); 171 exit; 172 173 case 'info_public_key': 174 $key = $imp_smime->getPublicKey(Util::getFormData('email')); 175 if (is_a($key, 'PEAR_Error')) { 176 $key = $key->getMessage(); 177 } 178 _printKeyInfo($key); 179 exit; 180 181 case 'view_personal_public_key': 182 _textWindowOutput('S/MIME Personal Public Key', $imp_smime->getPersonalPublicKey()); 183 exit; 184 case 'info_personal_public_key': 185 _printKeyInfo($imp_smime->getPersonalPublicKey()); 186 exit; 187 188 case 'view_personal_private_key': 189 _textWindowOutput('S/MIME Personal Private Key', $imp_smime->getPersonalPrivateKey()); 190 exit; 191 192 case 'import_personal_certs': 193 _importKeyDialog('process_import_personal_certs'); 194 exit; 195 196 case 'process_import_personal_certs': 197 if (!($pkcs12 = _getImportKey())) { 198 $notification->push(_("No personal S/MIME certificates imported."), 'horde.error'); 199 $actionID = 'import_personal_certs'; 200 _importKeyDialog('process_import_personal_certs'); 201 } else { 202 $res = $imp_smime->addFromPKCS12($pkcs12, Util::getFormData('upload_key_pass'), Util::getFormData('upload_key_pk_pass')); 203 if (is_a($res, 'PEAR_Error')) { 204 $notification->push(_("Personal S/MIME certificates NOT imported: ") . $res->getMessage(), 'horde.error'); 205 $actionID = 'import_personal_certs'; 206 _importKeyDialog('process_import_personal_certs'); 207 } else { 208 $notification->push(_("S/MIME Public/Private Keypair successfully added."), 'horde.success'); 209 _reloadWindow(); 210 } 211 } 212 exit; 213 214 case 'save_attachment_public_key': 215 require_once 'Horde/SessionObjects.php'; 216 217 $cacheSess = &Horde_SessionObjects::singleton(); 218 $cert = $cacheSess->query(Util::getFormData('cert')); 219 220 /* Add the public key to the storage system. */ 221 $cert = $imp_smime->addPublicKey($cert, Util::getFormData('from')); 222 if ($cert == false) { 223 $notification->push(_("No Certificate found"), 'horde.error'); 224 } else { 225 Util::closeWindowJS(); 226 } 227 exit; 228 229 case 'unset_passphrase': 230 if ($imp_smime->getPassphrase() !== false) { 231 $imp_smime->unsetPassphrase(); 232 $notification->push(_("Passphrase successfully unloaded."), 'horde.success'); 233 } 234 break; 235 236 case 'save_options': 237 $prefs->setValue('use_smime', Util::getFormData('use_smime')); 238 $notification->push(_("Preferences successfully updated."), 'horde.success'); 239 break; 240 } 241 242 /* Get list of Public Keys. */ 243 $pubkey_list = $imp_smime->listPublicKeys(); 244 if (is_a($pubkey_list, 'PEAR_Error')) { 245 $notification->push($pubkey_list, $pubkey_list->getCode()); 246 } 247 248 /* Get passphrase (if available). */ 249 $passphrase = $imp_smime->getPassphrase(); 250 251 require IMP_BASE . '/config/prefs.php'; 252 require_once 'Horde/Prefs/UI.php'; 253 $app = 'imp'; 254 Prefs_UI::generateHeader('smime'); 255 256 /* If S/MIME preference not active, or openssl PHP extension not available, do 257 * NOT show S/MIME Admin screen. */ 258 $openssl_check = $imp_smime->checkForOpenSSL(); 259 if (!is_a($openssl_check, 'PEAR_Error') && $prefs->getValue('use_smime')) { 260 $opensmimewin = $imp_smime->getJSOpenWinCode('open_passphrase_dialog'); 261 Horde::addScriptFile('popup.js'); 262 require IMP_TEMPLATES . '/smime/smime.inc'; 263 } else { 264 require IMP_TEMPLATES . '/smime/notactive.inc'; 265 } 266 267 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 |
![]() |