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