diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 10:17:37 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 12:44:24 +0300 |
commit | 8c155cd51cb55c89f16d9bcfcb397d4e784ac108 (patch) | |
tree | 52aa69f7db242bb0382e374490526af13a2af9d2 /lib | |
parent | a97cc293b5f04ee1d25a5e41103586f16ff02927 (diff) |
Server error/hint pages with a 500 error code to avoid it being seen instead of the actual resource
* found while reviewing #7205
* allow to specify a special status code
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 8 | ||||
-rw-r--r-- | lib/private/legacy/files.php | 6 | ||||
-rw-r--r-- | lib/private/legacy/template.php | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/lib/base.php b/lib/base.php index c859972d39b..54cbc700ec3 100644 --- a/lib/base.php +++ b/lib/base.php @@ -260,7 +260,8 @@ class OC { $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', - [ $urlGenerator->linkToDocs('admin-config') ] ) + [ $urlGenerator->linkToDocs('admin-config') ] ), + \OC_Response::STATUS_SERVICE_UNAVAILABLE ); } } @@ -750,11 +751,10 @@ class OC { // Check whether the sample configuration has been copied if($systemConfig->getValue('copied_sample_config', false)) { $l = \OC::$server->getL10N('lib'); - header('HTTP/1.1 503 Service Temporarily Unavailable'); - header('Status: 503 Service Temporarily Unavailable'); OC_Template::printErrorPage( $l->t('Sample configuration detected'), - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php'), + \OC_Response::STATUS_SERVICE_UNAVAILABLE ); return; } diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index 00cd5fbfe51..f4474197d86 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -198,18 +198,18 @@ class OC_Files { OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; - \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint); + \OC_Template::printErrorPage($l->t('File is currently busy, please try again later'), $hint, 200); } catch (\OCP\Files\ForbiddenException $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); - \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage()); + \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage(), 200); } catch (\Exception $ex) { self::unlockAllTheFiles($dir, $files, $getType, $view, $filename); OC::$server->getLogger()->logException($ex); $l = \OC::$server->getL10N('core'); $hint = method_exists($ex, 'getHint') ? $ex->getHint() : ''; - \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint); + \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint, 200); } } diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php index 3cca8245af0..4e89b18c144 100644 --- a/lib/private/legacy/template.php +++ b/lib/private/legacy/template.php @@ -306,7 +306,7 @@ class OC_Template extends \OC\Template\Base { * @param string $hint An optional hint message - needs to be properly escape * @suppress PhanAccessMethodInternal */ - public static function printErrorPage( $error_msg, $hint = '' ) { + public static function printErrorPage( $error_msg, $hint = '', $statusCode = \OC_Response::STATUS_INTERNAL_SERVER_ERROR ) { if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) { \OC_App::loadApp('theming'); } @@ -317,6 +317,7 @@ class OC_Template extends \OC\Template\Base { $hint = ''; } + http_response_code($statusCode); try { $content = new \OC_Template( '', 'error', 'error', false ); $errors = array(array('error' => $error_msg, 'hint' => $hint)); @@ -327,7 +328,6 @@ class OC_Template extends \OC\Template\Base { $logger->error("$error_msg $hint", ['app' => 'core']); $logger->logException($e, ['app' => 'core']); - header(self::getHttpProtocol() . ' 500 Internal Server Error'); header('Content-Type: text/plain; charset=utf-8'); print("$error_msg $hint"); } |