1*76ce1169SAndreas Gohr<?php 2*76ce1169SAndreas Gohr/** 3*76ce1169SAndreas Gohr * PHP LDAP CLASS FOR MANIPULATING ACTIVE DIRECTORY 4*76ce1169SAndreas Gohr * Version 4.0.4 5*76ce1169SAndreas Gohr * 6*76ce1169SAndreas Gohr * PHP Version 5 with SSL and LDAP support 7*76ce1169SAndreas Gohr * 8*76ce1169SAndreas Gohr * Written by Scott Barnett, Richard Hyland 9*76ce1169SAndreas Gohr * email: scott@wiggumworld.com, adldap@richardhyland.com 10*76ce1169SAndreas Gohr * http://adldap.sourceforge.net/ 11*76ce1169SAndreas Gohr * 12*76ce1169SAndreas Gohr * Copyright (c) 2006-2012 Scott Barnett, Richard Hyland 13*76ce1169SAndreas Gohr * 14*76ce1169SAndreas Gohr * We'd appreciate any improvements or additions to be submitted back 15*76ce1169SAndreas Gohr * to benefit the entire community :) 16*76ce1169SAndreas Gohr * 17*76ce1169SAndreas Gohr * This library is free software; you can redistribute it and/or 18*76ce1169SAndreas Gohr * modify it under the terms of the GNU Lesser General Public 19*76ce1169SAndreas Gohr * License as published by the Free Software Foundation; either 20*76ce1169SAndreas Gohr * version 2.1 of the License. 21*76ce1169SAndreas Gohr * 22*76ce1169SAndreas Gohr * This library is distributed in the hope that it will be useful, 23*76ce1169SAndreas Gohr * but WITHOUT ANY WARRANTY; without even the implied warranty of 24*76ce1169SAndreas Gohr * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25*76ce1169SAndreas Gohr * Lesser General Public License for more details. 26*76ce1169SAndreas Gohr * 27*76ce1169SAndreas Gohr * @category ToolsAndUtilities 28*76ce1169SAndreas Gohr * @package adLDAP 29*76ce1169SAndreas Gohr * @subpackage Exchange 30*76ce1169SAndreas Gohr * @author Scott Barnett, Richard Hyland 31*76ce1169SAndreas Gohr * @copyright (c) 2006-2012 Scott Barnett, Richard Hyland 32*76ce1169SAndreas Gohr * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPLv2.1 33*76ce1169SAndreas Gohr * @revision $Revision: 97 $ 34*76ce1169SAndreas Gohr * @version 4.0.4 35*76ce1169SAndreas Gohr * @link http://adldap.sourceforge.net/ 36*76ce1169SAndreas Gohr */ 37*76ce1169SAndreas Gohrrequire_once(dirname(__FILE__) . '/../adLDAP.php'); 38*76ce1169SAndreas Gohr 39*76ce1169SAndreas Gohr/** 40*76ce1169SAndreas Gohr* MICROSOFT EXCHANGE FUNCTIONS 41*76ce1169SAndreas Gohr*/ 42*76ce1169SAndreas Gohrclass adLDAPExchange { 43*76ce1169SAndreas Gohr /** 44*76ce1169SAndreas Gohr * The current adLDAP connection via dependency injection 45*76ce1169SAndreas Gohr * 46*76ce1169SAndreas Gohr * @var adLDAP 47*76ce1169SAndreas Gohr */ 48*76ce1169SAndreas Gohr protected $adldap; 49*76ce1169SAndreas Gohr 50*76ce1169SAndreas Gohr public function __construct(adLDAP $adldap) { 51*76ce1169SAndreas Gohr $this->adldap = $adldap; 52*76ce1169SAndreas Gohr } 53*76ce1169SAndreas Gohr 54*76ce1169SAndreas Gohr /** 55*76ce1169SAndreas Gohr * Create an Exchange account 56*76ce1169SAndreas Gohr * 57*76ce1169SAndreas Gohr * @param string $username The username of the user to add the Exchange account to 58*76ce1169SAndreas Gohr * @param array $storageGroup The mailbox, Exchange Storage Group, for the user account, this must be a full CN 59*76ce1169SAndreas Gohr * If the storage group has a different base_dn to the adLDAP configuration, set it using $base_dn 60*76ce1169SAndreas Gohr * @param string $emailAddress The primary email address to add to this user 61*76ce1169SAndreas Gohr * @param string $mailNickname The mail nick name. If mail nickname is blank, the username will be used 62*76ce1169SAndreas Gohr * @param bool $mdbUseDefaults Indicates whether the store should use the default quota, rather than the per-mailbox quota. 63*76ce1169SAndreas Gohr * @param string $baseDn Specify an alternative base_dn for the Exchange storage group 64*76ce1169SAndreas Gohr * @param bool $isGUID Is the username passed a GUID or a samAccountName 65*76ce1169SAndreas Gohr * @return bool 66*76ce1169SAndreas Gohr */ 67*76ce1169SAndreas Gohr public function createMailbox($username, $storageGroup, $emailAddress, $mailNickname=NULL, $useDefaults=TRUE, $baseDn=NULL, $isGUID=false) 68*76ce1169SAndreas Gohr { 69*76ce1169SAndreas Gohr if ($username === NULL){ return "Missing compulsory field [username]"; } 70*76ce1169SAndreas Gohr if ($storageGroup === NULL) { return "Missing compulsory array [storagegroup]"; } 71*76ce1169SAndreas Gohr if (!is_array($storageGroup)) { return "[storagegroup] must be an array"; } 72*76ce1169SAndreas Gohr if ($emailAddress === NULL) { return "Missing compulsory field [emailAddress]"; } 73*76ce1169SAndreas Gohr 74*76ce1169SAndreas Gohr if ($baseDn === NULL) { 75*76ce1169SAndreas Gohr $baseDn = $this->adldap->getBaseDn(); 76*76ce1169SAndreas Gohr } 77*76ce1169SAndreas Gohr 78*76ce1169SAndreas Gohr $container = "CN=" . implode(",CN=", $storageGroup); 79*76ce1169SAndreas Gohr 80*76ce1169SAndreas Gohr if ($mailNickname === NULL) { 81*76ce1169SAndreas Gohr $mailNickname = $username; 82*76ce1169SAndreas Gohr } 83*76ce1169SAndreas Gohr $mdbUseDefaults = $this->adldap->utilities()->boolToString($useDefaults); 84*76ce1169SAndreas Gohr 85*76ce1169SAndreas Gohr $attributes = array( 86*76ce1169SAndreas Gohr 'exchange_homemdb'=>$container.",".$baseDn, 87*76ce1169SAndreas Gohr 'exchange_proxyaddress'=>'SMTP:' . $emailAddress, 88*76ce1169SAndreas Gohr 'exchange_mailnickname'=>$mailNickname, 89*76ce1169SAndreas Gohr 'exchange_usedefaults'=>$mdbUseDefaults 90*76ce1169SAndreas Gohr ); 91*76ce1169SAndreas Gohr $result = $this->adldap->user()->modify($username, $attributes, $isGUID); 92*76ce1169SAndreas Gohr if ($result == false) { 93*76ce1169SAndreas Gohr return false; 94*76ce1169SAndreas Gohr } 95*76ce1169SAndreas Gohr return true; 96*76ce1169SAndreas Gohr } 97*76ce1169SAndreas Gohr 98*76ce1169SAndreas Gohr /** 99*76ce1169SAndreas Gohr * Add an X400 address to Exchange 100*76ce1169SAndreas Gohr * See http://tools.ietf.org/html/rfc1685 for more information. 101*76ce1169SAndreas Gohr * An X400 Address looks similar to this X400:c=US;a= ;p=Domain;o=Organization;s=Doe;g=John; 102*76ce1169SAndreas Gohr * 103*76ce1169SAndreas Gohr * @param string $username The username of the user to add the X400 to to 104*76ce1169SAndreas Gohr * @param string $country Country 105*76ce1169SAndreas Gohr * @param string $admd Administration Management Domain 106*76ce1169SAndreas Gohr * @param string $pdmd Private Management Domain (often your AD domain) 107*76ce1169SAndreas Gohr * @param string $org Organization 108*76ce1169SAndreas Gohr * @param string $surname Surname 109*76ce1169SAndreas Gohr * @param string $givenName Given name 110*76ce1169SAndreas Gohr * @param bool $isGUID Is the username passed a GUID or a samAccountName 111*76ce1169SAndreas Gohr * @return bool 112*76ce1169SAndreas Gohr */ 113*76ce1169SAndreas Gohr public function addX400($username, $country, $admd, $pdmd, $org, $surname, $givenName, $isGUID=false) 114*76ce1169SAndreas Gohr { 115*76ce1169SAndreas Gohr if ($username === NULL){ return "Missing compulsory field [username]"; } 116*76ce1169SAndreas Gohr 117*76ce1169SAndreas Gohr $proxyValue = 'X400:'; 118*76ce1169SAndreas Gohr 119*76ce1169SAndreas Gohr // Find the dn of the user 120*76ce1169SAndreas Gohr $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); 121*76ce1169SAndreas Gohr if ($user[0]["dn"] === NULL) { return false; } 122*76ce1169SAndreas Gohr $userDn = $user[0]["dn"]; 123*76ce1169SAndreas Gohr 124*76ce1169SAndreas Gohr // We do not have to demote an email address from the default so we can just add the new proxy address 125*76ce1169SAndreas Gohr $attributes['exchange_proxyaddress'] = $proxyValue . 'c=' . $country . ';a=' . $admd . ';p=' . $pdmd . ';o=' . $org . ';s=' . $surname . ';g=' . $givenName . ';'; 126*76ce1169SAndreas Gohr 127*76ce1169SAndreas Gohr // Translate the update to the LDAP schema 128*76ce1169SAndreas Gohr $add = $this->adldap->adldap_schema($attributes); 129*76ce1169SAndreas Gohr 130*76ce1169SAndreas Gohr if (!$add) { return false; } 131*76ce1169SAndreas Gohr 132*76ce1169SAndreas Gohr // Do the update 133*76ce1169SAndreas Gohr // Take out the @ to see any errors, usually this error might occur because the address already 134*76ce1169SAndreas Gohr // exists in the list of proxyAddresses 135*76ce1169SAndreas Gohr $result = @ldap_mod_add($this->adldap->getLdapConnection(), $userDn, $add); 136*76ce1169SAndreas Gohr if ($result == false) { 137*76ce1169SAndreas Gohr return false; 138*76ce1169SAndreas Gohr } 139*76ce1169SAndreas Gohr 140*76ce1169SAndreas Gohr return true; 141*76ce1169SAndreas Gohr } 142*76ce1169SAndreas Gohr 143*76ce1169SAndreas Gohr /** 144*76ce1169SAndreas Gohr * Add an address to Exchange 145*76ce1169SAndreas Gohr * 146*76ce1169SAndreas Gohr * @param string $username The username of the user to add the Exchange account to 147*76ce1169SAndreas Gohr * @param string $emailAddress The email address to add to this user 148*76ce1169SAndreas Gohr * @param bool $default Make this email address the default address, this is a bit more intensive as we have to demote any existing default addresses 149*76ce1169SAndreas Gohr * @param bool $isGUID Is the username passed a GUID or a samAccountName 150*76ce1169SAndreas Gohr * @return bool 151*76ce1169SAndreas Gohr */ 152*76ce1169SAndreas Gohr public function addAddress($username, $emailAddress, $default = FALSE, $isGUID = false) 153*76ce1169SAndreas Gohr { 154*76ce1169SAndreas Gohr if ($username === NULL) { return "Missing compulsory field [username]"; } 155*76ce1169SAndreas Gohr if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } 156*76ce1169SAndreas Gohr 157*76ce1169SAndreas Gohr $proxyValue = 'smtp:'; 158*76ce1169SAndreas Gohr if ($default === true) { 159*76ce1169SAndreas Gohr $proxyValue = 'SMTP:'; 160*76ce1169SAndreas Gohr } 161*76ce1169SAndreas Gohr 162*76ce1169SAndreas Gohr // Find the dn of the user 163*76ce1169SAndreas Gohr $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); 164*76ce1169SAndreas Gohr if ($user[0]["dn"] === NULL){ return false; } 165*76ce1169SAndreas Gohr $userDn = $user[0]["dn"]; 166*76ce1169SAndreas Gohr 167*76ce1169SAndreas Gohr // We need to scan existing proxy addresses and demote the default one 168*76ce1169SAndreas Gohr if (is_array($user[0]["proxyaddresses"]) && $default === true) { 169*76ce1169SAndreas Gohr $modAddresses = array(); 170*76ce1169SAndreas Gohr for ($i=0;$i<sizeof($user[0]['proxyaddresses']);$i++) { 171*76ce1169SAndreas Gohr if (strstr($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) { 172*76ce1169SAndreas Gohr $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]); 173*76ce1169SAndreas Gohr } 174*76ce1169SAndreas Gohr if ($user[0]['proxyaddresses'][$i] != '') { 175*76ce1169SAndreas Gohr $modAddresses['proxyAddresses'][$i] = $user[0]['proxyaddresses'][$i]; 176*76ce1169SAndreas Gohr } 177*76ce1169SAndreas Gohr } 178*76ce1169SAndreas Gohr $modAddresses['proxyAddresses'][(sizeof($user[0]['proxyaddresses'])-1)] = 'SMTP:' . $emailAddress; 179*76ce1169SAndreas Gohr 180*76ce1169SAndreas Gohr $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $modAddresses); 181*76ce1169SAndreas Gohr if ($result == false) { 182*76ce1169SAndreas Gohr return false; 183*76ce1169SAndreas Gohr } 184*76ce1169SAndreas Gohr 185*76ce1169SAndreas Gohr return true; 186*76ce1169SAndreas Gohr } 187*76ce1169SAndreas Gohr else { 188*76ce1169SAndreas Gohr // We do not have to demote an email address from the default so we can just add the new proxy address 189*76ce1169SAndreas Gohr $attributes['exchange_proxyaddress'] = $proxyValue . $emailAddress; 190*76ce1169SAndreas Gohr 191*76ce1169SAndreas Gohr // Translate the update to the LDAP schema 192*76ce1169SAndreas Gohr $add = $this->adldap->adldap_schema($attributes); 193*76ce1169SAndreas Gohr 194*76ce1169SAndreas Gohr if (!$add) { 195*76ce1169SAndreas Gohr return false; 196*76ce1169SAndreas Gohr } 197*76ce1169SAndreas Gohr 198*76ce1169SAndreas Gohr // Do the update 199*76ce1169SAndreas Gohr // Take out the @ to see any errors, usually this error might occur because the address already 200*76ce1169SAndreas Gohr // exists in the list of proxyAddresses 201*76ce1169SAndreas Gohr $result = @ldap_mod_add($this->adldap->getLdapConnection(), $userDn,$add); 202*76ce1169SAndreas Gohr if ($result == false) { 203*76ce1169SAndreas Gohr return false; 204*76ce1169SAndreas Gohr } 205*76ce1169SAndreas Gohr 206*76ce1169SAndreas Gohr return true; 207*76ce1169SAndreas Gohr } 208*76ce1169SAndreas Gohr } 209*76ce1169SAndreas Gohr 210*76ce1169SAndreas Gohr /** 211*76ce1169SAndreas Gohr * Remove an address to Exchange 212*76ce1169SAndreas Gohr * If you remove a default address the account will no longer have a default, 213*76ce1169SAndreas Gohr * we recommend changing the default address first 214*76ce1169SAndreas Gohr * 215*76ce1169SAndreas Gohr * @param string $username The username of the user to add the Exchange account to 216*76ce1169SAndreas Gohr * @param string $emailAddress The email address to add to this user 217*76ce1169SAndreas Gohr * @param bool $isGUID Is the username passed a GUID or a samAccountName 218*76ce1169SAndreas Gohr * @return bool 219*76ce1169SAndreas Gohr */ 220*76ce1169SAndreas Gohr public function deleteAddress($username, $emailAddress, $isGUID=false) 221*76ce1169SAndreas Gohr { 222*76ce1169SAndreas Gohr if ($username === NULL) { return "Missing compulsory field [username]"; } 223*76ce1169SAndreas Gohr if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } 224*76ce1169SAndreas Gohr 225*76ce1169SAndreas Gohr // Find the dn of the user 226*76ce1169SAndreas Gohr $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); 227*76ce1169SAndreas Gohr if ($user[0]["dn"] === NULL) { return false; } 228*76ce1169SAndreas Gohr $userDn = $user[0]["dn"]; 229*76ce1169SAndreas Gohr 230*76ce1169SAndreas Gohr if (is_array($user[0]["proxyaddresses"])) { 231*76ce1169SAndreas Gohr $mod = array(); 232*76ce1169SAndreas Gohr for ($i=0;$i<sizeof($user[0]['proxyaddresses']);$i++) { 233*76ce1169SAndreas Gohr if (strstr($user[0]['proxyaddresses'][$i], 'SMTP:') !== false && $user[0]['proxyaddresses'][$i] == 'SMTP:' . $emailAddress) { 234*76ce1169SAndreas Gohr $mod['proxyAddresses'][0] = 'SMTP:' . $emailAddress; 235*76ce1169SAndreas Gohr } 236*76ce1169SAndreas Gohr elseif (strstr($user[0]['proxyaddresses'][$i], 'smtp:') !== false && $user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { 237*76ce1169SAndreas Gohr $mod['proxyAddresses'][0] = 'smtp:' . $emailAddress; 238*76ce1169SAndreas Gohr } 239*76ce1169SAndreas Gohr } 240*76ce1169SAndreas Gohr 241*76ce1169SAndreas Gohr $result = @ldap_mod_del($this->adldap->getLdapConnection(), $userDn,$mod); 242*76ce1169SAndreas Gohr if ($result == false) { 243*76ce1169SAndreas Gohr return false; 244*76ce1169SAndreas Gohr } 245*76ce1169SAndreas Gohr 246*76ce1169SAndreas Gohr return true; 247*76ce1169SAndreas Gohr } 248*76ce1169SAndreas Gohr else { 249*76ce1169SAndreas Gohr return false; 250*76ce1169SAndreas Gohr } 251*76ce1169SAndreas Gohr } 252*76ce1169SAndreas Gohr /** 253*76ce1169SAndreas Gohr * Change the default address 254*76ce1169SAndreas Gohr * 255*76ce1169SAndreas Gohr * @param string $username The username of the user to add the Exchange account to 256*76ce1169SAndreas Gohr * @param string $emailAddress The email address to make default 257*76ce1169SAndreas Gohr * @param bool $isGUID Is the username passed a GUID or a samAccountName 258*76ce1169SAndreas Gohr * @return bool 259*76ce1169SAndreas Gohr */ 260*76ce1169SAndreas Gohr public function primaryAddress($username, $emailAddress, $isGUID = false) 261*76ce1169SAndreas Gohr { 262*76ce1169SAndreas Gohr if ($username === NULL) { return "Missing compulsory field [username]"; } 263*76ce1169SAndreas Gohr if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } 264*76ce1169SAndreas Gohr 265*76ce1169SAndreas Gohr // Find the dn of the user 266*76ce1169SAndreas Gohr $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); 267*76ce1169SAndreas Gohr if ($user[0]["dn"] === NULL){ return false; } 268*76ce1169SAndreas Gohr $userDn = $user[0]["dn"]; 269*76ce1169SAndreas Gohr 270*76ce1169SAndreas Gohr if (is_array($user[0]["proxyaddresses"])) { 271*76ce1169SAndreas Gohr $modAddresses = array(); 272*76ce1169SAndreas Gohr for ($i=0;$i<sizeof($user[0]['proxyaddresses']);$i++) { 273*76ce1169SAndreas Gohr if (strstr($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) { 274*76ce1169SAndreas Gohr $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]); 275*76ce1169SAndreas Gohr } 276*76ce1169SAndreas Gohr if ($user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { 277*76ce1169SAndreas Gohr $user[0]['proxyaddresses'][$i] = str_replace('smtp:', 'SMTP:', $user[0]['proxyaddresses'][$i]); 278*76ce1169SAndreas Gohr } 279*76ce1169SAndreas Gohr if ($user[0]['proxyaddresses'][$i] != '') { 280*76ce1169SAndreas Gohr $modAddresses['proxyAddresses'][$i] = $user[0]['proxyaddresses'][$i]; 281*76ce1169SAndreas Gohr } 282*76ce1169SAndreas Gohr } 283*76ce1169SAndreas Gohr 284*76ce1169SAndreas Gohr $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $modAddresses); 285*76ce1169SAndreas Gohr if ($result == false) { 286*76ce1169SAndreas Gohr return false; 287*76ce1169SAndreas Gohr } 288*76ce1169SAndreas Gohr 289*76ce1169SAndreas Gohr return true; 290*76ce1169SAndreas Gohr } 291*76ce1169SAndreas Gohr 292*76ce1169SAndreas Gohr } 293*76ce1169SAndreas Gohr 294*76ce1169SAndreas Gohr /** 295*76ce1169SAndreas Gohr * Mail enable a contact 296*76ce1169SAndreas Gohr * Allows email to be sent to them through Exchange 297*76ce1169SAndreas Gohr * 298*76ce1169SAndreas Gohr * @param string $distinguishedName The contact to mail enable 299*76ce1169SAndreas Gohr * @param string $emailAddress The email address to allow emails to be sent through 300*76ce1169SAndreas Gohr * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name 301*76ce1169SAndreas Gohr * @return bool 302*76ce1169SAndreas Gohr */ 303*76ce1169SAndreas Gohr public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) 304*76ce1169SAndreas Gohr { 305*76ce1169SAndreas Gohr if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedName]"; } 306*76ce1169SAndreas Gohr if ($emailAddress === NULL) { return "Missing compulsory field [emailAddress]"; } 307*76ce1169SAndreas Gohr 308*76ce1169SAndreas Gohr if ($mailNickname !== NULL) { 309*76ce1169SAndreas Gohr // Find the dn of the user 310*76ce1169SAndreas Gohr $user = $this->adldap->contact()->info($distinguishedName, array("cn","displayname")); 311*76ce1169SAndreas Gohr if ($user[0]["displayname"] === NULL) { return false; } 312*76ce1169SAndreas Gohr $mailNickname = $user[0]['displayname'][0]; 313*76ce1169SAndreas Gohr } 314*76ce1169SAndreas Gohr 315*76ce1169SAndreas Gohr $attributes = array("email"=>$emailAddress,"contact_email"=>"SMTP:" . $emailAddress,"exchange_proxyaddress"=>"SMTP:" . $emailAddress,"exchange_mailnickname" => $mailNickname); 316*76ce1169SAndreas Gohr 317*76ce1169SAndreas Gohr // Translate the update to the LDAP schema 318*76ce1169SAndreas Gohr $mod = $this->adldap->adldap_schema($attributes); 319*76ce1169SAndreas Gohr 320*76ce1169SAndreas Gohr // Check to see if this is an enabled status update 321*76ce1169SAndreas Gohr if (!$mod) { return false; } 322*76ce1169SAndreas Gohr 323*76ce1169SAndreas Gohr // Do the update 324*76ce1169SAndreas Gohr $result = ldap_modify($this->adldap->getLdapConnection(), $distinguishedName, $mod); 325*76ce1169SAndreas Gohr if ($result == false) { return false; } 326*76ce1169SAndreas Gohr 327*76ce1169SAndreas Gohr return true; 328*76ce1169SAndreas Gohr } 329*76ce1169SAndreas Gohr 330*76ce1169SAndreas Gohr /** 331*76ce1169SAndreas Gohr * Returns a list of Exchange Servers in the ConfigurationNamingContext of the domain 332*76ce1169SAndreas Gohr * 333*76ce1169SAndreas Gohr * @param array $attributes An array of the AD attributes you wish to return 334*76ce1169SAndreas Gohr * @return array 335*76ce1169SAndreas Gohr */ 336*76ce1169SAndreas Gohr public function servers($attributes = array('cn','distinguishedname','serialnumber')) 337*76ce1169SAndreas Gohr { 338*76ce1169SAndreas Gohr if (!$this->adldap->getLdapBind()){ return false; } 339*76ce1169SAndreas Gohr 340*76ce1169SAndreas Gohr $configurationNamingContext = $this->adldap->getRootDse(array('configurationnamingcontext')); 341*76ce1169SAndreas Gohr $sr = @ldap_search($this->adldap->getLdapConnection(), $configurationNamingContext[0]['configurationnamingcontext'][0],'(&(objectCategory=msExchExchangeServer))', $attributes); 342*76ce1169SAndreas Gohr $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); 343*76ce1169SAndreas Gohr return $entries; 344*76ce1169SAndreas Gohr } 345*76ce1169SAndreas Gohr 346*76ce1169SAndreas Gohr /** 347*76ce1169SAndreas Gohr * Returns a list of Storage Groups in Exchange for a given mail server 348*76ce1169SAndreas Gohr * 349*76ce1169SAndreas Gohr * @param string $exchangeServer The full DN of an Exchange server. You can use exchange_servers() to find the DN for your server 350*76ce1169SAndreas Gohr * @param array $attributes An array of the AD attributes you wish to return 351*76ce1169SAndreas Gohr * @param bool $recursive If enabled this will automatically query the databases within a storage group 352*76ce1169SAndreas Gohr * @return array 353*76ce1169SAndreas Gohr */ 354*76ce1169SAndreas Gohr public function storageGroups($exchangeServer, $attributes = array('cn','distinguishedname'), $recursive = NULL) 355*76ce1169SAndreas Gohr { 356*76ce1169SAndreas Gohr if (!$this->adldap->getLdapBind()){ return false; } 357*76ce1169SAndreas Gohr if ($exchangeServer === NULL) { return "Missing compulsory field [exchangeServer]"; } 358*76ce1169SAndreas Gohr if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } 359*76ce1169SAndreas Gohr 360*76ce1169SAndreas Gohr $filter = '(&(objectCategory=msExchStorageGroup))'; 361*76ce1169SAndreas Gohr $sr = @ldap_search($this->adldap->getLdapConnection(), $exchangeServer, $filter, $attributes); 362*76ce1169SAndreas Gohr $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); 363*76ce1169SAndreas Gohr 364*76ce1169SAndreas Gohr if ($recursive === true) { 365*76ce1169SAndreas Gohr for ($i=0; $i<$entries['count']; $i++) { 366*76ce1169SAndreas Gohr $entries[$i]['msexchprivatemdb'] = $this->storageDatabases($entries[$i]['distinguishedname'][0]); 367*76ce1169SAndreas Gohr } 368*76ce1169SAndreas Gohr } 369*76ce1169SAndreas Gohr 370*76ce1169SAndreas Gohr return $entries; 371*76ce1169SAndreas Gohr } 372*76ce1169SAndreas Gohr 373*76ce1169SAndreas Gohr /** 374*76ce1169SAndreas Gohr * Returns a list of Databases within any given storage group in Exchange for a given mail server 375*76ce1169SAndreas Gohr * 376*76ce1169SAndreas Gohr * @param string $storageGroup The full DN of an Storage Group. You can use exchange_storage_groups() to find the DN 377*76ce1169SAndreas Gohr * @param array $attributes An array of the AD attributes you wish to return 378*76ce1169SAndreas Gohr * @return array 379*76ce1169SAndreas Gohr */ 380*76ce1169SAndreas Gohr public function storageDatabases($storageGroup, $attributes = array('cn','distinguishedname','displayname')) { 381*76ce1169SAndreas Gohr if (!$this->adldap->getLdapBind()){ return false; } 382*76ce1169SAndreas Gohr if ($storageGroup === NULL) { return "Missing compulsory field [storageGroup]"; } 383*76ce1169SAndreas Gohr 384*76ce1169SAndreas Gohr $filter = '(&(objectCategory=msExchPrivateMDB))'; 385*76ce1169SAndreas Gohr $sr = @ldap_search($this->adldap->getLdapConnection(), $storageGroup, $filter, $attributes); 386*76ce1169SAndreas Gohr $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); 387*76ce1169SAndreas Gohr return $entries; 388*76ce1169SAndreas Gohr } 389*76ce1169SAndreas Gohr} 390*76ce1169SAndreas Gohr?>