|
|
|
@ -304,9 +304,10 @@ class OC_Template extends \OC\Template\Base { |
|
|
|
|
* Print a fatal error page and terminates the script |
|
|
|
|
* @param string $error_msg The error message to show |
|
|
|
|
* @param string $hint An optional hint message - needs to be properly escape |
|
|
|
|
* @param int $statusCode |
|
|
|
|
* @suppress PhanAccessMethodInternal |
|
|
|
|
*/ |
|
|
|
|
public static function printErrorPage( $error_msg, $hint = '', $statusCode = \OC_Response::STATUS_INTERNAL_SERVER_ERROR ) { |
|
|
|
|
public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) { |
|
|
|
|
if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) { |
|
|
|
|
\OC_App::loadApp('theming'); |
|
|
|
|
} |
|
|
|
@ -337,11 +338,12 @@ class OC_Template extends \OC\Template\Base { |
|
|
|
|
/** |
|
|
|
|
* print error page using Exception details |
|
|
|
|
* @param Exception|Throwable $exception |
|
|
|
|
* @param bool $fetchPage |
|
|
|
|
* @param int $statusCode |
|
|
|
|
* @return bool|string |
|
|
|
|
* @suppress PhanAccessMethodInternal |
|
|
|
|
*/ |
|
|
|
|
public static function printExceptionErrorPage($exception, $fetchPage = false) { |
|
|
|
|
public static function printExceptionErrorPage($exception, $statusCode = 503) { |
|
|
|
|
http_response_code($statusCode); |
|
|
|
|
try { |
|
|
|
|
$request = \OC::$server->getRequest(); |
|
|
|
|
$content = new \OC_Template('', 'exception', 'error', false); |
|
|
|
@ -354,16 +356,12 @@ class OC_Template extends \OC\Template\Base { |
|
|
|
|
$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); |
|
|
|
|
$content->assign('remoteAddr', $request->getRemoteAddress()); |
|
|
|
|
$content->assign('requestID', $request->getId()); |
|
|
|
|
if ($fetchPage) { |
|
|
|
|
return $content->fetchPage(); |
|
|
|
|
} |
|
|
|
|
$content->printPage(); |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
$logger = \OC::$server->getLogger(); |
|
|
|
|
$logger->logException($exception, ['app' => 'core']); |
|
|
|
|
$logger->logException($e, ['app' => 'core']); |
|
|
|
|
|
|
|
|
|
header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
|
|
|
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"); |
|
|
|
@ -372,26 +370,4 @@ class OC_Template extends \OC\Template\Base { |
|
|
|
|
} |
|
|
|
|
die(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This is only here to reduce the dependencies in case of an exception to |
|
|
|
|
* still be able to print a plain error message. |
|
|
|
|
* |
|
|
|
|
* Returns the used HTTP protocol. |
|
|
|
|
* |
|
|
|
|
* @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. |
|
|
|
|
* @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead |
|
|
|
|
*/ |
|
|
|
|
protected static function getHttpProtocol() { |
|
|
|
|
$claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
|
|
|
$validProtocols = [ |
|
|
|
|
'HTTP/1.0', |
|
|
|
|
'HTTP/1.1', |
|
|
|
|
'HTTP/2', |
|
|
|
|
]; |
|
|
|
|
if(in_array($claimedProtocol, $validProtocols, true)) { |
|
|
|
|
return $claimedProtocol; |
|
|
|
|
} |
|
|
|
|
return 'HTTP/1.1'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|