From 2cee6ab2f844690ffdaaa9e5c79c33841468c032 Mon Sep 17 00:00:00 2001 From: Eric Masseran Date: Sat, 28 Oct 2017 00:54:25 +0200 Subject: [PATCH 1/4] Change status code when config is write protected The http status code is now 500 Internal Server Error when config file can't be written. #6893 Signed-off-by: Eric Masseran --- lib/base.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/base.php b/lib/base.php index dc09d0f533d4d..d54f445c84dea 100644 --- a/lib/base.php +++ b/lib/base.php @@ -247,12 +247,16 @@ public static function checkConfig() { echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; exit; } else { + + header('HTTP/1.1 500 Internal Server Error'); + header('Status: 500 Internal Server Error'); OC_Template::printErrorPage( $l->t('Cannot write into "config" directory!'), $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) ); } + } } From b2431779d959989d858ddedd3dd27ce395644dcd Mon Sep 17 00:00:00 2001 From: Eric Masseran Date: Fri, 17 Nov 2017 11:34:37 +0100 Subject: [PATCH 2/4] Add hint msg, you can make config file read only If the config.php is not writable, print an error message: #6893 - with HTTP status 500 - Set config writable - Or set option to keep it read only Signed-off-by: Eric Masseran --- lib/base.php | 8 ++++++-- lib/private/legacy/util.php | 6 ++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/base.php b/lib/base.php index d54f445c84dea..5c9944183cd96 100644 --- a/lib/base.php +++ b/lib/base.php @@ -243,8 +243,10 @@ public static function checkConfig() { if (self::$CLI) { echo $l->t('Cannot write into "config" directory!')."\n"; echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; - echo "\n"; echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; + echo "\n"; + echo $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.')."\n"; + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; exit; } else { @@ -253,7 +255,9 @@ public static function checkConfig() { OC_Template::printErrorPage( $l->t('Cannot write into "config" directory!'), $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) + [ $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') ] ) ); } diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 2610ec3a7b6c0..e94c3a1c27844 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -728,8 +728,10 @@ public static function checkServer(\OC\SystemConfig $config) { $errors[] = array( 'error' => $l->t('Cannot write into "config" directory'), 'hint' => $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', - [$urlGenerator->linkToDocs('admin-dir_permissions')]) - ); + [ $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') ] ) + ); } } From fae80ce1ed317f84d3901f4559516248ab3172cb Mon Sep 17 00:00:00 2001 From: Eric Masseran Date: Mon, 20 Nov 2017 15:05:57 +0100 Subject: [PATCH 3/4] Correct indentation Signed-off-by: Eric Masseran --- lib/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/base.php b/lib/base.php index 5c9944183cd96..44cbc4f65c6c6 100644 --- a/lib/base.php +++ b/lib/base.php @@ -255,9 +255,9 @@ public static function checkConfig() { OC_Template::printErrorPage( $l->t('Cannot write into "config" directory!'), $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-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') ] ) ); } From 3fa843abcf3ba07c80318868638d73831cb33361 Mon Sep 17 00:00:00 2001 From: Eric Masseran Date: Wed, 29 Nov 2017 19:59:07 +0100 Subject: [PATCH 4/4] Use http_response_code instead of header Signed-off-by: Eric Masseran --- lib/base.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/base.php b/lib/base.php index 44cbc4f65c6c6..f92f2e135d2a4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -237,7 +237,6 @@ public static function checkConfig() { $configFileWritable = is_writable($configFilePath); if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() || !$configFileWritable && self::checkUpgrade(false)) { - $urlGenerator = \OC::$server->getURLGenerator(); if (self::$CLI) { @@ -249,9 +248,7 @@ public static function checkConfig() { echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-config') ])."\n"; exit; } else { - - header('HTTP/1.1 500 Internal Server Error'); - header('Status: 500 Internal Server Error'); + http_response_code(500); OC_Template::printErrorPage( $l->t('Cannot write into "config" directory!'), $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s',