@@ -101,7 +101,7 @@ |
||
| 101 | 101 | * @param string $computerName The name of the computer |
| 102 | 102 | * @param string $group The group to check |
| 103 | 103 | * @param bool $recursive Whether to check recursively |
| 104 | - * @return array |
|
| 104 | + * @return boolean |
|
| 105 | 105 | */ |
| 106 | 106 | public function inGroup($computerName, $group, $recursive = NULL) { |
| 107 | 107 | if ($computerName === NULL) { return false; } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | class adLDAPComputers { |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * The current adLDAP connection via dependency injection |
|
| 48 | - * |
|
| 49 | - * @var adLDAP |
|
| 50 | - */ |
|
| 47 | + * The current adLDAP connection via dependency injection |
|
| 48 | + * |
|
| 49 | + * @var adLDAP |
|
| 50 | + */ |
|
| 51 | 51 | protected $adldap; |
| 52 | 52 | |
| 53 | 53 | public function __construct(adLDAP $adldap) { |
@@ -55,12 +55,12 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Get information about a specific computer. Returned in a raw array format from AD |
|
| 59 | - * |
|
| 60 | - * @param string $computerName The name of the computer |
|
| 61 | - * @param array $fields Attributes to return |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 58 | + * Get information about a specific computer. Returned in a raw array format from AD |
|
| 59 | + * |
|
| 60 | + * @param string $computerName The name of the computer |
|
| 61 | + * @param array $fields Attributes to return |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | 64 | public function info($computerName, $fields = NULL) { |
| 65 | 65 | if ($computerName === NULL) { return false; } |
| 66 | 66 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Find information about the computers. Returned in a raw array format from AD |
|
| 80 | - * |
|
| 81 | - * @param string $computerName The name of the computer |
|
| 82 | - * @param array $fields Array of parameters to query |
|
| 83 | - * @return mixed |
|
| 84 | - */ |
|
| 79 | + * Find information about the computers. Returned in a raw array format from AD |
|
| 80 | + * |
|
| 81 | + * @param string $computerName The name of the computer |
|
| 82 | + * @param array $fields Array of parameters to query |
|
| 83 | + * @return mixed |
|
| 84 | + */ |
|
| 85 | 85 | public function infoCollection($computerName, $fields = NULL) { |
| 86 | 86 | if ($computerName === NULL) { return false; } |
| 87 | 87 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | - * Check if a computer is in a group |
|
| 100 | - * |
|
| 101 | - * @param string $computerName The name of the computer |
|
| 102 | - * @param string $group The group to check |
|
| 103 | - * @param bool $recursive Whether to check recursively |
|
| 104 | - * @return array |
|
| 105 | - */ |
|
| 99 | + * Check if a computer is in a group |
|
| 100 | + * |
|
| 101 | + * @param string $computerName The name of the computer |
|
| 102 | + * @param string $group The group to check |
|
| 103 | + * @param bool $recursive Whether to check recursively |
|
| 104 | + * @return array |
|
| 105 | + */ |
|
| 106 | 106 | public function inGroup($computerName, $group, $recursive = NULL) { |
| 107 | 107 | if ($computerName === NULL) { return false; } |
| 108 | 108 | if ($group === NULL) { return false; } |
@@ -120,12 +120,12 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | - * Get the groups a computer is in |
|
| 124 | - * |
|
| 125 | - * @param string $computerName The name of the computer |
|
| 126 | - * @param bool $recursive Whether to check recursively |
|
| 127 | - * @return array |
|
| 128 | - */ |
|
| 123 | + * Get the groups a computer is in |
|
| 124 | + * |
|
| 125 | + * @param string $computerName The name of the computer |
|
| 126 | + * @param bool $recursive Whether to check recursively |
|
| 127 | + * @return array |
|
| 128 | + */ |
|
| 129 | 129 | public function groups($computerName, $recursive = NULL) { |
| 130 | 130 | if ($computerName === NULL) { return false; } |
| 131 | 131 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | if ($recursive === true) { |
| 139 | 139 | foreach ($groups as $id => $groupName){ |
| 140 | - $extraGroups = $this->adldap->group()->recursiveGroups($groupName); |
|
| 141 | - $groups = array_merge($groups, $extraGroups); |
|
| 140 | + $extraGroups = $this->adldap->group()->recursiveGroups($groupName); |
|
| 141 | + $groups = array_merge($groups, $extraGroups); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | return $groups; |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 39 | -require_once(dirname(__FILE__) . '/../collections/adLDAPComputerCollection.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | +require_once(dirname(__FILE__).'/../collections/adLDAPComputerCollection.php'); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * COMPUTER MANAGEMENT FUNCTIONS |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | if ($computerName === NULL) { return false; } |
| 66 | 66 | if (!$this->adldap->getLdapBind()) { return false; } |
| 67 | 67 | |
| 68 | - $filter = "(&(objectClass=computer)(cn=" . $computerName . "))"; |
|
| 68 | + $filter = "(&(objectClass=computer)(cn=".$computerName."))"; |
|
| 69 | 69 | if ($fields === NULL) { |
| 70 | - $fields = array("memberof","cn","displayname","dnshostname","distinguishedname","objectcategory","operatingsystem","operatingsystemservicepack","operatingsystemversion"); |
|
| 70 | + $fields = array("memberof", "cn", "displayname", "dnshostname", "distinguishedname", "objectcategory", "operatingsystem", "operatingsystemservicepack", "operatingsystemversion"); |
|
| 71 | 71 | } |
| 72 | 72 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 73 | 73 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | public function groups($computerName, $recursive = NULL) { |
| 130 | 130 | if ($computerName === NULL) { return false; } |
| 131 | 131 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
| 132 | - if (!$this->adldap->getLdapBind()){ return false; } |
|
| 132 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
| 133 | 133 | |
| 134 | 134 | //search the directory for their information |
| 135 | 135 | $info = @$this->info($computerName, array("memberof", "primarygroupid")); |
| 136 | 136 | $groups = $this->adldap->utilities()->niceNames($info[0]["memberof"]); //presuming the entry returned is our guy (unique usernames) |
| 137 | 137 | |
| 138 | 138 | if ($recursive === true) { |
| 139 | - foreach ($groups as $id => $groupName){ |
|
| 139 | + foreach ($groups as $id => $groupName) { |
|
| 140 | 140 | $extraGroups = $this->adldap->group()->recursiveGroups($groupName); |
| 141 | 141 | $groups = array_merge($groups, $extraGroups); |
| 142 | 142 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * Create a contact |
| 59 | 59 | * |
| 60 | 60 | * @param array $attributes The attributes to set to the contact |
| 61 | - * @return bool |
|
| 61 | + * @return string|boolean |
|
| 62 | 62 | */ |
| 63 | 63 | public function create($attributes) { |
| 64 | 64 | // Check for compulsory fields |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * Determine the list of groups a contact is a member of |
| 97 | 97 | * |
| 98 | - * @param string $distinguisedname The full DN of a contact |
|
| 98 | + * @param string $distinguishedName The full DN of a contact |
|
| 99 | 99 | * @param bool $recursive Recursively check groups |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | /** |
| 121 | 121 | * Get contact information. Returned in a raw array format from AD |
| 122 | 122 | * |
| 123 | - * @param string $distinguisedname The full DN of a contact |
|
| 123 | + * @param string $distinguishedName The full DN of a contact |
|
| 124 | 124 | * @param array $fields Attributes to be returned |
| 125 | 125 | * @return array |
| 126 | 126 | */ |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @param string $distinguishedName The contact to query |
| 201 | 201 | * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
| 202 | - * @return bool |
|
| 202 | + * @return string|boolean |
|
| 203 | 203 | */ |
| 204 | 204 | public function modify($distinguishedName, $attributes) { |
| 205 | 205 | if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedname]"; } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Delete a contact |
| 225 | 225 | * |
| 226 | 226 | * @param string $distinguishedName The contact dn to delete (please be careful here!) |
| 227 | - * @return array |
|
| 227 | + * @return boolean |
|
| 228 | 228 | */ |
| 229 | 229 | public function delete($distinguishedName) { |
| 230 | 230 | $result = $this->folder()->delete($distinguishedName); |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | * Mail enable a contact |
| 272 | 272 | * Allows email to be sent to them through Exchange |
| 273 | 273 | * |
| 274 | - * @param string $distinguishedname The contact to mail enable |
|
| 275 | - * @param string $emailaddress The email address to allow emails to be sent through |
|
| 276 | - * @param string $mailnickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 277 | - * @return bool |
|
| 274 | + * @param string $distinguishedName The contact to mail enable |
|
| 275 | + * @param string $emailAddress The email address to allow emails to be sent through |
|
| 276 | + * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 277 | + * @return string|boolean |
|
| 278 | 278 | */ |
| 279 | 279 | public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) { |
| 280 | 280 | return $this->adldap->exchange()->contactMailEnable($distinguishedName, $emailAddress, $mailNickname); |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | class adLDAPContacts { |
| 42 | 42 | /** |
| 43 | - * The current adLDAP connection via dependency injection |
|
| 44 | - * |
|
| 45 | - * @var adLDAP |
|
| 46 | - */ |
|
| 43 | + * The current adLDAP connection via dependency injection |
|
| 44 | + * |
|
| 45 | + * @var adLDAP |
|
| 46 | + */ |
|
| 47 | 47 | protected $adldap; |
| 48 | 48 | |
| 49 | 49 | public function __construct(adLDAP $adldap) { |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | // * Still work to do in this area, and new functions to write |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Create a contact |
|
| 59 | - * |
|
| 60 | - * @param array $attributes The attributes to set to the contact |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 58 | + * Create a contact |
|
| 59 | + * |
|
| 60 | + * @param array $attributes The attributes to set to the contact |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | 63 | public function create($attributes) { |
| 64 | 64 | // Check for compulsory fields |
| 65 | 65 | if (!array_key_exists("display_name", $attributes)) { return "Missing compulsory field [display_name]"; } |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * Determine the list of groups a contact is a member of |
|
| 97 | - * |
|
| 98 | - * @param string $distinguisedname The full DN of a contact |
|
| 99 | - * @param bool $recursive Recursively check groups |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 96 | + * Determine the list of groups a contact is a member of |
|
| 97 | + * |
|
| 98 | + * @param string $distinguisedname The full DN of a contact |
|
| 99 | + * @param bool $recursive Recursively check groups |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | 102 | public function groups($distinguishedName, $recursive = NULL) { |
| 103 | 103 | if ($distinguishedName === NULL) { return false; } |
| 104 | 104 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | - * Get contact information. Returned in a raw array format from AD |
|
| 122 | - * |
|
| 123 | - * @param string $distinguisedname The full DN of a contact |
|
| 124 | - * @param array $fields Attributes to be returned |
|
| 125 | - * @return array |
|
| 126 | - */ |
|
| 121 | + * Get contact information. Returned in a raw array format from AD |
|
| 122 | + * |
|
| 123 | + * @param string $distinguisedname The full DN of a contact |
|
| 124 | + * @param array $fields Attributes to be returned |
|
| 125 | + * @return array |
|
| 126 | + */ |
|
| 127 | 127 | public function info($distinguishedName, $fields = NULL) |
| 128 | 128 | { |
| 129 | 129 | if ($distinguishedName === NULL) { return false; } |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | - * Find information about the contacts. Returned in a raw array format from AD |
|
| 155 | - * |
|
| 156 | - * @param string $distinguishedName The full DN of a contact |
|
| 157 | - * @param array $fields Array of parameters to query |
|
| 158 | - * @return mixed |
|
| 159 | - */ |
|
| 154 | + * Find information about the contacts. Returned in a raw array format from AD |
|
| 155 | + * |
|
| 156 | + * @param string $distinguishedName The full DN of a contact |
|
| 157 | + * @param array $fields Array of parameters to query |
|
| 158 | + * @return mixed |
|
| 159 | + */ |
|
| 160 | 160 | public function infoCollection($distinguishedName, $fields = NULL) { |
| 161 | 161 | if ($distinguishedName === NULL) { return false; } |
| 162 | 162 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | - * Determine if a contact is a member of a group |
|
| 175 | - * |
|
| 176 | - * @param string $distinguisedName The full DN of a contact |
|
| 177 | - * @param string $group The group name to query |
|
| 178 | - * @param bool $recursive Recursively check groups |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 174 | + * Determine if a contact is a member of a group |
|
| 175 | + * |
|
| 176 | + * @param string $distinguisedName The full DN of a contact |
|
| 177 | + * @param string $group The group name to query |
|
| 178 | + * @param bool $recursive Recursively check groups |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | 181 | public function inGroup($distinguisedName, $group, $recursive = NULL) { |
| 182 | 182 | if ($distinguisedName === NULL) { return false; } |
| 183 | 183 | if ($group === NULL) { return false; } |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | - * Modify a contact |
|
| 199 | - * |
|
| 200 | - * @param string $distinguishedName The contact to query |
|
| 201 | - * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 202 | - * @return bool |
|
| 203 | - */ |
|
| 198 | + * Modify a contact |
|
| 199 | + * |
|
| 200 | + * @param string $distinguishedName The contact to query |
|
| 201 | + * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 202 | + * @return bool |
|
| 203 | + */ |
|
| 204 | 204 | public function modify($distinguishedName, $attributes) { |
| 205 | 205 | if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedname]"; } |
| 206 | 206 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
| 224 | - * Delete a contact |
|
| 225 | - * |
|
| 226 | - * @param string $distinguishedName The contact dn to delete (please be careful here!) |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 224 | + * Delete a contact |
|
| 225 | + * |
|
| 226 | + * @param string $distinguishedName The contact dn to delete (please be careful here!) |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | 229 | public function delete($distinguishedName) { |
| 230 | 230 | $result = $this->folder()->delete($distinguishedName); |
| 231 | 231 | if ($result != true) { |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | - * Return a list of all contacts |
|
| 239 | - * |
|
| 240 | - * @param bool $includeDescription Include a description of a contact |
|
| 241 | - * @param string $search The search parameters |
|
| 242 | - * @param bool $sorted Whether to sort the results |
|
| 243 | - * @return array |
|
| 244 | - */ |
|
| 238 | + * Return a list of all contacts |
|
| 239 | + * |
|
| 240 | + * @param bool $includeDescription Include a description of a contact |
|
| 241 | + * @param string $search The search parameters |
|
| 242 | + * @param bool $sorted Whether to sort the results |
|
| 243 | + * @return array |
|
| 244 | + */ |
|
| 245 | 245 | public function all($includeDescription = false, $search = "*", $sorted = true) { |
| 246 | 246 | if (!$this->adldap->getLdapBind()) { return false; } |
| 247 | 247 | |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | - * Mail enable a contact |
|
| 272 | - * Allows email to be sent to them through Exchange |
|
| 273 | - * |
|
| 274 | - * @param string $distinguishedname The contact to mail enable |
|
| 275 | - * @param string $emailaddress The email address to allow emails to be sent through |
|
| 276 | - * @param string $mailnickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 277 | - * @return bool |
|
| 278 | - */ |
|
| 271 | + * Mail enable a contact |
|
| 272 | + * Allows email to be sent to them through Exchange |
|
| 273 | + * |
|
| 274 | + * @param string $distinguishedname The contact to mail enable |
|
| 275 | + * @param string $emailaddress The email address to allow emails to be sent through |
|
| 276 | + * @param string $mailnickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 277 | + * @return bool |
|
| 278 | + */ |
|
| 279 | 279 | public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) { |
| 280 | 280 | return $this->adldap->exchange()->contactMailEnable($distinguishedName, $emailAddress, $mailNickname); |
| 281 | 281 | } |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 39 | -require_once(dirname(__FILE__) . '/../collections/adLDAPContactCollection.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | +require_once(dirname(__FILE__).'/../collections/adLDAPContactCollection.php'); |
|
| 40 | 40 | |
| 41 | 41 | class adLDAPContacts { |
| 42 | 42 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | // Determine the container |
| 84 | 84 | $attributes["container"] = array_reverse($attributes["container"]); |
| 85 | - $container= "OU=" . implode(",OU=", $attributes["container"]); |
|
| 85 | + $container = "OU=".implode(",OU=", $attributes["container"]); |
|
| 86 | 86 | |
| 87 | 87 | // Add the entry |
| 88 | - $result = @ldap_add($this->adldap->getLdapConnection(), "CN=" . $this->adldap->utilities()->escapeCharacters($add["cn"][0]) . ", " . $container . "," . $this->adldap->getBaseDn(), $add); |
|
| 88 | + $result = @ldap_add($this->adldap->getLdapConnection(), "CN=".$this->adldap->utilities()->escapeCharacters($add["cn"][0]).", ".$container.",".$this->adldap->getBaseDn(), $add); |
|
| 89 | 89 | if ($result != true) { |
| 90 | 90 | return false; |
| 91 | 91 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | public function groups($distinguishedName, $recursive = NULL) { |
| 103 | 103 | if ($distinguishedName === NULL) { return false; } |
| 104 | 104 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
| 105 | - if (!$this->adldap->getLdapBind()){ return false; } |
|
| 105 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
| 106 | 106 | |
| 107 | 107 | // Search the directory for their information |
| 108 | 108 | $info = @$this->info($distinguishedName, array("memberof", "primarygroupid")); |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | if ($distinguishedName === NULL) { return false; } |
| 130 | 130 | if (!$this->adldap->getLdapBind()) { return false; } |
| 131 | 131 | |
| 132 | - $filter = "distinguishedName=" . $this->adldap->utilities()->ldapSlashes($distinguishedName); |
|
| 132 | + $filter = "distinguishedName=".$this->adldap->utilities()->ldapSlashes($distinguishedName); |
|
| 133 | 133 | if ($fields === NULL) { |
| 134 | 134 | $fields = array("distinguishedname", "mail", "memberof", "department", "displayname", "telephonenumber", "primarygroupid", "objectsid"); |
| 135 | 135 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | //$entries[0]["memberof"][]=$this->group_cn($entries[0]["primarygroupid"][0]); |
| 143 | 143 | $entries[0]["memberof"][] = $this->adldap->group()->getPrimaryGroup($entries[0]["primarygroupid"][0], $entries[0]["objectsid"][0]); |
| 144 | 144 | } else { |
| 145 | - $entries[0]["memberof"][] = "CN=Domain Users,CN=Users," . $this->adldap->getBaseDn(); |
|
| 145 | + $entries[0]["memberof"][] = "CN=Domain Users,CN=Users,".$this->adldap->getBaseDn(); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -246,16 +246,16 @@ discard block |
||
| 246 | 246 | if (!$this->adldap->getLdapBind()) { return false; } |
| 247 | 247 | |
| 248 | 248 | // Perform the search and grab all their details |
| 249 | - $filter = "(&(objectClass=contact)(cn=" . $search . "))"; |
|
| 250 | - $fields = array("displayname","distinguishedname"); |
|
| 249 | + $filter = "(&(objectClass=contact)(cn=".$search."))"; |
|
| 250 | + $fields = array("displayname", "distinguishedname"); |
|
| 251 | 251 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 252 | 252 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 253 | 253 | |
| 254 | 254 | $usersArray = array(); |
| 255 | - for ($i=0; $i<$entries["count"]; $i++) { |
|
| 256 | - if ($includeDescription && strlen($entries[$i]["displayname"][0])>0){ |
|
| 255 | + for ($i = 0; $i < $entries["count"]; $i++) { |
|
| 256 | + if ($includeDescription && strlen($entries[$i]["displayname"][0]) > 0) { |
|
| 257 | 257 | $usersArray[$entries[$i]["distinguishedname"][0]] = $entries[$i]["displayname"][0]; |
| 258 | - } elseif ($includeDescription){ |
|
| 258 | + } elseif ($includeDescription) { |
|
| 259 | 259 | $usersArray[$entries[$i]["distinguishedname"][0]] = $entries[$i]["distinguishedname"][0]; |
| 260 | 260 | } else { |
| 261 | 261 | array_push($usersArray, $entries[$i]["distinguishedname"][0]); |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | * If the storage group has a different base_dn to the adLDAP configuration, set it using $base_dn |
| 61 | 61 | * @param string $emailAddress The primary email address to add to this user |
| 62 | 62 | * @param string $mailNickname The mail nick name. If mail nickname is blank, the username will be used |
| 63 | - * @param bool $mdbUseDefaults Indicates whether the store should use the default quota, rather than the per-mailbox quota. |
|
| 63 | + * @param bool $useDefaults Indicates whether the store should use the default quota, rather than the per-mailbox quota. |
|
| 64 | 64 | * @param string $baseDn Specify an alternative base_dn for the Exchange storage group |
| 65 | 65 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 66 | - * @return bool |
|
| 66 | + * @return string|boolean |
|
| 67 | 67 | */ |
| 68 | 68 | public function createMailbox($username, $storageGroup, $emailAddress, $mailNickname=NULL, $useDefaults=TRUE, $baseDn=NULL, $isGUID=false) { |
| 69 | 69 | if ($username === NULL){ return "Missing compulsory field [username]"; } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param string $surname Surname |
| 109 | 109 | * @param string $givenName Given name |
| 110 | 110 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 111 | - * @return bool |
|
| 111 | + * @return string|boolean |
|
| 112 | 112 | */ |
| 113 | 113 | public function addX400($username, $country, $admd, $pdmd, $org, $surname, $givenName, $isGUID=false) { |
| 114 | 114 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string $emailAddress The email address to add to this user |
| 146 | 146 | * @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 |
| 147 | 147 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 148 | - * @return bool |
|
| 148 | + * @return string|boolean |
|
| 149 | 149 | */ |
| 150 | 150 | public function addAddress($username, $emailAddress, $default = FALSE, $isGUID = false) { |
| 151 | 151 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param string $username The username of the user to add the Exchange account to |
| 211 | 211 | * @param string $emailAddress The email address to add to this user |
| 212 | 212 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 213 | - * @return bool |
|
| 213 | + * @return string|boolean |
|
| 214 | 214 | */ |
| 215 | 215 | public function deleteAddress($username, $emailAddress, $isGUID=false) { |
| 216 | 216 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @param string $distinguishedName The contact to mail enable |
| 289 | 289 | * @param string $emailAddress The email address to allow emails to be sent through |
| 290 | 290 | * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
| 291 | - * @return bool |
|
| 291 | + * @return string|boolean |
|
| 292 | 292 | */ |
| 293 | 293 | public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) { |
| 294 | 294 | if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedName]"; } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | class adLDAPExchange { |
| 44 | 44 | /** |
| 45 | - * The current adLDAP connection via dependency injection |
|
| 46 | - * |
|
| 47 | - * @var adLDAP |
|
| 48 | - */ |
|
| 45 | + * The current adLDAP connection via dependency injection |
|
| 46 | + * |
|
| 47 | + * @var adLDAP |
|
| 48 | + */ |
|
| 49 | 49 | protected $adldap; |
| 50 | 50 | |
| 51 | 51 | public function __construct(adLDAP $adldap) { |
@@ -53,18 +53,18 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * Create an Exchange account |
|
| 57 | - * |
|
| 58 | - * @param string $username The username of the user to add the Exchange account to |
|
| 59 | - * @param array $storageGroup The mailbox, Exchange Storage Group, for the user account, this must be a full CN |
|
| 60 | - * If the storage group has a different base_dn to the adLDAP configuration, set it using $base_dn |
|
| 61 | - * @param string $emailAddress The primary email address to add to this user |
|
| 62 | - * @param string $mailNickname The mail nick name. If mail nickname is blank, the username will be used |
|
| 63 | - * @param bool $mdbUseDefaults Indicates whether the store should use the default quota, rather than the per-mailbox quota. |
|
| 64 | - * @param string $baseDn Specify an alternative base_dn for the Exchange storage group |
|
| 65 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 56 | + * Create an Exchange account |
|
| 57 | + * |
|
| 58 | + * @param string $username The username of the user to add the Exchange account to |
|
| 59 | + * @param array $storageGroup The mailbox, Exchange Storage Group, for the user account, this must be a full CN |
|
| 60 | + * If the storage group has a different base_dn to the adLDAP configuration, set it using $base_dn |
|
| 61 | + * @param string $emailAddress The primary email address to add to this user |
|
| 62 | + * @param string $mailNickname The mail nick name. If mail nickname is blank, the username will be used |
|
| 63 | + * @param bool $mdbUseDefaults Indicates whether the store should use the default quota, rather than the per-mailbox quota. |
|
| 64 | + * @param string $baseDn Specify an alternative base_dn for the Exchange storage group |
|
| 65 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | 68 | public function createMailbox($username, $storageGroup, $emailAddress, $mailNickname=NULL, $useDefaults=TRUE, $baseDn=NULL, $isGUID=false) { |
| 69 | 69 | if ($username === NULL){ return "Missing compulsory field [username]"; } |
| 70 | 70 | if ($storageGroup === NULL) { return "Missing compulsory array [storagegroup]"; } |
@@ -96,20 +96,20 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | - * Add an X400 address to Exchange |
|
| 100 | - * See http://tools.ietf.org/html/rfc1685 for more information. |
|
| 101 | - * An X400 Address looks similar to this X400:c=US;a= ;p=Domain;o=Organization;s=Doe;g=John; |
|
| 102 | - * |
|
| 103 | - * @param string $username The username of the user to add the X400 to to |
|
| 104 | - * @param string $country Country |
|
| 105 | - * @param string $admd Administration Management Domain |
|
| 106 | - * @param string $pdmd Private Management Domain (often your AD domain) |
|
| 107 | - * @param string $org Organization |
|
| 108 | - * @param string $surname Surname |
|
| 109 | - * @param string $givenName Given name |
|
| 110 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 99 | + * Add an X400 address to Exchange |
|
| 100 | + * See http://tools.ietf.org/html/rfc1685 for more information. |
|
| 101 | + * An X400 Address looks similar to this X400:c=US;a= ;p=Domain;o=Organization;s=Doe;g=John; |
|
| 102 | + * |
|
| 103 | + * @param string $username The username of the user to add the X400 to to |
|
| 104 | + * @param string $country Country |
|
| 105 | + * @param string $admd Administration Management Domain |
|
| 106 | + * @param string $pdmd Private Management Domain (often your AD domain) |
|
| 107 | + * @param string $org Organization |
|
| 108 | + * @param string $surname Surname |
|
| 109 | + * @param string $givenName Given name |
|
| 110 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | 113 | public function addX400($username, $country, $admd, $pdmd, $org, $surname, $givenName, $isGUID=false) { |
| 114 | 114 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 115 | 115 | |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | - * Add an address to Exchange |
|
| 143 | - * |
|
| 144 | - * @param string $username The username of the user to add the Exchange account to |
|
| 145 | - * @param string $emailAddress The email address to add to this user |
|
| 146 | - * @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 |
|
| 147 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 142 | + * Add an address to Exchange |
|
| 143 | + * |
|
| 144 | + * @param string $username The username of the user to add the Exchange account to |
|
| 145 | + * @param string $emailAddress The email address to add to this user |
|
| 146 | + * @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 |
|
| 147 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | 150 | public function addAddress($username, $emailAddress, $default = FALSE, $isGUID = false) { |
| 151 | 151 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 152 | 152 | if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | - * Remove an address to Exchange |
|
| 207 | - * If you remove a default address the account will no longer have a default, |
|
| 208 | - * we recommend changing the default address first |
|
| 209 | - * |
|
| 210 | - * @param string $username The username of the user to add the Exchange account to |
|
| 211 | - * @param string $emailAddress The email address to add to this user |
|
| 212 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 213 | - * @return bool |
|
| 214 | - */ |
|
| 206 | + * Remove an address to Exchange |
|
| 207 | + * If you remove a default address the account will no longer have a default, |
|
| 208 | + * we recommend changing the default address first |
|
| 209 | + * |
|
| 210 | + * @param string $username The username of the user to add the Exchange account to |
|
| 211 | + * @param string $emailAddress The email address to add to this user |
|
| 212 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 213 | + * @return bool |
|
| 214 | + */ |
|
| 215 | 215 | public function deleteAddress($username, $emailAddress, $isGUID=false) { |
| 216 | 216 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 217 | 217 | if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } |
@@ -243,13 +243,13 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | /** |
| 246 | - * Change the default address |
|
| 247 | - * |
|
| 248 | - * @param string $username The username of the user to add the Exchange account to |
|
| 249 | - * @param string $emailAddress The email address to make default |
|
| 250 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 246 | + * Change the default address |
|
| 247 | + * |
|
| 248 | + * @param string $username The username of the user to add the Exchange account to |
|
| 249 | + * @param string $emailAddress The email address to make default |
|
| 250 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | 253 | public function primaryAddress($username, $emailAddress, $isGUID = false) { |
| 254 | 254 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 255 | 255 | if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } |
@@ -282,14 +282,14 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | - * Mail enable a contact |
|
| 286 | - * Allows email to be sent to them through Exchange |
|
| 287 | - * |
|
| 288 | - * @param string $distinguishedName The contact to mail enable |
|
| 289 | - * @param string $emailAddress The email address to allow emails to be sent through |
|
| 290 | - * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 285 | + * Mail enable a contact |
|
| 286 | + * Allows email to be sent to them through Exchange |
|
| 287 | + * |
|
| 288 | + * @param string $distinguishedName The contact to mail enable |
|
| 289 | + * @param string $emailAddress The email address to allow emails to be sent through |
|
| 290 | + * @param string $mailNickname The mailnickname for the contact in Exchange. If NULL this will be set to the display name |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | 293 | public function contactMailEnable($distinguishedName, $emailAddress, $mailNickname = NULL) { |
| 294 | 294 | if ($distinguishedName === NULL) { return "Missing compulsory field [distinguishedName]"; } |
| 295 | 295 | if ($emailAddress === NULL) { return "Missing compulsory field [emailAddress]"; } |
@@ -317,11 +317,11 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | - * Returns a list of Exchange Servers in the ConfigurationNamingContext of the domain |
|
| 321 | - * |
|
| 322 | - * @param array $attributes An array of the AD attributes you wish to return |
|
| 323 | - * @return array |
|
| 324 | - */ |
|
| 320 | + * Returns a list of Exchange Servers in the ConfigurationNamingContext of the domain |
|
| 321 | + * |
|
| 322 | + * @param array $attributes An array of the AD attributes you wish to return |
|
| 323 | + * @return array |
|
| 324 | + */ |
|
| 325 | 325 | public function servers($attributes = array('cn','distinguishedname','serialnumber')) { |
| 326 | 326 | if (!$this->adldap->getLdapBind()) { return false; } |
| 327 | 327 | |
@@ -332,13 +332,13 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
| 335 | - * Returns a list of Storage Groups in Exchange for a given mail server |
|
| 336 | - * |
|
| 337 | - * @param string $exchangeServer The full DN of an Exchange server. You can use exchange_servers() to find the DN for your server |
|
| 338 | - * @param array $attributes An array of the AD attributes you wish to return |
|
| 339 | - * @param bool $recursive If enabled this will automatically query the databases within a storage group |
|
| 340 | - * @return array |
|
| 341 | - */ |
|
| 335 | + * Returns a list of Storage Groups in Exchange for a given mail server |
|
| 336 | + * |
|
| 337 | + * @param string $exchangeServer The full DN of an Exchange server. You can use exchange_servers() to find the DN for your server |
|
| 338 | + * @param array $attributes An array of the AD attributes you wish to return |
|
| 339 | + * @param bool $recursive If enabled this will automatically query the databases within a storage group |
|
| 340 | + * @return array |
|
| 341 | + */ |
|
| 342 | 342 | public function storageGroups($exchangeServer, $attributes = array('cn','distinguishedname'), $recursive = NULL) { |
| 343 | 343 | if (!$this->adldap->getLdapBind()) { return false; } |
| 344 | 344 | if ($exchangeServer === NULL) { return "Missing compulsory field [exchangeServer]"; } |
@@ -357,12 +357,12 @@ discard block |
||
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
| 360 | - * Returns a list of Databases within any given storage group in Exchange for a given mail server |
|
| 361 | - * |
|
| 362 | - * @param string $storageGroup The full DN of an Storage Group. You can use exchange_storage_groups() to find the DN |
|
| 363 | - * @param array $attributes An array of the AD attributes you wish to return |
|
| 364 | - * @return array |
|
| 365 | - */ |
|
| 360 | + * Returns a list of Databases within any given storage group in Exchange for a given mail server |
|
| 361 | + * |
|
| 362 | + * @param string $storageGroup The full DN of an Storage Group. You can use exchange_storage_groups() to find the DN |
|
| 363 | + * @param array $attributes An array of the AD attributes you wish to return |
|
| 364 | + * @return array |
|
| 365 | + */ |
|
| 366 | 366 | public function storageDatabases($storageGroup, $attributes = array('cn','distinguishedname','displayname')) { |
| 367 | 367 | if (!$this->adldap->getLdapBind()) { return false; } |
| 368 | 368 | if ($storageGroup === NULL) { return "Missing compulsory field [storageGroup]"; } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * MICROSOFT EXCHANGE FUNCTIONS |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 66 | 66 | * @return bool |
| 67 | 67 | */ |
| 68 | - public function createMailbox($username, $storageGroup, $emailAddress, $mailNickname=NULL, $useDefaults=TRUE, $baseDn=NULL, $isGUID=false) { |
|
| 69 | - if ($username === NULL){ return "Missing compulsory field [username]"; } |
|
| 68 | + public function createMailbox($username, $storageGroup, $emailAddress, $mailNickname = NULL, $useDefaults = TRUE, $baseDn = NULL, $isGUID = false) { |
|
| 69 | + if ($username === NULL) { return "Missing compulsory field [username]"; } |
|
| 70 | 70 | if ($storageGroup === NULL) { return "Missing compulsory array [storagegroup]"; } |
| 71 | 71 | if (!is_array($storageGroup)) { return "[storagegroup] must be an array"; } |
| 72 | 72 | if ($emailAddress === NULL) { return "Missing compulsory field [emailAddress]"; } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $baseDn = $this->adldap->getBaseDn(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $container = "CN=" . implode(",CN=", $storageGroup); |
|
| 78 | + $container = "CN=".implode(",CN=", $storageGroup); |
|
| 79 | 79 | |
| 80 | 80 | if ($mailNickname === NULL) { |
| 81 | 81 | $mailNickname = $username; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | $attributes = array( |
| 86 | 86 | 'exchange_homemdb'=>$container.",".$baseDn, |
| 87 | - 'exchange_proxyaddress'=>'SMTP:' . $emailAddress, |
|
| 87 | + 'exchange_proxyaddress'=>'SMTP:'.$emailAddress, |
|
| 88 | 88 | 'exchange_mailnickname'=>$mailNickname, |
| 89 | 89 | 'exchange_usedefaults'=>$mdbUseDefaults |
| 90 | 90 | ); |
@@ -110,18 +110,18 @@ discard block |
||
| 110 | 110 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 111 | 111 | * @return bool |
| 112 | 112 | */ |
| 113 | - public function addX400($username, $country, $admd, $pdmd, $org, $surname, $givenName, $isGUID=false) { |
|
| 113 | + public function addX400($username, $country, $admd, $pdmd, $org, $surname, $givenName, $isGUID = false) { |
|
| 114 | 114 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 115 | 115 | |
| 116 | 116 | $proxyValue = 'X400:'; |
| 117 | 117 | |
| 118 | 118 | // Find the dn of the user |
| 119 | - $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); |
|
| 119 | + $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID); |
|
| 120 | 120 | if ($user[0]["dn"] === NULL) { return false; } |
| 121 | 121 | $userDn = $user[0]["dn"]; |
| 122 | 122 | |
| 123 | 123 | // We do not have to demote an email address from the default so we can just add the new proxy address |
| 124 | - $attributes['exchange_proxyaddress'] = $proxyValue . 'c=' . $country . ';a=' . $admd . ';p=' . $pdmd . ';o=' . $org . ';s=' . $surname . ';g=' . $givenName . ';'; |
|
| 124 | + $attributes['exchange_proxyaddress'] = $proxyValue.'c='.$country.';a='.$admd.';p='.$pdmd.';o='.$org.';s='.$surname.';g='.$givenName.';'; |
|
| 125 | 125 | |
| 126 | 126 | // Translate the update to the LDAP schema |
| 127 | 127 | $add = $this->adldap->adldap_schema($attributes); |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Find the dn of the user |
| 160 | - $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); |
|
| 161 | - if ($user[0]["dn"] === NULL){ return false; } |
|
| 160 | + $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID); |
|
| 161 | + if ($user[0]["dn"] === NULL) { return false; } |
|
| 162 | 162 | $userDn = $user[0]["dn"]; |
| 163 | 163 | |
| 164 | 164 | // We need to scan existing proxy addresses and demote the default one |
| 165 | 165 | if (is_array($user[0]["proxyaddresses"]) && $default === true) { |
| 166 | 166 | $modAddresses = array(); |
| 167 | - for ($i=0;$i<$user[0]['proxyaddresses']['count'];$i++) { |
|
| 167 | + for ($i = 0; $i < $user[0]['proxyaddresses']['count']; $i++) { |
|
| 168 | 168 | if (strpos($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) { |
| 169 | 169 | $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]); |
| 170 | 170 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $modAddresses['proxyAddresses'][$i] = $user[0]['proxyaddresses'][$i]; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | - $modAddresses['proxyAddresses'][($user[0]['proxyaddresses']['count']-1)] = 'SMTP:' . $emailAddress; |
|
| 175 | + $modAddresses['proxyAddresses'][($user[0]['proxyaddresses']['count'] - 1)] = 'SMTP:'.$emailAddress; |
|
| 176 | 176 | |
| 177 | 177 | $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $modAddresses); |
| 178 | 178 | if ($result == false) { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | else { |
| 184 | 184 | // We do not have to demote an email address from the default so we can just add the new proxy address |
| 185 | - $attributes['exchange_proxyaddress'] = $proxyValue . $emailAddress; |
|
| 185 | + $attributes['exchange_proxyaddress'] = $proxyValue.$emailAddress; |
|
| 186 | 186 | |
| 187 | 187 | // Translate the update to the LDAP schema |
| 188 | 188 | $add = $this->adldap->adldap_schema($attributes); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | // Do the update |
| 195 | 195 | // Take out the @ to see any errors, usually this error might occur because the address already |
| 196 | 196 | // exists in the list of proxyAddresses |
| 197 | - $result = @ldap_mod_add($this->adldap->getLdapConnection(), $userDn,$add); |
|
| 197 | + $result = @ldap_mod_add($this->adldap->getLdapConnection(), $userDn, $add); |
|
| 198 | 198 | if ($result == false) { |
| 199 | 199 | return false; |
| 200 | 200 | } |
@@ -212,27 +212,27 @@ discard block |
||
| 212 | 212 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 213 | 213 | * @return bool |
| 214 | 214 | */ |
| 215 | - public function deleteAddress($username, $emailAddress, $isGUID=false) { |
|
| 215 | + public function deleteAddress($username, $emailAddress, $isGUID = false) { |
|
| 216 | 216 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 217 | 217 | if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } |
| 218 | 218 | |
| 219 | 219 | // Find the dn of the user |
| 220 | - $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); |
|
| 220 | + $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID); |
|
| 221 | 221 | if ($user[0]["dn"] === NULL) { return false; } |
| 222 | 222 | $userDn = $user[0]["dn"]; |
| 223 | 223 | |
| 224 | 224 | if (is_array($user[0]["proxyaddresses"])) { |
| 225 | 225 | $mod = array(); |
| 226 | - for ($i=0;$i<$user[0]['proxyaddresses']['count'];$i++) { |
|
| 227 | - if (strpos($user[0]['proxyaddresses'][$i], 'SMTP:') !== false && $user[0]['proxyaddresses'][$i] == 'SMTP:' . $emailAddress) { |
|
| 228 | - $mod['proxyAddresses'][0] = 'SMTP:' . $emailAddress; |
|
| 226 | + for ($i = 0; $i < $user[0]['proxyaddresses']['count']; $i++) { |
|
| 227 | + if (strpos($user[0]['proxyaddresses'][$i], 'SMTP:') !== false && $user[0]['proxyaddresses'][$i] == 'SMTP:'.$emailAddress) { |
|
| 228 | + $mod['proxyAddresses'][0] = 'SMTP:'.$emailAddress; |
|
| 229 | 229 | } |
| 230 | - elseif (strpos($user[0]['proxyaddresses'][$i], 'smtp:') !== false && $user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { |
|
| 231 | - $mod['proxyAddresses'][0] = 'smtp:' . $emailAddress; |
|
| 230 | + elseif (strpos($user[0]['proxyaddresses'][$i], 'smtp:') !== false && $user[0]['proxyaddresses'][$i] == 'smtp:'.$emailAddress) { |
|
| 231 | + $mod['proxyAddresses'][0] = 'smtp:'.$emailAddress; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $result = @ldap_mod_del($this->adldap->getLdapConnection(), $userDn,$mod); |
|
| 235 | + $result = @ldap_mod_del($this->adldap->getLdapConnection(), $userDn, $mod); |
|
| 236 | 236 | if ($result == false) { |
| 237 | 237 | return false; |
| 238 | 238 | } |
@@ -255,17 +255,17 @@ discard block |
||
| 255 | 255 | if ($emailAddress === NULL) { return "Missing compulsory fields [emailAddress]"; } |
| 256 | 256 | |
| 257 | 257 | // Find the dn of the user |
| 258 | - $user = $this->adldap->user()->info($username, array("cn","proxyaddresses"), $isGUID); |
|
| 258 | + $user = $this->adldap->user()->info($username, array("cn", "proxyaddresses"), $isGUID); |
|
| 259 | 259 | if ($user[0]["dn"] === NULL) { return false; } |
| 260 | 260 | $userDn = $user[0]["dn"]; |
| 261 | 261 | |
| 262 | 262 | if (is_array($user[0]["proxyaddresses"])) { |
| 263 | 263 | $modAddresses = array(); |
| 264 | - for ($i=0;$i<$user[0]['proxyaddresses']['count'];$i++) { |
|
| 264 | + for ($i = 0; $i < $user[0]['proxyaddresses']['count']; $i++) { |
|
| 265 | 265 | if (strpos($user[0]['proxyaddresses'][$i], 'SMTP:') !== false) { |
| 266 | 266 | $user[0]['proxyaddresses'][$i] = str_replace('SMTP:', 'smtp:', $user[0]['proxyaddresses'][$i]); |
| 267 | 267 | } |
| 268 | - if ($user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { |
|
| 268 | + if ($user[0]['proxyaddresses'][$i] == 'smtp:'.$emailAddress) { |
|
| 269 | 269 | $user[0]['proxyaddresses'][$i] = str_replace('smtp:', 'SMTP:', $user[0]['proxyaddresses'][$i]); |
| 270 | 270 | } |
| 271 | 271 | if ($user[0]['proxyaddresses'][$i] != '') { |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | |
| 297 | 297 | if ($mailNickname !== NULL) { |
| 298 | 298 | // Find the dn of the user |
| 299 | - $user = $this->adldap->contact()->info($distinguishedName, array("cn","displayname")); |
|
| 299 | + $user = $this->adldap->contact()->info($distinguishedName, array("cn", "displayname")); |
|
| 300 | 300 | if ($user[0]["displayname"] === NULL) { return false; } |
| 301 | 301 | $mailNickname = $user[0]['displayname'][0]; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - $attributes = array("email"=>$emailAddress,"contact_email"=>"SMTP:" . $emailAddress,"exchange_proxyaddress"=>"SMTP:" . $emailAddress,"exchange_mailnickname" => $mailNickname); |
|
| 304 | + $attributes = array("email"=>$emailAddress, "contact_email"=>"SMTP:".$emailAddress, "exchange_proxyaddress"=>"SMTP:".$emailAddress, "exchange_mailnickname" => $mailNickname); |
|
| 305 | 305 | |
| 306 | 306 | // Translate the update to the LDAP schema |
| 307 | 307 | $mod = $this->adldap->adldap_schema($attributes); |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | * @param array $attributes An array of the AD attributes you wish to return |
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | - public function servers($attributes = array('cn','distinguishedname','serialnumber')) { |
|
| 325 | + public function servers($attributes = array('cn', 'distinguishedname', 'serialnumber')) { |
|
| 326 | 326 | if (!$this->adldap->getLdapBind()) { return false; } |
| 327 | 327 | |
| 328 | 328 | $configurationNamingContext = $this->adldap->getRootDse(array('configurationnamingcontext')); |
| 329 | - $sr = @ldap_search($this->adldap->getLdapConnection(), $configurationNamingContext[0]['configurationnamingcontext'][0],'(&(objectCategory=msExchExchangeServer))', $attributes); |
|
| 329 | + $sr = @ldap_search($this->adldap->getLdapConnection(), $configurationNamingContext[0]['configurationnamingcontext'][0], '(&(objectCategory=msExchExchangeServer))', $attributes); |
|
| 330 | 330 | $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 331 | 331 | return $entries; |
| 332 | 332 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | * @param bool $recursive If enabled this will automatically query the databases within a storage group |
| 340 | 340 | * @return array |
| 341 | 341 | */ |
| 342 | - public function storageGroups($exchangeServer, $attributes = array('cn','distinguishedname'), $recursive = NULL) { |
|
| 342 | + public function storageGroups($exchangeServer, $attributes = array('cn', 'distinguishedname'), $recursive = NULL) { |
|
| 343 | 343 | if (!$this->adldap->getLdapBind()) { return false; } |
| 344 | 344 | if ($exchangeServer === NULL) { return "Missing compulsory field [exchangeServer]"; } |
| 345 | 345 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 350 | 350 | |
| 351 | 351 | if ($recursive === true) { |
| 352 | - for ($i=0; $i<$entries['count']; $i++) { |
|
| 352 | + for ($i = 0; $i < $entries['count']; $i++) { |
|
| 353 | 353 | $entries[$i]['msexchprivatemdb'] = $this->storageDatabases($entries[$i]['distinguishedname'][0]); |
| 354 | 354 | } |
| 355 | 355 | } |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | * @param array $attributes An array of the AD attributes you wish to return |
| 364 | 364 | * @return array |
| 365 | 365 | */ |
| 366 | - public function storageDatabases($storageGroup, $attributes = array('cn','distinguishedname','displayname')) { |
|
| 366 | + public function storageDatabases($storageGroup, $attributes = array('cn', 'distinguishedname', 'displayname')) { |
|
| 367 | 367 | if (!$this->adldap->getLdapBind()) { return false; } |
| 368 | 368 | if ($storageGroup === NULL) { return "Missing compulsory field [storageGroup]"; } |
| 369 | 369 | |
@@ -179,8 +179,7 @@ discard block |
||
| 179 | 179 | return false; |
| 180 | 180 | } |
| 181 | 181 | return true; |
| 182 | - } |
|
| 183 | - else { |
|
| 182 | + } else { |
|
| 184 | 183 | // We do not have to demote an email address from the default so we can just add the new proxy address |
| 185 | 184 | $attributes['exchange_proxyaddress'] = $proxyValue . $emailAddress; |
| 186 | 185 | |
@@ -226,8 +225,7 @@ discard block |
||
| 226 | 225 | for ($i=0;$i<$user[0]['proxyaddresses']['count'];$i++) { |
| 227 | 226 | if (strpos($user[0]['proxyaddresses'][$i], 'SMTP:') !== false && $user[0]['proxyaddresses'][$i] == 'SMTP:' . $emailAddress) { |
| 228 | 227 | $mod['proxyAddresses'][0] = 'SMTP:' . $emailAddress; |
| 229 | - } |
|
| 230 | - elseif (strpos($user[0]['proxyaddresses'][$i], 'smtp:') !== false && $user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { |
|
| 228 | + } elseif (strpos($user[0]['proxyaddresses'][$i], 'smtp:') !== false && $user[0]['proxyaddresses'][$i] == 'smtp:' . $emailAddress) { |
|
| 231 | 229 | $mod['proxyAddresses'][0] = 'smtp:' . $emailAddress; |
| 232 | 230 | } |
| 233 | 231 | } |
@@ -237,8 +235,7 @@ discard block |
||
| 237 | 235 | return false; |
| 238 | 236 | } |
| 239 | 237 | return true; |
| 240 | - } |
|
| 241 | - else { |
|
| 238 | + } else { |
|
| 242 | 239 | return false; |
| 243 | 240 | } |
| 244 | 241 | } |
@@ -145,7 +145,7 @@ |
||
| 145 | 145 | * Create an organizational unit |
| 146 | 146 | * |
| 147 | 147 | * @param array $attributes Default attributes of the ou |
| 148 | - * @return bool |
|
| 148 | + * @return string|boolean |
|
| 149 | 149 | */ |
| 150 | 150 | public function create($attributes) { |
| 151 | 151 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | class adLDAPFolders { |
| 44 | 44 | /** |
| 45 | - * The current adLDAP connection via dependency injection |
|
| 46 | - * |
|
| 47 | - * @var adLDAP |
|
| 48 | - */ |
|
| 45 | + * The current adLDAP connection via dependency injection |
|
| 46 | + * |
|
| 47 | + * @var adLDAP |
|
| 48 | + */ |
|
| 49 | 49 | protected $adldap; |
| 50 | 50 | |
| 51 | 51 | public function __construct(adLDAP $adldap) { |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * Delete a distinguished name from Active Directory |
|
| 57 | - * You should never need to call this yourself, just use the wrapper functions user_delete and contact_delete |
|
| 58 | - * |
|
| 59 | - * @param string $dn The distinguished name to delete |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 56 | + * Delete a distinguished name from Active Directory |
|
| 57 | + * You should never need to call this yourself, just use the wrapper functions user_delete and contact_delete |
|
| 58 | + * |
|
| 59 | + * @param string $dn The distinguished name to delete |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | 62 | public function delete($dn) { |
| 63 | 63 | $result = ldap_delete($this->adldap->getLdapConnection(), $dn); |
| 64 | 64 | if ($result != true) { |
@@ -68,17 +68,17 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * Returns a folder listing for a specific OU |
|
| 72 | - * See http://adldap.sourceforge.net/wiki/doku.php?id=api_folder_functions |
|
| 73 | - * |
|
| 74 | - * @param array $folderName An array to the OU you wish to list. |
|
| 75 | - * If set to NULL will list the root, strongly recommended to set |
|
| 76 | - * $recursive to false in that instance! |
|
| 77 | - * @param string $dnType The type of record to list. This can be ADLDAP_FOLDER or ADLDAP_CONTAINER. |
|
| 78 | - * @param bool $recursive Recursively search sub folders |
|
| 79 | - * @param bool $type Specify a type of object to search for |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 71 | + * Returns a folder listing for a specific OU |
|
| 72 | + * See http://adldap.sourceforge.net/wiki/doku.php?id=api_folder_functions |
|
| 73 | + * |
|
| 74 | + * @param array $folderName An array to the OU you wish to list. |
|
| 75 | + * If set to NULL will list the root, strongly recommended to set |
|
| 76 | + * $recursive to false in that instance! |
|
| 77 | + * @param string $dnType The type of record to list. This can be ADLDAP_FOLDER or ADLDAP_CONTAINER. |
|
| 78 | + * @param bool $recursive Recursively search sub folders |
|
| 79 | + * @param bool $type Specify a type of object to search for |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | 82 | public function listing($folderName = NULL, $dnType = adLDAP::ADLDAP_FOLDER, $recursive = NULL, $type = NULL) { |
| 83 | 83 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } //use the default option if they haven't set it |
| 84 | 84 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
| 145 | - * Create an organizational unit |
|
| 146 | - * |
|
| 147 | - * @param array $attributes Default attributes of the ou |
|
| 148 | - * @return bool |
|
| 149 | - */ |
|
| 145 | + * Create an organizational unit |
|
| 146 | + * |
|
| 147 | + * @param array $attributes Default attributes of the ou |
|
| 148 | + * @return bool |
|
| 149 | + */ |
|
| 150 | 150 | public function create($attributes) { |
| 151 | 151 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
| 152 | 152 | if (!is_array($attributes["container"])) { return "Container attribute must be an array."; } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * FOLDER / OU MANAGEMENT FUNCTIONS |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | // This requires us to not have an OU= part, just the base_dn |
| 117 | 117 | $searchOu = $this->adldap->getBaseDn(); |
| 118 | 118 | if (is_array($folderName)) { |
| 119 | - $ou = $dnType . "=" . implode("," . $dnType . "=", $folderName); |
|
| 120 | - $filter .= '(!(distinguishedname=' . $ou . ',' . $this->adldap->getBaseDn() . ')))'; |
|
| 121 | - $searchOu = $ou . ',' . $this->adldap->getBaseDn(); |
|
| 119 | + $ou = $dnType."=".implode(",".$dnType."=", $folderName); |
|
| 120 | + $filter .= '(!(distinguishedname='.$ou.','.$this->adldap->getBaseDn().')))'; |
|
| 121 | + $searchOu = $ou.','.$this->adldap->getBaseDn(); |
|
| 122 | 122 | } |
| 123 | 123 | else { |
| 124 | - $filter .= '(!(distinguishedname=' . $this->adldap->getBaseDn() . ')))'; |
|
| 124 | + $filter .= '(!(distinguishedname='.$this->adldap->getBaseDn().')))'; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if ($recursive === true) { |
@@ -150,21 +150,21 @@ discard block |
||
| 150 | 150 | public function create($attributes) { |
| 151 | 151 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
| 152 | 152 | if (!is_array($attributes["container"])) { return "Container attribute must be an array."; } |
| 153 | - if (!array_key_exists("ou_name",$attributes)) { return "Missing compulsory field [ou_name]"; } |
|
| 154 | - if (!array_key_exists("container",$attributes)) { return "Missing compulsory field [container]"; } |
|
| 153 | + if (!array_key_exists("ou_name", $attributes)) { return "Missing compulsory field [ou_name]"; } |
|
| 154 | + if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
|
| 155 | 155 | |
| 156 | 156 | $attributes["container"] = array_reverse($attributes["container"]); |
| 157 | 157 | |
| 158 | - $add=array(); |
|
| 158 | + $add = array(); |
|
| 159 | 159 | $add["objectClass"] = "organizationalUnit"; |
| 160 | 160 | $add["OU"] = $attributes['ou_name']; |
| 161 | 161 | $containers = ""; |
| 162 | 162 | if (count($attributes['container']) > 0) { |
| 163 | - $containers = "OU=" . implode(",OU=", $attributes["container"]) . ","; |
|
| 163 | + $containers = "OU=".implode(",OU=", $attributes["container"]).","; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $containers = "OU=" . implode(",OU=", $attributes["container"]); |
|
| 167 | - $result = ldap_add($this->adldap->getLdapConnection(), "OU=" . $add["OU"] . ", " . $containers . $this->adldap->getBaseDn(), $add); |
|
| 166 | + $containers = "OU=".implode(",OU=", $attributes["container"]); |
|
| 167 | + $result = ldap_add($this->adldap->getLdapConnection(), "OU=".$add["OU"].", ".$containers.$this->adldap->getBaseDn(), $add); |
|
| 168 | 168 | if ($result != true) { |
| 169 | 169 | return false; |
| 170 | 170 | } |
@@ -108,8 +108,7 @@ discard block |
||
| 108 | 108 | $filter .= '(objectClass=user)'; |
| 109 | 109 | break; |
| 110 | 110 | } |
| 111 | - } |
|
| 112 | - else { |
|
| 111 | + } else { |
|
| 113 | 112 | $filter .= '(objectClass=*)'; |
| 114 | 113 | } |
| 115 | 114 | // If the folder name is null then we will search the root level of AD |
@@ -119,8 +118,7 @@ discard block |
||
| 119 | 118 | $ou = $dnType . "=" . implode("," . $dnType . "=", $folderName); |
| 120 | 119 | $filter .= '(!(distinguishedname=' . $ou . ',' . $this->adldap->getBaseDn() . ')))'; |
| 121 | 120 | $searchOu = $ou . ',' . $this->adldap->getBaseDn(); |
| 122 | - } |
|
| 123 | - else { |
|
| 121 | + } else { |
|
| 124 | 122 | $filter .= '(!(distinguishedname=' . $this->adldap->getBaseDn() . ')))'; |
| 125 | 123 | } |
| 126 | 124 | |
@@ -130,8 +128,7 @@ discard block |
||
| 130 | 128 | if (is_array($entries)) { |
| 131 | 129 | return $entries; |
| 132 | 130 | } |
| 133 | - } |
|
| 134 | - else { |
|
| 131 | + } else { |
|
| 135 | 132 | $sr = ldap_list($this->adldap->getLdapConnection(), $searchOu, $filter, array('objectclass', 'distinguishedname', 'samaccountname')); |
| 136 | 133 | $entries = @ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 137 | 134 | if (is_array($entries)) { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * Create a group |
| 155 | 155 | * |
| 156 | 156 | * @param array $attributes Default attributes of the group |
| 157 | - * @return bool |
|
| 157 | + * @return string|boolean |
|
| 158 | 158 | */ |
| 159 | 159 | public function create($attributes) { |
| 160 | 160 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @param string $group The group to delete (please be careful here!) |
| 190 | 190 | * |
| 191 | - * @return array |
|
| 191 | + * @return string|boolean |
|
| 192 | 192 | */ |
| 193 | 193 | public function delete($group) { |
| 194 | 194 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | class adLDAPGroups { |
| 45 | 45 | /** |
| 46 | - * The current adLDAP connection via dependency injection |
|
| 47 | - * |
|
| 48 | - * @var adLDAP |
|
| 49 | - */ |
|
| 46 | + * The current adLDAP connection via dependency injection |
|
| 47 | + * |
|
| 48 | + * @var adLDAP |
|
| 49 | + */ |
|
| 50 | 50 | protected $adldap; |
| 51 | 51 | |
| 52 | 52 | public function __construct(adLDAP $adldap) { |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Add a group to a group |
|
| 58 | - * |
|
| 59 | - * @param string $parent The parent group name |
|
| 60 | - * @param string $child The child group name |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 57 | + * Add a group to a group |
|
| 58 | + * |
|
| 59 | + * @param string $parent The parent group name |
|
| 60 | + * @param string $child The child group name |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | 63 | public function addGroup($parent,$child) { |
| 64 | 64 | |
| 65 | 65 | // Find the parent group's dn |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | - * Add a user to a group |
|
| 91 | - * |
|
| 92 | - * @param string $group The group to add the user to |
|
| 93 | - * @param string $user The user to add to the group |
|
| 94 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 95 | - * @return bool |
|
| 96 | - */ |
|
| 90 | + * Add a user to a group |
|
| 91 | + * |
|
| 92 | + * @param string $group The group to add the user to |
|
| 93 | + * @param string $user The user to add to the group |
|
| 94 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 95 | + * @return bool |
|
| 96 | + */ |
|
| 97 | 97 | public function addUser($group, $user, $isGUID = false) { |
| 98 | 98 | // Adding a user is a bit fiddly, we need to get the full DN of the user |
| 99 | 99 | // and add it using the full DN of the group |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Add a contact to a group |
|
| 126 | - * |
|
| 127 | - * @param string $group The group to add the contact to |
|
| 128 | - * @param string $contactDn The DN of the contact to add |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 125 | + * Add a contact to a group |
|
| 126 | + * |
|
| 127 | + * @param string $group The group to add the contact to |
|
| 128 | + * @param string $contactDn The DN of the contact to add |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | 131 | public function addContact($group, $contactDn) |
| 132 | 132 | { |
| 133 | 133 | // To add a contact we take the contact's DN |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | - * Create a group |
|
| 155 | - * |
|
| 156 | - * @param array $attributes Default attributes of the group |
|
| 157 | - * @return bool |
|
| 158 | - */ |
|
| 154 | + * Create a group |
|
| 155 | + * |
|
| 156 | + * @param array $attributes Default attributes of the group |
|
| 157 | + * @return bool |
|
| 158 | + */ |
|
| 159 | 159 | public function create($attributes) { |
| 160 | 160 | if (!is_array($attributes)) { return "Attributes must be an array"; } |
| 161 | 161 | if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; } |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | - * Delete a group account |
|
| 188 | - * |
|
| 189 | - * @param string $group The group to delete (please be careful here!) |
|
| 190 | - * |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 187 | + * Delete a group account |
|
| 188 | + * |
|
| 189 | + * @param string $group The group to delete (please be careful here!) |
|
| 190 | + * |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | 193 | public function delete($group) { |
| 194 | 194 | if (!$this->adldap->getLdapBind()) { return false; } |
| 195 | 195 | if ($group === null) { return "Missing compulsory field [group]"; } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | if ($result !== true) { |
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | - return true; |
|
| 203 | + return true; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Remove a group from a group |
|
| 238 | - * |
|
| 239 | - * @param string $parent The parent group name |
|
| 240 | - * @param string $child The child group name |
|
| 241 | - * @return bool |
|
| 242 | - */ |
|
| 237 | + * Remove a group from a group |
|
| 238 | + * |
|
| 239 | + * @param string $parent The parent group name |
|
| 240 | + * @param string $child The child group name |
|
| 241 | + * @return bool |
|
| 242 | + */ |
|
| 243 | 243 | public function removeGroup($parent , $child) { |
| 244 | 244 | |
| 245 | 245 | // Find the parent dn |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | - * Remove a user from a group |
|
| 271 | - * |
|
| 272 | - * @param string $group The group to remove a user from |
|
| 273 | - * @param string $user The AD user to remove from the group |
|
| 274 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 275 | - * @return bool |
|
| 276 | - */ |
|
| 270 | + * Remove a user from a group |
|
| 271 | + * |
|
| 272 | + * @param string $group The group to remove a user from |
|
| 273 | + * @param string $user The AD user to remove from the group |
|
| 274 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 275 | + * @return bool |
|
| 276 | + */ |
|
| 277 | 277 | public function removeUser($group, $user, $isGUID = false) { |
| 278 | 278 | |
| 279 | 279 | // Find the parent dn |
@@ -300,12 +300,12 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
| 303 | - * Remove a contact from a group |
|
| 304 | - * |
|
| 305 | - * @param string $group The group to remove a user from |
|
| 306 | - * @param string $contactDn The DN of a contact to remove from the group |
|
| 307 | - * @return bool |
|
| 308 | - */ |
|
| 303 | + * Remove a contact from a group |
|
| 304 | + * |
|
| 305 | + * @param string $group The group to remove a user from |
|
| 306 | + * @param string $contactDn The DN of a contact to remove from the group |
|
| 307 | + * @return bool |
|
| 308 | + */ |
|
| 309 | 309 | public function removeContact($group, $contactDn) { |
| 310 | 310 | |
| 311 | 311 | // Find the parent dn |
@@ -326,12 +326,12 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | - * Return a list of groups in a group |
|
| 330 | - * |
|
| 331 | - * @param string $group The group to query |
|
| 332 | - * @param bool $recursive Recursively get groups |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 329 | + * Return a list of groups in a group |
|
| 330 | + * |
|
| 331 | + * @param string $group The group to query |
|
| 332 | + * @param bool $recursive Recursively get groups |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | 335 | public function inGroup($group, $recursive = NULL) { |
| 336 | 336 | if (!$this->adldap->getLdapBind()){ return false; } |
| 337 | 337 | if ($recursive === NULL){ $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | $groupArray = array(); |
| 347 | 347 | |
| 348 | 348 | for ($i=0; $i<$groups["count"]; $i++) { |
| 349 | - $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($groups[$i]) . "))"; |
|
| 350 | - $fields = array("samaccountname", "distinguishedname", "objectClass"); |
|
| 351 | - $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
|
| 352 | - $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 349 | + $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($groups[$i]) . "))"; |
|
| 350 | + $fields = array("samaccountname", "distinguishedname", "objectClass"); |
|
| 351 | + $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
|
| 352 | + $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 353 | 353 | |
| 354 | - // not a person, look for a group |
|
| 355 | - if ($entries['count'] == 0 && $recursive == true) { |
|
| 354 | + // not a person, look for a group |
|
| 355 | + if ($entries['count'] == 0 && $recursive == true) { |
|
| 356 | 356 | $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($groups[$i]) . "))"; |
| 357 | 357 | $fields = array("distinguishedname"); |
| 358 | 358 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
@@ -366,19 +366,19 @@ discard block |
||
| 366 | 366 | $groupArray = array_unique($groupArray); |
| 367 | 367 | } |
| 368 | 368 | continue; |
| 369 | - } |
|
| 370 | - $groupArray[] = $entries[0]['distinguishedname'][0]; |
|
| 369 | + } |
|
| 370 | + $groupArray[] = $entries[0]['distinguishedname'][0]; |
|
| 371 | 371 | } |
| 372 | 372 | return $groupArray; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
| 376 | - * Return a list of members in a group |
|
| 377 | - * |
|
| 378 | - * @param string $group The group to query |
|
| 379 | - * @param bool $recursive Recursively get group members |
|
| 380 | - * @return array |
|
| 381 | - */ |
|
| 376 | + * Return a list of members in a group |
|
| 377 | + * |
|
| 378 | + * @param string $group The group to query |
|
| 379 | + * @param bool $recursive Recursively get group members |
|
| 380 | + * @return array |
|
| 381 | + */ |
|
| 382 | 382 | public function members($group, $recursive = NULL) { |
| 383 | 383 | if (!$this->adldap->getLdapBind()) { return false; } |
| 384 | 384 | if ($recursive === NULL){ $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | $userArray = array(); |
| 397 | 397 | |
| 398 | 398 | for ($i=0; $i<$users["count"]; $i++) { |
| 399 | - $filter = "(&(objectCategory=person)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($users[$i]) . "))"; |
|
| 400 | - $fields = array("samaccountname", "distinguishedname", "objectClass"); |
|
| 401 | - $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
|
| 402 | - $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 399 | + $filter = "(&(objectCategory=person)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($users[$i]) . "))"; |
|
| 400 | + $fields = array("samaccountname", "distinguishedname", "objectClass"); |
|
| 401 | + $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
|
| 402 | + $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 403 | 403 | |
| 404 | - // not a person, look for a group |
|
| 405 | - if ($entries['count'] == 0 && $recursive == true) { |
|
| 404 | + // not a person, look for a group |
|
| 405 | + if ($entries['count'] == 0 && $recursive == true) { |
|
| 406 | 406 | $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($users[$i]) . "))"; |
| 407 | 407 | $fields = array("samaccountname"); |
| 408 | 408 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
@@ -416,29 +416,29 @@ discard block |
||
| 416 | 416 | $userArray = array_unique($userArray); |
| 417 | 417 | } |
| 418 | 418 | continue; |
| 419 | - } |
|
| 420 | - else if ($entries['count'] == 0) { |
|
| 419 | + } |
|
| 420 | + else if ($entries['count'] == 0) { |
|
| 421 | 421 | continue; |
| 422 | - } |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - if ((!isset($entries[0]['samaccountname'][0]) || $entries[0]['samaccountname'][0] === NULL) && $entries[0]['distinguishedname'][0] !== NULL) { |
|
| 425 | - $userArray[] = $entries[0]['distinguishedname'][0]; |
|
| 426 | - } |
|
| 427 | - else if ($entries[0]['samaccountname'][0] !== NULL) { |
|
| 424 | + if ((!isset($entries[0]['samaccountname'][0]) || $entries[0]['samaccountname'][0] === NULL) && $entries[0]['distinguishedname'][0] !== NULL) { |
|
| 425 | + $userArray[] = $entries[0]['distinguishedname'][0]; |
|
| 426 | + } |
|
| 427 | + else if ($entries[0]['samaccountname'][0] !== NULL) { |
|
| 428 | 428 | $userArray[] = $entries[0]['samaccountname'][0]; |
| 429 | - } |
|
| 429 | + } |
|
| 430 | 430 | } |
| 431 | 431 | return $userArray; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
| 435 | - * Group Information. Returns an array of raw information about a group. |
|
| 436 | - * The group name is case sensitive |
|
| 437 | - * |
|
| 438 | - * @param string $groupName The group name to retrieve info about |
|
| 439 | - * @param array $fields Fields to retrieve |
|
| 440 | - * @return array |
|
| 441 | - */ |
|
| 435 | + * Group Information. Returns an array of raw information about a group. |
|
| 436 | + * The group name is case sensitive |
|
| 437 | + * |
|
| 438 | + * @param string $groupName The group name to retrieve info about |
|
| 439 | + * @param array $fields Fields to retrieve |
|
| 440 | + * @return array |
|
| 441 | + */ |
|
| 442 | 442 | public function info($groupName, $fields = NULL) { |
| 443 | 443 | if ($groupName === NULL) { return false; } |
| 444 | 444 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -479,13 +479,13 @@ discard block |
||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /** |
| 482 | - * Group Information. Returns an collection |
|
| 483 | - * The group name is case sensitive |
|
| 484 | - * |
|
| 485 | - * @param string $groupName The group name to retrieve info about |
|
| 486 | - * @param array $fields Fields to retrieve |
|
| 487 | - * @return \adLDAP\collections\adLDAPGroupCollection |
|
| 488 | - */ |
|
| 482 | + * Group Information. Returns an collection |
|
| 483 | + * The group name is case sensitive |
|
| 484 | + * |
|
| 485 | + * @param string $groupName The group name to retrieve info about |
|
| 486 | + * @param array $fields Fields to retrieve |
|
| 487 | + * @return \adLDAP\collections\adLDAPGroupCollection |
|
| 488 | + */ |
|
| 489 | 489 | public function infoCollection($groupName, $fields = NULL) { |
| 490 | 490 | if ($groupName === NULL) { return false; } |
| 491 | 491 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
| 502 | - * Return a complete list of "groups in groups" |
|
| 503 | - * |
|
| 504 | - * @param string $group The group to get the list from |
|
| 505 | - * @return array |
|
| 506 | - */ |
|
| 502 | + * Return a complete list of "groups in groups" |
|
| 503 | + * |
|
| 504 | + * @param string $group The group to get the list from |
|
| 505 | + * @return array |
|
| 506 | + */ |
|
| 507 | 507 | public function recursiveGroups($group) { |
| 508 | 508 | if ($group === NULL) { return false; } |
| 509 | 509 | |
@@ -535,14 +535,14 @@ discard block |
||
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
| 538 | - * Returns a complete list of the groups in AD based on a SAM Account Type |
|
| 539 | - * |
|
| 540 | - * @param string $sAMAaccountType The account type to return |
|
| 541 | - * @param bool $includeDescription Whether to return a description |
|
| 542 | - * @param string $search Search parameters |
|
| 543 | - * @param bool $sorted Whether to sort the results |
|
| 544 | - * @return array |
|
| 545 | - */ |
|
| 538 | + * Returns a complete list of the groups in AD based on a SAM Account Type |
|
| 539 | + * |
|
| 540 | + * @param string $sAMAaccountType The account type to return |
|
| 541 | + * @param bool $includeDescription Whether to return a description |
|
| 542 | + * @param string $search Search parameters |
|
| 543 | + * @param bool $sorted Whether to sort the results |
|
| 544 | + * @return array |
|
| 545 | + */ |
|
| 546 | 546 | public function search($sAMAaccountType = adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP, $includeDescription = false, $search = "*", $sorted = true) { |
| 547 | 547 | if (!$this->adldap->getLdapBind()) { return false; } |
| 548 | 548 | |
@@ -575,12 +575,12 @@ discard block |
||
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
| 578 | - * Obtain the group's distinguished name based on their groupid |
|
| 579 | - * |
|
| 580 | - * |
|
| 581 | - * @param string $groupname The groupname |
|
| 582 | - * @return string |
|
| 583 | - */ |
|
| 578 | + * Obtain the group's distinguished name based on their groupid |
|
| 579 | + * |
|
| 580 | + * |
|
| 581 | + * @param string $groupname The groupname |
|
| 582 | + * @return string |
|
| 583 | + */ |
|
| 584 | 584 | public function dn($groupname) { |
| 585 | 585 | $group = $this->info($groupname, array("cn")); |
| 586 | 586 | if ($group[0]["dn"] === NULL) { |
@@ -591,55 +591,55 @@ discard block |
||
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
| 594 | - * Returns a complete list of all groups in AD |
|
| 595 | - * |
|
| 596 | - * @param bool $includeDescription Whether to return a description |
|
| 597 | - * @param string $search Search parameters |
|
| 598 | - * @param bool $sorted Whether to sort the results |
|
| 599 | - * @return array |
|
| 600 | - */ |
|
| 594 | + * Returns a complete list of all groups in AD |
|
| 595 | + * |
|
| 596 | + * @param bool $includeDescription Whether to return a description |
|
| 597 | + * @param string $search Search parameters |
|
| 598 | + * @param bool $sorted Whether to sort the results |
|
| 599 | + * @return array |
|
| 600 | + */ |
|
| 601 | 601 | public function all($includeDescription = false, $search = "*", $sorted = true) { |
| 602 | 602 | $groupsArray = $this->search(null, $includeDescription, $search, $sorted); |
| 603 | 603 | return $groupsArray; |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
| 607 | - * Returns a complete list of security groups in AD |
|
| 608 | - * |
|
| 609 | - * @param bool $includeDescription Whether to return a description |
|
| 610 | - * @param string $search Search parameters |
|
| 611 | - * @param bool $sorted Whether to sort the results |
|
| 612 | - * @return array |
|
| 613 | - */ |
|
| 607 | + * Returns a complete list of security groups in AD |
|
| 608 | + * |
|
| 609 | + * @param bool $includeDescription Whether to return a description |
|
| 610 | + * @param string $search Search parameters |
|
| 611 | + * @param bool $sorted Whether to sort the results |
|
| 612 | + * @return array |
|
| 613 | + */ |
|
| 614 | 614 | public function allSecurity($includeDescription = false, $search = "*", $sorted = true) { |
| 615 | 615 | $groupsArray = $this->search(adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP, $includeDescription, $search, $sorted); |
| 616 | 616 | return $groupsArray; |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
| 620 | - * Returns a complete list of distribution lists in AD |
|
| 621 | - * |
|
| 622 | - * @param bool $includeDescription Whether to return a description |
|
| 623 | - * @param string $search Search parameters |
|
| 624 | - * @param bool $sorted Whether to sort the results |
|
| 625 | - * @return array |
|
| 626 | - */ |
|
| 620 | + * Returns a complete list of distribution lists in AD |
|
| 621 | + * |
|
| 622 | + * @param bool $includeDescription Whether to return a description |
|
| 623 | + * @param string $search Search parameters |
|
| 624 | + * @param bool $sorted Whether to sort the results |
|
| 625 | + * @return array |
|
| 626 | + */ |
|
| 627 | 627 | public function allDistribution($includeDescription = false, $search = "*", $sorted = true) { |
| 628 | 628 | $groupsArray = $this->search(adLDAP::ADLDAP_DISTRIBUTION_GROUP, $includeDescription, $search, $sorted); |
| 629 | 629 | return $groupsArray; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
| 633 | - * Coping with AD not returning the primary group |
|
| 634 | - * http://support.microsoft.com/?kbid=321360 |
|
| 635 | - * |
|
| 636 | - * This is a re-write based on code submitted by Bruce which prevents the |
|
| 637 | - * need to search each security group to find the true primary group |
|
| 638 | - * |
|
| 639 | - * @param string $gid Group ID |
|
| 640 | - * @param string $usersid User's Object SID |
|
| 641 | - * @return mixed |
|
| 642 | - */ |
|
| 633 | + * Coping with AD not returning the primary group |
|
| 634 | + * http://support.microsoft.com/?kbid=321360 |
|
| 635 | + * |
|
| 636 | + * This is a re-write based on code submitted by Bruce which prevents the |
|
| 637 | + * need to search each security group to find the true primary group |
|
| 638 | + * |
|
| 639 | + * @param string $gid Group ID |
|
| 640 | + * @param string $usersid User's Object SID |
|
| 641 | + * @return mixed |
|
| 642 | + */ |
|
| 643 | 643 | public function getPrimaryGroup($gid, $usersid) { |
| 644 | 644 | if ($gid === NULL || $usersid === NULL) { return false; } |
| 645 | 645 | $sr = false; |
@@ -654,20 +654,20 @@ discard block |
||
| 654 | 654 | return $entries[0]['distinguishedname'][0]; |
| 655 | 655 | } |
| 656 | 656 | return false; |
| 657 | - } |
|
| 657 | + } |
|
| 658 | 658 | |
| 659 | - /** |
|
| 660 | - * Coping with AD not returning the primary group |
|
| 661 | - * http://support.microsoft.com/?kbid=321360 |
|
| 662 | - * |
|
| 663 | - * For some reason it's not possible to search on primarygrouptoken=XXX |
|
| 664 | - * If someone can show otherwise, I'd like to know about it :) |
|
| 665 | - * this way is resource intensive and generally a pain in the @#%^ |
|
| 666 | - * |
|
| 667 | - * @deprecated deprecated since version 3.1, see get get_primary_group |
|
| 668 | - * @param string $gid Group ID |
|
| 669 | - * @return string |
|
| 670 | - */ |
|
| 659 | + /** |
|
| 660 | + * Coping with AD not returning the primary group |
|
| 661 | + * http://support.microsoft.com/?kbid=321360 |
|
| 662 | + * |
|
| 663 | + * For some reason it's not possible to search on primarygrouptoken=XXX |
|
| 664 | + * If someone can show otherwise, I'd like to know about it :) |
|
| 665 | + * this way is resource intensive and generally a pain in the @#%^ |
|
| 666 | + * |
|
| 667 | + * @deprecated deprecated since version 3.1, see get get_primary_group |
|
| 668 | + * @param string $gid Group ID |
|
| 669 | + * @return string |
|
| 670 | + */ |
|
| 671 | 671 | public function cn($gid) { |
| 672 | 672 | if ($gid === NULL) { return false; } |
| 673 | 673 | $sr = false; |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 39 | -require_once(dirname(__FILE__) . '/../collections/adLDAPGroupCollection.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | +require_once(dirname(__FILE__).'/../collections/adLDAPGroupCollection.php'); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * GROUP FUNCTIONS |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param string $child The child group name |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | - public function addGroup($parent,$child) { |
|
| 63 | + public function addGroup($parent, $child) { |
|
| 64 | 64 | |
| 65 | 65 | // Find the parent group's dn |
| 66 | 66 | $parentGroup = $this->ginfo($parent, array("cn")); |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | $add["description"] = $attributes["description"]; |
| 176 | 176 | //$add["member"] = $member_array; UNTESTED |
| 177 | 177 | |
| 178 | - $container = "OU=" . implode(",OU=", $attributes["container"]); |
|
| 179 | - $result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . ", " . $container . "," . $this->adldap->getBaseDn(), $add); |
|
| 178 | + $container = "OU=".implode(",OU=", $attributes["container"]); |
|
| 179 | + $result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].", ".$container.",".$this->adldap->getBaseDn(), $add); |
|
| 180 | 180 | if ($result != true) { |
| 181 | 181 | return false; |
| 182 | 182 | } |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | if ($info[0]["dn"] === NULL) { |
| 217 | 217 | return false; |
| 218 | 218 | } |
| 219 | - else{ |
|
| 219 | + else { |
|
| 220 | 220 | $groupDN = $info[0]["dn"]; |
| 221 | 221 | } |
| 222 | 222 | $newRDN = 'CN='.$newName; |
| 223 | 223 | |
| 224 | 224 | // Determine the container |
| 225 | 225 | $container = array_reverse($container); |
| 226 | - $container = "OU=" . implode(", OU=",$container); |
|
| 226 | + $container = "OU=".implode(", OU=", $container); |
|
| 227 | 227 | |
| 228 | 228 | // Do the update |
| 229 | 229 | $result = @ldap_rename($this->adldap->getLdapConnection(), $groupDN, $newRDN, $container.', '.$this->adldap->getBaseDn(), true); |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @param string $child The child group name |
| 241 | 241 | * @return bool |
| 242 | 242 | */ |
| 243 | - public function removeGroup($parent , $child) { |
|
| 243 | + public function removeGroup($parent, $child) { |
|
| 244 | 244 | |
| 245 | 245 | // Find the parent dn |
| 246 | 246 | $parentGroup = $this->info($parent, array("cn")); |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | 335 | public function inGroup($group, $recursive = NULL) { |
| 336 | - if (!$this->adldap->getLdapBind()){ return false; } |
|
| 337 | - if ($recursive === NULL){ $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
|
| 336 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
| 337 | + if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
|
| 338 | 338 | |
| 339 | 339 | // Search the directory for the members of a group |
| 340 | - $info = $this->info($group, array("member","cn")); |
|
| 340 | + $info = $this->info($group, array("member", "cn")); |
|
| 341 | 341 | $groups = $info[0]["member"]; |
| 342 | 342 | if (!is_array($groups)) { |
| 343 | 343 | return false; |
@@ -345,15 +345,15 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | $groupArray = array(); |
| 347 | 347 | |
| 348 | - for ($i=0; $i<$groups["count"]; $i++) { |
|
| 349 | - $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($groups[$i]) . "))"; |
|
| 348 | + for ($i = 0; $i < $groups["count"]; $i++) { |
|
| 349 | + $filter = "(&(objectCategory=group)(distinguishedName=".$this->adldap->utilities()->ldapSlashes($groups[$i])."))"; |
|
| 350 | 350 | $fields = array("samaccountname", "distinguishedname", "objectClass"); |
| 351 | 351 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 352 | 352 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 353 | 353 | |
| 354 | 354 | // not a person, look for a group |
| 355 | 355 | if ($entries['count'] == 0 && $recursive == true) { |
| 356 | - $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($groups[$i]) . "))"; |
|
| 356 | + $filter = "(&(objectCategory=group)(distinguishedName=".$this->adldap->utilities()->ldapSlashes($groups[$i])."))"; |
|
| 357 | 357 | $fields = array("distinguishedname"); |
| 358 | 358 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 359 | 359 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
@@ -381,9 +381,9 @@ discard block |
||
| 381 | 381 | */ |
| 382 | 382 | public function members($group, $recursive = NULL) { |
| 383 | 383 | if (!$this->adldap->getLdapBind()) { return false; } |
| 384 | - if ($recursive === NULL){ $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
|
| 384 | + if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
|
| 385 | 385 | // Search the directory for the members of a group |
| 386 | - $info = $this->info($group, array("member","cn")); |
|
| 386 | + $info = $this->info($group, array("member", "cn")); |
|
| 387 | 387 | if (isset($info[0]["member"])) { |
| 388 | 388 | $users = $info[0]["member"]; |
| 389 | 389 | if (!is_array($users)) { |
@@ -395,15 +395,15 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | $userArray = array(); |
| 397 | 397 | |
| 398 | - for ($i=0; $i<$users["count"]; $i++) { |
|
| 399 | - $filter = "(&(objectCategory=person)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($users[$i]) . "))"; |
|
| 398 | + for ($i = 0; $i < $users["count"]; $i++) { |
|
| 399 | + $filter = "(&(objectCategory=person)(distinguishedName=".$this->adldap->utilities()->ldapSlashes($users[$i])."))"; |
|
| 400 | 400 | $fields = array("samaccountname", "distinguishedname", "objectClass"); |
| 401 | 401 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 402 | 402 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 403 | 403 | |
| 404 | 404 | // not a person, look for a group |
| 405 | 405 | if ($entries['count'] == 0 && $recursive == true) { |
| 406 | - $filter = "(&(objectCategory=group)(distinguishedName=" . $this->adldap->utilities()->ldapSlashes($users[$i]) . "))"; |
|
| 406 | + $filter = "(&(objectCategory=group)(distinguishedName=".$this->adldap->utilities()->ldapSlashes($users[$i])."))"; |
|
| 407 | 407 | $fields = array("samaccountname"); |
| 408 | 408 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 409 | 409 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
@@ -447,9 +447,9 @@ discard block |
||
| 447 | 447 | $groupName = stripslashes($groupName); |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $filter = "(&(objectCategory=group)(name=" . $this->adldap->utilities()->ldapSlashes($groupName) . "))"; |
|
| 450 | + $filter = "(&(objectCategory=group)(name=".$this->adldap->utilities()->ldapSlashes($groupName)."))"; |
|
| 451 | 451 | if ($fields === NULL) { |
| 452 | - $fields = array("member","memberof","cn","description","distinguishedname","objectcategory","samaccountname"); |
|
| 452 | + $fields = array("member", "memberof", "cn", "description", "distinguishedname", "objectcategory", "samaccountname"); |
|
| 453 | 453 | } |
| 454 | 454 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 455 | 455 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
@@ -457,22 +457,22 @@ discard block |
||
| 457 | 457 | // Windows 2003: Returns up to 1500 values (Windows 2000 only 1000 is not supported). |
| 458 | 458 | if (isset($entries[0]['member;range=0-1499']) && $entries[0]['member;range=0-1499']['count'] == 1500) { |
| 459 | 459 | $entries[0]['member']['count'] = "0"; |
| 460 | - $rangestep = 1499; // Step site |
|
| 461 | - $rangelow = 0; // Initial low range |
|
| 462 | - $rangehigh = $rangelow + $rangestep; // Initial high range |
|
| 460 | + $rangestep = 1499; // Step site |
|
| 461 | + $rangelow = 0; // Initial low range |
|
| 462 | + $rangehigh = $rangelow + $rangestep; // Initial high range |
|
| 463 | 463 | // do until array_keys($members[0])[0] ends with a '*', e. g. member;range=1499-*. It indicates end of the range |
| 464 | 464 | do { |
| 465 | - $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, array("member;range=" . $rangelow . "-" . $rangehigh)); |
|
| 465 | + $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, array("member;range=".$rangelow."-".$rangehigh)); |
|
| 466 | 466 | $members = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 467 | 467 | $memberrange = array_keys($members[0]); |
| 468 | 468 | $membercount = $members[0][$memberrange[0]]['count']; |
| 469 | 469 | // Copy range entries to member |
| 470 | - for ($i = 0; $i <= $membercount -1; $i++) { |
|
| 470 | + for ($i = 0; $i <= $membercount - 1; $i++) { |
|
| 471 | 471 | $entries[0]['member'][] = $members[0][$memberrange[0]][$i]; |
| 472 | 472 | } |
| 473 | 473 | $entries[0]['member']['count'] += $membercount; |
| 474 | - $rangelow += $rangestep +1; |
|
| 475 | - $rangehigh += $rangestep +1; |
|
| 474 | + $rangelow += $rangestep + 1; |
|
| 475 | + $rangehigh += $rangestep + 1; |
|
| 476 | 476 | } while (substr($memberrange[0], -1) != '*'); |
| 477 | 477 | } |
| 478 | 478 | return $entries; |
@@ -548,17 +548,17 @@ discard block |
||
| 548 | 548 | |
| 549 | 549 | $filter = '(&(objectCategory=group)'; |
| 550 | 550 | if ($sAMAaccountType !== null) { |
| 551 | - $filter .= '(samaccounttype='. $sAMAaccountType .')'; |
|
| 551 | + $filter .= '(samaccounttype='.$sAMAaccountType.')'; |
|
| 552 | 552 | } |
| 553 | - $filter .= '(cn=' . $search . '))'; |
|
| 553 | + $filter .= '(cn='.$search.'))'; |
|
| 554 | 554 | // Perform the search and grab all their details |
| 555 | 555 | $fields = array("samaccountname", "description"); |
| 556 | 556 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 557 | 557 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 558 | 558 | |
| 559 | 559 | $groupsArray = array(); |
| 560 | - for ($i=0; $i<$entries["count"]; $i++) { |
|
| 561 | - if ($includeDescription && strlen($entries[$i]["description"][0]) > 0 ) { |
|
| 560 | + for ($i = 0; $i < $entries["count"]; $i++) { |
|
| 561 | + if ($includeDescription && strlen($entries[$i]["description"][0]) > 0) { |
|
| 562 | 562 | $groupsArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["description"][0]; |
| 563 | 563 | } |
| 564 | 564 | else if ($includeDescription) { |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | if ($gid === NULL || $usersid === NULL) { return false; } |
| 645 | 645 | $sr = false; |
| 646 | 646 | |
| 647 | - $gsid = substr_replace($usersid, pack('V',$gid), strlen($usersid)-4,4); |
|
| 648 | - $filter = '(objectsid=' . $this->adldap->utilities()->getTextSID($gsid).')'; |
|
| 649 | - $fields = array("samaccountname","distinguishedname"); |
|
| 647 | + $gsid = substr_replace($usersid, pack('V', $gid), strlen($usersid) - 4, 4); |
|
| 648 | + $filter = '(objectsid='.$this->adldap->utilities()->getTextSID($gsid).')'; |
|
| 649 | + $fields = array("samaccountname", "distinguishedname"); |
|
| 650 | 650 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 651 | 651 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 652 | 652 | |
@@ -673,12 +673,12 @@ discard block |
||
| 673 | 673 | $sr = false; |
| 674 | 674 | $r = ''; |
| 675 | 675 | |
| 676 | - $filter = "(&(objectCategory=group)(samaccounttype=" . adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP . "))"; |
|
| 676 | + $filter = "(&(objectCategory=group)(samaccounttype=".adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP."))"; |
|
| 677 | 677 | $fields = array("primarygrouptoken", "samaccountname", "distinguishedname"); |
| 678 | 678 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 679 | 679 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 680 | 680 | |
| 681 | - for ($i=0; $i<$entries["count"]; $i++) { |
|
| 681 | + for ($i = 0; $i < $entries["count"]; $i++) { |
|
| 682 | 682 | if ($entries[$i]["primarygrouptoken"][0] == $gid) { |
| 683 | 683 | $r = $entries[$i]["distinguishedname"][0]; |
| 684 | 684 | $i = $entries["count"]; |
@@ -215,8 +215,7 @@ discard block |
||
| 215 | 215 | $info = $this->info($group); |
| 216 | 216 | if ($info[0]["dn"] === NULL) { |
| 217 | 217 | return false; |
| 218 | - } |
|
| 219 | - else{ |
|
| 218 | + } else{ |
|
| 220 | 219 | $groupDN = $info[0]["dn"]; |
| 221 | 220 | } |
| 222 | 221 | $newRDN = 'CN='.$newName; |
@@ -416,15 +415,13 @@ discard block |
||
| 416 | 415 | $userArray = array_unique($userArray); |
| 417 | 416 | } |
| 418 | 417 | continue; |
| 419 | - } |
|
| 420 | - else if ($entries['count'] == 0) { |
|
| 418 | + } else if ($entries['count'] == 0) { |
|
| 421 | 419 | continue; |
| 422 | 420 | } |
| 423 | 421 | |
| 424 | 422 | if ((!isset($entries[0]['samaccountname'][0]) || $entries[0]['samaccountname'][0] === NULL) && $entries[0]['distinguishedname'][0] !== NULL) { |
| 425 | 423 | $userArray[] = $entries[0]['distinguishedname'][0]; |
| 426 | - } |
|
| 427 | - else if ($entries[0]['samaccountname'][0] !== NULL) { |
|
| 424 | + } else if ($entries[0]['samaccountname'][0] !== NULL) { |
|
| 428 | 425 | $userArray[] = $entries[0]['samaccountname'][0]; |
| 429 | 426 | } |
| 430 | 427 | } |
@@ -560,11 +557,9 @@ discard block |
||
| 560 | 557 | for ($i=0; $i<$entries["count"]; $i++) { |
| 561 | 558 | if ($includeDescription && strlen($entries[$i]["description"][0]) > 0 ) { |
| 562 | 559 | $groupsArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["description"][0]; |
| 563 | - } |
|
| 564 | - else if ($includeDescription) { |
|
| 560 | + } else if ($includeDescription) { |
|
| 565 | 561 | $groupsArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["samaccountname"][0]; |
| 566 | - } |
|
| 567 | - else { |
|
| 562 | + } else { |
|
| 568 | 563 | array_push($groupsArray, $entries[$i]["samaccountname"][0]); |
| 569 | 564 | } |
| 570 | 565 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * If you specify a password here, this can only be performed over SSL |
| 72 | 72 | * |
| 73 | 73 | * @param array $attributes The attributes to set to the user account |
| 74 | - * @return bool |
|
| 74 | + * @return string|boolean |
|
| 75 | 75 | */ |
| 76 | 76 | public function create($attributes) { |
| 77 | 77 | // Check for compulsory fields |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | /** |
| 125 | 125 | * Account control options |
| 126 | 126 | * |
| 127 | - * @param array $options The options to convert to int |
|
| 127 | + * @param string[] $options The options to convert to int |
|
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | protected function accountControl($options) { |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @param string $username The username to delete (please be careful here!) |
| 164 | 164 | * @param bool $isGUID Is the username a GUID or a samAccountName |
| 165 | - * @return array |
|
| 165 | + * @return boolean |
|
| 166 | 166 | */ |
| 167 | 167 | public function delete($username, $isGUID = false) { |
| 168 | 168 | $userinfo = $this->info($username, array("*"), $isGUID); |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * @param string $username The username to query |
| 376 | 376 | * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
| 377 | 377 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 378 | - * @return bool |
|
| 378 | + * @return string|boolean |
|
| 379 | 379 | */ |
| 380 | 380 | public function modify($username, $attributes, $isGUID = false) { |
| 381 | 381 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * |
| 422 | 422 | * @param string $username The username to disable |
| 423 | 423 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 424 | - * @return bool |
|
| 424 | + * @return string|boolean |
|
| 425 | 425 | */ |
| 426 | 426 | public function disable($username, $isGUID = false) { |
| 427 | 427 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * |
| 438 | 438 | * @param string $username The username to enable |
| 439 | 439 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 440 | - * @return bool |
|
| 440 | + * @return string|boolean |
|
| 441 | 441 | */ |
| 442 | 442 | public function enable($username, $isGUID = false) { |
| 443 | 443 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | * @param string $username The username to move (please be careful here!) |
| 621 | 621 | * @param array $container The container or containers to move the user to (please be careful here!). |
| 622 | 622 | * accepts containers in 1. parent 2. child order |
| 623 | - * @return array |
|
| 623 | + * @return string|boolean |
|
| 624 | 624 | */ |
| 625 | 625 | public function move($username, $container) { |
| 626 | 626 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | class adLDAPUsers { |
| 45 | 45 | /** |
| 46 | - * The current adLDAP connection via dependency injection |
|
| 47 | - * |
|
| 48 | - * @var adLDAP |
|
| 49 | - */ |
|
| 46 | + * The current adLDAP connection via dependency injection |
|
| 47 | + * |
|
| 48 | + * @var adLDAP |
|
| 49 | + */ |
|
| 50 | 50 | protected $adldap; |
| 51 | 51 | |
| 52 | 52 | public function __construct(adLDAP $adldap) { |
@@ -54,25 +54,25 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Validate a user's login credentials |
|
| 58 | - * |
|
| 59 | - * @param string $username A user's AD username |
|
| 60 | - * @param string $password A user's AD password |
|
| 61 | - * @param bool optional $prevent_rebind |
|
| 62 | - * @return bool |
|
| 63 | - */ |
|
| 57 | + * Validate a user's login credentials |
|
| 58 | + * |
|
| 59 | + * @param string $username A user's AD username |
|
| 60 | + * @param string $password A user's AD password |
|
| 61 | + * @param bool optional $prevent_rebind |
|
| 62 | + * @return bool |
|
| 63 | + */ |
|
| 64 | 64 | public function authenticate($username, $password, $preventRebind = false) { |
| 65 | 65 | return $this->adldap->authenticate($username, $password, $preventRebind); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | - * Create a user |
|
| 70 | - * |
|
| 71 | - * If you specify a password here, this can only be performed over SSL |
|
| 72 | - * |
|
| 73 | - * @param array $attributes The attributes to set to the user account |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 69 | + * Create a user |
|
| 70 | + * |
|
| 71 | + * If you specify a password here, this can only be performed over SSL |
|
| 72 | + * |
|
| 73 | + * @param array $attributes The attributes to set to the user account |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | 76 | public function create($attributes) { |
| 77 | 77 | // Check for compulsory fields |
| 78 | 78 | if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; } |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Account control options |
|
| 126 | - * |
|
| 127 | - * @param array $options The options to convert to int |
|
| 128 | - * @return int |
|
| 129 | - */ |
|
| 125 | + * Account control options |
|
| 126 | + * |
|
| 127 | + * @param array $options The options to convert to int |
|
| 128 | + * @return int |
|
| 129 | + */ |
|
| 130 | 130 | protected function accountControl($options) { |
| 131 | 131 | $val=0; |
| 132 | 132 | |
@@ -158,12 +158,12 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | - * Delete a user account |
|
| 162 | - * |
|
| 163 | - * @param string $username The username to delete (please be careful here!) |
|
| 164 | - * @param bool $isGUID Is the username a GUID or a samAccountName |
|
| 165 | - * @return array |
|
| 166 | - */ |
|
| 161 | + * Delete a user account |
|
| 162 | + * |
|
| 163 | + * @param string $username The username to delete (please be careful here!) |
|
| 164 | + * @param bool $isGUID Is the username a GUID or a samAccountName |
|
| 165 | + * @return array |
|
| 166 | + */ |
|
| 167 | 167 | public function delete($username, $isGUID = false) { |
| 168 | 168 | $userinfo = $this->info($username, array("*"), $isGUID); |
| 169 | 169 | $dn = $userinfo[0]['distinguishedname'][0]; |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Groups the user is a member of |
|
| 179 | - * |
|
| 180 | - * @param string $username The username to query |
|
| 181 | - * @param bool $recursive Recursive list of groups |
|
| 182 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 183 | - * @return array |
|
| 184 | - */ |
|
| 178 | + * Groups the user is a member of |
|
| 179 | + * |
|
| 180 | + * @param string $username The username to query |
|
| 181 | + * @param bool $recursive Recursive list of groups |
|
| 182 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 183 | + * @return array |
|
| 184 | + */ |
|
| 185 | 185 | public function groups($username, $recursive = NULL, $isGUID = false) { |
| 186 | 186 | if ($username === NULL) { return false; } |
| 187 | 187 | if ($recursive === NULL) { $recursive = $this->adldap->getRecursiveGroups(); } // Use the default option if they haven't set it |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
| 204 | - * Find information about the users. Returned in a raw array format from AD |
|
| 205 | - * |
|
| 206 | - * @param string $username The username to query |
|
| 207 | - * @param array $fields Array of parameters to query |
|
| 208 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 209 | - * @return array |
|
| 210 | - */ |
|
| 204 | + * Find information about the users. Returned in a raw array format from AD |
|
| 205 | + * |
|
| 206 | + * @param string $username The username to query |
|
| 207 | + * @param array $fields Array of parameters to query |
|
| 208 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 209 | + * @return array |
|
| 210 | + */ |
|
| 211 | 211 | public function info($username, $fields = NULL, $isGUID = false) { |
| 212 | 212 | if ($username === NULL) { return false; } |
| 213 | 213 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -217,10 +217,10 @@ discard block |
||
| 217 | 217 | $filter = "objectguid=" . $username; |
| 218 | 218 | } |
| 219 | 219 | else if (strpos($username, "@")) { |
| 220 | - $filter = "userPrincipalName=" . $username; |
|
| 220 | + $filter = "userPrincipalName=" . $username; |
|
| 221 | 221 | } |
| 222 | 222 | else { |
| 223 | - $filter = "samaccountname=" . $username; |
|
| 223 | + $filter = "samaccountname=" . $username; |
|
| 224 | 224 | } |
| 225 | 225 | $filter = "(&(objectCategory=person)({$filter}))"; |
| 226 | 226 | if ($fields === NULL) { |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
| 257 | - * Find information about the users. Returned in a raw array format from AD |
|
| 258 | - * |
|
| 259 | - * @param string $username The username to query |
|
| 260 | - * @param array $fields Array of parameters to query |
|
| 261 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 262 | - * @return mixed |
|
| 263 | - */ |
|
| 257 | + * Find information about the users. Returned in a raw array format from AD |
|
| 258 | + * |
|
| 259 | + * @param string $username The username to query |
|
| 260 | + * @param array $fields Array of parameters to query |
|
| 261 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 262 | + * @return mixed |
|
| 263 | + */ |
|
| 264 | 264 | public function infoCollection($username, $fields = NULL, $isGUID = false) { |
| 265 | 265 | if ($username === NULL) { return false; } |
| 266 | 266 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -275,14 +275,14 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | - * Determine if a user is in a specific group |
|
| 279 | - * |
|
| 280 | - * @param string $username The username to query |
|
| 281 | - * @param string $group The name of the group to check against |
|
| 282 | - * @param bool $recursive Check groups recursively |
|
| 283 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 284 | - * @return bool |
|
| 285 | - */ |
|
| 278 | + * Determine if a user is in a specific group |
|
| 279 | + * |
|
| 280 | + * @param string $username The username to query |
|
| 281 | + * @param string $group The name of the group to check against |
|
| 282 | + * @param bool $recursive Check groups recursively |
|
| 283 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 284 | + * @return bool |
|
| 285 | + */ |
|
| 286 | 286 | public function inGroup($username, $group, $recursive = NULL, $isGUID = false) { |
| 287 | 287 | if ($username === NULL) { return false; } |
| 288 | 288 | if ($group === NULL) { return false; } |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
| 303 | - * Determine a user's password expiry date |
|
| 304 | - * |
|
| 305 | - * @param string $username The username to query |
|
| 306 | - * @param book $isGUID Is the username passed a GUID or a samAccountName |
|
| 307 | - * @requires bcmath http://www.php.net/manual/en/book.bc.php |
|
| 308 | - * @return array |
|
| 309 | - */ |
|
| 303 | + * Determine a user's password expiry date |
|
| 304 | + * |
|
| 305 | + * @param string $username The username to query |
|
| 306 | + * @param book $isGUID Is the username passed a GUID or a samAccountName |
|
| 307 | + * @requires bcmath http://www.php.net/manual/en/book.bc.php |
|
| 308 | + * @return array |
|
| 309 | + */ |
|
| 310 | 310 | public function passwordExpiry($username, $isGUID = false) { |
| 311 | 311 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 312 | 312 | if (!$this->adldap->getLdapBind()) { return false; } |
@@ -325,36 +325,36 @@ discard block |
||
| 325 | 325 | return "Password has expired"; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - // Password expiry in AD can be calculated from TWO values: |
|
| 329 | - // - User's own pwdLastSet attribute: stores the last time the password was changed |
|
| 330 | - // - Domain's maxPwdAge attribute: how long passwords last in the domain |
|
| 331 | - // |
|
| 332 | - // Although Microsoft chose to use a different base and unit for time measurements. |
|
| 333 | - // This function will convert them to Unix timestamps |
|
| 334 | - $sr = ldap_read($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), 'objectclass=*', array('maxPwdAge')); |
|
| 335 | - if (!$sr) { |
|
| 336 | - return false; |
|
| 337 | - } |
|
| 338 | - $info = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 339 | - $maxPwdAge = $info[0]['maxpwdage'][0]; |
|
| 328 | + // Password expiry in AD can be calculated from TWO values: |
|
| 329 | + // - User's own pwdLastSet attribute: stores the last time the password was changed |
|
| 330 | + // - Domain's maxPwdAge attribute: how long passwords last in the domain |
|
| 331 | + // |
|
| 332 | + // Although Microsoft chose to use a different base and unit for time measurements. |
|
| 333 | + // This function will convert them to Unix timestamps |
|
| 334 | + $sr = ldap_read($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), 'objectclass=*', array('maxPwdAge')); |
|
| 335 | + if (!$sr) { |
|
| 336 | + return false; |
|
| 337 | + } |
|
| 338 | + $info = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
|
| 339 | + $maxPwdAge = $info[0]['maxpwdage'][0]; |
|
| 340 | 340 | |
| 341 | - // See MSDN: http://msdn.microsoft.com/en-us/library/ms974598.aspx |
|
| 342 | - // |
|
| 343 | - // pwdLastSet contains the number of 100 nanosecond intervals since January 1, 1601 (UTC), |
|
| 344 | - // stored in a 64 bit integer. |
|
| 345 | - // |
|
| 346 | - // The number of seconds between this date and Unix epoch is 11644473600. |
|
| 347 | - // |
|
| 348 | - // maxPwdAge is stored as a large integer that represents the number of 100 nanosecond |
|
| 349 | - // intervals from the time the password was set before the password expires. |
|
| 350 | - // |
|
| 351 | - // We also need to scale this to seconds but also this value is a _negative_ quantity! |
|
| 352 | - // |
|
| 353 | - // If the low 32 bits of maxPwdAge are equal to 0 passwords do not expire |
|
| 354 | - // |
|
| 355 | - // Unfortunately the maths involved are too big for PHP integers, so I've had to require |
|
| 356 | - // BCMath functions to work with arbitrary precision numbers. |
|
| 357 | - if (bcmod($maxPwdAge, 4294967296) === '0') { |
|
| 341 | + // See MSDN: http://msdn.microsoft.com/en-us/library/ms974598.aspx |
|
| 342 | + // |
|
| 343 | + // pwdLastSet contains the number of 100 nanosecond intervals since January 1, 1601 (UTC), |
|
| 344 | + // stored in a 64 bit integer. |
|
| 345 | + // |
|
| 346 | + // The number of seconds between this date and Unix epoch is 11644473600. |
|
| 347 | + // |
|
| 348 | + // maxPwdAge is stored as a large integer that represents the number of 100 nanosecond |
|
| 349 | + // intervals from the time the password was set before the password expires. |
|
| 350 | + // |
|
| 351 | + // We also need to scale this to seconds but also this value is a _negative_ quantity! |
|
| 352 | + // |
|
| 353 | + // If the low 32 bits of maxPwdAge are equal to 0 passwords do not expire |
|
| 354 | + // |
|
| 355 | + // Unfortunately the maths involved are too big for PHP integers, so I've had to require |
|
| 356 | + // BCMath functions to work with arbitrary precision numbers. |
|
| 357 | + if (bcmod($maxPwdAge, 4294967296) === '0') { |
|
| 358 | 358 | return "Domain does not expire passwords"; |
| 359 | 359 | } |
| 360 | 360 | |
@@ -370,13 +370,13 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Modify a user |
|
| 374 | - * |
|
| 375 | - * @param string $username The username to query |
|
| 376 | - * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 377 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 378 | - * @return bool |
|
| 379 | - */ |
|
| 373 | + * Modify a user |
|
| 374 | + * |
|
| 375 | + * @param string $username The username to query |
|
| 376 | + * @param array $attributes The attributes to modify. Note if you set the enabled attribute you must not specify any other attributes |
|
| 377 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 378 | + * @return bool |
|
| 379 | + */ |
|
| 380 | 380 | public function modify($username, $attributes, $isGUID = false) { |
| 381 | 381 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 382 | 382 | if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) { |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
| 420 | - * Disable a user account |
|
| 421 | - * |
|
| 422 | - * @param string $username The username to disable |
|
| 423 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 424 | - * @return bool |
|
| 425 | - */ |
|
| 420 | + * Disable a user account |
|
| 421 | + * |
|
| 422 | + * @param string $username The username to disable |
|
| 423 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 424 | + * @return bool |
|
| 425 | + */ |
|
| 426 | 426 | public function disable($username, $isGUID = false) { |
| 427 | 427 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 428 | 428 | $attributes = array("enabled" => 0); |
@@ -433,12 +433,12 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
| 436 | - * Enable a user account |
|
| 437 | - * |
|
| 438 | - * @param string $username The username to enable |
|
| 439 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 440 | - * @return bool |
|
| 441 | - */ |
|
| 436 | + * Enable a user account |
|
| 437 | + * |
|
| 438 | + * @param string $username The username to enable |
|
| 439 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 440 | + * @return bool |
|
| 441 | + */ |
|
| 442 | 442 | public function enable($username, $isGUID = false) { |
| 443 | 443 | if ($username === NULL) { return "Missing compulsory field [username]"; } |
| 444 | 444 | $attributes = array("enabled" => 1); |
@@ -449,13 +449,13 @@ discard block |
||
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
| 452 | - * Set the password of a user - This must be performed over SSL |
|
| 453 | - * |
|
| 454 | - * @param string $username The username to modify |
|
| 455 | - * @param string $password The new password |
|
| 456 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 452 | + * Set the password of a user - This must be performed over SSL |
|
| 453 | + * |
|
| 454 | + * @param string $username The username to modify |
|
| 455 | + * @param string $password The new password |
|
| 456 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | 459 | public function password($username, $password, $isGUID = false) { |
| 460 | 460 | if ($username === NULL) { return false; } |
| 461 | 461 | if ($password === NULL) { return false; } |
@@ -490,11 +490,11 @@ discard block |
||
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
| 493 | - * Encode a password for transmission over LDAP |
|
| 494 | - * |
|
| 495 | - * @param string $password The password to encode |
|
| 496 | - * @return string |
|
| 497 | - */ |
|
| 493 | + * Encode a password for transmission over LDAP |
|
| 494 | + * |
|
| 495 | + * @param string $password The password to encode |
|
| 496 | + * @return string |
|
| 497 | + */ |
|
| 498 | 498 | public function encodePassword($password) { |
| 499 | 499 | $password="\"".$password."\""; |
| 500 | 500 | $encoded=""; |
@@ -503,13 +503,13 @@ discard block |
||
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
| 506 | - * Obtain the user's distinguished name based on their userid |
|
| 507 | - * |
|
| 508 | - * |
|
| 509 | - * @param string $username The username |
|
| 510 | - * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 511 | - * @return string |
|
| 512 | - */ |
|
| 506 | + * Obtain the user's distinguished name based on their userid |
|
| 507 | + * |
|
| 508 | + * |
|
| 509 | + * @param string $username The username |
|
| 510 | + * @param bool $isGUID Is the username passed a GUID or a samAccountName |
|
| 511 | + * @return string |
|
| 512 | + */ |
|
| 513 | 513 | public function dn($username, $isGUID=false) { |
| 514 | 514 | $user = $this->info($username, array("cn"), $isGUID); |
| 515 | 515 | if ($user[0]["dn"] === NULL) { |
@@ -520,13 +520,13 @@ discard block |
||
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
| 523 | - * Return a list of all users in AD |
|
| 524 | - * |
|
| 525 | - * @param bool $includeDescription Return a description of the user |
|
| 526 | - * @param string $search Search parameter |
|
| 527 | - * @param bool $sorted Sort the user accounts |
|
| 528 | - * @return array |
|
| 529 | - */ |
|
| 523 | + * Return a list of all users in AD |
|
| 524 | + * |
|
| 525 | + * @param bool $includeDescription Return a description of the user |
|
| 526 | + * @param string $search Search parameter |
|
| 527 | + * @param bool $sorted Sort the user accounts |
|
| 528 | + * @return array |
|
| 529 | + */ |
|
| 530 | 530 | public function all($includeDescription = false, $search = "*", $sorted = true) { |
| 531 | 531 | if (!$this->adldap->getLdapBind()) { return false; } |
| 532 | 532 | |
@@ -553,11 +553,11 @@ discard block |
||
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
| 556 | - * Converts a username (samAccountName) to a GUID |
|
| 557 | - * |
|
| 558 | - * @param string $username The username to query |
|
| 559 | - * @return string |
|
| 560 | - */ |
|
| 556 | + * Converts a username (samAccountName) to a GUID |
|
| 557 | + * |
|
| 558 | + * @param string $username The username to query |
|
| 559 | + * @return string |
|
| 560 | + */ |
|
| 561 | 561 | public function usernameToGuid($username) { |
| 562 | 562 | if (!$this->adldap->getLdapBind()){ return false; } |
| 563 | 563 | if ($username === null){ return "Missing compulsory field [username]"; } |
@@ -575,14 +575,14 @@ discard block |
||
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
| 578 | - * Return a list of all users in AD that have a specific value in a field |
|
| 579 | - * |
|
| 580 | - * @param bool $includeDescription Return a description of the user |
|
| 581 | - * @param string $searchField Field to search search for |
|
| 582 | - * @param string $searchFilter Value to search for in the specified field |
|
| 583 | - * @param bool $sorted Sort the user accounts |
|
| 584 | - * @return array |
|
| 585 | - */ |
|
| 578 | + * Return a list of all users in AD that have a specific value in a field |
|
| 579 | + * |
|
| 580 | + * @param bool $includeDescription Return a description of the user |
|
| 581 | + * @param string $searchField Field to search search for |
|
| 582 | + * @param string $searchFilter Value to search for in the specified field |
|
| 583 | + * @param bool $sorted Sort the user accounts |
|
| 584 | + * @return array |
|
| 585 | + */ |
|
| 586 | 586 | public function find($includeDescription = false, $searchField = false, $searchFilter = false, $sorted = true) { |
| 587 | 587 | if (!$this->adldap->getLdapBind()) { return false; } |
| 588 | 588 | |
@@ -609,19 +609,19 @@ discard block |
||
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | if ($sorted) { |
| 612 | - asort($usersArray); |
|
| 612 | + asort($usersArray); |
|
| 613 | 613 | } |
| 614 | 614 | return ($usersArray); |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
| 618 | - * Move a user account to a different OU |
|
| 619 | - * |
|
| 620 | - * @param string $username The username to move (please be careful here!) |
|
| 621 | - * @param array $container The container or containers to move the user to (please be careful here!). |
|
| 622 | - * accepts containers in 1. parent 2. child order |
|
| 623 | - * @return array |
|
| 624 | - */ |
|
| 618 | + * Move a user account to a different OU |
|
| 619 | + * |
|
| 620 | + * @param string $username The username to move (please be careful here!) |
|
| 621 | + * @param array $container The container or containers to move the user to (please be careful here!). |
|
| 622 | + * accepts containers in 1. parent 2. child order |
|
| 623 | + * @return array |
|
| 624 | + */ |
|
| 625 | 625 | public function move($username, $container) { |
| 626 | 626 | if (!$this->adldap->getLdapBind()) { return false; } |
| 627 | 627 | if ($username === null) { return "Missing compulsory field [username]"; } |
@@ -642,11 +642,11 @@ discard block |
||
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
| 645 | - * Get the last logon time of any user as a Unix timestamp |
|
| 646 | - * |
|
| 647 | - * @param string $username |
|
| 648 | - * @return long $unixTimestamp |
|
| 649 | - */ |
|
| 645 | + * Get the last logon time of any user as a Unix timestamp |
|
| 646 | + * |
|
| 647 | + * @param string $username |
|
| 648 | + * @return long $unixTimestamp |
|
| 649 | + */ |
|
| 650 | 650 | public function getLastLogon($username) { |
| 651 | 651 | if (!$this->adldap->getLdapBind()) { return false; } |
| 652 | 652 | if ($username === null) { return "Missing compulsory field [username]"; } |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 39 | -require_once(dirname(__FILE__) . '/../collections/adLDAPUserCollection.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | +require_once(dirname(__FILE__).'/../collections/adLDAPUserCollection.php'); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * USER FUNCTIONS |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; } |
| 83 | 83 | if (!is_array($attributes["container"])) { return "Container attribute must be an array."; } |
| 84 | 84 | |
| 85 | - if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) { |
|
| 85 | + if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) { |
|
| 86 | 86 | throw new \adLDAP\adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.'); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if (!array_key_exists("display_name", $attributes)) { |
| 90 | - $attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"]; |
|
| 90 | + $attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"]; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Translate the schema |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | // Determine the container |
| 113 | 113 | $attributes["container"] = array_reverse($attributes["container"]); |
| 114 | - $container = "OU=" . implode(", OU=",$attributes["container"]); |
|
| 114 | + $container = "OU=".implode(", OU=", $attributes["container"]); |
|
| 115 | 115 | |
| 116 | 116 | // Add the entry |
| 117 | - $result = @ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"][0] . ", " . $container . "," . $this->adldap->getBaseDn(), $add); |
|
| 117 | + $result = @ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"][0].", ".$container.",".$this->adldap->getBaseDn(), $add); |
|
| 118 | 118 | if ($result != true) { |
| 119 | 119 | return false; |
| 120 | 120 | } |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | * @return int |
| 129 | 129 | */ |
| 130 | 130 | protected function accountControl($options) { |
| 131 | - $val=0; |
|
| 131 | + $val = 0; |
|
| 132 | 132 | |
| 133 | 133 | if (is_array($options)) { |
| 134 | - if (in_array("SCRIPT",$options)) { $val=$val+1; } |
|
| 135 | - if (in_array("ACCOUNTDISABLE",$options)) { $val=$val+2; } |
|
| 136 | - if (in_array("HOMEDIR_REQUIRED",$options)) { $val=$val+8; } |
|
| 137 | - if (in_array("LOCKOUT",$options)) { $val=$val+16; } |
|
| 138 | - if (in_array("PASSWD_NOTREQD",$options)) { $val=$val+32; } |
|
| 134 | + if (in_array("SCRIPT", $options)) { $val = $val + 1; } |
|
| 135 | + if (in_array("ACCOUNTDISABLE", $options)) { $val = $val + 2; } |
|
| 136 | + if (in_array("HOMEDIR_REQUIRED", $options)) { $val = $val + 8; } |
|
| 137 | + if (in_array("LOCKOUT", $options)) { $val = $val + 16; } |
|
| 138 | + if (in_array("PASSWD_NOTREQD", $options)) { $val = $val + 32; } |
|
| 139 | 139 | //PASSWD_CANT_CHANGE Note You cannot assign this permission by directly modifying the UserAccountControl attribute. |
| 140 | 140 | //For information about how to set the permission programmatically, see the "Property flag descriptions" section. |
| 141 | - if (in_array("ENCRYPTED_TEXT_PWD_ALLOWED",$options)) { $val=$val+128; } |
|
| 142 | - if (in_array("TEMP_DUPLICATE_ACCOUNT",$options)) { $val=$val+256; } |
|
| 143 | - if (in_array("NORMAL_ACCOUNT",$options)) { $val=$val+512; } |
|
| 144 | - if (in_array("INTERDOMAIN_TRUST_ACCOUNT",$options)) { $val=$val+2048; } |
|
| 145 | - if (in_array("WORKSTATION_TRUST_ACCOUNT",$options)) { $val=$val+4096; } |
|
| 146 | - if (in_array("SERVER_TRUST_ACCOUNT",$options)) { $val=$val+8192; } |
|
| 147 | - if (in_array("DONT_EXPIRE_PASSWORD",$options)){ $val=$val+65536; } |
|
| 148 | - if (in_array("MNS_LOGON_ACCOUNT",$options)) { $val=$val+131072; } |
|
| 149 | - if (in_array("SMARTCARD_REQUIRED",$options)) { $val=$val+262144; } |
|
| 150 | - if (in_array("TRUSTED_FOR_DELEGATION",$options)) { $val=$val+524288; } |
|
| 151 | - if (in_array("NOT_DELEGATED",$options)) { $val=$val+1048576; } |
|
| 152 | - if (in_array("USE_DES_KEY_ONLY",$options)) { $val=$val+2097152; } |
|
| 153 | - if (in_array("DONT_REQ_PREAUTH",$options)) { $val=$val+4194304; } |
|
| 154 | - if (in_array("PASSWORD_EXPIRED",$options)) { $val=$val+8388608; } |
|
| 155 | - if (in_array("TRUSTED_TO_AUTH_FOR_DELEGATION",$options)) { $val=$val+16777216; } |
|
| 141 | + if (in_array("ENCRYPTED_TEXT_PWD_ALLOWED", $options)) { $val = $val + 128; } |
|
| 142 | + if (in_array("TEMP_DUPLICATE_ACCOUNT", $options)) { $val = $val + 256; } |
|
| 143 | + if (in_array("NORMAL_ACCOUNT", $options)) { $val = $val + 512; } |
|
| 144 | + if (in_array("INTERDOMAIN_TRUST_ACCOUNT", $options)) { $val = $val + 2048; } |
|
| 145 | + if (in_array("WORKSTATION_TRUST_ACCOUNT", $options)) { $val = $val + 4096; } |
|
| 146 | + if (in_array("SERVER_TRUST_ACCOUNT", $options)) { $val = $val + 8192; } |
|
| 147 | + if (in_array("DONT_EXPIRE_PASSWORD", $options)) { $val = $val + 65536; } |
|
| 148 | + if (in_array("MNS_LOGON_ACCOUNT", $options)) { $val = $val + 131072; } |
|
| 149 | + if (in_array("SMARTCARD_REQUIRED", $options)) { $val = $val + 262144; } |
|
| 150 | + if (in_array("TRUSTED_FOR_DELEGATION", $options)) { $val = $val + 524288; } |
|
| 151 | + if (in_array("NOT_DELEGATED", $options)) { $val = $val + 1048576; } |
|
| 152 | + if (in_array("USE_DES_KEY_ONLY", $options)) { $val = $val + 2097152; } |
|
| 153 | + if (in_array("DONT_REQ_PREAUTH", $options)) { $val = $val + 4194304; } |
|
| 154 | + if (in_array("PASSWORD_EXPIRED", $options)) { $val = $val + 8388608; } |
|
| 155 | + if (in_array("TRUSTED_TO_AUTH_FOR_DELEGATION", $options)) { $val = $val + 16777216; } |
|
| 156 | 156 | } |
| 157 | 157 | return $val; |
| 158 | 158 | } |
@@ -214,17 +214,17 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if ($isGUID === true) { |
| 216 | 216 | $username = $this->adldap->utilities()->strGuidToHex($username); |
| 217 | - $filter = "objectguid=" . $username; |
|
| 217 | + $filter = "objectguid=".$username; |
|
| 218 | 218 | } |
| 219 | 219 | else if (strpos($username, "@")) { |
| 220 | - $filter = "userPrincipalName=" . $username; |
|
| 220 | + $filter = "userPrincipalName=".$username; |
|
| 221 | 221 | } |
| 222 | 222 | else { |
| 223 | - $filter = "samaccountname=" . $username; |
|
| 223 | + $filter = "samaccountname=".$username; |
|
| 224 | 224 | } |
| 225 | 225 | $filter = "(&(objectCategory=person)({$filter}))"; |
| 226 | 226 | if ($fields === NULL) { |
| 227 | - $fields = array("samaccountname","mail","memberof","department","displayname","telephonenumber","primarygroupid","objectsid"); |
|
| 227 | + $fields = array("samaccountname", "mail", "memberof", "department", "displayname", "telephonenumber", "primarygroupid", "objectsid"); |
|
| 228 | 228 | } |
| 229 | 229 | if (!in_array("objectsid", $fields)) { |
| 230 | 230 | $fields[] = "objectsid"; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | //$entries[0]["memberof"][]=$this->group_cn($entries[0]["primarygroupid"][0]); |
| 241 | 241 | $entries[0]["memberof"][] = $this->adldap->group()->getPrimaryGroup($entries[0]["primarygroupid"][0], $entries[0]["objectsid"][0]); |
| 242 | 242 | } else { |
| 243 | - $entries[0]["memberof"][] = "CN=Domain Users,CN=Users," . $this->adldap->getBaseDn(); |
|
| 243 | + $entries[0]["memberof"][] = "CN=Domain Users,CN=Users,".$this->adldap->getBaseDn(); |
|
| 244 | 244 | } |
| 245 | 245 | if (!isset($entries[0]["memberof"]["count"])) { |
| 246 | 246 | $entries[0]["memberof"]["count"] = 0; |
@@ -469,15 +469,15 @@ discard block |
||
| 469 | 469 | return false; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - $add=array(); |
|
| 472 | + $add = array(); |
|
| 473 | 473 | $add["unicodePwd"][0] = $this->encodePassword($password); |
| 474 | 474 | |
| 475 | 475 | $result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add); |
| 476 | 476 | if ($result === false) { |
| 477 | 477 | $err = ldap_errno($this->adldap->getLdapConnection()); |
| 478 | 478 | if ($err) { |
| 479 | - $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.'; |
|
| 480 | - if($err == 53) { |
|
| 479 | + $msg = 'Error '.$err.': '.ldap_err2str($err).'.'; |
|
| 480 | + if ($err == 53) { |
|
| 481 | 481 | $msg .= ' Your password might not match the password policy.'; |
| 482 | 482 | } |
| 483 | 483 | throw new \adLDAP\adLDAPException($msg); |
@@ -496,9 +496,9 @@ discard block |
||
| 496 | 496 | * @return string |
| 497 | 497 | */ |
| 498 | 498 | public function encodePassword($password) { |
| 499 | - $password="\"".$password."\""; |
|
| 500 | - $encoded=""; |
|
| 501 | - for ($i=0; $i <strlen($password); $i++) { $encoded.="{$password{$i}}\000"; } |
|
| 499 | + $password = "\"".$password."\""; |
|
| 500 | + $encoded = ""; |
|
| 501 | + for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; } |
|
| 502 | 502 | return $encoded; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | * @param bool $isGUID Is the username passed a GUID or a samAccountName |
| 511 | 511 | * @return string |
| 512 | 512 | */ |
| 513 | - public function dn($username, $isGUID=false) { |
|
| 513 | + public function dn($username, $isGUID = false) { |
|
| 514 | 514 | $user = $this->info($username, array("cn"), $isGUID); |
| 515 | 515 | if ($user[0]["dn"] === NULL) { |
| 516 | 516 | return false; |
@@ -531,14 +531,14 @@ discard block |
||
| 531 | 531 | if (!$this->adldap->getLdapBind()) { return false; } |
| 532 | 532 | |
| 533 | 533 | // Perform the search and grab all their details |
| 534 | - $filter = "(&(objectClass=user)(samaccounttype=" . adLDAP::ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)(cn=" . $search . "))"; |
|
| 535 | - $fields = array("samaccountname","displayname"); |
|
| 534 | + $filter = "(&(objectClass=user)(samaccounttype=".adLDAP::ADLDAP_NORMAL_ACCOUNT.")(objectCategory=person)(cn=".$search."))"; |
|
| 535 | + $fields = array("samaccountname", "displayname"); |
|
| 536 | 536 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 537 | 537 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 538 | 538 | |
| 539 | 539 | $usersArray = array(); |
| 540 | - for ($i=0; $i<$entries["count"]; $i++) { |
|
| 541 | - if ($includeDescription && strlen($entries[$i]["displayname"][0])>0) { |
|
| 540 | + for ($i = 0; $i < $entries["count"]; $i++) { |
|
| 541 | + if ($includeDescription && strlen($entries[$i]["displayname"][0]) > 0) { |
|
| 542 | 542 | $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["displayname"][0]; |
| 543 | 543 | } elseif ($includeDescription) { |
| 544 | 544 | $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["samaccountname"][0]; |
@@ -559,10 +559,10 @@ discard block |
||
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | 561 | public function usernameToGuid($username) { |
| 562 | - if (!$this->adldap->getLdapBind()){ return false; } |
|
| 563 | - if ($username === null){ return "Missing compulsory field [username]"; } |
|
| 562 | + if (!$this->adldap->getLdapBind()) { return false; } |
|
| 563 | + if ($username === null) { return "Missing compulsory field [username]"; } |
|
| 564 | 564 | |
| 565 | - $filter = "samaccountname=" . $username; |
|
| 565 | + $filter = "samaccountname=".$username; |
|
| 566 | 566 | $fields = array("objectGUID"); |
| 567 | 567 | $sr = @ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 568 | 568 | if (ldap_count_entries($this->adldap->getLdapConnection(), $sr) > 0) { |
@@ -589,15 +589,15 @@ discard block |
||
| 589 | 589 | // Perform the search and grab all their details |
| 590 | 590 | $searchParams = ""; |
| 591 | 591 | if ($searchField) { |
| 592 | - $searchParams = "(" . $searchField . "=" . $searchFilter . ")"; |
|
| 592 | + $searchParams = "(".$searchField."=".$searchFilter.")"; |
|
| 593 | 593 | } |
| 594 | - $filter = "(&(objectClass=user)(samaccounttype=" . adLDAP::ADLDAP_NORMAL_ACCOUNT .")(objectCategory=person)" . $searchParams . ")"; |
|
| 595 | - $fields = array("samaccountname","displayname"); |
|
| 594 | + $filter = "(&(objectClass=user)(samaccounttype=".adLDAP::ADLDAP_NORMAL_ACCOUNT.")(objectCategory=person)".$searchParams.")"; |
|
| 595 | + $fields = array("samaccountname", "displayname"); |
|
| 596 | 596 | $sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields); |
| 597 | 597 | $entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr); |
| 598 | 598 | |
| 599 | 599 | $usersArray = array(); |
| 600 | - for ($i=0; $i < $entries["count"]; $i++) { |
|
| 600 | + for ($i = 0; $i < $entries["count"]; $i++) { |
|
| 601 | 601 | if ($includeDescription && strlen($entries[$i]["displayname"][0]) > 0) { |
| 602 | 602 | $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["displayname"][0]; |
| 603 | 603 | } |
@@ -630,10 +630,10 @@ discard block |
||
| 630 | 630 | |
| 631 | 631 | $userInfo = $this->info($username, array("*")); |
| 632 | 632 | $dn = $userInfo[0]['distinguishedname'][0]; |
| 633 | - $newRDn = "cn=" . $username; |
|
| 633 | + $newRDn = "cn=".$username; |
|
| 634 | 634 | $container = array_reverse($container); |
| 635 | - $newContainer = "ou=" . implode(",ou=",$container); |
|
| 636 | - $newBaseDn = strtolower($newContainer) . "," . $this->adldap->getBaseDn(); |
|
| 635 | + $newContainer = "ou=".implode(",ou=", $container); |
|
| 636 | + $newBaseDn = strtolower($newContainer).",".$this->adldap->getBaseDn(); |
|
| 637 | 637 | $result = @ldap_rename($this->adldap->getLdapConnection(), $dn, $newRDn, $newBaseDn, true); |
| 638 | 638 | if ($result !== true) { |
| 639 | 639 | return false; |
@@ -215,11 +215,9 @@ discard block |
||
| 215 | 215 | if ($isGUID === true) { |
| 216 | 216 | $username = $this->adldap->utilities()->strGuidToHex($username); |
| 217 | 217 | $filter = "objectguid=" . $username; |
| 218 | - } |
|
| 219 | - else if (strpos($username, "@")) { |
|
| 218 | + } else if (strpos($username, "@")) { |
|
| 220 | 219 | $filter = "userPrincipalName=" . $username; |
| 221 | - } |
|
| 222 | - else { |
|
| 220 | + } else { |
|
| 223 | 221 | $filter = "samaccountname=" . $username; |
| 224 | 222 | } |
| 225 | 223 | $filter = "(&(objectCategory=person)({$filter}))"; |
@@ -401,8 +399,7 @@ discard block |
||
| 401 | 399 | if (array_key_exists("enabled", $attributes)) { |
| 402 | 400 | if ($attributes["enabled"]) { |
| 403 | 401 | $controlOptions = array("NORMAL_ACCOUNT"); |
| 404 | - } |
|
| 405 | - else { |
|
| 402 | + } else { |
|
| 406 | 403 | $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE"); |
| 407 | 404 | } |
| 408 | 405 | $mod["userAccountControl"][0] = $this->accountControl($controlOptions); |
@@ -481,8 +478,7 @@ discard block |
||
| 481 | 478 | $msg .= ' Your password might not match the password policy.'; |
| 482 | 479 | } |
| 483 | 480 | throw new \adLDAP\adLDAPException($msg); |
| 484 | - } |
|
| 485 | - else { |
|
| 481 | + } else { |
|
| 486 | 482 | return false; |
| 487 | 483 | } |
| 488 | 484 | } |
@@ -600,11 +596,9 @@ discard block |
||
| 600 | 596 | for ($i=0; $i < $entries["count"]; $i++) { |
| 601 | 597 | if ($includeDescription && strlen($entries[$i]["displayname"][0]) > 0) { |
| 602 | 598 | $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["displayname"][0]; |
| 603 | - } |
|
| 604 | - else if ($includeDescription) { |
|
| 599 | + } else if ($includeDescription) { |
|
| 605 | 600 | $usersArray[$entries[$i]["samaccountname"][0]] = $entries[$i]["samaccountname"][0]; |
| 606 | - } |
|
| 607 | - else { |
|
| 601 | + } else { |
|
| 608 | 602 | array_push($usersArray, $entries[$i]["samaccountname"][0]); |
| 609 | 603 | } |
| 610 | 604 | } |
@@ -253,7 +253,7 @@ |
||
| 253 | 253 | * Round a Windows timestamp down to seconds and remove the seconds between 1601-01-01 and 1970-01-01 |
| 254 | 254 | * |
| 255 | 255 | * @param long $windowsTime |
| 256 | - * @return long $unixTime |
|
| 256 | + * @return double $unixTime |
|
| 257 | 257 | */ |
| 258 | 258 | public static function convertWindowsTimeToUnixTime($windowsTime) { |
| 259 | 259 | $unixTime = round($windowsTime / 10000000) - 11644473600; |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | const ADLDAP_VERSION = '5.0.0'; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * The current adLDAP connection via dependency injection |
|
| 48 | - * |
|
| 49 | - * @var adLDAP |
|
| 50 | - */ |
|
| 47 | + * The current adLDAP connection via dependency injection |
|
| 48 | + * |
|
| 49 | + * @var adLDAP |
|
| 50 | + */ |
|
| 51 | 51 | protected $adldap; |
| 52 | 52 | |
| 53 | 53 | public function __construct(adLDAP $adldap) { |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | - * Take an LDAP query and return the nice names, without all the LDAP prefixes (eg. CN, DN) |
|
| 60 | - * |
|
| 61 | - * @param array $groups |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 59 | + * Take an LDAP query and return the nice names, without all the LDAP prefixes (eg. CN, DN) |
|
| 60 | + * |
|
| 61 | + * @param array $groups |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | 64 | public function niceNames($groups) { |
| 65 | 65 | |
| 66 | 66 | $groupArray = array(); |
@@ -79,43 +79,43 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * Escape characters for use in an ldap_create function |
|
| 83 | - * |
|
| 84 | - * @param string $str |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 82 | + * Escape characters for use in an ldap_create function |
|
| 83 | + * |
|
| 84 | + * @param string $str |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | 87 | public function escapeCharacters($str) { |
| 88 | 88 | $str = str_replace(",", "\,", $str); |
| 89 | 89 | return $str; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | - * Escape strings for the use in LDAP filters |
|
| 94 | - * |
|
| 95 | - * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
| 96 | - * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
| 97 | - * |
|
| 98 | - * @param string $str The string the parse |
|
| 99 | - * @author Port by Andreas Gohr <[email protected]> |
|
| 100 | - * @author Modified for PHP55 by Esteban Santana Santana <[email protected]> |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 93 | + * Escape strings for the use in LDAP filters |
|
| 94 | + * |
|
| 95 | + * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT |
|
| 96 | + * Ported from Perl's Net::LDAP::Util escape_filter_value |
|
| 97 | + * |
|
| 98 | + * @param string $str The string the parse |
|
| 99 | + * @author Port by Andreas Gohr <[email protected]> |
|
| 100 | + * @author Modified for PHP55 by Esteban Santana Santana <[email protected]> |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | 103 | public function ldapSlashes($str) { |
| 104 | 104 | return preg_replace_callback( |
| 105 | - '/([\x00-\x1F\*\(\)\\\\])/', |
|
| 106 | - function ($matches) { |
|
| 107 | - return "\\".join("", unpack("H2", $matches[1])); |
|
| 108 | - }, |
|
| 109 | - $str |
|
| 110 | - ); |
|
| 105 | + '/([\x00-\x1F\*\(\)\\\\])/', |
|
| 106 | + function ($matches) { |
|
| 107 | + return "\\".join("", unpack("H2", $matches[1])); |
|
| 108 | + }, |
|
| 109 | + $str |
|
| 110 | + ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | - * Converts a string GUID to a hexdecimal value so it can be queried |
|
| 115 | - * |
|
| 116 | - * @param string $strGUID A string representation of a GUID |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 114 | + * Converts a string GUID to a hexdecimal value so it can be queried |
|
| 115 | + * |
|
| 116 | + * @param string $strGUID A string representation of a GUID |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | 119 | public function strGuidToHex($strGUID) { |
| 120 | 120 | $strGUID = str_replace('-', '', $strGUID); |
| 121 | 121 | |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | - * Convert a binary SID to a text SID |
|
| 142 | - * |
|
| 143 | - * @param string $binsid A Binary SID |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function getTextSID($binsid) { |
|
| 141 | + * Convert a binary SID to a text SID |
|
| 142 | + * |
|
| 143 | + * @param string $binsid A Binary SID |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function getTextSID($binsid) { |
|
| 147 | 147 | $hex_sid = bin2hex($binsid); |
| 148 | 148 | $rev = hexdec(substr($hex_sid, 0, 2)); |
| 149 | 149 | $subcount = hexdec(substr($hex_sid, 2, 2)); |
@@ -158,28 +158,28 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // Cheat by tacking on the S- |
| 160 | 160 | return 'S-' . $result; |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | - * Converts a little-endian hex number to one that hexdec() can convert |
|
| 165 | - * |
|
| 166 | - * @param string $hex A hex code |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function littleEndian($hex) { |
|
| 164 | + * Converts a little-endian hex number to one that hexdec() can convert |
|
| 165 | + * |
|
| 166 | + * @param string $hex A hex code |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function littleEndian($hex) { |
|
| 170 | 170 | $result = ''; |
| 171 | 171 | for ($x = strlen($hex) - 2; $x >= 0; $x = $x - 2) { |
| 172 | 172 | $result .= substr($hex, $x, 2); |
| 173 | 173 | } |
| 174 | 174 | return $result; |
| 175 | - } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Converts a binary attribute to a string |
|
| 179 | - * |
|
| 180 | - * @param string $bin A binary LDAP attribute |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 177 | + /** |
|
| 178 | + * Converts a binary attribute to a string |
|
| 179 | + * |
|
| 180 | + * @param string $bin A binary LDAP attribute |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | 183 | public function binaryToText($bin) { |
| 184 | 184 | $hex_guid = bin2hex($bin); |
| 185 | 185 | $hex_guid_to_guid_str = ''; |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
| 203 | - * Converts a binary GUID to a string GUID |
|
| 204 | - * |
|
| 205 | - * @param string $binaryGuid The binary GUID attribute to convert |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 203 | + * Converts a binary GUID to a string GUID |
|
| 204 | + * |
|
| 205 | + * @param string $binaryGuid The binary GUID attribute to convert |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | 208 | public function decodeGuid($binaryGuid) { |
| 209 | 209 | if ($binaryGuid === null){ return "Missing compulsory field [binaryGuid]"; } |
| 210 | 210 | |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | - * Convert a boolean value to a string |
|
| 217 | - * You should never need to call this yourself |
|
| 218 | - * |
|
| 219 | - * @param bool $bool Boolean value |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 216 | + * Convert a boolean value to a string |
|
| 217 | + * You should never need to call this yourself |
|
| 218 | + * |
|
| 219 | + * @param bool $bool Boolean value |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | 222 | public function boolToStr($bool) { |
| 223 | 223 | return ($bool) ? 'TRUE' : 'FALSE'; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | - * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
| 228 | - */ |
|
| 227 | + * Convert 8bit characters e.g. accented characters to UTF8 encoded characters |
|
| 228 | + */ |
|
| 229 | 229 | public function encode8Bit(&$item, $key) { |
| 230 | 230 | $encode = false; |
| 231 | 231 | if (is_string($item)) { |
@@ -241,23 +241,23 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | - * Get the current class version number |
|
| 245 | - * |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 244 | + * Get the current class version number |
|
| 245 | + * |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | 248 | public function getVersion() { |
| 249 | 249 | return self::ADLDAP_VERSION; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
| 253 | - * Round a Windows timestamp down to seconds and remove the seconds between 1601-01-01 and 1970-01-01 |
|
| 254 | - * |
|
| 255 | - * @param long $windowsTime |
|
| 256 | - * @return long $unixTime |
|
| 257 | - */ |
|
| 253 | + * Round a Windows timestamp down to seconds and remove the seconds between 1601-01-01 and 1970-01-01 |
|
| 254 | + * |
|
| 255 | + * @param long $windowsTime |
|
| 256 | + * @return long $unixTime |
|
| 257 | + */ |
|
| 258 | 258 | public static function convertWindowsTimeToUnixTime($windowsTime) { |
| 259 | - $unixTime = round($windowsTime / 10000000) - 11644473600; |
|
| 260 | - return $unixTime; |
|
| 259 | + $unixTime = round($windowsTime / 10000000) - 11644473600; |
|
| 260 | + return $unixTime; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @version 5.0.0 |
| 36 | 36 | * @link http://github.com/adldap/adLDAP |
| 37 | 37 | */ |
| 38 | -require_once(dirname(__FILE__) . '/../adLDAP.php'); |
|
| 38 | +require_once(dirname(__FILE__).'/../adLDAP.php'); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * UTILITY FUNCTIONS |
@@ -64,15 +64,15 @@ discard block |
||
| 64 | 64 | public function niceNames($groups) { |
| 65 | 65 | |
| 66 | 66 | $groupArray = array(); |
| 67 | - for ($i=0; $i<$groups["count"]; $i++) { // For each group |
|
| 67 | + for ($i = 0; $i < $groups["count"]; $i++) { // For each group |
|
| 68 | 68 | $line = $groups[$i]; |
| 69 | 69 | |
| 70 | - if (strlen($line)>0) { |
|
| 70 | + if (strlen($line) > 0) { |
|
| 71 | 71 | // More presumptions, they're all prefixed with CN= |
| 72 | 72 | // so we ditch the first three characters and the group |
| 73 | 73 | // name goes up to the first comma |
| 74 | - $bits=explode(",", $line); |
|
| 75 | - $groupArray[] = substr($bits[0], 3, (strlen($bits[0])-3)); |
|
| 74 | + $bits = explode(",", $line); |
|
| 75 | + $groupArray[] = substr($bits[0], 3, (strlen($bits[0]) - 3)); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | return $groupArray; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | public function ldapSlashes($str) { |
| 104 | 104 | return preg_replace_callback( |
| 105 | 105 | '/([\x00-\x1F\*\(\)\\\\])/', |
| 106 | - function ($matches) { |
|
| 106 | + function($matches) { |
|
| 107 | 107 | return "\\".join("", unpack("H2", $matches[1])); |
| 108 | 108 | }, |
| 109 | 109 | $str |
@@ -119,18 +119,18 @@ discard block |
||
| 119 | 119 | public function strGuidToHex($strGUID) { |
| 120 | 120 | $strGUID = str_replace('-', '', $strGUID); |
| 121 | 121 | |
| 122 | - $octet_str = '\\' . substr($strGUID, 6, 2); |
|
| 123 | - $octet_str .= '\\' . substr($strGUID, 4, 2); |
|
| 124 | - $octet_str .= '\\' . substr($strGUID, 2, 2); |
|
| 125 | - $octet_str .= '\\' . substr($strGUID, 0, 2); |
|
| 126 | - $octet_str .= '\\' . substr($strGUID, 10, 2); |
|
| 127 | - $octet_str .= '\\' . substr($strGUID, 8, 2); |
|
| 128 | - $octet_str .= '\\' . substr($strGUID, 14, 2); |
|
| 129 | - $octet_str .= '\\' . substr($strGUID, 12, 2); |
|
| 122 | + $octet_str = '\\'.substr($strGUID, 6, 2); |
|
| 123 | + $octet_str .= '\\'.substr($strGUID, 4, 2); |
|
| 124 | + $octet_str .= '\\'.substr($strGUID, 2, 2); |
|
| 125 | + $octet_str .= '\\'.substr($strGUID, 0, 2); |
|
| 126 | + $octet_str .= '\\'.substr($strGUID, 10, 2); |
|
| 127 | + $octet_str .= '\\'.substr($strGUID, 8, 2); |
|
| 128 | + $octet_str .= '\\'.substr($strGUID, 14, 2); |
|
| 129 | + $octet_str .= '\\'.substr($strGUID, 12, 2); |
|
| 130 | 130 | //$octet_str .= '\\' . substr($strGUID, 16, strlen($strGUID)); |
| 131 | - for ($i=16; $i<=(strlen($strGUID)-2); $i++) { |
|
| 131 | + for ($i = 16; $i <= (strlen($strGUID) - 2); $i++) { |
|
| 132 | 132 | if (($i % 2) == 0) { |
| 133 | - $octet_str .= '\\' . substr($strGUID, $i, 2); |
|
| 133 | + $octet_str .= '\\'.substr($strGUID, $i, 2); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -150,14 +150,14 @@ discard block |
||
| 150 | 150 | $auth = hexdec(substr($hex_sid, 4, 12)); |
| 151 | 151 | $result = "$rev-$auth"; |
| 152 | 152 | |
| 153 | - for ($x=0;$x < $subcount; $x++) { |
|
| 153 | + for ($x = 0; $x < $subcount; $x++) { |
|
| 154 | 154 | $subauth[$x] = |
| 155 | 155 | hexdec($this->littleEndian(substr($hex_sid, 16 + ($x * 8), 8))); |
| 156 | - $result .= "-" . $subauth[$x]; |
|
| 156 | + $result .= "-".$subauth[$x]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Cheat by tacking on the S- |
| 160 | - return 'S-' . $result; |
|
| 160 | + return 'S-'.$result; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -183,19 +183,19 @@ discard block |
||
| 183 | 183 | public function binaryToText($bin) { |
| 184 | 184 | $hex_guid = bin2hex($bin); |
| 185 | 185 | $hex_guid_to_guid_str = ''; |
| 186 | - for($k = 1; $k <= 4; ++$k) { |
|
| 186 | + for ($k = 1; $k <= 4; ++$k) { |
|
| 187 | 187 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
| 188 | 188 | } |
| 189 | 189 | $hex_guid_to_guid_str .= '-'; |
| 190 | - for($k = 1; $k <= 2; ++$k) { |
|
| 190 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 191 | 191 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
| 192 | 192 | } |
| 193 | 193 | $hex_guid_to_guid_str .= '-'; |
| 194 | - for($k = 1; $k <= 2; ++$k) { |
|
| 194 | + for ($k = 1; $k <= 2; ++$k) { |
|
| 195 | 195 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
| 196 | 196 | } |
| 197 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
| 198 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
| 197 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
| 198 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
| 199 | 199 | return strtoupper($hex_guid_to_guid_str); |
| 200 | 200 | } |
| 201 | 201 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * @return string |
| 207 | 207 | */ |
| 208 | 208 | public function decodeGuid($binaryGuid) { |
| 209 | - if ($binaryGuid === null){ return "Missing compulsory field [binaryGuid]"; } |
|
| 209 | + if ($binaryGuid === null) { return "Missing compulsory field [binaryGuid]"; } |
|
| 210 | 210 | |
| 211 | 211 | $strGUID = $this->binaryToText($binaryGuid); |
| 212 | 212 | return $strGUID; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | public function encode8Bit(&$item, $key) { |
| 230 | 230 | $encode = false; |
| 231 | 231 | if (is_string($item)) { |
| 232 | - for ($i=0; $i<strlen($item); $i++) { |
|
| 232 | + for ($i = 0; $i < strlen($item); $i++) { |
|
| 233 | 233 | if (ord($item[$i]) >> 7) { |
| 234 | 234 | $encode = true; |
| 235 | 235 | } |
@@ -268,16 +268,16 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return array |
| 270 | 270 | */ |
| 271 | - public function dnStrToArr($dnStr, $excludeBaseDn = true){ |
|
| 271 | + public function dnStrToArr($dnStr, $excludeBaseDn = true) { |
|
| 272 | 272 | $dnArr = array(); |
| 273 | - if(!empty($dnStr)){ |
|
| 273 | + if (!empty($dnStr)) { |
|
| 274 | 274 | $tmpArr = explode(',', $dnStr); |
| 275 | 275 | $baseDnArr = explode(',', $this->adldap->getBaseDn()); |
| 276 | - foreach($tmpArr as $_tmpStr){ |
|
| 277 | - if($excludeBaseDn && in_array($_tmpStr, $baseDnArr)){ |
|
| 276 | + foreach ($tmpArr as $_tmpStr) { |
|
| 277 | + if ($excludeBaseDn && in_array($_tmpStr, $baseDnArr)) { |
|
| 278 | 278 | continue; |
| 279 | 279 | } |
| 280 | - $dnArr[]= substr($_tmpStr, strpos($_tmpStr, '=') + 1); |
|
| 280 | + $dnArr[] = substr($_tmpStr, strpos($_tmpStr, '=') + 1); |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | return $dnArr; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string $left The left argument |
| 30 | 30 | * @param string $right The right argument |
| 31 | 31 | * |
| 32 | - * @return A base-10 string of the sum of the two arguments |
|
| 32 | + * @return string base-10 string of the sum of the two arguments |
|
| 33 | 33 | */ |
| 34 | 34 | public function add($left, $right) { |
| 35 | 35 | return bcadd($left, $right, 0); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $left The left argument |
| 42 | 42 | * @param string $right The right argument |
| 43 | 43 | * |
| 44 | - * @return A base-10 string of the difference of the two arguments |
|
| 44 | + * @return string base-10 string of the difference of the two arguments |
|
| 45 | 45 | */ |
| 46 | 46 | public function subtract($left, $right) { |
| 47 | 47 | return bcsub($left, $right); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string $left The left argument |
| 30 | 30 | * @param string $right The right argument |
| 31 | 31 | * |
| 32 | - * @return A base-10 string of the sum of the two arguments |
|
| 32 | + * @return string base-10 string of the sum of the two arguments |
|
| 33 | 33 | */ |
| 34 | 34 | public function add($left, $right) { |
| 35 | 35 | return gmp_strval(gmp_add($left, $right)); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $left The left argument |
| 42 | 42 | * @param string $right The right argument |
| 43 | 43 | * |
| 44 | - * @return A base-10 string of the difference of the two arguments |
|
| 44 | + * @return string base-10 string of the difference of the two arguments |
|
| 45 | 45 | */ |
| 46 | 46 | public function subtract($left, $right) { |
| 47 | 47 | return gmp_strval(gmp_sub($left, $right)); |