Completed
Pull Request — master (#5231)
by Morris
16:38
created
apps/user_ldap/ajax/testConfiguration.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
 			try {
67 67
 				$ldapWrapper->read($connection->getConnectionResource(), '', 'objectClass=*', array('dn'));
68 68
 			} catch (\Exception $e) {
69
-				if($e->getCode() === 1) {
69
+				if ($e->getCode() === 1) {
70 70
 					OCP\JSON::error(array('message' => $l->t('The configuration is invalid: anonymous bind is not allowed.')));
71 71
 					exit;
72 72
 				}
Please login to merge, or discard this patch.
apps/user_ldap/ajax/getConfiguration.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 OCP\JSON::checkAppEnabled('user_ldap');
30 30
 OCP\JSON::callCheck();
31 31
 
32
-$prefix = (string)$_POST['ldap_serverconfig_chooser'];
32
+$prefix = (string) $_POST['ldap_serverconfig_chooser'];
33 33
 $ldapWrapper = new OCA\User_LDAP\LDAP();
34 34
 $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix);
35 35
 $configuration = $connection->getConfiguration();
Please login to merge, or discard this patch.
apps/user_ldap/ajax/setConfiguration.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@
 block discarded – undo
30 30
 OCP\JSON::checkAppEnabled('user_ldap');
31 31
 OCP\JSON::callCheck();
32 32
 
33
-$prefix = (string)$_POST['ldap_serverconfig_chooser'];
33
+$prefix = (string) $_POST['ldap_serverconfig_chooser'];
34 34
 
35 35
 // Checkboxes are not submitted, when they are unchecked. Set them manually.
36 36
 // only legacy checkboxes (Advanced and Expert tab) need to be handled here,
37 37
 // the Wizard-like tabs handle it on their own
38 38
 $chkboxes = array('ldap_configuration_active', 'ldap_override_main_server',
39 39
 				  'ldap_turn_off_cert_check');
40
-foreach($chkboxes as $boxid) {
41
-	if(!isset($_POST[$boxid])) {
40
+foreach ($chkboxes as $boxid) {
41
+	if (!isset($_POST[$boxid])) {
42 42
 		$_POST[$boxid] = 0;
43 43
 	}
44 44
 }
Please login to merge, or discard this patch.
apps/user_ldap/ajax/deleteConfiguration.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
 OCP\JSON::checkAppEnabled('user_ldap');
32 32
 OCP\JSON::callCheck();
33 33
 
34
-$prefix = (string)$_POST['ldap_serverconfig_chooser'];
34
+$prefix = (string) $_POST['ldap_serverconfig_chooser'];
35 35
 $helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
36
-if($helper->deleteServerConfiguration($prefix)) {
36
+if ($helper->deleteServerConfiguration($prefix)) {
37 37
 	OCP\JSON::success();
38 38
 } else {
39 39
 	$l = \OC::$server->getL10N('user_ldap');
Please login to merge, or discard this patch.
apps/user_ldap/ajax/wizard.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -32,16 +32,16 @@  discard block
 block discarded – undo
32 32
 
33 33
 $l = \OC::$server->getL10N('user_ldap');
34 34
 
35
-if(!isset($_POST['action'])) {
35
+if (!isset($_POST['action'])) {
36 36
 	\OCP\JSON::error(array('message' => $l->t('No action specified')));
37 37
 }
38
-$action = (string)$_POST['action'];
38
+$action = (string) $_POST['action'];
39 39
 
40 40
 
41
-if(!isset($_POST['ldap_serverconfig_chooser'])) {
41
+if (!isset($_POST['ldap_serverconfig_chooser'])) {
42 42
 	\OCP\JSON::error(array('message' => $l->t('No configuration specified')));
43 43
 }
44
-$prefix = (string)$_POST['ldap_serverconfig_chooser'];
44
+$prefix = (string) $_POST['ldap_serverconfig_chooser'];
45 45
 
46 46
 $ldapWrapper = new \OCA\User_LDAP\LDAP();
47 47
 $configuration = new \OCA\User_LDAP\Configuration($prefix);
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
 $wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access);
68 68
 
69
-switch($action) {
69
+switch ($action) {
70 70
 	case 'guessPortAndTLS':
71 71
 	case 'guessBaseDN':
72 72
 	case 'detectEmailAttribute':
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	case 'countInBaseDN':
86 86
 		try {
87 87
 			$result = $wizard->$action();
88
-			if($result !== false) {
88
+			if ($result !== false) {
89 89
 				OCP\JSON::success($result->getResultArray());
90 90
 				exit;
91 91
 			}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		try {
102 102
 			$loginName = $_POST['ldap_test_loginname'];
103 103
 			$result = $wizard->$action($loginName);
104
-			if($result !== false) {
104
+			if ($result !== false) {
105 105
 				OCP\JSON::success($result->getResultArray());
106 106
 				exit;
107 107
 			}
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
 	case 'save':
118 118
 		$key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false;
119 119
 		$val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null;
120
-		if($key === false || is_null($val)) {
120
+		if ($key === false || is_null($val)) {
121 121
 			\OCP\JSON::error(array('message' => $l->t('No data specified')));
122 122
 			exit;
123 123
 		}
124 124
 		$cfg = array($key => $val);
125 125
 		$setParameters = array();
126 126
 		$configuration->setConfiguration($cfg, $setParameters);
127
-		if(!in_array($key, $setParameters)) {
127
+		if (!in_array($key, $setParameters)) {
128 128
 			\OCP\JSON::error(array('message' => $l->t($key.
129 129
 				' Could not set configuration %s', $setParameters[0])));
130 130
 			exit;
Please login to merge, or discard this patch.
apps/user_ldap/ajax/getNewServerConfigPrefix.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,12 +32,12 @@
 block discarded – undo
32 32
 sort($serverConnections);
33 33
 $lk = array_pop($serverConnections);
34 34
 $ln = intval(str_replace('s', '', $lk));
35
-$nk = 's'.str_pad($ln+1, 2, '0', STR_PAD_LEFT);
35
+$nk = 's'.str_pad($ln + 1, 2, '0', STR_PAD_LEFT);
36 36
 
37 37
 $resultData = array('configPrefix' => $nk);
38 38
 
39 39
 $newConfig = new \OCA\User_LDAP\Configuration($nk, false);
40
-if(isset($_POST['copyConfig'])) {
40
+if (isset($_POST['copyConfig'])) {
41 41
 	$originalConfig = new \OCA\User_LDAP\Configuration($_POST['copyConfig']);
42 42
 	$newConfig->setConfiguration($originalConfig->getConfiguration());
43 43
 } else {
Please login to merge, or discard this patch.
apps/user_ldap/lib/Mapping/AbstractMapping.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @return bool
54 54
 	 */
55 55
 	public function isColNameValid($col) {
56
-		switch($col) {
56
+		switch ($col) {
57 57
 			case 'ldap_dn':
58 58
 			case 'owncloud_name':
59 59
 			case 'directory_uuid':
@@ -72,19 +72,19 @@  discard block
 block discarded – undo
72 72
 	 * @return string|false
73 73
 	 */
74 74
 	protected function getXbyY($fetchCol, $compareCol, $search) {
75
-		if(!$this->isColNameValid($fetchCol)) {
75
+		if (!$this->isColNameValid($fetchCol)) {
76 76
 			//this is used internally only, but we don't want to risk
77 77
 			//having SQL injection at all.
78 78
 			throw new \Exception('Invalid Column Name');
79 79
 		}
80 80
 		$query = $this->dbc->prepare('
81
-			SELECT `' . $fetchCol . '`
82
-			FROM `'. $this->getTableName() .'`
83
-			WHERE `' . $compareCol . '` = ?
81
+			SELECT `' . $fetchCol.'`
82
+			FROM `'. $this->getTableName().'`
83
+			WHERE `' . $compareCol.'` = ?
84 84
 		');
85 85
 
86 86
 		$res = $query->execute(array($search));
87
-		if($res !== false) {
87
+		if ($res !== false) {
88 88
 			return $query->fetchColumn();
89 89
 		}
90 90
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	public function setDNbyUUID($fdn, $uuid) {
122 122
 		$query = $this->dbc->prepare('
123
-			UPDATE `' . $this->getTableName() . '`
123
+			UPDATE `' . $this->getTableName().'`
124 124
 			SET `ldap_dn` = ?
125 125
 			WHERE `directory_uuid` = ?
126 126
 		');
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function setUUIDbyDN($uuid, $fdn) {
141 141
 		$query = $this->dbc->prepare('
142
-			UPDATE `' . $this->getTableName() . '`
142
+			UPDATE `' . $this->getTableName().'`
143 143
 			SET `directory_uuid` = ?
144 144
 			WHERE `ldap_dn` = ?
145 145
 		');
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
 	public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") {
167 167
 		$query = $this->dbc->prepare('
168 168
 			SELECT `owncloud_name`
169
-			FROM `'. $this->getTableName() .'`
169
+			FROM `'. $this->getTableName().'`
170 170
 			WHERE `owncloud_name` LIKE ?
171 171
 		');
172 172
 
173 173
 		$res = $query->execute(array($prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch));
174 174
 		$names = array();
175
-		if($res !== false) {
176
-			while($row = $query->fetch()) {
175
+		if ($res !== false) {
176
+			while ($row = $query->fetch()) {
177 177
 				$names[] = $row['owncloud_name'];
178 178
 			}
179 179
 		}
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				`ldap_dn` AS `dn`,
212 212
 				`owncloud_name` AS `name`,
213 213
 				`directory_uuid` AS `uuid`
214
-			FROM `' . $this->getTableName() . '`',
214
+			FROM `' . $this->getTableName().'`',
215 215
 			$limit,
216 216
 			$offset
217 217
 		);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @return bool
229 229
 	 */
230 230
 	public function map($fdn, $name, $uuid) {
231
-		if(mb_strlen($fdn) > 255) {
231
+		if (mb_strlen($fdn) > 255) {
232 232
 			\OC::$server->getLogger()->error(
233 233
 				'Cannot map, because the DN exceeds 255 characters: {dn}',
234 234
 				[
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 		try {
249 249
 			$result = $this->dbc->insertIfNotExist($this->getTableName(), $row);
250 250
 			// insertIfNotExist returns values as int
251
-			return (bool)$result;
251
+			return (bool) $result;
252 252
 		} catch (\Exception $e) {
253 253
 			return false;
254 254
 		}
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	public function unmap($name) {
263 263
 		$query = $this->dbc->prepare('
264
-			DELETE FROM `'. $this->getTableName() .'`
264
+			DELETE FROM `'. $this->getTableName().'`
265 265
 			WHERE `owncloud_name` = ?');
266 266
 
267 267
 		return $this->modify($query, array($name));
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	public function clear() {
275 275
 		$sql = $this->dbc
276 276
 			->getDatabasePlatform()
277
-			->getTruncateTableSQL('`' . $this->getTableName() . '`');
277
+			->getTruncateTableSQL('`'.$this->getTableName().'`');
278 278
 		return $this->dbc->prepare($sql)->execute();
279 279
 	}
280 280
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Group_Proxy.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap) {
38 38
 		parent::__construct($ldap);
39
-		foreach($serverConfigPrefixes as $configPrefix) {
39
+		foreach ($serverConfigPrefixes as $configPrefix) {
40 40
 			$this->backends[$configPrefix] =
41 41
 				new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix));
42
-			if(is_null($this->refBackend)) {
42
+			if (is_null($this->refBackend)) {
43 43
 				$this->refBackend = &$this->backends[$configPrefix];
44 44
 			}
45 45
 		}
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	protected function walkBackends($gid, $method, $parameters) {
56 56
 		$cacheKey = $this->getGroupCacheKey($gid);
57
-		foreach($this->backends as $configPrefix => $backend) {
58
-			if($result = call_user_func_array(array($backend, $method), $parameters)) {
57
+		foreach ($this->backends as $configPrefix => $backend) {
58
+			if ($result = call_user_func_array(array($backend, $method), $parameters)) {
59 59
 				$this->writeToCache($cacheKey, $configPrefix);
60 60
 				return $result;
61 61
 			}
@@ -72,20 +72,20 @@  discard block
 block discarded – undo
72 72
 	 * @return mixed, the result of the method or false
73 73
 	 */
74 74
 	protected function callOnLastSeenOn($gid, $method, $parameters, $passOnWhen) {
75
-		$cacheKey = $this->getGroupCacheKey($gid);;
75
+		$cacheKey = $this->getGroupCacheKey($gid); ;
76 76
 		$prefix = $this->getFromCache($cacheKey);
77 77
 		//in case the uid has been found in the past, try this stored connection first
78
-		if(!is_null($prefix)) {
79
-			if(isset($this->backends[$prefix])) {
78
+		if (!is_null($prefix)) {
79
+			if (isset($this->backends[$prefix])) {
80 80
 				$result = call_user_func_array(array($this->backends[$prefix], $method), $parameters);
81
-				if($result === $passOnWhen) {
81
+				if ($result === $passOnWhen) {
82 82
 					//not found here, reset cache to null if group vanished
83 83
 					//because sometimes methods return false with a reason
84 84
 					$groupExists = call_user_func_array(
85 85
 						array($this->backends[$prefix], 'groupExists'),
86 86
 						array($gid)
87 87
 					);
88
-					if(!$groupExists) {
88
+					if (!$groupExists) {
89 89
 						$this->writeToCache($cacheKey, null);
90 90
 					}
91 91
 				}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	public function getUserGroups($uid) {
119 119
 		$groups = array();
120 120
 
121
-		foreach($this->backends as $backend) {
121
+		foreach ($this->backends as $backend) {
122 122
 			$backendGroups = $backend->getUserGroups($uid);
123 123
 			if (is_array($backendGroups)) {
124 124
 				$groups = array_merge($groups, $backendGroups);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
136 136
 		$users = array();
137 137
 
138
-		foreach($this->backends as $backend) {
138
+		foreach ($this->backends as $backend) {
139 139
 			$backendUsers = $backend->usersInGroup($gid, $search, $limit, $offset);
140 140
 			if (is_array($backendUsers)) {
141 141
 				$users = array_merge($users, $backendUsers);
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	public function getGroups($search = '', $limit = -1, $offset = 0) {
166 166
 		$groups = array();
167 167
 
168
-		foreach($this->backends as $backend) {
168
+		foreach ($this->backends as $backend) {
169 169
 			$backendGroups = $backend->getGroups($search, $limit, $offset);
170 170
 			if (is_array($backendGroups)) {
171 171
 				$groups = array_merge($groups, $backendGroups);
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAP.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 	 * @return mixed
53 53
 	 */
54 54
 	public function connect($host, $port) {
55
-		if(strpos($host, '://') === false) {
56
-			$host = 'ldap://' . $host;
55
+		if (strpos($host, '://') === false) {
56
+			$host = 'ldap://'.$host;
57 57
 		}
58
-		if(strpos($host, ':', strpos($host, '://') + 1) === false) {
58
+		if (strpos($host, ':', strpos($host, '://') + 1) === false) {
59 59
 			//ldap_connect ignores port parameter when URLs are passed
60
-			$host .= ':' . $port;
60
+			$host .= ':'.$port;
61 61
 		}
62 62
 		return $this->invokeLDAPMethod('connect', $host);
63 63
 	}
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @return bool
268 268
 	 */
269 269
 	protected function isResultFalse($result) {
270
-		if($result === false) {
270
+		if ($result === false) {
271 271
 			return true;
272 272
 		}
273 273
 
274
-		if($this->curFunc === 'ldap_search' && is_array($result)) {
274
+		if ($this->curFunc === 'ldap_search' && is_array($result)) {
275 275
 			foreach ($result as $singleResult) {
276
-				if($singleResult === false) {
276
+				if ($singleResult === false) {
277 277
 					return true;
278 278
 				}
279 279
 			}
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 */
288 288
 	protected function invokeLDAPMethod() {
289 289
 		$arguments = func_get_args();
290
-		$func = 'ldap_' . array_shift($arguments);
291
-		if(function_exists($func)) {
290
+		$func = 'ldap_'.array_shift($arguments);
291
+		if (function_exists($func)) {
292 292
 			$this->preFunctionCall($func, $arguments);
293 293
 			$result = call_user_func_array($func, $arguments);
294 294
 			if ($this->isResultFalse($result)) {
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	private function processLDAPError($resource) {
320 320
 		$errorCode = ldap_errno($resource);
321
-		if($errorCode === 0) {
321
+		if ($errorCode === 0) {
322 322
 			return;
323 323
 		}
324
-		$errorMsg  = ldap_error($resource);
324
+		$errorMsg = ldap_error($resource);
325 325
 
326
-		if($this->curFunc === 'ldap_get_entries'
326
+		if ($this->curFunc === 'ldap_get_entries'
327 327
 			&& $errorCode === -4) {
328 328
 		} else if ($errorCode === 32) {
329 329
 			//for now
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
 			throw new \Exception('LDAP Operations error', $errorCode);
338 338
 		} else if ($errorCode === 19) {
339 339
 			ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error);
340
-			throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode);
340
+			throw new ConstraintViolationException(!empty($extended_error) ? $extended_error : $errorMsg, $errorCode);
341 341
 		} else {
342 342
 			\OCP\Util::writeLog('user_ldap',
343
-				'LDAP error '.$errorMsg.' (' .
343
+				'LDAP error '.$errorMsg.' ('.
344 344
 				$errorCode.') after calling '.
345 345
 				$this->curFunc,
346 346
 				\OCP\Util::DEBUG);
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
 	 * Called after an ldap method is run to act on LDAP error if necessary
352 352
 	 */
353 353
 	private function postFunctionCall() {
354
-		if($this->isResource($this->curArgs[0])) {
354
+		if ($this->isResource($this->curArgs[0])) {
355 355
 			$resource = $this->curArgs[0];
356
-		} else if(
356
+		} else if (
357 357
 			   $this->curFunc === 'ldap_search'
358 358
 			&& is_array($this->curArgs[0])
359 359
 			&& $this->isResource($this->curArgs[0][0])
Please login to merge, or discard this patch.