@@ -61,1388 +61,1388 @@ |
||
| 61 | 61 | use OCP\IUser; |
| 62 | 62 | |
| 63 | 63 | class OC_Util { |
| 64 | - public static $scripts = array(); |
|
| 65 | - public static $styles = array(); |
|
| 66 | - public static $headers = array(); |
|
| 67 | - private static $rootMounted = false; |
|
| 68 | - private static $fsSetup = false; |
|
| 69 | - |
|
| 70 | - /** @var array Local cache of version.php */ |
|
| 71 | - private static $versionCache = null; |
|
| 72 | - |
|
| 73 | - protected static function getAppManager() { |
|
| 74 | - return \OC::$server->getAppManager(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - private static function initLocalStorageRootFS() { |
|
| 78 | - // mount local file backend as root |
|
| 79 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | - //first set up the local "root" storage |
|
| 81 | - \OC\Files\Filesystem::initMountManager(); |
|
| 82 | - if (!self::$rootMounted) { |
|
| 83 | - \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | - self::$rootMounted = true; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * mounting an object storage as the root fs will in essence remove the |
|
| 90 | - * necessity of a data folder being present. |
|
| 91 | - * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | - * |
|
| 93 | - * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | - */ |
|
| 95 | - private static function initObjectStoreRootFS($config) { |
|
| 96 | - // check misconfiguration |
|
| 97 | - if (empty($config['class'])) { |
|
| 98 | - \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | - } |
|
| 100 | - if (!isset($config['arguments'])) { |
|
| 101 | - $config['arguments'] = array(); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // instantiate object store implementation |
|
| 105 | - $name = $config['class']; |
|
| 106 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | - $segments = explode('\\', $name); |
|
| 108 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | - } |
|
| 110 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | - // mount with plain / root object store implementation |
|
| 112 | - $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | - |
|
| 114 | - // mount object storage as root |
|
| 115 | - \OC\Files\Filesystem::initMountManager(); |
|
| 116 | - if (!self::$rootMounted) { |
|
| 117 | - \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | - self::$rootMounted = true; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Can be set up |
|
| 124 | - * |
|
| 125 | - * @param string $user |
|
| 126 | - * @return boolean |
|
| 127 | - * @description configure the initial filesystem based on the configuration |
|
| 128 | - */ |
|
| 129 | - public static function setupFS($user = '') { |
|
| 130 | - //setting up the filesystem twice can only lead to trouble |
|
| 131 | - if (self::$fsSetup) { |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 136 | - |
|
| 137 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 138 | - if ($user === null) { |
|
| 139 | - $user = ''; |
|
| 140 | - } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 141 | - $user = OC_User::getUser(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 145 | - OC_App::loadApps(array('filesystem')); |
|
| 146 | - |
|
| 147 | - // the filesystem will finish when $user is not empty, |
|
| 148 | - // mark fs setup here to avoid doing the setup from loading |
|
| 149 | - // OC_Filesystem |
|
| 150 | - if ($user != '') { |
|
| 151 | - self::$fsSetup = true; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - \OC\Files\Filesystem::initMountManager(); |
|
| 155 | - |
|
| 156 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 157 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 159 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 160 | - $storage->setMountOptions($mount->getOptions()); |
|
| 161 | - } |
|
| 162 | - return $storage; |
|
| 163 | - }); |
|
| 164 | - |
|
| 165 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 167 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 168 | - 'storage' => $storage, |
|
| 169 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 170 | - ]); |
|
| 171 | - } |
|
| 172 | - return $storage; |
|
| 173 | - }); |
|
| 174 | - |
|
| 175 | - // install storage availability wrapper, before most other wrappers |
|
| 176 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 177 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 178 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 179 | - } |
|
| 180 | - return $storage; |
|
| 181 | - }); |
|
| 182 | - |
|
| 183 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 185 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 186 | - } |
|
| 187 | - return $storage; |
|
| 188 | - }); |
|
| 189 | - |
|
| 190 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 191 | - // set up quota for home storages, even for other users |
|
| 192 | - // which can happen when using sharing |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @var \OC\Files\Storage\Storage $storage |
|
| 196 | - */ |
|
| 197 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 198 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 199 | - ) { |
|
| 200 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 201 | - if (is_object($storage->getUser())) { |
|
| 202 | - $user = $storage->getUser()->getUID(); |
|
| 203 | - $quota = OC_Util::getUserQuota($user); |
|
| 204 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 205 | - return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $storage; |
|
| 211 | - }); |
|
| 212 | - |
|
| 213 | - OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 214 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 215 | - |
|
| 216 | - //check if we are using an object storage |
|
| 217 | - $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 218 | - if (isset($objectStore)) { |
|
| 219 | - self::initObjectStoreRootFS($objectStore); |
|
| 220 | - } else { |
|
| 221 | - self::initLocalStorageRootFS(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if ($user != '' && !OCP\User::userExists($user)) { |
|
| 225 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - //if we aren't logged in, there is no use to set up the filesystem |
|
| 230 | - if ($user != "") { |
|
| 231 | - |
|
| 232 | - $userDir = '/' . $user . '/files'; |
|
| 233 | - |
|
| 234 | - //jail the user into his "home" directory |
|
| 235 | - \OC\Files\Filesystem::init($user, $userDir); |
|
| 236 | - |
|
| 237 | - OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 238 | - } |
|
| 239 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 240 | - return true; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * check if a password is required for each public link |
|
| 245 | - * |
|
| 246 | - * @return boolean |
|
| 247 | - */ |
|
| 248 | - public static function isPublicLinkPasswordRequired() { |
|
| 249 | - $appConfig = \OC::$server->getAppConfig(); |
|
| 250 | - $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 251 | - return ($enforcePassword === 'yes') ? true : false; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * check if sharing is disabled for the current user |
|
| 256 | - * @param IConfig $config |
|
| 257 | - * @param IGroupManager $groupManager |
|
| 258 | - * @param IUser|null $user |
|
| 259 | - * @return bool |
|
| 260 | - */ |
|
| 261 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 262 | - if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 263 | - $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 264 | - $excludedGroups = json_decode($groupsList); |
|
| 265 | - if (is_null($excludedGroups)) { |
|
| 266 | - $excludedGroups = explode(',', $groupsList); |
|
| 267 | - $newValue = json_encode($excludedGroups); |
|
| 268 | - $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 269 | - } |
|
| 270 | - $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 271 | - if (!empty($usersGroups)) { |
|
| 272 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 273 | - // if the user is only in groups which are disabled for sharing then |
|
| 274 | - // sharing is also disabled for the user |
|
| 275 | - if (empty($remainingGroups)) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * check if share API enforces a default expire date |
|
| 285 | - * |
|
| 286 | - * @return boolean |
|
| 287 | - */ |
|
| 288 | - public static function isDefaultExpireDateEnforced() { |
|
| 289 | - $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 290 | - $enforceDefaultExpireDate = false; |
|
| 291 | - if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 292 | - $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 293 | - $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - return $enforceDefaultExpireDate; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Get the quota of a user |
|
| 301 | - * |
|
| 302 | - * @param string $userId |
|
| 303 | - * @return int Quota bytes |
|
| 304 | - */ |
|
| 305 | - public static function getUserQuota($userId) { |
|
| 306 | - $user = \OC::$server->getUserManager()->get($userId); |
|
| 307 | - if (is_null($user)) { |
|
| 308 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 309 | - } |
|
| 310 | - $userQuota = $user->getQuota(); |
|
| 311 | - if($userQuota === 'none') { |
|
| 312 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 313 | - } |
|
| 314 | - return OC_Helper::computerFileSize($userQuota); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * copies the skeleton to the users /files |
|
| 319 | - * |
|
| 320 | - * @param String $userId |
|
| 321 | - * @param \OCP\Files\Folder $userDirectory |
|
| 322 | - * @throws \RuntimeException |
|
| 323 | - */ |
|
| 324 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 325 | - |
|
| 326 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 327 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 328 | - |
|
| 329 | - if ($instanceId === null) { |
|
| 330 | - throw new \RuntimeException('no instance id!'); |
|
| 331 | - } |
|
| 332 | - $appdata = 'appdata_' . $instanceId; |
|
| 333 | - if ($userId === $appdata) { |
|
| 334 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if (!empty($skeletonDirectory)) { |
|
| 338 | - \OCP\Util::writeLog( |
|
| 339 | - 'files_skeleton', |
|
| 340 | - 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 341 | - \OCP\Util::DEBUG |
|
| 342 | - ); |
|
| 343 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 344 | - // update the file cache |
|
| 345 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * copies a directory recursively by using streams |
|
| 351 | - * |
|
| 352 | - * @param string $source |
|
| 353 | - * @param \OCP\Files\Folder $target |
|
| 354 | - * @return void |
|
| 355 | - */ |
|
| 356 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 357 | - $logger = \OC::$server->getLogger(); |
|
| 358 | - |
|
| 359 | - // Verify if folder exists |
|
| 360 | - $dir = opendir($source); |
|
| 361 | - if($dir === false) { |
|
| 362 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Copy the files |
|
| 367 | - while (false !== ($file = readdir($dir))) { |
|
| 368 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 369 | - if (is_dir($source . '/' . $file)) { |
|
| 370 | - $child = $target->newFolder($file); |
|
| 371 | - self::copyr($source . '/' . $file, $child); |
|
| 372 | - } else { |
|
| 373 | - $child = $target->newFile($file); |
|
| 374 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | - if($sourceStream === false) { |
|
| 376 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 377 | - closedir($dir); |
|
| 378 | - return; |
|
| 379 | - } |
|
| 380 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - closedir($dir); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public static function tearDownFS() { |
|
| 391 | - \OC\Files\Filesystem::tearDown(); |
|
| 392 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 393 | - self::$fsSetup = false; |
|
| 394 | - self::$rootMounted = false; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * get the current installed version of ownCloud |
|
| 399 | - * |
|
| 400 | - * @return array |
|
| 401 | - */ |
|
| 402 | - public static function getVersion() { |
|
| 403 | - OC_Util::loadVersion(); |
|
| 404 | - return self::$versionCache['OC_Version']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * get the current installed version string of ownCloud |
|
| 409 | - * |
|
| 410 | - * @return string |
|
| 411 | - */ |
|
| 412 | - public static function getVersionString() { |
|
| 413 | - OC_Util::loadVersion(); |
|
| 414 | - return self::$versionCache['OC_VersionString']; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @deprecated the value is of no use anymore |
|
| 419 | - * @return string |
|
| 420 | - */ |
|
| 421 | - public static function getEditionString() { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @description get the update channel of the current installed of ownCloud. |
|
| 427 | - * @return string |
|
| 428 | - */ |
|
| 429 | - public static function getChannel() { |
|
| 430 | - OC_Util::loadVersion(); |
|
| 431 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * @description get the build number of the current installed of ownCloud. |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public static function getBuild() { |
|
| 439 | - OC_Util::loadVersion(); |
|
| 440 | - return self::$versionCache['OC_Build']; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * @description load the version.php into the session as cache |
|
| 445 | - */ |
|
| 446 | - private static function loadVersion() { |
|
| 447 | - if (self::$versionCache !== null) { |
|
| 448 | - return; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | - require OC::$SERVERROOT . '/version.php'; |
|
| 453 | - /** @var $timestamp int */ |
|
| 454 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 455 | - /** @var $OC_Version string */ |
|
| 456 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 457 | - /** @var $OC_VersionString string */ |
|
| 458 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 459 | - /** @var $OC_Build string */ |
|
| 460 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 461 | - |
|
| 462 | - /** @var $OC_Channel string */ |
|
| 463 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 468 | - * |
|
| 469 | - * @param string $application application to get the files from |
|
| 470 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 471 | - * @param string $file the file inside of the above folder |
|
| 472 | - * @return string the path |
|
| 473 | - */ |
|
| 474 | - private static function generatePath($application, $directory, $file) { |
|
| 475 | - if (is_null($file)) { |
|
| 476 | - $file = $application; |
|
| 477 | - $application = ""; |
|
| 478 | - } |
|
| 479 | - if (!empty($application)) { |
|
| 480 | - return "$application/$directory/$file"; |
|
| 481 | - } else { |
|
| 482 | - return "$directory/$file"; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * add a javascript file |
|
| 488 | - * |
|
| 489 | - * @param string $application application id |
|
| 490 | - * @param string|null $file filename |
|
| 491 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 492 | - * @return void |
|
| 493 | - */ |
|
| 494 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 495 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 496 | - |
|
| 497 | - // core js files need separate handling |
|
| 498 | - if ($application !== 'core' && $file !== null) { |
|
| 499 | - self::addTranslations ( $application ); |
|
| 500 | - } |
|
| 501 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * add a javascript file from the vendor sub folder |
|
| 506 | - * |
|
| 507 | - * @param string $application application id |
|
| 508 | - * @param string|null $file filename |
|
| 509 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 510 | - * @return void |
|
| 511 | - */ |
|
| 512 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 513 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 514 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * add a translation JS file |
|
| 519 | - * |
|
| 520 | - * @param string $application application id |
|
| 521 | - * @param string $languageCode language code, defaults to the current language |
|
| 522 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 523 | - */ |
|
| 524 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 525 | - if (is_null($languageCode)) { |
|
| 526 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 527 | - } |
|
| 528 | - if (!empty($application)) { |
|
| 529 | - $path = "$application/l10n/$languageCode"; |
|
| 530 | - } else { |
|
| 531 | - $path = "l10n/$languageCode"; |
|
| 532 | - } |
|
| 533 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * add a css file |
|
| 538 | - * |
|
| 539 | - * @param string $application application id |
|
| 540 | - * @param string|null $file filename |
|
| 541 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 545 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 546 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * add a css file from the vendor sub folder |
|
| 551 | - * |
|
| 552 | - * @param string $application application id |
|
| 553 | - * @param string|null $file filename |
|
| 554 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 558 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * add an external resource css/js file |
|
| 564 | - * |
|
| 565 | - * @param string $application application id |
|
| 566 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 567 | - * @param string $path |
|
| 568 | - * @param string $type (script or style) |
|
| 569 | - * @return void |
|
| 570 | - */ |
|
| 571 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 572 | - |
|
| 573 | - if ($type === "style") { |
|
| 574 | - if (!in_array($path, self::$styles)) { |
|
| 575 | - if ($prepend === true) { |
|
| 576 | - array_unshift ( self::$styles, $path ); |
|
| 577 | - } else { |
|
| 578 | - self::$styles[] = $path; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } elseif ($type === "script") { |
|
| 582 | - if (!in_array($path, self::$scripts)) { |
|
| 583 | - if ($prepend === true) { |
|
| 584 | - array_unshift ( self::$scripts, $path ); |
|
| 585 | - } else { |
|
| 586 | - self::$scripts [] = $path; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Add a custom element to the header |
|
| 594 | - * If $text is null then the element will be written as empty element. |
|
| 595 | - * So use "" to get a closing tag. |
|
| 596 | - * @param string $tag tag name of the element |
|
| 597 | - * @param array $attributes array of attributes for the element |
|
| 598 | - * @param string $text the text content for the element |
|
| 599 | - */ |
|
| 600 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 601 | - self::$headers[] = array( |
|
| 602 | - 'tag' => $tag, |
|
| 603 | - 'attributes' => $attributes, |
|
| 604 | - 'text' => $text |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * formats a timestamp in the "right" way |
|
| 610 | - * |
|
| 611 | - * @param int $timestamp |
|
| 612 | - * @param bool $dateOnly option to omit time from the result |
|
| 613 | - * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 614 | - * @return string timestamp |
|
| 615 | - * |
|
| 616 | - * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 617 | - */ |
|
| 618 | - public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 619 | - if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 620 | - $timeZone = new \DateTimeZone($timeZone); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
| 624 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 625 | - if ($dateOnly) { |
|
| 626 | - return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 627 | - } |
|
| 628 | - return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * check if the current server configuration is suitable for ownCloud |
|
| 633 | - * |
|
| 634 | - * @param \OC\SystemConfig $config |
|
| 635 | - * @return array arrays with error messages and hints |
|
| 636 | - */ |
|
| 637 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 638 | - $l = \OC::$server->getL10N('lib'); |
|
| 639 | - $errors = array(); |
|
| 640 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 641 | - |
|
| 642 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 643 | - // this check needs to be done every time |
|
| 644 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 648 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 649 | - return $errors; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $webServerRestart = false; |
|
| 653 | - $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 654 | - \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 655 | - |
|
| 656 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | - |
|
| 658 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | - if (empty($availableDatabases)) { |
|
| 660 | - $errors[] = array( |
|
| 661 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | - 'hint' => '' //TODO: sane hint |
|
| 663 | - ); |
|
| 664 | - $webServerRestart = true; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - // Check if config folder is writable. |
|
| 668 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | - $errors[] = array( |
|
| 671 | - 'error' => $l->t('Cannot write into "config" directory'), |
|
| 672 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 673 | - . '%sgiving the webserver write access to the config directory%s.', |
|
| 674 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | - ); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - // Check if there is a writable install folder. |
|
| 680 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 681 | - if (OC_App::getInstallPath() === null |
|
| 682 | - || !is_writable(OC_App::getInstallPath()) |
|
| 683 | - || !is_readable(OC_App::getInstallPath()) |
|
| 684 | - ) { |
|
| 685 | - $errors[] = array( |
|
| 686 | - 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 687 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 688 | - . '%sgiving the webserver write access to the apps directory%s' |
|
| 689 | - . ' or disabling the appstore in the config file.', |
|
| 690 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - // Create root dir. |
|
| 695 | - if ($config->getValue('installed', false)) { |
|
| 696 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 697 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 698 | - if ($success) { |
|
| 699 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 700 | - } else { |
|
| 701 | - $errors[] = array( |
|
| 702 | - 'error' => $l->t('Cannot create "data" directory (%s)', array($CONFIG_DATADIRECTORY)), |
|
| 703 | - 'hint' => $l->t('This can usually be fixed by ' |
|
| 704 | - . '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.', |
|
| 705 | - array($urlGenerator->linkToDocs('admin-dir_permissions'))) |
|
| 706 | - ); |
|
| 707 | - } |
|
| 708 | - } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 709 | - //common hint for all file permissions error messages |
|
| 710 | - $permissionsHint = $l->t('Permissions can usually be fixed by ' |
|
| 711 | - . '%sgiving the webserver write access to the root directory%s.', |
|
| 712 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')); |
|
| 713 | - $errors[] = array( |
|
| 714 | - 'error' => 'Data directory (' . $CONFIG_DATADIRECTORY . ') not writable', |
|
| 715 | - 'hint' => $permissionsHint |
|
| 716 | - ); |
|
| 717 | - } else { |
|
| 718 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 723 | - $errors[] = array( |
|
| 724 | - 'error' => $l->t('Setting locale to %s failed', |
|
| 725 | - array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 726 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 727 | - 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - // Contains the dependencies that should be checked against |
|
| 732 | - // classes = class_exists |
|
| 733 | - // functions = function_exists |
|
| 734 | - // defined = defined |
|
| 735 | - // ini = ini_get |
|
| 736 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 737 | - // When adding new checks always verify that they pass on Travis as well |
|
| 738 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 739 | - $dependencies = array( |
|
| 740 | - 'classes' => array( |
|
| 741 | - 'ZipArchive' => 'zip', |
|
| 742 | - 'DOMDocument' => 'dom', |
|
| 743 | - 'XMLWriter' => 'XMLWriter', |
|
| 744 | - 'XMLReader' => 'XMLReader', |
|
| 745 | - ), |
|
| 746 | - 'functions' => [ |
|
| 747 | - 'xml_parser_create' => 'libxml', |
|
| 748 | - 'mb_strcut' => 'mb multibyte', |
|
| 749 | - 'ctype_digit' => 'ctype', |
|
| 750 | - 'json_encode' => 'JSON', |
|
| 751 | - 'gd_info' => 'GD', |
|
| 752 | - 'gzencode' => 'zlib', |
|
| 753 | - 'iconv' => 'iconv', |
|
| 754 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 755 | - 'hash' => 'HASH Message Digest Framework', |
|
| 756 | - 'curl_init' => 'cURL', |
|
| 757 | - 'openssl_verify' => 'OpenSSL', |
|
| 758 | - ], |
|
| 759 | - 'defined' => array( |
|
| 760 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 761 | - ), |
|
| 762 | - 'ini' => [ |
|
| 763 | - 'default_charset' => 'UTF-8', |
|
| 764 | - ], |
|
| 765 | - ); |
|
| 766 | - $missingDependencies = array(); |
|
| 767 | - $invalidIniSettings = []; |
|
| 768 | - $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 772 | - * and prevents installation. Once HHVM is more compatible with our |
|
| 773 | - * approach to check for these values we should re-enable those |
|
| 774 | - * checks. |
|
| 775 | - */ |
|
| 776 | - $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 777 | - if (!self::runningOnHhvm()) { |
|
| 778 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 779 | - if (!class_exists($class)) { |
|
| 780 | - $missingDependencies[] = $module; |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 784 | - if (!function_exists($function)) { |
|
| 785 | - $missingDependencies[] = $module; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 789 | - if (!defined($defined)) { |
|
| 790 | - $missingDependencies[] = $module; |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 794 | - if (is_bool($expected)) { |
|
| 795 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 796 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - if (is_int($expected)) { |
|
| 800 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 801 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - if (is_string($expected)) { |
|
| 805 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 806 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - foreach($missingDependencies as $missingDependency) { |
|
| 813 | - $errors[] = array( |
|
| 814 | - 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 815 | - 'hint' => $moduleHint |
|
| 816 | - ); |
|
| 817 | - $webServerRestart = true; |
|
| 818 | - } |
|
| 819 | - foreach($invalidIniSettings as $setting) { |
|
| 820 | - if(is_bool($setting[1])) { |
|
| 821 | - $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 822 | - } |
|
| 823 | - $errors[] = [ |
|
| 824 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 825 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 826 | - ]; |
|
| 827 | - $webServerRestart = true; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 832 | - * module is installed as it will return null if the checking setting is |
|
| 833 | - * not available and thus a check on the boolean value fails. |
|
| 834 | - * |
|
| 835 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 836 | - * check somehow in the long-term. |
|
| 837 | - */ |
|
| 838 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 840 | - $errors[] = array( |
|
| 841 | - 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 842 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 843 | - ); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - if(function_exists('xml_parser_create') && |
|
| 847 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 848 | - $version = LIBXML_LOADED_VERSION; |
|
| 849 | - $major = floor($version/10000); |
|
| 850 | - $version -= ($major * 10000); |
|
| 851 | - $minor = floor($version/100); |
|
| 852 | - $version -= ($minor * 100); |
|
| 853 | - $patch = $version; |
|
| 854 | - $errors[] = array( |
|
| 855 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 856 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 857 | - ); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - if (!self::isAnnotationsWorking()) { |
|
| 861 | - $errors[] = array( |
|
| 862 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 863 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 864 | - ); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 868 | - $errors[] = array( |
|
| 869 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 870 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 875 | - |
|
| 876 | - // Cache the result of this function |
|
| 877 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 878 | - |
|
| 879 | - return $errors; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Check the database version |
|
| 884 | - * |
|
| 885 | - * @return array errors array |
|
| 886 | - */ |
|
| 887 | - public static function checkDatabaseVersion() { |
|
| 888 | - $l = \OC::$server->getL10N('lib'); |
|
| 889 | - $errors = array(); |
|
| 890 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 891 | - if ($dbType === 'pgsql') { |
|
| 892 | - // check PostgreSQL version |
|
| 893 | - try { |
|
| 894 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 895 | - $data = $result->fetchRow(); |
|
| 896 | - if (isset($data['server_version'])) { |
|
| 897 | - $version = $data['server_version']; |
|
| 898 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 899 | - $errors[] = array( |
|
| 900 | - 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 901 | - 'hint' => $l->t('Please upgrade your database version') |
|
| 902 | - ); |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 906 | - $logger = \OC::$server->getLogger(); |
|
| 907 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 908 | - $logger->logException($e); |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - return $errors; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * Check for correct file permissions of data directory |
|
| 916 | - * |
|
| 917 | - * @param string $dataDirectory |
|
| 918 | - * @return array arrays with error messages and hints |
|
| 919 | - */ |
|
| 920 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 921 | - $l = \OC::$server->getL10N('lib'); |
|
| 922 | - $errors = array(); |
|
| 923 | - $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 924 | - . ' cannot be listed by other users.'); |
|
| 925 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 926 | - if (substr($perms, -1) != '0') { |
|
| 927 | - chmod($dataDirectory, 0770); |
|
| 928 | - clearstatcache(); |
|
| 929 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 930 | - if (substr($perms, 2, 1) != '0') { |
|
| 931 | - $errors[] = array( |
|
| 932 | - 'error' => $l->t('Data directory (%s) is readable by other users', array($dataDirectory)), |
|
| 933 | - 'hint' => $permissionsModHint |
|
| 934 | - ); |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - return $errors; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Check that the data directory exists and is valid by |
|
| 942 | - * checking the existence of the ".ocdata" file. |
|
| 943 | - * |
|
| 944 | - * @param string $dataDirectory data directory path |
|
| 945 | - * @return array errors found |
|
| 946 | - */ |
|
| 947 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 948 | - $l = \OC::$server->getL10N('lib'); |
|
| 949 | - $errors = []; |
|
| 950 | - if ($dataDirectory[0] !== '/') { |
|
| 951 | - $errors[] = [ |
|
| 952 | - 'error' => $l->t('Data directory (%s) must be an absolute path', [$dataDirectory]), |
|
| 953 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 954 | - ]; |
|
| 955 | - } |
|
| 956 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 957 | - $errors[] = [ |
|
| 958 | - 'error' => $l->t('Data directory (%s) is invalid', [$dataDirectory]), |
|
| 959 | - 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 960 | - ' ".ocdata" in its root.') |
|
| 961 | - ]; |
|
| 962 | - } |
|
| 963 | - return $errors; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Check if the user is logged in, redirects to home if not. With |
|
| 968 | - * redirect URL parameter to the request URI. |
|
| 969 | - * |
|
| 970 | - * @return void |
|
| 971 | - */ |
|
| 972 | - public static function checkLoggedIn() { |
|
| 973 | - // Check if we are a user |
|
| 974 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 975 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | - 'core.login.showLoginForm', |
|
| 977 | - [ |
|
| 978 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 979 | - ] |
|
| 980 | - ) |
|
| 981 | - ); |
|
| 982 | - exit(); |
|
| 983 | - } |
|
| 984 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 985 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 986 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | - exit(); |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * Check if the user is a admin, redirects to home if not |
|
| 993 | - * |
|
| 994 | - * @return void |
|
| 995 | - */ |
|
| 996 | - public static function checkAdminUser() { |
|
| 997 | - OC_Util::checkLoggedIn(); |
|
| 998 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 999 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | - exit(); |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * Check if the user is a subadmin, redirects to home if not |
|
| 1006 | - * |
|
| 1007 | - * @return null|boolean $groups where the current user is subadmin |
|
| 1008 | - */ |
|
| 1009 | - public static function checkSubAdminUser() { |
|
| 1010 | - OC_Util::checkLoggedIn(); |
|
| 1011 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1012 | - $isSubAdmin = false; |
|
| 1013 | - if($userObject !== null) { |
|
| 1014 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - if (!$isSubAdmin) { |
|
| 1018 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | - exit(); |
|
| 1020 | - } |
|
| 1021 | - return true; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - /** |
|
| 1025 | - * Returns the URL of the default page |
|
| 1026 | - * based on the system configuration and |
|
| 1027 | - * the apps visible for the current user |
|
| 1028 | - * |
|
| 1029 | - * @return string URL |
|
| 1030 | - */ |
|
| 1031 | - public static function getDefaultPageUrl() { |
|
| 1032 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1033 | - // Deny the redirect if the URL contains a @ |
|
| 1034 | - // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1035 | - if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1036 | - $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1037 | - } else { |
|
| 1038 | - $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1039 | - if ($defaultPage) { |
|
| 1040 | - $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1041 | - } else { |
|
| 1042 | - $appId = 'files'; |
|
| 1043 | - $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1044 | - // find the first app that is enabled for the current user |
|
| 1045 | - foreach ($defaultApps as $defaultApp) { |
|
| 1046 | - $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1047 | - if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1048 | - $appId = $defaultApp; |
|
| 1049 | - break; |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1055 | - } else { |
|
| 1056 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - return $location; |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * Redirect to the user default page |
|
| 1065 | - * |
|
| 1066 | - * @return void |
|
| 1067 | - */ |
|
| 1068 | - public static function redirectToDefaultPage() { |
|
| 1069 | - $location = self::getDefaultPageUrl(); |
|
| 1070 | - header('Location: ' . $location); |
|
| 1071 | - exit(); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * get an id unique for this instance |
|
| 1076 | - * |
|
| 1077 | - * @return string |
|
| 1078 | - */ |
|
| 1079 | - public static function getInstanceId() { |
|
| 1080 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1081 | - if (is_null($id)) { |
|
| 1082 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1083 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1085 | - } |
|
| 1086 | - return $id; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - /** |
|
| 1090 | - * Public function to sanitize HTML |
|
| 1091 | - * |
|
| 1092 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1093 | - * string or array of strings before displaying it on a web page. |
|
| 1094 | - * |
|
| 1095 | - * @param string|array $value |
|
| 1096 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1097 | - */ |
|
| 1098 | - public static function sanitizeHTML($value) { |
|
| 1099 | - if (is_array($value)) { |
|
| 1100 | - $value = array_map(function($value) { |
|
| 1101 | - return self::sanitizeHTML($value); |
|
| 1102 | - }, $value); |
|
| 1103 | - } else { |
|
| 1104 | - // Specify encoding for PHP<5.4 |
|
| 1105 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | - } |
|
| 1107 | - return $value; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Public function to encode url parameters |
|
| 1112 | - * |
|
| 1113 | - * This function is used to encode path to file before output. |
|
| 1114 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1115 | - * Character '/' is preserved as is. |
|
| 1116 | - * |
|
| 1117 | - * @param string $component part of URI to encode |
|
| 1118 | - * @return string |
|
| 1119 | - */ |
|
| 1120 | - public static function encodePath($component) { |
|
| 1121 | - $encoded = rawurlencode($component); |
|
| 1122 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1123 | - return $encoded; |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1128 | - // php dev server does not support htaccess |
|
| 1129 | - if (php_sapi_name() === 'cli-server') { |
|
| 1130 | - return false; |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - // testdata |
|
| 1134 | - $fileName = '/htaccesstest.txt'; |
|
| 1135 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1136 | - |
|
| 1137 | - // creating a test file |
|
| 1138 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1139 | - |
|
| 1140 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - $fp = @fopen($testFile, 'w'); |
|
| 1145 | - if (!$fp) { |
|
| 1146 | - throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1147 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1148 | - } |
|
| 1149 | - fwrite($fp, $testContent); |
|
| 1150 | - fclose($fp); |
|
| 1151 | - |
|
| 1152 | - return $testContent; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - /** |
|
| 1156 | - * Check if the .htaccess file is working |
|
| 1157 | - * @param \OCP\IConfig $config |
|
| 1158 | - * @return bool |
|
| 1159 | - * @throws Exception |
|
| 1160 | - * @throws \OC\HintException If the test file can't get written. |
|
| 1161 | - */ |
|
| 1162 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1163 | - |
|
| 1164 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1165 | - return true; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1169 | - if ($testContent === false) { |
|
| 1170 | - return false; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $fileName = '/htaccesstest.txt'; |
|
| 1174 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1175 | - |
|
| 1176 | - // accessing the file via http |
|
| 1177 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1178 | - try { |
|
| 1179 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1180 | - } catch (\Exception $e) { |
|
| 1181 | - $content = false; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - // cleanup |
|
| 1185 | - @unlink($testFile); |
|
| 1186 | - |
|
| 1187 | - /* |
|
| 64 | + public static $scripts = array(); |
|
| 65 | + public static $styles = array(); |
|
| 66 | + public static $headers = array(); |
|
| 67 | + private static $rootMounted = false; |
|
| 68 | + private static $fsSetup = false; |
|
| 69 | + |
|
| 70 | + /** @var array Local cache of version.php */ |
|
| 71 | + private static $versionCache = null; |
|
| 72 | + |
|
| 73 | + protected static function getAppManager() { |
|
| 74 | + return \OC::$server->getAppManager(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + private static function initLocalStorageRootFS() { |
|
| 78 | + // mount local file backend as root |
|
| 79 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 80 | + //first set up the local "root" storage |
|
| 81 | + \OC\Files\Filesystem::initMountManager(); |
|
| 82 | + if (!self::$rootMounted) { |
|
| 83 | + \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir' => $configDataDirectory), '/'); |
|
| 84 | + self::$rootMounted = true; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * mounting an object storage as the root fs will in essence remove the |
|
| 90 | + * necessity of a data folder being present. |
|
| 91 | + * TODO make home storage aware of this and use the object storage instead of local disk access |
|
| 92 | + * |
|
| 93 | + * @param array $config containing 'class' and optional 'arguments' |
|
| 94 | + */ |
|
| 95 | + private static function initObjectStoreRootFS($config) { |
|
| 96 | + // check misconfiguration |
|
| 97 | + if (empty($config['class'])) { |
|
| 98 | + \OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); |
|
| 99 | + } |
|
| 100 | + if (!isset($config['arguments'])) { |
|
| 101 | + $config['arguments'] = array(); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // instantiate object store implementation |
|
| 105 | + $name = $config['class']; |
|
| 106 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 107 | + $segments = explode('\\', $name); |
|
| 108 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 109 | + } |
|
| 110 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 111 | + // mount with plain / root object store implementation |
|
| 112 | + $config['class'] = '\OC\Files\ObjectStore\ObjectStoreStorage'; |
|
| 113 | + |
|
| 114 | + // mount object storage as root |
|
| 115 | + \OC\Files\Filesystem::initMountManager(); |
|
| 116 | + if (!self::$rootMounted) { |
|
| 117 | + \OC\Files\Filesystem::mount($config['class'], $config['arguments'], '/'); |
|
| 118 | + self::$rootMounted = true; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Can be set up |
|
| 124 | + * |
|
| 125 | + * @param string $user |
|
| 126 | + * @return boolean |
|
| 127 | + * @description configure the initial filesystem based on the configuration |
|
| 128 | + */ |
|
| 129 | + public static function setupFS($user = '') { |
|
| 130 | + //setting up the filesystem twice can only lead to trouble |
|
| 131 | + if (self::$fsSetup) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 136 | + |
|
| 137 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 138 | + if ($user === null) { |
|
| 139 | + $user = ''; |
|
| 140 | + } else if ($user == "" && \OC::$server->getUserSession()->isLoggedIn()) { |
|
| 141 | + $user = OC_User::getUser(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 145 | + OC_App::loadApps(array('filesystem')); |
|
| 146 | + |
|
| 147 | + // the filesystem will finish when $user is not empty, |
|
| 148 | + // mark fs setup here to avoid doing the setup from loading |
|
| 149 | + // OC_Filesystem |
|
| 150 | + if ($user != '') { |
|
| 151 | + self::$fsSetup = true; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + \OC\Files\Filesystem::initMountManager(); |
|
| 155 | + |
|
| 156 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 157 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 159 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 160 | + $storage->setMountOptions($mount->getOptions()); |
|
| 161 | + } |
|
| 162 | + return $storage; |
|
| 163 | + }); |
|
| 164 | + |
|
| 165 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 167 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 168 | + 'storage' => $storage, |
|
| 169 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 170 | + ]); |
|
| 171 | + } |
|
| 172 | + return $storage; |
|
| 173 | + }); |
|
| 174 | + |
|
| 175 | + // install storage availability wrapper, before most other wrappers |
|
| 176 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 177 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 178 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 179 | + } |
|
| 180 | + return $storage; |
|
| 181 | + }); |
|
| 182 | + |
|
| 183 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 185 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 186 | + } |
|
| 187 | + return $storage; |
|
| 188 | + }); |
|
| 189 | + |
|
| 190 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 191 | + // set up quota for home storages, even for other users |
|
| 192 | + // which can happen when using sharing |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @var \OC\Files\Storage\Storage $storage |
|
| 196 | + */ |
|
| 197 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 198 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 199 | + ) { |
|
| 200 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 201 | + if (is_object($storage->getUser())) { |
|
| 202 | + $user = $storage->getUser()->getUID(); |
|
| 203 | + $quota = OC_Util::getUserQuota($user); |
|
| 204 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 205 | + return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files')); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $storage; |
|
| 211 | + }); |
|
| 212 | + |
|
| 213 | + OC_Hook::emit('OC_Filesystem', 'preSetup', array('user' => $user)); |
|
| 214 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(true); |
|
| 215 | + |
|
| 216 | + //check if we are using an object storage |
|
| 217 | + $objectStore = \OC::$server->getSystemConfig()->getValue('objectstore', null); |
|
| 218 | + if (isset($objectStore)) { |
|
| 219 | + self::initObjectStoreRootFS($objectStore); |
|
| 220 | + } else { |
|
| 221 | + self::initLocalStorageRootFS(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if ($user != '' && !OCP\User::userExists($user)) { |
|
| 225 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + //if we aren't logged in, there is no use to set up the filesystem |
|
| 230 | + if ($user != "") { |
|
| 231 | + |
|
| 232 | + $userDir = '/' . $user . '/files'; |
|
| 233 | + |
|
| 234 | + //jail the user into his "home" directory |
|
| 235 | + \OC\Files\Filesystem::init($user, $userDir); |
|
| 236 | + |
|
| 237 | + OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir)); |
|
| 238 | + } |
|
| 239 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 240 | + return true; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * check if a password is required for each public link |
|
| 245 | + * |
|
| 246 | + * @return boolean |
|
| 247 | + */ |
|
| 248 | + public static function isPublicLinkPasswordRequired() { |
|
| 249 | + $appConfig = \OC::$server->getAppConfig(); |
|
| 250 | + $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no'); |
|
| 251 | + return ($enforcePassword === 'yes') ? true : false; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * check if sharing is disabled for the current user |
|
| 256 | + * @param IConfig $config |
|
| 257 | + * @param IGroupManager $groupManager |
|
| 258 | + * @param IUser|null $user |
|
| 259 | + * @return bool |
|
| 260 | + */ |
|
| 261 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 262 | + if ($config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
| 263 | + $groupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
| 264 | + $excludedGroups = json_decode($groupsList); |
|
| 265 | + if (is_null($excludedGroups)) { |
|
| 266 | + $excludedGroups = explode(',', $groupsList); |
|
| 267 | + $newValue = json_encode($excludedGroups); |
|
| 268 | + $config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
| 269 | + } |
|
| 270 | + $usersGroups = $groupManager->getUserGroupIds($user); |
|
| 271 | + if (!empty($usersGroups)) { |
|
| 272 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
| 273 | + // if the user is only in groups which are disabled for sharing then |
|
| 274 | + // sharing is also disabled for the user |
|
| 275 | + if (empty($remainingGroups)) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * check if share API enforces a default expire date |
|
| 285 | + * |
|
| 286 | + * @return boolean |
|
| 287 | + */ |
|
| 288 | + public static function isDefaultExpireDateEnforced() { |
|
| 289 | + $isDefaultExpireDateEnabled = \OCP\Config::getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 290 | + $enforceDefaultExpireDate = false; |
|
| 291 | + if ($isDefaultExpireDateEnabled === 'yes') { |
|
| 292 | + $value = \OCP\Config::getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 293 | + $enforceDefaultExpireDate = ($value === 'yes') ? true : false; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + return $enforceDefaultExpireDate; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Get the quota of a user |
|
| 301 | + * |
|
| 302 | + * @param string $userId |
|
| 303 | + * @return int Quota bytes |
|
| 304 | + */ |
|
| 305 | + public static function getUserQuota($userId) { |
|
| 306 | + $user = \OC::$server->getUserManager()->get($userId); |
|
| 307 | + if (is_null($user)) { |
|
| 308 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 309 | + } |
|
| 310 | + $userQuota = $user->getQuota(); |
|
| 311 | + if($userQuota === 'none') { |
|
| 312 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 313 | + } |
|
| 314 | + return OC_Helper::computerFileSize($userQuota); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * copies the skeleton to the users /files |
|
| 319 | + * |
|
| 320 | + * @param String $userId |
|
| 321 | + * @param \OCP\Files\Folder $userDirectory |
|
| 322 | + * @throws \RuntimeException |
|
| 323 | + */ |
|
| 324 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 325 | + |
|
| 326 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 327 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 328 | + |
|
| 329 | + if ($instanceId === null) { |
|
| 330 | + throw new \RuntimeException('no instance id!'); |
|
| 331 | + } |
|
| 332 | + $appdata = 'appdata_' . $instanceId; |
|
| 333 | + if ($userId === $appdata) { |
|
| 334 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if (!empty($skeletonDirectory)) { |
|
| 338 | + \OCP\Util::writeLog( |
|
| 339 | + 'files_skeleton', |
|
| 340 | + 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), |
|
| 341 | + \OCP\Util::DEBUG |
|
| 342 | + ); |
|
| 343 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 344 | + // update the file cache |
|
| 345 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * copies a directory recursively by using streams |
|
| 351 | + * |
|
| 352 | + * @param string $source |
|
| 353 | + * @param \OCP\Files\Folder $target |
|
| 354 | + * @return void |
|
| 355 | + */ |
|
| 356 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 357 | + $logger = \OC::$server->getLogger(); |
|
| 358 | + |
|
| 359 | + // Verify if folder exists |
|
| 360 | + $dir = opendir($source); |
|
| 361 | + if($dir === false) { |
|
| 362 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Copy the files |
|
| 367 | + while (false !== ($file = readdir($dir))) { |
|
| 368 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 369 | + if (is_dir($source . '/' . $file)) { |
|
| 370 | + $child = $target->newFolder($file); |
|
| 371 | + self::copyr($source . '/' . $file, $child); |
|
| 372 | + } else { |
|
| 373 | + $child = $target->newFile($file); |
|
| 374 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | + if($sourceStream === false) { |
|
| 376 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 377 | + closedir($dir); |
|
| 378 | + return; |
|
| 379 | + } |
|
| 380 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + closedir($dir); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public static function tearDownFS() { |
|
| 391 | + \OC\Files\Filesystem::tearDown(); |
|
| 392 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 393 | + self::$fsSetup = false; |
|
| 394 | + self::$rootMounted = false; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * get the current installed version of ownCloud |
|
| 399 | + * |
|
| 400 | + * @return array |
|
| 401 | + */ |
|
| 402 | + public static function getVersion() { |
|
| 403 | + OC_Util::loadVersion(); |
|
| 404 | + return self::$versionCache['OC_Version']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * get the current installed version string of ownCloud |
|
| 409 | + * |
|
| 410 | + * @return string |
|
| 411 | + */ |
|
| 412 | + public static function getVersionString() { |
|
| 413 | + OC_Util::loadVersion(); |
|
| 414 | + return self::$versionCache['OC_VersionString']; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @deprecated the value is of no use anymore |
|
| 419 | + * @return string |
|
| 420 | + */ |
|
| 421 | + public static function getEditionString() { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @description get the update channel of the current installed of ownCloud. |
|
| 427 | + * @return string |
|
| 428 | + */ |
|
| 429 | + public static function getChannel() { |
|
| 430 | + OC_Util::loadVersion(); |
|
| 431 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * @description get the build number of the current installed of ownCloud. |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public static function getBuild() { |
|
| 439 | + OC_Util::loadVersion(); |
|
| 440 | + return self::$versionCache['OC_Build']; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * @description load the version.php into the session as cache |
|
| 445 | + */ |
|
| 446 | + private static function loadVersion() { |
|
| 447 | + if (self::$versionCache !== null) { |
|
| 448 | + return; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | + require OC::$SERVERROOT . '/version.php'; |
|
| 453 | + /** @var $timestamp int */ |
|
| 454 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 455 | + /** @var $OC_Version string */ |
|
| 456 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 457 | + /** @var $OC_VersionString string */ |
|
| 458 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 459 | + /** @var $OC_Build string */ |
|
| 460 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 461 | + |
|
| 462 | + /** @var $OC_Channel string */ |
|
| 463 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 468 | + * |
|
| 469 | + * @param string $application application to get the files from |
|
| 470 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 471 | + * @param string $file the file inside of the above folder |
|
| 472 | + * @return string the path |
|
| 473 | + */ |
|
| 474 | + private static function generatePath($application, $directory, $file) { |
|
| 475 | + if (is_null($file)) { |
|
| 476 | + $file = $application; |
|
| 477 | + $application = ""; |
|
| 478 | + } |
|
| 479 | + if (!empty($application)) { |
|
| 480 | + return "$application/$directory/$file"; |
|
| 481 | + } else { |
|
| 482 | + return "$directory/$file"; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * add a javascript file |
|
| 488 | + * |
|
| 489 | + * @param string $application application id |
|
| 490 | + * @param string|null $file filename |
|
| 491 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 492 | + * @return void |
|
| 493 | + */ |
|
| 494 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 495 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 496 | + |
|
| 497 | + // core js files need separate handling |
|
| 498 | + if ($application !== 'core' && $file !== null) { |
|
| 499 | + self::addTranslations ( $application ); |
|
| 500 | + } |
|
| 501 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * add a javascript file from the vendor sub folder |
|
| 506 | + * |
|
| 507 | + * @param string $application application id |
|
| 508 | + * @param string|null $file filename |
|
| 509 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 510 | + * @return void |
|
| 511 | + */ |
|
| 512 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 513 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 514 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * add a translation JS file |
|
| 519 | + * |
|
| 520 | + * @param string $application application id |
|
| 521 | + * @param string $languageCode language code, defaults to the current language |
|
| 522 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 523 | + */ |
|
| 524 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 525 | + if (is_null($languageCode)) { |
|
| 526 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 527 | + } |
|
| 528 | + if (!empty($application)) { |
|
| 529 | + $path = "$application/l10n/$languageCode"; |
|
| 530 | + } else { |
|
| 531 | + $path = "l10n/$languageCode"; |
|
| 532 | + } |
|
| 533 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * add a css file |
|
| 538 | + * |
|
| 539 | + * @param string $application application id |
|
| 540 | + * @param string|null $file filename |
|
| 541 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 545 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 546 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * add a css file from the vendor sub folder |
|
| 551 | + * |
|
| 552 | + * @param string $application application id |
|
| 553 | + * @param string|null $file filename |
|
| 554 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 558 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 559 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * add an external resource css/js file |
|
| 564 | + * |
|
| 565 | + * @param string $application application id |
|
| 566 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 567 | + * @param string $path |
|
| 568 | + * @param string $type (script or style) |
|
| 569 | + * @return void |
|
| 570 | + */ |
|
| 571 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 572 | + |
|
| 573 | + if ($type === "style") { |
|
| 574 | + if (!in_array($path, self::$styles)) { |
|
| 575 | + if ($prepend === true) { |
|
| 576 | + array_unshift ( self::$styles, $path ); |
|
| 577 | + } else { |
|
| 578 | + self::$styles[] = $path; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } elseif ($type === "script") { |
|
| 582 | + if (!in_array($path, self::$scripts)) { |
|
| 583 | + if ($prepend === true) { |
|
| 584 | + array_unshift ( self::$scripts, $path ); |
|
| 585 | + } else { |
|
| 586 | + self::$scripts [] = $path; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Add a custom element to the header |
|
| 594 | + * If $text is null then the element will be written as empty element. |
|
| 595 | + * So use "" to get a closing tag. |
|
| 596 | + * @param string $tag tag name of the element |
|
| 597 | + * @param array $attributes array of attributes for the element |
|
| 598 | + * @param string $text the text content for the element |
|
| 599 | + */ |
|
| 600 | + public static function addHeader($tag, $attributes, $text=null) { |
|
| 601 | + self::$headers[] = array( |
|
| 602 | + 'tag' => $tag, |
|
| 603 | + 'attributes' => $attributes, |
|
| 604 | + 'text' => $text |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * formats a timestamp in the "right" way |
|
| 610 | + * |
|
| 611 | + * @param int $timestamp |
|
| 612 | + * @param bool $dateOnly option to omit time from the result |
|
| 613 | + * @param DateTimeZone|string $timeZone where the given timestamp shall be converted to |
|
| 614 | + * @return string timestamp |
|
| 615 | + * |
|
| 616 | + * @deprecated Use \OC::$server->query('DateTimeFormatter') instead |
|
| 617 | + */ |
|
| 618 | + public static function formatDate($timestamp, $dateOnly = false, $timeZone = null) { |
|
| 619 | + if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) { |
|
| 620 | + $timeZone = new \DateTimeZone($timeZone); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
| 624 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 625 | + if ($dateOnly) { |
|
| 626 | + return $formatter->formatDate($timestamp, 'long', $timeZone); |
|
| 627 | + } |
|
| 628 | + return $formatter->formatDateTime($timestamp, 'long', 'long', $timeZone); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * check if the current server configuration is suitable for ownCloud |
|
| 633 | + * |
|
| 634 | + * @param \OC\SystemConfig $config |
|
| 635 | + * @return array arrays with error messages and hints |
|
| 636 | + */ |
|
| 637 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 638 | + $l = \OC::$server->getL10N('lib'); |
|
| 639 | + $errors = array(); |
|
| 640 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 641 | + |
|
| 642 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 643 | + // this check needs to be done every time |
|
| 644 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 648 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 649 | + return $errors; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $webServerRestart = false; |
|
| 653 | + $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), |
|
| 654 | + \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); |
|
| 655 | + |
|
| 656 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | + |
|
| 658 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | + if (empty($availableDatabases)) { |
|
| 660 | + $errors[] = array( |
|
| 661 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | + 'hint' => '' //TODO: sane hint |
|
| 663 | + ); |
|
| 664 | + $webServerRestart = true; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + // Check if config folder is writable. |
|
| 668 | + if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | + $errors[] = array( |
|
| 671 | + 'error' => $l->t('Cannot write into "config" directory'), |
|
| 672 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 673 | + . '%sgiving the webserver write access to the config directory%s.', |
|
| 674 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | + ); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + // Check if there is a writable install folder. |
|
| 680 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 681 | + if (OC_App::getInstallPath() === null |
|
| 682 | + || !is_writable(OC_App::getInstallPath()) |
|
| 683 | + || !is_readable(OC_App::getInstallPath()) |
|
| 684 | + ) { |
|
| 685 | + $errors[] = array( |
|
| 686 | + 'error' => $l->t('Cannot write into "apps" directory'), |
|
| 687 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 688 | + . '%sgiving the webserver write access to the apps directory%s' |
|
| 689 | + . ' or disabling the appstore in the config file.', |
|
| 690 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + // Create root dir. |
|
| 695 | + if ($config->getValue('installed', false)) { |
|
| 696 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 697 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 698 | + if ($success) { |
|
| 699 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 700 | + } else { |
|
| 701 | + $errors[] = array( |
|
| 702 | + 'error' => $l->t('Cannot create "data" directory (%s)', array($CONFIG_DATADIRECTORY)), |
|
| 703 | + 'hint' => $l->t('This can usually be fixed by ' |
|
| 704 | + . '<a href="%s" target="_blank" rel="noreferrer">giving the webserver write access to the root directory</a>.', |
|
| 705 | + array($urlGenerator->linkToDocs('admin-dir_permissions'))) |
|
| 706 | + ); |
|
| 707 | + } |
|
| 708 | + } else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 709 | + //common hint for all file permissions error messages |
|
| 710 | + $permissionsHint = $l->t('Permissions can usually be fixed by ' |
|
| 711 | + . '%sgiving the webserver write access to the root directory%s.', |
|
| 712 | + array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')); |
|
| 713 | + $errors[] = array( |
|
| 714 | + 'error' => 'Data directory (' . $CONFIG_DATADIRECTORY . ') not writable', |
|
| 715 | + 'hint' => $permissionsHint |
|
| 716 | + ); |
|
| 717 | + } else { |
|
| 718 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 723 | + $errors[] = array( |
|
| 724 | + 'error' => $l->t('Setting locale to %s failed', |
|
| 725 | + array('en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 726 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8')), |
|
| 727 | + 'hint' => $l->t('Please install one of these locales on your system and restart your webserver.') |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + // Contains the dependencies that should be checked against |
|
| 732 | + // classes = class_exists |
|
| 733 | + // functions = function_exists |
|
| 734 | + // defined = defined |
|
| 735 | + // ini = ini_get |
|
| 736 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 737 | + // When adding new checks always verify that they pass on Travis as well |
|
| 738 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 739 | + $dependencies = array( |
|
| 740 | + 'classes' => array( |
|
| 741 | + 'ZipArchive' => 'zip', |
|
| 742 | + 'DOMDocument' => 'dom', |
|
| 743 | + 'XMLWriter' => 'XMLWriter', |
|
| 744 | + 'XMLReader' => 'XMLReader', |
|
| 745 | + ), |
|
| 746 | + 'functions' => [ |
|
| 747 | + 'xml_parser_create' => 'libxml', |
|
| 748 | + 'mb_strcut' => 'mb multibyte', |
|
| 749 | + 'ctype_digit' => 'ctype', |
|
| 750 | + 'json_encode' => 'JSON', |
|
| 751 | + 'gd_info' => 'GD', |
|
| 752 | + 'gzencode' => 'zlib', |
|
| 753 | + 'iconv' => 'iconv', |
|
| 754 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 755 | + 'hash' => 'HASH Message Digest Framework', |
|
| 756 | + 'curl_init' => 'cURL', |
|
| 757 | + 'openssl_verify' => 'OpenSSL', |
|
| 758 | + ], |
|
| 759 | + 'defined' => array( |
|
| 760 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 761 | + ), |
|
| 762 | + 'ini' => [ |
|
| 763 | + 'default_charset' => 'UTF-8', |
|
| 764 | + ], |
|
| 765 | + ); |
|
| 766 | + $missingDependencies = array(); |
|
| 767 | + $invalidIniSettings = []; |
|
| 768 | + $moduleHint = $l->t('Please ask your server administrator to install the module.'); |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * FIXME: The dependency check does not work properly on HHVM on the moment |
|
| 772 | + * and prevents installation. Once HHVM is more compatible with our |
|
| 773 | + * approach to check for these values we should re-enable those |
|
| 774 | + * checks. |
|
| 775 | + */ |
|
| 776 | + $iniWrapper = \OC::$server->getIniWrapper(); |
|
| 777 | + if (!self::runningOnHhvm()) { |
|
| 778 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 779 | + if (!class_exists($class)) { |
|
| 780 | + $missingDependencies[] = $module; |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 784 | + if (!function_exists($function)) { |
|
| 785 | + $missingDependencies[] = $module; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 789 | + if (!defined($defined)) { |
|
| 790 | + $missingDependencies[] = $module; |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 794 | + if (is_bool($expected)) { |
|
| 795 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 796 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + if (is_int($expected)) { |
|
| 800 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 801 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + if (is_string($expected)) { |
|
| 805 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 806 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + foreach($missingDependencies as $missingDependency) { |
|
| 813 | + $errors[] = array( |
|
| 814 | + 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
|
| 815 | + 'hint' => $moduleHint |
|
| 816 | + ); |
|
| 817 | + $webServerRestart = true; |
|
| 818 | + } |
|
| 819 | + foreach($invalidIniSettings as $setting) { |
|
| 820 | + if(is_bool($setting[1])) { |
|
| 821 | + $setting[1] = ($setting[1]) ? 'on' : 'off'; |
|
| 822 | + } |
|
| 823 | + $errors[] = [ |
|
| 824 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 825 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 826 | + ]; |
|
| 827 | + $webServerRestart = true; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 832 | + * module is installed as it will return null if the checking setting is |
|
| 833 | + * not available and thus a check on the boolean value fails. |
|
| 834 | + * |
|
| 835 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 836 | + * check somehow in the long-term. |
|
| 837 | + */ |
|
| 838 | + if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 840 | + $errors[] = array( |
|
| 841 | + 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 842 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini') |
|
| 843 | + ); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + if(function_exists('xml_parser_create') && |
|
| 847 | + LIBXML_LOADED_VERSION < 20700 ) { |
|
| 848 | + $version = LIBXML_LOADED_VERSION; |
|
| 849 | + $major = floor($version/10000); |
|
| 850 | + $version -= ($major * 10000); |
|
| 851 | + $minor = floor($version/100); |
|
| 852 | + $version -= ($minor * 100); |
|
| 853 | + $patch = $version; |
|
| 854 | + $errors[] = array( |
|
| 855 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 856 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 857 | + ); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + if (!self::isAnnotationsWorking()) { |
|
| 861 | + $errors[] = array( |
|
| 862 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 863 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 864 | + ); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 868 | + $errors[] = array( |
|
| 869 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 870 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 875 | + |
|
| 876 | + // Cache the result of this function |
|
| 877 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 878 | + |
|
| 879 | + return $errors; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Check the database version |
|
| 884 | + * |
|
| 885 | + * @return array errors array |
|
| 886 | + */ |
|
| 887 | + public static function checkDatabaseVersion() { |
|
| 888 | + $l = \OC::$server->getL10N('lib'); |
|
| 889 | + $errors = array(); |
|
| 890 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 891 | + if ($dbType === 'pgsql') { |
|
| 892 | + // check PostgreSQL version |
|
| 893 | + try { |
|
| 894 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 895 | + $data = $result->fetchRow(); |
|
| 896 | + if (isset($data['server_version'])) { |
|
| 897 | + $version = $data['server_version']; |
|
| 898 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 899 | + $errors[] = array( |
|
| 900 | + 'error' => $l->t('PostgreSQL >= 9 required'), |
|
| 901 | + 'hint' => $l->t('Please upgrade your database version') |
|
| 902 | + ); |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + } catch (\Doctrine\DBAL\DBALException $e) { |
|
| 906 | + $logger = \OC::$server->getLogger(); |
|
| 907 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 908 | + $logger->logException($e); |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + return $errors; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * Check for correct file permissions of data directory |
|
| 916 | + * |
|
| 917 | + * @param string $dataDirectory |
|
| 918 | + * @return array arrays with error messages and hints |
|
| 919 | + */ |
|
| 920 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 921 | + $l = \OC::$server->getL10N('lib'); |
|
| 922 | + $errors = array(); |
|
| 923 | + $permissionsModHint = $l->t('Please change the permissions to 0770 so that the directory' |
|
| 924 | + . ' cannot be listed by other users.'); |
|
| 925 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 926 | + if (substr($perms, -1) != '0') { |
|
| 927 | + chmod($dataDirectory, 0770); |
|
| 928 | + clearstatcache(); |
|
| 929 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 930 | + if (substr($perms, 2, 1) != '0') { |
|
| 931 | + $errors[] = array( |
|
| 932 | + 'error' => $l->t('Data directory (%s) is readable by other users', array($dataDirectory)), |
|
| 933 | + 'hint' => $permissionsModHint |
|
| 934 | + ); |
|
| 935 | + } |
|
| 936 | + } |
|
| 937 | + return $errors; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Check that the data directory exists and is valid by |
|
| 942 | + * checking the existence of the ".ocdata" file. |
|
| 943 | + * |
|
| 944 | + * @param string $dataDirectory data directory path |
|
| 945 | + * @return array errors found |
|
| 946 | + */ |
|
| 947 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 948 | + $l = \OC::$server->getL10N('lib'); |
|
| 949 | + $errors = []; |
|
| 950 | + if ($dataDirectory[0] !== '/') { |
|
| 951 | + $errors[] = [ |
|
| 952 | + 'error' => $l->t('Data directory (%s) must be an absolute path', [$dataDirectory]), |
|
| 953 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
|
| 954 | + ]; |
|
| 955 | + } |
|
| 956 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 957 | + $errors[] = [ |
|
| 958 | + 'error' => $l->t('Data directory (%s) is invalid', [$dataDirectory]), |
|
| 959 | + 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 960 | + ' ".ocdata" in its root.') |
|
| 961 | + ]; |
|
| 962 | + } |
|
| 963 | + return $errors; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Check if the user is logged in, redirects to home if not. With |
|
| 968 | + * redirect URL parameter to the request URI. |
|
| 969 | + * |
|
| 970 | + * @return void |
|
| 971 | + */ |
|
| 972 | + public static function checkLoggedIn() { |
|
| 973 | + // Check if we are a user |
|
| 974 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 975 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | + 'core.login.showLoginForm', |
|
| 977 | + [ |
|
| 978 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 979 | + ] |
|
| 980 | + ) |
|
| 981 | + ); |
|
| 982 | + exit(); |
|
| 983 | + } |
|
| 984 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 985 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 986 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | + exit(); |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * Check if the user is a admin, redirects to home if not |
|
| 993 | + * |
|
| 994 | + * @return void |
|
| 995 | + */ |
|
| 996 | + public static function checkAdminUser() { |
|
| 997 | + OC_Util::checkLoggedIn(); |
|
| 998 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 999 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | + exit(); |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * Check if the user is a subadmin, redirects to home if not |
|
| 1006 | + * |
|
| 1007 | + * @return null|boolean $groups where the current user is subadmin |
|
| 1008 | + */ |
|
| 1009 | + public static function checkSubAdminUser() { |
|
| 1010 | + OC_Util::checkLoggedIn(); |
|
| 1011 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
| 1012 | + $isSubAdmin = false; |
|
| 1013 | + if($userObject !== null) { |
|
| 1014 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + if (!$isSubAdmin) { |
|
| 1018 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | + exit(); |
|
| 1020 | + } |
|
| 1021 | + return true; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + /** |
|
| 1025 | + * Returns the URL of the default page |
|
| 1026 | + * based on the system configuration and |
|
| 1027 | + * the apps visible for the current user |
|
| 1028 | + * |
|
| 1029 | + * @return string URL |
|
| 1030 | + */ |
|
| 1031 | + public static function getDefaultPageUrl() { |
|
| 1032 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 1033 | + // Deny the redirect if the URL contains a @ |
|
| 1034 | + // This prevents unvalidated redirects like ?redirect_url=:[email protected] |
|
| 1035 | + if (isset($_REQUEST['redirect_url']) && strpos($_REQUEST['redirect_url'], '@') === false) { |
|
| 1036 | + $location = $urlGenerator->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); |
|
| 1037 | + } else { |
|
| 1038 | + $defaultPage = \OC::$server->getAppConfig()->getValue('core', 'defaultpage'); |
|
| 1039 | + if ($defaultPage) { |
|
| 1040 | + $location = $urlGenerator->getAbsoluteURL($defaultPage); |
|
| 1041 | + } else { |
|
| 1042 | + $appId = 'files'; |
|
| 1043 | + $defaultApps = explode(',', \OCP\Config::getSystemValue('defaultapp', 'files')); |
|
| 1044 | + // find the first app that is enabled for the current user |
|
| 1045 | + foreach ($defaultApps as $defaultApp) { |
|
| 1046 | + $defaultApp = OC_App::cleanAppId(strip_tags($defaultApp)); |
|
| 1047 | + if (static::getAppManager()->isEnabledForUser($defaultApp)) { |
|
| 1048 | + $appId = $defaultApp; |
|
| 1049 | + break; |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | + $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1055 | + } else { |
|
| 1056 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + return $location; |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * Redirect to the user default page |
|
| 1065 | + * |
|
| 1066 | + * @return void |
|
| 1067 | + */ |
|
| 1068 | + public static function redirectToDefaultPage() { |
|
| 1069 | + $location = self::getDefaultPageUrl(); |
|
| 1070 | + header('Location: ' . $location); |
|
| 1071 | + exit(); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * get an id unique for this instance |
|
| 1076 | + * |
|
| 1077 | + * @return string |
|
| 1078 | + */ |
|
| 1079 | + public static function getInstanceId() { |
|
| 1080 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1081 | + if (is_null($id)) { |
|
| 1082 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1083 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1085 | + } |
|
| 1086 | + return $id; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + /** |
|
| 1090 | + * Public function to sanitize HTML |
|
| 1091 | + * |
|
| 1092 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1093 | + * string or array of strings before displaying it on a web page. |
|
| 1094 | + * |
|
| 1095 | + * @param string|array $value |
|
| 1096 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1097 | + */ |
|
| 1098 | + public static function sanitizeHTML($value) { |
|
| 1099 | + if (is_array($value)) { |
|
| 1100 | + $value = array_map(function($value) { |
|
| 1101 | + return self::sanitizeHTML($value); |
|
| 1102 | + }, $value); |
|
| 1103 | + } else { |
|
| 1104 | + // Specify encoding for PHP<5.4 |
|
| 1105 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | + } |
|
| 1107 | + return $value; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Public function to encode url parameters |
|
| 1112 | + * |
|
| 1113 | + * This function is used to encode path to file before output. |
|
| 1114 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1115 | + * Character '/' is preserved as is. |
|
| 1116 | + * |
|
| 1117 | + * @param string $component part of URI to encode |
|
| 1118 | + * @return string |
|
| 1119 | + */ |
|
| 1120 | + public static function encodePath($component) { |
|
| 1121 | + $encoded = rawurlencode($component); |
|
| 1122 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1123 | + return $encoded; |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1128 | + // php dev server does not support htaccess |
|
| 1129 | + if (php_sapi_name() === 'cli-server') { |
|
| 1130 | + return false; |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + // testdata |
|
| 1134 | + $fileName = '/htaccesstest.txt'; |
|
| 1135 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1136 | + |
|
| 1137 | + // creating a test file |
|
| 1138 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1139 | + |
|
| 1140 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + $fp = @fopen($testFile, 'w'); |
|
| 1145 | + if (!$fp) { |
|
| 1146 | + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1147 | + 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1148 | + } |
|
| 1149 | + fwrite($fp, $testContent); |
|
| 1150 | + fclose($fp); |
|
| 1151 | + |
|
| 1152 | + return $testContent; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + /** |
|
| 1156 | + * Check if the .htaccess file is working |
|
| 1157 | + * @param \OCP\IConfig $config |
|
| 1158 | + * @return bool |
|
| 1159 | + * @throws Exception |
|
| 1160 | + * @throws \OC\HintException If the test file can't get written. |
|
| 1161 | + */ |
|
| 1162 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1163 | + |
|
| 1164 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1165 | + return true; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1169 | + if ($testContent === false) { |
|
| 1170 | + return false; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $fileName = '/htaccesstest.txt'; |
|
| 1174 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1175 | + |
|
| 1176 | + // accessing the file via http |
|
| 1177 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1178 | + try { |
|
| 1179 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1180 | + } catch (\Exception $e) { |
|
| 1181 | + $content = false; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + // cleanup |
|
| 1185 | + @unlink($testFile); |
|
| 1186 | + |
|
| 1187 | + /* |
|
| 1188 | 1188 | * If the content is not equal to test content our .htaccess |
| 1189 | 1189 | * is working as required |
| 1190 | 1190 | */ |
| 1191 | - return $content !== $testContent; |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Check if the setlocal call does not work. This can happen if the right |
|
| 1196 | - * local packages are not available on the server. |
|
| 1197 | - * |
|
| 1198 | - * @return bool |
|
| 1199 | - */ |
|
| 1200 | - public static function isSetLocaleWorking() { |
|
| 1201 | - \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1202 | - if ('' === basename('§')) { |
|
| 1203 | - return false; |
|
| 1204 | - } |
|
| 1205 | - return true; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * Check if it's possible to get the inline annotations |
|
| 1210 | - * |
|
| 1211 | - * @return bool |
|
| 1212 | - */ |
|
| 1213 | - public static function isAnnotationsWorking() { |
|
| 1214 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1215 | - $docs = $reflection->getDocComment(); |
|
| 1216 | - |
|
| 1217 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - /** |
|
| 1221 | - * Check if the PHP module fileinfo is loaded. |
|
| 1222 | - * |
|
| 1223 | - * @return bool |
|
| 1224 | - */ |
|
| 1225 | - public static function fileInfoLoaded() { |
|
| 1226 | - return function_exists('finfo_open'); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * clear all levels of output buffering |
|
| 1231 | - * |
|
| 1232 | - * @return void |
|
| 1233 | - */ |
|
| 1234 | - public static function obEnd() { |
|
| 1235 | - while (ob_get_level()) { |
|
| 1236 | - ob_end_clean(); |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * Checks whether the server is running on Mac OS X |
|
| 1242 | - * |
|
| 1243 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1244 | - */ |
|
| 1245 | - public static function runningOnMac() { |
|
| 1246 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * Checks whether server is running on HHVM |
|
| 1251 | - * |
|
| 1252 | - * @return bool True if running on HHVM, false otherwise |
|
| 1253 | - */ |
|
| 1254 | - public static function runningOnHhvm() { |
|
| 1255 | - return defined('HHVM_VERSION'); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1260 | - * theme exists and take that one |
|
| 1261 | - * |
|
| 1262 | - * @return string the theme |
|
| 1263 | - */ |
|
| 1264 | - public static function getTheme() { |
|
| 1265 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1266 | - |
|
| 1267 | - if ($theme === '') { |
|
| 1268 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1269 | - $theme = 'default'; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return $theme; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Clear a single file from the opcode cache |
|
| 1278 | - * This is useful for writing to the config file |
|
| 1279 | - * in case the opcode cache does not re-validate files |
|
| 1280 | - * Returns true if successful, false if unsuccessful: |
|
| 1281 | - * caller should fall back on clearing the entire cache |
|
| 1282 | - * with clearOpcodeCache() if unsuccessful |
|
| 1283 | - * |
|
| 1284 | - * @param string $path the path of the file to clear from the cache |
|
| 1285 | - * @return bool true if underlying function returns true, otherwise false |
|
| 1286 | - */ |
|
| 1287 | - public static function deleteFromOpcodeCache($path) { |
|
| 1288 | - $ret = false; |
|
| 1289 | - if ($path) { |
|
| 1290 | - // APC >= 3.1.1 |
|
| 1291 | - if (function_exists('apc_delete_file')) { |
|
| 1292 | - $ret = @apc_delete_file($path); |
|
| 1293 | - } |
|
| 1294 | - // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1295 | - if (function_exists('opcache_invalidate')) { |
|
| 1296 | - $ret = opcache_invalidate($path); |
|
| 1297 | - } |
|
| 1298 | - } |
|
| 1299 | - return $ret; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Clear the opcode cache if one exists |
|
| 1304 | - * This is necessary for writing to the config file |
|
| 1305 | - * in case the opcode cache does not re-validate files |
|
| 1306 | - * |
|
| 1307 | - * @return void |
|
| 1308 | - */ |
|
| 1309 | - public static function clearOpcodeCache() { |
|
| 1310 | - // APC |
|
| 1311 | - if (function_exists('apc_clear_cache')) { |
|
| 1312 | - apc_clear_cache(); |
|
| 1313 | - } |
|
| 1314 | - // Zend Opcache |
|
| 1315 | - if (function_exists('accelerator_reset')) { |
|
| 1316 | - accelerator_reset(); |
|
| 1317 | - } |
|
| 1318 | - // XCache |
|
| 1319 | - if (function_exists('xcache_clear_cache')) { |
|
| 1320 | - if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1321 | - \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1322 | - } else { |
|
| 1323 | - @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1324 | - } |
|
| 1325 | - } |
|
| 1326 | - // Opcache (PHP >= 5.5) |
|
| 1327 | - if (function_exists('opcache_reset')) { |
|
| 1328 | - opcache_reset(); |
|
| 1329 | - } |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Normalize a unicode string |
|
| 1334 | - * |
|
| 1335 | - * @param string $value a not normalized string |
|
| 1336 | - * @return bool|string |
|
| 1337 | - */ |
|
| 1338 | - public static function normalizeUnicode($value) { |
|
| 1339 | - if(Normalizer::isNormalized($value)) { |
|
| 1340 | - return $value; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1344 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1345 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1346 | - return $value; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - return $normalizedValue; |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - /** |
|
| 1353 | - * @param boolean|string $file |
|
| 1354 | - * @return string |
|
| 1355 | - */ |
|
| 1356 | - public static function basename($file) { |
|
| 1357 | - $file = rtrim($file, '/'); |
|
| 1358 | - $t = explode('/', $file); |
|
| 1359 | - return array_pop($t); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * A human readable string is generated based on version and build number |
|
| 1364 | - * |
|
| 1365 | - * @return string |
|
| 1366 | - */ |
|
| 1367 | - public static function getHumanVersion() { |
|
| 1368 | - $version = OC_Util::getVersionString(); |
|
| 1369 | - $build = OC_Util::getBuild(); |
|
| 1370 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1371 | - $version .= ' Build:' . $build; |
|
| 1372 | - } |
|
| 1373 | - return $version; |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * Returns whether the given file name is valid |
|
| 1378 | - * |
|
| 1379 | - * @param string $file file name to check |
|
| 1380 | - * @return bool true if the file name is valid, false otherwise |
|
| 1381 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1382 | - */ |
|
| 1383 | - public static function isValidFileName($file) { |
|
| 1384 | - $trimmed = trim($file); |
|
| 1385 | - if ($trimmed === '') { |
|
| 1386 | - return false; |
|
| 1387 | - } |
|
| 1388 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1389 | - return false; |
|
| 1390 | - } |
|
| 1391 | - foreach (str_split($trimmed) as $char) { |
|
| 1392 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1393 | - return false; |
|
| 1394 | - } |
|
| 1395 | - } |
|
| 1396 | - return true; |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - /** |
|
| 1400 | - * Check whether the instance needs to perform an upgrade, |
|
| 1401 | - * either when the core version is higher or any app requires |
|
| 1402 | - * an upgrade. |
|
| 1403 | - * |
|
| 1404 | - * @param \OC\SystemConfig $config |
|
| 1405 | - * @return bool whether the core or any app needs an upgrade |
|
| 1406 | - * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1407 | - */ |
|
| 1408 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1409 | - if ($config->getValue('installed', false)) { |
|
| 1410 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1411 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1412 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1413 | - if ($versionDiff > 0) { |
|
| 1414 | - return true; |
|
| 1415 | - } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1416 | - // downgrade with debug |
|
| 1417 | - $installedMajor = explode('.', $installedVersion); |
|
| 1418 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1419 | - $currentMajor = explode('.', $currentVersion); |
|
| 1420 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1421 | - if ($installedMajor === $currentMajor) { |
|
| 1422 | - // Same major, allow downgrade for developers |
|
| 1423 | - return true; |
|
| 1424 | - } else { |
|
| 1425 | - // downgrade attempt, throw exception |
|
| 1426 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1427 | - } |
|
| 1428 | - } else if ($versionDiff < 0) { |
|
| 1429 | - // downgrade attempt, throw exception |
|
| 1430 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // also check for upgrades for apps (independently from the user) |
|
| 1434 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1435 | - $shouldUpgrade = false; |
|
| 1436 | - foreach ($apps as $app) { |
|
| 1437 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1438 | - $shouldUpgrade = true; |
|
| 1439 | - break; |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - return $shouldUpgrade; |
|
| 1443 | - } else { |
|
| 1444 | - return false; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1191 | + return $content !== $testContent; |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Check if the setlocal call does not work. This can happen if the right |
|
| 1196 | + * local packages are not available on the server. |
|
| 1197 | + * |
|
| 1198 | + * @return bool |
|
| 1199 | + */ |
|
| 1200 | + public static function isSetLocaleWorking() { |
|
| 1201 | + \Patchwork\Utf8\Bootup::initLocale(); |
|
| 1202 | + if ('' === basename('§')) { |
|
| 1203 | + return false; |
|
| 1204 | + } |
|
| 1205 | + return true; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * Check if it's possible to get the inline annotations |
|
| 1210 | + * |
|
| 1211 | + * @return bool |
|
| 1212 | + */ |
|
| 1213 | + public static function isAnnotationsWorking() { |
|
| 1214 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1215 | + $docs = $reflection->getDocComment(); |
|
| 1216 | + |
|
| 1217 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + /** |
|
| 1221 | + * Check if the PHP module fileinfo is loaded. |
|
| 1222 | + * |
|
| 1223 | + * @return bool |
|
| 1224 | + */ |
|
| 1225 | + public static function fileInfoLoaded() { |
|
| 1226 | + return function_exists('finfo_open'); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * clear all levels of output buffering |
|
| 1231 | + * |
|
| 1232 | + * @return void |
|
| 1233 | + */ |
|
| 1234 | + public static function obEnd() { |
|
| 1235 | + while (ob_get_level()) { |
|
| 1236 | + ob_end_clean(); |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Checks whether the server is running on Mac OS X |
|
| 1242 | + * |
|
| 1243 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1244 | + */ |
|
| 1245 | + public static function runningOnMac() { |
|
| 1246 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * Checks whether server is running on HHVM |
|
| 1251 | + * |
|
| 1252 | + * @return bool True if running on HHVM, false otherwise |
|
| 1253 | + */ |
|
| 1254 | + public static function runningOnHhvm() { |
|
| 1255 | + return defined('HHVM_VERSION'); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1260 | + * theme exists and take that one |
|
| 1261 | + * |
|
| 1262 | + * @return string the theme |
|
| 1263 | + */ |
|
| 1264 | + public static function getTheme() { |
|
| 1265 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1266 | + |
|
| 1267 | + if ($theme === '') { |
|
| 1268 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1269 | + $theme = 'default'; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return $theme; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Clear a single file from the opcode cache |
|
| 1278 | + * This is useful for writing to the config file |
|
| 1279 | + * in case the opcode cache does not re-validate files |
|
| 1280 | + * Returns true if successful, false if unsuccessful: |
|
| 1281 | + * caller should fall back on clearing the entire cache |
|
| 1282 | + * with clearOpcodeCache() if unsuccessful |
|
| 1283 | + * |
|
| 1284 | + * @param string $path the path of the file to clear from the cache |
|
| 1285 | + * @return bool true if underlying function returns true, otherwise false |
|
| 1286 | + */ |
|
| 1287 | + public static function deleteFromOpcodeCache($path) { |
|
| 1288 | + $ret = false; |
|
| 1289 | + if ($path) { |
|
| 1290 | + // APC >= 3.1.1 |
|
| 1291 | + if (function_exists('apc_delete_file')) { |
|
| 1292 | + $ret = @apc_delete_file($path); |
|
| 1293 | + } |
|
| 1294 | + // Zend OpCache >= 7.0.0, PHP >= 5.5.0 |
|
| 1295 | + if (function_exists('opcache_invalidate')) { |
|
| 1296 | + $ret = opcache_invalidate($path); |
|
| 1297 | + } |
|
| 1298 | + } |
|
| 1299 | + return $ret; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Clear the opcode cache if one exists |
|
| 1304 | + * This is necessary for writing to the config file |
|
| 1305 | + * in case the opcode cache does not re-validate files |
|
| 1306 | + * |
|
| 1307 | + * @return void |
|
| 1308 | + */ |
|
| 1309 | + public static function clearOpcodeCache() { |
|
| 1310 | + // APC |
|
| 1311 | + if (function_exists('apc_clear_cache')) { |
|
| 1312 | + apc_clear_cache(); |
|
| 1313 | + } |
|
| 1314 | + // Zend Opcache |
|
| 1315 | + if (function_exists('accelerator_reset')) { |
|
| 1316 | + accelerator_reset(); |
|
| 1317 | + } |
|
| 1318 | + // XCache |
|
| 1319 | + if (function_exists('xcache_clear_cache')) { |
|
| 1320 | + if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { |
|
| 1321 | + \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); |
|
| 1322 | + } else { |
|
| 1323 | + @xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 1324 | + } |
|
| 1325 | + } |
|
| 1326 | + // Opcache (PHP >= 5.5) |
|
| 1327 | + if (function_exists('opcache_reset')) { |
|
| 1328 | + opcache_reset(); |
|
| 1329 | + } |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Normalize a unicode string |
|
| 1334 | + * |
|
| 1335 | + * @param string $value a not normalized string |
|
| 1336 | + * @return bool|string |
|
| 1337 | + */ |
|
| 1338 | + public static function normalizeUnicode($value) { |
|
| 1339 | + if(Normalizer::isNormalized($value)) { |
|
| 1340 | + return $value; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1344 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1345 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1346 | + return $value; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + return $normalizedValue; |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + /** |
|
| 1353 | + * @param boolean|string $file |
|
| 1354 | + * @return string |
|
| 1355 | + */ |
|
| 1356 | + public static function basename($file) { |
|
| 1357 | + $file = rtrim($file, '/'); |
|
| 1358 | + $t = explode('/', $file); |
|
| 1359 | + return array_pop($t); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * A human readable string is generated based on version and build number |
|
| 1364 | + * |
|
| 1365 | + * @return string |
|
| 1366 | + */ |
|
| 1367 | + public static function getHumanVersion() { |
|
| 1368 | + $version = OC_Util::getVersionString(); |
|
| 1369 | + $build = OC_Util::getBuild(); |
|
| 1370 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1371 | + $version .= ' Build:' . $build; |
|
| 1372 | + } |
|
| 1373 | + return $version; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * Returns whether the given file name is valid |
|
| 1378 | + * |
|
| 1379 | + * @param string $file file name to check |
|
| 1380 | + * @return bool true if the file name is valid, false otherwise |
|
| 1381 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1382 | + */ |
|
| 1383 | + public static function isValidFileName($file) { |
|
| 1384 | + $trimmed = trim($file); |
|
| 1385 | + if ($trimmed === '') { |
|
| 1386 | + return false; |
|
| 1387 | + } |
|
| 1388 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1389 | + return false; |
|
| 1390 | + } |
|
| 1391 | + foreach (str_split($trimmed) as $char) { |
|
| 1392 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1393 | + return false; |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + return true; |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * Check whether the instance needs to perform an upgrade, |
|
| 1401 | + * either when the core version is higher or any app requires |
|
| 1402 | + * an upgrade. |
|
| 1403 | + * |
|
| 1404 | + * @param \OC\SystemConfig $config |
|
| 1405 | + * @return bool whether the core or any app needs an upgrade |
|
| 1406 | + * @throws \OC\HintException When the upgrade from the given version is not allowed |
|
| 1407 | + */ |
|
| 1408 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1409 | + if ($config->getValue('installed', false)) { |
|
| 1410 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1411 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1412 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1413 | + if ($versionDiff > 0) { |
|
| 1414 | + return true; |
|
| 1415 | + } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1416 | + // downgrade with debug |
|
| 1417 | + $installedMajor = explode('.', $installedVersion); |
|
| 1418 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1419 | + $currentMajor = explode('.', $currentVersion); |
|
| 1420 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1421 | + if ($installedMajor === $currentMajor) { |
|
| 1422 | + // Same major, allow downgrade for developers |
|
| 1423 | + return true; |
|
| 1424 | + } else { |
|
| 1425 | + // downgrade attempt, throw exception |
|
| 1426 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1427 | + } |
|
| 1428 | + } else if ($versionDiff < 0) { |
|
| 1429 | + // downgrade attempt, throw exception |
|
| 1430 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // also check for upgrades for apps (independently from the user) |
|
| 1434 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1435 | + $shouldUpgrade = false; |
|
| 1436 | + foreach ($apps as $app) { |
|
| 1437 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1438 | + $shouldUpgrade = true; |
|
| 1439 | + break; |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + return $shouldUpgrade; |
|
| 1443 | + } else { |
|
| 1444 | + return false; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | 1447 | |
| 1448 | 1448 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | private static function initLocalStorageRootFS() { |
| 78 | 78 | // mount local file backend as root |
| 79 | - $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 79 | + $configDataDirectory = \OC::$server->getSystemConfig()->getValue("datadirectory", OC::$SERVERROOT."/data"); |
|
| 80 | 80 | //first set up the local "root" storage |
| 81 | 81 | \OC\Files\Filesystem::initMountManager(); |
| 82 | 82 | if (!self::$rootMounted) { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | \OC\Files\Filesystem::initMountManager(); |
| 155 | 155 | |
| 156 | 156 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 157 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 157 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 158 | 158 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
| 159 | 159 | /** @var \OC\Files\Storage\Common $storage */ |
| 160 | 160 | $storage->setMountOptions($mount->getOptions()); |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | return $storage; |
| 163 | 163 | }); |
| 164 | 164 | |
| 165 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 165 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 166 | 166 | if (!$mount->getOption('enable_sharing', true)) { |
| 167 | 167 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
| 168 | 168 | 'storage' => $storage, |
@@ -173,21 +173,21 @@ discard block |
||
| 173 | 173 | }); |
| 174 | 174 | |
| 175 | 175 | // install storage availability wrapper, before most other wrappers |
| 176 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, $storage) { |
|
| 176 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, $storage) { |
|
| 177 | 177 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 178 | 178 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
| 179 | 179 | } |
| 180 | 180 | return $storage; |
| 181 | 181 | }); |
| 182 | 182 | |
| 183 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 183 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 184 | 184 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 185 | 185 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
| 186 | 186 | } |
| 187 | 187 | return $storage; |
| 188 | 188 | }); |
| 189 | 189 | |
| 190 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 190 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 191 | 191 | // set up quota for home storages, even for other users |
| 192 | 192 | // which can happen when using sharing |
| 193 | 193 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | //if we aren't logged in, there is no use to set up the filesystem |
| 230 | 230 | if ($user != "") { |
| 231 | 231 | |
| 232 | - $userDir = '/' . $user . '/files'; |
|
| 232 | + $userDir = '/'.$user.'/files'; |
|
| 233 | 233 | |
| 234 | 234 | //jail the user into his "home" directory |
| 235 | 235 | \OC\Files\Filesystem::init($user, $userDir); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 309 | 309 | } |
| 310 | 310 | $userQuota = $user->getQuota(); |
| 311 | - if($userQuota === 'none') { |
|
| 311 | + if ($userQuota === 'none') { |
|
| 312 | 312 | return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
| 313 | 313 | } |
| 314 | 314 | return OC_Helper::computerFileSize($userQuota); |
@@ -323,15 +323,15 @@ discard block |
||
| 323 | 323 | */ |
| 324 | 324 | public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
| 325 | 325 | |
| 326 | - $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 326 | + $skeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
| 327 | 327 | $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
| 328 | 328 | |
| 329 | 329 | if ($instanceId === null) { |
| 330 | 330 | throw new \RuntimeException('no instance id!'); |
| 331 | 331 | } |
| 332 | - $appdata = 'appdata_' . $instanceId; |
|
| 332 | + $appdata = 'appdata_'.$instanceId; |
|
| 333 | 333 | if ($userId === $appdata) { |
| 334 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 334 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | if (!empty($skeletonDirectory)) { |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | // Verify if folder exists |
| 360 | 360 | $dir = opendir($source); |
| 361 | - if($dir === false) { |
|
| 361 | + if ($dir === false) { |
|
| 362 | 362 | $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
| 363 | 363 | return; |
| 364 | 364 | } |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | // Copy the files |
| 367 | 367 | while (false !== ($file = readdir($dir))) { |
| 368 | 368 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
| 369 | - if (is_dir($source . '/' . $file)) { |
|
| 369 | + if (is_dir($source.'/'.$file)) { |
|
| 370 | 370 | $child = $target->newFolder($file); |
| 371 | - self::copyr($source . '/' . $file, $child); |
|
| 371 | + self::copyr($source.'/'.$file, $child); |
|
| 372 | 372 | } else { |
| 373 | 373 | $child = $target->newFile($file); |
| 374 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 375 | - if($sourceStream === false) { |
|
| 376 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 374 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
| 375 | + if ($sourceStream === false) { |
|
| 376 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
| 377 | 377 | closedir($dir); |
| 378 | 378 | return; |
| 379 | 379 | } |
@@ -448,8 +448,8 @@ discard block |
||
| 448 | 448 | return; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 452 | - require OC::$SERVERROOT . '/version.php'; |
|
| 451 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
| 452 | + require OC::$SERVERROOT.'/version.php'; |
|
| 453 | 453 | /** @var $timestamp int */ |
| 454 | 454 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
| 455 | 455 | /** @var $OC_Version string */ |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | // core js files need separate handling |
| 498 | 498 | if ($application !== 'core' && $file !== null) { |
| 499 | - self::addTranslations ( $application ); |
|
| 499 | + self::addTranslations($application); |
|
| 500 | 500 | } |
| 501 | 501 | self::addExternalResource($application, $prepend, $path, "script"); |
| 502 | 502 | } |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | if ($type === "style") { |
| 574 | 574 | if (!in_array($path, self::$styles)) { |
| 575 | 575 | if ($prepend === true) { |
| 576 | - array_unshift ( self::$styles, $path ); |
|
| 576 | + array_unshift(self::$styles, $path); |
|
| 577 | 577 | } else { |
| 578 | 578 | self::$styles[] = $path; |
| 579 | 579 | } |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | } elseif ($type === "script") { |
| 582 | 582 | if (!in_array($path, self::$scripts)) { |
| 583 | 583 | if ($prepend === true) { |
| 584 | - array_unshift ( self::$scripts, $path ); |
|
| 584 | + array_unshift(self::$scripts, $path); |
|
| 585 | 585 | } else { |
| 586 | 586 | self::$scripts [] = $path; |
| 587 | 587 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | * @param array $attributes array of attributes for the element |
| 598 | 598 | * @param string $text the text content for the element |
| 599 | 599 | */ |
| 600 | - public static function addHeader($tag, $attributes, $text=null) { |
|
| 600 | + public static function addHeader($tag, $attributes, $text = null) { |
|
| 601 | 601 | self::$headers[] = array( |
| 602 | 602 | 'tag' => $tag, |
| 603 | 603 | 'attributes' => $attributes, |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public static function checkServer(\OC\SystemConfig $config) { |
| 638 | 638 | $l = \OC::$server->getL10N('lib'); |
| 639 | 639 | $errors = array(); |
| 640 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 640 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
| 641 | 641 | |
| 642 | 642 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
| 643 | 643 | // this check needs to be done every time |
@@ -665,13 +665,13 @@ discard block |
||
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | // Check if config folder is writable. |
| 668 | - if(!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 668 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | 669 | if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
| 670 | 670 | $errors[] = array( |
| 671 | 671 | 'error' => $l->t('Cannot write into "config" directory'), |
| 672 | 672 | 'hint' => $l->t('This can usually be fixed by ' |
| 673 | 673 | . '%sgiving the webserver write access to the config directory%s.', |
| 674 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 674 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
| 675 | 675 | ); |
| 676 | 676 | } |
| 677 | 677 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | 'hint' => $l->t('This can usually be fixed by ' |
| 688 | 688 | . '%sgiving the webserver write access to the apps directory%s' |
| 689 | 689 | . ' or disabling the appstore in the config file.', |
| 690 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')) |
|
| 690 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')) |
|
| 691 | 691 | ); |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -709,9 +709,9 @@ discard block |
||
| 709 | 709 | //common hint for all file permissions error messages |
| 710 | 710 | $permissionsHint = $l->t('Permissions can usually be fixed by ' |
| 711 | 711 | . '%sgiving the webserver write access to the root directory%s.', |
| 712 | - array('<a href="' . $urlGenerator->linkToDocs('admin-dir_permissions') . '" target="_blank" rel="noreferrer">', '</a>')); |
|
| 712 | + array('<a href="'.$urlGenerator->linkToDocs('admin-dir_permissions').'" target="_blank" rel="noreferrer">', '</a>')); |
|
| 713 | 713 | $errors[] = array( |
| 714 | - 'error' => 'Data directory (' . $CONFIG_DATADIRECTORY . ') not writable', |
|
| 714 | + 'error' => 'Data directory ('.$CONFIG_DATADIRECTORY.') not writable', |
|
| 715 | 715 | 'hint' => $permissionsHint |
| 716 | 716 | ); |
| 717 | 717 | } else { |
@@ -809,15 +809,15 @@ discard block |
||
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - foreach($missingDependencies as $missingDependency) { |
|
| 812 | + foreach ($missingDependencies as $missingDependency) { |
|
| 813 | 813 | $errors[] = array( |
| 814 | 814 | 'error' => $l->t('PHP module %s not installed.', array($missingDependency)), |
| 815 | 815 | 'hint' => $moduleHint |
| 816 | 816 | ); |
| 817 | 817 | $webServerRestart = true; |
| 818 | 818 | } |
| 819 | - foreach($invalidIniSettings as $setting) { |
|
| 820 | - if(is_bool($setting[1])) { |
|
| 819 | + foreach ($invalidIniSettings as $setting) { |
|
| 820 | + if (is_bool($setting[1])) { |
|
| 821 | 821 | $setting[1] = ($setting[1]) ? 'on' : 'off'; |
| 822 | 822 | } |
| 823 | 823 | $errors[] = [ |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * TODO: Should probably be implemented in the above generic dependency |
| 836 | 836 | * check somehow in the long-term. |
| 837 | 837 | */ |
| 838 | - if($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 838 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 839 | 839 | $iniWrapper->getBool('mbstring.func_overload') === true) { |
| 840 | 840 | $errors[] = array( |
| 841 | 841 | 'error' => $l->t('mbstring.func_overload is set to "%s" instead of the expected value "0"', [$iniWrapper->getString('mbstring.func_overload')]), |
@@ -843,16 +843,16 @@ discard block |
||
| 843 | 843 | ); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | - if(function_exists('xml_parser_create') && |
|
| 847 | - LIBXML_LOADED_VERSION < 20700 ) { |
|
| 846 | + if (function_exists('xml_parser_create') && |
|
| 847 | + LIBXML_LOADED_VERSION < 20700) { |
|
| 848 | 848 | $version = LIBXML_LOADED_VERSION; |
| 849 | - $major = floor($version/10000); |
|
| 849 | + $major = floor($version / 10000); |
|
| 850 | 850 | $version -= ($major * 10000); |
| 851 | - $minor = floor($version/100); |
|
| 851 | + $minor = floor($version / 100); |
|
| 852 | 852 | $version -= ($minor * 100); |
| 853 | 853 | $patch = $version; |
| 854 | 854 | $errors[] = array( |
| 855 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 855 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
| 856 | 856 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
| 857 | 857 | ); |
| 858 | 858 | } |
@@ -953,10 +953,10 @@ discard block |
||
| 953 | 953 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration') |
| 954 | 954 | ]; |
| 955 | 955 | } |
| 956 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 956 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
| 957 | 957 | $errors[] = [ |
| 958 | 958 | 'error' => $l->t('Data directory (%s) is invalid', [$dataDirectory]), |
| 959 | - 'hint' => $l->t('Please check that the data directory contains a file' . |
|
| 959 | + 'hint' => $l->t('Please check that the data directory contains a file'. |
|
| 960 | 960 | ' ".ocdata" in its root.') |
| 961 | 961 | ]; |
| 962 | 962 | } |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | public static function checkLoggedIn() { |
| 973 | 973 | // Check if we are a user |
| 974 | 974 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
| 975 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 975 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
| 976 | 976 | 'core.login.showLoginForm', |
| 977 | 977 | [ |
| 978 | 978 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | } |
| 984 | 984 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
| 985 | 985 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
| 986 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 986 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 987 | 987 | exit(); |
| 988 | 988 | } |
| 989 | 989 | } |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | public static function checkAdminUser() { |
| 997 | 997 | OC_Util::checkLoggedIn(); |
| 998 | 998 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
| 999 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 999 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1000 | 1000 | exit(); |
| 1001 | 1001 | } |
| 1002 | 1002 | } |
@@ -1010,12 +1010,12 @@ discard block |
||
| 1010 | 1010 | OC_Util::checkLoggedIn(); |
| 1011 | 1011 | $userObject = \OC::$server->getUserSession()->getUser(); |
| 1012 | 1012 | $isSubAdmin = false; |
| 1013 | - if($userObject !== null) { |
|
| 1013 | + if ($userObject !== null) { |
|
| 1014 | 1014 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | if (!$isSubAdmin) { |
| 1018 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1018 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 1019 | 1019 | exit(); |
| 1020 | 1020 | } |
| 1021 | 1021 | return true; |
@@ -1050,10 +1050,10 @@ discard block |
||
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - if(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | - $location = $urlGenerator->getAbsoluteURL('/apps/' . $appId . '/'); |
|
| 1053 | + if (\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true') { |
|
| 1054 | + $location = $urlGenerator->getAbsoluteURL('/apps/'.$appId.'/'); |
|
| 1055 | 1055 | } else { |
| 1056 | - $location = $urlGenerator->getAbsoluteURL('/index.php/apps/' . $appId . '/'); |
|
| 1056 | + $location = $urlGenerator->getAbsoluteURL('/index.php/apps/'.$appId.'/'); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
@@ -1067,7 +1067,7 @@ discard block |
||
| 1067 | 1067 | */ |
| 1068 | 1068 | public static function redirectToDefaultPage() { |
| 1069 | 1069 | $location = self::getDefaultPageUrl(); |
| 1070 | - header('Location: ' . $location); |
|
| 1070 | + header('Location: '.$location); |
|
| 1071 | 1071 | exit(); |
| 1072 | 1072 | } |
| 1073 | 1073 | |
@@ -1080,7 +1080,7 @@ discard block |
||
| 1080 | 1080 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
| 1081 | 1081 | if (is_null($id)) { |
| 1082 | 1082 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
| 1083 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1083 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1084 | 1084 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
| 1085 | 1085 | } |
| 1086 | 1086 | return $id; |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | }, $value); |
| 1103 | 1103 | } else { |
| 1104 | 1104 | // Specify encoding for PHP<5.4 |
| 1105 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1105 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | return $value; |
| 1108 | 1108 | } |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
| 1136 | 1136 | |
| 1137 | 1137 | // creating a test file |
| 1138 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1138 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1139 | 1139 | |
| 1140 | 1140 | if (file_exists($testFile)) {// already running this test, possible recursive call |
| 1141 | 1141 | return false; |
@@ -1144,7 +1144,7 @@ discard block |
||
| 1144 | 1144 | $fp = @fopen($testFile, 'w'); |
| 1145 | 1145 | if (!$fp) { |
| 1146 | 1146 | throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', |
| 1147 | - 'Make sure it is possible for the webserver to write to ' . $testFile); |
|
| 1147 | + 'Make sure it is possible for the webserver to write to '.$testFile); |
|
| 1148 | 1148 | } |
| 1149 | 1149 | fwrite($fp, $testContent); |
| 1150 | 1150 | fclose($fp); |
@@ -1171,10 +1171,10 @@ discard block |
||
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | 1173 | $fileName = '/htaccesstest.txt'; |
| 1174 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1174 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1175 | 1175 | |
| 1176 | 1176 | // accessing the file via http |
| 1177 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1177 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
| 1178 | 1178 | try { |
| 1179 | 1179 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
| 1180 | 1180 | } catch (\Exception $e) { |
@@ -1265,7 +1265,7 @@ discard block |
||
| 1265 | 1265 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
| 1266 | 1266 | |
| 1267 | 1267 | if ($theme === '') { |
| 1268 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1268 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
| 1269 | 1269 | $theme = 'default'; |
| 1270 | 1270 | } |
| 1271 | 1271 | } |
@@ -1336,13 +1336,13 @@ discard block |
||
| 1336 | 1336 | * @return bool|string |
| 1337 | 1337 | */ |
| 1338 | 1338 | public static function normalizeUnicode($value) { |
| 1339 | - if(Normalizer::isNormalized($value)) { |
|
| 1339 | + if (Normalizer::isNormalized($value)) { |
|
| 1340 | 1340 | return $value; |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | 1343 | $normalizedValue = Normalizer::normalize($value); |
| 1344 | 1344 | if ($normalizedValue === null || $normalizedValue === false) { |
| 1345 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1345 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
| 1346 | 1346 | return $value; |
| 1347 | 1347 | } |
| 1348 | 1348 | |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | $version = OC_Util::getVersionString(); |
| 1369 | 1369 | $build = OC_Util::getBuild(); |
| 1370 | 1370 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
| 1371 | - $version .= ' Build:' . $build; |
|
| 1371 | + $version .= ' Build:'.$build; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | return $version; |
| 1374 | 1374 | } |
@@ -1415,19 +1415,19 @@ discard block |
||
| 1415 | 1415 | } else if ($config->getValue('debug', false) && $versionDiff < 0) { |
| 1416 | 1416 | // downgrade with debug |
| 1417 | 1417 | $installedMajor = explode('.', $installedVersion); |
| 1418 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1418 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
| 1419 | 1419 | $currentMajor = explode('.', $currentVersion); |
| 1420 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1420 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
| 1421 | 1421 | if ($installedMajor === $currentMajor) { |
| 1422 | 1422 | // Same major, allow downgrade for developers |
| 1423 | 1423 | return true; |
| 1424 | 1424 | } else { |
| 1425 | 1425 | // downgrade attempt, throw exception |
| 1426 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1426 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1427 | 1427 | } |
| 1428 | 1428 | } else if ($versionDiff < 0) { |
| 1429 | 1429 | // downgrade attempt, throw exception |
| 1430 | - throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1430 | + throw new \OC\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // also check for upgrades for apps (independently from the user) |