query distribution list data too

This commit is contained in:
SJ 2013-03-02 14:09:06 +01:00
parent 691afa2b4f
commit 532fb2c51c
2 changed files with 18 additions and 12 deletions

View File

@ -99,6 +99,8 @@ $config['LDAP_HELPER_PASSWORD'] = 'xxxxxxx';
$config['LDAP_MAIL_ATTR'] = 'mail'; $config['LDAP_MAIL_ATTR'] = 'mail';
$config['LDAP_ACCOUNT_OBJECTCLASS'] = 'zimbraAccount'; $config['LDAP_ACCOUNT_OBJECTCLASS'] = 'zimbraAccount';
$config['LDAP_BASE_DN'] = ''; $config['LDAP_BASE_DN'] = '';
$config['LDAP_DISTRIBUTIONLIST_OBJECTCLASS'] = 'zimbraDistributionList';
$config['LDAP_DISTRIBUTIONLIST_ATTR'] = 'zimbraMailForwardingAddress';
$config['SIZE_X'] = 430; $config['SIZE_X'] = 430;
$config['SIZE_Y'] = 250; $config['SIZE_Y'] = 250;

View File

@ -66,7 +66,7 @@ class ModelUserAuth extends Model {
$ldap = new LDAP(LDAP_HOST, LDAP_HELPER_DN, LDAP_HELPER_PASSWORD); $ldap = new LDAP(LDAP_HOST, LDAP_HELPER_DN, LDAP_HELPER_PASSWORD);
if($ldap->is_bind_ok()) { if($ldap->is_bind_ok()) {
$query = $ldap->query(LDAP_BASE_DN, "(&(objectClass=" . LDAP_ACCOUNT_OBJECTCLASS . ")(" . LDAP_MAIL_ATTR . "=$username))", array()); $query = $ldap->query(LDAP_BASE_DN, "(|(&(objectClass=" . LDAP_ACCOUNT_OBJECTCLASS . ")(" . LDAP_MAIL_ATTR . "=$username))(&(objectClass=" . LDAP_DISTRIBUTIONLIST_OBJECTCLASS . ")(" . LDAP_DISTRIBUTIONLIST_ATTR . "=$username)" . "))", array());
if(isset($query->row)) { if(isset($query->row)) {
$a = $query->row; $a = $query->row;
@ -74,7 +74,7 @@ class ModelUserAuth extends Model {
$ldap_auth = new LDAP(LDAP_HOST, $a['dn'], $password); $ldap_auth = new LDAP(LDAP_HOST, $a['dn'], $password);
if($ldap_auth->is_bind_ok()) { if($ldap_auth->is_bind_ok()) {
$emails = $this->get_email_array_from_ldap_attr($a); $emails = $this->get_email_array_from_ldap_attr($query->rows);
$this->add_session_vars($a['cn'], $username, $emails); $this->add_session_vars($a['cn'], $username, $emails);
@ -95,21 +95,25 @@ class ModelUserAuth extends Model {
} }
private function get_email_array_from_ldap_attr($a = array(), $email = '') { private function get_email_array_from_ldap_attr($e = array()) {
$data = array(); $data = array();
foreach (array("mail", "mailalternateaddress", "proxyaddresses") as $mailattr) { foreach($e as $a) {
if(isset($a[$mailattr])) { foreach (array("mail", "mailalternateaddress", "proxyaddresses", LDAP_MAIL_ATTR, LDAP_DISTRIBUTIONLIST_ATTR) as $mailattr) {
if(isset($a[$mailattr])) {
if(isset($a[$mailattr]['count'])) { if(isset($a[$mailattr]['count'])) {
for($i = 0; $i < $a[$mailattr]['count']; $i++) { for($i = 0; $i < $a[$mailattr]['count']; $i++) {
if(preg_match("/^smtp\:/i", $a[$mailattr][$i]) || strchr($a[$mailattr][$i], '@') ) { if(preg_match("/^smtp\:/i", $a[$mailattr][$i]) || strchr($a[$mailattr][$i], '@') ) {
array_push($data, strtolower(preg_replace("/^smtp\:/i", "", $a[$mailattr][$i]))); $email = strtolower(preg_replace("/^smtp\:/i", "", $a[$mailattr][$i]));
if(!in_array($email, $data)) { array_push($data, $email); }
}
} }
} }
} else {
else { $email = strtolower(preg_replace("/^smtp\:/i", "", $a[$mailattr]));
array_push($data, strtolower(preg_replace("/^smtp\:/i", "", $a[$mailattr]))); if(!in_array($email, $data)) { array_push($data, $email); }
}
} }
} }
} }