5 * @Author Bogdan Baliuc <b.baliuc@rogers.com>
8 * Copyright (C) 2005 - 2007 MailZu
9 * License: GPL, see LICENSE
12 * Base directory of application
14 @define
('BASE_DIR', dirname(__FILE__
) . '/..');
18 include_once('CmnFns.class.php');
21 * Provide all database access/manipulation functionality for Exchange Auth
25 // The exchange hostname with port (hostname[:port])
27 // The exchange LDAP URI (ldap://hostname[:port])
29 // The user's logon name
31 // The user's first name
33 // The user's mail address(es)
39 * Constructor to initialize object
45 $this->exchHost
= $conf['auth']['exch_host'];
46 $this->exchLDAP
= $conf['auth']['exch_ldap'];
49 // User methods -------------------------------------------
53 * @param string $username
54 * @param string $password
55 * @param string $domain
58 function authUser($username, $password, $domain) {
60 $fulluser = $domain.'/'.$username;
61 $mbox = imap_open('{'.$this->exchHost
.'/imap}Inbox', $fulluser, $password);
62 if ($mbox === false) {
63 $this->err_msg
= translate('Invalid Username/Password');
66 $ignore = imap_errors();
69 $ldapconn = ldap_connect($this->exchLDAP
);
70 if ($ldapconn === false) {
71 $this->err_msg
= translate('Can not connect to LDAP server');
74 ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION
, 3);
75 ldap_set_option($ldapconn, LDAP_OPT_REFERRALS
, 0);
76 $ldapbind = ldap_bind($ldapconn);
77 if ($ldapbind === false) {
78 $this->err_msg
= translate('Can not bind to LDAP server');
81 $ldapattr = array('cn', 'rfc822Mailbox' ,'otherMailbox');
82 $read = ldap_search($ldapconn, '', '(uid='.$username.')', $ldapattr);
83 if ($read === false) {
84 $this->err_msg
= translate('Unable to search LDAP server');
87 $info = ldap_get_entries($ldapconn, $read);
88 $this->logonName
= strtolower($username);
89 $this->firstName
= $info[0]['cn'][0];
90 $this->emailAddress
[] = strtolower($info[0]['rfc822mailbox'][0]);
91 for ($i=0; $i<$info[0]['othermailbox']['count']; $i++
) {
92 $data = $info[0]['othermailbox'][$i];
93 if (strncasecmp($data, 'smtp$', 5) == 0) {
94 $this->emailAddress
[] = strtolower(substr($data, 5));
97 ldap_close($ldapconn);
102 * Returns the last error message
104 * @return last error message generated
107 return $this->err_msg
;
110 // Helper methods -------------------------------------------
113 * Returns user information
114 * @return array containing user information
116 function getUserData() {
118 'logonName' => $this->logonName
,
119 'firstName' => $this->firstName
,
120 'emailAddress' => $this->emailAddress