@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * @return mixed |
| 53 | 53 | */ |
| 54 | 54 | public function connect($host, $port) { |
| 55 | - if(strpos($host, '://') === false) { |
|
| 56 | - $host = 'ldap://' . $host; |
|
| 55 | + if (strpos($host, '://') === false) { |
|
| 56 | + $host = 'ldap://'.$host; |
|
| 57 | 57 | } |
| 58 | - if(strpos($host, ':', strpos($host, '://') + 1) === false) { |
|
| 58 | + if (strpos($host, ':', strpos($host, '://') + 1) === false) { |
|
| 59 | 59 | //ldap_connect ignores port parameter when URLs are passed |
| 60 | - $host .= ':' . $port; |
|
| 60 | + $host .= ':'.$port; |
|
| 61 | 61 | } |
| 62 | 62 | return $this->invokeLDAPMethod('connect', $host); |
| 63 | 63 | } |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * @return bool |
| 268 | 268 | */ |
| 269 | 269 | protected function isResultFalse($result) { |
| 270 | - if($result === false) { |
|
| 270 | + if ($result === false) { |
|
| 271 | 271 | return true; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if($this->curFunc === 'ldap_search' && is_array($result)) { |
|
| 274 | + if ($this->curFunc === 'ldap_search' && is_array($result)) { |
|
| 275 | 275 | foreach ($result as $singleResult) { |
| 276 | - if($singleResult === false) { |
|
| 276 | + if ($singleResult === false) { |
|
| 277 | 277 | return true; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | protected function invokeLDAPMethod() { |
| 289 | 289 | $arguments = func_get_args(); |
| 290 | - $func = 'ldap_' . array_shift($arguments); |
|
| 291 | - if(function_exists($func)) { |
|
| 290 | + $func = 'ldap_'.array_shift($arguments); |
|
| 291 | + if (function_exists($func)) { |
|
| 292 | 292 | $this->preFunctionCall($func, $arguments); |
| 293 | 293 | $result = call_user_func_array($func, $arguments); |
| 294 | 294 | if ($this->isResultFalse($result)) { |
@@ -318,12 +318,12 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | private function processLDAPError($resource) { |
| 320 | 320 | $errorCode = ldap_errno($resource); |
| 321 | - if($errorCode === 0) { |
|
| 321 | + if ($errorCode === 0) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | - $errorMsg = ldap_error($resource); |
|
| 324 | + $errorMsg = ldap_error($resource); |
|
| 325 | 325 | |
| 326 | - if($this->curFunc === 'ldap_get_entries' |
|
| 326 | + if ($this->curFunc === 'ldap_get_entries' |
|
| 327 | 327 | && $errorCode === -4) { |
| 328 | 328 | } else if ($errorCode === 32) { |
| 329 | 329 | //for now |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | throw new \Exception('LDAP Operations error', $errorCode); |
| 338 | 338 | } else if ($errorCode === 19) { |
| 339 | 339 | ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error); |
| 340 | - throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode); |
|
| 340 | + throw new ConstraintViolationException(!empty($extended_error) ? $extended_error : $errorMsg, $errorCode); |
|
| 341 | 341 | } else { |
| 342 | 342 | \OCP\Util::writeLog('user_ldap', |
| 343 | - 'LDAP error '.$errorMsg.' (' . |
|
| 343 | + 'LDAP error '.$errorMsg.' ('. |
|
| 344 | 344 | $errorCode.') after calling '. |
| 345 | 345 | $this->curFunc, |
| 346 | 346 | \OCP\Util::DEBUG); |
@@ -351,9 +351,9 @@ discard block |
||
| 351 | 351 | * Called after an ldap method is run to act on LDAP error if necessary |
| 352 | 352 | */ |
| 353 | 353 | private function postFunctionCall() { |
| 354 | - if($this->isResource($this->curArgs[0])) { |
|
| 354 | + if ($this->isResource($this->curArgs[0])) { |
|
| 355 | 355 | $resource = $this->curArgs[0]; |
| 356 | - } else if( |
|
| 356 | + } else if ( |
|
| 357 | 357 | $this->curFunc === 'ldap_search' |
| 358 | 358 | && is_array($this->curArgs[0]) |
| 359 | 359 | && $this->isResource($this->curArgs[0][0]) |
@@ -138,17 +138,17 @@ discard block |
||
| 138 | 138 | * @return null |
| 139 | 139 | */ |
| 140 | 140 | public function update() { |
| 141 | - if(is_null($this->dn)) { |
|
| 141 | + if (is_null($this->dn)) { |
|
| 142 | 142 | return null; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap', |
| 146 | 146 | self::USER_PREFKEY_FIRSTLOGIN, 0); |
| 147 | 147 | |
| 148 | - if($this->needsRefresh()) { |
|
| 148 | + if ($this->needsRefresh()) { |
|
| 149 | 149 | $this->updateEmail(); |
| 150 | 150 | $this->updateQuota(); |
| 151 | - if($hasLoggedIn !== 0) { |
|
| 151 | + if ($hasLoggedIn !== 0) { |
|
| 152 | 152 | //we do not need to try it, when the user has not been logged in |
| 153 | 153 | //before, because the file system will not be ready. |
| 154 | 154 | $this->updateAvatar(); |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | $this->markRefreshTime(); |
| 168 | 168 | //Quota |
| 169 | 169 | $attr = strtolower($this->connection->ldapQuotaAttribute); |
| 170 | - if(isset($ldapEntry[$attr])) { |
|
| 170 | + if (isset($ldapEntry[$attr])) { |
|
| 171 | 171 | $this->updateQuota($ldapEntry[$attr][0]); |
| 172 | 172 | } |
| 173 | 173 | unset($attr); |
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | $attr = strtolower($this->connection->ldapEmailAttribute); |
| 177 | - if(isset($ldapEntry[$attr])) { |
|
| 177 | + if (isset($ldapEntry[$attr])) { |
|
| 178 | 178 | $this->updateEmail($ldapEntry[$attr][0]); |
| 179 | 179 | } |
| 180 | 180 | unset($attr); |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | //displayName |
| 183 | 183 | $displayName = $displayName2 = ''; |
| 184 | 184 | $attr = strtolower($this->connection->ldapUserDisplayName); |
| 185 | - if(isset($ldapEntry[$attr])) { |
|
| 185 | + if (isset($ldapEntry[$attr])) { |
|
| 186 | 186 | $displayName = strval($ldapEntry[$attr][0]); |
| 187 | 187 | } |
| 188 | 188 | $attr = strtolower($this->connection->ldapUserDisplayName2); |
| 189 | - if(isset($ldapEntry[$attr])) { |
|
| 189 | + if (isset($ldapEntry[$attr])) { |
|
| 190 | 190 | $displayName2 = strval($ldapEntry[$attr][0]); |
| 191 | 191 | } |
| 192 | 192 | if ($displayName !== '') { |
@@ -200,16 +200,16 @@ discard block |
||
| 200 | 200 | unset($attr); |
| 201 | 201 | |
| 202 | 202 | // LDAP Username, needed for s2s sharing |
| 203 | - if(isset($ldapEntry['uid'])) { |
|
| 203 | + if (isset($ldapEntry['uid'])) { |
|
| 204 | 204 | $this->storeLDAPUserName($ldapEntry['uid'][0]); |
| 205 | - } else if(isset($ldapEntry['samaccountname'])) { |
|
| 205 | + } else if (isset($ldapEntry['samaccountname'])) { |
|
| 206 | 206 | $this->storeLDAPUserName($ldapEntry['samaccountname'][0]); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | //homePath |
| 210 | - if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
| 210 | + if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
| 211 | 211 | $attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:'))); |
| 212 | - if(isset($ldapEntry[$attr])) { |
|
| 212 | + if (isset($ldapEntry[$attr])) { |
|
| 213 | 213 | $this->access->cacheUserHome( |
| 214 | 214 | $this->getUsername(), $this->getHomePath($ldapEntry[$attr][0])); |
| 215 | 215 | } |
@@ -218,15 +218,15 @@ discard block |
||
| 218 | 218 | //memberOf groups |
| 219 | 219 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
| 220 | 220 | $groups = false; |
| 221 | - if(isset($ldapEntry['memberof'])) { |
|
| 221 | + if (isset($ldapEntry['memberof'])) { |
|
| 222 | 222 | $groups = $ldapEntry['memberof']; |
| 223 | 223 | } |
| 224 | 224 | $this->connection->writeToCache($cacheKey, $groups); |
| 225 | 225 | |
| 226 | 226 | //Avatar |
| 227 | 227 | $attrs = array('jpegphoto', 'thumbnailphoto'); |
| 228 | - foreach ($attrs as $attr) { |
|
| 229 | - if(isset($ldapEntry[$attr])) { |
|
| 228 | + foreach ($attrs as $attr) { |
|
| 229 | + if (isset($ldapEntry[$attr])) { |
|
| 230 | 230 | $this->avatarImage = $ldapEntry[$attr][0]; |
| 231 | 231 | // the call to the method that saves the avatar in the file |
| 232 | 232 | // system must be postponed after the login. It is to ensure |
@@ -279,12 +279,12 @@ discard block |
||
| 279 | 279 | if ($path !== '') { |
| 280 | 280 | //if attribute's value is an absolute path take this, otherwise append it to data dir |
| 281 | 281 | //check for / at the beginning or pattern c:\ resp. c:/ |
| 282 | - if( '/' !== $path[0] |
|
| 282 | + if ('/' !== $path[0] |
|
| 283 | 283 | && !(3 < strlen($path) && ctype_alpha($path[0]) |
| 284 | 284 | && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2])) |
| 285 | 285 | ) { |
| 286 | 286 | $path = $this->config->getSystemValue('datadirectory', |
| 287 | - \OC::$SERVERROOT.'/data' ) . '/' . $path; |
|
| 287 | + \OC::$SERVERROOT.'/data').'/'.$path; |
|
| 288 | 288 | } |
| 289 | 289 | //we need it to store it in the DB as well in case a user gets |
| 290 | 290 | //deleted so we can clean up afterwards |
@@ -294,11 +294,11 @@ discard block |
||
| 294 | 294 | return $path; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - if( !is_null($attr) |
|
| 297 | + if (!is_null($attr) |
|
| 298 | 298 | && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true) |
| 299 | 299 | ) { |
| 300 | 300 | // a naming rule attribute is defined, but it doesn't exist for that LDAP user |
| 301 | - throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername()); |
|
| 301 | + throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername()); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | //false will apply default behaviour as defined and done by OC_User |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function getMemberOfGroups() { |
| 310 | 310 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
| 311 | 311 | $memberOfGroups = $this->connection->getFromCache($cacheKey); |
| 312 | - if(!is_null($memberOfGroups)) { |
|
| 312 | + if (!is_null($memberOfGroups)) { |
|
| 313 | 313 | return $memberOfGroups; |
| 314 | 314 | } |
| 315 | 315 | $groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf'); |
@@ -322,15 +322,15 @@ discard block |
||
| 322 | 322 | * @return string data (provided by LDAP) | false |
| 323 | 323 | */ |
| 324 | 324 | public function getAvatarImage() { |
| 325 | - if(!is_null($this->avatarImage)) { |
|
| 325 | + if (!is_null($this->avatarImage)) { |
|
| 326 | 326 | return $this->avatarImage; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | $this->avatarImage = false; |
| 330 | 330 | $attributes = array('jpegPhoto', 'thumbnailPhoto'); |
| 331 | - foreach($attributes as $attribute) { |
|
| 331 | + foreach ($attributes as $attribute) { |
|
| 332 | 332 | $result = $this->access->readAttribute($this->dn, $attribute); |
| 333 | - if($result !== false && is_array($result) && isset($result[0])) { |
|
| 333 | + if ($result !== false && is_array($result) && isset($result[0])) { |
|
| 334 | 334 | $this->avatarImage = $result[0]; |
| 335 | 335 | break; |
| 336 | 336 | } |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | self::USER_PREFKEY_LASTREFRESH, 0); |
| 369 | 369 | |
| 370 | 370 | //TODO make interval configurable |
| 371 | - if((time() - intval($lastChecked)) < 86400 ) { |
|
| 371 | + if ((time() - intval($lastChecked)) < 86400) { |
|
| 372 | 372 | return false; |
| 373 | 373 | } |
| 374 | 374 | return true; |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | public function composeAndStoreDisplayName($displayName, $displayName2 = '') { |
| 396 | 396 | $displayName2 = strval($displayName2); |
| 397 | - if($displayName2 !== '') { |
|
| 398 | - $displayName .= ' (' . $displayName2 . ')'; |
|
| 397 | + if ($displayName2 !== '') { |
|
| 398 | + $displayName .= ' ('.$displayName2.')'; |
|
| 399 | 399 | } |
| 400 | 400 | $this->store('displayName', $displayName); |
| 401 | 401 | return $displayName; |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return bool |
| 418 | 418 | */ |
| 419 | 419 | private function wasRefreshed($feature) { |
| 420 | - if(isset($this->refreshedFeatures[$feature])) { |
|
| 420 | + if (isset($this->refreshedFeatures[$feature])) { |
|
| 421 | 421 | return true; |
| 422 | 422 | } |
| 423 | 423 | $this->refreshedFeatures[$feature] = 1; |
@@ -430,15 +430,15 @@ discard block |
||
| 430 | 430 | * @return null |
| 431 | 431 | */ |
| 432 | 432 | public function updateEmail($valueFromLDAP = null) { |
| 433 | - if($this->wasRefreshed('email')) { |
|
| 433 | + if ($this->wasRefreshed('email')) { |
|
| 434 | 434 | return; |
| 435 | 435 | } |
| 436 | 436 | $email = strval($valueFromLDAP); |
| 437 | - if(is_null($valueFromLDAP)) { |
|
| 437 | + if (is_null($valueFromLDAP)) { |
|
| 438 | 438 | $emailAttribute = $this->connection->ldapEmailAttribute; |
| 439 | 439 | if ($emailAttribute !== '') { |
| 440 | 440 | $aEmail = $this->access->readAttribute($this->dn, $emailAttribute); |
| 441 | - if(is_array($aEmail) && (count($aEmail) > 0)) { |
|
| 441 | + if (is_array($aEmail) && (count($aEmail) > 0)) { |
|
| 442 | 442 | $email = strval($aEmail[0]); |
| 443 | 443 | } |
| 444 | 444 | } |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @return null |
| 462 | 462 | */ |
| 463 | 463 | public function updateQuota($valueFromLDAP = null) { |
| 464 | - if($this->wasRefreshed('quota')) { |
|
| 464 | + if ($this->wasRefreshed('quota')) { |
|
| 465 | 465 | return; |
| 466 | 466 | } |
| 467 | 467 | //can be null |
@@ -469,16 +469,16 @@ discard block |
||
| 469 | 469 | $quota = $quotaDefault !== '' ? $quotaDefault : null; |
| 470 | 470 | $quota = !is_null($valueFromLDAP) ? $valueFromLDAP : $quota; |
| 471 | 471 | |
| 472 | - if(is_null($valueFromLDAP)) { |
|
| 472 | + if (is_null($valueFromLDAP)) { |
|
| 473 | 473 | $quotaAttribute = $this->connection->ldapQuotaAttribute; |
| 474 | 474 | if ($quotaAttribute !== '') { |
| 475 | 475 | $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); |
| 476 | - if($aQuota && (count($aQuota) > 0)) { |
|
| 476 | + if ($aQuota && (count($aQuota) > 0)) { |
|
| 477 | 477 | $quota = $aQuota[0]; |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | - if(!is_null($quota)) { |
|
| 481 | + if (!is_null($quota)) { |
|
| 482 | 482 | $this->userManager->get($this->uid)->setQuota($quota); |
| 483 | 483 | } |
| 484 | 484 | } |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | * @param array $params |
| 490 | 490 | */ |
| 491 | 491 | public function updateAvatarPostLogin($params) { |
| 492 | - if(isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
| 492 | + if (isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
| 493 | 493 | $this->updateAvatar(); |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -499,11 +499,11 @@ discard block |
||
| 499 | 499 | * @return null |
| 500 | 500 | */ |
| 501 | 501 | public function updateAvatar() { |
| 502 | - if($this->wasRefreshed('avatar')) { |
|
| 502 | + if ($this->wasRefreshed('avatar')) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | $avatarImage = $this->getAvatarImage(); |
| 506 | - if($avatarImage === false) { |
|
| 506 | + if ($avatarImage === false) { |
|
| 507 | 507 | //not set, nothing left to do; |
| 508 | 508 | return; |
| 509 | 509 | } |
@@ -516,18 +516,18 @@ discard block |
||
| 516 | 516 | * @return null |
| 517 | 517 | */ |
| 518 | 518 | private function setOwnCloudAvatar() { |
| 519 | - if(!$this->image->valid()) { |
|
| 519 | + if (!$this->image->valid()) { |
|
| 520 | 520 | $this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR); |
| 521 | 521 | return; |
| 522 | 522 | } |
| 523 | 523 | //make sure it is a square and not bigger than 128x128 |
| 524 | 524 | $size = min(array($this->image->width(), $this->image->height(), 128)); |
| 525 | - if(!$this->image->centerCrop($size)) { |
|
| 525 | + if (!$this->image->centerCrop($size)) { |
|
| 526 | 526 | $this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR); |
| 527 | 527 | return; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - if(!$this->fs->isLoaded()) { |
|
| 530 | + if (!$this->fs->isLoaded()) { |
|
| 531 | 531 | $this->fs->setup($this->uid); |
| 532 | 532 | } |
| 533 | 533 | |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | $avatar->set($this->image); |
| 537 | 537 | } catch (\Exception $e) { |
| 538 | 538 | \OC::$server->getLogger()->notice( |
| 539 | - 'Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), |
|
| 539 | + 'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(), |
|
| 540 | 540 | ['app' => 'user_ldap']); |
| 541 | 541 | } |
| 542 | 542 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 'user_ldap', 'isDeleted', '1'); |
| 72 | 72 | |
| 73 | 73 | $userObjects = array(); |
| 74 | - foreach($deletedUsers as $user) { |
|
| 74 | + foreach ($deletedUsers as $user) { |
|
| 75 | 75 | $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); |
| 76 | 76 | } |
| 77 | 77 | $this->deletedUsers = $userObjects; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @return \OCA\User_LDAP\User\OfflineUser[] |
| 85 | 85 | */ |
| 86 | 86 | public function getUsers() { |
| 87 | - if(is_array($this->deletedUsers)) { |
|
| 87 | + if (is_array($this->deletedUsers)) { |
|
| 88 | 88 | return $this->deletedUsers; |
| 89 | 89 | } |
| 90 | 90 | return $this->fetchDeletedUsers(); |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | public function hasUsers() { |
| 98 | - if($this->deletedUsers === false) { |
|
| 98 | + if ($this->deletedUsers === false) { |
|
| 99 | 99 | $this->fetchDeletedUsers(); |
| 100 | 100 | } |
| 101 | - if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
| 101 | + if (is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
| 102 | 102 | return true; |
| 103 | 103 | } |
| 104 | 104 | return false; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @return null |
| 131 | 131 | */ |
| 132 | 132 | private function checkAccess() { |
| 133 | - if(is_null($this->access)) { |
|
| 133 | + if (is_null($this->access)) { |
|
| 134 | 134 | throw new \Exception('LDAP Access instance must be set first'); |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -150,18 +150,18 @@ discard block |
||
| 150 | 150 | $this->access->getConnection()->ldapUserDisplayName, |
| 151 | 151 | $this->access->getConnection()->ldapUserDisplayName2, |
| 152 | 152 | ); |
| 153 | - foreach($possible as $attr) { |
|
| 154 | - if(!is_null($attr)) { |
|
| 153 | + foreach ($possible as $attr) { |
|
| 154 | + if (!is_null($attr)) { |
|
| 155 | 155 | $attributes[] = $attr; |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $homeRule = $this->access->getConnection()->homeFolderNamingRule; |
| 160 | - if(strpos($homeRule, 'attr:') === 0) { |
|
| 160 | + if (strpos($homeRule, 'attr:') === 0) { |
|
| 161 | 161 | $attributes[] = substr($homeRule, strlen('attr:')); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if(!$minimal) { |
|
| 164 | + if (!$minimal) { |
|
| 165 | 165 | // attributes that are not really important but may come with big |
| 166 | 166 | // payload. |
| 167 | 167 | $attributes = array_merge($attributes, array( |
@@ -204,11 +204,11 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | protected function createInstancyByUserName($id) { |
| 206 | 206 | //most likely a uid. Check whether it is a deleted user |
| 207 | - if($this->isDeletedUser($id)) { |
|
| 207 | + if ($this->isDeletedUser($id)) { |
|
| 208 | 208 | return $this->getDeletedUser($id); |
| 209 | 209 | } |
| 210 | 210 | $dn = $this->access->username2dn($id); |
| 211 | - if($dn !== false) { |
|
| 211 | + if ($dn !== false) { |
|
| 212 | 212 | return $this->createAndCache($dn, $id); |
| 213 | 213 | } |
| 214 | 214 | return null; |
@@ -222,15 +222,15 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function get($id) { |
| 224 | 224 | $this->checkAccess(); |
| 225 | - if(isset($this->usersByDN[$id])) { |
|
| 225 | + if (isset($this->usersByDN[$id])) { |
|
| 226 | 226 | return $this->usersByDN[$id]; |
| 227 | - } else if(isset($this->usersByUid[$id])) { |
|
| 227 | + } else if (isset($this->usersByUid[$id])) { |
|
| 228 | 228 | return $this->usersByUid[$id]; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if($this->access->stringResemblesDN($id) ) { |
|
| 231 | + if ($this->access->stringResemblesDN($id)) { |
|
| 232 | 232 | $uid = $this->access->dn2username($id); |
| 233 | - if($uid !== false) { |
|
| 233 | + if ($uid !== false) { |
|
| 234 | 234 | return $this->createAndCache($id, $uid); |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | * reads the user details |
| 180 | 180 | */ |
| 181 | 181 | protected function fetchDetails() { |
| 182 | - $properties = array ( |
|
| 182 | + $properties = array( |
|
| 183 | 183 | 'displayName' => 'user_ldap', |
| 184 | 184 | 'uid' => 'user_ldap', |
| 185 | 185 | 'homePath' => 'user_ldap', |
| 186 | 186 | 'email' => 'settings', |
| 187 | 187 | 'lastLogin' => 'login' |
| 188 | 188 | ); |
| 189 | - foreach($properties as $property => $app) { |
|
| 189 | + foreach ($properties as $property => $app) { |
|
| 190 | 190 | $this->$property = $this->config->getUserValue($this->ocName, $app, $property, ''); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | ', 1); |
| 210 | 210 | $query->execute(array($this->ocName)); |
| 211 | 211 | $sResult = $query->fetchColumn(0); |
| 212 | - if(intval($sResult) === 1) { |
|
| 212 | + if (intval($sResult) === 1) { |
|
| 213 | 213 | $this->hasActiveShares = true; |
| 214 | 214 | return; |
| 215 | 215 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | ', 1); |
| 222 | 222 | $query->execute(array($this->ocName)); |
| 223 | 223 | $sResult = $query->fetchColumn(0); |
| 224 | - if(intval($sResult) === 1) { |
|
| 224 | + if (intval($sResult) === 1) { |
|
| 225 | 225 | $this->hasActiveShares = true; |
| 226 | 226 | return; |
| 227 | 227 | } |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | public function delete($configID) { |
| 148 | 148 | try { |
| 149 | 149 | $this->ensureConfigIDExists($configID); |
| 150 | - if(!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 150 | + if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 151 | 151 | throw new OCSException('Could not delete configuration'); |
| 152 | 152 | } |
| 153 | - } catch(OCSException $e) { |
|
| 153 | + } catch (OCSException $e) { |
|
| 154 | 154 | throw $e; |
| 155 | - } catch(\Exception $e) { |
|
| 155 | + } catch (\Exception $e) { |
|
| 156 | 156 | $this->logger->logException($e); |
| 157 | 157 | throw new OCSException('An issue occurred when deleting the config.'); |
| 158 | 158 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | try { |
| 188 | 188 | $this->ensureConfigIDExists($configID); |
| 189 | 189 | |
| 190 | - if(!is_array($configData)) { |
|
| 190 | + if (!is_array($configData)) { |
|
| 191 | 191 | throw new OCSBadRequestException('configData is not properly set'); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | $configKeys = $configuration->getConfigTranslationArray(); |
| 196 | 196 | |
| 197 | 197 | foreach ($configKeys as $i => $key) { |
| 198 | - if(isset($configData[$key])) { |
|
| 198 | + if (isset($configData[$key])) { |
|
| 199 | 199 | $configuration->$key = $configData[$key]; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $configuration->saveConfiguration(); |
| 204 | - } catch(OCSException $e) { |
|
| 204 | + } catch (OCSException $e) { |
|
| 205 | 205 | throw $e; |
| 206 | 206 | } catch (\Exception $e) { |
| 207 | 207 | $this->logger->logException($e); |
@@ -288,16 +288,16 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | $config = new Configuration($configID); |
| 290 | 290 | $data = $config->getConfiguration(); |
| 291 | - if(!boolval(intval($showPassword))) { |
|
| 291 | + if (!boolval(intval($showPassword))) { |
|
| 292 | 292 | $data['ldapAgentPassword'] = '***'; |
| 293 | 293 | } |
| 294 | 294 | foreach ($data as $key => $value) { |
| 295 | - if(is_array($value)) { |
|
| 295 | + if (is_array($value)) { |
|
| 296 | 296 | $value = implode(';', $value); |
| 297 | 297 | $data[$key] = $value; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | - } catch(OCSException $e) { |
|
| 300 | + } catch (OCSException $e) { |
|
| 301 | 301 | throw $e; |
| 302 | 302 | } catch (\Exception $e) { |
| 303 | 303 | $this->logger->logException($e); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | private function ensureConfigIDExists($configID) { |
| 317 | 317 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
| 318 | - if(!in_array($configID, $prefixes, true)) { |
|
| 318 | + if (!in_array($configID, $prefixes, true)) { |
|
| 319 | 319 | throw new OCSNotFoundException('Config ID not found'); |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | static private $groupBE; |
| 47 | 47 | |
| 48 | - public function __construct(){ |
|
| 48 | + public function __construct() { |
|
| 49 | 49 | $this->interval = self::getRefreshInterval(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @param mixed $argument |
| 54 | 54 | */ |
| 55 | - public function run($argument){ |
|
| 55 | + public function run($argument) { |
|
| 56 | 56 | self::updateGroups(); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $knownGroups = array_keys(self::getKnownGroups()); |
| 63 | 63 | $actualGroups = self::getGroupBE()->getGroups(); |
| 64 | 64 | |
| 65 | - if(empty($actualGroups) && empty($knownGroups)) { |
|
| 65 | + if (empty($actualGroups) && empty($knownGroups)) { |
|
| 66 | 66 | \OCP\Util::writeLog('user_ldap', |
| 67 | 67 | 'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.', |
| 68 | 68 | \OCP\Util::INFO); |
@@ -94,26 +94,26 @@ discard block |
||
| 94 | 94 | SET `owncloudusers` = ? |
| 95 | 95 | WHERE `owncloudname` = ? |
| 96 | 96 | '); |
| 97 | - foreach($groups as $group) { |
|
| 97 | + foreach ($groups as $group) { |
|
| 98 | 98 | //we assume, that self::$groupsFromDB has been retrieved already |
| 99 | 99 | $knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']); |
| 100 | 100 | $actualUsers = self::getGroupBE()->usersInGroup($group); |
| 101 | 101 | $hasChanged = false; |
| 102 | - foreach(array_diff($knownUsers, $actualUsers) as $removedUser) { |
|
| 102 | + foreach (array_diff($knownUsers, $actualUsers) as $removedUser) { |
|
| 103 | 103 | \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group)); |
| 104 | 104 | \OCP\Util::writeLog('user_ldap', |
| 105 | 105 | 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', |
| 106 | 106 | \OCP\Util::INFO); |
| 107 | 107 | $hasChanged = true; |
| 108 | 108 | } |
| 109 | - foreach(array_diff($actualUsers, $knownUsers) as $addedUser) { |
|
| 109 | + foreach (array_diff($actualUsers, $knownUsers) as $addedUser) { |
|
| 110 | 110 | \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group)); |
| 111 | 111 | \OCP\Util::writeLog('user_ldap', |
| 112 | 112 | 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', |
| 113 | 113 | \OCP\Util::INFO); |
| 114 | 114 | $hasChanged = true; |
| 115 | 115 | } |
| 116 | - if($hasChanged) { |
|
| 116 | + if ($hasChanged) { |
|
| 117 | 117 | $query->execute(array(serialize($actualUsers), $group)); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`) |
| 133 | 133 | VALUES (?, ?) |
| 134 | 134 | '); |
| 135 | - foreach($createdGroups as $createdGroup) { |
|
| 135 | + foreach ($createdGroups as $createdGroup) { |
|
| 136 | 136 | \OCP\Util::writeLog('user_ldap', |
| 137 | 137 | 'bgJ "updateGroups" – new group "'.$createdGroup.'" found.', |
| 138 | 138 | \OCP\Util::INFO); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | FROM `*PREFIX*ldap_group_members` |
| 155 | 155 | WHERE `owncloudname` = ? |
| 156 | 156 | '); |
| 157 | - foreach($removedGroups as $removedGroup) { |
|
| 157 | + foreach ($removedGroups as $removedGroup) { |
|
| 158 | 158 | \OCP\Util::writeLog('user_ldap', |
| 159 | 159 | 'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.', |
| 160 | 160 | \OCP\Util::INFO); |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy |
| 170 | 170 | */ |
| 171 | 171 | static private function getGroupBE() { |
| 172 | - if(!is_null(self::$groupBE)) { |
|
| 172 | + if (!is_null(self::$groupBE)) { |
|
| 173 | 173 | return self::$groupBE; |
| 174 | 174 | } |
| 175 | 175 | $helper = new Helper(\OC::$server->getConfig()); |
| 176 | 176 | $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
| 177 | 177 | $ldapWrapper = new LDAP(); |
| 178 | - if(count($configPrefixes) === 1) { |
|
| 178 | + if (count($configPrefixes) === 1) { |
|
| 179 | 179 | //avoid the proxy when there is only one LDAP server configured |
| 180 | 180 | $dbc = \OC::$server->getDatabaseConnection(); |
| 181 | 181 | $userManager = new Manager( |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | static private function getKnownGroups() { |
| 207 | - if(is_array(self::$groupsFromDB)) { |
|
| 207 | + if (is_array(self::$groupsFromDB)) { |
|
| 208 | 208 | return self::$groupsFromDB; |
| 209 | 209 | } |
| 210 | 210 | $query = \OCP\DB::prepare(' |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | '); |
| 214 | 214 | $result = $query->execute()->fetchAll(); |
| 215 | 215 | self::$groupsFromDB = array(); |
| 216 | - foreach($result as $dataset) { |
|
| 216 | + foreach ($result as $dataset) { |
|
| 217 | 217 | self::$groupsFromDB[$dataset['owncloudname']] = $dataset; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -80,41 +80,41 @@ discard block |
||
| 80 | 80 | //pass in app.php we do add here, except something else is passed e.g. |
| 81 | 81 | //in tests. |
| 82 | 82 | |
| 83 | - if(isset($arguments['helper'])) { |
|
| 83 | + if (isset($arguments['helper'])) { |
|
| 84 | 84 | $this->ldapHelper = $arguments['helper']; |
| 85 | 85 | } else { |
| 86 | 86 | $this->ldapHelper = new Helper(\OC::$server->getConfig()); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if(isset($arguments['ocConfig'])) { |
|
| 89 | + if (isset($arguments['ocConfig'])) { |
|
| 90 | 90 | $this->ocConfig = $arguments['ocConfig']; |
| 91 | 91 | } else { |
| 92 | 92 | $this->ocConfig = \OC::$server->getConfig(); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if(isset($arguments['userBackend'])) { |
|
| 95 | + if (isset($arguments['userBackend'])) { |
|
| 96 | 96 | $this->userBackend = $arguments['userBackend']; |
| 97 | 97 | } else { |
| 98 | - $this->userBackend = new User_Proxy( |
|
| 98 | + $this->userBackend = new User_Proxy( |
|
| 99 | 99 | $this->ldapHelper->getServerConfigurationPrefixes(true), |
| 100 | 100 | new LDAP(), |
| 101 | 101 | $this->ocConfig |
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if(isset($arguments['db'])) { |
|
| 105 | + if (isset($arguments['db'])) { |
|
| 106 | 106 | $this->db = $arguments['db']; |
| 107 | 107 | } else { |
| 108 | 108 | $this->db = \OC::$server->getDatabaseConnection(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(isset($arguments['mapping'])) { |
|
| 111 | + if (isset($arguments['mapping'])) { |
|
| 112 | 112 | $this->mapping = $arguments['mapping']; |
| 113 | 113 | } else { |
| 114 | 114 | $this->mapping = new UserMapping($this->db); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(isset($arguments['deletedUsersIndex'])) { |
|
| 117 | + if (isset($arguments['deletedUsersIndex'])) { |
|
| 118 | 118 | $this->dui = $arguments['deletedUsersIndex']; |
| 119 | 119 | } else { |
| 120 | 120 | $this->dui = new DeletedUsersIndex( |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | public function run($argument) { |
| 130 | 130 | $this->setArguments($argument); |
| 131 | 131 | |
| 132 | - if(!$this->isCleanUpAllowed()) { |
|
| 132 | + if (!$this->isCleanUpAllowed()) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | $users = $this->mapping->getList($this->getOffset(), $this->limit); |
| 136 | - if(!is_array($users)) { |
|
| 136 | + if (!is_array($users)) { |
|
| 137 | 137 | //something wrong? Let's start from the beginning next time and |
| 138 | 138 | //abort |
| 139 | 139 | $this->setOffset(true); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public function isCleanUpAllowed() { |
| 161 | 161 | try { |
| 162 | - if($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 162 | + if ($this->ldapHelper->haveDisabledConfigurations()) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | } catch (\Exception $e) { |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @return bool |
| 177 | 177 | */ |
| 178 | 178 | private function isCleanUpEnabled() { |
| 179 | - return (bool)$this->ocConfig->getSystemValue( |
|
| 179 | + return (bool) $this->ocConfig->getSystemValue( |
|
| 180 | 180 | 'ldapUserCleanupInterval', strval($this->defaultIntervalMin)); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | * @param array $users result from getMappedUsers() |
| 186 | 186 | */ |
| 187 | 187 | private function checkUsers(array $users) { |
| 188 | - foreach($users as $user) { |
|
| 188 | + foreach ($users as $user) { |
|
| 189 | 189 | $this->checkUser($user); |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @param string[] $user |
| 196 | 196 | */ |
| 197 | 197 | private function checkUser(array $user) { |
| 198 | - if($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 198 | + if ($this->userBackend->userExistsOnLDAP($user['name'])) { |
|
| 199 | 199 | //still available, all good |
| 200 | 200 | |
| 201 | 201 | return; |
@@ -217,8 +217,7 @@ discard block |
||
| 217 | 217 | * @param bool $reset whether the offset should be set to 0 |
| 218 | 218 | */ |
| 219 | 219 | public function setOffset($reset = false) { |
| 220 | - $newOffset = $reset ? 0 : |
|
| 221 | - $this->getOffset() + $this->limit; |
|
| 220 | + $newOffset = $reset ? 0 : $this->getOffset() + $this->limit; |
|
| 222 | 221 | $this->ocConfig->setAppValue('user_ldap', 'cleanUpJobOffset', $newOffset); |
| 223 | 222 | } |
| 224 | 223 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param array|string $values |
| 53 | 53 | */ |
| 54 | 54 | public function addOptions($key, $values) { |
| 55 | - if(!is_array($values)) { |
|
| 55 | + if (!is_array($values)) { |
|
| 56 | 56 | $values = array($values); |
| 57 | 57 | } |
| 58 | 58 | $this->options[$key] = $values; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | public function getResultArray() { |
| 72 | 72 | $result = array(); |
| 73 | 73 | $result['changes'] = $this->changes; |
| 74 | - if(count($this->options) > 0) { |
|
| 74 | + if (count($this->options) > 0) { |
|
| 75 | 75 | $result['options'] = $this->options; |
| 76 | 76 | } |
| 77 | 77 | return $result; |