@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | return $this->userPluginManager->canChangeAvatar($uid); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if(!$this->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 105 | + if (!$this->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 106 | 106 | return true; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $user = $this->access->userManager->get($uid); |
| 110 | - if(!$user instanceof User) { |
|
| 110 | + if (!$user instanceof User) { |
|
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | 113 | $imageData = $user->getAvatarImage(); |
| 114 | - if($imageData === false) { |
|
| 114 | + if ($imageData === false) { |
|
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | return !$user->updateAvatar(true); |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | public function loginName2UserName($loginName) { |
| 127 | 127 | $cacheKey = 'loginName2UserName-'.$loginName; |
| 128 | 128 | $username = $this->access->connection->getFromCache($cacheKey); |
| 129 | - if(!is_null($username)) { |
|
| 129 | + if (!is_null($username)) { |
|
| 130 | 130 | return $username; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | try { |
| 134 | 134 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
| 135 | 135 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
| 136 | - if($user instanceof OfflineUser) { |
|
| 136 | + if ($user instanceof OfflineUser) { |
|
| 137 | 137 | // this path is not really possible, however get() is documented |
| 138 | 138 | // to return User or OfflineUser so we are very defensive here. |
| 139 | 139 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -169,9 +169,9 @@ discard block |
||
| 169 | 169 | //find out dn of the user name |
| 170 | 170 | $attrs = $this->access->userManager->getAttributes(); |
| 171 | 171 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
| 172 | - if(count($users) < 1) { |
|
| 173 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
| 174 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
| 172 | + if (count($users) < 1) { |
|
| 173 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
| 174 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
| 175 | 175 | } |
| 176 | 176 | return $users[0]; |
| 177 | 177 | } |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | public function checkPassword($uid, $password) { |
| 187 | 187 | try { |
| 188 | 188 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
| 189 | - } catch(NotOnLDAP $e) { |
|
| 190 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 189 | + } catch (NotOnLDAP $e) { |
|
| 190 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
| 191 | 191 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
| 192 | 192 | } |
| 193 | 193 | return false; |
@@ -195,16 +195,16 @@ discard block |
||
| 195 | 195 | $dn = $ldapRecord['dn'][0]; |
| 196 | 196 | $user = $this->access->userManager->get($dn); |
| 197 | 197 | |
| 198 | - if(!$user instanceof User) { |
|
| 198 | + if (!$user instanceof User) { |
|
| 199 | 199 | Util::writeLog('user_ldap', |
| 200 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
| 200 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
| 201 | 201 | '. Maybe the LDAP entry has no set display name attribute?', |
| 202 | 202 | Util::WARN); |
| 203 | 203 | return false; |
| 204 | 204 | } |
| 205 | - if($user->getUsername() !== false) { |
|
| 205 | + if ($user->getUsername() !== false) { |
|
| 206 | 206 | //are the credentials OK? |
| 207 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
| 207 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
| 208 | 208 | return false; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | $user = $this->access->userManager->get($uid); |
| 233 | 233 | |
| 234 | - if(!$user instanceof User) { |
|
| 235 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
| 234 | + if (!$user instanceof User) { |
|
| 235 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
| 236 | 236 | '. Maybe the LDAP entry has no set display name attribute?'); |
| 237 | 237 | } |
| 238 | - if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 238 | + if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) { |
|
| 239 | 239 | $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN; |
| 240 | 240 | $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange; |
| 241 | 241 | if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) { |
@@ -267,18 +267,18 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | //check if users are cached, if so return |
| 269 | 269 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
| 270 | - if(!is_null($ldap_users)) { |
|
| 270 | + if (!is_null($ldap_users)) { |
|
| 271 | 271 | return $ldap_users; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
| 275 | 275 | // error. With a limit of 0, we get 0 results. So we pass null. |
| 276 | - if($limit <= 0) { |
|
| 276 | + if ($limit <= 0) { |
|
| 277 | 277 | $limit = null; |
| 278 | 278 | } |
| 279 | 279 | $filter = $this->access->combineFilterWithAnd(array( |
| 280 | 280 | $this->access->connection->ldapUserFilter, |
| 281 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
| 281 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
| 282 | 282 | $this->access->getFilterPartForUserSearch($search) |
| 283 | 283 | )); |
| 284 | 284 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $this->access->userManager->getAttributes(true), |
| 292 | 292 | $limit, $offset); |
| 293 | 293 | $ldap_users = $this->access->nextcloudUserNames($ldap_users); |
| 294 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
| 294 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
| 295 | 295 | |
| 296 | 296 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
| 297 | 297 | return $ldap_users; |
@@ -307,19 +307,19 @@ discard block |
||
| 307 | 307 | * @throws \OC\ServerNotAvailableException |
| 308 | 308 | */ |
| 309 | 309 | public function userExistsOnLDAP($user) { |
| 310 | - if(is_string($user)) { |
|
| 310 | + if (is_string($user)) { |
|
| 311 | 311 | $user = $this->access->userManager->get($user); |
| 312 | 312 | } |
| 313 | - if(is_null($user)) { |
|
| 313 | + if (is_null($user)) { |
|
| 314 | 314 | return false; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $dn = $user->getDN(); |
| 318 | 318 | //check if user really still exists by reading its entry |
| 319 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 319 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
| 320 | 320 | $lcr = $this->access->connection->getConnectionResource(); |
| 321 | - if(is_null($lcr)) { |
|
| 322 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
| 321 | + if (is_null($lcr)) { |
|
| 322 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | try { |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if($user instanceof OfflineUser) { |
|
| 344 | + if ($user instanceof OfflineUser) { |
|
| 345 | 345 | $user->unmark(); |
| 346 | 346 | } |
| 347 | 347 | |
@@ -356,18 +356,18 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | public function userExists($uid) { |
| 358 | 358 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
| 359 | - if(!is_null($userExists)) { |
|
| 360 | - return (bool)$userExists; |
|
| 359 | + if (!is_null($userExists)) { |
|
| 360 | + return (bool) $userExists; |
|
| 361 | 361 | } |
| 362 | 362 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
| 363 | 363 | $user = $this->access->userManager->get($uid); |
| 364 | 364 | |
| 365 | - if(is_null($user)) { |
|
| 365 | + if (is_null($user)) { |
|
| 366 | 366 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
| 367 | 367 | $this->access->connection->ldapHost, Util::DEBUG); |
| 368 | 368 | $this->access->connection->writeToCache('userExists'.$uid, false); |
| 369 | 369 | return false; |
| 370 | - } else if($user instanceof OfflineUser) { |
|
| 370 | + } else if ($user instanceof OfflineUser) { |
|
| 371 | 371 | //express check for users marked as deleted. Returning true is |
| 372 | 372 | //necessary for cleanup |
| 373 | 373 | return true; |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | $result = $this->userExistsOnLDAP($user); |
| 377 | 377 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
| 378 | - if($result === true) { |
|
| 378 | + if ($result === true) { |
|
| 379 | 379 | $user->update(); |
| 380 | 380 | } |
| 381 | 381 | return $result; |
@@ -393,13 +393,13 @@ discard block |
||
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
| 396 | - if(intval($marked) === 0) { |
|
| 396 | + if (intval($marked) === 0) { |
|
| 397 | 397 | \OC::$server->getLogger()->notice( |
| 398 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
| 398 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
| 399 | 399 | array('app' => 'user_ldap')); |
| 400 | 400 | return false; |
| 401 | 401 | } |
| 402 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
| 402 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
| 403 | 403 | array('app' => 'user_ldap')); |
| 404 | 404 | |
| 405 | 405 | $this->access->getUserMapper()->unmap($uid); |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | public function getHome($uid) { |
| 419 | 419 | // user Exists check required as it is not done in user proxy! |
| 420 | - if(!$this->userExists($uid)) { |
|
| 420 | + if (!$this->userExists($uid)) { |
|
| 421 | 421 | return false; |
| 422 | 422 | } |
| 423 | 423 | |
@@ -427,22 +427,22 @@ discard block |
||
| 427 | 427 | |
| 428 | 428 | $cacheKey = 'getHome'.$uid; |
| 429 | 429 | $path = $this->access->connection->getFromCache($cacheKey); |
| 430 | - if(!is_null($path)) { |
|
| 430 | + if (!is_null($path)) { |
|
| 431 | 431 | return $path; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // early return path if it is a deleted user |
| 435 | 435 | $user = $this->access->userManager->get($uid); |
| 436 | - if($user instanceof OfflineUser) { |
|
| 437 | - if($this->currentUserInDeletionProcess !== null |
|
| 436 | + if ($user instanceof OfflineUser) { |
|
| 437 | + if ($this->currentUserInDeletionProcess !== null |
|
| 438 | 438 | && $this->currentUserInDeletionProcess === $user->getOCName() |
| 439 | 439 | ) { |
| 440 | 440 | return $user->getHomePath(); |
| 441 | 441 | } else { |
| 442 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 442 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 443 | 443 | } |
| 444 | 444 | } else if ($user === null) { |
| 445 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
| 445 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | $path = $user->getHomePath(); |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | return $this->userPluginManager->getDisplayName($uid); |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if(!$this->userExists($uid)) { |
|
| 464 | + if (!$this->userExists($uid)) { |
|
| 465 | 465 | return false; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | $cacheKey = 'getDisplayName'.$uid; |
| 469 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 469 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
| 470 | 470 | return $displayName; |
| 471 | 471 | } |
| 472 | 472 | |
@@ -483,10 +483,10 @@ discard block |
||
| 483 | 483 | $this->access->username2dn($uid), |
| 484 | 484 | $this->access->connection->ldapUserDisplayName); |
| 485 | 485 | |
| 486 | - if($displayName && (count($displayName) > 0)) { |
|
| 486 | + if ($displayName && (count($displayName) > 0)) { |
|
| 487 | 487 | $displayName = $displayName[0]; |
| 488 | 488 | |
| 489 | - if (is_array($displayName2)){ |
|
| 489 | + if (is_array($displayName2)) { |
|
| 490 | 490 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
| 491 | 491 | } |
| 492 | 492 | |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
| 530 | 530 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
| 531 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 531 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
| 532 | 532 | return $displayNames; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -550,12 +550,12 @@ discard block |
||
| 550 | 550 | * compared with \OC\User\Backend::CREATE_USER etc. |
| 551 | 551 | */ |
| 552 | 552 | public function implementsActions($actions) { |
| 553 | - return (bool)((Backend::CHECK_PASSWORD |
|
| 553 | + return (bool) ((Backend::CHECK_PASSWORD |
|
| 554 | 554 | | Backend::GET_HOME |
| 555 | 555 | | Backend::GET_DISPLAYNAME |
| 556 | 556 | | (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0) |
| 557 | 557 | | Backend::COUNT_USERS |
| 558 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0) |
|
| 558 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0) |
|
| 559 | 559 | | $this->userPluginManager->getImplementedActions()) |
| 560 | 560 | & $actions); |
| 561 | 561 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | |
| 580 | 580 | $filter = $this->access->getFilterForUserCount(); |
| 581 | 581 | $cacheKey = 'countUsers-'.$filter; |
| 582 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 582 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
| 583 | 583 | return $entries; |
| 584 | 584 | } |
| 585 | 585 | $entries = $this->access->countUsers($filter); |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | * Backend name to be shown in user management |
| 592 | 592 | * @return string the name of the backend to be shown |
| 593 | 593 | */ |
| 594 | - public function getBackendName(){ |
|
| 594 | + public function getBackendName() { |
|
| 595 | 595 | return 'LDAP'; |
| 596 | 596 | } |
| 597 | 597 | |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * @return null |
| 154 | 154 | */ |
| 155 | 155 | public function update() { |
| 156 | - if(is_null($this->dn)) { |
|
| 156 | + if (is_null($this->dn)) { |
|
| 157 | 157 | return null; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $hasLoggedIn = $this->config->getUserValue($this->uid, 'user_ldap', |
| 161 | 161 | self::USER_PREFKEY_FIRSTLOGIN, 0); |
| 162 | 162 | |
| 163 | - if($this->needsRefresh()) { |
|
| 163 | + if ($this->needsRefresh()) { |
|
| 164 | 164 | $this->updateEmail(); |
| 165 | 165 | $this->updateQuota(); |
| 166 | - if($hasLoggedIn !== 0) { |
|
| 166 | + if ($hasLoggedIn !== 0) { |
|
| 167 | 167 | //we do not need to try it, when the user has not been logged in |
| 168 | 168 | //before, because the file system will not be ready. |
| 169 | 169 | $this->updateAvatar(); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $this->markRefreshTime(); |
| 183 | 183 | //Quota |
| 184 | 184 | $attr = strtolower($this->connection->ldapQuotaAttribute); |
| 185 | - if(isset($ldapEntry[$attr])) { |
|
| 185 | + if (isset($ldapEntry[$attr])) { |
|
| 186 | 186 | $this->updateQuota($ldapEntry[$attr][0]); |
| 187 | 187 | } else { |
| 188 | 188 | if ($this->connection->ldapQuotaDefault !== '') { |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | //displayName |
| 195 | 195 | $displayName = $displayName2 = ''; |
| 196 | 196 | $attr = strtolower($this->connection->ldapUserDisplayName); |
| 197 | - if(isset($ldapEntry[$attr])) { |
|
| 197 | + if (isset($ldapEntry[$attr])) { |
|
| 198 | 198 | $displayName = strval($ldapEntry[$attr][0]); |
| 199 | 199 | } |
| 200 | 200 | $attr = strtolower($this->connection->ldapUserDisplayName2); |
| 201 | - if(isset($ldapEntry[$attr])) { |
|
| 201 | + if (isset($ldapEntry[$attr])) { |
|
| 202 | 202 | $displayName2 = strval($ldapEntry[$attr][0]); |
| 203 | 203 | } |
| 204 | 204 | if ($displayName !== '') { |
@@ -215,22 +215,22 @@ discard block |
||
| 215 | 215 | //email must be stored after displayname, because it would cause a user |
| 216 | 216 | //change event that will trigger fetching the display name again |
| 217 | 217 | $attr = strtolower($this->connection->ldapEmailAttribute); |
| 218 | - if(isset($ldapEntry[$attr])) { |
|
| 218 | + if (isset($ldapEntry[$attr])) { |
|
| 219 | 219 | $this->updateEmail($ldapEntry[$attr][0]); |
| 220 | 220 | } |
| 221 | 221 | unset($attr); |
| 222 | 222 | |
| 223 | 223 | // LDAP Username, needed for s2s sharing |
| 224 | - if(isset($ldapEntry['uid'])) { |
|
| 224 | + if (isset($ldapEntry['uid'])) { |
|
| 225 | 225 | $this->storeLDAPUserName($ldapEntry['uid'][0]); |
| 226 | - } else if(isset($ldapEntry['samaccountname'])) { |
|
| 226 | + } else if (isset($ldapEntry['samaccountname'])) { |
|
| 227 | 227 | $this->storeLDAPUserName($ldapEntry['samaccountname'][0]); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | //homePath |
| 231 | - if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
| 231 | + if (strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { |
|
| 232 | 232 | $attr = strtolower(substr($this->connection->homeFolderNamingRule, strlen('attr:'))); |
| 233 | - if(isset($ldapEntry[$attr])) { |
|
| 233 | + if (isset($ldapEntry[$attr])) { |
|
| 234 | 234 | $this->access->cacheUserHome( |
| 235 | 235 | $this->getUsername(), $this->getHomePath($ldapEntry[$attr][0])); |
| 236 | 236 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | //memberOf groups |
| 240 | 240 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
| 241 | 241 | $groups = false; |
| 242 | - if(isset($ldapEntry['memberof'])) { |
|
| 242 | + if (isset($ldapEntry['memberof'])) { |
|
| 243 | 243 | $groups = $ldapEntry['memberof']; |
| 244 | 244 | } |
| 245 | 245 | $this->connection->writeToCache($cacheKey, $groups); |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | /** @var Connection $connection */ |
| 249 | 249 | $connection = $this->access->getConnection(); |
| 250 | 250 | $attributes = $connection->resolveRule('avatar'); |
| 251 | - foreach ($attributes as $attribute) { |
|
| 252 | - if(isset($ldapEntry[$attribute])) { |
|
| 251 | + foreach ($attributes as $attribute) { |
|
| 252 | + if (isset($ldapEntry[$attribute])) { |
|
| 253 | 253 | $this->avatarImage = $ldapEntry[$attribute][0]; |
| 254 | 254 | // the call to the method that saves the avatar in the file |
| 255 | 255 | // system must be postponed after the login. It is to ensure |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | if ($path !== '') { |
| 303 | 303 | //if attribute's value is an absolute path take this, otherwise append it to data dir |
| 304 | 304 | //check for / at the beginning or pattern c:\ resp. c:/ |
| 305 | - if( '/' !== $path[0] |
|
| 305 | + if ('/' !== $path[0] |
|
| 306 | 306 | && !(3 < strlen($path) && ctype_alpha($path[0]) |
| 307 | 307 | && $path[1] === ':' && ('\\' === $path[2] || '/' === $path[2])) |
| 308 | 308 | ) { |
| 309 | 309 | $path = $this->config->getSystemValue('datadirectory', |
| 310 | - \OC::$SERVERROOT.'/data' ) . '/' . $path; |
|
| 310 | + \OC::$SERVERROOT.'/data').'/'.$path; |
|
| 311 | 311 | } |
| 312 | 312 | //we need it to store it in the DB as well in case a user gets |
| 313 | 313 | //deleted so we can clean up afterwards |
@@ -317,11 +317,11 @@ discard block |
||
| 317 | 317 | return $path; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if( !is_null($attr) |
|
| 320 | + if (!is_null($attr) |
|
| 321 | 321 | && $this->config->getAppValue('user_ldap', 'enforce_home_folder_naming_rule', true) |
| 322 | 322 | ) { |
| 323 | 323 | // a naming rule attribute is defined, but it doesn't exist for that LDAP user |
| 324 | - throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: ' . $this->getUsername()); |
|
| 324 | + throw new \Exception('Home dir attribute can\'t be read from LDAP for uid: '.$this->getUsername()); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | //false will apply default behaviour as defined and done by OC_User |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | public function getMemberOfGroups() { |
| 333 | 333 | $cacheKey = 'getMemberOf'.$this->getUsername(); |
| 334 | 334 | $memberOfGroups = $this->connection->getFromCache($cacheKey); |
| 335 | - if(!is_null($memberOfGroups)) { |
|
| 335 | + if (!is_null($memberOfGroups)) { |
|
| 336 | 336 | return $memberOfGroups; |
| 337 | 337 | } |
| 338 | 338 | $groupDNs = $this->access->readAttribute($this->getDN(), 'memberOf'); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @return string data (provided by LDAP) | false |
| 346 | 346 | */ |
| 347 | 347 | public function getAvatarImage() { |
| 348 | - if(!is_null($this->avatarImage)) { |
|
| 348 | + if (!is_null($this->avatarImage)) { |
|
| 349 | 349 | return $this->avatarImage; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -353,9 +353,9 @@ discard block |
||
| 353 | 353 | /** @var Connection $connection */ |
| 354 | 354 | $connection = $this->access->getConnection(); |
| 355 | 355 | $attributes = $connection->resolveRule('avatar'); |
| 356 | - foreach($attributes as $attribute) { |
|
| 356 | + foreach ($attributes as $attribute) { |
|
| 357 | 357 | $result = $this->access->readAttribute($this->dn, $attribute); |
| 358 | - if($result !== false && is_array($result) && isset($result[0])) { |
|
| 358 | + if ($result !== false && is_array($result) && isset($result[0])) { |
|
| 359 | 359 | $this->avatarImage = $result[0]; |
| 360 | 360 | break; |
| 361 | 361 | } |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | $lastChecked = $this->config->getUserValue($this->uid, 'user_ldap', |
| 393 | 393 | self::USER_PREFKEY_LASTREFRESH, 0); |
| 394 | 394 | |
| 395 | - if((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400)) ) { |
|
| 395 | + if ((time() - intval($lastChecked)) < intval($this->config->getAppValue('user_ldap', 'updateAttributesInterval', 86400))) { |
|
| 396 | 396 | return false; |
| 397 | 397 | } |
| 398 | 398 | return true; |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function composeAndStoreDisplayName($displayName, $displayName2 = '') { |
| 420 | 420 | $displayName2 = strval($displayName2); |
| 421 | - if($displayName2 !== '') { |
|
| 422 | - $displayName .= ' (' . $displayName2 . ')'; |
|
| 421 | + if ($displayName2 !== '') { |
|
| 422 | + $displayName .= ' ('.$displayName2.')'; |
|
| 423 | 423 | } |
| 424 | 424 | $this->store('displayName', $displayName); |
| 425 | 425 | return $displayName; |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | * @return bool |
| 442 | 442 | */ |
| 443 | 443 | private function wasRefreshed($feature) { |
| 444 | - if(isset($this->refreshedFeatures[$feature])) { |
|
| 444 | + if (isset($this->refreshedFeatures[$feature])) { |
|
| 445 | 445 | return true; |
| 446 | 446 | } |
| 447 | 447 | $this->refreshedFeatures[$feature] = 1; |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | * @return null |
| 455 | 455 | */ |
| 456 | 456 | public function updateEmail($valueFromLDAP = null) { |
| 457 | - if($this->wasRefreshed('email')) { |
|
| 457 | + if ($this->wasRefreshed('email')) { |
|
| 458 | 458 | return; |
| 459 | 459 | } |
| 460 | 460 | $email = strval($valueFromLDAP); |
| 461 | - if(is_null($valueFromLDAP)) { |
|
| 461 | + if (is_null($valueFromLDAP)) { |
|
| 462 | 462 | $emailAttribute = $this->connection->ldapEmailAttribute; |
| 463 | 463 | if ($emailAttribute !== '') { |
| 464 | 464 | $aEmail = $this->access->readAttribute($this->dn, $emailAttribute); |
| 465 | - if(is_array($aEmail) && (count($aEmail) > 0)) { |
|
| 465 | + if (is_array($aEmail) && (count($aEmail) > 0)) { |
|
| 466 | 466 | $email = strval($aEmail[0]); |
| 467 | 467 | } |
| 468 | 468 | } |
@@ -499,35 +499,35 @@ discard block |
||
| 499 | 499 | * @return null |
| 500 | 500 | */ |
| 501 | 501 | public function updateQuota($valueFromLDAP = null) { |
| 502 | - if($this->wasRefreshed('quota')) { |
|
| 502 | + if ($this->wasRefreshed('quota')) { |
|
| 503 | 503 | return; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | $quotaAttribute = $this->connection->ldapQuotaAttribute; |
| 507 | 507 | $defaultQuota = $this->connection->ldapQuotaDefault; |
| 508 | - if($quotaAttribute === '' && $defaultQuota === '') { |
|
| 508 | + if ($quotaAttribute === '' && $defaultQuota === '') { |
|
| 509 | 509 | return; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | $quota = false; |
| 513 | - if(is_null($valueFromLDAP) && $quotaAttribute !== '') { |
|
| 513 | + if (is_null($valueFromLDAP) && $quotaAttribute !== '') { |
|
| 514 | 514 | $aQuota = $this->access->readAttribute($this->dn, $quotaAttribute); |
| 515 | - if($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { |
|
| 515 | + if ($aQuota && (count($aQuota) > 0) && $this->verifyQuotaValue($aQuota[0])) { |
|
| 516 | 516 | $quota = $aQuota[0]; |
| 517 | - } else if(is_array($aQuota) && isset($aQuota[0])) { |
|
| 518 | - $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', Util::DEBUG); |
|
| 517 | + } else if (is_array($aQuota) && isset($aQuota[0])) { |
|
| 518 | + $this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$aQuota[0].']', Util::DEBUG); |
|
| 519 | 519 | } |
| 520 | 520 | } else if ($this->verifyQuotaValue($valueFromLDAP)) { |
| 521 | 521 | $quota = $valueFromLDAP; |
| 522 | 522 | } else { |
| 523 | - $this->log->log('no suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', Util::DEBUG); |
|
| 523 | + $this->log->log('no suitable LDAP quota found for user '.$this->uid.': ['.$valueFromLDAP.']', Util::DEBUG); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | if ($quota === false && $this->verifyQuotaValue($defaultQuota)) { |
| 527 | 527 | // quota not found using the LDAP attribute (or not parseable). Try the default quota |
| 528 | 528 | $quota = $defaultQuota; |
| 529 | - } else if($quota === false) { |
|
| 530 | - $this->log->log('no suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', Util::DEBUG); |
|
| 529 | + } else if ($quota === false) { |
|
| 530 | + $this->log->log('no suitable default quota found for user '.$this->uid.': ['.$defaultQuota.']', Util::DEBUG); |
|
| 531 | 531 | return; |
| 532 | 532 | } |
| 533 | 533 | |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | if ($targetUser instanceof IUser) { |
| 536 | 536 | $targetUser->setQuota($quota); |
| 537 | 537 | } else { |
| 538 | - $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', Util::INFO); |
|
| 538 | + $this->log->log('trying to set a quota for user '.$this->uid.' but the user is missing', Util::INFO); |
|
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @param array $params |
| 550 | 550 | */ |
| 551 | 551 | public function updateAvatarPostLogin($params) { |
| 552 | - if(isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
| 552 | + if (isset($params['uid']) && $params['uid'] === $this->getUsername()) { |
|
| 553 | 553 | $this->updateAvatar(); |
| 554 | 554 | } |
| 555 | 555 | } |
@@ -559,15 +559,15 @@ discard block |
||
| 559 | 559 | * @return bool |
| 560 | 560 | */ |
| 561 | 561 | public function updateAvatar($force = false) { |
| 562 | - if(!$force && $this->wasRefreshed('avatar')) { |
|
| 562 | + if (!$force && $this->wasRefreshed('avatar')) { |
|
| 563 | 563 | return false; |
| 564 | 564 | } |
| 565 | 565 | $avatarImage = $this->getAvatarImage(); |
| 566 | - if($avatarImage === false) { |
|
| 566 | + if ($avatarImage === false) { |
|
| 567 | 567 | //not set, nothing left to do; |
| 568 | 568 | return false; |
| 569 | 569 | } |
| 570 | - if(!$this->image->loadFromBase64(base64_encode($avatarImage))) { |
|
| 570 | + if (!$this->image->loadFromBase64(base64_encode($avatarImage))) { |
|
| 571 | 571 | return false; |
| 572 | 572 | } |
| 573 | 573 | return $this->setOwnCloudAvatar(); |
@@ -578,18 +578,18 @@ discard block |
||
| 578 | 578 | * @return bool |
| 579 | 579 | */ |
| 580 | 580 | private function setOwnCloudAvatar() { |
| 581 | - if(!$this->image->valid()) { |
|
| 581 | + if (!$this->image->valid()) { |
|
| 582 | 582 | $this->log->log('avatar image data from LDAP invalid for '.$this->dn, Util::ERROR); |
| 583 | 583 | return false; |
| 584 | 584 | } |
| 585 | 585 | //make sure it is a square and not bigger than 128x128 |
| 586 | 586 | $size = min(array($this->image->width(), $this->image->height(), 128)); |
| 587 | - if(!$this->image->centerCrop($size)) { |
|
| 587 | + if (!$this->image->centerCrop($size)) { |
|
| 588 | 588 | $this->log->log('croping image for avatar failed for '.$this->dn, Util::ERROR); |
| 589 | 589 | return false; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - if(!$this->fs->isLoaded()) { |
|
| 592 | + if (!$this->fs->isLoaded()) { |
|
| 593 | 593 | $this->fs->setup($this->uid); |
| 594 | 594 | } |
| 595 | 595 | |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | return true; |
| 600 | 600 | } catch (\Exception $e) { |
| 601 | 601 | \OC::$server->getLogger()->notice( |
| 602 | - 'Could not set avatar for ' . $this->dn . ', because: ' . $e->getMessage(), |
|
| 602 | + 'Could not set avatar for '.$this->dn.', because: '.$e->getMessage(), |
|
| 603 | 603 | ['app' => 'user_ldap']); |
| 604 | 604 | } |
| 605 | 605 | return false; |
@@ -613,17 +613,17 @@ discard block |
||
| 613 | 613 | public function handlePasswordExpiry($params) { |
| 614 | 614 | $ppolicyDN = $this->connection->ldapDefaultPPolicyDN; |
| 615 | 615 | if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) { |
| 616 | - return;//password expiry handling disabled |
|
| 616 | + return; //password expiry handling disabled |
|
| 617 | 617 | } |
| 618 | 618 | $uid = $params['uid']; |
| 619 | - if(isset($uid) && $uid === $this->getUsername()) { |
|
| 619 | + if (isset($uid) && $uid === $this->getUsername()) { |
|
| 620 | 620 | //retrieve relevant user attributes |
| 621 | 621 | $result = $this->access->search('objectclass=*', array($this->dn), ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']); |
| 622 | 622 | |
| 623 | - if(array_key_exists('pwdpolicysubentry', $result[0])) { |
|
| 623 | + if (array_key_exists('pwdpolicysubentry', $result[0])) { |
|
| 624 | 624 | $pwdPolicySubentry = $result[0]['pwdpolicysubentry']; |
| 625 | - if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){ |
|
| 626 | - $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN |
|
| 625 | + if ($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)) { |
|
| 626 | + $ppolicyDN = $pwdPolicySubentry[0]; //custom ppolicy DN |
|
| 627 | 627 | } |
| 628 | 628 | } |
| 629 | 629 | |
@@ -632,9 +632,9 @@ discard block |
||
| 632 | 632 | $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null; |
| 633 | 633 | |
| 634 | 634 | //retrieve relevant password policy attributes |
| 635 | - $cacheKey = 'ppolicyAttributes' . $ppolicyDN; |
|
| 635 | + $cacheKey = 'ppolicyAttributes'.$ppolicyDN; |
|
| 636 | 636 | $result = $this->connection->getFromCache($cacheKey); |
| 637 | - if(is_null($result)) { |
|
| 637 | + if (is_null($result)) { |
|
| 638 | 638 | $result = $this->access->search('objectclass=*', array($ppolicyDN), ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']); |
| 639 | 639 | $this->connection->writeToCache($cacheKey, $result); |
| 640 | 640 | } |
@@ -645,8 +645,8 @@ discard block |
||
| 645 | 645 | |
| 646 | 646 | //handle grace login |
| 647 | 647 | $pwdGraceUseTimeCount = count($pwdGraceUseTime); |
| 648 | - if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? |
|
| 649 | - if($pwdGraceAuthNLimit |
|
| 648 | + if ($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login? |
|
| 649 | + if ($pwdGraceAuthNLimit |
|
| 650 | 650 | && (count($pwdGraceAuthNLimit) > 0) |
| 651 | 651 | &&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available? |
| 652 | 652 | $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); |
@@ -659,24 +659,24 @@ discard block |
||
| 659 | 659 | exit(); |
| 660 | 660 | } |
| 661 | 661 | //handle pwdReset attribute |
| 662 | - if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password |
|
| 662 | + if ($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password |
|
| 663 | 663 | $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true'); |
| 664 | 664 | header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute( |
| 665 | 665 | 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid))); |
| 666 | 666 | exit(); |
| 667 | 667 | } |
| 668 | 668 | //handle password expiry warning |
| 669 | - if($pwdChangedTime && (count($pwdChangedTime) > 0)) { |
|
| 670 | - if($pwdMaxAge && (count($pwdMaxAge) > 0) |
|
| 669 | + if ($pwdChangedTime && (count($pwdChangedTime) > 0)) { |
|
| 670 | + if ($pwdMaxAge && (count($pwdMaxAge) > 0) |
|
| 671 | 671 | && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) { |
| 672 | 672 | $pwdMaxAgeInt = intval($pwdMaxAge[0]); |
| 673 | 673 | $pwdExpireWarningInt = intval($pwdExpireWarning[0]); |
| 674 | - if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){ |
|
| 674 | + if ($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0) { |
|
| 675 | 675 | $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]); |
| 676 | 676 | $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S')); |
| 677 | 677 | $currentDateTime = new \DateTime(); |
| 678 | 678 | $secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp(); |
| 679 | - if($secondsToExpiry <= $pwdExpireWarningInt) { |
|
| 679 | + if ($secondsToExpiry <= $pwdExpireWarningInt) { |
|
| 680 | 680 | //remove last password expiry warning if any |
| 681 | 681 | $notification = $this->notificationManager->createNotification(); |
| 682 | 682 | $notification->setApp('user_ldap') |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param $uid |
| 142 | 142 | */ |
| 143 | 143 | public function invalidate($uid) { |
| 144 | - if(!isset($this->usersByUid[$uid])) { |
|
| 144 | + if (!isset($this->usersByUid[$uid])) { |
|
| 145 | 145 | return; |
| 146 | 146 | } |
| 147 | 147 | $dn = $this->usersByUid[$uid]->getDN(); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * @return null |
| 156 | 156 | */ |
| 157 | 157 | private function checkAccess() { |
| 158 | - if(is_null($this->access)) { |
|
| 158 | + if (is_null($this->access)) { |
|
| 159 | 159 | throw new \Exception('LDAP Access instance must be set first'); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | $this->access->getConnection()->ldapUserDisplayName, |
| 178 | 178 | $this->access->getConnection()->ldapUserDisplayName2, |
| 179 | 179 | ); |
| 180 | - foreach($possible as $attr) { |
|
| 181 | - if(!is_null($attr)) { |
|
| 180 | + foreach ($possible as $attr) { |
|
| 181 | + if (!is_null($attr)) { |
|
| 182 | 182 | $attributes[] = $attr; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | $homeRule = $this->access->getConnection()->homeFolderNamingRule; |
| 187 | - if(strpos($homeRule, 'attr:') === 0) { |
|
| 187 | + if (strpos($homeRule, 'attr:') === 0) { |
|
| 188 | 188 | $attributes[] = substr($homeRule, strlen('attr:')); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if(!$minimal) { |
|
| 191 | + if (!$minimal) { |
|
| 192 | 192 | // attributes that are not really important but may come with big |
| 193 | 193 | // payload. |
| 194 | 194 | $attributes = array_merge( |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | protected function createInstancyByUserName($id) { |
| 233 | 233 | //most likely a uid. Check whether it is a deleted user |
| 234 | - if($this->isDeletedUser($id)) { |
|
| 234 | + if ($this->isDeletedUser($id)) { |
|
| 235 | 235 | return $this->getDeletedUser($id); |
| 236 | 236 | } |
| 237 | 237 | $dn = $this->access->username2dn($id); |
| 238 | - if($dn !== false) { |
|
| 238 | + if ($dn !== false) { |
|
| 239 | 239 | return $this->createAndCache($dn, $id); |
| 240 | 240 | } |
| 241 | 241 | return null; |
@@ -249,15 +249,15 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public function get($id) { |
| 251 | 251 | $this->checkAccess(); |
| 252 | - if(isset($this->usersByDN[$id])) { |
|
| 252 | + if (isset($this->usersByDN[$id])) { |
|
| 253 | 253 | return $this->usersByDN[$id]; |
| 254 | - } else if(isset($this->usersByUid[$id])) { |
|
| 254 | + } else if (isset($this->usersByUid[$id])) { |
|
| 255 | 255 | return $this->usersByUid[$id]; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($this->access->stringResemblesDN($id) ) { |
|
| 258 | + if ($this->access->stringResemblesDN($id)) { |
|
| 259 | 259 | $uid = $this->access->dn2username($id); |
| 260 | - if($uid !== false) { |
|
| 260 | + if ($uid !== false) { |
|
| 261 | 261 | return $this->createAndCache($id, $uid); |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function __construct($configPrefix, $autoRead = true) { |
| 117 | 117 | $this->configPrefix = $configPrefix; |
| 118 | - if($autoRead) { |
|
| 118 | + if ($autoRead) { |
|
| 119 | 119 | $this->readConfiguration(); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return mixed|null |
| 126 | 126 | */ |
| 127 | 127 | public function __get($name) { |
| 128 | - if(isset($this->config[$name])) { |
|
| 128 | + if (isset($this->config[$name])) { |
|
| 129 | 129 | return $this->config[$name]; |
| 130 | 130 | } |
| 131 | 131 | return null; |
@@ -156,22 +156,22 @@ discard block |
||
| 156 | 156 | * @return false|null |
| 157 | 157 | */ |
| 158 | 158 | public function setConfiguration($config, &$applied = null) { |
| 159 | - if(!is_array($config)) { |
|
| 159 | + if (!is_array($config)) { |
|
| 160 | 160 | return false; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $cta = $this->getConfigTranslationArray(); |
| 164 | - foreach($config as $inputKey => $val) { |
|
| 165 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 164 | + foreach ($config as $inputKey => $val) { |
|
| 165 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
| 166 | 166 | $key = $cta[$inputKey]; |
| 167 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
| 167 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
| 168 | 168 | $key = $inputKey; |
| 169 | 169 | } else { |
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $setMethod = 'setValue'; |
| 174 | - switch($key) { |
|
| 174 | + switch ($key) { |
|
| 175 | 175 | case 'ldapAgentPassword': |
| 176 | 176 | $setMethod = 'setRawValue'; |
| 177 | 177 | break; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | break; |
| 196 | 196 | } |
| 197 | 197 | $this->$setMethod($key, $val); |
| 198 | - if(is_array($applied)) { |
|
| 198 | + if (is_array($applied)) { |
|
| 199 | 199 | $applied[] = $inputKey; |
| 200 | 200 | // storing key as index avoids duplication, and as value for simplicity |
| 201 | 201 | } |
@@ -205,15 +205,15 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | public function readConfiguration() { |
| 208 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
| 208 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
| 209 | 209 | $cta = array_flip($this->getConfigTranslationArray()); |
| 210 | - foreach($this->config as $key => $val) { |
|
| 211 | - if(!isset($cta[$key])) { |
|
| 210 | + foreach ($this->config as $key => $val) { |
|
| 211 | + if (!isset($cta[$key])) { |
|
| 212 | 212 | //some are determined |
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | $dbKey = $cta[$key]; |
| 216 | - switch($key) { |
|
| 216 | + switch ($key) { |
|
| 217 | 217 | case 'ldapBase': |
| 218 | 218 | case 'ldapBaseUsers': |
| 219 | 219 | case 'ldapBaseGroups': |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function saveConfiguration() { |
| 258 | 258 | $cta = array_flip($this->getConfigTranslationArray()); |
| 259 | - foreach($this->unsavedChanges as $key) { |
|
| 259 | + foreach ($this->unsavedChanges as $key) { |
|
| 260 | 260 | $value = $this->config[$key]; |
| 261 | 261 | switch ($key) { |
| 262 | 262 | case 'ldapAgentPassword': |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | case 'ldapGroupFilterObjectclass': |
| 273 | 273 | case 'ldapGroupFilterGroups': |
| 274 | 274 | case 'ldapLoginFilterAttributes': |
| 275 | - if(is_array($value)) { |
|
| 275 | + if (is_array($value)) { |
|
| 276 | 276 | $value = implode("\n", $value); |
| 277 | 277 | } |
| 278 | 278 | break; |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | case 'ldapUuidGroupAttribute': |
| 284 | 284 | continue 2; |
| 285 | 285 | } |
| 286 | - if(is_null($value)) { |
|
| 286 | + if (is_null($value)) { |
|
| 287 | 287 | $value = ''; |
| 288 | 288 | } |
| 289 | 289 | $this->saveValue($cta[$key], $value); |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | protected function getMultiLine($varName) { |
| 300 | 300 | $value = $this->getValue($varName); |
| 301 | - if(empty($value)) { |
|
| 301 | + if (empty($value)) { |
|
| 302 | 302 | $value = ''; |
| 303 | 303 | } else { |
| 304 | 304 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -314,21 +314,21 @@ discard block |
||
| 314 | 314 | * @param array|string $value to set |
| 315 | 315 | */ |
| 316 | 316 | protected function setMultiLine($varName, $value) { |
| 317 | - if(empty($value)) { |
|
| 317 | + if (empty($value)) { |
|
| 318 | 318 | $value = ''; |
| 319 | 319 | } else if (!is_array($value)) { |
| 320 | 320 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
| 321 | - if($value === false) { |
|
| 321 | + if ($value === false) { |
|
| 322 | 322 | $value = ''; |
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if(!is_array($value)) { |
|
| 326 | + if (!is_array($value)) { |
|
| 327 | 327 | $finalValue = trim($value); |
| 328 | 328 | } else { |
| 329 | 329 | $finalValue = []; |
| 330 | - foreach($value as $key => $val) { |
|
| 331 | - if(is_string($val)) { |
|
| 330 | + foreach ($value as $key => $val) { |
|
| 331 | + if (is_string($val)) { |
|
| 332 | 332 | $val = trim($val); |
| 333 | 333 | if ($val !== '') { |
| 334 | 334 | //accidental line breaks are not wanted and can cause |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | */ |
| 376 | 376 | protected function getValue($varName) { |
| 377 | 377 | static $defaults; |
| 378 | - if(is_null($defaults)) { |
|
| 378 | + if (is_null($defaults)) { |
|
| 379 | 379 | $defaults = $this->getDefaults(); |
| 380 | 380 | } |
| 381 | 381 | return \OCP\Config::getAppValue('user_ldap', |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @param mixed $value to set |
| 391 | 391 | */ |
| 392 | 392 | protected function setValue($varName, $value) { |
| 393 | - if(is_string($value)) { |
|
| 393 | + if (is_string($value)) { |
|
| 394 | 394 | $value = trim($value); |
| 395 | 395 | } |
| 396 | 396 | $this->config[$varName] = $value; |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | * @throws \RuntimeException |
| 550 | 550 | */ |
| 551 | 551 | public function resolveRule($rule) { |
| 552 | - if($rule === 'avatar') { |
|
| 552 | + if ($rule === 'avatar') { |
|
| 553 | 553 | return $this->getAvatarAttributes(); |
| 554 | 554 | } |
| 555 | 555 | throw new \RuntimeException('Invalid rule'); |
@@ -559,17 +559,17 @@ discard block |
||
| 559 | 559 | $value = $this->ldapUserAvatarRule ?: self::AVATAR_PREFIX_DEFAULT; |
| 560 | 560 | $defaultAttributes = ['jpegphoto', 'thumbnailphoto']; |
| 561 | 561 | |
| 562 | - if($value === self::AVATAR_PREFIX_NONE) { |
|
| 562 | + if ($value === self::AVATAR_PREFIX_NONE) { |
|
| 563 | 563 | return []; |
| 564 | 564 | } |
| 565 | - if(strpos($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE) === 0) { |
|
| 565 | + if (strpos($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE) === 0) { |
|
| 566 | 566 | $attribute = trim(substr($value, strlen(self::AVATAR_PREFIX_DATA_ATTRIBUTE))); |
| 567 | - if($attribute === '') { |
|
| 567 | + if ($attribute === '') { |
|
| 568 | 568 | return $defaultAttributes; |
| 569 | 569 | } |
| 570 | 570 | return [strtolower($attribute)]; |
| 571 | 571 | } |
| 572 | - if($value !== self::AVATAR_PREFIX_DEFAULT) { |
|
| 572 | + if ($value !== self::AVATAR_PREFIX_DEFAULT) { |
|
| 573 | 573 | \OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to default.'); |
| 574 | 574 | } |
| 575 | 575 | return $defaultAttributes; |