@@ -61,1435 +61,1435 @@ |
||
| 61 | 61 | use OCP\IUser; |
| 62 | 62 | |
| 63 | 63 | class OC_Util { |
| 64 | - public static $scripts = array(); |
|
| 65 | - public static $styles = array(); |
|
| 66 | - public static $headers = array(); |
|
| 67 | - private static $rootMounted = false; |
|
| 68 | - private static $fsSetup = false; |
|
| 69 | - |
|
| 70 | - /** @var array Local cache of version.php */ |
|
| 71 | - private static $versionCache = null; |
|
| 72 | - |
|
| 73 | - protected static function getAppManager() { |
|
| 74 | - return \OC::$server->getAppManager(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - private static function initLocalStorageRootFS() { |
|
| 78 | - // mount local file backend as root |
|
| 79 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | - //first set up the local "root" storage |
|
| 81 | - \OC\Files\Filesystem::initMountManager(); |
|
| 82 | - if (!self::$rootMounted) { |
|
| 83 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | - self::$rootMounted = true; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * mounting an object storage as the root fs will in essence remove the |
|
| 90 | - * necessity of a data folder being present. |
|
| 91 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | - * |
|
| 93 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | - */ |
|
| 95 | - private static function initObjectStoreRootFS($config) { |
|
| 96 | - // check misconfiguration |
|
| 97 | - if (empty($config['class'])) { |
|
| 98 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | - } |
|
| 100 | - if (!isset($config['arguments'])) { |
|
| 101 | - $config['arguments'] = array(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // instantiate object store implementation |
|
| 105 | - $name = $config['class']; |
|
| 106 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | - $segments = explode('\\', $name); |
|
| 108 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | - } |
|
| 110 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | - // mount with plain / root object store implementation |
|
| 112 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | - |
|
| 114 | - // mount object storage as root |
|
| 115 | - \OC\Files\Filesystem::initMountManager(); |
|
| 116 | - if (!self::$rootMounted) { |
|
| 117 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | - self::$rootMounted = true; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * mounting an object storage as the root fs will in essence remove the |
|
| 124 | - * necessity of a data folder being present. |
|
| 125 | - * |
|
| 126 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 127 | - */ |
|
| 128 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
| 129 | - // check misconfiguration |
|
| 130 | - if (empty($config['class'])) { |
|
| 131 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 132 | - } |
|
| 133 | - if (!isset($config['arguments'])) { |
|
| 134 | - $config['arguments'] = array(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // instantiate object store implementation |
|
| 138 | - $name = $config['class']; |
|
| 139 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 140 | - $segments = explode('\\', $name); |
|
| 141 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if (!isset($config['arguments']['bucket'])) { |
|
| 145 | - $config['arguments']['bucket'] = ''; |
|
| 146 | - } |
|
| 147 | - // put the root FS always in first bucket for multibucket configuration |
|
| 148 | - $config['arguments']['bucket'] .= '0'; |
|
| 149 | - |
|
| 150 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 151 | - // mount with plain / root object store implementation |
|
| 152 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 153 | - |
|
| 154 | - // mount object storage as root |
|
| 155 | - \OC\Files\Filesystem::initMountManager(); |
|
| 156 | - if (!self::$rootMounted) { |
|
| 157 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 158 | - self::$rootMounted = true; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Can be set up |
|
| 164 | - * |
|
| 165 | - * @param string $user |
|
| 166 | - * @return boolean |
|
| 167 | - * @description configure the initial filesystem based on the configuration |
|
| 168 | - */ |
|
| 169 | - public static function setupFS($user = '') { |
|
| 170 | - //setting up the filesystem twice can only lead to trouble |
|
| 171 | - if (self::$fsSetup) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 176 | - |
|
| 177 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 178 | - if ($user === null) { |
|
| 179 | - $user = ''; |
|
| 180 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 181 | - $user = OC_User::getUser(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 185 | - OC_App::loadApps(array('filesystem')); |
|
| 186 | - |
|
| 187 | - // the filesystem will finish when $user is not empty, |
|
| 188 | - // mark fs setup here to avoid doing the setup from loading |
|
| 189 | - // OC_Filesystem |
|
| 190 | - if ($user != '') { |
|
| 191 | - self::$fsSetup = true; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - \OC\Files\Filesystem::initMountManager(); |
|
| 195 | - |
|
| 196 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 197 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 198 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 199 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 200 | - $storage->setMountOptions($mount->getOptions()); |
|
| 201 | - } |
|
| 202 | - return $storage; |
|
| 203 | - }); |
|
| 204 | - |
|
| 205 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 207 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 208 | - 'storage' => $storage, |
|
| 209 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 210 | - ]); |
|
| 211 | - } |
|
| 212 | - return $storage; |
|
| 213 | - }); |
|
| 214 | - |
|
| 215 | - // install storage availability wrapper, before most other wrappers |
|
| 216 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 217 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 218 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 219 | - } |
|
| 220 | - return $storage; |
|
| 221 | - }); |
|
| 222 | - |
|
| 223 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 224 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 225 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 226 | - } |
|
| 227 | - return $storage; |
|
| 228 | - }); |
|
| 229 | - |
|
| 230 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 231 | - // set up quota for home storages, even for other users |
|
| 232 | - // which can happen when using sharing |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @var \OC\Files\Storage\Storage $storage |
|
| 236 | - */ |
|
| 237 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 238 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 239 | - ) { |
|
| 240 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 241 | - if (is_object($storage->getUser())) { |
|
| 242 | - $user = $storage->getUser()->getUID(); |
|
| 243 | - $quota = OC_Util::getUserQuota($user); |
|
| 244 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 245 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $storage; |
|
| 251 | - }); |
|
| 252 | - |
|
| 253 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 254 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 255 | - |
|
| 256 | - //check if we are using an object storage |
|
| 257 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 258 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 259 | - |
|
| 260 | - // use the same order as in ObjectHomeMountProvider |
|
| 261 | - if (isset($objectStoreMultibucket)) { |
|
| 262 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 263 | - } elseif (isset($objectStore)) { |
|
| 264 | - self::initObjectStoreRootFS($objectStore); |
|
| 265 | - } else { |
|
| 266 | - self::initLocalStorageRootFS(); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - if ($user != '' && !OCP\User::userExists($user)) { |
|
| 270 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 275 | - if ($user != "") { |
|
| 276 | - |
|
| 277 | - $userDir = '/' . $user . '/files'; |
|
| 278 | - |
|
| 279 | - //jail the user into his "home" directory |
|
| 280 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 281 | - |
|
| 282 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 283 | - } |
|
| 284 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 285 | - return true; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * check if a password is required for each public link |
|
| 290 | - * |
|
| 291 | - * @return boolean |
|
| 292 | - */ |
|
| 293 | - public static function isPublicLinkPasswordRequired() { |
|
| 294 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 295 | - $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 296 | - return ($enforcePassword === 'yes') ? true : false; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * check if sharing is disabled for the current user |
|
| 301 | - * @param IConfig $config |
|
| 302 | - * @param IGroupManager $groupManager |
|
| 303 | - * @param IUser|null $user |
|
| 304 | - * @return bool |
|
| 305 | - */ |
|
| 306 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 307 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 308 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 309 | - $excludedGroups = json_decode($groupsList); |
|
| 310 | - if (is_null($excludedGroups)) { |
|
| 311 | - $excludedGroups = explode(',', $groupsList); |
|
| 312 | - $newValue = json_encode($excludedGroups); |
|
| 313 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 314 | - } |
|
| 315 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 316 | - if (!empty($usersGroups)) { |
|
| 317 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 318 | - // if the user is only in groups which are disabled for sharing then |
|
| 319 | - // sharing is also disabled for the user |
|
| 320 | - if (empty($remainingGroups)) { |
|
| 321 | - return true; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * check if share API enforces a default expire date |
|
| 330 | - * |
|
| 331 | - * @return boolean |
|
| 332 | - */ |
|
| 333 | - public static function isDefaultExpireDateEnforced() { |
|
| 334 | - $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 335 | - $enforceDefaultExpireDate = false; |
|
| 336 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 337 | - $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 338 | - $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - return $enforceDefaultExpireDate; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Get the quota of a user |
|
| 346 | - * |
|
| 347 | - * @param string $userId |
|
| 348 | - * @return int Quota bytes |
|
| 349 | - */ |
|
| 350 | - public static function getUserQuota($userId) { |
|
| 351 | - $user = \OC::$server->getUserManager()->get($userId); |
|
| 352 | - if (is_null($user)) { |
|
| 353 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 354 | - } |
|
| 355 | - $userQuota = $user->getQuota(); |
|
| 356 | - if($userQuota === 'none') { |
|
| 357 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 358 | - } |
|
| 359 | - return OC_Helper::computerFileSize($userQuota); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * copies the skeleton to the users /files |
|
| 364 | - * |
|
| 365 | - * @param String $userId |
|
| 366 | - * @param \OCP\Files\Folder $userDirectory |
|
| 367 | - * @throws \RuntimeException |
|
| 368 | - */ |
|
| 369 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 370 | - |
|
| 371 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 372 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 373 | - |
|
| 374 | - if ($instanceId === null) { |
|
| 375 | - throw new \RuntimeException('no instance id!'); |
|
| 376 | - } |
|
| 377 | - $appdata = 'appdata_' . $instanceId; |
|
| 378 | - if ($userId === $appdata) { |
|
| 379 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - if (!empty($skeletonDirectory)) { |
|
| 383 | - \OCP\Util::writeLog( |
|
| 384 | - 'files_skeleton', |
|
| 385 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 386 | - \OCP\Util::DEBUG |
|
| 387 | - ); |
|
| 388 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 389 | - // update the file cache |
|
| 390 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * copies a directory recursively by using streams |
|
| 396 | - * |
|
| 397 | - * @param string $source |
|
| 398 | - * @param \OCP\Files\Folder $target |
|
| 399 | - * @return void |
|
| 400 | - */ |
|
| 401 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 402 | - $logger = \OC::$server->getLogger(); |
|
| 403 | - |
|
| 404 | - // Verify if folder exists |
|
| 405 | - $dir = opendir($source); |
|
| 406 | - if($dir === false) { |
|
| 407 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 408 | - return; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // Copy the files |
|
| 412 | - while (false !== ($file = readdir($dir))) { |
|
| 413 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 414 | - if (is_dir($source . '/' . $file)) { |
|
| 415 | - $child = $target->newFolder($file); |
|
| 416 | - self::copyr($source . '/' . $file, $child); |
|
| 417 | - } else { |
|
| 418 | - $child = $target->newFile($file); |
|
| 419 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 420 | - if($sourceStream === false) { |
|
| 421 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 422 | - closedir($dir); |
|
| 423 | - return; |
|
| 424 | - } |
|
| 425 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - closedir($dir); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * @return void |
|
| 434 | - */ |
|
| 435 | - public static function tearDownFS() { |
|
| 436 | - \OC\Files\Filesystem::tearDown(); |
|
| 437 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 438 | - self::$fsSetup = false; |
|
| 439 | - self::$rootMounted = false; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * get the current installed version of ownCloud |
|
| 444 | - * |
|
| 445 | - * @return array |
|
| 446 | - */ |
|
| 447 | - public static function getVersion() { |
|
| 448 | - OC_Util::loadVersion(); |
|
| 449 | - return self::$versionCache['OC_Version']; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * get the current installed version string of ownCloud |
|
| 454 | - * |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public static function getVersionString() { |
|
| 458 | - OC_Util::loadVersion(); |
|
| 459 | - return self::$versionCache['OC_VersionString']; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @deprecated the value is of no use anymore |
|
| 464 | - * @return string |
|
| 465 | - */ |
|
| 466 | - public static function getEditionString() { |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @description get the update channel of the current installed of ownCloud. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public static function getChannel() { |
|
| 475 | - OC_Util::loadVersion(); |
|
| 476 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @description get the build number of the current installed of ownCloud. |
|
| 481 | - * @return string |
|
| 482 | - */ |
|
| 483 | - public static function getBuild() { |
|
| 484 | - OC_Util::loadVersion(); |
|
| 485 | - return self::$versionCache['OC_Build']; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * @description load the version.php into the session as cache |
|
| 490 | - */ |
|
| 491 | - private static function loadVersion() { |
|
| 492 | - if (self::$versionCache !== null) { |
|
| 493 | - return; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 497 | - require OC::$SERVERROOT . '/version.php'; |
|
| 498 | - /** @var $timestamp int */ |
|
| 499 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 500 | - /** @var $OC_Version string */ |
|
| 501 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 502 | - /** @var $OC_VersionString string */ |
|
| 503 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 504 | - /** @var $OC_Build string */ |
|
| 505 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 506 | - |
|
| 507 | - /** @var $OC_Channel string */ |
|
| 508 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 513 | - * |
|
| 514 | - * @param string $application application to get the files from |
|
| 515 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 516 | - * @param string $file the file inside of the above folder |
|
| 517 | - * @return string the path |
|
| 518 | - */ |
|
| 519 | - private static function generatePath($application, $directory, $file) { |
|
| 520 | - if (is_null($file)) { |
|
| 521 | - $file = $application; |
|
| 522 | - $application = ""; |
|
| 523 | - } |
|
| 524 | - if (!empty($application)) { |
|
| 525 | - return "$application/$directory/$file"; |
|
| 526 | - } else { |
|
| 527 | - return "$directory/$file"; |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * add a javascript file |
|
| 533 | - * |
|
| 534 | - * @param string $application application id |
|
| 535 | - * @param string|null $file filename |
|
| 536 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 537 | - * @return void |
|
| 538 | - */ |
|
| 539 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 540 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 541 | - |
|
| 542 | - // core js files need separate handling |
|
| 543 | - if ($application !== 'core' && $file !== null) { |
|
| 544 | - self::addTranslations ( $application ); |
|
| 545 | - } |
|
| 546 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * add a javascript file from the vendor sub folder |
|
| 551 | - * |
|
| 552 | - * @param string $application application id |
|
| 553 | - * @param string|null $file filename |
|
| 554 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 558 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * add a translation JS file |
|
| 564 | - * |
|
| 565 | - * @param string $application application id |
|
| 566 | - * @param string $languageCode language code, defaults to the current language |
|
| 567 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 568 | - */ |
|
| 569 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 570 | - if (is_null($languageCode)) { |
|
| 571 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 572 | - } |
|
| 573 | - if (!empty($application)) { |
|
| 574 | - $path = "$application/l10n/$languageCode"; |
|
| 575 | - } else { |
|
| 576 | - $path = "l10n/$languageCode"; |
|
| 577 | - } |
|
| 578 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * add a css file |
|
| 583 | - * |
|
| 584 | - * @param string $application application id |
|
| 585 | - * @param string|null $file filename |
|
| 586 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 587 | - * @return void |
|
| 588 | - */ |
|
| 589 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 590 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 591 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * add a css file from the vendor sub folder |
|
| 596 | - * |
|
| 597 | - * @param string $application application id |
|
| 598 | - * @param string|null $file filename |
|
| 599 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 600 | - * @return void |
|
| 601 | - */ |
|
| 602 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 603 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 604 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * add an external resource css/js file |
|
| 609 | - * |
|
| 610 | - * @param string $application application id |
|
| 611 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 612 | - * @param string $path |
|
| 613 | - * @param string $type (script or style) |
|
| 614 | - * @return void |
|
| 615 | - */ |
|
| 616 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 617 | - |
|
| 618 | - if ($type === "style") { |
|
| 619 | - if (!in_array($path, self::$styles)) { |
|
| 620 | - if ($prepend === true) { |
|
| 621 | - array_unshift ( self::$styles, $path ); |
|
| 622 | - } else { |
|
| 623 | - self::$styles[] = $path; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } elseif ($type === "script") { |
|
| 627 | - if (!in_array($path, self::$scripts)) { |
|
| 628 | - if ($prepend === true) { |
|
| 629 | - array_unshift ( self::$scripts, $path ); |
|
| 630 | - } else { |
|
| 631 | - self::$scripts [] = $path; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Add a custom element to the header |
|
| 639 | - * If $text is null then the element will be written as empty element. |
|
| 640 | - * So use "" to get a closing tag. |
|
| 641 | - * @param string $tag tag name of the element |
|
| 642 | - * @param array $attributes array of attributes for the element |
|
| 643 | - * @param string $text the text content for the element |
|
| 644 | - */ |
|
| 645 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 646 | - self::$headers[] = array( |
|
| 647 | - 'tag' => $tag, |
|
| 648 | - 'attributes' => $attributes, |
|
| 649 | - 'text' => $text |
|
| 650 | - ); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * formats a timestamp in the "right" way |
|
| 655 | - * |
|
| 656 | - * @param int $timestamp |
|
| 657 | - * @param bool $dateOnly option to omit time from the result |
|
| 658 | - * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 659 | - * @return string timestamp |
|
| 660 | - * |
|
| 661 | - * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 662 | - */ |
|
| 663 | - public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 664 | - if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 665 | - $timeZone = new \DateTimeZone($timeZone); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
| 669 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 670 | - if ($dateOnly) { |
|
| 671 | - return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 672 | - } |
|
| 673 | - return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * check if the current server configuration is suitable for ownCloud |
|
| 678 | - * |
|
| 679 | - * @param \OC\SystemConfig $config |
|
| 680 | - * @return array arrays with error messages and hints |
|
| 681 | - */ |
|
| 682 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 683 | - $l = \OC::$server->getL10N('lib'); |
|
| 684 | - $errors = array(); |
|
| 685 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 686 | - |
|
| 687 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 688 | - // this check needs to be done every time |
|
| 689 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 693 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 694 | - return $errors; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $webServerRestart = false; |
|
| 698 | - $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 699 | - \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 700 | - |
|
| 701 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 702 | - |
|
| 703 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 704 | - if (empty($availableDatabases)) { |
|
| 705 | - $errors[] = array( |
|
| 706 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 707 | - 'hint' => '' //TODO: sane hint |
|
| 708 | - ); |
|
| 709 | - $webServerRestart = true; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // Check if config folder is writable. |
|
| 713 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 714 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 715 | - $errors[] = array( |
|
| 716 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 717 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 718 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 719 | - ); |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - // Check if there is a writable install folder. |
|
| 724 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 725 | - if (OC_App::getInstallPath() === null |
|
| 726 | - || !is_writable(OC_App::getInstallPath()) |
|
| 727 | - || !is_readable(OC_App::getInstallPath()) |
|
| 728 | - ) { |
|
| 729 | - $errors[] = array( |
|
| 730 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 731 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 732 | - . ' or disabling the appstore in the config file. See %s', |
|
| 733 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 734 | - ); |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - // Create root dir. |
|
| 738 | - if ($config->getValue('installed', false)) { |
|
| 739 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 740 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 741 | - if ($success) { |
|
| 742 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 743 | - } else { |
|
| 744 | - $errors[] = [ |
|
| 745 | - 'error' => $l->t('Cannot create "data" directory'), |
|
| 746 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 747 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 748 | - ]; |
|
| 749 | - } |
|
| 750 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 751 | - //common hint for all file permissions error messages |
|
| 752 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 753 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 754 | - $errors[] = [ |
|
| 755 | - 'error' => 'Your data directory is not writable', |
|
| 756 | - 'hint' => $permissionsHint |
|
| 757 | - ]; |
|
| 758 | - } else { |
|
| 759 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 764 | - $errors[] = array( |
|
| 765 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 766 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 767 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 768 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 769 | - ); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // Contains the dependencies that should be checked against |
|
| 773 | - // classes = class_exists |
|
| 774 | - // functions = function_exists |
|
| 775 | - // defined = defined |
|
| 776 | - // ini = ini_get |
|
| 777 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 778 | - // When adding new checks always verify that they pass on Travis as well |
|
| 779 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 780 | - $dependencies = array( |
|
| 781 | - 'classes' => array( |
|
| 782 | - 'ZipArchive' => 'zip', |
|
| 783 | - 'DOMDocument' => 'dom', |
|
| 784 | - 'XMLWriter' => 'XMLWriter', |
|
| 785 | - 'XMLReader' => 'XMLReader', |
|
| 786 | - ), |
|
| 787 | - 'functions' => [ |
|
| 788 | - 'xml_parser_create' => 'libxml', |
|
| 789 | - 'mb_strcut' => 'mb multibyte', |
|
| 790 | - 'ctype_digit' => 'ctype', |
|
| 791 | - 'json_encode' => 'JSON', |
|
| 792 | - 'gd_info' => 'GD', |
|
| 793 | - 'gzencode' => 'zlib', |
|
| 794 | - 'iconv' => 'iconv', |
|
| 795 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 796 | - 'hash' => 'HASH Message Digest Framework', |
|
| 797 | - 'curl_init' => 'cURL', |
|
| 798 | - 'openssl_verify' => 'OpenSSL', |
|
| 799 | - ], |
|
| 800 | - 'defined' => array( |
|
| 801 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 802 | - ), |
|
| 803 | - 'ini' => [ |
|
| 804 | - 'default_charset' => 'UTF-8', |
|
| 805 | - ], |
|
| 806 | - ); |
|
| 807 | - $missingDependencies = array(); |
|
| 808 | - $invalidIniSettings = []; |
|
| 809 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 813 | - * and prevents installation. Once HHVM is more compatible with our |
|
| 814 | - * approach to check for these values we should re-enable those |
|
| 815 | - * checks. |
|
| 816 | - */ |
|
| 817 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 818 | - if (!self::runningOnHhvm()) { |
|
| 819 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 820 | - if (!class_exists($class)) { |
|
| 821 | - $missingDependencies[] = $module; |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 825 | - if (!function_exists($function)) { |
|
| 826 | - $missingDependencies[] = $module; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 830 | - if (!defined($defined)) { |
|
| 831 | - $missingDependencies[] = $module; |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 835 | - if (is_bool($expected)) { |
|
| 836 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 837 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - if (is_int($expected)) { |
|
| 841 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 842 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - if (is_string($expected)) { |
|
| 846 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 847 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - foreach($missingDependencies as $missingDependency) { |
|
| 854 | - $errors[] = array( |
|
| 855 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 856 | - 'hint' => $moduleHint |
|
| 857 | - ); |
|
| 858 | - $webServerRestart = true; |
|
| 859 | - } |
|
| 860 | - foreach($invalidIniSettings as $setting) { |
|
| 861 | - if(is_bool($setting[1])) { |
|
| 862 | - $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 863 | - } |
|
| 864 | - $errors[] = [ |
|
| 865 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 866 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 867 | - ]; |
|
| 868 | - $webServerRestart = true; |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 873 | - * module is installed as it will return null if the checking setting is |
|
| 874 | - * not available and thus a check on the boolean value fails. |
|
| 875 | - * |
|
| 876 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 877 | - * check somehow in the long-term. |
|
| 878 | - */ |
|
| 879 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 880 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 881 | - $errors[] = array( |
|
| 882 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 883 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 884 | - ); |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - if(function_exists('xml_parser_create') && |
|
| 888 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 889 | - $version = LIBXML_LOADED_VERSION; |
|
| 890 | - $major = floor($version/10000); |
|
| 891 | - $version -= ($major * 10000); |
|
| 892 | - $minor = floor($version/100); |
|
| 893 | - $version -= ($minor * 100); |
|
| 894 | - $patch = $version; |
|
| 895 | - $errors[] = array( |
|
| 896 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 897 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 898 | - ); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - if (!self::isAnnotationsWorking()) { |
|
| 902 | - $errors[] = array( |
|
| 903 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 904 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 905 | - ); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 909 | - $errors[] = array( |
|
| 910 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 911 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 916 | - |
|
| 917 | - // Cache the result of this function |
|
| 918 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 919 | - |
|
| 920 | - return $errors; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Check the database version |
|
| 925 | - * |
|
| 926 | - * @return array errors array |
|
| 927 | - */ |
|
| 928 | - public static function checkDatabaseVersion() { |
|
| 929 | - $l = \OC::$server->getL10N('lib'); |
|
| 930 | - $errors = array(); |
|
| 931 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 932 | - if ($dbType === 'pgsql') { |
|
| 933 | - // check PostgreSQL version |
|
| 934 | - try { |
|
| 935 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 936 | - $data = $result->fetchRow(); |
|
| 937 | - if (isset($data['server_version'])) { |
|
| 938 | - $version = $data['server_version']; |
|
| 939 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 940 | - $errors[] = array( |
|
| 941 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 942 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 943 | - ); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 947 | - $logger = \OC::$server->getLogger(); |
|
| 948 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 949 | - $logger->logException($e); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - return $errors; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * Check for correct file permissions of data directory |
|
| 957 | - * |
|
| 958 | - * @param string $dataDirectory |
|
| 959 | - * @return array arrays with error messages and hints |
|
| 960 | - */ |
|
| 961 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 962 | - $l = \OC::$server->getL10N('lib'); |
|
| 963 | - $errors = array(); |
|
| 964 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 965 | - . ' cannot be listed by other users.'); |
|
| 966 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 967 | - if (substr($perms, -1) !== '0') { |
|
| 968 | - chmod($dataDirectory, 0770); |
|
| 969 | - clearstatcache(); |
|
| 970 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 971 | - if ($perms[2] !== '0') { |
|
| 972 | - $errors[] = [ |
|
| 973 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
| 974 | - 'hint' => $permissionsModHint |
|
| 975 | - ]; |
|
| 976 | - } |
|
| 977 | - } |
|
| 978 | - return $errors; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * Check that the data directory exists and is valid by |
|
| 983 | - * checking the existence of the ".ocdata" file. |
|
| 984 | - * |
|
| 985 | - * @param string $dataDirectory data directory path |
|
| 986 | - * @return array errors found |
|
| 987 | - */ |
|
| 988 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 989 | - $l = \OC::$server->getL10N('lib'); |
|
| 990 | - $errors = []; |
|
| 991 | - if ($dataDirectory[0] !== '/') { |
|
| 992 | - $errors[] = [ |
|
| 993 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 994 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 995 | - ]; |
|
| 996 | - } |
|
| 997 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 998 | - $errors[] = [ |
|
| 999 | - 'error' => $l->t('Your data directory is invalid'), |
|
| 1000 | - 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 1001 | - ' ".ocdata" in its root.') |
|
| 1002 | - ]; |
|
| 1003 | - } |
|
| 1004 | - return $errors; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * Check if the user is logged in, redirects to home if not. With |
|
| 1009 | - * redirect URL parameter to the request URI. |
|
| 1010 | - * |
|
| 1011 | - * @return void |
|
| 1012 | - */ |
|
| 1013 | - public static function checkLoggedIn() { |
|
| 1014 | - // Check if we are a user |
|
| 1015 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1016 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1017 | - 'core.login.showLoginForm', |
|
| 1018 | - [ |
|
| 1019 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1020 | - ] |
|
| 1021 | - ) |
|
| 1022 | - ); |
|
| 1023 | - exit(); |
|
| 1024 | - } |
|
| 1025 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1026 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1027 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1028 | - exit(); |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Check if the user is a admin, redirects to home if not |
|
| 1034 | - * |
|
| 1035 | - * @return void |
|
| 1036 | - */ |
|
| 1037 | - public static function checkAdminUser() { |
|
| 1038 | - OC_Util::checkLoggedIn(); |
|
| 1039 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1040 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1041 | - exit(); |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * Check if the user is a subadmin, redirects to home if not |
|
| 1047 | - * |
|
| 1048 | - * @return null|boolean $groups where the current user is subadmin |
|
| 1049 | - */ |
|
| 1050 | - public static function checkSubAdminUser() { |
|
| 1051 | - OC_Util::checkLoggedIn(); |
|
| 1052 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1053 | - $isSubAdmin = false; |
|
| 1054 | - if($userObject !== null) { |
|
| 1055 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - if (!$isSubAdmin) { |
|
| 1059 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1060 | - exit(); |
|
| 1061 | - } |
|
| 1062 | - return true; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Returns the URL of the default page |
|
| 1067 | - * based on the system configuration and |
|
| 1068 | - * the apps visible for the current user |
|
| 1069 | - * |
|
| 1070 | - * @return string URL |
|
| 1071 | - */ |
|
| 1072 | - public static function getDefaultPageUrl() { |
|
| 1073 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1074 | - // Deny the redirect if the URL contains a @ |
|
| 1075 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1076 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1077 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1078 | - } else { |
|
| 1079 | - $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1080 | - if ($defaultPage) { |
|
| 1081 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1082 | - } else { |
|
| 1083 | - $appId = 'files'; |
|
| 1084 | - $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1085 | - // find the first app that is enabled for the current user |
|
| 1086 | - foreach ($defaultApps as $defaultApp) { |
|
| 1087 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1088 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1089 | - $appId = $defaultApp; |
|
| 1090 | - break; |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1095 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1096 | - } else { |
|
| 1097 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - return $location; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Redirect to the user default page |
|
| 1106 | - * |
|
| 1107 | - * @return void |
|
| 1108 | - */ |
|
| 1109 | - public static function redirectToDefaultPage() { |
|
| 1110 | - $location = self::getDefaultPageUrl(); |
|
| 1111 | - header('Location: ' . $location); |
|
| 1112 | - exit(); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * get an id unique for this instance |
|
| 1117 | - * |
|
| 1118 | - * @return string |
|
| 1119 | - */ |
|
| 1120 | - public static function getInstanceId() { |
|
| 1121 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1122 | - if (is_null($id)) { |
|
| 1123 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1124 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1125 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1126 | - } |
|
| 1127 | - return $id; |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * Public function to sanitize HTML |
|
| 1132 | - * |
|
| 1133 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1134 | - * string or array of strings before displaying it on a web page. |
|
| 1135 | - * |
|
| 1136 | - * @param string|array $value |
|
| 1137 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1138 | - */ |
|
| 1139 | - public static function sanitizeHTML($value) { |
|
| 1140 | - if (is_array($value)) { |
|
| 1141 | - $value = array_map(function($value) { |
|
| 1142 | - return self::sanitizeHTML($value); |
|
| 1143 | - }, $value); |
|
| 1144 | - } else { |
|
| 1145 | - // Specify encoding for PHP<5.4 |
|
| 1146 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1147 | - } |
|
| 1148 | - return $value; |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Public function to encode url parameters |
|
| 1153 | - * |
|
| 1154 | - * This function is used to encode path to file before output. |
|
| 1155 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1156 | - * Character '/' is preserved as is. |
|
| 1157 | - * |
|
| 1158 | - * @param string $component part of URI to encode |
|
| 1159 | - * @return string |
|
| 1160 | - */ |
|
| 1161 | - public static function encodePath($component) { |
|
| 1162 | - $encoded = rawurlencode($component); |
|
| 1163 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1164 | - return $encoded; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1169 | - // php dev server does not support htaccess |
|
| 1170 | - if (php_sapi_name() === 'cli-server') { |
|
| 1171 | - return false; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - // testdata |
|
| 1175 | - $fileName = '/htaccesstest.txt'; |
|
| 1176 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1177 | - |
|
| 1178 | - // creating a test file |
|
| 1179 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1180 | - |
|
| 1181 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1182 | - return false; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - $fp = @fopen($testFile, 'w'); |
|
| 1186 | - if (!$fp) { |
|
| 1187 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1188 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1189 | - } |
|
| 1190 | - fwrite($fp, $testContent); |
|
| 1191 | - fclose($fp); |
|
| 1192 | - |
|
| 1193 | - return $testContent; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * Check if the .htaccess file is working |
|
| 1198 | - * @param \OCP\IConfig $config |
|
| 1199 | - * @return bool |
|
| 1200 | - * @throws Exception |
|
| 1201 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1202 | - */ |
|
| 1203 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1204 | - |
|
| 1205 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1206 | - return true; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1210 | - if ($testContent === false) { |
|
| 1211 | - return false; |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - $fileName = '/htaccesstest.txt'; |
|
| 1215 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1216 | - |
|
| 1217 | - // accessing the file via http |
|
| 1218 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1219 | - try { |
|
| 1220 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1221 | - } catch (\Exception $e) { |
|
| 1222 | - $content = false; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - // cleanup |
|
| 1226 | - @unlink($testFile); |
|
| 1227 | - |
|
| 1228 | - /* |
|
| 64 | + public static $scripts = array(); |
|
| 65 | + public static $styles = array(); |
|
| 66 | + public static $headers = array(); |
|
| 67 | + private static $rootMounted = false; |
|
| 68 | + private static $fsSetup = false; |
|
| 69 | + |
|
| 70 | + /** @var array Local cache of version.php */ |
|
| 71 | + private static $versionCache = null; |
|
| 72 | + |
|
| 73 | + protected static function getAppManager() { |
|
| 74 | + return \OC::$server->getAppManager(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + private static function initLocalStorageRootFS() { |
|
| 78 | + // mount local file backend as root |
|
| 79 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | + //first set up the local "root" storage |
|
| 81 | + \OC\Files\Filesystem::initMountManager(); |
|
| 82 | + if (!self::$rootMounted) { |
|
| 83 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | + self::$rootMounted = true; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * mounting an object storage as the root fs will in essence remove the |
|
| 90 | + * necessity of a data folder being present. |
|
| 91 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | + * |
|
| 93 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | + */ |
|
| 95 | + private static function initObjectStoreRootFS($config) { |
|
| 96 | + // check misconfiguration |
|
| 97 | + if (empty($config['class'])) { |
|
| 98 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | + } |
|
| 100 | + if (!isset($config['arguments'])) { |
|
| 101 | + $config['arguments'] = array(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // instantiate object store implementation |
|
| 105 | + $name = $config['class']; |
|
| 106 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | + $segments = explode('\\', $name); |
|
| 108 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | + } |
|
| 110 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | + // mount with plain / root object store implementation |
|
| 112 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | + |
|
| 114 | + // mount object storage as root |
|
| 115 | + \OC\Files\Filesystem::initMountManager(); |
|
| 116 | + if (!self::$rootMounted) { |
|
| 117 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | + self::$rootMounted = true; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * mounting an object storage as the root fs will in essence remove the |
|
| 124 | + * necessity of a data folder being present. |
|
| 125 | + * |
|
| 126 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 127 | + */ |
|
| 128 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
| 129 | + // check misconfiguration |
|
| 130 | + if (empty($config['class'])) { |
|
| 131 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 132 | + } |
|
| 133 | + if (!isset($config['arguments'])) { |
|
| 134 | + $config['arguments'] = array(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // instantiate object store implementation |
|
| 138 | + $name = $config['class']; |
|
| 139 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 140 | + $segments = explode('\\', $name); |
|
| 141 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if (!isset($config['arguments']['bucket'])) { |
|
| 145 | + $config['arguments']['bucket'] = ''; |
|
| 146 | + } |
|
| 147 | + // put the root FS always in first bucket for multibucket configuration |
|
| 148 | + $config['arguments']['bucket'] .= '0'; |
|
| 149 | + |
|
| 150 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 151 | + // mount with plain / root object store implementation |
|
| 152 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 153 | + |
|
| 154 | + // mount object storage as root |
|
| 155 | + \OC\Files\Filesystem::initMountManager(); |
|
| 156 | + if (!self::$rootMounted) { |
|
| 157 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 158 | + self::$rootMounted = true; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Can be set up |
|
| 164 | + * |
|
| 165 | + * @param string $user |
|
| 166 | + * @return boolean |
|
| 167 | + * @description configure the initial filesystem based on the configuration |
|
| 168 | + */ |
|
| 169 | + public static function setupFS($user = '') { |
|
| 170 | + //setting up the filesystem twice can only lead to trouble |
|
| 171 | + if (self::$fsSetup) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 176 | + |
|
| 177 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 178 | + if ($user === null) { |
|
| 179 | + $user = ''; |
|
| 180 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 181 | + $user = OC_User::getUser(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 185 | + OC_App::loadApps(array('filesystem')); |
|
| 186 | + |
|
| 187 | + // the filesystem will finish when $user is not empty, |
|
| 188 | + // mark fs setup here to avoid doing the setup from loading |
|
| 189 | + // OC_Filesystem |
|
| 190 | + if ($user != '') { |
|
| 191 | + self::$fsSetup = true; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + \OC\Files\Filesystem::initMountManager(); |
|
| 195 | + |
|
| 196 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 197 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 198 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 199 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 200 | + $storage->setMountOptions($mount->getOptions()); |
|
| 201 | + } |
|
| 202 | + return $storage; |
|
| 203 | + }); |
|
| 204 | + |
|
| 205 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 207 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 208 | + 'storage' => $storage, |
|
| 209 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 210 | + ]); |
|
| 211 | + } |
|
| 212 | + return $storage; |
|
| 213 | + }); |
|
| 214 | + |
|
| 215 | + // install storage availability wrapper, before most other wrappers |
|
| 216 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 217 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 218 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 219 | + } |
|
| 220 | + return $storage; |
|
| 221 | + }); |
|
| 222 | + |
|
| 223 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 224 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 225 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 226 | + } |
|
| 227 | + return $storage; |
|
| 228 | + }); |
|
| 229 | + |
|
| 230 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 231 | + // set up quota for home storages, even for other users |
|
| 232 | + // which can happen when using sharing |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @var \OC\Files\Storage\Storage $storage |
|
| 236 | + */ |
|
| 237 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 238 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 239 | + ) { |
|
| 240 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 241 | + if (is_object($storage->getUser())) { |
|
| 242 | + $user = $storage->getUser()->getUID(); |
|
| 243 | + $quota = OC_Util::getUserQuota($user); |
|
| 244 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 245 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $storage; |
|
| 251 | + }); |
|
| 252 | + |
|
| 253 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 254 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 255 | + |
|
| 256 | + //check if we are using an object storage |
|
| 257 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 258 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 259 | + |
|
| 260 | + // use the same order as in ObjectHomeMountProvider |
|
| 261 | + if (isset($objectStoreMultibucket)) { |
|
| 262 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 263 | + } elseif (isset($objectStore)) { |
|
| 264 | + self::initObjectStoreRootFS($objectStore); |
|
| 265 | + } else { |
|
| 266 | + self::initLocalStorageRootFS(); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + if ($user != '' && !OCP\User::userExists($user)) { |
|
| 270 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 275 | + if ($user != "") { |
|
| 276 | + |
|
| 277 | + $userDir = '/' . $user . '/files'; |
|
| 278 | + |
|
| 279 | + //jail the user into his "home" directory |
|
| 280 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 281 | + |
|
| 282 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 283 | + } |
|
| 284 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 285 | + return true; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * check if a password is required for each public link |
|
| 290 | + * |
|
| 291 | + * @return boolean |
|
| 292 | + */ |
|
| 293 | + public static function isPublicLinkPasswordRequired() { |
|
| 294 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 295 | + $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 296 | + return ($enforcePassword === 'yes') ? true : false; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * check if sharing is disabled for the current user |
|
| 301 | + * @param IConfig $config |
|
| 302 | + * @param IGroupManager $groupManager |
|
| 303 | + * @param IUser|null $user |
|
| 304 | + * @return bool |
|
| 305 | + */ |
|
| 306 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 307 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 308 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 309 | + $excludedGroups = json_decode($groupsList); |
|
| 310 | + if (is_null($excludedGroups)) { |
|
| 311 | + $excludedGroups = explode(',', $groupsList); |
|
| 312 | + $newValue = json_encode($excludedGroups); |
|
| 313 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 314 | + } |
|
| 315 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 316 | + if (!empty($usersGroups)) { |
|
| 317 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 318 | + // if the user is only in groups which are disabled for sharing then |
|
| 319 | + // sharing is also disabled for the user |
|
| 320 | + if (empty($remainingGroups)) { |
|
| 321 | + return true; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * check if share API enforces a default expire date |
|
| 330 | + * |
|
| 331 | + * @return boolean |
|
| 332 | + */ |
|
| 333 | + public static function isDefaultExpireDateEnforced() { |
|
| 334 | + $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 335 | + $enforceDefaultExpireDate = false; |
|
| 336 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 337 | + $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 338 | + $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + return $enforceDefaultExpireDate; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Get the quota of a user |
|
| 346 | + * |
|
| 347 | + * @param string $userId |
|
| 348 | + * @return int Quota bytes |
|
| 349 | + */ |
|
| 350 | + public static function getUserQuota($userId) { |
|
| 351 | + $user = \OC::$server->getUserManager()->get($userId); |
|
| 352 | + if (is_null($user)) { |
|
| 353 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 354 | + } |
|
| 355 | + $userQuota = $user->getQuota(); |
|
| 356 | + if($userQuota === 'none') { |
|
| 357 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 358 | + } |
|
| 359 | + return OC_Helper::computerFileSize($userQuota); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * copies the skeleton to the users /files |
|
| 364 | + * |
|
| 365 | + * @param String $userId |
|
| 366 | + * @param \OCP\Files\Folder $userDirectory |
|
| 367 | + * @throws \RuntimeException |
|
| 368 | + */ |
|
| 369 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 370 | + |
|
| 371 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 372 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 373 | + |
|
| 374 | + if ($instanceId === null) { |
|
| 375 | + throw new \RuntimeException('no instance id!'); |
|
| 376 | + } |
|
| 377 | + $appdata = 'appdata_' . $instanceId; |
|
| 378 | + if ($userId === $appdata) { |
|
| 379 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + if (!empty($skeletonDirectory)) { |
|
| 383 | + \OCP\Util::writeLog( |
|
| 384 | + 'files_skeleton', |
|
| 385 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 386 | + \OCP\Util::DEBUG |
|
| 387 | + ); |
|
| 388 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 389 | + // update the file cache |
|
| 390 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * copies a directory recursively by using streams |
|
| 396 | + * |
|
| 397 | + * @param string $source |
|
| 398 | + * @param \OCP\Files\Folder $target |
|
| 399 | + * @return void |
|
| 400 | + */ |
|
| 401 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 402 | + $logger = \OC::$server->getLogger(); |
|
| 403 | + |
|
| 404 | + // Verify if folder exists |
|
| 405 | + $dir = opendir($source); |
|
| 406 | + if($dir === false) { |
|
| 407 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // Copy the files |
|
| 412 | + while (false !== ($file = readdir($dir))) { |
|
| 413 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 414 | + if (is_dir($source . '/' . $file)) { |
|
| 415 | + $child = $target->newFolder($file); |
|
| 416 | + self::copyr($source . '/' . $file, $child); |
|
| 417 | + } else { |
|
| 418 | + $child = $target->newFile($file); |
|
| 419 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 420 | + if($sourceStream === false) { |
|
| 421 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 422 | + closedir($dir); |
|
| 423 | + return; |
|
| 424 | + } |
|
| 425 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + closedir($dir); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * @return void |
|
| 434 | + */ |
|
| 435 | + public static function tearDownFS() { |
|
| 436 | + \OC\Files\Filesystem::tearDown(); |
|
| 437 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 438 | + self::$fsSetup = false; |
|
| 439 | + self::$rootMounted = false; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * get the current installed version of ownCloud |
|
| 444 | + * |
|
| 445 | + * @return array |
|
| 446 | + */ |
|
| 447 | + public static function getVersion() { |
|
| 448 | + OC_Util::loadVersion(); |
|
| 449 | + return self::$versionCache['OC_Version']; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * get the current installed version string of ownCloud |
|
| 454 | + * |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public static function getVersionString() { |
|
| 458 | + OC_Util::loadVersion(); |
|
| 459 | + return self::$versionCache['OC_VersionString']; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @deprecated the value is of no use anymore |
|
| 464 | + * @return string |
|
| 465 | + */ |
|
| 466 | + public static function getEditionString() { |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @description get the update channel of the current installed of ownCloud. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public static function getChannel() { |
|
| 475 | + OC_Util::loadVersion(); |
|
| 476 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @description get the build number of the current installed of ownCloud. |
|
| 481 | + * @return string |
|
| 482 | + */ |
|
| 483 | + public static function getBuild() { |
|
| 484 | + OC_Util::loadVersion(); |
|
| 485 | + return self::$versionCache['OC_Build']; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * @description load the version.php into the session as cache |
|
| 490 | + */ |
|
| 491 | + private static function loadVersion() { |
|
| 492 | + if (self::$versionCache !== null) { |
|
| 493 | + return; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 497 | + require OC::$SERVERROOT . '/version.php'; |
|
| 498 | + /** @var $timestamp int */ |
|
| 499 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 500 | + /** @var $OC_Version string */ |
|
| 501 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 502 | + /** @var $OC_VersionString string */ |
|
| 503 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 504 | + /** @var $OC_Build string */ |
|
| 505 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 506 | + |
|
| 507 | + /** @var $OC_Channel string */ |
|
| 508 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 513 | + * |
|
| 514 | + * @param string $application application to get the files from |
|
| 515 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 516 | + * @param string $file the file inside of the above folder |
|
| 517 | + * @return string the path |
|
| 518 | + */ |
|
| 519 | + private static function generatePath($application, $directory, $file) { |
|
| 520 | + if (is_null($file)) { |
|
| 521 | + $file = $application; |
|
| 522 | + $application = ""; |
|
| 523 | + } |
|
| 524 | + if (!empty($application)) { |
|
| 525 | + return "$application/$directory/$file"; |
|
| 526 | + } else { |
|
| 527 | + return "$directory/$file"; |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * add a javascript file |
|
| 533 | + * |
|
| 534 | + * @param string $application application id |
|
| 535 | + * @param string|null $file filename |
|
| 536 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 537 | + * @return void |
|
| 538 | + */ |
|
| 539 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 540 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 541 | + |
|
| 542 | + // core js files need separate handling |
|
| 543 | + if ($application !== 'core' && $file !== null) { |
|
| 544 | + self::addTranslations ( $application ); |
|
| 545 | + } |
|
| 546 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * add a javascript file from the vendor sub folder |
|
| 551 | + * |
|
| 552 | + * @param string $application application id |
|
| 553 | + * @param string|null $file filename |
|
| 554 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 558 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * add a translation JS file |
|
| 564 | + * |
|
| 565 | + * @param string $application application id |
|
| 566 | + * @param string $languageCode language code, defaults to the current language |
|
| 567 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 568 | + */ |
|
| 569 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 570 | + if (is_null($languageCode)) { |
|
| 571 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 572 | + } |
|
| 573 | + if (!empty($application)) { |
|
| 574 | + $path = "$application/l10n/$languageCode"; |
|
| 575 | + } else { |
|
| 576 | + $path = "l10n/$languageCode"; |
|
| 577 | + } |
|
| 578 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * add a css file |
|
| 583 | + * |
|
| 584 | + * @param string $application application id |
|
| 585 | + * @param string|null $file filename |
|
| 586 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 587 | + * @return void |
|
| 588 | + */ |
|
| 589 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 590 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 591 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * add a css file from the vendor sub folder |
|
| 596 | + * |
|
| 597 | + * @param string $application application id |
|
| 598 | + * @param string|null $file filename |
|
| 599 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 600 | + * @return void |
|
| 601 | + */ |
|
| 602 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 603 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 604 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * add an external resource css/js file |
|
| 609 | + * |
|
| 610 | + * @param string $application application id |
|
| 611 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 612 | + * @param string $path |
|
| 613 | + * @param string $type (script or style) |
|
| 614 | + * @return void |
|
| 615 | + */ |
|
| 616 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 617 | + |
|
| 618 | + if ($type === "style") { |
|
| 619 | + if (!in_array($path, self::$styles)) { |
|
| 620 | + if ($prepend === true) { |
|
| 621 | + array_unshift ( self::$styles, $path ); |
|
| 622 | + } else { |
|
| 623 | + self::$styles[] = $path; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } elseif ($type === "script") { |
|
| 627 | + if (!in_array($path, self::$scripts)) { |
|
| 628 | + if ($prepend === true) { |
|
| 629 | + array_unshift ( self::$scripts, $path ); |
|
| 630 | + } else { |
|
| 631 | + self::$scripts [] = $path; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Add a custom element to the header |
|
| 639 | + * If $text is null then the element will be written as empty element. |
|
| 640 | + * So use "" to get a closing tag. |
|
| 641 | + * @param string $tag tag name of the element |
|
| 642 | + * @param array $attributes array of attributes for the element |
|
| 643 | + * @param string $text the text content for the element |
|
| 644 | + */ |
|
| 645 | + public static function addHeader($tag, $attributes, $text=null) { |
|
| 646 | + self::$headers[] = array( |
|
| 647 | + 'tag' => $tag, |
|
| 648 | + 'attributes' => $attributes, |
|
| 649 | + 'text' => $text |
|
| 650 | + ); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * formats a timestamp in the "right" way |
|
| 655 | + * |
|
| 656 | + * @param int $timestamp |
|
| 657 | + * @param bool $dateOnly option to omit time from the result |
|
| 658 | + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 659 | + * @return string timestamp |
|
| 660 | + * |
|
| 661 | + * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 662 | + */ |
|
| 663 | + public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 664 | + if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 665 | + $timeZone = new \DateTimeZone($timeZone); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
| 669 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 670 | + if ($dateOnly) { |
|
| 671 | + return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 672 | + } |
|
| 673 | + return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * check if the current server configuration is suitable for ownCloud |
|
| 678 | + * |
|
| 679 | + * @param \OC\SystemConfig $config |
|
| 680 | + * @return array arrays with error messages and hints |
|
| 681 | + */ |
|
| 682 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 683 | + $l = \OC::$server->getL10N('lib'); |
|
| 684 | + $errors = array(); |
|
| 685 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 686 | + |
|
| 687 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 688 | + // this check needs to be done every time |
|
| 689 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 693 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 694 | + return $errors; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $webServerRestart = false; |
|
| 698 | + $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 699 | + \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 700 | + |
|
| 701 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 702 | + |
|
| 703 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 704 | + if (empty($availableDatabases)) { |
|
| 705 | + $errors[] = array( |
|
| 706 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 707 | + 'hint' => '' //TODO: sane hint |
|
| 708 | + ); |
|
| 709 | + $webServerRestart = true; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // Check if config folder is writable. |
|
| 713 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 714 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 715 | + $errors[] = array( |
|
| 716 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 717 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 718 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 719 | + ); |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + // Check if there is a writable install folder. |
|
| 724 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 725 | + if (OC_App::getInstallPath() === null |
|
| 726 | + || !is_writable(OC_App::getInstallPath()) |
|
| 727 | + || !is_readable(OC_App::getInstallPath()) |
|
| 728 | + ) { |
|
| 729 | + $errors[] = array( |
|
| 730 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 731 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 732 | + . ' or disabling the appstore in the config file. See %s', |
|
| 733 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 734 | + ); |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + // Create root dir. |
|
| 738 | + if ($config->getValue('installed', false)) { |
|
| 739 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 740 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 741 | + if ($success) { |
|
| 742 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 743 | + } else { |
|
| 744 | + $errors[] = [ |
|
| 745 | + 'error' => $l->t('Cannot create "data" directory'), |
|
| 746 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 747 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 748 | + ]; |
|
| 749 | + } |
|
| 750 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 751 | + //common hint for all file permissions error messages |
|
| 752 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 753 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 754 | + $errors[] = [ |
|
| 755 | + 'error' => 'Your data directory is not writable', |
|
| 756 | + 'hint' => $permissionsHint |
|
| 757 | + ]; |
|
| 758 | + } else { |
|
| 759 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 764 | + $errors[] = array( |
|
| 765 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 766 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 767 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 768 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 769 | + ); |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // Contains the dependencies that should be checked against |
|
| 773 | + // classes = class_exists |
|
| 774 | + // functions = function_exists |
|
| 775 | + // defined = defined |
|
| 776 | + // ini = ini_get |
|
| 777 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 778 | + // When adding new checks always verify that they pass on Travis as well |
|
| 779 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 780 | + $dependencies = array( |
|
| 781 | + 'classes' => array( |
|
| 782 | + 'ZipArchive' => 'zip', |
|
| 783 | + 'DOMDocument' => 'dom', |
|
| 784 | + 'XMLWriter' => 'XMLWriter', |
|
| 785 | + 'XMLReader' => 'XMLReader', |
|
| 786 | + ), |
|
| 787 | + 'functions' => [ |
|
| 788 | + 'xml_parser_create' => 'libxml', |
|
| 789 | + 'mb_strcut' => 'mb multibyte', |
|
| 790 | + 'ctype_digit' => 'ctype', |
|
| 791 | + 'json_encode' => 'JSON', |
|
| 792 | + 'gd_info' => 'GD', |
|
| 793 | + 'gzencode' => 'zlib', |
|
| 794 | + 'iconv' => 'iconv', |
|
| 795 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 796 | + 'hash' => 'HASH Message Digest Framework', |
|
| 797 | + 'curl_init' => 'cURL', |
|
| 798 | + 'openssl_verify' => 'OpenSSL', |
|
| 799 | + ], |
|
| 800 | + 'defined' => array( |
|
| 801 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 802 | + ), |
|
| 803 | + 'ini' => [ |
|
| 804 | + 'default_charset' => 'UTF-8', |
|
| 805 | + ], |
|
| 806 | + ); |
|
| 807 | + $missingDependencies = array(); |
|
| 808 | + $invalidIniSettings = []; |
|
| 809 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 813 | + * and prevents installation. Once HHVM is more compatible with our |
|
| 814 | + * approach to check for these values we should re-enable those |
|
| 815 | + * checks. |
|
| 816 | + */ |
|
| 817 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 818 | + if (!self::runningOnHhvm()) { |
|
| 819 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 820 | + if (!class_exists($class)) { |
|
| 821 | + $missingDependencies[] = $module; |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 825 | + if (!function_exists($function)) { |
|
| 826 | + $missingDependencies[] = $module; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 830 | + if (!defined($defined)) { |
|
| 831 | + $missingDependencies[] = $module; |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 835 | + if (is_bool($expected)) { |
|
| 836 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 837 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + if (is_int($expected)) { |
|
| 841 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 842 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + if (is_string($expected)) { |
|
| 846 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 847 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + foreach($missingDependencies as $missingDependency) { |
|
| 854 | + $errors[] = array( |
|
| 855 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 856 | + 'hint' => $moduleHint |
|
| 857 | + ); |
|
| 858 | + $webServerRestart = true; |
|
| 859 | + } |
|
| 860 | + foreach($invalidIniSettings as $setting) { |
|
| 861 | + if(is_bool($setting[1])) { |
|
| 862 | + $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 863 | + } |
|
| 864 | + $errors[] = [ |
|
| 865 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 866 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 867 | + ]; |
|
| 868 | + $webServerRestart = true; |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 873 | + * module is installed as it will return null if the checking setting is |
|
| 874 | + * not available and thus a check on the boolean value fails. |
|
| 875 | + * |
|
| 876 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 877 | + * check somehow in the long-term. |
|
| 878 | + */ |
|
| 879 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 880 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 881 | + $errors[] = array( |
|
| 882 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 883 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 884 | + ); |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + if(function_exists('xml_parser_create') && |
|
| 888 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
| 889 | + $version = LIBXML_LOADED_VERSION; |
|
| 890 | + $major = floor($version/10000); |
|
| 891 | + $version -= ($major * 10000); |
|
| 892 | + $minor = floor($version/100); |
|
| 893 | + $version -= ($minor * 100); |
|
| 894 | + $patch = $version; |
|
| 895 | + $errors[] = array( |
|
| 896 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 897 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 898 | + ); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + if (!self::isAnnotationsWorking()) { |
|
| 902 | + $errors[] = array( |
|
| 903 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 904 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 905 | + ); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 909 | + $errors[] = array( |
|
| 910 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 911 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 916 | + |
|
| 917 | + // Cache the result of this function |
|
| 918 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 919 | + |
|
| 920 | + return $errors; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Check the database version |
|
| 925 | + * |
|
| 926 | + * @return array errors array |
|
| 927 | + */ |
|
| 928 | + public static function checkDatabaseVersion() { |
|
| 929 | + $l = \OC::$server->getL10N('lib'); |
|
| 930 | + $errors = array(); |
|
| 931 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 932 | + if ($dbType === 'pgsql') { |
|
| 933 | + // check PostgreSQL version |
|
| 934 | + try { |
|
| 935 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 936 | + $data = $result->fetchRow(); |
|
| 937 | + if (isset($data['server_version'])) { |
|
| 938 | + $version = $data['server_version']; |
|
| 939 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 940 | + $errors[] = array( |
|
| 941 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 942 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 943 | + ); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 947 | + $logger = \OC::$server->getLogger(); |
|
| 948 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 949 | + $logger->logException($e); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + return $errors; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * Check for correct file permissions of data directory |
|
| 957 | + * |
|
| 958 | + * @param string $dataDirectory |
|
| 959 | + * @return array arrays with error messages and hints |
|
| 960 | + */ |
|
| 961 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 962 | + $l = \OC::$server->getL10N('lib'); |
|
| 963 | + $errors = array(); |
|
| 964 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 965 | + . ' cannot be listed by other users.'); |
|
| 966 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 967 | + if (substr($perms, -1) !== '0') { |
|
| 968 | + chmod($dataDirectory, 0770); |
|
| 969 | + clearstatcache(); |
|
| 970 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 971 | + if ($perms[2] !== '0') { |
|
| 972 | + $errors[] = [ |
|
| 973 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
| 974 | + 'hint' => $permissionsModHint |
|
| 975 | + ]; |
|
| 976 | + } |
|
| 977 | + } |
|
| 978 | + return $errors; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * Check that the data directory exists and is valid by |
|
| 983 | + * checking the existence of the ".ocdata" file. |
|
| 984 | + * |
|
| 985 | + * @param string $dataDirectory data directory path |
|
| 986 | + * @return array errors found |
|
| 987 | + */ |
|
| 988 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 989 | + $l = \OC::$server->getL10N('lib'); |
|
| 990 | + $errors = []; |
|
| 991 | + if ($dataDirectory[0] !== '/') { |
|
| 992 | + $errors[] = [ |
|
| 993 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 994 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 995 | + ]; |
|
| 996 | + } |
|
| 997 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 998 | + $errors[] = [ |
|
| 999 | + 'error' => $l->t('Your data directory is invalid'), |
|
| 1000 | + 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 1001 | + ' ".ocdata" in its root.') |
|
| 1002 | + ]; |
|
| 1003 | + } |
|
| 1004 | + return $errors; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Check if the user is logged in, redirects to home if not. With |
|
| 1009 | + * redirect URL parameter to the request URI. |
|
| 1010 | + * |
|
| 1011 | + * @return void |
|
| 1012 | + */ |
|
| 1013 | + public static function checkLoggedIn() { |
|
| 1014 | + // Check if we are a user |
|
| 1015 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1016 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1017 | + 'core.login.showLoginForm', |
|
| 1018 | + [ |
|
| 1019 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1020 | + ] |
|
| 1021 | + ) |
|
| 1022 | + ); |
|
| 1023 | + exit(); |
|
| 1024 | + } |
|
| 1025 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1026 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1027 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1028 | + exit(); |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Check if the user is a admin, redirects to home if not |
|
| 1034 | + * |
|
| 1035 | + * @return void |
|
| 1036 | + */ |
|
| 1037 | + public static function checkAdminUser() { |
|
| 1038 | + OC_Util::checkLoggedIn(); |
|
| 1039 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1040 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1041 | + exit(); |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Check if the user is a subadmin, redirects to home if not |
|
| 1047 | + * |
|
| 1048 | + * @return null|boolean $groups where the current user is subadmin |
|
| 1049 | + */ |
|
| 1050 | + public static function checkSubAdminUser() { |
|
| 1051 | + OC_Util::checkLoggedIn(); |
|
| 1052 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1053 | + $isSubAdmin = false; |
|
| 1054 | + if($userObject !== null) { |
|
| 1055 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + if (!$isSubAdmin) { |
|
| 1059 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1060 | + exit(); |
|
| 1061 | + } |
|
| 1062 | + return true; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Returns the URL of the default page |
|
| 1067 | + * based on the system configuration and |
|
| 1068 | + * the apps visible for the current user |
|
| 1069 | + * |
|
| 1070 | + * @return string URL |
|
| 1071 | + */ |
|
| 1072 | + public static function getDefaultPageUrl() { |
|
| 1073 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1074 | + // Deny the redirect if the URL contains a @ |
|
| 1075 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1076 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1077 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1078 | + } else { |
|
| 1079 | + $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1080 | + if ($defaultPage) { |
|
| 1081 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1082 | + } else { |
|
| 1083 | + $appId = 'files'; |
|
| 1084 | + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1085 | + // find the first app that is enabled for the current user |
|
| 1086 | + foreach ($defaultApps as $defaultApp) { |
|
| 1087 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1088 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1089 | + $appId = $defaultApp; |
|
| 1090 | + break; |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1095 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1096 | + } else { |
|
| 1097 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + return $location; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Redirect to the user default page |
|
| 1106 | + * |
|
| 1107 | + * @return void |
|
| 1108 | + */ |
|
| 1109 | + public static function redirectToDefaultPage() { |
|
| 1110 | + $location = self::getDefaultPageUrl(); |
|
| 1111 | + header('Location: ' . $location); |
|
| 1112 | + exit(); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * get an id unique for this instance |
|
| 1117 | + * |
|
| 1118 | + * @return string |
|
| 1119 | + */ |
|
| 1120 | + public static function getInstanceId() { |
|
| 1121 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1122 | + if (is_null($id)) { |
|
| 1123 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1124 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1125 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1126 | + } |
|
| 1127 | + return $id; |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * Public function to sanitize HTML |
|
| 1132 | + * |
|
| 1133 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1134 | + * string or array of strings before displaying it on a web page. |
|
| 1135 | + * |
|
| 1136 | + * @param string|array $value |
|
| 1137 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1138 | + */ |
|
| 1139 | + public static function sanitizeHTML($value) { |
|
| 1140 | + if (is_array($value)) { |
|
| 1141 | + $value = array_map(function($value) { |
|
| 1142 | + return self::sanitizeHTML($value); |
|
| 1143 | + }, $value); |
|
| 1144 | + } else { |
|
| 1145 | + // Specify encoding for PHP<5.4 |
|
| 1146 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1147 | + } |
|
| 1148 | + return $value; |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Public function to encode url parameters |
|
| 1153 | + * |
|
| 1154 | + * This function is used to encode path to file before output. |
|
| 1155 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1156 | + * Character '/' is preserved as is. |
|
| 1157 | + * |
|
| 1158 | + * @param string $component part of URI to encode |
|
| 1159 | + * @return string |
|
| 1160 | + */ |
|
| 1161 | + public static function encodePath($component) { |
|
| 1162 | + $encoded = rawurlencode($component); |
|
| 1163 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1164 | + return $encoded; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1169 | + // php dev server does not support htaccess |
|
| 1170 | + if (php_sapi_name() === 'cli-server') { |
|
| 1171 | + return false; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + // testdata |
|
| 1175 | + $fileName = '/htaccesstest.txt'; |
|
| 1176 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1177 | + |
|
| 1178 | + // creating a test file |
|
| 1179 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1180 | + |
|
| 1181 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1182 | + return false; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + $fp = @fopen($testFile, 'w'); |
|
| 1186 | + if (!$fp) { |
|
| 1187 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1188 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1189 | + } |
|
| 1190 | + fwrite($fp, $testContent); |
|
| 1191 | + fclose($fp); |
|
| 1192 | + |
|
| 1193 | + return $testContent; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * Check if the .htaccess file is working |
|
| 1198 | + * @param \OCP\IConfig $config |
|
| 1199 | + * @return bool |
|
| 1200 | + * @throws Exception |
|
| 1201 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1202 | + */ |
|
| 1203 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1204 | + |
|
| 1205 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1206 | + return true; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1210 | + if ($testContent === false) { |
|
| 1211 | + return false; |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + $fileName = '/htaccesstest.txt'; |
|
| 1215 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1216 | + |
|
| 1217 | + // accessing the file via http |
|
| 1218 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1219 | + try { |
|
| 1220 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1221 | + } catch (\Exception $e) { |
|
| 1222 | + $content = false; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + // cleanup |
|
| 1226 | + @unlink($testFile); |
|
| 1227 | + |
|
| 1228 | + /* |
|
| 1229 | 1229 | * If the content is not equal to test content our .htaccess |
| 1230 | 1230 | * is working as required |
| 1231 | 1231 | */ |
| 1232 | - return $content !== $testContent; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1237 | - * local packages are not available on the server. |
|
| 1238 | - * |
|
| 1239 | - * @return bool |
|
| 1240 | - */ |
|
| 1241 | - public static function isSetLocaleWorking() { |
|
| 1242 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1243 | - if ('' === basename('§')) { |
|
| 1244 | - return false; |
|
| 1245 | - } |
|
| 1246 | - return true; |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * Check if it's possible to get the inline annotations |
|
| 1251 | - * |
|
| 1252 | - * @return bool |
|
| 1253 | - */ |
|
| 1254 | - public static function isAnnotationsWorking() { |
|
| 1255 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1256 | - $docs = $reflection->getDocComment(); |
|
| 1257 | - |
|
| 1258 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - /** |
|
| 1262 | - * Check if the PHP module fileinfo is loaded. |
|
| 1263 | - * |
|
| 1264 | - * @return bool |
|
| 1265 | - */ |
|
| 1266 | - public static function fileInfoLoaded() { |
|
| 1267 | - return function_exists('finfo_open'); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * clear all levels of output buffering |
|
| 1272 | - * |
|
| 1273 | - * @return void |
|
| 1274 | - */ |
|
| 1275 | - public static function obEnd() { |
|
| 1276 | - while (ob_get_level()) { |
|
| 1277 | - ob_end_clean(); |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * Checks whether the server is running on Mac OS X |
|
| 1283 | - * |
|
| 1284 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1285 | - */ |
|
| 1286 | - public static function runningOnMac() { |
|
| 1287 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Checks whether server is running on HHVM |
|
| 1292 | - * |
|
| 1293 | - * @return bool True if running on HHVM, false otherwise |
|
| 1294 | - */ |
|
| 1295 | - public static function runningOnHhvm() { |
|
| 1296 | - return defined('HHVM_VERSION'); |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - /** |
|
| 1300 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1301 | - * theme exists and take that one |
|
| 1302 | - * |
|
| 1303 | - * @return string the theme |
|
| 1304 | - */ |
|
| 1305 | - public static function getTheme() { |
|
| 1306 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1307 | - |
|
| 1308 | - if ($theme === '') { |
|
| 1309 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1310 | - $theme = 'default'; |
|
| 1311 | - } |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - return $theme; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * Clear a single file from the opcode cache |
|
| 1319 | - * This is useful for writing to the config file |
|
| 1320 | - * in case the opcode cache does not re-validate files |
|
| 1321 | - * Returns true if successful, false if unsuccessful: |
|
| 1322 | - * caller should fall back on clearing the entire cache |
|
| 1323 | - * with clearOpcodeCache() if unsuccessful |
|
| 1324 | - * |
|
| 1325 | - * @param string $path the path of the file to clear from the cache |
|
| 1326 | - * @return bool true if underlying function returns true, otherwise false |
|
| 1327 | - */ |
|
| 1328 | - public static function deleteFromOpcodeCache($path) { |
|
| 1329 | - $ret = false; |
|
| 1330 | - if ($path) { |
|
| 1331 | - // APC >= 3.1.1 |
|
| 1332 | - if (function_exists('apc_delete_file')) { |
|
| 1333 | - $ret = @apc_delete_file($path); |
|
| 1334 | - } |
|
| 1335 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1336 | - if (function_exists('opcache_invalidate')) { |
|
| 1337 | - $ret = opcache_invalidate($path); |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - return $ret; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - /** |
|
| 1344 | - * Clear the opcode cache if one exists |
|
| 1345 | - * This is necessary for writing to the config file |
|
| 1346 | - * in case the opcode cache does not re-validate files |
|
| 1347 | - * |
|
| 1348 | - * @return void |
|
| 1349 | - */ |
|
| 1350 | - public static function clearOpcodeCache() { |
|
| 1351 | - // APC |
|
| 1352 | - if (function_exists('apc_clear_cache')) { |
|
| 1353 | - apc_clear_cache(); |
|
| 1354 | - } |
|
| 1355 | - // Zend Opcache |
|
| 1356 | - if (function_exists('accelerator_reset')) { |
|
| 1357 | - accelerator_reset(); |
|
| 1358 | - } |
|
| 1359 | - // XCache |
|
| 1360 | - if (function_exists('xcache_clear_cache')) { |
|
| 1361 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1362 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1363 | - } else { |
|
| 1364 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - // Opcache (PHP >= 5.5) |
|
| 1368 | - if (function_exists('opcache_reset')) { |
|
| 1369 | - opcache_reset(); |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * Normalize a unicode string |
|
| 1375 | - * |
|
| 1376 | - * @param string $value a not normalized string |
|
| 1377 | - * @return bool|string |
|
| 1378 | - */ |
|
| 1379 | - public static function normalizeUnicode($value) { |
|
| 1380 | - if(Normalizer::isNormalized($value)) { |
|
| 1381 | - return $value; |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1385 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1386 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1387 | - return $value; |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - return $normalizedValue; |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - /** |
|
| 1394 | - * @param boolean|string $file |
|
| 1395 | - * @return string |
|
| 1396 | - */ |
|
| 1397 | - public static function basename($file) { |
|
| 1398 | - $file = rtrim($file, '/'); |
|
| 1399 | - $t = explode('/', $file); |
|
| 1400 | - return array_pop($t); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - /** |
|
| 1404 | - * A human readable string is generated based on version and build number |
|
| 1405 | - * |
|
| 1406 | - * @return string |
|
| 1407 | - */ |
|
| 1408 | - public static function getHumanVersion() { |
|
| 1409 | - $version = OC_Util::getVersionString(); |
|
| 1410 | - $build = OC_Util::getBuild(); |
|
| 1411 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1412 | - $version .= ' Build:' . $build; |
|
| 1413 | - } |
|
| 1414 | - return $version; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * Returns whether the given file name is valid |
|
| 1419 | - * |
|
| 1420 | - * @param string $file file name to check |
|
| 1421 | - * @return bool true if the file name is valid, false otherwise |
|
| 1422 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1423 | - */ |
|
| 1424 | - public static function isValidFileName($file) { |
|
| 1425 | - $trimmed = trim($file); |
|
| 1426 | - if ($trimmed === '') { |
|
| 1427 | - return false; |
|
| 1428 | - } |
|
| 1429 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1430 | - return false; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // detect part files |
|
| 1434 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1435 | - return false; |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - foreach (str_split($trimmed) as $char) { |
|
| 1439 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1440 | - return false; |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - return true; |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * Check whether the instance needs to perform an upgrade, |
|
| 1448 | - * either when the core version is higher or any app requires |
|
| 1449 | - * an upgrade. |
|
| 1450 | - * |
|
| 1451 | - * @param \OC\SystemConfig $config |
|
| 1452 | - * @return bool whether the core or any app needs an upgrade |
|
| 1453 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1454 | - */ |
|
| 1455 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1456 | - if ($config->getValue('installed', false)) { |
|
| 1457 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1458 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1459 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1460 | - if ($versionDiff > 0) { |
|
| 1461 | - return true; |
|
| 1462 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1463 | - // downgrade with debug |
|
| 1464 | - $installedMajor = explode('.', $installedVersion); |
|
| 1465 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1466 | - $currentMajor = explode('.', $currentVersion); |
|
| 1467 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1468 | - if ($installedMajor === $currentMajor) { |
|
| 1469 | - // Same major, allow downgrade for developers |
|
| 1470 | - return true; |
|
| 1471 | - } else { |
|
| 1472 | - // downgrade attempt, throw exception |
|
| 1473 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1474 | - } |
|
| 1475 | - } else if ($versionDiff < 0) { |
|
| 1476 | - // downgrade attempt, throw exception |
|
| 1477 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1478 | - } |
|
| 1479 | - |
|
| 1480 | - // also check for upgrades for apps (independently from the user) |
|
| 1481 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1482 | - $shouldUpgrade = false; |
|
| 1483 | - foreach ($apps as $app) { |
|
| 1484 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1485 | - $shouldUpgrade = true; |
|
| 1486 | - break; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - return $shouldUpgrade; |
|
| 1490 | - } else { |
|
| 1491 | - return false; |
|
| 1492 | - } |
|
| 1493 | - } |
|
| 1232 | + return $content !== $testContent; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1237 | + * local packages are not available on the server. |
|
| 1238 | + * |
|
| 1239 | + * @return bool |
|
| 1240 | + */ |
|
| 1241 | + public static function isSetLocaleWorking() { |
|
| 1242 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1243 | + if ('' === basename('§')) { |
|
| 1244 | + return false; |
|
| 1245 | + } |
|
| 1246 | + return true; |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * Check if it's possible to get the inline annotations |
|
| 1251 | + * |
|
| 1252 | + * @return bool |
|
| 1253 | + */ |
|
| 1254 | + public static function isAnnotationsWorking() { |
|
| 1255 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1256 | + $docs = $reflection->getDocComment(); |
|
| 1257 | + |
|
| 1258 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + /** |
|
| 1262 | + * Check if the PHP module fileinfo is loaded. |
|
| 1263 | + * |
|
| 1264 | + * @return bool |
|
| 1265 | + */ |
|
| 1266 | + public static function fileInfoLoaded() { |
|
| 1267 | + return function_exists('finfo_open'); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * clear all levels of output buffering |
|
| 1272 | + * |
|
| 1273 | + * @return void |
|
| 1274 | + */ |
|
| 1275 | + public static function obEnd() { |
|
| 1276 | + while (ob_get_level()) { |
|
| 1277 | + ob_end_clean(); |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * Checks whether the server is running on Mac OS X |
|
| 1283 | + * |
|
| 1284 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1285 | + */ |
|
| 1286 | + public static function runningOnMac() { |
|
| 1287 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Checks whether server is running on HHVM |
|
| 1292 | + * |
|
| 1293 | + * @return bool True if running on HHVM, false otherwise |
|
| 1294 | + */ |
|
| 1295 | + public static function runningOnHhvm() { |
|
| 1296 | + return defined('HHVM_VERSION'); |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + /** |
|
| 1300 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1301 | + * theme exists and take that one |
|
| 1302 | + * |
|
| 1303 | + * @return string the theme |
|
| 1304 | + */ |
|
| 1305 | + public static function getTheme() { |
|
| 1306 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1307 | + |
|
| 1308 | + if ($theme === '') { |
|
| 1309 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1310 | + $theme = 'default'; |
|
| 1311 | + } |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + return $theme; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * Clear a single file from the opcode cache |
|
| 1319 | + * This is useful for writing to the config file |
|
| 1320 | + * in case the opcode cache does not re-validate files |
|
| 1321 | + * Returns true if successful, false if unsuccessful: |
|
| 1322 | + * caller should fall back on clearing the entire cache |
|
| 1323 | + * with clearOpcodeCache() if unsuccessful |
|
| 1324 | + * |
|
| 1325 | + * @param string $path the path of the file to clear from the cache |
|
| 1326 | + * @return bool true if underlying function returns true, otherwise false |
|
| 1327 | + */ |
|
| 1328 | + public static function deleteFromOpcodeCache($path) { |
|
| 1329 | + $ret = false; |
|
| 1330 | + if ($path) { |
|
| 1331 | + // APC >= 3.1.1 |
|
| 1332 | + if (function_exists('apc_delete_file')) { |
|
| 1333 | + $ret = @apc_delete_file($path); |
|
| 1334 | + } |
|
| 1335 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1336 | + if (function_exists('opcache_invalidate')) { |
|
| 1337 | + $ret = opcache_invalidate($path); |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + return $ret; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + /** |
|
| 1344 | + * Clear the opcode cache if one exists |
|
| 1345 | + * This is necessary for writing to the config file |
|
| 1346 | + * in case the opcode cache does not re-validate files |
|
| 1347 | + * |
|
| 1348 | + * @return void |
|
| 1349 | + */ |
|
| 1350 | + public static function clearOpcodeCache() { |
|
| 1351 | + // APC |
|
| 1352 | + if (function_exists('apc_clear_cache')) { |
|
| 1353 | + apc_clear_cache(); |
|
| 1354 | + } |
|
| 1355 | + // Zend Opcache |
|
| 1356 | + if (function_exists('accelerator_reset')) { |
|
| 1357 | + accelerator_reset(); |
|
| 1358 | + } |
|
| 1359 | + // XCache |
|
| 1360 | + if (function_exists('xcache_clear_cache')) { |
|
| 1361 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1362 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1363 | + } else { |
|
| 1364 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + // Opcache (PHP >= 5.5) |
|
| 1368 | + if (function_exists('opcache_reset')) { |
|
| 1369 | + opcache_reset(); |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * Normalize a unicode string |
|
| 1375 | + * |
|
| 1376 | + * @param string $value a not normalized string |
|
| 1377 | + * @return bool|string |
|
| 1378 | + */ |
|
| 1379 | + public static function normalizeUnicode($value) { |
|
| 1380 | + if(Normalizer::isNormalized($value)) { |
|
| 1381 | + return $value; |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1385 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1386 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1387 | + return $value; |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + return $normalizedValue; |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + /** |
|
| 1394 | + * @param boolean|string $file |
|
| 1395 | + * @return string |
|
| 1396 | + */ |
|
| 1397 | + public static function basename($file) { |
|
| 1398 | + $file = rtrim($file, '/'); |
|
| 1399 | + $t = explode('/', $file); |
|
| 1400 | + return array_pop($t); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + /** |
|
| 1404 | + * A human readable string is generated based on version and build number |
|
| 1405 | + * |
|
| 1406 | + * @return string |
|
| 1407 | + */ |
|
| 1408 | + public static function getHumanVersion() { |
|
| 1409 | + $version = OC_Util::getVersionString(); |
|
| 1410 | + $build = OC_Util::getBuild(); |
|
| 1411 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1412 | + $version .= ' Build:' . $build; |
|
| 1413 | + } |
|
| 1414 | + return $version; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * Returns whether the given file name is valid |
|
| 1419 | + * |
|
| 1420 | + * @param string $file file name to check |
|
| 1421 | + * @return bool true if the file name is valid, false otherwise |
|
| 1422 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1423 | + */ |
|
| 1424 | + public static function isValidFileName($file) { |
|
| 1425 | + $trimmed = trim($file); |
|
| 1426 | + if ($trimmed === '') { |
|
| 1427 | + return false; |
|
| 1428 | + } |
|
| 1429 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1430 | + return false; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // detect part files |
|
| 1434 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1435 | + return false; |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + foreach (str_split($trimmed) as $char) { |
|
| 1439 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + return true; |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * Check whether the instance needs to perform an upgrade, |
|
| 1448 | + * either when the core version is higher or any app requires |
|
| 1449 | + * an upgrade. |
|
| 1450 | + * |
|
| 1451 | + * @param \OC\SystemConfig $config |
|
| 1452 | + * @return bool whether the core or any app needs an upgrade |
|
| 1453 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1454 | + */ |
|
| 1455 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1456 | + if ($config->getValue('installed', false)) { |
|
| 1457 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1458 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1459 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1460 | + if ($versionDiff > 0) { |
|
| 1461 | + return true; |
|
| 1462 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1463 | + // downgrade with debug |
|
| 1464 | + $installedMajor = explode('.', $installedVersion); |
|
| 1465 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1466 | + $currentMajor = explode('.', $currentVersion); |
|
| 1467 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1468 | + if ($installedMajor === $currentMajor) { |
|
| 1469 | + // Same major, allow downgrade for developers |
|
| 1470 | + return true; |
|
| 1471 | + } else { |
|
| 1472 | + // downgrade attempt, throw exception |
|
| 1473 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1474 | + } |
|
| 1475 | + } else if ($versionDiff < 0) { |
|
| 1476 | + // downgrade attempt, throw exception |
|
| 1477 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1478 | + } |
|
| 1479 | + |
|
| 1480 | + // also check for upgrades for apps (independently from the user) |
|
| 1481 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1482 | + $shouldUpgrade = false; |
|
| 1483 | + foreach ($apps as $app) { |
|
| 1484 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1485 | + $shouldUpgrade = true; |
|
| 1486 | + break; |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + return $shouldUpgrade; |
|
| 1490 | + } else { |
|
| 1491 | + return false; |
|
| 1492 | + } |
|
| 1493 | + } |
|
| 1494 | 1494 | |
| 1495 | 1495 | } |
@@ -126,1654 +126,1654 @@ |
||
| 126 | 126 | * TODO: hookup all manager classes |
| 127 | 127 | */ |
| 128 | 128 | class Server extends ServerContainer implements IServerContainer { |
| 129 | - /** @var string */ |
|
| 130 | - private $webRoot; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param string $webRoot |
|
| 134 | - * @param \OC\Config $config |
|
| 135 | - */ |
|
| 136 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 137 | - parent::__construct(); |
|
| 138 | - $this->webRoot = $webRoot; |
|
| 139 | - |
|
| 140 | - $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
| 141 | - return $c; |
|
| 142 | - }); |
|
| 143 | - |
|
| 144 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 145 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 146 | - |
|
| 147 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 148 | - |
|
| 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', 'logout', function () { |
|
| 365 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 366 | - }); |
|
| 367 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 368 | - /** @var $user \OC\User\User */ |
|
| 369 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 370 | - }); |
|
| 371 | - return $userSession; |
|
| 372 | - }); |
|
| 373 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 374 | - |
|
| 375 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 376 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
| 377 | - }); |
|
| 378 | - |
|
| 379 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 380 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 381 | - |
|
| 382 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 383 | - return new \OC\AllConfig( |
|
| 384 | - $c->getSystemConfig() |
|
| 385 | - ); |
|
| 386 | - }); |
|
| 387 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 388 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 389 | - |
|
| 390 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 391 | - return new \OC\SystemConfig($config); |
|
| 392 | - }); |
|
| 393 | - |
|
| 394 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 395 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 396 | - }); |
|
| 397 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 398 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 399 | - |
|
| 400 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 401 | - return new \OC\L10N\Factory( |
|
| 402 | - $c->getConfig(), |
|
| 403 | - $c->getRequest(), |
|
| 404 | - $c->getUserSession(), |
|
| 405 | - \OC::$SERVERROOT |
|
| 406 | - ); |
|
| 407 | - }); |
|
| 408 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 409 | - |
|
| 410 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 411 | - $config = $c->getConfig(); |
|
| 412 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 413 | - return new \OC\URLGenerator( |
|
| 414 | - $config, |
|
| 415 | - $cacheFactory |
|
| 416 | - ); |
|
| 417 | - }); |
|
| 418 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 419 | - |
|
| 420 | - $this->registerService('AppHelper', function ($c) { |
|
| 421 | - return new \OC\AppHelper(); |
|
| 422 | - }); |
|
| 423 | - $this->registerService(AppFetcher::class, function ($c) { |
|
| 424 | - return new AppFetcher( |
|
| 425 | - $this->getAppDataDir('appstore'), |
|
| 426 | - $this->getHTTPClientService(), |
|
| 427 | - $this->query(TimeFactory::class), |
|
| 428 | - $this->getConfig() |
|
| 429 | - ); |
|
| 430 | - }); |
|
| 431 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 432 | - |
|
| 433 | - $this->registerService('CategoryFetcher', function ($c) { |
|
| 434 | - return new CategoryFetcher( |
|
| 435 | - $this->getAppDataDir('appstore'), |
|
| 436 | - $this->getHTTPClientService(), |
|
| 437 | - $this->query(TimeFactory::class), |
|
| 438 | - $this->getConfig() |
|
| 439 | - ); |
|
| 440 | - }); |
|
| 441 | - |
|
| 442 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 443 | - return new Cache\File(); |
|
| 444 | - }); |
|
| 445 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 446 | - |
|
| 447 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 448 | - $config = $c->getConfig(); |
|
| 449 | - |
|
| 450 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 451 | - $v = \OC_App::getAppVersions(); |
|
| 452 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 453 | - $version = implode(',', $v); |
|
| 454 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 455 | - $path = \OC::$SERVERROOT; |
|
| 456 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 457 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 458 | - $config->getSystemValue('memcache.local', null), |
|
| 459 | - $config->getSystemValue('memcache.distributed', null), |
|
| 460 | - $config->getSystemValue('memcache.locking', null) |
|
| 461 | - ); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 465 | - '\\OC\\Memcache\\ArrayCache', |
|
| 466 | - '\\OC\\Memcache\\ArrayCache', |
|
| 467 | - '\\OC\\Memcache\\ArrayCache' |
|
| 468 | - ); |
|
| 469 | - }); |
|
| 470 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 471 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 472 | - |
|
| 473 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 474 | - $systemConfig = $c->getSystemConfig(); |
|
| 475 | - return new RedisFactory($systemConfig); |
|
| 476 | - }); |
|
| 477 | - |
|
| 478 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 479 | - return new \OC\Activity\Manager( |
|
| 480 | - $c->getRequest(), |
|
| 481 | - $c->getUserSession(), |
|
| 482 | - $c->getConfig(), |
|
| 483 | - $c->query(IValidator::class) |
|
| 484 | - ); |
|
| 485 | - }); |
|
| 486 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 487 | - |
|
| 488 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 489 | - return new \OC\Activity\EventMerger( |
|
| 490 | - $c->getL10N('lib') |
|
| 491 | - ); |
|
| 492 | - }); |
|
| 493 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 494 | - |
|
| 495 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 496 | - return new AvatarManager( |
|
| 497 | - $c->getUserManager(), |
|
| 498 | - $c->getAppDataDir('avatar'), |
|
| 499 | - $c->getL10N('lib'), |
|
| 500 | - $c->getLogger(), |
|
| 501 | - $c->getConfig() |
|
| 502 | - ); |
|
| 503 | - }); |
|
| 504 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 505 | - |
|
| 506 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 507 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 508 | - $logger = Log::getLogClass($logType); |
|
| 509 | - call_user_func(array($logger, 'init')); |
|
| 510 | - |
|
| 511 | - return new Log($logger); |
|
| 512 | - }); |
|
| 513 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 514 | - |
|
| 515 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 516 | - $config = $c->getConfig(); |
|
| 517 | - return new \OC\BackgroundJob\JobList( |
|
| 518 | - $c->getDatabaseConnection(), |
|
| 519 | - $config, |
|
| 520 | - new TimeFactory() |
|
| 521 | - ); |
|
| 522 | - }); |
|
| 523 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 524 | - |
|
| 525 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 526 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 527 | - $logger = $c->getLogger(); |
|
| 528 | - if ($cacheFactory->isAvailable()) { |
|
| 529 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 530 | - } else { |
|
| 531 | - $router = new \OC\Route\Router($logger); |
|
| 532 | - } |
|
| 533 | - return $router; |
|
| 534 | - }); |
|
| 535 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 536 | - |
|
| 537 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 538 | - return new Search(); |
|
| 539 | - }); |
|
| 540 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 541 | - |
|
| 542 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
| 543 | - return new \OC\Security\RateLimiting\Limiter( |
|
| 544 | - $this->getUserSession(), |
|
| 545 | - $this->getRequest(), |
|
| 546 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 547 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 548 | - ); |
|
| 549 | - }); |
|
| 550 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 551 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 552 | - $this->getMemCacheFactory(), |
|
| 553 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 554 | - ); |
|
| 555 | - }); |
|
| 556 | - |
|
| 557 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 558 | - return new SecureRandom(); |
|
| 559 | - }); |
|
| 560 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 561 | - |
|
| 562 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 563 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 564 | - }); |
|
| 565 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 566 | - |
|
| 567 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 568 | - return new Hasher($c->getConfig()); |
|
| 569 | - }); |
|
| 570 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 571 | - |
|
| 572 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 573 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 574 | - }); |
|
| 575 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 576 | - |
|
| 577 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 578 | - $systemConfig = $c->getSystemConfig(); |
|
| 579 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 580 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 581 | - if (!$factory->isValidType($type)) { |
|
| 582 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 583 | - } |
|
| 584 | - $connectionParams = $factory->createConnectionParams(); |
|
| 585 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 586 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 587 | - return $connection; |
|
| 588 | - }); |
|
| 589 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 590 | - |
|
| 591 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 592 | - $config = $c->getConfig(); |
|
| 593 | - return new HTTPHelper( |
|
| 594 | - $config, |
|
| 595 | - $c->getHTTPClientService() |
|
| 596 | - ); |
|
| 597 | - }); |
|
| 598 | - |
|
| 599 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 600 | - $user = \OC_User::getUser(); |
|
| 601 | - $uid = $user ? $user : null; |
|
| 602 | - return new ClientService( |
|
| 603 | - $c->getConfig(), |
|
| 604 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
| 605 | - ); |
|
| 606 | - }); |
|
| 607 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 608 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 609 | - $eventLogger = new EventLogger(); |
|
| 610 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 611 | - // In debug mode, module is being activated by default |
|
| 612 | - $eventLogger->activate(); |
|
| 613 | - } |
|
| 614 | - return $eventLogger; |
|
| 615 | - }); |
|
| 616 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 617 | - |
|
| 618 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 619 | - $queryLogger = new QueryLogger(); |
|
| 620 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 621 | - // In debug mode, module is being activated by default |
|
| 622 | - $queryLogger->activate(); |
|
| 623 | - } |
|
| 624 | - return $queryLogger; |
|
| 625 | - }); |
|
| 626 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 627 | - |
|
| 628 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 629 | - return new TempManager( |
|
| 630 | - $c->getLogger(), |
|
| 631 | - $c->getConfig() |
|
| 632 | - ); |
|
| 633 | - }); |
|
| 634 | - $this->registerAlias('TempManager', TempManager::class); |
|
| 635 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 636 | - |
|
| 637 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 638 | - return new \OC\App\AppManager( |
|
| 639 | - $c->getUserSession(), |
|
| 640 | - $c->getAppConfig(), |
|
| 641 | - $c->getGroupManager(), |
|
| 642 | - $c->getMemCacheFactory(), |
|
| 643 | - $c->getEventDispatcher() |
|
| 644 | - ); |
|
| 645 | - }); |
|
| 646 | - $this->registerAlias('AppManager', AppManager::class); |
|
| 647 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 648 | - |
|
| 649 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 650 | - return new DateTimeZone( |
|
| 651 | - $c->getConfig(), |
|
| 652 | - $c->getSession() |
|
| 653 | - ); |
|
| 654 | - }); |
|
| 655 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 656 | - |
|
| 657 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 658 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 659 | - |
|
| 660 | - return new DateTimeFormatter( |
|
| 661 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 662 | - $c->getL10N('lib', $language) |
|
| 663 | - ); |
|
| 664 | - }); |
|
| 665 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 666 | - |
|
| 667 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 668 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 669 | - $listener = new UserMountCacheListener($mountCache); |
|
| 670 | - $listener->listen($c->getUserManager()); |
|
| 671 | - return $mountCache; |
|
| 672 | - }); |
|
| 673 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 674 | - |
|
| 675 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 676 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 677 | - $mountCache = $c->query('UserMountCache'); |
|
| 678 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 679 | - |
|
| 680 | - // builtin providers |
|
| 681 | - |
|
| 682 | - $config = $c->getConfig(); |
|
| 683 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 684 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 685 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 686 | - |
|
| 687 | - return $manager; |
|
| 688 | - }); |
|
| 689 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 690 | - |
|
| 691 | - $this->registerService('IniWrapper', function ($c) { |
|
| 692 | - return new IniGetWrapper(); |
|
| 693 | - }); |
|
| 694 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 695 | - $jobList = $c->getJobList(); |
|
| 696 | - return new AsyncBus($jobList); |
|
| 697 | - }); |
|
| 698 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 699 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 700 | - }); |
|
| 701 | - $this->registerService('Throttler', function(Server $c) { |
|
| 702 | - return new Throttler( |
|
| 703 | - $c->getDatabaseConnection(), |
|
| 704 | - new TimeFactory(), |
|
| 705 | - $c->getLogger(), |
|
| 706 | - $c->getConfig() |
|
| 707 | - ); |
|
| 708 | - }); |
|
| 709 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 710 | - // IConfig and IAppManager requires a working database. This code |
|
| 711 | - // might however be called when ownCloud is not yet setup. |
|
| 712 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 713 | - $config = $c->getConfig(); |
|
| 714 | - $appManager = $c->getAppManager(); |
|
| 715 | - } else { |
|
| 716 | - $config = null; |
|
| 717 | - $appManager = null; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - return new Checker( |
|
| 721 | - new EnvironmentHelper(), |
|
| 722 | - new FileAccessHelper(), |
|
| 723 | - new AppLocator(), |
|
| 724 | - $config, |
|
| 725 | - $c->getMemCacheFactory(), |
|
| 726 | - $appManager, |
|
| 727 | - $c->getTempManager() |
|
| 728 | - ); |
|
| 729 | - }); |
|
| 730 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 731 | - if (isset($this['urlParams'])) { |
|
| 732 | - $urlParams = $this['urlParams']; |
|
| 733 | - } else { |
|
| 734 | - $urlParams = []; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 738 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 739 | - ) { |
|
| 740 | - $stream = 'fakeinput://data'; |
|
| 741 | - } else { |
|
| 742 | - $stream = 'php://input'; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return new Request( |
|
| 746 | - [ |
|
| 747 | - 'get' => $_GET, |
|
| 748 | - 'post' => $_POST, |
|
| 749 | - 'files' => $_FILES, |
|
| 750 | - 'server' => $_SERVER, |
|
| 751 | - 'env' => $_ENV, |
|
| 752 | - 'cookies' => $_COOKIE, |
|
| 753 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 754 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 755 | - : null, |
|
| 756 | - 'urlParams' => $urlParams, |
|
| 757 | - ], |
|
| 758 | - $this->getSecureRandom(), |
|
| 759 | - $this->getConfig(), |
|
| 760 | - $this->getCsrfTokenManager(), |
|
| 761 | - $stream |
|
| 762 | - ); |
|
| 763 | - }); |
|
| 764 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 765 | - |
|
| 766 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 767 | - return new Mailer( |
|
| 768 | - $c->getConfig(), |
|
| 769 | - $c->getLogger(), |
|
| 770 | - $c->query(Defaults::class), |
|
| 771 | - $c->getURLGenerator(), |
|
| 772 | - $c->getL10N('lib') |
|
| 773 | - ); |
|
| 774 | - }); |
|
| 775 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 776 | - |
|
| 777 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
| 778 | - $config = $c->getConfig(); |
|
| 779 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 780 | - if(is_null($factoryClass)) { |
|
| 781 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 782 | - } |
|
| 783 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 784 | - $factory = new $factoryClass($this); |
|
| 785 | - return $factory->getLDAPProvider(); |
|
| 786 | - }); |
|
| 787 | - $this->registerService('LockingProvider', function (Server $c) { |
|
| 788 | - $ini = $c->getIniWrapper(); |
|
| 789 | - $config = $c->getConfig(); |
|
| 790 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 791 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 792 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 793 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 794 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 795 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 796 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 797 | - } |
|
| 798 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 799 | - } |
|
| 800 | - return new NoopLockingProvider(); |
|
| 801 | - }); |
|
| 802 | - |
|
| 803 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 804 | - return new \OC\Files\Mount\Manager(); |
|
| 805 | - }); |
|
| 806 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 807 | - |
|
| 808 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 809 | - return new \OC\Files\Type\Detection( |
|
| 810 | - $c->getURLGenerator(), |
|
| 811 | - \OC::$configDir, |
|
| 812 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 813 | - ); |
|
| 814 | - }); |
|
| 815 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 816 | - |
|
| 817 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 818 | - return new \OC\Files\Type\Loader( |
|
| 819 | - $c->getDatabaseConnection() |
|
| 820 | - ); |
|
| 821 | - }); |
|
| 822 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 823 | - $this->registerService(BundleFetcher::class, function () { |
|
| 824 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 825 | - }); |
|
| 826 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 827 | - return new Manager( |
|
| 828 | - $c->query(IValidator::class) |
|
| 829 | - ); |
|
| 830 | - }); |
|
| 831 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 832 | - |
|
| 833 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 834 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 835 | - $manager->registerCapability(function () use ($c) { |
|
| 836 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 837 | - }); |
|
| 838 | - return $manager; |
|
| 839 | - }); |
|
| 840 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 841 | - |
|
| 842 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 843 | - $config = $c->getConfig(); |
|
| 844 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 845 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 846 | - $factory = new $factoryClass($this); |
|
| 847 | - return $factory->getManager(); |
|
| 848 | - }); |
|
| 849 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 850 | - |
|
| 851 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 852 | - /* |
|
| 129 | + /** @var string */ |
|
| 130 | + private $webRoot; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param string $webRoot |
|
| 134 | + * @param \OC\Config $config |
|
| 135 | + */ |
|
| 136 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 137 | + parent::__construct(); |
|
| 138 | + $this->webRoot = $webRoot; |
|
| 139 | + |
|
| 140 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
| 141 | + return $c; |
|
| 142 | + }); |
|
| 143 | + |
|
| 144 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 145 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 146 | + |
|
| 147 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 148 | + |
|
| 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', 'logout', function () { |
|
| 365 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 366 | + }); |
|
| 367 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 368 | + /** @var $user \OC\User\User */ |
|
| 369 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 370 | + }); |
|
| 371 | + return $userSession; |
|
| 372 | + }); |
|
| 373 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 374 | + |
|
| 375 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 376 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
| 377 | + }); |
|
| 378 | + |
|
| 379 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 380 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 381 | + |
|
| 382 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 383 | + return new \OC\AllConfig( |
|
| 384 | + $c->getSystemConfig() |
|
| 385 | + ); |
|
| 386 | + }); |
|
| 387 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 388 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 389 | + |
|
| 390 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 391 | + return new \OC\SystemConfig($config); |
|
| 392 | + }); |
|
| 393 | + |
|
| 394 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 395 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 396 | + }); |
|
| 397 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 398 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 399 | + |
|
| 400 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 401 | + return new \OC\L10N\Factory( |
|
| 402 | + $c->getConfig(), |
|
| 403 | + $c->getRequest(), |
|
| 404 | + $c->getUserSession(), |
|
| 405 | + \OC::$SERVERROOT |
|
| 406 | + ); |
|
| 407 | + }); |
|
| 408 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 409 | + |
|
| 410 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 411 | + $config = $c->getConfig(); |
|
| 412 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 413 | + return new \OC\URLGenerator( |
|
| 414 | + $config, |
|
| 415 | + $cacheFactory |
|
| 416 | + ); |
|
| 417 | + }); |
|
| 418 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 419 | + |
|
| 420 | + $this->registerService('AppHelper', function ($c) { |
|
| 421 | + return new \OC\AppHelper(); |
|
| 422 | + }); |
|
| 423 | + $this->registerService(AppFetcher::class, function ($c) { |
|
| 424 | + return new AppFetcher( |
|
| 425 | + $this->getAppDataDir('appstore'), |
|
| 426 | + $this->getHTTPClientService(), |
|
| 427 | + $this->query(TimeFactory::class), |
|
| 428 | + $this->getConfig() |
|
| 429 | + ); |
|
| 430 | + }); |
|
| 431 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 432 | + |
|
| 433 | + $this->registerService('CategoryFetcher', function ($c) { |
|
| 434 | + return new CategoryFetcher( |
|
| 435 | + $this->getAppDataDir('appstore'), |
|
| 436 | + $this->getHTTPClientService(), |
|
| 437 | + $this->query(TimeFactory::class), |
|
| 438 | + $this->getConfig() |
|
| 439 | + ); |
|
| 440 | + }); |
|
| 441 | + |
|
| 442 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 443 | + return new Cache\File(); |
|
| 444 | + }); |
|
| 445 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 446 | + |
|
| 447 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 448 | + $config = $c->getConfig(); |
|
| 449 | + |
|
| 450 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 451 | + $v = \OC_App::getAppVersions(); |
|
| 452 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 453 | + $version = implode(',', $v); |
|
| 454 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 455 | + $path = \OC::$SERVERROOT; |
|
| 456 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 457 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 458 | + $config->getSystemValue('memcache.local', null), |
|
| 459 | + $config->getSystemValue('memcache.distributed', null), |
|
| 460 | + $config->getSystemValue('memcache.locking', null) |
|
| 461 | + ); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 465 | + '\\OC\\Memcache\\ArrayCache', |
|
| 466 | + '\\OC\\Memcache\\ArrayCache', |
|
| 467 | + '\\OC\\Memcache\\ArrayCache' |
|
| 468 | + ); |
|
| 469 | + }); |
|
| 470 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 471 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 472 | + |
|
| 473 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 474 | + $systemConfig = $c->getSystemConfig(); |
|
| 475 | + return new RedisFactory($systemConfig); |
|
| 476 | + }); |
|
| 477 | + |
|
| 478 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 479 | + return new \OC\Activity\Manager( |
|
| 480 | + $c->getRequest(), |
|
| 481 | + $c->getUserSession(), |
|
| 482 | + $c->getConfig(), |
|
| 483 | + $c->query(IValidator::class) |
|
| 484 | + ); |
|
| 485 | + }); |
|
| 486 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 487 | + |
|
| 488 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 489 | + return new \OC\Activity\EventMerger( |
|
| 490 | + $c->getL10N('lib') |
|
| 491 | + ); |
|
| 492 | + }); |
|
| 493 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 494 | + |
|
| 495 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 496 | + return new AvatarManager( |
|
| 497 | + $c->getUserManager(), |
|
| 498 | + $c->getAppDataDir('avatar'), |
|
| 499 | + $c->getL10N('lib'), |
|
| 500 | + $c->getLogger(), |
|
| 501 | + $c->getConfig() |
|
| 502 | + ); |
|
| 503 | + }); |
|
| 504 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 505 | + |
|
| 506 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 507 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 508 | + $logger = Log::getLogClass($logType); |
|
| 509 | + call_user_func(array($logger, 'init')); |
|
| 510 | + |
|
| 511 | + return new Log($logger); |
|
| 512 | + }); |
|
| 513 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 514 | + |
|
| 515 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 516 | + $config = $c->getConfig(); |
|
| 517 | + return new \OC\BackgroundJob\JobList( |
|
| 518 | + $c->getDatabaseConnection(), |
|
| 519 | + $config, |
|
| 520 | + new TimeFactory() |
|
| 521 | + ); |
|
| 522 | + }); |
|
| 523 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 524 | + |
|
| 525 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 526 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 527 | + $logger = $c->getLogger(); |
|
| 528 | + if ($cacheFactory->isAvailable()) { |
|
| 529 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
| 530 | + } else { |
|
| 531 | + $router = new \OC\Route\Router($logger); |
|
| 532 | + } |
|
| 533 | + return $router; |
|
| 534 | + }); |
|
| 535 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 536 | + |
|
| 537 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 538 | + return new Search(); |
|
| 539 | + }); |
|
| 540 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 541 | + |
|
| 542 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
| 543 | + return new \OC\Security\RateLimiting\Limiter( |
|
| 544 | + $this->getUserSession(), |
|
| 545 | + $this->getRequest(), |
|
| 546 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 547 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 548 | + ); |
|
| 549 | + }); |
|
| 550 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 551 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 552 | + $this->getMemCacheFactory(), |
|
| 553 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 554 | + ); |
|
| 555 | + }); |
|
| 556 | + |
|
| 557 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 558 | + return new SecureRandom(); |
|
| 559 | + }); |
|
| 560 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 561 | + |
|
| 562 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 563 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 564 | + }); |
|
| 565 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 566 | + |
|
| 567 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 568 | + return new Hasher($c->getConfig()); |
|
| 569 | + }); |
|
| 570 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 571 | + |
|
| 572 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 573 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 574 | + }); |
|
| 575 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 576 | + |
|
| 577 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 578 | + $systemConfig = $c->getSystemConfig(); |
|
| 579 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 580 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 581 | + if (!$factory->isValidType($type)) { |
|
| 582 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 583 | + } |
|
| 584 | + $connectionParams = $factory->createConnectionParams(); |
|
| 585 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 586 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 587 | + return $connection; |
|
| 588 | + }); |
|
| 589 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 590 | + |
|
| 591 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
| 592 | + $config = $c->getConfig(); |
|
| 593 | + return new HTTPHelper( |
|
| 594 | + $config, |
|
| 595 | + $c->getHTTPClientService() |
|
| 596 | + ); |
|
| 597 | + }); |
|
| 598 | + |
|
| 599 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 600 | + $user = \OC_User::getUser(); |
|
| 601 | + $uid = $user ? $user : null; |
|
| 602 | + return new ClientService( |
|
| 603 | + $c->getConfig(), |
|
| 604 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
| 605 | + ); |
|
| 606 | + }); |
|
| 607 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 608 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 609 | + $eventLogger = new EventLogger(); |
|
| 610 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 611 | + // In debug mode, module is being activated by default |
|
| 612 | + $eventLogger->activate(); |
|
| 613 | + } |
|
| 614 | + return $eventLogger; |
|
| 615 | + }); |
|
| 616 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 617 | + |
|
| 618 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 619 | + $queryLogger = new QueryLogger(); |
|
| 620 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 621 | + // In debug mode, module is being activated by default |
|
| 622 | + $queryLogger->activate(); |
|
| 623 | + } |
|
| 624 | + return $queryLogger; |
|
| 625 | + }); |
|
| 626 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 627 | + |
|
| 628 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 629 | + return new TempManager( |
|
| 630 | + $c->getLogger(), |
|
| 631 | + $c->getConfig() |
|
| 632 | + ); |
|
| 633 | + }); |
|
| 634 | + $this->registerAlias('TempManager', TempManager::class); |
|
| 635 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 636 | + |
|
| 637 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 638 | + return new \OC\App\AppManager( |
|
| 639 | + $c->getUserSession(), |
|
| 640 | + $c->getAppConfig(), |
|
| 641 | + $c->getGroupManager(), |
|
| 642 | + $c->getMemCacheFactory(), |
|
| 643 | + $c->getEventDispatcher() |
|
| 644 | + ); |
|
| 645 | + }); |
|
| 646 | + $this->registerAlias('AppManager', AppManager::class); |
|
| 647 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 648 | + |
|
| 649 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 650 | + return new DateTimeZone( |
|
| 651 | + $c->getConfig(), |
|
| 652 | + $c->getSession() |
|
| 653 | + ); |
|
| 654 | + }); |
|
| 655 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 656 | + |
|
| 657 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 658 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 659 | + |
|
| 660 | + return new DateTimeFormatter( |
|
| 661 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 662 | + $c->getL10N('lib', $language) |
|
| 663 | + ); |
|
| 664 | + }); |
|
| 665 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 666 | + |
|
| 667 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 668 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 669 | + $listener = new UserMountCacheListener($mountCache); |
|
| 670 | + $listener->listen($c->getUserManager()); |
|
| 671 | + return $mountCache; |
|
| 672 | + }); |
|
| 673 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 674 | + |
|
| 675 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 676 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 677 | + $mountCache = $c->query('UserMountCache'); |
|
| 678 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 679 | + |
|
| 680 | + // builtin providers |
|
| 681 | + |
|
| 682 | + $config = $c->getConfig(); |
|
| 683 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 684 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 685 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 686 | + |
|
| 687 | + return $manager; |
|
| 688 | + }); |
|
| 689 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 690 | + |
|
| 691 | + $this->registerService('IniWrapper', function ($c) { |
|
| 692 | + return new IniGetWrapper(); |
|
| 693 | + }); |
|
| 694 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 695 | + $jobList = $c->getJobList(); |
|
| 696 | + return new AsyncBus($jobList); |
|
| 697 | + }); |
|
| 698 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 699 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 700 | + }); |
|
| 701 | + $this->registerService('Throttler', function(Server $c) { |
|
| 702 | + return new Throttler( |
|
| 703 | + $c->getDatabaseConnection(), |
|
| 704 | + new TimeFactory(), |
|
| 705 | + $c->getLogger(), |
|
| 706 | + $c->getConfig() |
|
| 707 | + ); |
|
| 708 | + }); |
|
| 709 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 710 | + // IConfig and IAppManager requires a working database. This code |
|
| 711 | + // might however be called when ownCloud is not yet setup. |
|
| 712 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 713 | + $config = $c->getConfig(); |
|
| 714 | + $appManager = $c->getAppManager(); |
|
| 715 | + } else { |
|
| 716 | + $config = null; |
|
| 717 | + $appManager = null; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + return new Checker( |
|
| 721 | + new EnvironmentHelper(), |
|
| 722 | + new FileAccessHelper(), |
|
| 723 | + new AppLocator(), |
|
| 724 | + $config, |
|
| 725 | + $c->getMemCacheFactory(), |
|
| 726 | + $appManager, |
|
| 727 | + $c->getTempManager() |
|
| 728 | + ); |
|
| 729 | + }); |
|
| 730 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 731 | + if (isset($this['urlParams'])) { |
|
| 732 | + $urlParams = $this['urlParams']; |
|
| 733 | + } else { |
|
| 734 | + $urlParams = []; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 738 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 739 | + ) { |
|
| 740 | + $stream = 'fakeinput://data'; |
|
| 741 | + } else { |
|
| 742 | + $stream = 'php://input'; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return new Request( |
|
| 746 | + [ |
|
| 747 | + 'get' => $_GET, |
|
| 748 | + 'post' => $_POST, |
|
| 749 | + 'files' => $_FILES, |
|
| 750 | + 'server' => $_SERVER, |
|
| 751 | + 'env' => $_ENV, |
|
| 752 | + 'cookies' => $_COOKIE, |
|
| 753 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 754 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 755 | + : null, |
|
| 756 | + 'urlParams' => $urlParams, |
|
| 757 | + ], |
|
| 758 | + $this->getSecureRandom(), |
|
| 759 | + $this->getConfig(), |
|
| 760 | + $this->getCsrfTokenManager(), |
|
| 761 | + $stream |
|
| 762 | + ); |
|
| 763 | + }); |
|
| 764 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 765 | + |
|
| 766 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 767 | + return new Mailer( |
|
| 768 | + $c->getConfig(), |
|
| 769 | + $c->getLogger(), |
|
| 770 | + $c->query(Defaults::class), |
|
| 771 | + $c->getURLGenerator(), |
|
| 772 | + $c->getL10N('lib') |
|
| 773 | + ); |
|
| 774 | + }); |
|
| 775 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 776 | + |
|
| 777 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 778 | + $config = $c->getConfig(); |
|
| 779 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 780 | + if(is_null($factoryClass)) { |
|
| 781 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 782 | + } |
|
| 783 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 784 | + $factory = new $factoryClass($this); |
|
| 785 | + return $factory->getLDAPProvider(); |
|
| 786 | + }); |
|
| 787 | + $this->registerService('LockingProvider', function (Server $c) { |
|
| 788 | + $ini = $c->getIniWrapper(); |
|
| 789 | + $config = $c->getConfig(); |
|
| 790 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 791 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 792 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 793 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 794 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 795 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 796 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 797 | + } |
|
| 798 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
| 799 | + } |
|
| 800 | + return new NoopLockingProvider(); |
|
| 801 | + }); |
|
| 802 | + |
|
| 803 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 804 | + return new \OC\Files\Mount\Manager(); |
|
| 805 | + }); |
|
| 806 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 807 | + |
|
| 808 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 809 | + return new \OC\Files\Type\Detection( |
|
| 810 | + $c->getURLGenerator(), |
|
| 811 | + \OC::$configDir, |
|
| 812 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 813 | + ); |
|
| 814 | + }); |
|
| 815 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 816 | + |
|
| 817 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 818 | + return new \OC\Files\Type\Loader( |
|
| 819 | + $c->getDatabaseConnection() |
|
| 820 | + ); |
|
| 821 | + }); |
|
| 822 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 823 | + $this->registerService(BundleFetcher::class, function () { |
|
| 824 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 825 | + }); |
|
| 826 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 827 | + return new Manager( |
|
| 828 | + $c->query(IValidator::class) |
|
| 829 | + ); |
|
| 830 | + }); |
|
| 831 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 832 | + |
|
| 833 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 834 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 835 | + $manager->registerCapability(function () use ($c) { |
|
| 836 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 837 | + }); |
|
| 838 | + return $manager; |
|
| 839 | + }); |
|
| 840 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 841 | + |
|
| 842 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 843 | + $config = $c->getConfig(); |
|
| 844 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
| 845 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 846 | + $factory = new $factoryClass($this); |
|
| 847 | + return $factory->getManager(); |
|
| 848 | + }); |
|
| 849 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 850 | + |
|
| 851 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 852 | + /* |
|
| 853 | 853 | * Dark magic for autoloader. |
| 854 | 854 | * If we do a class_exists it will try to load the class which will |
| 855 | 855 | * make composer cache the result. Resulting in errors when enabling |
| 856 | 856 | * the theming app. |
| 857 | 857 | */ |
| 858 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 859 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 860 | - $classExists = true; |
|
| 861 | - } else { |
|
| 862 | - $classExists = false; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
| 866 | - return new ThemingDefaults( |
|
| 867 | - $c->getConfig(), |
|
| 868 | - $c->getL10N('theming'), |
|
| 869 | - $c->getURLGenerator(), |
|
| 870 | - $c->getAppDataDir('theming'), |
|
| 871 | - $c->getMemCacheFactory(), |
|
| 872 | - new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager()) |
|
| 873 | - ); |
|
| 874 | - } |
|
| 875 | - return new \OC_Defaults(); |
|
| 876 | - }); |
|
| 877 | - $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 878 | - /** @var Factory $cacheFactory */ |
|
| 879 | - $cacheFactory = $c->query(Factory::class); |
|
| 880 | - return new SCSSCacher( |
|
| 881 | - $c->getLogger(), |
|
| 882 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 883 | - $c->getURLGenerator(), |
|
| 884 | - $c->getConfig(), |
|
| 885 | - $c->getThemingDefaults(), |
|
| 886 | - \OC::$SERVERROOT, |
|
| 887 | - $cacheFactory->create('SCSS') |
|
| 888 | - ); |
|
| 889 | - }); |
|
| 890 | - $this->registerService(EventDispatcher::class, function () { |
|
| 891 | - return new EventDispatcher(); |
|
| 892 | - }); |
|
| 893 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 894 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 895 | - |
|
| 896 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 897 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 898 | - $request = new Request( |
|
| 899 | - [ |
|
| 900 | - 'get' => $_GET, |
|
| 901 | - 'post' => $_POST, |
|
| 902 | - 'files' => $_FILES, |
|
| 903 | - 'server' => $_SERVER, |
|
| 904 | - 'env' => $_ENV, |
|
| 905 | - 'cookies' => $_COOKIE, |
|
| 906 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 907 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 908 | - : null, |
|
| 909 | - ], |
|
| 910 | - $c->getSecureRandom(), |
|
| 911 | - $c->getConfig() |
|
| 912 | - ); |
|
| 913 | - |
|
| 914 | - return new CryptoWrapper( |
|
| 915 | - $c->getConfig(), |
|
| 916 | - $c->getCrypto(), |
|
| 917 | - $c->getSecureRandom(), |
|
| 918 | - $request |
|
| 919 | - ); |
|
| 920 | - }); |
|
| 921 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 922 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 923 | - |
|
| 924 | - return new CsrfTokenManager( |
|
| 925 | - $tokenGenerator, |
|
| 926 | - $c->query(SessionStorage::class) |
|
| 927 | - ); |
|
| 928 | - }); |
|
| 929 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 930 | - return new SessionStorage($c->getSession()); |
|
| 931 | - }); |
|
| 932 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 933 | - return new ContentSecurityPolicyManager(); |
|
| 934 | - }); |
|
| 935 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 936 | - |
|
| 937 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 938 | - return new ContentSecurityPolicyNonceManager( |
|
| 939 | - $c->getCsrfTokenManager(), |
|
| 940 | - $c->getRequest() |
|
| 941 | - ); |
|
| 942 | - }); |
|
| 943 | - |
|
| 944 | - $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 945 | - $config = $c->getConfig(); |
|
| 946 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 947 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 948 | - $factory = new $factoryClass($this); |
|
| 949 | - |
|
| 950 | - $manager = new \OC\Share20\Manager( |
|
| 951 | - $c->getLogger(), |
|
| 952 | - $c->getConfig(), |
|
| 953 | - $c->getSecureRandom(), |
|
| 954 | - $c->getHasher(), |
|
| 955 | - $c->getMountManager(), |
|
| 956 | - $c->getGroupManager(), |
|
| 957 | - $c->getL10N('core'), |
|
| 958 | - $factory, |
|
| 959 | - $c->getUserManager(), |
|
| 960 | - $c->getLazyRootFolder(), |
|
| 961 | - $c->getEventDispatcher() |
|
| 962 | - ); |
|
| 963 | - |
|
| 964 | - return $manager; |
|
| 965 | - }); |
|
| 966 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 967 | - |
|
| 968 | - $this->registerService('SettingsManager', function(Server $c) { |
|
| 969 | - $manager = new \OC\Settings\Manager( |
|
| 970 | - $c->getLogger(), |
|
| 971 | - $c->getDatabaseConnection(), |
|
| 972 | - $c->getL10N('lib'), |
|
| 973 | - $c->getConfig(), |
|
| 974 | - $c->getEncryptionManager(), |
|
| 975 | - $c->getUserManager(), |
|
| 976 | - $c->getLockingProvider(), |
|
| 977 | - $c->getRequest(), |
|
| 978 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 979 | - $c->getURLGenerator() |
|
| 980 | - ); |
|
| 981 | - return $manager; |
|
| 982 | - }); |
|
| 983 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 984 | - return new \OC\Files\AppData\Factory( |
|
| 985 | - $c->getRootFolder(), |
|
| 986 | - $c->getSystemConfig() |
|
| 987 | - ); |
|
| 988 | - }); |
|
| 989 | - |
|
| 990 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 991 | - return new LockdownManager(function() use ($c) { |
|
| 992 | - return $c->getSession(); |
|
| 993 | - }); |
|
| 994 | - }); |
|
| 995 | - |
|
| 996 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 997 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 998 | - }); |
|
| 999 | - |
|
| 1000 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1001 | - return new CloudIdManager(); |
|
| 1002 | - }); |
|
| 1003 | - |
|
| 1004 | - /* To trick DI since we don't extend the DIContainer here */ |
|
| 1005 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1006 | - return new CleanPreviewsBackgroundJob( |
|
| 1007 | - $c->getRootFolder(), |
|
| 1008 | - $c->getLogger(), |
|
| 1009 | - $c->getJobList(), |
|
| 1010 | - new TimeFactory() |
|
| 1011 | - ); |
|
| 1012 | - }); |
|
| 1013 | - |
|
| 1014 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1015 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1016 | - |
|
| 1017 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1018 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1019 | - |
|
| 1020 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1021 | - return new Defaults( |
|
| 1022 | - $c->getThemingDefaults() |
|
| 1023 | - ); |
|
| 1024 | - }); |
|
| 1025 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1026 | - |
|
| 1027 | - $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1028 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1029 | - }); |
|
| 1030 | - |
|
| 1031 | - $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1032 | - return new ShareHelper( |
|
| 1033 | - $c->query(\OCP\Share\IManager::class) |
|
| 1034 | - ); |
|
| 1035 | - }); |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * @return \OCP\Contacts\IManager |
|
| 1040 | - */ |
|
| 1041 | - public function getContactsManager() { |
|
| 1042 | - return $this->query('ContactsManager'); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * @return \OC\Encryption\Manager |
|
| 1047 | - */ |
|
| 1048 | - public function getEncryptionManager() { |
|
| 1049 | - return $this->query('EncryptionManager'); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - /** |
|
| 1053 | - * @return \OC\Encryption\File |
|
| 1054 | - */ |
|
| 1055 | - public function getEncryptionFilesHelper() { |
|
| 1056 | - return $this->query('EncryptionFileHelper'); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - /** |
|
| 1060 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1061 | - */ |
|
| 1062 | - public function getEncryptionKeyStorage() { |
|
| 1063 | - return $this->query('EncryptionKeyStorage'); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * The current request object holding all information about the request |
|
| 1068 | - * currently being processed is returned from this method. |
|
| 1069 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1070 | - * |
|
| 1071 | - * @return \OCP\IRequest |
|
| 1072 | - */ |
|
| 1073 | - public function getRequest() { |
|
| 1074 | - return $this->query('Request'); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * Returns the preview manager which can create preview images for a given file |
|
| 1079 | - * |
|
| 1080 | - * @return \OCP\IPreview |
|
| 1081 | - */ |
|
| 1082 | - public function getPreviewManager() { |
|
| 1083 | - return $this->query('PreviewManager'); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1088 | - * |
|
| 1089 | - * @see \OCP\ITagManager::load() |
|
| 1090 | - * @return \OCP\ITagManager |
|
| 1091 | - */ |
|
| 1092 | - public function getTagManager() { |
|
| 1093 | - return $this->query('TagManager'); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - /** |
|
| 1097 | - * Returns the system-tag manager |
|
| 1098 | - * |
|
| 1099 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 1100 | - * |
|
| 1101 | - * @since 9.0.0 |
|
| 1102 | - */ |
|
| 1103 | - public function getSystemTagManager() { |
|
| 1104 | - return $this->query('SystemTagManager'); |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * Returns the system-tag object mapper |
|
| 1109 | - * |
|
| 1110 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1111 | - * |
|
| 1112 | - * @since 9.0.0 |
|
| 1113 | - */ |
|
| 1114 | - public function getSystemTagObjectMapper() { |
|
| 1115 | - return $this->query('SystemTagObjectMapper'); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * Returns the avatar manager, used for avatar functionality |
|
| 1120 | - * |
|
| 1121 | - * @return \OCP\IAvatarManager |
|
| 1122 | - */ |
|
| 1123 | - public function getAvatarManager() { |
|
| 1124 | - return $this->query('AvatarManager'); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Returns the root folder of ownCloud's data directory |
|
| 1129 | - * |
|
| 1130 | - * @return \OCP\Files\IRootFolder |
|
| 1131 | - */ |
|
| 1132 | - public function getRootFolder() { |
|
| 1133 | - return $this->query('LazyRootFolder'); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Returns the root folder of ownCloud's data directory |
|
| 1138 | - * This is the lazy variant so this gets only initialized once it |
|
| 1139 | - * is actually used. |
|
| 1140 | - * |
|
| 1141 | - * @return \OCP\Files\IRootFolder |
|
| 1142 | - */ |
|
| 1143 | - public function getLazyRootFolder() { |
|
| 1144 | - return $this->query('LazyRootFolder'); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - /** |
|
| 1148 | - * Returns a view to ownCloud's files folder |
|
| 1149 | - * |
|
| 1150 | - * @param string $userId user ID |
|
| 1151 | - * @return \OCP\Files\Folder|null |
|
| 1152 | - */ |
|
| 1153 | - public function getUserFolder($userId = null) { |
|
| 1154 | - if ($userId === null) { |
|
| 1155 | - $user = $this->getUserSession()->getUser(); |
|
| 1156 | - if (!$user) { |
|
| 1157 | - return null; |
|
| 1158 | - } |
|
| 1159 | - $userId = $user->getUID(); |
|
| 1160 | - } |
|
| 1161 | - $root = $this->getRootFolder(); |
|
| 1162 | - return $root->getUserFolder($userId); |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - /** |
|
| 1166 | - * Returns an app-specific view in ownClouds data directory |
|
| 1167 | - * |
|
| 1168 | - * @return \OCP\Files\Folder |
|
| 1169 | - * @deprecated since 9.2.0 use IAppData |
|
| 1170 | - */ |
|
| 1171 | - public function getAppFolder() { |
|
| 1172 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1173 | - $root = $this->getRootFolder(); |
|
| 1174 | - if (!$root->nodeExists($dir)) { |
|
| 1175 | - $folder = $root->newFolder($dir); |
|
| 1176 | - } else { |
|
| 1177 | - $folder = $root->get($dir); |
|
| 1178 | - } |
|
| 1179 | - return $folder; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - /** |
|
| 1183 | - * @return \OC\User\Manager |
|
| 1184 | - */ |
|
| 1185 | - public function getUserManager() { |
|
| 1186 | - return $this->query('UserManager'); |
|
| 1187 | - } |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * @return \OC\Group\Manager |
|
| 1191 | - */ |
|
| 1192 | - public function getGroupManager() { |
|
| 1193 | - return $this->query('GroupManager'); |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * @return \OC\User\Session |
|
| 1198 | - */ |
|
| 1199 | - public function getUserSession() { |
|
| 1200 | - return $this->query('UserSession'); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * @return \OCP\ISession |
|
| 1205 | - */ |
|
| 1206 | - public function getSession() { |
|
| 1207 | - return $this->query('UserSession')->getSession(); |
|
| 1208 | - } |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * @param \OCP\ISession $session |
|
| 1212 | - */ |
|
| 1213 | - public function setSession(\OCP\ISession $session) { |
|
| 1214 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1215 | - $this->query('UserSession')->setSession($session); |
|
| 1216 | - $this->query(Store::class)->setSession($session); |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - /** |
|
| 1220 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1221 | - */ |
|
| 1222 | - public function getTwoFactorAuthManager() { |
|
| 1223 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * @return \OC\NavigationManager |
|
| 1228 | - */ |
|
| 1229 | - public function getNavigationManager() { |
|
| 1230 | - return $this->query('NavigationManager'); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - /** |
|
| 1234 | - * @return \OCP\IConfig |
|
| 1235 | - */ |
|
| 1236 | - public function getConfig() { |
|
| 1237 | - return $this->query('AllConfig'); |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * @internal For internal use only |
|
| 1242 | - * @return \OC\SystemConfig |
|
| 1243 | - */ |
|
| 1244 | - public function getSystemConfig() { |
|
| 1245 | - return $this->query('SystemConfig'); |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - /** |
|
| 1249 | - * Returns the app config manager |
|
| 1250 | - * |
|
| 1251 | - * @return \OCP\IAppConfig |
|
| 1252 | - */ |
|
| 1253 | - public function getAppConfig() { |
|
| 1254 | - return $this->query('AppConfig'); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * @return \OCP\L10N\IFactory |
|
| 1259 | - */ |
|
| 1260 | - public function getL10NFactory() { |
|
| 1261 | - return $this->query('L10NFactory'); |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * get an L10N instance |
|
| 1266 | - * |
|
| 1267 | - * @param string $app appid |
|
| 1268 | - * @param string $lang |
|
| 1269 | - * @return IL10N |
|
| 1270 | - */ |
|
| 1271 | - public function getL10N($app, $lang = null) { |
|
| 1272 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - /** |
|
| 1276 | - * @return \OCP\IURLGenerator |
|
| 1277 | - */ |
|
| 1278 | - public function getURLGenerator() { |
|
| 1279 | - return $this->query('URLGenerator'); |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * @return \OCP\IHelper |
|
| 1284 | - */ |
|
| 1285 | - public function getHelper() { |
|
| 1286 | - return $this->query('AppHelper'); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * @return AppFetcher |
|
| 1291 | - */ |
|
| 1292 | - public function getAppFetcher() { |
|
| 1293 | - return $this->query('AppFetcher'); |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1298 | - * getMemCacheFactory() instead. |
|
| 1299 | - * |
|
| 1300 | - * @return \OCP\ICache |
|
| 1301 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1302 | - */ |
|
| 1303 | - public function getCache() { |
|
| 1304 | - return $this->query('UserCache'); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Returns an \OCP\CacheFactory instance |
|
| 1309 | - * |
|
| 1310 | - * @return \OCP\ICacheFactory |
|
| 1311 | - */ |
|
| 1312 | - public function getMemCacheFactory() { |
|
| 1313 | - return $this->query('MemCacheFactory'); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * Returns an \OC\RedisFactory instance |
|
| 1318 | - * |
|
| 1319 | - * @return \OC\RedisFactory |
|
| 1320 | - */ |
|
| 1321 | - public function getGetRedisFactory() { |
|
| 1322 | - return $this->query('RedisFactory'); |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * Returns the current session |
|
| 1328 | - * |
|
| 1329 | - * @return \OCP\IDBConnection |
|
| 1330 | - */ |
|
| 1331 | - public function getDatabaseConnection() { |
|
| 1332 | - return $this->query('DatabaseConnection'); |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * Returns the activity manager |
|
| 1337 | - * |
|
| 1338 | - * @return \OCP\Activity\IManager |
|
| 1339 | - */ |
|
| 1340 | - public function getActivityManager() { |
|
| 1341 | - return $this->query('ActivityManager'); |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - /** |
|
| 1345 | - * Returns an job list for controlling background jobs |
|
| 1346 | - * |
|
| 1347 | - * @return \OCP\BackgroundJob\IJobList |
|
| 1348 | - */ |
|
| 1349 | - public function getJobList() { |
|
| 1350 | - return $this->query('JobList'); |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Returns a logger instance |
|
| 1355 | - * |
|
| 1356 | - * @return \OCP\ILogger |
|
| 1357 | - */ |
|
| 1358 | - public function getLogger() { |
|
| 1359 | - return $this->query('Logger'); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Returns a router for generating and matching urls |
|
| 1364 | - * |
|
| 1365 | - * @return \OCP\Route\IRouter |
|
| 1366 | - */ |
|
| 1367 | - public function getRouter() { |
|
| 1368 | - return $this->query('Router'); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - /** |
|
| 1372 | - * Returns a search instance |
|
| 1373 | - * |
|
| 1374 | - * @return \OCP\ISearch |
|
| 1375 | - */ |
|
| 1376 | - public function getSearch() { |
|
| 1377 | - return $this->query('Search'); |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * Returns a SecureRandom instance |
|
| 1382 | - * |
|
| 1383 | - * @return \OCP\Security\ISecureRandom |
|
| 1384 | - */ |
|
| 1385 | - public function getSecureRandom() { |
|
| 1386 | - return $this->query('SecureRandom'); |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - /** |
|
| 1390 | - * Returns a Crypto instance |
|
| 1391 | - * |
|
| 1392 | - * @return \OCP\Security\ICrypto |
|
| 1393 | - */ |
|
| 1394 | - public function getCrypto() { |
|
| 1395 | - return $this->query('Crypto'); |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - /** |
|
| 1399 | - * Returns a Hasher instance |
|
| 1400 | - * |
|
| 1401 | - * @return \OCP\Security\IHasher |
|
| 1402 | - */ |
|
| 1403 | - public function getHasher() { |
|
| 1404 | - return $this->query('Hasher'); |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - /** |
|
| 1408 | - * Returns a CredentialsManager instance |
|
| 1409 | - * |
|
| 1410 | - * @return \OCP\Security\ICredentialsManager |
|
| 1411 | - */ |
|
| 1412 | - public function getCredentialsManager() { |
|
| 1413 | - return $this->query('CredentialsManager'); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * Returns an instance of the HTTP helper class |
|
| 1418 | - * |
|
| 1419 | - * @deprecated Use getHTTPClientService() |
|
| 1420 | - * @return \OC\HTTPHelper |
|
| 1421 | - */ |
|
| 1422 | - public function getHTTPHelper() { |
|
| 1423 | - return $this->query('HTTPHelper'); |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * Get the certificate manager for the user |
|
| 1428 | - * |
|
| 1429 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1430 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1431 | - */ |
|
| 1432 | - public function getCertificateManager($userId = '') { |
|
| 1433 | - if ($userId === '') { |
|
| 1434 | - $userSession = $this->getUserSession(); |
|
| 1435 | - $user = $userSession->getUser(); |
|
| 1436 | - if (is_null($user)) { |
|
| 1437 | - return null; |
|
| 1438 | - } |
|
| 1439 | - $userId = $user->getUID(); |
|
| 1440 | - } |
|
| 1441 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * Returns an instance of the HTTP client service |
|
| 1446 | - * |
|
| 1447 | - * @return \OCP\Http\Client\IClientService |
|
| 1448 | - */ |
|
| 1449 | - public function getHTTPClientService() { |
|
| 1450 | - return $this->query('HttpClientService'); |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Create a new event source |
|
| 1455 | - * |
|
| 1456 | - * @return \OCP\IEventSource |
|
| 1457 | - */ |
|
| 1458 | - public function createEventSource() { |
|
| 1459 | - return new \OC_EventSource(); |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * Get the active event logger |
|
| 1464 | - * |
|
| 1465 | - * The returned logger only logs data when debug mode is enabled |
|
| 1466 | - * |
|
| 1467 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 1468 | - */ |
|
| 1469 | - public function getEventLogger() { |
|
| 1470 | - return $this->query('EventLogger'); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * Get the active query logger |
|
| 1475 | - * |
|
| 1476 | - * The returned logger only logs data when debug mode is enabled |
|
| 1477 | - * |
|
| 1478 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 1479 | - */ |
|
| 1480 | - public function getQueryLogger() { |
|
| 1481 | - return $this->query('QueryLogger'); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * Get the manager for temporary files and folders |
|
| 1486 | - * |
|
| 1487 | - * @return \OCP\ITempManager |
|
| 1488 | - */ |
|
| 1489 | - public function getTempManager() { |
|
| 1490 | - return $this->query('TempManager'); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Get the app manager |
|
| 1495 | - * |
|
| 1496 | - * @return \OCP\App\IAppManager |
|
| 1497 | - */ |
|
| 1498 | - public function getAppManager() { |
|
| 1499 | - return $this->query('AppManager'); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - /** |
|
| 1503 | - * Creates a new mailer |
|
| 1504 | - * |
|
| 1505 | - * @return \OCP\Mail\IMailer |
|
| 1506 | - */ |
|
| 1507 | - public function getMailer() { |
|
| 1508 | - return $this->query('Mailer'); |
|
| 1509 | - } |
|
| 1510 | - |
|
| 1511 | - /** |
|
| 1512 | - * Get the webroot |
|
| 1513 | - * |
|
| 1514 | - * @return string |
|
| 1515 | - */ |
|
| 1516 | - public function getWebRoot() { |
|
| 1517 | - return $this->webRoot; |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - /** |
|
| 1521 | - * @return \OC\OCSClient |
|
| 1522 | - */ |
|
| 1523 | - public function getOcsClient() { |
|
| 1524 | - return $this->query('OcsClient'); |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * @return \OCP\IDateTimeZone |
|
| 1529 | - */ |
|
| 1530 | - public function getDateTimeZone() { |
|
| 1531 | - return $this->query('DateTimeZone'); |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * @return \OCP\IDateTimeFormatter |
|
| 1536 | - */ |
|
| 1537 | - public function getDateTimeFormatter() { |
|
| 1538 | - return $this->query('DateTimeFormatter'); |
|
| 1539 | - } |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1543 | - */ |
|
| 1544 | - public function getMountProviderCollection() { |
|
| 1545 | - return $this->query('MountConfigManager'); |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - /** |
|
| 1549 | - * Get the IniWrapper |
|
| 1550 | - * |
|
| 1551 | - * @return IniGetWrapper |
|
| 1552 | - */ |
|
| 1553 | - public function getIniWrapper() { |
|
| 1554 | - return $this->query('IniWrapper'); |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - /** |
|
| 1558 | - * @return \OCP\Command\IBus |
|
| 1559 | - */ |
|
| 1560 | - public function getCommandBus() { |
|
| 1561 | - return $this->query('AsyncCommandBus'); |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - /** |
|
| 1565 | - * Get the trusted domain helper |
|
| 1566 | - * |
|
| 1567 | - * @return TrustedDomainHelper |
|
| 1568 | - */ |
|
| 1569 | - public function getTrustedDomainHelper() { |
|
| 1570 | - return $this->query('TrustedDomainHelper'); |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - /** |
|
| 1574 | - * Get the locking provider |
|
| 1575 | - * |
|
| 1576 | - * @return \OCP\Lock\ILockingProvider |
|
| 1577 | - * @since 8.1.0 |
|
| 1578 | - */ |
|
| 1579 | - public function getLockingProvider() { |
|
| 1580 | - return $this->query('LockingProvider'); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - /** |
|
| 1584 | - * @return \OCP\Files\Mount\IMountManager |
|
| 1585 | - **/ |
|
| 1586 | - function getMountManager() { |
|
| 1587 | - return $this->query('MountManager'); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1591 | - function getUserMountCache() { |
|
| 1592 | - return $this->query('UserMountCache'); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * Get the MimeTypeDetector |
|
| 1597 | - * |
|
| 1598 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 1599 | - */ |
|
| 1600 | - public function getMimeTypeDetector() { |
|
| 1601 | - return $this->query('MimeTypeDetector'); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * Get the MimeTypeLoader |
|
| 1606 | - * |
|
| 1607 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 1608 | - */ |
|
| 1609 | - public function getMimeTypeLoader() { |
|
| 1610 | - return $this->query('MimeTypeLoader'); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - /** |
|
| 1614 | - * Get the manager of all the capabilities |
|
| 1615 | - * |
|
| 1616 | - * @return \OC\CapabilitiesManager |
|
| 1617 | - */ |
|
| 1618 | - public function getCapabilitiesManager() { |
|
| 1619 | - return $this->query('CapabilitiesManager'); |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * Get the EventDispatcher |
|
| 1624 | - * |
|
| 1625 | - * @return EventDispatcherInterface |
|
| 1626 | - * @since 8.2.0 |
|
| 1627 | - */ |
|
| 1628 | - public function getEventDispatcher() { |
|
| 1629 | - return $this->query('EventDispatcher'); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - /** |
|
| 1633 | - * Get the Notification Manager |
|
| 1634 | - * |
|
| 1635 | - * @return \OCP\Notification\IManager |
|
| 1636 | - * @since 8.2.0 |
|
| 1637 | - */ |
|
| 1638 | - public function getNotificationManager() { |
|
| 1639 | - return $this->query('NotificationManager'); |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - /** |
|
| 1643 | - * @return \OCP\Comments\ICommentsManager |
|
| 1644 | - */ |
|
| 1645 | - public function getCommentsManager() { |
|
| 1646 | - return $this->query('CommentsManager'); |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - /** |
|
| 1650 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1651 | - */ |
|
| 1652 | - public function getThemingDefaults() { |
|
| 1653 | - return $this->query('ThemingDefaults'); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - /** |
|
| 1657 | - * @return \OC\IntegrityCheck\Checker |
|
| 1658 | - */ |
|
| 1659 | - public function getIntegrityCodeChecker() { |
|
| 1660 | - return $this->query('IntegrityCodeChecker'); |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - /** |
|
| 1664 | - * @return \OC\Session\CryptoWrapper |
|
| 1665 | - */ |
|
| 1666 | - public function getSessionCryptoWrapper() { |
|
| 1667 | - return $this->query('CryptoWrapper'); |
|
| 1668 | - } |
|
| 1669 | - |
|
| 1670 | - /** |
|
| 1671 | - * @return CsrfTokenManager |
|
| 1672 | - */ |
|
| 1673 | - public function getCsrfTokenManager() { |
|
| 1674 | - return $this->query('CsrfTokenManager'); |
|
| 1675 | - } |
|
| 1676 | - |
|
| 1677 | - /** |
|
| 1678 | - * @return Throttler |
|
| 1679 | - */ |
|
| 1680 | - public function getBruteForceThrottler() { |
|
| 1681 | - return $this->query('Throttler'); |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - /** |
|
| 1685 | - * @return IContentSecurityPolicyManager |
|
| 1686 | - */ |
|
| 1687 | - public function getContentSecurityPolicyManager() { |
|
| 1688 | - return $this->query('ContentSecurityPolicyManager'); |
|
| 1689 | - } |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * @return ContentSecurityPolicyNonceManager |
|
| 1693 | - */ |
|
| 1694 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1695 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - /** |
|
| 1699 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1700 | - * |
|
| 1701 | - * @return \OCA\Files_External\Service\BackendService |
|
| 1702 | - */ |
|
| 1703 | - public function getStoragesBackendService() { |
|
| 1704 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - /** |
|
| 1708 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1709 | - * |
|
| 1710 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1711 | - */ |
|
| 1712 | - public function getGlobalStoragesService() { |
|
| 1713 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - /** |
|
| 1717 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1718 | - * |
|
| 1719 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1720 | - */ |
|
| 1721 | - public function getUserGlobalStoragesService() { |
|
| 1722 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - /** |
|
| 1726 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1727 | - * |
|
| 1728 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1729 | - */ |
|
| 1730 | - public function getUserStoragesService() { |
|
| 1731 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1732 | - } |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * @return \OCP\Share\IManager |
|
| 1736 | - */ |
|
| 1737 | - public function getShareManager() { |
|
| 1738 | - return $this->query('ShareManager'); |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - /** |
|
| 1742 | - * Returns the LDAP Provider |
|
| 1743 | - * |
|
| 1744 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 1745 | - */ |
|
| 1746 | - public function getLDAPProvider() { |
|
| 1747 | - return $this->query('LDAPProvider'); |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - /** |
|
| 1751 | - * @return \OCP\Settings\IManager |
|
| 1752 | - */ |
|
| 1753 | - public function getSettingsManager() { |
|
| 1754 | - return $this->query('SettingsManager'); |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - /** |
|
| 1758 | - * @return \OCP\Files\IAppData |
|
| 1759 | - */ |
|
| 1760 | - public function getAppDataDir($app) { |
|
| 1761 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1762 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1763 | - return $factory->get($app); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - /** |
|
| 1767 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 1768 | - */ |
|
| 1769 | - public function getLockdownManager() { |
|
| 1770 | - return $this->query('LockdownManager'); |
|
| 1771 | - } |
|
| 1772 | - |
|
| 1773 | - /** |
|
| 1774 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1775 | - */ |
|
| 1776 | - public function getCloudIdManager() { |
|
| 1777 | - return $this->query(ICloudIdManager::class); |
|
| 1778 | - } |
|
| 858 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 859 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 860 | + $classExists = true; |
|
| 861 | + } else { |
|
| 862 | + $classExists = false; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
| 866 | + return new ThemingDefaults( |
|
| 867 | + $c->getConfig(), |
|
| 868 | + $c->getL10N('theming'), |
|
| 869 | + $c->getURLGenerator(), |
|
| 870 | + $c->getAppDataDir('theming'), |
|
| 871 | + $c->getMemCacheFactory(), |
|
| 872 | + new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager()) |
|
| 873 | + ); |
|
| 874 | + } |
|
| 875 | + return new \OC_Defaults(); |
|
| 876 | + }); |
|
| 877 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 878 | + /** @var Factory $cacheFactory */ |
|
| 879 | + $cacheFactory = $c->query(Factory::class); |
|
| 880 | + return new SCSSCacher( |
|
| 881 | + $c->getLogger(), |
|
| 882 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 883 | + $c->getURLGenerator(), |
|
| 884 | + $c->getConfig(), |
|
| 885 | + $c->getThemingDefaults(), |
|
| 886 | + \OC::$SERVERROOT, |
|
| 887 | + $cacheFactory->create('SCSS') |
|
| 888 | + ); |
|
| 889 | + }); |
|
| 890 | + $this->registerService(EventDispatcher::class, function () { |
|
| 891 | + return new EventDispatcher(); |
|
| 892 | + }); |
|
| 893 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 894 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 895 | + |
|
| 896 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 897 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 898 | + $request = new Request( |
|
| 899 | + [ |
|
| 900 | + 'get' => $_GET, |
|
| 901 | + 'post' => $_POST, |
|
| 902 | + 'files' => $_FILES, |
|
| 903 | + 'server' => $_SERVER, |
|
| 904 | + 'env' => $_ENV, |
|
| 905 | + 'cookies' => $_COOKIE, |
|
| 906 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 907 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 908 | + : null, |
|
| 909 | + ], |
|
| 910 | + $c->getSecureRandom(), |
|
| 911 | + $c->getConfig() |
|
| 912 | + ); |
|
| 913 | + |
|
| 914 | + return new CryptoWrapper( |
|
| 915 | + $c->getConfig(), |
|
| 916 | + $c->getCrypto(), |
|
| 917 | + $c->getSecureRandom(), |
|
| 918 | + $request |
|
| 919 | + ); |
|
| 920 | + }); |
|
| 921 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 922 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 923 | + |
|
| 924 | + return new CsrfTokenManager( |
|
| 925 | + $tokenGenerator, |
|
| 926 | + $c->query(SessionStorage::class) |
|
| 927 | + ); |
|
| 928 | + }); |
|
| 929 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 930 | + return new SessionStorage($c->getSession()); |
|
| 931 | + }); |
|
| 932 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 933 | + return new ContentSecurityPolicyManager(); |
|
| 934 | + }); |
|
| 935 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 936 | + |
|
| 937 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 938 | + return new ContentSecurityPolicyNonceManager( |
|
| 939 | + $c->getCsrfTokenManager(), |
|
| 940 | + $c->getRequest() |
|
| 941 | + ); |
|
| 942 | + }); |
|
| 943 | + |
|
| 944 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 945 | + $config = $c->getConfig(); |
|
| 946 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
| 947 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 948 | + $factory = new $factoryClass($this); |
|
| 949 | + |
|
| 950 | + $manager = new \OC\Share20\Manager( |
|
| 951 | + $c->getLogger(), |
|
| 952 | + $c->getConfig(), |
|
| 953 | + $c->getSecureRandom(), |
|
| 954 | + $c->getHasher(), |
|
| 955 | + $c->getMountManager(), |
|
| 956 | + $c->getGroupManager(), |
|
| 957 | + $c->getL10N('core'), |
|
| 958 | + $factory, |
|
| 959 | + $c->getUserManager(), |
|
| 960 | + $c->getLazyRootFolder(), |
|
| 961 | + $c->getEventDispatcher() |
|
| 962 | + ); |
|
| 963 | + |
|
| 964 | + return $manager; |
|
| 965 | + }); |
|
| 966 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 967 | + |
|
| 968 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 969 | + $manager = new \OC\Settings\Manager( |
|
| 970 | + $c->getLogger(), |
|
| 971 | + $c->getDatabaseConnection(), |
|
| 972 | + $c->getL10N('lib'), |
|
| 973 | + $c->getConfig(), |
|
| 974 | + $c->getEncryptionManager(), |
|
| 975 | + $c->getUserManager(), |
|
| 976 | + $c->getLockingProvider(), |
|
| 977 | + $c->getRequest(), |
|
| 978 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
| 979 | + $c->getURLGenerator() |
|
| 980 | + ); |
|
| 981 | + return $manager; |
|
| 982 | + }); |
|
| 983 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 984 | + return new \OC\Files\AppData\Factory( |
|
| 985 | + $c->getRootFolder(), |
|
| 986 | + $c->getSystemConfig() |
|
| 987 | + ); |
|
| 988 | + }); |
|
| 989 | + |
|
| 990 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 991 | + return new LockdownManager(function() use ($c) { |
|
| 992 | + return $c->getSession(); |
|
| 993 | + }); |
|
| 994 | + }); |
|
| 995 | + |
|
| 996 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 997 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 998 | + }); |
|
| 999 | + |
|
| 1000 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1001 | + return new CloudIdManager(); |
|
| 1002 | + }); |
|
| 1003 | + |
|
| 1004 | + /* To trick DI since we don't extend the DIContainer here */ |
|
| 1005 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1006 | + return new CleanPreviewsBackgroundJob( |
|
| 1007 | + $c->getRootFolder(), |
|
| 1008 | + $c->getLogger(), |
|
| 1009 | + $c->getJobList(), |
|
| 1010 | + new TimeFactory() |
|
| 1011 | + ); |
|
| 1012 | + }); |
|
| 1013 | + |
|
| 1014 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1015 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1016 | + |
|
| 1017 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1018 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1019 | + |
|
| 1020 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1021 | + return new Defaults( |
|
| 1022 | + $c->getThemingDefaults() |
|
| 1023 | + ); |
|
| 1024 | + }); |
|
| 1025 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1026 | + |
|
| 1027 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1028 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1029 | + }); |
|
| 1030 | + |
|
| 1031 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1032 | + return new ShareHelper( |
|
| 1033 | + $c->query(\OCP\Share\IManager::class) |
|
| 1034 | + ); |
|
| 1035 | + }); |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * @return \OCP\Contacts\IManager |
|
| 1040 | + */ |
|
| 1041 | + public function getContactsManager() { |
|
| 1042 | + return $this->query('ContactsManager'); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * @return \OC\Encryption\Manager |
|
| 1047 | + */ |
|
| 1048 | + public function getEncryptionManager() { |
|
| 1049 | + return $this->query('EncryptionManager'); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + /** |
|
| 1053 | + * @return \OC\Encryption\File |
|
| 1054 | + */ |
|
| 1055 | + public function getEncryptionFilesHelper() { |
|
| 1056 | + return $this->query('EncryptionFileHelper'); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + /** |
|
| 1060 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1061 | + */ |
|
| 1062 | + public function getEncryptionKeyStorage() { |
|
| 1063 | + return $this->query('EncryptionKeyStorage'); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * The current request object holding all information about the request |
|
| 1068 | + * currently being processed is returned from this method. |
|
| 1069 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1070 | + * |
|
| 1071 | + * @return \OCP\IRequest |
|
| 1072 | + */ |
|
| 1073 | + public function getRequest() { |
|
| 1074 | + return $this->query('Request'); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * Returns the preview manager which can create preview images for a given file |
|
| 1079 | + * |
|
| 1080 | + * @return \OCP\IPreview |
|
| 1081 | + */ |
|
| 1082 | + public function getPreviewManager() { |
|
| 1083 | + return $this->query('PreviewManager'); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1088 | + * |
|
| 1089 | + * @see \OCP\ITagManager::load() |
|
| 1090 | + * @return \OCP\ITagManager |
|
| 1091 | + */ |
|
| 1092 | + public function getTagManager() { |
|
| 1093 | + return $this->query('TagManager'); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * Returns the system-tag manager |
|
| 1098 | + * |
|
| 1099 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 1100 | + * |
|
| 1101 | + * @since 9.0.0 |
|
| 1102 | + */ |
|
| 1103 | + public function getSystemTagManager() { |
|
| 1104 | + return $this->query('SystemTagManager'); |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * Returns the system-tag object mapper |
|
| 1109 | + * |
|
| 1110 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1111 | + * |
|
| 1112 | + * @since 9.0.0 |
|
| 1113 | + */ |
|
| 1114 | + public function getSystemTagObjectMapper() { |
|
| 1115 | + return $this->query('SystemTagObjectMapper'); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * Returns the avatar manager, used for avatar functionality |
|
| 1120 | + * |
|
| 1121 | + * @return \OCP\IAvatarManager |
|
| 1122 | + */ |
|
| 1123 | + public function getAvatarManager() { |
|
| 1124 | + return $this->query('AvatarManager'); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Returns the root folder of ownCloud's data directory |
|
| 1129 | + * |
|
| 1130 | + * @return \OCP\Files\IRootFolder |
|
| 1131 | + */ |
|
| 1132 | + public function getRootFolder() { |
|
| 1133 | + return $this->query('LazyRootFolder'); |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Returns the root folder of ownCloud's data directory |
|
| 1138 | + * This is the lazy variant so this gets only initialized once it |
|
| 1139 | + * is actually used. |
|
| 1140 | + * |
|
| 1141 | + * @return \OCP\Files\IRootFolder |
|
| 1142 | + */ |
|
| 1143 | + public function getLazyRootFolder() { |
|
| 1144 | + return $this->query('LazyRootFolder'); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + /** |
|
| 1148 | + * Returns a view to ownCloud's files folder |
|
| 1149 | + * |
|
| 1150 | + * @param string $userId user ID |
|
| 1151 | + * @return \OCP\Files\Folder|null |
|
| 1152 | + */ |
|
| 1153 | + public function getUserFolder($userId = null) { |
|
| 1154 | + if ($userId === null) { |
|
| 1155 | + $user = $this->getUserSession()->getUser(); |
|
| 1156 | + if (!$user) { |
|
| 1157 | + return null; |
|
| 1158 | + } |
|
| 1159 | + $userId = $user->getUID(); |
|
| 1160 | + } |
|
| 1161 | + $root = $this->getRootFolder(); |
|
| 1162 | + return $root->getUserFolder($userId); |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + /** |
|
| 1166 | + * Returns an app-specific view in ownClouds data directory |
|
| 1167 | + * |
|
| 1168 | + * @return \OCP\Files\Folder |
|
| 1169 | + * @deprecated since 9.2.0 use IAppData |
|
| 1170 | + */ |
|
| 1171 | + public function getAppFolder() { |
|
| 1172 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1173 | + $root = $this->getRootFolder(); |
|
| 1174 | + if (!$root->nodeExists($dir)) { |
|
| 1175 | + $folder = $root->newFolder($dir); |
|
| 1176 | + } else { |
|
| 1177 | + $folder = $root->get($dir); |
|
| 1178 | + } |
|
| 1179 | + return $folder; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + /** |
|
| 1183 | + * @return \OC\User\Manager |
|
| 1184 | + */ |
|
| 1185 | + public function getUserManager() { |
|
| 1186 | + return $this->query('UserManager'); |
|
| 1187 | + } |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * @return \OC\Group\Manager |
|
| 1191 | + */ |
|
| 1192 | + public function getGroupManager() { |
|
| 1193 | + return $this->query('GroupManager'); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * @return \OC\User\Session |
|
| 1198 | + */ |
|
| 1199 | + public function getUserSession() { |
|
| 1200 | + return $this->query('UserSession'); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * @return \OCP\ISession |
|
| 1205 | + */ |
|
| 1206 | + public function getSession() { |
|
| 1207 | + return $this->query('UserSession')->getSession(); |
|
| 1208 | + } |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * @param \OCP\ISession $session |
|
| 1212 | + */ |
|
| 1213 | + public function setSession(\OCP\ISession $session) { |
|
| 1214 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1215 | + $this->query('UserSession')->setSession($session); |
|
| 1216 | + $this->query(Store::class)->setSession($session); |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + /** |
|
| 1220 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1221 | + */ |
|
| 1222 | + public function getTwoFactorAuthManager() { |
|
| 1223 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * @return \OC\NavigationManager |
|
| 1228 | + */ |
|
| 1229 | + public function getNavigationManager() { |
|
| 1230 | + return $this->query('NavigationManager'); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + /** |
|
| 1234 | + * @return \OCP\IConfig |
|
| 1235 | + */ |
|
| 1236 | + public function getConfig() { |
|
| 1237 | + return $this->query('AllConfig'); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * @internal For internal use only |
|
| 1242 | + * @return \OC\SystemConfig |
|
| 1243 | + */ |
|
| 1244 | + public function getSystemConfig() { |
|
| 1245 | + return $this->query('SystemConfig'); |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + /** |
|
| 1249 | + * Returns the app config manager |
|
| 1250 | + * |
|
| 1251 | + * @return \OCP\IAppConfig |
|
| 1252 | + */ |
|
| 1253 | + public function getAppConfig() { |
|
| 1254 | + return $this->query('AppConfig'); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * @return \OCP\L10N\IFactory |
|
| 1259 | + */ |
|
| 1260 | + public function getL10NFactory() { |
|
| 1261 | + return $this->query('L10NFactory'); |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * get an L10N instance |
|
| 1266 | + * |
|
| 1267 | + * @param string $app appid |
|
| 1268 | + * @param string $lang |
|
| 1269 | + * @return IL10N |
|
| 1270 | + */ |
|
| 1271 | + public function getL10N($app, $lang = null) { |
|
| 1272 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + /** |
|
| 1276 | + * @return \OCP\IURLGenerator |
|
| 1277 | + */ |
|
| 1278 | + public function getURLGenerator() { |
|
| 1279 | + return $this->query('URLGenerator'); |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * @return \OCP\IHelper |
|
| 1284 | + */ |
|
| 1285 | + public function getHelper() { |
|
| 1286 | + return $this->query('AppHelper'); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * @return AppFetcher |
|
| 1291 | + */ |
|
| 1292 | + public function getAppFetcher() { |
|
| 1293 | + return $this->query('AppFetcher'); |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1298 | + * getMemCacheFactory() instead. |
|
| 1299 | + * |
|
| 1300 | + * @return \OCP\ICache |
|
| 1301 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1302 | + */ |
|
| 1303 | + public function getCache() { |
|
| 1304 | + return $this->query('UserCache'); |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * Returns an \OCP\CacheFactory instance |
|
| 1309 | + * |
|
| 1310 | + * @return \OCP\ICacheFactory |
|
| 1311 | + */ |
|
| 1312 | + public function getMemCacheFactory() { |
|
| 1313 | + return $this->query('MemCacheFactory'); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Returns an \OC\RedisFactory instance |
|
| 1318 | + * |
|
| 1319 | + * @return \OC\RedisFactory |
|
| 1320 | + */ |
|
| 1321 | + public function getGetRedisFactory() { |
|
| 1322 | + return $this->query('RedisFactory'); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + /** |
|
| 1327 | + * Returns the current session |
|
| 1328 | + * |
|
| 1329 | + * @return \OCP\IDBConnection |
|
| 1330 | + */ |
|
| 1331 | + public function getDatabaseConnection() { |
|
| 1332 | + return $this->query('DatabaseConnection'); |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * Returns the activity manager |
|
| 1337 | + * |
|
| 1338 | + * @return \OCP\Activity\IManager |
|
| 1339 | + */ |
|
| 1340 | + public function getActivityManager() { |
|
| 1341 | + return $this->query('ActivityManager'); |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + /** |
|
| 1345 | + * Returns an job list for controlling background jobs |
|
| 1346 | + * |
|
| 1347 | + * @return \OCP\BackgroundJob\IJobList |
|
| 1348 | + */ |
|
| 1349 | + public function getJobList() { |
|
| 1350 | + return $this->query('JobList'); |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Returns a logger instance |
|
| 1355 | + * |
|
| 1356 | + * @return \OCP\ILogger |
|
| 1357 | + */ |
|
| 1358 | + public function getLogger() { |
|
| 1359 | + return $this->query('Logger'); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Returns a router for generating and matching urls |
|
| 1364 | + * |
|
| 1365 | + * @return \OCP\Route\IRouter |
|
| 1366 | + */ |
|
| 1367 | + public function getRouter() { |
|
| 1368 | + return $this->query('Router'); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + /** |
|
| 1372 | + * Returns a search instance |
|
| 1373 | + * |
|
| 1374 | + * @return \OCP\ISearch |
|
| 1375 | + */ |
|
| 1376 | + public function getSearch() { |
|
| 1377 | + return $this->query('Search'); |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * Returns a SecureRandom instance |
|
| 1382 | + * |
|
| 1383 | + * @return \OCP\Security\ISecureRandom |
|
| 1384 | + */ |
|
| 1385 | + public function getSecureRandom() { |
|
| 1386 | + return $this->query('SecureRandom'); |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + /** |
|
| 1390 | + * Returns a Crypto instance |
|
| 1391 | + * |
|
| 1392 | + * @return \OCP\Security\ICrypto |
|
| 1393 | + */ |
|
| 1394 | + public function getCrypto() { |
|
| 1395 | + return $this->query('Crypto'); |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + /** |
|
| 1399 | + * Returns a Hasher instance |
|
| 1400 | + * |
|
| 1401 | + * @return \OCP\Security\IHasher |
|
| 1402 | + */ |
|
| 1403 | + public function getHasher() { |
|
| 1404 | + return $this->query('Hasher'); |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + /** |
|
| 1408 | + * Returns a CredentialsManager instance |
|
| 1409 | + * |
|
| 1410 | + * @return \OCP\Security\ICredentialsManager |
|
| 1411 | + */ |
|
| 1412 | + public function getCredentialsManager() { |
|
| 1413 | + return $this->query('CredentialsManager'); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * Returns an instance of the HTTP helper class |
|
| 1418 | + * |
|
| 1419 | + * @deprecated Use getHTTPClientService() |
|
| 1420 | + * @return \OC\HTTPHelper |
|
| 1421 | + */ |
|
| 1422 | + public function getHTTPHelper() { |
|
| 1423 | + return $this->query('HTTPHelper'); |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * Get the certificate manager for the user |
|
| 1428 | + * |
|
| 1429 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1430 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1431 | + */ |
|
| 1432 | + public function getCertificateManager($userId = '') { |
|
| 1433 | + if ($userId === '') { |
|
| 1434 | + $userSession = $this->getUserSession(); |
|
| 1435 | + $user = $userSession->getUser(); |
|
| 1436 | + if (is_null($user)) { |
|
| 1437 | + return null; |
|
| 1438 | + } |
|
| 1439 | + $userId = $user->getUID(); |
|
| 1440 | + } |
|
| 1441 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * Returns an instance of the HTTP client service |
|
| 1446 | + * |
|
| 1447 | + * @return \OCP\Http\Client\IClientService |
|
| 1448 | + */ |
|
| 1449 | + public function getHTTPClientService() { |
|
| 1450 | + return $this->query('HttpClientService'); |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Create a new event source |
|
| 1455 | + * |
|
| 1456 | + * @return \OCP\IEventSource |
|
| 1457 | + */ |
|
| 1458 | + public function createEventSource() { |
|
| 1459 | + return new \OC_EventSource(); |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * Get the active event logger |
|
| 1464 | + * |
|
| 1465 | + * The returned logger only logs data when debug mode is enabled |
|
| 1466 | + * |
|
| 1467 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 1468 | + */ |
|
| 1469 | + public function getEventLogger() { |
|
| 1470 | + return $this->query('EventLogger'); |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * Get the active query logger |
|
| 1475 | + * |
|
| 1476 | + * The returned logger only logs data when debug mode is enabled |
|
| 1477 | + * |
|
| 1478 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 1479 | + */ |
|
| 1480 | + public function getQueryLogger() { |
|
| 1481 | + return $this->query('QueryLogger'); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * Get the manager for temporary files and folders |
|
| 1486 | + * |
|
| 1487 | + * @return \OCP\ITempManager |
|
| 1488 | + */ |
|
| 1489 | + public function getTempManager() { |
|
| 1490 | + return $this->query('TempManager'); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Get the app manager |
|
| 1495 | + * |
|
| 1496 | + * @return \OCP\App\IAppManager |
|
| 1497 | + */ |
|
| 1498 | + public function getAppManager() { |
|
| 1499 | + return $this->query('AppManager'); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + /** |
|
| 1503 | + * Creates a new mailer |
|
| 1504 | + * |
|
| 1505 | + * @return \OCP\Mail\IMailer |
|
| 1506 | + */ |
|
| 1507 | + public function getMailer() { |
|
| 1508 | + return $this->query('Mailer'); |
|
| 1509 | + } |
|
| 1510 | + |
|
| 1511 | + /** |
|
| 1512 | + * Get the webroot |
|
| 1513 | + * |
|
| 1514 | + * @return string |
|
| 1515 | + */ |
|
| 1516 | + public function getWebRoot() { |
|
| 1517 | + return $this->webRoot; |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + /** |
|
| 1521 | + * @return \OC\OCSClient |
|
| 1522 | + */ |
|
| 1523 | + public function getOcsClient() { |
|
| 1524 | + return $this->query('OcsClient'); |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * @return \OCP\IDateTimeZone |
|
| 1529 | + */ |
|
| 1530 | + public function getDateTimeZone() { |
|
| 1531 | + return $this->query('DateTimeZone'); |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * @return \OCP\IDateTimeFormatter |
|
| 1536 | + */ |
|
| 1537 | + public function getDateTimeFormatter() { |
|
| 1538 | + return $this->query('DateTimeFormatter'); |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1543 | + */ |
|
| 1544 | + public function getMountProviderCollection() { |
|
| 1545 | + return $this->query('MountConfigManager'); |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + /** |
|
| 1549 | + * Get the IniWrapper |
|
| 1550 | + * |
|
| 1551 | + * @return IniGetWrapper |
|
| 1552 | + */ |
|
| 1553 | + public function getIniWrapper() { |
|
| 1554 | + return $this->query('IniWrapper'); |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + /** |
|
| 1558 | + * @return \OCP\Command\IBus |
|
| 1559 | + */ |
|
| 1560 | + public function getCommandBus() { |
|
| 1561 | + return $this->query('AsyncCommandBus'); |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + /** |
|
| 1565 | + * Get the trusted domain helper |
|
| 1566 | + * |
|
| 1567 | + * @return TrustedDomainHelper |
|
| 1568 | + */ |
|
| 1569 | + public function getTrustedDomainHelper() { |
|
| 1570 | + return $this->query('TrustedDomainHelper'); |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + /** |
|
| 1574 | + * Get the locking provider |
|
| 1575 | + * |
|
| 1576 | + * @return \OCP\Lock\ILockingProvider |
|
| 1577 | + * @since 8.1.0 |
|
| 1578 | + */ |
|
| 1579 | + public function getLockingProvider() { |
|
| 1580 | + return $this->query('LockingProvider'); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + /** |
|
| 1584 | + * @return \OCP\Files\Mount\IMountManager |
|
| 1585 | + **/ |
|
| 1586 | + function getMountManager() { |
|
| 1587 | + return $this->query('MountManager'); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1591 | + function getUserMountCache() { |
|
| 1592 | + return $this->query('UserMountCache'); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * Get the MimeTypeDetector |
|
| 1597 | + * |
|
| 1598 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 1599 | + */ |
|
| 1600 | + public function getMimeTypeDetector() { |
|
| 1601 | + return $this->query('MimeTypeDetector'); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * Get the MimeTypeLoader |
|
| 1606 | + * |
|
| 1607 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 1608 | + */ |
|
| 1609 | + public function getMimeTypeLoader() { |
|
| 1610 | + return $this->query('MimeTypeLoader'); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + /** |
|
| 1614 | + * Get the manager of all the capabilities |
|
| 1615 | + * |
|
| 1616 | + * @return \OC\CapabilitiesManager |
|
| 1617 | + */ |
|
| 1618 | + public function getCapabilitiesManager() { |
|
| 1619 | + return $this->query('CapabilitiesManager'); |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * Get the EventDispatcher |
|
| 1624 | + * |
|
| 1625 | + * @return EventDispatcherInterface |
|
| 1626 | + * @since 8.2.0 |
|
| 1627 | + */ |
|
| 1628 | + public function getEventDispatcher() { |
|
| 1629 | + return $this->query('EventDispatcher'); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + /** |
|
| 1633 | + * Get the Notification Manager |
|
| 1634 | + * |
|
| 1635 | + * @return \OCP\Notification\IManager |
|
| 1636 | + * @since 8.2.0 |
|
| 1637 | + */ |
|
| 1638 | + public function getNotificationManager() { |
|
| 1639 | + return $this->query('NotificationManager'); |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + /** |
|
| 1643 | + * @return \OCP\Comments\ICommentsManager |
|
| 1644 | + */ |
|
| 1645 | + public function getCommentsManager() { |
|
| 1646 | + return $this->query('CommentsManager'); |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + /** |
|
| 1650 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1651 | + */ |
|
| 1652 | + public function getThemingDefaults() { |
|
| 1653 | + return $this->query('ThemingDefaults'); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + /** |
|
| 1657 | + * @return \OC\IntegrityCheck\Checker |
|
| 1658 | + */ |
|
| 1659 | + public function getIntegrityCodeChecker() { |
|
| 1660 | + return $this->query('IntegrityCodeChecker'); |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + /** |
|
| 1664 | + * @return \OC\Session\CryptoWrapper |
|
| 1665 | + */ |
|
| 1666 | + public function getSessionCryptoWrapper() { |
|
| 1667 | + return $this->query('CryptoWrapper'); |
|
| 1668 | + } |
|
| 1669 | + |
|
| 1670 | + /** |
|
| 1671 | + * @return CsrfTokenManager |
|
| 1672 | + */ |
|
| 1673 | + public function getCsrfTokenManager() { |
|
| 1674 | + return $this->query('CsrfTokenManager'); |
|
| 1675 | + } |
|
| 1676 | + |
|
| 1677 | + /** |
|
| 1678 | + * @return Throttler |
|
| 1679 | + */ |
|
| 1680 | + public function getBruteForceThrottler() { |
|
| 1681 | + return $this->query('Throttler'); |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + /** |
|
| 1685 | + * @return IContentSecurityPolicyManager |
|
| 1686 | + */ |
|
| 1687 | + public function getContentSecurityPolicyManager() { |
|
| 1688 | + return $this->query('ContentSecurityPolicyManager'); |
|
| 1689 | + } |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * @return ContentSecurityPolicyNonceManager |
|
| 1693 | + */ |
|
| 1694 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1695 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + /** |
|
| 1699 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1700 | + * |
|
| 1701 | + * @return \OCA\Files_External\Service\BackendService |
|
| 1702 | + */ |
|
| 1703 | + public function getStoragesBackendService() { |
|
| 1704 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + /** |
|
| 1708 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1709 | + * |
|
| 1710 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1711 | + */ |
|
| 1712 | + public function getGlobalStoragesService() { |
|
| 1713 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + /** |
|
| 1717 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1718 | + * |
|
| 1719 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1720 | + */ |
|
| 1721 | + public function getUserGlobalStoragesService() { |
|
| 1722 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + /** |
|
| 1726 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1727 | + * |
|
| 1728 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1729 | + */ |
|
| 1730 | + public function getUserStoragesService() { |
|
| 1731 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1732 | + } |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * @return \OCP\Share\IManager |
|
| 1736 | + */ |
|
| 1737 | + public function getShareManager() { |
|
| 1738 | + return $this->query('ShareManager'); |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + /** |
|
| 1742 | + * Returns the LDAP Provider |
|
| 1743 | + * |
|
| 1744 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 1745 | + */ |
|
| 1746 | + public function getLDAPProvider() { |
|
| 1747 | + return $this->query('LDAPProvider'); |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + /** |
|
| 1751 | + * @return \OCP\Settings\IManager |
|
| 1752 | + */ |
|
| 1753 | + public function getSettingsManager() { |
|
| 1754 | + return $this->query('SettingsManager'); |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + /** |
|
| 1758 | + * @return \OCP\Files\IAppData |
|
| 1759 | + */ |
|
| 1760 | + public function getAppDataDir($app) { |
|
| 1761 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1762 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1763 | + return $factory->get($app); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + /** |
|
| 1767 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 1768 | + */ |
|
| 1769 | + public function getLockdownManager() { |
|
| 1770 | + return $this->query('LockdownManager'); |
|
| 1771 | + } |
|
| 1772 | + |
|
| 1773 | + /** |
|
| 1774 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1775 | + */ |
|
| 1776 | + public function getCloudIdManager() { |
|
| 1777 | + return $this->query(ICloudIdManager::class); |
|
| 1778 | + } |
|
| 1779 | 1779 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | |
| 150 | 150 | |
| 151 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 151 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
| 152 | 152 | return new PreviewManager( |
| 153 | 153 | $c->getConfig(), |
| 154 | 154 | $c->getRootFolder(), |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | }); |
| 160 | 160 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
| 161 | 161 | |
| 162 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 162 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 163 | 163 | return new \OC\Preview\Watcher( |
| 164 | 164 | $c->getAppDataDir('preview') |
| 165 | 165 | ); |
| 166 | 166 | }); |
| 167 | 167 | |
| 168 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 168 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
| 169 | 169 | $view = new View(); |
| 170 | 170 | $util = new Encryption\Util( |
| 171 | 171 | $view, |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | ); |
| 184 | 184 | }); |
| 185 | 185 | |
| 186 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 186 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 187 | 187 | $util = new Encryption\Util( |
| 188 | 188 | new View(), |
| 189 | 189 | $c->getUserManager(), |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | ); |
| 198 | 198 | }); |
| 199 | 199 | |
| 200 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 200 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 201 | 201 | $view = new View(); |
| 202 | 202 | $util = new Encryption\Util( |
| 203 | 203 | $view, |
@@ -208,32 +208,32 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | return new Encryption\Keys\Storage($view, $util); |
| 210 | 210 | }); |
| 211 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 211 | + $this->registerService('TagMapper', function(Server $c) { |
|
| 212 | 212 | return new TagMapper($c->getDatabaseConnection()); |
| 213 | 213 | }); |
| 214 | 214 | |
| 215 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 215 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
| 216 | 216 | $tagMapper = $c->query('TagMapper'); |
| 217 | 217 | return new TagManager($tagMapper, $c->getUserSession()); |
| 218 | 218 | }); |
| 219 | 219 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
| 220 | 220 | |
| 221 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 221 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 222 | 222 | $config = $c->getConfig(); |
| 223 | 223 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
| 224 | 224 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
| 225 | 225 | $factory = new $factoryClass($this); |
| 226 | 226 | return $factory; |
| 227 | 227 | }); |
| 228 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 228 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
| 229 | 229 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 230 | 230 | }); |
| 231 | 231 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
| 232 | 232 | |
| 233 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 233 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
| 234 | 234 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 235 | 235 | }); |
| 236 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 236 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 237 | 237 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 238 | 238 | $view = new View(); |
| 239 | 239 | $root = new Root( |
@@ -261,30 +261,30 @@ discard block |
||
| 261 | 261 | }); |
| 262 | 262 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
| 263 | 263 | |
| 264 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
| 264 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
| 265 | 265 | $config = $c->getConfig(); |
| 266 | 266 | return new \OC\User\Manager($config); |
| 267 | 267 | }); |
| 268 | 268 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
| 269 | 269 | |
| 270 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 270 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 271 | 271 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
| 272 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 272 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 273 | 273 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
| 274 | 274 | }); |
| 275 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 275 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
| 276 | 276 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
| 277 | 277 | }); |
| 278 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 278 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 279 | 279 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
| 280 | 280 | }); |
| 281 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 281 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 282 | 282 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
| 283 | 283 | }); |
| 284 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 284 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 285 | 285 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 286 | 286 | }); |
| 287 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 287 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 288 | 288 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 289 | 289 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 290 | 290 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | return new Store($session, $logger, $tokenProvider); |
| 305 | 305 | }); |
| 306 | 306 | $this->registerAlias(IStore::class, Store::class); |
| 307 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
| 307 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
| 308 | 308 | $dbConnection = $c->getDatabaseConnection(); |
| 309 | 309 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
| 310 | 310 | }); |
| 311 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
| 311 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
| 312 | 312 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
| 313 | 313 | $crypto = $c->getCrypto(); |
| 314 | 314 | $config = $c->getConfig(); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | }); |
| 319 | 319 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
| 320 | 320 | |
| 321 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 321 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
| 322 | 322 | $manager = $c->getUserManager(); |
| 323 | 323 | $session = new \OC\Session\Memory(''); |
| 324 | 324 | $timeFactory = new TimeFactory(); |
@@ -331,40 +331,40 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 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) { |
|
| 334 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 335 | 335 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 336 | 336 | }); |
| 337 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 337 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 338 | 338 | /** @var $user \OC\User\User */ |
| 339 | 339 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
| 340 | 340 | }); |
| 341 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
| 341 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
| 342 | 342 | /** @var $user \OC\User\User */ |
| 343 | 343 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
| 344 | 344 | }); |
| 345 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 345 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 346 | 346 | /** @var $user \OC\User\User */ |
| 347 | 347 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
| 348 | 348 | }); |
| 349 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 349 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 350 | 350 | /** @var $user \OC\User\User */ |
| 351 | 351 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 352 | 352 | }); |
| 353 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 353 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 354 | 354 | /** @var $user \OC\User\User */ |
| 355 | 355 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 356 | 356 | }); |
| 357 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 357 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 358 | 358 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 359 | 359 | }); |
| 360 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 360 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
| 361 | 361 | /** @var $user \OC\User\User */ |
| 362 | 362 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 363 | 363 | }); |
| 364 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 364 | + $userSession->listen('\OC\User', 'logout', function() { |
|
| 365 | 365 | \OC_Hook::emit('OC_User', 'logout', array()); |
| 366 | 366 | }); |
| 367 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 367 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 368 | 368 | /** @var $user \OC\User\User */ |
| 369 | 369 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
| 370 | 370 | }); |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | }); |
| 373 | 373 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
| 374 | 374 | |
| 375 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 375 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
| 376 | 376 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
| 377 | 377 | }); |
| 378 | 378 | |
| 379 | 379 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
| 380 | 380 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
| 381 | 381 | |
| 382 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 382 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
| 383 | 383 | return new \OC\AllConfig( |
| 384 | 384 | $c->getSystemConfig() |
| 385 | 385 | ); |
@@ -387,17 +387,17 @@ discard block |
||
| 387 | 387 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
| 388 | 388 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 389 | 389 | |
| 390 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 390 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
| 391 | 391 | return new \OC\SystemConfig($config); |
| 392 | 392 | }); |
| 393 | 393 | |
| 394 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 394 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
| 395 | 395 | return new \OC\AppConfig($c->getDatabaseConnection()); |
| 396 | 396 | }); |
| 397 | 397 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
| 398 | 398 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
| 399 | 399 | |
| 400 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 400 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
| 401 | 401 | return new \OC\L10N\Factory( |
| 402 | 402 | $c->getConfig(), |
| 403 | 403 | $c->getRequest(), |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | }); |
| 408 | 408 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
| 409 | 409 | |
| 410 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 410 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
| 411 | 411 | $config = $c->getConfig(); |
| 412 | 412 | $cacheFactory = $c->getMemCacheFactory(); |
| 413 | 413 | return new \OC\URLGenerator( |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | }); |
| 418 | 418 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
| 419 | 419 | |
| 420 | - $this->registerService('AppHelper', function ($c) { |
|
| 420 | + $this->registerService('AppHelper', function($c) { |
|
| 421 | 421 | return new \OC\AppHelper(); |
| 422 | 422 | }); |
| 423 | - $this->registerService(AppFetcher::class, function ($c) { |
|
| 423 | + $this->registerService(AppFetcher::class, function($c) { |
|
| 424 | 424 | return new AppFetcher( |
| 425 | 425 | $this->getAppDataDir('appstore'), |
| 426 | 426 | $this->getHTTPClientService(), |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | }); |
| 431 | 431 | $this->registerAlias('AppFetcher', AppFetcher::class); |
| 432 | 432 | |
| 433 | - $this->registerService('CategoryFetcher', function ($c) { |
|
| 433 | + $this->registerService('CategoryFetcher', function($c) { |
|
| 434 | 434 | return new CategoryFetcher( |
| 435 | 435 | $this->getAppDataDir('appstore'), |
| 436 | 436 | $this->getHTTPClientService(), |
@@ -439,21 +439,21 @@ discard block |
||
| 439 | 439 | ); |
| 440 | 440 | }); |
| 441 | 441 | |
| 442 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 442 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
| 443 | 443 | return new Cache\File(); |
| 444 | 444 | }); |
| 445 | 445 | $this->registerAlias('UserCache', \OCP\ICache::class); |
| 446 | 446 | |
| 447 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 447 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 448 | 448 | $config = $c->getConfig(); |
| 449 | 449 | |
| 450 | 450 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
| 451 | 451 | $v = \OC_App::getAppVersions(); |
| 452 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
| 452 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php')); |
|
| 453 | 453 | $version = implode(',', $v); |
| 454 | 454 | $instanceId = \OC_Util::getInstanceId(); |
| 455 | 455 | $path = \OC::$SERVERROOT; |
| 456 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
| 456 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT); |
|
| 457 | 457 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 458 | 458 | $config->getSystemValue('memcache.local', null), |
| 459 | 459 | $config->getSystemValue('memcache.distributed', null), |
@@ -470,12 +470,12 @@ discard block |
||
| 470 | 470 | $this->registerAlias('MemCacheFactory', Factory::class); |
| 471 | 471 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 472 | 472 | |
| 473 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 473 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 474 | 474 | $systemConfig = $c->getSystemConfig(); |
| 475 | 475 | return new RedisFactory($systemConfig); |
| 476 | 476 | }); |
| 477 | 477 | |
| 478 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 478 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 479 | 479 | return new \OC\Activity\Manager( |
| 480 | 480 | $c->getRequest(), |
| 481 | 481 | $c->getUserSession(), |
@@ -485,14 +485,14 @@ discard block |
||
| 485 | 485 | }); |
| 486 | 486 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 487 | 487 | |
| 488 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 488 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 489 | 489 | return new \OC\Activity\EventMerger( |
| 490 | 490 | $c->getL10N('lib') |
| 491 | 491 | ); |
| 492 | 492 | }); |
| 493 | 493 | $this->registerAlias(IValidator::class, Validator::class); |
| 494 | 494 | |
| 495 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 495 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
| 496 | 496 | return new AvatarManager( |
| 497 | 497 | $c->getUserManager(), |
| 498 | 498 | $c->getAppDataDir('avatar'), |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | }); |
| 504 | 504 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
| 505 | 505 | |
| 506 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 506 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
| 507 | 507 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
| 508 | 508 | $logger = Log::getLogClass($logType); |
| 509 | 509 | call_user_func(array($logger, 'init')); |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | }); |
| 513 | 513 | $this->registerAlias('Logger', \OCP\ILogger::class); |
| 514 | 514 | |
| 515 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 515 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
| 516 | 516 | $config = $c->getConfig(); |
| 517 | 517 | return new \OC\BackgroundJob\JobList( |
| 518 | 518 | $c->getDatabaseConnection(), |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | }); |
| 523 | 523 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
| 524 | 524 | |
| 525 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 525 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
| 526 | 526 | $cacheFactory = $c->getMemCacheFactory(); |
| 527 | 527 | $logger = $c->getLogger(); |
| 528 | 528 | if ($cacheFactory->isAvailable()) { |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | }); |
| 535 | 535 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
| 536 | 536 | |
| 537 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 537 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
| 538 | 538 | return new Search(); |
| 539 | 539 | }); |
| 540 | 540 | $this->registerAlias('Search', \OCP\ISearch::class); |
@@ -554,27 +554,27 @@ discard block |
||
| 554 | 554 | ); |
| 555 | 555 | }); |
| 556 | 556 | |
| 557 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 557 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
| 558 | 558 | return new SecureRandom(); |
| 559 | 559 | }); |
| 560 | 560 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
| 561 | 561 | |
| 562 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 562 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
| 563 | 563 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
| 564 | 564 | }); |
| 565 | 565 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
| 566 | 566 | |
| 567 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 567 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
| 568 | 568 | return new Hasher($c->getConfig()); |
| 569 | 569 | }); |
| 570 | 570 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
| 571 | 571 | |
| 572 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 572 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
| 573 | 573 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
| 574 | 574 | }); |
| 575 | 575 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
| 576 | 576 | |
| 577 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 577 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 578 | 578 | $systemConfig = $c->getSystemConfig(); |
| 579 | 579 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 580 | 580 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | }); |
| 589 | 589 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
| 590 | 590 | |
| 591 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
| 591 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
| 592 | 592 | $config = $c->getConfig(); |
| 593 | 593 | return new HTTPHelper( |
| 594 | 594 | $config, |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | ); |
| 597 | 597 | }); |
| 598 | 598 | |
| 599 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 599 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
| 600 | 600 | $user = \OC_User::getUser(); |
| 601 | 601 | $uid = $user ? $user : null; |
| 602 | 602 | return new ClientService( |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | ); |
| 606 | 606 | }); |
| 607 | 607 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
| 608 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 608 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
| 609 | 609 | $eventLogger = new EventLogger(); |
| 610 | 610 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 611 | 611 | // In debug mode, module is being activated by default |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | }); |
| 616 | 616 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
| 617 | 617 | |
| 618 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 618 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
| 619 | 619 | $queryLogger = new QueryLogger(); |
| 620 | 620 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 621 | 621 | // In debug mode, module is being activated by default |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | }); |
| 626 | 626 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
| 627 | 627 | |
| 628 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 628 | + $this->registerService(TempManager::class, function(Server $c) { |
|
| 629 | 629 | return new TempManager( |
| 630 | 630 | $c->getLogger(), |
| 631 | 631 | $c->getConfig() |
@@ -634,7 +634,7 @@ discard block |
||
| 634 | 634 | $this->registerAlias('TempManager', TempManager::class); |
| 635 | 635 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 636 | 636 | |
| 637 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 637 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 638 | 638 | return new \OC\App\AppManager( |
| 639 | 639 | $c->getUserSession(), |
| 640 | 640 | $c->getAppConfig(), |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | $this->registerAlias('AppManager', AppManager::class); |
| 647 | 647 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 648 | 648 | |
| 649 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 649 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
| 650 | 650 | return new DateTimeZone( |
| 651 | 651 | $c->getConfig(), |
| 652 | 652 | $c->getSession() |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | }); |
| 655 | 655 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
| 656 | 656 | |
| 657 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 657 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
| 658 | 658 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 659 | 659 | |
| 660 | 660 | return new DateTimeFormatter( |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | }); |
| 665 | 665 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
| 666 | 666 | |
| 667 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 667 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
| 668 | 668 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 669 | 669 | $listener = new UserMountCacheListener($mountCache); |
| 670 | 670 | $listener->listen($c->getUserManager()); |
@@ -672,10 +672,10 @@ discard block |
||
| 672 | 672 | }); |
| 673 | 673 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
| 674 | 674 | |
| 675 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 675 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
| 676 | 676 | $loader = \OC\Files\Filesystem::getLoader(); |
| 677 | 677 | $mountCache = $c->query('UserMountCache'); |
| 678 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 678 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 679 | 679 | |
| 680 | 680 | // builtin providers |
| 681 | 681 | |
@@ -688,14 +688,14 @@ discard block |
||
| 688 | 688 | }); |
| 689 | 689 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
| 690 | 690 | |
| 691 | - $this->registerService('IniWrapper', function ($c) { |
|
| 691 | + $this->registerService('IniWrapper', function($c) { |
|
| 692 | 692 | return new IniGetWrapper(); |
| 693 | 693 | }); |
| 694 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 694 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 695 | 695 | $jobList = $c->getJobList(); |
| 696 | 696 | return new AsyncBus($jobList); |
| 697 | 697 | }); |
| 698 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 698 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
| 699 | 699 | return new TrustedDomainHelper($this->getConfig()); |
| 700 | 700 | }); |
| 701 | 701 | $this->registerService('Throttler', function(Server $c) { |
@@ -706,10 +706,10 @@ discard block |
||
| 706 | 706 | $c->getConfig() |
| 707 | 707 | ); |
| 708 | 708 | }); |
| 709 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 709 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 710 | 710 | // IConfig and IAppManager requires a working database. This code |
| 711 | 711 | // might however be called when ownCloud is not yet setup. |
| 712 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 712 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 713 | 713 | $config = $c->getConfig(); |
| 714 | 714 | $appManager = $c->getAppManager(); |
| 715 | 715 | } else { |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | $c->getTempManager() |
| 728 | 728 | ); |
| 729 | 729 | }); |
| 730 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 730 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 731 | 731 | if (isset($this['urlParams'])) { |
| 732 | 732 | $urlParams = $this['urlParams']; |
| 733 | 733 | } else { |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | }); |
| 764 | 764 | $this->registerAlias('Request', \OCP\IRequest::class); |
| 765 | 765 | |
| 766 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 766 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
| 767 | 767 | return new Mailer( |
| 768 | 768 | $c->getConfig(), |
| 769 | 769 | $c->getLogger(), |
@@ -777,14 +777,14 @@ discard block |
||
| 777 | 777 | $this->registerService('LDAPProvider', function(Server $c) { |
| 778 | 778 | $config = $c->getConfig(); |
| 779 | 779 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 780 | - if(is_null($factoryClass)) { |
|
| 780 | + if (is_null($factoryClass)) { |
|
| 781 | 781 | throw new \Exception('ldapProviderFactory not set'); |
| 782 | 782 | } |
| 783 | 783 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
| 784 | 784 | $factory = new $factoryClass($this); |
| 785 | 785 | return $factory->getLDAPProvider(); |
| 786 | 786 | }); |
| 787 | - $this->registerService('LockingProvider', function (Server $c) { |
|
| 787 | + $this->registerService('LockingProvider', function(Server $c) { |
|
| 788 | 788 | $ini = $c->getIniWrapper(); |
| 789 | 789 | $config = $c->getConfig(); |
| 790 | 790 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -800,39 +800,39 @@ discard block |
||
| 800 | 800 | return new NoopLockingProvider(); |
| 801 | 801 | }); |
| 802 | 802 | |
| 803 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 803 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
| 804 | 804 | return new \OC\Files\Mount\Manager(); |
| 805 | 805 | }); |
| 806 | 806 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
| 807 | 807 | |
| 808 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 808 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
| 809 | 809 | return new \OC\Files\Type\Detection( |
| 810 | 810 | $c->getURLGenerator(), |
| 811 | 811 | \OC::$configDir, |
| 812 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 812 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 813 | 813 | ); |
| 814 | 814 | }); |
| 815 | 815 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
| 816 | 816 | |
| 817 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 817 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
| 818 | 818 | return new \OC\Files\Type\Loader( |
| 819 | 819 | $c->getDatabaseConnection() |
| 820 | 820 | ); |
| 821 | 821 | }); |
| 822 | 822 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
| 823 | - $this->registerService(BundleFetcher::class, function () { |
|
| 823 | + $this->registerService(BundleFetcher::class, function() { |
|
| 824 | 824 | return new BundleFetcher($this->getL10N('lib')); |
| 825 | 825 | }); |
| 826 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 826 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
| 827 | 827 | return new Manager( |
| 828 | 828 | $c->query(IValidator::class) |
| 829 | 829 | ); |
| 830 | 830 | }); |
| 831 | 831 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 832 | 832 | |
| 833 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 833 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
| 834 | 834 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
| 835 | - $manager->registerCapability(function () use ($c) { |
|
| 835 | + $manager->registerCapability(function() use ($c) { |
|
| 836 | 836 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 837 | 837 | }); |
| 838 | 838 | return $manager; |
@@ -887,13 +887,13 @@ discard block |
||
| 887 | 887 | $cacheFactory->create('SCSS') |
| 888 | 888 | ); |
| 889 | 889 | }); |
| 890 | - $this->registerService(EventDispatcher::class, function () { |
|
| 890 | + $this->registerService(EventDispatcher::class, function() { |
|
| 891 | 891 | return new EventDispatcher(); |
| 892 | 892 | }); |
| 893 | 893 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
| 894 | 894 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
| 895 | 895 | |
| 896 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 896 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 897 | 897 | // FIXME: Instantiiated here due to cyclic dependency |
| 898 | 898 | $request = new Request( |
| 899 | 899 | [ |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | $request |
| 919 | 919 | ); |
| 920 | 920 | }); |
| 921 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 921 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
| 922 | 922 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
| 923 | 923 | |
| 924 | 924 | return new CsrfTokenManager( |
@@ -926,10 +926,10 @@ discard block |
||
| 926 | 926 | $c->query(SessionStorage::class) |
| 927 | 927 | ); |
| 928 | 928 | }); |
| 929 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 929 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 930 | 930 | return new SessionStorage($c->getSession()); |
| 931 | 931 | }); |
| 932 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 932 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
| 933 | 933 | return new ContentSecurityPolicyManager(); |
| 934 | 934 | }); |
| 935 | 935 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
@@ -980,29 +980,29 @@ discard block |
||
| 980 | 980 | ); |
| 981 | 981 | return $manager; |
| 982 | 982 | }); |
| 983 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 983 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 984 | 984 | return new \OC\Files\AppData\Factory( |
| 985 | 985 | $c->getRootFolder(), |
| 986 | 986 | $c->getSystemConfig() |
| 987 | 987 | ); |
| 988 | 988 | }); |
| 989 | 989 | |
| 990 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 990 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 991 | 991 | return new LockdownManager(function() use ($c) { |
| 992 | 992 | return $c->getSession(); |
| 993 | 993 | }); |
| 994 | 994 | }); |
| 995 | 995 | |
| 996 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 996 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 997 | 997 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 998 | 998 | }); |
| 999 | 999 | |
| 1000 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1000 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 1001 | 1001 | return new CloudIdManager(); |
| 1002 | 1002 | }); |
| 1003 | 1003 | |
| 1004 | 1004 | /* To trick DI since we don't extend the DIContainer here */ |
| 1005 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
| 1005 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
| 1006 | 1006 | return new CleanPreviewsBackgroundJob( |
| 1007 | 1007 | $c->getRootFolder(), |
| 1008 | 1008 | $c->getLogger(), |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1018 | 1018 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1019 | 1019 | |
| 1020 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1020 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1021 | 1021 | return new Defaults( |
| 1022 | 1022 | $c->getThemingDefaults() |
| 1023 | 1023 | ); |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | * @deprecated since 9.2.0 use IAppData |
| 1170 | 1170 | */ |
| 1171 | 1171 | public function getAppFolder() { |
| 1172 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1172 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
| 1173 | 1173 | $root = $this->getRootFolder(); |
| 1174 | 1174 | if (!$root->nodeExists($dir)) { |
| 1175 | 1175 | $folder = $root->newFolder($dir); |