. * */ // Unfortunately we need this class for shutdown function class TemporaryCronClass { public static $sent = false; public static $lockfile = ""; public static $keeplock = false; } // We use this function to handle (unexpected) shutdowns function handleUnexpectedShutdown() { // Delete lockfile if (!TemporaryCronClass::$keeplock && file_exists(TemporaryCronClass::$lockfile)) { unlink(TemporaryCronClass::$lockfile); } // Say goodbye if the app did not shutdown properly if (!TemporaryCronClass::$sent) { if (OC::$CLI) { echo 'Unexpected error!' . PHP_EOL; } else { OC_JSON::error(array('data' => array('message' => 'Unexpected error!'))); } } } require_once 'lib/base.php'; session_write_close(); // Don't do anything if ownCloud has not been installed if (!OC_Config::getValue('installed', false)) { exit(0); } // Handle unexpected errors register_shutdown_function('handleUnexpectedShutdown'); // Delete temp folder OC_Helper::cleanTmpNoClean(); // Exit if background jobs are disabled! $appmode = OC_BackgroundJob::getExecutionType(); if ($appmode == 'none') { TemporaryCronClass::$sent = true; if (OC::$CLI) { echo 'Background Jobs are disabled!' . PHP_EOL; } else { OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!'))); } exit(1); } if (OC::$CLI) { // Create lock file first TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock'; // We call ownCloud from the CLI (aka cron) if ($appmode != 'cron') { // Use cron in feature! OC_BackgroundJob::setExecutionType('cron'); } // check if backgroundjobs is still running if (file_exists(TemporaryCronClass::$lockfile)) { TemporaryCronClass::$keeplock = true; TemporaryCronClass::$sent = true; echo "Another instance of cron.php is still running!"; exit(1); } // Create a lock file touch(TemporaryCronClass::$lockfile); // Work $jobList = new \OC\BackgroundJob\JobList(); $jobs = $jobList->getAll(); foreach ($jobs as $job) { $job->execute($jobList); } } else { // We call cron.php from some website if ($appmode == 'cron') { // Cron is cron :-P OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!'))); } else { // Work and success :-) $jobList = new \OC\BackgroundJob\JobList(); $job = $jobList->getNext(); $job->execute($jobList); $jobList->setLastJob($job); OC_JSON::success(); } } // done! TemporaryCronClass::$sent = true; exit(); nge/chore/update_nc_cypress_beta.11'>artonge/chore/update_nc_cypress_beta.11 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/index.php
blob: 1b3a8c04bdebff441871da98bbe7096f39e45264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
 * @copyright Copyright (c) 2016, ownCloud, Inc.
 *
 * @author Georg Ehrke <oc.list@georgehrke.com>
 * @author Joas Schilling <coding@schilljs.com>
 * @author Jörn Friedrich Dreyer <jfd@butonic.de>
 * @author Lukas Reschke <lukas@statuscode.ch>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Robin Appelman <robin@icewind.nl>
 * @author Roeland Jago Douma <roeland@famdouma.nl>
 * @author Sergio Bertolín <sbertolin@solidgear.es>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 * @author Vincent Petry <pvince81@owncloud.com>
 *
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 *
 */

require_once __DIR__ . '/lib/versioncheck.php';

try {

	require_once __DIR__ . '/lib/base.php';

	OC::handleRequest();

} catch(\OC\ServiceUnavailableException $ex) {
	\OC::$server->getLogger()->logException($ex, array('app' => 'index'));

	//show the user a detailed error page
	OC_Template::printExceptionErrorPage($ex, 503);
} catch (\OC\HintException $ex) {
	try {
		OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
	} catch (Exception $ex2) {
		try {
			\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
			\OC::$server->getLogger()->logException($ex2, array('app' => 'index'));
		} catch (Throwable $e) {
			// no way to log it properly - but to avoid a white page of death we try harder and ignore this one here
		}

		//show the user a detailed error page
		OC_Template::printExceptionErrorPage($ex, 500);
	}
} catch (\OC\User\LoginException $ex) {
	OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 403);
} catch (Exception $ex) {
	\OC::$server->getLogger()->logException($ex, array('app' => 'index'));

	//show the user a detailed error page
	OC_Template::printExceptionErrorPage($ex, 500);
} catch (Error $ex) {
	try {
		\OC::$server->getLogger()->logException($ex, array('app' => 'index'));
	} catch (Error $e) {
		http_response_code(500);
		header('Content-Type: text/plain; charset=utf-8');
		print("Internal Server Error\n\n");
		print("The server encountered an internal error and was unable to complete your request.\n");
		print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
		print("More details can be found in the webserver log.\n");

		throw $ex;
	}
	OC_Template::printExceptionErrorPage($ex, 500);
}