@@ -103,6 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * Chceks if the ownCloud server can connect to a specific URL using both HTTPS and HTTP |
| 106 | + * @param string $sitename |
|
| 106 | 107 | * @return bool |
| 107 | 108 | */ |
| 108 | 109 | private function isSiteReachable($sitename) { |
@@ -285,7 +286,7 @@ discard block |
||
| 285 | 286 | |
| 286 | 287 | /** |
| 287 | 288 | * @NoCSRFRequired |
| 288 | - * @return DataResponse |
|
| 289 | + * @return DataDisplayResponse |
|
| 289 | 290 | */ |
| 290 | 291 | public function getFailedIntegrityCheckFiles() { |
| 291 | 292 | if(!$this->checker->isCodeCheckEnforced()) { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | 'www.google.com', |
| 105 | 105 | 'www.github.com']; |
| 106 | 106 | |
| 107 | - foreach($siteArray as $site) { |
|
| 107 | + foreach ($siteArray as $site) { |
|
| 108 | 108 | if ($this->isSiteReachable($site)) { |
| 109 | 109 | return true; |
| 110 | 110 | } |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | 119 | private function isSiteReachable($sitename) { |
| 120 | - $httpSiteName = 'http://' . $sitename . '/'; |
|
| 121 | - $httpsSiteName = 'https://' . $sitename . '/'; |
|
| 120 | + $httpSiteName = 'http://'.$sitename.'/'; |
|
| 121 | + $httpsSiteName = 'https://'.$sitename.'/'; |
|
| 122 | 122 | |
| 123 | 123 | try { |
| 124 | 124 | $client = $this->clientService->newClient(); |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | * @return bool |
| 146 | 146 | */ |
| 147 | 147 | private function isUrandomAvailable() { |
| 148 | - if(@file_exists('/dev/urandom')) { |
|
| 148 | + if (@file_exists('/dev/urandom')) { |
|
| 149 | 149 | $file = fopen('/dev/urandom', 'rb'); |
| 150 | - if($file) { |
|
| 150 | + if ($file) { |
|
| 151 | 151 | fclose($file); |
| 152 | 152 | return true; |
| 153 | 153 | } |
@@ -178,40 +178,40 @@ discard block |
||
| 178 | 178 | // Don't run check when: |
| 179 | 179 | // 1. Server has `has_internet_connection` set to false |
| 180 | 180 | // 2. AppStore AND S2S is disabled |
| 181 | - if(!$this->config->getSystemValue('has_internet_connection', true)) { |
|
| 181 | + if (!$this->config->getSystemValue('has_internet_connection', true)) { |
|
| 182 | 182 | return ''; |
| 183 | 183 | } |
| 184 | - if(!$this->config->getSystemValue('appstoreenabled', true) |
|
| 184 | + if (!$this->config->getSystemValue('appstoreenabled', true) |
|
| 185 | 185 | && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no' |
| 186 | 186 | && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') { |
| 187 | 187 | return ''; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $versionString = $this->getCurlVersion(); |
| 191 | - if(isset($versionString['ssl_version'])) { |
|
| 191 | + if (isset($versionString['ssl_version'])) { |
|
| 192 | 192 | $versionString = $versionString['ssl_version']; |
| 193 | 193 | } else { |
| 194 | 194 | return ''; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing'); |
|
| 198 | - if(!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 199 | - $features = (string)$this->l10n->t('Federated Cloud Sharing'); |
|
| 197 | + $features = (string) $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing'); |
|
| 198 | + if (!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 199 | + $features = (string) $this->l10n->t('Federated Cloud Sharing'); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Check if at least OpenSSL after 1.01d or 1.0.2b |
| 203 | - if(strpos($versionString, 'OpenSSL/') === 0) { |
|
| 203 | + if (strpos($versionString, 'OpenSSL/') === 0) { |
|
| 204 | 204 | $majorVersion = substr($versionString, 8, 5); |
| 205 | 205 | $patchRelease = substr($versionString, 13, 6); |
| 206 | 206 | |
| 207 | - if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) || |
|
| 207 | + if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) || |
|
| 208 | 208 | ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) { |
| 209 | 209 | return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]); |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // Check if NSS and perform heuristic check |
| 214 | - if(strpos($versionString, 'NSS/') === 0) { |
|
| 214 | + if (strpos($versionString, 'NSS/') === 0) { |
|
| 215 | 215 | try { |
| 216 | 216 | $firstClient = $this->clientService->newClient(); |
| 217 | 217 | $firstClient->get('https://www.owncloud.org/'); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | $secondClient = $this->clientService->newClient(); |
| 220 | 220 | $secondClient->get('https://owncloud.org/'); |
| 221 | 221 | } catch (ClientException $e) { |
| 222 | - if($e->getResponse()->getStatusCode() === 400) { |
|
| 222 | + if ($e->getResponse()->getStatusCode() === 400) { |
|
| 223 | 223 | return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]); |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | * @return DataResponse |
| 301 | 301 | */ |
| 302 | 302 | public function getFailedIntegrityCheckFiles() { |
| 303 | - if(!$this->checker->isCodeCheckEnforced()) { |
|
| 303 | + if (!$this->checker->isCodeCheckEnforced()) { |
|
| 304 | 304 | return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.'); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | $completeResults = $this->checker->getResults(); |
| 308 | 308 | |
| 309 | - if(!empty($completeResults)) { |
|
| 309 | + if (!empty($completeResults)) { |
|
| 310 | 310 | $formattedTextResponse = 'Technical information |
| 311 | 311 | ===================== |
| 312 | 312 | The following list covers which files have failed the integrity check. Please read |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | Results |
| 317 | 317 | ======= |
| 318 | 318 | '; |
| 319 | - foreach($completeResults as $context => $contextResult) { |
|
| 319 | + foreach ($completeResults as $context => $contextResult) { |
|
| 320 | 320 | $formattedTextResponse .= "- $context\n"; |
| 321 | 321 | |
| 322 | - foreach($contextResult as $category => $result) { |
|
| 322 | + foreach ($contextResult as $category => $result) { |
|
| 323 | 323 | $formattedTextResponse .= "\t- $category\n"; |
| 324 | - if($category !== 'EXCEPTION') { |
|
| 324 | + if ($category !== 'EXCEPTION') { |
|
| 325 | 325 | foreach ($result as $key => $results) { |
| 326 | 326 | $formattedTextResponse .= "\t\t- $key\n"; |
| 327 | 327 | } |
@@ -364,27 +364,27 @@ discard block |
||
| 364 | 364 | |
| 365 | 365 | $isOpcacheProperlySetUp = true; |
| 366 | 366 | |
| 367 | - if(!$iniWrapper->getBool('opcache.enable')) { |
|
| 367 | + if (!$iniWrapper->getBool('opcache.enable')) { |
|
| 368 | 368 | $isOpcacheProperlySetUp = false; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - if(!$iniWrapper->getBool('opcache.save_comments')) { |
|
| 371 | + if (!$iniWrapper->getBool('opcache.save_comments')) { |
|
| 372 | 372 | $isOpcacheProperlySetUp = false; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if(!$iniWrapper->getBool('opcache.enable_cli')) { |
|
| 375 | + if (!$iniWrapper->getBool('opcache.enable_cli')) { |
|
| 376 | 376 | $isOpcacheProperlySetUp = false; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) { |
|
| 379 | + if ($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) { |
|
| 380 | 380 | $isOpcacheProperlySetUp = false; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) { |
|
| 383 | + if ($iniWrapper->getNumeric('opcache.memory_consumption') < 128) { |
|
| 384 | 384 | $isOpcacheProperlySetUp = false; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) { |
|
| 387 | + if ($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) { |
|
| 388 | 388 | $isOpcacheProperlySetUp = false; |
| 389 | 389 | } |
| 390 | 390 | |
@@ -46,282 +46,282 @@ discard block |
||
| 46 | 46 | * @package OC\Settings\Controller |
| 47 | 47 | */ |
| 48 | 48 | class CheckSetupController extends Controller { |
| 49 | - /** @var IConfig */ |
|
| 50 | - private $config; |
|
| 51 | - /** @var IClientService */ |
|
| 52 | - private $clientService; |
|
| 53 | - /** @var \OC_Util */ |
|
| 54 | - private $util; |
|
| 55 | - /** @var IURLGenerator */ |
|
| 56 | - private $urlGenerator; |
|
| 57 | - /** @var IL10N */ |
|
| 58 | - private $l10n; |
|
| 59 | - /** @var Checker */ |
|
| 60 | - private $checker; |
|
| 61 | - /** @var ILogger */ |
|
| 62 | - private $logger; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param string $AppName |
|
| 66 | - * @param IRequest $request |
|
| 67 | - * @param IConfig $config |
|
| 68 | - * @param IClientService $clientService |
|
| 69 | - * @param IURLGenerator $urlGenerator |
|
| 70 | - * @param \OC_Util $util |
|
| 71 | - * @param IL10N $l10n |
|
| 72 | - * @param Checker $checker |
|
| 73 | - * @param ILogger $logger |
|
| 74 | - */ |
|
| 75 | - public function __construct($AppName, |
|
| 76 | - IRequest $request, |
|
| 77 | - IConfig $config, |
|
| 78 | - IClientService $clientService, |
|
| 79 | - IURLGenerator $urlGenerator, |
|
| 80 | - \OC_Util $util, |
|
| 81 | - IL10N $l10n, |
|
| 82 | - Checker $checker, |
|
| 83 | - ILogger $logger) { |
|
| 84 | - parent::__construct($AppName, $request); |
|
| 85 | - $this->config = $config; |
|
| 86 | - $this->clientService = $clientService; |
|
| 87 | - $this->util = $util; |
|
| 88 | - $this->urlGenerator = $urlGenerator; |
|
| 89 | - $this->l10n = $l10n; |
|
| 90 | - $this->checker = $checker; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Checks if the ownCloud server can connect to the internet using HTTPS and HTTP |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - private function isInternetConnectionWorking() { |
|
| 99 | - if ($this->config->getSystemValue('has_internet_connection', true) === false) { |
|
| 100 | - return false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $siteArray = ['www.nextcloud.com', |
|
| 104 | - 'www.google.com', |
|
| 105 | - 'www.github.com']; |
|
| 106 | - |
|
| 107 | - foreach($siteArray as $site) { |
|
| 108 | - if ($this->isSiteReachable($site)) { |
|
| 109 | - return true; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Chceks if the ownCloud server can connect to a specific URL using both HTTPS and HTTP |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - private function isSiteReachable($sitename) { |
|
| 120 | - $httpSiteName = 'http://' . $sitename . '/'; |
|
| 121 | - $httpsSiteName = 'https://' . $sitename . '/'; |
|
| 122 | - |
|
| 123 | - try { |
|
| 124 | - $client = $this->clientService->newClient(); |
|
| 125 | - $client->get($httpSiteName); |
|
| 126 | - $client->get($httpsSiteName); |
|
| 127 | - } catch (\Exception $e) { |
|
| 128 | - $this->logger->logException($e, ['app' => 'internet_connection_check']); |
|
| 129 | - return false; |
|
| 130 | - } |
|
| 131 | - return true; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Checks whether a local memcache is installed or not |
|
| 136 | - * @return bool |
|
| 137 | - */ |
|
| 138 | - private function isMemcacheConfigured() { |
|
| 139 | - return $this->config->getSystemValue('memcache.local', null) !== null; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Whether /dev/urandom is available to the PHP controller |
|
| 144 | - * |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - private function isUrandomAvailable() { |
|
| 148 | - if(@file_exists('/dev/urandom')) { |
|
| 149 | - $file = fopen('/dev/urandom', 'rb'); |
|
| 150 | - if($file) { |
|
| 151 | - fclose($file); |
|
| 152 | - return true; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Public for the sake of unit-testing |
|
| 161 | - * |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - protected function getCurlVersion() { |
|
| 165 | - return curl_version(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Check if the used SSL lib is outdated. Older OpenSSL and NSS versions do |
|
| 170 | - * have multiple bugs which likely lead to problems in combination with |
|
| 171 | - * functionality required by ownCloud such as SNI. |
|
| 172 | - * |
|
| 173 | - * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546 |
|
| 174 | - * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172 |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - private function isUsedTlsLibOutdated() { |
|
| 178 | - // Don't run check when: |
|
| 179 | - // 1. Server has `has_internet_connection` set to false |
|
| 180 | - // 2. AppStore AND S2S is disabled |
|
| 181 | - if(!$this->config->getSystemValue('has_internet_connection', true)) { |
|
| 182 | - return ''; |
|
| 183 | - } |
|
| 184 | - if(!$this->config->getSystemValue('appstoreenabled', true) |
|
| 185 | - && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no' |
|
| 186 | - && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $versionString = $this->getCurlVersion(); |
|
| 191 | - if(isset($versionString['ssl_version'])) { |
|
| 192 | - $versionString = $versionString['ssl_version']; |
|
| 193 | - } else { |
|
| 194 | - return ''; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing'); |
|
| 198 | - if(!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 199 | - $features = (string)$this->l10n->t('Federated Cloud Sharing'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // Check if at least OpenSSL after 1.01d or 1.0.2b |
|
| 203 | - if(strpos($versionString, 'OpenSSL/') === 0) { |
|
| 204 | - $majorVersion = substr($versionString, 8, 5); |
|
| 205 | - $patchRelease = substr($versionString, 13, 6); |
|
| 206 | - |
|
| 207 | - if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) || |
|
| 208 | - ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) { |
|
| 209 | - return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // Check if NSS and perform heuristic check |
|
| 214 | - if(strpos($versionString, 'NSS/') === 0) { |
|
| 215 | - try { |
|
| 216 | - $firstClient = $this->clientService->newClient(); |
|
| 217 | - $firstClient->get('https://www.owncloud.org/'); |
|
| 218 | - |
|
| 219 | - $secondClient = $this->clientService->newClient(); |
|
| 220 | - $secondClient->get('https://owncloud.org/'); |
|
| 221 | - } catch (ClientException $e) { |
|
| 222 | - if($e->getResponse()->getStatusCode() === 400) { |
|
| 223 | - return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return ''; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Whether the version is outdated |
|
| 233 | - * |
|
| 234 | - * @return bool |
|
| 235 | - */ |
|
| 236 | - protected function isPhpOutdated() { |
|
| 237 | - if (version_compare(PHP_VERSION, '5.5.0') === -1) { |
|
| 238 | - return true; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - return false; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Whether the php version is still supported (at time of release) |
|
| 246 | - * according to: https://secure.php.net/supported-versions.php |
|
| 247 | - * |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - private function isPhpSupported() { |
|
| 251 | - return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION]; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Check if the reverse proxy configuration is working as expected |
|
| 256 | - * |
|
| 257 | - * @return bool |
|
| 258 | - */ |
|
| 259 | - private function forwardedForHeadersWorking() { |
|
| 260 | - $trustedProxies = $this->config->getSystemValue('trusted_proxies', []); |
|
| 261 | - $remoteAddress = $this->request->getRemoteAddress(); |
|
| 262 | - |
|
| 263 | - if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) { |
|
| 264 | - return false; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // either not enabled or working correctly |
|
| 268 | - return true; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Checks if the correct memcache module for PHP is installed. Only |
|
| 273 | - * fails if memcached is configured and the working module is not installed. |
|
| 274 | - * |
|
| 275 | - * @return bool |
|
| 276 | - */ |
|
| 277 | - private function isCorrectMemcachedPHPModuleInstalled() { |
|
| 278 | - if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') { |
|
| 279 | - return true; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // there are two different memcached modules for PHP |
|
| 283 | - // we only support memcached and not memcache |
|
| 284 | - // https://code.google.com/p/memcached/wiki/PHPClientComparison |
|
| 285 | - return !(!extension_loaded('memcached') && extension_loaded('memcache')); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * Checks if set_time_limit is not disabled. |
|
| 290 | - * |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - private function isSettimelimitAvailable() { |
|
| 294 | - if (function_exists('set_time_limit') |
|
| 295 | - && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 296 | - return true; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return false; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @return RedirectResponse |
|
| 304 | - */ |
|
| 305 | - public function rescanFailedIntegrityCheck() { |
|
| 306 | - $this->checker->runInstanceVerification(); |
|
| 307 | - return new RedirectResponse( |
|
| 308 | - $this->urlGenerator->linkToRoute('settings.AdminSettings.index') |
|
| 309 | - ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @NoCSRFRequired |
|
| 314 | - * @return DataResponse |
|
| 315 | - */ |
|
| 316 | - public function getFailedIntegrityCheckFiles() { |
|
| 317 | - if(!$this->checker->isCodeCheckEnforced()) { |
|
| 318 | - return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.'); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $completeResults = $this->checker->getResults(); |
|
| 322 | - |
|
| 323 | - if(!empty($completeResults)) { |
|
| 324 | - $formattedTextResponse = 'Technical information |
|
| 49 | + /** @var IConfig */ |
|
| 50 | + private $config; |
|
| 51 | + /** @var IClientService */ |
|
| 52 | + private $clientService; |
|
| 53 | + /** @var \OC_Util */ |
|
| 54 | + private $util; |
|
| 55 | + /** @var IURLGenerator */ |
|
| 56 | + private $urlGenerator; |
|
| 57 | + /** @var IL10N */ |
|
| 58 | + private $l10n; |
|
| 59 | + /** @var Checker */ |
|
| 60 | + private $checker; |
|
| 61 | + /** @var ILogger */ |
|
| 62 | + private $logger; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param string $AppName |
|
| 66 | + * @param IRequest $request |
|
| 67 | + * @param IConfig $config |
|
| 68 | + * @param IClientService $clientService |
|
| 69 | + * @param IURLGenerator $urlGenerator |
|
| 70 | + * @param \OC_Util $util |
|
| 71 | + * @param IL10N $l10n |
|
| 72 | + * @param Checker $checker |
|
| 73 | + * @param ILogger $logger |
|
| 74 | + */ |
|
| 75 | + public function __construct($AppName, |
|
| 76 | + IRequest $request, |
|
| 77 | + IConfig $config, |
|
| 78 | + IClientService $clientService, |
|
| 79 | + IURLGenerator $urlGenerator, |
|
| 80 | + \OC_Util $util, |
|
| 81 | + IL10N $l10n, |
|
| 82 | + Checker $checker, |
|
| 83 | + ILogger $logger) { |
|
| 84 | + parent::__construct($AppName, $request); |
|
| 85 | + $this->config = $config; |
|
| 86 | + $this->clientService = $clientService; |
|
| 87 | + $this->util = $util; |
|
| 88 | + $this->urlGenerator = $urlGenerator; |
|
| 89 | + $this->l10n = $l10n; |
|
| 90 | + $this->checker = $checker; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Checks if the ownCloud server can connect to the internet using HTTPS and HTTP |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + private function isInternetConnectionWorking() { |
|
| 99 | + if ($this->config->getSystemValue('has_internet_connection', true) === false) { |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $siteArray = ['www.nextcloud.com', |
|
| 104 | + 'www.google.com', |
|
| 105 | + 'www.github.com']; |
|
| 106 | + |
|
| 107 | + foreach($siteArray as $site) { |
|
| 108 | + if ($this->isSiteReachable($site)) { |
|
| 109 | + return true; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Chceks if the ownCloud server can connect to a specific URL using both HTTPS and HTTP |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + private function isSiteReachable($sitename) { |
|
| 120 | + $httpSiteName = 'http://' . $sitename . '/'; |
|
| 121 | + $httpsSiteName = 'https://' . $sitename . '/'; |
|
| 122 | + |
|
| 123 | + try { |
|
| 124 | + $client = $this->clientService->newClient(); |
|
| 125 | + $client->get($httpSiteName); |
|
| 126 | + $client->get($httpsSiteName); |
|
| 127 | + } catch (\Exception $e) { |
|
| 128 | + $this->logger->logException($e, ['app' => 'internet_connection_check']); |
|
| 129 | + return false; |
|
| 130 | + } |
|
| 131 | + return true; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Checks whether a local memcache is installed or not |
|
| 136 | + * @return bool |
|
| 137 | + */ |
|
| 138 | + private function isMemcacheConfigured() { |
|
| 139 | + return $this->config->getSystemValue('memcache.local', null) !== null; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Whether /dev/urandom is available to the PHP controller |
|
| 144 | + * |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + private function isUrandomAvailable() { |
|
| 148 | + if(@file_exists('/dev/urandom')) { |
|
| 149 | + $file = fopen('/dev/urandom', 'rb'); |
|
| 150 | + if($file) { |
|
| 151 | + fclose($file); |
|
| 152 | + return true; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Public for the sake of unit-testing |
|
| 161 | + * |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + protected function getCurlVersion() { |
|
| 165 | + return curl_version(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Check if the used SSL lib is outdated. Older OpenSSL and NSS versions do |
|
| 170 | + * have multiple bugs which likely lead to problems in combination with |
|
| 171 | + * functionality required by ownCloud such as SNI. |
|
| 172 | + * |
|
| 173 | + * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546 |
|
| 174 | + * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172 |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + private function isUsedTlsLibOutdated() { |
|
| 178 | + // Don't run check when: |
|
| 179 | + // 1. Server has `has_internet_connection` set to false |
|
| 180 | + // 2. AppStore AND S2S is disabled |
|
| 181 | + if(!$this->config->getSystemValue('has_internet_connection', true)) { |
|
| 182 | + return ''; |
|
| 183 | + } |
|
| 184 | + if(!$this->config->getSystemValue('appstoreenabled', true) |
|
| 185 | + && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no' |
|
| 186 | + && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $versionString = $this->getCurlVersion(); |
|
| 191 | + if(isset($versionString['ssl_version'])) { |
|
| 192 | + $versionString = $versionString['ssl_version']; |
|
| 193 | + } else { |
|
| 194 | + return ''; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $features = (string)$this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing'); |
|
| 198 | + if(!$this->config->getSystemValue('appstoreenabled', true)) { |
|
| 199 | + $features = (string)$this->l10n->t('Federated Cloud Sharing'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // Check if at least OpenSSL after 1.01d or 1.0.2b |
|
| 203 | + if(strpos($versionString, 'OpenSSL/') === 0) { |
|
| 204 | + $majorVersion = substr($versionString, 8, 5); |
|
| 205 | + $patchRelease = substr($versionString, 13, 6); |
|
| 206 | + |
|
| 207 | + if(($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) || |
|
| 208 | + ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) { |
|
| 209 | + return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // Check if NSS and perform heuristic check |
|
| 214 | + if(strpos($versionString, 'NSS/') === 0) { |
|
| 215 | + try { |
|
| 216 | + $firstClient = $this->clientService->newClient(); |
|
| 217 | + $firstClient->get('https://www.owncloud.org/'); |
|
| 218 | + |
|
| 219 | + $secondClient = $this->clientService->newClient(); |
|
| 220 | + $secondClient->get('https://owncloud.org/'); |
|
| 221 | + } catch (ClientException $e) { |
|
| 222 | + if($e->getResponse()->getStatusCode() === 400) { |
|
| 223 | + return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return ''; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Whether the version is outdated |
|
| 233 | + * |
|
| 234 | + * @return bool |
|
| 235 | + */ |
|
| 236 | + protected function isPhpOutdated() { |
|
| 237 | + if (version_compare(PHP_VERSION, '5.5.0') === -1) { |
|
| 238 | + return true; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Whether the php version is still supported (at time of release) |
|
| 246 | + * according to: https://secure.php.net/supported-versions.php |
|
| 247 | + * |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + private function isPhpSupported() { |
|
| 251 | + return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION]; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Check if the reverse proxy configuration is working as expected |
|
| 256 | + * |
|
| 257 | + * @return bool |
|
| 258 | + */ |
|
| 259 | + private function forwardedForHeadersWorking() { |
|
| 260 | + $trustedProxies = $this->config->getSystemValue('trusted_proxies', []); |
|
| 261 | + $remoteAddress = $this->request->getRemoteAddress(); |
|
| 262 | + |
|
| 263 | + if (is_array($trustedProxies) && in_array($remoteAddress, $trustedProxies)) { |
|
| 264 | + return false; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // either not enabled or working correctly |
|
| 268 | + return true; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Checks if the correct memcache module for PHP is installed. Only |
|
| 273 | + * fails if memcached is configured and the working module is not installed. |
|
| 274 | + * |
|
| 275 | + * @return bool |
|
| 276 | + */ |
|
| 277 | + private function isCorrectMemcachedPHPModuleInstalled() { |
|
| 278 | + if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') { |
|
| 279 | + return true; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // there are two different memcached modules for PHP |
|
| 283 | + // we only support memcached and not memcache |
|
| 284 | + // https://code.google.com/p/memcached/wiki/PHPClientComparison |
|
| 285 | + return !(!extension_loaded('memcached') && extension_loaded('memcache')); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * Checks if set_time_limit is not disabled. |
|
| 290 | + * |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + private function isSettimelimitAvailable() { |
|
| 294 | + if (function_exists('set_time_limit') |
|
| 295 | + && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 296 | + return true; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return false; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @return RedirectResponse |
|
| 304 | + */ |
|
| 305 | + public function rescanFailedIntegrityCheck() { |
|
| 306 | + $this->checker->runInstanceVerification(); |
|
| 307 | + return new RedirectResponse( |
|
| 308 | + $this->urlGenerator->linkToRoute('settings.AdminSettings.index') |
|
| 309 | + ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @NoCSRFRequired |
|
| 314 | + * @return DataResponse |
|
| 315 | + */ |
|
| 316 | + public function getFailedIntegrityCheckFiles() { |
|
| 317 | + if(!$this->checker->isCodeCheckEnforced()) { |
|
| 318 | + return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.'); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $completeResults = $this->checker->getResults(); |
|
| 322 | + |
|
| 323 | + if(!empty($completeResults)) { |
|
| 324 | + $formattedTextResponse = 'Technical information |
|
| 325 | 325 | ===================== |
| 326 | 326 | The following list covers which files have failed the integrity check. Please read |
| 327 | 327 | the previous linked documentation to learn more about the errors and how to fix |
@@ -330,103 +330,103 @@ discard block |
||
| 330 | 330 | Results |
| 331 | 331 | ======= |
| 332 | 332 | '; |
| 333 | - foreach($completeResults as $context => $contextResult) { |
|
| 334 | - $formattedTextResponse .= "- $context\n"; |
|
| 335 | - |
|
| 336 | - foreach($contextResult as $category => $result) { |
|
| 337 | - $formattedTextResponse .= "\t- $category\n"; |
|
| 338 | - if($category !== 'EXCEPTION') { |
|
| 339 | - foreach ($result as $key => $results) { |
|
| 340 | - $formattedTextResponse .= "\t\t- $key\n"; |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - foreach ($result as $key => $results) { |
|
| 344 | - $formattedTextResponse .= "\t\t- $results\n"; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - $formattedTextResponse .= ' |
|
| 333 | + foreach($completeResults as $context => $contextResult) { |
|
| 334 | + $formattedTextResponse .= "- $context\n"; |
|
| 335 | + |
|
| 336 | + foreach($contextResult as $category => $result) { |
|
| 337 | + $formattedTextResponse .= "\t- $category\n"; |
|
| 338 | + if($category !== 'EXCEPTION') { |
|
| 339 | + foreach ($result as $key => $results) { |
|
| 340 | + $formattedTextResponse .= "\t\t- $key\n"; |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + foreach ($result as $key => $results) { |
|
| 344 | + $formattedTextResponse .= "\t\t- $results\n"; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + $formattedTextResponse .= ' |
|
| 352 | 352 | Raw output |
| 353 | 353 | ========== |
| 354 | 354 | '; |
| 355 | - $formattedTextResponse .= print_r($completeResults, true); |
|
| 356 | - } else { |
|
| 357 | - $formattedTextResponse = 'No errors have been found.'; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - $response = new DataDisplayResponse( |
|
| 362 | - $formattedTextResponse, |
|
| 363 | - Http::STATUS_OK, |
|
| 364 | - [ |
|
| 365 | - 'Content-Type' => 'text/plain', |
|
| 366 | - ] |
|
| 367 | - ); |
|
| 368 | - |
|
| 369 | - return $response; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Checks whether a PHP opcache is properly set up |
|
| 374 | - * @return bool |
|
| 375 | - */ |
|
| 376 | - protected function isOpcacheProperlySetup() { |
|
| 377 | - $iniWrapper = new IniGetWrapper(); |
|
| 378 | - |
|
| 379 | - $isOpcacheProperlySetUp = true; |
|
| 380 | - |
|
| 381 | - if(!$iniWrapper->getBool('opcache.enable')) { |
|
| 382 | - $isOpcacheProperlySetUp = false; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - if(!$iniWrapper->getBool('opcache.save_comments')) { |
|
| 386 | - $isOpcacheProperlySetUp = false; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - if(!$iniWrapper->getBool('opcache.enable_cli')) { |
|
| 390 | - $isOpcacheProperlySetUp = false; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) { |
|
| 394 | - $isOpcacheProperlySetUp = false; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) { |
|
| 398 | - $isOpcacheProperlySetUp = false; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) { |
|
| 402 | - $isOpcacheProperlySetUp = false; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return $isOpcacheProperlySetUp; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @return DataResponse |
|
| 410 | - */ |
|
| 411 | - public function check() { |
|
| 412 | - return new DataResponse( |
|
| 413 | - [ |
|
| 414 | - 'serverHasInternetConnection' => $this->isInternetConnectionWorking(), |
|
| 415 | - 'isMemcacheConfigured' => $this->isMemcacheConfigured(), |
|
| 416 | - 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'), |
|
| 417 | - 'isUrandomAvailable' => $this->isUrandomAvailable(), |
|
| 418 | - 'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'), |
|
| 419 | - 'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(), |
|
| 420 | - 'phpSupported' => $this->isPhpSupported(), |
|
| 421 | - 'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(), |
|
| 422 | - 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'), |
|
| 423 | - 'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(), |
|
| 424 | - 'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(), |
|
| 425 | - 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'), |
|
| 426 | - 'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(), |
|
| 427 | - 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'), |
|
| 428 | - 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), |
|
| 429 | - ] |
|
| 430 | - ); |
|
| 431 | - } |
|
| 355 | + $formattedTextResponse .= print_r($completeResults, true); |
|
| 356 | + } else { |
|
| 357 | + $formattedTextResponse = 'No errors have been found.'; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + $response = new DataDisplayResponse( |
|
| 362 | + $formattedTextResponse, |
|
| 363 | + Http::STATUS_OK, |
|
| 364 | + [ |
|
| 365 | + 'Content-Type' => 'text/plain', |
|
| 366 | + ] |
|
| 367 | + ); |
|
| 368 | + |
|
| 369 | + return $response; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Checks whether a PHP opcache is properly set up |
|
| 374 | + * @return bool |
|
| 375 | + */ |
|
| 376 | + protected function isOpcacheProperlySetup() { |
|
| 377 | + $iniWrapper = new IniGetWrapper(); |
|
| 378 | + |
|
| 379 | + $isOpcacheProperlySetUp = true; |
|
| 380 | + |
|
| 381 | + if(!$iniWrapper->getBool('opcache.enable')) { |
|
| 382 | + $isOpcacheProperlySetUp = false; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + if(!$iniWrapper->getBool('opcache.save_comments')) { |
|
| 386 | + $isOpcacheProperlySetUp = false; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + if(!$iniWrapper->getBool('opcache.enable_cli')) { |
|
| 390 | + $isOpcacheProperlySetUp = false; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if($iniWrapper->getNumeric('opcache.max_accelerated_files') < 10000) { |
|
| 394 | + $isOpcacheProperlySetUp = false; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if($iniWrapper->getNumeric('opcache.memory_consumption') < 128) { |
|
| 398 | + $isOpcacheProperlySetUp = false; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + if($iniWrapper->getNumeric('opcache.interned_strings_buffer') < 8) { |
|
| 402 | + $isOpcacheProperlySetUp = false; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return $isOpcacheProperlySetUp; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @return DataResponse |
|
| 410 | + */ |
|
| 411 | + public function check() { |
|
| 412 | + return new DataResponse( |
|
| 413 | + [ |
|
| 414 | + 'serverHasInternetConnection' => $this->isInternetConnectionWorking(), |
|
| 415 | + 'isMemcacheConfigured' => $this->isMemcacheConfigured(), |
|
| 416 | + 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'), |
|
| 417 | + 'isUrandomAvailable' => $this->isUrandomAvailable(), |
|
| 418 | + 'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'), |
|
| 419 | + 'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(), |
|
| 420 | + 'phpSupported' => $this->isPhpSupported(), |
|
| 421 | + 'forwardedForHeadersWorking' => $this->forwardedForHeadersWorking(), |
|
| 422 | + 'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'), |
|
| 423 | + 'isCorrectMemcachedPHPModuleInstalled' => $this->isCorrectMemcachedPHPModuleInstalled(), |
|
| 424 | + 'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(), |
|
| 425 | + 'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'), |
|
| 426 | + 'isOpcacheProperlySetup' => $this->isOpcacheProperlySetup(), |
|
| 427 | + 'phpOpcacheDocumentation' => $this->urlGenerator->linkToDocs('admin-php-opcache'), |
|
| 428 | + 'isSettimelimitAvailable' => $this->isSettimelimitAvailable(), |
|
| 429 | + ] |
|
| 430 | + ); |
|
| 431 | + } |
|
| 432 | 432 | } |
@@ -1104,7 +1104,7 @@ |
||
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | /** |
| 1107 | - * @param array $reqs |
|
| 1107 | + * @param string[] $reqs |
|
| 1108 | 1108 | * @return bool |
| 1109 | 1109 | */ |
| 1110 | 1110 | private function checkRequirements($reqs) { |
@@ -38,1311 +38,1311 @@ |
||
| 38 | 38 | use OC\ServerNotAvailableException; |
| 39 | 39 | |
| 40 | 40 | class Wizard extends LDAPUtility { |
| 41 | - /** @var \OCP\IL10N */ |
|
| 42 | - static protected $l; |
|
| 43 | - protected $access; |
|
| 44 | - protected $cr; |
|
| 45 | - protected $configuration; |
|
| 46 | - protected $result; |
|
| 47 | - protected $resultCache = array(); |
|
| 48 | - |
|
| 49 | - const LRESULT_PROCESSED_OK = 2; |
|
| 50 | - const LRESULT_PROCESSED_INVALID = 3; |
|
| 51 | - const LRESULT_PROCESSED_SKIP = 4; |
|
| 52 | - |
|
| 53 | - const LFILTER_LOGIN = 2; |
|
| 54 | - const LFILTER_USER_LIST = 3; |
|
| 55 | - const LFILTER_GROUP_LIST = 4; |
|
| 56 | - |
|
| 57 | - const LFILTER_MODE_ASSISTED = 2; |
|
| 58 | - const LFILTER_MODE_RAW = 1; |
|
| 59 | - |
|
| 60 | - const LDAP_NW_TIMEOUT = 4; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Constructor |
|
| 64 | - * @param Configuration $configuration an instance of Configuration |
|
| 65 | - * @param ILDAPWrapper $ldap an instance of ILDAPWrapper |
|
| 66 | - * @param Access $access |
|
| 67 | - */ |
|
| 68 | - public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
|
| 69 | - parent::__construct($ldap); |
|
| 70 | - $this->configuration = $configuration; |
|
| 71 | - if(is_null(Wizard::$l)) { |
|
| 72 | - Wizard::$l = \OC::$server->getL10N('user_ldap'); |
|
| 73 | - } |
|
| 74 | - $this->access = $access; |
|
| 75 | - $this->result = new WizardResult(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function __destruct() { |
|
| 79 | - if($this->result->hasChanges()) { |
|
| 80 | - $this->configuration->saveConfiguration(); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * counts entries in the LDAP directory |
|
| 86 | - * |
|
| 87 | - * @param string $filter the LDAP search filter |
|
| 88 | - * @param string $type a string being either 'users' or 'groups'; |
|
| 89 | - * @return bool|int |
|
| 90 | - * @throws \Exception |
|
| 91 | - */ |
|
| 92 | - public function countEntries($filter, $type) { |
|
| 93 | - $reqs = array('ldapHost', 'ldapPort', 'ldapBase'); |
|
| 94 | - if($type === 'users') { |
|
| 95 | - $reqs[] = 'ldapUserFilter'; |
|
| 96 | - } |
|
| 97 | - if(!$this->checkRequirements($reqs)) { |
|
| 98 | - throw new \Exception('Requirements not met', 400); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $attr = array('dn'); // default |
|
| 102 | - $limit = 1001; |
|
| 103 | - if($type === 'groups') { |
|
| 104 | - $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 105 | - } else if($type === 'users') { |
|
| 106 | - $result = $this->access->countUsers($filter, $attr, $limit); |
|
| 107 | - } else if ($type === 'objects') { |
|
| 108 | - $result = $this->access->countObjects($limit); |
|
| 109 | - } else { |
|
| 110 | - throw new \Exception('Internal error: Invalid object type', 500); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return $result; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * formats the return value of a count operation to the string to be |
|
| 118 | - * inserted. |
|
| 119 | - * |
|
| 120 | - * @param bool|int $count |
|
| 121 | - * @return int|string |
|
| 122 | - */ |
|
| 123 | - private function formatCountResult($count) { |
|
| 124 | - $formatted = ($count !== false) ? $count : 0; |
|
| 125 | - if($formatted > 1000) { |
|
| 126 | - $formatted = '> 1000'; |
|
| 127 | - } |
|
| 128 | - return $formatted; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function countGroups() { |
|
| 132 | - $filter = $this->configuration->ldapGroupFilter; |
|
| 133 | - |
|
| 134 | - if(empty($filter)) { |
|
| 135 | - $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
|
| 136 | - $this->result->addChange('ldap_group_count', $output); |
|
| 137 | - return $this->result; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - try { |
|
| 141 | - $groupsTotal = $this->formatCountResult($this->countEntries($filter, 'groups')); |
|
| 142 | - } catch (\Exception $e) { |
|
| 143 | - //400 can be ignored, 500 is forwarded |
|
| 144 | - if($e->getCode() === 500) { |
|
| 145 | - throw $e; |
|
| 146 | - } |
|
| 147 | - return false; |
|
| 148 | - } |
|
| 149 | - $output = self::$l->n('%s group found', '%s groups found', $groupsTotal, array($groupsTotal)); |
|
| 150 | - $this->result->addChange('ldap_group_count', $output); |
|
| 151 | - return $this->result; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return WizardResult |
|
| 156 | - * @throws \Exception |
|
| 157 | - */ |
|
| 158 | - public function countUsers() { |
|
| 159 | - $filter = $this->access->getFilterForUserCount(); |
|
| 160 | - |
|
| 161 | - $usersTotal = $this->formatCountResult($this->countEntries($filter, 'users')); |
|
| 162 | - $output = self::$l->n('%s user found', '%s users found', $usersTotal, array($usersTotal)); |
|
| 163 | - $this->result->addChange('ldap_user_count', $output); |
|
| 164 | - return $this->result; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * counts any objects in the currently set base dn |
|
| 169 | - * |
|
| 170 | - * @return WizardResult |
|
| 171 | - * @throws \Exception |
|
| 172 | - */ |
|
| 173 | - public function countInBaseDN() { |
|
| 174 | - // we don't need to provide a filter in this case |
|
| 175 | - $total = $this->countEntries(null, 'objects'); |
|
| 176 | - if($total === false) { |
|
| 177 | - throw new \Exception('invalid results received'); |
|
| 178 | - } |
|
| 179 | - $this->result->addChange('ldap_test_base', $total); |
|
| 180 | - return $this->result; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * counts users with a specified attribute |
|
| 185 | - * @param string $attr |
|
| 186 | - * @param bool $existsCheck |
|
| 187 | - * @return int|bool |
|
| 188 | - */ |
|
| 189 | - public function countUsersWithAttribute($attr, $existsCheck = false) { |
|
| 190 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 191 | - 'ldapPort', |
|
| 192 | - 'ldapBase', |
|
| 193 | - 'ldapUserFilter', |
|
| 194 | - ))) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $filter = $this->access->combineFilterWithAnd(array( |
|
| 199 | - $this->configuration->ldapUserFilter, |
|
| 200 | - $attr . '=*' |
|
| 201 | - )); |
|
| 202 | - |
|
| 203 | - $limit = ($existsCheck === false) ? null : 1; |
|
| 204 | - |
|
| 205 | - return $this->access->countUsers($filter, array('dn'), $limit); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * detects the display name attribute. If a setting is already present that |
|
| 210 | - * returns at least one hit, the detection will be canceled. |
|
| 211 | - * @return WizardResult|bool |
|
| 212 | - * @throws \Exception |
|
| 213 | - */ |
|
| 214 | - public function detectUserDisplayNameAttribute() { |
|
| 215 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 216 | - 'ldapPort', |
|
| 217 | - 'ldapBase', |
|
| 218 | - 'ldapUserFilter', |
|
| 219 | - ))) { |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $attr = $this->configuration->ldapUserDisplayName; |
|
| 224 | - if ($attr !== '' && $attr !== 'displayName') { |
|
| 225 | - // most likely not the default value with upper case N, |
|
| 226 | - // verify it still produces a result |
|
| 227 | - $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 228 | - if($count > 0) { |
|
| 229 | - //no change, but we sent it back to make sure the user interface |
|
| 230 | - //is still correct, even if the ajax call was cancelled meanwhile |
|
| 231 | - $this->result->addChange('ldap_display_name', $attr); |
|
| 232 | - return $this->result; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // first attribute that has at least one result wins |
|
| 237 | - $displayNameAttrs = array('displayname', 'cn'); |
|
| 238 | - foreach ($displayNameAttrs as $attr) { |
|
| 239 | - $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 240 | - |
|
| 241 | - if($count > 0) { |
|
| 242 | - $this->applyFind('ldap_display_name', $attr); |
|
| 243 | - return $this->result; |
|
| 244 | - } |
|
| 245 | - }; |
|
| 246 | - |
|
| 247 | - throw new \Exception(self::$l->t('Could not detect user display name attribute. Please specify it yourself in advanced LDAP settings.')); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * detects the most often used email attribute for users applying to the |
|
| 252 | - * user list filter. If a setting is already present that returns at least |
|
| 253 | - * one hit, the detection will be canceled. |
|
| 254 | - * @return WizardResult|bool |
|
| 255 | - */ |
|
| 256 | - public function detectEmailAttribute() { |
|
| 257 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 258 | - 'ldapPort', |
|
| 259 | - 'ldapBase', |
|
| 260 | - 'ldapUserFilter', |
|
| 261 | - ))) { |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $attr = $this->configuration->ldapEmailAttribute; |
|
| 266 | - if ($attr !== '') { |
|
| 267 | - $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 268 | - if($count > 0) { |
|
| 269 | - return false; |
|
| 270 | - } |
|
| 271 | - $writeLog = true; |
|
| 272 | - } else { |
|
| 273 | - $writeLog = false; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $emailAttributes = array('mail', 'mailPrimaryAddress'); |
|
| 277 | - $winner = ''; |
|
| 278 | - $maxUsers = 0; |
|
| 279 | - foreach($emailAttributes as $attr) { |
|
| 280 | - $count = $this->countUsersWithAttribute($attr); |
|
| 281 | - if($count > $maxUsers) { |
|
| 282 | - $maxUsers = $count; |
|
| 283 | - $winner = $attr; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if($winner !== '') { |
|
| 288 | - $this->applyFind('ldap_email_attr', $winner); |
|
| 289 | - if($writeLog) { |
|
| 290 | - \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 291 | - 'automatically been reset, because the original value ' . |
|
| 292 | - 'did not return any results.', \OCP\Util::INFO); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - return $this->result; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return WizardResult |
|
| 301 | - * @throws \Exception |
|
| 302 | - */ |
|
| 303 | - public function determineAttributes() { |
|
| 304 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 305 | - 'ldapPort', |
|
| 306 | - 'ldapBase', |
|
| 307 | - 'ldapUserFilter', |
|
| 308 | - ))) { |
|
| 309 | - return false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $attributes = $this->getUserAttributes(); |
|
| 313 | - |
|
| 314 | - natcasesort($attributes); |
|
| 315 | - $attributes = array_values($attributes); |
|
| 316 | - |
|
| 317 | - $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
|
| 318 | - |
|
| 319 | - $selected = $this->configuration->ldapLoginFilterAttributes; |
|
| 320 | - if(is_array($selected) && !empty($selected)) { |
|
| 321 | - $this->result->addChange('ldap_loginfilter_attributes', $selected); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $this->result; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * detects the available LDAP attributes |
|
| 329 | - * @return array|false The instance's WizardResult instance |
|
| 330 | - * @throws \Exception |
|
| 331 | - */ |
|
| 332 | - private function getUserAttributes() { |
|
| 333 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 334 | - 'ldapPort', |
|
| 335 | - 'ldapBase', |
|
| 336 | - 'ldapUserFilter', |
|
| 337 | - ))) { |
|
| 338 | - return false; |
|
| 339 | - } |
|
| 340 | - $cr = $this->getConnection(); |
|
| 341 | - if(!$cr) { |
|
| 342 | - throw new \Exception('Could not connect to LDAP'); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - $base = $this->configuration->ldapBase[0]; |
|
| 346 | - $filter = $this->configuration->ldapUserFilter; |
|
| 347 | - $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
|
| 348 | - if(!$this->ldap->isResource($rr)) { |
|
| 349 | - return false; |
|
| 350 | - } |
|
| 351 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 352 | - $attributes = $this->ldap->getAttributes($cr, $er); |
|
| 353 | - $pureAttributes = array(); |
|
| 354 | - for($i = 0; $i < $attributes['count']; $i++) { |
|
| 355 | - $pureAttributes[] = $attributes[$i]; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $pureAttributes; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * detects the available LDAP groups |
|
| 363 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 364 | - */ |
|
| 365 | - public function determineGroupsForGroups() { |
|
| 366 | - return $this->determineGroups('ldap_groupfilter_groups', |
|
| 367 | - 'ldapGroupFilterGroups', |
|
| 368 | - false); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * detects the available LDAP groups |
|
| 373 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 374 | - */ |
|
| 375 | - public function determineGroupsForUsers() { |
|
| 376 | - return $this->determineGroups('ldap_userfilter_groups', |
|
| 377 | - 'ldapUserFilterGroups'); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * detects the available LDAP groups |
|
| 382 | - * @param string $dbKey |
|
| 383 | - * @param string $confKey |
|
| 384 | - * @param bool $testMemberOf |
|
| 385 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 386 | - * @throws \Exception |
|
| 387 | - */ |
|
| 388 | - private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
|
| 389 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 390 | - 'ldapPort', |
|
| 391 | - 'ldapBase', |
|
| 392 | - ))) { |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - $cr = $this->getConnection(); |
|
| 396 | - if(!$cr) { |
|
| 397 | - throw new \Exception('Could not connect to LDAP'); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - $this->fetchGroups($dbKey, $confKey); |
|
| 401 | - |
|
| 402 | - if($testMemberOf) { |
|
| 403 | - $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
|
| 404 | - $this->result->markChange(); |
|
| 405 | - if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 406 | - throw new \Exception('memberOf is not supported by the server'); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return $this->result; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * fetches all groups from LDAP and adds them to the result object |
|
| 415 | - * |
|
| 416 | - * @param string $dbKey |
|
| 417 | - * @param string $confKey |
|
| 418 | - * @return array $groupEntries |
|
| 419 | - * @throws \Exception |
|
| 420 | - */ |
|
| 421 | - public function fetchGroups($dbKey, $confKey) { |
|
| 422 | - $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
|
| 423 | - |
|
| 424 | - $filterParts = array(); |
|
| 425 | - foreach($obclasses as $obclass) { |
|
| 426 | - $filterParts[] = 'objectclass='.$obclass; |
|
| 427 | - } |
|
| 428 | - //we filter for everything |
|
| 429 | - //- that looks like a group and |
|
| 430 | - //- has the group display name set |
|
| 431 | - $filter = $this->access->combineFilterWithOr($filterParts); |
|
| 432 | - $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); |
|
| 433 | - |
|
| 434 | - $groupNames = array(); |
|
| 435 | - $groupEntries = array(); |
|
| 436 | - $limit = 400; |
|
| 437 | - $offset = 0; |
|
| 438 | - do { |
|
| 439 | - // we need to request dn additionally here, otherwise memberOf |
|
| 440 | - // detection will fail later |
|
| 441 | - $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
|
| 442 | - foreach($result as $item) { |
|
| 443 | - if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 444 | - // just in case - no issue known |
|
| 445 | - continue; |
|
| 446 | - } |
|
| 447 | - $groupNames[] = $item['cn'][0]; |
|
| 448 | - $groupEntries[] = $item; |
|
| 449 | - } |
|
| 450 | - $offset += $limit; |
|
| 451 | - } while ($this->access->hasMoreResults()); |
|
| 452 | - |
|
| 453 | - if(count($groupNames) > 0) { |
|
| 454 | - natsort($groupNames); |
|
| 455 | - $this->result->addOptions($dbKey, array_values($groupNames)); |
|
| 456 | - } else { |
|
| 457 | - throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - $setFeatures = $this->configuration->$confKey; |
|
| 461 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 462 | - //something is already configured? pre-select it. |
|
| 463 | - $this->result->addChange($dbKey, $setFeatures); |
|
| 464 | - } |
|
| 465 | - return $groupEntries; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - public function determineGroupMemberAssoc() { |
|
| 469 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 470 | - 'ldapPort', |
|
| 471 | - 'ldapGroupFilter', |
|
| 472 | - ))) { |
|
| 473 | - return false; |
|
| 474 | - } |
|
| 475 | - $attribute = $this->detectGroupMemberAssoc(); |
|
| 476 | - if($attribute === false) { |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
|
| 480 | - $this->result->addChange('ldap_group_member_assoc_attribute', $attribute); |
|
| 481 | - |
|
| 482 | - return $this->result; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Detects the available object classes |
|
| 487 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 488 | - * @throws \Exception |
|
| 489 | - */ |
|
| 490 | - public function determineGroupObjectClasses() { |
|
| 491 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 492 | - 'ldapPort', |
|
| 493 | - 'ldapBase', |
|
| 494 | - ))) { |
|
| 495 | - return false; |
|
| 496 | - } |
|
| 497 | - $cr = $this->getConnection(); |
|
| 498 | - if(!$cr) { |
|
| 499 | - throw new \Exception('Could not connect to LDAP'); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - $obclasses = array('groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*'); |
|
| 503 | - $this->determineFeature($obclasses, |
|
| 504 | - 'objectclass', |
|
| 505 | - 'ldap_groupfilter_objectclass', |
|
| 506 | - 'ldapGroupFilterObjectclass', |
|
| 507 | - false); |
|
| 508 | - |
|
| 509 | - return $this->result; |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * detects the available object classes |
|
| 514 | - * @return WizardResult |
|
| 515 | - * @throws \Exception |
|
| 516 | - */ |
|
| 517 | - public function determineUserObjectClasses() { |
|
| 518 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 519 | - 'ldapPort', |
|
| 520 | - 'ldapBase', |
|
| 521 | - ))) { |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - $cr = $this->getConnection(); |
|
| 525 | - if(!$cr) { |
|
| 526 | - throw new \Exception('Could not connect to LDAP'); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $obclasses = array('inetOrgPerson', 'person', 'organizationalPerson', |
|
| 530 | - 'user', 'posixAccount', '*'); |
|
| 531 | - $filter = $this->configuration->ldapUserFilter; |
|
| 532 | - //if filter is empty, it is probably the first time the wizard is called |
|
| 533 | - //then, apply suggestions. |
|
| 534 | - $this->determineFeature($obclasses, |
|
| 535 | - 'objectclass', |
|
| 536 | - 'ldap_userfilter_objectclass', |
|
| 537 | - 'ldapUserFilterObjectclass', |
|
| 538 | - empty($filter)); |
|
| 539 | - |
|
| 540 | - return $this->result; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @return WizardResult|false |
|
| 545 | - * @throws \Exception |
|
| 546 | - */ |
|
| 547 | - public function getGroupFilter() { |
|
| 548 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 549 | - 'ldapPort', |
|
| 550 | - 'ldapBase', |
|
| 551 | - ))) { |
|
| 552 | - return false; |
|
| 553 | - } |
|
| 554 | - //make sure the use display name is set |
|
| 555 | - $displayName = $this->configuration->ldapGroupDisplayName; |
|
| 556 | - if ($displayName === '') { |
|
| 557 | - $d = $this->configuration->getDefaults(); |
|
| 558 | - $this->applyFind('ldap_group_display_name', |
|
| 559 | - $d['ldap_group_display_name']); |
|
| 560 | - } |
|
| 561 | - $filter = $this->composeLdapFilter(self::LFILTER_GROUP_LIST); |
|
| 562 | - |
|
| 563 | - $this->applyFind('ldap_group_filter', $filter); |
|
| 564 | - return $this->result; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * @return WizardResult|false |
|
| 569 | - * @throws \Exception |
|
| 570 | - */ |
|
| 571 | - public function getUserListFilter() { |
|
| 572 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 573 | - 'ldapPort', |
|
| 574 | - 'ldapBase', |
|
| 575 | - ))) { |
|
| 576 | - return false; |
|
| 577 | - } |
|
| 578 | - //make sure the use display name is set |
|
| 579 | - $displayName = $this->configuration->ldapUserDisplayName; |
|
| 580 | - if ($displayName === '') { |
|
| 581 | - $d = $this->configuration->getDefaults(); |
|
| 582 | - $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
|
| 583 | - } |
|
| 584 | - $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
|
| 585 | - if(!$filter) { |
|
| 586 | - throw new \Exception('Cannot create filter'); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - $this->applyFind('ldap_userlist_filter', $filter); |
|
| 590 | - return $this->result; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * @return bool|WizardResult |
|
| 595 | - * @throws \Exception |
|
| 596 | - */ |
|
| 597 | - public function getUserLoginFilter() { |
|
| 598 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 599 | - 'ldapPort', |
|
| 600 | - 'ldapBase', |
|
| 601 | - 'ldapUserFilter', |
|
| 602 | - ))) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
|
| 607 | - if(!$filter) { |
|
| 608 | - throw new \Exception('Cannot create filter'); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - $this->applyFind('ldap_login_filter', $filter); |
|
| 612 | - return $this->result; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * @return bool|WizardResult |
|
| 617 | - * @param string $loginName |
|
| 618 | - * @throws \Exception |
|
| 619 | - */ |
|
| 620 | - public function testLoginName($loginName) { |
|
| 621 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 622 | - 'ldapPort', |
|
| 623 | - 'ldapBase', |
|
| 624 | - 'ldapLoginFilter', |
|
| 625 | - ))) { |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - $cr = $this->access->connection->getConnectionResource(); |
|
| 630 | - if(!$this->ldap->isResource($cr)) { |
|
| 631 | - throw new \Exception('connection error'); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 635 | - === false) { |
|
| 636 | - throw new \Exception('missing placeholder'); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - $users = $this->access->countUsersByLoginName($loginName); |
|
| 640 | - if($this->ldap->errno($cr) !== 0) { |
|
| 641 | - throw new \Exception($this->ldap->error($cr)); |
|
| 642 | - } |
|
| 643 | - $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
|
| 644 | - $this->result->addChange('ldap_test_loginname', $users); |
|
| 645 | - $this->result->addChange('ldap_test_effective_filter', $filter); |
|
| 646 | - return $this->result; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * Tries to determine the port, requires given Host, User DN and Password |
|
| 651 | - * @return WizardResult|false WizardResult on success, false otherwise |
|
| 652 | - * @throws \Exception |
|
| 653 | - */ |
|
| 654 | - public function guessPortAndTLS() { |
|
| 655 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 656 | - ))) { |
|
| 657 | - return false; |
|
| 658 | - } |
|
| 659 | - $this->checkHost(); |
|
| 660 | - $portSettings = $this->getPortSettingsToTry(); |
|
| 661 | - |
|
| 662 | - if(!is_array($portSettings)) { |
|
| 663 | - throw new \Exception(print_r($portSettings, true)); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - //proceed from the best configuration and return on first success |
|
| 667 | - foreach($portSettings as $setting) { |
|
| 668 | - $p = $setting['port']; |
|
| 669 | - $t = $setting['tls']; |
|
| 670 | - \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, \OCP\Util::DEBUG); |
|
| 671 | - //connectAndBind may throw Exception, it needs to be catched by the |
|
| 672 | - //callee of this method |
|
| 673 | - |
|
| 674 | - try { |
|
| 675 | - $settingsFound = $this->connectAndBind($p, $t); |
|
| 676 | - } catch (\Exception $e) { |
|
| 677 | - // any reply other than -1 (= cannot connect) is already okay, |
|
| 678 | - // because then we found the server |
|
| 679 | - // unavailable startTLS returns -11 |
|
| 680 | - if($e->getCode() > 0) { |
|
| 681 | - $settingsFound = true; |
|
| 682 | - } else { |
|
| 683 | - throw $e; |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - if ($settingsFound === true) { |
|
| 688 | - $config = array( |
|
| 689 | - 'ldapPort' => $p, |
|
| 690 | - 'ldapTLS' => intval($t) |
|
| 691 | - ); |
|
| 692 | - $this->configuration->setConfiguration($config); |
|
| 693 | - \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG); |
|
| 694 | - $this->result->addChange('ldap_port', $p); |
|
| 695 | - return $this->result; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - //custom port, undetected (we do not brute force) |
|
| 700 | - return false; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * tries to determine a base dn from User DN or LDAP Host |
|
| 705 | - * @return WizardResult|false WizardResult on success, false otherwise |
|
| 706 | - */ |
|
| 707 | - public function guessBaseDN() { |
|
| 708 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 709 | - 'ldapPort', |
|
| 710 | - ))) { |
|
| 711 | - return false; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - //check whether a DN is given in the agent name (99.9% of all cases) |
|
| 715 | - $base = null; |
|
| 716 | - $i = stripos($this->configuration->ldapAgentName, 'dc='); |
|
| 717 | - if($i !== false) { |
|
| 718 | - $base = substr($this->configuration->ldapAgentName, $i); |
|
| 719 | - if($this->testBaseDN($base)) { |
|
| 720 | - $this->applyFind('ldap_base', $base); |
|
| 721 | - return $this->result; |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - //this did not help :( |
|
| 726 | - //Let's see whether we can parse the Host URL and convert the domain to |
|
| 727 | - //a base DN |
|
| 728 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 729 | - $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
|
| 730 | - if(!$domain) { |
|
| 731 | - return false; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - $dparts = explode('.', $domain); |
|
| 735 | - while(count($dparts) > 0) { |
|
| 736 | - $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 737 | - if ($base !== $base2 && $this->testBaseDN($base2)) { |
|
| 738 | - $this->applyFind('ldap_base', $base2); |
|
| 739 | - return $this->result; |
|
| 740 | - } |
|
| 741 | - array_shift($dparts); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * sets the found value for the configuration key in the WizardResult |
|
| 749 | - * as well as in the Configuration instance |
|
| 750 | - * @param string $key the configuration key |
|
| 751 | - * @param string $value the (detected) value |
|
| 752 | - * |
|
| 753 | - */ |
|
| 754 | - private function applyFind($key, $value) { |
|
| 755 | - $this->result->addChange($key, $value); |
|
| 756 | - $this->configuration->setConfiguration(array($key => $value)); |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * Checks, whether a port was entered in the Host configuration |
|
| 761 | - * field. In this case the port will be stripped off, but also stored as |
|
| 762 | - * setting. |
|
| 763 | - */ |
|
| 764 | - private function checkHost() { |
|
| 765 | - $host = $this->configuration->ldapHost; |
|
| 766 | - $hostInfo = parse_url($host); |
|
| 767 | - |
|
| 768 | - //removes Port from Host |
|
| 769 | - if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 770 | - $port = $hostInfo['port']; |
|
| 771 | - $host = str_replace(':'.$port, '', $host); |
|
| 772 | - $this->applyFind('ldap_host', $host); |
|
| 773 | - $this->applyFind('ldap_port', $port); |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * tries to detect the group member association attribute which is |
|
| 779 | - * one of 'uniqueMember', 'memberUid', 'member', 'gidNumber' |
|
| 780 | - * @return string|false, string with the attribute name, false on error |
|
| 781 | - * @throws \Exception |
|
| 782 | - */ |
|
| 783 | - private function detectGroupMemberAssoc() { |
|
| 784 | - $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
|
| 785 | - $filter = $this->configuration->ldapGroupFilter; |
|
| 786 | - if(empty($filter)) { |
|
| 787 | - return false; |
|
| 788 | - } |
|
| 789 | - $cr = $this->getConnection(); |
|
| 790 | - if(!$cr) { |
|
| 791 | - throw new \Exception('Could not connect to LDAP'); |
|
| 792 | - } |
|
| 793 | - $base = $this->configuration->ldapBase[0]; |
|
| 794 | - $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
|
| 795 | - if(!$this->ldap->isResource($rr)) { |
|
| 796 | - return false; |
|
| 797 | - } |
|
| 798 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 799 | - while(is_resource($er)) { |
|
| 800 | - $this->ldap->getDN($cr, $er); |
|
| 801 | - $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 802 | - $result = array(); |
|
| 803 | - $possibleAttrsCount = count($possibleAttrs); |
|
| 804 | - for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 805 | - if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 806 | - $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if(!empty($result)) { |
|
| 810 | - natsort($result); |
|
| 811 | - return key($result); |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - $er = $this->ldap->nextEntry($cr, $er); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - return false; |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Checks whether for a given BaseDN results will be returned |
|
| 822 | - * @param string $base the BaseDN to test |
|
| 823 | - * @return bool true on success, false otherwise |
|
| 824 | - * @throws \Exception |
|
| 825 | - */ |
|
| 826 | - private function testBaseDN($base) { |
|
| 827 | - $cr = $this->getConnection(); |
|
| 828 | - if(!$cr) { |
|
| 829 | - throw new \Exception('Could not connect to LDAP'); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - //base is there, let's validate it. If we search for anything, we should |
|
| 833 | - //get a result set > 0 on a proper base |
|
| 834 | - $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
|
| 835 | - if(!$this->ldap->isResource($rr)) { |
|
| 836 | - $errorNo = $this->ldap->errno($cr); |
|
| 837 | - $errorMsg = $this->ldap->error($cr); |
|
| 838 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
|
| 839 | - ' Error '.$errorNo.': '.$errorMsg, \OCP\Util::INFO); |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - $entries = $this->ldap->countEntries($cr, $rr); |
|
| 843 | - return ($entries !== false) && ($entries > 0); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * Checks whether the server supports memberOf in LDAP Filter. |
|
| 848 | - * Note: at least in OpenLDAP, availability of memberOf is dependent on |
|
| 849 | - * a configured objectClass. I.e. not necessarily for all available groups |
|
| 850 | - * memberOf does work. |
|
| 851 | - * |
|
| 852 | - * @return bool true if it does, false otherwise |
|
| 853 | - * @throws \Exception |
|
| 854 | - */ |
|
| 855 | - private function testMemberOf() { |
|
| 856 | - $cr = $this->getConnection(); |
|
| 857 | - if(!$cr) { |
|
| 858 | - throw new \Exception('Could not connect to LDAP'); |
|
| 859 | - } |
|
| 860 | - $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
|
| 861 | - if(is_int($result) && $result > 0) { |
|
| 862 | - return true; |
|
| 863 | - } |
|
| 864 | - return false; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * creates an LDAP Filter from given configuration |
|
| 869 | - * @param integer $filterType int, for which use case the filter shall be created |
|
| 870 | - * can be any of self::LFILTER_USER_LIST, self::LFILTER_LOGIN or |
|
| 871 | - * self::LFILTER_GROUP_LIST |
|
| 872 | - * @return string|false string with the filter on success, false otherwise |
|
| 873 | - * @throws \Exception |
|
| 874 | - */ |
|
| 875 | - private function composeLdapFilter($filterType) { |
|
| 876 | - $filter = ''; |
|
| 877 | - $parts = 0; |
|
| 878 | - switch ($filterType) { |
|
| 879 | - case self::LFILTER_USER_LIST: |
|
| 880 | - $objcs = $this->configuration->ldapUserFilterObjectclass; |
|
| 881 | - //glue objectclasses |
|
| 882 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 883 | - $filter .= '(|'; |
|
| 884 | - foreach($objcs as $objc) { |
|
| 885 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 886 | - } |
|
| 887 | - $filter .= ')'; |
|
| 888 | - $parts++; |
|
| 889 | - } |
|
| 890 | - //glue group memberships |
|
| 891 | - if($this->configuration->hasMemberOfFilterSupport) { |
|
| 892 | - $cns = $this->configuration->ldapUserFilterGroups; |
|
| 893 | - if(is_array($cns) && count($cns) > 0) { |
|
| 894 | - $filter .= '(|'; |
|
| 895 | - $cr = $this->getConnection(); |
|
| 896 | - if(!$cr) { |
|
| 897 | - throw new \Exception('Could not connect to LDAP'); |
|
| 898 | - } |
|
| 899 | - $base = $this->configuration->ldapBase[0]; |
|
| 900 | - foreach($cns as $cn) { |
|
| 901 | - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 902 | - if(!$this->ldap->isResource($rr)) { |
|
| 903 | - continue; |
|
| 904 | - } |
|
| 905 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 906 | - $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 907 | - $dn = $this->ldap->getDN($cr, $er); |
|
| 908 | - if ($dn === false || $dn === '') { |
|
| 909 | - continue; |
|
| 910 | - } |
|
| 911 | - $filterPart = '(memberof=' . $dn . ')'; |
|
| 912 | - if(isset($attrs['primaryGroupToken'])) { |
|
| 913 | - $pgt = $attrs['primaryGroupToken'][0]; |
|
| 914 | - $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 915 | - $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 916 | - } |
|
| 917 | - $filter .= $filterPart; |
|
| 918 | - } |
|
| 919 | - $filter .= ')'; |
|
| 920 | - } |
|
| 921 | - $parts++; |
|
| 922 | - } |
|
| 923 | - //wrap parts in AND condition |
|
| 924 | - if($parts > 1) { |
|
| 925 | - $filter = '(&' . $filter . ')'; |
|
| 926 | - } |
|
| 927 | - if ($filter === '') { |
|
| 928 | - $filter = '(objectclass=*)'; |
|
| 929 | - } |
|
| 930 | - break; |
|
| 931 | - |
|
| 932 | - case self::LFILTER_GROUP_LIST: |
|
| 933 | - $objcs = $this->configuration->ldapGroupFilterObjectclass; |
|
| 934 | - //glue objectclasses |
|
| 935 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 936 | - $filter .= '(|'; |
|
| 937 | - foreach($objcs as $objc) { |
|
| 938 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 939 | - } |
|
| 940 | - $filter .= ')'; |
|
| 941 | - $parts++; |
|
| 942 | - } |
|
| 943 | - //glue group memberships |
|
| 944 | - $cns = $this->configuration->ldapGroupFilterGroups; |
|
| 945 | - if(is_array($cns) && count($cns) > 0) { |
|
| 946 | - $filter .= '(|'; |
|
| 947 | - foreach($cns as $cn) { |
|
| 948 | - $filter .= '(cn=' . $cn . ')'; |
|
| 949 | - } |
|
| 950 | - $filter .= ')'; |
|
| 951 | - } |
|
| 952 | - $parts++; |
|
| 953 | - //wrap parts in AND condition |
|
| 954 | - if($parts > 1) { |
|
| 955 | - $filter = '(&' . $filter . ')'; |
|
| 956 | - } |
|
| 957 | - break; |
|
| 958 | - |
|
| 959 | - case self::LFILTER_LOGIN: |
|
| 960 | - $ulf = $this->configuration->ldapUserFilter; |
|
| 961 | - $loginpart = '=%uid'; |
|
| 962 | - $filterUsername = ''; |
|
| 963 | - $userAttributes = $this->getUserAttributes(); |
|
| 964 | - $userAttributes = array_change_key_case(array_flip($userAttributes)); |
|
| 965 | - $parts = 0; |
|
| 966 | - |
|
| 967 | - if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 968 | - $attr = ''; |
|
| 969 | - if(isset($userAttributes['uid'])) { |
|
| 970 | - $attr = 'uid'; |
|
| 971 | - } else if(isset($userAttributes['samaccountname'])) { |
|
| 972 | - $attr = 'samaccountname'; |
|
| 973 | - } else if(isset($userAttributes['cn'])) { |
|
| 974 | - //fallback |
|
| 975 | - $attr = 'cn'; |
|
| 976 | - } |
|
| 977 | - if ($attr !== '') { |
|
| 978 | - $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 979 | - $parts++; |
|
| 980 | - } |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - $filterEmail = ''; |
|
| 984 | - if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 985 | - $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
|
| 986 | - $parts++; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - $filterAttributes = ''; |
|
| 990 | - $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
|
| 991 | - if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 992 | - $filterAttributes = '(|'; |
|
| 993 | - foreach($attrsToFilter as $attribute) { |
|
| 994 | - $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 995 | - } |
|
| 996 | - $filterAttributes .= ')'; |
|
| 997 | - $parts++; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - $filterLogin = ''; |
|
| 1001 | - if($parts > 1) { |
|
| 1002 | - $filterLogin = '(|'; |
|
| 1003 | - } |
|
| 1004 | - $filterLogin .= $filterUsername; |
|
| 1005 | - $filterLogin .= $filterEmail; |
|
| 1006 | - $filterLogin .= $filterAttributes; |
|
| 1007 | - if($parts > 1) { |
|
| 1008 | - $filterLogin .= ')'; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - $filter = '(&'.$ulf.$filterLogin.')'; |
|
| 1012 | - break; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, \OCP\Util::DEBUG); |
|
| 1016 | - |
|
| 1017 | - return $filter; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - /** |
|
| 1021 | - * Connects and Binds to an LDAP Server |
|
| 1022 | - * |
|
| 1023 | - * @param int $port the port to connect with |
|
| 1024 | - * @param bool $tls whether startTLS is to be used |
|
| 1025 | - * @return bool |
|
| 1026 | - * @throws \Exception |
|
| 1027 | - */ |
|
| 1028 | - private function connectAndBind($port, $tls) { |
|
| 1029 | - //connect, does not really trigger any server communication |
|
| 1030 | - $host = $this->configuration->ldapHost; |
|
| 1031 | - $hostInfo = parse_url($host); |
|
| 1032 | - if(!$hostInfo) { |
|
| 1033 | - throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1034 | - } |
|
| 1035 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', \OCP\Util::DEBUG); |
|
| 1036 | - $cr = $this->ldap->connect($host, $port); |
|
| 1037 | - if(!is_resource($cr)) { |
|
| 1038 | - throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - //set LDAP options |
|
| 1042 | - $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1043 | - $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1044 | - $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1045 | - |
|
| 1046 | - try { |
|
| 1047 | - if($tls) { |
|
| 1048 | - $isTlsWorking = @$this->ldap->startTls($cr); |
|
| 1049 | - if(!$isTlsWorking) { |
|
| 1050 | - return false; |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', \OCP\Util::DEBUG); |
|
| 1055 | - //interesting part: do the bind! |
|
| 1056 | - $login = $this->ldap->bind($cr, |
|
| 1057 | - $this->configuration->ldapAgentName, |
|
| 1058 | - $this->configuration->ldapAgentPassword |
|
| 1059 | - ); |
|
| 1060 | - $errNo = $this->ldap->errno($cr); |
|
| 1061 | - $error = ldap_error($cr); |
|
| 1062 | - $this->ldap->unbind($cr); |
|
| 1063 | - } catch(ServerNotAvailableException $e) { |
|
| 1064 | - return false; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - if($login === true) { |
|
| 1068 | - $this->ldap->unbind($cr); |
|
| 1069 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . intval($tls), \OCP\Util::DEBUG); |
|
| 1070 | - return true; |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - if($errNo === -1) { |
|
| 1074 | - //host, port or TLS wrong |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - throw new \Exception($error, $errNo); |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * checks whether a valid combination of agent and password has been |
|
| 1082 | - * provided (either two values or nothing for anonymous connect) |
|
| 1083 | - * @return bool, true if everything is fine, false otherwise |
|
| 1084 | - */ |
|
| 1085 | - private function checkAgentRequirements() { |
|
| 1086 | - $agent = $this->configuration->ldapAgentName; |
|
| 1087 | - $pwd = $this->configuration->ldapAgentPassword; |
|
| 1088 | - |
|
| 1089 | - return |
|
| 1090 | - ($agent !== '' && $pwd !== '') |
|
| 1091 | - || ($agent === '' && $pwd === '') |
|
| 1092 | - ; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * @param array $reqs |
|
| 1097 | - * @return bool |
|
| 1098 | - */ |
|
| 1099 | - private function checkRequirements($reqs) { |
|
| 1100 | - $this->checkAgentRequirements(); |
|
| 1101 | - foreach($reqs as $option) { |
|
| 1102 | - $value = $this->configuration->$option; |
|
| 1103 | - if(empty($value)) { |
|
| 1104 | - return false; |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - return true; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * does a cumulativeSearch on LDAP to get different values of a |
|
| 1112 | - * specified attribute |
|
| 1113 | - * @param string[] $filters array, the filters that shall be used in the search |
|
| 1114 | - * @param string $attr the attribute of which a list of values shall be returned |
|
| 1115 | - * @param int $dnReadLimit the amount of how many DNs should be analyzed. |
|
| 1116 | - * The lower, the faster |
|
| 1117 | - * @param string $maxF string. if not null, this variable will have the filter that |
|
| 1118 | - * yields most result entries |
|
| 1119 | - * @return array|false an array with the values on success, false otherwise |
|
| 1120 | - */ |
|
| 1121 | - public function cumulativeSearchOnAttribute($filters, $attr, $dnReadLimit = 3, &$maxF = null) { |
|
| 1122 | - $dnRead = array(); |
|
| 1123 | - $foundItems = array(); |
|
| 1124 | - $maxEntries = 0; |
|
| 1125 | - if(!is_array($this->configuration->ldapBase) |
|
| 1126 | - || !isset($this->configuration->ldapBase[0])) { |
|
| 1127 | - return false; |
|
| 1128 | - } |
|
| 1129 | - $base = $this->configuration->ldapBase[0]; |
|
| 1130 | - $cr = $this->getConnection(); |
|
| 1131 | - if(!$this->ldap->isResource($cr)) { |
|
| 1132 | - return false; |
|
| 1133 | - } |
|
| 1134 | - $lastFilter = null; |
|
| 1135 | - if(isset($filters[count($filters)-1])) { |
|
| 1136 | - $lastFilter = $filters[count($filters)-1]; |
|
| 1137 | - } |
|
| 1138 | - foreach($filters as $filter) { |
|
| 1139 | - if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1140 | - //skip when the filter is a wildcard and results were found |
|
| 1141 | - continue; |
|
| 1142 | - } |
|
| 1143 | - // 20k limit for performance and reason |
|
| 1144 | - $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
|
| 1145 | - if(!$this->ldap->isResource($rr)) { |
|
| 1146 | - continue; |
|
| 1147 | - } |
|
| 1148 | - $entries = $this->ldap->countEntries($cr, $rr); |
|
| 1149 | - $getEntryFunc = 'firstEntry'; |
|
| 1150 | - if(($entries !== false) && ($entries > 0)) { |
|
| 1151 | - if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1152 | - $maxEntries = $entries; |
|
| 1153 | - $maxF = $filter; |
|
| 1154 | - } |
|
| 1155 | - $dnReadCount = 0; |
|
| 1156 | - do { |
|
| 1157 | - $entry = $this->ldap->$getEntryFunc($cr, $rr); |
|
| 1158 | - $getEntryFunc = 'nextEntry'; |
|
| 1159 | - if(!$this->ldap->isResource($entry)) { |
|
| 1160 | - continue 2; |
|
| 1161 | - } |
|
| 1162 | - $rr = $entry; //will be expected by nextEntry next round |
|
| 1163 | - $attributes = $this->ldap->getAttributes($cr, $entry); |
|
| 1164 | - $dn = $this->ldap->getDN($cr, $entry); |
|
| 1165 | - if($dn === false || in_array($dn, $dnRead)) { |
|
| 1166 | - continue; |
|
| 1167 | - } |
|
| 1168 | - $newItems = array(); |
|
| 1169 | - $state = $this->getAttributeValuesFromEntry($attributes, |
|
| 1170 | - $attr, |
|
| 1171 | - $newItems); |
|
| 1172 | - $dnReadCount++; |
|
| 1173 | - $foundItems = array_merge($foundItems, $newItems); |
|
| 1174 | - $this->resultCache[$dn][$attr] = $newItems; |
|
| 1175 | - $dnRead[] = $dn; |
|
| 1176 | - } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1177 | - || $this->ldap->isResource($entry)) |
|
| 1178 | - && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
|
| 1179 | - } |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return array_unique($foundItems); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * determines if and which $attr are available on the LDAP server |
|
| 1187 | - * @param string[] $objectclasses the objectclasses to use as search filter |
|
| 1188 | - * @param string $attr the attribute to look for |
|
| 1189 | - * @param string $dbkey the dbkey of the setting the feature is connected to |
|
| 1190 | - * @param string $confkey the confkey counterpart for the $dbkey as used in the |
|
| 1191 | - * Configuration class |
|
| 1192 | - * @param bool $po whether the objectClass with most result entries |
|
| 1193 | - * shall be pre-selected via the result |
|
| 1194 | - * @return array|false list of found items. |
|
| 1195 | - * @throws \Exception |
|
| 1196 | - */ |
|
| 1197 | - private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
|
| 1198 | - $cr = $this->getConnection(); |
|
| 1199 | - if(!$cr) { |
|
| 1200 | - throw new \Exception('Could not connect to LDAP'); |
|
| 1201 | - } |
|
| 1202 | - $p = 'objectclass='; |
|
| 1203 | - foreach($objectclasses as $key => $value) { |
|
| 1204 | - $objectclasses[$key] = $p.$value; |
|
| 1205 | - } |
|
| 1206 | - $maxEntryObjC = ''; |
|
| 1207 | - |
|
| 1208 | - //how deep to dig? |
|
| 1209 | - //When looking for objectclasses, testing few entries is sufficient, |
|
| 1210 | - $dig = 3; |
|
| 1211 | - |
|
| 1212 | - $availableFeatures = |
|
| 1213 | - $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
|
| 1214 | - $dig, $maxEntryObjC); |
|
| 1215 | - if(is_array($availableFeatures) |
|
| 1216 | - && count($availableFeatures) > 0) { |
|
| 1217 | - natcasesort($availableFeatures); |
|
| 1218 | - //natcasesort keeps indices, but we must get rid of them for proper |
|
| 1219 | - //sorting in the web UI. Therefore: array_values |
|
| 1220 | - $this->result->addOptions($dbkey, array_values($availableFeatures)); |
|
| 1221 | - } else { |
|
| 1222 | - throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - $setFeatures = $this->configuration->$confkey; |
|
| 1226 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1227 | - //something is already configured? pre-select it. |
|
| 1228 | - $this->result->addChange($dbkey, $setFeatures); |
|
| 1229 | - } else if ($po && $maxEntryObjC !== '') { |
|
| 1230 | - //pre-select objectclass with most result entries |
|
| 1231 | - $maxEntryObjC = str_replace($p, '', $maxEntryObjC); |
|
| 1232 | - $this->applyFind($dbkey, $maxEntryObjC); |
|
| 1233 | - $this->result->addChange($dbkey, $maxEntryObjC); |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - return $availableFeatures; |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * appends a list of values fr |
|
| 1241 | - * @param resource $result the return value from ldap_get_attributes |
|
| 1242 | - * @param string $attribute the attribute values to look for |
|
| 1243 | - * @param array &$known new values will be appended here |
|
| 1244 | - * @return int, state on of the class constants LRESULT_PROCESSED_OK, |
|
| 1245 | - * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
|
| 1246 | - */ |
|
| 1247 | - private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
|
| 1248 | - if(!is_array($result) |
|
| 1249 | - || !isset($result['count']) |
|
| 1250 | - || !$result['count'] > 0) { |
|
| 1251 | - return self::LRESULT_PROCESSED_INVALID; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // strtolower on all keys for proper comparison |
|
| 1255 | - $result = \OCP\Util::mb_array_change_key_case($result); |
|
| 1256 | - $attribute = strtolower($attribute); |
|
| 1257 | - if(isset($result[$attribute])) { |
|
| 1258 | - foreach($result[$attribute] as $key => $val) { |
|
| 1259 | - if($key === 'count') { |
|
| 1260 | - continue; |
|
| 1261 | - } |
|
| 1262 | - if(!in_array($val, $known)) { |
|
| 1263 | - $known[] = $val; |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - return self::LRESULT_PROCESSED_OK; |
|
| 1267 | - } else { |
|
| 1268 | - return self::LRESULT_PROCESSED_SKIP; |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * @return bool|mixed |
|
| 1274 | - */ |
|
| 1275 | - private function getConnection() { |
|
| 1276 | - if(!is_null($this->cr)) { |
|
| 1277 | - return $this->cr; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - $cr = $this->ldap->connect( |
|
| 1281 | - $this->configuration->ldapHost, |
|
| 1282 | - $this->configuration->ldapPort |
|
| 1283 | - ); |
|
| 1284 | - |
|
| 1285 | - $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1286 | - $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1287 | - $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1288 | - if($this->configuration->ldapTLS === 1) { |
|
| 1289 | - $this->ldap->startTls($cr); |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - $lo = @$this->ldap->bind($cr, |
|
| 1293 | - $this->configuration->ldapAgentName, |
|
| 1294 | - $this->configuration->ldapAgentPassword); |
|
| 1295 | - if($lo === true) { |
|
| 1296 | - $this->$cr = $cr; |
|
| 1297 | - return $cr; |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - return false; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * @return array |
|
| 1305 | - */ |
|
| 1306 | - private function getDefaultLdapPortSettings() { |
|
| 1307 | - static $settings = array( |
|
| 1308 | - array('port' => 7636, 'tls' => false), |
|
| 1309 | - array('port' => 636, 'tls' => false), |
|
| 1310 | - array('port' => 7389, 'tls' => true), |
|
| 1311 | - array('port' => 389, 'tls' => true), |
|
| 1312 | - array('port' => 7389, 'tls' => false), |
|
| 1313 | - array('port' => 389, 'tls' => false), |
|
| 1314 | - ); |
|
| 1315 | - return $settings; |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * @return array |
|
| 1320 | - */ |
|
| 1321 | - private function getPortSettingsToTry() { |
|
| 1322 | - //389 ← LDAP / Unencrypted or StartTLS |
|
| 1323 | - //636 ← LDAPS / SSL |
|
| 1324 | - //7xxx ← UCS. need to be checked first, because both ports may be open |
|
| 1325 | - $host = $this->configuration->ldapHost; |
|
| 1326 | - $port = intval($this->configuration->ldapPort); |
|
| 1327 | - $portSettings = array(); |
|
| 1328 | - |
|
| 1329 | - //In case the port is already provided, we will check this first |
|
| 1330 | - if($port > 0) { |
|
| 1331 | - $hostInfo = parse_url($host); |
|
| 1332 | - if(!(is_array($hostInfo) |
|
| 1333 | - && isset($hostInfo['scheme']) |
|
| 1334 | - && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
|
| 1335 | - $portSettings[] = array('port' => $port, 'tls' => true); |
|
| 1336 | - } |
|
| 1337 | - $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - //default ports |
|
| 1341 | - $portSettings = array_merge($portSettings, |
|
| 1342 | - $this->getDefaultLdapPortSettings()); |
|
| 1343 | - |
|
| 1344 | - return $portSettings; |
|
| 1345 | - } |
|
| 41 | + /** @var \OCP\IL10N */ |
|
| 42 | + static protected $l; |
|
| 43 | + protected $access; |
|
| 44 | + protected $cr; |
|
| 45 | + protected $configuration; |
|
| 46 | + protected $result; |
|
| 47 | + protected $resultCache = array(); |
|
| 48 | + |
|
| 49 | + const LRESULT_PROCESSED_OK = 2; |
|
| 50 | + const LRESULT_PROCESSED_INVALID = 3; |
|
| 51 | + const LRESULT_PROCESSED_SKIP = 4; |
|
| 52 | + |
|
| 53 | + const LFILTER_LOGIN = 2; |
|
| 54 | + const LFILTER_USER_LIST = 3; |
|
| 55 | + const LFILTER_GROUP_LIST = 4; |
|
| 56 | + |
|
| 57 | + const LFILTER_MODE_ASSISTED = 2; |
|
| 58 | + const LFILTER_MODE_RAW = 1; |
|
| 59 | + |
|
| 60 | + const LDAP_NW_TIMEOUT = 4; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Constructor |
|
| 64 | + * @param Configuration $configuration an instance of Configuration |
|
| 65 | + * @param ILDAPWrapper $ldap an instance of ILDAPWrapper |
|
| 66 | + * @param Access $access |
|
| 67 | + */ |
|
| 68 | + public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
|
| 69 | + parent::__construct($ldap); |
|
| 70 | + $this->configuration = $configuration; |
|
| 71 | + if(is_null(Wizard::$l)) { |
|
| 72 | + Wizard::$l = \OC::$server->getL10N('user_ldap'); |
|
| 73 | + } |
|
| 74 | + $this->access = $access; |
|
| 75 | + $this->result = new WizardResult(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function __destruct() { |
|
| 79 | + if($this->result->hasChanges()) { |
|
| 80 | + $this->configuration->saveConfiguration(); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * counts entries in the LDAP directory |
|
| 86 | + * |
|
| 87 | + * @param string $filter the LDAP search filter |
|
| 88 | + * @param string $type a string being either 'users' or 'groups'; |
|
| 89 | + * @return bool|int |
|
| 90 | + * @throws \Exception |
|
| 91 | + */ |
|
| 92 | + public function countEntries($filter, $type) { |
|
| 93 | + $reqs = array('ldapHost', 'ldapPort', 'ldapBase'); |
|
| 94 | + if($type === 'users') { |
|
| 95 | + $reqs[] = 'ldapUserFilter'; |
|
| 96 | + } |
|
| 97 | + if(!$this->checkRequirements($reqs)) { |
|
| 98 | + throw new \Exception('Requirements not met', 400); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $attr = array('dn'); // default |
|
| 102 | + $limit = 1001; |
|
| 103 | + if($type === 'groups') { |
|
| 104 | + $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 105 | + } else if($type === 'users') { |
|
| 106 | + $result = $this->access->countUsers($filter, $attr, $limit); |
|
| 107 | + } else if ($type === 'objects') { |
|
| 108 | + $result = $this->access->countObjects($limit); |
|
| 109 | + } else { |
|
| 110 | + throw new \Exception('Internal error: Invalid object type', 500); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return $result; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * formats the return value of a count operation to the string to be |
|
| 118 | + * inserted. |
|
| 119 | + * |
|
| 120 | + * @param bool|int $count |
|
| 121 | + * @return int|string |
|
| 122 | + */ |
|
| 123 | + private function formatCountResult($count) { |
|
| 124 | + $formatted = ($count !== false) ? $count : 0; |
|
| 125 | + if($formatted > 1000) { |
|
| 126 | + $formatted = '> 1000'; |
|
| 127 | + } |
|
| 128 | + return $formatted; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function countGroups() { |
|
| 132 | + $filter = $this->configuration->ldapGroupFilter; |
|
| 133 | + |
|
| 134 | + if(empty($filter)) { |
|
| 135 | + $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
|
| 136 | + $this->result->addChange('ldap_group_count', $output); |
|
| 137 | + return $this->result; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + try { |
|
| 141 | + $groupsTotal = $this->formatCountResult($this->countEntries($filter, 'groups')); |
|
| 142 | + } catch (\Exception $e) { |
|
| 143 | + //400 can be ignored, 500 is forwarded |
|
| 144 | + if($e->getCode() === 500) { |
|
| 145 | + throw $e; |
|
| 146 | + } |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 149 | + $output = self::$l->n('%s group found', '%s groups found', $groupsTotal, array($groupsTotal)); |
|
| 150 | + $this->result->addChange('ldap_group_count', $output); |
|
| 151 | + return $this->result; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return WizardResult |
|
| 156 | + * @throws \Exception |
|
| 157 | + */ |
|
| 158 | + public function countUsers() { |
|
| 159 | + $filter = $this->access->getFilterForUserCount(); |
|
| 160 | + |
|
| 161 | + $usersTotal = $this->formatCountResult($this->countEntries($filter, 'users')); |
|
| 162 | + $output = self::$l->n('%s user found', '%s users found', $usersTotal, array($usersTotal)); |
|
| 163 | + $this->result->addChange('ldap_user_count', $output); |
|
| 164 | + return $this->result; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * counts any objects in the currently set base dn |
|
| 169 | + * |
|
| 170 | + * @return WizardResult |
|
| 171 | + * @throws \Exception |
|
| 172 | + */ |
|
| 173 | + public function countInBaseDN() { |
|
| 174 | + // we don't need to provide a filter in this case |
|
| 175 | + $total = $this->countEntries(null, 'objects'); |
|
| 176 | + if($total === false) { |
|
| 177 | + throw new \Exception('invalid results received'); |
|
| 178 | + } |
|
| 179 | + $this->result->addChange('ldap_test_base', $total); |
|
| 180 | + return $this->result; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * counts users with a specified attribute |
|
| 185 | + * @param string $attr |
|
| 186 | + * @param bool $existsCheck |
|
| 187 | + * @return int|bool |
|
| 188 | + */ |
|
| 189 | + public function countUsersWithAttribute($attr, $existsCheck = false) { |
|
| 190 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 191 | + 'ldapPort', |
|
| 192 | + 'ldapBase', |
|
| 193 | + 'ldapUserFilter', |
|
| 194 | + ))) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $filter = $this->access->combineFilterWithAnd(array( |
|
| 199 | + $this->configuration->ldapUserFilter, |
|
| 200 | + $attr . '=*' |
|
| 201 | + )); |
|
| 202 | + |
|
| 203 | + $limit = ($existsCheck === false) ? null : 1; |
|
| 204 | + |
|
| 205 | + return $this->access->countUsers($filter, array('dn'), $limit); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * detects the display name attribute. If a setting is already present that |
|
| 210 | + * returns at least one hit, the detection will be canceled. |
|
| 211 | + * @return WizardResult|bool |
|
| 212 | + * @throws \Exception |
|
| 213 | + */ |
|
| 214 | + public function detectUserDisplayNameAttribute() { |
|
| 215 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 216 | + 'ldapPort', |
|
| 217 | + 'ldapBase', |
|
| 218 | + 'ldapUserFilter', |
|
| 219 | + ))) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $attr = $this->configuration->ldapUserDisplayName; |
|
| 224 | + if ($attr !== '' && $attr !== 'displayName') { |
|
| 225 | + // most likely not the default value with upper case N, |
|
| 226 | + // verify it still produces a result |
|
| 227 | + $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 228 | + if($count > 0) { |
|
| 229 | + //no change, but we sent it back to make sure the user interface |
|
| 230 | + //is still correct, even if the ajax call was cancelled meanwhile |
|
| 231 | + $this->result->addChange('ldap_display_name', $attr); |
|
| 232 | + return $this->result; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // first attribute that has at least one result wins |
|
| 237 | + $displayNameAttrs = array('displayname', 'cn'); |
|
| 238 | + foreach ($displayNameAttrs as $attr) { |
|
| 239 | + $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 240 | + |
|
| 241 | + if($count > 0) { |
|
| 242 | + $this->applyFind('ldap_display_name', $attr); |
|
| 243 | + return $this->result; |
|
| 244 | + } |
|
| 245 | + }; |
|
| 246 | + |
|
| 247 | + throw new \Exception(self::$l->t('Could not detect user display name attribute. Please specify it yourself in advanced LDAP settings.')); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * detects the most often used email attribute for users applying to the |
|
| 252 | + * user list filter. If a setting is already present that returns at least |
|
| 253 | + * one hit, the detection will be canceled. |
|
| 254 | + * @return WizardResult|bool |
|
| 255 | + */ |
|
| 256 | + public function detectEmailAttribute() { |
|
| 257 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 258 | + 'ldapPort', |
|
| 259 | + 'ldapBase', |
|
| 260 | + 'ldapUserFilter', |
|
| 261 | + ))) { |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $attr = $this->configuration->ldapEmailAttribute; |
|
| 266 | + if ($attr !== '') { |
|
| 267 | + $count = intval($this->countUsersWithAttribute($attr, true)); |
|
| 268 | + if($count > 0) { |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 271 | + $writeLog = true; |
|
| 272 | + } else { |
|
| 273 | + $writeLog = false; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $emailAttributes = array('mail', 'mailPrimaryAddress'); |
|
| 277 | + $winner = ''; |
|
| 278 | + $maxUsers = 0; |
|
| 279 | + foreach($emailAttributes as $attr) { |
|
| 280 | + $count = $this->countUsersWithAttribute($attr); |
|
| 281 | + if($count > $maxUsers) { |
|
| 282 | + $maxUsers = $count; |
|
| 283 | + $winner = $attr; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if($winner !== '') { |
|
| 288 | + $this->applyFind('ldap_email_attr', $winner); |
|
| 289 | + if($writeLog) { |
|
| 290 | + \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 291 | + 'automatically been reset, because the original value ' . |
|
| 292 | + 'did not return any results.', \OCP\Util::INFO); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + return $this->result; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return WizardResult |
|
| 301 | + * @throws \Exception |
|
| 302 | + */ |
|
| 303 | + public function determineAttributes() { |
|
| 304 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 305 | + 'ldapPort', |
|
| 306 | + 'ldapBase', |
|
| 307 | + 'ldapUserFilter', |
|
| 308 | + ))) { |
|
| 309 | + return false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $attributes = $this->getUserAttributes(); |
|
| 313 | + |
|
| 314 | + natcasesort($attributes); |
|
| 315 | + $attributes = array_values($attributes); |
|
| 316 | + |
|
| 317 | + $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
|
| 318 | + |
|
| 319 | + $selected = $this->configuration->ldapLoginFilterAttributes; |
|
| 320 | + if(is_array($selected) && !empty($selected)) { |
|
| 321 | + $this->result->addChange('ldap_loginfilter_attributes', $selected); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $this->result; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * detects the available LDAP attributes |
|
| 329 | + * @return array|false The instance's WizardResult instance |
|
| 330 | + * @throws \Exception |
|
| 331 | + */ |
|
| 332 | + private function getUserAttributes() { |
|
| 333 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 334 | + 'ldapPort', |
|
| 335 | + 'ldapBase', |
|
| 336 | + 'ldapUserFilter', |
|
| 337 | + ))) { |
|
| 338 | + return false; |
|
| 339 | + } |
|
| 340 | + $cr = $this->getConnection(); |
|
| 341 | + if(!$cr) { |
|
| 342 | + throw new \Exception('Could not connect to LDAP'); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + $base = $this->configuration->ldapBase[0]; |
|
| 346 | + $filter = $this->configuration->ldapUserFilter; |
|
| 347 | + $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
|
| 348 | + if(!$this->ldap->isResource($rr)) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 351 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 352 | + $attributes = $this->ldap->getAttributes($cr, $er); |
|
| 353 | + $pureAttributes = array(); |
|
| 354 | + for($i = 0; $i < $attributes['count']; $i++) { |
|
| 355 | + $pureAttributes[] = $attributes[$i]; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $pureAttributes; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * detects the available LDAP groups |
|
| 363 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 364 | + */ |
|
| 365 | + public function determineGroupsForGroups() { |
|
| 366 | + return $this->determineGroups('ldap_groupfilter_groups', |
|
| 367 | + 'ldapGroupFilterGroups', |
|
| 368 | + false); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * detects the available LDAP groups |
|
| 373 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 374 | + */ |
|
| 375 | + public function determineGroupsForUsers() { |
|
| 376 | + return $this->determineGroups('ldap_userfilter_groups', |
|
| 377 | + 'ldapUserFilterGroups'); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * detects the available LDAP groups |
|
| 382 | + * @param string $dbKey |
|
| 383 | + * @param string $confKey |
|
| 384 | + * @param bool $testMemberOf |
|
| 385 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 386 | + * @throws \Exception |
|
| 387 | + */ |
|
| 388 | + private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
|
| 389 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 390 | + 'ldapPort', |
|
| 391 | + 'ldapBase', |
|
| 392 | + ))) { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + $cr = $this->getConnection(); |
|
| 396 | + if(!$cr) { |
|
| 397 | + throw new \Exception('Could not connect to LDAP'); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + $this->fetchGroups($dbKey, $confKey); |
|
| 401 | + |
|
| 402 | + if($testMemberOf) { |
|
| 403 | + $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
|
| 404 | + $this->result->markChange(); |
|
| 405 | + if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 406 | + throw new \Exception('memberOf is not supported by the server'); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return $this->result; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * fetches all groups from LDAP and adds them to the result object |
|
| 415 | + * |
|
| 416 | + * @param string $dbKey |
|
| 417 | + * @param string $confKey |
|
| 418 | + * @return array $groupEntries |
|
| 419 | + * @throws \Exception |
|
| 420 | + */ |
|
| 421 | + public function fetchGroups($dbKey, $confKey) { |
|
| 422 | + $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
|
| 423 | + |
|
| 424 | + $filterParts = array(); |
|
| 425 | + foreach($obclasses as $obclass) { |
|
| 426 | + $filterParts[] = 'objectclass='.$obclass; |
|
| 427 | + } |
|
| 428 | + //we filter for everything |
|
| 429 | + //- that looks like a group and |
|
| 430 | + //- has the group display name set |
|
| 431 | + $filter = $this->access->combineFilterWithOr($filterParts); |
|
| 432 | + $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); |
|
| 433 | + |
|
| 434 | + $groupNames = array(); |
|
| 435 | + $groupEntries = array(); |
|
| 436 | + $limit = 400; |
|
| 437 | + $offset = 0; |
|
| 438 | + do { |
|
| 439 | + // we need to request dn additionally here, otherwise memberOf |
|
| 440 | + // detection will fail later |
|
| 441 | + $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
|
| 442 | + foreach($result as $item) { |
|
| 443 | + if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 444 | + // just in case - no issue known |
|
| 445 | + continue; |
|
| 446 | + } |
|
| 447 | + $groupNames[] = $item['cn'][0]; |
|
| 448 | + $groupEntries[] = $item; |
|
| 449 | + } |
|
| 450 | + $offset += $limit; |
|
| 451 | + } while ($this->access->hasMoreResults()); |
|
| 452 | + |
|
| 453 | + if(count($groupNames) > 0) { |
|
| 454 | + natsort($groupNames); |
|
| 455 | + $this->result->addOptions($dbKey, array_values($groupNames)); |
|
| 456 | + } else { |
|
| 457 | + throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + $setFeatures = $this->configuration->$confKey; |
|
| 461 | + if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 462 | + //something is already configured? pre-select it. |
|
| 463 | + $this->result->addChange($dbKey, $setFeatures); |
|
| 464 | + } |
|
| 465 | + return $groupEntries; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + public function determineGroupMemberAssoc() { |
|
| 469 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 470 | + 'ldapPort', |
|
| 471 | + 'ldapGroupFilter', |
|
| 472 | + ))) { |
|
| 473 | + return false; |
|
| 474 | + } |
|
| 475 | + $attribute = $this->detectGroupMemberAssoc(); |
|
| 476 | + if($attribute === false) { |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
|
| 480 | + $this->result->addChange('ldap_group_member_assoc_attribute', $attribute); |
|
| 481 | + |
|
| 482 | + return $this->result; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Detects the available object classes |
|
| 487 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 488 | + * @throws \Exception |
|
| 489 | + */ |
|
| 490 | + public function determineGroupObjectClasses() { |
|
| 491 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 492 | + 'ldapPort', |
|
| 493 | + 'ldapBase', |
|
| 494 | + ))) { |
|
| 495 | + return false; |
|
| 496 | + } |
|
| 497 | + $cr = $this->getConnection(); |
|
| 498 | + if(!$cr) { |
|
| 499 | + throw new \Exception('Could not connect to LDAP'); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + $obclasses = array('groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*'); |
|
| 503 | + $this->determineFeature($obclasses, |
|
| 504 | + 'objectclass', |
|
| 505 | + 'ldap_groupfilter_objectclass', |
|
| 506 | + 'ldapGroupFilterObjectclass', |
|
| 507 | + false); |
|
| 508 | + |
|
| 509 | + return $this->result; |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * detects the available object classes |
|
| 514 | + * @return WizardResult |
|
| 515 | + * @throws \Exception |
|
| 516 | + */ |
|
| 517 | + public function determineUserObjectClasses() { |
|
| 518 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 519 | + 'ldapPort', |
|
| 520 | + 'ldapBase', |
|
| 521 | + ))) { |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + $cr = $this->getConnection(); |
|
| 525 | + if(!$cr) { |
|
| 526 | + throw new \Exception('Could not connect to LDAP'); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $obclasses = array('inetOrgPerson', 'person', 'organizationalPerson', |
|
| 530 | + 'user', 'posixAccount', '*'); |
|
| 531 | + $filter = $this->configuration->ldapUserFilter; |
|
| 532 | + //if filter is empty, it is probably the first time the wizard is called |
|
| 533 | + //then, apply suggestions. |
|
| 534 | + $this->determineFeature($obclasses, |
|
| 535 | + 'objectclass', |
|
| 536 | + 'ldap_userfilter_objectclass', |
|
| 537 | + 'ldapUserFilterObjectclass', |
|
| 538 | + empty($filter)); |
|
| 539 | + |
|
| 540 | + return $this->result; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @return WizardResult|false |
|
| 545 | + * @throws \Exception |
|
| 546 | + */ |
|
| 547 | + public function getGroupFilter() { |
|
| 548 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 549 | + 'ldapPort', |
|
| 550 | + 'ldapBase', |
|
| 551 | + ))) { |
|
| 552 | + return false; |
|
| 553 | + } |
|
| 554 | + //make sure the use display name is set |
|
| 555 | + $displayName = $this->configuration->ldapGroupDisplayName; |
|
| 556 | + if ($displayName === '') { |
|
| 557 | + $d = $this->configuration->getDefaults(); |
|
| 558 | + $this->applyFind('ldap_group_display_name', |
|
| 559 | + $d['ldap_group_display_name']); |
|
| 560 | + } |
|
| 561 | + $filter = $this->composeLdapFilter(self::LFILTER_GROUP_LIST); |
|
| 562 | + |
|
| 563 | + $this->applyFind('ldap_group_filter', $filter); |
|
| 564 | + return $this->result; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * @return WizardResult|false |
|
| 569 | + * @throws \Exception |
|
| 570 | + */ |
|
| 571 | + public function getUserListFilter() { |
|
| 572 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 573 | + 'ldapPort', |
|
| 574 | + 'ldapBase', |
|
| 575 | + ))) { |
|
| 576 | + return false; |
|
| 577 | + } |
|
| 578 | + //make sure the use display name is set |
|
| 579 | + $displayName = $this->configuration->ldapUserDisplayName; |
|
| 580 | + if ($displayName === '') { |
|
| 581 | + $d = $this->configuration->getDefaults(); |
|
| 582 | + $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
|
| 583 | + } |
|
| 584 | + $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
|
| 585 | + if(!$filter) { |
|
| 586 | + throw new \Exception('Cannot create filter'); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $this->applyFind('ldap_userlist_filter', $filter); |
|
| 590 | + return $this->result; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * @return bool|WizardResult |
|
| 595 | + * @throws \Exception |
|
| 596 | + */ |
|
| 597 | + public function getUserLoginFilter() { |
|
| 598 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 599 | + 'ldapPort', |
|
| 600 | + 'ldapBase', |
|
| 601 | + 'ldapUserFilter', |
|
| 602 | + ))) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
|
| 607 | + if(!$filter) { |
|
| 608 | + throw new \Exception('Cannot create filter'); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + $this->applyFind('ldap_login_filter', $filter); |
|
| 612 | + return $this->result; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * @return bool|WizardResult |
|
| 617 | + * @param string $loginName |
|
| 618 | + * @throws \Exception |
|
| 619 | + */ |
|
| 620 | + public function testLoginName($loginName) { |
|
| 621 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 622 | + 'ldapPort', |
|
| 623 | + 'ldapBase', |
|
| 624 | + 'ldapLoginFilter', |
|
| 625 | + ))) { |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + $cr = $this->access->connection->getConnectionResource(); |
|
| 630 | + if(!$this->ldap->isResource($cr)) { |
|
| 631 | + throw new \Exception('connection error'); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 635 | + === false) { |
|
| 636 | + throw new \Exception('missing placeholder'); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + $users = $this->access->countUsersByLoginName($loginName); |
|
| 640 | + if($this->ldap->errno($cr) !== 0) { |
|
| 641 | + throw new \Exception($this->ldap->error($cr)); |
|
| 642 | + } |
|
| 643 | + $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
|
| 644 | + $this->result->addChange('ldap_test_loginname', $users); |
|
| 645 | + $this->result->addChange('ldap_test_effective_filter', $filter); |
|
| 646 | + return $this->result; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * Tries to determine the port, requires given Host, User DN and Password |
|
| 651 | + * @return WizardResult|false WizardResult on success, false otherwise |
|
| 652 | + * @throws \Exception |
|
| 653 | + */ |
|
| 654 | + public function guessPortAndTLS() { |
|
| 655 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 656 | + ))) { |
|
| 657 | + return false; |
|
| 658 | + } |
|
| 659 | + $this->checkHost(); |
|
| 660 | + $portSettings = $this->getPortSettingsToTry(); |
|
| 661 | + |
|
| 662 | + if(!is_array($portSettings)) { |
|
| 663 | + throw new \Exception(print_r($portSettings, true)); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + //proceed from the best configuration and return on first success |
|
| 667 | + foreach($portSettings as $setting) { |
|
| 668 | + $p = $setting['port']; |
|
| 669 | + $t = $setting['tls']; |
|
| 670 | + \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, \OCP\Util::DEBUG); |
|
| 671 | + //connectAndBind may throw Exception, it needs to be catched by the |
|
| 672 | + //callee of this method |
|
| 673 | + |
|
| 674 | + try { |
|
| 675 | + $settingsFound = $this->connectAndBind($p, $t); |
|
| 676 | + } catch (\Exception $e) { |
|
| 677 | + // any reply other than -1 (= cannot connect) is already okay, |
|
| 678 | + // because then we found the server |
|
| 679 | + // unavailable startTLS returns -11 |
|
| 680 | + if($e->getCode() > 0) { |
|
| 681 | + $settingsFound = true; |
|
| 682 | + } else { |
|
| 683 | + throw $e; |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + if ($settingsFound === true) { |
|
| 688 | + $config = array( |
|
| 689 | + 'ldapPort' => $p, |
|
| 690 | + 'ldapTLS' => intval($t) |
|
| 691 | + ); |
|
| 692 | + $this->configuration->setConfiguration($config); |
|
| 693 | + \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG); |
|
| 694 | + $this->result->addChange('ldap_port', $p); |
|
| 695 | + return $this->result; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + //custom port, undetected (we do not brute force) |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * tries to determine a base dn from User DN or LDAP Host |
|
| 705 | + * @return WizardResult|false WizardResult on success, false otherwise |
|
| 706 | + */ |
|
| 707 | + public function guessBaseDN() { |
|
| 708 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 709 | + 'ldapPort', |
|
| 710 | + ))) { |
|
| 711 | + return false; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + //check whether a DN is given in the agent name (99.9% of all cases) |
|
| 715 | + $base = null; |
|
| 716 | + $i = stripos($this->configuration->ldapAgentName, 'dc='); |
|
| 717 | + if($i !== false) { |
|
| 718 | + $base = substr($this->configuration->ldapAgentName, $i); |
|
| 719 | + if($this->testBaseDN($base)) { |
|
| 720 | + $this->applyFind('ldap_base', $base); |
|
| 721 | + return $this->result; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + //this did not help :( |
|
| 726 | + //Let's see whether we can parse the Host URL and convert the domain to |
|
| 727 | + //a base DN |
|
| 728 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 729 | + $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
|
| 730 | + if(!$domain) { |
|
| 731 | + return false; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + $dparts = explode('.', $domain); |
|
| 735 | + while(count($dparts) > 0) { |
|
| 736 | + $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 737 | + if ($base !== $base2 && $this->testBaseDN($base2)) { |
|
| 738 | + $this->applyFind('ldap_base', $base2); |
|
| 739 | + return $this->result; |
|
| 740 | + } |
|
| 741 | + array_shift($dparts); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * sets the found value for the configuration key in the WizardResult |
|
| 749 | + * as well as in the Configuration instance |
|
| 750 | + * @param string $key the configuration key |
|
| 751 | + * @param string $value the (detected) value |
|
| 752 | + * |
|
| 753 | + */ |
|
| 754 | + private function applyFind($key, $value) { |
|
| 755 | + $this->result->addChange($key, $value); |
|
| 756 | + $this->configuration->setConfiguration(array($key => $value)); |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * Checks, whether a port was entered in the Host configuration |
|
| 761 | + * field. In this case the port will be stripped off, but also stored as |
|
| 762 | + * setting. |
|
| 763 | + */ |
|
| 764 | + private function checkHost() { |
|
| 765 | + $host = $this->configuration->ldapHost; |
|
| 766 | + $hostInfo = parse_url($host); |
|
| 767 | + |
|
| 768 | + //removes Port from Host |
|
| 769 | + if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 770 | + $port = $hostInfo['port']; |
|
| 771 | + $host = str_replace(':'.$port, '', $host); |
|
| 772 | + $this->applyFind('ldap_host', $host); |
|
| 773 | + $this->applyFind('ldap_port', $port); |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * tries to detect the group member association attribute which is |
|
| 779 | + * one of 'uniqueMember', 'memberUid', 'member', 'gidNumber' |
|
| 780 | + * @return string|false, string with the attribute name, false on error |
|
| 781 | + * @throws \Exception |
|
| 782 | + */ |
|
| 783 | + private function detectGroupMemberAssoc() { |
|
| 784 | + $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
|
| 785 | + $filter = $this->configuration->ldapGroupFilter; |
|
| 786 | + if(empty($filter)) { |
|
| 787 | + return false; |
|
| 788 | + } |
|
| 789 | + $cr = $this->getConnection(); |
|
| 790 | + if(!$cr) { |
|
| 791 | + throw new \Exception('Could not connect to LDAP'); |
|
| 792 | + } |
|
| 793 | + $base = $this->configuration->ldapBase[0]; |
|
| 794 | + $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
|
| 795 | + if(!$this->ldap->isResource($rr)) { |
|
| 796 | + return false; |
|
| 797 | + } |
|
| 798 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 799 | + while(is_resource($er)) { |
|
| 800 | + $this->ldap->getDN($cr, $er); |
|
| 801 | + $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 802 | + $result = array(); |
|
| 803 | + $possibleAttrsCount = count($possibleAttrs); |
|
| 804 | + for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 805 | + if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 806 | + $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if(!empty($result)) { |
|
| 810 | + natsort($result); |
|
| 811 | + return key($result); |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + $er = $this->ldap->nextEntry($cr, $er); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Checks whether for a given BaseDN results will be returned |
|
| 822 | + * @param string $base the BaseDN to test |
|
| 823 | + * @return bool true on success, false otherwise |
|
| 824 | + * @throws \Exception |
|
| 825 | + */ |
|
| 826 | + private function testBaseDN($base) { |
|
| 827 | + $cr = $this->getConnection(); |
|
| 828 | + if(!$cr) { |
|
| 829 | + throw new \Exception('Could not connect to LDAP'); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + //base is there, let's validate it. If we search for anything, we should |
|
| 833 | + //get a result set > 0 on a proper base |
|
| 834 | + $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
|
| 835 | + if(!$this->ldap->isResource($rr)) { |
|
| 836 | + $errorNo = $this->ldap->errno($cr); |
|
| 837 | + $errorMsg = $this->ldap->error($cr); |
|
| 838 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
|
| 839 | + ' Error '.$errorNo.': '.$errorMsg, \OCP\Util::INFO); |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + $entries = $this->ldap->countEntries($cr, $rr); |
|
| 843 | + return ($entries !== false) && ($entries > 0); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * Checks whether the server supports memberOf in LDAP Filter. |
|
| 848 | + * Note: at least in OpenLDAP, availability of memberOf is dependent on |
|
| 849 | + * a configured objectClass. I.e. not necessarily for all available groups |
|
| 850 | + * memberOf does work. |
|
| 851 | + * |
|
| 852 | + * @return bool true if it does, false otherwise |
|
| 853 | + * @throws \Exception |
|
| 854 | + */ |
|
| 855 | + private function testMemberOf() { |
|
| 856 | + $cr = $this->getConnection(); |
|
| 857 | + if(!$cr) { |
|
| 858 | + throw new \Exception('Could not connect to LDAP'); |
|
| 859 | + } |
|
| 860 | + $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
|
| 861 | + if(is_int($result) && $result > 0) { |
|
| 862 | + return true; |
|
| 863 | + } |
|
| 864 | + return false; |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * creates an LDAP Filter from given configuration |
|
| 869 | + * @param integer $filterType int, for which use case the filter shall be created |
|
| 870 | + * can be any of self::LFILTER_USER_LIST, self::LFILTER_LOGIN or |
|
| 871 | + * self::LFILTER_GROUP_LIST |
|
| 872 | + * @return string|false string with the filter on success, false otherwise |
|
| 873 | + * @throws \Exception |
|
| 874 | + */ |
|
| 875 | + private function composeLdapFilter($filterType) { |
|
| 876 | + $filter = ''; |
|
| 877 | + $parts = 0; |
|
| 878 | + switch ($filterType) { |
|
| 879 | + case self::LFILTER_USER_LIST: |
|
| 880 | + $objcs = $this->configuration->ldapUserFilterObjectclass; |
|
| 881 | + //glue objectclasses |
|
| 882 | + if(is_array($objcs) && count($objcs) > 0) { |
|
| 883 | + $filter .= '(|'; |
|
| 884 | + foreach($objcs as $objc) { |
|
| 885 | + $filter .= '(objectclass=' . $objc . ')'; |
|
| 886 | + } |
|
| 887 | + $filter .= ')'; |
|
| 888 | + $parts++; |
|
| 889 | + } |
|
| 890 | + //glue group memberships |
|
| 891 | + if($this->configuration->hasMemberOfFilterSupport) { |
|
| 892 | + $cns = $this->configuration->ldapUserFilterGroups; |
|
| 893 | + if(is_array($cns) && count($cns) > 0) { |
|
| 894 | + $filter .= '(|'; |
|
| 895 | + $cr = $this->getConnection(); |
|
| 896 | + if(!$cr) { |
|
| 897 | + throw new \Exception('Could not connect to LDAP'); |
|
| 898 | + } |
|
| 899 | + $base = $this->configuration->ldapBase[0]; |
|
| 900 | + foreach($cns as $cn) { |
|
| 901 | + $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 902 | + if(!$this->ldap->isResource($rr)) { |
|
| 903 | + continue; |
|
| 904 | + } |
|
| 905 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 906 | + $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 907 | + $dn = $this->ldap->getDN($cr, $er); |
|
| 908 | + if ($dn === false || $dn === '') { |
|
| 909 | + continue; |
|
| 910 | + } |
|
| 911 | + $filterPart = '(memberof=' . $dn . ')'; |
|
| 912 | + if(isset($attrs['primaryGroupToken'])) { |
|
| 913 | + $pgt = $attrs['primaryGroupToken'][0]; |
|
| 914 | + $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 915 | + $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 916 | + } |
|
| 917 | + $filter .= $filterPart; |
|
| 918 | + } |
|
| 919 | + $filter .= ')'; |
|
| 920 | + } |
|
| 921 | + $parts++; |
|
| 922 | + } |
|
| 923 | + //wrap parts in AND condition |
|
| 924 | + if($parts > 1) { |
|
| 925 | + $filter = '(&' . $filter . ')'; |
|
| 926 | + } |
|
| 927 | + if ($filter === '') { |
|
| 928 | + $filter = '(objectclass=*)'; |
|
| 929 | + } |
|
| 930 | + break; |
|
| 931 | + |
|
| 932 | + case self::LFILTER_GROUP_LIST: |
|
| 933 | + $objcs = $this->configuration->ldapGroupFilterObjectclass; |
|
| 934 | + //glue objectclasses |
|
| 935 | + if(is_array($objcs) && count($objcs) > 0) { |
|
| 936 | + $filter .= '(|'; |
|
| 937 | + foreach($objcs as $objc) { |
|
| 938 | + $filter .= '(objectclass=' . $objc . ')'; |
|
| 939 | + } |
|
| 940 | + $filter .= ')'; |
|
| 941 | + $parts++; |
|
| 942 | + } |
|
| 943 | + //glue group memberships |
|
| 944 | + $cns = $this->configuration->ldapGroupFilterGroups; |
|
| 945 | + if(is_array($cns) && count($cns) > 0) { |
|
| 946 | + $filter .= '(|'; |
|
| 947 | + foreach($cns as $cn) { |
|
| 948 | + $filter .= '(cn=' . $cn . ')'; |
|
| 949 | + } |
|
| 950 | + $filter .= ')'; |
|
| 951 | + } |
|
| 952 | + $parts++; |
|
| 953 | + //wrap parts in AND condition |
|
| 954 | + if($parts > 1) { |
|
| 955 | + $filter = '(&' . $filter . ')'; |
|
| 956 | + } |
|
| 957 | + break; |
|
| 958 | + |
|
| 959 | + case self::LFILTER_LOGIN: |
|
| 960 | + $ulf = $this->configuration->ldapUserFilter; |
|
| 961 | + $loginpart = '=%uid'; |
|
| 962 | + $filterUsername = ''; |
|
| 963 | + $userAttributes = $this->getUserAttributes(); |
|
| 964 | + $userAttributes = array_change_key_case(array_flip($userAttributes)); |
|
| 965 | + $parts = 0; |
|
| 966 | + |
|
| 967 | + if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 968 | + $attr = ''; |
|
| 969 | + if(isset($userAttributes['uid'])) { |
|
| 970 | + $attr = 'uid'; |
|
| 971 | + } else if(isset($userAttributes['samaccountname'])) { |
|
| 972 | + $attr = 'samaccountname'; |
|
| 973 | + } else if(isset($userAttributes['cn'])) { |
|
| 974 | + //fallback |
|
| 975 | + $attr = 'cn'; |
|
| 976 | + } |
|
| 977 | + if ($attr !== '') { |
|
| 978 | + $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 979 | + $parts++; |
|
| 980 | + } |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + $filterEmail = ''; |
|
| 984 | + if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 985 | + $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
|
| 986 | + $parts++; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + $filterAttributes = ''; |
|
| 990 | + $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
|
| 991 | + if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 992 | + $filterAttributes = '(|'; |
|
| 993 | + foreach($attrsToFilter as $attribute) { |
|
| 994 | + $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 995 | + } |
|
| 996 | + $filterAttributes .= ')'; |
|
| 997 | + $parts++; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + $filterLogin = ''; |
|
| 1001 | + if($parts > 1) { |
|
| 1002 | + $filterLogin = '(|'; |
|
| 1003 | + } |
|
| 1004 | + $filterLogin .= $filterUsername; |
|
| 1005 | + $filterLogin .= $filterEmail; |
|
| 1006 | + $filterLogin .= $filterAttributes; |
|
| 1007 | + if($parts > 1) { |
|
| 1008 | + $filterLogin .= ')'; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + $filter = '(&'.$ulf.$filterLogin.')'; |
|
| 1012 | + break; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, \OCP\Util::DEBUG); |
|
| 1016 | + |
|
| 1017 | + return $filter; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + /** |
|
| 1021 | + * Connects and Binds to an LDAP Server |
|
| 1022 | + * |
|
| 1023 | + * @param int $port the port to connect with |
|
| 1024 | + * @param bool $tls whether startTLS is to be used |
|
| 1025 | + * @return bool |
|
| 1026 | + * @throws \Exception |
|
| 1027 | + */ |
|
| 1028 | + private function connectAndBind($port, $tls) { |
|
| 1029 | + //connect, does not really trigger any server communication |
|
| 1030 | + $host = $this->configuration->ldapHost; |
|
| 1031 | + $hostInfo = parse_url($host); |
|
| 1032 | + if(!$hostInfo) { |
|
| 1033 | + throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1034 | + } |
|
| 1035 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', \OCP\Util::DEBUG); |
|
| 1036 | + $cr = $this->ldap->connect($host, $port); |
|
| 1037 | + if(!is_resource($cr)) { |
|
| 1038 | + throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + //set LDAP options |
|
| 1042 | + $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1043 | + $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1044 | + $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1045 | + |
|
| 1046 | + try { |
|
| 1047 | + if($tls) { |
|
| 1048 | + $isTlsWorking = @$this->ldap->startTls($cr); |
|
| 1049 | + if(!$isTlsWorking) { |
|
| 1050 | + return false; |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', \OCP\Util::DEBUG); |
|
| 1055 | + //interesting part: do the bind! |
|
| 1056 | + $login = $this->ldap->bind($cr, |
|
| 1057 | + $this->configuration->ldapAgentName, |
|
| 1058 | + $this->configuration->ldapAgentPassword |
|
| 1059 | + ); |
|
| 1060 | + $errNo = $this->ldap->errno($cr); |
|
| 1061 | + $error = ldap_error($cr); |
|
| 1062 | + $this->ldap->unbind($cr); |
|
| 1063 | + } catch(ServerNotAvailableException $e) { |
|
| 1064 | + return false; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + if($login === true) { |
|
| 1068 | + $this->ldap->unbind($cr); |
|
| 1069 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . intval($tls), \OCP\Util::DEBUG); |
|
| 1070 | + return true; |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + if($errNo === -1) { |
|
| 1074 | + //host, port or TLS wrong |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + throw new \Exception($error, $errNo); |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * checks whether a valid combination of agent and password has been |
|
| 1082 | + * provided (either two values or nothing for anonymous connect) |
|
| 1083 | + * @return bool, true if everything is fine, false otherwise |
|
| 1084 | + */ |
|
| 1085 | + private function checkAgentRequirements() { |
|
| 1086 | + $agent = $this->configuration->ldapAgentName; |
|
| 1087 | + $pwd = $this->configuration->ldapAgentPassword; |
|
| 1088 | + |
|
| 1089 | + return |
|
| 1090 | + ($agent !== '' && $pwd !== '') |
|
| 1091 | + || ($agent === '' && $pwd === '') |
|
| 1092 | + ; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * @param array $reqs |
|
| 1097 | + * @return bool |
|
| 1098 | + */ |
|
| 1099 | + private function checkRequirements($reqs) { |
|
| 1100 | + $this->checkAgentRequirements(); |
|
| 1101 | + foreach($reqs as $option) { |
|
| 1102 | + $value = $this->configuration->$option; |
|
| 1103 | + if(empty($value)) { |
|
| 1104 | + return false; |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + return true; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * does a cumulativeSearch on LDAP to get different values of a |
|
| 1112 | + * specified attribute |
|
| 1113 | + * @param string[] $filters array, the filters that shall be used in the search |
|
| 1114 | + * @param string $attr the attribute of which a list of values shall be returned |
|
| 1115 | + * @param int $dnReadLimit the amount of how many DNs should be analyzed. |
|
| 1116 | + * The lower, the faster |
|
| 1117 | + * @param string $maxF string. if not null, this variable will have the filter that |
|
| 1118 | + * yields most result entries |
|
| 1119 | + * @return array|false an array with the values on success, false otherwise |
|
| 1120 | + */ |
|
| 1121 | + public function cumulativeSearchOnAttribute($filters, $attr, $dnReadLimit = 3, &$maxF = null) { |
|
| 1122 | + $dnRead = array(); |
|
| 1123 | + $foundItems = array(); |
|
| 1124 | + $maxEntries = 0; |
|
| 1125 | + if(!is_array($this->configuration->ldapBase) |
|
| 1126 | + || !isset($this->configuration->ldapBase[0])) { |
|
| 1127 | + return false; |
|
| 1128 | + } |
|
| 1129 | + $base = $this->configuration->ldapBase[0]; |
|
| 1130 | + $cr = $this->getConnection(); |
|
| 1131 | + if(!$this->ldap->isResource($cr)) { |
|
| 1132 | + return false; |
|
| 1133 | + } |
|
| 1134 | + $lastFilter = null; |
|
| 1135 | + if(isset($filters[count($filters)-1])) { |
|
| 1136 | + $lastFilter = $filters[count($filters)-1]; |
|
| 1137 | + } |
|
| 1138 | + foreach($filters as $filter) { |
|
| 1139 | + if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1140 | + //skip when the filter is a wildcard and results were found |
|
| 1141 | + continue; |
|
| 1142 | + } |
|
| 1143 | + // 20k limit for performance and reason |
|
| 1144 | + $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
|
| 1145 | + if(!$this->ldap->isResource($rr)) { |
|
| 1146 | + continue; |
|
| 1147 | + } |
|
| 1148 | + $entries = $this->ldap->countEntries($cr, $rr); |
|
| 1149 | + $getEntryFunc = 'firstEntry'; |
|
| 1150 | + if(($entries !== false) && ($entries > 0)) { |
|
| 1151 | + if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1152 | + $maxEntries = $entries; |
|
| 1153 | + $maxF = $filter; |
|
| 1154 | + } |
|
| 1155 | + $dnReadCount = 0; |
|
| 1156 | + do { |
|
| 1157 | + $entry = $this->ldap->$getEntryFunc($cr, $rr); |
|
| 1158 | + $getEntryFunc = 'nextEntry'; |
|
| 1159 | + if(!$this->ldap->isResource($entry)) { |
|
| 1160 | + continue 2; |
|
| 1161 | + } |
|
| 1162 | + $rr = $entry; //will be expected by nextEntry next round |
|
| 1163 | + $attributes = $this->ldap->getAttributes($cr, $entry); |
|
| 1164 | + $dn = $this->ldap->getDN($cr, $entry); |
|
| 1165 | + if($dn === false || in_array($dn, $dnRead)) { |
|
| 1166 | + continue; |
|
| 1167 | + } |
|
| 1168 | + $newItems = array(); |
|
| 1169 | + $state = $this->getAttributeValuesFromEntry($attributes, |
|
| 1170 | + $attr, |
|
| 1171 | + $newItems); |
|
| 1172 | + $dnReadCount++; |
|
| 1173 | + $foundItems = array_merge($foundItems, $newItems); |
|
| 1174 | + $this->resultCache[$dn][$attr] = $newItems; |
|
| 1175 | + $dnRead[] = $dn; |
|
| 1176 | + } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1177 | + || $this->ldap->isResource($entry)) |
|
| 1178 | + && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
|
| 1179 | + } |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return array_unique($foundItems); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * determines if and which $attr are available on the LDAP server |
|
| 1187 | + * @param string[] $objectclasses the objectclasses to use as search filter |
|
| 1188 | + * @param string $attr the attribute to look for |
|
| 1189 | + * @param string $dbkey the dbkey of the setting the feature is connected to |
|
| 1190 | + * @param string $confkey the confkey counterpart for the $dbkey as used in the |
|
| 1191 | + * Configuration class |
|
| 1192 | + * @param bool $po whether the objectClass with most result entries |
|
| 1193 | + * shall be pre-selected via the result |
|
| 1194 | + * @return array|false list of found items. |
|
| 1195 | + * @throws \Exception |
|
| 1196 | + */ |
|
| 1197 | + private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
|
| 1198 | + $cr = $this->getConnection(); |
|
| 1199 | + if(!$cr) { |
|
| 1200 | + throw new \Exception('Could not connect to LDAP'); |
|
| 1201 | + } |
|
| 1202 | + $p = 'objectclass='; |
|
| 1203 | + foreach($objectclasses as $key => $value) { |
|
| 1204 | + $objectclasses[$key] = $p.$value; |
|
| 1205 | + } |
|
| 1206 | + $maxEntryObjC = ''; |
|
| 1207 | + |
|
| 1208 | + //how deep to dig? |
|
| 1209 | + //When looking for objectclasses, testing few entries is sufficient, |
|
| 1210 | + $dig = 3; |
|
| 1211 | + |
|
| 1212 | + $availableFeatures = |
|
| 1213 | + $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
|
| 1214 | + $dig, $maxEntryObjC); |
|
| 1215 | + if(is_array($availableFeatures) |
|
| 1216 | + && count($availableFeatures) > 0) { |
|
| 1217 | + natcasesort($availableFeatures); |
|
| 1218 | + //natcasesort keeps indices, but we must get rid of them for proper |
|
| 1219 | + //sorting in the web UI. Therefore: array_values |
|
| 1220 | + $this->result->addOptions($dbkey, array_values($availableFeatures)); |
|
| 1221 | + } else { |
|
| 1222 | + throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + $setFeatures = $this->configuration->$confkey; |
|
| 1226 | + if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1227 | + //something is already configured? pre-select it. |
|
| 1228 | + $this->result->addChange($dbkey, $setFeatures); |
|
| 1229 | + } else if ($po && $maxEntryObjC !== '') { |
|
| 1230 | + //pre-select objectclass with most result entries |
|
| 1231 | + $maxEntryObjC = str_replace($p, '', $maxEntryObjC); |
|
| 1232 | + $this->applyFind($dbkey, $maxEntryObjC); |
|
| 1233 | + $this->result->addChange($dbkey, $maxEntryObjC); |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + return $availableFeatures; |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * appends a list of values fr |
|
| 1241 | + * @param resource $result the return value from ldap_get_attributes |
|
| 1242 | + * @param string $attribute the attribute values to look for |
|
| 1243 | + * @param array &$known new values will be appended here |
|
| 1244 | + * @return int, state on of the class constants LRESULT_PROCESSED_OK, |
|
| 1245 | + * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
|
| 1246 | + */ |
|
| 1247 | + private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
|
| 1248 | + if(!is_array($result) |
|
| 1249 | + || !isset($result['count']) |
|
| 1250 | + || !$result['count'] > 0) { |
|
| 1251 | + return self::LRESULT_PROCESSED_INVALID; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // strtolower on all keys for proper comparison |
|
| 1255 | + $result = \OCP\Util::mb_array_change_key_case($result); |
|
| 1256 | + $attribute = strtolower($attribute); |
|
| 1257 | + if(isset($result[$attribute])) { |
|
| 1258 | + foreach($result[$attribute] as $key => $val) { |
|
| 1259 | + if($key === 'count') { |
|
| 1260 | + continue; |
|
| 1261 | + } |
|
| 1262 | + if(!in_array($val, $known)) { |
|
| 1263 | + $known[] = $val; |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + return self::LRESULT_PROCESSED_OK; |
|
| 1267 | + } else { |
|
| 1268 | + return self::LRESULT_PROCESSED_SKIP; |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * @return bool|mixed |
|
| 1274 | + */ |
|
| 1275 | + private function getConnection() { |
|
| 1276 | + if(!is_null($this->cr)) { |
|
| 1277 | + return $this->cr; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + $cr = $this->ldap->connect( |
|
| 1281 | + $this->configuration->ldapHost, |
|
| 1282 | + $this->configuration->ldapPort |
|
| 1283 | + ); |
|
| 1284 | + |
|
| 1285 | + $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1286 | + $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1287 | + $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1288 | + if($this->configuration->ldapTLS === 1) { |
|
| 1289 | + $this->ldap->startTls($cr); |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + $lo = @$this->ldap->bind($cr, |
|
| 1293 | + $this->configuration->ldapAgentName, |
|
| 1294 | + $this->configuration->ldapAgentPassword); |
|
| 1295 | + if($lo === true) { |
|
| 1296 | + $this->$cr = $cr; |
|
| 1297 | + return $cr; |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + return false; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * @return array |
|
| 1305 | + */ |
|
| 1306 | + private function getDefaultLdapPortSettings() { |
|
| 1307 | + static $settings = array( |
|
| 1308 | + array('port' => 7636, 'tls' => false), |
|
| 1309 | + array('port' => 636, 'tls' => false), |
|
| 1310 | + array('port' => 7389, 'tls' => true), |
|
| 1311 | + array('port' => 389, 'tls' => true), |
|
| 1312 | + array('port' => 7389, 'tls' => false), |
|
| 1313 | + array('port' => 389, 'tls' => false), |
|
| 1314 | + ); |
|
| 1315 | + return $settings; |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * @return array |
|
| 1320 | + */ |
|
| 1321 | + private function getPortSettingsToTry() { |
|
| 1322 | + //389 ← LDAP / Unencrypted or StartTLS |
|
| 1323 | + //636 ← LDAPS / SSL |
|
| 1324 | + //7xxx ← UCS. need to be checked first, because both ports may be open |
|
| 1325 | + $host = $this->configuration->ldapHost; |
|
| 1326 | + $port = intval($this->configuration->ldapPort); |
|
| 1327 | + $portSettings = array(); |
|
| 1328 | + |
|
| 1329 | + //In case the port is already provided, we will check this first |
|
| 1330 | + if($port > 0) { |
|
| 1331 | + $hostInfo = parse_url($host); |
|
| 1332 | + if(!(is_array($hostInfo) |
|
| 1333 | + && isset($hostInfo['scheme']) |
|
| 1334 | + && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
|
| 1335 | + $portSettings[] = array('port' => $port, 'tls' => true); |
|
| 1336 | + } |
|
| 1337 | + $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + //default ports |
|
| 1341 | + $portSettings = array_merge($portSettings, |
|
| 1342 | + $this->getDefaultLdapPortSettings()); |
|
| 1343 | + |
|
| 1344 | + return $portSettings; |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | 1347 | |
| 1348 | 1348 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
| 69 | 69 | parent::__construct($ldap); |
| 70 | 70 | $this->configuration = $configuration; |
| 71 | - if(is_null(Wizard::$l)) { |
|
| 71 | + if (is_null(Wizard::$l)) { |
|
| 72 | 72 | Wizard::$l = \OC::$server->getL10N('user_ldap'); |
| 73 | 73 | } |
| 74 | 74 | $this->access = $access; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | public function __destruct() { |
| 79 | - if($this->result->hasChanges()) { |
|
| 79 | + if ($this->result->hasChanges()) { |
|
| 80 | 80 | $this->configuration->saveConfiguration(); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -91,18 +91,18 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function countEntries($filter, $type) { |
| 93 | 93 | $reqs = array('ldapHost', 'ldapPort', 'ldapBase'); |
| 94 | - if($type === 'users') { |
|
| 94 | + if ($type === 'users') { |
|
| 95 | 95 | $reqs[] = 'ldapUserFilter'; |
| 96 | 96 | } |
| 97 | - if(!$this->checkRequirements($reqs)) { |
|
| 97 | + if (!$this->checkRequirements($reqs)) { |
|
| 98 | 98 | throw new \Exception('Requirements not met', 400); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $attr = array('dn'); // default |
| 102 | 102 | $limit = 1001; |
| 103 | - if($type === 'groups') { |
|
| 104 | - $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 105 | - } else if($type === 'users') { |
|
| 103 | + if ($type === 'groups') { |
|
| 104 | + $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 105 | + } else if ($type === 'users') { |
|
| 106 | 106 | $result = $this->access->countUsers($filter, $attr, $limit); |
| 107 | 107 | } else if ($type === 'objects') { |
| 108 | 108 | $result = $this->access->countObjects($limit); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | private function formatCountResult($count) { |
| 124 | 124 | $formatted = ($count !== false) ? $count : 0; |
| 125 | - if($formatted > 1000) { |
|
| 125 | + if ($formatted > 1000) { |
|
| 126 | 126 | $formatted = '> 1000'; |
| 127 | 127 | } |
| 128 | 128 | return $formatted; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | public function countGroups() { |
| 132 | 132 | $filter = $this->configuration->ldapGroupFilter; |
| 133 | 133 | |
| 134 | - if(empty($filter)) { |
|
| 134 | + if (empty($filter)) { |
|
| 135 | 135 | $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
| 136 | 136 | $this->result->addChange('ldap_group_count', $output); |
| 137 | 137 | return $this->result; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $groupsTotal = $this->formatCountResult($this->countEntries($filter, 'groups')); |
| 142 | 142 | } catch (\Exception $e) { |
| 143 | 143 | //400 can be ignored, 500 is forwarded |
| 144 | - if($e->getCode() === 500) { |
|
| 144 | + if ($e->getCode() === 500) { |
|
| 145 | 145 | throw $e; |
| 146 | 146 | } |
| 147 | 147 | return false; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | public function countInBaseDN() { |
| 174 | 174 | // we don't need to provide a filter in this case |
| 175 | 175 | $total = $this->countEntries(null, 'objects'); |
| 176 | - if($total === false) { |
|
| 176 | + if ($total === false) { |
|
| 177 | 177 | throw new \Exception('invalid results received'); |
| 178 | 178 | } |
| 179 | 179 | $this->result->addChange('ldap_test_base', $total); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @return int|bool |
| 188 | 188 | */ |
| 189 | 189 | public function countUsersWithAttribute($attr, $existsCheck = false) { |
| 190 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 190 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 191 | 191 | 'ldapPort', |
| 192 | 192 | 'ldapBase', |
| 193 | 193 | 'ldapUserFilter', |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | $filter = $this->access->combineFilterWithAnd(array( |
| 199 | 199 | $this->configuration->ldapUserFilter, |
| 200 | - $attr . '=*' |
|
| 200 | + $attr.'=*' |
|
| 201 | 201 | )); |
| 202 | 202 | |
| 203 | 203 | $limit = ($existsCheck === false) ? null : 1; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @throws \Exception |
| 213 | 213 | */ |
| 214 | 214 | public function detectUserDisplayNameAttribute() { |
| 215 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 215 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 216 | 216 | 'ldapPort', |
| 217 | 217 | 'ldapBase', |
| 218 | 218 | 'ldapUserFilter', |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | // most likely not the default value with upper case N, |
| 226 | 226 | // verify it still produces a result |
| 227 | 227 | $count = intval($this->countUsersWithAttribute($attr, true)); |
| 228 | - if($count > 0) { |
|
| 228 | + if ($count > 0) { |
|
| 229 | 229 | //no change, but we sent it back to make sure the user interface |
| 230 | 230 | //is still correct, even if the ajax call was cancelled meanwhile |
| 231 | 231 | $this->result->addChange('ldap_display_name', $attr); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | foreach ($displayNameAttrs as $attr) { |
| 239 | 239 | $count = intval($this->countUsersWithAttribute($attr, true)); |
| 240 | 240 | |
| 241 | - if($count > 0) { |
|
| 241 | + if ($count > 0) { |
|
| 242 | 242 | $this->applyFind('ldap_display_name', $attr); |
| 243 | 243 | return $this->result; |
| 244 | 244 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @return WizardResult|bool |
| 255 | 255 | */ |
| 256 | 256 | public function detectEmailAttribute() { |
| 257 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 257 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 258 | 258 | 'ldapPort', |
| 259 | 259 | 'ldapBase', |
| 260 | 260 | 'ldapUserFilter', |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $attr = $this->configuration->ldapEmailAttribute; |
| 266 | 266 | if ($attr !== '') { |
| 267 | 267 | $count = intval($this->countUsersWithAttribute($attr, true)); |
| 268 | - if($count > 0) { |
|
| 268 | + if ($count > 0) { |
|
| 269 | 269 | return false; |
| 270 | 270 | } |
| 271 | 271 | $writeLog = true; |
@@ -276,19 +276,19 @@ discard block |
||
| 276 | 276 | $emailAttributes = array('mail', 'mailPrimaryAddress'); |
| 277 | 277 | $winner = ''; |
| 278 | 278 | $maxUsers = 0; |
| 279 | - foreach($emailAttributes as $attr) { |
|
| 279 | + foreach ($emailAttributes as $attr) { |
|
| 280 | 280 | $count = $this->countUsersWithAttribute($attr); |
| 281 | - if($count > $maxUsers) { |
|
| 281 | + if ($count > $maxUsers) { |
|
| 282 | 282 | $maxUsers = $count; |
| 283 | 283 | $winner = $attr; |
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if($winner !== '') { |
|
| 287 | + if ($winner !== '') { |
|
| 288 | 288 | $this->applyFind('ldap_email_attr', $winner); |
| 289 | - if($writeLog) { |
|
| 290 | - \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 291 | - 'automatically been reset, because the original value ' . |
|
| 289 | + if ($writeLog) { |
|
| 290 | + \OCP\Util::writeLog('user_ldap', 'The mail attribute has '. |
|
| 291 | + 'automatically been reset, because the original value '. |
|
| 292 | 292 | 'did not return any results.', \OCP\Util::INFO); |
| 293 | 293 | } |
| 294 | 294 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @throws \Exception |
| 302 | 302 | */ |
| 303 | 303 | public function determineAttributes() { |
| 304 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 304 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 305 | 305 | 'ldapPort', |
| 306 | 306 | 'ldapBase', |
| 307 | 307 | 'ldapUserFilter', |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
| 318 | 318 | |
| 319 | 319 | $selected = $this->configuration->ldapLoginFilterAttributes; |
| 320 | - if(is_array($selected) && !empty($selected)) { |
|
| 320 | + if (is_array($selected) && !empty($selected)) { |
|
| 321 | 321 | $this->result->addChange('ldap_loginfilter_attributes', $selected); |
| 322 | 322 | } |
| 323 | 323 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @throws \Exception |
| 331 | 331 | */ |
| 332 | 332 | private function getUserAttributes() { |
| 333 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 333 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 334 | 334 | 'ldapPort', |
| 335 | 335 | 'ldapBase', |
| 336 | 336 | 'ldapUserFilter', |
@@ -338,20 +338,20 @@ discard block |
||
| 338 | 338 | return false; |
| 339 | 339 | } |
| 340 | 340 | $cr = $this->getConnection(); |
| 341 | - if(!$cr) { |
|
| 341 | + if (!$cr) { |
|
| 342 | 342 | throw new \Exception('Could not connect to LDAP'); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | $base = $this->configuration->ldapBase[0]; |
| 346 | 346 | $filter = $this->configuration->ldapUserFilter; |
| 347 | 347 | $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
| 348 | - if(!$this->ldap->isResource($rr)) { |
|
| 348 | + if (!$this->ldap->isResource($rr)) { |
|
| 349 | 349 | return false; |
| 350 | 350 | } |
| 351 | 351 | $er = $this->ldap->firstEntry($cr, $rr); |
| 352 | 352 | $attributes = $this->ldap->getAttributes($cr, $er); |
| 353 | 353 | $pureAttributes = array(); |
| 354 | - for($i = 0; $i < $attributes['count']; $i++) { |
|
| 354 | + for ($i = 0; $i < $attributes['count']; $i++) { |
|
| 355 | 355 | $pureAttributes[] = $attributes[$i]; |
| 356 | 356 | } |
| 357 | 357 | |
@@ -386,23 +386,23 @@ discard block |
||
| 386 | 386 | * @throws \Exception |
| 387 | 387 | */ |
| 388 | 388 | private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
| 389 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 389 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 390 | 390 | 'ldapPort', |
| 391 | 391 | 'ldapBase', |
| 392 | 392 | ))) { |
| 393 | 393 | return false; |
| 394 | 394 | } |
| 395 | 395 | $cr = $this->getConnection(); |
| 396 | - if(!$cr) { |
|
| 396 | + if (!$cr) { |
|
| 397 | 397 | throw new \Exception('Could not connect to LDAP'); |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | $this->fetchGroups($dbKey, $confKey); |
| 401 | 401 | |
| 402 | - if($testMemberOf) { |
|
| 402 | + if ($testMemberOf) { |
|
| 403 | 403 | $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
| 404 | 404 | $this->result->markChange(); |
| 405 | - if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 405 | + if (!$this->configuration->hasMemberOfFilterSupport) { |
|
| 406 | 406 | throw new \Exception('memberOf is not supported by the server'); |
| 407 | 407 | } |
| 408 | 408 | } |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
| 423 | 423 | |
| 424 | 424 | $filterParts = array(); |
| 425 | - foreach($obclasses as $obclass) { |
|
| 425 | + foreach ($obclasses as $obclass) { |
|
| 426 | 426 | $filterParts[] = 'objectclass='.$obclass; |
| 427 | 427 | } |
| 428 | 428 | //we filter for everything |
@@ -439,8 +439,8 @@ discard block |
||
| 439 | 439 | // we need to request dn additionally here, otherwise memberOf |
| 440 | 440 | // detection will fail later |
| 441 | 441 | $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
| 442 | - foreach($result as $item) { |
|
| 443 | - if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 442 | + foreach ($result as $item) { |
|
| 443 | + if (!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 444 | 444 | // just in case - no issue known |
| 445 | 445 | continue; |
| 446 | 446 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $offset += $limit; |
| 451 | 451 | } while ($this->access->hasMoreResults()); |
| 452 | 452 | |
| 453 | - if(count($groupNames) > 0) { |
|
| 453 | + if (count($groupNames) > 0) { |
|
| 454 | 454 | natsort($groupNames); |
| 455 | 455 | $this->result->addOptions($dbKey, array_values($groupNames)); |
| 456 | 456 | } else { |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | $setFeatures = $this->configuration->$confKey; |
| 461 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 461 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 462 | 462 | //something is already configured? pre-select it. |
| 463 | 463 | $this->result->addChange($dbKey, $setFeatures); |
| 464 | 464 | } |
@@ -466,14 +466,14 @@ discard block |
||
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | public function determineGroupMemberAssoc() { |
| 469 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 469 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 470 | 470 | 'ldapPort', |
| 471 | 471 | 'ldapGroupFilter', |
| 472 | 472 | ))) { |
| 473 | 473 | return false; |
| 474 | 474 | } |
| 475 | 475 | $attribute = $this->detectGroupMemberAssoc(); |
| 476 | - if($attribute === false) { |
|
| 476 | + if ($attribute === false) { |
|
| 477 | 477 | return false; |
| 478 | 478 | } |
| 479 | 479 | $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | * @throws \Exception |
| 489 | 489 | */ |
| 490 | 490 | public function determineGroupObjectClasses() { |
| 491 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 491 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 492 | 492 | 'ldapPort', |
| 493 | 493 | 'ldapBase', |
| 494 | 494 | ))) { |
| 495 | 495 | return false; |
| 496 | 496 | } |
| 497 | 497 | $cr = $this->getConnection(); |
| 498 | - if(!$cr) { |
|
| 498 | + if (!$cr) { |
|
| 499 | 499 | throw new \Exception('Could not connect to LDAP'); |
| 500 | 500 | } |
| 501 | 501 | |
@@ -515,14 +515,14 @@ discard block |
||
| 515 | 515 | * @throws \Exception |
| 516 | 516 | */ |
| 517 | 517 | public function determineUserObjectClasses() { |
| 518 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 518 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 519 | 519 | 'ldapPort', |
| 520 | 520 | 'ldapBase', |
| 521 | 521 | ))) { |
| 522 | 522 | return false; |
| 523 | 523 | } |
| 524 | 524 | $cr = $this->getConnection(); |
| 525 | - if(!$cr) { |
|
| 525 | + if (!$cr) { |
|
| 526 | 526 | throw new \Exception('Could not connect to LDAP'); |
| 527 | 527 | } |
| 528 | 528 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * @throws \Exception |
| 546 | 546 | */ |
| 547 | 547 | public function getGroupFilter() { |
| 548 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 548 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 549 | 549 | 'ldapPort', |
| 550 | 550 | 'ldapBase', |
| 551 | 551 | ))) { |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @throws \Exception |
| 570 | 570 | */ |
| 571 | 571 | public function getUserListFilter() { |
| 572 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 572 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 573 | 573 | 'ldapPort', |
| 574 | 574 | 'ldapBase', |
| 575 | 575 | ))) { |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
| 583 | 583 | } |
| 584 | 584 | $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
| 585 | - if(!$filter) { |
|
| 585 | + if (!$filter) { |
|
| 586 | 586 | throw new \Exception('Cannot create filter'); |
| 587 | 587 | } |
| 588 | 588 | |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @throws \Exception |
| 596 | 596 | */ |
| 597 | 597 | public function getUserLoginFilter() { |
| 598 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 598 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 599 | 599 | 'ldapPort', |
| 600 | 600 | 'ldapBase', |
| 601 | 601 | 'ldapUserFilter', |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
| 607 | - if(!$filter) { |
|
| 607 | + if (!$filter) { |
|
| 608 | 608 | throw new \Exception('Cannot create filter'); |
| 609 | 609 | } |
| 610 | 610 | |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | * @throws \Exception |
| 619 | 619 | */ |
| 620 | 620 | public function testLoginName($loginName) { |
| 621 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 621 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 622 | 622 | 'ldapPort', |
| 623 | 623 | 'ldapBase', |
| 624 | 624 | 'ldapLoginFilter', |
@@ -627,17 +627,17 @@ discard block |
||
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | $cr = $this->access->connection->getConnectionResource(); |
| 630 | - if(!$this->ldap->isResource($cr)) { |
|
| 630 | + if (!$this->ldap->isResource($cr)) { |
|
| 631 | 631 | throw new \Exception('connection error'); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 634 | + if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 635 | 635 | === false) { |
| 636 | 636 | throw new \Exception('missing placeholder'); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | $users = $this->access->countUsersByLoginName($loginName); |
| 640 | - if($this->ldap->errno($cr) !== 0) { |
|
| 640 | + if ($this->ldap->errno($cr) !== 0) { |
|
| 641 | 641 | throw new \Exception($this->ldap->error($cr)); |
| 642 | 642 | } |
| 643 | 643 | $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
@@ -652,22 +652,22 @@ discard block |
||
| 652 | 652 | * @throws \Exception |
| 653 | 653 | */ |
| 654 | 654 | public function guessPortAndTLS() { |
| 655 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 655 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 656 | 656 | ))) { |
| 657 | 657 | return false; |
| 658 | 658 | } |
| 659 | 659 | $this->checkHost(); |
| 660 | 660 | $portSettings = $this->getPortSettingsToTry(); |
| 661 | 661 | |
| 662 | - if(!is_array($portSettings)) { |
|
| 662 | + if (!is_array($portSettings)) { |
|
| 663 | 663 | throw new \Exception(print_r($portSettings, true)); |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | //proceed from the best configuration and return on first success |
| 667 | - foreach($portSettings as $setting) { |
|
| 667 | + foreach ($portSettings as $setting) { |
|
| 668 | 668 | $p = $setting['port']; |
| 669 | 669 | $t = $setting['tls']; |
| 670 | - \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, \OCP\Util::DEBUG); |
|
| 670 | + \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '.$p.', TLS '.$t, \OCP\Util::DEBUG); |
|
| 671 | 671 | //connectAndBind may throw Exception, it needs to be catched by the |
| 672 | 672 | //callee of this method |
| 673 | 673 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | // any reply other than -1 (= cannot connect) is already okay, |
| 678 | 678 | // because then we found the server |
| 679 | 679 | // unavailable startTLS returns -11 |
| 680 | - if($e->getCode() > 0) { |
|
| 680 | + if ($e->getCode() > 0) { |
|
| 681 | 681 | $settingsFound = true; |
| 682 | 682 | } else { |
| 683 | 683 | throw $e; |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | 'ldapTLS' => intval($t) |
| 691 | 691 | ); |
| 692 | 692 | $this->configuration->setConfiguration($config); |
| 693 | - \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG); |
|
| 693 | + \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port '.$p, \OCP\Util::DEBUG); |
|
| 694 | 694 | $this->result->addChange('ldap_port', $p); |
| 695 | 695 | return $this->result; |
| 696 | 696 | } |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @return WizardResult|false WizardResult on success, false otherwise |
| 706 | 706 | */ |
| 707 | 707 | public function guessBaseDN() { |
| 708 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 708 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 709 | 709 | 'ldapPort', |
| 710 | 710 | ))) { |
| 711 | 711 | return false; |
@@ -714,9 +714,9 @@ discard block |
||
| 714 | 714 | //check whether a DN is given in the agent name (99.9% of all cases) |
| 715 | 715 | $base = null; |
| 716 | 716 | $i = stripos($this->configuration->ldapAgentName, 'dc='); |
| 717 | - if($i !== false) { |
|
| 717 | + if ($i !== false) { |
|
| 718 | 718 | $base = substr($this->configuration->ldapAgentName, $i); |
| 719 | - if($this->testBaseDN($base)) { |
|
| 719 | + if ($this->testBaseDN($base)) { |
|
| 720 | 720 | $this->applyFind('ldap_base', $base); |
| 721 | 721 | return $this->result; |
| 722 | 722 | } |
@@ -727,13 +727,13 @@ discard block |
||
| 727 | 727 | //a base DN |
| 728 | 728 | $helper = new Helper(\OC::$server->getConfig()); |
| 729 | 729 | $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
| 730 | - if(!$domain) { |
|
| 730 | + if (!$domain) { |
|
| 731 | 731 | return false; |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | $dparts = explode('.', $domain); |
| 735 | - while(count($dparts) > 0) { |
|
| 736 | - $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 735 | + while (count($dparts) > 0) { |
|
| 736 | + $base2 = 'dc='.implode(',dc=', $dparts); |
|
| 737 | 737 | if ($base !== $base2 && $this->testBaseDN($base2)) { |
| 738 | 738 | $this->applyFind('ldap_base', $base2); |
| 739 | 739 | return $this->result; |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | $hostInfo = parse_url($host); |
| 767 | 767 | |
| 768 | 768 | //removes Port from Host |
| 769 | - if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 769 | + if (is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 770 | 770 | $port = $hostInfo['port']; |
| 771 | 771 | $host = str_replace(':'.$port, '', $host); |
| 772 | 772 | $this->applyFind('ldap_host', $host); |
@@ -783,30 +783,30 @@ discard block |
||
| 783 | 783 | private function detectGroupMemberAssoc() { |
| 784 | 784 | $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
| 785 | 785 | $filter = $this->configuration->ldapGroupFilter; |
| 786 | - if(empty($filter)) { |
|
| 786 | + if (empty($filter)) { |
|
| 787 | 787 | return false; |
| 788 | 788 | } |
| 789 | 789 | $cr = $this->getConnection(); |
| 790 | - if(!$cr) { |
|
| 790 | + if (!$cr) { |
|
| 791 | 791 | throw new \Exception('Could not connect to LDAP'); |
| 792 | 792 | } |
| 793 | 793 | $base = $this->configuration->ldapBase[0]; |
| 794 | 794 | $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
| 795 | - if(!$this->ldap->isResource($rr)) { |
|
| 795 | + if (!$this->ldap->isResource($rr)) { |
|
| 796 | 796 | return false; |
| 797 | 797 | } |
| 798 | 798 | $er = $this->ldap->firstEntry($cr, $rr); |
| 799 | - while(is_resource($er)) { |
|
| 799 | + while (is_resource($er)) { |
|
| 800 | 800 | $this->ldap->getDN($cr, $er); |
| 801 | 801 | $attrs = $this->ldap->getAttributes($cr, $er); |
| 802 | 802 | $result = array(); |
| 803 | 803 | $possibleAttrsCount = count($possibleAttrs); |
| 804 | - for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 805 | - if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 804 | + for ($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 805 | + if (isset($attrs[$possibleAttrs[$i]])) { |
|
| 806 | 806 | $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | - if(!empty($result)) { |
|
| 809 | + if (!empty($result)) { |
|
| 810 | 810 | natsort($result); |
| 811 | 811 | return key($result); |
| 812 | 812 | } |
@@ -825,14 +825,14 @@ discard block |
||
| 825 | 825 | */ |
| 826 | 826 | private function testBaseDN($base) { |
| 827 | 827 | $cr = $this->getConnection(); |
| 828 | - if(!$cr) { |
|
| 828 | + if (!$cr) { |
|
| 829 | 829 | throw new \Exception('Could not connect to LDAP'); |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | //base is there, let's validate it. If we search for anything, we should |
| 833 | 833 | //get a result set > 0 on a proper base |
| 834 | 834 | $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
| 835 | - if(!$this->ldap->isResource($rr)) { |
|
| 835 | + if (!$this->ldap->isResource($rr)) { |
|
| 836 | 836 | $errorNo = $this->ldap->errno($cr); |
| 837 | 837 | $errorMsg = $this->ldap->error($cr); |
| 838 | 838 | \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
@@ -854,11 +854,11 @@ discard block |
||
| 854 | 854 | */ |
| 855 | 855 | private function testMemberOf() { |
| 856 | 856 | $cr = $this->getConnection(); |
| 857 | - if(!$cr) { |
|
| 857 | + if (!$cr) { |
|
| 858 | 858 | throw new \Exception('Could not connect to LDAP'); |
| 859 | 859 | } |
| 860 | 860 | $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
| 861 | - if(is_int($result) && $result > 0) { |
|
| 861 | + if (is_int($result) && $result > 0) { |
|
| 862 | 862 | return true; |
| 863 | 863 | } |
| 864 | 864 | return false; |
@@ -879,27 +879,27 @@ discard block |
||
| 879 | 879 | case self::LFILTER_USER_LIST: |
| 880 | 880 | $objcs = $this->configuration->ldapUserFilterObjectclass; |
| 881 | 881 | //glue objectclasses |
| 882 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 882 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 883 | 883 | $filter .= '(|'; |
| 884 | - foreach($objcs as $objc) { |
|
| 885 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 884 | + foreach ($objcs as $objc) { |
|
| 885 | + $filter .= '(objectclass='.$objc.')'; |
|
| 886 | 886 | } |
| 887 | 887 | $filter .= ')'; |
| 888 | 888 | $parts++; |
| 889 | 889 | } |
| 890 | 890 | //glue group memberships |
| 891 | - if($this->configuration->hasMemberOfFilterSupport) { |
|
| 891 | + if ($this->configuration->hasMemberOfFilterSupport) { |
|
| 892 | 892 | $cns = $this->configuration->ldapUserFilterGroups; |
| 893 | - if(is_array($cns) && count($cns) > 0) { |
|
| 893 | + if (is_array($cns) && count($cns) > 0) { |
|
| 894 | 894 | $filter .= '(|'; |
| 895 | 895 | $cr = $this->getConnection(); |
| 896 | - if(!$cr) { |
|
| 896 | + if (!$cr) { |
|
| 897 | 897 | throw new \Exception('Could not connect to LDAP'); |
| 898 | 898 | } |
| 899 | 899 | $base = $this->configuration->ldapBase[0]; |
| 900 | - foreach($cns as $cn) { |
|
| 901 | - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 902 | - if(!$this->ldap->isResource($rr)) { |
|
| 900 | + foreach ($cns as $cn) { |
|
| 901 | + $rr = $this->ldap->search($cr, $base, 'cn='.$cn, array('dn', 'primaryGroupToken')); |
|
| 902 | + if (!$this->ldap->isResource($rr)) { |
|
| 903 | 903 | continue; |
| 904 | 904 | } |
| 905 | 905 | $er = $this->ldap->firstEntry($cr, $rr); |
@@ -908,11 +908,11 @@ discard block |
||
| 908 | 908 | if ($dn === false || $dn === '') { |
| 909 | 909 | continue; |
| 910 | 910 | } |
| 911 | - $filterPart = '(memberof=' . $dn . ')'; |
|
| 912 | - if(isset($attrs['primaryGroupToken'])) { |
|
| 911 | + $filterPart = '(memberof='.$dn.')'; |
|
| 912 | + if (isset($attrs['primaryGroupToken'])) { |
|
| 913 | 913 | $pgt = $attrs['primaryGroupToken'][0]; |
| 914 | - $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 915 | - $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 914 | + $primaryFilterPart = '(primaryGroupID='.$pgt.')'; |
|
| 915 | + $filterPart = '(|'.$filterPart.$primaryFilterPart.')'; |
|
| 916 | 916 | } |
| 917 | 917 | $filter .= $filterPart; |
| 918 | 918 | } |
@@ -921,8 +921,8 @@ discard block |
||
| 921 | 921 | $parts++; |
| 922 | 922 | } |
| 923 | 923 | //wrap parts in AND condition |
| 924 | - if($parts > 1) { |
|
| 925 | - $filter = '(&' . $filter . ')'; |
|
| 924 | + if ($parts > 1) { |
|
| 925 | + $filter = '(&'.$filter.')'; |
|
| 926 | 926 | } |
| 927 | 927 | if ($filter === '') { |
| 928 | 928 | $filter = '(objectclass=*)'; |
@@ -932,27 +932,27 @@ discard block |
||
| 932 | 932 | case self::LFILTER_GROUP_LIST: |
| 933 | 933 | $objcs = $this->configuration->ldapGroupFilterObjectclass; |
| 934 | 934 | //glue objectclasses |
| 935 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 935 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 936 | 936 | $filter .= '(|'; |
| 937 | - foreach($objcs as $objc) { |
|
| 938 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 937 | + foreach ($objcs as $objc) { |
|
| 938 | + $filter .= '(objectclass='.$objc.')'; |
|
| 939 | 939 | } |
| 940 | 940 | $filter .= ')'; |
| 941 | 941 | $parts++; |
| 942 | 942 | } |
| 943 | 943 | //glue group memberships |
| 944 | 944 | $cns = $this->configuration->ldapGroupFilterGroups; |
| 945 | - if(is_array($cns) && count($cns) > 0) { |
|
| 945 | + if (is_array($cns) && count($cns) > 0) { |
|
| 946 | 946 | $filter .= '(|'; |
| 947 | - foreach($cns as $cn) { |
|
| 948 | - $filter .= '(cn=' . $cn . ')'; |
|
| 947 | + foreach ($cns as $cn) { |
|
| 948 | + $filter .= '(cn='.$cn.')'; |
|
| 949 | 949 | } |
| 950 | 950 | $filter .= ')'; |
| 951 | 951 | } |
| 952 | 952 | $parts++; |
| 953 | 953 | //wrap parts in AND condition |
| 954 | - if($parts > 1) { |
|
| 955 | - $filter = '(&' . $filter . ')'; |
|
| 954 | + if ($parts > 1) { |
|
| 955 | + $filter = '(&'.$filter.')'; |
|
| 956 | 956 | } |
| 957 | 957 | break; |
| 958 | 958 | |
@@ -964,47 +964,47 @@ discard block |
||
| 964 | 964 | $userAttributes = array_change_key_case(array_flip($userAttributes)); |
| 965 | 965 | $parts = 0; |
| 966 | 966 | |
| 967 | - if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 967 | + if ($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 968 | 968 | $attr = ''; |
| 969 | - if(isset($userAttributes['uid'])) { |
|
| 969 | + if (isset($userAttributes['uid'])) { |
|
| 970 | 970 | $attr = 'uid'; |
| 971 | - } else if(isset($userAttributes['samaccountname'])) { |
|
| 971 | + } else if (isset($userAttributes['samaccountname'])) { |
|
| 972 | 972 | $attr = 'samaccountname'; |
| 973 | - } else if(isset($userAttributes['cn'])) { |
|
| 973 | + } else if (isset($userAttributes['cn'])) { |
|
| 974 | 974 | //fallback |
| 975 | 975 | $attr = 'cn'; |
| 976 | 976 | } |
| 977 | 977 | if ($attr !== '') { |
| 978 | - $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 978 | + $filterUsername = '('.$attr.$loginpart.')'; |
|
| 979 | 979 | $parts++; |
| 980 | 980 | } |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | $filterEmail = ''; |
| 984 | - if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 984 | + if ($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 985 | 985 | $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
| 986 | 986 | $parts++; |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | $filterAttributes = ''; |
| 990 | 990 | $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
| 991 | - if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 991 | + if (is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 992 | 992 | $filterAttributes = '(|'; |
| 993 | - foreach($attrsToFilter as $attribute) { |
|
| 994 | - $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 993 | + foreach ($attrsToFilter as $attribute) { |
|
| 994 | + $filterAttributes .= '('.$attribute.$loginpart.')'; |
|
| 995 | 995 | } |
| 996 | 996 | $filterAttributes .= ')'; |
| 997 | 997 | $parts++; |
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | $filterLogin = ''; |
| 1001 | - if($parts > 1) { |
|
| 1001 | + if ($parts > 1) { |
|
| 1002 | 1002 | $filterLogin = '(|'; |
| 1003 | 1003 | } |
| 1004 | 1004 | $filterLogin .= $filterUsername; |
| 1005 | 1005 | $filterLogin .= $filterEmail; |
| 1006 | 1006 | $filterLogin .= $filterAttributes; |
| 1007 | - if($parts > 1) { |
|
| 1007 | + if ($parts > 1) { |
|
| 1008 | 1008 | $filterLogin .= ')'; |
| 1009 | 1009 | } |
| 1010 | 1010 | |
@@ -1029,12 +1029,12 @@ discard block |
||
| 1029 | 1029 | //connect, does not really trigger any server communication |
| 1030 | 1030 | $host = $this->configuration->ldapHost; |
| 1031 | 1031 | $hostInfo = parse_url($host); |
| 1032 | - if(!$hostInfo) { |
|
| 1032 | + if (!$hostInfo) { |
|
| 1033 | 1033 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1034 | 1034 | } |
| 1035 | 1035 | \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', \OCP\Util::DEBUG); |
| 1036 | 1036 | $cr = $this->ldap->connect($host, $port); |
| 1037 | - if(!is_resource($cr)) { |
|
| 1037 | + if (!is_resource($cr)) { |
|
| 1038 | 1038 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1039 | 1039 | } |
| 1040 | 1040 | |
@@ -1044,9 +1044,9 @@ discard block |
||
| 1044 | 1044 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1045 | 1045 | |
| 1046 | 1046 | try { |
| 1047 | - if($tls) { |
|
| 1047 | + if ($tls) { |
|
| 1048 | 1048 | $isTlsWorking = @$this->ldap->startTls($cr); |
| 1049 | - if(!$isTlsWorking) { |
|
| 1049 | + if (!$isTlsWorking) { |
|
| 1050 | 1050 | return false; |
| 1051 | 1051 | } |
| 1052 | 1052 | } |
@@ -1060,17 +1060,17 @@ discard block |
||
| 1060 | 1060 | $errNo = $this->ldap->errno($cr); |
| 1061 | 1061 | $error = ldap_error($cr); |
| 1062 | 1062 | $this->ldap->unbind($cr); |
| 1063 | - } catch(ServerNotAvailableException $e) { |
|
| 1063 | + } catch (ServerNotAvailableException $e) { |
|
| 1064 | 1064 | return false; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - if($login === true) { |
|
| 1067 | + if ($login === true) { |
|
| 1068 | 1068 | $this->ldap->unbind($cr); |
| 1069 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . intval($tls), \OCP\Util::DEBUG); |
|
| 1069 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '.$port.' TLS '.intval($tls), \OCP\Util::DEBUG); |
|
| 1070 | 1070 | return true; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | - if($errNo === -1) { |
|
| 1073 | + if ($errNo === -1) { |
|
| 1074 | 1074 | //host, port or TLS wrong |
| 1075 | 1075 | return false; |
| 1076 | 1076 | } |
@@ -1098,9 +1098,9 @@ discard block |
||
| 1098 | 1098 | */ |
| 1099 | 1099 | private function checkRequirements($reqs) { |
| 1100 | 1100 | $this->checkAgentRequirements(); |
| 1101 | - foreach($reqs as $option) { |
|
| 1101 | + foreach ($reqs as $option) { |
|
| 1102 | 1102 | $value = $this->configuration->$option; |
| 1103 | - if(empty($value)) { |
|
| 1103 | + if (empty($value)) { |
|
| 1104 | 1104 | return false; |
| 1105 | 1105 | } |
| 1106 | 1106 | } |
@@ -1122,33 +1122,33 @@ discard block |
||
| 1122 | 1122 | $dnRead = array(); |
| 1123 | 1123 | $foundItems = array(); |
| 1124 | 1124 | $maxEntries = 0; |
| 1125 | - if(!is_array($this->configuration->ldapBase) |
|
| 1125 | + if (!is_array($this->configuration->ldapBase) |
|
| 1126 | 1126 | || !isset($this->configuration->ldapBase[0])) { |
| 1127 | 1127 | return false; |
| 1128 | 1128 | } |
| 1129 | 1129 | $base = $this->configuration->ldapBase[0]; |
| 1130 | 1130 | $cr = $this->getConnection(); |
| 1131 | - if(!$this->ldap->isResource($cr)) { |
|
| 1131 | + if (!$this->ldap->isResource($cr)) { |
|
| 1132 | 1132 | return false; |
| 1133 | 1133 | } |
| 1134 | 1134 | $lastFilter = null; |
| 1135 | - if(isset($filters[count($filters)-1])) { |
|
| 1136 | - $lastFilter = $filters[count($filters)-1]; |
|
| 1135 | + if (isset($filters[count($filters) - 1])) { |
|
| 1136 | + $lastFilter = $filters[count($filters) - 1]; |
|
| 1137 | 1137 | } |
| 1138 | - foreach($filters as $filter) { |
|
| 1139 | - if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1138 | + foreach ($filters as $filter) { |
|
| 1139 | + if ($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1140 | 1140 | //skip when the filter is a wildcard and results were found |
| 1141 | 1141 | continue; |
| 1142 | 1142 | } |
| 1143 | 1143 | // 20k limit for performance and reason |
| 1144 | 1144 | $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
| 1145 | - if(!$this->ldap->isResource($rr)) { |
|
| 1145 | + if (!$this->ldap->isResource($rr)) { |
|
| 1146 | 1146 | continue; |
| 1147 | 1147 | } |
| 1148 | 1148 | $entries = $this->ldap->countEntries($cr, $rr); |
| 1149 | 1149 | $getEntryFunc = 'firstEntry'; |
| 1150 | - if(($entries !== false) && ($entries > 0)) { |
|
| 1151 | - if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1150 | + if (($entries !== false) && ($entries > 0)) { |
|
| 1151 | + if (!is_null($maxF) && $entries > $maxEntries) { |
|
| 1152 | 1152 | $maxEntries = $entries; |
| 1153 | 1153 | $maxF = $filter; |
| 1154 | 1154 | } |
@@ -1156,13 +1156,13 @@ discard block |
||
| 1156 | 1156 | do { |
| 1157 | 1157 | $entry = $this->ldap->$getEntryFunc($cr, $rr); |
| 1158 | 1158 | $getEntryFunc = 'nextEntry'; |
| 1159 | - if(!$this->ldap->isResource($entry)) { |
|
| 1159 | + if (!$this->ldap->isResource($entry)) { |
|
| 1160 | 1160 | continue 2; |
| 1161 | 1161 | } |
| 1162 | 1162 | $rr = $entry; //will be expected by nextEntry next round |
| 1163 | 1163 | $attributes = $this->ldap->getAttributes($cr, $entry); |
| 1164 | 1164 | $dn = $this->ldap->getDN($cr, $entry); |
| 1165 | - if($dn === false || in_array($dn, $dnRead)) { |
|
| 1165 | + if ($dn === false || in_array($dn, $dnRead)) { |
|
| 1166 | 1166 | continue; |
| 1167 | 1167 | } |
| 1168 | 1168 | $newItems = array(); |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | $foundItems = array_merge($foundItems, $newItems); |
| 1174 | 1174 | $this->resultCache[$dn][$attr] = $newItems; |
| 1175 | 1175 | $dnRead[] = $dn; |
| 1176 | - } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1176 | + } while (($state === self::LRESULT_PROCESSED_SKIP |
|
| 1177 | 1177 | || $this->ldap->isResource($entry)) |
| 1178 | 1178 | && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
| 1179 | 1179 | } |
@@ -1196,11 +1196,11 @@ discard block |
||
| 1196 | 1196 | */ |
| 1197 | 1197 | private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
| 1198 | 1198 | $cr = $this->getConnection(); |
| 1199 | - if(!$cr) { |
|
| 1199 | + if (!$cr) { |
|
| 1200 | 1200 | throw new \Exception('Could not connect to LDAP'); |
| 1201 | 1201 | } |
| 1202 | 1202 | $p = 'objectclass='; |
| 1203 | - foreach($objectclasses as $key => $value) { |
|
| 1203 | + foreach ($objectclasses as $key => $value) { |
|
| 1204 | 1204 | $objectclasses[$key] = $p.$value; |
| 1205 | 1205 | } |
| 1206 | 1206 | $maxEntryObjC = ''; |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | $availableFeatures = |
| 1213 | 1213 | $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
| 1214 | 1214 | $dig, $maxEntryObjC); |
| 1215 | - if(is_array($availableFeatures) |
|
| 1215 | + if (is_array($availableFeatures) |
|
| 1216 | 1216 | && count($availableFeatures) > 0) { |
| 1217 | 1217 | natcasesort($availableFeatures); |
| 1218 | 1218 | //natcasesort keeps indices, but we must get rid of them for proper |
@@ -1223,7 +1223,7 @@ discard block |
||
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | 1225 | $setFeatures = $this->configuration->$confkey; |
| 1226 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1226 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1227 | 1227 | //something is already configured? pre-select it. |
| 1228 | 1228 | $this->result->addChange($dbkey, $setFeatures); |
| 1229 | 1229 | } else if ($po && $maxEntryObjC !== '') { |
@@ -1245,7 +1245,7 @@ discard block |
||
| 1245 | 1245 | * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
| 1246 | 1246 | */ |
| 1247 | 1247 | private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
| 1248 | - if(!is_array($result) |
|
| 1248 | + if (!is_array($result) |
|
| 1249 | 1249 | || !isset($result['count']) |
| 1250 | 1250 | || !$result['count'] > 0) { |
| 1251 | 1251 | return self::LRESULT_PROCESSED_INVALID; |
@@ -1254,12 +1254,12 @@ discard block |
||
| 1254 | 1254 | // strtolower on all keys for proper comparison |
| 1255 | 1255 | $result = \OCP\Util::mb_array_change_key_case($result); |
| 1256 | 1256 | $attribute = strtolower($attribute); |
| 1257 | - if(isset($result[$attribute])) { |
|
| 1258 | - foreach($result[$attribute] as $key => $val) { |
|
| 1259 | - if($key === 'count') { |
|
| 1257 | + if (isset($result[$attribute])) { |
|
| 1258 | + foreach ($result[$attribute] as $key => $val) { |
|
| 1259 | + if ($key === 'count') { |
|
| 1260 | 1260 | continue; |
| 1261 | 1261 | } |
| 1262 | - if(!in_array($val, $known)) { |
|
| 1262 | + if (!in_array($val, $known)) { |
|
| 1263 | 1263 | $known[] = $val; |
| 1264 | 1264 | } |
| 1265 | 1265 | } |
@@ -1273,7 +1273,7 @@ discard block |
||
| 1273 | 1273 | * @return bool|mixed |
| 1274 | 1274 | */ |
| 1275 | 1275 | private function getConnection() { |
| 1276 | - if(!is_null($this->cr)) { |
|
| 1276 | + if (!is_null($this->cr)) { |
|
| 1277 | 1277 | return $this->cr; |
| 1278 | 1278 | } |
| 1279 | 1279 | |
@@ -1285,14 +1285,14 @@ discard block |
||
| 1285 | 1285 | $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
| 1286 | 1286 | $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
| 1287 | 1287 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1288 | - if($this->configuration->ldapTLS === 1) { |
|
| 1288 | + if ($this->configuration->ldapTLS === 1) { |
|
| 1289 | 1289 | $this->ldap->startTls($cr); |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | $lo = @$this->ldap->bind($cr, |
| 1293 | 1293 | $this->configuration->ldapAgentName, |
| 1294 | 1294 | $this->configuration->ldapAgentPassword); |
| 1295 | - if($lo === true) { |
|
| 1295 | + if ($lo === true) { |
|
| 1296 | 1296 | $this->$cr = $cr; |
| 1297 | 1297 | return $cr; |
| 1298 | 1298 | } |
@@ -1327,14 +1327,14 @@ discard block |
||
| 1327 | 1327 | $portSettings = array(); |
| 1328 | 1328 | |
| 1329 | 1329 | //In case the port is already provided, we will check this first |
| 1330 | - if($port > 0) { |
|
| 1330 | + if ($port > 0) { |
|
| 1331 | 1331 | $hostInfo = parse_url($host); |
| 1332 | - if(!(is_array($hostInfo) |
|
| 1332 | + if (!(is_array($hostInfo) |
|
| 1333 | 1333 | && isset($hostInfo['scheme']) |
| 1334 | 1334 | && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
| 1335 | 1335 | $portSettings[] = array('port' => $port, 'tls' => true); |
| 1336 | 1336 | } |
| 1337 | - $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1337 | + $portSettings[] = array('port' => $port, 'tls' => false); |
|
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | 1340 | //default ports |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param string $newPath |
| 112 | 112 | * @param \OCP\Share\IShare $share |
| 113 | - * @return bool |
|
| 113 | + * @return boolean|null |
|
| 114 | 114 | */ |
| 115 | 115 | private function updateFileTarget($newPath, &$share) { |
| 116 | 116 | $share->setTarget($newPath); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param string $path |
| 127 | 127 | * @param View $view |
| 128 | 128 | * @param SharedMount[] $mountpoints |
| 129 | - * @return mixed |
|
| 129 | + * @return string |
|
| 130 | 130 | */ |
| 131 | 131 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 132 | 132 | $pathinfo = pathinfo($path); |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
| 67 | 67 | $this->user = $arguments['user']; |
| 68 | - $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 68 | + $this->recipientView = new View('/'.$this->user.'/files'); |
|
| 69 | 69 | |
| 70 | 70 | $this->superShare = $arguments['superShare']; |
| 71 | 71 | $this->groupedShares = $arguments['groupedShares']; |
| 72 | 72 | |
| 73 | 73 | $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
| 74 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 75 | - $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 74 | + $absMountPoint = '/'.$this->user.'/files'.$newMountPoint; |
|
| 75 | + $arguments['ownerView'] = new View('/'.$this->superShare->getShareOwner().'/files'); |
|
| 76 | 76 | parent::__construct($storage, $absMountPoint, $arguments, $loader); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $newMountPoint = $this->generateUniqueTarget( |
| 96 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 96 | + \OC\Files\Filesystem::normalizePath($parent.'/'.$mountPoint), |
|
| 97 | 97 | $this->recipientView, |
| 98 | 98 | $mountpoints |
| 99 | 99 | ); |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 132 | 132 | $pathinfo = pathinfo($path); |
| 133 | - $ext = (isset($pathinfo['extension'])) ? '.' . $pathinfo['extension'] : ''; |
|
| 133 | + $ext = (isset($pathinfo['extension'])) ? '.'.$pathinfo['extension'] : ''; |
|
| 134 | 134 | $name = $pathinfo['filename']; |
| 135 | 135 | $dir = $pathinfo['dirname']; |
| 136 | 136 | |
| 137 | 137 | // Helper function to find existing mount points |
| 138 | - $mountpointExists = function ($path) use ($mountpoints) { |
|
| 138 | + $mountpointExists = function($path) use ($mountpoints) { |
|
| 139 | 139 | foreach ($mountpoints as $mountpoint) { |
| 140 | 140 | if ($mountpoint->getShare()->getTarget() === $path) { |
| 141 | 141 | return true; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | $i = 2; |
| 148 | 148 | while ($view->file_exists($path) || $mountpointExists($path)) { |
| 149 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 149 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
| 150 | 150 | $i++; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | // it is not a file relative to data/user/files |
| 168 | 168 | if (count($split) < 3 || $split[1] !== 'files') { |
| 169 | 169 | \OCP\Util::writeLog('file sharing', |
| 170 | - 'Can not strip userid and "files/" from path: ' . $path, |
|
| 170 | + 'Can not strip userid and "files/" from path: '.$path, |
|
| 171 | 171 | \OCP\Util::ERROR); |
| 172 | 172 | throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
| 173 | 173 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $sliced = array_slice($split, 2); |
| 177 | 177 | $relPath = implode('/', $sliced); |
| 178 | 178 | |
| 179 | - return '/' . $relPath; |
|
| 179 | + return '/'.$relPath; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $this->storage->setMountPoint($relTargetPath); |
| 199 | 199 | } catch (\Exception $e) { |
| 200 | 200 | \OCP\Util::writeLog('file sharing', |
| 201 | - 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"', |
|
| 201 | + 'Could not rename mount point for shared folder "'.$this->getMountPoint().'" to "'.$target.'"', |
|
| 202 | 202 | \OCP\Util::ERROR); |
| 203 | 203 | } |
| 204 | 204 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $row = $result->fetch(); |
| 254 | 254 | $result->closeCursor(); |
| 255 | 255 | if ($row) { |
| 256 | - return (int)$row['storage']; |
|
| 256 | + return (int) $row['storage']; |
|
| 257 | 257 | } |
| 258 | 258 | return -1; |
| 259 | 259 | } |
@@ -36,230 +36,230 @@ |
||
| 36 | 36 | * Shared mount points can be moved by the user |
| 37 | 37 | */ |
| 38 | 38 | class SharedMount extends MountPoint implements MoveableMount { |
| 39 | - /** |
|
| 40 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 41 | - */ |
|
| 42 | - protected $storage = null; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var \OC\Files\View |
|
| 46 | - */ |
|
| 47 | - private $recipientView; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - private $user; |
|
| 53 | - |
|
| 54 | - /** @var \OCP\Share\IShare */ |
|
| 55 | - private $superShare; |
|
| 56 | - |
|
| 57 | - /** @var \OCP\Share\IShare[] */ |
|
| 58 | - private $groupedShares; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string $storage |
|
| 62 | - * @param SharedMount[] $mountpoints |
|
| 63 | - * @param array|null $arguments |
|
| 64 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 65 | - */ |
|
| 66 | - public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
|
| 67 | - $this->user = $arguments['user']; |
|
| 68 | - $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 69 | - |
|
| 70 | - $this->superShare = $arguments['superShare']; |
|
| 71 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 72 | - |
|
| 73 | - $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
|
| 74 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 75 | - $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 76 | - parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * check if the parent folder exists otherwise move the mount point up |
|
| 81 | - * |
|
| 82 | - * @param \OCP\Share\IShare $share |
|
| 83 | - * @param SharedMount[] $mountpoints |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) { |
|
| 87 | - |
|
| 88 | - $mountPoint = basename($share->getTarget()); |
|
| 89 | - $parent = dirname($share->getTarget()); |
|
| 90 | - |
|
| 91 | - if (!$this->recipientView->is_dir($parent)) { |
|
| 92 | - $parent = Helper::getShareFolder($this->recipientView); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $newMountPoint = $this->generateUniqueTarget( |
|
| 96 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 97 | - $this->recipientView, |
|
| 98 | - $mountpoints |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - if ($newMountPoint !== $share->getTarget()) { |
|
| 102 | - $this->updateFileTarget($newMountPoint, $share); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $newMountPoint; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * update fileTarget in the database if the mount point changed |
|
| 110 | - * |
|
| 111 | - * @param string $newPath |
|
| 112 | - * @param \OCP\Share\IShare $share |
|
| 113 | - * @return bool |
|
| 114 | - */ |
|
| 115 | - private function updateFileTarget($newPath, &$share) { |
|
| 116 | - $share->setTarget($newPath); |
|
| 117 | - |
|
| 118 | - foreach ($this->groupedShares as $tmpShare) { |
|
| 119 | - $tmpShare->setTarget($newPath); |
|
| 120 | - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $path |
|
| 127 | - * @param View $view |
|
| 128 | - * @param SharedMount[] $mountpoints |
|
| 129 | - * @return mixed |
|
| 130 | - */ |
|
| 131 | - private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 132 | - $pathinfo = pathinfo($path); |
|
| 133 | - $ext = (isset($pathinfo['extension'])) ? '.' . $pathinfo['extension'] : ''; |
|
| 134 | - $name = $pathinfo['filename']; |
|
| 135 | - $dir = $pathinfo['dirname']; |
|
| 136 | - |
|
| 137 | - // Helper function to find existing mount points |
|
| 138 | - $mountpointExists = function ($path) use ($mountpoints) { |
|
| 139 | - foreach ($mountpoints as $mountpoint) { |
|
| 140 | - if ($mountpoint->getShare()->getTarget() === $path) { |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - return false; |
|
| 145 | - }; |
|
| 146 | - |
|
| 147 | - $i = 2; |
|
| 148 | - while ($view->file_exists($path) || $mountpointExists($path)) { |
|
| 149 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 150 | - $i++; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $path; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Format a path to be relative to the /user/files/ directory |
|
| 158 | - * |
|
| 159 | - * @param string $path the absolute path |
|
| 160 | - * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 161 | - * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 162 | - */ |
|
| 163 | - protected function stripUserFilesPath($path) { |
|
| 164 | - $trimmed = ltrim($path, '/'); |
|
| 165 | - $split = explode('/', $trimmed); |
|
| 166 | - |
|
| 167 | - // it is not a file relative to data/user/files |
|
| 168 | - if (count($split) < 3 || $split[1] !== 'files') { |
|
| 169 | - \OCP\Util::writeLog('file sharing', |
|
| 170 | - 'Can not strip userid and "files/" from path: ' . $path, |
|
| 171 | - \OCP\Util::ERROR); |
|
| 172 | - throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // skip 'user' and 'files' |
|
| 176 | - $sliced = array_slice($split, 2); |
|
| 177 | - $relPath = implode('/', $sliced); |
|
| 178 | - |
|
| 179 | - return '/' . $relPath; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Move the mount point to $target |
|
| 184 | - * |
|
| 185 | - * @param string $target the target mount point |
|
| 186 | - * @return bool |
|
| 187 | - */ |
|
| 188 | - public function moveMount($target) { |
|
| 189 | - |
|
| 190 | - $relTargetPath = $this->stripUserFilesPath($target); |
|
| 191 | - $share = $this->storage->getShare(); |
|
| 192 | - |
|
| 193 | - $result = true; |
|
| 194 | - |
|
| 195 | - try { |
|
| 196 | - $this->updateFileTarget($relTargetPath, $share); |
|
| 197 | - $this->setMountPoint($target); |
|
| 198 | - $this->storage->setMountPoint($relTargetPath); |
|
| 199 | - } catch (\Exception $e) { |
|
| 200 | - \OCP\Util::writeLog('file sharing', |
|
| 201 | - 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"', |
|
| 202 | - \OCP\Util::ERROR); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $result; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Remove the mount points |
|
| 210 | - * |
|
| 211 | - * @return bool |
|
| 212 | - */ |
|
| 213 | - public function removeMount() { |
|
| 214 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 215 | - /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
| 216 | - $storage = $this->getStorage(); |
|
| 217 | - $result = $storage->unshareStorage(); |
|
| 218 | - $mountManager->removeMount($this->mountPoint); |
|
| 219 | - |
|
| 220 | - return $result; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return \OCP\Share\IShare |
|
| 225 | - */ |
|
| 226 | - public function getShare() { |
|
| 227 | - return $this->superShare; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Get the file id of the root of the storage |
|
| 232 | - * |
|
| 233 | - * @return int |
|
| 234 | - */ |
|
| 235 | - public function getStorageRootId() { |
|
| 236 | - return $this->getShare()->getNodeId(); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @return int |
|
| 241 | - */ |
|
| 242 | - public function getNumericStorageId() { |
|
| 243 | - if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 244 | - return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 245 | - } else { |
|
| 246 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 247 | - |
|
| 248 | - $query = $builder->select('storage') |
|
| 249 | - ->from('filecache') |
|
| 250 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 251 | - |
|
| 252 | - $result = $query->execute(); |
|
| 253 | - $row = $result->fetch(); |
|
| 254 | - $result->closeCursor(); |
|
| 255 | - if ($row) { |
|
| 256 | - return (int)$row['storage']; |
|
| 257 | - } |
|
| 258 | - return -1; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function getMountType() { |
|
| 263 | - return 'shared'; |
|
| 264 | - } |
|
| 39 | + /** |
|
| 40 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 41 | + */ |
|
| 42 | + protected $storage = null; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var \OC\Files\View |
|
| 46 | + */ |
|
| 47 | + private $recipientView; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + private $user; |
|
| 53 | + |
|
| 54 | + /** @var \OCP\Share\IShare */ |
|
| 55 | + private $superShare; |
|
| 56 | + |
|
| 57 | + /** @var \OCP\Share\IShare[] */ |
|
| 58 | + private $groupedShares; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string $storage |
|
| 62 | + * @param SharedMount[] $mountpoints |
|
| 63 | + * @param array|null $arguments |
|
| 64 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 65 | + */ |
|
| 66 | + public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
|
| 67 | + $this->user = $arguments['user']; |
|
| 68 | + $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 69 | + |
|
| 70 | + $this->superShare = $arguments['superShare']; |
|
| 71 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 72 | + |
|
| 73 | + $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
|
| 74 | + $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 75 | + $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 76 | + parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * check if the parent folder exists otherwise move the mount point up |
|
| 81 | + * |
|
| 82 | + * @param \OCP\Share\IShare $share |
|
| 83 | + * @param SharedMount[] $mountpoints |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) { |
|
| 87 | + |
|
| 88 | + $mountPoint = basename($share->getTarget()); |
|
| 89 | + $parent = dirname($share->getTarget()); |
|
| 90 | + |
|
| 91 | + if (!$this->recipientView->is_dir($parent)) { |
|
| 92 | + $parent = Helper::getShareFolder($this->recipientView); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $newMountPoint = $this->generateUniqueTarget( |
|
| 96 | + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 97 | + $this->recipientView, |
|
| 98 | + $mountpoints |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + if ($newMountPoint !== $share->getTarget()) { |
|
| 102 | + $this->updateFileTarget($newMountPoint, $share); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $newMountPoint; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * update fileTarget in the database if the mount point changed |
|
| 110 | + * |
|
| 111 | + * @param string $newPath |
|
| 112 | + * @param \OCP\Share\IShare $share |
|
| 113 | + * @return bool |
|
| 114 | + */ |
|
| 115 | + private function updateFileTarget($newPath, &$share) { |
|
| 116 | + $share->setTarget($newPath); |
|
| 117 | + |
|
| 118 | + foreach ($this->groupedShares as $tmpShare) { |
|
| 119 | + $tmpShare->setTarget($newPath); |
|
| 120 | + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $path |
|
| 127 | + * @param View $view |
|
| 128 | + * @param SharedMount[] $mountpoints |
|
| 129 | + * @return mixed |
|
| 130 | + */ |
|
| 131 | + private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 132 | + $pathinfo = pathinfo($path); |
|
| 133 | + $ext = (isset($pathinfo['extension'])) ? '.' . $pathinfo['extension'] : ''; |
|
| 134 | + $name = $pathinfo['filename']; |
|
| 135 | + $dir = $pathinfo['dirname']; |
|
| 136 | + |
|
| 137 | + // Helper function to find existing mount points |
|
| 138 | + $mountpointExists = function ($path) use ($mountpoints) { |
|
| 139 | + foreach ($mountpoints as $mountpoint) { |
|
| 140 | + if ($mountpoint->getShare()->getTarget() === $path) { |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + return false; |
|
| 145 | + }; |
|
| 146 | + |
|
| 147 | + $i = 2; |
|
| 148 | + while ($view->file_exists($path) || $mountpointExists($path)) { |
|
| 149 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 150 | + $i++; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $path; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Format a path to be relative to the /user/files/ directory |
|
| 158 | + * |
|
| 159 | + * @param string $path the absolute path |
|
| 160 | + * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 161 | + * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 162 | + */ |
|
| 163 | + protected function stripUserFilesPath($path) { |
|
| 164 | + $trimmed = ltrim($path, '/'); |
|
| 165 | + $split = explode('/', $trimmed); |
|
| 166 | + |
|
| 167 | + // it is not a file relative to data/user/files |
|
| 168 | + if (count($split) < 3 || $split[1] !== 'files') { |
|
| 169 | + \OCP\Util::writeLog('file sharing', |
|
| 170 | + 'Can not strip userid and "files/" from path: ' . $path, |
|
| 171 | + \OCP\Util::ERROR); |
|
| 172 | + throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // skip 'user' and 'files' |
|
| 176 | + $sliced = array_slice($split, 2); |
|
| 177 | + $relPath = implode('/', $sliced); |
|
| 178 | + |
|
| 179 | + return '/' . $relPath; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Move the mount point to $target |
|
| 184 | + * |
|
| 185 | + * @param string $target the target mount point |
|
| 186 | + * @return bool |
|
| 187 | + */ |
|
| 188 | + public function moveMount($target) { |
|
| 189 | + |
|
| 190 | + $relTargetPath = $this->stripUserFilesPath($target); |
|
| 191 | + $share = $this->storage->getShare(); |
|
| 192 | + |
|
| 193 | + $result = true; |
|
| 194 | + |
|
| 195 | + try { |
|
| 196 | + $this->updateFileTarget($relTargetPath, $share); |
|
| 197 | + $this->setMountPoint($target); |
|
| 198 | + $this->storage->setMountPoint($relTargetPath); |
|
| 199 | + } catch (\Exception $e) { |
|
| 200 | + \OCP\Util::writeLog('file sharing', |
|
| 201 | + 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"', |
|
| 202 | + \OCP\Util::ERROR); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $result; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Remove the mount points |
|
| 210 | + * |
|
| 211 | + * @return bool |
|
| 212 | + */ |
|
| 213 | + public function removeMount() { |
|
| 214 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 215 | + /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
| 216 | + $storage = $this->getStorage(); |
|
| 217 | + $result = $storage->unshareStorage(); |
|
| 218 | + $mountManager->removeMount($this->mountPoint); |
|
| 219 | + |
|
| 220 | + return $result; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return \OCP\Share\IShare |
|
| 225 | + */ |
|
| 226 | + public function getShare() { |
|
| 227 | + return $this->superShare; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Get the file id of the root of the storage |
|
| 232 | + * |
|
| 233 | + * @return int |
|
| 234 | + */ |
|
| 235 | + public function getStorageRootId() { |
|
| 236 | + return $this->getShare()->getNodeId(); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @return int |
|
| 241 | + */ |
|
| 242 | + public function getNumericStorageId() { |
|
| 243 | + if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 244 | + return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 245 | + } else { |
|
| 246 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 247 | + |
|
| 248 | + $query = $builder->select('storage') |
|
| 249 | + ->from('filecache') |
|
| 250 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 251 | + |
|
| 252 | + $result = $query->execute(); |
|
| 253 | + $row = $result->fetch(); |
|
| 254 | + $result->closeCursor(); |
|
| 255 | + if ($row) { |
|
| 256 | + return (int)$row['storage']; |
|
| 257 | + } |
|
| 258 | + return -1; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function getMountType() { |
|
| 263 | + return 'shared'; |
|
| 264 | + } |
|
| 265 | 265 | } |
@@ -334,7 +334,7 @@ |
||
| 334 | 334 | * |
| 335 | 335 | * @param int $size file size in bytes |
| 336 | 336 | * @param array $files override '.htaccess' and '.user.ini' locations |
| 337 | - * @return bool false on failure, size on success |
|
| 337 | + * @return integer false on failure, size on success |
|
| 338 | 338 | */ |
| 339 | 339 | public static function setUploadLimit($size, $files = []) { |
| 340 | 340 | //don't allow user to break his config |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if (!is_array($files)) { |
| 118 | - $filename = $dir . '/' . $files; |
|
| 118 | + $filename = $dir.'/'.$files; |
|
| 119 | 119 | if (!$view->is_dir($filename)) { |
| 120 | 120 | self::getSingleFile($view, $dir, $files, is_null($params) ? array() : $params); |
| 121 | 121 | return; |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | $name = $basename; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $filename = $dir . '/' . $name; |
|
| 133 | + $filename = $dir.'/'.$name; |
|
| 134 | 134 | } else { |
| 135 | - $filename = $dir . '/' . $files; |
|
| 135 | + $filename = $dir.'/'.$files; |
|
| 136 | 136 | $getType = self::ZIP_DIR; |
| 137 | 137 | // downloading root ? |
| 138 | 138 | if ($files !== '') { |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | ignore_user_abort(true); |
| 152 | 152 | if ($getType === self::ZIP_FILES) { |
| 153 | 153 | foreach ($files as $file) { |
| 154 | - $file = $dir . '/' . $file; |
|
| 154 | + $file = $dir.'/'.$file; |
|
| 155 | 155 | if (\OC\Files\Filesystem::is_file($file)) { |
| 156 | 156 | $fileSize = \OC\Files\Filesystem::filesize($file); |
| 157 | 157 | $fileTime = \OC\Files\Filesystem::filemtime($file); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } elseif ($getType === self::ZIP_DIR) { |
| 166 | - $file = $dir . '/' . $files; |
|
| 166 | + $file = $dir.'/'.$files; |
|
| 167 | 167 | $streamer->addDirRecursive($file); |
| 168 | 168 | } |
| 169 | 169 | $streamer->finalize(); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @return array $rangeArray ('from'=>int,'to'=>int), ... |
| 196 | 196 | */ |
| 197 | 197 | private static function parseHttpRangeHeader($rangeHeaderPos, $fileSize) { |
| 198 | - $rArray=explode(',', $rangeHeaderPos); |
|
| 198 | + $rArray = explode(',', $rangeHeaderPos); |
|
| 199 | 199 | $minOffset = 0; |
| 200 | 200 | $ind = 0; |
| 201 | 201 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | if ($ranges[0] < $minOffset) { // case: bytes=500-700,601-999 |
| 208 | 208 | $ranges[0] = $minOffset; |
| 209 | 209 | } |
| 210 | - if ($ind > 0 && $rangeArray[$ind-1]['to']+1 == $ranges[0]) { // case: bytes=500-600,601-999 |
|
| 210 | + if ($ind > 0 && $rangeArray[$ind - 1]['to'] + 1 == $ranges[0]) { // case: bytes=500-600,601-999 |
|
| 211 | 211 | $ind--; |
| 212 | 212 | $ranges[0] = $rangeArray[$ind]['from']; |
| 213 | 213 | } |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | if (is_numeric($ranges[0]) && is_numeric($ranges[1]) && $ranges[0] < $fileSize && $ranges[0] <= $ranges[1]) { |
| 217 | 217 | // case: x-x |
| 218 | 218 | if ($ranges[1] >= $fileSize) { |
| 219 | - $ranges[1] = $fileSize-1; |
|
| 219 | + $ranges[1] = $fileSize - 1; |
|
| 220 | 220 | } |
| 221 | - $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $ranges[1], 'size' => $fileSize ); |
|
| 221 | + $rangeArray[$ind++] = array('from' => $ranges[0], 'to' => $ranges[1], 'size' => $fileSize); |
|
| 222 | 222 | $minOffset = $ranges[1] + 1; |
| 223 | 223 | if ($minOffset >= $fileSize) { |
| 224 | 224 | break; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | elseif (is_numeric($ranges[0]) && $ranges[0] < $fileSize) { |
| 228 | 228 | // case: x- |
| 229 | - $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 229 | + $rangeArray[$ind++] = array('from' => $ranges[0], 'to' => $fileSize - 1, 'size' => $fileSize); |
|
| 230 | 230 | break; |
| 231 | 231 | } |
| 232 | 232 | elseif (is_numeric($ranges[1])) { |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | if ($ranges[1] > $fileSize) { |
| 235 | 235 | $ranges[1] = $fileSize; |
| 236 | 236 | } |
| 237 | - $rangeArray[$ind++] = array( 'from' => $fileSize-$ranges[1], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 237 | + $rangeArray[$ind++] = array('from' => $fileSize - $ranges[1], 'to' => $fileSize - 1, 'size' => $fileSize); |
|
| 238 | 238 | break; |
| 239 | 239 | } |
| 240 | 240 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header |
| 249 | 249 | */ |
| 250 | 250 | private static function getSingleFile($view, $dir, $name, $params) { |
| 251 | - $filename = $dir . '/' . $name; |
|
| 251 | + $filename = $dir.'/'.$name; |
|
| 252 | 252 | OC_Util::obEnd(); |
| 253 | 253 | $view->lockFile($filename, ILockingProvider::LOCK_SHARED); |
| 254 | 254 | |
@@ -314,17 +314,17 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public static function lockFiles($view, $dir, $files) { |
| 316 | 316 | if (!is_array($files)) { |
| 317 | - $file = $dir . '/' . $files; |
|
| 317 | + $file = $dir.'/'.$files; |
|
| 318 | 318 | $files = [$file]; |
| 319 | 319 | } |
| 320 | 320 | foreach ($files as $file) { |
| 321 | - $file = $dir . '/' . $file; |
|
| 321 | + $file = $dir.'/'.$file; |
|
| 322 | 322 | $view->lockFile($file, ILockingProvider::LOCK_SHARED); |
| 323 | 323 | if ($view->is_dir($file)) { |
| 324 | 324 | $contents = $view->getDirectoryContent($file); |
| 325 | 325 | $contents = array_map(function($fileInfo) use ($file) { |
| 326 | 326 | /** @var \OCP\Files\FileInfo $fileInfo */ |
| 327 | - return $file . '/' . $fileInfo->getName(); |
|
| 327 | + return $file.'/'.$fileInfo->getName(); |
|
| 328 | 328 | }, $contents); |
| 329 | 329 | self::lockFiles($view, $dir, $contents); |
| 330 | 330 | } |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | // default locations if not overridden by $files |
| 355 | 355 | $files = array_merge([ |
| 356 | - '.htaccess' => OC::$SERVERROOT . '/.htaccess', |
|
| 357 | - '.user.ini' => OC::$SERVERROOT . '/.user.ini' |
|
| 356 | + '.htaccess' => OC::$SERVERROOT.'/.htaccess', |
|
| 357 | + '.user.ini' => OC::$SERVERROOT.'/.user.ini' |
|
| 358 | 358 | ], $files); |
| 359 | 359 | |
| 360 | 360 | $updateFiles = [ |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | $handle = @fopen($filename, 'r+'); |
| 376 | 376 | if (!$handle) { |
| 377 | 377 | \OCP\Util::writeLog('files', |
| 378 | - 'Can\'t write upload limit to ' . $filename . '. Please check the file permissions', |
|
| 378 | + 'Can\'t write upload limit to '.$filename.'. Please check the file permissions', |
|
| 379 | 379 | \OCP\Util::WARN); |
| 380 | 380 | $success = false; |
| 381 | 381 | continue; // try to update as many files as possible |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | $content = $newContent; |
| 396 | 396 | } |
| 397 | 397 | if ($hasReplaced === 0) { |
| 398 | - $content .= "\n" . $setting; |
|
| 398 | + $content .= "\n".$setting; |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
@@ -426,12 +426,12 @@ discard block |
||
| 426 | 426 | } |
| 427 | 427 | if ($getType === self::ZIP_FILES) { |
| 428 | 428 | foreach ($files as $file) { |
| 429 | - $file = $dir . '/' . $file; |
|
| 429 | + $file = $dir.'/'.$file; |
|
| 430 | 430 | $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | if ($getType === self::ZIP_DIR) { |
| 434 | - $file = $dir . '/' . $files; |
|
| 434 | + $file = $dir.'/'.$files; |
|
| 435 | 435 | $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -83,13 +83,11 @@ discard block |
||
| 83 | 83 | if (count($rangeArray) > 1) { |
| 84 | 84 | $type = 'multipart/byteranges; boundary='.self::getBoundary(); |
| 85 | 85 | // no Content-Length header here |
| 86 | - } |
|
| 87 | - else { |
|
| 86 | + } else { |
|
| 88 | 87 | header(sprintf('Content-Range: bytes %d-%d/%d', $rangeArray[0]['from'], $rangeArray[0]['to'], $fileSize), true); |
| 89 | 88 | OC_Response::setContentLengthHeader($rangeArray[0]['to'] - $rangeArray[0]['from'] + 1); |
| 90 | 89 | } |
| 91 | - } |
|
| 92 | - else { |
|
| 90 | + } else { |
|
| 93 | 91 | OC_Response::setContentLengthHeader($fileSize); |
| 94 | 92 | } |
| 95 | 93 | } |
@@ -223,13 +221,11 @@ discard block |
||
| 223 | 221 | if ($minOffset >= $fileSize) { |
| 224 | 222 | break; |
| 225 | 223 | } |
| 226 | - } |
|
| 227 | - elseif (is_numeric($ranges[0]) && $ranges[0] < $fileSize) { |
|
| 224 | + } elseif (is_numeric($ranges[0]) && $ranges[0] < $fileSize) { |
|
| 228 | 225 | // case: x- |
| 229 | 226 | $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $fileSize-1, 'size' => $fileSize ); |
| 230 | 227 | break; |
| 231 | - } |
|
| 232 | - elseif (is_numeric($ranges[1])) { |
|
| 228 | + } elseif (is_numeric($ranges[1])) { |
|
| 233 | 229 | // case: -x |
| 234 | 230 | if ($ranges[1] > $fileSize) { |
| 235 | 231 | $ranges[1] = $fileSize; |
@@ -277,8 +273,7 @@ discard block |
||
| 277 | 273 | try { |
| 278 | 274 | if (count($rangeArray) == 1) { |
| 279 | 275 | $view->readfilePart($filename, $rangeArray[0]['from'], $rangeArray[0]['to']); |
| 280 | - } |
|
| 281 | - else { |
|
| 276 | + } else { |
|
| 282 | 277 | // check if file is seekable (if not throw UnseekableException) |
| 283 | 278 | // we have to check it before body contents |
| 284 | 279 | $view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']); |
@@ -301,8 +296,7 @@ discard block |
||
| 301 | 296 | self::sendHeaders($filename, $name, array()); |
| 302 | 297 | $view->readfile($filename); |
| 303 | 298 | } |
| 304 | - } |
|
| 305 | - else { |
|
| 299 | + } else { |
|
| 306 | 300 | $view->readfile($filename); |
| 307 | 301 | } |
| 308 | 302 | } |
@@ -46,396 +46,396 @@ |
||
| 46 | 46 | * |
| 47 | 47 | */ |
| 48 | 48 | class OC_Files { |
| 49 | - const FILE = 1; |
|
| 50 | - const ZIP_FILES = 2; |
|
| 51 | - const ZIP_DIR = 3; |
|
| 52 | - |
|
| 53 | - const UPLOAD_MIN_LIMIT_BYTES = 1048576; // 1 MiB |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - private static $multipartBoundary = ''; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - private static function getBoundary() { |
|
| 62 | - if (empty(self::$multipartBoundary)) { |
|
| 63 | - self::$multipartBoundary = md5(mt_rand()); |
|
| 64 | - } |
|
| 65 | - return self::$multipartBoundary; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param string $filename |
|
| 70 | - * @param string $name |
|
| 71 | - * @param array $rangeArray ('from'=>int,'to'=>int), ... |
|
| 72 | - */ |
|
| 73 | - private static function sendHeaders($filename, $name, array $rangeArray) { |
|
| 74 | - OC_Response::setContentDispositionHeader($name, 'attachment'); |
|
| 75 | - header('Content-Transfer-Encoding: binary', true); |
|
| 76 | - OC_Response::disableCaching(); |
|
| 77 | - $fileSize = \OC\Files\Filesystem::filesize($filename); |
|
| 78 | - $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)); |
|
| 79 | - if ($fileSize > -1) { |
|
| 80 | - if (!empty($rangeArray)) { |
|
| 81 | - header('HTTP/1.1 206 Partial Content', true); |
|
| 82 | - header('Accept-Ranges: bytes', true); |
|
| 83 | - if (count($rangeArray) > 1) { |
|
| 84 | - $type = 'multipart/byteranges; boundary='.self::getBoundary(); |
|
| 85 | - // no Content-Length header here |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - header(sprintf('Content-Range: bytes %d-%d/%d', $rangeArray[0]['from'], $rangeArray[0]['to'], $fileSize), true); |
|
| 89 | - OC_Response::setContentLengthHeader($rangeArray[0]['to'] - $rangeArray[0]['from'] + 1); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - else { |
|
| 93 | - OC_Response::setContentLengthHeader($fileSize); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - header('Content-Type: '.$type, true); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * return the content of a file or return a zip file containing multiple files |
|
| 101 | - * |
|
| 102 | - * @param string $dir |
|
| 103 | - * @param string $files ; separated list of files to download |
|
| 104 | - * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header |
|
| 105 | - */ |
|
| 106 | - public static function get($dir, $files, $params = null) { |
|
| 107 | - |
|
| 108 | - $view = \OC\Files\Filesystem::getView(); |
|
| 109 | - $getType = self::FILE; |
|
| 110 | - $filename = $dir; |
|
| 111 | - try { |
|
| 112 | - |
|
| 113 | - if (is_array($files) && count($files) === 1) { |
|
| 114 | - $files = $files[0]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if (!is_array($files)) { |
|
| 118 | - $filename = $dir . '/' . $files; |
|
| 119 | - if (!$view->is_dir($filename)) { |
|
| 120 | - self::getSingleFile($view, $dir, $files, is_null($params) ? array() : $params); |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $name = 'download'; |
|
| 126 | - if (is_array($files)) { |
|
| 127 | - $getType = self::ZIP_FILES; |
|
| 128 | - $basename = basename($dir); |
|
| 129 | - if ($basename) { |
|
| 130 | - $name = $basename; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $filename = $dir . '/' . $name; |
|
| 134 | - } else { |
|
| 135 | - $filename = $dir . '/' . $files; |
|
| 136 | - $getType = self::ZIP_DIR; |
|
| 137 | - // downloading root ? |
|
| 138 | - if ($files !== '') { |
|
| 139 | - $name = $files; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $streamer = new Streamer(); |
|
| 144 | - OC_Util::obEnd(); |
|
| 145 | - |
|
| 146 | - self::lockFiles($view, $dir, $files); |
|
| 147 | - |
|
| 148 | - $streamer->sendHeaders($name); |
|
| 149 | - $executionTime = intval(OC::$server->getIniWrapper()->getNumeric('max_execution_time')); |
|
| 150 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 151 | - @set_time_limit(0); |
|
| 152 | - } |
|
| 153 | - ignore_user_abort(true); |
|
| 154 | - if ($getType === self::ZIP_FILES) { |
|
| 155 | - foreach ($files as $file) { |
|
| 156 | - $file = $dir . '/' . $file; |
|
| 157 | - if (\OC\Files\Filesystem::is_file($file)) { |
|
| 158 | - $fileSize = \OC\Files\Filesystem::filesize($file); |
|
| 159 | - $fileTime = \OC\Files\Filesystem::filemtime($file); |
|
| 160 | - $fh = \OC\Files\Filesystem::fopen($file, 'r'); |
|
| 161 | - $streamer->addFileFromStream($fh, basename($file), $fileSize, $fileTime); |
|
| 162 | - fclose($fh); |
|
| 163 | - } elseif (\OC\Files\Filesystem::is_dir($file)) { |
|
| 164 | - $streamer->addDirRecursive($file); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } elseif ($getType === self::ZIP_DIR) { |
|
| 168 | - $file = $dir . '/' . $files; |
|
| 169 | - $streamer->addDirRecursive($file); |
|
| 170 | - } |
|
| 171 | - $streamer->finalize(); |
|
| 172 | - set_time_limit($executionTime); |
|
| 173 | - self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 174 | - } catch (\OCP\Lock\LockedException $ex) { |
|
| 175 | - self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 176 | - OC::$server->getLogger()->logException($ex); |
|
| 177 | - $l = \OC::$server->getL10N('core'); |
|
| 178 | - $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; |
|
| 179 | - \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); |
|
| 180 | - } catch (\OCP\Files\ForbiddenException $ex) { |
|
| 181 | - self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 182 | - OC::$server->getLogger()->logException($ex); |
|
| 183 | - $l = \OC::$server->getL10N('core'); |
|
| 184 | - \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage()); |
|
| 185 | - } catch (\Exception $ex) { |
|
| 186 | - self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 187 | - OC::$server->getLogger()->logException($ex); |
|
| 188 | - $l = \OC::$server->getL10N('core'); |
|
| 189 | - $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; |
|
| 190 | - \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param string $rangeHeaderPos |
|
| 196 | - * @param int $fileSize |
|
| 197 | - * @return array $rangeArray ('from'=>int,'to'=>int), ... |
|
| 198 | - */ |
|
| 199 | - private static function parseHttpRangeHeader($rangeHeaderPos, $fileSize) { |
|
| 200 | - $rArray=explode(',', $rangeHeaderPos); |
|
| 201 | - $minOffset = 0; |
|
| 202 | - $ind = 0; |
|
| 203 | - |
|
| 204 | - $rangeArray = array(); |
|
| 205 | - |
|
| 206 | - foreach ($rArray as $value) { |
|
| 207 | - $ranges = explode('-', $value); |
|
| 208 | - if (is_numeric($ranges[0])) { |
|
| 209 | - if ($ranges[0] < $minOffset) { // case: bytes=500-700,601-999 |
|
| 210 | - $ranges[0] = $minOffset; |
|
| 211 | - } |
|
| 212 | - if ($ind > 0 && $rangeArray[$ind-1]['to']+1 == $ranges[0]) { // case: bytes=500-600,601-999 |
|
| 213 | - $ind--; |
|
| 214 | - $ranges[0] = $rangeArray[$ind]['from']; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if (is_numeric($ranges[0]) && is_numeric($ranges[1]) && $ranges[0] < $fileSize && $ranges[0] <= $ranges[1]) { |
|
| 219 | - // case: x-x |
|
| 220 | - if ($ranges[1] >= $fileSize) { |
|
| 221 | - $ranges[1] = $fileSize-1; |
|
| 222 | - } |
|
| 223 | - $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $ranges[1], 'size' => $fileSize ); |
|
| 224 | - $minOffset = $ranges[1] + 1; |
|
| 225 | - if ($minOffset >= $fileSize) { |
|
| 226 | - break; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - elseif (is_numeric($ranges[0]) && $ranges[0] < $fileSize) { |
|
| 230 | - // case: x- |
|
| 231 | - $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 232 | - break; |
|
| 233 | - } |
|
| 234 | - elseif (is_numeric($ranges[1])) { |
|
| 235 | - // case: -x |
|
| 236 | - if ($ranges[1] > $fileSize) { |
|
| 237 | - $ranges[1] = $fileSize; |
|
| 238 | - } |
|
| 239 | - $rangeArray[$ind++] = array( 'from' => $fileSize-$ranges[1], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 240 | - break; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - return $rangeArray; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param View $view |
|
| 248 | - * @param string $name |
|
| 249 | - * @param string $dir |
|
| 250 | - * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header |
|
| 251 | - */ |
|
| 252 | - private static function getSingleFile($view, $dir, $name, $params) { |
|
| 253 | - $filename = $dir . '/' . $name; |
|
| 254 | - OC_Util::obEnd(); |
|
| 255 | - $view->lockFile($filename, ILockingProvider::LOCK_SHARED); |
|
| 49 | + const FILE = 1; |
|
| 50 | + const ZIP_FILES = 2; |
|
| 51 | + const ZIP_DIR = 3; |
|
| 52 | + |
|
| 53 | + const UPLOAD_MIN_LIMIT_BYTES = 1048576; // 1 MiB |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + private static $multipartBoundary = ''; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + private static function getBoundary() { |
|
| 62 | + if (empty(self::$multipartBoundary)) { |
|
| 63 | + self::$multipartBoundary = md5(mt_rand()); |
|
| 64 | + } |
|
| 65 | + return self::$multipartBoundary; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param string $filename |
|
| 70 | + * @param string $name |
|
| 71 | + * @param array $rangeArray ('from'=>int,'to'=>int), ... |
|
| 72 | + */ |
|
| 73 | + private static function sendHeaders($filename, $name, array $rangeArray) { |
|
| 74 | + OC_Response::setContentDispositionHeader($name, 'attachment'); |
|
| 75 | + header('Content-Transfer-Encoding: binary', true); |
|
| 76 | + OC_Response::disableCaching(); |
|
| 77 | + $fileSize = \OC\Files\Filesystem::filesize($filename); |
|
| 78 | + $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)); |
|
| 79 | + if ($fileSize > -1) { |
|
| 80 | + if (!empty($rangeArray)) { |
|
| 81 | + header('HTTP/1.1 206 Partial Content', true); |
|
| 82 | + header('Accept-Ranges: bytes', true); |
|
| 83 | + if (count($rangeArray) > 1) { |
|
| 84 | + $type = 'multipart/byteranges; boundary='.self::getBoundary(); |
|
| 85 | + // no Content-Length header here |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + header(sprintf('Content-Range: bytes %d-%d/%d', $rangeArray[0]['from'], $rangeArray[0]['to'], $fileSize), true); |
|
| 89 | + OC_Response::setContentLengthHeader($rangeArray[0]['to'] - $rangeArray[0]['from'] + 1); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + else { |
|
| 93 | + OC_Response::setContentLengthHeader($fileSize); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + header('Content-Type: '.$type, true); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * return the content of a file or return a zip file containing multiple files |
|
| 101 | + * |
|
| 102 | + * @param string $dir |
|
| 103 | + * @param string $files ; separated list of files to download |
|
| 104 | + * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header |
|
| 105 | + */ |
|
| 106 | + public static function get($dir, $files, $params = null) { |
|
| 107 | + |
|
| 108 | + $view = \OC\Files\Filesystem::getView(); |
|
| 109 | + $getType = self::FILE; |
|
| 110 | + $filename = $dir; |
|
| 111 | + try { |
|
| 112 | + |
|
| 113 | + if (is_array($files) && count($files) === 1) { |
|
| 114 | + $files = $files[0]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if (!is_array($files)) { |
|
| 118 | + $filename = $dir . '/' . $files; |
|
| 119 | + if (!$view->is_dir($filename)) { |
|
| 120 | + self::getSingleFile($view, $dir, $files, is_null($params) ? array() : $params); |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $name = 'download'; |
|
| 126 | + if (is_array($files)) { |
|
| 127 | + $getType = self::ZIP_FILES; |
|
| 128 | + $basename = basename($dir); |
|
| 129 | + if ($basename) { |
|
| 130 | + $name = $basename; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $filename = $dir . '/' . $name; |
|
| 134 | + } else { |
|
| 135 | + $filename = $dir . '/' . $files; |
|
| 136 | + $getType = self::ZIP_DIR; |
|
| 137 | + // downloading root ? |
|
| 138 | + if ($files !== '') { |
|
| 139 | + $name = $files; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $streamer = new Streamer(); |
|
| 144 | + OC_Util::obEnd(); |
|
| 145 | + |
|
| 146 | + self::lockFiles($view, $dir, $files); |
|
| 147 | + |
|
| 148 | + $streamer->sendHeaders($name); |
|
| 149 | + $executionTime = intval(OC::$server->getIniWrapper()->getNumeric('max_execution_time')); |
|
| 150 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 151 | + @set_time_limit(0); |
|
| 152 | + } |
|
| 153 | + ignore_user_abort(true); |
|
| 154 | + if ($getType === self::ZIP_FILES) { |
|
| 155 | + foreach ($files as $file) { |
|
| 156 | + $file = $dir . '/' . $file; |
|
| 157 | + if (\OC\Files\Filesystem::is_file($file)) { |
|
| 158 | + $fileSize = \OC\Files\Filesystem::filesize($file); |
|
| 159 | + $fileTime = \OC\Files\Filesystem::filemtime($file); |
|
| 160 | + $fh = \OC\Files\Filesystem::fopen($file, 'r'); |
|
| 161 | + $streamer->addFileFromStream($fh, basename($file), $fileSize, $fileTime); |
|
| 162 | + fclose($fh); |
|
| 163 | + } elseif (\OC\Files\Filesystem::is_dir($file)) { |
|
| 164 | + $streamer->addDirRecursive($file); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } elseif ($getType === self::ZIP_DIR) { |
|
| 168 | + $file = $dir . '/' . $files; |
|
| 169 | + $streamer->addDirRecursive($file); |
|
| 170 | + } |
|
| 171 | + $streamer->finalize(); |
|
| 172 | + set_time_limit($executionTime); |
|
| 173 | + self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 174 | + } catch (\OCP\Lock\LockedException $ex) { |
|
| 175 | + self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 176 | + OC::$server->getLogger()->logException($ex); |
|
| 177 | + $l = \OC::$server->getL10N('core'); |
|
| 178 | + $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; |
|
| 179 | + \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); |
|
| 180 | + } catch (\OCP\Files\ForbiddenException $ex) { |
|
| 181 | + self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 182 | + OC::$server->getLogger()->logException($ex); |
|
| 183 | + $l = \OC::$server->getL10N('core'); |
|
| 184 | + \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage()); |
|
| 185 | + } catch (\Exception $ex) { |
|
| 186 | + self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); |
|
| 187 | + OC::$server->getLogger()->logException($ex); |
|
| 188 | + $l = \OC::$server->getL10N('core'); |
|
| 189 | + $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; |
|
| 190 | + \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param string $rangeHeaderPos |
|
| 196 | + * @param int $fileSize |
|
| 197 | + * @return array $rangeArray ('from'=>int,'to'=>int), ... |
|
| 198 | + */ |
|
| 199 | + private static function parseHttpRangeHeader($rangeHeaderPos, $fileSize) { |
|
| 200 | + $rArray=explode(',', $rangeHeaderPos); |
|
| 201 | + $minOffset = 0; |
|
| 202 | + $ind = 0; |
|
| 203 | + |
|
| 204 | + $rangeArray = array(); |
|
| 205 | + |
|
| 206 | + foreach ($rArray as $value) { |
|
| 207 | + $ranges = explode('-', $value); |
|
| 208 | + if (is_numeric($ranges[0])) { |
|
| 209 | + if ($ranges[0] < $minOffset) { // case: bytes=500-700,601-999 |
|
| 210 | + $ranges[0] = $minOffset; |
|
| 211 | + } |
|
| 212 | + if ($ind > 0 && $rangeArray[$ind-1]['to']+1 == $ranges[0]) { // case: bytes=500-600,601-999 |
|
| 213 | + $ind--; |
|
| 214 | + $ranges[0] = $rangeArray[$ind]['from']; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if (is_numeric($ranges[0]) && is_numeric($ranges[1]) && $ranges[0] < $fileSize && $ranges[0] <= $ranges[1]) { |
|
| 219 | + // case: x-x |
|
| 220 | + if ($ranges[1] >= $fileSize) { |
|
| 221 | + $ranges[1] = $fileSize-1; |
|
| 222 | + } |
|
| 223 | + $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $ranges[1], 'size' => $fileSize ); |
|
| 224 | + $minOffset = $ranges[1] + 1; |
|
| 225 | + if ($minOffset >= $fileSize) { |
|
| 226 | + break; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + elseif (is_numeric($ranges[0]) && $ranges[0] < $fileSize) { |
|
| 230 | + // case: x- |
|
| 231 | + $rangeArray[$ind++] = array( 'from' => $ranges[0], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 232 | + break; |
|
| 233 | + } |
|
| 234 | + elseif (is_numeric($ranges[1])) { |
|
| 235 | + // case: -x |
|
| 236 | + if ($ranges[1] > $fileSize) { |
|
| 237 | + $ranges[1] = $fileSize; |
|
| 238 | + } |
|
| 239 | + $rangeArray[$ind++] = array( 'from' => $fileSize-$ranges[1], 'to' => $fileSize-1, 'size' => $fileSize ); |
|
| 240 | + break; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + return $rangeArray; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param View $view |
|
| 248 | + * @param string $name |
|
| 249 | + * @param string $dir |
|
| 250 | + * @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header |
|
| 251 | + */ |
|
| 252 | + private static function getSingleFile($view, $dir, $name, $params) { |
|
| 253 | + $filename = $dir . '/' . $name; |
|
| 254 | + OC_Util::obEnd(); |
|
| 255 | + $view->lockFile($filename, ILockingProvider::LOCK_SHARED); |
|
| 256 | 256 | |
| 257 | - $rangeArray = array(); |
|
| 257 | + $rangeArray = array(); |
|
| 258 | 258 | |
| 259 | - if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') { |
|
| 260 | - $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), |
|
| 261 | - \OC\Files\Filesystem::filesize($filename)); |
|
| 262 | - } |
|
| 259 | + if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') { |
|
| 260 | + $rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), |
|
| 261 | + \OC\Files\Filesystem::filesize($filename)); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - if (\OC\Files\Filesystem::isReadable($filename)) { |
|
| 265 | - self::sendHeaders($filename, $name, $rangeArray); |
|
| 266 | - } elseif (!\OC\Files\Filesystem::file_exists($filename)) { |
|
| 267 | - header("HTTP/1.1 404 Not Found"); |
|
| 268 | - $tmpl = new OC_Template('', '404', 'guest'); |
|
| 269 | - $tmpl->printPage(); |
|
| 270 | - exit(); |
|
| 271 | - } else { |
|
| 272 | - header("HTTP/1.1 403 Forbidden"); |
|
| 273 | - die('403 Forbidden'); |
|
| 274 | - } |
|
| 275 | - if (isset($params['head']) && $params['head']) { |
|
| 276 | - return; |
|
| 277 | - } |
|
| 278 | - if (!empty($rangeArray)) { |
|
| 279 | - try { |
|
| 280 | - if (count($rangeArray) == 1) { |
|
| 281 | - $view->readfilePart($filename, $rangeArray[0]['from'], $rangeArray[0]['to']); |
|
| 282 | - } |
|
| 283 | - else { |
|
| 284 | - // check if file is seekable (if not throw UnseekableException) |
|
| 285 | - // we have to check it before body contents |
|
| 286 | - $view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']); |
|
| 287 | - |
|
| 288 | - $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)); |
|
| 289 | - |
|
| 290 | - foreach ($rangeArray as $range) { |
|
| 291 | - echo "\r\n--".self::getBoundary()."\r\n". |
|
| 292 | - "Content-type: ".$type."\r\n". |
|
| 293 | - "Content-range: bytes ".$range['from']."-".$range['to']."/".$range['size']."\r\n\r\n"; |
|
| 294 | - $view->readfilePart($filename, $range['from'], $range['to']); |
|
| 295 | - } |
|
| 296 | - echo "\r\n--".self::getBoundary()."--\r\n"; |
|
| 297 | - } |
|
| 298 | - } catch (\OCP\Files\UnseekableException $ex) { |
|
| 299 | - // file is unseekable |
|
| 300 | - header_remove('Accept-Ranges'); |
|
| 301 | - header_remove('Content-Range'); |
|
| 302 | - header("HTTP/1.1 200 OK"); |
|
| 303 | - self::sendHeaders($filename, $name, array()); |
|
| 304 | - $view->readfile($filename); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - else { |
|
| 308 | - $view->readfile($filename); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @param View $view |
|
| 314 | - * @param string $dir |
|
| 315 | - * @param string[]|string $files |
|
| 316 | - */ |
|
| 317 | - public static function lockFiles($view, $dir, $files) { |
|
| 318 | - if (!is_array($files)) { |
|
| 319 | - $file = $dir . '/' . $files; |
|
| 320 | - $files = [$file]; |
|
| 321 | - } |
|
| 322 | - foreach ($files as $file) { |
|
| 323 | - $file = $dir . '/' . $file; |
|
| 324 | - $view->lockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 325 | - if ($view->is_dir($file)) { |
|
| 326 | - $contents = $view->getDirectoryContent($file); |
|
| 327 | - $contents = array_map(function($fileInfo) use ($file) { |
|
| 328 | - /** @var \OCP\Files\FileInfo $fileInfo */ |
|
| 329 | - return $file . '/' . $fileInfo->getName(); |
|
| 330 | - }, $contents); |
|
| 331 | - self::lockFiles($view, $dir, $contents); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * set the maximum upload size limit for apache hosts using .htaccess |
|
| 338 | - * |
|
| 339 | - * @param int $size file size in bytes |
|
| 340 | - * @param array $files override '.htaccess' and '.user.ini' locations |
|
| 341 | - * @return bool false on failure, size on success |
|
| 342 | - */ |
|
| 343 | - public static function setUploadLimit($size, $files = []) { |
|
| 344 | - //don't allow user to break his config |
|
| 345 | - $size = intval($size); |
|
| 346 | - if ($size < self::UPLOAD_MIN_LIMIT_BYTES) { |
|
| 347 | - return false; |
|
| 348 | - } |
|
| 349 | - $size = OC_Helper::phpFileSize($size); |
|
| 350 | - |
|
| 351 | - $phpValueKeys = array( |
|
| 352 | - 'upload_max_filesize', |
|
| 353 | - 'post_max_size' |
|
| 354 | - ); |
|
| 355 | - |
|
| 356 | - // default locations if not overridden by $files |
|
| 357 | - $files = array_merge([ |
|
| 358 | - '.htaccess' => OC::$SERVERROOT . '/.htaccess', |
|
| 359 | - '.user.ini' => OC::$SERVERROOT . '/.user.ini' |
|
| 360 | - ], $files); |
|
| 361 | - |
|
| 362 | - $updateFiles = [ |
|
| 363 | - $files['.htaccess'] => [ |
|
| 364 | - 'pattern' => '/php_value %1$s (\S)*/', |
|
| 365 | - 'setting' => 'php_value %1$s %2$s' |
|
| 366 | - ], |
|
| 367 | - $files['.user.ini'] => [ |
|
| 368 | - 'pattern' => '/%1$s=(\S)*/', |
|
| 369 | - 'setting' => '%1$s=%2$s' |
|
| 370 | - ] |
|
| 371 | - ]; |
|
| 372 | - |
|
| 373 | - $success = true; |
|
| 374 | - |
|
| 375 | - foreach ($updateFiles as $filename => $patternMap) { |
|
| 376 | - // suppress warnings from fopen() |
|
| 377 | - $handle = @fopen($filename, 'r+'); |
|
| 378 | - if (!$handle) { |
|
| 379 | - \OCP\Util::writeLog('files', |
|
| 380 | - 'Can\'t write upload limit to ' . $filename . '. Please check the file permissions', |
|
| 381 | - \OCP\Util::WARN); |
|
| 382 | - $success = false; |
|
| 383 | - continue; // try to update as many files as possible |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $content = ''; |
|
| 387 | - while (!feof($handle)) { |
|
| 388 | - $content .= fread($handle, 1000); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - foreach ($phpValueKeys as $key) { |
|
| 392 | - $pattern = vsprintf($patternMap['pattern'], [$key]); |
|
| 393 | - $setting = vsprintf($patternMap['setting'], [$key, $size]); |
|
| 394 | - $hasReplaced = 0; |
|
| 395 | - $newContent = preg_replace($pattern, $setting, $content, 2, $hasReplaced); |
|
| 396 | - if ($newContent !== null) { |
|
| 397 | - $content = $newContent; |
|
| 398 | - } |
|
| 399 | - if ($hasReplaced === 0) { |
|
| 400 | - $content .= "\n" . $setting; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // write file back |
|
| 405 | - ftruncate($handle, 0); |
|
| 406 | - rewind($handle); |
|
| 407 | - fwrite($handle, $content); |
|
| 408 | - |
|
| 409 | - fclose($handle); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - if ($success) { |
|
| 413 | - return OC_Helper::computerFileSize($size); |
|
| 414 | - } |
|
| 415 | - return false; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @param string $dir |
|
| 420 | - * @param $files |
|
| 421 | - * @param integer $getType |
|
| 422 | - * @param View $view |
|
| 423 | - * @param string $filename |
|
| 424 | - */ |
|
| 425 | - private static function unlockAllTheFiles($dir, $files, $getType, $view, $filename) { |
|
| 426 | - if ($getType === self::FILE) { |
|
| 427 | - $view->unlockFile($filename, ILockingProvider::LOCK_SHARED); |
|
| 428 | - } |
|
| 429 | - if ($getType === self::ZIP_FILES) { |
|
| 430 | - foreach ($files as $file) { |
|
| 431 | - $file = $dir . '/' . $file; |
|
| 432 | - $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - if ($getType === self::ZIP_DIR) { |
|
| 436 | - $file = $dir . '/' . $files; |
|
| 437 | - $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 438 | - } |
|
| 439 | - } |
|
| 264 | + if (\OC\Files\Filesystem::isReadable($filename)) { |
|
| 265 | + self::sendHeaders($filename, $name, $rangeArray); |
|
| 266 | + } elseif (!\OC\Files\Filesystem::file_exists($filename)) { |
|
| 267 | + header("HTTP/1.1 404 Not Found"); |
|
| 268 | + $tmpl = new OC_Template('', '404', 'guest'); |
|
| 269 | + $tmpl->printPage(); |
|
| 270 | + exit(); |
|
| 271 | + } else { |
|
| 272 | + header("HTTP/1.1 403 Forbidden"); |
|
| 273 | + die('403 Forbidden'); |
|
| 274 | + } |
|
| 275 | + if (isset($params['head']) && $params['head']) { |
|
| 276 | + return; |
|
| 277 | + } |
|
| 278 | + if (!empty($rangeArray)) { |
|
| 279 | + try { |
|
| 280 | + if (count($rangeArray) == 1) { |
|
| 281 | + $view->readfilePart($filename, $rangeArray[0]['from'], $rangeArray[0]['to']); |
|
| 282 | + } |
|
| 283 | + else { |
|
| 284 | + // check if file is seekable (if not throw UnseekableException) |
|
| 285 | + // we have to check it before body contents |
|
| 286 | + $view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']); |
|
| 287 | + |
|
| 288 | + $type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)); |
|
| 289 | + |
|
| 290 | + foreach ($rangeArray as $range) { |
|
| 291 | + echo "\r\n--".self::getBoundary()."\r\n". |
|
| 292 | + "Content-type: ".$type."\r\n". |
|
| 293 | + "Content-range: bytes ".$range['from']."-".$range['to']."/".$range['size']."\r\n\r\n"; |
|
| 294 | + $view->readfilePart($filename, $range['from'], $range['to']); |
|
| 295 | + } |
|
| 296 | + echo "\r\n--".self::getBoundary()."--\r\n"; |
|
| 297 | + } |
|
| 298 | + } catch (\OCP\Files\UnseekableException $ex) { |
|
| 299 | + // file is unseekable |
|
| 300 | + header_remove('Accept-Ranges'); |
|
| 301 | + header_remove('Content-Range'); |
|
| 302 | + header("HTTP/1.1 200 OK"); |
|
| 303 | + self::sendHeaders($filename, $name, array()); |
|
| 304 | + $view->readfile($filename); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + else { |
|
| 308 | + $view->readfile($filename); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @param View $view |
|
| 314 | + * @param string $dir |
|
| 315 | + * @param string[]|string $files |
|
| 316 | + */ |
|
| 317 | + public static function lockFiles($view, $dir, $files) { |
|
| 318 | + if (!is_array($files)) { |
|
| 319 | + $file = $dir . '/' . $files; |
|
| 320 | + $files = [$file]; |
|
| 321 | + } |
|
| 322 | + foreach ($files as $file) { |
|
| 323 | + $file = $dir . '/' . $file; |
|
| 324 | + $view->lockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 325 | + if ($view->is_dir($file)) { |
|
| 326 | + $contents = $view->getDirectoryContent($file); |
|
| 327 | + $contents = array_map(function($fileInfo) use ($file) { |
|
| 328 | + /** @var \OCP\Files\FileInfo $fileInfo */ |
|
| 329 | + return $file . '/' . $fileInfo->getName(); |
|
| 330 | + }, $contents); |
|
| 331 | + self::lockFiles($view, $dir, $contents); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * set the maximum upload size limit for apache hosts using .htaccess |
|
| 338 | + * |
|
| 339 | + * @param int $size file size in bytes |
|
| 340 | + * @param array $files override '.htaccess' and '.user.ini' locations |
|
| 341 | + * @return bool false on failure, size on success |
|
| 342 | + */ |
|
| 343 | + public static function setUploadLimit($size, $files = []) { |
|
| 344 | + //don't allow user to break his config |
|
| 345 | + $size = intval($size); |
|
| 346 | + if ($size < self::UPLOAD_MIN_LIMIT_BYTES) { |
|
| 347 | + return false; |
|
| 348 | + } |
|
| 349 | + $size = OC_Helper::phpFileSize($size); |
|
| 350 | + |
|
| 351 | + $phpValueKeys = array( |
|
| 352 | + 'upload_max_filesize', |
|
| 353 | + 'post_max_size' |
|
| 354 | + ); |
|
| 355 | + |
|
| 356 | + // default locations if not overridden by $files |
|
| 357 | + $files = array_merge([ |
|
| 358 | + '.htaccess' => OC::$SERVERROOT . '/.htaccess', |
|
| 359 | + '.user.ini' => OC::$SERVERROOT . '/.user.ini' |
|
| 360 | + ], $files); |
|
| 361 | + |
|
| 362 | + $updateFiles = [ |
|
| 363 | + $files['.htaccess'] => [ |
|
| 364 | + 'pattern' => '/php_value %1$s (\S)*/', |
|
| 365 | + 'setting' => 'php_value %1$s %2$s' |
|
| 366 | + ], |
|
| 367 | + $files['.user.ini'] => [ |
|
| 368 | + 'pattern' => '/%1$s=(\S)*/', |
|
| 369 | + 'setting' => '%1$s=%2$s' |
|
| 370 | + ] |
|
| 371 | + ]; |
|
| 372 | + |
|
| 373 | + $success = true; |
|
| 374 | + |
|
| 375 | + foreach ($updateFiles as $filename => $patternMap) { |
|
| 376 | + // suppress warnings from fopen() |
|
| 377 | + $handle = @fopen($filename, 'r+'); |
|
| 378 | + if (!$handle) { |
|
| 379 | + \OCP\Util::writeLog('files', |
|
| 380 | + 'Can\'t write upload limit to ' . $filename . '. Please check the file permissions', |
|
| 381 | + \OCP\Util::WARN); |
|
| 382 | + $success = false; |
|
| 383 | + continue; // try to update as many files as possible |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $content = ''; |
|
| 387 | + while (!feof($handle)) { |
|
| 388 | + $content .= fread($handle, 1000); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + foreach ($phpValueKeys as $key) { |
|
| 392 | + $pattern = vsprintf($patternMap['pattern'], [$key]); |
|
| 393 | + $setting = vsprintf($patternMap['setting'], [$key, $size]); |
|
| 394 | + $hasReplaced = 0; |
|
| 395 | + $newContent = preg_replace($pattern, $setting, $content, 2, $hasReplaced); |
|
| 396 | + if ($newContent !== null) { |
|
| 397 | + $content = $newContent; |
|
| 398 | + } |
|
| 399 | + if ($hasReplaced === 0) { |
|
| 400 | + $content .= "\n" . $setting; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // write file back |
|
| 405 | + ftruncate($handle, 0); |
|
| 406 | + rewind($handle); |
|
| 407 | + fwrite($handle, $content); |
|
| 408 | + |
|
| 409 | + fclose($handle); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + if ($success) { |
|
| 413 | + return OC_Helper::computerFileSize($size); |
|
| 414 | + } |
|
| 415 | + return false; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @param string $dir |
|
| 420 | + * @param $files |
|
| 421 | + * @param integer $getType |
|
| 422 | + * @param View $view |
|
| 423 | + * @param string $filename |
|
| 424 | + */ |
|
| 425 | + private static function unlockAllTheFiles($dir, $files, $getType, $view, $filename) { |
|
| 426 | + if ($getType === self::FILE) { |
|
| 427 | + $view->unlockFile($filename, ILockingProvider::LOCK_SHARED); |
|
| 428 | + } |
|
| 429 | + if ($getType === self::ZIP_FILES) { |
|
| 430 | + foreach ($files as $file) { |
|
| 431 | + $file = $dir . '/' . $file; |
|
| 432 | + $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + if ($getType === self::ZIP_DIR) { |
|
| 436 | + $file = $dir . '/' . $files; |
|
| 437 | + $view->unlockFile($file, ILockingProvider::LOCK_SHARED); |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | 441 | } |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | * @param string $key |
| 96 | 96 | * @param mixed $value |
| 97 | 97 | * @param int $ttl |
| 98 | - * @return bool|mixed |
|
| 98 | + * @return boolean |
|
| 99 | 99 | * @throws \OC\ForbiddenException |
| 100 | 100 | */ |
| 101 | 101 | public function set($key, $value, $ttl = 0) { |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | $rootView = new View(); |
| 52 | 52 | $user = \OC::$server->getUserSession()->getUser(); |
| 53 | 53 | Filesystem::initMountPoints($user->getUID()); |
| 54 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 55 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 54 | + if (!$rootView->file_exists('/'.$user->getUID().'/cache')) { |
|
| 55 | + $rootView->mkdir('/'.$user->getUID().'/cache'); |
|
| 56 | 56 | } |
| 57 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 57 | + $this->storage = new View('/'.$user->getUID().'/cache'); |
|
| 58 | 58 | return $this->storage; |
| 59 | 59 | } else { |
| 60 | 60 | \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | // unique id to avoid chunk collision, just in case |
| 105 | 105 | $uniqueId = \OC::$server->getSecureRandom()->generate( |
| 106 | 106 | 16, |
| 107 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 107 | + ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER |
|
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | 110 | // use part file to prevent hasKey() to find the key |
| 111 | 111 | // while it is being written |
| 112 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 112 | + $keyPart = $key.'.'.$uniqueId.'.part'; |
|
| 113 | 113 | if ($storage and $storage->file_put_contents($keyPart, $value)) { |
| 114 | 114 | if ($ttl === 0) { |
| 115 | 115 | $ttl = 86400; // 60*60*24 |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | if (is_resource($dh)) { |
| 159 | 159 | while (($file = readdir($dh)) !== false) { |
| 160 | 160 | if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
| 161 | - $storage->unlink('/' . $file); |
|
| 161 | + $storage->unlink('/'.$file); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -183,17 +183,17 @@ discard block |
||
| 183 | 183 | while (($file = readdir($dh)) !== false) { |
| 184 | 184 | if ($file != '.' and $file != '..') { |
| 185 | 185 | try { |
| 186 | - $mtime = $storage->filemtime('/' . $file); |
|
| 186 | + $mtime = $storage->filemtime('/'.$file); |
|
| 187 | 187 | if ($mtime < $now) { |
| 188 | - $storage->unlink('/' . $file); |
|
| 188 | + $storage->unlink('/'.$file); |
|
| 189 | 189 | } |
| 190 | 190 | } catch (\OCP\Lock\LockedException $e) { |
| 191 | 191 | // ignore locked chunks |
| 192 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 192 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
| 193 | 193 | } catch (\OCP\Files\ForbiddenException $e) { |
| 194 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 194 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "'.$file.'"', array('app' => 'core')); |
|
| 195 | 195 | } catch (\OCP\Files\LockNotAcquiredException $e) { |
| 196 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 196 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |
@@ -33,170 +33,170 @@ |
||
| 33 | 33 | |
| 34 | 34 | class File implements ICache { |
| 35 | 35 | |
| 36 | - /** @var View */ |
|
| 37 | - protected $storage; |
|
| 36 | + /** @var View */ |
|
| 37 | + protected $storage; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Returns the cache storage for the logged in user |
|
| 41 | - * |
|
| 42 | - * @return \OC\Files\View cache storage |
|
| 43 | - * @throws \OC\ForbiddenException |
|
| 44 | - * @throws \OC\User\NoUserException |
|
| 45 | - */ |
|
| 46 | - protected function getStorage() { |
|
| 47 | - if (isset($this->storage)) { |
|
| 48 | - return $this->storage; |
|
| 49 | - } |
|
| 50 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 51 | - $rootView = new View(); |
|
| 52 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 53 | - Filesystem::initMountPoints($user->getUID()); |
|
| 54 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 55 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 56 | - } |
|
| 57 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 58 | - return $this->storage; |
|
| 59 | - } else { |
|
| 60 | - \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
|
| 61 | - throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
| 62 | - } |
|
| 63 | - } |
|
| 39 | + /** |
|
| 40 | + * Returns the cache storage for the logged in user |
|
| 41 | + * |
|
| 42 | + * @return \OC\Files\View cache storage |
|
| 43 | + * @throws \OC\ForbiddenException |
|
| 44 | + * @throws \OC\User\NoUserException |
|
| 45 | + */ |
|
| 46 | + protected function getStorage() { |
|
| 47 | + if (isset($this->storage)) { |
|
| 48 | + return $this->storage; |
|
| 49 | + } |
|
| 50 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 51 | + $rootView = new View(); |
|
| 52 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 53 | + Filesystem::initMountPoints($user->getUID()); |
|
| 54 | + if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 55 | + $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 56 | + } |
|
| 57 | + $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 58 | + return $this->storage; |
|
| 59 | + } else { |
|
| 60 | + \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); |
|
| 61 | + throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param string $key |
|
| 67 | - * @return mixed|null |
|
| 68 | - * @throws \OC\ForbiddenException |
|
| 69 | - */ |
|
| 70 | - public function get($key) { |
|
| 71 | - $result = null; |
|
| 72 | - if ($this->hasKey($key)) { |
|
| 73 | - $storage = $this->getStorage(); |
|
| 74 | - $result = $storage->file_get_contents($key); |
|
| 75 | - } |
|
| 76 | - return $result; |
|
| 77 | - } |
|
| 65 | + /** |
|
| 66 | + * @param string $key |
|
| 67 | + * @return mixed|null |
|
| 68 | + * @throws \OC\ForbiddenException |
|
| 69 | + */ |
|
| 70 | + public function get($key) { |
|
| 71 | + $result = null; |
|
| 72 | + if ($this->hasKey($key)) { |
|
| 73 | + $storage = $this->getStorage(); |
|
| 74 | + $result = $storage->file_get_contents($key); |
|
| 75 | + } |
|
| 76 | + return $result; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Returns the size of the stored/cached data |
|
| 81 | - * |
|
| 82 | - * @param string $key |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function size($key) { |
|
| 86 | - $result = 0; |
|
| 87 | - if ($this->hasKey($key)) { |
|
| 88 | - $storage = $this->getStorage(); |
|
| 89 | - $result = $storage->filesize($key); |
|
| 90 | - } |
|
| 91 | - return $result; |
|
| 92 | - } |
|
| 79 | + /** |
|
| 80 | + * Returns the size of the stored/cached data |
|
| 81 | + * |
|
| 82 | + * @param string $key |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function size($key) { |
|
| 86 | + $result = 0; |
|
| 87 | + if ($this->hasKey($key)) { |
|
| 88 | + $storage = $this->getStorage(); |
|
| 89 | + $result = $storage->filesize($key); |
|
| 90 | + } |
|
| 91 | + return $result; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @param string $key |
|
| 96 | - * @param mixed $value |
|
| 97 | - * @param int $ttl |
|
| 98 | - * @return bool|mixed |
|
| 99 | - * @throws \OC\ForbiddenException |
|
| 100 | - */ |
|
| 101 | - public function set($key, $value, $ttl = 0) { |
|
| 102 | - $storage = $this->getStorage(); |
|
| 103 | - $result = false; |
|
| 104 | - // unique id to avoid chunk collision, just in case |
|
| 105 | - $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
| 106 | - 16, |
|
| 107 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 108 | - ); |
|
| 94 | + /** |
|
| 95 | + * @param string $key |
|
| 96 | + * @param mixed $value |
|
| 97 | + * @param int $ttl |
|
| 98 | + * @return bool|mixed |
|
| 99 | + * @throws \OC\ForbiddenException |
|
| 100 | + */ |
|
| 101 | + public function set($key, $value, $ttl = 0) { |
|
| 102 | + $storage = $this->getStorage(); |
|
| 103 | + $result = false; |
|
| 104 | + // unique id to avoid chunk collision, just in case |
|
| 105 | + $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
| 106 | + 16, |
|
| 107 | + ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 108 | + ); |
|
| 109 | 109 | |
| 110 | - // use part file to prevent hasKey() to find the key |
|
| 111 | - // while it is being written |
|
| 112 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 113 | - if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
| 114 | - if ($ttl === 0) { |
|
| 115 | - $ttl = 86400; // 60*60*24 |
|
| 116 | - } |
|
| 117 | - $result = $storage->touch($keyPart, time() + $ttl); |
|
| 118 | - $result &= $storage->rename($keyPart, $key); |
|
| 119 | - } |
|
| 120 | - return $result; |
|
| 121 | - } |
|
| 110 | + // use part file to prevent hasKey() to find the key |
|
| 111 | + // while it is being written |
|
| 112 | + $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 113 | + if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
| 114 | + if ($ttl === 0) { |
|
| 115 | + $ttl = 86400; // 60*60*24 |
|
| 116 | + } |
|
| 117 | + $result = $storage->touch($keyPart, time() + $ttl); |
|
| 118 | + $result &= $storage->rename($keyPart, $key); |
|
| 119 | + } |
|
| 120 | + return $result; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @param string $key |
|
| 125 | - * @return bool |
|
| 126 | - * @throws \OC\ForbiddenException |
|
| 127 | - */ |
|
| 128 | - public function hasKey($key) { |
|
| 129 | - $storage = $this->getStorage(); |
|
| 130 | - if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
| 131 | - return true; |
|
| 132 | - } |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 123 | + /** |
|
| 124 | + * @param string $key |
|
| 125 | + * @return bool |
|
| 126 | + * @throws \OC\ForbiddenException |
|
| 127 | + */ |
|
| 128 | + public function hasKey($key) { |
|
| 129 | + $storage = $this->getStorage(); |
|
| 130 | + if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
| 131 | + return true; |
|
| 132 | + } |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @param string $key |
|
| 138 | - * @return bool|mixed |
|
| 139 | - * @throws \OC\ForbiddenException |
|
| 140 | - */ |
|
| 141 | - public function remove($key) { |
|
| 142 | - $storage = $this->getStorage(); |
|
| 143 | - if (!$storage) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - return $storage->unlink($key); |
|
| 147 | - } |
|
| 136 | + /** |
|
| 137 | + * @param string $key |
|
| 138 | + * @return bool|mixed |
|
| 139 | + * @throws \OC\ForbiddenException |
|
| 140 | + */ |
|
| 141 | + public function remove($key) { |
|
| 142 | + $storage = $this->getStorage(); |
|
| 143 | + if (!$storage) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + return $storage->unlink($key); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @param string $prefix |
|
| 151 | - * @return bool |
|
| 152 | - * @throws \OC\ForbiddenException |
|
| 153 | - */ |
|
| 154 | - public function clear($prefix = '') { |
|
| 155 | - $storage = $this->getStorage(); |
|
| 156 | - if ($storage and $storage->is_dir('/')) { |
|
| 157 | - $dh = $storage->opendir('/'); |
|
| 158 | - if (is_resource($dh)) { |
|
| 159 | - while (($file = readdir($dh)) !== false) { |
|
| 160 | - if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
| 161 | - $storage->unlink('/' . $file); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return true; |
|
| 167 | - } |
|
| 149 | + /** |
|
| 150 | + * @param string $prefix |
|
| 151 | + * @return bool |
|
| 152 | + * @throws \OC\ForbiddenException |
|
| 153 | + */ |
|
| 154 | + public function clear($prefix = '') { |
|
| 155 | + $storage = $this->getStorage(); |
|
| 156 | + if ($storage and $storage->is_dir('/')) { |
|
| 157 | + $dh = $storage->opendir('/'); |
|
| 158 | + if (is_resource($dh)) { |
|
| 159 | + while (($file = readdir($dh)) !== false) { |
|
| 160 | + if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
| 161 | + $storage->unlink('/' . $file); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return true; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Runs GC |
|
| 171 | - * @throws \OC\ForbiddenException |
|
| 172 | - */ |
|
| 173 | - public function gc() { |
|
| 174 | - $storage = $this->getStorage(); |
|
| 175 | - if ($storage and $storage->is_dir('/')) { |
|
| 176 | - // extra hour safety, in case of stray part chunks that take longer to write, |
|
| 177 | - // because touch() is only called after the chunk was finished |
|
| 178 | - $now = time() - 3600; |
|
| 179 | - $dh = $storage->opendir('/'); |
|
| 180 | - if (!is_resource($dh)) { |
|
| 181 | - return null; |
|
| 182 | - } |
|
| 183 | - while (($file = readdir($dh)) !== false) { |
|
| 184 | - if ($file != '.' and $file != '..') { |
|
| 185 | - try { |
|
| 186 | - $mtime = $storage->filemtime('/' . $file); |
|
| 187 | - if ($mtime < $now) { |
|
| 188 | - $storage->unlink('/' . $file); |
|
| 189 | - } |
|
| 190 | - } catch (\OCP\Lock\LockedException $e) { |
|
| 191 | - // ignore locked chunks |
|
| 192 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 193 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
| 194 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 195 | - } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
| 196 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 169 | + /** |
|
| 170 | + * Runs GC |
|
| 171 | + * @throws \OC\ForbiddenException |
|
| 172 | + */ |
|
| 173 | + public function gc() { |
|
| 174 | + $storage = $this->getStorage(); |
|
| 175 | + if ($storage and $storage->is_dir('/')) { |
|
| 176 | + // extra hour safety, in case of stray part chunks that take longer to write, |
|
| 177 | + // because touch() is only called after the chunk was finished |
|
| 178 | + $now = time() - 3600; |
|
| 179 | + $dh = $storage->opendir('/'); |
|
| 180 | + if (!is_resource($dh)) { |
|
| 181 | + return null; |
|
| 182 | + } |
|
| 183 | + while (($file = readdir($dh)) !== false) { |
|
| 184 | + if ($file != '.' and $file != '..') { |
|
| 185 | + try { |
|
| 186 | + $mtime = $storage->filemtime('/' . $file); |
|
| 187 | + if ($mtime < $now) { |
|
| 188 | + $storage->unlink('/' . $file); |
|
| 189 | + } |
|
| 190 | + } catch (\OCP\Lock\LockedException $e) { |
|
| 191 | + // ignore locked chunks |
|
| 192 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 193 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
| 194 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 195 | + } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
| 196 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | - * @param $message |
|
| 135 | + * @param string $message |
|
| 136 | 136 | * @param array $additional |
| 137 | 137 | * @return array |
| 138 | 138 | */ |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function checkPasswordResetToken($token, $userId) { |
| 169 | 169 | $user = $this->userManager->get($userId); |
| 170 | - if($user === null || !$user->isEnabled()) { |
|
| 170 | + if ($user === null || !$user->isEnabled()) { |
|
| 171 | 171 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | $splittedToken = explode(':', $decryptedToken); |
| 183 | - if(count($splittedToken) !== 2) { |
|
| 183 | + if (count($splittedToken) !== 2) { |
|
| 184 | 184 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 187 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 12) || |
|
| 188 | 188 | $user->getLastLogin() > $splittedToken[0]) { |
| 189 | 189 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
| 190 | 190 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @param array $additional |
| 200 | 200 | * @return array |
| 201 | 201 | */ |
| 202 | - private function error($message, array $additional=array()) { |
|
| 202 | + private function error($message, array $additional = array()) { |
|
| 203 | 203 | return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
| 204 | 204 | } |
| 205 | 205 | |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @param string $user |
| 219 | 219 | * @return JSONResponse |
| 220 | 220 | */ |
| 221 | - public function email($user){ |
|
| 221 | + public function email($user) { |
|
| 222 | 222 | if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
| 223 | 223 | return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
| 224 | 224 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | // FIXME: use HTTP error codes |
| 227 | 227 | try { |
| 228 | 228 | $this->sendEmail($user); |
| 229 | - } catch (\Exception $e){ |
|
| 229 | + } catch (\Exception $e) { |
|
| 230 | 230 | $response = new JSONResponse($this->error($e->getMessage())); |
| 231 | 231 | $response->throttle(); |
| 232 | 232 | return $response; |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
| 270 | 270 | @\OC::$server->getUserSession()->unsetMagicInCookie(); |
| 271 | - } catch (\Exception $e){ |
|
| 271 | + } catch (\Exception $e) { |
|
| 272 | 272 | return $this->error($e->getMessage()); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | ISecureRandom::CHAR_LOWER. |
| 300 | 300 | ISecureRandom::CHAR_UPPER |
| 301 | 301 | ); |
| 302 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 303 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 302 | + $tokenValue = $this->timeFactory->getTime().':'.$token; |
|
| 303 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email.$this->config->getSystemValue('secret')); |
|
| 304 | 304 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
| 305 | 305 | |
| 306 | 306 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
@@ -55,314 +55,314 @@ |
||
| 55 | 55 | */ |
| 56 | 56 | class LostController extends Controller { |
| 57 | 57 | |
| 58 | - /** @var IURLGenerator */ |
|
| 59 | - protected $urlGenerator; |
|
| 60 | - /** @var IUserManager */ |
|
| 61 | - protected $userManager; |
|
| 62 | - /** @var Defaults */ |
|
| 63 | - protected $defaults; |
|
| 64 | - /** @var IL10N */ |
|
| 65 | - protected $l10n; |
|
| 66 | - /** @var string */ |
|
| 67 | - protected $from; |
|
| 68 | - /** @var IManager */ |
|
| 69 | - protected $encryptionManager; |
|
| 70 | - /** @var IConfig */ |
|
| 71 | - protected $config; |
|
| 72 | - /** @var ISecureRandom */ |
|
| 73 | - protected $secureRandom; |
|
| 74 | - /** @var IMailer */ |
|
| 75 | - protected $mailer; |
|
| 76 | - /** @var ITimeFactory */ |
|
| 77 | - protected $timeFactory; |
|
| 78 | - /** @var ICrypto */ |
|
| 79 | - protected $crypto; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param string $appName |
|
| 83 | - * @param IRequest $request |
|
| 84 | - * @param IURLGenerator $urlGenerator |
|
| 85 | - * @param IUserManager $userManager |
|
| 86 | - * @param Defaults $defaults |
|
| 87 | - * @param IL10N $l10n |
|
| 88 | - * @param IConfig $config |
|
| 89 | - * @param ISecureRandom $secureRandom |
|
| 90 | - * @param string $defaultMailAddress |
|
| 91 | - * @param IManager $encryptionManager |
|
| 92 | - * @param IMailer $mailer |
|
| 93 | - * @param ITimeFactory $timeFactory |
|
| 94 | - * @param ICrypto $crypto |
|
| 95 | - */ |
|
| 96 | - public function __construct($appName, |
|
| 97 | - IRequest $request, |
|
| 98 | - IURLGenerator $urlGenerator, |
|
| 99 | - IUserManager $userManager, |
|
| 100 | - Defaults $defaults, |
|
| 101 | - IL10N $l10n, |
|
| 102 | - IConfig $config, |
|
| 103 | - ISecureRandom $secureRandom, |
|
| 104 | - $defaultMailAddress, |
|
| 105 | - IManager $encryptionManager, |
|
| 106 | - IMailer $mailer, |
|
| 107 | - ITimeFactory $timeFactory, |
|
| 108 | - ICrypto $crypto) { |
|
| 109 | - parent::__construct($appName, $request); |
|
| 110 | - $this->urlGenerator = $urlGenerator; |
|
| 111 | - $this->userManager = $userManager; |
|
| 112 | - $this->defaults = $defaults; |
|
| 113 | - $this->l10n = $l10n; |
|
| 114 | - $this->secureRandom = $secureRandom; |
|
| 115 | - $this->from = $defaultMailAddress; |
|
| 116 | - $this->encryptionManager = $encryptionManager; |
|
| 117 | - $this->config = $config; |
|
| 118 | - $this->mailer = $mailer; |
|
| 119 | - $this->timeFactory = $timeFactory; |
|
| 120 | - $this->crypto = $crypto; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Someone wants to reset their password: |
|
| 125 | - * |
|
| 126 | - * @PublicPage |
|
| 127 | - * @NoCSRFRequired |
|
| 128 | - * |
|
| 129 | - * @param string $token |
|
| 130 | - * @param string $userId |
|
| 131 | - * @return TemplateResponse |
|
| 132 | - */ |
|
| 133 | - public function resetform($token, $userId) { |
|
| 134 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 135 | - return new TemplateResponse('core', 'error', [ |
|
| 136 | - 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
| 137 | - ], |
|
| 138 | - 'guest' |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - try { |
|
| 143 | - $this->checkPasswordResetToken($token, $userId); |
|
| 144 | - } catch (\Exception $e) { |
|
| 145 | - return new TemplateResponse( |
|
| 146 | - 'core', 'error', [ |
|
| 147 | - "errors" => array(array("error" => $e->getMessage())) |
|
| 148 | - ], |
|
| 149 | - 'guest' |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return new TemplateResponse( |
|
| 154 | - 'core', |
|
| 155 | - 'lostpassword/resetpassword', |
|
| 156 | - array( |
|
| 157 | - 'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)), |
|
| 158 | - ), |
|
| 159 | - 'guest' |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param string $token |
|
| 165 | - * @param string $userId |
|
| 166 | - * @throws \Exception |
|
| 167 | - */ |
|
| 168 | - protected function checkPasswordResetToken($token, $userId) { |
|
| 169 | - $user = $this->userManager->get($userId); |
|
| 170 | - if($user === null || !$user->isEnabled()) { |
|
| 171 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - try { |
|
| 175 | - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
| 176 | - $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
| 177 | - $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
| 178 | - } catch (\Exception $e) { |
|
| 179 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $splittedToken = explode(':', $decryptedToken); |
|
| 183 | - if(count($splittedToken) !== 2) { |
|
| 184 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 188 | - $user->getLastLogin() > $splittedToken[0]) { |
|
| 189 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - if (!hash_equals($splittedToken[1], $token)) { |
|
| 193 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $message |
|
| 199 | - * @param array $additional |
|
| 200 | - * @return array |
|
| 201 | - */ |
|
| 202 | - private function error($message, array $additional=array()) { |
|
| 203 | - return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @return array |
|
| 208 | - */ |
|
| 209 | - private function success() { |
|
| 210 | - return array('status'=>'success'); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @PublicPage |
|
| 215 | - * @BruteForceProtection(action=passwordResetEmail) |
|
| 216 | - * @AnonRateThrottle(limit=10, period=300) |
|
| 217 | - * |
|
| 218 | - * @param string $user |
|
| 219 | - * @return JSONResponse |
|
| 220 | - */ |
|
| 221 | - public function email($user){ |
|
| 222 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 223 | - return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // FIXME: use HTTP error codes |
|
| 227 | - try { |
|
| 228 | - $this->sendEmail($user); |
|
| 229 | - } catch (\Exception $e){ |
|
| 230 | - $response = new JSONResponse($this->error($e->getMessage())); |
|
| 231 | - $response->throttle(); |
|
| 232 | - return $response; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $response = new JSONResponse($this->success()); |
|
| 236 | - $response->throttle(); |
|
| 237 | - return $response; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @PublicPage |
|
| 242 | - * @param string $token |
|
| 243 | - * @param string $userId |
|
| 244 | - * @param string $password |
|
| 245 | - * @param boolean $proceed |
|
| 246 | - * @return array |
|
| 247 | - */ |
|
| 248 | - public function setPassword($token, $userId, $password, $proceed) { |
|
| 249 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 250 | - return $this->error($this->l10n->t('Password reset is disabled')); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
| 254 | - return $this->error('', array('encryption' => true)); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - try { |
|
| 258 | - $this->checkPasswordResetToken($token, $userId); |
|
| 259 | - $user = $this->userManager->get($userId); |
|
| 260 | - |
|
| 261 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 262 | - |
|
| 263 | - if (!$user->setPassword($password)) { |
|
| 264 | - throw new \Exception(); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 268 | - |
|
| 269 | - $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
| 270 | - @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
| 271 | - } catch (\Exception $e){ |
|
| 272 | - return $this->error($e->getMessage()); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return $this->success(); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @param string $input |
|
| 280 | - * @throws \Exception |
|
| 281 | - */ |
|
| 282 | - protected function sendEmail($input) { |
|
| 283 | - $user = $this->findUserByIdOrMail($input); |
|
| 284 | - $email = $user->getEMailAddress(); |
|
| 285 | - |
|
| 286 | - if (empty($email)) { |
|
| 287 | - throw new \Exception( |
|
| 288 | - $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.') |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - // Generate the token. It is stored encrypted in the database with the |
|
| 293 | - // secret being the users' email address appended with the system secret. |
|
| 294 | - // This makes the token automatically invalidate once the user changes |
|
| 295 | - // their email address. |
|
| 296 | - $token = $this->secureRandom->generate( |
|
| 297 | - 21, |
|
| 298 | - ISecureRandom::CHAR_DIGITS. |
|
| 299 | - ISecureRandom::CHAR_LOWER. |
|
| 300 | - ISecureRandom::CHAR_UPPER |
|
| 301 | - ); |
|
| 302 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 303 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 304 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
| 305 | - |
|
| 306 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
|
| 307 | - |
|
| 308 | - $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
| 309 | - 'link' => $link, |
|
| 310 | - ]); |
|
| 311 | - |
|
| 312 | - $emailTemplate->addHeader(); |
|
| 313 | - $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
| 314 | - |
|
| 315 | - $emailTemplate->addBodyText( |
|
| 316 | - $this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.'), |
|
| 317 | - $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - $emailTemplate->addBodyButton( |
|
| 321 | - $this->l10n->t('Reset your password'), |
|
| 322 | - $link, |
|
| 323 | - false |
|
| 324 | - ); |
|
| 325 | - $emailTemplate->addFooter(); |
|
| 326 | - |
|
| 327 | - try { |
|
| 328 | - $message = $this->mailer->createMessage(); |
|
| 329 | - $message->setTo([$email => $user->getUID()]); |
|
| 330 | - $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
| 331 | - $message->setPlainBody($emailTemplate->renderText()); |
|
| 332 | - $message->setHtmlBody($emailTemplate->renderHtml()); |
|
| 333 | - $message->setFrom([$this->from => $this->defaults->getName()]); |
|
| 334 | - $this->mailer->send($message); |
|
| 335 | - } catch (\Exception $e) { |
|
| 336 | - throw new \Exception($this->l10n->t( |
|
| 337 | - 'Couldn\'t send reset email. Please contact your administrator.' |
|
| 338 | - )); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @param string $input |
|
| 344 | - * @return IUser |
|
| 345 | - * @throws \InvalidArgumentException |
|
| 346 | - */ |
|
| 347 | - protected function findUserByIdOrMail($input) { |
|
| 348 | - $user = $this->userManager->get($input); |
|
| 349 | - if ($user instanceof IUser) { |
|
| 350 | - if (!$user->isEnabled()) { |
|
| 351 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return $user; |
|
| 355 | - } |
|
| 356 | - $users = $this->userManager->getByEmail($input); |
|
| 357 | - if (count($users) === 1) { |
|
| 358 | - $user = $users[0]; |
|
| 359 | - if (!$user->isEnabled()) { |
|
| 360 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $user; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 367 | - } |
|
| 58 | + /** @var IURLGenerator */ |
|
| 59 | + protected $urlGenerator; |
|
| 60 | + /** @var IUserManager */ |
|
| 61 | + protected $userManager; |
|
| 62 | + /** @var Defaults */ |
|
| 63 | + protected $defaults; |
|
| 64 | + /** @var IL10N */ |
|
| 65 | + protected $l10n; |
|
| 66 | + /** @var string */ |
|
| 67 | + protected $from; |
|
| 68 | + /** @var IManager */ |
|
| 69 | + protected $encryptionManager; |
|
| 70 | + /** @var IConfig */ |
|
| 71 | + protected $config; |
|
| 72 | + /** @var ISecureRandom */ |
|
| 73 | + protected $secureRandom; |
|
| 74 | + /** @var IMailer */ |
|
| 75 | + protected $mailer; |
|
| 76 | + /** @var ITimeFactory */ |
|
| 77 | + protected $timeFactory; |
|
| 78 | + /** @var ICrypto */ |
|
| 79 | + protected $crypto; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param string $appName |
|
| 83 | + * @param IRequest $request |
|
| 84 | + * @param IURLGenerator $urlGenerator |
|
| 85 | + * @param IUserManager $userManager |
|
| 86 | + * @param Defaults $defaults |
|
| 87 | + * @param IL10N $l10n |
|
| 88 | + * @param IConfig $config |
|
| 89 | + * @param ISecureRandom $secureRandom |
|
| 90 | + * @param string $defaultMailAddress |
|
| 91 | + * @param IManager $encryptionManager |
|
| 92 | + * @param IMailer $mailer |
|
| 93 | + * @param ITimeFactory $timeFactory |
|
| 94 | + * @param ICrypto $crypto |
|
| 95 | + */ |
|
| 96 | + public function __construct($appName, |
|
| 97 | + IRequest $request, |
|
| 98 | + IURLGenerator $urlGenerator, |
|
| 99 | + IUserManager $userManager, |
|
| 100 | + Defaults $defaults, |
|
| 101 | + IL10N $l10n, |
|
| 102 | + IConfig $config, |
|
| 103 | + ISecureRandom $secureRandom, |
|
| 104 | + $defaultMailAddress, |
|
| 105 | + IManager $encryptionManager, |
|
| 106 | + IMailer $mailer, |
|
| 107 | + ITimeFactory $timeFactory, |
|
| 108 | + ICrypto $crypto) { |
|
| 109 | + parent::__construct($appName, $request); |
|
| 110 | + $this->urlGenerator = $urlGenerator; |
|
| 111 | + $this->userManager = $userManager; |
|
| 112 | + $this->defaults = $defaults; |
|
| 113 | + $this->l10n = $l10n; |
|
| 114 | + $this->secureRandom = $secureRandom; |
|
| 115 | + $this->from = $defaultMailAddress; |
|
| 116 | + $this->encryptionManager = $encryptionManager; |
|
| 117 | + $this->config = $config; |
|
| 118 | + $this->mailer = $mailer; |
|
| 119 | + $this->timeFactory = $timeFactory; |
|
| 120 | + $this->crypto = $crypto; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Someone wants to reset their password: |
|
| 125 | + * |
|
| 126 | + * @PublicPage |
|
| 127 | + * @NoCSRFRequired |
|
| 128 | + * |
|
| 129 | + * @param string $token |
|
| 130 | + * @param string $userId |
|
| 131 | + * @return TemplateResponse |
|
| 132 | + */ |
|
| 133 | + public function resetform($token, $userId) { |
|
| 134 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 135 | + return new TemplateResponse('core', 'error', [ |
|
| 136 | + 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
| 137 | + ], |
|
| 138 | + 'guest' |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + try { |
|
| 143 | + $this->checkPasswordResetToken($token, $userId); |
|
| 144 | + } catch (\Exception $e) { |
|
| 145 | + return new TemplateResponse( |
|
| 146 | + 'core', 'error', [ |
|
| 147 | + "errors" => array(array("error" => $e->getMessage())) |
|
| 148 | + ], |
|
| 149 | + 'guest' |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return new TemplateResponse( |
|
| 154 | + 'core', |
|
| 155 | + 'lostpassword/resetpassword', |
|
| 156 | + array( |
|
| 157 | + 'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)), |
|
| 158 | + ), |
|
| 159 | + 'guest' |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param string $token |
|
| 165 | + * @param string $userId |
|
| 166 | + * @throws \Exception |
|
| 167 | + */ |
|
| 168 | + protected function checkPasswordResetToken($token, $userId) { |
|
| 169 | + $user = $this->userManager->get($userId); |
|
| 170 | + if($user === null || !$user->isEnabled()) { |
|
| 171 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + try { |
|
| 175 | + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
| 176 | + $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
| 177 | + $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
| 178 | + } catch (\Exception $e) { |
|
| 179 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $splittedToken = explode(':', $decryptedToken); |
|
| 183 | + if(count($splittedToken) !== 2) { |
|
| 184 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 188 | + $user->getLastLogin() > $splittedToken[0]) { |
|
| 189 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + if (!hash_equals($splittedToken[1], $token)) { |
|
| 193 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $message |
|
| 199 | + * @param array $additional |
|
| 200 | + * @return array |
|
| 201 | + */ |
|
| 202 | + private function error($message, array $additional=array()) { |
|
| 203 | + return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @return array |
|
| 208 | + */ |
|
| 209 | + private function success() { |
|
| 210 | + return array('status'=>'success'); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @PublicPage |
|
| 215 | + * @BruteForceProtection(action=passwordResetEmail) |
|
| 216 | + * @AnonRateThrottle(limit=10, period=300) |
|
| 217 | + * |
|
| 218 | + * @param string $user |
|
| 219 | + * @return JSONResponse |
|
| 220 | + */ |
|
| 221 | + public function email($user){ |
|
| 222 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 223 | + return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // FIXME: use HTTP error codes |
|
| 227 | + try { |
|
| 228 | + $this->sendEmail($user); |
|
| 229 | + } catch (\Exception $e){ |
|
| 230 | + $response = new JSONResponse($this->error($e->getMessage())); |
|
| 231 | + $response->throttle(); |
|
| 232 | + return $response; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $response = new JSONResponse($this->success()); |
|
| 236 | + $response->throttle(); |
|
| 237 | + return $response; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @PublicPage |
|
| 242 | + * @param string $token |
|
| 243 | + * @param string $userId |
|
| 244 | + * @param string $password |
|
| 245 | + * @param boolean $proceed |
|
| 246 | + * @return array |
|
| 247 | + */ |
|
| 248 | + public function setPassword($token, $userId, $password, $proceed) { |
|
| 249 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 250 | + return $this->error($this->l10n->t('Password reset is disabled')); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
| 254 | + return $this->error('', array('encryption' => true)); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + try { |
|
| 258 | + $this->checkPasswordResetToken($token, $userId); |
|
| 259 | + $user = $this->userManager->get($userId); |
|
| 260 | + |
|
| 261 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 262 | + |
|
| 263 | + if (!$user->setPassword($password)) { |
|
| 264 | + throw new \Exception(); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 268 | + |
|
| 269 | + $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
| 270 | + @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
| 271 | + } catch (\Exception $e){ |
|
| 272 | + return $this->error($e->getMessage()); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return $this->success(); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @param string $input |
|
| 280 | + * @throws \Exception |
|
| 281 | + */ |
|
| 282 | + protected function sendEmail($input) { |
|
| 283 | + $user = $this->findUserByIdOrMail($input); |
|
| 284 | + $email = $user->getEMailAddress(); |
|
| 285 | + |
|
| 286 | + if (empty($email)) { |
|
| 287 | + throw new \Exception( |
|
| 288 | + $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.') |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + // Generate the token. It is stored encrypted in the database with the |
|
| 293 | + // secret being the users' email address appended with the system secret. |
|
| 294 | + // This makes the token automatically invalidate once the user changes |
|
| 295 | + // their email address. |
|
| 296 | + $token = $this->secureRandom->generate( |
|
| 297 | + 21, |
|
| 298 | + ISecureRandom::CHAR_DIGITS. |
|
| 299 | + ISecureRandom::CHAR_LOWER. |
|
| 300 | + ISecureRandom::CHAR_UPPER |
|
| 301 | + ); |
|
| 302 | + $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 303 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 304 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
| 305 | + |
|
| 306 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
|
| 307 | + |
|
| 308 | + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
| 309 | + 'link' => $link, |
|
| 310 | + ]); |
|
| 311 | + |
|
| 312 | + $emailTemplate->addHeader(); |
|
| 313 | + $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
| 314 | + |
|
| 315 | + $emailTemplate->addBodyText( |
|
| 316 | + $this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.'), |
|
| 317 | + $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + $emailTemplate->addBodyButton( |
|
| 321 | + $this->l10n->t('Reset your password'), |
|
| 322 | + $link, |
|
| 323 | + false |
|
| 324 | + ); |
|
| 325 | + $emailTemplate->addFooter(); |
|
| 326 | + |
|
| 327 | + try { |
|
| 328 | + $message = $this->mailer->createMessage(); |
|
| 329 | + $message->setTo([$email => $user->getUID()]); |
|
| 330 | + $message->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
| 331 | + $message->setPlainBody($emailTemplate->renderText()); |
|
| 332 | + $message->setHtmlBody($emailTemplate->renderHtml()); |
|
| 333 | + $message->setFrom([$this->from => $this->defaults->getName()]); |
|
| 334 | + $this->mailer->send($message); |
|
| 335 | + } catch (\Exception $e) { |
|
| 336 | + throw new \Exception($this->l10n->t( |
|
| 337 | + 'Couldn\'t send reset email. Please contact your administrator.' |
|
| 338 | + )); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @param string $input |
|
| 344 | + * @return IUser |
|
| 345 | + * @throws \InvalidArgumentException |
|
| 346 | + */ |
|
| 347 | + protected function findUserByIdOrMail($input) { |
|
| 348 | + $user = $this->userManager->get($input); |
|
| 349 | + if ($user instanceof IUser) { |
|
| 350 | + if (!$user->isEnabled()) { |
|
| 351 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return $user; |
|
| 355 | + } |
|
| 356 | + $users = $this->userManager->getByEmail($input); |
|
| 357 | + if (count($users) === 1) { |
|
| 358 | + $user = $users[0]; |
|
| 359 | + if (!$user->isEnabled()) { |
|
| 360 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $user; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 367 | + } |
|
| 368 | 368 | } |
@@ -89,6 +89,9 @@ discard block |
||
| 89 | 89 | return $this->getMountsFromQuery($query); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + /** |
|
| 93 | + * @param string $userId |
|
| 94 | + */ |
|
| 92 | 95 | public function getMountsForUser($userId, $groupIds) { |
| 93 | 96 | $builder = $this->connection->getQueryBuilder(); |
| 94 | 97 | $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
@@ -125,6 +128,10 @@ discard block |
||
| 125 | 128 | return $this->getMountsFromQuery($query); |
| 126 | 129 | } |
| 127 | 130 | |
| 131 | + /** |
|
| 132 | + * @param integer $type |
|
| 133 | + * @param string|null $value |
|
| 134 | + */ |
|
| 128 | 135 | protected function getForQuery(IQueryBuilder $builder, $type, $value) { |
| 129 | 136 | $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
| 130 | 137 | ->from('external_mounts', 'm') |
@@ -332,6 +339,9 @@ discard block |
||
| 332 | 339 | } |
| 333 | 340 | } |
| 334 | 341 | |
| 342 | + /** |
|
| 343 | + * @param integer $mountId |
|
| 344 | + */ |
|
| 335 | 345 | public function addApplicable($mountId, $type, $value) { |
| 336 | 346 | $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ |
| 337 | 347 | 'mount_id' => $mountId, |
@@ -340,6 +350,9 @@ discard block |
||
| 340 | 350 | ], ['mount_id', 'type', 'value']); |
| 341 | 351 | } |
| 342 | 352 | |
| 353 | + /** |
|
| 354 | + * @param integer $mountId |
|
| 355 | + */ |
|
| 343 | 356 | public function removeApplicable($mountId, $type, $value) { |
| 344 | 357 | $builder = $this->connection->getQueryBuilder(); |
| 345 | 358 | $query = $builder->delete('external_applicable') |
@@ -473,6 +486,9 @@ discard block |
||
| 473 | 486 | return array_combine($keys, $values); |
| 474 | 487 | } |
| 475 | 488 | |
| 489 | + /** |
|
| 490 | + * @param string $value |
|
| 491 | + */ |
|
| 476 | 492 | private function encryptValue($value) { |
| 477 | 493 | return $this->crypto->encrypt($value); |
| 478 | 494 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function getAdminMountsForMultiple($type, array $values) { |
| 180 | 180 | $builder = $this->connection->getQueryBuilder(); |
| 181 | - $params = array_map(function ($value) use ($builder) { |
|
| 181 | + $params = array_map(function($value) use ($builder) { |
|
| 182 | 182 | return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
| 183 | 183 | }, $values); |
| 184 | 184 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
| 232 | 232 | ]); |
| 233 | 233 | $query->execute(); |
| 234 | - return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 234 | + return (int) $this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | } |
| 368 | 368 | $uniqueMounts = array_values($uniqueMounts); |
| 369 | 369 | |
| 370 | - $mountIds = array_map(function ($mount) { |
|
| 370 | + $mountIds = array_map(function($mount) { |
|
| 371 | 371 | return $mount['mount_id']; |
| 372 | 372 | }, $uniqueMounts); |
| 373 | 373 | $mountIds = array_values(array_unique($mountIds)); |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | $config = $this->getConfigForMounts($mountIds); |
| 377 | 377 | $options = $this->getOptionsForMounts($mountIds); |
| 378 | 378 | |
| 379 | - return array_map(function ($mount, $applicable, $config, $options) { |
|
| 380 | - $mount['type'] = (int)$mount['type']; |
|
| 381 | - $mount['priority'] = (int)$mount['priority']; |
|
| 379 | + return array_map(function($mount, $applicable, $config, $options) { |
|
| 380 | + $mount['type'] = (int) $mount['type']; |
|
| 381 | + $mount['priority'] = (int) $mount['priority']; |
|
| 382 | 382 | $mount['applicable'] = $applicable; |
| 383 | 383 | $mount['config'] = $config; |
| 384 | 384 | $mount['options'] = $options; |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | } |
| 401 | 401 | $builder = $this->connection->getQueryBuilder(); |
| 402 | 402 | $fields[] = 'mount_id'; |
| 403 | - $placeHolders = array_map(function ($id) use ($builder) { |
|
| 403 | + $placeHolders = array_map(function($id) use ($builder) { |
|
| 404 | 404 | return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
| 405 | 405 | }, $mountIds); |
| 406 | 406 | $query = $builder->select($fields) |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | } |
| 415 | 415 | foreach ($rows as $row) { |
| 416 | 416 | if (isset($row['type'])) { |
| 417 | - $row['type'] = (int)$row['type']; |
|
| 417 | + $row['type'] = (int) $row['type']; |
|
| 418 | 418 | } |
| 419 | 419 | $result[$row['mount_id']][] = $row; |
| 420 | 420 | } |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | public function getOptionsForMounts($mountIds) { |
| 446 | 446 | $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
| 447 | 447 | $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
| 448 | - return array_map(function (array $options) { |
|
| 449 | - return array_map(function ($option) { |
|
| 448 | + return array_map(function(array $options) { |
|
| 449 | + return array_map(function($option) { |
|
| 450 | 450 | return json_decode($option); |
| 451 | 451 | }, $options); |
| 452 | 452 | }, $optionsMap); |
@@ -457,16 +457,16 @@ discard block |
||
| 457 | 457 | * @return array ['key1' => $value1, ...] |
| 458 | 458 | */ |
| 459 | 459 | private function createKeyValueMap(array $keyValuePairs) { |
| 460 | - $decryptedPairts = array_map(function ($pair) { |
|
| 460 | + $decryptedPairts = array_map(function($pair) { |
|
| 461 | 461 | if ($pair['key'] === 'password') { |
| 462 | 462 | $pair['value'] = $this->decryptValue($pair['value']); |
| 463 | 463 | } |
| 464 | 464 | return $pair; |
| 465 | 465 | }, $keyValuePairs); |
| 466 | - $keys = array_map(function ($pair) { |
|
| 466 | + $keys = array_map(function($pair) { |
|
| 467 | 467 | return $pair['key']; |
| 468 | 468 | }, $decryptedPairts); |
| 469 | - $values = array_map(function ($pair) { |
|
| 469 | + $values = array_map(function($pair) { |
|
| 470 | 470 | return $pair['value']; |
| 471 | 471 | }, $decryptedPairts); |
| 472 | 472 | |
@@ -32,460 +32,460 @@ |
||
| 32 | 32 | * Stores the mount config in the database |
| 33 | 33 | */ |
| 34 | 34 | class DBConfigService { |
| 35 | - const MOUNT_TYPE_ADMIN = 1; |
|
| 36 | - const MOUNT_TYPE_PERSONAl = 2; |
|
| 37 | - |
|
| 38 | - const APPLICABLE_TYPE_GLOBAL = 1; |
|
| 39 | - const APPLICABLE_TYPE_GROUP = 2; |
|
| 40 | - const APPLICABLE_TYPE_USER = 3; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var IDBConnection |
|
| 44 | - */ |
|
| 45 | - private $connection; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var ICrypto |
|
| 49 | - */ |
|
| 50 | - private $crypto; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * DBConfigService constructor. |
|
| 54 | - * |
|
| 55 | - * @param IDBConnection $connection |
|
| 56 | - * @param ICrypto $crypto |
|
| 57 | - */ |
|
| 58 | - public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
| 59 | - $this->connection = $connection; |
|
| 60 | - $this->crypto = $crypto; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param int $mountId |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function getMountById($mountId) { |
|
| 68 | - $builder = $this->connection->getQueryBuilder(); |
|
| 69 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 70 | - ->from('external_mounts', 'm') |
|
| 71 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 72 | - $mounts = $this->getMountsFromQuery($query); |
|
| 73 | - if (count($mounts) > 0) { |
|
| 74 | - return $mounts[0]; |
|
| 75 | - } else { |
|
| 76 | - return null; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get all configured mounts |
|
| 82 | - * |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public function getAllMounts() { |
|
| 86 | - $builder = $this->connection->getQueryBuilder(); |
|
| 87 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 88 | - ->from('external_mounts'); |
|
| 89 | - return $this->getMountsFromQuery($query); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function getMountsForUser($userId, $groupIds) { |
|
| 93 | - $builder = $this->connection->getQueryBuilder(); |
|
| 94 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 95 | - ->from('external_mounts', 'm') |
|
| 96 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 97 | - ->where($builder->expr()->orX( |
|
| 98 | - $builder->expr()->andX( // global mounts |
|
| 99 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)), |
|
| 100 | - $builder->expr()->isNull('a.value') |
|
| 101 | - ), |
|
| 102 | - $builder->expr()->andX( // mounts for user |
|
| 103 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)), |
|
| 104 | - $builder->expr()->eq('a.value', $builder->createNamedParameter($userId)) |
|
| 105 | - ), |
|
| 106 | - $builder->expr()->andX( // mounts for group |
|
| 107 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)), |
|
| 108 | - $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)) |
|
| 109 | - ) |
|
| 110 | - )); |
|
| 111 | - |
|
| 112 | - return $this->getMountsFromQuery($query); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Get admin defined mounts |
|
| 117 | - * |
|
| 118 | - * @return array |
|
| 119 | - * @suppress SqlInjectionChecker |
|
| 120 | - */ |
|
| 121 | - public function getAdminMounts() { |
|
| 122 | - $builder = $this->connection->getQueryBuilder(); |
|
| 123 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 124 | - ->from('external_mounts') |
|
| 125 | - ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 126 | - return $this->getMountsFromQuery($query); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function getForQuery(IQueryBuilder $builder, $type, $value) { |
|
| 130 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 131 | - ->from('external_mounts', 'm') |
|
| 132 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 133 | - ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 134 | - |
|
| 135 | - if (is_null($value)) { |
|
| 136 | - $query = $query->andWhere($builder->expr()->isNull('a.value')); |
|
| 137 | - } else { |
|
| 138 | - $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value))); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $query; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get mounts by applicable |
|
| 146 | - * |
|
| 147 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 148 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - public function getMountsFor($type, $value) { |
|
| 152 | - $builder = $this->connection->getQueryBuilder(); |
|
| 153 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 154 | - |
|
| 155 | - return $this->getMountsFromQuery($query); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get admin defined mounts by applicable |
|
| 160 | - * |
|
| 161 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 162 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 163 | - * @return array |
|
| 164 | - * @suppress SqlInjectionChecker |
|
| 165 | - */ |
|
| 166 | - public function getAdminMountsFor($type, $value) { |
|
| 167 | - $builder = $this->connection->getQueryBuilder(); |
|
| 168 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 169 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 170 | - |
|
| 171 | - return $this->getMountsFromQuery($query); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Get admin defined mounts for multiple applicable |
|
| 176 | - * |
|
| 177 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 178 | - * @param string[] $values user_ids or group_ids |
|
| 179 | - * @return array |
|
| 180 | - * @suppress SqlInjectionChecker |
|
| 181 | - */ |
|
| 182 | - public function getAdminMountsForMultiple($type, array $values) { |
|
| 183 | - $builder = $this->connection->getQueryBuilder(); |
|
| 184 | - $params = array_map(function ($value) use ($builder) { |
|
| 185 | - return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
|
| 186 | - }, $values); |
|
| 187 | - |
|
| 188 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 189 | - ->from('external_mounts', 'm') |
|
| 190 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 191 | - ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 192 | - ->andWhere($builder->expr()->in('a.value', $params)); |
|
| 193 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 194 | - |
|
| 195 | - return $this->getMountsFromQuery($query); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Get user defined mounts by applicable |
|
| 200 | - * |
|
| 201 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 202 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 203 | - * @return array |
|
| 204 | - * @suppress SqlInjectionChecker |
|
| 205 | - */ |
|
| 206 | - public function getUserMountsFor($type, $value) { |
|
| 207 | - $builder = $this->connection->getQueryBuilder(); |
|
| 208 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 209 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT))); |
|
| 210 | - |
|
| 211 | - return $this->getMountsFromQuery($query); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Add a mount to the database |
|
| 216 | - * |
|
| 217 | - * @param string $mountPoint |
|
| 218 | - * @param string $storageBackend |
|
| 219 | - * @param string $authBackend |
|
| 220 | - * @param int $priority |
|
| 221 | - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL |
|
| 222 | - * @return int the id of the new mount |
|
| 223 | - */ |
|
| 224 | - public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { |
|
| 225 | - if (!$priority) { |
|
| 226 | - $priority = 100; |
|
| 227 | - } |
|
| 228 | - $builder = $this->connection->getQueryBuilder(); |
|
| 229 | - $query = $builder->insert('external_mounts') |
|
| 230 | - ->values([ |
|
| 231 | - 'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR), |
|
| 232 | - 'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR), |
|
| 233 | - 'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR), |
|
| 234 | - 'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT), |
|
| 235 | - 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
|
| 236 | - ]); |
|
| 237 | - $query->execute(); |
|
| 238 | - return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Remove a mount from the database |
|
| 243 | - * |
|
| 244 | - * @param int $mountId |
|
| 245 | - */ |
|
| 246 | - public function removeMount($mountId) { |
|
| 247 | - $builder = $this->connection->getQueryBuilder(); |
|
| 248 | - $query = $builder->delete('external_mounts') |
|
| 249 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 250 | - $query->execute(); |
|
| 251 | - |
|
| 252 | - $query = $builder->delete('external_applicable') |
|
| 253 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 254 | - $query->execute(); |
|
| 255 | - |
|
| 256 | - $query = $builder->delete('external_config') |
|
| 257 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 258 | - $query->execute(); |
|
| 259 | - |
|
| 260 | - $query = $builder->delete('external_options') |
|
| 261 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 262 | - $query->execute(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @param int $mountId |
|
| 267 | - * @param string $newMountPoint |
|
| 268 | - */ |
|
| 269 | - public function setMountPoint($mountId, $newMountPoint) { |
|
| 270 | - $builder = $this->connection->getQueryBuilder(); |
|
| 271 | - |
|
| 272 | - $query = $builder->update('external_mounts') |
|
| 273 | - ->set('mount_point', $builder->createNamedParameter($newMountPoint)) |
|
| 274 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 275 | - |
|
| 276 | - $query->execute(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param int $mountId |
|
| 281 | - * @param string $newAuthBackend |
|
| 282 | - */ |
|
| 283 | - public function setAuthBackend($mountId, $newAuthBackend) { |
|
| 284 | - $builder = $this->connection->getQueryBuilder(); |
|
| 285 | - |
|
| 286 | - $query = $builder->update('external_mounts') |
|
| 287 | - ->set('auth_backend', $builder->createNamedParameter($newAuthBackend)) |
|
| 288 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 289 | - |
|
| 290 | - $query->execute(); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param int $mountId |
|
| 295 | - * @param string $key |
|
| 296 | - * @param string $value |
|
| 297 | - */ |
|
| 298 | - public function setConfig($mountId, $key, $value) { |
|
| 299 | - if ($key === 'password') { |
|
| 300 | - $value = $this->encryptValue($value); |
|
| 301 | - } |
|
| 302 | - $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ |
|
| 303 | - 'mount_id' => $mountId, |
|
| 304 | - 'key' => $key, |
|
| 305 | - 'value' => $value |
|
| 306 | - ], ['mount_id', 'key']); |
|
| 307 | - if ($count === 0) { |
|
| 308 | - $builder = $this->connection->getQueryBuilder(); |
|
| 309 | - $query = $builder->update('external_config') |
|
| 310 | - ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) |
|
| 311 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 312 | - ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 313 | - $query->execute(); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param int $mountId |
|
| 319 | - * @param string $key |
|
| 320 | - * @param string $value |
|
| 321 | - */ |
|
| 322 | - public function setOption($mountId, $key, $value) { |
|
| 323 | - |
|
| 324 | - $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ |
|
| 325 | - 'mount_id' => $mountId, |
|
| 326 | - 'key' => $key, |
|
| 327 | - 'value' => json_encode($value) |
|
| 328 | - ], ['mount_id', 'key']); |
|
| 329 | - if ($count === 0) { |
|
| 330 | - $builder = $this->connection->getQueryBuilder(); |
|
| 331 | - $query = $builder->update('external_options') |
|
| 332 | - ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) |
|
| 333 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 334 | - ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 335 | - $query->execute(); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - public function addApplicable($mountId, $type, $value) { |
|
| 340 | - $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ |
|
| 341 | - 'mount_id' => $mountId, |
|
| 342 | - 'type' => $type, |
|
| 343 | - 'value' => $value |
|
| 344 | - ], ['mount_id', 'type', 'value']); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - public function removeApplicable($mountId, $type, $value) { |
|
| 348 | - $builder = $this->connection->getQueryBuilder(); |
|
| 349 | - $query = $builder->delete('external_applicable') |
|
| 350 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 351 | - ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 352 | - |
|
| 353 | - if (is_null($value)) { |
|
| 354 | - $query = $query->andWhere($builder->expr()->isNull('value')); |
|
| 355 | - } else { |
|
| 356 | - $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $query->execute(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - private function getMountsFromQuery(IQueryBuilder $query) { |
|
| 363 | - $result = $query->execute(); |
|
| 364 | - $mounts = $result->fetchAll(); |
|
| 365 | - $uniqueMounts = []; |
|
| 366 | - foreach ($mounts as $mount) { |
|
| 367 | - $id = $mount['mount_id']; |
|
| 368 | - if (!isset($uniqueMounts[$id])) { |
|
| 369 | - $uniqueMounts[$id] = $mount; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - $uniqueMounts = array_values($uniqueMounts); |
|
| 373 | - |
|
| 374 | - $mountIds = array_map(function ($mount) { |
|
| 375 | - return $mount['mount_id']; |
|
| 376 | - }, $uniqueMounts); |
|
| 377 | - $mountIds = array_values(array_unique($mountIds)); |
|
| 378 | - |
|
| 379 | - $applicable = $this->getApplicableForMounts($mountIds); |
|
| 380 | - $config = $this->getConfigForMounts($mountIds); |
|
| 381 | - $options = $this->getOptionsForMounts($mountIds); |
|
| 382 | - |
|
| 383 | - return array_map(function ($mount, $applicable, $config, $options) { |
|
| 384 | - $mount['type'] = (int)$mount['type']; |
|
| 385 | - $mount['priority'] = (int)$mount['priority']; |
|
| 386 | - $mount['applicable'] = $applicable; |
|
| 387 | - $mount['config'] = $config; |
|
| 388 | - $mount['options'] = $options; |
|
| 389 | - return $mount; |
|
| 390 | - }, $uniqueMounts, $applicable, $config, $options); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Get mount options from a table grouped by mount id |
|
| 395 | - * |
|
| 396 | - * @param string $table |
|
| 397 | - * @param string[] $fields |
|
| 398 | - * @param int[] $mountIds |
|
| 399 | - * @return array [$mountId => [['field1' => $value1, ...], ...], ...] |
|
| 400 | - */ |
|
| 401 | - private function selectForMounts($table, array $fields, array $mountIds) { |
|
| 402 | - if (count($mountIds) === 0) { |
|
| 403 | - return []; |
|
| 404 | - } |
|
| 405 | - $builder = $this->connection->getQueryBuilder(); |
|
| 406 | - $fields[] = 'mount_id'; |
|
| 407 | - $placeHolders = array_map(function ($id) use ($builder) { |
|
| 408 | - return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
|
| 409 | - }, $mountIds); |
|
| 410 | - $query = $builder->select($fields) |
|
| 411 | - ->from($table) |
|
| 412 | - ->where($builder->expr()->in('mount_id', $placeHolders)); |
|
| 413 | - $rows = $query->execute()->fetchAll(); |
|
| 414 | - |
|
| 415 | - $result = []; |
|
| 416 | - foreach ($mountIds as $mountId) { |
|
| 417 | - $result[$mountId] = []; |
|
| 418 | - } |
|
| 419 | - foreach ($rows as $row) { |
|
| 420 | - if (isset($row['type'])) { |
|
| 421 | - $row['type'] = (int)$row['type']; |
|
| 422 | - } |
|
| 423 | - $result[$row['mount_id']][] = $row; |
|
| 424 | - } |
|
| 425 | - return $result; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param int[] $mountIds |
|
| 430 | - * @return array [$id => [['type' => $type, 'value' => $value], ...], ...] |
|
| 431 | - */ |
|
| 432 | - public function getApplicableForMounts($mountIds) { |
|
| 433 | - return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @param int[] $mountIds |
|
| 438 | - * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 439 | - */ |
|
| 440 | - public function getConfigForMounts($mountIds) { |
|
| 441 | - $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds); |
|
| 442 | - return array_map([$this, 'createKeyValueMap'], $mountConfigs); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param int[] $mountIds |
|
| 447 | - * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 448 | - */ |
|
| 449 | - public function getOptionsForMounts($mountIds) { |
|
| 450 | - $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
|
| 451 | - $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
|
| 452 | - return array_map(function (array $options) { |
|
| 453 | - return array_map(function ($option) { |
|
| 454 | - return json_decode($option); |
|
| 455 | - }, $options); |
|
| 456 | - }, $optionsMap); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...] |
|
| 461 | - * @return array ['key1' => $value1, ...] |
|
| 462 | - */ |
|
| 463 | - private function createKeyValueMap(array $keyValuePairs) { |
|
| 464 | - $decryptedPairts = array_map(function ($pair) { |
|
| 465 | - if ($pair['key'] === 'password') { |
|
| 466 | - $pair['value'] = $this->decryptValue($pair['value']); |
|
| 467 | - } |
|
| 468 | - return $pair; |
|
| 469 | - }, $keyValuePairs); |
|
| 470 | - $keys = array_map(function ($pair) { |
|
| 471 | - return $pair['key']; |
|
| 472 | - }, $decryptedPairts); |
|
| 473 | - $values = array_map(function ($pair) { |
|
| 474 | - return $pair['value']; |
|
| 475 | - }, $decryptedPairts); |
|
| 476 | - |
|
| 477 | - return array_combine($keys, $values); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - private function encryptValue($value) { |
|
| 481 | - return $this->crypto->encrypt($value); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - private function decryptValue($value) { |
|
| 485 | - try { |
|
| 486 | - return $this->crypto->decrypt($value); |
|
| 487 | - } catch (\Exception $e) { |
|
| 488 | - return $value; |
|
| 489 | - } |
|
| 490 | - } |
|
| 35 | + const MOUNT_TYPE_ADMIN = 1; |
|
| 36 | + const MOUNT_TYPE_PERSONAl = 2; |
|
| 37 | + |
|
| 38 | + const APPLICABLE_TYPE_GLOBAL = 1; |
|
| 39 | + const APPLICABLE_TYPE_GROUP = 2; |
|
| 40 | + const APPLICABLE_TYPE_USER = 3; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var IDBConnection |
|
| 44 | + */ |
|
| 45 | + private $connection; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var ICrypto |
|
| 49 | + */ |
|
| 50 | + private $crypto; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * DBConfigService constructor. |
|
| 54 | + * |
|
| 55 | + * @param IDBConnection $connection |
|
| 56 | + * @param ICrypto $crypto |
|
| 57 | + */ |
|
| 58 | + public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
| 59 | + $this->connection = $connection; |
|
| 60 | + $this->crypto = $crypto; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param int $mountId |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function getMountById($mountId) { |
|
| 68 | + $builder = $this->connection->getQueryBuilder(); |
|
| 69 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 70 | + ->from('external_mounts', 'm') |
|
| 71 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 72 | + $mounts = $this->getMountsFromQuery($query); |
|
| 73 | + if (count($mounts) > 0) { |
|
| 74 | + return $mounts[0]; |
|
| 75 | + } else { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get all configured mounts |
|
| 82 | + * |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public function getAllMounts() { |
|
| 86 | + $builder = $this->connection->getQueryBuilder(); |
|
| 87 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 88 | + ->from('external_mounts'); |
|
| 89 | + return $this->getMountsFromQuery($query); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function getMountsForUser($userId, $groupIds) { |
|
| 93 | + $builder = $this->connection->getQueryBuilder(); |
|
| 94 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 95 | + ->from('external_mounts', 'm') |
|
| 96 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 97 | + ->where($builder->expr()->orX( |
|
| 98 | + $builder->expr()->andX( // global mounts |
|
| 99 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)), |
|
| 100 | + $builder->expr()->isNull('a.value') |
|
| 101 | + ), |
|
| 102 | + $builder->expr()->andX( // mounts for user |
|
| 103 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)), |
|
| 104 | + $builder->expr()->eq('a.value', $builder->createNamedParameter($userId)) |
|
| 105 | + ), |
|
| 106 | + $builder->expr()->andX( // mounts for group |
|
| 107 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)), |
|
| 108 | + $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)) |
|
| 109 | + ) |
|
| 110 | + )); |
|
| 111 | + |
|
| 112 | + return $this->getMountsFromQuery($query); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Get admin defined mounts |
|
| 117 | + * |
|
| 118 | + * @return array |
|
| 119 | + * @suppress SqlInjectionChecker |
|
| 120 | + */ |
|
| 121 | + public function getAdminMounts() { |
|
| 122 | + $builder = $this->connection->getQueryBuilder(); |
|
| 123 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 124 | + ->from('external_mounts') |
|
| 125 | + ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 126 | + return $this->getMountsFromQuery($query); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function getForQuery(IQueryBuilder $builder, $type, $value) { |
|
| 130 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 131 | + ->from('external_mounts', 'm') |
|
| 132 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 133 | + ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 134 | + |
|
| 135 | + if (is_null($value)) { |
|
| 136 | + $query = $query->andWhere($builder->expr()->isNull('a.value')); |
|
| 137 | + } else { |
|
| 138 | + $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value))); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $query; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get mounts by applicable |
|
| 146 | + * |
|
| 147 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 148 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + public function getMountsFor($type, $value) { |
|
| 152 | + $builder = $this->connection->getQueryBuilder(); |
|
| 153 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 154 | + |
|
| 155 | + return $this->getMountsFromQuery($query); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get admin defined mounts by applicable |
|
| 160 | + * |
|
| 161 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 162 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 163 | + * @return array |
|
| 164 | + * @suppress SqlInjectionChecker |
|
| 165 | + */ |
|
| 166 | + public function getAdminMountsFor($type, $value) { |
|
| 167 | + $builder = $this->connection->getQueryBuilder(); |
|
| 168 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 169 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 170 | + |
|
| 171 | + return $this->getMountsFromQuery($query); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Get admin defined mounts for multiple applicable |
|
| 176 | + * |
|
| 177 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 178 | + * @param string[] $values user_ids or group_ids |
|
| 179 | + * @return array |
|
| 180 | + * @suppress SqlInjectionChecker |
|
| 181 | + */ |
|
| 182 | + public function getAdminMountsForMultiple($type, array $values) { |
|
| 183 | + $builder = $this->connection->getQueryBuilder(); |
|
| 184 | + $params = array_map(function ($value) use ($builder) { |
|
| 185 | + return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
|
| 186 | + }, $values); |
|
| 187 | + |
|
| 188 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 189 | + ->from('external_mounts', 'm') |
|
| 190 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 191 | + ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 192 | + ->andWhere($builder->expr()->in('a.value', $params)); |
|
| 193 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 194 | + |
|
| 195 | + return $this->getMountsFromQuery($query); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Get user defined mounts by applicable |
|
| 200 | + * |
|
| 201 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 202 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 203 | + * @return array |
|
| 204 | + * @suppress SqlInjectionChecker |
|
| 205 | + */ |
|
| 206 | + public function getUserMountsFor($type, $value) { |
|
| 207 | + $builder = $this->connection->getQueryBuilder(); |
|
| 208 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 209 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT))); |
|
| 210 | + |
|
| 211 | + return $this->getMountsFromQuery($query); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Add a mount to the database |
|
| 216 | + * |
|
| 217 | + * @param string $mountPoint |
|
| 218 | + * @param string $storageBackend |
|
| 219 | + * @param string $authBackend |
|
| 220 | + * @param int $priority |
|
| 221 | + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL |
|
| 222 | + * @return int the id of the new mount |
|
| 223 | + */ |
|
| 224 | + public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { |
|
| 225 | + if (!$priority) { |
|
| 226 | + $priority = 100; |
|
| 227 | + } |
|
| 228 | + $builder = $this->connection->getQueryBuilder(); |
|
| 229 | + $query = $builder->insert('external_mounts') |
|
| 230 | + ->values([ |
|
| 231 | + 'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR), |
|
| 232 | + 'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR), |
|
| 233 | + 'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR), |
|
| 234 | + 'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT), |
|
| 235 | + 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
|
| 236 | + ]); |
|
| 237 | + $query->execute(); |
|
| 238 | + return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Remove a mount from the database |
|
| 243 | + * |
|
| 244 | + * @param int $mountId |
|
| 245 | + */ |
|
| 246 | + public function removeMount($mountId) { |
|
| 247 | + $builder = $this->connection->getQueryBuilder(); |
|
| 248 | + $query = $builder->delete('external_mounts') |
|
| 249 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 250 | + $query->execute(); |
|
| 251 | + |
|
| 252 | + $query = $builder->delete('external_applicable') |
|
| 253 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 254 | + $query->execute(); |
|
| 255 | + |
|
| 256 | + $query = $builder->delete('external_config') |
|
| 257 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 258 | + $query->execute(); |
|
| 259 | + |
|
| 260 | + $query = $builder->delete('external_options') |
|
| 261 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 262 | + $query->execute(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @param int $mountId |
|
| 267 | + * @param string $newMountPoint |
|
| 268 | + */ |
|
| 269 | + public function setMountPoint($mountId, $newMountPoint) { |
|
| 270 | + $builder = $this->connection->getQueryBuilder(); |
|
| 271 | + |
|
| 272 | + $query = $builder->update('external_mounts') |
|
| 273 | + ->set('mount_point', $builder->createNamedParameter($newMountPoint)) |
|
| 274 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 275 | + |
|
| 276 | + $query->execute(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param int $mountId |
|
| 281 | + * @param string $newAuthBackend |
|
| 282 | + */ |
|
| 283 | + public function setAuthBackend($mountId, $newAuthBackend) { |
|
| 284 | + $builder = $this->connection->getQueryBuilder(); |
|
| 285 | + |
|
| 286 | + $query = $builder->update('external_mounts') |
|
| 287 | + ->set('auth_backend', $builder->createNamedParameter($newAuthBackend)) |
|
| 288 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 289 | + |
|
| 290 | + $query->execute(); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param int $mountId |
|
| 295 | + * @param string $key |
|
| 296 | + * @param string $value |
|
| 297 | + */ |
|
| 298 | + public function setConfig($mountId, $key, $value) { |
|
| 299 | + if ($key === 'password') { |
|
| 300 | + $value = $this->encryptValue($value); |
|
| 301 | + } |
|
| 302 | + $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ |
|
| 303 | + 'mount_id' => $mountId, |
|
| 304 | + 'key' => $key, |
|
| 305 | + 'value' => $value |
|
| 306 | + ], ['mount_id', 'key']); |
|
| 307 | + if ($count === 0) { |
|
| 308 | + $builder = $this->connection->getQueryBuilder(); |
|
| 309 | + $query = $builder->update('external_config') |
|
| 310 | + ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) |
|
| 311 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 312 | + ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 313 | + $query->execute(); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param int $mountId |
|
| 319 | + * @param string $key |
|
| 320 | + * @param string $value |
|
| 321 | + */ |
|
| 322 | + public function setOption($mountId, $key, $value) { |
|
| 323 | + |
|
| 324 | + $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ |
|
| 325 | + 'mount_id' => $mountId, |
|
| 326 | + 'key' => $key, |
|
| 327 | + 'value' => json_encode($value) |
|
| 328 | + ], ['mount_id', 'key']); |
|
| 329 | + if ($count === 0) { |
|
| 330 | + $builder = $this->connection->getQueryBuilder(); |
|
| 331 | + $query = $builder->update('external_options') |
|
| 332 | + ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) |
|
| 333 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 334 | + ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 335 | + $query->execute(); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + public function addApplicable($mountId, $type, $value) { |
|
| 340 | + $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ |
|
| 341 | + 'mount_id' => $mountId, |
|
| 342 | + 'type' => $type, |
|
| 343 | + 'value' => $value |
|
| 344 | + ], ['mount_id', 'type', 'value']); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + public function removeApplicable($mountId, $type, $value) { |
|
| 348 | + $builder = $this->connection->getQueryBuilder(); |
|
| 349 | + $query = $builder->delete('external_applicable') |
|
| 350 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 351 | + ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 352 | + |
|
| 353 | + if (is_null($value)) { |
|
| 354 | + $query = $query->andWhere($builder->expr()->isNull('value')); |
|
| 355 | + } else { |
|
| 356 | + $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $query->execute(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + private function getMountsFromQuery(IQueryBuilder $query) { |
|
| 363 | + $result = $query->execute(); |
|
| 364 | + $mounts = $result->fetchAll(); |
|
| 365 | + $uniqueMounts = []; |
|
| 366 | + foreach ($mounts as $mount) { |
|
| 367 | + $id = $mount['mount_id']; |
|
| 368 | + if (!isset($uniqueMounts[$id])) { |
|
| 369 | + $uniqueMounts[$id] = $mount; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + $uniqueMounts = array_values($uniqueMounts); |
|
| 373 | + |
|
| 374 | + $mountIds = array_map(function ($mount) { |
|
| 375 | + return $mount['mount_id']; |
|
| 376 | + }, $uniqueMounts); |
|
| 377 | + $mountIds = array_values(array_unique($mountIds)); |
|
| 378 | + |
|
| 379 | + $applicable = $this->getApplicableForMounts($mountIds); |
|
| 380 | + $config = $this->getConfigForMounts($mountIds); |
|
| 381 | + $options = $this->getOptionsForMounts($mountIds); |
|
| 382 | + |
|
| 383 | + return array_map(function ($mount, $applicable, $config, $options) { |
|
| 384 | + $mount['type'] = (int)$mount['type']; |
|
| 385 | + $mount['priority'] = (int)$mount['priority']; |
|
| 386 | + $mount['applicable'] = $applicable; |
|
| 387 | + $mount['config'] = $config; |
|
| 388 | + $mount['options'] = $options; |
|
| 389 | + return $mount; |
|
| 390 | + }, $uniqueMounts, $applicable, $config, $options); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Get mount options from a table grouped by mount id |
|
| 395 | + * |
|
| 396 | + * @param string $table |
|
| 397 | + * @param string[] $fields |
|
| 398 | + * @param int[] $mountIds |
|
| 399 | + * @return array [$mountId => [['field1' => $value1, ...], ...], ...] |
|
| 400 | + */ |
|
| 401 | + private function selectForMounts($table, array $fields, array $mountIds) { |
|
| 402 | + if (count($mountIds) === 0) { |
|
| 403 | + return []; |
|
| 404 | + } |
|
| 405 | + $builder = $this->connection->getQueryBuilder(); |
|
| 406 | + $fields[] = 'mount_id'; |
|
| 407 | + $placeHolders = array_map(function ($id) use ($builder) { |
|
| 408 | + return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
|
| 409 | + }, $mountIds); |
|
| 410 | + $query = $builder->select($fields) |
|
| 411 | + ->from($table) |
|
| 412 | + ->where($builder->expr()->in('mount_id', $placeHolders)); |
|
| 413 | + $rows = $query->execute()->fetchAll(); |
|
| 414 | + |
|
| 415 | + $result = []; |
|
| 416 | + foreach ($mountIds as $mountId) { |
|
| 417 | + $result[$mountId] = []; |
|
| 418 | + } |
|
| 419 | + foreach ($rows as $row) { |
|
| 420 | + if (isset($row['type'])) { |
|
| 421 | + $row['type'] = (int)$row['type']; |
|
| 422 | + } |
|
| 423 | + $result[$row['mount_id']][] = $row; |
|
| 424 | + } |
|
| 425 | + return $result; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @param int[] $mountIds |
|
| 430 | + * @return array [$id => [['type' => $type, 'value' => $value], ...], ...] |
|
| 431 | + */ |
|
| 432 | + public function getApplicableForMounts($mountIds) { |
|
| 433 | + return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @param int[] $mountIds |
|
| 438 | + * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 439 | + */ |
|
| 440 | + public function getConfigForMounts($mountIds) { |
|
| 441 | + $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds); |
|
| 442 | + return array_map([$this, 'createKeyValueMap'], $mountConfigs); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param int[] $mountIds |
|
| 447 | + * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 448 | + */ |
|
| 449 | + public function getOptionsForMounts($mountIds) { |
|
| 450 | + $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
|
| 451 | + $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
|
| 452 | + return array_map(function (array $options) { |
|
| 453 | + return array_map(function ($option) { |
|
| 454 | + return json_decode($option); |
|
| 455 | + }, $options); |
|
| 456 | + }, $optionsMap); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...] |
|
| 461 | + * @return array ['key1' => $value1, ...] |
|
| 462 | + */ |
|
| 463 | + private function createKeyValueMap(array $keyValuePairs) { |
|
| 464 | + $decryptedPairts = array_map(function ($pair) { |
|
| 465 | + if ($pair['key'] === 'password') { |
|
| 466 | + $pair['value'] = $this->decryptValue($pair['value']); |
|
| 467 | + } |
|
| 468 | + return $pair; |
|
| 469 | + }, $keyValuePairs); |
|
| 470 | + $keys = array_map(function ($pair) { |
|
| 471 | + return $pair['key']; |
|
| 472 | + }, $decryptedPairts); |
|
| 473 | + $values = array_map(function ($pair) { |
|
| 474 | + return $pair['value']; |
|
| 475 | + }, $decryptedPairts); |
|
| 476 | + |
|
| 477 | + return array_combine($keys, $values); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + private function encryptValue($value) { |
|
| 481 | + return $this->crypto->encrypt($value); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + private function decryptValue($value) { |
|
| 485 | + try { |
|
| 486 | + return $this->crypto->decrypt($value); |
|
| 487 | + } catch (\Exception $e) { |
|
| 488 | + return $value; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | 491 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | /** |
| 25 | 25 | * BaseResponse constructor. |
| 26 | 26 | * |
| 27 | - * @param DataResponse|null $dataResponse |
|
| 27 | + * @param DataResponse $dataResponse |
|
| 28 | 28 | * @param string $format |
| 29 | 29 | * @param string|null $statusMessage |
| 30 | 30 | * @param int|null $itemsCount |
@@ -27,70 +27,70 @@ |
||
| 27 | 27 | use OCP\AppFramework\Http\Response; |
| 28 | 28 | |
| 29 | 29 | abstract class BaseResponse extends Response { |
| 30 | - /** @var array */ |
|
| 31 | - protected $data; |
|
| 30 | + /** @var array */ |
|
| 31 | + protected $data; |
|
| 32 | 32 | |
| 33 | - /** @var string */ |
|
| 34 | - protected $format; |
|
| 33 | + /** @var string */ |
|
| 34 | + protected $format; |
|
| 35 | 35 | |
| 36 | - /** @var string */ |
|
| 37 | - protected $statusMessage; |
|
| 36 | + /** @var string */ |
|
| 37 | + protected $statusMessage; |
|
| 38 | 38 | |
| 39 | - /** @var int */ |
|
| 40 | - protected $itemsCount; |
|
| 39 | + /** @var int */ |
|
| 40 | + protected $itemsCount; |
|
| 41 | 41 | |
| 42 | - /** @var int */ |
|
| 43 | - protected $itemsPerPage; |
|
| 42 | + /** @var int */ |
|
| 43 | + protected $itemsPerPage; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * BaseResponse constructor. |
|
| 47 | - * |
|
| 48 | - * @param DataResponse|null $dataResponse |
|
| 49 | - * @param string $format |
|
| 50 | - * @param string|null $statusMessage |
|
| 51 | - * @param int|null $itemsCount |
|
| 52 | - * @param int|null $itemsPerPage |
|
| 53 | - */ |
|
| 54 | - public function __construct(DataResponse $dataResponse, |
|
| 55 | - $format = 'xml', |
|
| 56 | - $statusMessage = null, |
|
| 57 | - $itemsCount = null, |
|
| 58 | - $itemsPerPage = null) { |
|
| 59 | - $this->format = $format; |
|
| 60 | - $this->statusMessage = $statusMessage; |
|
| 61 | - $this->itemsCount = $itemsCount; |
|
| 62 | - $this->itemsPerPage = $itemsPerPage; |
|
| 45 | + /** |
|
| 46 | + * BaseResponse constructor. |
|
| 47 | + * |
|
| 48 | + * @param DataResponse|null $dataResponse |
|
| 49 | + * @param string $format |
|
| 50 | + * @param string|null $statusMessage |
|
| 51 | + * @param int|null $itemsCount |
|
| 52 | + * @param int|null $itemsPerPage |
|
| 53 | + */ |
|
| 54 | + public function __construct(DataResponse $dataResponse, |
|
| 55 | + $format = 'xml', |
|
| 56 | + $statusMessage = null, |
|
| 57 | + $itemsCount = null, |
|
| 58 | + $itemsPerPage = null) { |
|
| 59 | + $this->format = $format; |
|
| 60 | + $this->statusMessage = $statusMessage; |
|
| 61 | + $this->itemsCount = $itemsCount; |
|
| 62 | + $this->itemsPerPage = $itemsPerPage; |
|
| 63 | 63 | |
| 64 | - $this->data = $dataResponse->getData(); |
|
| 64 | + $this->data = $dataResponse->getData(); |
|
| 65 | 65 | |
| 66 | - $this->setHeaders($dataResponse->getHeaders()); |
|
| 67 | - $this->setStatus($dataResponse->getStatus()); |
|
| 68 | - $this->setETag($dataResponse->getETag()); |
|
| 69 | - $this->setLastModified($dataResponse->getLastModified()); |
|
| 70 | - $this->setCookies($dataResponse->getCookies()); |
|
| 71 | - $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 66 | + $this->setHeaders($dataResponse->getHeaders()); |
|
| 67 | + $this->setStatus($dataResponse->getStatus()); |
|
| 68 | + $this->setETag($dataResponse->getETag()); |
|
| 69 | + $this->setLastModified($dataResponse->getLastModified()); |
|
| 70 | + $this->setCookies($dataResponse->getCookies()); |
|
| 71 | + $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 72 | 72 | |
| 73 | - if ($format === 'json') { |
|
| 74 | - $this->addHeader( |
|
| 75 | - 'Content-Type', 'application/json; charset=utf-8' |
|
| 76 | - ); |
|
| 77 | - } else { |
|
| 78 | - $this->addHeader( |
|
| 79 | - 'Content-Type', 'application/xml; charset=utf-8' |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - } |
|
| 73 | + if ($format === 'json') { |
|
| 74 | + $this->addHeader( |
|
| 75 | + 'Content-Type', 'application/json; charset=utf-8' |
|
| 76 | + ); |
|
| 77 | + } else { |
|
| 78 | + $this->addHeader( |
|
| 79 | + 'Content-Type', 'application/xml; charset=utf-8' |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @param string[] $meta |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - protected function renderResult($meta) { |
|
| 89 | - // TODO rewrite functions |
|
| 90 | - return \OC_API::renderResult($this->format, $meta, $this->data); |
|
| 91 | - } |
|
| 84 | + /** |
|
| 85 | + * @param string[] $meta |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + protected function renderResult($meta) { |
|
| 89 | + // TODO rewrite functions |
|
| 90 | + return \OC_API::renderResult($this->format, $meta, $this->data); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function getOCSStatus() { |
|
| 94 | - return parent::getStatus(); |
|
| 95 | - } |
|
| 93 | + public function getOCSStatus() { |
|
| 94 | + return parent::getStatus(); |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | use OCP\AppFramework\Http\EmptyContentSecurityPolicy; |
| 27 | 27 | use OCP\AppFramework\Http\Response; |
| 28 | 28 | |
| 29 | -abstract class BaseResponse extends Response { |
|
| 29 | +abstract class BaseResponse extends Response { |
|
| 30 | 30 | /** @var array */ |
| 31 | 31 | protected $data; |
| 32 | 32 | |
@@ -1143,7 +1143,7 @@ discard block |
||
| 1143 | 1143 | * Get the certificate manager for the user |
| 1144 | 1144 | * |
| 1145 | 1145 | * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
| 1146 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1146 | + * @return null|CertificateManager | null if $uid is null and no user is logged in |
|
| 1147 | 1147 | */ |
| 1148 | 1148 | public function getCertificateManager($userId = '') { |
| 1149 | 1149 | if ($userId === '') { |
@@ -1464,6 +1464,7 @@ discard block |
||
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | /** |
| 1467 | + * @param string $app |
|
| 1467 | 1468 | * @return \OCP\Files\IAppData |
| 1468 | 1469 | */ |
| 1469 | 1470 | public function getAppDataDir($app) { |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | parent::__construct(); |
| 142 | 142 | $this->webRoot = $webRoot; |
| 143 | 143 | |
| 144 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 144 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
| 145 | 145 | return $c; |
| 146 | 146 | }); |
| 147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 152 | 152 | |
| 153 | 153 | |
| 154 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 154 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
| 155 | 155 | return new PreviewManager( |
| 156 | 156 | $c->getConfig(), |
| 157 | 157 | $c->getRootFolder(), |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | }); |
| 163 | 163 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
| 164 | 164 | |
| 165 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 165 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 166 | 166 | return new \OC\Preview\Watcher( |
| 167 | 167 | $c->getAppDataDir('preview') |
| 168 | 168 | ); |
| 169 | 169 | }); |
| 170 | 170 | |
| 171 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 171 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
| 172 | 172 | $view = new View(); |
| 173 | 173 | $util = new Encryption\Util( |
| 174 | 174 | $view, |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | ); |
| 187 | 187 | }); |
| 188 | 188 | |
| 189 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 189 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 190 | 190 | $util = new Encryption\Util( |
| 191 | 191 | new View(), |
| 192 | 192 | $c->getUserManager(), |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | ); |
| 201 | 201 | }); |
| 202 | 202 | |
| 203 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 203 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 204 | 204 | $view = new View(); |
| 205 | 205 | $util = new Encryption\Util( |
| 206 | 206 | $view, |
@@ -211,32 +211,32 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | return new Encryption\Keys\Storage($view, $util); |
| 213 | 213 | }); |
| 214 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 214 | + $this->registerService('TagMapper', function(Server $c) { |
|
| 215 | 215 | return new TagMapper($c->getDatabaseConnection()); |
| 216 | 216 | }); |
| 217 | 217 | |
| 218 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 218 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
| 219 | 219 | $tagMapper = $c->query('TagMapper'); |
| 220 | 220 | return new TagManager($tagMapper, $c->getUserSession()); |
| 221 | 221 | }); |
| 222 | 222 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
| 223 | 223 | |
| 224 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 224 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 225 | 225 | $config = $c->getConfig(); |
| 226 | 226 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
| 227 | 227 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
| 228 | 228 | $factory = new $factoryClass($this); |
| 229 | 229 | return $factory; |
| 230 | 230 | }); |
| 231 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 231 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
| 232 | 232 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 233 | 233 | }); |
| 234 | 234 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
| 235 | 235 | |
| 236 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 236 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
| 237 | 237 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 238 | 238 | }); |
| 239 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 239 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 240 | 240 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 241 | 241 | $view = new View(); |
| 242 | 242 | $root = new Root( |
@@ -257,37 +257,37 @@ discard block |
||
| 257 | 257 | }); |
| 258 | 258 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
| 259 | 259 | |
| 260 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 261 | - return new LazyRoot(function () use ($c) { |
|
| 260 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
| 261 | + return new LazyRoot(function() use ($c) { |
|
| 262 | 262 | return $c->query('RootFolder'); |
| 263 | 263 | }); |
| 264 | 264 | }); |
| 265 | 265 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
| 266 | 266 | |
| 267 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 267 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
| 268 | 268 | $config = $c->getConfig(); |
| 269 | 269 | return new \OC\User\Manager($config); |
| 270 | 270 | }); |
| 271 | 271 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
| 272 | 272 | |
| 273 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 273 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 274 | 274 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
| 275 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 275 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 276 | 276 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
| 277 | 277 | }); |
| 278 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 278 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
| 279 | 279 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
| 280 | 280 | }); |
| 281 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 281 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 282 | 282 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
| 283 | 283 | }); |
| 284 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 284 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 285 | 285 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
| 286 | 286 | }); |
| 287 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 287 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 288 | 288 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 289 | 289 | }); |
| 290 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 290 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 291 | 291 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 292 | 292 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 293 | 293 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | }); |
| 297 | 297 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
| 298 | 298 | |
| 299 | - $this->registerService(Store::class, function (Server $c) { |
|
| 299 | + $this->registerService(Store::class, function(Server $c) { |
|
| 300 | 300 | $session = $c->getSession(); |
| 301 | 301 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
| 302 | 302 | $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
@@ -307,11 +307,11 @@ discard block |
||
| 307 | 307 | return new Store($session, $logger, $tokenProvider); |
| 308 | 308 | }); |
| 309 | 309 | $this->registerAlias(IStore::class, Store::class); |
| 310 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 310 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
| 311 | 311 | $dbConnection = $c->getDatabaseConnection(); |
| 312 | 312 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
| 313 | 313 | }); |
| 314 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 314 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
| 315 | 315 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
| 316 | 316 | $crypto = $c->getCrypto(); |
| 317 | 317 | $config = $c->getConfig(); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | }); |
| 322 | 322 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
| 323 | 323 | |
| 324 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 324 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
| 325 | 325 | $manager = $c->getUserManager(); |
| 326 | 326 | $session = new \OC\Session\Memory(''); |
| 327 | 327 | $timeFactory = new TimeFactory(); |
@@ -334,44 +334,44 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
| 337 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 337 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 338 | 338 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 339 | 339 | }); |
| 340 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 340 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 341 | 341 | /** @var $user \OC\User\User */ |
| 342 | 342 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
| 343 | 343 | }); |
| 344 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 344 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
| 345 | 345 | /** @var $user \OC\User\User */ |
| 346 | 346 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
| 347 | 347 | }); |
| 348 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 348 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 349 | 349 | /** @var $user \OC\User\User */ |
| 350 | 350 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
| 351 | 351 | }); |
| 352 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 352 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 353 | 353 | /** @var $user \OC\User\User */ |
| 354 | 354 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 355 | 355 | }); |
| 356 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 356 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 357 | 357 | /** @var $user \OC\User\User */ |
| 358 | 358 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 359 | 359 | }); |
| 360 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 360 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 361 | 361 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 362 | 362 | }); |
| 363 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 363 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
| 364 | 364 | /** @var $user \OC\User\User */ |
| 365 | 365 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 366 | 366 | }); |
| 367 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 367 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 368 | 368 | /** @var $user \OC\User\User */ |
| 369 | 369 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 370 | 370 | }); |
| 371 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 371 | + $userSession->listen('\OC\User', 'logout', function() { |
|
| 372 | 372 | \OC_Hook::emit('OC_User', 'logout', array()); |
| 373 | 373 | }); |
| 374 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 374 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 375 | 375 | /** @var $user \OC\User\User */ |
| 376 | 376 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
| 377 | 377 | }); |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | }); |
| 380 | 380 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
| 381 | 381 | |
| 382 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 382 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
| 383 | 383 | return new \OC\Authentication\TwoFactorAuth\Manager( |
| 384 | 384 | $c->getAppManager(), |
| 385 | 385 | $c->getSession(), |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
| 395 | 395 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
| 396 | 396 | |
| 397 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 397 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
| 398 | 398 | return new \OC\AllConfig( |
| 399 | 399 | $c->getSystemConfig() |
| 400 | 400 | ); |
@@ -402,17 +402,17 @@ discard block |
||
| 402 | 402 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
| 403 | 403 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 404 | 404 | |
| 405 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 405 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
| 406 | 406 | return new \OC\SystemConfig($config); |
| 407 | 407 | }); |
| 408 | 408 | |
| 409 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 409 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
| 410 | 410 | return new \OC\AppConfig($c->getDatabaseConnection()); |
| 411 | 411 | }); |
| 412 | 412 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
| 413 | 413 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
| 414 | 414 | |
| 415 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 415 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
| 416 | 416 | return new \OC\L10N\Factory( |
| 417 | 417 | $c->getConfig(), |
| 418 | 418 | $c->getRequest(), |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | }); |
| 423 | 423 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
| 424 | 424 | |
| 425 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 425 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
| 426 | 426 | $config = $c->getConfig(); |
| 427 | 427 | $cacheFactory = $c->getMemCacheFactory(); |
| 428 | 428 | $request = $c->getRequest(); |
@@ -434,18 +434,18 @@ discard block |
||
| 434 | 434 | }); |
| 435 | 435 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
| 436 | 436 | |
| 437 | - $this->registerService('AppHelper', function ($c) { |
|
| 437 | + $this->registerService('AppHelper', function($c) { |
|
| 438 | 438 | return new \OC\AppHelper(); |
| 439 | 439 | }); |
| 440 | 440 | $this->registerAlias('AppFetcher', AppFetcher::class); |
| 441 | 441 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
| 442 | 442 | |
| 443 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 443 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
| 444 | 444 | return new Cache\File(); |
| 445 | 445 | }); |
| 446 | 446 | $this->registerAlias('UserCache', \OCP\ICache::class); |
| 447 | 447 | |
| 448 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 448 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 449 | 449 | |
| 450 | 450 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
| 451 | 451 | '\\OC\\Memcache\\ArrayCache', |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | $version = implode(',', $v); |
| 463 | 463 | $instanceId = \OC_Util::getInstanceId(); |
| 464 | 464 | $path = \OC::$SERVERROOT; |
| 465 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
| 465 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
| 466 | 466 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 467 | 467 | $config->getSystemValue('memcache.local', null), |
| 468 | 468 | $config->getSystemValue('memcache.distributed', null), |
@@ -475,12 +475,12 @@ discard block |
||
| 475 | 475 | $this->registerAlias('MemCacheFactory', Factory::class); |
| 476 | 476 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 477 | 477 | |
| 478 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 478 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 479 | 479 | $systemConfig = $c->getSystemConfig(); |
| 480 | 480 | return new RedisFactory($systemConfig); |
| 481 | 481 | }); |
| 482 | 482 | |
| 483 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 483 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 484 | 484 | return new \OC\Activity\Manager( |
| 485 | 485 | $c->getRequest(), |
| 486 | 486 | $c->getUserSession(), |
@@ -490,14 +490,14 @@ discard block |
||
| 490 | 490 | }); |
| 491 | 491 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 492 | 492 | |
| 493 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 493 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 494 | 494 | return new \OC\Activity\EventMerger( |
| 495 | 495 | $c->getL10N('lib') |
| 496 | 496 | ); |
| 497 | 497 | }); |
| 498 | 498 | $this->registerAlias(IValidator::class, Validator::class); |
| 499 | 499 | |
| 500 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 500 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
| 501 | 501 | return new AvatarManager( |
| 502 | 502 | $c->getUserManager(), |
| 503 | 503 | $c->getAppDataDir('avatar'), |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | }); |
| 509 | 509 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
| 510 | 510 | |
| 511 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 511 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
| 512 | 512 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
| 513 | 513 | $logger = Log::getLogClass($logType); |
| 514 | 514 | call_user_func(array($logger, 'init')); |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | }); |
| 518 | 518 | $this->registerAlias('Logger', \OCP\ILogger::class); |
| 519 | 519 | |
| 520 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 520 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
| 521 | 521 | $config = $c->getConfig(); |
| 522 | 522 | return new \OC\BackgroundJob\JobList( |
| 523 | 523 | $c->getDatabaseConnection(), |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | }); |
| 528 | 528 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
| 529 | 529 | |
| 530 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 530 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
| 531 | 531 | $cacheFactory = $c->getMemCacheFactory(); |
| 532 | 532 | $logger = $c->getLogger(); |
| 533 | 533 | if ($cacheFactory->isAvailable()) { |
@@ -539,12 +539,12 @@ discard block |
||
| 539 | 539 | }); |
| 540 | 540 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
| 541 | 541 | |
| 542 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 542 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
| 543 | 543 | return new Search(); |
| 544 | 544 | }); |
| 545 | 545 | $this->registerAlias('Search', \OCP\ISearch::class); |
| 546 | 546 | |
| 547 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
| 547 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
| 548 | 548 | return new \OC\Security\RateLimiting\Limiter( |
| 549 | 549 | $this->getUserSession(), |
| 550 | 550 | $this->getRequest(), |
@@ -552,34 +552,34 @@ discard block |
||
| 552 | 552 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
| 553 | 553 | ); |
| 554 | 554 | }); |
| 555 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 555 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 556 | 556 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
| 557 | 557 | $this->getMemCacheFactory(), |
| 558 | 558 | new \OC\AppFramework\Utility\TimeFactory() |
| 559 | 559 | ); |
| 560 | 560 | }); |
| 561 | 561 | |
| 562 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 562 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
| 563 | 563 | return new SecureRandom(); |
| 564 | 564 | }); |
| 565 | 565 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
| 566 | 566 | |
| 567 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 567 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
| 568 | 568 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
| 569 | 569 | }); |
| 570 | 570 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
| 571 | 571 | |
| 572 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 572 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
| 573 | 573 | return new Hasher($c->getConfig()); |
| 574 | 574 | }); |
| 575 | 575 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
| 576 | 576 | |
| 577 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 577 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
| 578 | 578 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
| 579 | 579 | }); |
| 580 | 580 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
| 581 | 581 | |
| 582 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 582 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 583 | 583 | $systemConfig = $c->getSystemConfig(); |
| 584 | 584 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 585 | 585 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | }); |
| 594 | 594 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
| 595 | 595 | |
| 596 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 596 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
| 597 | 597 | $config = $c->getConfig(); |
| 598 | 598 | return new HTTPHelper( |
| 599 | 599 | $config, |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | ); |
| 602 | 602 | }); |
| 603 | 603 | |
| 604 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 604 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
| 605 | 605 | $user = \OC_User::getUser(); |
| 606 | 606 | $uid = $user ? $user : null; |
| 607 | 607 | return new ClientService( |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | ); |
| 617 | 617 | }); |
| 618 | 618 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
| 619 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 619 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
| 620 | 620 | $eventLogger = new EventLogger(); |
| 621 | 621 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 622 | 622 | // In debug mode, module is being activated by default |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | }); |
| 627 | 627 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
| 628 | 628 | |
| 629 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 629 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
| 630 | 630 | $queryLogger = new QueryLogger(); |
| 631 | 631 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 632 | 632 | // In debug mode, module is being activated by default |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | }); |
| 637 | 637 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
| 638 | 638 | |
| 639 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 639 | + $this->registerService(TempManager::class, function(Server $c) { |
|
| 640 | 640 | return new TempManager( |
| 641 | 641 | $c->getLogger(), |
| 642 | 642 | $c->getConfig() |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | $this->registerAlias('TempManager', TempManager::class); |
| 646 | 646 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 647 | 647 | |
| 648 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 648 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 649 | 649 | return new \OC\App\AppManager( |
| 650 | 650 | $c->getUserSession(), |
| 651 | 651 | $c->getAppConfig(), |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | $this->registerAlias('AppManager', AppManager::class); |
| 658 | 658 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 659 | 659 | |
| 660 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 660 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
| 661 | 661 | return new DateTimeZone( |
| 662 | 662 | $c->getConfig(), |
| 663 | 663 | $c->getSession() |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | }); |
| 666 | 666 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
| 667 | 667 | |
| 668 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 668 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
| 669 | 669 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 670 | 670 | |
| 671 | 671 | return new DateTimeFormatter( |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | }); |
| 676 | 676 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
| 677 | 677 | |
| 678 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 678 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
| 679 | 679 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 680 | 680 | $listener = new UserMountCacheListener($mountCache); |
| 681 | 681 | $listener->listen($c->getUserManager()); |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | }); |
| 684 | 684 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
| 685 | 685 | |
| 686 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 686 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
| 687 | 687 | $loader = \OC\Files\Filesystem::getLoader(); |
| 688 | 688 | $mountCache = $c->query('UserMountCache'); |
| 689 | 689 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -699,10 +699,10 @@ discard block |
||
| 699 | 699 | }); |
| 700 | 700 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
| 701 | 701 | |
| 702 | - $this->registerService('IniWrapper', function ($c) { |
|
| 702 | + $this->registerService('IniWrapper', function($c) { |
|
| 703 | 703 | return new IniGetWrapper(); |
| 704 | 704 | }); |
| 705 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 705 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 706 | 706 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
| 707 | 707 | if ($busClass) { |
| 708 | 708 | list($app, $class) = explode('::', $busClass, 2); |
@@ -717,10 +717,10 @@ discard block |
||
| 717 | 717 | return new CronBus($jobList); |
| 718 | 718 | } |
| 719 | 719 | }); |
| 720 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 720 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
| 721 | 721 | return new TrustedDomainHelper($this->getConfig()); |
| 722 | 722 | }); |
| 723 | - $this->registerService('Throttler', function (Server $c) { |
|
| 723 | + $this->registerService('Throttler', function(Server $c) { |
|
| 724 | 724 | return new Throttler( |
| 725 | 725 | $c->getDatabaseConnection(), |
| 726 | 726 | new TimeFactory(), |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | $c->getConfig() |
| 729 | 729 | ); |
| 730 | 730 | }); |
| 731 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 731 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 732 | 732 | // IConfig and IAppManager requires a working database. This code |
| 733 | 733 | // might however be called when ownCloud is not yet setup. |
| 734 | 734 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | $c->getTempManager() |
| 750 | 750 | ); |
| 751 | 751 | }); |
| 752 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 752 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 753 | 753 | if (isset($this['urlParams'])) { |
| 754 | 754 | $urlParams = $this['urlParams']; |
| 755 | 755 | } else { |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | }); |
| 786 | 786 | $this->registerAlias('Request', \OCP\IRequest::class); |
| 787 | 787 | |
| 788 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 788 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
| 789 | 789 | return new Mailer( |
| 790 | 790 | $c->getConfig(), |
| 791 | 791 | $c->getLogger(), |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | }); |
| 797 | 797 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
| 798 | 798 | |
| 799 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 799 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 800 | 800 | $config = $c->getConfig(); |
| 801 | 801 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 802 | 802 | if (is_null($factoryClass)) { |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | $factory = new $factoryClass($this); |
| 807 | 807 | return $factory->getLDAPProvider(); |
| 808 | 808 | }); |
| 809 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 809 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
| 810 | 810 | $ini = $c->getIniWrapper(); |
| 811 | 811 | $config = $c->getConfig(); |
| 812 | 812 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -823,49 +823,49 @@ discard block |
||
| 823 | 823 | }); |
| 824 | 824 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
| 825 | 825 | |
| 826 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 826 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
| 827 | 827 | return new \OC\Files\Mount\Manager(); |
| 828 | 828 | }); |
| 829 | 829 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
| 830 | 830 | |
| 831 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 831 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
| 832 | 832 | return new \OC\Files\Type\Detection( |
| 833 | 833 | $c->getURLGenerator(), |
| 834 | 834 | \OC::$configDir, |
| 835 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 835 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 836 | 836 | ); |
| 837 | 837 | }); |
| 838 | 838 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
| 839 | 839 | |
| 840 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 840 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
| 841 | 841 | return new \OC\Files\Type\Loader( |
| 842 | 842 | $c->getDatabaseConnection() |
| 843 | 843 | ); |
| 844 | 844 | }); |
| 845 | 845 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
| 846 | - $this->registerService(BundleFetcher::class, function () { |
|
| 846 | + $this->registerService(BundleFetcher::class, function() { |
|
| 847 | 847 | return new BundleFetcher($this->getL10N('lib')); |
| 848 | 848 | }); |
| 849 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 849 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
| 850 | 850 | return new Manager( |
| 851 | 851 | $c->query(IValidator::class) |
| 852 | 852 | ); |
| 853 | 853 | }); |
| 854 | 854 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 855 | 855 | |
| 856 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 856 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
| 857 | 857 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
| 858 | - $manager->registerCapability(function () use ($c) { |
|
| 858 | + $manager->registerCapability(function() use ($c) { |
|
| 859 | 859 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 860 | 860 | }); |
| 861 | - $manager->registerCapability(function () use ($c) { |
|
| 861 | + $manager->registerCapability(function() use ($c) { |
|
| 862 | 862 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
| 863 | 863 | }); |
| 864 | 864 | return $manager; |
| 865 | 865 | }); |
| 866 | 866 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
| 867 | 867 | |
| 868 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 868 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 869 | 869 | $config = $c->getConfig(); |
| 870 | 870 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
| 871 | 871 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | }); |
| 875 | 875 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
| 876 | 876 | |
| 877 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 877 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 878 | 878 | /* |
| 879 | 879 | * Dark magic for autoloader. |
| 880 | 880 | * If we do a class_exists it will try to load the class which will |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | } |
| 901 | 901 | return new \OC_Defaults(); |
| 902 | 902 | }); |
| 903 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 903 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 904 | 904 | /** @var Factory $cacheFactory */ |
| 905 | 905 | $cacheFactory = $c->query(Factory::class); |
| 906 | 906 | return new SCSSCacher( |
@@ -913,13 +913,13 @@ discard block |
||
| 913 | 913 | $cacheFactory->create('SCSS') |
| 914 | 914 | ); |
| 915 | 915 | }); |
| 916 | - $this->registerService(EventDispatcher::class, function () { |
|
| 916 | + $this->registerService(EventDispatcher::class, function() { |
|
| 917 | 917 | return new EventDispatcher(); |
| 918 | 918 | }); |
| 919 | 919 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
| 920 | 920 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
| 921 | 921 | |
| 922 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 922 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 923 | 923 | // FIXME: Instantiiated here due to cyclic dependency |
| 924 | 924 | $request = new Request( |
| 925 | 925 | [ |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | $request |
| 945 | 945 | ); |
| 946 | 946 | }); |
| 947 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 947 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
| 948 | 948 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
| 949 | 949 | |
| 950 | 950 | return new CsrfTokenManager( |
@@ -952,22 +952,22 @@ discard block |
||
| 952 | 952 | $c->query(SessionStorage::class) |
| 953 | 953 | ); |
| 954 | 954 | }); |
| 955 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 955 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 956 | 956 | return new SessionStorage($c->getSession()); |
| 957 | 957 | }); |
| 958 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 958 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
| 959 | 959 | return new ContentSecurityPolicyManager(); |
| 960 | 960 | }); |
| 961 | 961 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
| 962 | 962 | |
| 963 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 963 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 964 | 964 | return new ContentSecurityPolicyNonceManager( |
| 965 | 965 | $c->getCsrfTokenManager(), |
| 966 | 966 | $c->getRequest() |
| 967 | 967 | ); |
| 968 | 968 | }); |
| 969 | 969 | |
| 970 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 970 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 971 | 971 | $config = $c->getConfig(); |
| 972 | 972 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
| 973 | 973 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | }); |
| 995 | 995 | $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
| 996 | 996 | |
| 997 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 997 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 998 | 998 | $manager = new \OC\Settings\Manager( |
| 999 | 999 | $c->getLogger(), |
| 1000 | 1000 | $c->getDatabaseConnection(), |
@@ -1014,29 +1014,29 @@ discard block |
||
| 1014 | 1014 | ); |
| 1015 | 1015 | return $manager; |
| 1016 | 1016 | }); |
| 1017 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1017 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 1018 | 1018 | return new \OC\Files\AppData\Factory( |
| 1019 | 1019 | $c->getRootFolder(), |
| 1020 | 1020 | $c->getSystemConfig() |
| 1021 | 1021 | ); |
| 1022 | 1022 | }); |
| 1023 | 1023 | |
| 1024 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1025 | - return new LockdownManager(function () use ($c) { |
|
| 1024 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 1025 | + return new LockdownManager(function() use ($c) { |
|
| 1026 | 1026 | return $c->getSession(); |
| 1027 | 1027 | }); |
| 1028 | 1028 | }); |
| 1029 | 1029 | |
| 1030 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1030 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 1031 | 1031 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 1032 | 1032 | }); |
| 1033 | 1033 | |
| 1034 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1034 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 1035 | 1035 | return new CloudIdManager(); |
| 1036 | 1036 | }); |
| 1037 | 1037 | |
| 1038 | 1038 | /* To trick DI since we don't extend the DIContainer here */ |
| 1039 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1039 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
| 1040 | 1040 | return new CleanPreviewsBackgroundJob( |
| 1041 | 1041 | $c->getRootFolder(), |
| 1042 | 1042 | $c->getLogger(), |
@@ -1051,18 +1051,18 @@ discard block |
||
| 1051 | 1051 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1052 | 1052 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1053 | 1053 | |
| 1054 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1054 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1055 | 1055 | return new Defaults( |
| 1056 | 1056 | $c->getThemingDefaults() |
| 1057 | 1057 | ); |
| 1058 | 1058 | }); |
| 1059 | 1059 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
| 1060 | 1060 | |
| 1061 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1061 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1062 | 1062 | return $c->query(\OCP\IUserSession::class)->getSession(); |
| 1063 | 1063 | }); |
| 1064 | 1064 | |
| 1065 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1065 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1066 | 1066 | return new ShareHelper( |
| 1067 | 1067 | $c->query(\OCP\Share\IManager::class) |
| 1068 | 1068 | ); |
@@ -1203,7 +1203,7 @@ discard block |
||
| 1203 | 1203 | * @deprecated since 9.2.0 use IAppData |
| 1204 | 1204 | */ |
| 1205 | 1205 | public function getAppFolder() { |
| 1206 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1206 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
| 1207 | 1207 | $root = $this->getRootFolder(); |
| 1208 | 1208 | if (!$root->nodeExists($dir)) { |
| 1209 | 1209 | $folder = $root->newFolder($dir); |
@@ -99,7 +99,6 @@ |
||
| 99 | 99 | use OC\Tagging\TagMapper; |
| 100 | 100 | use OC\Template\SCSSCacher; |
| 101 | 101 | use OCA\Theming\ThemingDefaults; |
| 102 | - |
|
| 103 | 102 | use OCP\App\IAppManager; |
| 104 | 103 | use OCP\AppFramework\Utility\ITimeFactory; |
| 105 | 104 | use OCP\Defaults; |
@@ -127,1691 +127,1691 @@ |
||
| 127 | 127 | * TODO: hookup all manager classes |
| 128 | 128 | */ |
| 129 | 129 | class Server extends ServerContainer implements IServerContainer { |
| 130 | - /** @var string */ |
|
| 131 | - private $webRoot; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param string $webRoot |
|
| 135 | - * @param \OC\Config $config |
|
| 136 | - */ |
|
| 137 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 138 | - parent::__construct(); |
|
| 139 | - $this->webRoot = $webRoot; |
|
| 140 | - |
|
| 141 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 142 | - return $c; |
|
| 143 | - }); |
|
| 144 | - |
|
| 145 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 146 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 147 | - |
|
| 148 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 152 | - return new PreviewManager( |
|
| 153 | - $c->getConfig(), |
|
| 154 | - $c->getRootFolder(), |
|
| 155 | - $c->getAppDataDir('preview'), |
|
| 156 | - $c->getEventDispatcher(), |
|
| 157 | - $c->getSession()->get('user_id') |
|
| 158 | - ); |
|
| 159 | - }); |
|
| 160 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 161 | - |
|
| 162 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 163 | - return new \OC\Preview\Watcher( |
|
| 164 | - $c->getAppDataDir('preview') |
|
| 165 | - ); |
|
| 166 | - }); |
|
| 167 | - |
|
| 168 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 169 | - $view = new View(); |
|
| 170 | - $util = new Encryption\Util( |
|
| 171 | - $view, |
|
| 172 | - $c->getUserManager(), |
|
| 173 | - $c->getGroupManager(), |
|
| 174 | - $c->getConfig() |
|
| 175 | - ); |
|
| 176 | - return new Encryption\Manager( |
|
| 177 | - $c->getConfig(), |
|
| 178 | - $c->getLogger(), |
|
| 179 | - $c->getL10N('core'), |
|
| 180 | - new View(), |
|
| 181 | - $util, |
|
| 182 | - new ArrayCache() |
|
| 183 | - ); |
|
| 184 | - }); |
|
| 185 | - |
|
| 186 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 187 | - $util = new Encryption\Util( |
|
| 188 | - new View(), |
|
| 189 | - $c->getUserManager(), |
|
| 190 | - $c->getGroupManager(), |
|
| 191 | - $c->getConfig() |
|
| 192 | - ); |
|
| 193 | - return new Encryption\File( |
|
| 194 | - $util, |
|
| 195 | - $c->getRootFolder(), |
|
| 196 | - $c->getShareManager() |
|
| 197 | - ); |
|
| 198 | - }); |
|
| 199 | - |
|
| 200 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 201 | - $view = new View(); |
|
| 202 | - $util = new Encryption\Util( |
|
| 203 | - $view, |
|
| 204 | - $c->getUserManager(), |
|
| 205 | - $c->getGroupManager(), |
|
| 206 | - $c->getConfig() |
|
| 207 | - ); |
|
| 208 | - |
|
| 209 | - return new Encryption\Keys\Storage($view, $util); |
|
| 210 | - }); |
|
| 211 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 212 | - return new TagMapper($c->getDatabaseConnection()); |
|
| 213 | - }); |
|
| 214 | - |
|
| 215 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 216 | - $tagMapper = $c->query('TagMapper'); |
|
| 217 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
| 218 | - }); |
|
| 219 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 220 | - |
|
| 221 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 222 | - $config = $c->getConfig(); |
|
| 223 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
| 224 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
| 225 | - $factory = new $factoryClass($this); |
|
| 226 | - return $factory; |
|
| 227 | - }); |
|
| 228 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 229 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 230 | - }); |
|
| 231 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 232 | - |
|
| 233 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 234 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 235 | - }); |
|
| 236 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 237 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 238 | - $view = new View(); |
|
| 239 | - $root = new Root( |
|
| 240 | - $manager, |
|
| 241 | - $view, |
|
| 242 | - null, |
|
| 243 | - $c->getUserMountCache(), |
|
| 244 | - $this->getLogger(), |
|
| 245 | - $this->getUserManager() |
|
| 246 | - ); |
|
| 247 | - $connector = new HookConnector($root, $view); |
|
| 248 | - $connector->viewToNode(); |
|
| 249 | - |
|
| 250 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 251 | - $previewConnector->connectWatcher(); |
|
| 252 | - |
|
| 253 | - return $root; |
|
| 254 | - }); |
|
| 255 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 256 | - |
|
| 257 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 258 | - return new LazyRoot(function () use ($c) { |
|
| 259 | - return $c->query('RootFolder'); |
|
| 260 | - }); |
|
| 261 | - }); |
|
| 262 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 263 | - |
|
| 264 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 265 | - $config = $c->getConfig(); |
|
| 266 | - return new \OC\User\Manager($config); |
|
| 267 | - }); |
|
| 268 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
| 269 | - |
|
| 270 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 271 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 272 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 273 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 274 | - }); |
|
| 275 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 276 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 277 | - }); |
|
| 278 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 279 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 280 | - }); |
|
| 281 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 282 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 283 | - }); |
|
| 284 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 285 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 286 | - }); |
|
| 287 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 288 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 289 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 290 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 291 | - }); |
|
| 292 | - return $groupManager; |
|
| 293 | - }); |
|
| 294 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 295 | - |
|
| 296 | - $this->registerService(Store::class, function (Server $c) { |
|
| 297 | - $session = $c->getSession(); |
|
| 298 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 299 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 300 | - } else { |
|
| 301 | - $tokenProvider = null; |
|
| 302 | - } |
|
| 303 | - $logger = $c->getLogger(); |
|
| 304 | - return new Store($session, $logger, $tokenProvider); |
|
| 305 | - }); |
|
| 306 | - $this->registerAlias(IStore::class, Store::class); |
|
| 307 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 308 | - $dbConnection = $c->getDatabaseConnection(); |
|
| 309 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 310 | - }); |
|
| 311 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 312 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
| 313 | - $crypto = $c->getCrypto(); |
|
| 314 | - $config = $c->getConfig(); |
|
| 315 | - $logger = $c->getLogger(); |
|
| 316 | - $timeFactory = new TimeFactory(); |
|
| 317 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 318 | - }); |
|
| 319 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
| 320 | - |
|
| 321 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 322 | - $manager = $c->getUserManager(); |
|
| 323 | - $session = new \OC\Session\Memory(''); |
|
| 324 | - $timeFactory = new TimeFactory(); |
|
| 325 | - // Token providers might require a working database. This code |
|
| 326 | - // might however be called when ownCloud is not yet setup. |
|
| 327 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 328 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 329 | - } else { |
|
| 330 | - $defaultTokenProvider = null; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
| 334 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 335 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 336 | - }); |
|
| 337 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 338 | - /** @var $user \OC\User\User */ |
|
| 339 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 340 | - }); |
|
| 341 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 342 | - /** @var $user \OC\User\User */ |
|
| 343 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 344 | - }); |
|
| 345 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 346 | - /** @var $user \OC\User\User */ |
|
| 347 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 348 | - }); |
|
| 349 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 350 | - /** @var $user \OC\User\User */ |
|
| 351 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 352 | - }); |
|
| 353 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 354 | - /** @var $user \OC\User\User */ |
|
| 355 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 356 | - }); |
|
| 357 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 358 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 359 | - }); |
|
| 360 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 361 | - /** @var $user \OC\User\User */ |
|
| 362 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 363 | - }); |
|
| 364 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 365 | - /** @var $user \OC\User\User */ |
|
| 366 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 367 | - }); |
|
| 368 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 369 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 370 | - }); |
|
| 371 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 372 | - /** @var $user \OC\User\User */ |
|
| 373 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 374 | - }); |
|
| 375 | - return $userSession; |
|
| 376 | - }); |
|
| 377 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 378 | - |
|
| 379 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 380 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
| 381 | - $c->getAppManager(), |
|
| 382 | - $c->getSession(), |
|
| 383 | - $c->getConfig(), |
|
| 384 | - $c->getActivityManager(), |
|
| 385 | - $c->getLogger(), |
|
| 386 | - $c->query(\OC\Authentication\Token\IProvider::class), |
|
| 387 | - $c->query(ITimeFactory::class) |
|
| 388 | - ); |
|
| 389 | - }); |
|
| 390 | - |
|
| 391 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 392 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 393 | - |
|
| 394 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 395 | - return new \OC\AllConfig( |
|
| 396 | - $c->getSystemConfig() |
|
| 397 | - ); |
|
| 398 | - }); |
|
| 399 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 400 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 401 | - |
|
| 402 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 403 | - return new \OC\SystemConfig($config); |
|
| 404 | - }); |
|
| 405 | - |
|
| 406 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 407 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 408 | - }); |
|
| 409 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 410 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 411 | - |
|
| 412 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 413 | - return new \OC\L10N\Factory( |
|
| 414 | - $c->getConfig(), |
|
| 415 | - $c->getRequest(), |
|
| 416 | - $c->getUserSession(), |
|
| 417 | - \OC::$SERVERROOT |
|
| 418 | - ); |
|
| 419 | - }); |
|
| 420 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 421 | - |
|
| 422 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 423 | - $config = $c->getConfig(); |
|
| 424 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 425 | - $request = $c->getRequest(); |
|
| 426 | - return new \OC\URLGenerator( |
|
| 427 | - $config, |
|
| 428 | - $cacheFactory, |
|
| 429 | - $request |
|
| 430 | - ); |
|
| 431 | - }); |
|
| 432 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 433 | - |
|
| 434 | - $this->registerService('AppHelper', function ($c) { |
|
| 435 | - return new \OC\AppHelper(); |
|
| 436 | - }); |
|
| 437 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 438 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 439 | - |
|
| 440 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 441 | - return new Cache\File(); |
|
| 442 | - }); |
|
| 443 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 444 | - |
|
| 445 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 446 | - |
|
| 447 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 448 | - '\\OC\\Memcache\\ArrayCache', |
|
| 449 | - '\\OC\\Memcache\\ArrayCache', |
|
| 450 | - '\\OC\\Memcache\\ArrayCache' |
|
| 451 | - ); |
|
| 452 | - $config = $c->getConfig(); |
|
| 453 | - $request = $c->getRequest(); |
|
| 454 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
| 455 | - |
|
| 456 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 457 | - $v = \OC_App::getAppVersions(); |
|
| 458 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 459 | - $version = implode(',', $v); |
|
| 460 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 461 | - $path = \OC::$SERVERROOT; |
|
| 462 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
| 463 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 464 | - $config->getSystemValue('memcache.local', null), |
|
| 465 | - $config->getSystemValue('memcache.distributed', null), |
|
| 466 | - $config->getSystemValue('memcache.locking', null) |
|
| 467 | - ); |
|
| 468 | - } |
|
| 469 | - return $arrayCacheFactory; |
|
| 470 | - |
|
| 471 | - }); |
|
| 472 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 473 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 474 | - |
|
| 475 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 476 | - $systemConfig = $c->getSystemConfig(); |
|
| 477 | - return new RedisFactory($systemConfig); |
|
| 478 | - }); |
|
| 479 | - |
|
| 480 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 481 | - return new \OC\Activity\Manager( |
|
| 482 | - $c->getRequest(), |
|
| 483 | - $c->getUserSession(), |
|
| 484 | - $c->getConfig(), |
|
| 485 | - $c->query(IValidator::class) |
|
| 486 | - ); |
|
| 487 | - }); |
|
| 488 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 489 | - |
|
| 490 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 491 | - return new \OC\Activity\EventMerger( |
|
| 492 | - $c->getL10N('lib') |
|
| 493 | - ); |
|
| 494 | - }); |
|
| 495 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 496 | - |
|
| 497 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 498 | - return new AvatarManager( |
|
| 499 | - $c->getUserManager(), |
|
| 500 | - $c->getAppDataDir('avatar'), |
|
| 501 | - $c->getL10N('lib'), |
|
| 502 | - $c->getLogger(), |
|
| 503 | - $c->getConfig() |
|
| 504 | - ); |
|
| 505 | - }); |
|
| 506 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 507 | - |
|
| 508 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 509 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 510 | - $logger = Log::getLogClass($logType); |
|
| 511 | - call_user_func(array($logger, 'init')); |
|
| 512 | - |
|
| 513 | - return new Log($logger); |
|
| 514 | - }); |
|
| 515 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 516 | - |
|
| 517 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 518 | - $config = $c->getConfig(); |
|
| 519 | - return new \OC\BackgroundJob\JobList( |
|
| 520 | - $c->getDatabaseConnection(), |
|
| 521 | - $config, |
|
| 522 | - new TimeFactory() |
|
| 523 | - ); |
|
| 524 | - }); |
|
| 525 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 526 | - |
|
| 527 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 528 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 529 | - $logger = $c->getLogger(); |
|
| 530 | - if ($cacheFactory->isAvailable()) { |
|
| 531 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 532 | - } else { |
|
| 533 | - $router = new \OC\Route\Router($logger); |
|
| 534 | - } |
|
| 535 | - return $router; |
|
| 536 | - }); |
|
| 537 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 538 | - |
|
| 539 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 540 | - return new Search(); |
|
| 541 | - }); |
|
| 542 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 543 | - |
|
| 544 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
| 545 | - return new \OC\Security\RateLimiting\Limiter( |
|
| 546 | - $this->getUserSession(), |
|
| 547 | - $this->getRequest(), |
|
| 548 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 549 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 550 | - ); |
|
| 551 | - }); |
|
| 552 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 553 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 554 | - $this->getMemCacheFactory(), |
|
| 555 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 556 | - ); |
|
| 557 | - }); |
|
| 558 | - |
|
| 559 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 560 | - return new SecureRandom(); |
|
| 561 | - }); |
|
| 562 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 563 | - |
|
| 564 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 565 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 566 | - }); |
|
| 567 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 568 | - |
|
| 569 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 570 | - return new Hasher($c->getConfig()); |
|
| 571 | - }); |
|
| 572 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 573 | - |
|
| 574 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 575 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 576 | - }); |
|
| 577 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 578 | - |
|
| 579 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 580 | - $systemConfig = $c->getSystemConfig(); |
|
| 581 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 582 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 583 | - if (!$factory->isValidType($type)) { |
|
| 584 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 585 | - } |
|
| 586 | - $connectionParams = $factory->createConnectionParams(); |
|
| 587 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 588 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 589 | - return $connection; |
|
| 590 | - }); |
|
| 591 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 592 | - |
|
| 593 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 594 | - $config = $c->getConfig(); |
|
| 595 | - return new HTTPHelper( |
|
| 596 | - $config, |
|
| 597 | - $c->getHTTPClientService() |
|
| 598 | - ); |
|
| 599 | - }); |
|
| 600 | - |
|
| 601 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 602 | - $user = \OC_User::getUser(); |
|
| 603 | - $uid = $user ? $user : null; |
|
| 604 | - return new ClientService( |
|
| 605 | - $c->getConfig(), |
|
| 606 | - new \OC\Security\CertificateManager( |
|
| 607 | - $uid, |
|
| 608 | - new View(), |
|
| 609 | - $c->getConfig(), |
|
| 610 | - $c->getLogger(), |
|
| 611 | - $c->getSecureRandom() |
|
| 612 | - ) |
|
| 613 | - ); |
|
| 614 | - }); |
|
| 615 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 616 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 617 | - $eventLogger = new EventLogger(); |
|
| 618 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 619 | - // In debug mode, module is being activated by default |
|
| 620 | - $eventLogger->activate(); |
|
| 621 | - } |
|
| 622 | - return $eventLogger; |
|
| 623 | - }); |
|
| 624 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 625 | - |
|
| 626 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 627 | - $queryLogger = new QueryLogger(); |
|
| 628 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 629 | - // In debug mode, module is being activated by default |
|
| 630 | - $queryLogger->activate(); |
|
| 631 | - } |
|
| 632 | - return $queryLogger; |
|
| 633 | - }); |
|
| 634 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 635 | - |
|
| 636 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 637 | - return new TempManager( |
|
| 638 | - $c->getLogger(), |
|
| 639 | - $c->getConfig() |
|
| 640 | - ); |
|
| 641 | - }); |
|
| 642 | - $this->registerAlias('TempManager', TempManager::class); |
|
| 643 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 644 | - |
|
| 645 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 646 | - return new \OC\App\AppManager( |
|
| 647 | - $c->getUserSession(), |
|
| 648 | - $c->getAppConfig(), |
|
| 649 | - $c->getGroupManager(), |
|
| 650 | - $c->getMemCacheFactory(), |
|
| 651 | - $c->getEventDispatcher() |
|
| 652 | - ); |
|
| 653 | - }); |
|
| 654 | - $this->registerAlias('AppManager', AppManager::class); |
|
| 655 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 656 | - |
|
| 657 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 658 | - return new DateTimeZone( |
|
| 659 | - $c->getConfig(), |
|
| 660 | - $c->getSession() |
|
| 661 | - ); |
|
| 662 | - }); |
|
| 663 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 664 | - |
|
| 665 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 666 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 667 | - |
|
| 668 | - return new DateTimeFormatter( |
|
| 669 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 670 | - $c->getL10N('lib', $language) |
|
| 671 | - ); |
|
| 672 | - }); |
|
| 673 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 674 | - |
|
| 675 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 676 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 677 | - $listener = new UserMountCacheListener($mountCache); |
|
| 678 | - $listener->listen($c->getUserManager()); |
|
| 679 | - return $mountCache; |
|
| 680 | - }); |
|
| 681 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 682 | - |
|
| 683 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 684 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 685 | - $mountCache = $c->query('UserMountCache'); |
|
| 686 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 687 | - |
|
| 688 | - // builtin providers |
|
| 689 | - |
|
| 690 | - $config = $c->getConfig(); |
|
| 691 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 692 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 693 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 694 | - |
|
| 695 | - return $manager; |
|
| 696 | - }); |
|
| 697 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 698 | - |
|
| 699 | - $this->registerService('IniWrapper', function ($c) { |
|
| 700 | - return new IniGetWrapper(); |
|
| 701 | - }); |
|
| 702 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 703 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 704 | - if ($busClass) { |
|
| 705 | - list($app, $class) = explode('::', $busClass, 2); |
|
| 706 | - if ($c->getAppManager()->isInstalled($app)) { |
|
| 707 | - \OC_App::loadApp($app); |
|
| 708 | - return $c->query($class); |
|
| 709 | - } else { |
|
| 710 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 711 | - } |
|
| 712 | - } else { |
|
| 713 | - $jobList = $c->getJobList(); |
|
| 714 | - return new CronBus($jobList); |
|
| 715 | - } |
|
| 716 | - }); |
|
| 717 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 718 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 719 | - }); |
|
| 720 | - $this->registerService('Throttler', function (Server $c) { |
|
| 721 | - return new Throttler( |
|
| 722 | - $c->getDatabaseConnection(), |
|
| 723 | - new TimeFactory(), |
|
| 724 | - $c->getLogger(), |
|
| 725 | - $c->getConfig() |
|
| 726 | - ); |
|
| 727 | - }); |
|
| 728 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 729 | - // IConfig and IAppManager requires a working database. This code |
|
| 730 | - // might however be called when ownCloud is not yet setup. |
|
| 731 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 732 | - $config = $c->getConfig(); |
|
| 733 | - $appManager = $c->getAppManager(); |
|
| 734 | - } else { |
|
| 735 | - $config = null; |
|
| 736 | - $appManager = null; |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - return new Checker( |
|
| 740 | - new EnvironmentHelper(), |
|
| 741 | - new FileAccessHelper(), |
|
| 742 | - new AppLocator(), |
|
| 743 | - $config, |
|
| 744 | - $c->getMemCacheFactory(), |
|
| 745 | - $appManager, |
|
| 746 | - $c->getTempManager() |
|
| 747 | - ); |
|
| 748 | - }); |
|
| 749 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 750 | - if (isset($this['urlParams'])) { |
|
| 751 | - $urlParams = $this['urlParams']; |
|
| 752 | - } else { |
|
| 753 | - $urlParams = []; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 757 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 758 | - ) { |
|
| 759 | - $stream = 'fakeinput://data'; |
|
| 760 | - } else { |
|
| 761 | - $stream = 'php://input'; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return new Request( |
|
| 765 | - [ |
|
| 766 | - 'get' => $_GET, |
|
| 767 | - 'post' => $_POST, |
|
| 768 | - 'files' => $_FILES, |
|
| 769 | - 'server' => $_SERVER, |
|
| 770 | - 'env' => $_ENV, |
|
| 771 | - 'cookies' => $_COOKIE, |
|
| 772 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 773 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 774 | - : null, |
|
| 775 | - 'urlParams' => $urlParams, |
|
| 776 | - ], |
|
| 777 | - $this->getSecureRandom(), |
|
| 778 | - $this->getConfig(), |
|
| 779 | - $this->getCsrfTokenManager(), |
|
| 780 | - $stream |
|
| 781 | - ); |
|
| 782 | - }); |
|
| 783 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 784 | - |
|
| 785 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 786 | - return new Mailer( |
|
| 787 | - $c->getConfig(), |
|
| 788 | - $c->getLogger(), |
|
| 789 | - $c->query(Defaults::class), |
|
| 790 | - $c->getURLGenerator(), |
|
| 791 | - $c->getL10N('lib') |
|
| 792 | - ); |
|
| 793 | - }); |
|
| 794 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 795 | - |
|
| 796 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 797 | - $config = $c->getConfig(); |
|
| 798 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 799 | - if (is_null($factoryClass)) { |
|
| 800 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 801 | - } |
|
| 802 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 803 | - $factory = new $factoryClass($this); |
|
| 804 | - return $factory->getLDAPProvider(); |
|
| 805 | - }); |
|
| 806 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 807 | - $ini = $c->getIniWrapper(); |
|
| 808 | - $config = $c->getConfig(); |
|
| 809 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 810 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 811 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 812 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 813 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 814 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 815 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 816 | - } |
|
| 817 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 818 | - } |
|
| 819 | - return new NoopLockingProvider(); |
|
| 820 | - }); |
|
| 821 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 822 | - |
|
| 823 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 824 | - return new \OC\Files\Mount\Manager(); |
|
| 825 | - }); |
|
| 826 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 827 | - |
|
| 828 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 829 | - return new \OC\Files\Type\Detection( |
|
| 830 | - $c->getURLGenerator(), |
|
| 831 | - \OC::$configDir, |
|
| 832 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 833 | - ); |
|
| 834 | - }); |
|
| 835 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 836 | - |
|
| 837 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 838 | - return new \OC\Files\Type\Loader( |
|
| 839 | - $c->getDatabaseConnection() |
|
| 840 | - ); |
|
| 841 | - }); |
|
| 842 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 843 | - $this->registerService(BundleFetcher::class, function () { |
|
| 844 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 845 | - }); |
|
| 846 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 847 | - return new Manager( |
|
| 848 | - $c->query(IValidator::class) |
|
| 849 | - ); |
|
| 850 | - }); |
|
| 851 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 852 | - |
|
| 853 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 854 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 855 | - $manager->registerCapability(function () use ($c) { |
|
| 856 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 857 | - }); |
|
| 858 | - $manager->registerCapability(function () use ($c) { |
|
| 859 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 860 | - }); |
|
| 861 | - return $manager; |
|
| 862 | - }); |
|
| 863 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 864 | - |
|
| 865 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 866 | - $config = $c->getConfig(); |
|
| 867 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 868 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 869 | - $factory = new $factoryClass($this); |
|
| 870 | - return $factory->getManager(); |
|
| 871 | - }); |
|
| 872 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 873 | - |
|
| 874 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 875 | - /* |
|
| 130 | + /** @var string */ |
|
| 131 | + private $webRoot; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param string $webRoot |
|
| 135 | + * @param \OC\Config $config |
|
| 136 | + */ |
|
| 137 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 138 | + parent::__construct(); |
|
| 139 | + $this->webRoot = $webRoot; |
|
| 140 | + |
|
| 141 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 142 | + return $c; |
|
| 143 | + }); |
|
| 144 | + |
|
| 145 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 146 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 147 | + |
|
| 148 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 152 | + return new PreviewManager( |
|
| 153 | + $c->getConfig(), |
|
| 154 | + $c->getRootFolder(), |
|
| 155 | + $c->getAppDataDir('preview'), |
|
| 156 | + $c->getEventDispatcher(), |
|
| 157 | + $c->getSession()->get('user_id') |
|
| 158 | + ); |
|
| 159 | + }); |
|
| 160 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 161 | + |
|
| 162 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 163 | + return new \OC\Preview\Watcher( |
|
| 164 | + $c->getAppDataDir('preview') |
|
| 165 | + ); |
|
| 166 | + }); |
|
| 167 | + |
|
| 168 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
| 169 | + $view = new View(); |
|
| 170 | + $util = new Encryption\Util( |
|
| 171 | + $view, |
|
| 172 | + $c->getUserManager(), |
|
| 173 | + $c->getGroupManager(), |
|
| 174 | + $c->getConfig() |
|
| 175 | + ); |
|
| 176 | + return new Encryption\Manager( |
|
| 177 | + $c->getConfig(), |
|
| 178 | + $c->getLogger(), |
|
| 179 | + $c->getL10N('core'), |
|
| 180 | + new View(), |
|
| 181 | + $util, |
|
| 182 | + new ArrayCache() |
|
| 183 | + ); |
|
| 184 | + }); |
|
| 185 | + |
|
| 186 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 187 | + $util = new Encryption\Util( |
|
| 188 | + new View(), |
|
| 189 | + $c->getUserManager(), |
|
| 190 | + $c->getGroupManager(), |
|
| 191 | + $c->getConfig() |
|
| 192 | + ); |
|
| 193 | + return new Encryption\File( |
|
| 194 | + $util, |
|
| 195 | + $c->getRootFolder(), |
|
| 196 | + $c->getShareManager() |
|
| 197 | + ); |
|
| 198 | + }); |
|
| 199 | + |
|
| 200 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 201 | + $view = new View(); |
|
| 202 | + $util = new Encryption\Util( |
|
| 203 | + $view, |
|
| 204 | + $c->getUserManager(), |
|
| 205 | + $c->getGroupManager(), |
|
| 206 | + $c->getConfig() |
|
| 207 | + ); |
|
| 208 | + |
|
| 209 | + return new Encryption\Keys\Storage($view, $util); |
|
| 210 | + }); |
|
| 211 | + $this->registerService('TagMapper', function (Server $c) { |
|
| 212 | + return new TagMapper($c->getDatabaseConnection()); |
|
| 213 | + }); |
|
| 214 | + |
|
| 215 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 216 | + $tagMapper = $c->query('TagMapper'); |
|
| 217 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
| 218 | + }); |
|
| 219 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 220 | + |
|
| 221 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 222 | + $config = $c->getConfig(); |
|
| 223 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
| 224 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
| 225 | + $factory = new $factoryClass($this); |
|
| 226 | + return $factory; |
|
| 227 | + }); |
|
| 228 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 229 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 230 | + }); |
|
| 231 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 232 | + |
|
| 233 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 234 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 235 | + }); |
|
| 236 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 237 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 238 | + $view = new View(); |
|
| 239 | + $root = new Root( |
|
| 240 | + $manager, |
|
| 241 | + $view, |
|
| 242 | + null, |
|
| 243 | + $c->getUserMountCache(), |
|
| 244 | + $this->getLogger(), |
|
| 245 | + $this->getUserManager() |
|
| 246 | + ); |
|
| 247 | + $connector = new HookConnector($root, $view); |
|
| 248 | + $connector->viewToNode(); |
|
| 249 | + |
|
| 250 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 251 | + $previewConnector->connectWatcher(); |
|
| 252 | + |
|
| 253 | + return $root; |
|
| 254 | + }); |
|
| 255 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 256 | + |
|
| 257 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 258 | + return new LazyRoot(function () use ($c) { |
|
| 259 | + return $c->query('RootFolder'); |
|
| 260 | + }); |
|
| 261 | + }); |
|
| 262 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 263 | + |
|
| 264 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 265 | + $config = $c->getConfig(); |
|
| 266 | + return new \OC\User\Manager($config); |
|
| 267 | + }); |
|
| 268 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
| 269 | + |
|
| 270 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 271 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 272 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 273 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 274 | + }); |
|
| 275 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 276 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 277 | + }); |
|
| 278 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 279 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 280 | + }); |
|
| 281 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 282 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 283 | + }); |
|
| 284 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 285 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 286 | + }); |
|
| 287 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 288 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 289 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 290 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 291 | + }); |
|
| 292 | + return $groupManager; |
|
| 293 | + }); |
|
| 294 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 295 | + |
|
| 296 | + $this->registerService(Store::class, function (Server $c) { |
|
| 297 | + $session = $c->getSession(); |
|
| 298 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 299 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 300 | + } else { |
|
| 301 | + $tokenProvider = null; |
|
| 302 | + } |
|
| 303 | + $logger = $c->getLogger(); |
|
| 304 | + return new Store($session, $logger, $tokenProvider); |
|
| 305 | + }); |
|
| 306 | + $this->registerAlias(IStore::class, Store::class); |
|
| 307 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 308 | + $dbConnection = $c->getDatabaseConnection(); |
|
| 309 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 310 | + }); |
|
| 311 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 312 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
| 313 | + $crypto = $c->getCrypto(); |
|
| 314 | + $config = $c->getConfig(); |
|
| 315 | + $logger = $c->getLogger(); |
|
| 316 | + $timeFactory = new TimeFactory(); |
|
| 317 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 318 | + }); |
|
| 319 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
| 320 | + |
|
| 321 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 322 | + $manager = $c->getUserManager(); |
|
| 323 | + $session = new \OC\Session\Memory(''); |
|
| 324 | + $timeFactory = new TimeFactory(); |
|
| 325 | + // Token providers might require a working database. This code |
|
| 326 | + // might however be called when ownCloud is not yet setup. |
|
| 327 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 328 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
| 329 | + } else { |
|
| 330 | + $defaultTokenProvider = null; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
| 334 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 335 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 336 | + }); |
|
| 337 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 338 | + /** @var $user \OC\User\User */ |
|
| 339 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 340 | + }); |
|
| 341 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 342 | + /** @var $user \OC\User\User */ |
|
| 343 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 344 | + }); |
|
| 345 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 346 | + /** @var $user \OC\User\User */ |
|
| 347 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 348 | + }); |
|
| 349 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 350 | + /** @var $user \OC\User\User */ |
|
| 351 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 352 | + }); |
|
| 353 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 354 | + /** @var $user \OC\User\User */ |
|
| 355 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 356 | + }); |
|
| 357 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 358 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 359 | + }); |
|
| 360 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 361 | + /** @var $user \OC\User\User */ |
|
| 362 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 363 | + }); |
|
| 364 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 365 | + /** @var $user \OC\User\User */ |
|
| 366 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 367 | + }); |
|
| 368 | + $userSession->listen('\OC\User', 'logout', function () { |
|
| 369 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 370 | + }); |
|
| 371 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 372 | + /** @var $user \OC\User\User */ |
|
| 373 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 374 | + }); |
|
| 375 | + return $userSession; |
|
| 376 | + }); |
|
| 377 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 378 | + |
|
| 379 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 380 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
| 381 | + $c->getAppManager(), |
|
| 382 | + $c->getSession(), |
|
| 383 | + $c->getConfig(), |
|
| 384 | + $c->getActivityManager(), |
|
| 385 | + $c->getLogger(), |
|
| 386 | + $c->query(\OC\Authentication\Token\IProvider::class), |
|
| 387 | + $c->query(ITimeFactory::class) |
|
| 388 | + ); |
|
| 389 | + }); |
|
| 390 | + |
|
| 391 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 392 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 393 | + |
|
| 394 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 395 | + return new \OC\AllConfig( |
|
| 396 | + $c->getSystemConfig() |
|
| 397 | + ); |
|
| 398 | + }); |
|
| 399 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 400 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 401 | + |
|
| 402 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 403 | + return new \OC\SystemConfig($config); |
|
| 404 | + }); |
|
| 405 | + |
|
| 406 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 407 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 408 | + }); |
|
| 409 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 410 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 411 | + |
|
| 412 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 413 | + return new \OC\L10N\Factory( |
|
| 414 | + $c->getConfig(), |
|
| 415 | + $c->getRequest(), |
|
| 416 | + $c->getUserSession(), |
|
| 417 | + \OC::$SERVERROOT |
|
| 418 | + ); |
|
| 419 | + }); |
|
| 420 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 421 | + |
|
| 422 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 423 | + $config = $c->getConfig(); |
|
| 424 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 425 | + $request = $c->getRequest(); |
|
| 426 | + return new \OC\URLGenerator( |
|
| 427 | + $config, |
|
| 428 | + $cacheFactory, |
|
| 429 | + $request |
|
| 430 | + ); |
|
| 431 | + }); |
|
| 432 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 433 | + |
|
| 434 | + $this->registerService('AppHelper', function ($c) { |
|
| 435 | + return new \OC\AppHelper(); |
|
| 436 | + }); |
|
| 437 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 438 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 439 | + |
|
| 440 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 441 | + return new Cache\File(); |
|
| 442 | + }); |
|
| 443 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 444 | + |
|
| 445 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 446 | + |
|
| 447 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 448 | + '\\OC\\Memcache\\ArrayCache', |
|
| 449 | + '\\OC\\Memcache\\ArrayCache', |
|
| 450 | + '\\OC\\Memcache\\ArrayCache' |
|
| 451 | + ); |
|
| 452 | + $config = $c->getConfig(); |
|
| 453 | + $request = $c->getRequest(); |
|
| 454 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
| 455 | + |
|
| 456 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 457 | + $v = \OC_App::getAppVersions(); |
|
| 458 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 459 | + $version = implode(',', $v); |
|
| 460 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 461 | + $path = \OC::$SERVERROOT; |
|
| 462 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
| 463 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 464 | + $config->getSystemValue('memcache.local', null), |
|
| 465 | + $config->getSystemValue('memcache.distributed', null), |
|
| 466 | + $config->getSystemValue('memcache.locking', null) |
|
| 467 | + ); |
|
| 468 | + } |
|
| 469 | + return $arrayCacheFactory; |
|
| 470 | + |
|
| 471 | + }); |
|
| 472 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 473 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 474 | + |
|
| 475 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 476 | + $systemConfig = $c->getSystemConfig(); |
|
| 477 | + return new RedisFactory($systemConfig); |
|
| 478 | + }); |
|
| 479 | + |
|
| 480 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 481 | + return new \OC\Activity\Manager( |
|
| 482 | + $c->getRequest(), |
|
| 483 | + $c->getUserSession(), |
|
| 484 | + $c->getConfig(), |
|
| 485 | + $c->query(IValidator::class) |
|
| 486 | + ); |
|
| 487 | + }); |
|
| 488 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 489 | + |
|
| 490 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 491 | + return new \OC\Activity\EventMerger( |
|
| 492 | + $c->getL10N('lib') |
|
| 493 | + ); |
|
| 494 | + }); |
|
| 495 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 496 | + |
|
| 497 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 498 | + return new AvatarManager( |
|
| 499 | + $c->getUserManager(), |
|
| 500 | + $c->getAppDataDir('avatar'), |
|
| 501 | + $c->getL10N('lib'), |
|
| 502 | + $c->getLogger(), |
|
| 503 | + $c->getConfig() |
|
| 504 | + ); |
|
| 505 | + }); |
|
| 506 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 507 | + |
|
| 508 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 509 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 510 | + $logger = Log::getLogClass($logType); |
|
| 511 | + call_user_func(array($logger, 'init')); |
|
| 512 | + |
|
| 513 | + return new Log($logger); |
|
| 514 | + }); |
|
| 515 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 516 | + |
|
| 517 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 518 | + $config = $c->getConfig(); |
|
| 519 | + return new \OC\BackgroundJob\JobList( |
|
| 520 | + $c->getDatabaseConnection(), |
|
| 521 | + $config, |
|
| 522 | + new TimeFactory() |
|
| 523 | + ); |
|
| 524 | + }); |
|
| 525 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 526 | + |
|
| 527 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 528 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 529 | + $logger = $c->getLogger(); |
|
| 530 | + if ($cacheFactory->isAvailable()) { |
|
| 531 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 532 | + } else { |
|
| 533 | + $router = new \OC\Route\Router($logger); |
|
| 534 | + } |
|
| 535 | + return $router; |
|
| 536 | + }); |
|
| 537 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 538 | + |
|
| 539 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 540 | + return new Search(); |
|
| 541 | + }); |
|
| 542 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 543 | + |
|
| 544 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
| 545 | + return new \OC\Security\RateLimiting\Limiter( |
|
| 546 | + $this->getUserSession(), |
|
| 547 | + $this->getRequest(), |
|
| 548 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 549 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 550 | + ); |
|
| 551 | + }); |
|
| 552 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 553 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 554 | + $this->getMemCacheFactory(), |
|
| 555 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 556 | + ); |
|
| 557 | + }); |
|
| 558 | + |
|
| 559 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 560 | + return new SecureRandom(); |
|
| 561 | + }); |
|
| 562 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 563 | + |
|
| 564 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 565 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 566 | + }); |
|
| 567 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 568 | + |
|
| 569 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 570 | + return new Hasher($c->getConfig()); |
|
| 571 | + }); |
|
| 572 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 573 | + |
|
| 574 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 575 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 576 | + }); |
|
| 577 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 578 | + |
|
| 579 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 580 | + $systemConfig = $c->getSystemConfig(); |
|
| 581 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 582 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 583 | + if (!$factory->isValidType($type)) { |
|
| 584 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 585 | + } |
|
| 586 | + $connectionParams = $factory->createConnectionParams(); |
|
| 587 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 588 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 589 | + return $connection; |
|
| 590 | + }); |
|
| 591 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 592 | + |
|
| 593 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
| 594 | + $config = $c->getConfig(); |
|
| 595 | + return new HTTPHelper( |
|
| 596 | + $config, |
|
| 597 | + $c->getHTTPClientService() |
|
| 598 | + ); |
|
| 599 | + }); |
|
| 600 | + |
|
| 601 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 602 | + $user = \OC_User::getUser(); |
|
| 603 | + $uid = $user ? $user : null; |
|
| 604 | + return new ClientService( |
|
| 605 | + $c->getConfig(), |
|
| 606 | + new \OC\Security\CertificateManager( |
|
| 607 | + $uid, |
|
| 608 | + new View(), |
|
| 609 | + $c->getConfig(), |
|
| 610 | + $c->getLogger(), |
|
| 611 | + $c->getSecureRandom() |
|
| 612 | + ) |
|
| 613 | + ); |
|
| 614 | + }); |
|
| 615 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 616 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 617 | + $eventLogger = new EventLogger(); |
|
| 618 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 619 | + // In debug mode, module is being activated by default |
|
| 620 | + $eventLogger->activate(); |
|
| 621 | + } |
|
| 622 | + return $eventLogger; |
|
| 623 | + }); |
|
| 624 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 625 | + |
|
| 626 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 627 | + $queryLogger = new QueryLogger(); |
|
| 628 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 629 | + // In debug mode, module is being activated by default |
|
| 630 | + $queryLogger->activate(); |
|
| 631 | + } |
|
| 632 | + return $queryLogger; |
|
| 633 | + }); |
|
| 634 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 635 | + |
|
| 636 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 637 | + return new TempManager( |
|
| 638 | + $c->getLogger(), |
|
| 639 | + $c->getConfig() |
|
| 640 | + ); |
|
| 641 | + }); |
|
| 642 | + $this->registerAlias('TempManager', TempManager::class); |
|
| 643 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 644 | + |
|
| 645 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 646 | + return new \OC\App\AppManager( |
|
| 647 | + $c->getUserSession(), |
|
| 648 | + $c->getAppConfig(), |
|
| 649 | + $c->getGroupManager(), |
|
| 650 | + $c->getMemCacheFactory(), |
|
| 651 | + $c->getEventDispatcher() |
|
| 652 | + ); |
|
| 653 | + }); |
|
| 654 | + $this->registerAlias('AppManager', AppManager::class); |
|
| 655 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 656 | + |
|
| 657 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 658 | + return new DateTimeZone( |
|
| 659 | + $c->getConfig(), |
|
| 660 | + $c->getSession() |
|
| 661 | + ); |
|
| 662 | + }); |
|
| 663 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 664 | + |
|
| 665 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 666 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 667 | + |
|
| 668 | + return new DateTimeFormatter( |
|
| 669 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 670 | + $c->getL10N('lib', $language) |
|
| 671 | + ); |
|
| 672 | + }); |
|
| 673 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 674 | + |
|
| 675 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 676 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 677 | + $listener = new UserMountCacheListener($mountCache); |
|
| 678 | + $listener->listen($c->getUserManager()); |
|
| 679 | + return $mountCache; |
|
| 680 | + }); |
|
| 681 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 682 | + |
|
| 683 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 684 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 685 | + $mountCache = $c->query('UserMountCache'); |
|
| 686 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 687 | + |
|
| 688 | + // builtin providers |
|
| 689 | + |
|
| 690 | + $config = $c->getConfig(); |
|
| 691 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 692 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 693 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 694 | + |
|
| 695 | + return $manager; |
|
| 696 | + }); |
|
| 697 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 698 | + |
|
| 699 | + $this->registerService('IniWrapper', function ($c) { |
|
| 700 | + return new IniGetWrapper(); |
|
| 701 | + }); |
|
| 702 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 703 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 704 | + if ($busClass) { |
|
| 705 | + list($app, $class) = explode('::', $busClass, 2); |
|
| 706 | + if ($c->getAppManager()->isInstalled($app)) { |
|
| 707 | + \OC_App::loadApp($app); |
|
| 708 | + return $c->query($class); |
|
| 709 | + } else { |
|
| 710 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 711 | + } |
|
| 712 | + } else { |
|
| 713 | + $jobList = $c->getJobList(); |
|
| 714 | + return new CronBus($jobList); |
|
| 715 | + } |
|
| 716 | + }); |
|
| 717 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 718 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 719 | + }); |
|
| 720 | + $this->registerService('Throttler', function (Server $c) { |
|
| 721 | + return new Throttler( |
|
| 722 | + $c->getDatabaseConnection(), |
|
| 723 | + new TimeFactory(), |
|
| 724 | + $c->getLogger(), |
|
| 725 | + $c->getConfig() |
|
| 726 | + ); |
|
| 727 | + }); |
|
| 728 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 729 | + // IConfig and IAppManager requires a working database. This code |
|
| 730 | + // might however be called when ownCloud is not yet setup. |
|
| 731 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 732 | + $config = $c->getConfig(); |
|
| 733 | + $appManager = $c->getAppManager(); |
|
| 734 | + } else { |
|
| 735 | + $config = null; |
|
| 736 | + $appManager = null; |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + return new Checker( |
|
| 740 | + new EnvironmentHelper(), |
|
| 741 | + new FileAccessHelper(), |
|
| 742 | + new AppLocator(), |
|
| 743 | + $config, |
|
| 744 | + $c->getMemCacheFactory(), |
|
| 745 | + $appManager, |
|
| 746 | + $c->getTempManager() |
|
| 747 | + ); |
|
| 748 | + }); |
|
| 749 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 750 | + if (isset($this['urlParams'])) { |
|
| 751 | + $urlParams = $this['urlParams']; |
|
| 752 | + } else { |
|
| 753 | + $urlParams = []; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 757 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 758 | + ) { |
|
| 759 | + $stream = 'fakeinput://data'; |
|
| 760 | + } else { |
|
| 761 | + $stream = 'php://input'; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return new Request( |
|
| 765 | + [ |
|
| 766 | + 'get' => $_GET, |
|
| 767 | + 'post' => $_POST, |
|
| 768 | + 'files' => $_FILES, |
|
| 769 | + 'server' => $_SERVER, |
|
| 770 | + 'env' => $_ENV, |
|
| 771 | + 'cookies' => $_COOKIE, |
|
| 772 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 773 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 774 | + : null, |
|
| 775 | + 'urlParams' => $urlParams, |
|
| 776 | + ], |
|
| 777 | + $this->getSecureRandom(), |
|
| 778 | + $this->getConfig(), |
|
| 779 | + $this->getCsrfTokenManager(), |
|
| 780 | + $stream |
|
| 781 | + ); |
|
| 782 | + }); |
|
| 783 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 784 | + |
|
| 785 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 786 | + return new Mailer( |
|
| 787 | + $c->getConfig(), |
|
| 788 | + $c->getLogger(), |
|
| 789 | + $c->query(Defaults::class), |
|
| 790 | + $c->getURLGenerator(), |
|
| 791 | + $c->getL10N('lib') |
|
| 792 | + ); |
|
| 793 | + }); |
|
| 794 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 795 | + |
|
| 796 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
| 797 | + $config = $c->getConfig(); |
|
| 798 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 799 | + if (is_null($factoryClass)) { |
|
| 800 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 801 | + } |
|
| 802 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 803 | + $factory = new $factoryClass($this); |
|
| 804 | + return $factory->getLDAPProvider(); |
|
| 805 | + }); |
|
| 806 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 807 | + $ini = $c->getIniWrapper(); |
|
| 808 | + $config = $c->getConfig(); |
|
| 809 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 810 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 811 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 812 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 813 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 814 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 815 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 816 | + } |
|
| 817 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 818 | + } |
|
| 819 | + return new NoopLockingProvider(); |
|
| 820 | + }); |
|
| 821 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 822 | + |
|
| 823 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 824 | + return new \OC\Files\Mount\Manager(); |
|
| 825 | + }); |
|
| 826 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 827 | + |
|
| 828 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 829 | + return new \OC\Files\Type\Detection( |
|
| 830 | + $c->getURLGenerator(), |
|
| 831 | + \OC::$configDir, |
|
| 832 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 833 | + ); |
|
| 834 | + }); |
|
| 835 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 836 | + |
|
| 837 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 838 | + return new \OC\Files\Type\Loader( |
|
| 839 | + $c->getDatabaseConnection() |
|
| 840 | + ); |
|
| 841 | + }); |
|
| 842 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 843 | + $this->registerService(BundleFetcher::class, function () { |
|
| 844 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 845 | + }); |
|
| 846 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 847 | + return new Manager( |
|
| 848 | + $c->query(IValidator::class) |
|
| 849 | + ); |
|
| 850 | + }); |
|
| 851 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 852 | + |
|
| 853 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 854 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 855 | + $manager->registerCapability(function () use ($c) { |
|
| 856 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 857 | + }); |
|
| 858 | + $manager->registerCapability(function () use ($c) { |
|
| 859 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 860 | + }); |
|
| 861 | + return $manager; |
|
| 862 | + }); |
|
| 863 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 864 | + |
|
| 865 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 866 | + $config = $c->getConfig(); |
|
| 867 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 868 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 869 | + $factory = new $factoryClass($this); |
|
| 870 | + return $factory->getManager(); |
|
| 871 | + }); |
|
| 872 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 873 | + |
|
| 874 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 875 | + /* |
|
| 876 | 876 | * Dark magic for autoloader. |
| 877 | 877 | * If we do a class_exists it will try to load the class which will |
| 878 | 878 | * make composer cache the result. Resulting in errors when enabling |
| 879 | 879 | * the theming app. |
| 880 | 880 | */ |
| 881 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 882 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 883 | - $classExists = true; |
|
| 884 | - } else { |
|
| 885 | - $classExists = false; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 889 | - return new ThemingDefaults( |
|
| 890 | - $c->getConfig(), |
|
| 891 | - $c->getL10N('theming'), |
|
| 892 | - $c->getURLGenerator(), |
|
| 893 | - $c->getAppDataDir('theming'), |
|
| 894 | - $c->getMemCacheFactory(), |
|
| 895 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
| 896 | - $this->getAppManager() |
|
| 897 | - ); |
|
| 898 | - } |
|
| 899 | - return new \OC_Defaults(); |
|
| 900 | - }); |
|
| 901 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 902 | - /** @var Factory $cacheFactory */ |
|
| 903 | - $cacheFactory = $c->query(Factory::class); |
|
| 904 | - return new SCSSCacher( |
|
| 905 | - $c->getLogger(), |
|
| 906 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 907 | - $c->getURLGenerator(), |
|
| 908 | - $c->getConfig(), |
|
| 909 | - $c->getThemingDefaults(), |
|
| 910 | - \OC::$SERVERROOT, |
|
| 911 | - $cacheFactory->create('SCSS') |
|
| 912 | - ); |
|
| 913 | - }); |
|
| 914 | - $this->registerService(EventDispatcher::class, function () { |
|
| 915 | - return new EventDispatcher(); |
|
| 916 | - }); |
|
| 917 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 918 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 919 | - |
|
| 920 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 921 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 922 | - $request = new Request( |
|
| 923 | - [ |
|
| 924 | - 'get' => $_GET, |
|
| 925 | - 'post' => $_POST, |
|
| 926 | - 'files' => $_FILES, |
|
| 927 | - 'server' => $_SERVER, |
|
| 928 | - 'env' => $_ENV, |
|
| 929 | - 'cookies' => $_COOKIE, |
|
| 930 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 931 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 932 | - : null, |
|
| 933 | - ], |
|
| 934 | - $c->getSecureRandom(), |
|
| 935 | - $c->getConfig() |
|
| 936 | - ); |
|
| 937 | - |
|
| 938 | - return new CryptoWrapper( |
|
| 939 | - $c->getConfig(), |
|
| 940 | - $c->getCrypto(), |
|
| 941 | - $c->getSecureRandom(), |
|
| 942 | - $request |
|
| 943 | - ); |
|
| 944 | - }); |
|
| 945 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 946 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 947 | - |
|
| 948 | - return new CsrfTokenManager( |
|
| 949 | - $tokenGenerator, |
|
| 950 | - $c->query(SessionStorage::class) |
|
| 951 | - ); |
|
| 952 | - }); |
|
| 953 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 954 | - return new SessionStorage($c->getSession()); |
|
| 955 | - }); |
|
| 956 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 957 | - return new ContentSecurityPolicyManager(); |
|
| 958 | - }); |
|
| 959 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 960 | - |
|
| 961 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 962 | - return new ContentSecurityPolicyNonceManager( |
|
| 963 | - $c->getCsrfTokenManager(), |
|
| 964 | - $c->getRequest() |
|
| 965 | - ); |
|
| 966 | - }); |
|
| 967 | - |
|
| 968 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 969 | - $config = $c->getConfig(); |
|
| 970 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 971 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 972 | - $factory = new $factoryClass($this); |
|
| 973 | - |
|
| 974 | - $manager = new \OC\Share20\Manager( |
|
| 975 | - $c->getLogger(), |
|
| 976 | - $c->getConfig(), |
|
| 977 | - $c->getSecureRandom(), |
|
| 978 | - $c->getHasher(), |
|
| 979 | - $c->getMountManager(), |
|
| 980 | - $c->getGroupManager(), |
|
| 981 | - $c->getL10N('lib'), |
|
| 982 | - $c->getL10NFactory(), |
|
| 983 | - $factory, |
|
| 984 | - $c->getUserManager(), |
|
| 985 | - $c->getLazyRootFolder(), |
|
| 986 | - $c->getEventDispatcher(), |
|
| 987 | - $c->getMailer(), |
|
| 988 | - $c->getURLGenerator(), |
|
| 989 | - $c->getThemingDefaults() |
|
| 990 | - ); |
|
| 991 | - |
|
| 992 | - return $manager; |
|
| 993 | - }); |
|
| 994 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 995 | - |
|
| 996 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 997 | - $manager = new \OC\Settings\Manager( |
|
| 998 | - $c->getLogger(), |
|
| 999 | - $c->getDatabaseConnection(), |
|
| 1000 | - $c->getL10N('lib'), |
|
| 1001 | - $c->getConfig(), |
|
| 1002 | - $c->getEncryptionManager(), |
|
| 1003 | - $c->getUserManager(), |
|
| 1004 | - $c->getLockingProvider(), |
|
| 1005 | - $c->getRequest(), |
|
| 1006 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 1007 | - $c->getURLGenerator(), |
|
| 1008 | - $c->query(AccountManager::class), |
|
| 1009 | - $c->getGroupManager(), |
|
| 1010 | - $c->getL10NFactory(), |
|
| 1011 | - $c->getThemingDefaults(), |
|
| 1012 | - $c->getAppManager() |
|
| 1013 | - ); |
|
| 1014 | - return $manager; |
|
| 1015 | - }); |
|
| 1016 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1017 | - return new \OC\Files\AppData\Factory( |
|
| 1018 | - $c->getRootFolder(), |
|
| 1019 | - $c->getSystemConfig() |
|
| 1020 | - ); |
|
| 1021 | - }); |
|
| 1022 | - |
|
| 1023 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1024 | - return new LockdownManager(function () use ($c) { |
|
| 1025 | - return $c->getSession(); |
|
| 1026 | - }); |
|
| 1027 | - }); |
|
| 1028 | - |
|
| 1029 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1030 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1031 | - }); |
|
| 1032 | - |
|
| 1033 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1034 | - return new CloudIdManager(); |
|
| 1035 | - }); |
|
| 1036 | - |
|
| 1037 | - /* To trick DI since we don't extend the DIContainer here */ |
|
| 1038 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1039 | - return new CleanPreviewsBackgroundJob( |
|
| 1040 | - $c->getRootFolder(), |
|
| 1041 | - $c->getLogger(), |
|
| 1042 | - $c->getJobList(), |
|
| 1043 | - new TimeFactory() |
|
| 1044 | - ); |
|
| 1045 | - }); |
|
| 1046 | - |
|
| 1047 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1048 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1049 | - |
|
| 1050 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1051 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1052 | - |
|
| 1053 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1054 | - return new Defaults( |
|
| 1055 | - $c->getThemingDefaults() |
|
| 1056 | - ); |
|
| 1057 | - }); |
|
| 1058 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1059 | - |
|
| 1060 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1061 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1062 | - }); |
|
| 1063 | - |
|
| 1064 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1065 | - return new ShareHelper( |
|
| 1066 | - $c->query(\OCP\Share\IManager::class) |
|
| 1067 | - ); |
|
| 1068 | - }); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - /** |
|
| 1072 | - * @return \OCP\Contacts\IManager |
|
| 1073 | - */ |
|
| 1074 | - public function getContactsManager() { |
|
| 1075 | - return $this->query('ContactsManager'); |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * @return \OC\Encryption\Manager |
|
| 1080 | - */ |
|
| 1081 | - public function getEncryptionManager() { |
|
| 1082 | - return $this->query('EncryptionManager'); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * @return \OC\Encryption\File |
|
| 1087 | - */ |
|
| 1088 | - public function getEncryptionFilesHelper() { |
|
| 1089 | - return $this->query('EncryptionFileHelper'); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - /** |
|
| 1093 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1094 | - */ |
|
| 1095 | - public function getEncryptionKeyStorage() { |
|
| 1096 | - return $this->query('EncryptionKeyStorage'); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - /** |
|
| 1100 | - * The current request object holding all information about the request |
|
| 1101 | - * currently being processed is returned from this method. |
|
| 1102 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1103 | - * |
|
| 1104 | - * @return \OCP\IRequest |
|
| 1105 | - */ |
|
| 1106 | - public function getRequest() { |
|
| 1107 | - return $this->query('Request'); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Returns the preview manager which can create preview images for a given file |
|
| 1112 | - * |
|
| 1113 | - * @return \OCP\IPreview |
|
| 1114 | - */ |
|
| 1115 | - public function getPreviewManager() { |
|
| 1116 | - return $this->query('PreviewManager'); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1121 | - * |
|
| 1122 | - * @see \OCP\ITagManager::load() |
|
| 1123 | - * @return \OCP\ITagManager |
|
| 1124 | - */ |
|
| 1125 | - public function getTagManager() { |
|
| 1126 | - return $this->query('TagManager'); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * Returns the system-tag manager |
|
| 1131 | - * |
|
| 1132 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 1133 | - * |
|
| 1134 | - * @since 9.0.0 |
|
| 1135 | - */ |
|
| 1136 | - public function getSystemTagManager() { |
|
| 1137 | - return $this->query('SystemTagManager'); |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * Returns the system-tag object mapper |
|
| 1142 | - * |
|
| 1143 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1144 | - * |
|
| 1145 | - * @since 9.0.0 |
|
| 1146 | - */ |
|
| 1147 | - public function getSystemTagObjectMapper() { |
|
| 1148 | - return $this->query('SystemTagObjectMapper'); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Returns the avatar manager, used for avatar functionality |
|
| 1153 | - * |
|
| 1154 | - * @return \OCP\IAvatarManager |
|
| 1155 | - */ |
|
| 1156 | - public function getAvatarManager() { |
|
| 1157 | - return $this->query('AvatarManager'); |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - /** |
|
| 1161 | - * Returns the root folder of ownCloud's data directory |
|
| 1162 | - * |
|
| 1163 | - * @return \OCP\Files\IRootFolder |
|
| 1164 | - */ |
|
| 1165 | - public function getRootFolder() { |
|
| 1166 | - return $this->query('LazyRootFolder'); |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * Returns the root folder of ownCloud's data directory |
|
| 1171 | - * This is the lazy variant so this gets only initialized once it |
|
| 1172 | - * is actually used. |
|
| 1173 | - * |
|
| 1174 | - * @return \OCP\Files\IRootFolder |
|
| 1175 | - */ |
|
| 1176 | - public function getLazyRootFolder() { |
|
| 1177 | - return $this->query('LazyRootFolder'); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - /** |
|
| 1181 | - * Returns a view to ownCloud's files folder |
|
| 1182 | - * |
|
| 1183 | - * @param string $userId user ID |
|
| 1184 | - * @return \OCP\Files\Folder|null |
|
| 1185 | - */ |
|
| 1186 | - public function getUserFolder($userId = null) { |
|
| 1187 | - if ($userId === null) { |
|
| 1188 | - $user = $this->getUserSession()->getUser(); |
|
| 1189 | - if (!$user) { |
|
| 1190 | - return null; |
|
| 1191 | - } |
|
| 1192 | - $userId = $user->getUID(); |
|
| 1193 | - } |
|
| 1194 | - $root = $this->getRootFolder(); |
|
| 1195 | - return $root->getUserFolder($userId); |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Returns an app-specific view in ownClouds data directory |
|
| 1200 | - * |
|
| 1201 | - * @return \OCP\Files\Folder |
|
| 1202 | - * @deprecated since 9.2.0 use IAppData |
|
| 1203 | - */ |
|
| 1204 | - public function getAppFolder() { |
|
| 1205 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1206 | - $root = $this->getRootFolder(); |
|
| 1207 | - if (!$root->nodeExists($dir)) { |
|
| 1208 | - $folder = $root->newFolder($dir); |
|
| 1209 | - } else { |
|
| 1210 | - $folder = $root->get($dir); |
|
| 1211 | - } |
|
| 1212 | - return $folder; |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * @return \OC\User\Manager |
|
| 1217 | - */ |
|
| 1218 | - public function getUserManager() { |
|
| 1219 | - return $this->query('UserManager'); |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * @return \OC\Group\Manager |
|
| 1224 | - */ |
|
| 1225 | - public function getGroupManager() { |
|
| 1226 | - return $this->query('GroupManager'); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * @return \OC\User\Session |
|
| 1231 | - */ |
|
| 1232 | - public function getUserSession() { |
|
| 1233 | - return $this->query('UserSession'); |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * @return \OCP\ISession |
|
| 1238 | - */ |
|
| 1239 | - public function getSession() { |
|
| 1240 | - return $this->query('UserSession')->getSession(); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * @param \OCP\ISession $session |
|
| 1245 | - */ |
|
| 1246 | - public function setSession(\OCP\ISession $session) { |
|
| 1247 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1248 | - $this->query('UserSession')->setSession($session); |
|
| 1249 | - $this->query(Store::class)->setSession($session); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1254 | - */ |
|
| 1255 | - public function getTwoFactorAuthManager() { |
|
| 1256 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - /** |
|
| 1260 | - * @return \OC\NavigationManager |
|
| 1261 | - */ |
|
| 1262 | - public function getNavigationManager() { |
|
| 1263 | - return $this->query('NavigationManager'); |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - /** |
|
| 1267 | - * @return \OCP\IConfig |
|
| 1268 | - */ |
|
| 1269 | - public function getConfig() { |
|
| 1270 | - return $this->query('AllConfig'); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * @return \OC\SystemConfig |
|
| 1275 | - */ |
|
| 1276 | - public function getSystemConfig() { |
|
| 1277 | - return $this->query('SystemConfig'); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Returns the app config manager |
|
| 1282 | - * |
|
| 1283 | - * @return \OCP\IAppConfig |
|
| 1284 | - */ |
|
| 1285 | - public function getAppConfig() { |
|
| 1286 | - return $this->query('AppConfig'); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * @return \OCP\L10N\IFactory |
|
| 1291 | - */ |
|
| 1292 | - public function getL10NFactory() { |
|
| 1293 | - return $this->query('L10NFactory'); |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * get an L10N instance |
|
| 1298 | - * |
|
| 1299 | - * @param string $app appid |
|
| 1300 | - * @param string $lang |
|
| 1301 | - * @return IL10N |
|
| 1302 | - */ |
|
| 1303 | - public function getL10N($app, $lang = null) { |
|
| 1304 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * @return \OCP\IURLGenerator |
|
| 1309 | - */ |
|
| 1310 | - public function getURLGenerator() { |
|
| 1311 | - return $this->query('URLGenerator'); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * @return \OCP\IHelper |
|
| 1316 | - */ |
|
| 1317 | - public function getHelper() { |
|
| 1318 | - return $this->query('AppHelper'); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * @return AppFetcher |
|
| 1323 | - */ |
|
| 1324 | - public function getAppFetcher() { |
|
| 1325 | - return $this->query(AppFetcher::class); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1330 | - * getMemCacheFactory() instead. |
|
| 1331 | - * |
|
| 1332 | - * @return \OCP\ICache |
|
| 1333 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1334 | - */ |
|
| 1335 | - public function getCache() { |
|
| 1336 | - return $this->query('UserCache'); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Returns an \OCP\CacheFactory instance |
|
| 1341 | - * |
|
| 1342 | - * @return \OCP\ICacheFactory |
|
| 1343 | - */ |
|
| 1344 | - public function getMemCacheFactory() { |
|
| 1345 | - return $this->query('MemCacheFactory'); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Returns an \OC\RedisFactory instance |
|
| 1350 | - * |
|
| 1351 | - * @return \OC\RedisFactory |
|
| 1352 | - */ |
|
| 1353 | - public function getGetRedisFactory() { |
|
| 1354 | - return $this->query('RedisFactory'); |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - /** |
|
| 1359 | - * Returns the current session |
|
| 1360 | - * |
|
| 1361 | - * @return \OCP\IDBConnection |
|
| 1362 | - */ |
|
| 1363 | - public function getDatabaseConnection() { |
|
| 1364 | - return $this->query('DatabaseConnection'); |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * Returns the activity manager |
|
| 1369 | - * |
|
| 1370 | - * @return \OCP\Activity\IManager |
|
| 1371 | - */ |
|
| 1372 | - public function getActivityManager() { |
|
| 1373 | - return $this->query('ActivityManager'); |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * Returns an job list for controlling background jobs |
|
| 1378 | - * |
|
| 1379 | - * @return \OCP\BackgroundJob\IJobList |
|
| 1380 | - */ |
|
| 1381 | - public function getJobList() { |
|
| 1382 | - return $this->query('JobList'); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - /** |
|
| 1386 | - * Returns a logger instance |
|
| 1387 | - * |
|
| 1388 | - * @return \OCP\ILogger |
|
| 1389 | - */ |
|
| 1390 | - public function getLogger() { |
|
| 1391 | - return $this->query('Logger'); |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * Returns a router for generating and matching urls |
|
| 1396 | - * |
|
| 1397 | - * @return \OCP\Route\IRouter |
|
| 1398 | - */ |
|
| 1399 | - public function getRouter() { |
|
| 1400 | - return $this->query('Router'); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - /** |
|
| 1404 | - * Returns a search instance |
|
| 1405 | - * |
|
| 1406 | - * @return \OCP\ISearch |
|
| 1407 | - */ |
|
| 1408 | - public function getSearch() { |
|
| 1409 | - return $this->query('Search'); |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * Returns a SecureRandom instance |
|
| 1414 | - * |
|
| 1415 | - * @return \OCP\Security\ISecureRandom |
|
| 1416 | - */ |
|
| 1417 | - public function getSecureRandom() { |
|
| 1418 | - return $this->query('SecureRandom'); |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * Returns a Crypto instance |
|
| 1423 | - * |
|
| 1424 | - * @return \OCP\Security\ICrypto |
|
| 1425 | - */ |
|
| 1426 | - public function getCrypto() { |
|
| 1427 | - return $this->query('Crypto'); |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - /** |
|
| 1431 | - * Returns a Hasher instance |
|
| 1432 | - * |
|
| 1433 | - * @return \OCP\Security\IHasher |
|
| 1434 | - */ |
|
| 1435 | - public function getHasher() { |
|
| 1436 | - return $this->query('Hasher'); |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - /** |
|
| 1440 | - * Returns a CredentialsManager instance |
|
| 1441 | - * |
|
| 1442 | - * @return \OCP\Security\ICredentialsManager |
|
| 1443 | - */ |
|
| 1444 | - public function getCredentialsManager() { |
|
| 1445 | - return $this->query('CredentialsManager'); |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - /** |
|
| 1449 | - * Returns an instance of the HTTP helper class |
|
| 1450 | - * |
|
| 1451 | - * @deprecated Use getHTTPClientService() |
|
| 1452 | - * @return \OC\HTTPHelper |
|
| 1453 | - */ |
|
| 1454 | - public function getHTTPHelper() { |
|
| 1455 | - return $this->query('HTTPHelper'); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * Get the certificate manager for the user |
|
| 1460 | - * |
|
| 1461 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1462 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1463 | - */ |
|
| 1464 | - public function getCertificateManager($userId = '') { |
|
| 1465 | - if ($userId === '') { |
|
| 1466 | - $userSession = $this->getUserSession(); |
|
| 1467 | - $user = $userSession->getUser(); |
|
| 1468 | - if (is_null($user)) { |
|
| 1469 | - return null; |
|
| 1470 | - } |
|
| 1471 | - $userId = $user->getUID(); |
|
| 1472 | - } |
|
| 1473 | - return new CertificateManager( |
|
| 1474 | - $userId, |
|
| 1475 | - new View(), |
|
| 1476 | - $this->getConfig(), |
|
| 1477 | - $this->getLogger(), |
|
| 1478 | - $this->getSecureRandom() |
|
| 1479 | - ); |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - /** |
|
| 1483 | - * Returns an instance of the HTTP client service |
|
| 1484 | - * |
|
| 1485 | - * @return \OCP\Http\Client\IClientService |
|
| 1486 | - */ |
|
| 1487 | - public function getHTTPClientService() { |
|
| 1488 | - return $this->query('HttpClientService'); |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - /** |
|
| 1492 | - * Create a new event source |
|
| 1493 | - * |
|
| 1494 | - * @return \OCP\IEventSource |
|
| 1495 | - */ |
|
| 1496 | - public function createEventSource() { |
|
| 1497 | - return new \OC_EventSource(); |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * Get the active event logger |
|
| 1502 | - * |
|
| 1503 | - * The returned logger only logs data when debug mode is enabled |
|
| 1504 | - * |
|
| 1505 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 1506 | - */ |
|
| 1507 | - public function getEventLogger() { |
|
| 1508 | - return $this->query('EventLogger'); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - /** |
|
| 1512 | - * Get the active query logger |
|
| 1513 | - * |
|
| 1514 | - * The returned logger only logs data when debug mode is enabled |
|
| 1515 | - * |
|
| 1516 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 1517 | - */ |
|
| 1518 | - public function getQueryLogger() { |
|
| 1519 | - return $this->query('QueryLogger'); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - /** |
|
| 1523 | - * Get the manager for temporary files and folders |
|
| 1524 | - * |
|
| 1525 | - * @return \OCP\ITempManager |
|
| 1526 | - */ |
|
| 1527 | - public function getTempManager() { |
|
| 1528 | - return $this->query('TempManager'); |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * Get the app manager |
|
| 1533 | - * |
|
| 1534 | - * @return \OCP\App\IAppManager |
|
| 1535 | - */ |
|
| 1536 | - public function getAppManager() { |
|
| 1537 | - return $this->query('AppManager'); |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - /** |
|
| 1541 | - * Creates a new mailer |
|
| 1542 | - * |
|
| 1543 | - * @return \OCP\Mail\IMailer |
|
| 1544 | - */ |
|
| 1545 | - public function getMailer() { |
|
| 1546 | - return $this->query('Mailer'); |
|
| 1547 | - } |
|
| 1548 | - |
|
| 1549 | - /** |
|
| 1550 | - * Get the webroot |
|
| 1551 | - * |
|
| 1552 | - * @return string |
|
| 1553 | - */ |
|
| 1554 | - public function getWebRoot() { |
|
| 1555 | - return $this->webRoot; |
|
| 1556 | - } |
|
| 1557 | - |
|
| 1558 | - /** |
|
| 1559 | - * @return \OC\OCSClient |
|
| 1560 | - */ |
|
| 1561 | - public function getOcsClient() { |
|
| 1562 | - return $this->query('OcsClient'); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - /** |
|
| 1566 | - * @return \OCP\IDateTimeZone |
|
| 1567 | - */ |
|
| 1568 | - public function getDateTimeZone() { |
|
| 1569 | - return $this->query('DateTimeZone'); |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - /** |
|
| 1573 | - * @return \OCP\IDateTimeFormatter |
|
| 1574 | - */ |
|
| 1575 | - public function getDateTimeFormatter() { |
|
| 1576 | - return $this->query('DateTimeFormatter'); |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - /** |
|
| 1580 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1581 | - */ |
|
| 1582 | - public function getMountProviderCollection() { |
|
| 1583 | - return $this->query('MountConfigManager'); |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - /** |
|
| 1587 | - * Get the IniWrapper |
|
| 1588 | - * |
|
| 1589 | - * @return IniGetWrapper |
|
| 1590 | - */ |
|
| 1591 | - public function getIniWrapper() { |
|
| 1592 | - return $this->query('IniWrapper'); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * @return \OCP\Command\IBus |
|
| 1597 | - */ |
|
| 1598 | - public function getCommandBus() { |
|
| 1599 | - return $this->query('AsyncCommandBus'); |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - /** |
|
| 1603 | - * Get the trusted domain helper |
|
| 1604 | - * |
|
| 1605 | - * @return TrustedDomainHelper |
|
| 1606 | - */ |
|
| 1607 | - public function getTrustedDomainHelper() { |
|
| 1608 | - return $this->query('TrustedDomainHelper'); |
|
| 1609 | - } |
|
| 1610 | - |
|
| 1611 | - /** |
|
| 1612 | - * Get the locking provider |
|
| 1613 | - * |
|
| 1614 | - * @return \OCP\Lock\ILockingProvider |
|
| 1615 | - * @since 8.1.0 |
|
| 1616 | - */ |
|
| 1617 | - public function getLockingProvider() { |
|
| 1618 | - return $this->query('LockingProvider'); |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * @return \OCP\Files\Mount\IMountManager |
|
| 1623 | - **/ |
|
| 1624 | - function getMountManager() { |
|
| 1625 | - return $this->query('MountManager'); |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1629 | - function getUserMountCache() { |
|
| 1630 | - return $this->query('UserMountCache'); |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - /** |
|
| 1634 | - * Get the MimeTypeDetector |
|
| 1635 | - * |
|
| 1636 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 1637 | - */ |
|
| 1638 | - public function getMimeTypeDetector() { |
|
| 1639 | - return $this->query('MimeTypeDetector'); |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - /** |
|
| 1643 | - * Get the MimeTypeLoader |
|
| 1644 | - * |
|
| 1645 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 1646 | - */ |
|
| 1647 | - public function getMimeTypeLoader() { |
|
| 1648 | - return $this->query('MimeTypeLoader'); |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - /** |
|
| 1652 | - * Get the manager of all the capabilities |
|
| 1653 | - * |
|
| 1654 | - * @return \OC\CapabilitiesManager |
|
| 1655 | - */ |
|
| 1656 | - public function getCapabilitiesManager() { |
|
| 1657 | - return $this->query('CapabilitiesManager'); |
|
| 1658 | - } |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * Get the EventDispatcher |
|
| 1662 | - * |
|
| 1663 | - * @return EventDispatcherInterface |
|
| 1664 | - * @since 8.2.0 |
|
| 1665 | - */ |
|
| 1666 | - public function getEventDispatcher() { |
|
| 1667 | - return $this->query('EventDispatcher'); |
|
| 1668 | - } |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * Get the Notification Manager |
|
| 1672 | - * |
|
| 1673 | - * @return \OCP\Notification\IManager |
|
| 1674 | - * @since 8.2.0 |
|
| 1675 | - */ |
|
| 1676 | - public function getNotificationManager() { |
|
| 1677 | - return $this->query('NotificationManager'); |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * @return \OCP\Comments\ICommentsManager |
|
| 1682 | - */ |
|
| 1683 | - public function getCommentsManager() { |
|
| 1684 | - return $this->query('CommentsManager'); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1689 | - */ |
|
| 1690 | - public function getThemingDefaults() { |
|
| 1691 | - return $this->query('ThemingDefaults'); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - /** |
|
| 1695 | - * @return \OC\IntegrityCheck\Checker |
|
| 1696 | - */ |
|
| 1697 | - public function getIntegrityCodeChecker() { |
|
| 1698 | - return $this->query('IntegrityCodeChecker'); |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - /** |
|
| 1702 | - * @return \OC\Session\CryptoWrapper |
|
| 1703 | - */ |
|
| 1704 | - public function getSessionCryptoWrapper() { |
|
| 1705 | - return $this->query('CryptoWrapper'); |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * @return CsrfTokenManager |
|
| 1710 | - */ |
|
| 1711 | - public function getCsrfTokenManager() { |
|
| 1712 | - return $this->query('CsrfTokenManager'); |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - /** |
|
| 1716 | - * @return Throttler |
|
| 1717 | - */ |
|
| 1718 | - public function getBruteForceThrottler() { |
|
| 1719 | - return $this->query('Throttler'); |
|
| 1720 | - } |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * @return IContentSecurityPolicyManager |
|
| 1724 | - */ |
|
| 1725 | - public function getContentSecurityPolicyManager() { |
|
| 1726 | - return $this->query('ContentSecurityPolicyManager'); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - /** |
|
| 1730 | - * @return ContentSecurityPolicyNonceManager |
|
| 1731 | - */ |
|
| 1732 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1733 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - /** |
|
| 1737 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1738 | - * |
|
| 1739 | - * @return \OCA\Files_External\Service\BackendService |
|
| 1740 | - */ |
|
| 1741 | - public function getStoragesBackendService() { |
|
| 1742 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - /** |
|
| 1746 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1747 | - * |
|
| 1748 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1749 | - */ |
|
| 1750 | - public function getGlobalStoragesService() { |
|
| 1751 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - /** |
|
| 1755 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1756 | - * |
|
| 1757 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1758 | - */ |
|
| 1759 | - public function getUserGlobalStoragesService() { |
|
| 1760 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1761 | - } |
|
| 1762 | - |
|
| 1763 | - /** |
|
| 1764 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1765 | - * |
|
| 1766 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1767 | - */ |
|
| 1768 | - public function getUserStoragesService() { |
|
| 1769 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1770 | - } |
|
| 1771 | - |
|
| 1772 | - /** |
|
| 1773 | - * @return \OCP\Share\IManager |
|
| 1774 | - */ |
|
| 1775 | - public function getShareManager() { |
|
| 1776 | - return $this->query('ShareManager'); |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * Returns the LDAP Provider |
|
| 1781 | - * |
|
| 1782 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 1783 | - */ |
|
| 1784 | - public function getLDAPProvider() { |
|
| 1785 | - return $this->query('LDAPProvider'); |
|
| 1786 | - } |
|
| 1787 | - |
|
| 1788 | - /** |
|
| 1789 | - * @return \OCP\Settings\IManager |
|
| 1790 | - */ |
|
| 1791 | - public function getSettingsManager() { |
|
| 1792 | - return $this->query('SettingsManager'); |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - /** |
|
| 1796 | - * @return \OCP\Files\IAppData |
|
| 1797 | - */ |
|
| 1798 | - public function getAppDataDir($app) { |
|
| 1799 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1800 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1801 | - return $factory->get($app); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - /** |
|
| 1805 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 1806 | - */ |
|
| 1807 | - public function getLockdownManager() { |
|
| 1808 | - return $this->query('LockdownManager'); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - /** |
|
| 1812 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1813 | - */ |
|
| 1814 | - public function getCloudIdManager() { |
|
| 1815 | - return $this->query(ICloudIdManager::class); |
|
| 1816 | - } |
|
| 881 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 882 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 883 | + $classExists = true; |
|
| 884 | + } else { |
|
| 885 | + $classExists = false; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 889 | + return new ThemingDefaults( |
|
| 890 | + $c->getConfig(), |
|
| 891 | + $c->getL10N('theming'), |
|
| 892 | + $c->getURLGenerator(), |
|
| 893 | + $c->getAppDataDir('theming'), |
|
| 894 | + $c->getMemCacheFactory(), |
|
| 895 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
| 896 | + $this->getAppManager() |
|
| 897 | + ); |
|
| 898 | + } |
|
| 899 | + return new \OC_Defaults(); |
|
| 900 | + }); |
|
| 901 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 902 | + /** @var Factory $cacheFactory */ |
|
| 903 | + $cacheFactory = $c->query(Factory::class); |
|
| 904 | + return new SCSSCacher( |
|
| 905 | + $c->getLogger(), |
|
| 906 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 907 | + $c->getURLGenerator(), |
|
| 908 | + $c->getConfig(), |
|
| 909 | + $c->getThemingDefaults(), |
|
| 910 | + \OC::$SERVERROOT, |
|
| 911 | + $cacheFactory->create('SCSS') |
|
| 912 | + ); |
|
| 913 | + }); |
|
| 914 | + $this->registerService(EventDispatcher::class, function () { |
|
| 915 | + return new EventDispatcher(); |
|
| 916 | + }); |
|
| 917 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 918 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 919 | + |
|
| 920 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 921 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 922 | + $request = new Request( |
|
| 923 | + [ |
|
| 924 | + 'get' => $_GET, |
|
| 925 | + 'post' => $_POST, |
|
| 926 | + 'files' => $_FILES, |
|
| 927 | + 'server' => $_SERVER, |
|
| 928 | + 'env' => $_ENV, |
|
| 929 | + 'cookies' => $_COOKIE, |
|
| 930 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 931 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 932 | + : null, |
|
| 933 | + ], |
|
| 934 | + $c->getSecureRandom(), |
|
| 935 | + $c->getConfig() |
|
| 936 | + ); |
|
| 937 | + |
|
| 938 | + return new CryptoWrapper( |
|
| 939 | + $c->getConfig(), |
|
| 940 | + $c->getCrypto(), |
|
| 941 | + $c->getSecureRandom(), |
|
| 942 | + $request |
|
| 943 | + ); |
|
| 944 | + }); |
|
| 945 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 946 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 947 | + |
|
| 948 | + return new CsrfTokenManager( |
|
| 949 | + $tokenGenerator, |
|
| 950 | + $c->query(SessionStorage::class) |
|
| 951 | + ); |
|
| 952 | + }); |
|
| 953 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 954 | + return new SessionStorage($c->getSession()); |
|
| 955 | + }); |
|
| 956 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 957 | + return new ContentSecurityPolicyManager(); |
|
| 958 | + }); |
|
| 959 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 960 | + |
|
| 961 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 962 | + return new ContentSecurityPolicyNonceManager( |
|
| 963 | + $c->getCsrfTokenManager(), |
|
| 964 | + $c->getRequest() |
|
| 965 | + ); |
|
| 966 | + }); |
|
| 967 | + |
|
| 968 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 969 | + $config = $c->getConfig(); |
|
| 970 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 971 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 972 | + $factory = new $factoryClass($this); |
|
| 973 | + |
|
| 974 | + $manager = new \OC\Share20\Manager( |
|
| 975 | + $c->getLogger(), |
|
| 976 | + $c->getConfig(), |
|
| 977 | + $c->getSecureRandom(), |
|
| 978 | + $c->getHasher(), |
|
| 979 | + $c->getMountManager(), |
|
| 980 | + $c->getGroupManager(), |
|
| 981 | + $c->getL10N('lib'), |
|
| 982 | + $c->getL10NFactory(), |
|
| 983 | + $factory, |
|
| 984 | + $c->getUserManager(), |
|
| 985 | + $c->getLazyRootFolder(), |
|
| 986 | + $c->getEventDispatcher(), |
|
| 987 | + $c->getMailer(), |
|
| 988 | + $c->getURLGenerator(), |
|
| 989 | + $c->getThemingDefaults() |
|
| 990 | + ); |
|
| 991 | + |
|
| 992 | + return $manager; |
|
| 993 | + }); |
|
| 994 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 995 | + |
|
| 996 | + $this->registerService('SettingsManager', function (Server $c) { |
|
| 997 | + $manager = new \OC\Settings\Manager( |
|
| 998 | + $c->getLogger(), |
|
| 999 | + $c->getDatabaseConnection(), |
|
| 1000 | + $c->getL10N('lib'), |
|
| 1001 | + $c->getConfig(), |
|
| 1002 | + $c->getEncryptionManager(), |
|
| 1003 | + $c->getUserManager(), |
|
| 1004 | + $c->getLockingProvider(), |
|
| 1005 | + $c->getRequest(), |
|
| 1006 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 1007 | + $c->getURLGenerator(), |
|
| 1008 | + $c->query(AccountManager::class), |
|
| 1009 | + $c->getGroupManager(), |
|
| 1010 | + $c->getL10NFactory(), |
|
| 1011 | + $c->getThemingDefaults(), |
|
| 1012 | + $c->getAppManager() |
|
| 1013 | + ); |
|
| 1014 | + return $manager; |
|
| 1015 | + }); |
|
| 1016 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1017 | + return new \OC\Files\AppData\Factory( |
|
| 1018 | + $c->getRootFolder(), |
|
| 1019 | + $c->getSystemConfig() |
|
| 1020 | + ); |
|
| 1021 | + }); |
|
| 1022 | + |
|
| 1023 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 1024 | + return new LockdownManager(function () use ($c) { |
|
| 1025 | + return $c->getSession(); |
|
| 1026 | + }); |
|
| 1027 | + }); |
|
| 1028 | + |
|
| 1029 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1030 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1031 | + }); |
|
| 1032 | + |
|
| 1033 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1034 | + return new CloudIdManager(); |
|
| 1035 | + }); |
|
| 1036 | + |
|
| 1037 | + /* To trick DI since we don't extend the DIContainer here */ |
|
| 1038 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1039 | + return new CleanPreviewsBackgroundJob( |
|
| 1040 | + $c->getRootFolder(), |
|
| 1041 | + $c->getLogger(), |
|
| 1042 | + $c->getJobList(), |
|
| 1043 | + new TimeFactory() |
|
| 1044 | + ); |
|
| 1045 | + }); |
|
| 1046 | + |
|
| 1047 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1048 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1049 | + |
|
| 1050 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1051 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1052 | + |
|
| 1053 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1054 | + return new Defaults( |
|
| 1055 | + $c->getThemingDefaults() |
|
| 1056 | + ); |
|
| 1057 | + }); |
|
| 1058 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1059 | + |
|
| 1060 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1061 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1062 | + }); |
|
| 1063 | + |
|
| 1064 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1065 | + return new ShareHelper( |
|
| 1066 | + $c->query(\OCP\Share\IManager::class) |
|
| 1067 | + ); |
|
| 1068 | + }); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + /** |
|
| 1072 | + * @return \OCP\Contacts\IManager |
|
| 1073 | + */ |
|
| 1074 | + public function getContactsManager() { |
|
| 1075 | + return $this->query('ContactsManager'); |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * @return \OC\Encryption\Manager |
|
| 1080 | + */ |
|
| 1081 | + public function getEncryptionManager() { |
|
| 1082 | + return $this->query('EncryptionManager'); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * @return \OC\Encryption\File |
|
| 1087 | + */ |
|
| 1088 | + public function getEncryptionFilesHelper() { |
|
| 1089 | + return $this->query('EncryptionFileHelper'); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + /** |
|
| 1093 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1094 | + */ |
|
| 1095 | + public function getEncryptionKeyStorage() { |
|
| 1096 | + return $this->query('EncryptionKeyStorage'); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + /** |
|
| 1100 | + * The current request object holding all information about the request |
|
| 1101 | + * currently being processed is returned from this method. |
|
| 1102 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1103 | + * |
|
| 1104 | + * @return \OCP\IRequest |
|
| 1105 | + */ |
|
| 1106 | + public function getRequest() { |
|
| 1107 | + return $this->query('Request'); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Returns the preview manager which can create preview images for a given file |
|
| 1112 | + * |
|
| 1113 | + * @return \OCP\IPreview |
|
| 1114 | + */ |
|
| 1115 | + public function getPreviewManager() { |
|
| 1116 | + return $this->query('PreviewManager'); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1121 | + * |
|
| 1122 | + * @see \OCP\ITagManager::load() |
|
| 1123 | + * @return \OCP\ITagManager |
|
| 1124 | + */ |
|
| 1125 | + public function getTagManager() { |
|
| 1126 | + return $this->query('TagManager'); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * Returns the system-tag manager |
|
| 1131 | + * |
|
| 1132 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 1133 | + * |
|
| 1134 | + * @since 9.0.0 |
|
| 1135 | + */ |
|
| 1136 | + public function getSystemTagManager() { |
|
| 1137 | + return $this->query('SystemTagManager'); |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * Returns the system-tag object mapper |
|
| 1142 | + * |
|
| 1143 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1144 | + * |
|
| 1145 | + * @since 9.0.0 |
|
| 1146 | + */ |
|
| 1147 | + public function getSystemTagObjectMapper() { |
|
| 1148 | + return $this->query('SystemTagObjectMapper'); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Returns the avatar manager, used for avatar functionality |
|
| 1153 | + * |
|
| 1154 | + * @return \OCP\IAvatarManager |
|
| 1155 | + */ |
|
| 1156 | + public function getAvatarManager() { |
|
| 1157 | + return $this->query('AvatarManager'); |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + /** |
|
| 1161 | + * Returns the root folder of ownCloud's data directory |
|
| 1162 | + * |
|
| 1163 | + * @return \OCP\Files\IRootFolder |
|
| 1164 | + */ |
|
| 1165 | + public function getRootFolder() { |
|
| 1166 | + return $this->query('LazyRootFolder'); |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * Returns the root folder of ownCloud's data directory |
|
| 1171 | + * This is the lazy variant so this gets only initialized once it |
|
| 1172 | + * is actually used. |
|
| 1173 | + * |
|
| 1174 | + * @return \OCP\Files\IRootFolder |
|
| 1175 | + */ |
|
| 1176 | + public function getLazyRootFolder() { |
|
| 1177 | + return $this->query('LazyRootFolder'); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + /** |
|
| 1181 | + * Returns a view to ownCloud's files folder |
|
| 1182 | + * |
|
| 1183 | + * @param string $userId user ID |
|
| 1184 | + * @return \OCP\Files\Folder|null |
|
| 1185 | + */ |
|
| 1186 | + public function getUserFolder($userId = null) { |
|
| 1187 | + if ($userId === null) { |
|
| 1188 | + $user = $this->getUserSession()->getUser(); |
|
| 1189 | + if (!$user) { |
|
| 1190 | + return null; |
|
| 1191 | + } |
|
| 1192 | + $userId = $user->getUID(); |
|
| 1193 | + } |
|
| 1194 | + $root = $this->getRootFolder(); |
|
| 1195 | + return $root->getUserFolder($userId); |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Returns an app-specific view in ownClouds data directory |
|
| 1200 | + * |
|
| 1201 | + * @return \OCP\Files\Folder |
|
| 1202 | + * @deprecated since 9.2.0 use IAppData |
|
| 1203 | + */ |
|
| 1204 | + public function getAppFolder() { |
|
| 1205 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1206 | + $root = $this->getRootFolder(); |
|
| 1207 | + if (!$root->nodeExists($dir)) { |
|
| 1208 | + $folder = $root->newFolder($dir); |
|
| 1209 | + } else { |
|
| 1210 | + $folder = $root->get($dir); |
|
| 1211 | + } |
|
| 1212 | + return $folder; |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * @return \OC\User\Manager |
|
| 1217 | + */ |
|
| 1218 | + public function getUserManager() { |
|
| 1219 | + return $this->query('UserManager'); |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * @return \OC\Group\Manager |
|
| 1224 | + */ |
|
| 1225 | + public function getGroupManager() { |
|
| 1226 | + return $this->query('GroupManager'); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * @return \OC\User\Session |
|
| 1231 | + */ |
|
| 1232 | + public function getUserSession() { |
|
| 1233 | + return $this->query('UserSession'); |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + /** |
|
| 1237 | + * @return \OCP\ISession |
|
| 1238 | + */ |
|
| 1239 | + public function getSession() { |
|
| 1240 | + return $this->query('UserSession')->getSession(); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * @param \OCP\ISession $session |
|
| 1245 | + */ |
|
| 1246 | + public function setSession(\OCP\ISession $session) { |
|
| 1247 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1248 | + $this->query('UserSession')->setSession($session); |
|
| 1249 | + $this->query(Store::class)->setSession($session); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1254 | + */ |
|
| 1255 | + public function getTwoFactorAuthManager() { |
|
| 1256 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + /** |
|
| 1260 | + * @return \OC\NavigationManager |
|
| 1261 | + */ |
|
| 1262 | + public function getNavigationManager() { |
|
| 1263 | + return $this->query('NavigationManager'); |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + /** |
|
| 1267 | + * @return \OCP\IConfig |
|
| 1268 | + */ |
|
| 1269 | + public function getConfig() { |
|
| 1270 | + return $this->query('AllConfig'); |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * @return \OC\SystemConfig |
|
| 1275 | + */ |
|
| 1276 | + public function getSystemConfig() { |
|
| 1277 | + return $this->query('SystemConfig'); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Returns the app config manager |
|
| 1282 | + * |
|
| 1283 | + * @return \OCP\IAppConfig |
|
| 1284 | + */ |
|
| 1285 | + public function getAppConfig() { |
|
| 1286 | + return $this->query('AppConfig'); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * @return \OCP\L10N\IFactory |
|
| 1291 | + */ |
|
| 1292 | + public function getL10NFactory() { |
|
| 1293 | + return $this->query('L10NFactory'); |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * get an L10N instance |
|
| 1298 | + * |
|
| 1299 | + * @param string $app appid |
|
| 1300 | + * @param string $lang |
|
| 1301 | + * @return IL10N |
|
| 1302 | + */ |
|
| 1303 | + public function getL10N($app, $lang = null) { |
|
| 1304 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * @return \OCP\IURLGenerator |
|
| 1309 | + */ |
|
| 1310 | + public function getURLGenerator() { |
|
| 1311 | + return $this->query('URLGenerator'); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * @return \OCP\IHelper |
|
| 1316 | + */ |
|
| 1317 | + public function getHelper() { |
|
| 1318 | + return $this->query('AppHelper'); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * @return AppFetcher |
|
| 1323 | + */ |
|
| 1324 | + public function getAppFetcher() { |
|
| 1325 | + return $this->query(AppFetcher::class); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1330 | + * getMemCacheFactory() instead. |
|
| 1331 | + * |
|
| 1332 | + * @return \OCP\ICache |
|
| 1333 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1334 | + */ |
|
| 1335 | + public function getCache() { |
|
| 1336 | + return $this->query('UserCache'); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Returns an \OCP\CacheFactory instance |
|
| 1341 | + * |
|
| 1342 | + * @return \OCP\ICacheFactory |
|
| 1343 | + */ |
|
| 1344 | + public function getMemCacheFactory() { |
|
| 1345 | + return $this->query('MemCacheFactory'); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Returns an \OC\RedisFactory instance |
|
| 1350 | + * |
|
| 1351 | + * @return \OC\RedisFactory |
|
| 1352 | + */ |
|
| 1353 | + public function getGetRedisFactory() { |
|
| 1354 | + return $this->query('RedisFactory'); |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * Returns the current session |
|
| 1360 | + * |
|
| 1361 | + * @return \OCP\IDBConnection |
|
| 1362 | + */ |
|
| 1363 | + public function getDatabaseConnection() { |
|
| 1364 | + return $this->query('DatabaseConnection'); |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * Returns the activity manager |
|
| 1369 | + * |
|
| 1370 | + * @return \OCP\Activity\IManager |
|
| 1371 | + */ |
|
| 1372 | + public function getActivityManager() { |
|
| 1373 | + return $this->query('ActivityManager'); |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * Returns an job list for controlling background jobs |
|
| 1378 | + * |
|
| 1379 | + * @return \OCP\BackgroundJob\IJobList |
|
| 1380 | + */ |
|
| 1381 | + public function getJobList() { |
|
| 1382 | + return $this->query('JobList'); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + /** |
|
| 1386 | + * Returns a logger instance |
|
| 1387 | + * |
|
| 1388 | + * @return \OCP\ILogger |
|
| 1389 | + */ |
|
| 1390 | + public function getLogger() { |
|
| 1391 | + return $this->query('Logger'); |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * Returns a router for generating and matching urls |
|
| 1396 | + * |
|
| 1397 | + * @return \OCP\Route\IRouter |
|
| 1398 | + */ |
|
| 1399 | + public function getRouter() { |
|
| 1400 | + return $this->query('Router'); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + /** |
|
| 1404 | + * Returns a search instance |
|
| 1405 | + * |
|
| 1406 | + * @return \OCP\ISearch |
|
| 1407 | + */ |
|
| 1408 | + public function getSearch() { |
|
| 1409 | + return $this->query('Search'); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * Returns a SecureRandom instance |
|
| 1414 | + * |
|
| 1415 | + * @return \OCP\Security\ISecureRandom |
|
| 1416 | + */ |
|
| 1417 | + public function getSecureRandom() { |
|
| 1418 | + return $this->query('SecureRandom'); |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * Returns a Crypto instance |
|
| 1423 | + * |
|
| 1424 | + * @return \OCP\Security\ICrypto |
|
| 1425 | + */ |
|
| 1426 | + public function getCrypto() { |
|
| 1427 | + return $this->query('Crypto'); |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + /** |
|
| 1431 | + * Returns a Hasher instance |
|
| 1432 | + * |
|
| 1433 | + * @return \OCP\Security\IHasher |
|
| 1434 | + */ |
|
| 1435 | + public function getHasher() { |
|
| 1436 | + return $this->query('Hasher'); |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + /** |
|
| 1440 | + * Returns a CredentialsManager instance |
|
| 1441 | + * |
|
| 1442 | + * @return \OCP\Security\ICredentialsManager |
|
| 1443 | + */ |
|
| 1444 | + public function getCredentialsManager() { |
|
| 1445 | + return $this->query('CredentialsManager'); |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + /** |
|
| 1449 | + * Returns an instance of the HTTP helper class |
|
| 1450 | + * |
|
| 1451 | + * @deprecated Use getHTTPClientService() |
|
| 1452 | + * @return \OC\HTTPHelper |
|
| 1453 | + */ |
|
| 1454 | + public function getHTTPHelper() { |
|
| 1455 | + return $this->query('HTTPHelper'); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * Get the certificate manager for the user |
|
| 1460 | + * |
|
| 1461 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1462 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1463 | + */ |
|
| 1464 | + public function getCertificateManager($userId = '') { |
|
| 1465 | + if ($userId === '') { |
|
| 1466 | + $userSession = $this->getUserSession(); |
|
| 1467 | + $user = $userSession->getUser(); |
|
| 1468 | + if (is_null($user)) { |
|
| 1469 | + return null; |
|
| 1470 | + } |
|
| 1471 | + $userId = $user->getUID(); |
|
| 1472 | + } |
|
| 1473 | + return new CertificateManager( |
|
| 1474 | + $userId, |
|
| 1475 | + new View(), |
|
| 1476 | + $this->getConfig(), |
|
| 1477 | + $this->getLogger(), |
|
| 1478 | + $this->getSecureRandom() |
|
| 1479 | + ); |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + /** |
|
| 1483 | + * Returns an instance of the HTTP client service |
|
| 1484 | + * |
|
| 1485 | + * @return \OCP\Http\Client\IClientService |
|
| 1486 | + */ |
|
| 1487 | + public function getHTTPClientService() { |
|
| 1488 | + return $this->query('HttpClientService'); |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + /** |
|
| 1492 | + * Create a new event source |
|
| 1493 | + * |
|
| 1494 | + * @return \OCP\IEventSource |
|
| 1495 | + */ |
|
| 1496 | + public function createEventSource() { |
|
| 1497 | + return new \OC_EventSource(); |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * Get the active event logger |
|
| 1502 | + * |
|
| 1503 | + * The returned logger only logs data when debug mode is enabled |
|
| 1504 | + * |
|
| 1505 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 1506 | + */ |
|
| 1507 | + public function getEventLogger() { |
|
| 1508 | + return $this->query('EventLogger'); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + /** |
|
| 1512 | + * Get the active query logger |
|
| 1513 | + * |
|
| 1514 | + * The returned logger only logs data when debug mode is enabled |
|
| 1515 | + * |
|
| 1516 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 1517 | + */ |
|
| 1518 | + public function getQueryLogger() { |
|
| 1519 | + return $this->query('QueryLogger'); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + /** |
|
| 1523 | + * Get the manager for temporary files and folders |
|
| 1524 | + * |
|
| 1525 | + * @return \OCP\ITempManager |
|
| 1526 | + */ |
|
| 1527 | + public function getTempManager() { |
|
| 1528 | + return $this->query('TempManager'); |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * Get the app manager |
|
| 1533 | + * |
|
| 1534 | + * @return \OCP\App\IAppManager |
|
| 1535 | + */ |
|
| 1536 | + public function getAppManager() { |
|
| 1537 | + return $this->query('AppManager'); |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + /** |
|
| 1541 | + * Creates a new mailer |
|
| 1542 | + * |
|
| 1543 | + * @return \OCP\Mail\IMailer |
|
| 1544 | + */ |
|
| 1545 | + public function getMailer() { |
|
| 1546 | + return $this->query('Mailer'); |
|
| 1547 | + } |
|
| 1548 | + |
|
| 1549 | + /** |
|
| 1550 | + * Get the webroot |
|
| 1551 | + * |
|
| 1552 | + * @return string |
|
| 1553 | + */ |
|
| 1554 | + public function getWebRoot() { |
|
| 1555 | + return $this->webRoot; |
|
| 1556 | + } |
|
| 1557 | + |
|
| 1558 | + /** |
|
| 1559 | + * @return \OC\OCSClient |
|
| 1560 | + */ |
|
| 1561 | + public function getOcsClient() { |
|
| 1562 | + return $this->query('OcsClient'); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + /** |
|
| 1566 | + * @return \OCP\IDateTimeZone |
|
| 1567 | + */ |
|
| 1568 | + public function getDateTimeZone() { |
|
| 1569 | + return $this->query('DateTimeZone'); |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + /** |
|
| 1573 | + * @return \OCP\IDateTimeFormatter |
|
| 1574 | + */ |
|
| 1575 | + public function getDateTimeFormatter() { |
|
| 1576 | + return $this->query('DateTimeFormatter'); |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + /** |
|
| 1580 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1581 | + */ |
|
| 1582 | + public function getMountProviderCollection() { |
|
| 1583 | + return $this->query('MountConfigManager'); |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + /** |
|
| 1587 | + * Get the IniWrapper |
|
| 1588 | + * |
|
| 1589 | + * @return IniGetWrapper |
|
| 1590 | + */ |
|
| 1591 | + public function getIniWrapper() { |
|
| 1592 | + return $this->query('IniWrapper'); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * @return \OCP\Command\IBus |
|
| 1597 | + */ |
|
| 1598 | + public function getCommandBus() { |
|
| 1599 | + return $this->query('AsyncCommandBus'); |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + /** |
|
| 1603 | + * Get the trusted domain helper |
|
| 1604 | + * |
|
| 1605 | + * @return TrustedDomainHelper |
|
| 1606 | + */ |
|
| 1607 | + public function getTrustedDomainHelper() { |
|
| 1608 | + return $this->query('TrustedDomainHelper'); |
|
| 1609 | + } |
|
| 1610 | + |
|
| 1611 | + /** |
|
| 1612 | + * Get the locking provider |
|
| 1613 | + * |
|
| 1614 | + * @return \OCP\Lock\ILockingProvider |
|
| 1615 | + * @since 8.1.0 |
|
| 1616 | + */ |
|
| 1617 | + public function getLockingProvider() { |
|
| 1618 | + return $this->query('LockingProvider'); |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * @return \OCP\Files\Mount\IMountManager |
|
| 1623 | + **/ |
|
| 1624 | + function getMountManager() { |
|
| 1625 | + return $this->query('MountManager'); |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1629 | + function getUserMountCache() { |
|
| 1630 | + return $this->query('UserMountCache'); |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + /** |
|
| 1634 | + * Get the MimeTypeDetector |
|
| 1635 | + * |
|
| 1636 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 1637 | + */ |
|
| 1638 | + public function getMimeTypeDetector() { |
|
| 1639 | + return $this->query('MimeTypeDetector'); |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + /** |
|
| 1643 | + * Get the MimeTypeLoader |
|
| 1644 | + * |
|
| 1645 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 1646 | + */ |
|
| 1647 | + public function getMimeTypeLoader() { |
|
| 1648 | + return $this->query('MimeTypeLoader'); |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + /** |
|
| 1652 | + * Get the manager of all the capabilities |
|
| 1653 | + * |
|
| 1654 | + * @return \OC\CapabilitiesManager |
|
| 1655 | + */ |
|
| 1656 | + public function getCapabilitiesManager() { |
|
| 1657 | + return $this->query('CapabilitiesManager'); |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * Get the EventDispatcher |
|
| 1662 | + * |
|
| 1663 | + * @return EventDispatcherInterface |
|
| 1664 | + * @since 8.2.0 |
|
| 1665 | + */ |
|
| 1666 | + public function getEventDispatcher() { |
|
| 1667 | + return $this->query('EventDispatcher'); |
|
| 1668 | + } |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * Get the Notification Manager |
|
| 1672 | + * |
|
| 1673 | + * @return \OCP\Notification\IManager |
|
| 1674 | + * @since 8.2.0 |
|
| 1675 | + */ |
|
| 1676 | + public function getNotificationManager() { |
|
| 1677 | + return $this->query('NotificationManager'); |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * @return \OCP\Comments\ICommentsManager |
|
| 1682 | + */ |
|
| 1683 | + public function getCommentsManager() { |
|
| 1684 | + return $this->query('CommentsManager'); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1689 | + */ |
|
| 1690 | + public function getThemingDefaults() { |
|
| 1691 | + return $this->query('ThemingDefaults'); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + /** |
|
| 1695 | + * @return \OC\IntegrityCheck\Checker |
|
| 1696 | + */ |
|
| 1697 | + public function getIntegrityCodeChecker() { |
|
| 1698 | + return $this->query('IntegrityCodeChecker'); |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + /** |
|
| 1702 | + * @return \OC\Session\CryptoWrapper |
|
| 1703 | + */ |
|
| 1704 | + public function getSessionCryptoWrapper() { |
|
| 1705 | + return $this->query('CryptoWrapper'); |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * @return CsrfTokenManager |
|
| 1710 | + */ |
|
| 1711 | + public function getCsrfTokenManager() { |
|
| 1712 | + return $this->query('CsrfTokenManager'); |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + /** |
|
| 1716 | + * @return Throttler |
|
| 1717 | + */ |
|
| 1718 | + public function getBruteForceThrottler() { |
|
| 1719 | + return $this->query('Throttler'); |
|
| 1720 | + } |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * @return IContentSecurityPolicyManager |
|
| 1724 | + */ |
|
| 1725 | + public function getContentSecurityPolicyManager() { |
|
| 1726 | + return $this->query('ContentSecurityPolicyManager'); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + /** |
|
| 1730 | + * @return ContentSecurityPolicyNonceManager |
|
| 1731 | + */ |
|
| 1732 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1733 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + /** |
|
| 1737 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1738 | + * |
|
| 1739 | + * @return \OCA\Files_External\Service\BackendService |
|
| 1740 | + */ |
|
| 1741 | + public function getStoragesBackendService() { |
|
| 1742 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + /** |
|
| 1746 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1747 | + * |
|
| 1748 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1749 | + */ |
|
| 1750 | + public function getGlobalStoragesService() { |
|
| 1751 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + /** |
|
| 1755 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1756 | + * |
|
| 1757 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1758 | + */ |
|
| 1759 | + public function getUserGlobalStoragesService() { |
|
| 1760 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1761 | + } |
|
| 1762 | + |
|
| 1763 | + /** |
|
| 1764 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1765 | + * |
|
| 1766 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1767 | + */ |
|
| 1768 | + public function getUserStoragesService() { |
|
| 1769 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1770 | + } |
|
| 1771 | + |
|
| 1772 | + /** |
|
| 1773 | + * @return \OCP\Share\IManager |
|
| 1774 | + */ |
|
| 1775 | + public function getShareManager() { |
|
| 1776 | + return $this->query('ShareManager'); |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + /** |
|
| 1780 | + * Returns the LDAP Provider |
|
| 1781 | + * |
|
| 1782 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 1783 | + */ |
|
| 1784 | + public function getLDAPProvider() { |
|
| 1785 | + return $this->query('LDAPProvider'); |
|
| 1786 | + } |
|
| 1787 | + |
|
| 1788 | + /** |
|
| 1789 | + * @return \OCP\Settings\IManager |
|
| 1790 | + */ |
|
| 1791 | + public function getSettingsManager() { |
|
| 1792 | + return $this->query('SettingsManager'); |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + /** |
|
| 1796 | + * @return \OCP\Files\IAppData |
|
| 1797 | + */ |
|
| 1798 | + public function getAppDataDir($app) { |
|
| 1799 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1800 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1801 | + return $factory->get($app); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + /** |
|
| 1805 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 1806 | + */ |
|
| 1807 | + public function getLockdownManager() { |
|
| 1808 | + return $this->query('LockdownManager'); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + /** |
|
| 1812 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1813 | + */ |
|
| 1814 | + public function getCloudIdManager() { |
|
| 1815 | + return $this->query(ICloudIdManager::class); |
|
| 1816 | + } |
|
| 1817 | 1817 | } |