[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * The Auth_imp:: class provides an IMP implementation of the Horde 4 * authentication system. 5 * 6 * Required parameters:<pre> 7 * None.</pre> 8 * 9 * Optional parameters:<pre> 10 * None.</pre> 11 * 12 * 13 * $Horde: imp/lib/Auth/imp.php,v 1.16.6.16 2007/01/02 13:54:57 jan Exp $ 14 * 15 * Copyright 2003-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 16 * 17 * See the enclosed file COPYING for license information (LGPL). If you 18 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 19 * 20 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 21 * @since Horde 3.0 22 * @package Horde_Auth 23 */ 24 class Auth_imp extends Auth { 25 26 /** 27 * IMP specific authentication parameters. 28 * 29 * @var array 30 */ 31 var $_impParams = array( 32 'flags' => 0, 33 'setup' => false 34 ); 35 36 /** 37 * Constructs a new IMP authentication object. 38 * 39 * @param array $params A hash containing connection parameters. 40 */ 41 function Auth_imp($params = array()) 42 { 43 if (!Util::extensionExists('imap')) { 44 Horde::fatal(PEAR::raiseError(_("Auth_imp: Required IMAP extension not found.")), __FILE__, __LINE__); 45 } 46 } 47 48 /** 49 * Find out if a set of login credentials are valid, and if 50 * requested, mark the user as logged in in the current session. 51 * 52 * @param string $userID The userID to check. 53 * @param array $credentials The credentials to check. 54 * @param boolean $login Whether to log the user in. If false, we'll 55 * only test the credentials and won't modify 56 * the current session. 57 * 58 * @return boolean Whether or not the credentials are valid. 59 */ 60 function authenticate($userID = null, $credentials = array(), 61 $login = false) 62 { 63 // Check for for hordeauth. 64 if (empty($_SESSION['imp']['uniquser'])) { 65 if (IMP::canAutoLogin()) { 66 $server_key = IMP::getAutoLoginServer(); 67 68 require IMP_BASE . '/config/servers.php'; 69 $ptr = &$servers[$server_key]; 70 if (isset($ptr['hordeauth'])) { 71 72 if (strcasecmp($ptr['hordeauth'], 'full') == 0) { 73 $imapuser = Auth::getAuth(); 74 } else { 75 $imapuser = Auth::getBareAuth(); 76 } 77 $pass = Auth::getCredential('password'); 78 79 require_once IMP_BASE . '/lib/Session.php'; 80 if (IMP_Session::createSession($imapuser, $pass, 81 $ptr['server'], $ptr)) { 82 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 83 $entry = sprintf('Login success for %s [%s] (forwarded for [%s]) to {%s:%s}', 84 $imapuser, 85 $_SERVER['REMOTE_ADDR'], 86 $_SERVER['HTTP_X_FORWARDED_FOR'], 87 $ptr['server'], 88 $ptr['port']); 89 } else { 90 $entry = sprintf('Login success for %s [%s] to {%s:%s}', 91 $imapuser, 92 $_SERVER['REMOTE_ADDR'], 93 $ptr['server'], 94 $ptr['port']); 95 } 96 Horde::logMessage($entry, __FILE__, __LINE__, 97 PEAR_LOG_NOTICE); 98 return true; 99 } 100 } 101 } 102 } 103 104 if (empty($userID)) { 105 if (empty($_SESSION['imp']['uniquser'])) { 106 return false; 107 } 108 $userID = $_SESSION['imp']['uniquser']; 109 } 110 111 if (empty($credentials)) { 112 if (empty($_SESSION['imp']['pass'])) { 113 return false; 114 } 115 $credentials = array('password' => Secret::read(Secret::getKey('imp'), $_SESSION['imp']['pass'])); 116 } 117 118 $login = ($login && ($this->getProvider() == 'imp')); 119 120 return parent::authenticate($userID, $credentials, $login); 121 } 122 123 /** 124 * Set IMP-specific authentication options. 125 * 126 * @param array $params The params to set. 127 * <pre> 128 * Keys: 129 * ----- 130 * 'flags' -- (integer) Flags to pass to imap_open(). 131 * DEFAULT: 0 132 * </pre> 133 */ 134 function authenticateOptions($params = array()) 135 { 136 $this->_impParams = array_merge($this->_impParams, $params); 137 } 138 139 /** 140 * Find out if a set of login credentials are valid. 141 * 142 * @access private 143 * 144 * @param string $userID The userID to check. 145 * @param array $credentials An array of login credentials. 146 * 147 * @return boolean Whether or not the credentials are valid. 148 */ 149 function _authenticate($userID, $credentials) 150 { 151 global $conf, $prefs; 152 153 if (!(isset($_SESSION['imp']) && is_array($_SESSION['imp']))) { 154 if (isset($prefs)) { 155 $prefs->cleanup(true); 156 } 157 $this->_setAuthError(AUTH_REASON_SESSION); 158 return false; 159 } 160 161 /* Set the maildomain. */ 162 $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', 163 $prefs->getValue('mail_domain')); 164 if (!empty($maildomain)) { 165 $_SESSION['imp']['maildomain'] = $maildomain; 166 } elseif (!empty($_SESSION['imp']['maildomain'])) { 167 $prefs->setValue('mail_domain', $_SESSION['imp']['maildomain']); 168 } 169 170 171 if (!isset($GLOBALS['imp'])) { 172 $GLOBALS['imp'] = &$_SESSION['imp']; 173 } 174 175 $connstr = null; 176 $flags = $this->_impParams['flags']; 177 $flags &= ~OP_ANONYMOUS; 178 179 /* Process the mailbox parameter (if present). */ 180 $mailbox = Util::getFormData('mailbox'); 181 if (!is_null($mailbox)) { 182 $_SESSION['imp']['mailbox'] = $mailbox; 183 } elseif (!isset($_SESSION['imp']['mailbox'])) { 184 $_SESSION['imp']['mailbox'] = 'INBOX'; 185 } 186 $_SESSION['imp']['thismailbox'] = Util::getFormData('thismailbox', $_SESSION['imp']['mailbox']); 187 188 /* Is this a search mailbox? */ 189 $imp_search_params = null; 190 if (strpos($_SESSION['imp']['mailbox'], IMP_SEARCH_MBOX) === 0) { 191 $imp_search_params = array('id' => $_SESSION['imp']['mailbox']); 192 } 193 require_once IMP_BASE . '/lib/Search.php'; 194 $GLOBALS['imp_search'] = new IMP_Search($imp_search_params); 195 196 switch ($_SESSION['imp']['base_protocol']) { 197 case 'pop3': 198 $connstr = 'INBOX'; 199 $flags &= ~OP_HALFOPEN; 200 201 /* Turn some options off if we are working with POP3. */ 202 $conf['user']['allow_folders'] = false; 203 $prefs->setValue('save_sent_mail', false); 204 $prefs->setLocked('save_sent_mail', true); 205 $prefs->setLocked('sent_mail_folder', true); 206 $prefs->setLocked('drafts_folder', true); 207 $prefs->setLocked('trash_folder', true); 208 break; 209 210 case 'imap': 211 if ($flags ^ OP_HALFOPEN) { 212 $connstr = $_SESSION['imp']['thismailbox']; 213 if ($GLOBALS['imp_search']->isSearchMbox($_SESSION['imp']['thismailbox'])) { 214 if (strstr(Util::getFormData('index'), ':')) { 215 $tmp = explode(':', Util::getFormData('index')); 216 $connstr = $tmp[1]; 217 $flags |= OP_HALFOPEN; 218 } else { 219 $aindex = Util::getFormData('array_index'); 220 if ($aindex !== null) { 221 $tmp = explode(IMP_MSG_SEP, $_SESSION['imp']['msgl']); 222 $mbox = substr($tmp[$aindex], strpos($tmp[$aindex], IMP_IDX_SEP) + 1); 223 $connstr = $mbox; 224 $flags |= OP_HALFOPEN; 225 } 226 } 227 } 228 } 229 break; 230 } 231 232 /* Open an IMAP stream. */ 233 require_once IMP_BASE . '/lib/IMAP.php'; 234 $imp_imap = &IMP_IMAP::singleton(); 235 $imp_imap->changeMbox($connstr, $flags); 236 237 if (!$_SESSION['imp']['stream']) { 238 if (!empty($_SESSION['imp']['server']) && 239 !empty($_SESSION['imp']['port']) && 240 !empty($_SESSION['imp']['protocol']) && 241 !empty($_SESSION['imp']['user'])) { 242 if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 243 $entry = sprintf('FAILED LOGIN %s (forwarded for [%s]) to %s:%s[%s] as %s', 244 $_SERVER['REMOTE_ADDR'], 245 $_SERVER['HTTP_X_FORWARDED_FOR'], 246 $_SESSION['imp']['server'], 247 $_SESSION['imp']['port'], 248 $_SESSION['imp']['protocol'], 249 $_SESSION['imp']['user']); 250 } else { 251 $entry = sprintf('FAILED LOGIN %s to %s:%s[%s] as %s', 252 $_SERVER['REMOTE_ADDR'], 253 $_SESSION['imp']['server'], 254 $_SESSION['imp']['port'], 255 $_SESSION['imp']['protocol'], 256 $_SESSION['imp']['user']); 257 } 258 Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_ERR); 259 } 260 261 unset($_SESSION['imp']); 262 if (isset($prefs)) { 263 $prefs->cleanup(true); 264 } 265 $this->_setAuthError(AUTH_REASON_FAILED); 266 return false; 267 } 268 269 return true; 270 } 271 272 /** 273 * Somewhat of a hack to allow IMP to set an authentication error message 274 * that may occur outside of this file. 275 * 276 * @param string $msg The error message to set. 277 */ 278 function IMPsetAuthErrorMsg($msg) 279 { 280 $this->_setAuthError(AUTH_REASON_MESSAGE, $msg); 281 } 282 283 }
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 |
![]() |