@@ -65,1442 +65,1442 @@ |
||
| 65 | 65 | use OCP\IUser; |
| 66 | 66 | |
| 67 | 67 | class OC_Util { |
| 68 | - public static $scripts = array(); |
|
| 69 | - public static $styles = array(); |
|
| 70 | - public static $headers = array(); |
|
| 71 | - private static $rootMounted = false; |
|
| 72 | - private static $fsSetup = false; |
|
| 73 | - |
|
| 74 | - /** @var array Local cache of version.php */ |
|
| 75 | - private static $versionCache = null; |
|
| 76 | - |
|
| 77 | - protected static function getAppManager() { |
|
| 78 | - return \OC::$server->getAppManager(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - private static function initLocalStorageRootFS() { |
|
| 82 | - // mount local file backend as root |
|
| 83 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 84 | - //first set up the local "root" storage |
|
| 85 | - \OC\Files\Filesystem::initMountManager(); |
|
| 86 | - if (!self::$rootMounted) { |
|
| 87 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 88 | - self::$rootMounted = true; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * mounting an object storage as the root fs will in essence remove the |
|
| 94 | - * necessity of a data folder being present. |
|
| 95 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 96 | - * |
|
| 97 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 98 | - * @suppress PhanDeprecatedFunction |
|
| 99 | - */ |
|
| 100 | - private static function initObjectStoreRootFS($config) { |
|
| 101 | - // check misconfiguration |
|
| 102 | - if (empty($config['class'])) { |
|
| 103 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 104 | - } |
|
| 105 | - if (!isset($config['arguments'])) { |
|
| 106 | - $config['arguments'] = array(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // instantiate object store implementation |
|
| 110 | - $name = $config['class']; |
|
| 111 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 112 | - $segments = explode('\\', $name); |
|
| 113 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 114 | - } |
|
| 115 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 116 | - // mount with plain / root object store implementation |
|
| 117 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 118 | - |
|
| 119 | - // mount object storage as root |
|
| 120 | - \OC\Files\Filesystem::initMountManager(); |
|
| 121 | - if (!self::$rootMounted) { |
|
| 122 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 123 | - self::$rootMounted = true; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * mounting an object storage as the root fs will in essence remove the |
|
| 129 | - * necessity of a data folder being present. |
|
| 130 | - * |
|
| 131 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 132 | - * @suppress PhanDeprecatedFunction |
|
| 133 | - */ |
|
| 134 | - private static function initObjectStoreMultibucketRootFS($config) { |
|
| 135 | - // check misconfiguration |
|
| 136 | - if (empty($config['class'])) { |
|
| 137 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 138 | - } |
|
| 139 | - if (!isset($config['arguments'])) { |
|
| 140 | - $config['arguments'] = array(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // instantiate object store implementation |
|
| 144 | - $name = $config['class']; |
|
| 145 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 146 | - $segments = explode('\\', $name); |
|
| 147 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - if (!isset($config['arguments']['bucket'])) { |
|
| 151 | - $config['arguments']['bucket'] = ''; |
|
| 152 | - } |
|
| 153 | - // put the root FS always in first bucket for multibucket configuration |
|
| 154 | - $config['arguments']['bucket'] .= '0'; |
|
| 155 | - |
|
| 156 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 157 | - // mount with plain / root object store implementation |
|
| 158 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 159 | - |
|
| 160 | - // mount object storage as root |
|
| 161 | - \OC\Files\Filesystem::initMountManager(); |
|
| 162 | - if (!self::$rootMounted) { |
|
| 163 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 164 | - self::$rootMounted = true; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Can be set up |
|
| 170 | - * |
|
| 171 | - * @param string $user |
|
| 172 | - * @return boolean |
|
| 173 | - * @description configure the initial filesystem based on the configuration |
|
| 174 | - * @suppress PhanDeprecatedFunction |
|
| 175 | - * @suppress PhanAccessMethodInternal |
|
| 176 | - */ |
|
| 177 | - public static function setupFS($user = '') { |
|
| 178 | - //setting up the filesystem twice can only lead to trouble |
|
| 179 | - if (self::$fsSetup) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 184 | - |
|
| 185 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 186 | - if ($user === null) { |
|
| 187 | - $user = ''; |
|
| 188 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 189 | - $user = OC_User::getUser(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 193 | - OC_App::loadApps(array('filesystem')); |
|
| 194 | - |
|
| 195 | - // the filesystem will finish when $user is not empty, |
|
| 196 | - // mark fs setup here to avoid doing the setup from loading |
|
| 197 | - // OC_Filesystem |
|
| 198 | - if ($user != '') { |
|
| 199 | - self::$fsSetup = true; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - \OC\Files\Filesystem::initMountManager(); |
|
| 203 | - |
|
| 204 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 205 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 207 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 208 | - $storage->setMountOptions($mount->getOptions()); |
|
| 209 | - } |
|
| 210 | - return $storage; |
|
| 211 | - }); |
|
| 212 | - |
|
| 213 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 214 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 215 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 216 | - 'storage' => $storage, |
|
| 217 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 218 | - ]); |
|
| 219 | - } |
|
| 220 | - return $storage; |
|
| 221 | - }); |
|
| 222 | - |
|
| 223 | - // install storage availability wrapper, before most other wrappers |
|
| 224 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 225 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 226 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 227 | - } |
|
| 228 | - return $storage; |
|
| 229 | - }); |
|
| 230 | - |
|
| 231 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 232 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 233 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 234 | - } |
|
| 235 | - return $storage; |
|
| 236 | - }); |
|
| 237 | - |
|
| 238 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 239 | - // set up quota for home storages, even for other users |
|
| 240 | - // which can happen when using sharing |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @var \OC\Files\Storage\Storage $storage |
|
| 244 | - */ |
|
| 245 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 246 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 247 | - ) { |
|
| 248 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 249 | - if (is_object($storage->getUser())) { |
|
| 250 | - $user = $storage->getUser()->getUID(); |
|
| 251 | - $quota = OC_Util::getUserQuota($user); |
|
| 252 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 253 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $storage; |
|
| 259 | - }); |
|
| 260 | - |
|
| 261 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 262 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 263 | - |
|
| 264 | - //check if we are using an object storage |
|
| 265 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 266 | - $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 267 | - |
|
| 268 | - // use the same order as in ObjectHomeMountProvider |
|
| 269 | - if (isset($objectStoreMultibucket)) { |
|
| 270 | - self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 271 | - } elseif (isset($objectStore)) { |
|
| 272 | - self::initObjectStoreRootFS($objectStore); |
|
| 273 | - } else { |
|
| 274 | - self::initLocalStorageRootFS(); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
| 278 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 283 | - if ($user != "") { |
|
| 284 | - |
|
| 285 | - $userDir = '/' . $user . '/files'; |
|
| 286 | - |
|
| 287 | - //jail the user into his "home" directory |
|
| 288 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 289 | - |
|
| 290 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 291 | - } |
|
| 292 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 293 | - return true; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * check if a password is required for each public link |
|
| 298 | - * |
|
| 299 | - * @return boolean |
|
| 300 | - * @suppress PhanDeprecatedFunction |
|
| 301 | - */ |
|
| 302 | - public static function isPublicLinkPasswordRequired() { |
|
| 303 | - $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 304 | - return $enforcePassword === 'yes'; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * check if sharing is disabled for the current user |
|
| 309 | - * @param IConfig $config |
|
| 310 | - * @param IGroupManager $groupManager |
|
| 311 | - * @param IUser|null $user |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 315 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 316 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 317 | - $excludedGroups = json_decode($groupsList); |
|
| 318 | - if (is_null($excludedGroups)) { |
|
| 319 | - $excludedGroups = explode(',', $groupsList); |
|
| 320 | - $newValue = json_encode($excludedGroups); |
|
| 321 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 322 | - } |
|
| 323 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 324 | - if (!empty($usersGroups)) { |
|
| 325 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 326 | - // if the user is only in groups which are disabled for sharing then |
|
| 327 | - // sharing is also disabled for the user |
|
| 328 | - if (empty($remainingGroups)) { |
|
| 329 | - return true; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * check if share API enforces a default expire date |
|
| 338 | - * |
|
| 339 | - * @return boolean |
|
| 340 | - * @suppress PhanDeprecatedFunction |
|
| 341 | - */ |
|
| 342 | - public static function isDefaultExpireDateEnforced() { |
|
| 343 | - $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 344 | - $enforceDefaultExpireDate = false; |
|
| 345 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 346 | - $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 347 | - $enforceDefaultExpireDate = $value === 'yes'; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return $enforceDefaultExpireDate; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Get the quota of a user |
|
| 355 | - * |
|
| 356 | - * @param string $userId |
|
| 357 | - * @return float Quota bytes |
|
| 358 | - */ |
|
| 359 | - public static function getUserQuota($userId) { |
|
| 360 | - $user = \OC::$server->getUserManager()->get($userId); |
|
| 361 | - if (is_null($user)) { |
|
| 362 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 363 | - } |
|
| 364 | - $userQuota = $user->getQuota(); |
|
| 365 | - if($userQuota === 'none') { |
|
| 366 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 367 | - } |
|
| 368 | - return OC_Helper::computerFileSize($userQuota); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * copies the skeleton to the users /files |
|
| 373 | - * |
|
| 374 | - * @param String $userId |
|
| 375 | - * @param \OCP\Files\Folder $userDirectory |
|
| 376 | - * @throws \RuntimeException |
|
| 377 | - * @suppress PhanDeprecatedFunction |
|
| 378 | - */ |
|
| 379 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 380 | - |
|
| 381 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 382 | - $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 383 | - $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 384 | - |
|
| 385 | - if (!file_exists($skeletonDirectory)) { |
|
| 386 | - $dialectStart = strpos($userLang, '_'); |
|
| 387 | - if ($dialectStart !== false) { |
|
| 388 | - $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 389 | - } |
|
| 390 | - if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 391 | - $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 392 | - } |
|
| 393 | - if (!file_exists($skeletonDirectory)) { |
|
| 394 | - $skeletonDirectory = ''; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 399 | - |
|
| 400 | - if ($instanceId === null) { |
|
| 401 | - throw new \RuntimeException('no instance id!'); |
|
| 402 | - } |
|
| 403 | - $appdata = 'appdata_' . $instanceId; |
|
| 404 | - if ($userId === $appdata) { |
|
| 405 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if (!empty($skeletonDirectory)) { |
|
| 409 | - \OCP\Util::writeLog( |
|
| 410 | - 'files_skeleton', |
|
| 411 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 412 | - \OCP\Util::DEBUG |
|
| 413 | - ); |
|
| 414 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 415 | - // update the file cache |
|
| 416 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * copies a directory recursively by using streams |
|
| 422 | - * |
|
| 423 | - * @param string $source |
|
| 424 | - * @param \OCP\Files\Folder $target |
|
| 425 | - * @return void |
|
| 426 | - */ |
|
| 427 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 428 | - $logger = \OC::$server->getLogger(); |
|
| 429 | - |
|
| 430 | - // Verify if folder exists |
|
| 431 | - $dir = opendir($source); |
|
| 432 | - if($dir === false) { |
|
| 433 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Copy the files |
|
| 438 | - while (false !== ($file = readdir($dir))) { |
|
| 439 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 440 | - if (is_dir($source . '/' . $file)) { |
|
| 441 | - $child = $target->newFolder($file); |
|
| 442 | - self::copyr($source . '/' . $file, $child); |
|
| 443 | - } else { |
|
| 444 | - $child = $target->newFile($file); |
|
| 445 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 446 | - if($sourceStream === false) { |
|
| 447 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 448 | - closedir($dir); |
|
| 449 | - return; |
|
| 450 | - } |
|
| 451 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - closedir($dir); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @return void |
|
| 460 | - * @suppress PhanUndeclaredMethod |
|
| 461 | - */ |
|
| 462 | - public static function tearDownFS() { |
|
| 463 | - \OC\Files\Filesystem::tearDown(); |
|
| 464 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 465 | - self::$fsSetup = false; |
|
| 466 | - self::$rootMounted = false; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * get the current installed version of ownCloud |
|
| 471 | - * |
|
| 472 | - * @return array |
|
| 473 | - */ |
|
| 474 | - public static function getVersion() { |
|
| 475 | - OC_Util::loadVersion(); |
|
| 476 | - return self::$versionCache['OC_Version']; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * get the current installed version string of ownCloud |
|
| 481 | - * |
|
| 482 | - * @return string |
|
| 483 | - */ |
|
| 484 | - public static function getVersionString() { |
|
| 485 | - OC_Util::loadVersion(); |
|
| 486 | - return self::$versionCache['OC_VersionString']; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * @deprecated the value is of no use anymore |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - public static function getEditionString() { |
|
| 494 | - return ''; |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * @description get the update channel of the current installed of ownCloud. |
|
| 499 | - * @return string |
|
| 500 | - */ |
|
| 501 | - public static function getChannel() { |
|
| 502 | - OC_Util::loadVersion(); |
|
| 503 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @description get the build number of the current installed of ownCloud. |
|
| 508 | - * @return string |
|
| 509 | - */ |
|
| 510 | - public static function getBuild() { |
|
| 511 | - OC_Util::loadVersion(); |
|
| 512 | - return self::$versionCache['OC_Build']; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * @description load the version.php into the session as cache |
|
| 517 | - * @suppress PhanUndeclaredVariable |
|
| 518 | - */ |
|
| 519 | - private static function loadVersion() { |
|
| 520 | - if (self::$versionCache !== null) { |
|
| 521 | - return; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 525 | - require OC::$SERVERROOT . '/version.php'; |
|
| 526 | - /** @var $timestamp int */ |
|
| 527 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 528 | - /** @var $OC_Version string */ |
|
| 529 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 530 | - /** @var $OC_VersionString string */ |
|
| 531 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 532 | - /** @var $OC_Build string */ |
|
| 533 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 534 | - |
|
| 535 | - /** @var $OC_Channel string */ |
|
| 536 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 541 | - * |
|
| 542 | - * @param string $application application to get the files from |
|
| 543 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 544 | - * @param string $file the file inside of the above folder |
|
| 545 | - * @return string the path |
|
| 546 | - */ |
|
| 547 | - private static function generatePath($application, $directory, $file) { |
|
| 548 | - if (is_null($file)) { |
|
| 549 | - $file = $application; |
|
| 550 | - $application = ""; |
|
| 551 | - } |
|
| 552 | - if (!empty($application)) { |
|
| 553 | - return "$application/$directory/$file"; |
|
| 554 | - } else { |
|
| 555 | - return "$directory/$file"; |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * add a javascript file |
|
| 561 | - * |
|
| 562 | - * @param string $application application id |
|
| 563 | - * @param string|null $file filename |
|
| 564 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 565 | - * @return void |
|
| 566 | - */ |
|
| 567 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 568 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 569 | - |
|
| 570 | - // core js files need separate handling |
|
| 571 | - if ($application !== 'core' && $file !== null) { |
|
| 572 | - self::addTranslations ( $application ); |
|
| 573 | - } |
|
| 574 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * add a javascript file from the vendor sub folder |
|
| 579 | - * |
|
| 580 | - * @param string $application application id |
|
| 581 | - * @param string|null $file filename |
|
| 582 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 583 | - * @return void |
|
| 584 | - */ |
|
| 585 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 586 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 587 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * add a translation JS file |
|
| 592 | - * |
|
| 593 | - * @param string $application application id |
|
| 594 | - * @param string|null $languageCode language code, defaults to the current language |
|
| 595 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 596 | - */ |
|
| 597 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 598 | - if (is_null($languageCode)) { |
|
| 599 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 600 | - } |
|
| 601 | - if (!empty($application)) { |
|
| 602 | - $path = "$application/l10n/$languageCode"; |
|
| 603 | - } else { |
|
| 604 | - $path = "l10n/$languageCode"; |
|
| 605 | - } |
|
| 606 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * add a css file |
|
| 611 | - * |
|
| 612 | - * @param string $application application id |
|
| 613 | - * @param string|null $file filename |
|
| 614 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 615 | - * @return void |
|
| 616 | - */ |
|
| 617 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 618 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 619 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * add a css file from the vendor sub folder |
|
| 624 | - * |
|
| 625 | - * @param string $application application id |
|
| 626 | - * @param string|null $file filename |
|
| 627 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 628 | - * @return void |
|
| 629 | - */ |
|
| 630 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 631 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 632 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * add an external resource css/js file |
|
| 637 | - * |
|
| 638 | - * @param string $application application id |
|
| 639 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 640 | - * @param string $path |
|
| 641 | - * @param string $type (script or style) |
|
| 642 | - * @return void |
|
| 643 | - */ |
|
| 644 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 645 | - |
|
| 646 | - if ($type === "style") { |
|
| 647 | - if (!in_array($path, self::$styles)) { |
|
| 648 | - if ($prepend === true) { |
|
| 649 | - array_unshift ( self::$styles, $path ); |
|
| 650 | - } else { |
|
| 651 | - self::$styles[] = $path; |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } elseif ($type === "script") { |
|
| 655 | - if (!in_array($path, self::$scripts)) { |
|
| 656 | - if ($prepend === true) { |
|
| 657 | - array_unshift ( self::$scripts, $path ); |
|
| 658 | - } else { |
|
| 659 | - self::$scripts [] = $path; |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * Add a custom element to the header |
|
| 667 | - * If $text is null then the element will be written as empty element. |
|
| 668 | - * So use "" to get a closing tag. |
|
| 669 | - * @param string $tag tag name of the element |
|
| 670 | - * @param array $attributes array of attributes for the element |
|
| 671 | - * @param string $text the text content for the element |
|
| 672 | - */ |
|
| 673 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 674 | - self::$headers[] = array( |
|
| 675 | - 'tag' => $tag, |
|
| 676 | - 'attributes' => $attributes, |
|
| 677 | - 'text' => $text |
|
| 678 | - ); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * check if the current server configuration is suitable for ownCloud |
|
| 683 | - * |
|
| 684 | - * @param \OC\SystemConfig $config |
|
| 685 | - * @return array arrays with error messages and hints |
|
| 686 | - */ |
|
| 687 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 688 | - $l = \OC::$server->getL10N('lib'); |
|
| 689 | - $errors = array(); |
|
| 690 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 691 | - |
|
| 692 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 693 | - // this check needs to be done every time |
|
| 694 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 698 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 699 | - return $errors; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - $webServerRestart = false; |
|
| 703 | - $setup = new \OC\Setup( |
|
| 704 | - $config, |
|
| 705 | - \OC::$server->getIniWrapper(), |
|
| 706 | - \OC::$server->getL10N('lib'), |
|
| 707 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 708 | - \OC::$server->getLogger(), |
|
| 709 | - \OC::$server->getSecureRandom(), |
|
| 710 | - \OC::$server->query(\OC\Installer::class) |
|
| 711 | - ); |
|
| 712 | - |
|
| 713 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 714 | - |
|
| 715 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 716 | - if (empty($availableDatabases)) { |
|
| 717 | - $errors[] = array( |
|
| 718 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 719 | - 'hint' => '' //TODO: sane hint |
|
| 720 | - ); |
|
| 721 | - $webServerRestart = true; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // Check if config folder is writable. |
|
| 725 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 726 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 727 | - $errors[] = array( |
|
| 728 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 729 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 68 | + public static $scripts = array(); |
|
| 69 | + public static $styles = array(); |
|
| 70 | + public static $headers = array(); |
|
| 71 | + private static $rootMounted = false; |
|
| 72 | + private static $fsSetup = false; |
|
| 73 | + |
|
| 74 | + /** @var array Local cache of version.php */ |
|
| 75 | + private static $versionCache = null; |
|
| 76 | + |
|
| 77 | + protected static function getAppManager() { |
|
| 78 | + return \OC::$server->getAppManager(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + private static function initLocalStorageRootFS() { |
|
| 82 | + // mount local file backend as root |
|
| 83 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 84 | + //first set up the local "root" storage |
|
| 85 | + \OC\Files\Filesystem::initMountManager(); |
|
| 86 | + if (!self::$rootMounted) { |
|
| 87 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 88 | + self::$rootMounted = true; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * mounting an object storage as the root fs will in essence remove the |
|
| 94 | + * necessity of a data folder being present. |
|
| 95 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 96 | + * |
|
| 97 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 98 | + * @suppress PhanDeprecatedFunction |
|
| 99 | + */ |
|
| 100 | + private static function initObjectStoreRootFS($config) { |
|
| 101 | + // check misconfiguration |
|
| 102 | + if (empty($config['class'])) { |
|
| 103 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 104 | + } |
|
| 105 | + if (!isset($config['arguments'])) { |
|
| 106 | + $config['arguments'] = array(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // instantiate object store implementation |
|
| 110 | + $name = $config['class']; |
|
| 111 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 112 | + $segments = explode('\\', $name); |
|
| 113 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 114 | + } |
|
| 115 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 116 | + // mount with plain / root object store implementation |
|
| 117 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 118 | + |
|
| 119 | + // mount object storage as root |
|
| 120 | + \OC\Files\Filesystem::initMountManager(); |
|
| 121 | + if (!self::$rootMounted) { |
|
| 122 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 123 | + self::$rootMounted = true; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * mounting an object storage as the root fs will in essence remove the |
|
| 129 | + * necessity of a data folder being present. |
|
| 130 | + * |
|
| 131 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 132 | + * @suppress PhanDeprecatedFunction |
|
| 133 | + */ |
|
| 134 | + private static function initObjectStoreMultibucketRootFS($config) { |
|
| 135 | + // check misconfiguration |
|
| 136 | + if (empty($config['class'])) { |
|
| 137 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 138 | + } |
|
| 139 | + if (!isset($config['arguments'])) { |
|
| 140 | + $config['arguments'] = array(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // instantiate object store implementation |
|
| 144 | + $name = $config['class']; |
|
| 145 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 146 | + $segments = explode('\\', $name); |
|
| 147 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + if (!isset($config['arguments']['bucket'])) { |
|
| 151 | + $config['arguments']['bucket'] = ''; |
|
| 152 | + } |
|
| 153 | + // put the root FS always in first bucket for multibucket configuration |
|
| 154 | + $config['arguments']['bucket'] .= '0'; |
|
| 155 | + |
|
| 156 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 157 | + // mount with plain / root object store implementation |
|
| 158 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 159 | + |
|
| 160 | + // mount object storage as root |
|
| 161 | + \OC\Files\Filesystem::initMountManager(); |
|
| 162 | + if (!self::$rootMounted) { |
|
| 163 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 164 | + self::$rootMounted = true; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Can be set up |
|
| 170 | + * |
|
| 171 | + * @param string $user |
|
| 172 | + * @return boolean |
|
| 173 | + * @description configure the initial filesystem based on the configuration |
|
| 174 | + * @suppress PhanDeprecatedFunction |
|
| 175 | + * @suppress PhanAccessMethodInternal |
|
| 176 | + */ |
|
| 177 | + public static function setupFS($user = '') { |
|
| 178 | + //setting up the filesystem twice can only lead to trouble |
|
| 179 | + if (self::$fsSetup) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 184 | + |
|
| 185 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 186 | + if ($user === null) { |
|
| 187 | + $user = ''; |
|
| 188 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 189 | + $user = OC_User::getUser(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 193 | + OC_App::loadApps(array('filesystem')); |
|
| 194 | + |
|
| 195 | + // the filesystem will finish when $user is not empty, |
|
| 196 | + // mark fs setup here to avoid doing the setup from loading |
|
| 197 | + // OC_Filesystem |
|
| 198 | + if ($user != '') { |
|
| 199 | + self::$fsSetup = true; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + \OC\Files\Filesystem::initMountManager(); |
|
| 203 | + |
|
| 204 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 205 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 207 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 208 | + $storage->setMountOptions($mount->getOptions()); |
|
| 209 | + } |
|
| 210 | + return $storage; |
|
| 211 | + }); |
|
| 212 | + |
|
| 213 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 214 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 215 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 216 | + 'storage' => $storage, |
|
| 217 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 218 | + ]); |
|
| 219 | + } |
|
| 220 | + return $storage; |
|
| 221 | + }); |
|
| 222 | + |
|
| 223 | + // install storage availability wrapper, before most other wrappers |
|
| 224 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 225 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 226 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 227 | + } |
|
| 228 | + return $storage; |
|
| 229 | + }); |
|
| 230 | + |
|
| 231 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 232 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 233 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 234 | + } |
|
| 235 | + return $storage; |
|
| 236 | + }); |
|
| 237 | + |
|
| 238 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 239 | + // set up quota for home storages, even for other users |
|
| 240 | + // which can happen when using sharing |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @var \OC\Files\Storage\Storage $storage |
|
| 244 | + */ |
|
| 245 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 246 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 247 | + ) { |
|
| 248 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 249 | + if (is_object($storage->getUser())) { |
|
| 250 | + $user = $storage->getUser()->getUID(); |
|
| 251 | + $quota = OC_Util::getUserQuota($user); |
|
| 252 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 253 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $storage; |
|
| 259 | + }); |
|
| 260 | + |
|
| 261 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 262 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 263 | + |
|
| 264 | + //check if we are using an object storage |
|
| 265 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 266 | + $objectStoreMultibucket = \OC::$server->getSystemConfig()->getValue('objectstore_multibucket', null); |
|
| 267 | + |
|
| 268 | + // use the same order as in ObjectHomeMountProvider |
|
| 269 | + if (isset($objectStoreMultibucket)) { |
|
| 270 | + self::initObjectStoreMultibucketRootFS($objectStoreMultibucket); |
|
| 271 | + } elseif (isset($objectStore)) { |
|
| 272 | + self::initObjectStoreRootFS($objectStore); |
|
| 273 | + } else { |
|
| 274 | + self::initLocalStorageRootFS(); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + if ($user != '' && !\OC::$server->getUserManager()->userExists($user)) { |
|
| 278 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 283 | + if ($user != "") { |
|
| 284 | + |
|
| 285 | + $userDir = '/' . $user . '/files'; |
|
| 286 | + |
|
| 287 | + //jail the user into his "home" directory |
|
| 288 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 289 | + |
|
| 290 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 291 | + } |
|
| 292 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 293 | + return true; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * check if a password is required for each public link |
|
| 298 | + * |
|
| 299 | + * @return boolean |
|
| 300 | + * @suppress PhanDeprecatedFunction |
|
| 301 | + */ |
|
| 302 | + public static function isPublicLinkPasswordRequired() { |
|
| 303 | + $enforcePassword = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 304 | + return $enforcePassword === 'yes'; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * check if sharing is disabled for the current user |
|
| 309 | + * @param IConfig $config |
|
| 310 | + * @param IGroupManager $groupManager |
|
| 311 | + * @param IUser|null $user |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 315 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 316 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 317 | + $excludedGroups = json_decode($groupsList); |
|
| 318 | + if (is_null($excludedGroups)) { |
|
| 319 | + $excludedGroups = explode(',', $groupsList); |
|
| 320 | + $newValue = json_encode($excludedGroups); |
|
| 321 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 322 | + } |
|
| 323 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 324 | + if (!empty($usersGroups)) { |
|
| 325 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 326 | + // if the user is only in groups which are disabled for sharing then |
|
| 327 | + // sharing is also disabled for the user |
|
| 328 | + if (empty($remainingGroups)) { |
|
| 329 | + return true; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * check if share API enforces a default expire date |
|
| 338 | + * |
|
| 339 | + * @return boolean |
|
| 340 | + * @suppress PhanDeprecatedFunction |
|
| 341 | + */ |
|
| 342 | + public static function isDefaultExpireDateEnforced() { |
|
| 343 | + $isDefaultExpireDateEnabled = \OC::$server->getConfig()->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 344 | + $enforceDefaultExpireDate = false; |
|
| 345 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 346 | + $value = \OC::$server->getConfig()->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 347 | + $enforceDefaultExpireDate = $value === 'yes'; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return $enforceDefaultExpireDate; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Get the quota of a user |
|
| 355 | + * |
|
| 356 | + * @param string $userId |
|
| 357 | + * @return float Quota bytes |
|
| 358 | + */ |
|
| 359 | + public static function getUserQuota($userId) { |
|
| 360 | + $user = \OC::$server->getUserManager()->get($userId); |
|
| 361 | + if (is_null($user)) { |
|
| 362 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 363 | + } |
|
| 364 | + $userQuota = $user->getQuota(); |
|
| 365 | + if($userQuota === 'none') { |
|
| 366 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 367 | + } |
|
| 368 | + return OC_Helper::computerFileSize($userQuota); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * copies the skeleton to the users /files |
|
| 373 | + * |
|
| 374 | + * @param String $userId |
|
| 375 | + * @param \OCP\Files\Folder $userDirectory |
|
| 376 | + * @throws \RuntimeException |
|
| 377 | + * @suppress PhanDeprecatedFunction |
|
| 378 | + */ |
|
| 379 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 380 | + |
|
| 381 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 382 | + $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 383 | + $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 384 | + |
|
| 385 | + if (!file_exists($skeletonDirectory)) { |
|
| 386 | + $dialectStart = strpos($userLang, '_'); |
|
| 387 | + if ($dialectStart !== false) { |
|
| 388 | + $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 389 | + } |
|
| 390 | + if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 391 | + $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 392 | + } |
|
| 393 | + if (!file_exists($skeletonDirectory)) { |
|
| 394 | + $skeletonDirectory = ''; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 399 | + |
|
| 400 | + if ($instanceId === null) { |
|
| 401 | + throw new \RuntimeException('no instance id!'); |
|
| 402 | + } |
|
| 403 | + $appdata = 'appdata_' . $instanceId; |
|
| 404 | + if ($userId === $appdata) { |
|
| 405 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if (!empty($skeletonDirectory)) { |
|
| 409 | + \OCP\Util::writeLog( |
|
| 410 | + 'files_skeleton', |
|
| 411 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 412 | + \OCP\Util::DEBUG |
|
| 413 | + ); |
|
| 414 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 415 | + // update the file cache |
|
| 416 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * copies a directory recursively by using streams |
|
| 422 | + * |
|
| 423 | + * @param string $source |
|
| 424 | + * @param \OCP\Files\Folder $target |
|
| 425 | + * @return void |
|
| 426 | + */ |
|
| 427 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 428 | + $logger = \OC::$server->getLogger(); |
|
| 429 | + |
|
| 430 | + // Verify if folder exists |
|
| 431 | + $dir = opendir($source); |
|
| 432 | + if($dir === false) { |
|
| 433 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Copy the files |
|
| 438 | + while (false !== ($file = readdir($dir))) { |
|
| 439 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 440 | + if (is_dir($source . '/' . $file)) { |
|
| 441 | + $child = $target->newFolder($file); |
|
| 442 | + self::copyr($source . '/' . $file, $child); |
|
| 443 | + } else { |
|
| 444 | + $child = $target->newFile($file); |
|
| 445 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 446 | + if($sourceStream === false) { |
|
| 447 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 448 | + closedir($dir); |
|
| 449 | + return; |
|
| 450 | + } |
|
| 451 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + closedir($dir); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @return void |
|
| 460 | + * @suppress PhanUndeclaredMethod |
|
| 461 | + */ |
|
| 462 | + public static function tearDownFS() { |
|
| 463 | + \OC\Files\Filesystem::tearDown(); |
|
| 464 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 465 | + self::$fsSetup = false; |
|
| 466 | + self::$rootMounted = false; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * get the current installed version of ownCloud |
|
| 471 | + * |
|
| 472 | + * @return array |
|
| 473 | + */ |
|
| 474 | + public static function getVersion() { |
|
| 475 | + OC_Util::loadVersion(); |
|
| 476 | + return self::$versionCache['OC_Version']; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * get the current installed version string of ownCloud |
|
| 481 | + * |
|
| 482 | + * @return string |
|
| 483 | + */ |
|
| 484 | + public static function getVersionString() { |
|
| 485 | + OC_Util::loadVersion(); |
|
| 486 | + return self::$versionCache['OC_VersionString']; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * @deprecated the value is of no use anymore |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + public static function getEditionString() { |
|
| 494 | + return ''; |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * @description get the update channel of the current installed of ownCloud. |
|
| 499 | + * @return string |
|
| 500 | + */ |
|
| 501 | + public static function getChannel() { |
|
| 502 | + OC_Util::loadVersion(); |
|
| 503 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @description get the build number of the current installed of ownCloud. |
|
| 508 | + * @return string |
|
| 509 | + */ |
|
| 510 | + public static function getBuild() { |
|
| 511 | + OC_Util::loadVersion(); |
|
| 512 | + return self::$versionCache['OC_Build']; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * @description load the version.php into the session as cache |
|
| 517 | + * @suppress PhanUndeclaredVariable |
|
| 518 | + */ |
|
| 519 | + private static function loadVersion() { |
|
| 520 | + if (self::$versionCache !== null) { |
|
| 521 | + return; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 525 | + require OC::$SERVERROOT . '/version.php'; |
|
| 526 | + /** @var $timestamp int */ |
|
| 527 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 528 | + /** @var $OC_Version string */ |
|
| 529 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 530 | + /** @var $OC_VersionString string */ |
|
| 531 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 532 | + /** @var $OC_Build string */ |
|
| 533 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 534 | + |
|
| 535 | + /** @var $OC_Channel string */ |
|
| 536 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 541 | + * |
|
| 542 | + * @param string $application application to get the files from |
|
| 543 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 544 | + * @param string $file the file inside of the above folder |
|
| 545 | + * @return string the path |
|
| 546 | + */ |
|
| 547 | + private static function generatePath($application, $directory, $file) { |
|
| 548 | + if (is_null($file)) { |
|
| 549 | + $file = $application; |
|
| 550 | + $application = ""; |
|
| 551 | + } |
|
| 552 | + if (!empty($application)) { |
|
| 553 | + return "$application/$directory/$file"; |
|
| 554 | + } else { |
|
| 555 | + return "$directory/$file"; |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * add a javascript file |
|
| 561 | + * |
|
| 562 | + * @param string $application application id |
|
| 563 | + * @param string|null $file filename |
|
| 564 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 565 | + * @return void |
|
| 566 | + */ |
|
| 567 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 568 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 569 | + |
|
| 570 | + // core js files need separate handling |
|
| 571 | + if ($application !== 'core' && $file !== null) { |
|
| 572 | + self::addTranslations ( $application ); |
|
| 573 | + } |
|
| 574 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * add a javascript file from the vendor sub folder |
|
| 579 | + * |
|
| 580 | + * @param string $application application id |
|
| 581 | + * @param string|null $file filename |
|
| 582 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 583 | + * @return void |
|
| 584 | + */ |
|
| 585 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 586 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 587 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * add a translation JS file |
|
| 592 | + * |
|
| 593 | + * @param string $application application id |
|
| 594 | + * @param string|null $languageCode language code, defaults to the current language |
|
| 595 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 596 | + */ |
|
| 597 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 598 | + if (is_null($languageCode)) { |
|
| 599 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 600 | + } |
|
| 601 | + if (!empty($application)) { |
|
| 602 | + $path = "$application/l10n/$languageCode"; |
|
| 603 | + } else { |
|
| 604 | + $path = "l10n/$languageCode"; |
|
| 605 | + } |
|
| 606 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * add a css file |
|
| 611 | + * |
|
| 612 | + * @param string $application application id |
|
| 613 | + * @param string|null $file filename |
|
| 614 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 615 | + * @return void |
|
| 616 | + */ |
|
| 617 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 618 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 619 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * add a css file from the vendor sub folder |
|
| 624 | + * |
|
| 625 | + * @param string $application application id |
|
| 626 | + * @param string|null $file filename |
|
| 627 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 628 | + * @return void |
|
| 629 | + */ |
|
| 630 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 631 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 632 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * add an external resource css/js file |
|
| 637 | + * |
|
| 638 | + * @param string $application application id |
|
| 639 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 640 | + * @param string $path |
|
| 641 | + * @param string $type (script or style) |
|
| 642 | + * @return void |
|
| 643 | + */ |
|
| 644 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 645 | + |
|
| 646 | + if ($type === "style") { |
|
| 647 | + if (!in_array($path, self::$styles)) { |
|
| 648 | + if ($prepend === true) { |
|
| 649 | + array_unshift ( self::$styles, $path ); |
|
| 650 | + } else { |
|
| 651 | + self::$styles[] = $path; |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } elseif ($type === "script") { |
|
| 655 | + if (!in_array($path, self::$scripts)) { |
|
| 656 | + if ($prepend === true) { |
|
| 657 | + array_unshift ( self::$scripts, $path ); |
|
| 658 | + } else { |
|
| 659 | + self::$scripts [] = $path; |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * Add a custom element to the header |
|
| 667 | + * If $text is null then the element will be written as empty element. |
|
| 668 | + * So use "" to get a closing tag. |
|
| 669 | + * @param string $tag tag name of the element |
|
| 670 | + * @param array $attributes array of attributes for the element |
|
| 671 | + * @param string $text the text content for the element |
|
| 672 | + */ |
|
| 673 | + public static function addHeader($tag, $attributes, $text=null) { |
|
| 674 | + self::$headers[] = array( |
|
| 675 | + 'tag' => $tag, |
|
| 676 | + 'attributes' => $attributes, |
|
| 677 | + 'text' => $text |
|
| 678 | + ); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * check if the current server configuration is suitable for ownCloud |
|
| 683 | + * |
|
| 684 | + * @param \OC\SystemConfig $config |
|
| 685 | + * @return array arrays with error messages and hints |
|
| 686 | + */ |
|
| 687 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 688 | + $l = \OC::$server->getL10N('lib'); |
|
| 689 | + $errors = array(); |
|
| 690 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 691 | + |
|
| 692 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 693 | + // this check needs to be done every time |
|
| 694 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 698 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 699 | + return $errors; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + $webServerRestart = false; |
|
| 703 | + $setup = new \OC\Setup( |
|
| 704 | + $config, |
|
| 705 | + \OC::$server->getIniWrapper(), |
|
| 706 | + \OC::$server->getL10N('lib'), |
|
| 707 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 708 | + \OC::$server->getLogger(), |
|
| 709 | + \OC::$server->getSecureRandom(), |
|
| 710 | + \OC::$server->query(\OC\Installer::class) |
|
| 711 | + ); |
|
| 712 | + |
|
| 713 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 714 | + |
|
| 715 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 716 | + if (empty($availableDatabases)) { |
|
| 717 | + $errors[] = array( |
|
| 718 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 719 | + 'hint' => '' //TODO: sane hint |
|
| 720 | + ); |
|
| 721 | + $webServerRestart = true; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // Check if config folder is writable. |
|
| 725 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 726 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 727 | + $errors[] = array( |
|
| 728 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 729 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 730 | 730 | [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
| 731 | 731 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
| 732 | 732 | [ $urlGenerator->linkToDocs('admin-config') ] ) |
| 733 | 733 | ); |
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - // Check if there is a writable install folder. |
|
| 738 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 739 | - if (OC_App::getInstallPath() === null |
|
| 740 | - || !is_writable(OC_App::getInstallPath()) |
|
| 741 | - || !is_readable(OC_App::getInstallPath()) |
|
| 742 | - ) { |
|
| 743 | - $errors[] = array( |
|
| 744 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 745 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 746 | - . ' or disabling the appstore in the config file. See %s', |
|
| 747 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 748 | - ); |
|
| 749 | - } |
|
| 750 | - } |
|
| 751 | - // Create root dir. |
|
| 752 | - if ($config->getValue('installed', false)) { |
|
| 753 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 754 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 755 | - if ($success) { |
|
| 756 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 757 | - } else { |
|
| 758 | - $errors[] = [ |
|
| 759 | - 'error' => $l->t('Cannot create "data" directory'), |
|
| 760 | - 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 761 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 762 | - ]; |
|
| 763 | - } |
|
| 764 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 765 | - //common hint for all file permissions error messages |
|
| 766 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 767 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 768 | - $errors[] = [ |
|
| 769 | - 'error' => 'Your data directory is not writable', |
|
| 770 | - 'hint' => $permissionsHint |
|
| 771 | - ]; |
|
| 772 | - } else { |
|
| 773 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 778 | - $errors[] = array( |
|
| 779 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 780 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 781 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 782 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 783 | - ); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // Contains the dependencies that should be checked against |
|
| 787 | - // classes = class_exists |
|
| 788 | - // functions = function_exists |
|
| 789 | - // defined = defined |
|
| 790 | - // ini = ini_get |
|
| 791 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 792 | - // When adding new checks always verify that they pass on Travis as well |
|
| 793 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 794 | - $dependencies = array( |
|
| 795 | - 'classes' => array( |
|
| 796 | - 'ZipArchive' => 'zip', |
|
| 797 | - 'DOMDocument' => 'dom', |
|
| 798 | - 'XMLWriter' => 'XMLWriter', |
|
| 799 | - 'XMLReader' => 'XMLReader', |
|
| 800 | - ), |
|
| 801 | - 'functions' => [ |
|
| 802 | - 'xml_parser_create' => 'libxml', |
|
| 803 | - 'mb_strcut' => 'mb multibyte', |
|
| 804 | - 'ctype_digit' => 'ctype', |
|
| 805 | - 'json_encode' => 'JSON', |
|
| 806 | - 'gd_info' => 'GD', |
|
| 807 | - 'gzencode' => 'zlib', |
|
| 808 | - 'iconv' => 'iconv', |
|
| 809 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 810 | - 'hash' => 'HASH Message Digest Framework', |
|
| 811 | - 'curl_init' => 'cURL', |
|
| 812 | - 'openssl_verify' => 'OpenSSL', |
|
| 813 | - ], |
|
| 814 | - 'defined' => array( |
|
| 815 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 816 | - ), |
|
| 817 | - 'ini' => [ |
|
| 818 | - 'default_charset' => 'UTF-8', |
|
| 819 | - ], |
|
| 820 | - ); |
|
| 821 | - $missingDependencies = array(); |
|
| 822 | - $invalidIniSettings = []; |
|
| 823 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 827 | - * and prevents installation. Once HHVM is more compatible with our |
|
| 828 | - * approach to check for these values we should re-enable those |
|
| 829 | - * checks. |
|
| 830 | - */ |
|
| 831 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 832 | - if (!self::runningOnHhvm()) { |
|
| 833 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 834 | - if (!class_exists($class)) { |
|
| 835 | - $missingDependencies[] = $module; |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 839 | - if (!function_exists($function)) { |
|
| 840 | - $missingDependencies[] = $module; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 844 | - if (!defined($defined)) { |
|
| 845 | - $missingDependencies[] = $module; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 849 | - if (is_bool($expected)) { |
|
| 850 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 851 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - if (is_int($expected)) { |
|
| 855 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 856 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - if (is_string($expected)) { |
|
| 860 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 861 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - foreach($missingDependencies as $missingDependency) { |
|
| 868 | - $errors[] = array( |
|
| 869 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 870 | - 'hint' => $moduleHint |
|
| 871 | - ); |
|
| 872 | - $webServerRestart = true; |
|
| 873 | - } |
|
| 874 | - foreach($invalidIniSettings as $setting) { |
|
| 875 | - if(is_bool($setting[1])) { |
|
| 876 | - $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 877 | - } |
|
| 878 | - $errors[] = [ |
|
| 879 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 880 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 881 | - ]; |
|
| 882 | - $webServerRestart = true; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 887 | - * module is installed as it will return null if the checking setting is |
|
| 888 | - * not available and thus a check on the boolean value fails. |
|
| 889 | - * |
|
| 890 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 891 | - * check somehow in the long-term. |
|
| 892 | - */ |
|
| 893 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 894 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 895 | - $errors[] = array( |
|
| 896 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 897 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 898 | - ); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - if(function_exists('xml_parser_create') && |
|
| 902 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 903 | - $version = LIBXML_LOADED_VERSION; |
|
| 904 | - $major = floor($version/10000); |
|
| 905 | - $version -= ($major * 10000); |
|
| 906 | - $minor = floor($version/100); |
|
| 907 | - $version -= ($minor * 100); |
|
| 908 | - $patch = $version; |
|
| 909 | - $errors[] = array( |
|
| 910 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 911 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - if (!self::isAnnotationsWorking()) { |
|
| 916 | - $errors[] = array( |
|
| 917 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 918 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 919 | - ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 923 | - $errors[] = array( |
|
| 924 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 925 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 926 | - ); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 930 | - |
|
| 931 | - // Cache the result of this function |
|
| 932 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 933 | - |
|
| 934 | - return $errors; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * Check the database version |
|
| 939 | - * |
|
| 940 | - * @return array errors array |
|
| 941 | - */ |
|
| 942 | - public static function checkDatabaseVersion() { |
|
| 943 | - $l = \OC::$server->getL10N('lib'); |
|
| 944 | - $errors = array(); |
|
| 945 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 946 | - if ($dbType === 'pgsql') { |
|
| 947 | - // check PostgreSQL version |
|
| 948 | - try { |
|
| 949 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 950 | - $data = $result->fetchRow(); |
|
| 951 | - if (isset($data['server_version'])) { |
|
| 952 | - $version = $data['server_version']; |
|
| 953 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 954 | - $errors[] = array( |
|
| 955 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 956 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 957 | - ); |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 961 | - $logger = \OC::$server->getLogger(); |
|
| 962 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 963 | - $logger->logException($e); |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - return $errors; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * Check for correct file permissions of data directory |
|
| 971 | - * |
|
| 972 | - * @param string $dataDirectory |
|
| 973 | - * @return array arrays with error messages and hints |
|
| 974 | - */ |
|
| 975 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 976 | - if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 977 | - return []; |
|
| 978 | - } |
|
| 979 | - $l = \OC::$server->getL10N('lib'); |
|
| 980 | - $errors = []; |
|
| 981 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 982 | - . ' cannot be listed by other users.'); |
|
| 983 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 984 | - if (substr($perms, -1) !== '0') { |
|
| 985 | - chmod($dataDirectory, 0770); |
|
| 986 | - clearstatcache(); |
|
| 987 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 988 | - if ($perms[2] !== '0') { |
|
| 989 | - $errors[] = [ |
|
| 990 | - 'error' => $l->t('Your data directory is readable by other users'), |
|
| 991 | - 'hint' => $permissionsModHint |
|
| 992 | - ]; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - return $errors; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * Check that the data directory exists and is valid by |
|
| 1000 | - * checking the existence of the ".ocdata" file. |
|
| 1001 | - * |
|
| 1002 | - * @param string $dataDirectory data directory path |
|
| 1003 | - * @return array errors found |
|
| 1004 | - */ |
|
| 1005 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1006 | - $l = \OC::$server->getL10N('lib'); |
|
| 1007 | - $errors = []; |
|
| 1008 | - if ($dataDirectory[0] !== '/') { |
|
| 1009 | - $errors[] = [ |
|
| 1010 | - 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1011 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1012 | - ]; |
|
| 1013 | - } |
|
| 1014 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1015 | - $errors[] = [ |
|
| 1016 | - 'error' => $l->t('Your data directory is invalid'), |
|
| 1017 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1018 | - ' in the root of the data directory.') |
|
| 1019 | - ]; |
|
| 1020 | - } |
|
| 1021 | - return $errors; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - /** |
|
| 1025 | - * Check if the user is logged in, redirects to home if not. With |
|
| 1026 | - * redirect URL parameter to the request URI. |
|
| 1027 | - * |
|
| 1028 | - * @return void |
|
| 1029 | - */ |
|
| 1030 | - public static function checkLoggedIn() { |
|
| 1031 | - // Check if we are a user |
|
| 1032 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1033 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1034 | - 'core.login.showLoginForm', |
|
| 1035 | - [ |
|
| 1036 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1037 | - ] |
|
| 1038 | - ) |
|
| 1039 | - ); |
|
| 1040 | - exit(); |
|
| 1041 | - } |
|
| 1042 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1043 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1044 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1045 | - exit(); |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * Check if the user is a admin, redirects to home if not |
|
| 1051 | - * |
|
| 1052 | - * @return void |
|
| 1053 | - */ |
|
| 1054 | - public static function checkAdminUser() { |
|
| 1055 | - OC_Util::checkLoggedIn(); |
|
| 1056 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1057 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1058 | - exit(); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Check if the user is a subadmin, redirects to home if not |
|
| 1064 | - * |
|
| 1065 | - * @return null|boolean $groups where the current user is subadmin |
|
| 1066 | - */ |
|
| 1067 | - public static function checkSubAdminUser() { |
|
| 1068 | - OC_Util::checkLoggedIn(); |
|
| 1069 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1070 | - $isSubAdmin = false; |
|
| 1071 | - if($userObject !== null) { |
|
| 1072 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - if (!$isSubAdmin) { |
|
| 1076 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1077 | - exit(); |
|
| 1078 | - } |
|
| 1079 | - return true; |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * Returns the URL of the default page |
|
| 1084 | - * based on the system configuration and |
|
| 1085 | - * the apps visible for the current user |
|
| 1086 | - * |
|
| 1087 | - * @return string URL |
|
| 1088 | - * @suppress PhanDeprecatedFunction |
|
| 1089 | - */ |
|
| 1090 | - public static function getDefaultPageUrl() { |
|
| 1091 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1092 | - // Deny the redirect if the URL contains a @ |
|
| 1093 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1094 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1095 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1096 | - } else { |
|
| 1097 | - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
| 1098 | - if ($defaultPage) { |
|
| 1099 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1100 | - } else { |
|
| 1101 | - $appId = 'files'; |
|
| 1102 | - $config = \OC::$server->getConfig(); |
|
| 1103 | - $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
| 1104 | - // find the first app that is enabled for the current user |
|
| 1105 | - foreach ($defaultApps as $defaultApp) { |
|
| 1106 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1107 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1108 | - $appId = $defaultApp; |
|
| 1109 | - break; |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1114 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1115 | - } else { |
|
| 1116 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - return $location; |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * Redirect to the user default page |
|
| 1125 | - * |
|
| 1126 | - * @return void |
|
| 1127 | - */ |
|
| 1128 | - public static function redirectToDefaultPage() { |
|
| 1129 | - $location = self::getDefaultPageUrl(); |
|
| 1130 | - header('Location: ' . $location); |
|
| 1131 | - exit(); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * get an id unique for this instance |
|
| 1136 | - * |
|
| 1137 | - * @return string |
|
| 1138 | - */ |
|
| 1139 | - public static function getInstanceId() { |
|
| 1140 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1141 | - if (is_null($id)) { |
|
| 1142 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1143 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1144 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1145 | - } |
|
| 1146 | - return $id; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Public function to sanitize HTML |
|
| 1151 | - * |
|
| 1152 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1153 | - * string or array of strings before displaying it on a web page. |
|
| 1154 | - * |
|
| 1155 | - * @param string|array $value |
|
| 1156 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1157 | - */ |
|
| 1158 | - public static function sanitizeHTML($value) { |
|
| 1159 | - if (is_array($value)) { |
|
| 1160 | - $value = array_map(function($value) { |
|
| 1161 | - return self::sanitizeHTML($value); |
|
| 1162 | - }, $value); |
|
| 1163 | - } else { |
|
| 1164 | - // Specify encoding for PHP<5.4 |
|
| 1165 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1166 | - } |
|
| 1167 | - return $value; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * Public function to encode url parameters |
|
| 1172 | - * |
|
| 1173 | - * This function is used to encode path to file before output. |
|
| 1174 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1175 | - * Character '/' is preserved as is. |
|
| 1176 | - * |
|
| 1177 | - * @param string $component part of URI to encode |
|
| 1178 | - * @return string |
|
| 1179 | - */ |
|
| 1180 | - public static function encodePath($component) { |
|
| 1181 | - $encoded = rawurlencode($component); |
|
| 1182 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1183 | - return $encoded; |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1188 | - // php dev server does not support htaccess |
|
| 1189 | - if (php_sapi_name() === 'cli-server') { |
|
| 1190 | - return false; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - // testdata |
|
| 1194 | - $fileName = '/htaccesstest.txt'; |
|
| 1195 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1196 | - |
|
| 1197 | - // creating a test file |
|
| 1198 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1199 | - |
|
| 1200 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1201 | - return false; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - $fp = @fopen($testFile, 'w'); |
|
| 1205 | - if (!$fp) { |
|
| 1206 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1207 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1208 | - } |
|
| 1209 | - fwrite($fp, $testContent); |
|
| 1210 | - fclose($fp); |
|
| 1211 | - |
|
| 1212 | - return $testContent; |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * Check if the .htaccess file is working |
|
| 1217 | - * @param \OCP\IConfig $config |
|
| 1218 | - * @return bool |
|
| 1219 | - * @throws Exception |
|
| 1220 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1221 | - */ |
|
| 1222 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1223 | - |
|
| 1224 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1225 | - return true; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1229 | - if ($testContent === false) { |
|
| 1230 | - return false; |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - $fileName = '/htaccesstest.txt'; |
|
| 1234 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1235 | - |
|
| 1236 | - // accessing the file via http |
|
| 1237 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1238 | - try { |
|
| 1239 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1240 | - } catch (\Exception $e) { |
|
| 1241 | - $content = false; |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - // cleanup |
|
| 1245 | - @unlink($testFile); |
|
| 1246 | - |
|
| 1247 | - /* |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + // Check if there is a writable install folder. |
|
| 738 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 739 | + if (OC_App::getInstallPath() === null |
|
| 740 | + || !is_writable(OC_App::getInstallPath()) |
|
| 741 | + || !is_readable(OC_App::getInstallPath()) |
|
| 742 | + ) { |
|
| 743 | + $errors[] = array( |
|
| 744 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 745 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the apps directory' |
|
| 746 | + . ' or disabling the appstore in the config file. See %s', |
|
| 747 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 748 | + ); |
|
| 749 | + } |
|
| 750 | + } |
|
| 751 | + // Create root dir. |
|
| 752 | + if ($config->getValue('installed', false)) { |
|
| 753 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 754 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 755 | + if ($success) { |
|
| 756 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 757 | + } else { |
|
| 758 | + $errors[] = [ |
|
| 759 | + 'error' => $l->t('Cannot create "data" directory'), |
|
| 760 | + 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the root directory. See %s', |
|
| 761 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 762 | + ]; |
|
| 763 | + } |
|
| 764 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 765 | + //common hint for all file permissions error messages |
|
| 766 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.', |
|
| 767 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 768 | + $errors[] = [ |
|
| 769 | + 'error' => 'Your data directory is not writable', |
|
| 770 | + 'hint' => $permissionsHint |
|
| 771 | + ]; |
|
| 772 | + } else { |
|
| 773 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 778 | + $errors[] = array( |
|
| 779 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 780 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 781 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 782 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 783 | + ); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // Contains the dependencies that should be checked against |
|
| 787 | + // classes = class_exists |
|
| 788 | + // functions = function_exists |
|
| 789 | + // defined = defined |
|
| 790 | + // ini = ini_get |
|
| 791 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 792 | + // When adding new checks always verify that they pass on Travis as well |
|
| 793 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 794 | + $dependencies = array( |
|
| 795 | + 'classes' => array( |
|
| 796 | + 'ZipArchive' => 'zip', |
|
| 797 | + 'DOMDocument' => 'dom', |
|
| 798 | + 'XMLWriter' => 'XMLWriter', |
|
| 799 | + 'XMLReader' => 'XMLReader', |
|
| 800 | + ), |
|
| 801 | + 'functions' => [ |
|
| 802 | + 'xml_parser_create' => 'libxml', |
|
| 803 | + 'mb_strcut' => 'mb multibyte', |
|
| 804 | + 'ctype_digit' => 'ctype', |
|
| 805 | + 'json_encode' => 'JSON', |
|
| 806 | + 'gd_info' => 'GD', |
|
| 807 | + 'gzencode' => 'zlib', |
|
| 808 | + 'iconv' => 'iconv', |
|
| 809 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 810 | + 'hash' => 'HASH Message Digest Framework', |
|
| 811 | + 'curl_init' => 'cURL', |
|
| 812 | + 'openssl_verify' => 'OpenSSL', |
|
| 813 | + ], |
|
| 814 | + 'defined' => array( |
|
| 815 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 816 | + ), |
|
| 817 | + 'ini' => [ |
|
| 818 | + 'default_charset' => 'UTF-8', |
|
| 819 | + ], |
|
| 820 | + ); |
|
| 821 | + $missingDependencies = array(); |
|
| 822 | + $invalidIniSettings = []; |
|
| 823 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 827 | + * and prevents installation. Once HHVM is more compatible with our |
|
| 828 | + * approach to check for these values we should re-enable those |
|
| 829 | + * checks. |
|
| 830 | + */ |
|
| 831 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 832 | + if (!self::runningOnHhvm()) { |
|
| 833 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 834 | + if (!class_exists($class)) { |
|
| 835 | + $missingDependencies[] = $module; |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 839 | + if (!function_exists($function)) { |
|
| 840 | + $missingDependencies[] = $module; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 844 | + if (!defined($defined)) { |
|
| 845 | + $missingDependencies[] = $module; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 849 | + if (is_bool($expected)) { |
|
| 850 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 851 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + if (is_int($expected)) { |
|
| 855 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 856 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + if (is_string($expected)) { |
|
| 860 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 861 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + foreach($missingDependencies as $missingDependency) { |
|
| 868 | + $errors[] = array( |
|
| 869 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 870 | + 'hint' => $moduleHint |
|
| 871 | + ); |
|
| 872 | + $webServerRestart = true; |
|
| 873 | + } |
|
| 874 | + foreach($invalidIniSettings as $setting) { |
|
| 875 | + if(is_bool($setting[1])) { |
|
| 876 | + $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 877 | + } |
|
| 878 | + $errors[] = [ |
|
| 879 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 880 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 881 | + ]; |
|
| 882 | + $webServerRestart = true; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 887 | + * module is installed as it will return null if the checking setting is |
|
| 888 | + * not available and thus a check on the boolean value fails. |
|
| 889 | + * |
|
| 890 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 891 | + * check somehow in the long-term. |
|
| 892 | + */ |
|
| 893 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 894 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 895 | + $errors[] = array( |
|
| 896 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 897 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 898 | + ); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + if(function_exists('xml_parser_create') && |
|
| 902 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
| 903 | + $version = LIBXML_LOADED_VERSION; |
|
| 904 | + $major = floor($version/10000); |
|
| 905 | + $version -= ($major * 10000); |
|
| 906 | + $minor = floor($version/100); |
|
| 907 | + $version -= ($minor * 100); |
|
| 908 | + $patch = $version; |
|
| 909 | + $errors[] = array( |
|
| 910 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 911 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + if (!self::isAnnotationsWorking()) { |
|
| 916 | + $errors[] = array( |
|
| 917 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 918 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 919 | + ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 923 | + $errors[] = array( |
|
| 924 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 925 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 926 | + ); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 930 | + |
|
| 931 | + // Cache the result of this function |
|
| 932 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 933 | + |
|
| 934 | + return $errors; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * Check the database version |
|
| 939 | + * |
|
| 940 | + * @return array errors array |
|
| 941 | + */ |
|
| 942 | + public static function checkDatabaseVersion() { |
|
| 943 | + $l = \OC::$server->getL10N('lib'); |
|
| 944 | + $errors = array(); |
|
| 945 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 946 | + if ($dbType === 'pgsql') { |
|
| 947 | + // check PostgreSQL version |
|
| 948 | + try { |
|
| 949 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 950 | + $data = $result->fetchRow(); |
|
| 951 | + if (isset($data['server_version'])) { |
|
| 952 | + $version = $data['server_version']; |
|
| 953 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 954 | + $errors[] = array( |
|
| 955 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 956 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 957 | + ); |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 961 | + $logger = \OC::$server->getLogger(); |
|
| 962 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 963 | + $logger->logException($e); |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + return $errors; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * Check for correct file permissions of data directory |
|
| 971 | + * |
|
| 972 | + * @param string $dataDirectory |
|
| 973 | + * @return array arrays with error messages and hints |
|
| 974 | + */ |
|
| 975 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 976 | + if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 977 | + return []; |
|
| 978 | + } |
|
| 979 | + $l = \OC::$server->getL10N('lib'); |
|
| 980 | + $errors = []; |
|
| 981 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 982 | + . ' cannot be listed by other users.'); |
|
| 983 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 984 | + if (substr($perms, -1) !== '0') { |
|
| 985 | + chmod($dataDirectory, 0770); |
|
| 986 | + clearstatcache(); |
|
| 987 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 988 | + if ($perms[2] !== '0') { |
|
| 989 | + $errors[] = [ |
|
| 990 | + 'error' => $l->t('Your data directory is readable by other users'), |
|
| 991 | + 'hint' => $permissionsModHint |
|
| 992 | + ]; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + return $errors; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * Check that the data directory exists and is valid by |
|
| 1000 | + * checking the existence of the ".ocdata" file. |
|
| 1001 | + * |
|
| 1002 | + * @param string $dataDirectory data directory path |
|
| 1003 | + * @return array errors found |
|
| 1004 | + */ |
|
| 1005 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 1006 | + $l = \OC::$server->getL10N('lib'); |
|
| 1007 | + $errors = []; |
|
| 1008 | + if ($dataDirectory[0] !== '/') { |
|
| 1009 | + $errors[] = [ |
|
| 1010 | + 'error' => $l->t('Your data directory must be an absolute path'), |
|
| 1011 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 1012 | + ]; |
|
| 1013 | + } |
|
| 1014 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1015 | + $errors[] = [ |
|
| 1016 | + 'error' => $l->t('Your data directory is invalid'), |
|
| 1017 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1018 | + ' in the root of the data directory.') |
|
| 1019 | + ]; |
|
| 1020 | + } |
|
| 1021 | + return $errors; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + /** |
|
| 1025 | + * Check if the user is logged in, redirects to home if not. With |
|
| 1026 | + * redirect URL parameter to the request URI. |
|
| 1027 | + * |
|
| 1028 | + * @return void |
|
| 1029 | + */ |
|
| 1030 | + public static function checkLoggedIn() { |
|
| 1031 | + // Check if we are a user |
|
| 1032 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1033 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1034 | + 'core.login.showLoginForm', |
|
| 1035 | + [ |
|
| 1036 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 1037 | + ] |
|
| 1038 | + ) |
|
| 1039 | + ); |
|
| 1040 | + exit(); |
|
| 1041 | + } |
|
| 1042 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 1043 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 1044 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1045 | + exit(); |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * Check if the user is a admin, redirects to home if not |
|
| 1051 | + * |
|
| 1052 | + * @return void |
|
| 1053 | + */ |
|
| 1054 | + public static function checkAdminUser() { |
|
| 1055 | + OC_Util::checkLoggedIn(); |
|
| 1056 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 1057 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1058 | + exit(); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Check if the user is a subadmin, redirects to home if not |
|
| 1064 | + * |
|
| 1065 | + * @return null|boolean $groups where the current user is subadmin |
|
| 1066 | + */ |
|
| 1067 | + public static function checkSubAdminUser() { |
|
| 1068 | + OC_Util::checkLoggedIn(); |
|
| 1069 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1070 | + $isSubAdmin = false; |
|
| 1071 | + if($userObject !== null) { |
|
| 1072 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + if (!$isSubAdmin) { |
|
| 1076 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1077 | + exit(); |
|
| 1078 | + } |
|
| 1079 | + return true; |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * Returns the URL of the default page |
|
| 1084 | + * based on the system configuration and |
|
| 1085 | + * the apps visible for the current user |
|
| 1086 | + * |
|
| 1087 | + * @return string URL |
|
| 1088 | + * @suppress PhanDeprecatedFunction |
|
| 1089 | + */ |
|
| 1090 | + public static function getDefaultPageUrl() { |
|
| 1091 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1092 | + // Deny the redirect if the URL contains a @ |
|
| 1093 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1094 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1095 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1096 | + } else { |
|
| 1097 | + $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); |
|
| 1098 | + if ($defaultPage) { |
|
| 1099 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1100 | + } else { |
|
| 1101 | + $appId = 'files'; |
|
| 1102 | + $config = \OC::$server->getConfig(); |
|
| 1103 | + $defaultApps = explode(',', $config->getSystemValue('defaultapp', 'files')); |
|
| 1104 | + // find the first app that is enabled for the current user |
|
| 1105 | + foreach ($defaultApps as $defaultApp) { |
|
| 1106 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1107 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1108 | + $appId = $defaultApp; |
|
| 1109 | + break; |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1114 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1115 | + } else { |
|
| 1116 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + return $location; |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * Redirect to the user default page |
|
| 1125 | + * |
|
| 1126 | + * @return void |
|
| 1127 | + */ |
|
| 1128 | + public static function redirectToDefaultPage() { |
|
| 1129 | + $location = self::getDefaultPageUrl(); |
|
| 1130 | + header('Location: ' . $location); |
|
| 1131 | + exit(); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * get an id unique for this instance |
|
| 1136 | + * |
|
| 1137 | + * @return string |
|
| 1138 | + */ |
|
| 1139 | + public static function getInstanceId() { |
|
| 1140 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1141 | + if (is_null($id)) { |
|
| 1142 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1143 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1144 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1145 | + } |
|
| 1146 | + return $id; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Public function to sanitize HTML |
|
| 1151 | + * |
|
| 1152 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1153 | + * string or array of strings before displaying it on a web page. |
|
| 1154 | + * |
|
| 1155 | + * @param string|array $value |
|
| 1156 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1157 | + */ |
|
| 1158 | + public static function sanitizeHTML($value) { |
|
| 1159 | + if (is_array($value)) { |
|
| 1160 | + $value = array_map(function($value) { |
|
| 1161 | + return self::sanitizeHTML($value); |
|
| 1162 | + }, $value); |
|
| 1163 | + } else { |
|
| 1164 | + // Specify encoding for PHP<5.4 |
|
| 1165 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1166 | + } |
|
| 1167 | + return $value; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * Public function to encode url parameters |
|
| 1172 | + * |
|
| 1173 | + * This function is used to encode path to file before output. |
|
| 1174 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1175 | + * Character '/' is preserved as is. |
|
| 1176 | + * |
|
| 1177 | + * @param string $component part of URI to encode |
|
| 1178 | + * @return string |
|
| 1179 | + */ |
|
| 1180 | + public static function encodePath($component) { |
|
| 1181 | + $encoded = rawurlencode($component); |
|
| 1182 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1183 | + return $encoded; |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1188 | + // php dev server does not support htaccess |
|
| 1189 | + if (php_sapi_name() === 'cli-server') { |
|
| 1190 | + return false; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + // testdata |
|
| 1194 | + $fileName = '/htaccesstest.txt'; |
|
| 1195 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1196 | + |
|
| 1197 | + // creating a test file |
|
| 1198 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1199 | + |
|
| 1200 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1201 | + return false; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + $fp = @fopen($testFile, 'w'); |
|
| 1205 | + if (!$fp) { |
|
| 1206 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1207 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1208 | + } |
|
| 1209 | + fwrite($fp, $testContent); |
|
| 1210 | + fclose($fp); |
|
| 1211 | + |
|
| 1212 | + return $testContent; |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * Check if the .htaccess file is working |
|
| 1217 | + * @param \OCP\IConfig $config |
|
| 1218 | + * @return bool |
|
| 1219 | + * @throws Exception |
|
| 1220 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1221 | + */ |
|
| 1222 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1223 | + |
|
| 1224 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1225 | + return true; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1229 | + if ($testContent === false) { |
|
| 1230 | + return false; |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + $fileName = '/htaccesstest.txt'; |
|
| 1234 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1235 | + |
|
| 1236 | + // accessing the file via http |
|
| 1237 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1238 | + try { |
|
| 1239 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1240 | + } catch (\Exception $e) { |
|
| 1241 | + $content = false; |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + // cleanup |
|
| 1245 | + @unlink($testFile); |
|
| 1246 | + |
|
| 1247 | + /* |
|
| 1248 | 1248 | * If the content is not equal to test content our .htaccess |
| 1249 | 1249 | * is working as required |
| 1250 | 1250 | */ |
| 1251 | - return $content !== $testContent; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1256 | - * local packages are not available on the server. |
|
| 1257 | - * |
|
| 1258 | - * @return bool |
|
| 1259 | - */ |
|
| 1260 | - public static function isSetLocaleWorking() { |
|
| 1261 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1262 | - if ('' === basename('§')) { |
|
| 1263 | - return false; |
|
| 1264 | - } |
|
| 1265 | - return true; |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * Check if it's possible to get the inline annotations |
|
| 1270 | - * |
|
| 1271 | - * @return bool |
|
| 1272 | - */ |
|
| 1273 | - public static function isAnnotationsWorking() { |
|
| 1274 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1275 | - $docs = $reflection->getDocComment(); |
|
| 1276 | - |
|
| 1277 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * Check if the PHP module fileinfo is loaded. |
|
| 1282 | - * |
|
| 1283 | - * @return bool |
|
| 1284 | - */ |
|
| 1285 | - public static function fileInfoLoaded() { |
|
| 1286 | - return function_exists('finfo_open'); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * clear all levels of output buffering |
|
| 1291 | - * |
|
| 1292 | - * @return void |
|
| 1293 | - */ |
|
| 1294 | - public static function obEnd() { |
|
| 1295 | - while (ob_get_level()) { |
|
| 1296 | - ob_end_clean(); |
|
| 1297 | - } |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - /** |
|
| 1301 | - * Checks whether the server is running on Mac OS X |
|
| 1302 | - * |
|
| 1303 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1304 | - */ |
|
| 1305 | - public static function runningOnMac() { |
|
| 1306 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Checks whether server is running on HHVM |
|
| 1311 | - * |
|
| 1312 | - * @return bool True if running on HHVM, false otherwise |
|
| 1313 | - */ |
|
| 1314 | - public static function runningOnHhvm() { |
|
| 1315 | - return defined('HHVM_VERSION'); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1320 | - * theme exists and take that one |
|
| 1321 | - * |
|
| 1322 | - * @return string the theme |
|
| 1323 | - */ |
|
| 1324 | - public static function getTheme() { |
|
| 1325 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1326 | - |
|
| 1327 | - if ($theme === '') { |
|
| 1328 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1329 | - $theme = 'default'; |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - return $theme; |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * Clear a single file from the opcode cache |
|
| 1338 | - * This is useful for writing to the config file |
|
| 1339 | - * in case the opcode cache does not re-validate files |
|
| 1340 | - * Returns true if successful, false if unsuccessful: |
|
| 1341 | - * caller should fall back on clearing the entire cache |
|
| 1342 | - * with clearOpcodeCache() if unsuccessful |
|
| 1343 | - * |
|
| 1344 | - * @param string $path the path of the file to clear from the cache |
|
| 1345 | - * @return bool true if underlying function returns true, otherwise false |
|
| 1346 | - */ |
|
| 1347 | - public static function deleteFromOpcodeCache($path) { |
|
| 1348 | - $ret = false; |
|
| 1349 | - if ($path) { |
|
| 1350 | - // APC >= 3.1.1 |
|
| 1351 | - if (function_exists('apc_delete_file')) { |
|
| 1352 | - $ret = @apc_delete_file($path); |
|
| 1353 | - } |
|
| 1354 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1355 | - if (function_exists('opcache_invalidate')) { |
|
| 1356 | - $ret = opcache_invalidate($path); |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - return $ret; |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Clear the opcode cache if one exists |
|
| 1364 | - * This is necessary for writing to the config file |
|
| 1365 | - * in case the opcode cache does not re-validate files |
|
| 1366 | - * |
|
| 1367 | - * @return void |
|
| 1368 | - * @suppress PhanDeprecatedFunction |
|
| 1369 | - * @suppress PhanUndeclaredConstant |
|
| 1370 | - */ |
|
| 1371 | - public static function clearOpcodeCache() { |
|
| 1372 | - // APC |
|
| 1373 | - if (function_exists('apc_clear_cache')) { |
|
| 1374 | - apc_clear_cache(); |
|
| 1375 | - } |
|
| 1376 | - // Zend Opcache |
|
| 1377 | - if (function_exists('accelerator_reset')) { |
|
| 1378 | - accelerator_reset(); |
|
| 1379 | - } |
|
| 1380 | - // XCache |
|
| 1381 | - if (function_exists('xcache_clear_cache')) { |
|
| 1382 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1383 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1384 | - } else { |
|
| 1385 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - // Opcache (PHP >= 5.5) |
|
| 1389 | - if (function_exists('opcache_reset')) { |
|
| 1390 | - opcache_reset(); |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - /** |
|
| 1395 | - * Normalize a unicode string |
|
| 1396 | - * |
|
| 1397 | - * @param string $value a not normalized string |
|
| 1398 | - * @return bool|string |
|
| 1399 | - */ |
|
| 1400 | - public static function normalizeUnicode($value) { |
|
| 1401 | - if(Normalizer::isNormalized($value)) { |
|
| 1402 | - return $value; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1406 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1407 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1408 | - return $value; |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - return $normalizedValue; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - /** |
|
| 1415 | - * A human readable string is generated based on version and build number |
|
| 1416 | - * |
|
| 1417 | - * @return string |
|
| 1418 | - */ |
|
| 1419 | - public static function getHumanVersion() { |
|
| 1420 | - $version = OC_Util::getVersionString(); |
|
| 1421 | - $build = OC_Util::getBuild(); |
|
| 1422 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1423 | - $version .= ' Build:' . $build; |
|
| 1424 | - } |
|
| 1425 | - return $version; |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * Returns whether the given file name is valid |
|
| 1430 | - * |
|
| 1431 | - * @param string $file file name to check |
|
| 1432 | - * @return bool true if the file name is valid, false otherwise |
|
| 1433 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1434 | - */ |
|
| 1435 | - public static function isValidFileName($file) { |
|
| 1436 | - $trimmed = trim($file); |
|
| 1437 | - if ($trimmed === '') { |
|
| 1438 | - return false; |
|
| 1439 | - } |
|
| 1440 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1441 | - return false; |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - // detect part files |
|
| 1445 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1446 | - return false; |
|
| 1447 | - } |
|
| 1448 | - |
|
| 1449 | - foreach (str_split($trimmed) as $char) { |
|
| 1450 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1451 | - return false; |
|
| 1452 | - } |
|
| 1453 | - } |
|
| 1454 | - return true; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * Check whether the instance needs to perform an upgrade, |
|
| 1459 | - * either when the core version is higher or any app requires |
|
| 1460 | - * an upgrade. |
|
| 1461 | - * |
|
| 1462 | - * @param \OC\SystemConfig $config |
|
| 1463 | - * @return bool whether the core or any app needs an upgrade |
|
| 1464 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1465 | - */ |
|
| 1466 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1467 | - if ($config->getValue('installed', false)) { |
|
| 1468 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1469 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1470 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1471 | - if ($versionDiff > 0) { |
|
| 1472 | - return true; |
|
| 1473 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1474 | - // downgrade with debug |
|
| 1475 | - $installedMajor = explode('.', $installedVersion); |
|
| 1476 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1477 | - $currentMajor = explode('.', $currentVersion); |
|
| 1478 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1479 | - if ($installedMajor === $currentMajor) { |
|
| 1480 | - // Same major, allow downgrade for developers |
|
| 1481 | - return true; |
|
| 1482 | - } else { |
|
| 1483 | - // downgrade attempt, throw exception |
|
| 1484 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1485 | - } |
|
| 1486 | - } else if ($versionDiff < 0) { |
|
| 1487 | - // downgrade attempt, throw exception |
|
| 1488 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - // also check for upgrades for apps (independently from the user) |
|
| 1492 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1493 | - $shouldUpgrade = false; |
|
| 1494 | - foreach ($apps as $app) { |
|
| 1495 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1496 | - $shouldUpgrade = true; |
|
| 1497 | - break; |
|
| 1498 | - } |
|
| 1499 | - } |
|
| 1500 | - return $shouldUpgrade; |
|
| 1501 | - } else { |
|
| 1502 | - return false; |
|
| 1503 | - } |
|
| 1504 | - } |
|
| 1251 | + return $content !== $testContent; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1256 | + * local packages are not available on the server. |
|
| 1257 | + * |
|
| 1258 | + * @return bool |
|
| 1259 | + */ |
|
| 1260 | + public static function isSetLocaleWorking() { |
|
| 1261 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1262 | + if ('' === basename('§')) { |
|
| 1263 | + return false; |
|
| 1264 | + } |
|
| 1265 | + return true; |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * Check if it's possible to get the inline annotations |
|
| 1270 | + * |
|
| 1271 | + * @return bool |
|
| 1272 | + */ |
|
| 1273 | + public static function isAnnotationsWorking() { |
|
| 1274 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1275 | + $docs = $reflection->getDocComment(); |
|
| 1276 | + |
|
| 1277 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * Check if the PHP module fileinfo is loaded. |
|
| 1282 | + * |
|
| 1283 | + * @return bool |
|
| 1284 | + */ |
|
| 1285 | + public static function fileInfoLoaded() { |
|
| 1286 | + return function_exists('finfo_open'); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * clear all levels of output buffering |
|
| 1291 | + * |
|
| 1292 | + * @return void |
|
| 1293 | + */ |
|
| 1294 | + public static function obEnd() { |
|
| 1295 | + while (ob_get_level()) { |
|
| 1296 | + ob_end_clean(); |
|
| 1297 | + } |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + /** |
|
| 1301 | + * Checks whether the server is running on Mac OS X |
|
| 1302 | + * |
|
| 1303 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1304 | + */ |
|
| 1305 | + public static function runningOnMac() { |
|
| 1306 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Checks whether server is running on HHVM |
|
| 1311 | + * |
|
| 1312 | + * @return bool True if running on HHVM, false otherwise |
|
| 1313 | + */ |
|
| 1314 | + public static function runningOnHhvm() { |
|
| 1315 | + return defined('HHVM_VERSION'); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1320 | + * theme exists and take that one |
|
| 1321 | + * |
|
| 1322 | + * @return string the theme |
|
| 1323 | + */ |
|
| 1324 | + public static function getTheme() { |
|
| 1325 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1326 | + |
|
| 1327 | + if ($theme === '') { |
|
| 1328 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1329 | + $theme = 'default'; |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + return $theme; |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * Clear a single file from the opcode cache |
|
| 1338 | + * This is useful for writing to the config file |
|
| 1339 | + * in case the opcode cache does not re-validate files |
|
| 1340 | + * Returns true if successful, false if unsuccessful: |
|
| 1341 | + * caller should fall back on clearing the entire cache |
|
| 1342 | + * with clearOpcodeCache() if unsuccessful |
|
| 1343 | + * |
|
| 1344 | + * @param string $path the path of the file to clear from the cache |
|
| 1345 | + * @return bool true if underlying function returns true, otherwise false |
|
| 1346 | + */ |
|
| 1347 | + public static function deleteFromOpcodeCache($path) { |
|
| 1348 | + $ret = false; |
|
| 1349 | + if ($path) { |
|
| 1350 | + // APC >= 3.1.1 |
|
| 1351 | + if (function_exists('apc_delete_file')) { |
|
| 1352 | + $ret = @apc_delete_file($path); |
|
| 1353 | + } |
|
| 1354 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1355 | + if (function_exists('opcache_invalidate')) { |
|
| 1356 | + $ret = opcache_invalidate($path); |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + return $ret; |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Clear the opcode cache if one exists |
|
| 1364 | + * This is necessary for writing to the config file |
|
| 1365 | + * in case the opcode cache does not re-validate files |
|
| 1366 | + * |
|
| 1367 | + * @return void |
|
| 1368 | + * @suppress PhanDeprecatedFunction |
|
| 1369 | + * @suppress PhanUndeclaredConstant |
|
| 1370 | + */ |
|
| 1371 | + public static function clearOpcodeCache() { |
|
| 1372 | + // APC |
|
| 1373 | + if (function_exists('apc_clear_cache')) { |
|
| 1374 | + apc_clear_cache(); |
|
| 1375 | + } |
|
| 1376 | + // Zend Opcache |
|
| 1377 | + if (function_exists('accelerator_reset')) { |
|
| 1378 | + accelerator_reset(); |
|
| 1379 | + } |
|
| 1380 | + // XCache |
|
| 1381 | + if (function_exists('xcache_clear_cache')) { |
|
| 1382 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1383 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1384 | + } else { |
|
| 1385 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + // Opcache (PHP >= 5.5) |
|
| 1389 | + if (function_exists('opcache_reset')) { |
|
| 1390 | + opcache_reset(); |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + /** |
|
| 1395 | + * Normalize a unicode string |
|
| 1396 | + * |
|
| 1397 | + * @param string $value a not normalized string |
|
| 1398 | + * @return bool|string |
|
| 1399 | + */ |
|
| 1400 | + public static function normalizeUnicode($value) { |
|
| 1401 | + if(Normalizer::isNormalized($value)) { |
|
| 1402 | + return $value; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1406 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1407 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1408 | + return $value; |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + return $normalizedValue; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + /** |
|
| 1415 | + * A human readable string is generated based on version and build number |
|
| 1416 | + * |
|
| 1417 | + * @return string |
|
| 1418 | + */ |
|
| 1419 | + public static function getHumanVersion() { |
|
| 1420 | + $version = OC_Util::getVersionString(); |
|
| 1421 | + $build = OC_Util::getBuild(); |
|
| 1422 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1423 | + $version .= ' Build:' . $build; |
|
| 1424 | + } |
|
| 1425 | + return $version; |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * Returns whether the given file name is valid |
|
| 1430 | + * |
|
| 1431 | + * @param string $file file name to check |
|
| 1432 | + * @return bool true if the file name is valid, false otherwise |
|
| 1433 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1434 | + */ |
|
| 1435 | + public static function isValidFileName($file) { |
|
| 1436 | + $trimmed = trim($file); |
|
| 1437 | + if ($trimmed === '') { |
|
| 1438 | + return false; |
|
| 1439 | + } |
|
| 1440 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1441 | + return false; |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + // detect part files |
|
| 1445 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1446 | + return false; |
|
| 1447 | + } |
|
| 1448 | + |
|
| 1449 | + foreach (str_split($trimmed) as $char) { |
|
| 1450 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1451 | + return false; |
|
| 1452 | + } |
|
| 1453 | + } |
|
| 1454 | + return true; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * Check whether the instance needs to perform an upgrade, |
|
| 1459 | + * either when the core version is higher or any app requires |
|
| 1460 | + * an upgrade. |
|
| 1461 | + * |
|
| 1462 | + * @param \OC\SystemConfig $config |
|
| 1463 | + * @return bool whether the core or any app needs an upgrade |
|
| 1464 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1465 | + */ |
|
| 1466 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1467 | + if ($config->getValue('installed', false)) { |
|
| 1468 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1469 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1470 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1471 | + if ($versionDiff > 0) { |
|
| 1472 | + return true; |
|
| 1473 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1474 | + // downgrade with debug |
|
| 1475 | + $installedMajor = explode('.', $installedVersion); |
|
| 1476 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1477 | + $currentMajor = explode('.', $currentVersion); |
|
| 1478 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1479 | + if ($installedMajor === $currentMajor) { |
|
| 1480 | + // Same major, allow downgrade for developers |
|
| 1481 | + return true; |
|
| 1482 | + } else { |
|
| 1483 | + // downgrade attempt, throw exception |
|
| 1484 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1485 | + } |
|
| 1486 | + } else if ($versionDiff < 0) { |
|
| 1487 | + // downgrade attempt, throw exception |
|
| 1488 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + // also check for upgrades for apps (independently from the user) |
|
| 1492 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1493 | + $shouldUpgrade = false; |
|
| 1494 | + foreach ($apps as $app) { |
|
| 1495 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1496 | + $shouldUpgrade = true; |
|
| 1497 | + break; |
|
| 1498 | + } |
|
| 1499 | + } |
|
| 1500 | + return $shouldUpgrade; |
|
| 1501 | + } else { |
|
| 1502 | + return false; |
|
| 1503 | + } |
|
| 1504 | + } |
|
| 1505 | 1505 | |
| 1506 | 1506 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | private static function initLocalStorageRootFS() { |
| 82 | 82 | // mount local file backend as root |
| 83 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 83 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT."/data"); |
|
| 84 | 84 | //first set up the local "root" storage |
| 85 | 85 | \OC\Files\Filesystem::initMountManager(); |
| 86 | 86 | if (!self::$rootMounted) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | \OC\Files\Filesystem::initMountManager(); |
| 203 | 203 | |
| 204 | 204 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 205 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 205 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 206 | 206 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
| 207 | 207 | /** @var \OC\Files\Storage\Common $storage */ |
| 208 | 208 | $storage->setMountOptions($mount->getOptions()); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | return $storage; |
| 211 | 211 | }); |
| 212 | 212 | |
| 213 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 213 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 214 | 214 | if (!$mount->getOption('enable_sharing', true)) { |
| 215 | 215 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
| 216 | 216 | 'storage' => $storage, |
@@ -221,21 +221,21 @@ discard block |
||
| 221 | 221 | }); |
| 222 | 222 | |
| 223 | 223 | // install storage availability wrapper, before most other wrappers |
| 224 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 224 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 225 | 225 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 226 | 226 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
| 227 | 227 | } |
| 228 | 228 | return $storage; |
| 229 | 229 | }); |
| 230 | 230 | |
| 231 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 231 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 232 | 232 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 233 | 233 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
| 234 | 234 | } |
| 235 | 235 | return $storage; |
| 236 | 236 | }); |
| 237 | 237 | |
| 238 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 238 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 239 | 239 | // set up quota for home storages, even for other users |
| 240 | 240 | // which can happen when using sharing |
| 241 | 241 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | //if we aren't logged in, there is no use to set up the filesystem |
| 283 | 283 | if ($user != "") { |
| 284 | 284 | |
| 285 | - $userDir = '/' . $user . '/files'; |
|
| 285 | + $userDir = '/'.$user.'/files'; |
|
| 286 | 286 | |
| 287 | 287 | //jail the user into his "home" directory |
| 288 | 288 | \OC\Files\Filesystem::init($user, $userDir); |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 363 | 363 | } |
| 364 | 364 | $userQuota = $user->getQuota(); |
| 365 | - if($userQuota === 'none') { |
|
| 365 | + if ($userQuota === 'none') { |
|
| 366 | 366 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 367 | 367 | } |
| 368 | 368 | return OC_Helper::computerFileSize($userQuota); |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
| 380 | 380 | |
| 381 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 381 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
| 382 | 382 | $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
| 383 | 383 | $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
| 384 | 384 | |
@@ -400,9 +400,9 @@ discard block |
||
| 400 | 400 | if ($instanceId === null) { |
| 401 | 401 | throw new \RuntimeException('no instance id!'); |
| 402 | 402 | } |
| 403 | - $appdata = 'appdata_' . $instanceId; |
|
| 403 | + $appdata = 'appdata_'.$instanceId; |
|
| 404 | 404 | if ($userId === $appdata) { |
| 405 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 405 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | if (!empty($skeletonDirectory)) { |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | |
| 430 | 430 | // Verify if folder exists |
| 431 | 431 | $dir = opendir($source); |
| 432 | - if($dir === false) { |
|
| 432 | + if ($dir === false) { |
|
| 433 | 433 | $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
| 434 | 434 | return; |
| 435 | 435 | } |
@@ -437,14 +437,14 @@ discard block |
||
| 437 | 437 | // Copy the files |
| 438 | 438 | while (false !== ($file = readdir($dir))) { |
| 439 | 439 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
| 440 | - if (is_dir($source . '/' . $file)) { |
|
| 440 | + if (is_dir($source.'/'.$file)) { |
|
| 441 | 441 | $child = $target->newFolder($file); |
| 442 | - self::copyr($source . '/' . $file, $child); |
|
| 442 | + self::copyr($source.'/'.$file, $child); |
|
| 443 | 443 | } else { |
| 444 | 444 | $child = $target->newFile($file); |
| 445 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 446 | - if($sourceStream === false) { |
|
| 447 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 445 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
| 446 | + if ($sourceStream === false) { |
|
| 447 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
| 448 | 448 | closedir($dir); |
| 449 | 449 | return; |
| 450 | 450 | } |
@@ -521,8 +521,8 @@ discard block |
||
| 521 | 521 | return; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 525 | - require OC::$SERVERROOT . '/version.php'; |
|
| 524 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
| 525 | + require OC::$SERVERROOT.'/version.php'; |
|
| 526 | 526 | /** @var $timestamp int */ |
| 527 | 527 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
| 528 | 528 | /** @var $OC_Version string */ |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | |
| 570 | 570 | // core js files need separate handling |
| 571 | 571 | if ($application !== 'core' && $file !== null) { |
| 572 | - self::addTranslations ( $application ); |
|
| 572 | + self::addTranslations($application); |
|
| 573 | 573 | } |
| 574 | 574 | self::addExternalResource($application, $prepend, $path, "script"); |
| 575 | 575 | } |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | if ($type === "style") { |
| 647 | 647 | if (!in_array($path, self::$styles)) { |
| 648 | 648 | if ($prepend === true) { |
| 649 | - array_unshift ( self::$styles, $path ); |
|
| 649 | + array_unshift(self::$styles, $path); |
|
| 650 | 650 | } else { |
| 651 | 651 | self::$styles[] = $path; |
| 652 | 652 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | } elseif ($type === "script") { |
| 655 | 655 | if (!in_array($path, self::$scripts)) { |
| 656 | 656 | if ($prepend === true) { |
| 657 | - array_unshift ( self::$scripts, $path ); |
|
| 657 | + array_unshift(self::$scripts, $path); |
|
| 658 | 658 | } else { |
| 659 | 659 | self::$scripts [] = $path; |
| 660 | 660 | } |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | * @param array $attributes array of attributes for the element |
| 671 | 671 | * @param string $text the text content for the element |
| 672 | 672 | */ |
| 673 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 673 | + public static function addHeader($tag, $attributes, $text = null) { |
|
| 674 | 674 | self::$headers[] = array( |
| 675 | 675 | 'tag' => $tag, |
| 676 | 676 | 'attributes' => $attributes, |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | public static function checkServer(\OC\SystemConfig $config) { |
| 688 | 688 | $l = \OC::$server->getL10N('lib'); |
| 689 | 689 | $errors = array(); |
| 690 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 690 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
| 691 | 691 | |
| 692 | 692 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
| 693 | 693 | // this check needs to be done every time |
@@ -722,14 +722,14 @@ discard block |
||
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // Check if config folder is writable. |
| 725 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 725 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 726 | 726 | if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
| 727 | 727 | $errors[] = array( |
| 728 | 728 | 'error' => $l->t('Cannot write into "config" directory'), |
| 729 | 729 | 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
| 730 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 730 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
| 731 | 731 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
| 732 | - [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
| 732 | + [$urlGenerator->linkToDocs('admin-config')]) |
|
| 733 | 733 | ); |
| 734 | 734 | } |
| 735 | 735 | } |
@@ -864,15 +864,15 @@ discard block |
||
| 864 | 864 | } |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | - foreach($missingDependencies as $missingDependency) { |
|
| 867 | + foreach ($missingDependencies as $missingDependency) { |
|
| 868 | 868 | $errors[] = array( |
| 869 | 869 | 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
| 870 | 870 | 'hint' => $moduleHint |
| 871 | 871 | ); |
| 872 | 872 | $webServerRestart = true; |
| 873 | 873 | } |
| 874 | - foreach($invalidIniSettings as $setting) { |
|
| 875 | - if(is_bool($setting[1])) { |
|
| 874 | + foreach ($invalidIniSettings as $setting) { |
|
| 875 | + if (is_bool($setting[1])) { |
|
| 876 | 876 | $setting[1] = $setting[1] ? 'on' : 'off'; |
| 877 | 877 | } |
| 878 | 878 | $errors[] = [ |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | * TODO: Should probably be implemented in the above generic dependency |
| 891 | 891 | * check somehow in the long-term. |
| 892 | 892 | */ |
| 893 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 893 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 894 | 894 | $iniWrapper->getBool('mbstring.func_overload') === true) { |
| 895 | 895 | $errors[] = array( |
| 896 | 896 | 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
@@ -898,16 +898,16 @@ discard block |
||
| 898 | 898 | ); |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - if(function_exists('xml_parser_create') && |
|
| 902 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 901 | + if (function_exists('xml_parser_create') && |
|
| 902 | + LIBXML_LOADED_VERSION < 20700) { |
|
| 903 | 903 | $version = LIBXML_LOADED_VERSION; |
| 904 | - $major = floor($version/10000); |
|
| 904 | + $major = floor($version / 10000); |
|
| 905 | 905 | $version -= ($major * 10000); |
| 906 | - $minor = floor($version/100); |
|
| 906 | + $minor = floor($version / 100); |
|
| 907 | 907 | $version -= ($minor * 100); |
| 908 | 908 | $patch = $version; |
| 909 | 909 | $errors[] = array( |
| 910 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 910 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
| 911 | 911 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
| 912 | 912 | ); |
| 913 | 913 | } |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | * @return array arrays with error messages and hints |
| 974 | 974 | */ |
| 975 | 975 | public static function checkDataDirectoryPermissions($dataDirectory) { |
| 976 | - if(\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 976 | + if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 977 | 977 | return []; |
| 978 | 978 | } |
| 979 | 979 | $l = \OC::$server->getL10N('lib'); |
@@ -1011,10 +1011,10 @@ discard block |
||
| 1011 | 1011 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
| 1012 | 1012 | ]; |
| 1013 | 1013 | } |
| 1014 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 1014 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
| 1015 | 1015 | $errors[] = [ |
| 1016 | 1016 | 'error' => $l->t('Your data directory is invalid'), |
| 1017 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 1017 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"'. |
|
| 1018 | 1018 | ' in the root of the data directory.') |
| 1019 | 1019 | ]; |
| 1020 | 1020 | } |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | public static function checkLoggedIn() { |
| 1031 | 1031 | // Check if we are a user |
| 1032 | 1032 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
| 1033 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 1033 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
| 1034 | 1034 | 'core.login.showLoginForm', |
| 1035 | 1035 | [ |
| 1036 | 1036 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | } |
| 1042 | 1042 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
| 1043 | 1043 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
| 1044 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1044 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 1045 | 1045 | exit(); |
| 1046 | 1046 | } |
| 1047 | 1047 | } |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | public static function checkAdminUser() { |
| 1055 | 1055 | OC_Util::checkLoggedIn(); |
| 1056 | 1056 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
| 1057 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1057 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1058 | 1058 | exit(); |
| 1059 | 1059 | } |
| 1060 | 1060 | } |
@@ -1068,12 +1068,12 @@ discard block |
||
| 1068 | 1068 | OC_Util::checkLoggedIn(); |
| 1069 | 1069 | $userObject = \OC::$server->getUserSession()->getUser(); |
| 1070 | 1070 | $isSubAdmin = false; |
| 1071 | - if($userObject !== null) { |
|
| 1071 | + if ($userObject !== null) { |
|
| 1072 | 1072 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | if (!$isSubAdmin) { |
| 1076 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1076 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1077 | 1077 | exit(); |
| 1078 | 1078 | } |
| 1079 | 1079 | return true; |
@@ -1110,10 +1110,10 @@ discard block |
||
| 1110 | 1110 | } |
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | - if($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1114 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1113 | + if ($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1114 | + $location = $urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
| 1115 | 1115 | } else { |
| 1116 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1116 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | */ |
| 1128 | 1128 | public static function redirectToDefaultPage() { |
| 1129 | 1129 | $location = self::getDefaultPageUrl(); |
| 1130 | - header('Location: ' . $location); |
|
| 1130 | + header('Location: '.$location); |
|
| 1131 | 1131 | exit(); |
| 1132 | 1132 | } |
| 1133 | 1133 | |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
| 1141 | 1141 | if (is_null($id)) { |
| 1142 | 1142 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
| 1143 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1143 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1144 | 1144 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
| 1145 | 1145 | } |
| 1146 | 1146 | return $id; |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | }, $value); |
| 1163 | 1163 | } else { |
| 1164 | 1164 | // Specify encoding for PHP<5.4 |
| 1165 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1165 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | return $value; |
| 1168 | 1168 | } |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
| 1196 | 1196 | |
| 1197 | 1197 | // creating a test file |
| 1198 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1198 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1199 | 1199 | |
| 1200 | 1200 | if (file_exists($testFile)) {// already running this test, possible recursive call |
| 1201 | 1201 | return false; |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | $fp = @fopen($testFile, 'w'); |
| 1205 | 1205 | if (!$fp) { |
| 1206 | 1206 | throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
| 1207 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1207 | + 'Make sure it is possible for the webserver to write to '.$testFile); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | fwrite($fp, $testContent); |
| 1210 | 1210 | fclose($fp); |
@@ -1231,10 +1231,10 @@ discard block |
||
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | $fileName = '/htaccesstest.txt'; |
| 1234 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1234 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1235 | 1235 | |
| 1236 | 1236 | // accessing the file via http |
| 1237 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1237 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
| 1238 | 1238 | try { |
| 1239 | 1239 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
| 1240 | 1240 | } catch (\Exception $e) { |
@@ -1325,7 +1325,7 @@ discard block |
||
| 1325 | 1325 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
| 1326 | 1326 | |
| 1327 | 1327 | if ($theme === '') { |
| 1328 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1328 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
| 1329 | 1329 | $theme = 'default'; |
| 1330 | 1330 | } |
| 1331 | 1331 | } |
@@ -1398,13 +1398,13 @@ discard block |
||
| 1398 | 1398 | * @return bool|string |
| 1399 | 1399 | */ |
| 1400 | 1400 | public static function normalizeUnicode($value) { |
| 1401 | - if(Normalizer::isNormalized($value)) { |
|
| 1401 | + if (Normalizer::isNormalized($value)) { |
|
| 1402 | 1402 | return $value; |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | $normalizedValue = Normalizer::normalize($value); |
| 1406 | 1406 | if ($normalizedValue === null || $normalizedValue === false) { |
| 1407 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1407 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
| 1408 | 1408 | return $value; |
| 1409 | 1409 | } |
| 1410 | 1410 | |
@@ -1420,7 +1420,7 @@ discard block |
||
| 1420 | 1420 | $version = OC_Util::getVersionString(); |
| 1421 | 1421 | $build = OC_Util::getBuild(); |
| 1422 | 1422 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
| 1423 | - $version .= ' Build:' . $build; |
|
| 1423 | + $version .= ' Build:'.$build; |
|
| 1424 | 1424 | } |
| 1425 | 1425 | return $version; |
| 1426 | 1426 | } |
@@ -1442,7 +1442,7 @@ discard block |
||
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | 1444 | // detect part files |
| 1445 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1445 | + if (preg_match('/'.\OCP\Files\FileInfo::BLACKLIST_FILES_REGEX.'/', $trimmed) !== 0) { |
|
| 1446 | 1446 | return false; |
| 1447 | 1447 | } |
| 1448 | 1448 | |
@@ -1473,19 +1473,19 @@ discard block |
||
| 1473 | 1473 | } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
| 1474 | 1474 | // downgrade with debug |
| 1475 | 1475 | $installedMajor = explode('.', $installedVersion); |
| 1476 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1476 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
| 1477 | 1477 | $currentMajor = explode('.', $currentVersion); |
| 1478 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1478 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
| 1479 | 1479 | if ($installedMajor === $currentMajor) { |
| 1480 | 1480 | // Same major, allow downgrade for developers |
| 1481 | 1481 | return true; |
| 1482 | 1482 | } else { |
| 1483 | 1483 | // downgrade attempt, throw exception |
| 1484 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1484 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | } else if ($versionDiff < 0) { |
| 1487 | 1487 | // downgrade attempt, throw exception |
| 1488 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1488 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | 1491 | // also check for upgrades for apps (independently from the user) |
@@ -67,1003 +67,1003 @@ |
||
| 67 | 67 | * OC_autoload! |
| 68 | 68 | */ |
| 69 | 69 | class OC { |
| 70 | - /** |
|
| 71 | - * Associative array for autoloading. classname => filename |
|
| 72 | - */ |
|
| 73 | - public static $CLASSPATH = array(); |
|
| 74 | - /** |
|
| 75 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 76 | - */ |
|
| 77 | - public static $SERVERROOT = ''; |
|
| 78 | - /** |
|
| 79 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 80 | - */ |
|
| 81 | - private static $SUBURI = ''; |
|
| 82 | - /** |
|
| 83 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 84 | - */ |
|
| 85 | - public static $WEBROOT = ''; |
|
| 86 | - /** |
|
| 87 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 88 | - * web path in 'url' |
|
| 89 | - */ |
|
| 90 | - public static $APPSROOTS = array(); |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 95 | - public static $configDir; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * requested app |
|
| 99 | - */ |
|
| 100 | - public static $REQUESTEDAPP = ''; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * check if Nextcloud runs in cli mode |
|
| 104 | - */ |
|
| 105 | - public static $CLI = false; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @var \OC\Autoloader $loader |
|
| 109 | - */ |
|
| 110 | - public static $loader = null; |
|
| 111 | - |
|
| 112 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 113 | - public static $composerAutoloader = null; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var \OC\Server |
|
| 117 | - */ |
|
| 118 | - public static $server = null; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @var \OC\Config |
|
| 122 | - */ |
|
| 123 | - private static $config = null; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 127 | - * the app path list is empty or contains an invalid path |
|
| 128 | - */ |
|
| 129 | - public static function initPaths() { |
|
| 130 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 131 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 132 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 133 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 134 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 135 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 136 | - } else { |
|
| 137 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 138 | - } |
|
| 139 | - self::$config = new \OC\Config(self::$configDir); |
|
| 140 | - |
|
| 141 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 142 | - /** |
|
| 143 | - * FIXME: The following lines are required because we can't yet instantiate |
|
| 144 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 145 | - */ |
|
| 146 | - $params = [ |
|
| 147 | - 'server' => [ |
|
| 148 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 149 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 150 | - ], |
|
| 151 | - ]; |
|
| 152 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 153 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 154 | - if (substr($scriptName, -1) == '/') { |
|
| 155 | - $scriptName .= 'index.php'; |
|
| 156 | - //make sure suburi follows the same rules as scriptName |
|
| 157 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 158 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 159 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 160 | - } |
|
| 161 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - if (OC::$CLI) { |
|
| 167 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 168 | - } else { |
|
| 169 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 170 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 171 | - |
|
| 172 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 173 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 174 | - } |
|
| 175 | - } else { |
|
| 176 | - // The scriptName is not ending with OC::$SUBURI |
|
| 177 | - // This most likely means that we are calling from CLI. |
|
| 178 | - // However some cron jobs still need to generate |
|
| 179 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 180 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 184 | - // slash which is required by URL generation. |
|
| 185 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 186 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 187 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
| 188 | - exit(); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // search the apps folder |
|
| 193 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 194 | - if (!empty($config_paths)) { |
|
| 195 | - foreach ($config_paths as $paths) { |
|
| 196 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 197 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 198 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 199 | - OC::$APPSROOTS[] = $paths; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 203 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 204 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 205 | - OC::$APPSROOTS[] = array( |
|
| 206 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 207 | - 'url' => '/apps', |
|
| 208 | - 'writable' => true |
|
| 209 | - ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (empty(OC::$APPSROOTS)) { |
|
| 213 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 214 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 215 | - } |
|
| 216 | - $paths = array(); |
|
| 217 | - foreach (OC::$APPSROOTS as $path) { |
|
| 218 | - $paths[] = $path['path']; |
|
| 219 | - if (!is_dir($path['path'])) { |
|
| 220 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 221 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 222 | - . ' config.php file.', $path['path'])); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // set the right include path |
|
| 227 | - set_include_path( |
|
| 228 | - implode(PATH_SEPARATOR, $paths) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public static function checkConfig() { |
|
| 233 | - $l = \OC::$server->getL10N('lib'); |
|
| 234 | - |
|
| 235 | - // Create config if it does not already exist |
|
| 236 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 237 | - if(!file_exists($configFilePath)) { |
|
| 238 | - @touch($configFilePath); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Check if config is writable |
|
| 242 | - $configFileWritable = is_writable($configFilePath); |
|
| 243 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 244 | - || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 245 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 246 | - |
|
| 247 | - if (self::$CLI) { |
|
| 248 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 249 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 250 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 251 | - echo "\n"; |
|
| 252 | - echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 253 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 254 | - exit; |
|
| 255 | - } else { |
|
| 256 | - http_response_code(500); |
|
| 257 | - OC_Template::printErrorPage( |
|
| 258 | - $l->t('Cannot write into "config" directory!'), |
|
| 259 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 260 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 261 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 262 | - [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
| 263 | - ); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - public static function checkInstalled() { |
|
| 270 | - if (defined('OC_CONSOLE')) { |
|
| 271 | - return; |
|
| 272 | - } |
|
| 273 | - // Redirect to installer if not installed |
|
| 274 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 275 | - if (OC::$CLI) { |
|
| 276 | - throw new Exception('Not installed'); |
|
| 277 | - } else { |
|
| 278 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 279 | - header('Location: ' . $url); |
|
| 280 | - } |
|
| 281 | - exit(); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - public static function checkMaintenanceMode() { |
|
| 286 | - // Allow ajax update script to execute without being stopped |
|
| 287 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 288 | - // send http status 503 |
|
| 289 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 290 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 291 | - header('Retry-After: 120'); |
|
| 292 | - |
|
| 293 | - // render error page |
|
| 294 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
| 295 | - OC_Util::addScript('maintenance-check'); |
|
| 296 | - OC_Util::addStyle('core', 'guest'); |
|
| 297 | - $template->printPage(); |
|
| 298 | - die(); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Prints the upgrade page |
|
| 304 | - * |
|
| 305 | - * @param \OC\SystemConfig $systemConfig |
|
| 306 | - */ |
|
| 307 | - private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 308 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 309 | - $tooBig = false; |
|
| 310 | - if (!$disableWebUpdater) { |
|
| 311 | - $apps = \OC::$server->getAppManager(); |
|
| 312 | - if ($apps->isInstalled('user_ldap')) { |
|
| 313 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 314 | - |
|
| 315 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 316 | - ->from('ldap_user_mapping') |
|
| 317 | - ->execute(); |
|
| 318 | - $row = $result->fetch(); |
|
| 319 | - $result->closeCursor(); |
|
| 320 | - |
|
| 321 | - $tooBig = ($row['user_count'] > 50); |
|
| 322 | - } |
|
| 323 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 324 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 325 | - |
|
| 326 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 327 | - ->from('user_saml_users') |
|
| 328 | - ->execute(); |
|
| 329 | - $row = $result->fetch(); |
|
| 330 | - $result->closeCursor(); |
|
| 331 | - |
|
| 332 | - $tooBig = ($row['user_count'] > 50); |
|
| 333 | - } |
|
| 334 | - if (!$tooBig) { |
|
| 335 | - // count users |
|
| 336 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 337 | - $totalUsers = array_sum($stats); |
|
| 338 | - $tooBig = ($totalUsers > 50); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 342 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 343 | - |
|
| 344 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 345 | - // send http status 503 |
|
| 346 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 347 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 348 | - header('Retry-After: 120'); |
|
| 349 | - |
|
| 350 | - // render error page |
|
| 351 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 352 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 353 | - $template->assign('version', OC_Util::getVersionString()); |
|
| 354 | - $template->assign('tooBig', $tooBig); |
|
| 355 | - |
|
| 356 | - $template->printPage(); |
|
| 357 | - die(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // check whether this is a core update or apps update |
|
| 361 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 362 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 363 | - |
|
| 364 | - // if not a core upgrade, then it's apps upgrade |
|
| 365 | - $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 366 | - |
|
| 367 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 368 | - $systemConfig->setValue('theme', ''); |
|
| 369 | - OC_Util::addScript('config'); // needed for web root |
|
| 370 | - OC_Util::addScript('update'); |
|
| 371 | - |
|
| 372 | - /** @var \OC\App\AppManager $appManager */ |
|
| 373 | - $appManager = \OC::$server->getAppManager(); |
|
| 374 | - |
|
| 375 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 376 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 377 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 378 | - |
|
| 379 | - // get third party apps |
|
| 380 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 381 | - $ocVersion = implode('.', $ocVersion); |
|
| 382 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 383 | - $incompatibleShippedApps = []; |
|
| 384 | - foreach ($incompatibleApps as $appInfo) { |
|
| 385 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 386 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if (!empty($incompatibleShippedApps)) { |
|
| 391 | - $l = \OC::$server->getL10N('core'); |
|
| 392 | - $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 393 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 397 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 398 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 399 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 400 | - $tmpl->printPage(); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - public static function initSession() { |
|
| 404 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 405 | - ini_set('session.cookie_secure', true); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - // prevents javascript from accessing php session cookies |
|
| 409 | - ini_set('session.cookie_httponly', 'true'); |
|
| 410 | - |
|
| 411 | - // set the cookie path to the Nextcloud directory |
|
| 412 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 413 | - ini_set('session.cookie_path', $cookie_path); |
|
| 414 | - |
|
| 415 | - // Let the session name be changed in the initSession Hook |
|
| 416 | - $sessionName = OC_Util::getInstanceId(); |
|
| 417 | - |
|
| 418 | - try { |
|
| 419 | - // Allow session apps to create a custom session object |
|
| 420 | - $useCustomSession = false; |
|
| 421 | - $session = self::$server->getSession(); |
|
| 422 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 423 | - if (!$useCustomSession) { |
|
| 424 | - // set the session name to the instance id - which is unique |
|
| 425 | - $session = new \OC\Session\Internal($sessionName); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 429 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 430 | - self::$server->setSession($session); |
|
| 431 | - |
|
| 432 | - // if session can't be started break with http 500 error |
|
| 433 | - } catch (Exception $e) { |
|
| 434 | - \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 435 | - //show the user a detailed error page |
|
| 436 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 437 | - OC_Template::printExceptionErrorPage($e); |
|
| 438 | - die(); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 442 | - |
|
| 443 | - // session timeout |
|
| 444 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 445 | - if (isset($_COOKIE[session_name()])) { |
|
| 446 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 447 | - } |
|
| 448 | - \OC::$server->getUserSession()->logout(); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - $session->set('LAST_ACTIVITY', time()); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - private static function getSessionLifeTime() { |
|
| 458 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - public static function loadAppClassPaths() { |
|
| 462 | - foreach (OC_App::getEnabledApps() as $app) { |
|
| 463 | - $appPath = OC_App::getAppPath($app); |
|
| 464 | - if ($appPath === false) { |
|
| 465 | - continue; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 469 | - if (file_exists($file)) { |
|
| 470 | - require_once $file; |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Try to set some values to the required Nextcloud default |
|
| 477 | - */ |
|
| 478 | - public static function setRequiredIniValues() { |
|
| 479 | - @ini_set('default_charset', 'UTF-8'); |
|
| 480 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Send the same site cookies |
|
| 485 | - */ |
|
| 486 | - private static function sendSameSiteCookies() { |
|
| 487 | - $cookieParams = session_get_cookie_params(); |
|
| 488 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 489 | - $policies = [ |
|
| 490 | - 'lax', |
|
| 491 | - 'strict', |
|
| 492 | - ]; |
|
| 493 | - |
|
| 494 | - // Append __Host to the cookie if it meets the requirements |
|
| 495 | - $cookiePrefix = ''; |
|
| 496 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 497 | - $cookiePrefix = '__Host-'; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - foreach($policies as $policy) { |
|
| 501 | - header( |
|
| 502 | - sprintf( |
|
| 503 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 504 | - $cookiePrefix, |
|
| 505 | - $policy, |
|
| 506 | - $cookieParams['path'], |
|
| 507 | - $policy |
|
| 508 | - ), |
|
| 509 | - false |
|
| 510 | - ); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 516 | - * be set in every request if cookies are sent to add a second level of |
|
| 517 | - * defense against CSRF. |
|
| 518 | - * |
|
| 519 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 520 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 521 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 522 | - */ |
|
| 523 | - private static function performSameSiteCookieProtection() { |
|
| 524 | - $request = \OC::$server->getRequest(); |
|
| 525 | - |
|
| 526 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 527 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 528 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 529 | - // here. |
|
| 530 | - $incompatibleUserAgents = [ |
|
| 531 | - // OS X Finder |
|
| 532 | - '/^WebDAVFS/', |
|
| 533 | - '/^Microsoft-WebDAV-MiniRedir/', |
|
| 534 | - ]; |
|
| 535 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 536 | - return; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - if(count($_COOKIE) > 0) { |
|
| 540 | - $requestUri = $request->getScriptName(); |
|
| 541 | - $processingScript = explode('/', $requestUri); |
|
| 542 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 543 | - |
|
| 544 | - // index.php routes are handled in the middleware |
|
| 545 | - if($processingScript === 'index.php') { |
|
| 546 | - return; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // All other endpoints require the lax and the strict cookie |
|
| 550 | - if(!$request->passesStrictCookieCheck()) { |
|
| 551 | - self::sendSameSiteCookies(); |
|
| 552 | - // Debug mode gets access to the resources without strict cookie |
|
| 553 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 554 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 555 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 556 | - exit(); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 560 | - self::sendSameSiteCookies(); |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - public static function init() { |
|
| 565 | - // calculate the root directories |
|
| 566 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 567 | - |
|
| 568 | - // register autoloader |
|
| 569 | - $loaderStart = microtime(true); |
|
| 570 | - require_once __DIR__ . '/autoloader.php'; |
|
| 571 | - self::$loader = new \OC\Autoloader([ |
|
| 572 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 573 | - ]); |
|
| 574 | - if (defined('PHPUNIT_RUN')) { |
|
| 575 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 576 | - } |
|
| 577 | - spl_autoload_register(array(self::$loader, 'load')); |
|
| 578 | - $loaderEnd = microtime(true); |
|
| 579 | - |
|
| 580 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 581 | - |
|
| 582 | - // Add default composer PSR-4 autoloader |
|
| 583 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 584 | - |
|
| 585 | - try { |
|
| 586 | - self::initPaths(); |
|
| 587 | - // setup 3rdparty autoloader |
|
| 588 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 589 | - if (!file_exists($vendorAutoLoad)) { |
|
| 590 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 591 | - } |
|
| 592 | - require_once $vendorAutoLoad; |
|
| 593 | - |
|
| 594 | - } catch (\RuntimeException $e) { |
|
| 595 | - if (!self::$CLI) { |
|
| 596 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 597 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 598 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 599 | - } |
|
| 600 | - // we can't use the template error page here, because this needs the |
|
| 601 | - // DI container which isn't available yet |
|
| 602 | - print($e->getMessage()); |
|
| 603 | - exit(); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // setup the basic server |
|
| 607 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 608 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 609 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 610 | - |
|
| 611 | - // Don't display errors and log them |
|
| 612 | - error_reporting(E_ALL | E_STRICT); |
|
| 613 | - @ini_set('display_errors', '0'); |
|
| 614 | - @ini_set('log_errors', '1'); |
|
| 615 | - |
|
| 616 | - if(!date_default_timezone_set('UTC')) { |
|
| 617 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - //try to configure php to enable big file uploads. |
|
| 621 | - //this doesn´t work always depending on the webserver and php configuration. |
|
| 622 | - //Let´s try to overwrite some defaults anyway |
|
| 623 | - |
|
| 624 | - //try to set the maximum execution time to 60min |
|
| 625 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 626 | - @set_time_limit(3600); |
|
| 627 | - } |
|
| 628 | - @ini_set('max_execution_time', '3600'); |
|
| 629 | - @ini_set('max_input_time', '3600'); |
|
| 630 | - |
|
| 631 | - //try to set the maximum filesize to 10G |
|
| 632 | - @ini_set('upload_max_filesize', '10G'); |
|
| 633 | - @ini_set('post_max_size', '10G'); |
|
| 634 | - @ini_set('file_uploads', '50'); |
|
| 635 | - |
|
| 636 | - self::setRequiredIniValues(); |
|
| 637 | - self::handleAuthHeaders(); |
|
| 638 | - self::registerAutoloaderCache(); |
|
| 639 | - |
|
| 640 | - // initialize intl fallback is necessary |
|
| 641 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
| 642 | - OC_Util::isSetLocaleWorking(); |
|
| 643 | - |
|
| 644 | - if (!defined('PHPUNIT_RUN')) { |
|
| 645 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 646 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 647 | - OC\Log\ErrorHandler::register($debug); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 651 | - OC_App::loadApps(array('session')); |
|
| 652 | - if (!self::$CLI) { |
|
| 653 | - self::initSession(); |
|
| 654 | - } |
|
| 655 | - \OC::$server->getEventLogger()->end('init_session'); |
|
| 656 | - self::checkConfig(); |
|
| 657 | - self::checkInstalled(); |
|
| 658 | - |
|
| 659 | - OC_Response::addSecurityHeaders(); |
|
| 660 | - |
|
| 661 | - self::performSameSiteCookieProtection(); |
|
| 662 | - |
|
| 663 | - if (!defined('OC_CONSOLE')) { |
|
| 664 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 665 | - if (count($errors) > 0) { |
|
| 666 | - if (self::$CLI) { |
|
| 667 | - // Convert l10n string into regular string for usage in database |
|
| 668 | - $staticErrors = []; |
|
| 669 | - foreach ($errors as $error) { |
|
| 670 | - echo $error['error'] . "\n"; |
|
| 671 | - echo $error['hint'] . "\n\n"; |
|
| 672 | - $staticErrors[] = [ |
|
| 673 | - 'error' => (string)$error['error'], |
|
| 674 | - 'hint' => (string)$error['hint'], |
|
| 675 | - ]; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - try { |
|
| 679 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 680 | - } catch (\Exception $e) { |
|
| 681 | - echo('Writing to database failed'); |
|
| 682 | - } |
|
| 683 | - exit(1); |
|
| 684 | - } else { |
|
| 685 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 686 | - OC_Util::addStyle('guest'); |
|
| 687 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 688 | - exit; |
|
| 689 | - } |
|
| 690 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 691 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - //try to set the session lifetime |
|
| 695 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 696 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 697 | - |
|
| 698 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 699 | - |
|
| 700 | - // User and Groups |
|
| 701 | - if (!$systemConfig->getValue("installed", false)) { |
|
| 702 | - self::$server->getSession()->set('user_id', ''); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - OC_User::useBackend(new \OC\User\Database()); |
|
| 706 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 707 | - |
|
| 708 | - // Subscribe to the hook |
|
| 709 | - \OCP\Util::connectHook( |
|
| 710 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 711 | - 'preLoginNameUsedAsUserName', |
|
| 712 | - '\OC\User\Database', |
|
| 713 | - 'preLoginNameUsedAsUserName' |
|
| 714 | - ); |
|
| 715 | - |
|
| 716 | - //setup extra user backends |
|
| 717 | - if (!\OCP\Util::needUpgrade()) { |
|
| 718 | - OC_User::setupBackends(); |
|
| 719 | - } else { |
|
| 720 | - // Run upgrades in incognito mode |
|
| 721 | - OC_User::setIncognitoMode(true); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - self::registerCleanupHooks(); |
|
| 725 | - self::registerFilesystemHooks(); |
|
| 726 | - self::registerShareHooks(); |
|
| 727 | - self::registerEncryptionWrapper(); |
|
| 728 | - self::registerEncryptionHooks(); |
|
| 729 | - self::registerAccountHooks(); |
|
| 730 | - |
|
| 731 | - // Make sure that the application class is not loaded before the database is setup |
|
| 732 | - if ($systemConfig->getValue("installed", false)) { |
|
| 733 | - $settings = new \OC\Settings\Application(); |
|
| 734 | - $settings->register(); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - //make sure temporary files are cleaned up |
|
| 738 | - $tmpManager = \OC::$server->getTempManager(); |
|
| 739 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
| 740 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
| 741 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 742 | - |
|
| 743 | - // Check whether the sample configuration has been copied |
|
| 744 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 745 | - $l = \OC::$server->getL10N('lib'); |
|
| 746 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 747 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 748 | - OC_Template::printErrorPage( |
|
| 749 | - $l->t('Sample configuration detected'), |
|
| 750 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 751 | - ); |
|
| 752 | - return; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - $request = \OC::$server->getRequest(); |
|
| 756 | - $host = $request->getInsecureServerHost(); |
|
| 757 | - /** |
|
| 758 | - * if the host passed in headers isn't trusted |
|
| 759 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 760 | - */ |
|
| 761 | - if (!OC::$CLI |
|
| 762 | - // overwritehost is always trusted, workaround to not have to make |
|
| 763 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 764 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 765 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 766 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 767 | - ) { |
|
| 768 | - // Allow access to CSS resources |
|
| 769 | - $isScssRequest = false; |
|
| 770 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 771 | - $isScssRequest = true; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 775 | - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
| 776 | - header('Status: 400 Bad Request'); |
|
| 777 | - header('Content-Type: application/json'); |
|
| 778 | - echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 779 | - exit(); |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - if (!$isScssRequest) { |
|
| 783 | - OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
| 784 | - header('Status: 400 Bad Request'); |
|
| 785 | - |
|
| 786 | - \OC::$server->getLogger()->info( |
|
| 787 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 788 | - [ |
|
| 789 | - 'app' => 'core', |
|
| 790 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 791 | - 'host' => $host, |
|
| 792 | - ] |
|
| 793 | - ); |
|
| 794 | - |
|
| 795 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 796 | - $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 797 | - $tmpl->printPage(); |
|
| 798 | - |
|
| 799 | - exit(); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - \OC::$server->getEventLogger()->end('boot'); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * register hooks for the cleanup of cache and bruteforce protection |
|
| 807 | - */ |
|
| 808 | - public static function registerCleanupHooks() { |
|
| 809 | - //don't try to do this before we are properly setup |
|
| 810 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 811 | - |
|
| 812 | - // NOTE: This will be replaced to use OCP |
|
| 813 | - $userSession = self::$server->getUserSession(); |
|
| 814 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 815 | - if (!defined('PHPUNIT_RUN')) { |
|
| 816 | - // reset brute force delay for this IP address and username |
|
| 817 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 818 | - $request = \OC::$server->getRequest(); |
|
| 819 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 820 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - try { |
|
| 824 | - $cache = new \OC\Cache\File(); |
|
| 825 | - $cache->gc(); |
|
| 826 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 827 | - // not a GC exception, pass it on |
|
| 828 | - throw $e; |
|
| 829 | - } catch (\OC\ForbiddenException $e) { |
|
| 830 | - // filesystem blocked for this request, ignore |
|
| 831 | - } catch (\Exception $e) { |
|
| 832 | - // a GC exception should not prevent users from using OC, |
|
| 833 | - // so log the exception |
|
| 834 | - \OC::$server->getLogger()->logException($e, [ |
|
| 835 | - 'message' => 'Exception when running cache gc.', |
|
| 836 | - 'level' => \OCP\Util::WARN, |
|
| 837 | - 'app' => 'core', |
|
| 838 | - ]); |
|
| 839 | - } |
|
| 840 | - }); |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - private static function registerEncryptionWrapper() { |
|
| 845 | - $manager = self::$server->getEncryptionManager(); |
|
| 846 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - private static function registerEncryptionHooks() { |
|
| 850 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 851 | - if ($enabled) { |
|
| 852 | - \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 853 | - \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 854 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 855 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - private static function registerAccountHooks() { |
|
| 860 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 861 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * register hooks for the filesystem |
|
| 866 | - */ |
|
| 867 | - public static function registerFilesystemHooks() { |
|
| 868 | - // Check for blacklisted files |
|
| 869 | - OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 870 | - OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * register hooks for sharing |
|
| 875 | - */ |
|
| 876 | - public static function registerShareHooks() { |
|
| 877 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 878 | - OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 879 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
| 880 | - OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - protected static function registerAutoloaderCache() { |
|
| 885 | - // The class loader takes an optional low-latency cache, which MUST be |
|
| 886 | - // namespaced. The instanceid is used for namespacing, but might be |
|
| 887 | - // unavailable at this point. Furthermore, it might not be possible to |
|
| 888 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 889 | - // config file may not be writable. As such, we only register a class |
|
| 890 | - // loader cache if instanceid is available without trying to create one. |
|
| 891 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 892 | - if ($instanceId) { |
|
| 893 | - try { |
|
| 894 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 895 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 896 | - } catch (\Exception $ex) { |
|
| 897 | - } |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * Handle the request |
|
| 903 | - */ |
|
| 904 | - public static function handleRequest() { |
|
| 905 | - |
|
| 906 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 907 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 908 | - // load all the classpaths from the enabled apps so they are available |
|
| 909 | - // in the routing files of each app |
|
| 910 | - OC::loadAppClassPaths(); |
|
| 911 | - |
|
| 912 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 913 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 914 | - \OC::$server->getSession()->clear(); |
|
| 915 | - $setupHelper = new OC\Setup( |
|
| 916 | - $systemConfig, |
|
| 917 | - \OC::$server->getIniWrapper(), |
|
| 918 | - \OC::$server->getL10N('lib'), |
|
| 919 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 920 | - \OC::$server->getLogger(), |
|
| 921 | - \OC::$server->getSecureRandom(), |
|
| 922 | - \OC::$server->query(\OC\Installer::class) |
|
| 923 | - ); |
|
| 924 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 925 | - $controller->run($_POST); |
|
| 926 | - exit(); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - $request = \OC::$server->getRequest(); |
|
| 930 | - $requestPath = $request->getRawPathInfo(); |
|
| 931 | - if ($requestPath === '/heartbeat') { |
|
| 932 | - return; |
|
| 933 | - } |
|
| 934 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 935 | - self::checkMaintenanceMode(); |
|
| 936 | - |
|
| 937 | - if (\OCP\Util::needUpgrade()) { |
|
| 938 | - if (function_exists('opcache_reset')) { |
|
| 939 | - opcache_reset(); |
|
| 940 | - } |
|
| 941 | - if (!$systemConfig->getValue('maintenance', false)) { |
|
| 942 | - self::printUpgradePage($systemConfig); |
|
| 943 | - exit(); |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - // emergency app disabling |
|
| 949 | - if ($requestPath === '/disableapp' |
|
| 950 | - && $request->getMethod() === 'POST' |
|
| 951 | - && ((array)$request->getParam('appid')) !== '' |
|
| 952 | - ) { |
|
| 953 | - \OC_JSON::callCheck(); |
|
| 954 | - \OC_JSON::checkAdminUser(); |
|
| 955 | - $appIds = (array)$request->getParam('appid'); |
|
| 956 | - foreach($appIds as $appId) { |
|
| 957 | - $appId = \OC_App::cleanAppId($appId); |
|
| 958 | - \OC::$server->getAppManager()->disableApp($appId); |
|
| 959 | - } |
|
| 960 | - \OC_JSON::success(); |
|
| 961 | - exit(); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - // Always load authentication apps |
|
| 965 | - OC_App::loadApps(['authentication']); |
|
| 966 | - |
|
| 967 | - // Load minimum set of apps |
|
| 968 | - if (!\OCP\Util::needUpgrade() |
|
| 969 | - && !$systemConfig->getValue('maintenance', false)) { |
|
| 970 | - // For logged-in users: Load everything |
|
| 971 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 972 | - OC_App::loadApps(); |
|
| 973 | - } else { |
|
| 974 | - // For guests: Load only filesystem and logging |
|
| 975 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 976 | - self::handleLogin($request); |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - if (!self::$CLI) { |
|
| 981 | - try { |
|
| 982 | - if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
| 983 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 984 | - OC_App::loadApps(); |
|
| 985 | - } |
|
| 986 | - OC_Util::setupFS(); |
|
| 987 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 988 | - return; |
|
| 989 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 990 | - //header('HTTP/1.0 404 Not Found'); |
|
| 991 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 992 | - OC_Response::setStatus(405); |
|
| 993 | - return; |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - // Handle WebDAV |
|
| 998 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 999 | - // not allowed any more to prevent people |
|
| 1000 | - // mounting this root directly. |
|
| 1001 | - // Users need to mount remote.php/webdav instead. |
|
| 1002 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
| 1003 | - header('Status: 405 Method Not Allowed'); |
|
| 1004 | - return; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - // Someone is logged in |
|
| 1008 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1009 | - OC_App::loadApps(); |
|
| 1010 | - OC_User::setupBackends(); |
|
| 1011 | - OC_Util::setupFS(); |
|
| 1012 | - // FIXME |
|
| 1013 | - // Redirect to default application |
|
| 1014 | - OC_Util::redirectToDefaultPage(); |
|
| 1015 | - } else { |
|
| 1016 | - // Not handled and not logged in |
|
| 1017 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - /** |
|
| 1022 | - * Check login: apache auth, auth token, basic auth |
|
| 1023 | - * |
|
| 1024 | - * @param OCP\IRequest $request |
|
| 1025 | - * @return boolean |
|
| 1026 | - */ |
|
| 1027 | - static function handleLogin(OCP\IRequest $request) { |
|
| 1028 | - $userSession = self::$server->getUserSession(); |
|
| 1029 | - if (OC_User::handleApacheAuth()) { |
|
| 1030 | - return true; |
|
| 1031 | - } |
|
| 1032 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1033 | - return true; |
|
| 1034 | - } |
|
| 1035 | - if (isset($_COOKIE['nc_username']) |
|
| 1036 | - && isset($_COOKIE['nc_token']) |
|
| 1037 | - && isset($_COOKIE['nc_session_id']) |
|
| 1038 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1039 | - return true; |
|
| 1040 | - } |
|
| 1041 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1042 | - return true; |
|
| 1043 | - } |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - protected static function handleAuthHeaders() { |
|
| 1048 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1049 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1050 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1054 | - $vars = array( |
|
| 1055 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1056 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1057 | - ); |
|
| 1058 | - foreach ($vars as $var) { |
|
| 1059 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1060 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1061 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1062 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1063 | - break; |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 70 | + /** |
|
| 71 | + * Associative array for autoloading. classname => filename |
|
| 72 | + */ |
|
| 73 | + public static $CLASSPATH = array(); |
|
| 74 | + /** |
|
| 75 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 76 | + */ |
|
| 77 | + public static $SERVERROOT = ''; |
|
| 78 | + /** |
|
| 79 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 80 | + */ |
|
| 81 | + private static $SUBURI = ''; |
|
| 82 | + /** |
|
| 83 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 84 | + */ |
|
| 85 | + public static $WEBROOT = ''; |
|
| 86 | + /** |
|
| 87 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 88 | + * web path in 'url' |
|
| 89 | + */ |
|
| 90 | + public static $APPSROOTS = array(); |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | + public static $configDir; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * requested app |
|
| 99 | + */ |
|
| 100 | + public static $REQUESTEDAPP = ''; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * check if Nextcloud runs in cli mode |
|
| 104 | + */ |
|
| 105 | + public static $CLI = false; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @var \OC\Autoloader $loader |
|
| 109 | + */ |
|
| 110 | + public static $loader = null; |
|
| 111 | + |
|
| 112 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 113 | + public static $composerAutoloader = null; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var \OC\Server |
|
| 117 | + */ |
|
| 118 | + public static $server = null; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @var \OC\Config |
|
| 122 | + */ |
|
| 123 | + private static $config = null; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 127 | + * the app path list is empty or contains an invalid path |
|
| 128 | + */ |
|
| 129 | + public static function initPaths() { |
|
| 130 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 131 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 132 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 133 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 134 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 135 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 136 | + } else { |
|
| 137 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 138 | + } |
|
| 139 | + self::$config = new \OC\Config(self::$configDir); |
|
| 140 | + |
|
| 141 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 142 | + /** |
|
| 143 | + * FIXME: The following lines are required because we can't yet instantiate |
|
| 144 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 145 | + */ |
|
| 146 | + $params = [ |
|
| 147 | + 'server' => [ |
|
| 148 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 149 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 150 | + ], |
|
| 151 | + ]; |
|
| 152 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 153 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 154 | + if (substr($scriptName, -1) == '/') { |
|
| 155 | + $scriptName .= 'index.php'; |
|
| 156 | + //make sure suburi follows the same rules as scriptName |
|
| 157 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 158 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 159 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 160 | + } |
|
| 161 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + if (OC::$CLI) { |
|
| 167 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 168 | + } else { |
|
| 169 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 170 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 171 | + |
|
| 172 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 173 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 174 | + } |
|
| 175 | + } else { |
|
| 176 | + // The scriptName is not ending with OC::$SUBURI |
|
| 177 | + // This most likely means that we are calling from CLI. |
|
| 178 | + // However some cron jobs still need to generate |
|
| 179 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 180 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 184 | + // slash which is required by URL generation. |
|
| 185 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 186 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 187 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
| 188 | + exit(); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // search the apps folder |
|
| 193 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 194 | + if (!empty($config_paths)) { |
|
| 195 | + foreach ($config_paths as $paths) { |
|
| 196 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 197 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 198 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 199 | + OC::$APPSROOTS[] = $paths; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 203 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 204 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 205 | + OC::$APPSROOTS[] = array( |
|
| 206 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 207 | + 'url' => '/apps', |
|
| 208 | + 'writable' => true |
|
| 209 | + ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (empty(OC::$APPSROOTS)) { |
|
| 213 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 214 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 215 | + } |
|
| 216 | + $paths = array(); |
|
| 217 | + foreach (OC::$APPSROOTS as $path) { |
|
| 218 | + $paths[] = $path['path']; |
|
| 219 | + if (!is_dir($path['path'])) { |
|
| 220 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 221 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 222 | + . ' config.php file.', $path['path'])); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // set the right include path |
|
| 227 | + set_include_path( |
|
| 228 | + implode(PATH_SEPARATOR, $paths) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public static function checkConfig() { |
|
| 233 | + $l = \OC::$server->getL10N('lib'); |
|
| 234 | + |
|
| 235 | + // Create config if it does not already exist |
|
| 236 | + $configFilePath = self::$configDir .'/config.php'; |
|
| 237 | + if(!file_exists($configFilePath)) { |
|
| 238 | + @touch($configFilePath); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Check if config is writable |
|
| 242 | + $configFileWritable = is_writable($configFilePath); |
|
| 243 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 244 | + || !$configFileWritable && \OCP\Util::needUpgrade()) { |
|
| 245 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 246 | + |
|
| 247 | + if (self::$CLI) { |
|
| 248 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 249 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 250 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 251 | + echo "\n"; |
|
| 252 | + echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
|
| 253 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 254 | + exit; |
|
| 255 | + } else { |
|
| 256 | + http_response_code(500); |
|
| 257 | + OC_Template::printErrorPage( |
|
| 258 | + $l->t('Cannot write into "config" directory!'), |
|
| 259 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 260 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 261 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 262 | + [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + public static function checkInstalled() { |
|
| 270 | + if (defined('OC_CONSOLE')) { |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | + // Redirect to installer if not installed |
|
| 274 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 275 | + if (OC::$CLI) { |
|
| 276 | + throw new Exception('Not installed'); |
|
| 277 | + } else { |
|
| 278 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 279 | + header('Location: ' . $url); |
|
| 280 | + } |
|
| 281 | + exit(); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + public static function checkMaintenanceMode() { |
|
| 286 | + // Allow ajax update script to execute without being stopped |
|
| 287 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 288 | + // send http status 503 |
|
| 289 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 290 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 291 | + header('Retry-After: 120'); |
|
| 292 | + |
|
| 293 | + // render error page |
|
| 294 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
| 295 | + OC_Util::addScript('maintenance-check'); |
|
| 296 | + OC_Util::addStyle('core', 'guest'); |
|
| 297 | + $template->printPage(); |
|
| 298 | + die(); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Prints the upgrade page |
|
| 304 | + * |
|
| 305 | + * @param \OC\SystemConfig $systemConfig |
|
| 306 | + */ |
|
| 307 | + private static function printUpgradePage(\OC\SystemConfig $systemConfig) { |
|
| 308 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 309 | + $tooBig = false; |
|
| 310 | + if (!$disableWebUpdater) { |
|
| 311 | + $apps = \OC::$server->getAppManager(); |
|
| 312 | + if ($apps->isInstalled('user_ldap')) { |
|
| 313 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 314 | + |
|
| 315 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 316 | + ->from('ldap_user_mapping') |
|
| 317 | + ->execute(); |
|
| 318 | + $row = $result->fetch(); |
|
| 319 | + $result->closeCursor(); |
|
| 320 | + |
|
| 321 | + $tooBig = ($row['user_count'] > 50); |
|
| 322 | + } |
|
| 323 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 324 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 325 | + |
|
| 326 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 327 | + ->from('user_saml_users') |
|
| 328 | + ->execute(); |
|
| 329 | + $row = $result->fetch(); |
|
| 330 | + $result->closeCursor(); |
|
| 331 | + |
|
| 332 | + $tooBig = ($row['user_count'] > 50); |
|
| 333 | + } |
|
| 334 | + if (!$tooBig) { |
|
| 335 | + // count users |
|
| 336 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 337 | + $totalUsers = array_sum($stats); |
|
| 338 | + $tooBig = ($totalUsers > 50); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 342 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 343 | + |
|
| 344 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 345 | + // send http status 503 |
|
| 346 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 347 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 348 | + header('Retry-After: 120'); |
|
| 349 | + |
|
| 350 | + // render error page |
|
| 351 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 352 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 353 | + $template->assign('version', OC_Util::getVersionString()); |
|
| 354 | + $template->assign('tooBig', $tooBig); |
|
| 355 | + |
|
| 356 | + $template->printPage(); |
|
| 357 | + die(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // check whether this is a core update or apps update |
|
| 361 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 362 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 363 | + |
|
| 364 | + // if not a core upgrade, then it's apps upgrade |
|
| 365 | + $isAppsOnlyUpgrade = version_compare($currentVersion, $installedVersion, '='); |
|
| 366 | + |
|
| 367 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 368 | + $systemConfig->setValue('theme', ''); |
|
| 369 | + OC_Util::addScript('config'); // needed for web root |
|
| 370 | + OC_Util::addScript('update'); |
|
| 371 | + |
|
| 372 | + /** @var \OC\App\AppManager $appManager */ |
|
| 373 | + $appManager = \OC::$server->getAppManager(); |
|
| 374 | + |
|
| 375 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 376 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 377 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 378 | + |
|
| 379 | + // get third party apps |
|
| 380 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 381 | + $ocVersion = implode('.', $ocVersion); |
|
| 382 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 383 | + $incompatibleShippedApps = []; |
|
| 384 | + foreach ($incompatibleApps as $appInfo) { |
|
| 385 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 386 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if (!empty($incompatibleShippedApps)) { |
|
| 391 | + $l = \OC::$server->getL10N('core'); |
|
| 392 | + $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 393 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 397 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 398 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 399 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 400 | + $tmpl->printPage(); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + public static function initSession() { |
|
| 404 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 405 | + ini_set('session.cookie_secure', true); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + // prevents javascript from accessing php session cookies |
|
| 409 | + ini_set('session.cookie_httponly', 'true'); |
|
| 410 | + |
|
| 411 | + // set the cookie path to the Nextcloud directory |
|
| 412 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 413 | + ini_set('session.cookie_path', $cookie_path); |
|
| 414 | + |
|
| 415 | + // Let the session name be changed in the initSession Hook |
|
| 416 | + $sessionName = OC_Util::getInstanceId(); |
|
| 417 | + |
|
| 418 | + try { |
|
| 419 | + // Allow session apps to create a custom session object |
|
| 420 | + $useCustomSession = false; |
|
| 421 | + $session = self::$server->getSession(); |
|
| 422 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 423 | + if (!$useCustomSession) { |
|
| 424 | + // set the session name to the instance id - which is unique |
|
| 425 | + $session = new \OC\Session\Internal($sessionName); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 429 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 430 | + self::$server->setSession($session); |
|
| 431 | + |
|
| 432 | + // if session can't be started break with http 500 error |
|
| 433 | + } catch (Exception $e) { |
|
| 434 | + \OC::$server->getLogger()->logException($e, ['app' => 'base']); |
|
| 435 | + //show the user a detailed error page |
|
| 436 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 437 | + OC_Template::printExceptionErrorPage($e); |
|
| 438 | + die(); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 442 | + |
|
| 443 | + // session timeout |
|
| 444 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 445 | + if (isset($_COOKIE[session_name()])) { |
|
| 446 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 447 | + } |
|
| 448 | + \OC::$server->getUserSession()->logout(); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + $session->set('LAST_ACTIVITY', time()); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + private static function getSessionLifeTime() { |
|
| 458 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + public static function loadAppClassPaths() { |
|
| 462 | + foreach (OC_App::getEnabledApps() as $app) { |
|
| 463 | + $appPath = OC_App::getAppPath($app); |
|
| 464 | + if ($appPath === false) { |
|
| 465 | + continue; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + $file = $appPath . '/appinfo/classpath.php'; |
|
| 469 | + if (file_exists($file)) { |
|
| 470 | + require_once $file; |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Try to set some values to the required Nextcloud default |
|
| 477 | + */ |
|
| 478 | + public static function setRequiredIniValues() { |
|
| 479 | + @ini_set('default_charset', 'UTF-8'); |
|
| 480 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Send the same site cookies |
|
| 485 | + */ |
|
| 486 | + private static function sendSameSiteCookies() { |
|
| 487 | + $cookieParams = session_get_cookie_params(); |
|
| 488 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 489 | + $policies = [ |
|
| 490 | + 'lax', |
|
| 491 | + 'strict', |
|
| 492 | + ]; |
|
| 493 | + |
|
| 494 | + // Append __Host to the cookie if it meets the requirements |
|
| 495 | + $cookiePrefix = ''; |
|
| 496 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 497 | + $cookiePrefix = '__Host-'; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + foreach($policies as $policy) { |
|
| 501 | + header( |
|
| 502 | + sprintf( |
|
| 503 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 504 | + $cookiePrefix, |
|
| 505 | + $policy, |
|
| 506 | + $cookieParams['path'], |
|
| 507 | + $policy |
|
| 508 | + ), |
|
| 509 | + false |
|
| 510 | + ); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 516 | + * be set in every request if cookies are sent to add a second level of |
|
| 517 | + * defense against CSRF. |
|
| 518 | + * |
|
| 519 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 520 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 521 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 522 | + */ |
|
| 523 | + private static function performSameSiteCookieProtection() { |
|
| 524 | + $request = \OC::$server->getRequest(); |
|
| 525 | + |
|
| 526 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 527 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 528 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 529 | + // here. |
|
| 530 | + $incompatibleUserAgents = [ |
|
| 531 | + // OS X Finder |
|
| 532 | + '/^WebDAVFS/', |
|
| 533 | + '/^Microsoft-WebDAV-MiniRedir/', |
|
| 534 | + ]; |
|
| 535 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 536 | + return; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + if(count($_COOKIE) > 0) { |
|
| 540 | + $requestUri = $request->getScriptName(); |
|
| 541 | + $processingScript = explode('/', $requestUri); |
|
| 542 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
| 543 | + |
|
| 544 | + // index.php routes are handled in the middleware |
|
| 545 | + if($processingScript === 'index.php') { |
|
| 546 | + return; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // All other endpoints require the lax and the strict cookie |
|
| 550 | + if(!$request->passesStrictCookieCheck()) { |
|
| 551 | + self::sendSameSiteCookies(); |
|
| 552 | + // Debug mode gets access to the resources without strict cookie |
|
| 553 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 554 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 555 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 556 | + exit(); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 560 | + self::sendSameSiteCookies(); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + public static function init() { |
|
| 565 | + // calculate the root directories |
|
| 566 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 567 | + |
|
| 568 | + // register autoloader |
|
| 569 | + $loaderStart = microtime(true); |
|
| 570 | + require_once __DIR__ . '/autoloader.php'; |
|
| 571 | + self::$loader = new \OC\Autoloader([ |
|
| 572 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
| 573 | + ]); |
|
| 574 | + if (defined('PHPUNIT_RUN')) { |
|
| 575 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 576 | + } |
|
| 577 | + spl_autoload_register(array(self::$loader, 'load')); |
|
| 578 | + $loaderEnd = microtime(true); |
|
| 579 | + |
|
| 580 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 581 | + |
|
| 582 | + // Add default composer PSR-4 autoloader |
|
| 583 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 584 | + |
|
| 585 | + try { |
|
| 586 | + self::initPaths(); |
|
| 587 | + // setup 3rdparty autoloader |
|
| 588 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 589 | + if (!file_exists($vendorAutoLoad)) { |
|
| 590 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 591 | + } |
|
| 592 | + require_once $vendorAutoLoad; |
|
| 593 | + |
|
| 594 | + } catch (\RuntimeException $e) { |
|
| 595 | + if (!self::$CLI) { |
|
| 596 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 597 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 598 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 599 | + } |
|
| 600 | + // we can't use the template error page here, because this needs the |
|
| 601 | + // DI container which isn't available yet |
|
| 602 | + print($e->getMessage()); |
|
| 603 | + exit(); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // setup the basic server |
|
| 607 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 608 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 609 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 610 | + |
|
| 611 | + // Don't display errors and log them |
|
| 612 | + error_reporting(E_ALL | E_STRICT); |
|
| 613 | + @ini_set('display_errors', '0'); |
|
| 614 | + @ini_set('log_errors', '1'); |
|
| 615 | + |
|
| 616 | + if(!date_default_timezone_set('UTC')) { |
|
| 617 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + //try to configure php to enable big file uploads. |
|
| 621 | + //this doesn´t work always depending on the webserver and php configuration. |
|
| 622 | + //Let´s try to overwrite some defaults anyway |
|
| 623 | + |
|
| 624 | + //try to set the maximum execution time to 60min |
|
| 625 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 626 | + @set_time_limit(3600); |
|
| 627 | + } |
|
| 628 | + @ini_set('max_execution_time', '3600'); |
|
| 629 | + @ini_set('max_input_time', '3600'); |
|
| 630 | + |
|
| 631 | + //try to set the maximum filesize to 10G |
|
| 632 | + @ini_set('upload_max_filesize', '10G'); |
|
| 633 | + @ini_set('post_max_size', '10G'); |
|
| 634 | + @ini_set('file_uploads', '50'); |
|
| 635 | + |
|
| 636 | + self::setRequiredIniValues(); |
|
| 637 | + self::handleAuthHeaders(); |
|
| 638 | + self::registerAutoloaderCache(); |
|
| 639 | + |
|
| 640 | + // initialize intl fallback is necessary |
|
| 641 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
| 642 | + OC_Util::isSetLocaleWorking(); |
|
| 643 | + |
|
| 644 | + if (!defined('PHPUNIT_RUN')) { |
|
| 645 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 646 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 647 | + OC\Log\ErrorHandler::register($debug); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 651 | + OC_App::loadApps(array('session')); |
|
| 652 | + if (!self::$CLI) { |
|
| 653 | + self::initSession(); |
|
| 654 | + } |
|
| 655 | + \OC::$server->getEventLogger()->end('init_session'); |
|
| 656 | + self::checkConfig(); |
|
| 657 | + self::checkInstalled(); |
|
| 658 | + |
|
| 659 | + OC_Response::addSecurityHeaders(); |
|
| 660 | + |
|
| 661 | + self::performSameSiteCookieProtection(); |
|
| 662 | + |
|
| 663 | + if (!defined('OC_CONSOLE')) { |
|
| 664 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 665 | + if (count($errors) > 0) { |
|
| 666 | + if (self::$CLI) { |
|
| 667 | + // Convert l10n string into regular string for usage in database |
|
| 668 | + $staticErrors = []; |
|
| 669 | + foreach ($errors as $error) { |
|
| 670 | + echo $error['error'] . "\n"; |
|
| 671 | + echo $error['hint'] . "\n\n"; |
|
| 672 | + $staticErrors[] = [ |
|
| 673 | + 'error' => (string)$error['error'], |
|
| 674 | + 'hint' => (string)$error['hint'], |
|
| 675 | + ]; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + try { |
|
| 679 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 680 | + } catch (\Exception $e) { |
|
| 681 | + echo('Writing to database failed'); |
|
| 682 | + } |
|
| 683 | + exit(1); |
|
| 684 | + } else { |
|
| 685 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 686 | + OC_Util::addStyle('guest'); |
|
| 687 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 688 | + exit; |
|
| 689 | + } |
|
| 690 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 691 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + //try to set the session lifetime |
|
| 695 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 696 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 697 | + |
|
| 698 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 699 | + |
|
| 700 | + // User and Groups |
|
| 701 | + if (!$systemConfig->getValue("installed", false)) { |
|
| 702 | + self::$server->getSession()->set('user_id', ''); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + OC_User::useBackend(new \OC\User\Database()); |
|
| 706 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 707 | + |
|
| 708 | + // Subscribe to the hook |
|
| 709 | + \OCP\Util::connectHook( |
|
| 710 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 711 | + 'preLoginNameUsedAsUserName', |
|
| 712 | + '\OC\User\Database', |
|
| 713 | + 'preLoginNameUsedAsUserName' |
|
| 714 | + ); |
|
| 715 | + |
|
| 716 | + //setup extra user backends |
|
| 717 | + if (!\OCP\Util::needUpgrade()) { |
|
| 718 | + OC_User::setupBackends(); |
|
| 719 | + } else { |
|
| 720 | + // Run upgrades in incognito mode |
|
| 721 | + OC_User::setIncognitoMode(true); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + self::registerCleanupHooks(); |
|
| 725 | + self::registerFilesystemHooks(); |
|
| 726 | + self::registerShareHooks(); |
|
| 727 | + self::registerEncryptionWrapper(); |
|
| 728 | + self::registerEncryptionHooks(); |
|
| 729 | + self::registerAccountHooks(); |
|
| 730 | + |
|
| 731 | + // Make sure that the application class is not loaded before the database is setup |
|
| 732 | + if ($systemConfig->getValue("installed", false)) { |
|
| 733 | + $settings = new \OC\Settings\Application(); |
|
| 734 | + $settings->register(); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + //make sure temporary files are cleaned up |
|
| 738 | + $tmpManager = \OC::$server->getTempManager(); |
|
| 739 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
| 740 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
| 741 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 742 | + |
|
| 743 | + // Check whether the sample configuration has been copied |
|
| 744 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 745 | + $l = \OC::$server->getL10N('lib'); |
|
| 746 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 747 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 748 | + OC_Template::printErrorPage( |
|
| 749 | + $l->t('Sample configuration detected'), |
|
| 750 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 751 | + ); |
|
| 752 | + return; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + $request = \OC::$server->getRequest(); |
|
| 756 | + $host = $request->getInsecureServerHost(); |
|
| 757 | + /** |
|
| 758 | + * if the host passed in headers isn't trusted |
|
| 759 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 760 | + */ |
|
| 761 | + if (!OC::$CLI |
|
| 762 | + // overwritehost is always trusted, workaround to not have to make |
|
| 763 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 764 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 765 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 766 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 767 | + ) { |
|
| 768 | + // Allow access to CSS resources |
|
| 769 | + $isScssRequest = false; |
|
| 770 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 771 | + $isScssRequest = true; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 775 | + OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
| 776 | + header('Status: 400 Bad Request'); |
|
| 777 | + header('Content-Type: application/json'); |
|
| 778 | + echo '{"error": "Trusted domain error.", "code": 15}'; |
|
| 779 | + exit(); |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + if (!$isScssRequest) { |
|
| 783 | + OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
|
| 784 | + header('Status: 400 Bad Request'); |
|
| 785 | + |
|
| 786 | + \OC::$server->getLogger()->info( |
|
| 787 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 788 | + [ |
|
| 789 | + 'app' => 'core', |
|
| 790 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 791 | + 'host' => $host, |
|
| 792 | + ] |
|
| 793 | + ); |
|
| 794 | + |
|
| 795 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 796 | + $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); |
|
| 797 | + $tmpl->printPage(); |
|
| 798 | + |
|
| 799 | + exit(); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + \OC::$server->getEventLogger()->end('boot'); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * register hooks for the cleanup of cache and bruteforce protection |
|
| 807 | + */ |
|
| 808 | + public static function registerCleanupHooks() { |
|
| 809 | + //don't try to do this before we are properly setup |
|
| 810 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !\OCP\Util::needUpgrade()) { |
|
| 811 | + |
|
| 812 | + // NOTE: This will be replaced to use OCP |
|
| 813 | + $userSession = self::$server->getUserSession(); |
|
| 814 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 815 | + if (!defined('PHPUNIT_RUN')) { |
|
| 816 | + // reset brute force delay for this IP address and username |
|
| 817 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 818 | + $request = \OC::$server->getRequest(); |
|
| 819 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 820 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + try { |
|
| 824 | + $cache = new \OC\Cache\File(); |
|
| 825 | + $cache->gc(); |
|
| 826 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 827 | + // not a GC exception, pass it on |
|
| 828 | + throw $e; |
|
| 829 | + } catch (\OC\ForbiddenException $e) { |
|
| 830 | + // filesystem blocked for this request, ignore |
|
| 831 | + } catch (\Exception $e) { |
|
| 832 | + // a GC exception should not prevent users from using OC, |
|
| 833 | + // so log the exception |
|
| 834 | + \OC::$server->getLogger()->logException($e, [ |
|
| 835 | + 'message' => 'Exception when running cache gc.', |
|
| 836 | + 'level' => \OCP\Util::WARN, |
|
| 837 | + 'app' => 'core', |
|
| 838 | + ]); |
|
| 839 | + } |
|
| 840 | + }); |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + private static function registerEncryptionWrapper() { |
|
| 845 | + $manager = self::$server->getEncryptionManager(); |
|
| 846 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + private static function registerEncryptionHooks() { |
|
| 850 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 851 | + if ($enabled) { |
|
| 852 | + \OCP\Util::connectHook(Share::class, 'post_shared', HookManager::class, 'postShared'); |
|
| 853 | + \OCP\Util::connectHook(Share::class, 'post_unshare', HookManager::class, 'postUnshared'); |
|
| 854 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', HookManager::class, 'postRename'); |
|
| 855 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', HookManager::class, 'postRestore'); |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + private static function registerAccountHooks() { |
|
| 860 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 861 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * register hooks for the filesystem |
|
| 866 | + */ |
|
| 867 | + public static function registerFilesystemHooks() { |
|
| 868 | + // Check for blacklisted files |
|
| 869 | + OC_Hook::connect('OC_Filesystem', 'write', Filesystem::class, 'isBlacklisted'); |
|
| 870 | + OC_Hook::connect('OC_Filesystem', 'rename', Filesystem::class, 'isBlacklisted'); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * register hooks for sharing |
|
| 875 | + */ |
|
| 876 | + public static function registerShareHooks() { |
|
| 877 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 878 | + OC_Hook::connect('OC_User', 'post_deleteUser', Hooks::class, 'post_deleteUser'); |
|
| 879 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', Hooks::class, 'post_removeFromGroup'); |
|
| 880 | + OC_Hook::connect('OC_User', 'post_deleteGroup', Hooks::class, 'post_deleteGroup'); |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + protected static function registerAutoloaderCache() { |
|
| 885 | + // The class loader takes an optional low-latency cache, which MUST be |
|
| 886 | + // namespaced. The instanceid is used for namespacing, but might be |
|
| 887 | + // unavailable at this point. Furthermore, it might not be possible to |
|
| 888 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 889 | + // config file may not be writable. As such, we only register a class |
|
| 890 | + // loader cache if instanceid is available without trying to create one. |
|
| 891 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 892 | + if ($instanceId) { |
|
| 893 | + try { |
|
| 894 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 895 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 896 | + } catch (\Exception $ex) { |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * Handle the request |
|
| 903 | + */ |
|
| 904 | + public static function handleRequest() { |
|
| 905 | + |
|
| 906 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 907 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 908 | + // load all the classpaths from the enabled apps so they are available |
|
| 909 | + // in the routing files of each app |
|
| 910 | + OC::loadAppClassPaths(); |
|
| 911 | + |
|
| 912 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 913 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 914 | + \OC::$server->getSession()->clear(); |
|
| 915 | + $setupHelper = new OC\Setup( |
|
| 916 | + $systemConfig, |
|
| 917 | + \OC::$server->getIniWrapper(), |
|
| 918 | + \OC::$server->getL10N('lib'), |
|
| 919 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 920 | + \OC::$server->getLogger(), |
|
| 921 | + \OC::$server->getSecureRandom(), |
|
| 922 | + \OC::$server->query(\OC\Installer::class) |
|
| 923 | + ); |
|
| 924 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 925 | + $controller->run($_POST); |
|
| 926 | + exit(); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + $request = \OC::$server->getRequest(); |
|
| 930 | + $requestPath = $request->getRawPathInfo(); |
|
| 931 | + if ($requestPath === '/heartbeat') { |
|
| 932 | + return; |
|
| 933 | + } |
|
| 934 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 935 | + self::checkMaintenanceMode(); |
|
| 936 | + |
|
| 937 | + if (\OCP\Util::needUpgrade()) { |
|
| 938 | + if (function_exists('opcache_reset')) { |
|
| 939 | + opcache_reset(); |
|
| 940 | + } |
|
| 941 | + if (!$systemConfig->getValue('maintenance', false)) { |
|
| 942 | + self::printUpgradePage($systemConfig); |
|
| 943 | + exit(); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + // emergency app disabling |
|
| 949 | + if ($requestPath === '/disableapp' |
|
| 950 | + && $request->getMethod() === 'POST' |
|
| 951 | + && ((array)$request->getParam('appid')) !== '' |
|
| 952 | + ) { |
|
| 953 | + \OC_JSON::callCheck(); |
|
| 954 | + \OC_JSON::checkAdminUser(); |
|
| 955 | + $appIds = (array)$request->getParam('appid'); |
|
| 956 | + foreach($appIds as $appId) { |
|
| 957 | + $appId = \OC_App::cleanAppId($appId); |
|
| 958 | + \OC::$server->getAppManager()->disableApp($appId); |
|
| 959 | + } |
|
| 960 | + \OC_JSON::success(); |
|
| 961 | + exit(); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + // Always load authentication apps |
|
| 965 | + OC_App::loadApps(['authentication']); |
|
| 966 | + |
|
| 967 | + // Load minimum set of apps |
|
| 968 | + if (!\OCP\Util::needUpgrade() |
|
| 969 | + && !$systemConfig->getValue('maintenance', false)) { |
|
| 970 | + // For logged-in users: Load everything |
|
| 971 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 972 | + OC_App::loadApps(); |
|
| 973 | + } else { |
|
| 974 | + // For guests: Load only filesystem and logging |
|
| 975 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 976 | + self::handleLogin($request); |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + if (!self::$CLI) { |
|
| 981 | + try { |
|
| 982 | + if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { |
|
| 983 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 984 | + OC_App::loadApps(); |
|
| 985 | + } |
|
| 986 | + OC_Util::setupFS(); |
|
| 987 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 988 | + return; |
|
| 989 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 990 | + //header('HTTP/1.0 404 Not Found'); |
|
| 991 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 992 | + OC_Response::setStatus(405); |
|
| 993 | + return; |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + // Handle WebDAV |
|
| 998 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 999 | + // not allowed any more to prevent people |
|
| 1000 | + // mounting this root directly. |
|
| 1001 | + // Users need to mount remote.php/webdav instead. |
|
| 1002 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
| 1003 | + header('Status: 405 Method Not Allowed'); |
|
| 1004 | + return; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + // Someone is logged in |
|
| 1008 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1009 | + OC_App::loadApps(); |
|
| 1010 | + OC_User::setupBackends(); |
|
| 1011 | + OC_Util::setupFS(); |
|
| 1012 | + // FIXME |
|
| 1013 | + // Redirect to default application |
|
| 1014 | + OC_Util::redirectToDefaultPage(); |
|
| 1015 | + } else { |
|
| 1016 | + // Not handled and not logged in |
|
| 1017 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + /** |
|
| 1022 | + * Check login: apache auth, auth token, basic auth |
|
| 1023 | + * |
|
| 1024 | + * @param OCP\IRequest $request |
|
| 1025 | + * @return boolean |
|
| 1026 | + */ |
|
| 1027 | + static function handleLogin(OCP\IRequest $request) { |
|
| 1028 | + $userSession = self::$server->getUserSession(); |
|
| 1029 | + if (OC_User::handleApacheAuth()) { |
|
| 1030 | + return true; |
|
| 1031 | + } |
|
| 1032 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1033 | + return true; |
|
| 1034 | + } |
|
| 1035 | + if (isset($_COOKIE['nc_username']) |
|
| 1036 | + && isset($_COOKIE['nc_token']) |
|
| 1037 | + && isset($_COOKIE['nc_session_id']) |
|
| 1038 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1039 | + return true; |
|
| 1040 | + } |
|
| 1041 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1042 | + return true; |
|
| 1043 | + } |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + protected static function handleAuthHeaders() { |
|
| 1048 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1049 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1050 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1054 | + $vars = array( |
|
| 1055 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1056 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1057 | + ); |
|
| 1058 | + foreach ($vars as $var) { |
|
| 1059 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1060 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1061 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1062 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1063 | + break; |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | OC::init(); |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | * the app path list is empty or contains an invalid path |
| 128 | 128 | */ |
| 129 | 129 | public static function initPaths() { |
| 130 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 131 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 132 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 133 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 134 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 135 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 130 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 131 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
| 132 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
| 133 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
| 134 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 135 | + self::$configDir = rtrim($dir, '/').'/'; |
|
| 136 | 136 | } else { |
| 137 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 137 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
| 138 | 138 | } |
| 139 | 139 | self::$config = new \OC\Config(self::$configDir); |
| 140 | 140 | |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | //make sure suburi follows the same rules as scriptName |
| 157 | 157 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
| 158 | 158 | if (substr(OC::$SUBURI, -1) != '/') { |
| 159 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 159 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
| 160 | 160 | } |
| 161 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 161 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
| 171 | 171 | |
| 172 | 172 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
| 173 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 173 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
| 174 | 174 | } |
| 175 | 175 | } else { |
| 176 | 176 | // The scriptName is not ending with OC::$SUBURI |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | OC::$APPSROOTS[] = $paths; |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 203 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 204 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 202 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
| 203 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
| 204 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
| 205 | 205 | OC::$APPSROOTS[] = array( |
| 206 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 206 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
| 207 | 207 | 'url' => '/apps', |
| 208 | 208 | 'writable' => true |
| 209 | 209 | ); |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | $l = \OC::$server->getL10N('lib'); |
| 234 | 234 | |
| 235 | 235 | // Create config if it does not already exist |
| 236 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 237 | - if(!file_exists($configFilePath)) { |
|
| 236 | + $configFilePath = self::$configDir.'/config.php'; |
|
| 237 | + if (!file_exists($configFilePath)) { |
|
| 238 | 238 | @touch($configFilePath); |
| 239 | 239 | } |
| 240 | 240 | |
@@ -247,19 +247,19 @@ discard block |
||
| 247 | 247 | if (self::$CLI) { |
| 248 | 248 | echo $l->t('Cannot write into "config" directory!')."\n"; |
| 249 | 249 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
| 250 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 250 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
| 251 | 251 | echo "\n"; |
| 252 | 252 | echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; |
| 253 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; |
|
| 253 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-config')])."\n"; |
|
| 254 | 254 | exit; |
| 255 | 255 | } else { |
| 256 | 256 | http_response_code(500); |
| 257 | 257 | OC_Template::printErrorPage( |
| 258 | 258 | $l->t('Cannot write into "config" directory!'), |
| 259 | 259 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
| 260 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 260 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
| 261 | 261 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
| 262 | - [ $urlGenerator->linkToDocs('admin-config') ] ) |
|
| 262 | + [$urlGenerator->linkToDocs('admin-config')]) |
|
| 263 | 263 | ); |
| 264 | 264 | } |
| 265 | 265 | |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | if (OC::$CLI) { |
| 276 | 276 | throw new Exception('Not installed'); |
| 277 | 277 | } else { |
| 278 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 279 | - header('Location: ' . $url); |
|
| 278 | + $url = OC::$WEBROOT.'/index.php'; |
|
| 279 | + header('Location: '.$url); |
|
| 280 | 280 | } |
| 281 | 281 | exit(); |
| 282 | 282 | } |
@@ -383,14 +383,14 @@ discard block |
||
| 383 | 383 | $incompatibleShippedApps = []; |
| 384 | 384 | foreach ($incompatibleApps as $appInfo) { |
| 385 | 385 | if ($appManager->isShipped($appInfo['id'])) { |
| 386 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 386 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | if (!empty($incompatibleShippedApps)) { |
| 391 | 391 | $l = \OC::$server->getL10N('core'); |
| 392 | 392 | $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
| 393 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 393 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | public static function initSession() { |
| 404 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 404 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 405 | 405 | ini_set('session.cookie_secure', true); |
| 406 | 406 | } |
| 407 | 407 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | ini_set('session.cookie_httponly', 'true'); |
| 410 | 410 | |
| 411 | 411 | // set the cookie path to the Nextcloud directory |
| 412 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 412 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
| 413 | 413 | ini_set('session.cookie_path', $cookie_path); |
| 414 | 414 | |
| 415 | 415 | // Let the session name be changed in the initSession Hook |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | // session timeout |
| 444 | 444 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
| 445 | 445 | if (isset($_COOKIE[session_name()])) { |
| 446 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 446 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
| 447 | 447 | } |
| 448 | 448 | \OC::$server->getUserSession()->logout(); |
| 449 | 449 | } |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | continue; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 468 | + $file = $appPath.'/appinfo/classpath.php'; |
|
| 469 | 469 | if (file_exists($file)) { |
| 470 | 470 | require_once $file; |
| 471 | 471 | } |
@@ -493,14 +493,14 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | // Append __Host to the cookie if it meets the requirements |
| 495 | 495 | $cookiePrefix = ''; |
| 496 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 496 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 497 | 497 | $cookiePrefix = '__Host-'; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - foreach($policies as $policy) { |
|
| 500 | + foreach ($policies as $policy) { |
|
| 501 | 501 | header( |
| 502 | 502 | sprintf( |
| 503 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 503 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 504 | 504 | $cookiePrefix, |
| 505 | 505 | $policy, |
| 506 | 506 | $cookieParams['path'], |
@@ -532,31 +532,31 @@ discard block |
||
| 532 | 532 | '/^WebDAVFS/', |
| 533 | 533 | '/^Microsoft-WebDAV-MiniRedir/', |
| 534 | 534 | ]; |
| 535 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 535 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 536 | 536 | return; |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - if(count($_COOKIE) > 0) { |
|
| 539 | + if (count($_COOKIE) > 0) { |
|
| 540 | 540 | $requestUri = $request->getScriptName(); |
| 541 | 541 | $processingScript = explode('/', $requestUri); |
| 542 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 542 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 543 | 543 | |
| 544 | 544 | // index.php routes are handled in the middleware |
| 545 | - if($processingScript === 'index.php') { |
|
| 545 | + if ($processingScript === 'index.php') { |
|
| 546 | 546 | return; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | // All other endpoints require the lax and the strict cookie |
| 550 | - if(!$request->passesStrictCookieCheck()) { |
|
| 550 | + if (!$request->passesStrictCookieCheck()) { |
|
| 551 | 551 | self::sendSameSiteCookies(); |
| 552 | 552 | // Debug mode gets access to the resources without strict cookie |
| 553 | 553 | // due to the fact that the SabreDAV browser also lives there. |
| 554 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 554 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 555 | 555 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
| 556 | 556 | exit(); |
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 559 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 560 | 560 | self::sendSameSiteCookies(); |
| 561 | 561 | } |
| 562 | 562 | } |
@@ -567,12 +567,12 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | // register autoloader |
| 569 | 569 | $loaderStart = microtime(true); |
| 570 | - require_once __DIR__ . '/autoloader.php'; |
|
| 570 | + require_once __DIR__.'/autoloader.php'; |
|
| 571 | 571 | self::$loader = new \OC\Autoloader([ |
| 572 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 572 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
| 573 | 573 | ]); |
| 574 | 574 | if (defined('PHPUNIT_RUN')) { |
| 575 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 575 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
| 576 | 576 | } |
| 577 | 577 | spl_autoload_register(array(self::$loader, 'load')); |
| 578 | 578 | $loaderEnd = microtime(true); |
@@ -580,12 +580,12 @@ discard block |
||
| 580 | 580 | self::$CLI = (php_sapi_name() == 'cli'); |
| 581 | 581 | |
| 582 | 582 | // Add default composer PSR-4 autoloader |
| 583 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 583 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
| 584 | 584 | |
| 585 | 585 | try { |
| 586 | 586 | self::initPaths(); |
| 587 | 587 | // setup 3rdparty autoloader |
| 588 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 588 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
| 589 | 589 | if (!file_exists($vendorAutoLoad)) { |
| 590 | 590 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
| 591 | 591 | } |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | if (!self::$CLI) { |
| 596 | 596 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
| 597 | 597 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
| 598 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 598 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 599 | 599 | } |
| 600 | 600 | // we can't use the template error page here, because this needs the |
| 601 | 601 | // DI container which isn't available yet |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | @ini_set('display_errors', '0'); |
| 614 | 614 | @ini_set('log_errors', '1'); |
| 615 | 615 | |
| 616 | - if(!date_default_timezone_set('UTC')) { |
|
| 616 | + if (!date_default_timezone_set('UTC')) { |
|
| 617 | 617 | throw new \RuntimeException('Could not set timezone to UTC'); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -667,11 +667,11 @@ discard block |
||
| 667 | 667 | // Convert l10n string into regular string for usage in database |
| 668 | 668 | $staticErrors = []; |
| 669 | 669 | foreach ($errors as $error) { |
| 670 | - echo $error['error'] . "\n"; |
|
| 671 | - echo $error['hint'] . "\n\n"; |
|
| 670 | + echo $error['error']."\n"; |
|
| 671 | + echo $error['hint']."\n\n"; |
|
| 672 | 672 | $staticErrors[] = [ |
| 673 | - 'error' => (string)$error['error'], |
|
| 674 | - 'hint' => (string)$error['hint'], |
|
| 673 | + 'error' => (string) $error['error'], |
|
| 674 | + 'hint' => (string) $error['hint'], |
|
| 675 | 675 | ]; |
| 676 | 676 | } |
| 677 | 677 | |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | } |
| 694 | 694 | //try to set the session lifetime |
| 695 | 695 | $sessionLifeTime = self::getSessionLifeTime(); |
| 696 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 696 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
| 697 | 697 | |
| 698 | 698 | $systemConfig = \OC::$server->getSystemConfig(); |
| 699 | 699 | |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
| 742 | 742 | |
| 743 | 743 | // Check whether the sample configuration has been copied |
| 744 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 744 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 745 | 745 | $l = \OC::$server->getL10N('lib'); |
| 746 | 746 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
| 747 | 747 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -767,11 +767,11 @@ discard block |
||
| 767 | 767 | ) { |
| 768 | 768 | // Allow access to CSS resources |
| 769 | 769 | $isScssRequest = false; |
| 770 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 770 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 771 | 771 | $isScssRequest = true; |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - if(substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 774 | + if (substr($request->getRequestUri(), -11) === '/status.php') { |
|
| 775 | 775 | OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); |
| 776 | 776 | header('Status: 400 Bad Request'); |
| 777 | 777 | header('Content-Type: application/json'); |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | // NOTE: This will be replaced to use OCP |
| 813 | 813 | $userSession = self::$server->getUserSession(); |
| 814 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 814 | + $userSession->listen('\OC\User', 'postLogin', function() use ($userSession) { |
|
| 815 | 815 | if (!defined('PHPUNIT_RUN')) { |
| 816 | 816 | // reset brute force delay for this IP address and username |
| 817 | 817 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
@@ -948,12 +948,12 @@ discard block |
||
| 948 | 948 | // emergency app disabling |
| 949 | 949 | if ($requestPath === '/disableapp' |
| 950 | 950 | && $request->getMethod() === 'POST' |
| 951 | - && ((array)$request->getParam('appid')) !== '' |
|
| 951 | + && ((array) $request->getParam('appid')) !== '' |
|
| 952 | 952 | ) { |
| 953 | 953 | \OC_JSON::callCheck(); |
| 954 | 954 | \OC_JSON::checkAdminUser(); |
| 955 | - $appIds = (array)$request->getParam('appid'); |
|
| 956 | - foreach($appIds as $appId) { |
|
| 955 | + $appIds = (array) $request->getParam('appid'); |
|
| 956 | + foreach ($appIds as $appId) { |
|
| 957 | 957 | $appId = \OC_App::cleanAppId($appId); |
| 958 | 958 | \OC::$server->getAppManager()->disableApp($appId); |
| 959 | 959 | } |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | if (!\OCP\Util::needUpgrade() |
| 969 | 969 | && !$systemConfig->getValue('maintenance', false)) { |
| 970 | 970 | // For logged-in users: Load everything |
| 971 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 971 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 972 | 972 | OC_App::loadApps(); |
| 973 | 973 | } else { |
| 974 | 974 | // For guests: Load only filesystem and logging |