@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <fieldset id="ldapWizard1"> |
2 | 2 | <p> |
3 | 3 | <select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser"> |
4 | - <?php if(count($_['serverConfigurationPrefixes']) === 0 ) { |
|
4 | + <?php if (count($_['serverConfigurationPrefixes']) === 0) { |
|
5 | 5 | ?> |
6 | - <option value="" selected><?php p($l->t('1. Server'));?></option>'); |
|
6 | + <option value="" selected><?php p($l->t('1. Server')); ?></option>'); |
|
7 | 7 | <?php |
8 | 8 | } else { |
9 | 9 | $i = 1; |
10 | 10 | $sel = ' selected'; |
11 | - foreach($_['serverConfigurationPrefixes'] as $prefix) { |
|
11 | + foreach ($_['serverConfigurationPrefixes'] as $prefix) { |
|
12 | 12 | ?> |
13 | - <option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', array($i++)));?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option> |
|
13 | + <option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', array($i++))); ?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option> |
|
14 | 14 | <?php |
15 | 15 | } |
16 | 16 | } |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | </select> |
19 | 19 | <button type="button" id="ldap_action_add_configuration" |
20 | 20 | name="ldap_action_add_configuration" class="icon-add icon-default-style" |
21 | - title="<?php p($l->t('Add a new configuration'));?>"> </button> |
|
21 | + title="<?php p($l->t('Add a new configuration')); ?>"> </button> |
|
22 | 22 | <button type="button" id="ldap_action_copy_configuration" |
23 | 23 | name="ldap_action_copy_configuration" |
24 | 24 | class="ldapIconCopy icon-default-style" |
25 | - title="<?php p($l->t('Copy current configuration into new directory binding'));?>"> </button> |
|
25 | + title="<?php p($l->t('Copy current configuration into new directory binding')); ?>"> </button> |
|
26 | 26 | <button type="button" id="ldap_action_delete_configuration" |
27 | 27 | name="ldap_action_delete_configuration" class="icon-delete icon-default-style" |
28 | - title="<?php p($l->t('Delete the current configuration'));?>"> </button> |
|
28 | + title="<?php p($l->t('Delete the current configuration')); ?>"> </button> |
|
29 | 29 | </p> |
30 | 30 | |
31 | 31 | <div class="hostPortCombinator"> |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | <div class="table"> |
35 | 35 | <input type="text" class="host" id="ldap_host" |
36 | 36 | name="ldap_host" |
37 | - placeholder="<?php p($l->t('Host'));?>" |
|
38 | - title="<?php p($l->t('You can omit the protocol, unless you require SSL. If so, start with ldaps://'));?>" |
|
37 | + placeholder="<?php p($l->t('Host')); ?>" |
|
38 | + title="<?php p($l->t('You can omit the protocol, unless you require SSL. If so, start with ldaps://')); ?>" |
|
39 | 39 | /> |
40 | 40 | <span class="hostPortCombinatorSpan"> |
41 | 41 | <input type="number" id="ldap_port" name="ldap_port" |
42 | - placeholder="<?php p($l->t('Port'));?>" /> |
|
42 | + placeholder="<?php p($l->t('Port')); ?>" /> |
|
43 | 43 | <button class="ldapDetectPort" name="ldapDetectPort" type="button"> |
44 | - <?php p($l->t('Detect Port'));?> |
|
44 | + <?php p($l->t('Detect Port')); ?> |
|
45 | 45 | </button> |
46 | 46 | </span> |
47 | 47 | </div> |
@@ -51,19 +51,19 @@ discard block |
||
51 | 51 | <div class="tablerow"> |
52 | 52 | <input type="text" id="ldap_dn" name="ldap_dn" |
53 | 53 | class="tablecell" |
54 | - placeholder="<?php p($l->t('User DN'));?>" autocomplete="off" |
|
55 | - title="<?php p($l->t('The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.'));?>" |
|
54 | + placeholder="<?php p($l->t('User DN')); ?>" autocomplete="off" |
|
55 | + title="<?php p($l->t('The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.')); ?>" |
|
56 | 56 | /> |
57 | 57 | </div> |
58 | 58 | |
59 | 59 | <div class="tablerow"> |
60 | 60 | <input type="password" id="ldap_agent_password" |
61 | 61 | class="tablecell" name="ldap_agent_password" |
62 | - placeholder="<?php p($l->t('Password'));?>" autocomplete="off" |
|
63 | - title="<?php p($l->t('For anonymous access, leave DN and Password empty.'));?>" |
|
62 | + placeholder="<?php p($l->t('Password')); ?>" autocomplete="off" |
|
63 | + title="<?php p($l->t('For anonymous access, leave DN and Password empty.')); ?>" |
|
64 | 64 | /> |
65 | 65 | <button class="ldapSaveAgentCredentials" name="ldapSaveAgentCredentials" type="button"> |
66 | - <?php p($l->t('Save Credentials'));?> |
|
66 | + <?php p($l->t('Save Credentials')); ?> |
|
67 | 67 | </button> |
68 | 68 | </div> |
69 | 69 | <div class="tablerow"> </div> |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | <div class="tablerow"> |
72 | 72 | <textarea id="ldap_base" name="ldap_base" |
73 | 73 | class="tablecell" |
74 | - placeholder="<?php p($l->t('One Base DN per line'));?>" |
|
75 | - title="<?php p($l->t('You can specify Base DN for users and groups in the Advanced tab'));?>"> |
|
74 | + placeholder="<?php p($l->t('One Base DN per line')); ?>" |
|
75 | + title="<?php p($l->t('You can specify Base DN for users and groups in the Advanced tab')); ?>"> |
|
76 | 76 | </textarea> |
77 | 77 | <button class="ldapDetectBase" name="ldapDetectBase" type="button"> |
78 | - <?php p($l->t('Detect Base DN'));?> |
|
78 | + <?php p($l->t('Detect Base DN')); ?> |
|
79 | 79 | </button> |
80 | 80 | <button class="ldapTestBase" name="ldapTestBase" type="button"> |
81 | - <?php p($l->t('Test Base DN'));?> |
|
81 | + <?php p($l->t('Test Base DN')); ?> |
|
82 | 82 | </button> |
83 | 83 | </div> |
84 | 84 | |
85 | 85 | <div class="tablerow left"> |
86 | 86 | <input type="checkbox" id="ldap_experienced_admin" value="1" |
87 | 87 | name="ldap_experienced_admin" class="tablecell" |
88 | - title="<?php p($l->t('Avoids automatic LDAP requests. Better for bigger setups, but requires some LDAP knowledge.'));?>" |
|
88 | + title="<?php p($l->t('Avoids automatic LDAP requests. Better for bigger setups, but requires some LDAP knowledge.')); ?>" |
|
89 | 89 | /> |
90 | 90 | <label for="ldap_experienced_admin" class="tablecell"> |
91 | - <?php p($l->t('Manually enter LDAP filters (recommended for large directories)'));?> |
|
91 | + <?php p($l->t('Manually enter LDAP filters (recommended for large directories)')); ?> |
|
92 | 92 | </label> |
93 | 93 | </div> |
94 | 94 |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function __construct($configPrefix, $autoRead = true) { |
109 | 109 | $this->configPrefix = $configPrefix; |
110 | - if($autoRead) { |
|
110 | + if ($autoRead) { |
|
111 | 111 | $this->readConfiguration(); |
112 | 112 | } |
113 | 113 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return mixed|null |
118 | 118 | */ |
119 | 119 | public function __get($name) { |
120 | - if(isset($this->config[$name])) { |
|
120 | + if (isset($this->config[$name])) { |
|
121 | 121 | return $this->config[$name]; |
122 | 122 | } |
123 | 123 | return null; |
@@ -148,22 +148,22 @@ discard block |
||
148 | 148 | * @return false|null |
149 | 149 | */ |
150 | 150 | public function setConfiguration($config, &$applied = null) { |
151 | - if(!is_array($config)) { |
|
151 | + if (!is_array($config)) { |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $cta = $this->getConfigTranslationArray(); |
156 | - foreach($config as $inputKey => $val) { |
|
157 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
156 | + foreach ($config as $inputKey => $val) { |
|
157 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
158 | 158 | $key = $cta[$inputKey]; |
159 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
159 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
160 | 160 | $key = $inputKey; |
161 | 161 | } else { |
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | |
165 | 165 | $setMethod = 'setValue'; |
166 | - switch($key) { |
|
166 | + switch ($key) { |
|
167 | 167 | case 'ldapAgentPassword': |
168 | 168 | $setMethod = 'setRawValue'; |
169 | 169 | break; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | break; |
188 | 188 | } |
189 | 189 | $this->$setMethod($key, $val); |
190 | - if(is_array($applied)) { |
|
190 | + if (is_array($applied)) { |
|
191 | 191 | $applied[] = $inputKey; |
192 | 192 | // storing key as index avoids duplication, and as value for simplicity |
193 | 193 | } |
@@ -197,15 +197,15 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | public function readConfiguration() { |
200 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
200 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
201 | 201 | $cta = array_flip($this->getConfigTranslationArray()); |
202 | - foreach($this->config as $key => $val) { |
|
203 | - if(!isset($cta[$key])) { |
|
202 | + foreach ($this->config as $key => $val) { |
|
203 | + if (!isset($cta[$key])) { |
|
204 | 204 | //some are determined |
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | $dbKey = $cta[$key]; |
208 | - switch($key) { |
|
208 | + switch ($key) { |
|
209 | 209 | case 'ldapBase': |
210 | 210 | case 'ldapBaseUsers': |
211 | 211 | case 'ldapBaseGroups': |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function saveConfiguration() { |
250 | 250 | $cta = array_flip($this->getConfigTranslationArray()); |
251 | - foreach($this->unsavedChanges as $key) { |
|
251 | + foreach ($this->unsavedChanges as $key) { |
|
252 | 252 | $value = $this->config[$key]; |
253 | 253 | switch ($key) { |
254 | 254 | case 'ldapAgentPassword': |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | case 'ldapGroupFilterObjectclass': |
265 | 265 | case 'ldapGroupFilterGroups': |
266 | 266 | case 'ldapLoginFilterAttributes': |
267 | - if(is_array($value)) { |
|
267 | + if (is_array($value)) { |
|
268 | 268 | $value = implode("\n", $value); |
269 | 269 | } |
270 | 270 | break; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | case 'ldapUuidGroupAttribute': |
276 | 276 | continue 2; |
277 | 277 | } |
278 | - if(is_null($value)) { |
|
278 | + if (is_null($value)) { |
|
279 | 279 | $value = ''; |
280 | 280 | } |
281 | 281 | $this->saveValue($cta[$key], $value); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | protected function getMultiLine($varName) { |
291 | 291 | $value = $this->getValue($varName); |
292 | - if(empty($value)) { |
|
292 | + if (empty($value)) { |
|
293 | 293 | $value = ''; |
294 | 294 | } else { |
295 | 295 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | * @param array|string $value to set |
306 | 306 | */ |
307 | 307 | protected function setMultiLine($varName, $value) { |
308 | - if(empty($value)) { |
|
308 | + if (empty($value)) { |
|
309 | 309 | $value = ''; |
310 | 310 | } else if (!is_array($value)) { |
311 | 311 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
312 | - if($value === false) { |
|
312 | + if ($value === false) { |
|
313 | 313 | $value = ''; |
314 | 314 | } |
315 | 315 | } |
316 | 316 | |
317 | - if(!is_array($value)) { |
|
317 | + if (!is_array($value)) { |
|
318 | 318 | $finalValue = trim($value); |
319 | 319 | } else { |
320 | 320 | $finalValue = []; |
321 | - foreach($value as $key => $val) { |
|
322 | - if(is_string($val)) { |
|
321 | + foreach ($value as $key => $val) { |
|
322 | + if (is_string($val)) { |
|
323 | 323 | $val = trim($val); |
324 | 324 | if ($val !== '') { |
325 | 325 | //accidental line breaks are not wanted and can cause |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | protected function getValue($varName) { |
368 | 368 | static $defaults; |
369 | - if(is_null($defaults)) { |
|
369 | + if (is_null($defaults)) { |
|
370 | 370 | $defaults = $this->getDefaults(); |
371 | 371 | } |
372 | 372 | return \OCP\Config::getAppValue('user_ldap', |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @param mixed $value to set |
382 | 382 | */ |
383 | 383 | protected function setValue($varName, $value) { |
384 | - if(is_string($value)) { |
|
384 | + if (is_string($value)) { |
|
385 | 385 | $value = trim($value); |
386 | 386 | } |
387 | 387 | $this->config[$varName] = $value; |
@@ -35,501 +35,501 @@ |
||
35 | 35 | * @property int ldapPagingSize holds an integer |
36 | 36 | */ |
37 | 37 | class Configuration { |
38 | - protected $configPrefix = null; |
|
39 | - protected $configRead = false; |
|
40 | - /** |
|
41 | - * @var string[] pre-filled with one reference key so that at least one entry is written on save request and |
|
42 | - * the config ID is registered |
|
43 | - */ |
|
44 | - protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; |
|
38 | + protected $configPrefix = null; |
|
39 | + protected $configRead = false; |
|
40 | + /** |
|
41 | + * @var string[] pre-filled with one reference key so that at least one entry is written on save request and |
|
42 | + * the config ID is registered |
|
43 | + */ |
|
44 | + protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; |
|
45 | 45 | |
46 | - //settings |
|
47 | - protected $config = array( |
|
48 | - 'ldapHost' => null, |
|
49 | - 'ldapPort' => null, |
|
50 | - 'ldapBackupHost' => null, |
|
51 | - 'ldapBackupPort' => null, |
|
52 | - 'ldapBase' => null, |
|
53 | - 'ldapBaseUsers' => null, |
|
54 | - 'ldapBaseGroups' => null, |
|
55 | - 'ldapAgentName' => null, |
|
56 | - 'ldapAgentPassword' => null, |
|
57 | - 'ldapTLS' => null, |
|
58 | - 'turnOffCertCheck' => null, |
|
59 | - 'ldapIgnoreNamingRules' => null, |
|
60 | - 'ldapUserDisplayName' => null, |
|
61 | - 'ldapUserDisplayName2' => null, |
|
62 | - 'ldapGidNumber' => null, |
|
63 | - 'ldapUserFilterObjectclass' => null, |
|
64 | - 'ldapUserFilterGroups' => null, |
|
65 | - 'ldapUserFilter' => null, |
|
66 | - 'ldapUserFilterMode' => null, |
|
67 | - 'ldapGroupFilter' => null, |
|
68 | - 'ldapGroupFilterMode' => null, |
|
69 | - 'ldapGroupFilterObjectclass' => null, |
|
70 | - 'ldapGroupFilterGroups' => null, |
|
71 | - 'ldapGroupDisplayName' => null, |
|
72 | - 'ldapGroupMemberAssocAttr' => null, |
|
73 | - 'ldapLoginFilter' => null, |
|
74 | - 'ldapLoginFilterMode' => null, |
|
75 | - 'ldapLoginFilterEmail' => null, |
|
76 | - 'ldapLoginFilterUsername' => null, |
|
77 | - 'ldapLoginFilterAttributes' => null, |
|
78 | - 'ldapQuotaAttribute' => null, |
|
79 | - 'ldapQuotaDefault' => null, |
|
80 | - 'ldapEmailAttribute' => null, |
|
81 | - 'ldapCacheTTL' => null, |
|
82 | - 'ldapUuidUserAttribute' => 'auto', |
|
83 | - 'ldapUuidGroupAttribute' => 'auto', |
|
84 | - 'ldapOverrideMainServer' => false, |
|
85 | - 'ldapConfigurationActive' => false, |
|
86 | - 'ldapAttributesForUserSearch' => null, |
|
87 | - 'ldapAttributesForGroupSearch' => null, |
|
88 | - 'ldapExperiencedAdmin' => false, |
|
89 | - 'homeFolderNamingRule' => null, |
|
90 | - 'hasPagedResultSupport' => false, |
|
91 | - 'hasMemberOfFilterSupport' => false, |
|
92 | - 'useMemberOfToDetectMembership' => true, |
|
93 | - 'ldapExpertUsernameAttr' => null, |
|
94 | - 'ldapExpertUUIDUserAttr' => null, |
|
95 | - 'ldapExpertUUIDGroupAttr' => null, |
|
96 | - 'lastJpegPhotoLookup' => null, |
|
97 | - 'ldapNestedGroups' => false, |
|
98 | - 'ldapPagingSize' => null, |
|
99 | - 'turnOnPasswordChange' => false, |
|
100 | - 'ldapDynamicGroupMemberURL' => null, |
|
101 | - 'ldapDefaultPPolicyDN' => null, |
|
102 | - ); |
|
46 | + //settings |
|
47 | + protected $config = array( |
|
48 | + 'ldapHost' => null, |
|
49 | + 'ldapPort' => null, |
|
50 | + 'ldapBackupHost' => null, |
|
51 | + 'ldapBackupPort' => null, |
|
52 | + 'ldapBase' => null, |
|
53 | + 'ldapBaseUsers' => null, |
|
54 | + 'ldapBaseGroups' => null, |
|
55 | + 'ldapAgentName' => null, |
|
56 | + 'ldapAgentPassword' => null, |
|
57 | + 'ldapTLS' => null, |
|
58 | + 'turnOffCertCheck' => null, |
|
59 | + 'ldapIgnoreNamingRules' => null, |
|
60 | + 'ldapUserDisplayName' => null, |
|
61 | + 'ldapUserDisplayName2' => null, |
|
62 | + 'ldapGidNumber' => null, |
|
63 | + 'ldapUserFilterObjectclass' => null, |
|
64 | + 'ldapUserFilterGroups' => null, |
|
65 | + 'ldapUserFilter' => null, |
|
66 | + 'ldapUserFilterMode' => null, |
|
67 | + 'ldapGroupFilter' => null, |
|
68 | + 'ldapGroupFilterMode' => null, |
|
69 | + 'ldapGroupFilterObjectclass' => null, |
|
70 | + 'ldapGroupFilterGroups' => null, |
|
71 | + 'ldapGroupDisplayName' => null, |
|
72 | + 'ldapGroupMemberAssocAttr' => null, |
|
73 | + 'ldapLoginFilter' => null, |
|
74 | + 'ldapLoginFilterMode' => null, |
|
75 | + 'ldapLoginFilterEmail' => null, |
|
76 | + 'ldapLoginFilterUsername' => null, |
|
77 | + 'ldapLoginFilterAttributes' => null, |
|
78 | + 'ldapQuotaAttribute' => null, |
|
79 | + 'ldapQuotaDefault' => null, |
|
80 | + 'ldapEmailAttribute' => null, |
|
81 | + 'ldapCacheTTL' => null, |
|
82 | + 'ldapUuidUserAttribute' => 'auto', |
|
83 | + 'ldapUuidGroupAttribute' => 'auto', |
|
84 | + 'ldapOverrideMainServer' => false, |
|
85 | + 'ldapConfigurationActive' => false, |
|
86 | + 'ldapAttributesForUserSearch' => null, |
|
87 | + 'ldapAttributesForGroupSearch' => null, |
|
88 | + 'ldapExperiencedAdmin' => false, |
|
89 | + 'homeFolderNamingRule' => null, |
|
90 | + 'hasPagedResultSupport' => false, |
|
91 | + 'hasMemberOfFilterSupport' => false, |
|
92 | + 'useMemberOfToDetectMembership' => true, |
|
93 | + 'ldapExpertUsernameAttr' => null, |
|
94 | + 'ldapExpertUUIDUserAttr' => null, |
|
95 | + 'ldapExpertUUIDGroupAttr' => null, |
|
96 | + 'lastJpegPhotoLookup' => null, |
|
97 | + 'ldapNestedGroups' => false, |
|
98 | + 'ldapPagingSize' => null, |
|
99 | + 'turnOnPasswordChange' => false, |
|
100 | + 'ldapDynamicGroupMemberURL' => null, |
|
101 | + 'ldapDefaultPPolicyDN' => null, |
|
102 | + ); |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $configPrefix |
|
106 | - * @param bool $autoRead |
|
107 | - */ |
|
108 | - public function __construct($configPrefix, $autoRead = true) { |
|
109 | - $this->configPrefix = $configPrefix; |
|
110 | - if($autoRead) { |
|
111 | - $this->readConfiguration(); |
|
112 | - } |
|
113 | - } |
|
104 | + /** |
|
105 | + * @param string $configPrefix |
|
106 | + * @param bool $autoRead |
|
107 | + */ |
|
108 | + public function __construct($configPrefix, $autoRead = true) { |
|
109 | + $this->configPrefix = $configPrefix; |
|
110 | + if($autoRead) { |
|
111 | + $this->readConfiguration(); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @param string $name |
|
117 | - * @return mixed|null |
|
118 | - */ |
|
119 | - public function __get($name) { |
|
120 | - if(isset($this->config[$name])) { |
|
121 | - return $this->config[$name]; |
|
122 | - } |
|
123 | - return null; |
|
124 | - } |
|
115 | + /** |
|
116 | + * @param string $name |
|
117 | + * @return mixed|null |
|
118 | + */ |
|
119 | + public function __get($name) { |
|
120 | + if(isset($this->config[$name])) { |
|
121 | + return $this->config[$name]; |
|
122 | + } |
|
123 | + return null; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param string $name |
|
128 | - * @param mixed $value |
|
129 | - */ |
|
130 | - public function __set($name, $value) { |
|
131 | - $this->setConfiguration(array($name => $value)); |
|
132 | - } |
|
126 | + /** |
|
127 | + * @param string $name |
|
128 | + * @param mixed $value |
|
129 | + */ |
|
130 | + public function __set($name, $value) { |
|
131 | + $this->setConfiguration(array($name => $value)); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function getConfiguration() { |
|
138 | - return $this->config; |
|
139 | - } |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function getConfiguration() { |
|
138 | + return $this->config; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * set LDAP configuration with values delivered by an array, not read |
|
143 | - * from configuration. It does not save the configuration! To do so, you |
|
144 | - * must call saveConfiguration afterwards. |
|
145 | - * @param array $config array that holds the config parameters in an associated |
|
146 | - * array |
|
147 | - * @param array &$applied optional; array where the set fields will be given to |
|
148 | - * @return false|null |
|
149 | - */ |
|
150 | - public function setConfiguration($config, &$applied = null) { |
|
151 | - if(!is_array($config)) { |
|
152 | - return false; |
|
153 | - } |
|
141 | + /** |
|
142 | + * set LDAP configuration with values delivered by an array, not read |
|
143 | + * from configuration. It does not save the configuration! To do so, you |
|
144 | + * must call saveConfiguration afterwards. |
|
145 | + * @param array $config array that holds the config parameters in an associated |
|
146 | + * array |
|
147 | + * @param array &$applied optional; array where the set fields will be given to |
|
148 | + * @return false|null |
|
149 | + */ |
|
150 | + public function setConfiguration($config, &$applied = null) { |
|
151 | + if(!is_array($config)) { |
|
152 | + return false; |
|
153 | + } |
|
154 | 154 | |
155 | - $cta = $this->getConfigTranslationArray(); |
|
156 | - foreach($config as $inputKey => $val) { |
|
157 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
158 | - $key = $cta[$inputKey]; |
|
159 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
160 | - $key = $inputKey; |
|
161 | - } else { |
|
162 | - continue; |
|
163 | - } |
|
155 | + $cta = $this->getConfigTranslationArray(); |
|
156 | + foreach($config as $inputKey => $val) { |
|
157 | + if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
158 | + $key = $cta[$inputKey]; |
|
159 | + } elseif(array_key_exists($inputKey, $this->config)) { |
|
160 | + $key = $inputKey; |
|
161 | + } else { |
|
162 | + continue; |
|
163 | + } |
|
164 | 164 | |
165 | - $setMethod = 'setValue'; |
|
166 | - switch($key) { |
|
167 | - case 'ldapAgentPassword': |
|
168 | - $setMethod = 'setRawValue'; |
|
169 | - break; |
|
170 | - case 'homeFolderNamingRule': |
|
171 | - $trimmedVal = trim($val); |
|
172 | - if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
173 | - $val = 'attr:'.$trimmedVal; |
|
174 | - } |
|
175 | - break; |
|
176 | - case 'ldapBase': |
|
177 | - case 'ldapBaseUsers': |
|
178 | - case 'ldapBaseGroups': |
|
179 | - case 'ldapAttributesForUserSearch': |
|
180 | - case 'ldapAttributesForGroupSearch': |
|
181 | - case 'ldapUserFilterObjectclass': |
|
182 | - case 'ldapUserFilterGroups': |
|
183 | - case 'ldapGroupFilterObjectclass': |
|
184 | - case 'ldapGroupFilterGroups': |
|
185 | - case 'ldapLoginFilterAttributes': |
|
186 | - $setMethod = 'setMultiLine'; |
|
187 | - break; |
|
188 | - } |
|
189 | - $this->$setMethod($key, $val); |
|
190 | - if(is_array($applied)) { |
|
191 | - $applied[] = $inputKey; |
|
192 | - // storing key as index avoids duplication, and as value for simplicity |
|
193 | - } |
|
194 | - $this->unsavedChanges[$key] = $key; |
|
195 | - } |
|
196 | - return null; |
|
197 | - } |
|
165 | + $setMethod = 'setValue'; |
|
166 | + switch($key) { |
|
167 | + case 'ldapAgentPassword': |
|
168 | + $setMethod = 'setRawValue'; |
|
169 | + break; |
|
170 | + case 'homeFolderNamingRule': |
|
171 | + $trimmedVal = trim($val); |
|
172 | + if ($trimmedVal !== '' && strpos($val, 'attr:') === false) { |
|
173 | + $val = 'attr:'.$trimmedVal; |
|
174 | + } |
|
175 | + break; |
|
176 | + case 'ldapBase': |
|
177 | + case 'ldapBaseUsers': |
|
178 | + case 'ldapBaseGroups': |
|
179 | + case 'ldapAttributesForUserSearch': |
|
180 | + case 'ldapAttributesForGroupSearch': |
|
181 | + case 'ldapUserFilterObjectclass': |
|
182 | + case 'ldapUserFilterGroups': |
|
183 | + case 'ldapGroupFilterObjectclass': |
|
184 | + case 'ldapGroupFilterGroups': |
|
185 | + case 'ldapLoginFilterAttributes': |
|
186 | + $setMethod = 'setMultiLine'; |
|
187 | + break; |
|
188 | + } |
|
189 | + $this->$setMethod($key, $val); |
|
190 | + if(is_array($applied)) { |
|
191 | + $applied[] = $inputKey; |
|
192 | + // storing key as index avoids duplication, and as value for simplicity |
|
193 | + } |
|
194 | + $this->unsavedChanges[$key] = $key; |
|
195 | + } |
|
196 | + return null; |
|
197 | + } |
|
198 | 198 | |
199 | - public function readConfiguration() { |
|
200 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
201 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
202 | - foreach($this->config as $key => $val) { |
|
203 | - if(!isset($cta[$key])) { |
|
204 | - //some are determined |
|
205 | - continue; |
|
206 | - } |
|
207 | - $dbKey = $cta[$key]; |
|
208 | - switch($key) { |
|
209 | - case 'ldapBase': |
|
210 | - case 'ldapBaseUsers': |
|
211 | - case 'ldapBaseGroups': |
|
212 | - case 'ldapAttributesForUserSearch': |
|
213 | - case 'ldapAttributesForGroupSearch': |
|
214 | - case 'ldapUserFilterObjectclass': |
|
215 | - case 'ldapUserFilterGroups': |
|
216 | - case 'ldapGroupFilterObjectclass': |
|
217 | - case 'ldapGroupFilterGroups': |
|
218 | - case 'ldapLoginFilterAttributes': |
|
219 | - $readMethod = 'getMultiLine'; |
|
220 | - break; |
|
221 | - case 'ldapIgnoreNamingRules': |
|
222 | - $readMethod = 'getSystemValue'; |
|
223 | - $dbKey = $key; |
|
224 | - break; |
|
225 | - case 'ldapAgentPassword': |
|
226 | - $readMethod = 'getPwd'; |
|
227 | - break; |
|
228 | - case 'ldapUserDisplayName2': |
|
229 | - case 'ldapGroupDisplayName': |
|
230 | - $readMethod = 'getLcValue'; |
|
231 | - break; |
|
232 | - case 'ldapUserDisplayName': |
|
233 | - default: |
|
234 | - // user display name does not lower case because |
|
235 | - // we rely on an upper case N as indicator whether to |
|
236 | - // auto-detect it or not. FIXME |
|
237 | - $readMethod = 'getValue'; |
|
238 | - break; |
|
239 | - } |
|
240 | - $this->config[$key] = $this->$readMethod($dbKey); |
|
241 | - } |
|
242 | - $this->configRead = true; |
|
243 | - } |
|
244 | - } |
|
199 | + public function readConfiguration() { |
|
200 | + if(!$this->configRead && !is_null($this->configPrefix)) { |
|
201 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
202 | + foreach($this->config as $key => $val) { |
|
203 | + if(!isset($cta[$key])) { |
|
204 | + //some are determined |
|
205 | + continue; |
|
206 | + } |
|
207 | + $dbKey = $cta[$key]; |
|
208 | + switch($key) { |
|
209 | + case 'ldapBase': |
|
210 | + case 'ldapBaseUsers': |
|
211 | + case 'ldapBaseGroups': |
|
212 | + case 'ldapAttributesForUserSearch': |
|
213 | + case 'ldapAttributesForGroupSearch': |
|
214 | + case 'ldapUserFilterObjectclass': |
|
215 | + case 'ldapUserFilterGroups': |
|
216 | + case 'ldapGroupFilterObjectclass': |
|
217 | + case 'ldapGroupFilterGroups': |
|
218 | + case 'ldapLoginFilterAttributes': |
|
219 | + $readMethod = 'getMultiLine'; |
|
220 | + break; |
|
221 | + case 'ldapIgnoreNamingRules': |
|
222 | + $readMethod = 'getSystemValue'; |
|
223 | + $dbKey = $key; |
|
224 | + break; |
|
225 | + case 'ldapAgentPassword': |
|
226 | + $readMethod = 'getPwd'; |
|
227 | + break; |
|
228 | + case 'ldapUserDisplayName2': |
|
229 | + case 'ldapGroupDisplayName': |
|
230 | + $readMethod = 'getLcValue'; |
|
231 | + break; |
|
232 | + case 'ldapUserDisplayName': |
|
233 | + default: |
|
234 | + // user display name does not lower case because |
|
235 | + // we rely on an upper case N as indicator whether to |
|
236 | + // auto-detect it or not. FIXME |
|
237 | + $readMethod = 'getValue'; |
|
238 | + break; |
|
239 | + } |
|
240 | + $this->config[$key] = $this->$readMethod($dbKey); |
|
241 | + } |
|
242 | + $this->configRead = true; |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * saves the current config changes in the database |
|
248 | - */ |
|
249 | - public function saveConfiguration() { |
|
250 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
251 | - foreach($this->unsavedChanges as $key) { |
|
252 | - $value = $this->config[$key]; |
|
253 | - switch ($key) { |
|
254 | - case 'ldapAgentPassword': |
|
255 | - $value = base64_encode($value); |
|
256 | - break; |
|
257 | - case 'ldapBase': |
|
258 | - case 'ldapBaseUsers': |
|
259 | - case 'ldapBaseGroups': |
|
260 | - case 'ldapAttributesForUserSearch': |
|
261 | - case 'ldapAttributesForGroupSearch': |
|
262 | - case 'ldapUserFilterObjectclass': |
|
263 | - case 'ldapUserFilterGroups': |
|
264 | - case 'ldapGroupFilterObjectclass': |
|
265 | - case 'ldapGroupFilterGroups': |
|
266 | - case 'ldapLoginFilterAttributes': |
|
267 | - if(is_array($value)) { |
|
268 | - $value = implode("\n", $value); |
|
269 | - } |
|
270 | - break; |
|
271 | - //following options are not stored but detected, skip them |
|
272 | - case 'ldapIgnoreNamingRules': |
|
273 | - case 'hasPagedResultSupport': |
|
274 | - case 'ldapUuidUserAttribute': |
|
275 | - case 'ldapUuidGroupAttribute': |
|
276 | - continue 2; |
|
277 | - } |
|
278 | - if(is_null($value)) { |
|
279 | - $value = ''; |
|
280 | - } |
|
281 | - $this->saveValue($cta[$key], $value); |
|
282 | - } |
|
283 | - $this->unsavedChanges = []; |
|
284 | - } |
|
246 | + /** |
|
247 | + * saves the current config changes in the database |
|
248 | + */ |
|
249 | + public function saveConfiguration() { |
|
250 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
251 | + foreach($this->unsavedChanges as $key) { |
|
252 | + $value = $this->config[$key]; |
|
253 | + switch ($key) { |
|
254 | + case 'ldapAgentPassword': |
|
255 | + $value = base64_encode($value); |
|
256 | + break; |
|
257 | + case 'ldapBase': |
|
258 | + case 'ldapBaseUsers': |
|
259 | + case 'ldapBaseGroups': |
|
260 | + case 'ldapAttributesForUserSearch': |
|
261 | + case 'ldapAttributesForGroupSearch': |
|
262 | + case 'ldapUserFilterObjectclass': |
|
263 | + case 'ldapUserFilterGroups': |
|
264 | + case 'ldapGroupFilterObjectclass': |
|
265 | + case 'ldapGroupFilterGroups': |
|
266 | + case 'ldapLoginFilterAttributes': |
|
267 | + if(is_array($value)) { |
|
268 | + $value = implode("\n", $value); |
|
269 | + } |
|
270 | + break; |
|
271 | + //following options are not stored but detected, skip them |
|
272 | + case 'ldapIgnoreNamingRules': |
|
273 | + case 'hasPagedResultSupport': |
|
274 | + case 'ldapUuidUserAttribute': |
|
275 | + case 'ldapUuidGroupAttribute': |
|
276 | + continue 2; |
|
277 | + } |
|
278 | + if(is_null($value)) { |
|
279 | + $value = ''; |
|
280 | + } |
|
281 | + $this->saveValue($cta[$key], $value); |
|
282 | + } |
|
283 | + $this->unsavedChanges = []; |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * @param string $varName |
|
288 | - * @return array|string |
|
289 | - */ |
|
290 | - protected function getMultiLine($varName) { |
|
291 | - $value = $this->getValue($varName); |
|
292 | - if(empty($value)) { |
|
293 | - $value = ''; |
|
294 | - } else { |
|
295 | - $value = preg_split('/\r\n|\r|\n/', $value); |
|
296 | - } |
|
286 | + /** |
|
287 | + * @param string $varName |
|
288 | + * @return array|string |
|
289 | + */ |
|
290 | + protected function getMultiLine($varName) { |
|
291 | + $value = $this->getValue($varName); |
|
292 | + if(empty($value)) { |
|
293 | + $value = ''; |
|
294 | + } else { |
|
295 | + $value = preg_split('/\r\n|\r|\n/', $value); |
|
296 | + } |
|
297 | 297 | |
298 | - return $value; |
|
299 | - } |
|
298 | + return $value; |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Sets multi-line values as arrays |
|
303 | - * |
|
304 | - * @param string $varName name of config-key |
|
305 | - * @param array|string $value to set |
|
306 | - */ |
|
307 | - protected function setMultiLine($varName, $value) { |
|
308 | - if(empty($value)) { |
|
309 | - $value = ''; |
|
310 | - } else if (!is_array($value)) { |
|
311 | - $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
312 | - if($value === false) { |
|
313 | - $value = ''; |
|
314 | - } |
|
315 | - } |
|
301 | + /** |
|
302 | + * Sets multi-line values as arrays |
|
303 | + * |
|
304 | + * @param string $varName name of config-key |
|
305 | + * @param array|string $value to set |
|
306 | + */ |
|
307 | + protected function setMultiLine($varName, $value) { |
|
308 | + if(empty($value)) { |
|
309 | + $value = ''; |
|
310 | + } else if (!is_array($value)) { |
|
311 | + $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
312 | + if($value === false) { |
|
313 | + $value = ''; |
|
314 | + } |
|
315 | + } |
|
316 | 316 | |
317 | - if(!is_array($value)) { |
|
318 | - $finalValue = trim($value); |
|
319 | - } else { |
|
320 | - $finalValue = []; |
|
321 | - foreach($value as $key => $val) { |
|
322 | - if(is_string($val)) { |
|
323 | - $val = trim($val); |
|
324 | - if ($val !== '') { |
|
325 | - //accidental line breaks are not wanted and can cause |
|
326 | - // odd behaviour. Thus, away with them. |
|
327 | - $finalValue[] = $val; |
|
328 | - } |
|
329 | - } else { |
|
330 | - $finalValue[] = $val; |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
317 | + if(!is_array($value)) { |
|
318 | + $finalValue = trim($value); |
|
319 | + } else { |
|
320 | + $finalValue = []; |
|
321 | + foreach($value as $key => $val) { |
|
322 | + if(is_string($val)) { |
|
323 | + $val = trim($val); |
|
324 | + if ($val !== '') { |
|
325 | + //accidental line breaks are not wanted and can cause |
|
326 | + // odd behaviour. Thus, away with them. |
|
327 | + $finalValue[] = $val; |
|
328 | + } |
|
329 | + } else { |
|
330 | + $finalValue[] = $val; |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | 334 | |
335 | - $this->setRawValue($varName, $finalValue); |
|
336 | - } |
|
335 | + $this->setRawValue($varName, $finalValue); |
|
336 | + } |
|
337 | 337 | |
338 | - /** |
|
339 | - * @param string $varName |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - protected function getPwd($varName) { |
|
343 | - return base64_decode($this->getValue($varName)); |
|
344 | - } |
|
338 | + /** |
|
339 | + * @param string $varName |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + protected function getPwd($varName) { |
|
343 | + return base64_decode($this->getValue($varName)); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * @param string $varName |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - protected function getLcValue($varName) { |
|
351 | - return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
352 | - } |
|
346 | + /** |
|
347 | + * @param string $varName |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + protected function getLcValue($varName) { |
|
351 | + return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * @param string $varName |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - protected function getSystemValue($varName) { |
|
359 | - //FIXME: if another system value is added, softcode the default value |
|
360 | - return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
361 | - } |
|
354 | + /** |
|
355 | + * @param string $varName |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + protected function getSystemValue($varName) { |
|
359 | + //FIXME: if another system value is added, softcode the default value |
|
360 | + return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
361 | + } |
|
362 | 362 | |
363 | - /** |
|
364 | - * @param string $varName |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - protected function getValue($varName) { |
|
368 | - static $defaults; |
|
369 | - if(is_null($defaults)) { |
|
370 | - $defaults = $this->getDefaults(); |
|
371 | - } |
|
372 | - return \OCP\Config::getAppValue('user_ldap', |
|
373 | - $this->configPrefix.$varName, |
|
374 | - $defaults[$varName]); |
|
375 | - } |
|
363 | + /** |
|
364 | + * @param string $varName |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + protected function getValue($varName) { |
|
368 | + static $defaults; |
|
369 | + if(is_null($defaults)) { |
|
370 | + $defaults = $this->getDefaults(); |
|
371 | + } |
|
372 | + return \OCP\Config::getAppValue('user_ldap', |
|
373 | + $this->configPrefix.$varName, |
|
374 | + $defaults[$varName]); |
|
375 | + } |
|
376 | 376 | |
377 | - /** |
|
378 | - * Sets a scalar value. |
|
379 | - * |
|
380 | - * @param string $varName name of config key |
|
381 | - * @param mixed $value to set |
|
382 | - */ |
|
383 | - protected function setValue($varName, $value) { |
|
384 | - if(is_string($value)) { |
|
385 | - $value = trim($value); |
|
386 | - } |
|
387 | - $this->config[$varName] = $value; |
|
388 | - } |
|
377 | + /** |
|
378 | + * Sets a scalar value. |
|
379 | + * |
|
380 | + * @param string $varName name of config key |
|
381 | + * @param mixed $value to set |
|
382 | + */ |
|
383 | + protected function setValue($varName, $value) { |
|
384 | + if(is_string($value)) { |
|
385 | + $value = trim($value); |
|
386 | + } |
|
387 | + $this->config[$varName] = $value; |
|
388 | + } |
|
389 | 389 | |
390 | - /** |
|
391 | - * Sets a scalar value without trimming. |
|
392 | - * |
|
393 | - * @param string $varName name of config key |
|
394 | - * @param mixed $value to set |
|
395 | - */ |
|
396 | - protected function setRawValue($varName, $value) { |
|
397 | - $this->config[$varName] = $value; |
|
398 | - } |
|
390 | + /** |
|
391 | + * Sets a scalar value without trimming. |
|
392 | + * |
|
393 | + * @param string $varName name of config key |
|
394 | + * @param mixed $value to set |
|
395 | + */ |
|
396 | + protected function setRawValue($varName, $value) { |
|
397 | + $this->config[$varName] = $value; |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * @param string $varName |
|
402 | - * @param string $value |
|
403 | - * @return bool |
|
404 | - */ |
|
405 | - protected function saveValue($varName, $value) { |
|
406 | - \OC::$server->getConfig()->setAppValue( |
|
407 | - 'user_ldap', |
|
408 | - $this->configPrefix.$varName, |
|
409 | - $value |
|
410 | - ); |
|
411 | - return true; |
|
412 | - } |
|
400 | + /** |
|
401 | + * @param string $varName |
|
402 | + * @param string $value |
|
403 | + * @return bool |
|
404 | + */ |
|
405 | + protected function saveValue($varName, $value) { |
|
406 | + \OC::$server->getConfig()->setAppValue( |
|
407 | + 'user_ldap', |
|
408 | + $this->configPrefix.$varName, |
|
409 | + $value |
|
410 | + ); |
|
411 | + return true; |
|
412 | + } |
|
413 | 413 | |
414 | - /** |
|
415 | - * @return array an associative array with the default values. Keys are correspond |
|
416 | - * to config-value entries in the database table |
|
417 | - */ |
|
418 | - public function getDefaults() { |
|
419 | - return array( |
|
420 | - 'ldap_host' => '', |
|
421 | - 'ldap_port' => '', |
|
422 | - 'ldap_backup_host' => '', |
|
423 | - 'ldap_backup_port' => '', |
|
424 | - 'ldap_override_main_server' => '', |
|
425 | - 'ldap_dn' => '', |
|
426 | - 'ldap_agent_password' => '', |
|
427 | - 'ldap_base' => '', |
|
428 | - 'ldap_base_users' => '', |
|
429 | - 'ldap_base_groups' => '', |
|
430 | - 'ldap_userlist_filter' => '', |
|
431 | - 'ldap_user_filter_mode' => 0, |
|
432 | - 'ldap_userfilter_objectclass' => '', |
|
433 | - 'ldap_userfilter_groups' => '', |
|
434 | - 'ldap_login_filter' => '', |
|
435 | - 'ldap_login_filter_mode' => 0, |
|
436 | - 'ldap_loginfilter_email' => 0, |
|
437 | - 'ldap_loginfilter_username' => 1, |
|
438 | - 'ldap_loginfilter_attributes' => '', |
|
439 | - 'ldap_group_filter' => '', |
|
440 | - 'ldap_group_filter_mode' => 0, |
|
441 | - 'ldap_groupfilter_objectclass' => '', |
|
442 | - 'ldap_groupfilter_groups' => '', |
|
443 | - 'ldap_gid_number' => 'gidNumber', |
|
444 | - 'ldap_display_name' => 'displayName', |
|
445 | - 'ldap_user_display_name_2' => '', |
|
446 | - 'ldap_group_display_name' => 'cn', |
|
447 | - 'ldap_tls' => 0, |
|
448 | - 'ldap_quota_def' => '', |
|
449 | - 'ldap_quota_attr' => '', |
|
450 | - 'ldap_email_attr' => '', |
|
451 | - 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
452 | - 'ldap_cache_ttl' => 600, |
|
453 | - 'ldap_uuid_user_attribute' => 'auto', |
|
454 | - 'ldap_uuid_group_attribute' => 'auto', |
|
455 | - 'home_folder_naming_rule' => '', |
|
456 | - 'ldap_turn_off_cert_check' => 0, |
|
457 | - 'ldap_configuration_active' => 0, |
|
458 | - 'ldap_attributes_for_user_search' => '', |
|
459 | - 'ldap_attributes_for_group_search' => '', |
|
460 | - 'ldap_expert_username_attr' => '', |
|
461 | - 'ldap_expert_uuid_user_attr' => '', |
|
462 | - 'ldap_expert_uuid_group_attr' => '', |
|
463 | - 'has_memberof_filter_support' => 0, |
|
464 | - 'use_memberof_to_detect_membership' => 1, |
|
465 | - 'last_jpegPhoto_lookup' => 0, |
|
466 | - 'ldap_nested_groups' => 0, |
|
467 | - 'ldap_paging_size' => 500, |
|
468 | - 'ldap_turn_on_pwd_change' => 0, |
|
469 | - 'ldap_experienced_admin' => 0, |
|
470 | - 'ldap_dynamic_group_member_url' => '', |
|
471 | - 'ldap_default_ppolicy_dn' => '', |
|
472 | - ); |
|
473 | - } |
|
414 | + /** |
|
415 | + * @return array an associative array with the default values. Keys are correspond |
|
416 | + * to config-value entries in the database table |
|
417 | + */ |
|
418 | + public function getDefaults() { |
|
419 | + return array( |
|
420 | + 'ldap_host' => '', |
|
421 | + 'ldap_port' => '', |
|
422 | + 'ldap_backup_host' => '', |
|
423 | + 'ldap_backup_port' => '', |
|
424 | + 'ldap_override_main_server' => '', |
|
425 | + 'ldap_dn' => '', |
|
426 | + 'ldap_agent_password' => '', |
|
427 | + 'ldap_base' => '', |
|
428 | + 'ldap_base_users' => '', |
|
429 | + 'ldap_base_groups' => '', |
|
430 | + 'ldap_userlist_filter' => '', |
|
431 | + 'ldap_user_filter_mode' => 0, |
|
432 | + 'ldap_userfilter_objectclass' => '', |
|
433 | + 'ldap_userfilter_groups' => '', |
|
434 | + 'ldap_login_filter' => '', |
|
435 | + 'ldap_login_filter_mode' => 0, |
|
436 | + 'ldap_loginfilter_email' => 0, |
|
437 | + 'ldap_loginfilter_username' => 1, |
|
438 | + 'ldap_loginfilter_attributes' => '', |
|
439 | + 'ldap_group_filter' => '', |
|
440 | + 'ldap_group_filter_mode' => 0, |
|
441 | + 'ldap_groupfilter_objectclass' => '', |
|
442 | + 'ldap_groupfilter_groups' => '', |
|
443 | + 'ldap_gid_number' => 'gidNumber', |
|
444 | + 'ldap_display_name' => 'displayName', |
|
445 | + 'ldap_user_display_name_2' => '', |
|
446 | + 'ldap_group_display_name' => 'cn', |
|
447 | + 'ldap_tls' => 0, |
|
448 | + 'ldap_quota_def' => '', |
|
449 | + 'ldap_quota_attr' => '', |
|
450 | + 'ldap_email_attr' => '', |
|
451 | + 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
452 | + 'ldap_cache_ttl' => 600, |
|
453 | + 'ldap_uuid_user_attribute' => 'auto', |
|
454 | + 'ldap_uuid_group_attribute' => 'auto', |
|
455 | + 'home_folder_naming_rule' => '', |
|
456 | + 'ldap_turn_off_cert_check' => 0, |
|
457 | + 'ldap_configuration_active' => 0, |
|
458 | + 'ldap_attributes_for_user_search' => '', |
|
459 | + 'ldap_attributes_for_group_search' => '', |
|
460 | + 'ldap_expert_username_attr' => '', |
|
461 | + 'ldap_expert_uuid_user_attr' => '', |
|
462 | + 'ldap_expert_uuid_group_attr' => '', |
|
463 | + 'has_memberof_filter_support' => 0, |
|
464 | + 'use_memberof_to_detect_membership' => 1, |
|
465 | + 'last_jpegPhoto_lookup' => 0, |
|
466 | + 'ldap_nested_groups' => 0, |
|
467 | + 'ldap_paging_size' => 500, |
|
468 | + 'ldap_turn_on_pwd_change' => 0, |
|
469 | + 'ldap_experienced_admin' => 0, |
|
470 | + 'ldap_dynamic_group_member_url' => '', |
|
471 | + 'ldap_default_ppolicy_dn' => '', |
|
472 | + ); |
|
473 | + } |
|
474 | 474 | |
475 | - /** |
|
476 | - * @return array that maps internal variable names to database fields |
|
477 | - */ |
|
478 | - public function getConfigTranslationArray() { |
|
479 | - //TODO: merge them into one representation |
|
480 | - static $array = array( |
|
481 | - 'ldap_host' => 'ldapHost', |
|
482 | - 'ldap_port' => 'ldapPort', |
|
483 | - 'ldap_backup_host' => 'ldapBackupHost', |
|
484 | - 'ldap_backup_port' => 'ldapBackupPort', |
|
485 | - 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
486 | - 'ldap_dn' => 'ldapAgentName', |
|
487 | - 'ldap_agent_password' => 'ldapAgentPassword', |
|
488 | - 'ldap_base' => 'ldapBase', |
|
489 | - 'ldap_base_users' => 'ldapBaseUsers', |
|
490 | - 'ldap_base_groups' => 'ldapBaseGroups', |
|
491 | - 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
492 | - 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
493 | - 'ldap_userlist_filter' => 'ldapUserFilter', |
|
494 | - 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
495 | - 'ldap_login_filter' => 'ldapLoginFilter', |
|
496 | - 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
497 | - 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
498 | - 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
499 | - 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
500 | - 'ldap_group_filter' => 'ldapGroupFilter', |
|
501 | - 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
502 | - 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
503 | - 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
504 | - 'ldap_gid_number' => 'ldapGidNumber', |
|
505 | - 'ldap_display_name' => 'ldapUserDisplayName', |
|
506 | - 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
507 | - 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
508 | - 'ldap_tls' => 'ldapTLS', |
|
509 | - 'ldap_quota_def' => 'ldapQuotaDefault', |
|
510 | - 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
511 | - 'ldap_email_attr' => 'ldapEmailAttribute', |
|
512 | - 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
513 | - 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
514 | - 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
515 | - 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
516 | - 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
517 | - 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
518 | - 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
519 | - 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
520 | - 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
521 | - 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
522 | - 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
523 | - 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
524 | - 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
525 | - 'ldap_nested_groups' => 'ldapNestedGroups', |
|
526 | - 'ldap_paging_size' => 'ldapPagingSize', |
|
527 | - 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
528 | - 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
529 | - 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
530 | - 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
531 | - ); |
|
532 | - return $array; |
|
533 | - } |
|
475 | + /** |
|
476 | + * @return array that maps internal variable names to database fields |
|
477 | + */ |
|
478 | + public function getConfigTranslationArray() { |
|
479 | + //TODO: merge them into one representation |
|
480 | + static $array = array( |
|
481 | + 'ldap_host' => 'ldapHost', |
|
482 | + 'ldap_port' => 'ldapPort', |
|
483 | + 'ldap_backup_host' => 'ldapBackupHost', |
|
484 | + 'ldap_backup_port' => 'ldapBackupPort', |
|
485 | + 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
486 | + 'ldap_dn' => 'ldapAgentName', |
|
487 | + 'ldap_agent_password' => 'ldapAgentPassword', |
|
488 | + 'ldap_base' => 'ldapBase', |
|
489 | + 'ldap_base_users' => 'ldapBaseUsers', |
|
490 | + 'ldap_base_groups' => 'ldapBaseGroups', |
|
491 | + 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
492 | + 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
493 | + 'ldap_userlist_filter' => 'ldapUserFilter', |
|
494 | + 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
495 | + 'ldap_login_filter' => 'ldapLoginFilter', |
|
496 | + 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
497 | + 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
498 | + 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
499 | + 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
500 | + 'ldap_group_filter' => 'ldapGroupFilter', |
|
501 | + 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
502 | + 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
503 | + 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
504 | + 'ldap_gid_number' => 'ldapGidNumber', |
|
505 | + 'ldap_display_name' => 'ldapUserDisplayName', |
|
506 | + 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
507 | + 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
508 | + 'ldap_tls' => 'ldapTLS', |
|
509 | + 'ldap_quota_def' => 'ldapQuotaDefault', |
|
510 | + 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
511 | + 'ldap_email_attr' => 'ldapEmailAttribute', |
|
512 | + 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
513 | + 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
514 | + 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
515 | + 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
516 | + 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
517 | + 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
518 | + 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
519 | + 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
520 | + 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
521 | + 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
522 | + 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
523 | + 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
524 | + 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
525 | + 'ldap_nested_groups' => 'ldapNestedGroups', |
|
526 | + 'ldap_paging_size' => 'ldapPagingSize', |
|
527 | + 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
528 | + 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
529 | + 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
530 | + 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
531 | + ); |
|
532 | + return $array; |
|
533 | + } |
|
534 | 534 | |
535 | 535 | } |
@@ -56,582 +56,582 @@ |
||
56 | 56 | * @property string ldapUuidGroupAttribute |
57 | 57 | */ |
58 | 58 | class Connection extends LDAPUtility { |
59 | - private $ldapConnectionRes = null; |
|
60 | - private $configPrefix; |
|
61 | - private $configID; |
|
62 | - private $configured = false; |
|
63 | - private $hasPagedResultSupport = true; |
|
64 | - //whether connection should be kept on __destruct |
|
65 | - private $dontDestruct = false; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var bool runtime flag that indicates whether supported primary groups are available |
|
69 | - */ |
|
70 | - public $hasPrimaryGroups = true; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
74 | - */ |
|
75 | - public $hasGidNumber = true; |
|
76 | - |
|
77 | - //cache handler |
|
78 | - protected $cache; |
|
79 | - |
|
80 | - /** @var Configuration settings handler **/ |
|
81 | - protected $configuration; |
|
82 | - |
|
83 | - protected $doNotValidate = false; |
|
84 | - |
|
85 | - protected $ignoreValidation = false; |
|
86 | - |
|
87 | - /** |
|
88 | - * Constructor |
|
89 | - * @param ILDAPWrapper $ldap |
|
90 | - * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
91 | - * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
92 | - */ |
|
93 | - public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
94 | - parent::__construct($ldap); |
|
95 | - $this->configPrefix = $configPrefix; |
|
96 | - $this->configID = $configID; |
|
97 | - $this->configuration = new Configuration($configPrefix, |
|
98 | - !is_null($configID)); |
|
99 | - $memcache = \OC::$server->getMemCacheFactory(); |
|
100 | - if($memcache->isAvailable()) { |
|
101 | - $this->cache = $memcache->create(); |
|
102 | - } |
|
103 | - $helper = new Helper(\OC::$server->getConfig()); |
|
104 | - $this->doNotValidate = !in_array($this->configPrefix, |
|
105 | - $helper->getServerConfigurationPrefixes()); |
|
106 | - $this->hasPagedResultSupport = |
|
107 | - intval($this->configuration->ldapPagingSize) !== 0 |
|
108 | - || $this->ldap->hasPagedResultSupport(); |
|
109 | - } |
|
110 | - |
|
111 | - public function __destruct() { |
|
112 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
113 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
114 | - }; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * defines behaviour when the instance is cloned |
|
119 | - */ |
|
120 | - public function __clone() { |
|
121 | - $this->configuration = new Configuration($this->configPrefix, |
|
122 | - !is_null($this->configID)); |
|
123 | - $this->ldapConnectionRes = null; |
|
124 | - $this->dontDestruct = true; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $name |
|
129 | - * @return bool|mixed |
|
130 | - */ |
|
131 | - public function __get($name) { |
|
132 | - if(!$this->configured) { |
|
133 | - $this->readConfiguration(); |
|
134 | - } |
|
135 | - |
|
136 | - if($name === 'hasPagedResultSupport') { |
|
137 | - return $this->hasPagedResultSupport; |
|
138 | - } |
|
139 | - |
|
140 | - return $this->configuration->$name; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $name |
|
145 | - * @param mixed $value |
|
146 | - */ |
|
147 | - public function __set($name, $value) { |
|
148 | - $this->doNotValidate = false; |
|
149 | - $before = $this->configuration->$name; |
|
150 | - $this->configuration->$name = $value; |
|
151 | - $after = $this->configuration->$name; |
|
152 | - if($before !== $after) { |
|
153 | - if ($this->configID !== '' && $this->configID !== null) { |
|
154 | - $this->configuration->saveConfiguration(); |
|
155 | - } |
|
156 | - $this->validateConfiguration(); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * sets whether the result of the configuration validation shall |
|
162 | - * be ignored when establishing the connection. Used by the Wizard |
|
163 | - * in early configuration state. |
|
164 | - * @param bool $state |
|
165 | - */ |
|
166 | - public function setIgnoreValidation($state) { |
|
167 | - $this->ignoreValidation = (bool)$state; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * initializes the LDAP backend |
|
172 | - * @param bool $force read the config settings no matter what |
|
173 | - */ |
|
174 | - public function init($force = false) { |
|
175 | - $this->readConfiguration($force); |
|
176 | - $this->establishConnection(); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Returns the LDAP handler |
|
181 | - */ |
|
182 | - public function getConnectionResource() { |
|
183 | - if(!$this->ldapConnectionRes) { |
|
184 | - $this->init(); |
|
185 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
186 | - $this->ldapConnectionRes = null; |
|
187 | - $this->establishConnection(); |
|
188 | - } |
|
189 | - if(is_null($this->ldapConnectionRes)) { |
|
190 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
191 | - throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
192 | - } |
|
193 | - return $this->ldapConnectionRes; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * resets the connection resource |
|
198 | - */ |
|
199 | - public function resetConnectionResource() { |
|
200 | - if(!is_null($this->ldapConnectionRes)) { |
|
201 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
202 | - $this->ldapConnectionRes = null; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string|null $key |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - private function getCacheKey($key) { |
|
211 | - $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
212 | - if(is_null($key)) { |
|
213 | - return $prefix; |
|
214 | - } |
|
215 | - return $prefix.md5($key); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @param string $key |
|
220 | - * @return mixed|null |
|
221 | - */ |
|
222 | - public function getFromCache($key) { |
|
223 | - if(!$this->configured) { |
|
224 | - $this->readConfiguration(); |
|
225 | - } |
|
226 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
227 | - return null; |
|
228 | - } |
|
229 | - $key = $this->getCacheKey($key); |
|
230 | - |
|
231 | - return json_decode(base64_decode($this->cache->get($key)), true); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @param string $key |
|
236 | - * @param mixed $value |
|
237 | - * |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function writeToCache($key, $value) { |
|
241 | - if(!$this->configured) { |
|
242 | - $this->readConfiguration(); |
|
243 | - } |
|
244 | - if(is_null($this->cache) |
|
245 | - || !$this->configuration->ldapCacheTTL |
|
246 | - || !$this->configuration->ldapConfigurationActive) { |
|
247 | - return null; |
|
248 | - } |
|
249 | - $key = $this->getCacheKey($key); |
|
250 | - $value = base64_encode(json_encode($value)); |
|
251 | - $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
252 | - } |
|
253 | - |
|
254 | - public function clearCache() { |
|
255 | - if(!is_null($this->cache)) { |
|
256 | - $this->cache->clear($this->getCacheKey(null)); |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Caches the general LDAP configuration. |
|
262 | - * @param bool $force optional. true, if the re-read should be forced. defaults |
|
263 | - * to false. |
|
264 | - * @return null |
|
265 | - */ |
|
266 | - private function readConfiguration($force = false) { |
|
267 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
268 | - $this->configuration->readConfiguration(); |
|
269 | - $this->configured = $this->validateConfiguration(); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * set LDAP configuration with values delivered by an array, not read from configuration |
|
275 | - * @param array $config array that holds the config parameters in an associated array |
|
276 | - * @param array &$setParameters optional; array where the set fields will be given to |
|
277 | - * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
278 | - */ |
|
279 | - public function setConfiguration($config, &$setParameters = null) { |
|
280 | - if(is_null($setParameters)) { |
|
281 | - $setParameters = array(); |
|
282 | - } |
|
283 | - $this->doNotValidate = false; |
|
284 | - $this->configuration->setConfiguration($config, $setParameters); |
|
285 | - if(count($setParameters) > 0) { |
|
286 | - $this->configured = $this->validateConfiguration(); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - return $this->configured; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * saves the current Configuration in the database and empties the |
|
295 | - * cache |
|
296 | - * @return null |
|
297 | - */ |
|
298 | - public function saveConfiguration() { |
|
299 | - $this->configuration->saveConfiguration(); |
|
300 | - $this->clearCache(); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * get the current LDAP configuration |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - public function getConfiguration() { |
|
308 | - $this->readConfiguration(); |
|
309 | - $config = $this->configuration->getConfiguration(); |
|
310 | - $cta = $this->configuration->getConfigTranslationArray(); |
|
311 | - $result = array(); |
|
312 | - foreach($cta as $dbkey => $configkey) { |
|
313 | - switch($configkey) { |
|
314 | - case 'homeFolderNamingRule': |
|
315 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
316 | - $result[$dbkey] = substr($config[$configkey], 5); |
|
317 | - } else { |
|
318 | - $result[$dbkey] = ''; |
|
319 | - } |
|
320 | - break; |
|
321 | - case 'ldapBase': |
|
322 | - case 'ldapBaseUsers': |
|
323 | - case 'ldapBaseGroups': |
|
324 | - case 'ldapAttributesForUserSearch': |
|
325 | - case 'ldapAttributesForGroupSearch': |
|
326 | - if(is_array($config[$configkey])) { |
|
327 | - $result[$dbkey] = implode("\n", $config[$configkey]); |
|
328 | - break; |
|
329 | - } //else follows default |
|
330 | - default: |
|
331 | - $result[$dbkey] = $config[$configkey]; |
|
332 | - } |
|
333 | - } |
|
334 | - return $result; |
|
335 | - } |
|
336 | - |
|
337 | - private function doSoftValidation() { |
|
338 | - //if User or Group Base are not set, take over Base DN setting |
|
339 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
340 | - $val = $this->configuration->$keyBase; |
|
341 | - if(empty($val)) { |
|
342 | - $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
347 | - 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
348 | - as $expertSetting => $effectiveSetting) { |
|
349 | - $uuidOverride = $this->configuration->$expertSetting; |
|
350 | - if(!empty($uuidOverride)) { |
|
351 | - $this->configuration->$effectiveSetting = $uuidOverride; |
|
352 | - } else { |
|
353 | - $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
354 | - 'objectguid', 'guid', 'ipauniqueid'); |
|
355 | - if(!in_array($this->configuration->$effectiveSetting, |
|
356 | - $uuidAttributes) |
|
357 | - && (!is_null($this->configID))) { |
|
358 | - $this->configuration->$effectiveSetting = 'auto'; |
|
359 | - $this->configuration->saveConfiguration(); |
|
360 | - \OCP\Util::writeLog('user_ldap', |
|
361 | - 'Illegal value for the '. |
|
362 | - $effectiveSetting.', '.'reset to '. |
|
363 | - 'autodetect.', \OCP\Util::INFO); |
|
364 | - } |
|
365 | - |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - $backupPort = intval($this->configuration->ldapBackupPort); |
|
370 | - if ($backupPort <= 0) { |
|
371 | - $this->configuration->backupPort = $this->configuration->ldapPort; |
|
372 | - } |
|
373 | - |
|
374 | - //make sure empty search attributes are saved as simple, empty array |
|
375 | - $saKeys = array('ldapAttributesForUserSearch', |
|
376 | - 'ldapAttributesForGroupSearch'); |
|
377 | - foreach($saKeys as $key) { |
|
378 | - $val = $this->configuration->$key; |
|
379 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
380 | - $this->configuration->$key = array(); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
385 | - && $this->configuration->ldapTLS) { |
|
386 | - $this->configuration->ldapTLS = false; |
|
387 | - \OCP\Util::writeLog('user_ldap', |
|
388 | - 'LDAPS (already using secure connection) and '. |
|
389 | - 'TLS do not work together. Switched off TLS.', |
|
390 | - \OCP\Util::INFO); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - private function doCriticalValidation() { |
|
398 | - $configurationOK = true; |
|
399 | - $errorStr = 'Configuration Error (prefix '. |
|
400 | - strval($this->configPrefix).'): '; |
|
401 | - |
|
402 | - //options that shall not be empty |
|
403 | - $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
404 | - 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
405 | - foreach($options as $key) { |
|
406 | - $val = $this->configuration->$key; |
|
407 | - if(empty($val)) { |
|
408 | - switch($key) { |
|
409 | - case 'ldapHost': |
|
410 | - $subj = 'LDAP Host'; |
|
411 | - break; |
|
412 | - case 'ldapPort': |
|
413 | - $subj = 'LDAP Port'; |
|
414 | - break; |
|
415 | - case 'ldapUserDisplayName': |
|
416 | - $subj = 'LDAP User Display Name'; |
|
417 | - break; |
|
418 | - case 'ldapGroupDisplayName': |
|
419 | - $subj = 'LDAP Group Display Name'; |
|
420 | - break; |
|
421 | - case 'ldapLoginFilter': |
|
422 | - $subj = 'LDAP Login Filter'; |
|
423 | - break; |
|
424 | - default: |
|
425 | - $subj = $key; |
|
426 | - break; |
|
427 | - } |
|
428 | - $configurationOK = false; |
|
429 | - \OCP\Util::writeLog('user_ldap', |
|
430 | - $errorStr.'No '.$subj.' given!', |
|
431 | - \OCP\Util::WARN); |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - //combinations |
|
436 | - $agent = $this->configuration->ldapAgentName; |
|
437 | - $pwd = $this->configuration->ldapAgentPassword; |
|
438 | - if ( |
|
439 | - ($agent === '' && $pwd !== '') |
|
440 | - || ($agent !== '' && $pwd === '') |
|
441 | - ) { |
|
442 | - \OCP\Util::writeLog('user_ldap', |
|
443 | - $errorStr.'either no password is given for the '. |
|
444 | - 'user agent or a password is given, but not an '. |
|
445 | - 'LDAP agent.', |
|
446 | - \OCP\Util::WARN); |
|
447 | - $configurationOK = false; |
|
448 | - } |
|
449 | - |
|
450 | - $base = $this->configuration->ldapBase; |
|
451 | - $baseUsers = $this->configuration->ldapBaseUsers; |
|
452 | - $baseGroups = $this->configuration->ldapBaseGroups; |
|
453 | - |
|
454 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
455 | - \OCP\Util::writeLog('user_ldap', |
|
456 | - $errorStr.'Not a single Base DN given.', |
|
457 | - \OCP\Util::WARN); |
|
458 | - $configurationOK = false; |
|
459 | - } |
|
460 | - |
|
461 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
462 | - === false) { |
|
463 | - \OCP\Util::writeLog('user_ldap', |
|
464 | - $errorStr.'login filter does not contain %uid '. |
|
465 | - 'place holder.', |
|
466 | - \OCP\Util::WARN); |
|
467 | - $configurationOK = false; |
|
468 | - } |
|
469 | - |
|
470 | - return $configurationOK; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Validates the user specified configuration |
|
475 | - * @return bool true if configuration seems OK, false otherwise |
|
476 | - */ |
|
477 | - private function validateConfiguration() { |
|
478 | - |
|
479 | - if($this->doNotValidate) { |
|
480 | - //don't do a validation if it is a new configuration with pure |
|
481 | - //default values. Will be allowed on changes via __set or |
|
482 | - //setConfiguration |
|
483 | - return false; |
|
484 | - } |
|
485 | - |
|
486 | - // first step: "soft" checks: settings that are not really |
|
487 | - // necessary, but advisable. If left empty, give an info message |
|
488 | - $this->doSoftValidation(); |
|
489 | - |
|
490 | - //second step: critical checks. If left empty or filled wrong, mark as |
|
491 | - //not configured and give a warning. |
|
492 | - return $this->doCriticalValidation(); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * Connects and Binds to LDAP |
|
498 | - */ |
|
499 | - private function establishConnection() { |
|
500 | - if(!$this->configuration->ldapConfigurationActive) { |
|
501 | - return null; |
|
502 | - } |
|
503 | - static $phpLDAPinstalled = true; |
|
504 | - if(!$phpLDAPinstalled) { |
|
505 | - return false; |
|
506 | - } |
|
507 | - if(!$this->ignoreValidation && !$this->configured) { |
|
508 | - \OCP\Util::writeLog('user_ldap', |
|
509 | - 'Configuration is invalid, cannot connect', |
|
510 | - \OCP\Util::WARN); |
|
511 | - return false; |
|
512 | - } |
|
513 | - if(!$this->ldapConnectionRes) { |
|
514 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
515 | - $phpLDAPinstalled = false; |
|
516 | - \OCP\Util::writeLog('user_ldap', |
|
517 | - 'function ldap_connect is not available. Make '. |
|
518 | - 'sure that the PHP ldap module is installed.', |
|
519 | - \OCP\Util::ERROR); |
|
520 | - |
|
521 | - return false; |
|
522 | - } |
|
523 | - if($this->configuration->turnOffCertCheck) { |
|
524 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
525 | - \OCP\Util::writeLog('user_ldap', |
|
526 | - 'Turned off SSL certificate validation successfully.', |
|
527 | - \OCP\Util::DEBUG); |
|
528 | - } else { |
|
529 | - \OCP\Util::writeLog('user_ldap', |
|
530 | - 'Could not turn off SSL certificate validation.', |
|
531 | - \OCP\Util::WARN); |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer |
|
536 | - || $this->getFromCache('overrideMainServer')); |
|
537 | - $isBackupHost = (trim($this->configuration->ldapBackupHost) !== ""); |
|
538 | - $bindStatus = false; |
|
539 | - $error = -1; |
|
540 | - try { |
|
541 | - if (!$isOverrideMainServer) { |
|
542 | - $this->doConnect($this->configuration->ldapHost, |
|
543 | - $this->configuration->ldapPort); |
|
544 | - $bindStatus = $this->bind(); |
|
545 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
546 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
547 | - } |
|
548 | - if($bindStatus === true) { |
|
549 | - return $bindStatus; |
|
550 | - } |
|
551 | - } catch (ServerNotAvailableException $e) { |
|
552 | - if(!$isBackupHost) { |
|
553 | - throw $e; |
|
554 | - } |
|
555 | - } |
|
556 | - |
|
557 | - //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
558 | - if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
559 | - $this->doConnect($this->configuration->ldapBackupHost, |
|
560 | - $this->configuration->ldapBackupPort); |
|
561 | - $bindStatus = $this->bind(); |
|
562 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
563 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
564 | - if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
565 | - //when bind to backup server succeeded and failed to main server, |
|
566 | - //skip contacting him until next cache refresh |
|
567 | - $this->writeToCache('overrideMainServer', true); |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - return $bindStatus; |
|
572 | - } |
|
573 | - return null; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * @param string $host |
|
578 | - * @param string $port |
|
579 | - * @return bool |
|
580 | - * @throws \OC\ServerNotAvailableException |
|
581 | - */ |
|
582 | - private function doConnect($host, $port) { |
|
583 | - if ($host === '') { |
|
584 | - return false; |
|
585 | - } |
|
586 | - |
|
587 | - $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
588 | - |
|
589 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
590 | - throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
591 | - } |
|
592 | - |
|
593 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
594 | - throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
|
595 | - } |
|
596 | - |
|
597 | - if($this->configuration->ldapTLS) { |
|
598 | - if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
599 | - throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - return true; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Binds to LDAP |
|
608 | - */ |
|
609 | - public function bind() { |
|
610 | - if(!$this->configuration->ldapConfigurationActive) { |
|
611 | - return false; |
|
612 | - } |
|
613 | - $cr = $this->getConnectionResource(); |
|
614 | - if(!$this->ldap->isResource($cr)) { |
|
615 | - return false; |
|
616 | - } |
|
617 | - $ldapLogin = @$this->ldap->bind($cr, |
|
618 | - $this->configuration->ldapAgentName, |
|
619 | - $this->configuration->ldapAgentPassword); |
|
620 | - if(!$ldapLogin) { |
|
621 | - $errno = $this->ldap->errno($cr); |
|
622 | - |
|
623 | - \OCP\Util::writeLog('user_ldap', |
|
624 | - 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
625 | - \OCP\Util::WARN); |
|
626 | - |
|
627 | - // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
|
628 | - if($errno !== 0x00 && $errno !== 0x31) { |
|
629 | - $this->ldapConnectionRes = null; |
|
630 | - } |
|
631 | - |
|
632 | - return false; |
|
633 | - } |
|
634 | - return true; |
|
635 | - } |
|
59 | + private $ldapConnectionRes = null; |
|
60 | + private $configPrefix; |
|
61 | + private $configID; |
|
62 | + private $configured = false; |
|
63 | + private $hasPagedResultSupport = true; |
|
64 | + //whether connection should be kept on __destruct |
|
65 | + private $dontDestruct = false; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var bool runtime flag that indicates whether supported primary groups are available |
|
69 | + */ |
|
70 | + public $hasPrimaryGroups = true; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
74 | + */ |
|
75 | + public $hasGidNumber = true; |
|
76 | + |
|
77 | + //cache handler |
|
78 | + protected $cache; |
|
79 | + |
|
80 | + /** @var Configuration settings handler **/ |
|
81 | + protected $configuration; |
|
82 | + |
|
83 | + protected $doNotValidate = false; |
|
84 | + |
|
85 | + protected $ignoreValidation = false; |
|
86 | + |
|
87 | + /** |
|
88 | + * Constructor |
|
89 | + * @param ILDAPWrapper $ldap |
|
90 | + * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
91 | + * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
92 | + */ |
|
93 | + public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
94 | + parent::__construct($ldap); |
|
95 | + $this->configPrefix = $configPrefix; |
|
96 | + $this->configID = $configID; |
|
97 | + $this->configuration = new Configuration($configPrefix, |
|
98 | + !is_null($configID)); |
|
99 | + $memcache = \OC::$server->getMemCacheFactory(); |
|
100 | + if($memcache->isAvailable()) { |
|
101 | + $this->cache = $memcache->create(); |
|
102 | + } |
|
103 | + $helper = new Helper(\OC::$server->getConfig()); |
|
104 | + $this->doNotValidate = !in_array($this->configPrefix, |
|
105 | + $helper->getServerConfigurationPrefixes()); |
|
106 | + $this->hasPagedResultSupport = |
|
107 | + intval($this->configuration->ldapPagingSize) !== 0 |
|
108 | + || $this->ldap->hasPagedResultSupport(); |
|
109 | + } |
|
110 | + |
|
111 | + public function __destruct() { |
|
112 | + if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
113 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
114 | + }; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * defines behaviour when the instance is cloned |
|
119 | + */ |
|
120 | + public function __clone() { |
|
121 | + $this->configuration = new Configuration($this->configPrefix, |
|
122 | + !is_null($this->configID)); |
|
123 | + $this->ldapConnectionRes = null; |
|
124 | + $this->dontDestruct = true; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $name |
|
129 | + * @return bool|mixed |
|
130 | + */ |
|
131 | + public function __get($name) { |
|
132 | + if(!$this->configured) { |
|
133 | + $this->readConfiguration(); |
|
134 | + } |
|
135 | + |
|
136 | + if($name === 'hasPagedResultSupport') { |
|
137 | + return $this->hasPagedResultSupport; |
|
138 | + } |
|
139 | + |
|
140 | + return $this->configuration->$name; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $name |
|
145 | + * @param mixed $value |
|
146 | + */ |
|
147 | + public function __set($name, $value) { |
|
148 | + $this->doNotValidate = false; |
|
149 | + $before = $this->configuration->$name; |
|
150 | + $this->configuration->$name = $value; |
|
151 | + $after = $this->configuration->$name; |
|
152 | + if($before !== $after) { |
|
153 | + if ($this->configID !== '' && $this->configID !== null) { |
|
154 | + $this->configuration->saveConfiguration(); |
|
155 | + } |
|
156 | + $this->validateConfiguration(); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * sets whether the result of the configuration validation shall |
|
162 | + * be ignored when establishing the connection. Used by the Wizard |
|
163 | + * in early configuration state. |
|
164 | + * @param bool $state |
|
165 | + */ |
|
166 | + public function setIgnoreValidation($state) { |
|
167 | + $this->ignoreValidation = (bool)$state; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * initializes the LDAP backend |
|
172 | + * @param bool $force read the config settings no matter what |
|
173 | + */ |
|
174 | + public function init($force = false) { |
|
175 | + $this->readConfiguration($force); |
|
176 | + $this->establishConnection(); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Returns the LDAP handler |
|
181 | + */ |
|
182 | + public function getConnectionResource() { |
|
183 | + if(!$this->ldapConnectionRes) { |
|
184 | + $this->init(); |
|
185 | + } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
186 | + $this->ldapConnectionRes = null; |
|
187 | + $this->establishConnection(); |
|
188 | + } |
|
189 | + if(is_null($this->ldapConnectionRes)) { |
|
190 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
191 | + throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
192 | + } |
|
193 | + return $this->ldapConnectionRes; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * resets the connection resource |
|
198 | + */ |
|
199 | + public function resetConnectionResource() { |
|
200 | + if(!is_null($this->ldapConnectionRes)) { |
|
201 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
202 | + $this->ldapConnectionRes = null; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string|null $key |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + private function getCacheKey($key) { |
|
211 | + $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
212 | + if(is_null($key)) { |
|
213 | + return $prefix; |
|
214 | + } |
|
215 | + return $prefix.md5($key); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @param string $key |
|
220 | + * @return mixed|null |
|
221 | + */ |
|
222 | + public function getFromCache($key) { |
|
223 | + if(!$this->configured) { |
|
224 | + $this->readConfiguration(); |
|
225 | + } |
|
226 | + if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
227 | + return null; |
|
228 | + } |
|
229 | + $key = $this->getCacheKey($key); |
|
230 | + |
|
231 | + return json_decode(base64_decode($this->cache->get($key)), true); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @param string $key |
|
236 | + * @param mixed $value |
|
237 | + * |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function writeToCache($key, $value) { |
|
241 | + if(!$this->configured) { |
|
242 | + $this->readConfiguration(); |
|
243 | + } |
|
244 | + if(is_null($this->cache) |
|
245 | + || !$this->configuration->ldapCacheTTL |
|
246 | + || !$this->configuration->ldapConfigurationActive) { |
|
247 | + return null; |
|
248 | + } |
|
249 | + $key = $this->getCacheKey($key); |
|
250 | + $value = base64_encode(json_encode($value)); |
|
251 | + $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
252 | + } |
|
253 | + |
|
254 | + public function clearCache() { |
|
255 | + if(!is_null($this->cache)) { |
|
256 | + $this->cache->clear($this->getCacheKey(null)); |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Caches the general LDAP configuration. |
|
262 | + * @param bool $force optional. true, if the re-read should be forced. defaults |
|
263 | + * to false. |
|
264 | + * @return null |
|
265 | + */ |
|
266 | + private function readConfiguration($force = false) { |
|
267 | + if((!$this->configured || $force) && !is_null($this->configID)) { |
|
268 | + $this->configuration->readConfiguration(); |
|
269 | + $this->configured = $this->validateConfiguration(); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * set LDAP configuration with values delivered by an array, not read from configuration |
|
275 | + * @param array $config array that holds the config parameters in an associated array |
|
276 | + * @param array &$setParameters optional; array where the set fields will be given to |
|
277 | + * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
278 | + */ |
|
279 | + public function setConfiguration($config, &$setParameters = null) { |
|
280 | + if(is_null($setParameters)) { |
|
281 | + $setParameters = array(); |
|
282 | + } |
|
283 | + $this->doNotValidate = false; |
|
284 | + $this->configuration->setConfiguration($config, $setParameters); |
|
285 | + if(count($setParameters) > 0) { |
|
286 | + $this->configured = $this->validateConfiguration(); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + return $this->configured; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * saves the current Configuration in the database and empties the |
|
295 | + * cache |
|
296 | + * @return null |
|
297 | + */ |
|
298 | + public function saveConfiguration() { |
|
299 | + $this->configuration->saveConfiguration(); |
|
300 | + $this->clearCache(); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * get the current LDAP configuration |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + public function getConfiguration() { |
|
308 | + $this->readConfiguration(); |
|
309 | + $config = $this->configuration->getConfiguration(); |
|
310 | + $cta = $this->configuration->getConfigTranslationArray(); |
|
311 | + $result = array(); |
|
312 | + foreach($cta as $dbkey => $configkey) { |
|
313 | + switch($configkey) { |
|
314 | + case 'homeFolderNamingRule': |
|
315 | + if(strpos($config[$configkey], 'attr:') === 0) { |
|
316 | + $result[$dbkey] = substr($config[$configkey], 5); |
|
317 | + } else { |
|
318 | + $result[$dbkey] = ''; |
|
319 | + } |
|
320 | + break; |
|
321 | + case 'ldapBase': |
|
322 | + case 'ldapBaseUsers': |
|
323 | + case 'ldapBaseGroups': |
|
324 | + case 'ldapAttributesForUserSearch': |
|
325 | + case 'ldapAttributesForGroupSearch': |
|
326 | + if(is_array($config[$configkey])) { |
|
327 | + $result[$dbkey] = implode("\n", $config[$configkey]); |
|
328 | + break; |
|
329 | + } //else follows default |
|
330 | + default: |
|
331 | + $result[$dbkey] = $config[$configkey]; |
|
332 | + } |
|
333 | + } |
|
334 | + return $result; |
|
335 | + } |
|
336 | + |
|
337 | + private function doSoftValidation() { |
|
338 | + //if User or Group Base are not set, take over Base DN setting |
|
339 | + foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
340 | + $val = $this->configuration->$keyBase; |
|
341 | + if(empty($val)) { |
|
342 | + $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
347 | + 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
348 | + as $expertSetting => $effectiveSetting) { |
|
349 | + $uuidOverride = $this->configuration->$expertSetting; |
|
350 | + if(!empty($uuidOverride)) { |
|
351 | + $this->configuration->$effectiveSetting = $uuidOverride; |
|
352 | + } else { |
|
353 | + $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
|
354 | + 'objectguid', 'guid', 'ipauniqueid'); |
|
355 | + if(!in_array($this->configuration->$effectiveSetting, |
|
356 | + $uuidAttributes) |
|
357 | + && (!is_null($this->configID))) { |
|
358 | + $this->configuration->$effectiveSetting = 'auto'; |
|
359 | + $this->configuration->saveConfiguration(); |
|
360 | + \OCP\Util::writeLog('user_ldap', |
|
361 | + 'Illegal value for the '. |
|
362 | + $effectiveSetting.', '.'reset to '. |
|
363 | + 'autodetect.', \OCP\Util::INFO); |
|
364 | + } |
|
365 | + |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + $backupPort = intval($this->configuration->ldapBackupPort); |
|
370 | + if ($backupPort <= 0) { |
|
371 | + $this->configuration->backupPort = $this->configuration->ldapPort; |
|
372 | + } |
|
373 | + |
|
374 | + //make sure empty search attributes are saved as simple, empty array |
|
375 | + $saKeys = array('ldapAttributesForUserSearch', |
|
376 | + 'ldapAttributesForGroupSearch'); |
|
377 | + foreach($saKeys as $key) { |
|
378 | + $val = $this->configuration->$key; |
|
379 | + if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
380 | + $this->configuration->$key = array(); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
385 | + && $this->configuration->ldapTLS) { |
|
386 | + $this->configuration->ldapTLS = false; |
|
387 | + \OCP\Util::writeLog('user_ldap', |
|
388 | + 'LDAPS (already using secure connection) and '. |
|
389 | + 'TLS do not work together. Switched off TLS.', |
|
390 | + \OCP\Util::INFO); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + private function doCriticalValidation() { |
|
398 | + $configurationOK = true; |
|
399 | + $errorStr = 'Configuration Error (prefix '. |
|
400 | + strval($this->configPrefix).'): '; |
|
401 | + |
|
402 | + //options that shall not be empty |
|
403 | + $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
404 | + 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
405 | + foreach($options as $key) { |
|
406 | + $val = $this->configuration->$key; |
|
407 | + if(empty($val)) { |
|
408 | + switch($key) { |
|
409 | + case 'ldapHost': |
|
410 | + $subj = 'LDAP Host'; |
|
411 | + break; |
|
412 | + case 'ldapPort': |
|
413 | + $subj = 'LDAP Port'; |
|
414 | + break; |
|
415 | + case 'ldapUserDisplayName': |
|
416 | + $subj = 'LDAP User Display Name'; |
|
417 | + break; |
|
418 | + case 'ldapGroupDisplayName': |
|
419 | + $subj = 'LDAP Group Display Name'; |
|
420 | + break; |
|
421 | + case 'ldapLoginFilter': |
|
422 | + $subj = 'LDAP Login Filter'; |
|
423 | + break; |
|
424 | + default: |
|
425 | + $subj = $key; |
|
426 | + break; |
|
427 | + } |
|
428 | + $configurationOK = false; |
|
429 | + \OCP\Util::writeLog('user_ldap', |
|
430 | + $errorStr.'No '.$subj.' given!', |
|
431 | + \OCP\Util::WARN); |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + //combinations |
|
436 | + $agent = $this->configuration->ldapAgentName; |
|
437 | + $pwd = $this->configuration->ldapAgentPassword; |
|
438 | + if ( |
|
439 | + ($agent === '' && $pwd !== '') |
|
440 | + || ($agent !== '' && $pwd === '') |
|
441 | + ) { |
|
442 | + \OCP\Util::writeLog('user_ldap', |
|
443 | + $errorStr.'either no password is given for the '. |
|
444 | + 'user agent or a password is given, but not an '. |
|
445 | + 'LDAP agent.', |
|
446 | + \OCP\Util::WARN); |
|
447 | + $configurationOK = false; |
|
448 | + } |
|
449 | + |
|
450 | + $base = $this->configuration->ldapBase; |
|
451 | + $baseUsers = $this->configuration->ldapBaseUsers; |
|
452 | + $baseGroups = $this->configuration->ldapBaseGroups; |
|
453 | + |
|
454 | + if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
455 | + \OCP\Util::writeLog('user_ldap', |
|
456 | + $errorStr.'Not a single Base DN given.', |
|
457 | + \OCP\Util::WARN); |
|
458 | + $configurationOK = false; |
|
459 | + } |
|
460 | + |
|
461 | + if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
462 | + === false) { |
|
463 | + \OCP\Util::writeLog('user_ldap', |
|
464 | + $errorStr.'login filter does not contain %uid '. |
|
465 | + 'place holder.', |
|
466 | + \OCP\Util::WARN); |
|
467 | + $configurationOK = false; |
|
468 | + } |
|
469 | + |
|
470 | + return $configurationOK; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Validates the user specified configuration |
|
475 | + * @return bool true if configuration seems OK, false otherwise |
|
476 | + */ |
|
477 | + private function validateConfiguration() { |
|
478 | + |
|
479 | + if($this->doNotValidate) { |
|
480 | + //don't do a validation if it is a new configuration with pure |
|
481 | + //default values. Will be allowed on changes via __set or |
|
482 | + //setConfiguration |
|
483 | + return false; |
|
484 | + } |
|
485 | + |
|
486 | + // first step: "soft" checks: settings that are not really |
|
487 | + // necessary, but advisable. If left empty, give an info message |
|
488 | + $this->doSoftValidation(); |
|
489 | + |
|
490 | + //second step: critical checks. If left empty or filled wrong, mark as |
|
491 | + //not configured and give a warning. |
|
492 | + return $this->doCriticalValidation(); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * Connects and Binds to LDAP |
|
498 | + */ |
|
499 | + private function establishConnection() { |
|
500 | + if(!$this->configuration->ldapConfigurationActive) { |
|
501 | + return null; |
|
502 | + } |
|
503 | + static $phpLDAPinstalled = true; |
|
504 | + if(!$phpLDAPinstalled) { |
|
505 | + return false; |
|
506 | + } |
|
507 | + if(!$this->ignoreValidation && !$this->configured) { |
|
508 | + \OCP\Util::writeLog('user_ldap', |
|
509 | + 'Configuration is invalid, cannot connect', |
|
510 | + \OCP\Util::WARN); |
|
511 | + return false; |
|
512 | + } |
|
513 | + if(!$this->ldapConnectionRes) { |
|
514 | + if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
515 | + $phpLDAPinstalled = false; |
|
516 | + \OCP\Util::writeLog('user_ldap', |
|
517 | + 'function ldap_connect is not available. Make '. |
|
518 | + 'sure that the PHP ldap module is installed.', |
|
519 | + \OCP\Util::ERROR); |
|
520 | + |
|
521 | + return false; |
|
522 | + } |
|
523 | + if($this->configuration->turnOffCertCheck) { |
|
524 | + if(putenv('LDAPTLS_REQCERT=never')) { |
|
525 | + \OCP\Util::writeLog('user_ldap', |
|
526 | + 'Turned off SSL certificate validation successfully.', |
|
527 | + \OCP\Util::DEBUG); |
|
528 | + } else { |
|
529 | + \OCP\Util::writeLog('user_ldap', |
|
530 | + 'Could not turn off SSL certificate validation.', |
|
531 | + \OCP\Util::WARN); |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer |
|
536 | + || $this->getFromCache('overrideMainServer')); |
|
537 | + $isBackupHost = (trim($this->configuration->ldapBackupHost) !== ""); |
|
538 | + $bindStatus = false; |
|
539 | + $error = -1; |
|
540 | + try { |
|
541 | + if (!$isOverrideMainServer) { |
|
542 | + $this->doConnect($this->configuration->ldapHost, |
|
543 | + $this->configuration->ldapPort); |
|
544 | + $bindStatus = $this->bind(); |
|
545 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
546 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
547 | + } |
|
548 | + if($bindStatus === true) { |
|
549 | + return $bindStatus; |
|
550 | + } |
|
551 | + } catch (ServerNotAvailableException $e) { |
|
552 | + if(!$isBackupHost) { |
|
553 | + throw $e; |
|
554 | + } |
|
555 | + } |
|
556 | + |
|
557 | + //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
558 | + if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
559 | + $this->doConnect($this->configuration->ldapBackupHost, |
|
560 | + $this->configuration->ldapBackupPort); |
|
561 | + $bindStatus = $this->bind(); |
|
562 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
563 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
564 | + if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
565 | + //when bind to backup server succeeded and failed to main server, |
|
566 | + //skip contacting him until next cache refresh |
|
567 | + $this->writeToCache('overrideMainServer', true); |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + return $bindStatus; |
|
572 | + } |
|
573 | + return null; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * @param string $host |
|
578 | + * @param string $port |
|
579 | + * @return bool |
|
580 | + * @throws \OC\ServerNotAvailableException |
|
581 | + */ |
|
582 | + private function doConnect($host, $port) { |
|
583 | + if ($host === '') { |
|
584 | + return false; |
|
585 | + } |
|
586 | + |
|
587 | + $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
588 | + |
|
589 | + if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
590 | + throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
591 | + } |
|
592 | + |
|
593 | + if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
594 | + throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
|
595 | + } |
|
596 | + |
|
597 | + if($this->configuration->ldapTLS) { |
|
598 | + if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
599 | + throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + return true; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Binds to LDAP |
|
608 | + */ |
|
609 | + public function bind() { |
|
610 | + if(!$this->configuration->ldapConfigurationActive) { |
|
611 | + return false; |
|
612 | + } |
|
613 | + $cr = $this->getConnectionResource(); |
|
614 | + if(!$this->ldap->isResource($cr)) { |
|
615 | + return false; |
|
616 | + } |
|
617 | + $ldapLogin = @$this->ldap->bind($cr, |
|
618 | + $this->configuration->ldapAgentName, |
|
619 | + $this->configuration->ldapAgentPassword); |
|
620 | + if(!$ldapLogin) { |
|
621 | + $errno = $this->ldap->errno($cr); |
|
622 | + |
|
623 | + \OCP\Util::writeLog('user_ldap', |
|
624 | + 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
625 | + \OCP\Util::WARN); |
|
626 | + |
|
627 | + // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
|
628 | + if($errno !== 0x00 && $errno !== 0x31) { |
|
629 | + $this->ldapConnectionRes = null; |
|
630 | + } |
|
631 | + |
|
632 | + return false; |
|
633 | + } |
|
634 | + return true; |
|
635 | + } |
|
636 | 636 | |
637 | 637 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $this->configuration = new Configuration($configPrefix, |
98 | 98 | !is_null($configID)); |
99 | 99 | $memcache = \OC::$server->getMemCacheFactory(); |
100 | - if($memcache->isAvailable()) { |
|
100 | + if ($memcache->isAvailable()) { |
|
101 | 101 | $this->cache = $memcache->create(); |
102 | 102 | } |
103 | 103 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | public function __destruct() { |
112 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
112 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
113 | 113 | @$this->ldap->unbind($this->ldapConnectionRes); |
114 | 114 | }; |
115 | 115 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * @return bool|mixed |
130 | 130 | */ |
131 | 131 | public function __get($name) { |
132 | - if(!$this->configured) { |
|
132 | + if (!$this->configured) { |
|
133 | 133 | $this->readConfiguration(); |
134 | 134 | } |
135 | 135 | |
136 | - if($name === 'hasPagedResultSupport') { |
|
136 | + if ($name === 'hasPagedResultSupport') { |
|
137 | 137 | return $this->hasPagedResultSupport; |
138 | 138 | } |
139 | 139 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $before = $this->configuration->$name; |
150 | 150 | $this->configuration->$name = $value; |
151 | 151 | $after = $this->configuration->$name; |
152 | - if($before !== $after) { |
|
152 | + if ($before !== $after) { |
|
153 | 153 | if ($this->configID !== '' && $this->configID !== null) { |
154 | 154 | $this->configuration->saveConfiguration(); |
155 | 155 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param bool $state |
165 | 165 | */ |
166 | 166 | public function setIgnoreValidation($state) { |
167 | - $this->ignoreValidation = (bool)$state; |
|
167 | + $this->ignoreValidation = (bool) $state; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | * Returns the LDAP handler |
181 | 181 | */ |
182 | 182 | public function getConnectionResource() { |
183 | - if(!$this->ldapConnectionRes) { |
|
183 | + if (!$this->ldapConnectionRes) { |
|
184 | 184 | $this->init(); |
185 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
185 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
186 | 186 | $this->ldapConnectionRes = null; |
187 | 187 | $this->establishConnection(); |
188 | 188 | } |
189 | - if(is_null($this->ldapConnectionRes)) { |
|
190 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
189 | + if (is_null($this->ldapConnectionRes)) { |
|
190 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
191 | 191 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
192 | 192 | } |
193 | 193 | return $this->ldapConnectionRes; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * resets the connection resource |
198 | 198 | */ |
199 | 199 | public function resetConnectionResource() { |
200 | - if(!is_null($this->ldapConnectionRes)) { |
|
200 | + if (!is_null($this->ldapConnectionRes)) { |
|
201 | 201 | @$this->ldap->unbind($this->ldapConnectionRes); |
202 | 202 | $this->ldapConnectionRes = null; |
203 | 203 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function getCacheKey($key) { |
211 | 211 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
212 | - if(is_null($key)) { |
|
212 | + if (is_null($key)) { |
|
213 | 213 | return $prefix; |
214 | 214 | } |
215 | 215 | return $prefix.md5($key); |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | * @return mixed|null |
221 | 221 | */ |
222 | 222 | public function getFromCache($key) { |
223 | - if(!$this->configured) { |
|
223 | + if (!$this->configured) { |
|
224 | 224 | $this->readConfiguration(); |
225 | 225 | } |
226 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
226 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
227 | 227 | return null; |
228 | 228 | } |
229 | 229 | $key = $this->getCacheKey($key); |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | * @return string |
239 | 239 | */ |
240 | 240 | public function writeToCache($key, $value) { |
241 | - if(!$this->configured) { |
|
241 | + if (!$this->configured) { |
|
242 | 242 | $this->readConfiguration(); |
243 | 243 | } |
244 | - if(is_null($this->cache) |
|
244 | + if (is_null($this->cache) |
|
245 | 245 | || !$this->configuration->ldapCacheTTL |
246 | 246 | || !$this->configuration->ldapConfigurationActive) { |
247 | 247 | return null; |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | public function clearCache() { |
255 | - if(!is_null($this->cache)) { |
|
255 | + if (!is_null($this->cache)) { |
|
256 | 256 | $this->cache->clear($this->getCacheKey(null)); |
257 | 257 | } |
258 | 258 | } |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @return null |
265 | 265 | */ |
266 | 266 | private function readConfiguration($force = false) { |
267 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
267 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
268 | 268 | $this->configuration->readConfiguration(); |
269 | 269 | $this->configured = $this->validateConfiguration(); |
270 | 270 | } |
@@ -277,12 +277,12 @@ discard block |
||
277 | 277 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
278 | 278 | */ |
279 | 279 | public function setConfiguration($config, &$setParameters = null) { |
280 | - if(is_null($setParameters)) { |
|
280 | + if (is_null($setParameters)) { |
|
281 | 281 | $setParameters = array(); |
282 | 282 | } |
283 | 283 | $this->doNotValidate = false; |
284 | 284 | $this->configuration->setConfiguration($config, $setParameters); |
285 | - if(count($setParameters) > 0) { |
|
285 | + if (count($setParameters) > 0) { |
|
286 | 286 | $this->configured = $this->validateConfiguration(); |
287 | 287 | } |
288 | 288 | |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | $config = $this->configuration->getConfiguration(); |
310 | 310 | $cta = $this->configuration->getConfigTranslationArray(); |
311 | 311 | $result = array(); |
312 | - foreach($cta as $dbkey => $configkey) { |
|
313 | - switch($configkey) { |
|
312 | + foreach ($cta as $dbkey => $configkey) { |
|
313 | + switch ($configkey) { |
|
314 | 314 | case 'homeFolderNamingRule': |
315 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
315 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
316 | 316 | $result[$dbkey] = substr($config[$configkey], 5); |
317 | 317 | } else { |
318 | 318 | $result[$dbkey] = ''; |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | case 'ldapBaseGroups': |
324 | 324 | case 'ldapAttributesForUserSearch': |
325 | 325 | case 'ldapAttributesForGroupSearch': |
326 | - if(is_array($config[$configkey])) { |
|
326 | + if (is_array($config[$configkey])) { |
|
327 | 327 | $result[$dbkey] = implode("\n", $config[$configkey]); |
328 | 328 | break; |
329 | 329 | } //else follows default |
@@ -336,23 +336,23 @@ discard block |
||
336 | 336 | |
337 | 337 | private function doSoftValidation() { |
338 | 338 | //if User or Group Base are not set, take over Base DN setting |
339 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
339 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
340 | 340 | $val = $this->configuration->$keyBase; |
341 | - if(empty($val)) { |
|
341 | + if (empty($val)) { |
|
342 | 342 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
346 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
346 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
347 | 347 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
348 | 348 | as $expertSetting => $effectiveSetting) { |
349 | 349 | $uuidOverride = $this->configuration->$expertSetting; |
350 | - if(!empty($uuidOverride)) { |
|
350 | + if (!empty($uuidOverride)) { |
|
351 | 351 | $this->configuration->$effectiveSetting = $uuidOverride; |
352 | 352 | } else { |
353 | 353 | $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
354 | 354 | 'objectguid', 'guid', 'ipauniqueid'); |
355 | - if(!in_array($this->configuration->$effectiveSetting, |
|
355 | + if (!in_array($this->configuration->$effectiveSetting, |
|
356 | 356 | $uuidAttributes) |
357 | 357 | && (!is_null($this->configID))) { |
358 | 358 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -374,14 +374,14 @@ discard block |
||
374 | 374 | //make sure empty search attributes are saved as simple, empty array |
375 | 375 | $saKeys = array('ldapAttributesForUserSearch', |
376 | 376 | 'ldapAttributesForGroupSearch'); |
377 | - foreach($saKeys as $key) { |
|
377 | + foreach ($saKeys as $key) { |
|
378 | 378 | $val = $this->configuration->$key; |
379 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
379 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
380 | 380 | $this->configuration->$key = array(); |
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
384 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
385 | 385 | && $this->configuration->ldapTLS) { |
386 | 386 | $this->configuration->ldapTLS = false; |
387 | 387 | \OCP\Util::writeLog('user_ldap', |
@@ -402,10 +402,10 @@ discard block |
||
402 | 402 | //options that shall not be empty |
403 | 403 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
404 | 404 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
405 | - foreach($options as $key) { |
|
405 | + foreach ($options as $key) { |
|
406 | 406 | $val = $this->configuration->$key; |
407 | - if(empty($val)) { |
|
408 | - switch($key) { |
|
407 | + if (empty($val)) { |
|
408 | + switch ($key) { |
|
409 | 409 | case 'ldapHost': |
410 | 410 | $subj = 'LDAP Host'; |
411 | 411 | break; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | $agent = $this->configuration->ldapAgentName; |
437 | 437 | $pwd = $this->configuration->ldapAgentPassword; |
438 | 438 | if ( |
439 | - ($agent === '' && $pwd !== '') |
|
439 | + ($agent === '' && $pwd !== '') |
|
440 | 440 | || ($agent !== '' && $pwd === '') |
441 | 441 | ) { |
442 | 442 | \OCP\Util::writeLog('user_ldap', |
@@ -451,14 +451,14 @@ discard block |
||
451 | 451 | $baseUsers = $this->configuration->ldapBaseUsers; |
452 | 452 | $baseGroups = $this->configuration->ldapBaseGroups; |
453 | 453 | |
454 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
454 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
455 | 455 | \OCP\Util::writeLog('user_ldap', |
456 | 456 | $errorStr.'Not a single Base DN given.', |
457 | 457 | \OCP\Util::WARN); |
458 | 458 | $configurationOK = false; |
459 | 459 | } |
460 | 460 | |
461 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
461 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
462 | 462 | === false) { |
463 | 463 | \OCP\Util::writeLog('user_ldap', |
464 | 464 | $errorStr.'login filter does not contain %uid '. |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | */ |
477 | 477 | private function validateConfiguration() { |
478 | 478 | |
479 | - if($this->doNotValidate) { |
|
479 | + if ($this->doNotValidate) { |
|
480 | 480 | //don't do a validation if it is a new configuration with pure |
481 | 481 | //default values. Will be allowed on changes via __set or |
482 | 482 | //setConfiguration |
@@ -497,21 +497,21 @@ discard block |
||
497 | 497 | * Connects and Binds to LDAP |
498 | 498 | */ |
499 | 499 | private function establishConnection() { |
500 | - if(!$this->configuration->ldapConfigurationActive) { |
|
500 | + if (!$this->configuration->ldapConfigurationActive) { |
|
501 | 501 | return null; |
502 | 502 | } |
503 | 503 | static $phpLDAPinstalled = true; |
504 | - if(!$phpLDAPinstalled) { |
|
504 | + if (!$phpLDAPinstalled) { |
|
505 | 505 | return false; |
506 | 506 | } |
507 | - if(!$this->ignoreValidation && !$this->configured) { |
|
507 | + if (!$this->ignoreValidation && !$this->configured) { |
|
508 | 508 | \OCP\Util::writeLog('user_ldap', |
509 | 509 | 'Configuration is invalid, cannot connect', |
510 | 510 | \OCP\Util::WARN); |
511 | 511 | return false; |
512 | 512 | } |
513 | - if(!$this->ldapConnectionRes) { |
|
514 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
513 | + if (!$this->ldapConnectionRes) { |
|
514 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
515 | 515 | $phpLDAPinstalled = false; |
516 | 516 | \OCP\Util::writeLog('user_ldap', |
517 | 517 | 'function ldap_connect is not available. Make '. |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | |
521 | 521 | return false; |
522 | 522 | } |
523 | - if($this->configuration->turnOffCertCheck) { |
|
524 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
523 | + if ($this->configuration->turnOffCertCheck) { |
|
524 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
525 | 525 | \OCP\Util::writeLog('user_ldap', |
526 | 526 | 'Turned off SSL certificate validation successfully.', |
527 | 527 | \OCP\Util::DEBUG); |
@@ -545,23 +545,23 @@ discard block |
||
545 | 545 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
546 | 546 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
547 | 547 | } |
548 | - if($bindStatus === true) { |
|
548 | + if ($bindStatus === true) { |
|
549 | 549 | return $bindStatus; |
550 | 550 | } |
551 | 551 | } catch (ServerNotAvailableException $e) { |
552 | - if(!$isBackupHost) { |
|
552 | + if (!$isBackupHost) { |
|
553 | 553 | throw $e; |
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
557 | 557 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
558 | - if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
558 | + if ($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
559 | 559 | $this->doConnect($this->configuration->ldapBackupHost, |
560 | 560 | $this->configuration->ldapBackupPort); |
561 | 561 | $bindStatus = $this->bind(); |
562 | 562 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
563 | 563 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
564 | - if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
564 | + if ($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
565 | 565 | //when bind to backup server succeeded and failed to main server, |
566 | 566 | //skip contacting him until next cache refresh |
567 | 567 | $this->writeToCache('overrideMainServer', true); |
@@ -586,17 +586,17 @@ discard block |
||
586 | 586 | |
587 | 587 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
588 | 588 | |
589 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
589 | + if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
590 | 590 | throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
591 | 591 | } |
592 | 592 | |
593 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
593 | + if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
594 | 594 | throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
595 | 595 | } |
596 | 596 | |
597 | - if($this->configuration->ldapTLS) { |
|
598 | - if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
599 | - throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
597 | + if ($this->configuration->ldapTLS) { |
|
598 | + if (!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
599 | + throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host '.$host.'.'); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
@@ -607,25 +607,25 @@ discard block |
||
607 | 607 | * Binds to LDAP |
608 | 608 | */ |
609 | 609 | public function bind() { |
610 | - if(!$this->configuration->ldapConfigurationActive) { |
|
610 | + if (!$this->configuration->ldapConfigurationActive) { |
|
611 | 611 | return false; |
612 | 612 | } |
613 | 613 | $cr = $this->getConnectionResource(); |
614 | - if(!$this->ldap->isResource($cr)) { |
|
614 | + if (!$this->ldap->isResource($cr)) { |
|
615 | 615 | return false; |
616 | 616 | } |
617 | 617 | $ldapLogin = @$this->ldap->bind($cr, |
618 | 618 | $this->configuration->ldapAgentName, |
619 | 619 | $this->configuration->ldapAgentPassword); |
620 | - if(!$ldapLogin) { |
|
620 | + if (!$ldapLogin) { |
|
621 | 621 | $errno = $this->ldap->errno($cr); |
622 | 622 | |
623 | 623 | \OCP\Util::writeLog('user_ldap', |
624 | - 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
624 | + 'Bind failed: '.$errno.': '.$this->ldap->error($cr), |
|
625 | 625 | \OCP\Util::WARN); |
626 | 626 | |
627 | 627 | // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
628 | - if($errno !== 0x00 && $errno !== 0x31) { |
|
628 | + if ($errno !== 0x00 && $errno !== 0x31) { |
|
629 | 629 | $this->ldapConnectionRes = null; |
630 | 630 | } |
631 | 631 |