[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Auth_imap:: class provides an IMAP implementation of the Horde 4 * authentication system. 5 * 6 * Optional parameters:<pre> 7 * 'hostspec' The hostname or IP address of the server. 8 * DEFAULT: 'localhost' 9 * 'port' The server port to which we will connect. 10 * IMAP is generally 143, while IMAP-SSL is generally 993. 11 * DEFAULT: 143 12 * 'protocol' The connection protocol (e.g. 'imap', 'pop3', 'nntp'). 13 * Protocol is one of 'imap/notls' (or only 'imap' if you 14 * have a c-client version 2000c or older), 'imap/ssl', 15 * or 'imap/ssl/novalidate-cert' (for a self-signed 16 * certificate). 17 * DEFAULT: 'imap' 18 * 'admin_user' The name of a user with admin privileges. 19 * DEFAULT: null 20 * 'admin_password' The password of the adminstrator. 21 * DEFAULT: null 22 * 'userhierarchy' The hierarchy where user mailboxes are stored. 23 * DEFAULT: 'user.' 24 * 'dsn' The full IMAP connection string. 25 * If not present, this is built from 'hostspec', 'port' 26 * and 'protocol' parameters.</pre> 27 * 28 * 29 * If setting up as Horde auth handler in conf.php, this is a sample entry:<pre> 30 * $conf['auth']['params']['hostspec'] = 'imap.example.com'; 31 * $conf['auth']['params']['port'] = 143; 32 * $conf['auth']['params']['protocol'] = 'imap/notls/novalidate-cert';</pre> 33 * 34 * 35 * $Horde: framework/Auth/Auth/imap.php,v 1.28.10.9 2006/05/31 19:39:48 slusarz Exp $ 36 * 37 * Copyright 1999-2006 Chuck Hagenbuch <chuck@horde.org> 38 * Copyright 1999-2006 Gaudenz Steinlin <gaudenz.steinlin@id.unibe.ch> 39 * Copyright 2004-2006 Jan Schneider <jan@horde.org> 40 * 41 * See the enclosed file COPYING for license information (LGPL). If you 42 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 43 * 44 * @author Chuck Hagenbuch <chuck@horde.org> 45 * @author Gaudenz Steinlin <gaudenz.steinlin@id.unibe.ch> 46 * @author Jan Schneider <jan@horde.org> 47 * @since Horde 1.3 48 * @package Horde_Auth 49 */ 50 class Auth_imap extends Auth { 51 52 /** 53 * Constructs a new IMAP authentication object. 54 * 55 * @param array $params A hash containing connection parameters. 56 */ 57 function Auth_imap($params = array()) 58 { 59 if (!Util::extensionExists('imap')) { 60 Horde::fatal(_("Auth_imap: Required IMAP extension not found."), __FILE__, __LINE__); 61 } 62 63 $default_params = array( 64 'hostspec' => 'localhost', 65 'port' => '143', 66 'protocol' => 'imap', 67 'userhierarchy' => 'user.' 68 ); 69 $this->_params = array_merge($default_params, $params); 70 71 if (!empty($this->_params['admin_user'])) { 72 $this->capabilities['add'] = true; 73 $this->capabilities['remove'] = true; 74 $this->capabilities['list'] = true; 75 } 76 77 /* Create DSN string. */ 78 if (!isset($this->_params['dsn'])) { 79 $this->_params['dsn'] = sprintf('{%s:%d/%s}', 80 $this->_params['hostspec'], 81 $this->_params['port'], 82 $this->_params['protocol']); 83 } 84 } 85 86 /** 87 * Find out if a set of login credentials are valid. 88 * 89 * @access private 90 * 91 * @param string $userId The userId to check. 92 * @param array $credentials An array of login credentials. For IMAP, 93 * this must contain a password entry. 94 * 95 * @return boolean Whether or not the credentials are valid. 96 */ 97 function _authenticate($userId, $credentials) 98 { 99 if (empty($credentials['password'])) { 100 Horde::fatal(_("No password provided for IMAP authentication."), __FILE__, __LINE__); 101 } 102 103 $imap = @imap_open($this->_params['dsn'], $userId, 104 $credentials['password'], OP_HALFOPEN); 105 106 if ($imap) { 107 @imap_close($imap); 108 return true; 109 } else { 110 $this->_setAuthError(AUTH_REASON_BADLOGIN); 111 return false; 112 } 113 } 114 115 /** 116 * Add a set of authentication credentials. 117 * 118 * @param string $userId The userId to add. 119 * @param array $credentials The credentials to use. 120 * 121 * @return mixed True on success or a PEAR_Error object on failure. 122 */ 123 function addUser($userId, $credentials) 124 { 125 require_once 'Horde/IMAP/Admin.php'; 126 $imap = &new IMAP_Admin($this->_params); 127 return $imap->addMailbox(String::convertCharset($userId, NLS::getCharset(), 'utf7-imap')); 128 } 129 130 /** 131 * Delete a set of authentication credentials. 132 * 133 * @param string $userId The userId to delete. 134 * 135 * @return mixed True on success or a PEAR_Error object on failure. 136 */ 137 function removeUser($userId) 138 { 139 require_once 'Horde/IMAP/Admin.php'; 140 $imap = &new IMAP_Admin($this->_params); 141 $result = $imap->removeMailbox(String::convertCharset($userId, NLS::getCharset(), 'utf7-imap')); 142 if (is_a($result, 'PEAR_Error')) { 143 return $result; 144 } 145 return $this->removeUserData($userId); 146 } 147 148 /** 149 * List all users in the system. 150 * 151 * @return mixed The array of userIds, or a PEAR_Error object on failure. 152 */ 153 function listUsers() 154 { 155 require_once 'Horde/IMAP/Admin.php'; 156 $imap = &new IMAP_Admin($this->_params); 157 return $imap->listMailboxes(); 158 } 159 160 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |