2010-03-10 13:03:40 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:07:57 +02:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-03-31 10:49:10 +02:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 15:56:42 +01:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 11:44:34 +01:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 19:56:05 +02:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 11:44:34 +01:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 18:13:36 +02:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2019-12-03 19:57:53 +01:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 15:56:42 +01:00
|
|
|
* @author Sergio Bertolín <sbertolin@solidgear.es>
|
2015-03-26 11:44:34 +01:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2020-12-16 14:54:15 +01:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2015-03-26 11:44:34 +01:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 19:57:53 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 11:44:34 +01:00
|
|
|
*
|
|
|
|
*/
|
2017-10-13 21:30:29 +02:00
|
|
|
require_once __DIR__ . '/lib/versioncheck.php';
|
2023-11-30 12:52:35 +01:00
|
|
|
|
|
|
|
use OCP\Security\Bruteforce\MaxDelayReached;
|
2023-03-28 22:20:08 +02:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-02-05 11:41:00 +01:00
|
|
|
|
2013-06-10 13:45:19 +02:00
|
|
|
try {
|
2016-10-06 12:13:02 +02:00
|
|
|
require_once __DIR__ . '/lib/base.php';
|
2011-04-16 15:47:27 +02:00
|
|
|
|
2013-06-10 13:45:19 +02:00
|
|
|
OC::handleRequest();
|
2020-04-10 14:19:56 +02:00
|
|
|
} catch (\OC\ServiceUnavailableException $ex) {
|
2023-03-28 22:20:08 +02:00
|
|
|
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
|
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2014-07-24 17:18:10 +02:00
|
|
|
|
|
|
|
//show the user a detailed error page
|
2018-06-26 12:15:09 +02:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 503);
|
2021-06-30 01:20:33 +02:00
|
|
|
} catch (\OCP\HintException $ex) {
|
2017-09-26 11:21:39 +02:00
|
|
|
try {
|
2018-06-26 12:15:09 +02:00
|
|
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
|
2017-09-26 11:21:39 +02:00
|
|
|
} catch (Exception $ex2) {
|
2018-06-29 11:22:05 +02:00
|
|
|
try {
|
2023-03-28 22:20:08 +02:00
|
|
|
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
|
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
|
|
|
\OC::$server->get(LoggerInterface::class)->error($ex2->getMessage(), [
|
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex2,
|
|
|
|
]);
|
2018-06-29 11:22:05 +02:00
|
|
|
} 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
|
|
|
|
}
|
2017-09-26 11:21:39 +02:00
|
|
|
|
|
|
|
//show the user a detailed error page
|
2018-06-26 10:32:50 +02:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2017-09-26 11:21:39 +02:00
|
|
|
}
|
2016-10-04 14:51:54 +02:00
|
|
|
} catch (\OC\User\LoginException $ex) {
|
2021-04-30 23:09:29 +02:00
|
|
|
$request = \OC::$server->getRequest();
|
|
|
|
/**
|
|
|
|
* Routes with the @CORS annotation and other API endpoints should
|
|
|
|
* not return a webpage, so we only print the error page when html is accepted,
|
|
|
|
* otherwise we reply with a JSON array like the SecurityMiddleware would do.
|
|
|
|
*/
|
2022-01-12 20:44:38 +01:00
|
|
|
if (stripos($request->getHeader('Accept'), 'html') === false) {
|
2021-04-30 23:09:29 +02:00
|
|
|
http_response_code(401);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
echo json_encode(['message' => $ex->getMessage()]);
|
|
|
|
exit();
|
|
|
|
}
|
2021-04-30 23:08:57 +02:00
|
|
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
|
2023-11-30 12:52:35 +01:00
|
|
|
} catch (MaxDelayReached $ex) {
|
|
|
|
$request = \OC::$server->getRequest();
|
|
|
|
/**
|
|
|
|
* Routes with the @CORS annotation and other API endpoints should
|
|
|
|
* not return a webpage, so we only print the error page when html is accepted,
|
|
|
|
* otherwise we reply with a JSON array like the BruteForceMiddleware would do.
|
|
|
|
*/
|
|
|
|
if (stripos($request->getHeader('Accept'), 'html') === false) {
|
|
|
|
http_response_code(429);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
echo json_encode(['message' => $ex->getMessage()]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
http_response_code(429);
|
|
|
|
OC_Template::printGuestPage('core', '429');
|
2013-06-10 13:45:19 +02:00
|
|
|
} catch (Exception $ex) {
|
2023-03-28 22:20:08 +02:00
|
|
|
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
|
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2013-10-22 19:16:34 +02:00
|
|
|
|
2013-06-10 13:45:19 +02:00
|
|
|
//show the user a detailed error page
|
2018-06-26 10:32:50 +02:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2016-04-20 18:01:47 +02:00
|
|
|
} catch (Error $ex) {
|
2017-11-06 09:36:19 +01:00
|
|
|
try {
|
2023-03-28 22:20:08 +02:00
|
|
|
\OC::$server->get(LoggerInterface::class)->error($ex->getMessage(), [
|
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2017-11-06 09:36:19 +01:00
|
|
|
} catch (Error $e) {
|
2018-06-26 10:32:50 +02:00
|
|
|
http_response_code(500);
|
2017-11-06 09:36:19 +01:00
|
|
|
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");
|
|
|
|
|
2018-11-01 22:27:54 +01:00
|
|
|
throw $ex;
|
2017-11-06 09:36:19 +01:00
|
|
|
}
|
2018-06-26 12:15:09 +02:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2013-06-25 16:45:42 +02:00
|
|
|
}
|