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