2010-03-10 13:03:40 +01:00
|
|
|
<?php
|
2024-02-08 15:10:31 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-03-10 13:03:40 +01:00
|
|
|
/**
|
2024-05-24 19:43:47 +02: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 11:44:34 +01:00
|
|
|
*/
|
2024-02-08 15:10:31 +01:00
|
|
|
|
2017-10-13 21:30:29 +02:00
|
|
|
require_once __DIR__ . '/lib/versioncheck.php';
|
2023-11-30 12:52:35 +01:00
|
|
|
|
2024-02-08 15:10:31 +01:00
|
|
|
use OC\ServiceUnavailableException;
|
|
|
|
use OC\User\LoginException;
|
|
|
|
use OCP\HintException;
|
|
|
|
use OCP\IRequest;
|
2023-11-30 12:52:35 +01:00
|
|
|
use OCP\Security\Bruteforce\MaxDelayReached;
|
2024-02-08 15:10:31 +01:00
|
|
|
use OCP\Server;
|
2025-02-25 18:44:02 +01:00
|
|
|
use OCP\Template\ITemplateManager;
|
2023-03-28 21:20:08 +01: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();
|
2024-02-08 15:10:31 +01:00
|
|
|
} catch (ServiceUnavailableException $ex) {
|
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 21:20:08 +01:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2014-07-24 17:18:10 +02:00
|
|
|
|
|
|
|
//show the user a detailed error page
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printExceptionErrorPage($ex, 503);
|
2024-02-08 15:10:31 +01:00
|
|
|
} catch (HintException $ex) {
|
2017-09-26 11:21:39 +02:00
|
|
|
try {
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->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 {
|
2024-02-08 15:10:31 +01:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 21:20:08 +01:00
|
|
|
'app' => 'index',
|
|
|
|
'exception' => $ex,
|
|
|
|
]);
|
2024-02-08 15:10:31 +01:00
|
|
|
Server::get(LoggerInterface::class)->error($ex2->getMessage(), [
|
2023-03-28 21:20:08 +01:00
|
|
|
'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
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printExceptionErrorPage($ex, 500);
|
2017-09-26 11:21:39 +02:00
|
|
|
}
|
2024-02-08 15:10:31 +01:00
|
|
|
} catch (LoginException $ex) {
|
|
|
|
$request = Server::get(IRequest::class);
|
2021-04-30 23:09:29 +02: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 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();
|
|
|
|
}
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printErrorPage($ex->getMessage(), $ex->getMessage(), 401);
|
2023-11-30 12:52:35 +01:00
|
|
|
} catch (MaxDelayReached $ex) {
|
2024-02-08 15:10:31 +01:00
|
|
|
$request = Server::get(IRequest::class);
|
2023-11-30 12:52:35 +01: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 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printGuestPage('core', '429');
|
2013-06-10 13:45:19 +02:00
|
|
|
} catch (Exception $ex) {
|
2024-02-08 15:10:31 +01:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 21:20:08 +01:00
|
|
|
'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
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printExceptionErrorPage($ex, 500);
|
2016-04-20 18:01:47 +02:00
|
|
|
} catch (Error $ex) {
|
2017-11-06 09:36:19 +01:00
|
|
|
try {
|
2024-02-08 15:10:31 +01:00
|
|
|
Server::get(LoggerInterface::class)->error($ex->getMessage(), [
|
2023-03-28 21:20:08 +01:00
|
|
|
'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
|
|
|
}
|
2025-02-25 18:44:02 +01:00
|
|
|
Server::get(ITemplateManager::class)->printExceptionErrorPage($ex, 500);
|
2013-06-25 17:45:42 +03:00
|
|
|
}
|