@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | $helper = new Helper(\OC::$server->getConfig()); |
51 | 51 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
52 | 52 | $configID = $input->getArgument('configID'); |
53 | - if(!in_array($configID, $availableConfigs)) { |
|
53 | + if (!in_array($configID, $availableConfigs)) { |
|
54 | 54 | $output->writeln("Invalid configID"); |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $result = $this->testConfig($configID); |
59 | - if($result === 0) { |
|
59 | + if ($result === 0) { |
|
60 | 60 | $output->writeln('The configuration is valid and the connection could be established!'); |
61 | - } else if($result === 1) { |
|
61 | + } else if ($result === 1) { |
|
62 | 62 | $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
63 | - } else if($result === 2) { |
|
63 | + } else if ($result === 2) { |
|
64 | 64 | $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
65 | 65 | } else { |
66 | 66 | $output->writeln('Your LDAP server was kidnapped by aliens.'); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | //ensure validation is run before we attempt the bind |
80 | 80 | $connection->getConfiguration(); |
81 | 81 | |
82 | - if(!$connection->setConfiguration(array( |
|
82 | + if (!$connection->setConfiguration(array( |
|
83 | 83 | 'ldap_configuration_active' => 1, |
84 | 84 | ))) { |
85 | 85 | return 1; |
86 | 86 | } |
87 | - if($connection->bind()) { |
|
87 | + if ($connection->bind()) { |
|
88 | 88 | return 0; |
89 | 89 | } |
90 | 90 | return 2; |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $helper = new Helper(\OC::$server->getConfig()); |
61 | 61 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
62 | 62 | $configID = $input->getArgument('configID'); |
63 | - if(!in_array($configID, $availableConfigs)) { |
|
63 | + if (!in_array($configID, $availableConfigs)) { |
|
64 | 64 | $output->writeln("Invalid configID"); |
65 | 65 | return; |
66 | 66 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | 'Dir', 'Sharer')); |
72 | 72 | $rows = array(); |
73 | 73 | $resultSet = $this->dui->getUsers(); |
74 | - foreach($resultSet as $user) { |
|
74 | + foreach ($resultSet as $user) { |
|
75 | 75 | $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
76 | 76 | $lastLogin = ($user->getLastLogin() > 0) ? |
77 | 77 | $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
@@ -63,9 +63,9 @@ |
||
63 | 63 | $configHolder->saveConfiguration(); |
64 | 64 | |
65 | 65 | $prose = ''; |
66 | - if(!$input->getOption('only-print-prefix')) { |
|
66 | + if (!$input->getOption('only-print-prefix')) { |
|
67 | 67 | $prose = 'Created new configuration with configID '; |
68 | 68 | } |
69 | - $output->writeln($prose . "{$configPrefix}"); |
|
69 | + $output->writeln($prose."{$configPrefix}"); |
|
70 | 70 | } |
71 | 71 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | protected function execute(InputInterface $input, OutputInterface $output) { |
68 | 68 | $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
69 | 69 | $configID = $input->getArgument('configID'); |
70 | - if(!is_null($configID)) { |
|
70 | + if (!is_null($configID)) { |
|
71 | 71 | $configIDs[] = $configID; |
72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
72 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
73 | 73 | $output->writeln("Invalid configID"); |
74 | 74 | return; |
75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
88 | 88 | */ |
89 | 89 | protected function renderConfigs($configIDs, $output, $withPassword) { |
90 | - foreach($configIDs as $id) { |
|
90 | + foreach ($configIDs as $id) { |
|
91 | 91 | $configHolder = new Configuration($id); |
92 | 92 | $configuration = $configHolder->getConfiguration(); |
93 | 93 | ksort($configuration); |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | $table = new Table($output); |
96 | 96 | $table->setHeaders(array('Configuration', $id)); |
97 | 97 | $rows = array(); |
98 | - foreach($configuration as $key => $value) { |
|
99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
98 | + foreach ($configuration as $key => $value) { |
|
99 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
100 | 100 | $value = '***'; |
101 | 101 | } |
102 | - if(is_array($value)) { |
|
102 | + if (is_array($value)) { |
|
103 | 103 | $value = implode(';', $value); |
104 | 104 | } |
105 | 105 | $rows[] = array($key, $value); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function __construct($configPrefix, $autoRead = true) { |
103 | 103 | $this->configPrefix = $configPrefix; |
104 | - if($autoRead) { |
|
104 | + if ($autoRead) { |
|
105 | 105 | $this->readConfiguration(); |
106 | 106 | } |
107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return mixed|null |
112 | 112 | */ |
113 | 113 | public function __get($name) { |
114 | - if(isset($this->config[$name])) { |
|
114 | + if (isset($this->config[$name])) { |
|
115 | 115 | return $this->config[$name]; |
116 | 116 | } |
117 | 117 | return null; |
@@ -142,22 +142,22 @@ discard block |
||
142 | 142 | * @return false|null |
143 | 143 | */ |
144 | 144 | public function setConfiguration($config, &$applied = null) { |
145 | - if(!is_array($config)) { |
|
145 | + if (!is_array($config)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $cta = $this->getConfigTranslationArray(); |
150 | - foreach($config as $inputKey => $val) { |
|
151 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
150 | + foreach ($config as $inputKey => $val) { |
|
151 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
152 | 152 | $key = $cta[$inputKey]; |
153 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
153 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
154 | 154 | $key = $inputKey; |
155 | 155 | } else { |
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $setMethod = 'setValue'; |
160 | - switch($key) { |
|
160 | + switch ($key) { |
|
161 | 161 | case 'ldapAgentPassword': |
162 | 162 | $setMethod = 'setRawValue'; |
163 | 163 | break; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | break; |
182 | 182 | } |
183 | 183 | $this->$setMethod($key, $val); |
184 | - if(is_array($applied)) { |
|
184 | + if (is_array($applied)) { |
|
185 | 185 | $applied[] = $inputKey; |
186 | 186 | } |
187 | 187 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | public function readConfiguration() { |
192 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
192 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
193 | 193 | $cta = array_flip($this->getConfigTranslationArray()); |
194 | - foreach($this->config as $key => $val) { |
|
195 | - if(!isset($cta[$key])) { |
|
194 | + foreach ($this->config as $key => $val) { |
|
195 | + if (!isset($cta[$key])) { |
|
196 | 196 | //some are determined |
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | $dbKey = $cta[$key]; |
200 | - switch($key) { |
|
200 | + switch ($key) { |
|
201 | 201 | case 'ldapBase': |
202 | 202 | case 'ldapBaseUsers': |
203 | 203 | case 'ldapBaseGroups': |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function saveConfiguration() { |
242 | 242 | $cta = array_flip($this->getConfigTranslationArray()); |
243 | - foreach($this->config as $key => $value) { |
|
243 | + foreach ($this->config as $key => $value) { |
|
244 | 244 | switch ($key) { |
245 | 245 | case 'ldapAgentPassword': |
246 | 246 | $value = base64_encode($value); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | case 'ldapGroupFilterObjectclass': |
256 | 256 | case 'ldapGroupFilterGroups': |
257 | 257 | case 'ldapLoginFilterAttributes': |
258 | - if(is_array($value)) { |
|
258 | + if (is_array($value)) { |
|
259 | 259 | $value = implode("\n", $value); |
260 | 260 | } |
261 | 261 | break; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | case 'ldapUuidGroupAttribute': |
267 | 267 | continue 2; |
268 | 268 | } |
269 | - if(is_null($value)) { |
|
269 | + if (is_null($value)) { |
|
270 | 270 | $value = ''; |
271 | 271 | } |
272 | 272 | $this->saveValue($cta[$key], $value); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function getMultiLine($varName) { |
281 | 281 | $value = $this->getValue($varName); |
282 | - if(empty($value)) { |
|
282 | + if (empty($value)) { |
|
283 | 283 | $value = ''; |
284 | 284 | } else { |
285 | 285 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | * @param array|string $value to set |
296 | 296 | */ |
297 | 297 | protected function setMultiLine($varName, $value) { |
298 | - if(empty($value)) { |
|
298 | + if (empty($value)) { |
|
299 | 299 | $value = ''; |
300 | 300 | } else if (!is_array($value)) { |
301 | 301 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
302 | - if($value === false) { |
|
302 | + if ($value === false) { |
|
303 | 303 | $value = ''; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if(!is_array($value)) { |
|
307 | + if (!is_array($value)) { |
|
308 | 308 | $finalValue = trim($value); |
309 | 309 | } else { |
310 | 310 | $finalValue = []; |
311 | - foreach($value as $key => $val) { |
|
312 | - if(is_string($val)) { |
|
311 | + foreach ($value as $key => $val) { |
|
312 | + if (is_string($val)) { |
|
313 | 313 | $val = trim($val); |
314 | 314 | if ($val !== '') { |
315 | 315 | //accidental line breaks are not wanted and can cause |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | protected function getValue($varName) { |
358 | 358 | static $defaults; |
359 | - if(is_null($defaults)) { |
|
359 | + if (is_null($defaults)) { |
|
360 | 360 | $defaults = $this->getDefaults(); |
361 | 361 | } |
362 | 362 | return \OCP\Config::getAppValue('user_ldap', |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param mixed $value to set |
372 | 372 | */ |
373 | 373 | protected function setValue($varName, $value) { |
374 | - if(is_string($value)) { |
|
374 | + if (is_string($value)) { |
|
375 | 375 | $value = trim($value); |
376 | 376 | } |
377 | 377 | $this->config[$varName] = $value; |
@@ -62,7 +62,7 @@ |
||
62 | 62 | // assign default values |
63 | 63 | $config = new Configuration('', false); |
64 | 64 | $defaults = $config->getDefaults(); |
65 | - foreach($defaults as $key => $default) { |
|
65 | + foreach ($defaults as $key => $default) { |
|
66 | 66 | $parameters[$key.'_default'] = $default; |
67 | 67 | } |
68 | 68 |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $this->configuration = new Configuration($configPrefix, |
88 | 88 | !is_null($configID)); |
89 | 89 | $memcache = \OC::$server->getMemCacheFactory(); |
90 | - if($memcache->isAvailable()) { |
|
90 | + if ($memcache->isAvailable()) { |
|
91 | 91 | $this->cache = $memcache->create(); |
92 | 92 | } |
93 | 93 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | public function __destruct() { |
102 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
102 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
103 | 103 | @$this->ldap->unbind($this->ldapConnectionRes); |
104 | 104 | }; |
105 | 105 | } |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @return bool|mixed|void |
120 | 120 | */ |
121 | 121 | public function __get($name) { |
122 | - if(!$this->configured) { |
|
122 | + if (!$this->configured) { |
|
123 | 123 | $this->readConfiguration(); |
124 | 124 | } |
125 | 125 | |
126 | - if($name === 'hasPagedResultSupport') { |
|
126 | + if ($name === 'hasPagedResultSupport') { |
|
127 | 127 | return $this->hasPagedResultSupport; |
128 | 128 | } |
129 | 129 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $before = $this->configuration->$name; |
140 | 140 | $this->configuration->$name = $value; |
141 | 141 | $after = $this->configuration->$name; |
142 | - if($before !== $after) { |
|
142 | + if ($before !== $after) { |
|
143 | 143 | if ($this->configID !== '') { |
144 | 144 | $this->configuration->saveConfiguration(); |
145 | 145 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param bool $state |
155 | 155 | */ |
156 | 156 | public function setIgnoreValidation($state) { |
157 | - $this->ignoreValidation = (bool)$state; |
|
157 | + $this->ignoreValidation = (bool) $state; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | * Returns the LDAP handler |
171 | 171 | */ |
172 | 172 | public function getConnectionResource() { |
173 | - if(!$this->ldapConnectionRes) { |
|
173 | + if (!$this->ldapConnectionRes) { |
|
174 | 174 | $this->init(); |
175 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
175 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
176 | 176 | $this->ldapConnectionRes = null; |
177 | 177 | $this->establishConnection(); |
178 | 178 | } |
179 | - if(is_null($this->ldapConnectionRes)) { |
|
180 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
179 | + if (is_null($this->ldapConnectionRes)) { |
|
180 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
181 | 181 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
182 | 182 | } |
183 | 183 | return $this->ldapConnectionRes; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * resets the connection resource |
188 | 188 | */ |
189 | 189 | public function resetConnectionResource() { |
190 | - if(!is_null($this->ldapConnectionRes)) { |
|
190 | + if (!is_null($this->ldapConnectionRes)) { |
|
191 | 191 | @$this->ldap->unbind($this->ldapConnectionRes); |
192 | 192 | $this->ldapConnectionRes = null; |
193 | 193 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private function getCacheKey($key) { |
201 | 201 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
202 | - if(is_null($key)) { |
|
202 | + if (is_null($key)) { |
|
203 | 203 | return $prefix; |
204 | 204 | } |
205 | 205 | return $prefix.md5($key); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @return mixed|null |
211 | 211 | */ |
212 | 212 | public function getFromCache($key) { |
213 | - if(!$this->configured) { |
|
213 | + if (!$this->configured) { |
|
214 | 214 | $this->readConfiguration(); |
215 | 215 | } |
216 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
216 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
217 | 217 | return null; |
218 | 218 | } |
219 | 219 | $key = $this->getCacheKey($key); |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * @return string |
229 | 229 | */ |
230 | 230 | public function writeToCache($key, $value) { |
231 | - if(!$this->configured) { |
|
231 | + if (!$this->configured) { |
|
232 | 232 | $this->readConfiguration(); |
233 | 233 | } |
234 | - if(is_null($this->cache) |
|
234 | + if (is_null($this->cache) |
|
235 | 235 | || !$this->configuration->ldapCacheTTL |
236 | 236 | || !$this->configuration->ldapConfigurationActive) { |
237 | 237 | return null; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | public function clearCache() { |
245 | - if(!is_null($this->cache)) { |
|
245 | + if (!is_null($this->cache)) { |
|
246 | 246 | $this->cache->clear($this->getCacheKey(null)); |
247 | 247 | } |
248 | 248 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @return null |
255 | 255 | */ |
256 | 256 | private function readConfiguration($force = false) { |
257 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
257 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
258 | 258 | $this->configuration->readConfiguration(); |
259 | 259 | $this->configured = $this->validateConfiguration(); |
260 | 260 | } |
@@ -267,12 +267,12 @@ discard block |
||
267 | 267 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
268 | 268 | */ |
269 | 269 | public function setConfiguration($config, &$setParameters = null) { |
270 | - if(is_null($setParameters)) { |
|
270 | + if (is_null($setParameters)) { |
|
271 | 271 | $setParameters = array(); |
272 | 272 | } |
273 | 273 | $this->doNotValidate = false; |
274 | 274 | $this->configuration->setConfiguration($config, $setParameters); |
275 | - if(count($setParameters) > 0) { |
|
275 | + if (count($setParameters) > 0) { |
|
276 | 276 | $this->configured = $this->validateConfiguration(); |
277 | 277 | } |
278 | 278 | |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | $config = $this->configuration->getConfiguration(); |
300 | 300 | $cta = $this->configuration->getConfigTranslationArray(); |
301 | 301 | $result = array(); |
302 | - foreach($cta as $dbkey => $configkey) { |
|
303 | - switch($configkey) { |
|
302 | + foreach ($cta as $dbkey => $configkey) { |
|
303 | + switch ($configkey) { |
|
304 | 304 | case 'homeFolderNamingRule': |
305 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
305 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
306 | 306 | $result[$dbkey] = substr($config[$configkey], 5); |
307 | 307 | } else { |
308 | 308 | $result[$dbkey] = ''; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | case 'ldapBaseGroups': |
314 | 314 | case 'ldapAttributesForUserSearch': |
315 | 315 | case 'ldapAttributesForGroupSearch': |
316 | - if(is_array($config[$configkey])) { |
|
316 | + if (is_array($config[$configkey])) { |
|
317 | 317 | $result[$dbkey] = implode("\n", $config[$configkey]); |
318 | 318 | break; |
319 | 319 | } //else follows default |
@@ -326,23 +326,23 @@ discard block |
||
326 | 326 | |
327 | 327 | private function doSoftValidation() { |
328 | 328 | //if User or Group Base are not set, take over Base DN setting |
329 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
329 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
330 | 330 | $val = $this->configuration->$keyBase; |
331 | - if(empty($val)) { |
|
331 | + if (empty($val)) { |
|
332 | 332 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
336 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
337 | 337 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
338 | 338 | as $expertSetting => $effectiveSetting) { |
339 | 339 | $uuidOverride = $this->configuration->$expertSetting; |
340 | - if(!empty($uuidOverride)) { |
|
340 | + if (!empty($uuidOverride)) { |
|
341 | 341 | $this->configuration->$effectiveSetting = $uuidOverride; |
342 | 342 | } else { |
343 | 343 | $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
344 | 344 | 'objectguid', 'guid', 'ipauniqueid'); |
345 | - if(!in_array($this->configuration->$effectiveSetting, |
|
345 | + if (!in_array($this->configuration->$effectiveSetting, |
|
346 | 346 | $uuidAttributes) |
347 | 347 | && (!is_null($this->configID))) { |
348 | 348 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -364,14 +364,14 @@ discard block |
||
364 | 364 | //make sure empty search attributes are saved as simple, empty array |
365 | 365 | $saKeys = array('ldapAttributesForUserSearch', |
366 | 366 | 'ldapAttributesForGroupSearch'); |
367 | - foreach($saKeys as $key) { |
|
367 | + foreach ($saKeys as $key) { |
|
368 | 368 | $val = $this->configuration->$key; |
369 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
369 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
370 | 370 | $this->configuration->$key = array(); |
371 | 371 | } |
372 | 372 | } |
373 | 373 | |
374 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
374 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
375 | 375 | && $this->configuration->ldapTLS) { |
376 | 376 | $this->configuration->ldapTLS = false; |
377 | 377 | \OCP\Util::writeLog('user_ldap', |
@@ -392,10 +392,10 @@ discard block |
||
392 | 392 | //options that shall not be empty |
393 | 393 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
394 | 394 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
395 | - foreach($options as $key) { |
|
395 | + foreach ($options as $key) { |
|
396 | 396 | $val = $this->configuration->$key; |
397 | - if(empty($val)) { |
|
398 | - switch($key) { |
|
397 | + if (empty($val)) { |
|
398 | + switch ($key) { |
|
399 | 399 | case 'ldapHost': |
400 | 400 | $subj = 'LDAP Host'; |
401 | 401 | break; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | $agent = $this->configuration->ldapAgentName; |
427 | 427 | $pwd = $this->configuration->ldapAgentPassword; |
428 | 428 | if ( |
429 | - ($agent === '' && $pwd !== '') |
|
429 | + ($agent === '' && $pwd !== '') |
|
430 | 430 | || ($agent !== '' && $pwd === '') |
431 | 431 | ) { |
432 | 432 | \OCP\Util::writeLog('user_ldap', |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | $baseUsers = $this->configuration->ldapBaseUsers; |
442 | 442 | $baseGroups = $this->configuration->ldapBaseGroups; |
443 | 443 | |
444 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
444 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
445 | 445 | \OCP\Util::writeLog('user_ldap', |
446 | 446 | $errorStr.'Not a single Base DN given.', |
447 | 447 | \OCP\Util::WARN); |
448 | 448 | $configurationOK = false; |
449 | 449 | } |
450 | 450 | |
451 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
451 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
452 | 452 | === false) { |
453 | 453 | \OCP\Util::writeLog('user_ldap', |
454 | 454 | $errorStr.'login filter does not contain %uid '. |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | */ |
467 | 467 | private function validateConfiguration() { |
468 | 468 | |
469 | - if($this->doNotValidate) { |
|
469 | + if ($this->doNotValidate) { |
|
470 | 470 | //don't do a validation if it is a new configuration with pure |
471 | 471 | //default values. Will be allowed on changes via __set or |
472 | 472 | //setConfiguration |
@@ -487,21 +487,21 @@ discard block |
||
487 | 487 | * Connects and Binds to LDAP |
488 | 488 | */ |
489 | 489 | private function establishConnection() { |
490 | - if(!$this->configuration->ldapConfigurationActive) { |
|
490 | + if (!$this->configuration->ldapConfigurationActive) { |
|
491 | 491 | return null; |
492 | 492 | } |
493 | 493 | static $phpLDAPinstalled = true; |
494 | - if(!$phpLDAPinstalled) { |
|
494 | + if (!$phpLDAPinstalled) { |
|
495 | 495 | return false; |
496 | 496 | } |
497 | - if(!$this->ignoreValidation && !$this->configured) { |
|
497 | + if (!$this->ignoreValidation && !$this->configured) { |
|
498 | 498 | \OCP\Util::writeLog('user_ldap', |
499 | 499 | 'Configuration is invalid, cannot connect', |
500 | 500 | \OCP\Util::WARN); |
501 | 501 | return false; |
502 | 502 | } |
503 | - if(!$this->ldapConnectionRes) { |
|
504 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
503 | + if (!$this->ldapConnectionRes) { |
|
504 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
505 | 505 | $phpLDAPinstalled = false; |
506 | 506 | \OCP\Util::writeLog('user_ldap', |
507 | 507 | 'function ldap_connect is not available. Make '. |
@@ -510,8 +510,8 @@ discard block |
||
510 | 510 | |
511 | 511 | return false; |
512 | 512 | } |
513 | - if($this->configuration->turnOffCertCheck) { |
|
514 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
513 | + if ($this->configuration->turnOffCertCheck) { |
|
514 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
515 | 515 | \OCP\Util::writeLog('user_ldap', |
516 | 516 | 'Turned off SSL certificate validation successfully.', |
517 | 517 | \OCP\Util::DEBUG); |
@@ -534,24 +534,24 @@ discard block |
||
534 | 534 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
535 | 535 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
536 | 536 | } |
537 | - if($bindStatus === true) { |
|
537 | + if ($bindStatus === true) { |
|
538 | 538 | return $bindStatus; |
539 | 539 | } |
540 | 540 | } catch (\OC\ServerNotAvailableException $e) { |
541 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
541 | + if (trim($this->configuration->ldapBackupHost) === "") { |
|
542 | 542 | throw $e; |
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
546 | 546 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
547 | - if( $error !== 0 |
|
547 | + if ($error !== 0 |
|
548 | 548 | || $this->configuration->ldapOverrideMainServer |
549 | 549 | || $this->getFromCache('overrideMainServer')) |
550 | 550 | { |
551 | 551 | $this->doConnect($this->configuration->ldapBackupHost, |
552 | 552 | $this->configuration->ldapBackupPort); |
553 | 553 | $bindStatus = $this->bind(); |
554 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
554 | + if ($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
555 | 555 | //when bind to backup server succeeded and failed to main server, |
556 | 556 | //skip contacting him until next cache refresh |
557 | 557 | $this->writeToCache('overrideMainServer', true); |
@@ -573,9 +573,9 @@ discard block |
||
573 | 573 | return false; |
574 | 574 | } |
575 | 575 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
576 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
577 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
578 | - if($this->configuration->ldapTLS) { |
|
576 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
577 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
578 | + if ($this->configuration->ldapTLS) { |
|
579 | 579 | $this->ldap->startTls($this->ldapConnectionRes); |
580 | 580 | } |
581 | 581 | } |
@@ -590,25 +590,25 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function bind() { |
592 | 592 | static $getConnectionResourceAttempt = false; |
593 | - if(!$this->configuration->ldapConfigurationActive) { |
|
593 | + if (!$this->configuration->ldapConfigurationActive) { |
|
594 | 594 | return false; |
595 | 595 | } |
596 | - if($getConnectionResourceAttempt) { |
|
596 | + if ($getConnectionResourceAttempt) { |
|
597 | 597 | $getConnectionResourceAttempt = false; |
598 | 598 | return false; |
599 | 599 | } |
600 | 600 | $getConnectionResourceAttempt = true; |
601 | 601 | $cr = $this->getConnectionResource(); |
602 | 602 | $getConnectionResourceAttempt = false; |
603 | - if(!$this->ldap->isResource($cr)) { |
|
603 | + if (!$this->ldap->isResource($cr)) { |
|
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | $ldapLogin = @$this->ldap->bind($cr, |
607 | 607 | $this->configuration->ldapAgentName, |
608 | 608 | $this->configuration->ldapAgentPassword); |
609 | - if(!$ldapLogin) { |
|
609 | + if (!$ldapLogin) { |
|
610 | 610 | \OCP\Util::writeLog('user_ldap', |
611 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
611 | + 'Bind failed: '.$this->ldap->errno($cr).': '.$this->ldap->error($cr), |
|
612 | 612 | \OCP\Util::WARN); |
613 | 613 | $this->ldapConnectionRes = null; |
614 | 614 | return false; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $this->logger = $serverContainer->getLogger(); |
48 | 48 | $this->helper = $helper; |
49 | 49 | $this->deletedUsersIndex = $deletedUsersIndex; |
50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend) { |
|
51 | 51 | $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
52 | 52 | if ($backend instanceof IUserLDAP) { |
53 | 53 | $this->backend = $backend; |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @throws \Exception if translation was unsuccessful |
65 | 65 | */ |
66 | 66 | public function getUserDN($uid) { |
67 | - if(!$this->backend->userExists($uid)){ |
|
67 | + if (!$this->backend->userExists($uid)) { |
|
68 | 68 | throw new \Exception('User id not found in LDAP'); |
69 | 69 | } |
70 | 70 | $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
71 | - if(!$result){ |
|
71 | + if (!$result) { |
|
72 | 72 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
73 | 73 | } |
74 | 74 | return $result; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getUserName($dn) { |
85 | 85 | $result = $this->backend->dn2UserName($dn); |
86 | - if(!$result){ |
|
86 | + if (!$result) { |
|
87 | 87 | throw new \Exception('Translation to internal user name unsuccessful'); |
88 | 88 | } |
89 | 89 | return $result; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @throws \Exception if user id was not found in LDAP |
116 | 116 | */ |
117 | 117 | public function getLDAPConnection($uid) { |
118 | - if(!$this->backend->userExists($uid)){ |
|
118 | + if (!$this->backend->userExists($uid)) { |
|
119 | 119 | throw new \Exception('User id not found in LDAP'); |
120 | 120 | } |
121 | 121 | return $this->backend->getNewLDAPConnection($uid); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @throws \Exception if user id was not found in LDAP |
129 | 129 | */ |
130 | 130 | public function getLDAPBaseUsers($uid) { |
131 | - if(!$this->backend->userExists($uid)){ |
|
131 | + if (!$this->backend->userExists($uid)) { |
|
132 | 132 | throw new \Exception('User id not found in LDAP'); |
133 | 133 | } |
134 | 134 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @throws \Exception if user id was not found in LDAP |
142 | 142 | */ |
143 | 143 | public function getLDAPBaseGroups($uid) { |
144 | - if(!$this->backend->userExists($uid)){ |
|
144 | + if (!$this->backend->userExists($uid)) { |
|
145 | 145 | throw new \Exception('User id not found in LDAP'); |
146 | 146 | } |
147 | 147 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @throws \Exception if user id was not found in LDAP |
154 | 154 | */ |
155 | 155 | public function clearCache($uid) { |
156 | - if(!$this->backend->userExists($uid)){ |
|
156 | + if (!$this->backend->userExists($uid)) { |
|
157 | 157 | throw new \Exception('User id not found in LDAP'); |
158 | 158 | } |
159 | 159 | $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |