@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
| 73 | 73 | parent::__construct($ldap); |
| 74 | 74 | $this->configuration = $configuration; |
| 75 | - if(is_null(Wizard::$l)) { |
|
| 75 | + if (is_null(Wizard::$l)) { |
|
| 76 | 76 | Wizard::$l = \OC::$server->getL10N('user_ldap'); |
| 77 | 77 | } |
| 78 | 78 | $this->access = $access; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function __destruct() { |
| 83 | - if($this->result->hasChanges()) { |
|
| 83 | + if ($this->result->hasChanges()) { |
|
| 84 | 84 | $this->configuration->saveConfiguration(); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function countEntries(string $filter, string $type): int { |
| 97 | 97 | $reqs = ['ldapHost', 'ldapPort', 'ldapBase']; |
| 98 | - if($type === 'users') { |
|
| 98 | + if ($type === 'users') { |
|
| 99 | 99 | $reqs[] = 'ldapUserFilter'; |
| 100 | 100 | } |
| 101 | - if(!$this->checkRequirements($reqs)) { |
|
| 101 | + if (!$this->checkRequirements($reqs)) { |
|
| 102 | 102 | throw new \Exception('Requirements not met', 400); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $attr = ['dn']; // default |
| 106 | 106 | $limit = 1001; |
| 107 | - if($type === 'groups') { |
|
| 108 | - $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | - } else if($type === 'users') { |
|
| 107 | + if ($type === 'groups') { |
|
| 108 | + $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | + } else if ($type === 'users') { |
|
| 110 | 110 | $result = $this->access->countUsers($filter, $attr, $limit); |
| 111 | 111 | } else if ($type === 'objects') { |
| 112 | 112 | $result = $this->access->countObjects($limit); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | throw new \Exception('Internal error: Invalid object type', 500); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - return (int)$result; |
|
| 117 | + return (int) $result; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | 127 | private function formatCountResult(int $count): string { |
| 128 | - if($count > 1000) { |
|
| 128 | + if ($count > 1000) { |
|
| 129 | 129 | return '> 1000'; |
| 130 | 130 | } |
| 131 | - return (string)$count; |
|
| 131 | + return (string) $count; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public function countGroups() { |
| 135 | 135 | $filter = $this->configuration->ldapGroupFilter; |
| 136 | 136 | |
| 137 | - if(empty($filter)) { |
|
| 137 | + if (empty($filter)) { |
|
| 138 | 138 | $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
| 139 | 139 | $this->result->addChange('ldap_group_count', $output); |
| 140 | 140 | return $this->result; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $groupsTotal = $this->countEntries($filter, 'groups'); |
| 145 | 145 | } catch (\Exception $e) { |
| 146 | 146 | //400 can be ignored, 500 is forwarded |
| 147 | - if($e->getCode() === 500) { |
|
| 147 | + if ($e->getCode() === 500) { |
|
| 148 | 148 | throw $e; |
| 149 | 149 | } |
| 150 | 150 | return false; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function countInBaseDN() { |
| 187 | 187 | // we don't need to provide a filter in this case |
| 188 | 188 | $total = $this->countEntries('', 'objects'); |
| 189 | - if($total === false) { |
|
| 189 | + if ($total === false) { |
|
| 190 | 190 | throw new \Exception('invalid results received'); |
| 191 | 191 | } |
| 192 | 192 | $this->result->addChange('ldap_test_base', $total); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return int|bool |
| 201 | 201 | */ |
| 202 | 202 | public function countUsersWithAttribute($attr, $existsCheck = false) { |
| 203 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 203 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 204 | 204 | 'ldapPort', |
| 205 | 205 | 'ldapBase', |
| 206 | 206 | 'ldapUserFilter', |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $filter = $this->access->combineFilterWithAnd(array( |
| 212 | 212 | $this->configuration->ldapUserFilter, |
| 213 | - $attr . '=*' |
|
| 213 | + $attr.'=*' |
|
| 214 | 214 | )); |
| 215 | 215 | |
| 216 | 216 | $limit = ($existsCheck === false) ? null : 1; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @throws \Exception |
| 226 | 226 | */ |
| 227 | 227 | public function detectUserDisplayNameAttribute() { |
| 228 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 228 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 229 | 229 | 'ldapPort', |
| 230 | 230 | 'ldapBase', |
| 231 | 231 | 'ldapUserFilter', |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | if ($attr !== '' && $attr !== 'displayName') { |
| 238 | 238 | // most likely not the default value with upper case N, |
| 239 | 239 | // verify it still produces a result |
| 240 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 241 | - if($count > 0) { |
|
| 240 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 241 | + if ($count > 0) { |
|
| 242 | 242 | //no change, but we sent it back to make sure the user interface |
| 243 | 243 | //is still correct, even if the ajax call was cancelled meanwhile |
| 244 | 244 | $this->result->addChange('ldap_display_name', $attr); |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | // first attribute that has at least one result wins |
| 250 | 250 | $displayNameAttrs = array('displayname', 'cn'); |
| 251 | 251 | foreach ($displayNameAttrs as $attr) { |
| 252 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 252 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 253 | 253 | |
| 254 | - if($count > 0) { |
|
| 254 | + if ($count > 0) { |
|
| 255 | 255 | $this->applyFind('ldap_display_name', $attr); |
| 256 | 256 | return $this->result; |
| 257 | 257 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return WizardResult|bool |
| 268 | 268 | */ |
| 269 | 269 | public function detectEmailAttribute() { |
| 270 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 270 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 271 | 271 | 'ldapPort', |
| 272 | 272 | 'ldapBase', |
| 273 | 273 | 'ldapUserFilter', |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | $attr = $this->configuration->ldapEmailAttribute; |
| 279 | 279 | if ($attr !== '') { |
| 280 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 281 | - if($count > 0) { |
|
| 280 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 281 | + if ($count > 0) { |
|
| 282 | 282 | return false; |
| 283 | 283 | } |
| 284 | 284 | $writeLog = true; |
@@ -289,19 +289,19 @@ discard block |
||
| 289 | 289 | $emailAttributes = array('mail', 'mailPrimaryAddress'); |
| 290 | 290 | $winner = ''; |
| 291 | 291 | $maxUsers = 0; |
| 292 | - foreach($emailAttributes as $attr) { |
|
| 292 | + foreach ($emailAttributes as $attr) { |
|
| 293 | 293 | $count = $this->countUsersWithAttribute($attr); |
| 294 | - if($count > $maxUsers) { |
|
| 294 | + if ($count > $maxUsers) { |
|
| 295 | 295 | $maxUsers = $count; |
| 296 | 296 | $winner = $attr; |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if($winner !== '') { |
|
| 300 | + if ($winner !== '') { |
|
| 301 | 301 | $this->applyFind('ldap_email_attr', $winner); |
| 302 | - if($writeLog) { |
|
| 303 | - \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 304 | - 'automatically been reset, because the original value ' . |
|
| 302 | + if ($writeLog) { |
|
| 303 | + \OCP\Util::writeLog('user_ldap', 'The mail attribute has '. |
|
| 304 | + 'automatically been reset, because the original value '. |
|
| 305 | 305 | 'did not return any results.', ILogger::INFO); |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @throws \Exception |
| 315 | 315 | */ |
| 316 | 316 | public function determineAttributes() { |
| 317 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 317 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 318 | 318 | 'ldapPort', |
| 319 | 319 | 'ldapBase', |
| 320 | 320 | 'ldapUserFilter', |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
| 331 | 331 | |
| 332 | 332 | $selected = $this->configuration->ldapLoginFilterAttributes; |
| 333 | - if(is_array($selected) && !empty($selected)) { |
|
| 333 | + if (is_array($selected) && !empty($selected)) { |
|
| 334 | 334 | $this->result->addChange('ldap_loginfilter_attributes', $selected); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | * @throws \Exception |
| 344 | 344 | */ |
| 345 | 345 | private function getUserAttributes() { |
| 346 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 346 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 347 | 347 | 'ldapPort', |
| 348 | 348 | 'ldapBase', |
| 349 | 349 | 'ldapUserFilter', |
@@ -351,20 +351,20 @@ discard block |
||
| 351 | 351 | return false; |
| 352 | 352 | } |
| 353 | 353 | $cr = $this->getConnection(); |
| 354 | - if(!$cr) { |
|
| 354 | + if (!$cr) { |
|
| 355 | 355 | throw new \Exception('Could not connect to LDAP'); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $base = $this->configuration->ldapBase[0]; |
| 359 | 359 | $filter = $this->configuration->ldapUserFilter; |
| 360 | 360 | $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
| 361 | - if(!$this->ldap->isResource($rr)) { |
|
| 361 | + if (!$this->ldap->isResource($rr)) { |
|
| 362 | 362 | return false; |
| 363 | 363 | } |
| 364 | 364 | $er = $this->ldap->firstEntry($cr, $rr); |
| 365 | 365 | $attributes = $this->ldap->getAttributes($cr, $er); |
| 366 | 366 | $pureAttributes = array(); |
| 367 | - for($i = 0; $i < $attributes['count']; $i++) { |
|
| 367 | + for ($i = 0; $i < $attributes['count']; $i++) { |
|
| 368 | 368 | $pureAttributes[] = $attributes[$i]; |
| 369 | 369 | } |
| 370 | 370 | |
@@ -399,23 +399,23 @@ discard block |
||
| 399 | 399 | * @throws \Exception |
| 400 | 400 | */ |
| 401 | 401 | private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
| 402 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 402 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 403 | 403 | 'ldapPort', |
| 404 | 404 | 'ldapBase', |
| 405 | 405 | ))) { |
| 406 | 406 | return false; |
| 407 | 407 | } |
| 408 | 408 | $cr = $this->getConnection(); |
| 409 | - if(!$cr) { |
|
| 409 | + if (!$cr) { |
|
| 410 | 410 | throw new \Exception('Could not connect to LDAP'); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | $this->fetchGroups($dbKey, $confKey); |
| 414 | 414 | |
| 415 | - if($testMemberOf) { |
|
| 415 | + if ($testMemberOf) { |
|
| 416 | 416 | $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
| 417 | 417 | $this->result->markChange(); |
| 418 | - if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 418 | + if (!$this->configuration->hasMemberOfFilterSupport) { |
|
| 419 | 419 | throw new \Exception('memberOf is not supported by the server'); |
| 420 | 420 | } |
| 421 | 421 | } |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
| 436 | 436 | |
| 437 | 437 | $filterParts = array(); |
| 438 | - foreach($obclasses as $obclass) { |
|
| 438 | + foreach ($obclasses as $obclass) { |
|
| 439 | 439 | $filterParts[] = 'objectclass='.$obclass; |
| 440 | 440 | } |
| 441 | 441 | //we filter for everything |
@@ -452,8 +452,8 @@ discard block |
||
| 452 | 452 | // we need to request dn additionally here, otherwise memberOf |
| 453 | 453 | // detection will fail later |
| 454 | 454 | $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
| 455 | - foreach($result as $item) { |
|
| 456 | - if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 455 | + foreach ($result as $item) { |
|
| 456 | + if (!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 457 | 457 | // just in case - no issue known |
| 458 | 458 | continue; |
| 459 | 459 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | $offset += $limit; |
| 464 | 464 | } while ($this->access->hasMoreResults()); |
| 465 | 465 | |
| 466 | - if(count($groupNames) > 0) { |
|
| 466 | + if (count($groupNames) > 0) { |
|
| 467 | 467 | natsort($groupNames); |
| 468 | 468 | $this->result->addOptions($dbKey, array_values($groupNames)); |
| 469 | 469 | } else { |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | $setFeatures = $this->configuration->$confKey; |
| 474 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 474 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 475 | 475 | //something is already configured? pre-select it. |
| 476 | 476 | $this->result->addChange($dbKey, $setFeatures); |
| 477 | 477 | } |
@@ -479,14 +479,14 @@ discard block |
||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | public function determineGroupMemberAssoc() { |
| 482 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 482 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 483 | 483 | 'ldapPort', |
| 484 | 484 | 'ldapGroupFilter', |
| 485 | 485 | ))) { |
| 486 | 486 | return false; |
| 487 | 487 | } |
| 488 | 488 | $attribute = $this->detectGroupMemberAssoc(); |
| 489 | - if($attribute === false) { |
|
| 489 | + if ($attribute === false) { |
|
| 490 | 490 | return false; |
| 491 | 491 | } |
| 492 | 492 | $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
@@ -501,14 +501,14 @@ discard block |
||
| 501 | 501 | * @throws \Exception |
| 502 | 502 | */ |
| 503 | 503 | public function determineGroupObjectClasses() { |
| 504 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 504 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 505 | 505 | 'ldapPort', |
| 506 | 506 | 'ldapBase', |
| 507 | 507 | ))) { |
| 508 | 508 | return false; |
| 509 | 509 | } |
| 510 | 510 | $cr = $this->getConnection(); |
| 511 | - if(!$cr) { |
|
| 511 | + if (!$cr) { |
|
| 512 | 512 | throw new \Exception('Could not connect to LDAP'); |
| 513 | 513 | } |
| 514 | 514 | |
@@ -528,14 +528,14 @@ discard block |
||
| 528 | 528 | * @throws \Exception |
| 529 | 529 | */ |
| 530 | 530 | public function determineUserObjectClasses() { |
| 531 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 531 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 532 | 532 | 'ldapPort', |
| 533 | 533 | 'ldapBase', |
| 534 | 534 | ))) { |
| 535 | 535 | return false; |
| 536 | 536 | } |
| 537 | 537 | $cr = $this->getConnection(); |
| 538 | - if(!$cr) { |
|
| 538 | + if (!$cr) { |
|
| 539 | 539 | throw new \Exception('Could not connect to LDAP'); |
| 540 | 540 | } |
| 541 | 541 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * @throws \Exception |
| 559 | 559 | */ |
| 560 | 560 | public function getGroupFilter() { |
| 561 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 561 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 562 | 562 | 'ldapPort', |
| 563 | 563 | 'ldapBase', |
| 564 | 564 | ))) { |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | * @throws \Exception |
| 583 | 583 | */ |
| 584 | 584 | public function getUserListFilter() { |
| 585 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 585 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 586 | 586 | 'ldapPort', |
| 587 | 587 | 'ldapBase', |
| 588 | 588 | ))) { |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
| 596 | 596 | } |
| 597 | 597 | $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
| 598 | - if(!$filter) { |
|
| 598 | + if (!$filter) { |
|
| 599 | 599 | throw new \Exception('Cannot create filter'); |
| 600 | 600 | } |
| 601 | 601 | |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @throws \Exception |
| 609 | 609 | */ |
| 610 | 610 | public function getUserLoginFilter() { |
| 611 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 611 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 612 | 612 | 'ldapPort', |
| 613 | 613 | 'ldapBase', |
| 614 | 614 | 'ldapUserFilter', |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
| 620 | - if(!$filter) { |
|
| 620 | + if (!$filter) { |
|
| 621 | 621 | throw new \Exception('Cannot create filter'); |
| 622 | 622 | } |
| 623 | 623 | |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | * @throws \Exception |
| 632 | 632 | */ |
| 633 | 633 | public function testLoginName($loginName) { |
| 634 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 634 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 635 | 635 | 'ldapPort', |
| 636 | 636 | 'ldapBase', |
| 637 | 637 | 'ldapLoginFilter', |
@@ -640,17 +640,17 @@ discard block |
||
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | $cr = $this->access->connection->getConnectionResource(); |
| 643 | - if(!$this->ldap->isResource($cr)) { |
|
| 643 | + if (!$this->ldap->isResource($cr)) { |
|
| 644 | 644 | throw new \Exception('connection error'); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 647 | + if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 648 | 648 | === false) { |
| 649 | 649 | throw new \Exception('missing placeholder'); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | $users = $this->access->countUsersByLoginName($loginName); |
| 653 | - if($this->ldap->errno($cr) !== 0) { |
|
| 653 | + if ($this->ldap->errno($cr) !== 0) { |
|
| 654 | 654 | throw new \Exception($this->ldap->error($cr)); |
| 655 | 655 | } |
| 656 | 656 | $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
@@ -665,22 +665,22 @@ discard block |
||
| 665 | 665 | * @throws \Exception |
| 666 | 666 | */ |
| 667 | 667 | public function guessPortAndTLS() { |
| 668 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 668 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 669 | 669 | ))) { |
| 670 | 670 | return false; |
| 671 | 671 | } |
| 672 | 672 | $this->checkHost(); |
| 673 | 673 | $portSettings = $this->getPortSettingsToTry(); |
| 674 | 674 | |
| 675 | - if(!is_array($portSettings)) { |
|
| 675 | + if (!is_array($portSettings)) { |
|
| 676 | 676 | throw new \Exception(print_r($portSettings, true)); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | //proceed from the best configuration and return on first success |
| 680 | - foreach($portSettings as $setting) { |
|
| 680 | + foreach ($portSettings as $setting) { |
|
| 681 | 681 | $p = $setting['port']; |
| 682 | 682 | $t = $setting['tls']; |
| 683 | - \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG); |
|
| 683 | + \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '.$p.', TLS '.$t, ILogger::DEBUG); |
|
| 684 | 684 | //connectAndBind may throw Exception, it needs to be catched by the |
| 685 | 685 | //callee of this method |
| 686 | 686 | |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | // any reply other than -1 (= cannot connect) is already okay, |
| 691 | 691 | // because then we found the server |
| 692 | 692 | // unavailable startTLS returns -11 |
| 693 | - if($e->getCode() > 0) { |
|
| 693 | + if ($e->getCode() > 0) { |
|
| 694 | 694 | $settingsFound = true; |
| 695 | 695 | } else { |
| 696 | 696 | throw $e; |
@@ -700,10 +700,10 @@ discard block |
||
| 700 | 700 | if ($settingsFound === true) { |
| 701 | 701 | $config = array( |
| 702 | 702 | 'ldapPort' => $p, |
| 703 | - 'ldapTLS' => (int)$t |
|
| 703 | + 'ldapTLS' => (int) $t |
|
| 704 | 704 | ); |
| 705 | 705 | $this->configuration->setConfiguration($config); |
| 706 | - \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG); |
|
| 706 | + \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port '.$p, ILogger::DEBUG); |
|
| 707 | 707 | $this->result->addChange('ldap_port', $p); |
| 708 | 708 | return $this->result; |
| 709 | 709 | } |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | * @return WizardResult|false WizardResult on success, false otherwise |
| 719 | 719 | */ |
| 720 | 720 | public function guessBaseDN() { |
| 721 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 721 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 722 | 722 | 'ldapPort', |
| 723 | 723 | ))) { |
| 724 | 724 | return false; |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | //check whether a DN is given in the agent name (99.9% of all cases) |
| 728 | 728 | $base = null; |
| 729 | 729 | $i = stripos($this->configuration->ldapAgentName, 'dc='); |
| 730 | - if($i !== false) { |
|
| 730 | + if ($i !== false) { |
|
| 731 | 731 | $base = substr($this->configuration->ldapAgentName, $i); |
| 732 | - if($this->testBaseDN($base)) { |
|
| 732 | + if ($this->testBaseDN($base)) { |
|
| 733 | 733 | $this->applyFind('ldap_base', $base); |
| 734 | 734 | return $this->result; |
| 735 | 735 | } |
@@ -740,13 +740,13 @@ discard block |
||
| 740 | 740 | //a base DN |
| 741 | 741 | $helper = new Helper(\OC::$server->getConfig()); |
| 742 | 742 | $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
| 743 | - if(!$domain) { |
|
| 743 | + if (!$domain) { |
|
| 744 | 744 | return false; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | $dparts = explode('.', $domain); |
| 748 | - while(count($dparts) > 0) { |
|
| 749 | - $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 748 | + while (count($dparts) > 0) { |
|
| 749 | + $base2 = 'dc='.implode(',dc=', $dparts); |
|
| 750 | 750 | if ($base !== $base2 && $this->testBaseDN($base2)) { |
| 751 | 751 | $this->applyFind('ldap_base', $base2); |
| 752 | 752 | return $this->result; |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | $hostInfo = parse_url($host); |
| 780 | 780 | |
| 781 | 781 | //removes Port from Host |
| 782 | - if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 782 | + if (is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 783 | 783 | $port = $hostInfo['port']; |
| 784 | 784 | $host = str_replace(':'.$port, '', $host); |
| 785 | 785 | $this->applyFind('ldap_host', $host); |
@@ -796,30 +796,30 @@ discard block |
||
| 796 | 796 | private function detectGroupMemberAssoc() { |
| 797 | 797 | $possibleAttrs = ['uniqueMember', 'memberUid', 'member', 'gidNumber']; |
| 798 | 798 | $filter = $this->configuration->ldapGroupFilter; |
| 799 | - if(empty($filter)) { |
|
| 799 | + if (empty($filter)) { |
|
| 800 | 800 | return false; |
| 801 | 801 | } |
| 802 | 802 | $cr = $this->getConnection(); |
| 803 | - if(!$cr) { |
|
| 803 | + if (!$cr) { |
|
| 804 | 804 | throw new \Exception('Could not connect to LDAP'); |
| 805 | 805 | } |
| 806 | 806 | $base = $this->configuration->ldapBaseGroups[0] ?: $this->configuration->ldapBase[0]; |
| 807 | 807 | $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
| 808 | - if(!$this->ldap->isResource($rr)) { |
|
| 808 | + if (!$this->ldap->isResource($rr)) { |
|
| 809 | 809 | return false; |
| 810 | 810 | } |
| 811 | 811 | $er = $this->ldap->firstEntry($cr, $rr); |
| 812 | - while(is_resource($er)) { |
|
| 812 | + while (is_resource($er)) { |
|
| 813 | 813 | $this->ldap->getDN($cr, $er); |
| 814 | 814 | $attrs = $this->ldap->getAttributes($cr, $er); |
| 815 | 815 | $result = []; |
| 816 | 816 | $possibleAttrsCount = count($possibleAttrs); |
| 817 | - for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | - if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 817 | + for ($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | + if (isset($attrs[$possibleAttrs[$i]])) { |
|
| 819 | 819 | $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
| 820 | 820 | } |
| 821 | 821 | } |
| 822 | - if(!empty($result)) { |
|
| 822 | + if (!empty($result)) { |
|
| 823 | 823 | natsort($result); |
| 824 | 824 | return key($result); |
| 825 | 825 | } |
@@ -838,14 +838,14 @@ discard block |
||
| 838 | 838 | */ |
| 839 | 839 | private function testBaseDN($base) { |
| 840 | 840 | $cr = $this->getConnection(); |
| 841 | - if(!$cr) { |
|
| 841 | + if (!$cr) { |
|
| 842 | 842 | throw new \Exception('Could not connect to LDAP'); |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | //base is there, let's validate it. If we search for anything, we should |
| 846 | 846 | //get a result set > 0 on a proper base |
| 847 | 847 | $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
| 848 | - if(!$this->ldap->isResource($rr)) { |
|
| 848 | + if (!$this->ldap->isResource($rr)) { |
|
| 849 | 849 | $errorNo = $this->ldap->errno($cr); |
| 850 | 850 | $errorMsg = $this->ldap->error($cr); |
| 851 | 851 | \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | */ |
| 868 | 868 | private function testMemberOf() { |
| 869 | 869 | $cr = $this->getConnection(); |
| 870 | - if(!$cr) { |
|
| 870 | + if (!$cr) { |
|
| 871 | 871 | throw new \Exception('Could not connect to LDAP'); |
| 872 | 872 | } |
| 873 | 873 | $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
| 874 | - if(is_int($result) && $result > 0) { |
|
| 874 | + if (is_int($result) && $result > 0) { |
|
| 875 | 875 | return true; |
| 876 | 876 | } |
| 877 | 877 | return false; |
@@ -892,27 +892,27 @@ discard block |
||
| 892 | 892 | case self::LFILTER_USER_LIST: |
| 893 | 893 | $objcs = $this->configuration->ldapUserFilterObjectclass; |
| 894 | 894 | //glue objectclasses |
| 895 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 895 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 896 | 896 | $filter .= '(|'; |
| 897 | - foreach($objcs as $objc) { |
|
| 898 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 897 | + foreach ($objcs as $objc) { |
|
| 898 | + $filter .= '(objectclass='.$objc.')'; |
|
| 899 | 899 | } |
| 900 | 900 | $filter .= ')'; |
| 901 | 901 | $parts++; |
| 902 | 902 | } |
| 903 | 903 | //glue group memberships |
| 904 | - if($this->configuration->hasMemberOfFilterSupport) { |
|
| 904 | + if ($this->configuration->hasMemberOfFilterSupport) { |
|
| 905 | 905 | $cns = $this->configuration->ldapUserFilterGroups; |
| 906 | - if(is_array($cns) && count($cns) > 0) { |
|
| 906 | + if (is_array($cns) && count($cns) > 0) { |
|
| 907 | 907 | $filter .= '(|'; |
| 908 | 908 | $cr = $this->getConnection(); |
| 909 | - if(!$cr) { |
|
| 909 | + if (!$cr) { |
|
| 910 | 910 | throw new \Exception('Could not connect to LDAP'); |
| 911 | 911 | } |
| 912 | 912 | $base = $this->configuration->ldapBase[0]; |
| 913 | - foreach($cns as $cn) { |
|
| 914 | - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 915 | - if(!$this->ldap->isResource($rr)) { |
|
| 913 | + foreach ($cns as $cn) { |
|
| 914 | + $rr = $this->ldap->search($cr, $base, 'cn='.$cn, array('dn', 'primaryGroupToken')); |
|
| 915 | + if (!$this->ldap->isResource($rr)) { |
|
| 916 | 916 | continue; |
| 917 | 917 | } |
| 918 | 918 | $er = $this->ldap->firstEntry($cr, $rr); |
@@ -921,11 +921,11 @@ discard block |
||
| 921 | 921 | if ($dn === false || $dn === '') { |
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | - $filterPart = '(memberof=' . $dn . ')'; |
|
| 925 | - if(isset($attrs['primaryGroupToken'])) { |
|
| 924 | + $filterPart = '(memberof='.$dn.')'; |
|
| 925 | + if (isset($attrs['primaryGroupToken'])) { |
|
| 926 | 926 | $pgt = $attrs['primaryGroupToken'][0]; |
| 927 | - $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 928 | - $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 927 | + $primaryFilterPart = '(primaryGroupID='.$pgt.')'; |
|
| 928 | + $filterPart = '(|'.$filterPart.$primaryFilterPart.')'; |
|
| 929 | 929 | } |
| 930 | 930 | $filter .= $filterPart; |
| 931 | 931 | } |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | $parts++; |
| 935 | 935 | } |
| 936 | 936 | //wrap parts in AND condition |
| 937 | - if($parts > 1) { |
|
| 938 | - $filter = '(&' . $filter . ')'; |
|
| 937 | + if ($parts > 1) { |
|
| 938 | + $filter = '(&'.$filter.')'; |
|
| 939 | 939 | } |
| 940 | 940 | if ($filter === '') { |
| 941 | 941 | $filter = '(objectclass=*)'; |
@@ -945,27 +945,27 @@ discard block |
||
| 945 | 945 | case self::LFILTER_GROUP_LIST: |
| 946 | 946 | $objcs = $this->configuration->ldapGroupFilterObjectclass; |
| 947 | 947 | //glue objectclasses |
| 948 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 948 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 949 | 949 | $filter .= '(|'; |
| 950 | - foreach($objcs as $objc) { |
|
| 951 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 950 | + foreach ($objcs as $objc) { |
|
| 951 | + $filter .= '(objectclass='.$objc.')'; |
|
| 952 | 952 | } |
| 953 | 953 | $filter .= ')'; |
| 954 | 954 | $parts++; |
| 955 | 955 | } |
| 956 | 956 | //glue group memberships |
| 957 | 957 | $cns = $this->configuration->ldapGroupFilterGroups; |
| 958 | - if(is_array($cns) && count($cns) > 0) { |
|
| 958 | + if (is_array($cns) && count($cns) > 0) { |
|
| 959 | 959 | $filter .= '(|'; |
| 960 | - foreach($cns as $cn) { |
|
| 961 | - $filter .= '(cn=' . $cn . ')'; |
|
| 960 | + foreach ($cns as $cn) { |
|
| 961 | + $filter .= '(cn='.$cn.')'; |
|
| 962 | 962 | } |
| 963 | 963 | $filter .= ')'; |
| 964 | 964 | } |
| 965 | 965 | $parts++; |
| 966 | 966 | //wrap parts in AND condition |
| 967 | - if($parts > 1) { |
|
| 968 | - $filter = '(&' . $filter . ')'; |
|
| 967 | + if ($parts > 1) { |
|
| 968 | + $filter = '(&'.$filter.')'; |
|
| 969 | 969 | } |
| 970 | 970 | break; |
| 971 | 971 | |
@@ -977,47 +977,47 @@ discard block |
||
| 977 | 977 | $userAttributes = array_change_key_case(array_flip($userAttributes)); |
| 978 | 978 | $parts = 0; |
| 979 | 979 | |
| 980 | - if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 980 | + if ($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 981 | 981 | $attr = ''; |
| 982 | - if(isset($userAttributes['uid'])) { |
|
| 982 | + if (isset($userAttributes['uid'])) { |
|
| 983 | 983 | $attr = 'uid'; |
| 984 | - } else if(isset($userAttributes['samaccountname'])) { |
|
| 984 | + } else if (isset($userAttributes['samaccountname'])) { |
|
| 985 | 985 | $attr = 'samaccountname'; |
| 986 | - } else if(isset($userAttributes['cn'])) { |
|
| 986 | + } else if (isset($userAttributes['cn'])) { |
|
| 987 | 987 | //fallback |
| 988 | 988 | $attr = 'cn'; |
| 989 | 989 | } |
| 990 | 990 | if ($attr !== '') { |
| 991 | - $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 991 | + $filterUsername = '('.$attr.$loginpart.')'; |
|
| 992 | 992 | $parts++; |
| 993 | 993 | } |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | $filterEmail = ''; |
| 997 | - if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 997 | + if ($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 998 | 998 | $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
| 999 | 999 | $parts++; |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | $filterAttributes = ''; |
| 1003 | 1003 | $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
| 1004 | - if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1004 | + if (is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1005 | 1005 | $filterAttributes = '(|'; |
| 1006 | - foreach($attrsToFilter as $attribute) { |
|
| 1007 | - $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 1006 | + foreach ($attrsToFilter as $attribute) { |
|
| 1007 | + $filterAttributes .= '('.$attribute.$loginpart.')'; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | $filterAttributes .= ')'; |
| 1010 | 1010 | $parts++; |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | $filterLogin = ''; |
| 1014 | - if($parts > 1) { |
|
| 1014 | + if ($parts > 1) { |
|
| 1015 | 1015 | $filterLogin = '(|'; |
| 1016 | 1016 | } |
| 1017 | 1017 | $filterLogin .= $filterUsername; |
| 1018 | 1018 | $filterLogin .= $filterEmail; |
| 1019 | 1019 | $filterLogin .= $filterAttributes; |
| 1020 | - if($parts > 1) { |
|
| 1020 | + if ($parts > 1) { |
|
| 1021 | 1021 | $filterLogin .= ')'; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
@@ -1042,12 +1042,12 @@ discard block |
||
| 1042 | 1042 | //connect, does not really trigger any server communication |
| 1043 | 1043 | $host = $this->configuration->ldapHost; |
| 1044 | 1044 | $hostInfo = parse_url($host); |
| 1045 | - if(!$hostInfo) { |
|
| 1045 | + if (!$hostInfo) { |
|
| 1046 | 1046 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1047 | 1047 | } |
| 1048 | 1048 | \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG); |
| 1049 | 1049 | $cr = $this->ldap->connect($host, $port); |
| 1050 | - if(!is_resource($cr)) { |
|
| 1050 | + if (!is_resource($cr)) { |
|
| 1051 | 1051 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
@@ -1057,9 +1057,9 @@ discard block |
||
| 1057 | 1057 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1058 | 1058 | |
| 1059 | 1059 | try { |
| 1060 | - if($tls) { |
|
| 1060 | + if ($tls) { |
|
| 1061 | 1061 | $isTlsWorking = @$this->ldap->startTls($cr); |
| 1062 | - if(!$isTlsWorking) { |
|
| 1062 | + if (!$isTlsWorking) { |
|
| 1063 | 1063 | return false; |
| 1064 | 1064 | } |
| 1065 | 1065 | } |
@@ -1073,17 +1073,17 @@ discard block |
||
| 1073 | 1073 | $errNo = $this->ldap->errno($cr); |
| 1074 | 1074 | $error = ldap_error($cr); |
| 1075 | 1075 | $this->ldap->unbind($cr); |
| 1076 | - } catch(ServerNotAvailableException $e) { |
|
| 1076 | + } catch (ServerNotAvailableException $e) { |
|
| 1077 | 1077 | return false; |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if($login === true) { |
|
| 1080 | + if ($login === true) { |
|
| 1081 | 1081 | $this->ldap->unbind($cr); |
| 1082 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG); |
|
| 1082 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '.$port.' TLS '.(int) $tls, ILogger::DEBUG); |
|
| 1083 | 1083 | return true; |
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | - if($errNo === -1) { |
|
| 1086 | + if ($errNo === -1) { |
|
| 1087 | 1087 | //host, port or TLS wrong |
| 1088 | 1088 | return false; |
| 1089 | 1089 | } |
@@ -1111,9 +1111,9 @@ discard block |
||
| 1111 | 1111 | */ |
| 1112 | 1112 | private function checkRequirements($reqs) { |
| 1113 | 1113 | $this->checkAgentRequirements(); |
| 1114 | - foreach($reqs as $option) { |
|
| 1114 | + foreach ($reqs as $option) { |
|
| 1115 | 1115 | $value = $this->configuration->$option; |
| 1116 | - if(empty($value)) { |
|
| 1116 | + if (empty($value)) { |
|
| 1117 | 1117 | return false; |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
@@ -1135,33 +1135,33 @@ discard block |
||
| 1135 | 1135 | $dnRead = array(); |
| 1136 | 1136 | $foundItems = array(); |
| 1137 | 1137 | $maxEntries = 0; |
| 1138 | - if(!is_array($this->configuration->ldapBase) |
|
| 1138 | + if (!is_array($this->configuration->ldapBase) |
|
| 1139 | 1139 | || !isset($this->configuration->ldapBase[0])) { |
| 1140 | 1140 | return false; |
| 1141 | 1141 | } |
| 1142 | 1142 | $base = $this->configuration->ldapBase[0]; |
| 1143 | 1143 | $cr = $this->getConnection(); |
| 1144 | - if(!$this->ldap->isResource($cr)) { |
|
| 1144 | + if (!$this->ldap->isResource($cr)) { |
|
| 1145 | 1145 | return false; |
| 1146 | 1146 | } |
| 1147 | 1147 | $lastFilter = null; |
| 1148 | - if(isset($filters[count($filters)-1])) { |
|
| 1149 | - $lastFilter = $filters[count($filters)-1]; |
|
| 1148 | + if (isset($filters[count($filters) - 1])) { |
|
| 1149 | + $lastFilter = $filters[count($filters) - 1]; |
|
| 1150 | 1150 | } |
| 1151 | - foreach($filters as $filter) { |
|
| 1152 | - if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1151 | + foreach ($filters as $filter) { |
|
| 1152 | + if ($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1153 | 1153 | //skip when the filter is a wildcard and results were found |
| 1154 | 1154 | continue; |
| 1155 | 1155 | } |
| 1156 | 1156 | // 20k limit for performance and reason |
| 1157 | 1157 | $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
| 1158 | - if(!$this->ldap->isResource($rr)) { |
|
| 1158 | + if (!$this->ldap->isResource($rr)) { |
|
| 1159 | 1159 | continue; |
| 1160 | 1160 | } |
| 1161 | 1161 | $entries = $this->ldap->countEntries($cr, $rr); |
| 1162 | 1162 | $getEntryFunc = 'firstEntry'; |
| 1163 | - if(($entries !== false) && ($entries > 0)) { |
|
| 1164 | - if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1163 | + if (($entries !== false) && ($entries > 0)) { |
|
| 1164 | + if (!is_null($maxF) && $entries > $maxEntries) { |
|
| 1165 | 1165 | $maxEntries = $entries; |
| 1166 | 1166 | $maxF = $filter; |
| 1167 | 1167 | } |
@@ -1169,13 +1169,13 @@ discard block |
||
| 1169 | 1169 | do { |
| 1170 | 1170 | $entry = $this->ldap->$getEntryFunc($cr, $rr); |
| 1171 | 1171 | $getEntryFunc = 'nextEntry'; |
| 1172 | - if(!$this->ldap->isResource($entry)) { |
|
| 1172 | + if (!$this->ldap->isResource($entry)) { |
|
| 1173 | 1173 | continue 2; |
| 1174 | 1174 | } |
| 1175 | 1175 | $rr = $entry; //will be expected by nextEntry next round |
| 1176 | 1176 | $attributes = $this->ldap->getAttributes($cr, $entry); |
| 1177 | 1177 | $dn = $this->ldap->getDN($cr, $entry); |
| 1178 | - if($dn === false || in_array($dn, $dnRead)) { |
|
| 1178 | + if ($dn === false || in_array($dn, $dnRead)) { |
|
| 1179 | 1179 | continue; |
| 1180 | 1180 | } |
| 1181 | 1181 | $newItems = array(); |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | $foundItems = array_merge($foundItems, $newItems); |
| 1187 | 1187 | $this->resultCache[$dn][$attr] = $newItems; |
| 1188 | 1188 | $dnRead[] = $dn; |
| 1189 | - } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1189 | + } while (($state === self::LRESULT_PROCESSED_SKIP |
|
| 1190 | 1190 | || $this->ldap->isResource($entry)) |
| 1191 | 1191 | && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
| 1192 | 1192 | } |
@@ -1209,11 +1209,11 @@ discard block |
||
| 1209 | 1209 | */ |
| 1210 | 1210 | private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
| 1211 | 1211 | $cr = $this->getConnection(); |
| 1212 | - if(!$cr) { |
|
| 1212 | + if (!$cr) { |
|
| 1213 | 1213 | throw new \Exception('Could not connect to LDAP'); |
| 1214 | 1214 | } |
| 1215 | 1215 | $p = 'objectclass='; |
| 1216 | - foreach($objectclasses as $key => $value) { |
|
| 1216 | + foreach ($objectclasses as $key => $value) { |
|
| 1217 | 1217 | $objectclasses[$key] = $p.$value; |
| 1218 | 1218 | } |
| 1219 | 1219 | $maxEntryObjC = ''; |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | $availableFeatures = |
| 1226 | 1226 | $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
| 1227 | 1227 | $dig, $maxEntryObjC); |
| 1228 | - if(is_array($availableFeatures) |
|
| 1228 | + if (is_array($availableFeatures) |
|
| 1229 | 1229 | && count($availableFeatures) > 0) { |
| 1230 | 1230 | natcasesort($availableFeatures); |
| 1231 | 1231 | //natcasesort keeps indices, but we must get rid of them for proper |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | $setFeatures = $this->configuration->$confkey; |
| 1239 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1239 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1240 | 1240 | //something is already configured? pre-select it. |
| 1241 | 1241 | $this->result->addChange($dbkey, $setFeatures); |
| 1242 | 1242 | } else if ($po && $maxEntryObjC !== '') { |
@@ -1258,7 +1258,7 @@ discard block |
||
| 1258 | 1258 | * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
| 1259 | 1259 | */ |
| 1260 | 1260 | private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
| 1261 | - if(!is_array($result) |
|
| 1261 | + if (!is_array($result) |
|
| 1262 | 1262 | || !isset($result['count']) |
| 1263 | 1263 | || !$result['count'] > 0) { |
| 1264 | 1264 | return self::LRESULT_PROCESSED_INVALID; |
@@ -1267,12 +1267,12 @@ discard block |
||
| 1267 | 1267 | // strtolower on all keys for proper comparison |
| 1268 | 1268 | $result = \OCP\Util::mb_array_change_key_case($result); |
| 1269 | 1269 | $attribute = strtolower($attribute); |
| 1270 | - if(isset($result[$attribute])) { |
|
| 1271 | - foreach($result[$attribute] as $key => $val) { |
|
| 1272 | - if($key === 'count') { |
|
| 1270 | + if (isset($result[$attribute])) { |
|
| 1271 | + foreach ($result[$attribute] as $key => $val) { |
|
| 1272 | + if ($key === 'count') { |
|
| 1273 | 1273 | continue; |
| 1274 | 1274 | } |
| 1275 | - if(!in_array($val, $known)) { |
|
| 1275 | + if (!in_array($val, $known)) { |
|
| 1276 | 1276 | $known[] = $val; |
| 1277 | 1277 | } |
| 1278 | 1278 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | * @return bool|mixed |
| 1287 | 1287 | */ |
| 1288 | 1288 | private function getConnection() { |
| 1289 | - if(!is_null($this->cr)) { |
|
| 1289 | + if (!is_null($this->cr)) { |
|
| 1290 | 1290 | return $this->cr; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
@@ -1298,14 +1298,14 @@ discard block |
||
| 1298 | 1298 | $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
| 1299 | 1299 | $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
| 1300 | 1300 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1301 | - if($this->configuration->ldapTLS === 1) { |
|
| 1301 | + if ($this->configuration->ldapTLS === 1) { |
|
| 1302 | 1302 | $this->ldap->startTls($cr); |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | $lo = @$this->ldap->bind($cr, |
| 1306 | 1306 | $this->configuration->ldapAgentName, |
| 1307 | 1307 | $this->configuration->ldapAgentPassword); |
| 1308 | - if($lo === true) { |
|
| 1308 | + if ($lo === true) { |
|
| 1309 | 1309 | $this->$cr = $cr; |
| 1310 | 1310 | return $cr; |
| 1311 | 1311 | } |
@@ -1336,18 +1336,18 @@ discard block |
||
| 1336 | 1336 | //636 ← LDAPS / SSL |
| 1337 | 1337 | //7xxx ← UCS. need to be checked first, because both ports may be open |
| 1338 | 1338 | $host = $this->configuration->ldapHost; |
| 1339 | - $port = (int)$this->configuration->ldapPort; |
|
| 1339 | + $port = (int) $this->configuration->ldapPort; |
|
| 1340 | 1340 | $portSettings = array(); |
| 1341 | 1341 | |
| 1342 | 1342 | //In case the port is already provided, we will check this first |
| 1343 | - if($port > 0) { |
|
| 1343 | + if ($port > 0) { |
|
| 1344 | 1344 | $hostInfo = parse_url($host); |
| 1345 | - if(!(is_array($hostInfo) |
|
| 1345 | + if (!(is_array($hostInfo) |
|
| 1346 | 1346 | && isset($hostInfo['scheme']) |
| 1347 | 1347 | && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
| 1348 | 1348 | $portSettings[] = array('port' => $port, 'tls' => true); |
| 1349 | 1349 | } |
| 1350 | - $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1350 | + $portSettings[] = array('port' => $port, 'tls' => false); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | //default ports |