2010-03-10 12:03:40 +00:00
|
|
|
<?php
|
2024-02-08 14:10:31 +00:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-03-10 12:03:40 +00:00
|
|
|
/**
|
2024-05-24 17:43:47 +00:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-03-26 10:44:34 +00:00
|
|
|
*/
|
2024-02-08 14:10:31 +00:00
|
|
|
|
2017-10-13 19:30:29 +00:00
|
|
|
require_once __DIR__ . '/lib/versioncheck.php';
|
2023-11-30 11:52:35 +00:00
|
|
|
|
2024-02-08 14:10:31 +00:00
|
|
|
use OC\ServiceUnavailableException;
|
|
|
|
use OC\User\LoginException;
|
|
|
|
use OCP\HintException;
|
|
|
|
use OCP\IRequest;
|
2023-11-30 11:52:35 +00:00
|
|
|
use OCP\Security\Bruteforce\MaxDelayReached;
|
2024-02-08 14:10:31 +00:00
|
|
|
use OCP\Server;
|
2023-03-28 20:20:08 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-02-05 10:41:00 +00:00
|
|
|
|
2013-06-10 11:45:19 +00:00
|
|
|
try {
|
2016-10-06 10:13:02 +00:00
|
|
|
require_once __DIR__ . '/lib/base.php';
|
2011-04-16 13:47:27 +00:00
|
|
|
|
2013-06-10 11:45:19 +00:00
|
|
|
OC::handleRequest();
|
2024-02-08 14:10:31 +00:00
|
|
|
} catch (ServiceUnavailableException $ex) {
|
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 20:20:08 +00:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2014-07-24 15:18:10 +00:00
|
|
|
|
|
|
|
//show the user a detailed error page
|
2018-06-26 10:15:09 +00:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 503);
|
2024-02-08 14:10:31 +00:00
|
|
|
} catch (HintException $ex) {
|
2017-09-26 09:21:39 +00:00
|
|
|
try {
|
2018-06-26 10:15:09 +00:00
|
|
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getHint(), 503);
|
2017-09-26 09:21:39 +00:00
|
|
|
} catch (Exception $ex2) {
|
2018-06-29 09:22:05 +00:00
|
|
|
try {
|
2024-02-08 14:10:31 +00:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 20:20:08 +00:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2024-02-08 14:10:31 +00:00
|
|
|
Server::get(LoggerInterface::class)->error($ex2->getMessage(), [
|
2023-03-28 20:20:08 +00:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex2,
|
|
|
|
]);
|
2018-06-29 09:22:05 +00: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 09:21:39 +00:00
|
|
|
|
|
|
|
//show the user a detailed error page
|
2018-06-26 08:32:50 +00:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2017-09-26 09:21:39 +00:00
|
|
|
}
|
2024-02-08 14:10:31 +00:00
|
|
|
} catch (LoginException $ex) {
|
|
|
|
$request = Server::get(IRequest::class);
|
2021-04-30 21:09:29 +00:00
|
|
|
/**
|
|
|
|
* 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 19:44:38 +00:00
|
|
|
if (stripos($request->getHeader('Accept'), 'html') === false) {
|
2021-04-30 21:09:29 +00:00
|
|
|
http_response_code(401);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
echo json_encode(['message' => $ex->getMessage()]);
|
|
|
|
exit();
|
|
|
|
}
|
2021-04-30 21:08:57 +00:00
|
|
|
OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
|
2023-11-30 11:52:35 +00:00
|
|
|
} catch (MaxDelayReached $ex) {
|
2024-02-08 14:10:31 +00:00
|
|
|
$request = Server::get(IRequest::class);
|
2023-11-30 11:52:35 +00:00
|
|
|
/**
|
|
|
|
* 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 11:45:19 +00:00
|
|
|
} catch (Exception $ex) {
|
2024-02-08 14:10:31 +00:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 20:20:08 +00:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2013-10-22 17:16:34 +00:00
|
|
|
|
2013-06-10 11:45:19 +00:00
|
|
|
//show the user a detailed error page
|
2018-06-26 08:32:50 +00:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2016-04-20 16:01:47 +00:00
|
|
|
} catch (Error $ex) {
|
2017-11-06 08:36:19 +00:00
|
|
|
try {
|
2024-02-08 14:10:31 +00:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 20:20:08 +00:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2017-11-06 08:36:19 +00:00
|
|
|
} catch (Error $e) {
|
2018-06-26 08:32:50 +00:00
|
|
|
http_response_code(500);
|
2017-11-06 08:36:19 +00: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 21:27:54 +00:00
|
|
|
throw $ex;
|
2017-11-06 08:36:19 +00:00
|
|
|
}
|
2018-06-26 10:15:09 +00:00
|
|
|
OC_Template::printExceptionErrorPage($ex, 500);
|
2013-06-25 14:45:42 +00:00
|
|
|
}
|