@@ -38,64 +38,64 @@ |
||
| 38 | 38 | // Show warning if a PHP version below 7.0 is used, this has to happen here |
| 39 | 39 | // because base.php will already use 7.0 syntax. |
| 40 | 40 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 41 | - echo 'This version of Nextcloud requires at least PHP 7.0'.PHP_EOL; |
|
| 42 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL; |
|
| 43 | - return; |
|
| 41 | + echo 'This version of Nextcloud requires at least PHP 7.0'.PHP_EOL; |
|
| 42 | + echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL; |
|
| 43 | + return; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function exceptionHandler($exception) { |
| 47 | - echo "An unhandled exception has been thrown:" . PHP_EOL; |
|
| 48 | - echo $exception; |
|
| 49 | - exit(1); |
|
| 47 | + echo "An unhandled exception has been thrown:" . PHP_EOL; |
|
| 48 | + echo $exception; |
|
| 49 | + exit(1); |
|
| 50 | 50 | } |
| 51 | 51 | try { |
| 52 | - require_once __DIR__ . '/lib/base.php'; |
|
| 52 | + require_once __DIR__ . '/lib/base.php'; |
|
| 53 | 53 | |
| 54 | - // set to run indefinitely if needed |
|
| 55 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 56 | - @set_time_limit(0); |
|
| 57 | - } |
|
| 54 | + // set to run indefinitely if needed |
|
| 55 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 56 | + @set_time_limit(0); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - if (!OC::$CLI) { |
|
| 60 | - echo "This script can be run from the command line only" . PHP_EOL; |
|
| 61 | - exit(1); |
|
| 62 | - } |
|
| 59 | + if (!OC::$CLI) { |
|
| 60 | + echo "This script can be run from the command line only" . PHP_EOL; |
|
| 61 | + exit(1); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - set_exception_handler('exceptionHandler'); |
|
| 64 | + set_exception_handler('exceptionHandler'); |
|
| 65 | 65 | |
| 66 | - if (!function_exists('posix_getuid')) { |
|
| 67 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 68 | - exit(1); |
|
| 69 | - } |
|
| 70 | - $user = posix_getpwuid(posix_getuid()); |
|
| 71 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 72 | - if ($user['name'] !== $configUser['name']) { |
|
| 73 | - echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; |
|
| 74 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 75 | - echo "Owner of config.php: " . $configUser['name'] . PHP_EOL; |
|
| 76 | - echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 77 | - exit(1); |
|
| 78 | - } |
|
| 66 | + if (!function_exists('posix_getuid')) { |
|
| 67 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 68 | + exit(1); |
|
| 69 | + } |
|
| 70 | + $user = posix_getpwuid(posix_getuid()); |
|
| 71 | + $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 72 | + if ($user['name'] !== $configUser['name']) { |
|
| 73 | + echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; |
|
| 74 | + echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 75 | + echo "Owner of config.php: " . $configUser['name'] . PHP_EOL; |
|
| 76 | + echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 77 | + exit(1); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $oldWorkingDir = getcwd(); |
|
| 81 | - if ($oldWorkingDir === false) { |
|
| 82 | - echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 83 | - echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 84 | - } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
|
| 85 | - echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 86 | - echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 87 | - exit(1); |
|
| 88 | - } |
|
| 80 | + $oldWorkingDir = getcwd(); |
|
| 81 | + if ($oldWorkingDir === false) { |
|
| 82 | + echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 83 | + echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 84 | + } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
|
| 85 | + echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 86 | + echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 87 | + exit(1); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) { |
|
| 91 | - echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL; |
|
| 92 | - } |
|
| 90 | + if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) { |
|
| 91 | + echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger()); |
|
| 95 | - $application->loadCommands(new ArgvInput(), new ConsoleOutput()); |
|
| 96 | - $application->run(); |
|
| 94 | + $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger()); |
|
| 95 | + $application->loadCommands(new ArgvInput(), new ConsoleOutput()); |
|
| 96 | + $application->run(); |
|
| 97 | 97 | } catch (Exception $ex) { |
| 98 | - exceptionHandler($ex); |
|
| 98 | + exceptionHandler($ex); |
|
| 99 | 99 | } catch (Error $ex) { |
| 100 | - exceptionHandler($ex); |
|
| 100 | + exceptionHandler($ex); |
|
| 101 | 101 | } |
@@ -39,17 +39,17 @@ discard block |
||
| 39 | 39 | // because base.php will already use 7.0 syntax. |
| 40 | 40 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 41 | 41 | echo 'This version of Nextcloud requires at least PHP 7.0'.PHP_EOL; |
| 42 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL; |
|
| 42 | + echo 'You are currently running '.PHP_VERSION.'. Please update your PHP version.'.PHP_EOL; |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function exceptionHandler($exception) { |
| 47 | - echo "An unhandled exception has been thrown:" . PHP_EOL; |
|
| 47 | + echo "An unhandled exception has been thrown:".PHP_EOL; |
|
| 48 | 48 | echo $exception; |
| 49 | 49 | exit(1); |
| 50 | 50 | } |
| 51 | 51 | try { |
| 52 | - require_once __DIR__ . '/lib/base.php'; |
|
| 52 | + require_once __DIR__.'/lib/base.php'; |
|
| 53 | 53 | |
| 54 | 54 | // set to run indefinitely if needed |
| 55 | 55 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
@@ -57,38 +57,38 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if (!OC::$CLI) { |
| 60 | - echo "This script can be run from the command line only" . PHP_EOL; |
|
| 60 | + echo "This script can be run from the command line only".PHP_EOL; |
|
| 61 | 61 | exit(1); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | set_exception_handler('exceptionHandler'); |
| 65 | 65 | |
| 66 | 66 | if (!function_exists('posix_getuid')) { |
| 67 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 67 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php".PHP_EOL; |
|
| 68 | 68 | exit(1); |
| 69 | 69 | } |
| 70 | 70 | $user = posix_getpwuid(posix_getuid()); |
| 71 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 71 | + $configUser = posix_getpwuid(fileowner(OC::$configDir.'config.php')); |
|
| 72 | 72 | if ($user['name'] !== $configUser['name']) { |
| 73 | - echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; |
|
| 74 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 75 | - echo "Owner of config.php: " . $configUser['name'] . PHP_EOL; |
|
| 76 | - echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL; |
|
| 73 | + echo "Console has to be executed with the user that owns the file config/config.php".PHP_EOL; |
|
| 74 | + echo "Current user: ".$user['name'].PHP_EOL; |
|
| 75 | + echo "Owner of config.php: ".$configUser['name'].PHP_EOL; |
|
| 76 | + echo "Try adding 'sudo -u ".$configUser['name']." ' to the beginning of the command (without the single quotes)".PHP_EOL; |
|
| 77 | 77 | exit(1); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $oldWorkingDir = getcwd(); |
| 81 | 81 | if ($oldWorkingDir === false) { |
| 82 | - echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 83 | - echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
|
| 82 | + echo "This script can be run from the Nextcloud root directory only.".PHP_EOL; |
|
| 83 | + echo "Can't determine current working dir - the script will continue to work but be aware of the above fact.".PHP_EOL; |
|
| 84 | 84 | } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) { |
| 85 | - echo "This script can be run from the Nextcloud root directory only." . PHP_EOL; |
|
| 86 | - echo "Can't change to Nextcloud root directory." . PHP_EOL; |
|
| 85 | + echo "This script can be run from the Nextcloud root directory only.".PHP_EOL; |
|
| 86 | + echo "Can't change to Nextcloud root directory.".PHP_EOL; |
|
| 87 | 87 | exit(1); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) { |
| 91 | - echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL; |
|
| 91 | + echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php".PHP_EOL; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger()); |
@@ -36,131 +36,131 @@ |
||
| 36 | 36 | |
| 37 | 37 | // Show warning if a PHP version below 7.0 is used |
| 38 | 38 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 39 | - echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
|
| 40 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 41 | - return; |
|
| 39 | + echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
|
| 40 | + echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 41 | + return; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | try { |
| 45 | 45 | |
| 46 | - require_once __DIR__ . '/lib/base.php'; |
|
| 47 | - |
|
| 48 | - if (\OCP\Util::needUpgrade()) { |
|
| 49 | - \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | - exit; |
|
| 51 | - } |
|
| 52 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 53 | - \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 54 | - exit; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // load all apps to get all api routes properly setup |
|
| 58 | - OC_App::loadApps(); |
|
| 59 | - |
|
| 60 | - \OC::$server->getSession()->close(); |
|
| 61 | - |
|
| 62 | - // initialize a dummy memory session |
|
| 63 | - $session = new \OC\Session\Memory(''); |
|
| 64 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 65 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 66 | - \OC::$server->setSession($session); |
|
| 67 | - |
|
| 68 | - $logger = \OC::$server->getLogger(); |
|
| 69 | - $config = \OC::$server->getConfig(); |
|
| 70 | - |
|
| 71 | - // Don't do anything if ownCloud has not been installed |
|
| 72 | - if (!$config->getSystemValue('installed', false)) { |
|
| 73 | - exit(0); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - \OC::$server->getTempManager()->cleanOld(); |
|
| 77 | - |
|
| 78 | - // Exit if background jobs are disabled! |
|
| 79 | - $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 80 | - if ($appMode == 'none') { |
|
| 81 | - if (OC::$CLI) { |
|
| 82 | - echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 83 | - } else { |
|
| 84 | - OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 85 | - } |
|
| 86 | - exit(1); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - if (OC::$CLI) { |
|
| 90 | - // set to run indefinitely if needed |
|
| 91 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 92 | - @set_time_limit(0); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // the cron job must be executed with the right user |
|
| 96 | - if (!function_exists('posix_getuid')) { |
|
| 97 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 98 | - exit(1); |
|
| 99 | - } |
|
| 100 | - $user = posix_getpwuid(posix_getuid()); |
|
| 101 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 102 | - if ($user['name'] !== $configUser['name']) { |
|
| 103 | - echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 104 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 105 | - echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 106 | - exit(1); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // We call ownCloud from the CLI (aka cron) |
|
| 110 | - if ($appMode != 'cron') { |
|
| 111 | - \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // Work |
|
| 115 | - $jobList = \OC::$server->getJobList(); |
|
| 116 | - |
|
| 117 | - // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 118 | - // system cron task should spawn. |
|
| 119 | - $endTime = time() + 14 * 60; |
|
| 120 | - |
|
| 121 | - $executedJobs = []; |
|
| 122 | - while ($job = $jobList->getNext()) { |
|
| 123 | - if (isset($executedJobs[$job->getId()])) { |
|
| 124 | - $jobList->unlockJob($job); |
|
| 125 | - break; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $job->execute($jobList, $logger); |
|
| 129 | - // clean up after unclean jobs |
|
| 130 | - \OC_Util::tearDownFS(); |
|
| 131 | - |
|
| 132 | - $jobList->setLastJob($job); |
|
| 133 | - $executedJobs[$job->getId()] = true; |
|
| 134 | - unset($job); |
|
| 135 | - |
|
| 136 | - if (time() > $endTime) { |
|
| 137 | - break; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - } else { |
|
| 142 | - // We call cron.php from some website |
|
| 143 | - if ($appMode == 'cron') { |
|
| 144 | - // Cron is cron :-P |
|
| 145 | - OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 146 | - } else { |
|
| 147 | - // Work and success :-) |
|
| 148 | - $jobList = \OC::$server->getJobList(); |
|
| 149 | - $job = $jobList->getNext(); |
|
| 150 | - if ($job != null) { |
|
| 151 | - $job->execute($jobList, $logger); |
|
| 152 | - $jobList->setLastJob($job); |
|
| 153 | - } |
|
| 154 | - OC_JSON::success(); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // Log the successful cron execution |
|
| 159 | - \OC::$server->getConfig()->setAppValue('core', 'lastcron', time()); |
|
| 160 | - exit(); |
|
| 46 | + require_once __DIR__ . '/lib/base.php'; |
|
| 47 | + |
|
| 48 | + if (\OCP\Util::needUpgrade()) { |
|
| 49 | + \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
|
| 50 | + exit; |
|
| 51 | + } |
|
| 52 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
| 53 | + \OCP\Util::writeLog('cron', 'We are in maintenance mode, skipping cron', \OCP\Util::DEBUG); |
|
| 54 | + exit; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // load all apps to get all api routes properly setup |
|
| 58 | + OC_App::loadApps(); |
|
| 59 | + |
|
| 60 | + \OC::$server->getSession()->close(); |
|
| 61 | + |
|
| 62 | + // initialize a dummy memory session |
|
| 63 | + $session = new \OC\Session\Memory(''); |
|
| 64 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 65 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 66 | + \OC::$server->setSession($session); |
|
| 67 | + |
|
| 68 | + $logger = \OC::$server->getLogger(); |
|
| 69 | + $config = \OC::$server->getConfig(); |
|
| 70 | + |
|
| 71 | + // Don't do anything if ownCloud has not been installed |
|
| 72 | + if (!$config->getSystemValue('installed', false)) { |
|
| 73 | + exit(0); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + \OC::$server->getTempManager()->cleanOld(); |
|
| 77 | + |
|
| 78 | + // Exit if background jobs are disabled! |
|
| 79 | + $appMode = \OCP\BackgroundJob::getExecutionType(); |
|
| 80 | + if ($appMode == 'none') { |
|
| 81 | + if (OC::$CLI) { |
|
| 82 | + echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 83 | + } else { |
|
| 84 | + OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
|
| 85 | + } |
|
| 86 | + exit(1); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + if (OC::$CLI) { |
|
| 90 | + // set to run indefinitely if needed |
|
| 91 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 92 | + @set_time_limit(0); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // the cron job must be executed with the right user |
|
| 96 | + if (!function_exists('posix_getuid')) { |
|
| 97 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 98 | + exit(1); |
|
| 99 | + } |
|
| 100 | + $user = posix_getpwuid(posix_getuid()); |
|
| 101 | + $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 102 | + if ($user['name'] !== $configUser['name']) { |
|
| 103 | + echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 104 | + echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 105 | + echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 106 | + exit(1); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // We call ownCloud from the CLI (aka cron) |
|
| 110 | + if ($appMode != 'cron') { |
|
| 111 | + \OCP\BackgroundJob::setExecutionType('cron'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // Work |
|
| 115 | + $jobList = \OC::$server->getJobList(); |
|
| 116 | + |
|
| 117 | + // We only ask for jobs for 14 minutes, because after 15 minutes the next |
|
| 118 | + // system cron task should spawn. |
|
| 119 | + $endTime = time() + 14 * 60; |
|
| 120 | + |
|
| 121 | + $executedJobs = []; |
|
| 122 | + while ($job = $jobList->getNext()) { |
|
| 123 | + if (isset($executedJobs[$job->getId()])) { |
|
| 124 | + $jobList->unlockJob($job); |
|
| 125 | + break; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $job->execute($jobList, $logger); |
|
| 129 | + // clean up after unclean jobs |
|
| 130 | + \OC_Util::tearDownFS(); |
|
| 131 | + |
|
| 132 | + $jobList->setLastJob($job); |
|
| 133 | + $executedJobs[$job->getId()] = true; |
|
| 134 | + unset($job); |
|
| 135 | + |
|
| 136 | + if (time() > $endTime) { |
|
| 137 | + break; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } else { |
|
| 142 | + // We call cron.php from some website |
|
| 143 | + if ($appMode == 'cron') { |
|
| 144 | + // Cron is cron :-P |
|
| 145 | + OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); |
|
| 146 | + } else { |
|
| 147 | + // Work and success :-) |
|
| 148 | + $jobList = \OC::$server->getJobList(); |
|
| 149 | + $job = $jobList->getNext(); |
|
| 150 | + if ($job != null) { |
|
| 151 | + $job->execute($jobList, $logger); |
|
| 152 | + $jobList->setLastJob($job); |
|
| 153 | + } |
|
| 154 | + OC_JSON::success(); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // Log the successful cron execution |
|
| 159 | + \OC::$server->getConfig()->setAppValue('core', 'lastcron', time()); |
|
| 160 | + exit(); |
|
| 161 | 161 | |
| 162 | 162 | } catch (Exception $ex) { |
| 163 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 163 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 164 | 164 | } catch (Error $ex) { |
| 165 | - \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 165 | + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); |
|
| 166 | 166 | } |
@@ -37,13 +37,13 @@ discard block |
||
| 37 | 37 | // Show warning if a PHP version below 7.0 is used |
| 38 | 38 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 39 | 39 | echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
| 40 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 40 | + echo 'You are currently running '.PHP_VERSION.'. Please update your PHP version.'; |
|
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | try { |
| 45 | 45 | |
| 46 | - require_once __DIR__ . '/lib/base.php'; |
|
| 46 | + require_once __DIR__.'/lib/base.php'; |
|
| 47 | 47 | |
| 48 | 48 | if (\OCP\Util::needUpgrade()) { |
| 49 | 49 | \OCP\Util::writeLog('cron', 'Update required, skipping cron', \OCP\Util::DEBUG); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $appMode = \OCP\BackgroundJob::getExecutionType(); |
| 80 | 80 | if ($appMode == 'none') { |
| 81 | 81 | if (OC::$CLI) { |
| 82 | - echo 'Background Jobs are disabled!' . PHP_EOL; |
|
| 82 | + echo 'Background Jobs are disabled!'.PHP_EOL; |
|
| 83 | 83 | } else { |
| 84 | 84 | OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); |
| 85 | 85 | } |
@@ -94,15 +94,15 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | // the cron job must be executed with the right user |
| 96 | 96 | if (!function_exists('posix_getuid')) { |
| 97 | - echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; |
|
| 97 | + echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php".PHP_EOL; |
|
| 98 | 98 | exit(1); |
| 99 | 99 | } |
| 100 | 100 | $user = posix_getpwuid(posix_getuid()); |
| 101 | - $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); |
|
| 101 | + $configUser = posix_getpwuid(fileowner(OC::$configDir.'config.php')); |
|
| 102 | 102 | if ($user['name'] !== $configUser['name']) { |
| 103 | - echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL; |
|
| 104 | - echo "Current user: " . $user['name'] . PHP_EOL; |
|
| 105 | - echo "Web server user: " . $configUser['name'] . PHP_EOL; |
|
| 103 | + echo "Console has to be executed with the same user as the web server is operated".PHP_EOL; |
|
| 104 | + echo "Current user: ".$user['name'].PHP_EOL; |
|
| 105 | + echo "Web server user: ".$configUser['name'].PHP_EOL; |
|
| 106 | 106 | exit(1); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -64,1010 +64,1010 @@ |
||
| 64 | 64 | * OC_autoload! |
| 65 | 65 | */ |
| 66 | 66 | class OC { |
| 67 | - /** |
|
| 68 | - * Associative array for autoloading. classname => filename |
|
| 69 | - */ |
|
| 70 | - public static $CLASSPATH = array(); |
|
| 71 | - /** |
|
| 72 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 73 | - */ |
|
| 74 | - public static $SERVERROOT = ''; |
|
| 75 | - /** |
|
| 76 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 77 | - */ |
|
| 78 | - private static $SUBURI = ''; |
|
| 79 | - /** |
|
| 80 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 81 | - */ |
|
| 82 | - public static $WEBROOT = ''; |
|
| 83 | - /** |
|
| 84 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 85 | - * web path in 'url' |
|
| 86 | - */ |
|
| 87 | - public static $APPSROOTS = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 92 | - public static $configDir; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * requested app |
|
| 96 | - */ |
|
| 97 | - public static $REQUESTEDAPP = ''; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * check if Nextcloud runs in cli mode |
|
| 101 | - */ |
|
| 102 | - public static $CLI = false; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @var \OC\Autoloader $loader |
|
| 106 | - */ |
|
| 107 | - public static $loader = null; |
|
| 108 | - |
|
| 109 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 110 | - public static $composerAutoloader = null; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var \OC\Server |
|
| 114 | - */ |
|
| 115 | - public static $server = null; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var \OC\Config |
|
| 119 | - */ |
|
| 120 | - private static $config = null; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 124 | - * the app path list is empty or contains an invalid path |
|
| 125 | - */ |
|
| 126 | - public static function initPaths() { |
|
| 127 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 128 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 129 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 130 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 131 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 132 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 133 | - } else { |
|
| 134 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 135 | - } |
|
| 136 | - self::$config = new \OC\Config(self::$configDir); |
|
| 137 | - |
|
| 138 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 139 | - /** |
|
| 140 | - * FIXME: The following lines are required because we can't yet instantiate |
|
| 141 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 142 | - */ |
|
| 143 | - $params = [ |
|
| 144 | - 'server' => [ |
|
| 145 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 146 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 147 | - ], |
|
| 148 | - ]; |
|
| 149 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 150 | - $scriptName = $fakeRequest->getScriptName(); |
|
| 151 | - if (substr($scriptName, -1) == '/') { |
|
| 152 | - $scriptName .= 'index.php'; |
|
| 153 | - //make sure suburi follows the same rules as scriptName |
|
| 154 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 155 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
| 156 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 157 | - } |
|
| 158 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - if (OC::$CLI) { |
|
| 164 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 165 | - } else { |
|
| 166 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 167 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 168 | - |
|
| 169 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 170 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 171 | - } |
|
| 172 | - } else { |
|
| 173 | - // The scriptName is not ending with OC::$SUBURI |
|
| 174 | - // This most likely means that we are calling from CLI. |
|
| 175 | - // However some cron jobs still need to generate |
|
| 176 | - // a web URL, so we use overwritewebroot as a fallback. |
|
| 177 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 181 | - // slash which is required by URL generation. |
|
| 182 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 183 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 184 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
| 185 | - exit(); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // search the apps folder |
|
| 190 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 191 | - if (!empty($config_paths)) { |
|
| 192 | - foreach ($config_paths as $paths) { |
|
| 193 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
| 194 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
| 195 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
| 196 | - OC::$APPSROOTS[] = $paths; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 200 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 201 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 202 | - OC::$APPSROOTS[] = array( |
|
| 203 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 204 | - 'url' => '/apps', |
|
| 205 | - 'writable' => true |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (empty(OC::$APPSROOTS)) { |
|
| 210 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 211 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 212 | - } |
|
| 213 | - $paths = array(); |
|
| 214 | - foreach (OC::$APPSROOTS as $path) { |
|
| 215 | - $paths[] = $path['path']; |
|
| 216 | - if (!is_dir($path['path'])) { |
|
| 217 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 218 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 219 | - . ' config.php file.', $path['path'])); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // set the right include path |
|
| 224 | - set_include_path( |
|
| 225 | - implode(PATH_SEPARATOR, $paths) |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - public static function checkConfig() { |
|
| 230 | - $l = \OC::$server->getL10N('lib'); |
|
| 231 | - |
|
| 232 | - // Create config if it does not already exist |
|
| 233 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 234 | - if(!file_exists($configFilePath)) { |
|
| 235 | - @touch($configFilePath); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - // Check if config is writable |
|
| 239 | - $configFileWritable = is_writable($configFilePath); |
|
| 240 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 241 | - || !$configFileWritable && self::checkUpgrade(false)) { |
|
| 242 | - |
|
| 243 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 244 | - |
|
| 245 | - if (self::$CLI) { |
|
| 246 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 247 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 248 | - echo "\n"; |
|
| 249 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 250 | - exit; |
|
| 251 | - } else { |
|
| 252 | - OC_Template::printErrorPage( |
|
| 253 | - $l->t('Cannot write into "config" directory!'), |
|
| 254 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 255 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
| 256 | - ); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - public static function checkInstalled() { |
|
| 262 | - if (defined('OC_CONSOLE')) { |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - // Redirect to installer if not installed |
|
| 266 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 267 | - if (OC::$CLI) { |
|
| 268 | - throw new Exception('Not installed'); |
|
| 269 | - } else { |
|
| 270 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 271 | - header('Location: ' . $url); |
|
| 272 | - } |
|
| 273 | - exit(); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - public static function checkMaintenanceMode() { |
|
| 278 | - // Allow ajax update script to execute without being stopped |
|
| 279 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 280 | - // send http status 503 |
|
| 281 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 282 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 283 | - header('Retry-After: 120'); |
|
| 284 | - |
|
| 285 | - // render error page |
|
| 286 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
| 287 | - OC_Util::addScript('maintenance-check'); |
|
| 288 | - OC_Util::addStyle('core', 'guest'); |
|
| 289 | - $template->printPage(); |
|
| 290 | - die(); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Checks if the version requires an update and shows |
|
| 296 | - * @param bool $showTemplate Whether an update screen should get shown |
|
| 297 | - * @return bool|void |
|
| 298 | - */ |
|
| 299 | - public static function checkUpgrade($showTemplate = true) { |
|
| 300 | - if (\OCP\Util::needUpgrade()) { |
|
| 301 | - if (function_exists('opcache_reset')) { |
|
| 302 | - opcache_reset(); |
|
| 303 | - } |
|
| 304 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 305 | - if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
| 306 | - self::printUpgradePage(); |
|
| 307 | - exit(); |
|
| 308 | - } else { |
|
| 309 | - return true; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - return false; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Prints the upgrade page |
|
| 317 | - */ |
|
| 318 | - private static function printUpgradePage() { |
|
| 319 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 320 | - |
|
| 321 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 322 | - $tooBig = false; |
|
| 323 | - if (!$disableWebUpdater) { |
|
| 324 | - $apps = \OC::$server->getAppManager(); |
|
| 325 | - $tooBig = false; |
|
| 326 | - if ($apps->isInstalled('user_ldap')) { |
|
| 327 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 328 | - |
|
| 329 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 330 | - ->from('ldap_user_mapping') |
|
| 331 | - ->execute(); |
|
| 332 | - $row = $result->fetch(); |
|
| 333 | - $result->closeCursor(); |
|
| 334 | - |
|
| 335 | - $tooBig = ($row['user_count'] > 50); |
|
| 336 | - } |
|
| 337 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 338 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 339 | - |
|
| 340 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 341 | - ->from('user_saml_users') |
|
| 342 | - ->execute(); |
|
| 343 | - $row = $result->fetch(); |
|
| 344 | - $result->closeCursor(); |
|
| 345 | - |
|
| 346 | - $tooBig = ($row['user_count'] > 50); |
|
| 347 | - } |
|
| 348 | - if (!$tooBig) { |
|
| 349 | - // count users |
|
| 350 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 351 | - $totalUsers = array_sum($stats); |
|
| 352 | - $tooBig = ($totalUsers > 50); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 356 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 357 | - |
|
| 358 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 359 | - // send http status 503 |
|
| 360 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 361 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 362 | - header('Retry-After: 120'); |
|
| 363 | - |
|
| 364 | - // render error page |
|
| 365 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 366 | - $template->assign('productName', 'nextcloud'); // for now |
|
| 367 | - $template->assign('version', OC_Util::getVersionString()); |
|
| 368 | - $template->assign('tooBig', $tooBig); |
|
| 369 | - |
|
| 370 | - $template->printPage(); |
|
| 371 | - die(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // check whether this is a core update or apps update |
|
| 375 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 376 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 377 | - |
|
| 378 | - // if not a core upgrade, then it's apps upgrade |
|
| 379 | - $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
| 380 | - |
|
| 381 | - $oldTheme = $systemConfig->getValue('theme'); |
|
| 382 | - $systemConfig->setValue('theme', ''); |
|
| 383 | - OC_Util::addScript('config'); // needed for web root |
|
| 384 | - OC_Util::addScript('update'); |
|
| 385 | - |
|
| 386 | - /** @var \OC\App\AppManager $appManager */ |
|
| 387 | - $appManager = \OC::$server->getAppManager(); |
|
| 388 | - |
|
| 389 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 390 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 391 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 392 | - |
|
| 393 | - // get third party apps |
|
| 394 | - $ocVersion = \OCP\Util::getVersion(); |
|
| 395 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 396 | - $incompatibleShippedApps = []; |
|
| 397 | - foreach ($incompatibleApps as $appInfo) { |
|
| 398 | - if ($appManager->isShipped($appInfo['id'])) { |
|
| 399 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - if (!empty($incompatibleShippedApps)) { |
|
| 404 | - $l = \OC::$server->getL10N('core'); |
|
| 405 | - $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 406 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 410 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 411 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 412 | - $tmpl->assign('oldTheme', $oldTheme); |
|
| 413 | - $tmpl->printPage(); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public static function initSession() { |
|
| 417 | - // prevents javascript from accessing php session cookies |
|
| 418 | - ini_set('session.cookie_httponly', 'true'); |
|
| 419 | - |
|
| 420 | - // set the cookie path to the Nextcloud directory |
|
| 421 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 422 | - ini_set('session.cookie_path', $cookie_path); |
|
| 423 | - |
|
| 424 | - // Let the session name be changed in the initSession Hook |
|
| 425 | - $sessionName = OC_Util::getInstanceId(); |
|
| 426 | - |
|
| 427 | - try { |
|
| 428 | - // Allow session apps to create a custom session object |
|
| 429 | - $useCustomSession = false; |
|
| 430 | - $session = self::$server->getSession(); |
|
| 431 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 432 | - if (!$useCustomSession) { |
|
| 433 | - // set the session name to the instance id - which is unique |
|
| 434 | - $session = new \OC\Session\Internal($sessionName); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 438 | - $session = $cryptoWrapper->wrapSession($session); |
|
| 439 | - self::$server->setSession($session); |
|
| 440 | - |
|
| 441 | - // if session can't be started break with http 500 error |
|
| 442 | - } catch (Exception $e) { |
|
| 443 | - \OCP\Util::logException('base', $e); |
|
| 444 | - //show the user a detailed error page |
|
| 445 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 446 | - OC_Template::printExceptionErrorPage($e); |
|
| 447 | - die(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 451 | - |
|
| 452 | - // session timeout |
|
| 453 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 454 | - if (isset($_COOKIE[session_name()])) { |
|
| 455 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 456 | - } |
|
| 457 | - \OC::$server->getUserSession()->logout(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - $session->set('LAST_ACTIVITY', time()); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @return string |
|
| 465 | - */ |
|
| 466 | - private static function getSessionLifeTime() { |
|
| 467 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - public static function loadAppClassPaths() { |
|
| 471 | - foreach (OC_App::getEnabledApps() as $app) { |
|
| 472 | - $appPath = OC_App::getAppPath($app); |
|
| 473 | - if ($appPath === false) { |
|
| 474 | - continue; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 478 | - if (file_exists($file)) { |
|
| 479 | - require_once $file; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Try to set some values to the required Nextcloud default |
|
| 486 | - */ |
|
| 487 | - public static function setRequiredIniValues() { |
|
| 488 | - @ini_set('default_charset', 'UTF-8'); |
|
| 489 | - @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Send the same site cookies |
|
| 494 | - */ |
|
| 495 | - private static function sendSameSiteCookies() { |
|
| 496 | - $cookieParams = session_get_cookie_params(); |
|
| 497 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 498 | - $policies = [ |
|
| 499 | - 'lax', |
|
| 500 | - 'strict', |
|
| 501 | - ]; |
|
| 502 | - |
|
| 503 | - // Append __Host to the cookie if it meets the requirements |
|
| 504 | - $cookiePrefix = ''; |
|
| 505 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 506 | - $cookiePrefix = '__Host-'; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - foreach($policies as $policy) { |
|
| 510 | - header( |
|
| 511 | - sprintf( |
|
| 512 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 513 | - $cookiePrefix, |
|
| 514 | - $policy, |
|
| 515 | - $cookieParams['path'], |
|
| 516 | - $policy |
|
| 517 | - ), |
|
| 518 | - false |
|
| 519 | - ); |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 525 | - * be set in every request if cookies are sent to add a second level of |
|
| 526 | - * defense against CSRF. |
|
| 527 | - * |
|
| 528 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
| 529 | - * We use an additional cookie since we want to protect logout CSRF and |
|
| 530 | - * also we can't directly interfere with PHP's session mechanism. |
|
| 531 | - */ |
|
| 532 | - private static function performSameSiteCookieProtection() { |
|
| 533 | - $request = \OC::$server->getRequest(); |
|
| 534 | - |
|
| 535 | - // Some user agents are notorious and don't really properly follow HTTP |
|
| 536 | - // specifications. For those, have an automated opt-out. Since the protection |
|
| 537 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
| 538 | - // here. |
|
| 539 | - $incompatibleUserAgents = [ |
|
| 540 | - // OS X Finder |
|
| 541 | - '/^WebDAVFS/', |
|
| 542 | - ]; |
|
| 543 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 544 | - return; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if(count($_COOKIE) > 0) { |
|
| 548 | - $requestUri = $request->getScriptName(); |
|
| 549 | - $processingScript = explode('/', $requestUri); |
|
| 550 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 551 | - |
|
| 552 | - // index.php routes are handled in the middleware |
|
| 553 | - if($processingScript === 'index.php') { |
|
| 554 | - return; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // All other endpoints require the lax and the strict cookie |
|
| 558 | - if(!$request->passesStrictCookieCheck()) { |
|
| 559 | - self::sendSameSiteCookies(); |
|
| 560 | - // Debug mode gets access to the resources without strict cookie |
|
| 561 | - // due to the fact that the SabreDAV browser also lives there. |
|
| 562 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 563 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 564 | - exit(); |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 568 | - self::sendSameSiteCookies(); |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - public static function init() { |
|
| 573 | - // calculate the root directories |
|
| 574 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 575 | - |
|
| 576 | - // register autoloader |
|
| 577 | - $loaderStart = microtime(true); |
|
| 578 | - require_once __DIR__ . '/autoloader.php'; |
|
| 579 | - self::$loader = new \OC\Autoloader([ |
|
| 580 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 581 | - ]); |
|
| 582 | - if (defined('PHPUNIT_RUN')) { |
|
| 583 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 584 | - } |
|
| 585 | - spl_autoload_register(array(self::$loader, 'load')); |
|
| 586 | - $loaderEnd = microtime(true); |
|
| 587 | - |
|
| 588 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
| 589 | - |
|
| 590 | - // Add default composer PSR-4 autoloader |
|
| 591 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 592 | - |
|
| 593 | - try { |
|
| 594 | - self::initPaths(); |
|
| 595 | - // setup 3rdparty autoloader |
|
| 596 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 597 | - if (!file_exists($vendorAutoLoad)) { |
|
| 598 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 599 | - } |
|
| 600 | - require_once $vendorAutoLoad; |
|
| 601 | - |
|
| 602 | - } catch (\RuntimeException $e) { |
|
| 603 | - if (!self::$CLI) { |
|
| 604 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 605 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 606 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 607 | - } |
|
| 608 | - // we can't use the template error page here, because this needs the |
|
| 609 | - // DI container which isn't available yet |
|
| 610 | - print($e->getMessage()); |
|
| 611 | - exit(); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - // setup the basic server |
|
| 615 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 616 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 617 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 618 | - |
|
| 619 | - // Don't display errors and log them |
|
| 620 | - error_reporting(E_ALL | E_STRICT); |
|
| 621 | - @ini_set('display_errors', '0'); |
|
| 622 | - @ini_set('log_errors', '1'); |
|
| 623 | - |
|
| 624 | - if(!date_default_timezone_set('UTC')) { |
|
| 625 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 626 | - }; |
|
| 627 | - |
|
| 628 | - //try to configure php to enable big file uploads. |
|
| 629 | - //this doesn´t work always depending on the webserver and php configuration. |
|
| 630 | - //Let´s try to overwrite some defaults anyway |
|
| 631 | - |
|
| 632 | - //try to set the maximum execution time to 60min |
|
| 633 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 634 | - @set_time_limit(3600); |
|
| 635 | - } |
|
| 636 | - @ini_set('max_execution_time', '3600'); |
|
| 637 | - @ini_set('max_input_time', '3600'); |
|
| 638 | - |
|
| 639 | - //try to set the maximum filesize to 10G |
|
| 640 | - @ini_set('upload_max_filesize', '10G'); |
|
| 641 | - @ini_set('post_max_size', '10G'); |
|
| 642 | - @ini_set('file_uploads', '50'); |
|
| 643 | - |
|
| 644 | - self::setRequiredIniValues(); |
|
| 645 | - self::handleAuthHeaders(); |
|
| 646 | - self::registerAutoloaderCache(); |
|
| 647 | - |
|
| 648 | - // initialize intl fallback is necessary |
|
| 649 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
| 650 | - OC_Util::isSetLocaleWorking(); |
|
| 651 | - |
|
| 652 | - if (!defined('PHPUNIT_RUN')) { |
|
| 653 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 654 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 655 | - OC\Log\ErrorHandler::register($debug); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 659 | - OC_App::loadApps(array('session')); |
|
| 660 | - if (!self::$CLI) { |
|
| 661 | - self::initSession(); |
|
| 662 | - } |
|
| 663 | - \OC::$server->getEventLogger()->end('init_session'); |
|
| 664 | - self::checkConfig(); |
|
| 665 | - self::checkInstalled(); |
|
| 666 | - |
|
| 667 | - OC_Response::addSecurityHeaders(); |
|
| 668 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 669 | - ini_set('session.cookie_secure', true); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - self::performSameSiteCookieProtection(); |
|
| 673 | - |
|
| 674 | - if (!defined('OC_CONSOLE')) { |
|
| 675 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 676 | - if (count($errors) > 0) { |
|
| 677 | - if (self::$CLI) { |
|
| 678 | - // Convert l10n string into regular string for usage in database |
|
| 679 | - $staticErrors = []; |
|
| 680 | - foreach ($errors as $error) { |
|
| 681 | - echo $error['error'] . "\n"; |
|
| 682 | - echo $error['hint'] . "\n\n"; |
|
| 683 | - $staticErrors[] = [ |
|
| 684 | - 'error' => (string)$error['error'], |
|
| 685 | - 'hint' => (string)$error['hint'], |
|
| 686 | - ]; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - try { |
|
| 690 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 691 | - } catch (\Exception $e) { |
|
| 692 | - echo('Writing to database failed'); |
|
| 693 | - } |
|
| 694 | - exit(1); |
|
| 695 | - } else { |
|
| 696 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 697 | - OC_Util::addStyle('guest'); |
|
| 698 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 699 | - exit; |
|
| 700 | - } |
|
| 701 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 702 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - //try to set the session lifetime |
|
| 706 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
| 707 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 708 | - |
|
| 709 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 710 | - |
|
| 711 | - // User and Groups |
|
| 712 | - if (!$systemConfig->getValue("installed", false)) { |
|
| 713 | - self::$server->getSession()->set('user_id', ''); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - OC_User::useBackend(new \OC\User\Database()); |
|
| 717 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 718 | - |
|
| 719 | - // Subscribe to the hook |
|
| 720 | - \OCP\Util::connectHook( |
|
| 721 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 722 | - 'preLoginNameUsedAsUserName', |
|
| 723 | - '\OC\User\Database', |
|
| 724 | - 'preLoginNameUsedAsUserName' |
|
| 725 | - ); |
|
| 726 | - |
|
| 727 | - //setup extra user backends |
|
| 728 | - if (!self::checkUpgrade(false)) { |
|
| 729 | - OC_User::setupBackends(); |
|
| 730 | - } else { |
|
| 731 | - // Run upgrades in incognito mode |
|
| 732 | - OC_User::setIncognitoMode(true); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - self::registerCleanupHooks(); |
|
| 736 | - self::registerFilesystemHooks(); |
|
| 737 | - self::registerShareHooks(); |
|
| 738 | - self::registerEncryptionWrapper(); |
|
| 739 | - self::registerEncryptionHooks(); |
|
| 740 | - self::registerAccountHooks(); |
|
| 741 | - self::registerSettingsHooks(); |
|
| 742 | - |
|
| 743 | - $settings = new \OC\Settings\Application(); |
|
| 744 | - $settings->register(); |
|
| 745 | - |
|
| 746 | - //make sure temporary files are cleaned up |
|
| 747 | - $tmpManager = \OC::$server->getTempManager(); |
|
| 748 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
| 749 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
| 750 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 751 | - |
|
| 752 | - // Check whether the sample configuration has been copied |
|
| 753 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 754 | - $l = \OC::$server->getL10N('lib'); |
|
| 755 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 756 | - header('Status: 503 Service Temporarily Unavailable'); |
|
| 757 | - OC_Template::printErrorPage( |
|
| 758 | - $l->t('Sample configuration detected'), |
|
| 759 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 760 | - ); |
|
| 761 | - return; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - $request = \OC::$server->getRequest(); |
|
| 765 | - $host = $request->getInsecureServerHost(); |
|
| 766 | - /** |
|
| 767 | - * if the host passed in headers isn't trusted |
|
| 768 | - * FIXME: Should not be in here at all :see_no_evil: |
|
| 769 | - */ |
|
| 770 | - if (!OC::$CLI |
|
| 771 | - // overwritehost is always trusted, workaround to not have to make |
|
| 772 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 773 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 774 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 775 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 776 | - ) { |
|
| 777 | - // Allow access to CSS resources |
|
| 778 | - $isScssRequest = false; |
|
| 779 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 780 | - $isScssRequest = true; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - if (!$isScssRequest) { |
|
| 784 | - header('HTTP/1.1 400 Bad Request'); |
|
| 785 | - header('Status: 400 Bad Request'); |
|
| 786 | - |
|
| 787 | - \OC::$server->getLogger()->warning( |
|
| 788 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 789 | - [ |
|
| 790 | - 'app' => 'core', |
|
| 791 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
| 792 | - 'host' => $host, |
|
| 793 | - ] |
|
| 794 | - ); |
|
| 795 | - |
|
| 796 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 797 | - $tmpl->assign('domain', $host); |
|
| 798 | - $tmpl->printPage(); |
|
| 799 | - |
|
| 800 | - exit(); |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - \OC::$server->getEventLogger()->end('boot'); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * register hooks for the cleanup of cache and bruteforce protection |
|
| 808 | - */ |
|
| 809 | - public static function registerCleanupHooks() { |
|
| 810 | - //don't try to do this before we are properly setup |
|
| 811 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
| 812 | - |
|
| 813 | - // NOTE: This will be replaced to use OCP |
|
| 814 | - $userSession = self::$server->getUserSession(); |
|
| 815 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 816 | - if (!defined('PHPUNIT_RUN')) { |
|
| 817 | - // reset brute force delay for this IP address and username |
|
| 818 | - $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 819 | - $request = \OC::$server->getRequest(); |
|
| 820 | - $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 821 | - $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - try { |
|
| 825 | - $cache = new \OC\Cache\File(); |
|
| 826 | - $cache->gc(); |
|
| 827 | - } catch (\OC\ServerNotAvailableException $e) { |
|
| 828 | - // not a GC exception, pass it on |
|
| 829 | - throw $e; |
|
| 830 | - } catch (\OC\ForbiddenException $e) { |
|
| 831 | - // filesystem blocked for this request, ignore |
|
| 832 | - } catch (\Exception $e) { |
|
| 833 | - // a GC exception should not prevent users from using OC, |
|
| 834 | - // so log the exception |
|
| 835 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 836 | - } |
|
| 837 | - }); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - public static function registerSettingsHooks() { |
|
| 842 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 843 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
| 844 | - /** @var \OCP\App\ManagerEvent $event */ |
|
| 845 | - \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
| 846 | - }); |
|
| 847 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
| 848 | - /** @var \OCP\App\ManagerEvent $event */ |
|
| 849 | - $jobList = \OC::$server->getJobList(); |
|
| 850 | - $job = 'OC\\Settings\\RemoveOrphaned'; |
|
| 851 | - if(!($jobList->has($job, null))) { |
|
| 852 | - $jobList->add($job); |
|
| 853 | - } |
|
| 854 | - }); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - private static function registerEncryptionWrapper() { |
|
| 858 | - $manager = self::$server->getEncryptionManager(); |
|
| 859 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - private static function registerEncryptionHooks() { |
|
| 863 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 864 | - if ($enabled) { |
|
| 865 | - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
| 866 | - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
| 867 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
| 868 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - private static function registerAccountHooks() { |
|
| 873 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 874 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * register hooks for the filesystem |
|
| 879 | - */ |
|
| 880 | - public static function registerFilesystemHooks() { |
|
| 881 | - // Check for blacklisted files |
|
| 882 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 883 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * register hooks for sharing |
|
| 888 | - */ |
|
| 889 | - public static function registerShareHooks() { |
|
| 890 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 891 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
| 892 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
| 893 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - protected static function registerAutoloaderCache() { |
|
| 898 | - // The class loader takes an optional low-latency cache, which MUST be |
|
| 899 | - // namespaced. The instanceid is used for namespacing, but might be |
|
| 900 | - // unavailable at this point. Furthermore, it might not be possible to |
|
| 901 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 902 | - // config file may not be writable. As such, we only register a class |
|
| 903 | - // loader cache if instanceid is available without trying to create one. |
|
| 904 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 905 | - if ($instanceId) { |
|
| 906 | - try { |
|
| 907 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 908 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 909 | - } catch (\Exception $ex) { |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * Handle the request |
|
| 916 | - */ |
|
| 917 | - public static function handleRequest() { |
|
| 918 | - |
|
| 919 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 920 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 921 | - // load all the classpaths from the enabled apps so they are available |
|
| 922 | - // in the routing files of each app |
|
| 923 | - OC::loadAppClassPaths(); |
|
| 924 | - |
|
| 925 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 926 | - if (!$systemConfig->getValue('installed', false)) { |
|
| 927 | - \OC::$server->getSession()->clear(); |
|
| 928 | - $setupHelper = new OC\Setup( |
|
| 929 | - \OC::$server->getSystemConfig(), |
|
| 930 | - \OC::$server->getIniWrapper(), |
|
| 931 | - \OC::$server->getL10N('lib'), |
|
| 932 | - \OC::$server->query(\OCP\Defaults::class), |
|
| 933 | - \OC::$server->getLogger(), |
|
| 934 | - \OC::$server->getSecureRandom(), |
|
| 935 | - \OC::$server->query(\OC\Installer::class) |
|
| 936 | - ); |
|
| 937 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 938 | - $controller->run($_POST); |
|
| 939 | - exit(); |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - $request = \OC::$server->getRequest(); |
|
| 943 | - $requestPath = $request->getRawPathInfo(); |
|
| 944 | - if ($requestPath === '/heartbeat') { |
|
| 945 | - return; |
|
| 946 | - } |
|
| 947 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 948 | - self::checkMaintenanceMode(); |
|
| 949 | - self::checkUpgrade(); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - // emergency app disabling |
|
| 953 | - if ($requestPath === '/disableapp' |
|
| 954 | - && $request->getMethod() === 'POST' |
|
| 955 | - && ((array)$request->getParam('appid')) !== '' |
|
| 956 | - ) { |
|
| 957 | - \OCP\JSON::callCheck(); |
|
| 958 | - \OCP\JSON::checkAdminUser(); |
|
| 959 | - $appIds = (array)$request->getParam('appid'); |
|
| 960 | - foreach($appIds as $appId) { |
|
| 961 | - $appId = \OC_App::cleanAppId($appId); |
|
| 962 | - \OC_App::disable($appId); |
|
| 963 | - } |
|
| 964 | - \OC_JSON::success(); |
|
| 965 | - exit(); |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - // Always load authentication apps |
|
| 969 | - OC_App::loadApps(['authentication']); |
|
| 970 | - |
|
| 971 | - // Load minimum set of apps |
|
| 972 | - if (!self::checkUpgrade(false) |
|
| 973 | - && !$systemConfig->getValue('maintenance', false)) { |
|
| 974 | - // For logged-in users: Load everything |
|
| 975 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 976 | - OC_App::loadApps(); |
|
| 977 | - } else { |
|
| 978 | - // For guests: Load only filesystem and logging |
|
| 979 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 980 | - self::handleLogin($request); |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - if (!self::$CLI) { |
|
| 985 | - try { |
|
| 986 | - if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
| 987 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
| 988 | - OC_App::loadApps(); |
|
| 989 | - } |
|
| 990 | - OC_Util::setupFS(); |
|
| 991 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 992 | - return; |
|
| 993 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 994 | - //header('HTTP/1.0 404 Not Found'); |
|
| 995 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 996 | - OC_Response::setStatus(405); |
|
| 997 | - return; |
|
| 998 | - } |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - // Handle WebDAV |
|
| 1002 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1003 | - // not allowed any more to prevent people |
|
| 1004 | - // mounting this root directly. |
|
| 1005 | - // Users need to mount remote.php/webdav instead. |
|
| 1006 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
| 1007 | - header('Status: 405 Method Not Allowed'); |
|
| 1008 | - return; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - // Someone is logged in |
|
| 1012 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1013 | - OC_App::loadApps(); |
|
| 1014 | - OC_User::setupBackends(); |
|
| 1015 | - OC_Util::setupFS(); |
|
| 1016 | - // FIXME |
|
| 1017 | - // Redirect to default application |
|
| 1018 | - OC_Util::redirectToDefaultPage(); |
|
| 1019 | - } else { |
|
| 1020 | - // Not handled and not logged in |
|
| 1021 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * Check login: apache auth, auth token, basic auth |
|
| 1027 | - * |
|
| 1028 | - * @param OCP\IRequest $request |
|
| 1029 | - * @return boolean |
|
| 1030 | - */ |
|
| 1031 | - static function handleLogin(OCP\IRequest $request) { |
|
| 1032 | - $userSession = self::$server->getUserSession(); |
|
| 1033 | - if (OC_User::handleApacheAuth()) { |
|
| 1034 | - return true; |
|
| 1035 | - } |
|
| 1036 | - if ($userSession->tryTokenLogin($request)) { |
|
| 1037 | - return true; |
|
| 1038 | - } |
|
| 1039 | - if (isset($_COOKIE['nc_username']) |
|
| 1040 | - && isset($_COOKIE['nc_token']) |
|
| 1041 | - && isset($_COOKIE['nc_session_id']) |
|
| 1042 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1043 | - return true; |
|
| 1044 | - } |
|
| 1045 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1046 | - return true; |
|
| 1047 | - } |
|
| 1048 | - return false; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - protected static function handleAuthHeaders() { |
|
| 1052 | - //copy http auth headers for apache+php-fcgid work around |
|
| 1053 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1054 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1058 | - $vars = array( |
|
| 1059 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1060 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1061 | - ); |
|
| 1062 | - foreach ($vars as $var) { |
|
| 1063 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1064 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1065 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1066 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1067 | - break; |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 67 | + /** |
|
| 68 | + * Associative array for autoloading. classname => filename |
|
| 69 | + */ |
|
| 70 | + public static $CLASSPATH = array(); |
|
| 71 | + /** |
|
| 72 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
| 73 | + */ |
|
| 74 | + public static $SERVERROOT = ''; |
|
| 75 | + /** |
|
| 76 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
| 77 | + */ |
|
| 78 | + private static $SUBURI = ''; |
|
| 79 | + /** |
|
| 80 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
| 81 | + */ |
|
| 82 | + public static $WEBROOT = ''; |
|
| 83 | + /** |
|
| 84 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
| 85 | + * web path in 'url' |
|
| 86 | + */ |
|
| 87 | + public static $APPSROOTS = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | + public static $configDir; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * requested app |
|
| 96 | + */ |
|
| 97 | + public static $REQUESTEDAPP = ''; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * check if Nextcloud runs in cli mode |
|
| 101 | + */ |
|
| 102 | + public static $CLI = false; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @var \OC\Autoloader $loader |
|
| 106 | + */ |
|
| 107 | + public static $loader = null; |
|
| 108 | + |
|
| 109 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
| 110 | + public static $composerAutoloader = null; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var \OC\Server |
|
| 114 | + */ |
|
| 115 | + public static $server = null; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var \OC\Config |
|
| 119 | + */ |
|
| 120 | + private static $config = null; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
| 124 | + * the app path list is empty or contains an invalid path |
|
| 125 | + */ |
|
| 126 | + public static function initPaths() { |
|
| 127 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 128 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 129 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 130 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 131 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 132 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
| 133 | + } else { |
|
| 134 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 135 | + } |
|
| 136 | + self::$config = new \OC\Config(self::$configDir); |
|
| 137 | + |
|
| 138 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
| 139 | + /** |
|
| 140 | + * FIXME: The following lines are required because we can't yet instantiate |
|
| 141 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
| 142 | + */ |
|
| 143 | + $params = [ |
|
| 144 | + 'server' => [ |
|
| 145 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
| 146 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
| 147 | + ], |
|
| 148 | + ]; |
|
| 149 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
| 150 | + $scriptName = $fakeRequest->getScriptName(); |
|
| 151 | + if (substr($scriptName, -1) == '/') { |
|
| 152 | + $scriptName .= 'index.php'; |
|
| 153 | + //make sure suburi follows the same rules as scriptName |
|
| 154 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
| 155 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
| 156 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 157 | + } |
|
| 158 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + if (OC::$CLI) { |
|
| 164 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 165 | + } else { |
|
| 166 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
| 167 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
| 168 | + |
|
| 169 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
| 170 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 171 | + } |
|
| 172 | + } else { |
|
| 173 | + // The scriptName is not ending with OC::$SUBURI |
|
| 174 | + // This most likely means that we are calling from CLI. |
|
| 175 | + // However some cron jobs still need to generate |
|
| 176 | + // a web URL, so we use overwritewebroot as a fallback. |
|
| 177 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
| 181 | + // slash which is required by URL generation. |
|
| 182 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
| 183 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
| 184 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
| 185 | + exit(); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // search the apps folder |
|
| 190 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
| 191 | + if (!empty($config_paths)) { |
|
| 192 | + foreach ($config_paths as $paths) { |
|
| 193 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
| 194 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
| 195 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
| 196 | + OC::$APPSROOTS[] = $paths; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 200 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 201 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 202 | + OC::$APPSROOTS[] = array( |
|
| 203 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 204 | + 'url' => '/apps', |
|
| 205 | + 'writable' => true |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (empty(OC::$APPSROOTS)) { |
|
| 210 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
| 211 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
| 212 | + } |
|
| 213 | + $paths = array(); |
|
| 214 | + foreach (OC::$APPSROOTS as $path) { |
|
| 215 | + $paths[] = $path['path']; |
|
| 216 | + if (!is_dir($path['path'])) { |
|
| 217 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
| 218 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
| 219 | + . ' config.php file.', $path['path'])); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // set the right include path |
|
| 224 | + set_include_path( |
|
| 225 | + implode(PATH_SEPARATOR, $paths) |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + public static function checkConfig() { |
|
| 230 | + $l = \OC::$server->getL10N('lib'); |
|
| 231 | + |
|
| 232 | + // Create config if it does not already exist |
|
| 233 | + $configFilePath = self::$configDir .'/config.php'; |
|
| 234 | + if(!file_exists($configFilePath)) { |
|
| 235 | + @touch($configFilePath); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + // Check if config is writable |
|
| 239 | + $configFileWritable = is_writable($configFilePath); |
|
| 240 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
| 241 | + || !$configFileWritable && self::checkUpgrade(false)) { |
|
| 242 | + |
|
| 243 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 244 | + |
|
| 245 | + if (self::$CLI) { |
|
| 246 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
| 247 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
| 248 | + echo "\n"; |
|
| 249 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 250 | + exit; |
|
| 251 | + } else { |
|
| 252 | + OC_Template::printErrorPage( |
|
| 253 | + $l->t('Cannot write into "config" directory!'), |
|
| 254 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
| 255 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
| 256 | + ); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + public static function checkInstalled() { |
|
| 262 | + if (defined('OC_CONSOLE')) { |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + // Redirect to installer if not installed |
|
| 266 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
| 267 | + if (OC::$CLI) { |
|
| 268 | + throw new Exception('Not installed'); |
|
| 269 | + } else { |
|
| 270 | + $url = OC::$WEBROOT . '/index.php'; |
|
| 271 | + header('Location: ' . $url); |
|
| 272 | + } |
|
| 273 | + exit(); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + public static function checkMaintenanceMode() { |
|
| 278 | + // Allow ajax update script to execute without being stopped |
|
| 279 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
| 280 | + // send http status 503 |
|
| 281 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 282 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 283 | + header('Retry-After: 120'); |
|
| 284 | + |
|
| 285 | + // render error page |
|
| 286 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
| 287 | + OC_Util::addScript('maintenance-check'); |
|
| 288 | + OC_Util::addStyle('core', 'guest'); |
|
| 289 | + $template->printPage(); |
|
| 290 | + die(); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Checks if the version requires an update and shows |
|
| 296 | + * @param bool $showTemplate Whether an update screen should get shown |
|
| 297 | + * @return bool|void |
|
| 298 | + */ |
|
| 299 | + public static function checkUpgrade($showTemplate = true) { |
|
| 300 | + if (\OCP\Util::needUpgrade()) { |
|
| 301 | + if (function_exists('opcache_reset')) { |
|
| 302 | + opcache_reset(); |
|
| 303 | + } |
|
| 304 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 305 | + if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
| 306 | + self::printUpgradePage(); |
|
| 307 | + exit(); |
|
| 308 | + } else { |
|
| 309 | + return true; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + return false; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Prints the upgrade page |
|
| 317 | + */ |
|
| 318 | + private static function printUpgradePage() { |
|
| 319 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 320 | + |
|
| 321 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
| 322 | + $tooBig = false; |
|
| 323 | + if (!$disableWebUpdater) { |
|
| 324 | + $apps = \OC::$server->getAppManager(); |
|
| 325 | + $tooBig = false; |
|
| 326 | + if ($apps->isInstalled('user_ldap')) { |
|
| 327 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 328 | + |
|
| 329 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 330 | + ->from('ldap_user_mapping') |
|
| 331 | + ->execute(); |
|
| 332 | + $row = $result->fetch(); |
|
| 333 | + $result->closeCursor(); |
|
| 334 | + |
|
| 335 | + $tooBig = ($row['user_count'] > 50); |
|
| 336 | + } |
|
| 337 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
| 338 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 339 | + |
|
| 340 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
| 341 | + ->from('user_saml_users') |
|
| 342 | + ->execute(); |
|
| 343 | + $row = $result->fetch(); |
|
| 344 | + $result->closeCursor(); |
|
| 345 | + |
|
| 346 | + $tooBig = ($row['user_count'] > 50); |
|
| 347 | + } |
|
| 348 | + if (!$tooBig) { |
|
| 349 | + // count users |
|
| 350 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
| 351 | + $totalUsers = array_sum($stats); |
|
| 352 | + $tooBig = ($totalUsers > 50); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
| 356 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
| 357 | + |
|
| 358 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
| 359 | + // send http status 503 |
|
| 360 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 361 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 362 | + header('Retry-After: 120'); |
|
| 363 | + |
|
| 364 | + // render error page |
|
| 365 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
| 366 | + $template->assign('productName', 'nextcloud'); // for now |
|
| 367 | + $template->assign('version', OC_Util::getVersionString()); |
|
| 368 | + $template->assign('tooBig', $tooBig); |
|
| 369 | + |
|
| 370 | + $template->printPage(); |
|
| 371 | + die(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // check whether this is a core update or apps update |
|
| 375 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
| 376 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 377 | + |
|
| 378 | + // if not a core upgrade, then it's apps upgrade |
|
| 379 | + $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
| 380 | + |
|
| 381 | + $oldTheme = $systemConfig->getValue('theme'); |
|
| 382 | + $systemConfig->setValue('theme', ''); |
|
| 383 | + OC_Util::addScript('config'); // needed for web root |
|
| 384 | + OC_Util::addScript('update'); |
|
| 385 | + |
|
| 386 | + /** @var \OC\App\AppManager $appManager */ |
|
| 387 | + $appManager = \OC::$server->getAppManager(); |
|
| 388 | + |
|
| 389 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
| 390 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
| 391 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
| 392 | + |
|
| 393 | + // get third party apps |
|
| 394 | + $ocVersion = \OCP\Util::getVersion(); |
|
| 395 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
| 396 | + $incompatibleShippedApps = []; |
|
| 397 | + foreach ($incompatibleApps as $appInfo) { |
|
| 398 | + if ($appManager->isShipped($appInfo['id'])) { |
|
| 399 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + if (!empty($incompatibleShippedApps)) { |
|
| 404 | + $l = \OC::$server->getL10N('core'); |
|
| 405 | + $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
| 406 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
|
| 410 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
| 411 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
| 412 | + $tmpl->assign('oldTheme', $oldTheme); |
|
| 413 | + $tmpl->printPage(); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public static function initSession() { |
|
| 417 | + // prevents javascript from accessing php session cookies |
|
| 418 | + ini_set('session.cookie_httponly', 'true'); |
|
| 419 | + |
|
| 420 | + // set the cookie path to the Nextcloud directory |
|
| 421 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 422 | + ini_set('session.cookie_path', $cookie_path); |
|
| 423 | + |
|
| 424 | + // Let the session name be changed in the initSession Hook |
|
| 425 | + $sessionName = OC_Util::getInstanceId(); |
|
| 426 | + |
|
| 427 | + try { |
|
| 428 | + // Allow session apps to create a custom session object |
|
| 429 | + $useCustomSession = false; |
|
| 430 | + $session = self::$server->getSession(); |
|
| 431 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
| 432 | + if (!$useCustomSession) { |
|
| 433 | + // set the session name to the instance id - which is unique |
|
| 434 | + $session = new \OC\Session\Internal($sessionName); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
| 438 | + $session = $cryptoWrapper->wrapSession($session); |
|
| 439 | + self::$server->setSession($session); |
|
| 440 | + |
|
| 441 | + // if session can't be started break with http 500 error |
|
| 442 | + } catch (Exception $e) { |
|
| 443 | + \OCP\Util::logException('base', $e); |
|
| 444 | + //show the user a detailed error page |
|
| 445 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 446 | + OC_Template::printExceptionErrorPage($e); |
|
| 447 | + die(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 451 | + |
|
| 452 | + // session timeout |
|
| 453 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
| 454 | + if (isset($_COOKIE[session_name()])) { |
|
| 455 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 456 | + } |
|
| 457 | + \OC::$server->getUserSession()->logout(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + $session->set('LAST_ACTIVITY', time()); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @return string |
|
| 465 | + */ |
|
| 466 | + private static function getSessionLifeTime() { |
|
| 467 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + public static function loadAppClassPaths() { |
|
| 471 | + foreach (OC_App::getEnabledApps() as $app) { |
|
| 472 | + $appPath = OC_App::getAppPath($app); |
|
| 473 | + if ($appPath === false) { |
|
| 474 | + continue; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $file = $appPath . '/appinfo/classpath.php'; |
|
| 478 | + if (file_exists($file)) { |
|
| 479 | + require_once $file; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Try to set some values to the required Nextcloud default |
|
| 486 | + */ |
|
| 487 | + public static function setRequiredIniValues() { |
|
| 488 | + @ini_set('default_charset', 'UTF-8'); |
|
| 489 | + @ini_set('gd.jpeg_ignore_warning', '1'); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Send the same site cookies |
|
| 494 | + */ |
|
| 495 | + private static function sendSameSiteCookies() { |
|
| 496 | + $cookieParams = session_get_cookie_params(); |
|
| 497 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
| 498 | + $policies = [ |
|
| 499 | + 'lax', |
|
| 500 | + 'strict', |
|
| 501 | + ]; |
|
| 502 | + |
|
| 503 | + // Append __Host to the cookie if it meets the requirements |
|
| 504 | + $cookiePrefix = ''; |
|
| 505 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 506 | + $cookiePrefix = '__Host-'; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + foreach($policies as $policy) { |
|
| 510 | + header( |
|
| 511 | + sprintf( |
|
| 512 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 513 | + $cookiePrefix, |
|
| 514 | + $policy, |
|
| 515 | + $cookieParams['path'], |
|
| 516 | + $policy |
|
| 517 | + ), |
|
| 518 | + false |
|
| 519 | + ); |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
| 525 | + * be set in every request if cookies are sent to add a second level of |
|
| 526 | + * defense against CSRF. |
|
| 527 | + * |
|
| 528 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
| 529 | + * We use an additional cookie since we want to protect logout CSRF and |
|
| 530 | + * also we can't directly interfere with PHP's session mechanism. |
|
| 531 | + */ |
|
| 532 | + private static function performSameSiteCookieProtection() { |
|
| 533 | + $request = \OC::$server->getRequest(); |
|
| 534 | + |
|
| 535 | + // Some user agents are notorious and don't really properly follow HTTP |
|
| 536 | + // specifications. For those, have an automated opt-out. Since the protection |
|
| 537 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
| 538 | + // here. |
|
| 539 | + $incompatibleUserAgents = [ |
|
| 540 | + // OS X Finder |
|
| 541 | + '/^WebDAVFS/', |
|
| 542 | + ]; |
|
| 543 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 544 | + return; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if(count($_COOKIE) > 0) { |
|
| 548 | + $requestUri = $request->getScriptName(); |
|
| 549 | + $processingScript = explode('/', $requestUri); |
|
| 550 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
| 551 | + |
|
| 552 | + // index.php routes are handled in the middleware |
|
| 553 | + if($processingScript === 'index.php') { |
|
| 554 | + return; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // All other endpoints require the lax and the strict cookie |
|
| 558 | + if(!$request->passesStrictCookieCheck()) { |
|
| 559 | + self::sendSameSiteCookies(); |
|
| 560 | + // Debug mode gets access to the resources without strict cookie |
|
| 561 | + // due to the fact that the SabreDAV browser also lives there. |
|
| 562 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 563 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 564 | + exit(); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 568 | + self::sendSameSiteCookies(); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + public static function init() { |
|
| 573 | + // calculate the root directories |
|
| 574 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
| 575 | + |
|
| 576 | + // register autoloader |
|
| 577 | + $loaderStart = microtime(true); |
|
| 578 | + require_once __DIR__ . '/autoloader.php'; |
|
| 579 | + self::$loader = new \OC\Autoloader([ |
|
| 580 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
| 581 | + ]); |
|
| 582 | + if (defined('PHPUNIT_RUN')) { |
|
| 583 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 584 | + } |
|
| 585 | + spl_autoload_register(array(self::$loader, 'load')); |
|
| 586 | + $loaderEnd = microtime(true); |
|
| 587 | + |
|
| 588 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
| 589 | + |
|
| 590 | + // Add default composer PSR-4 autoloader |
|
| 591 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 592 | + |
|
| 593 | + try { |
|
| 594 | + self::initPaths(); |
|
| 595 | + // setup 3rdparty autoloader |
|
| 596 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 597 | + if (!file_exists($vendorAutoLoad)) { |
|
| 598 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
| 599 | + } |
|
| 600 | + require_once $vendorAutoLoad; |
|
| 601 | + |
|
| 602 | + } catch (\RuntimeException $e) { |
|
| 603 | + if (!self::$CLI) { |
|
| 604 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 605 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
| 606 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 607 | + } |
|
| 608 | + // we can't use the template error page here, because this needs the |
|
| 609 | + // DI container which isn't available yet |
|
| 610 | + print($e->getMessage()); |
|
| 611 | + exit(); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + // setup the basic server |
|
| 615 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
| 616 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
| 617 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
| 618 | + |
|
| 619 | + // Don't display errors and log them |
|
| 620 | + error_reporting(E_ALL | E_STRICT); |
|
| 621 | + @ini_set('display_errors', '0'); |
|
| 622 | + @ini_set('log_errors', '1'); |
|
| 623 | + |
|
| 624 | + if(!date_default_timezone_set('UTC')) { |
|
| 625 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
| 626 | + }; |
|
| 627 | + |
|
| 628 | + //try to configure php to enable big file uploads. |
|
| 629 | + //this doesn´t work always depending on the webserver and php configuration. |
|
| 630 | + //Let´s try to overwrite some defaults anyway |
|
| 631 | + |
|
| 632 | + //try to set the maximum execution time to 60min |
|
| 633 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 634 | + @set_time_limit(3600); |
|
| 635 | + } |
|
| 636 | + @ini_set('max_execution_time', '3600'); |
|
| 637 | + @ini_set('max_input_time', '3600'); |
|
| 638 | + |
|
| 639 | + //try to set the maximum filesize to 10G |
|
| 640 | + @ini_set('upload_max_filesize', '10G'); |
|
| 641 | + @ini_set('post_max_size', '10G'); |
|
| 642 | + @ini_set('file_uploads', '50'); |
|
| 643 | + |
|
| 644 | + self::setRequiredIniValues(); |
|
| 645 | + self::handleAuthHeaders(); |
|
| 646 | + self::registerAutoloaderCache(); |
|
| 647 | + |
|
| 648 | + // initialize intl fallback is necessary |
|
| 649 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
| 650 | + OC_Util::isSetLocaleWorking(); |
|
| 651 | + |
|
| 652 | + if (!defined('PHPUNIT_RUN')) { |
|
| 653 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
| 654 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
| 655 | + OC\Log\ErrorHandler::register($debug); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
| 659 | + OC_App::loadApps(array('session')); |
|
| 660 | + if (!self::$CLI) { |
|
| 661 | + self::initSession(); |
|
| 662 | + } |
|
| 663 | + \OC::$server->getEventLogger()->end('init_session'); |
|
| 664 | + self::checkConfig(); |
|
| 665 | + self::checkInstalled(); |
|
| 666 | + |
|
| 667 | + OC_Response::addSecurityHeaders(); |
|
| 668 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 669 | + ini_set('session.cookie_secure', true); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + self::performSameSiteCookieProtection(); |
|
| 673 | + |
|
| 674 | + if (!defined('OC_CONSOLE')) { |
|
| 675 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 676 | + if (count($errors) > 0) { |
|
| 677 | + if (self::$CLI) { |
|
| 678 | + // Convert l10n string into regular string for usage in database |
|
| 679 | + $staticErrors = []; |
|
| 680 | + foreach ($errors as $error) { |
|
| 681 | + echo $error['error'] . "\n"; |
|
| 682 | + echo $error['hint'] . "\n\n"; |
|
| 683 | + $staticErrors[] = [ |
|
| 684 | + 'error' => (string)$error['error'], |
|
| 685 | + 'hint' => (string)$error['hint'], |
|
| 686 | + ]; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + try { |
|
| 690 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
| 691 | + } catch (\Exception $e) { |
|
| 692 | + echo('Writing to database failed'); |
|
| 693 | + } |
|
| 694 | + exit(1); |
|
| 695 | + } else { |
|
| 696 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 697 | + OC_Util::addStyle('guest'); |
|
| 698 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
| 699 | + exit; |
|
| 700 | + } |
|
| 701 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
| 702 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + //try to set the session lifetime |
|
| 706 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
| 707 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 708 | + |
|
| 709 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 710 | + |
|
| 711 | + // User and Groups |
|
| 712 | + if (!$systemConfig->getValue("installed", false)) { |
|
| 713 | + self::$server->getSession()->set('user_id', ''); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + OC_User::useBackend(new \OC\User\Database()); |
|
| 717 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
| 718 | + |
|
| 719 | + // Subscribe to the hook |
|
| 720 | + \OCP\Util::connectHook( |
|
| 721 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 722 | + 'preLoginNameUsedAsUserName', |
|
| 723 | + '\OC\User\Database', |
|
| 724 | + 'preLoginNameUsedAsUserName' |
|
| 725 | + ); |
|
| 726 | + |
|
| 727 | + //setup extra user backends |
|
| 728 | + if (!self::checkUpgrade(false)) { |
|
| 729 | + OC_User::setupBackends(); |
|
| 730 | + } else { |
|
| 731 | + // Run upgrades in incognito mode |
|
| 732 | + OC_User::setIncognitoMode(true); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + self::registerCleanupHooks(); |
|
| 736 | + self::registerFilesystemHooks(); |
|
| 737 | + self::registerShareHooks(); |
|
| 738 | + self::registerEncryptionWrapper(); |
|
| 739 | + self::registerEncryptionHooks(); |
|
| 740 | + self::registerAccountHooks(); |
|
| 741 | + self::registerSettingsHooks(); |
|
| 742 | + |
|
| 743 | + $settings = new \OC\Settings\Application(); |
|
| 744 | + $settings->register(); |
|
| 745 | + |
|
| 746 | + //make sure temporary files are cleaned up |
|
| 747 | + $tmpManager = \OC::$server->getTempManager(); |
|
| 748 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
| 749 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
| 750 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
| 751 | + |
|
| 752 | + // Check whether the sample configuration has been copied |
|
| 753 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 754 | + $l = \OC::$server->getL10N('lib'); |
|
| 755 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
| 756 | + header('Status: 503 Service Temporarily Unavailable'); |
|
| 757 | + OC_Template::printErrorPage( |
|
| 758 | + $l->t('Sample configuration detected'), |
|
| 759 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
| 760 | + ); |
|
| 761 | + return; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + $request = \OC::$server->getRequest(); |
|
| 765 | + $host = $request->getInsecureServerHost(); |
|
| 766 | + /** |
|
| 767 | + * if the host passed in headers isn't trusted |
|
| 768 | + * FIXME: Should not be in here at all :see_no_evil: |
|
| 769 | + */ |
|
| 770 | + if (!OC::$CLI |
|
| 771 | + // overwritehost is always trusted, workaround to not have to make |
|
| 772 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
| 773 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
| 774 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
| 775 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
| 776 | + ) { |
|
| 777 | + // Allow access to CSS resources |
|
| 778 | + $isScssRequest = false; |
|
| 779 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 780 | + $isScssRequest = true; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + if (!$isScssRequest) { |
|
| 784 | + header('HTTP/1.1 400 Bad Request'); |
|
| 785 | + header('Status: 400 Bad Request'); |
|
| 786 | + |
|
| 787 | + \OC::$server->getLogger()->warning( |
|
| 788 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
| 789 | + [ |
|
| 790 | + 'app' => 'core', |
|
| 791 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
| 792 | + 'host' => $host, |
|
| 793 | + ] |
|
| 794 | + ); |
|
| 795 | + |
|
| 796 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
| 797 | + $tmpl->assign('domain', $host); |
|
| 798 | + $tmpl->printPage(); |
|
| 799 | + |
|
| 800 | + exit(); |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + \OC::$server->getEventLogger()->end('boot'); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * register hooks for the cleanup of cache and bruteforce protection |
|
| 808 | + */ |
|
| 809 | + public static function registerCleanupHooks() { |
|
| 810 | + //don't try to do this before we are properly setup |
|
| 811 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
| 812 | + |
|
| 813 | + // NOTE: This will be replaced to use OCP |
|
| 814 | + $userSession = self::$server->getUserSession(); |
|
| 815 | + $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 816 | + if (!defined('PHPUNIT_RUN')) { |
|
| 817 | + // reset brute force delay for this IP address and username |
|
| 818 | + $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
|
| 819 | + $request = \OC::$server->getRequest(); |
|
| 820 | + $throttler = \OC::$server->getBruteForceThrottler(); |
|
| 821 | + $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + try { |
|
| 825 | + $cache = new \OC\Cache\File(); |
|
| 826 | + $cache->gc(); |
|
| 827 | + } catch (\OC\ServerNotAvailableException $e) { |
|
| 828 | + // not a GC exception, pass it on |
|
| 829 | + throw $e; |
|
| 830 | + } catch (\OC\ForbiddenException $e) { |
|
| 831 | + // filesystem blocked for this request, ignore |
|
| 832 | + } catch (\Exception $e) { |
|
| 833 | + // a GC exception should not prevent users from using OC, |
|
| 834 | + // so log the exception |
|
| 835 | + \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 836 | + } |
|
| 837 | + }); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + public static function registerSettingsHooks() { |
|
| 842 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 843 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
| 844 | + /** @var \OCP\App\ManagerEvent $event */ |
|
| 845 | + \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
| 846 | + }); |
|
| 847 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
| 848 | + /** @var \OCP\App\ManagerEvent $event */ |
|
| 849 | + $jobList = \OC::$server->getJobList(); |
|
| 850 | + $job = 'OC\\Settings\\RemoveOrphaned'; |
|
| 851 | + if(!($jobList->has($job, null))) { |
|
| 852 | + $jobList->add($job); |
|
| 853 | + } |
|
| 854 | + }); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + private static function registerEncryptionWrapper() { |
|
| 858 | + $manager = self::$server->getEncryptionManager(); |
|
| 859 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + private static function registerEncryptionHooks() { |
|
| 863 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
| 864 | + if ($enabled) { |
|
| 865 | + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
| 866 | + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
| 867 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
| 868 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + private static function registerAccountHooks() { |
|
| 873 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
| 874 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * register hooks for the filesystem |
|
| 879 | + */ |
|
| 880 | + public static function registerFilesystemHooks() { |
|
| 881 | + // Check for blacklisted files |
|
| 882 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 883 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * register hooks for sharing |
|
| 888 | + */ |
|
| 889 | + public static function registerShareHooks() { |
|
| 890 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
| 891 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
| 892 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
| 893 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + protected static function registerAutoloaderCache() { |
|
| 898 | + // The class loader takes an optional low-latency cache, which MUST be |
|
| 899 | + // namespaced. The instanceid is used for namespacing, but might be |
|
| 900 | + // unavailable at this point. Furthermore, it might not be possible to |
|
| 901 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
| 902 | + // config file may not be writable. As such, we only register a class |
|
| 903 | + // loader cache if instanceid is available without trying to create one. |
|
| 904 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 905 | + if ($instanceId) { |
|
| 906 | + try { |
|
| 907 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
| 908 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
| 909 | + } catch (\Exception $ex) { |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * Handle the request |
|
| 916 | + */ |
|
| 917 | + public static function handleRequest() { |
|
| 918 | + |
|
| 919 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
| 920 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 921 | + // load all the classpaths from the enabled apps so they are available |
|
| 922 | + // in the routing files of each app |
|
| 923 | + OC::loadAppClassPaths(); |
|
| 924 | + |
|
| 925 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
| 926 | + if (!$systemConfig->getValue('installed', false)) { |
|
| 927 | + \OC::$server->getSession()->clear(); |
|
| 928 | + $setupHelper = new OC\Setup( |
|
| 929 | + \OC::$server->getSystemConfig(), |
|
| 930 | + \OC::$server->getIniWrapper(), |
|
| 931 | + \OC::$server->getL10N('lib'), |
|
| 932 | + \OC::$server->query(\OCP\Defaults::class), |
|
| 933 | + \OC::$server->getLogger(), |
|
| 934 | + \OC::$server->getSecureRandom(), |
|
| 935 | + \OC::$server->query(\OC\Installer::class) |
|
| 936 | + ); |
|
| 937 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
| 938 | + $controller->run($_POST); |
|
| 939 | + exit(); |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + $request = \OC::$server->getRequest(); |
|
| 943 | + $requestPath = $request->getRawPathInfo(); |
|
| 944 | + if ($requestPath === '/heartbeat') { |
|
| 945 | + return; |
|
| 946 | + } |
|
| 947 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
| 948 | + self::checkMaintenanceMode(); |
|
| 949 | + self::checkUpgrade(); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + // emergency app disabling |
|
| 953 | + if ($requestPath === '/disableapp' |
|
| 954 | + && $request->getMethod() === 'POST' |
|
| 955 | + && ((array)$request->getParam('appid')) !== '' |
|
| 956 | + ) { |
|
| 957 | + \OCP\JSON::callCheck(); |
|
| 958 | + \OCP\JSON::checkAdminUser(); |
|
| 959 | + $appIds = (array)$request->getParam('appid'); |
|
| 960 | + foreach($appIds as $appId) { |
|
| 961 | + $appId = \OC_App::cleanAppId($appId); |
|
| 962 | + \OC_App::disable($appId); |
|
| 963 | + } |
|
| 964 | + \OC_JSON::success(); |
|
| 965 | + exit(); |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + // Always load authentication apps |
|
| 969 | + OC_App::loadApps(['authentication']); |
|
| 970 | + |
|
| 971 | + // Load minimum set of apps |
|
| 972 | + if (!self::checkUpgrade(false) |
|
| 973 | + && !$systemConfig->getValue('maintenance', false)) { |
|
| 974 | + // For logged-in users: Load everything |
|
| 975 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 976 | + OC_App::loadApps(); |
|
| 977 | + } else { |
|
| 978 | + // For guests: Load only filesystem and logging |
|
| 979 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 980 | + self::handleLogin($request); |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + if (!self::$CLI) { |
|
| 985 | + try { |
|
| 986 | + if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
| 987 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
| 988 | + OC_App::loadApps(); |
|
| 989 | + } |
|
| 990 | + OC_Util::setupFS(); |
|
| 991 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
| 992 | + return; |
|
| 993 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
| 994 | + //header('HTTP/1.0 404 Not Found'); |
|
| 995 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
| 996 | + OC_Response::setStatus(405); |
|
| 997 | + return; |
|
| 998 | + } |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + // Handle WebDAV |
|
| 1002 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 1003 | + // not allowed any more to prevent people |
|
| 1004 | + // mounting this root directly. |
|
| 1005 | + // Users need to mount remote.php/webdav instead. |
|
| 1006 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
| 1007 | + header('Status: 405 Method Not Allowed'); |
|
| 1008 | + return; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + // Someone is logged in |
|
| 1012 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 1013 | + OC_App::loadApps(); |
|
| 1014 | + OC_User::setupBackends(); |
|
| 1015 | + OC_Util::setupFS(); |
|
| 1016 | + // FIXME |
|
| 1017 | + // Redirect to default application |
|
| 1018 | + OC_Util::redirectToDefaultPage(); |
|
| 1019 | + } else { |
|
| 1020 | + // Not handled and not logged in |
|
| 1021 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * Check login: apache auth, auth token, basic auth |
|
| 1027 | + * |
|
| 1028 | + * @param OCP\IRequest $request |
|
| 1029 | + * @return boolean |
|
| 1030 | + */ |
|
| 1031 | + static function handleLogin(OCP\IRequest $request) { |
|
| 1032 | + $userSession = self::$server->getUserSession(); |
|
| 1033 | + if (OC_User::handleApacheAuth()) { |
|
| 1034 | + return true; |
|
| 1035 | + } |
|
| 1036 | + if ($userSession->tryTokenLogin($request)) { |
|
| 1037 | + return true; |
|
| 1038 | + } |
|
| 1039 | + if (isset($_COOKIE['nc_username']) |
|
| 1040 | + && isset($_COOKIE['nc_token']) |
|
| 1041 | + && isset($_COOKIE['nc_session_id']) |
|
| 1042 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
| 1043 | + return true; |
|
| 1044 | + } |
|
| 1045 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
| 1046 | + return true; |
|
| 1047 | + } |
|
| 1048 | + return false; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + protected static function handleAuthHeaders() { |
|
| 1052 | + //copy http auth headers for apache+php-fcgid work around |
|
| 1053 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
| 1054 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
| 1058 | + $vars = array( |
|
| 1059 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
| 1060 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
| 1061 | + ); |
|
| 1062 | + foreach ($vars as $var) { |
|
| 1063 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
| 1064 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
| 1065 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
| 1066 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
| 1067 | + break; |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | OC::init(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | * the app path list is empty or contains an invalid path |
| 125 | 125 | */ |
| 126 | 126 | public static function initPaths() { |
| 127 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
| 128 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
| 129 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
| 130 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
| 131 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 132 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
| 127 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
| 128 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
| 129 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
| 130 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
| 131 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
| 132 | + self::$configDir = rtrim($dir, '/').'/'; |
|
| 133 | 133 | } else { |
| 134 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
| 134 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
| 135 | 135 | } |
| 136 | 136 | self::$config = new \OC\Config(self::$configDir); |
| 137 | 137 | |
@@ -153,9 +153,9 @@ discard block |
||
| 153 | 153 | //make sure suburi follows the same rules as scriptName |
| 154 | 154 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
| 155 | 155 | if (substr(OC::$SUBURI, -1) != '/') { |
| 156 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
| 156 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
| 157 | 157 | } |
| 158 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
| 158 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
| 168 | 168 | |
| 169 | 169 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
| 170 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
| 170 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
| 171 | 171 | } |
| 172 | 172 | } else { |
| 173 | 173 | // The scriptName is not ending with OC::$SUBURI |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | OC::$APPSROOTS[] = $paths; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
| 200 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
| 201 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
| 199 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
| 200 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
| 201 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
| 202 | 202 | OC::$APPSROOTS[] = array( |
| 203 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
| 203 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
| 204 | 204 | 'url' => '/apps', |
| 205 | 205 | 'writable' => true |
| 206 | 206 | ); |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | $l = \OC::$server->getL10N('lib'); |
| 231 | 231 | |
| 232 | 232 | // Create config if it does not already exist |
| 233 | - $configFilePath = self::$configDir .'/config.php'; |
|
| 234 | - if(!file_exists($configFilePath)) { |
|
| 233 | + $configFilePath = self::$configDir.'/config.php'; |
|
| 234 | + if (!file_exists($configFilePath)) { |
|
| 235 | 235 | @touch($configFilePath); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -246,13 +246,13 @@ discard block |
||
| 246 | 246 | echo $l->t('Cannot write into "config" directory!')."\n"; |
| 247 | 247 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
| 248 | 248 | echo "\n"; |
| 249 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
| 249 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
| 250 | 250 | exit; |
| 251 | 251 | } else { |
| 252 | 252 | OC_Template::printErrorPage( |
| 253 | 253 | $l->t('Cannot write into "config" directory!'), |
| 254 | 254 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
| 255 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
| 255 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 256 | 256 | ); |
| 257 | 257 | } |
| 258 | 258 | } |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | if (OC::$CLI) { |
| 268 | 268 | throw new Exception('Not installed'); |
| 269 | 269 | } else { |
| 270 | - $url = OC::$WEBROOT . '/index.php'; |
|
| 271 | - header('Location: ' . $url); |
|
| 270 | + $url = OC::$WEBROOT.'/index.php'; |
|
| 271 | + header('Location: '.$url); |
|
| 272 | 272 | } |
| 273 | 273 | exit(); |
| 274 | 274 | } |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | $incompatibleShippedApps = []; |
| 397 | 397 | foreach ($incompatibleApps as $appInfo) { |
| 398 | 398 | if ($appManager->isShipped($appInfo['id'])) { |
| 399 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
| 399 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | if (!empty($incompatibleShippedApps)) { |
| 404 | 404 | $l = \OC::$server->getL10N('core'); |
| 405 | 405 | $hint = $l->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
| 406 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 406 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | ini_set('session.cookie_httponly', 'true'); |
| 419 | 419 | |
| 420 | 420 | // set the cookie path to the Nextcloud directory |
| 421 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
| 421 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
| 422 | 422 | ini_set('session.cookie_path', $cookie_path); |
| 423 | 423 | |
| 424 | 424 | // Let the session name be changed in the initSession Hook |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | // session timeout |
| 453 | 453 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
| 454 | 454 | if (isset($_COOKIE[session_name()])) { |
| 455 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
| 455 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
| 456 | 456 | } |
| 457 | 457 | \OC::$server->getUserSession()->logout(); |
| 458 | 458 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | continue; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - $file = $appPath . '/appinfo/classpath.php'; |
|
| 477 | + $file = $appPath.'/appinfo/classpath.php'; |
|
| 478 | 478 | if (file_exists($file)) { |
| 479 | 479 | require_once $file; |
| 480 | 480 | } |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | // Append __Host to the cookie if it meets the requirements |
| 504 | 504 | $cookiePrefix = ''; |
| 505 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 505 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
| 506 | 506 | $cookiePrefix = '__Host-'; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - foreach($policies as $policy) { |
|
| 509 | + foreach ($policies as $policy) { |
|
| 510 | 510 | header( |
| 511 | 511 | sprintf( |
| 512 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 512 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
| 513 | 513 | $cookiePrefix, |
| 514 | 514 | $policy, |
| 515 | 515 | $cookieParams['path'], |
@@ -540,31 +540,31 @@ discard block |
||
| 540 | 540 | // OS X Finder |
| 541 | 541 | '/^WebDAVFS/', |
| 542 | 542 | ]; |
| 543 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
| 543 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
| 544 | 544 | return; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - if(count($_COOKIE) > 0) { |
|
| 547 | + if (count($_COOKIE) > 0) { |
|
| 548 | 548 | $requestUri = $request->getScriptName(); |
| 549 | 549 | $processingScript = explode('/', $requestUri); |
| 550 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
| 550 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
| 551 | 551 | |
| 552 | 552 | // index.php routes are handled in the middleware |
| 553 | - if($processingScript === 'index.php') { |
|
| 553 | + if ($processingScript === 'index.php') { |
|
| 554 | 554 | return; |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | // All other endpoints require the lax and the strict cookie |
| 558 | - if(!$request->passesStrictCookieCheck()) { |
|
| 558 | + if (!$request->passesStrictCookieCheck()) { |
|
| 559 | 559 | self::sendSameSiteCookies(); |
| 560 | 560 | // Debug mode gets access to the resources without strict cookie |
| 561 | 561 | // due to the fact that the SabreDAV browser also lives there. |
| 562 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 562 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 563 | 563 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
| 564 | 564 | exit(); |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 567 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
| 568 | 568 | self::sendSameSiteCookies(); |
| 569 | 569 | } |
| 570 | 570 | } |
@@ -575,12 +575,12 @@ discard block |
||
| 575 | 575 | |
| 576 | 576 | // register autoloader |
| 577 | 577 | $loaderStart = microtime(true); |
| 578 | - require_once __DIR__ . '/autoloader.php'; |
|
| 578 | + require_once __DIR__.'/autoloader.php'; |
|
| 579 | 579 | self::$loader = new \OC\Autoloader([ |
| 580 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
| 580 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
| 581 | 581 | ]); |
| 582 | 582 | if (defined('PHPUNIT_RUN')) { |
| 583 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
| 583 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
| 584 | 584 | } |
| 585 | 585 | spl_autoload_register(array(self::$loader, 'load')); |
| 586 | 586 | $loaderEnd = microtime(true); |
@@ -588,12 +588,12 @@ discard block |
||
| 588 | 588 | self::$CLI = (php_sapi_name() == 'cli'); |
| 589 | 589 | |
| 590 | 590 | // Add default composer PSR-4 autoloader |
| 591 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
| 591 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
| 592 | 592 | |
| 593 | 593 | try { |
| 594 | 594 | self::initPaths(); |
| 595 | 595 | // setup 3rdparty autoloader |
| 596 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
| 596 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
| 597 | 597 | if (!file_exists($vendorAutoLoad)) { |
| 598 | 598 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
| 599 | 599 | } |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | if (!self::$CLI) { |
| 604 | 604 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
| 605 | 605 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
| 606 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 606 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 607 | 607 | } |
| 608 | 608 | // we can't use the template error page here, because this needs the |
| 609 | 609 | // DI container which isn't available yet |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | @ini_set('display_errors', '0'); |
| 622 | 622 | @ini_set('log_errors', '1'); |
| 623 | 623 | |
| 624 | - if(!date_default_timezone_set('UTC')) { |
|
| 624 | + if (!date_default_timezone_set('UTC')) { |
|
| 625 | 625 | throw new \RuntimeException('Could not set timezone to UTC'); |
| 626 | 626 | }; |
| 627 | 627 | |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | self::checkInstalled(); |
| 666 | 666 | |
| 667 | 667 | OC_Response::addSecurityHeaders(); |
| 668 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 668 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
| 669 | 669 | ini_set('session.cookie_secure', true); |
| 670 | 670 | } |
| 671 | 671 | |
@@ -678,11 +678,11 @@ discard block |
||
| 678 | 678 | // Convert l10n string into regular string for usage in database |
| 679 | 679 | $staticErrors = []; |
| 680 | 680 | foreach ($errors as $error) { |
| 681 | - echo $error['error'] . "\n"; |
|
| 682 | - echo $error['hint'] . "\n\n"; |
|
| 681 | + echo $error['error']."\n"; |
|
| 682 | + echo $error['hint']."\n\n"; |
|
| 683 | 683 | $staticErrors[] = [ |
| 684 | - 'error' => (string)$error['error'], |
|
| 685 | - 'hint' => (string)$error['hint'], |
|
| 684 | + 'error' => (string) $error['error'], |
|
| 685 | + 'hint' => (string) $error['hint'], |
|
| 686 | 686 | ]; |
| 687 | 687 | } |
| 688 | 688 | |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | } |
| 705 | 705 | //try to set the session lifetime |
| 706 | 706 | $sessionLifeTime = self::getSessionLifeTime(); |
| 707 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
| 707 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
| 708 | 708 | |
| 709 | 709 | $systemConfig = \OC::$server->getSystemConfig(); |
| 710 | 710 | |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
| 751 | 751 | |
| 752 | 752 | // Check whether the sample configuration has been copied |
| 753 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
| 753 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
| 754 | 754 | $l = \OC::$server->getL10N('lib'); |
| 755 | 755 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
| 756 | 756 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | ) { |
| 777 | 777 | // Allow access to CSS resources |
| 778 | 778 | $isScssRequest = false; |
| 779 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 779 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
| 780 | 780 | $isScssRequest = true; |
| 781 | 781 | } |
| 782 | 782 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | |
| 813 | 813 | // NOTE: This will be replaced to use OCP |
| 814 | 814 | $userSession = self::$server->getUserSession(); |
| 815 | - $userSession->listen('\OC\User', 'postLogin', function () use ($userSession) { |
|
| 815 | + $userSession->listen('\OC\User', 'postLogin', function() use ($userSession) { |
|
| 816 | 816 | if (!defined('PHPUNIT_RUN')) { |
| 817 | 817 | // reset brute force delay for this IP address and username |
| 818 | 818 | $uid = \OC::$server->getUserSession()->getUser()->getUID(); |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | } catch (\Exception $e) { |
| 833 | 833 | // a GC exception should not prevent users from using OC, |
| 834 | 834 | // so log the exception |
| 835 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
| 835 | + \OC::$server->getLogger()->warning('Exception when running cache gc: '.$e->getMessage(), array('app' => 'core')); |
|
| 836 | 836 | } |
| 837 | 837 | }); |
| 838 | 838 | } |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | /** @var \OCP\App\ManagerEvent $event */ |
| 849 | 849 | $jobList = \OC::$server->getJobList(); |
| 850 | 850 | $job = 'OC\\Settings\\RemoveOrphaned'; |
| 851 | - if(!($jobList->has($job, null))) { |
|
| 851 | + if (!($jobList->has($job, null))) { |
|
| 852 | 852 | $jobList->add($job); |
| 853 | 853 | } |
| 854 | 854 | }); |
@@ -952,12 +952,12 @@ discard block |
||
| 952 | 952 | // emergency app disabling |
| 953 | 953 | if ($requestPath === '/disableapp' |
| 954 | 954 | && $request->getMethod() === 'POST' |
| 955 | - && ((array)$request->getParam('appid')) !== '' |
|
| 955 | + && ((array) $request->getParam('appid')) !== '' |
|
| 956 | 956 | ) { |
| 957 | 957 | \OCP\JSON::callCheck(); |
| 958 | 958 | \OCP\JSON::checkAdminUser(); |
| 959 | - $appIds = (array)$request->getParam('appid'); |
|
| 960 | - foreach($appIds as $appId) { |
|
| 959 | + $appIds = (array) $request->getParam('appid'); |
|
| 960 | + foreach ($appIds as $appId) { |
|
| 961 | 961 | $appId = \OC_App::cleanAppId($appId); |
| 962 | 962 | \OC_App::disable($appId); |
| 963 | 963 | } |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | if (!self::checkUpgrade(false) |
| 973 | 973 | && !$systemConfig->getValue('maintenance', false)) { |
| 974 | 974 | // For logged-in users: Load everything |
| 975 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 975 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 976 | 976 | OC_App::loadApps(); |
| 977 | 977 | } else { |
| 978 | 978 | // For guests: Load only filesystem and logging |
@@ -31,68 +31,68 @@ |
||
| 31 | 31 | // Show warning if a PHP version below 7.0 is used, this has to happen here |
| 32 | 32 | // because base.php will already use 7.0 syntax. |
| 33 | 33 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 34 | - echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
|
| 35 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 36 | - return; |
|
| 34 | + echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
|
| 35 | + echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 36 | + return; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | try { |
| 40 | 40 | |
| 41 | - require_once __DIR__ . '/lib/base.php'; |
|
| 41 | + require_once __DIR__ . '/lib/base.php'; |
|
| 42 | 42 | |
| 43 | - OC::handleRequest(); |
|
| 43 | + OC::handleRequest(); |
|
| 44 | 44 | |
| 45 | 45 | } catch(\OC\ServiceUnavailableException $ex) { |
| 46 | - \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 46 | + \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 47 | 47 | |
| 48 | - //show the user a detailed error page |
|
| 49 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 50 | - OC_Template::printExceptionErrorPage($ex); |
|
| 48 | + //show the user a detailed error page |
|
| 49 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 50 | + OC_Template::printExceptionErrorPage($ex); |
|
| 51 | 51 | } catch (\OC\HintException $ex) { |
| 52 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 53 | - try { |
|
| 54 | - OC_Template::printErrorPage($ex->getMessage(), $ex->getHint()); |
|
| 55 | - } catch (Exception $ex2) { |
|
| 56 | - \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 57 | - \OC::$server->getLogger()->logException($ex2, array('app' => 'index')); |
|
| 52 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
| 53 | + try { |
|
| 54 | + OC_Template::printErrorPage($ex->getMessage(), $ex->getHint()); |
|
| 55 | + } catch (Exception $ex2) { |
|
| 56 | + \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 57 | + \OC::$server->getLogger()->logException($ex2, array('app' => 'index')); |
|
| 58 | 58 | |
| 59 | - //show the user a detailed error page |
|
| 60 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 61 | - OC_Template::printExceptionErrorPage($ex); |
|
| 62 | - } |
|
| 59 | + //show the user a detailed error page |
|
| 60 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 61 | + OC_Template::printExceptionErrorPage($ex); |
|
| 62 | + } |
|
| 63 | 63 | } catch (\OC\User\LoginException $ex) { |
| 64 | - OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN); |
|
| 65 | - OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage()); |
|
| 64 | + OC_Response::setStatus(OC_Response::STATUS_FORBIDDEN); |
|
| 65 | + OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage()); |
|
| 66 | 66 | } catch (Exception $ex) { |
| 67 | - \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 67 | + \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 68 | 68 | |
| 69 | - //show the user a detailed error page |
|
| 70 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 71 | - OC_Template::printExceptionErrorPage($ex); |
|
| 69 | + //show the user a detailed error page |
|
| 70 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 71 | + OC_Template::printExceptionErrorPage($ex); |
|
| 72 | 72 | } catch (Error $ex) { |
| 73 | - try { |
|
| 74 | - \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 75 | - } catch (Error $e) { |
|
| 73 | + try { |
|
| 74 | + \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
|
| 75 | + } catch (Error $e) { |
|
| 76 | 76 | |
| 77 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 78 | - $validProtocols = [ |
|
| 79 | - 'HTTP/1.0', |
|
| 80 | - 'HTTP/1.1', |
|
| 81 | - 'HTTP/2', |
|
| 82 | - ]; |
|
| 83 | - $protocol = 'HTTP/1.1'; |
|
| 84 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 85 | - $protocol = $claimedProtocol; |
|
| 86 | - } |
|
| 87 | - header($protocol . ' 500 Internal Server Error'); |
|
| 88 | - header('Content-Type: text/plain; charset=utf-8'); |
|
| 89 | - print("Internal Server Error\n\n"); |
|
| 90 | - print("The server encountered an internal error and was unable to complete your request.\n"); |
|
| 91 | - print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
| 92 | - print("More details can be found in the webserver log.\n"); |
|
| 77 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
| 78 | + $validProtocols = [ |
|
| 79 | + 'HTTP/1.0', |
|
| 80 | + 'HTTP/1.1', |
|
| 81 | + 'HTTP/2', |
|
| 82 | + ]; |
|
| 83 | + $protocol = 'HTTP/1.1'; |
|
| 84 | + if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 85 | + $protocol = $claimedProtocol; |
|
| 86 | + } |
|
| 87 | + header($protocol . ' 500 Internal Server Error'); |
|
| 88 | + header('Content-Type: text/plain; charset=utf-8'); |
|
| 89 | + print("Internal Server Error\n\n"); |
|
| 90 | + print("The server encountered an internal error and was unable to complete your request.\n"); |
|
| 91 | + print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
| 92 | + print("More details can be found in the webserver log.\n"); |
|
| 93 | 93 | |
| 94 | - throw $e; |
|
| 95 | - } |
|
| 96 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 97 | - OC_Template::printExceptionErrorPage($ex); |
|
| 94 | + throw $e; |
|
| 95 | + } |
|
| 96 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
| 97 | + OC_Template::printExceptionErrorPage($ex); |
|
| 98 | 98 | } |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | // because base.php will already use 7.0 syntax. |
| 33 | 33 | if (version_compare(PHP_VERSION, '7.0') === -1) { |
| 34 | 34 | echo 'This version of Nextcloud requires at least PHP 7.0<br/>'; |
| 35 | - echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'; |
|
| 35 | + echo 'You are currently running '.PHP_VERSION.'. Please update your PHP version.'; |
|
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | try { |
| 40 | 40 | |
| 41 | - require_once __DIR__ . '/lib/base.php'; |
|
| 41 | + require_once __DIR__.'/lib/base.php'; |
|
| 42 | 42 | |
| 43 | 43 | OC::handleRequest(); |
| 44 | 44 | |
| 45 | -} catch(\OC\ServiceUnavailableException $ex) { |
|
| 45 | +} catch (\OC\ServiceUnavailableException $ex) { |
|
| 46 | 46 | \OC::$server->getLogger()->logException($ex, array('app' => 'index')); |
| 47 | 47 | |
| 48 | 48 | //show the user a detailed error page |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | 'HTTP/2', |
| 82 | 82 | ]; |
| 83 | 83 | $protocol = 'HTTP/1.1'; |
| 84 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
| 84 | + if (in_array($claimedProtocol, $validProtocols, true)) { |
|
| 85 | 85 | $protocol = $claimedProtocol; |
| 86 | 86 | } |
| 87 | - header($protocol . ' 500 Internal Server Error'); |
|
| 87 | + header($protocol.' 500 Internal Server Error'); |
|
| 88 | 88 | header('Content-Type: text/plain; charset=utf-8'); |
| 89 | 89 | print("Internal Server Error\n\n"); |
| 90 | 90 | print("The server encountered an internal error and was unable to complete your request.\n"); |