@@ -32,12 +32,12 @@ |
||
| 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 { |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * @return mixed |
| 53 | 53 | */ |
| 54 | 54 | public function connect($host, $port) { |
| 55 | - if(strpos($host, '://') === false) { |
|
| 56 | - $host = 'ldap://' . $host; |
|
| 55 | + if (strpos($host, '://') === false) { |
|
| 56 | + $host = 'ldap://'.$host; |
|
| 57 | 57 | } |
| 58 | - if(strpos($host, ':', strpos($host, '://') + 1) === false) { |
|
| 58 | + if (strpos($host, ':', strpos($host, '://') + 1) === false) { |
|
| 59 | 59 | //ldap_connect ignores port parameter when URLs are passed |
| 60 | - $host .= ':' . $port; |
|
| 60 | + $host .= ':'.$port; |
|
| 61 | 61 | } |
| 62 | 62 | return $this->invokeLDAPMethod('connect', $host); |
| 63 | 63 | } |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * @return bool |
| 268 | 268 | */ |
| 269 | 269 | protected function isResultFalse($result) { |
| 270 | - if($result === false) { |
|
| 270 | + if ($result === false) { |
|
| 271 | 271 | return true; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if($this->curFunc === 'ldap_search' && is_array($result)) { |
|
| 274 | + if ($this->curFunc === 'ldap_search' && is_array($result)) { |
|
| 275 | 275 | foreach ($result as $singleResult) { |
| 276 | - if($singleResult === false) { |
|
| 276 | + if ($singleResult === false) { |
|
| 277 | 277 | return true; |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | protected function invokeLDAPMethod() { |
| 289 | 289 | $arguments = func_get_args(); |
| 290 | - $func = 'ldap_' . array_shift($arguments); |
|
| 291 | - if(function_exists($func)) { |
|
| 290 | + $func = 'ldap_'.array_shift($arguments); |
|
| 291 | + if (function_exists($func)) { |
|
| 292 | 292 | $this->preFunctionCall($func, $arguments); |
| 293 | 293 | $result = call_user_func_array($func, $arguments); |
| 294 | 294 | if ($this->isResultFalse($result)) { |
@@ -318,12 +318,12 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | private function processLDAPError($resource) { |
| 320 | 320 | $errorCode = ldap_errno($resource); |
| 321 | - if($errorCode === 0) { |
|
| 321 | + if ($errorCode === 0) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | - $errorMsg = ldap_error($resource); |
|
| 324 | + $errorMsg = ldap_error($resource); |
|
| 325 | 325 | |
| 326 | - if($this->curFunc === 'ldap_get_entries' |
|
| 326 | + if ($this->curFunc === 'ldap_get_entries' |
|
| 327 | 327 | && $errorCode === -4) { |
| 328 | 328 | } else if ($errorCode === 32) { |
| 329 | 329 | //for now |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | throw new \Exception('LDAP Operations error', $errorCode); |
| 338 | 338 | } else if ($errorCode === 19) { |
| 339 | 339 | ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error); |
| 340 | - throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode); |
|
| 340 | + throw new ConstraintViolationException(!empty($extended_error) ? $extended_error : $errorMsg, $errorCode); |
|
| 341 | 341 | } else { |
| 342 | 342 | \OCP\Util::writeLog('user_ldap', |
| 343 | - 'LDAP error '.$errorMsg.' (' . |
|
| 343 | + 'LDAP error '.$errorMsg.' ('. |
|
| 344 | 344 | $errorCode.') after calling '. |
| 345 | 345 | $this->curFunc, |
| 346 | 346 | \OCP\Util::DEBUG); |
@@ -351,9 +351,9 @@ discard block |
||
| 351 | 351 | * Called after an ldap method is run to act on LDAP error if necessary |
| 352 | 352 | */ |
| 353 | 353 | private function postFunctionCall() { |
| 354 | - if($this->isResource($this->curArgs[0])) { |
|
| 354 | + if ($this->isResource($this->curArgs[0])) { |
|
| 355 | 355 | $resource = $this->curArgs[0]; |
| 356 | - } else if( |
|
| 356 | + } else if ( |
|
| 357 | 357 | $this->curFunc === 'ldap_search' |
| 358 | 358 | && is_array($this->curArgs[0]) |
| 359 | 359 | && $this->isResource($this->curArgs[0][0]) |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 'user_ldap', 'isDeleted', '1'); |
| 72 | 72 | |
| 73 | 73 | $userObjects = array(); |
| 74 | - foreach($deletedUsers as $user) { |
|
| 74 | + foreach ($deletedUsers as $user) { |
|
| 75 | 75 | $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); |
| 76 | 76 | } |
| 77 | 77 | $this->deletedUsers = $userObjects; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @return \OCA\User_LDAP\User\OfflineUser[] |
| 85 | 85 | */ |
| 86 | 86 | public function getUsers() { |
| 87 | - if(is_array($this->deletedUsers)) { |
|
| 87 | + if (is_array($this->deletedUsers)) { |
|
| 88 | 88 | return $this->deletedUsers; |
| 89 | 89 | } |
| 90 | 90 | return $this->fetchDeletedUsers(); |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | public function hasUsers() { |
| 98 | - if($this->deletedUsers === false) { |
|
| 98 | + if ($this->deletedUsers === false) { |
|
| 99 | 99 | $this->fetchDeletedUsers(); |
| 100 | 100 | } |
| 101 | - if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
| 101 | + if (is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
| 102 | 102 | return true; |
| 103 | 103 | } |
| 104 | 104 | return false; |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | * reads the user details |
| 180 | 180 | */ |
| 181 | 181 | protected function fetchDetails() { |
| 182 | - $properties = array ( |
|
| 182 | + $properties = array( |
|
| 183 | 183 | 'displayName' => 'user_ldap', |
| 184 | 184 | 'uid' => 'user_ldap', |
| 185 | 185 | 'homePath' => 'user_ldap', |
| 186 | 186 | 'email' => 'settings', |
| 187 | 187 | 'lastLogin' => 'login' |
| 188 | 188 | ); |
| 189 | - foreach($properties as $property => $app) { |
|
| 189 | + foreach ($properties as $property => $app) { |
|
| 190 | 190 | $this->$property = $this->config->getUserValue($this->ocName, $app, $property, ''); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | ', 1); |
| 210 | 210 | $query->execute(array($this->ocName)); |
| 211 | 211 | $sResult = $query->fetchColumn(0); |
| 212 | - if(intval($sResult) === 1) { |
|
| 212 | + if (intval($sResult) === 1) { |
|
| 213 | 213 | $this->hasActiveShares = true; |
| 214 | 214 | return; |
| 215 | 215 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | ', 1); |
| 222 | 222 | $query->execute(array($this->ocName)); |
| 223 | 223 | $sResult = $query->fetchColumn(0); |
| 224 | - if(intval($sResult) === 1) { |
|
| 224 | + if (intval($sResult) === 1) { |
|
| 225 | 225 | $this->hasActiveShares = true; |
| 226 | 226 | return; |
| 227 | 227 | } |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | public function delete($configID) { |
| 148 | 148 | try { |
| 149 | 149 | $this->ensureConfigIDExists($configID); |
| 150 | - if(!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 150 | + if (!$this->ldapHelper->deleteServerConfiguration($configID)) { |
|
| 151 | 151 | throw new OCSException('Could not delete configuration'); |
| 152 | 152 | } |
| 153 | - } catch(OCSException $e) { |
|
| 153 | + } catch (OCSException $e) { |
|
| 154 | 154 | throw $e; |
| 155 | - } catch(\Exception $e) { |
|
| 155 | + } catch (\Exception $e) { |
|
| 156 | 156 | $this->logger->logException($e); |
| 157 | 157 | throw new OCSException('An issue occurred when deleting the config.'); |
| 158 | 158 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | try { |
| 188 | 188 | $this->ensureConfigIDExists($configID); |
| 189 | 189 | |
| 190 | - if(!is_array($configData)) { |
|
| 190 | + if (!is_array($configData)) { |
|
| 191 | 191 | throw new OCSBadRequestException('configData is not properly set'); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | $configKeys = $configuration->getConfigTranslationArray(); |
| 196 | 196 | |
| 197 | 197 | foreach ($configKeys as $i => $key) { |
| 198 | - if(isset($configData[$key])) { |
|
| 198 | + if (isset($configData[$key])) { |
|
| 199 | 199 | $configuration->$key = $configData[$key]; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $configuration->saveConfiguration(); |
| 204 | - } catch(OCSException $e) { |
|
| 204 | + } catch (OCSException $e) { |
|
| 205 | 205 | throw $e; |
| 206 | 206 | } catch (\Exception $e) { |
| 207 | 207 | $this->logger->logException($e); |
@@ -288,16 +288,16 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | $config = new Configuration($configID); |
| 290 | 290 | $data = $config->getConfiguration(); |
| 291 | - if(!boolval(intval($showPassword))) { |
|
| 291 | + if (!boolval(intval($showPassword))) { |
|
| 292 | 292 | $data['ldapAgentPassword'] = '***'; |
| 293 | 293 | } |
| 294 | 294 | foreach ($data as $key => $value) { |
| 295 | - if(is_array($value)) { |
|
| 295 | + if (is_array($value)) { |
|
| 296 | 296 | $value = implode(';', $value); |
| 297 | 297 | $data[$key] = $value; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | - } catch(OCSException $e) { |
|
| 300 | + } catch (OCSException $e) { |
|
| 301 | 301 | throw $e; |
| 302 | 302 | } catch (\Exception $e) { |
| 303 | 303 | $this->logger->logException($e); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | private function ensureConfigIDExists($configID) { |
| 317 | 317 | $prefixes = $this->ldapHelper->getServerConfigurationPrefixes(); |
| 318 | - if(!in_array($configID, $prefixes, true)) { |
|
| 318 | + if (!in_array($configID, $prefixes, true)) { |
|
| 319 | 319 | throw new OCSNotFoundException('Config ID not found'); |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | static private $groupBE; |
| 47 | 47 | |
| 48 | - public function __construct(){ |
|
| 48 | + public function __construct() { |
|
| 49 | 49 | $this->interval = self::getRefreshInterval(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @param mixed $argument |
| 54 | 54 | */ |
| 55 | - public function run($argument){ |
|
| 55 | + public function run($argument) { |
|
| 56 | 56 | self::updateGroups(); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $knownGroups = array_keys(self::getKnownGroups()); |
| 63 | 63 | $actualGroups = self::getGroupBE()->getGroups(); |
| 64 | 64 | |
| 65 | - if(empty($actualGroups) && empty($knownGroups)) { |
|
| 65 | + if (empty($actualGroups) && empty($knownGroups)) { |
|
| 66 | 66 | \OCP\Util::writeLog('user_ldap', |
| 67 | 67 | 'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.', |
| 68 | 68 | \OCP\Util::INFO); |
@@ -94,26 +94,26 @@ discard block |
||
| 94 | 94 | SET `owncloudusers` = ? |
| 95 | 95 | WHERE `owncloudname` = ? |
| 96 | 96 | '); |
| 97 | - foreach($groups as $group) { |
|
| 97 | + foreach ($groups as $group) { |
|
| 98 | 98 | //we assume, that self::$groupsFromDB has been retrieved already |
| 99 | 99 | $knownUsers = unserialize(self::$groupsFromDB[$group]['owncloudusers']); |
| 100 | 100 | $actualUsers = self::getGroupBE()->usersInGroup($group); |
| 101 | 101 | $hasChanged = false; |
| 102 | - foreach(array_diff($knownUsers, $actualUsers) as $removedUser) { |
|
| 102 | + foreach (array_diff($knownUsers, $actualUsers) as $removedUser) { |
|
| 103 | 103 | \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group)); |
| 104 | 104 | \OCP\Util::writeLog('user_ldap', |
| 105 | 105 | 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', |
| 106 | 106 | \OCP\Util::INFO); |
| 107 | 107 | $hasChanged = true; |
| 108 | 108 | } |
| 109 | - foreach(array_diff($actualUsers, $knownUsers) as $addedUser) { |
|
| 109 | + foreach (array_diff($actualUsers, $knownUsers) as $addedUser) { |
|
| 110 | 110 | \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group)); |
| 111 | 111 | \OCP\Util::writeLog('user_ldap', |
| 112 | 112 | 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', |
| 113 | 113 | \OCP\Util::INFO); |
| 114 | 114 | $hasChanged = true; |
| 115 | 115 | } |
| 116 | - if($hasChanged) { |
|
| 116 | + if ($hasChanged) { |
|
| 117 | 117 | $query->execute(array(serialize($actualUsers), $group)); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`) |
| 133 | 133 | VALUES (?, ?) |
| 134 | 134 | '); |
| 135 | - foreach($createdGroups as $createdGroup) { |
|
| 135 | + foreach ($createdGroups as $createdGroup) { |
|
| 136 | 136 | \OCP\Util::writeLog('user_ldap', |
| 137 | 137 | 'bgJ "updateGroups" – new group "'.$createdGroup.'" found.', |
| 138 | 138 | \OCP\Util::INFO); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | FROM `*PREFIX*ldap_group_members` |
| 155 | 155 | WHERE `owncloudname` = ? |
| 156 | 156 | '); |
| 157 | - foreach($removedGroups as $removedGroup) { |
|
| 157 | + foreach ($removedGroups as $removedGroup) { |
|
| 158 | 158 | \OCP\Util::writeLog('user_ldap', |
| 159 | 159 | 'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.', |
| 160 | 160 | \OCP\Util::INFO); |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | * @return \OCA\User_LDAP\Group_LDAP|\OCA\User_LDAP\Group_Proxy |
| 170 | 170 | */ |
| 171 | 171 | static private function getGroupBE() { |
| 172 | - if(!is_null(self::$groupBE)) { |
|
| 172 | + if (!is_null(self::$groupBE)) { |
|
| 173 | 173 | return self::$groupBE; |
| 174 | 174 | } |
| 175 | 175 | $helper = new Helper(\OC::$server->getConfig()); |
| 176 | 176 | $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
| 177 | 177 | $ldapWrapper = new LDAP(); |
| 178 | - if(count($configPrefixes) === 1) { |
|
| 178 | + if (count($configPrefixes) === 1) { |
|
| 179 | 179 | //avoid the proxy when there is only one LDAP server configured |
| 180 | 180 | $dbc = \OC::$server->getDatabaseConnection(); |
| 181 | 181 | $userManager = new Manager( |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | static private function getKnownGroups() { |
| 207 | - if(is_array(self::$groupsFromDB)) { |
|
| 207 | + if (is_array(self::$groupsFromDB)) { |
|
| 208 | 208 | return self::$groupsFromDB; |
| 209 | 209 | } |
| 210 | 210 | $query = \OCP\DB::prepare(' |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | '); |
| 214 | 214 | $result = $query->execute()->fetchAll(); |
| 215 | 215 | self::$groupsFromDB = array(); |
| 216 | - foreach($result as $dataset) { |
|
| 216 | + foreach ($result as $dataset) { |
|
| 217 | 217 | self::$groupsFromDB[$dataset['owncloudname']] = $dataset; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param array|string $values |
| 53 | 53 | */ |
| 54 | 54 | public function addOptions($key, $values) { |
| 55 | - if(!is_array($values)) { |
|
| 55 | + if (!is_array($values)) { |
|
| 56 | 56 | $values = array($values); |
| 57 | 57 | } |
| 58 | 58 | $this->options[$key] = $values; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | public function getResultArray() { |
| 72 | 72 | $result = array(); |
| 73 | 73 | $result['changes'] = $this->changes; |
| 74 | - if(count($this->options) > 0) { |
|
| 74 | + if (count($this->options) > 0) { |
|
| 75 | 75 | $result['options'] = $this->options; |
| 76 | 76 | } |
| 77 | 77 | return $result; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function run(IOutput $output) { |
| 73 | 73 | $installedVersion = $this->config->getAppValue('user_ldap', 'installed_version', '1.2.1'); |
| 74 | - if(version_compare($installedVersion, '1.2.1') !== -1) { |
|
| 74 | + if (version_compare($installedVersion, '1.2.1') !== -1) { |
|
| 75 | 75 | return; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | do { |
| 83 | 83 | $retry = false; |
| 84 | 84 | $records = $mapper->getList($offset, $batchSize); |
| 85 | - if(count($records) === 0){ |
|
| 85 | + if (count($records) === 0) { |
|
| 86 | 86 | continue; |
| 87 | 87 | } |
| 88 | 88 | try { |
| 89 | 89 | $this->jobList->add($jobClass, ['records' => $records]); |
| 90 | 90 | $offset += $batchSize; |
| 91 | 91 | } catch (\InvalidArgumentException $e) { |
| 92 | - if(strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
| 92 | + if (strpos($e->getMessage(), 'Background job arguments can\'t exceed 4000') !== false) { |
|
| 93 | 93 | $batchSize = intval(floor(count($records) * 0.8)); |
| 94 | 94 | $retry = true; |
| 95 | 95 | } |
@@ -38,14 +38,14 @@ |
||
| 38 | 38 | |
| 39 | 39 | public function run($argument) { |
| 40 | 40 | $isUser = $this->proxy instanceof User_Proxy; |
| 41 | - foreach($argument['records'] as $record) { |
|
| 41 | + foreach ($argument['records'] as $record) { |
|
| 42 | 42 | $access = $this->proxy->getLDAPAccess($record['name']); |
| 43 | 43 | $uuid = $access->getUUID($record['dn'], $isUser); |
| 44 | - if($uuid === false) { |
|
| 44 | + if ($uuid === false) { |
|
| 45 | 45 | // record not found, no prob, continue with the next |
| 46 | 46 | continue; |
| 47 | 47 | } |
| 48 | - if($uuid !== $record['uuid']) { |
|
| 48 | + if ($uuid !== $record['uuid']) { |
|
| 49 | 49 | $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
| 50 | 50 | } |
| 51 | 51 | } |