From 70a781fa5a654dce4314182bae59377f1d52ae56 Mon Sep 17 00:00:00 2001 From: Andreas Neustifter Date: Fri, 27 Apr 2018 21:27:55 +0200 Subject: [PATCH 1/3] Proper error when rewrite fails during install. When Curl tries to fetch the rewrite test URL and something goes wrong the user has no clue what was the problem. This problems can include: - The rewriting not working at all. - HTTPS redirects do not work. - Curl does not accept the presented SSL cert. This commit fixes this by providing the Curl error message to the user to further debug the problem. Fixes #3629.~ --- mod/install.php | 19 +++++++++++++------ src/Util/Network.php | 10 +++++++--- view/install/style.css | 3 +++ view/templates/install_checks.tpl | 8 +++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/mod/install.php b/mod/install.php index eb740c7b6..06f728729 100644 --- a/mod/install.php +++ b/mod/install.php @@ -303,12 +303,13 @@ function install_content(App $a) { * required : boolean * help : string optional */ -function check_add(&$checks, $title, $status, $required, $help) { +function check_add(&$checks, $title, $status, $required, $help, $error_msg = "") { $checks[] = [ 'title' => $title, 'status' => $status, 'required' => $required, 'help' => $help, + 'error_msg' => $error_msg, ]; } @@ -489,18 +490,24 @@ function check_smarty3(&$checks) { function check_htaccess(&$checks) { $status = true; $help = ""; + $error_msg = ""; if (function_exists('curl_init')) { - $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchUrlFull(System::baseUrl()."/install/testrewrite"); - if ($test != "ok") { - $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); + $url = normalise_link(System::baseUrl()."/install/testrewrite"); + if ($test['body'] != "ok") { + $test = Network::fetchUrlFull($url); } - if ($test != "ok") { + if ($test['body'] != "ok") { $status = false; $help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.'); + $error_msg = []; + $error_msg['head'] = L10n::t('Error message from Curl when fetching'); + $error_msg['url'] = $test['redirect_url']; + $error_msg['msg'] = $test['error']; } - check_add($checks, L10n::t('Url rewrite is working'), $status, true, $help); + check_add($checks, L10n::t('Url rewrite is working'), $status, true, $help, $error_msg); } else { // cannot check modrewrite if libcurl is not installed /// @TODO Maybe issue warning here? diff --git a/src/Util/Network.php b/src/Util/Network.php index 4a11f9259..91c4b7d39 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -36,7 +36,13 @@ class Network */ public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) { - $ret = self::curl( + $ret = fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); + + return($ret['body']); + } + public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) + { + return self::curl( $url, $binary, $redirects, @@ -45,8 +51,6 @@ class Network 'cookiejar'=>$cookiejar ] ); - - return($ret['body']); } /** diff --git a/view/install/style.css b/view/install/style.css index 2f995d599..d6140a1bb 100644 --- a/view/install/style.css +++ b/view/install/style.css @@ -32,6 +32,9 @@ td.help { td.help blockquote { margin-left: 60px; } +.error_header { + margin-left: 60px; +} input[type="submit"] { margin: 2em 0; } diff --git a/view/templates/install_checks.tpl b/view/templates/install_checks.tpl index 10a197482..f96072911 100644 --- a/view/templates/install_checks.tpl +++ b/view/templates/install_checks.tpl @@ -16,7 +16,13 @@ {{/if}} {{if $check.required}}(required){{/if}} {{if $check.help}} -
{{$check.help}}
+ +
{{$check.help}}
+ {{if $check.error_msg}} +
{{$check.error_msg.head}}
{{$check.error_msg.url}}
+
{{$check.error_msg.msg}}
+ {{/if}} + {{/if}} {{/foreach}} From 5b4dce5983d10ca057d10c1dcbad3f144bc34f9c Mon Sep 17 00:00:00 2001 From: Andreas Neustifter Date: Fri, 27 Apr 2018 21:28:22 +0200 Subject: [PATCH 2/3] Exclude editor backups from Git. --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8d86b9587..9e6504184 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ include/jquery-1.4.2.min.js favicon.* home.html addon +*.orig *~ robots.txt @@ -57,4 +58,4 @@ venv/ /view/asset #ignore config files from JetBrains -/.idea \ No newline at end of file +/.idea From 9bf58e46f622b051240d282acd3e52382d0fcb84 Mon Sep 17 00:00:00 2001 From: Andreas Neustifter Date: Fri, 27 Apr 2018 20:22:17 +0000 Subject: [PATCH 3/3] Changes requested by @MrPetovan. --- src/Util/Network.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Util/Network.php b/src/Util/Network.php index 91c4b7d39..f0338e048 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -38,8 +38,25 @@ class Network { $ret = fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); - return($ret['body']); + return $ret['body']; } + + /** + * @brief Curl wrapper with array of return values. + * + * Inner workings and parameters are the same as @ref fetchUrl but returns an array with + * all the information collected during the fetch. + * + * @param string $url URL to fetch + * @param boolean $binary default false + * TRUE if asked to return binary results (file download) + * @param integer $redirects The recursion counter for internal use - default 0 + * @param integer $timeout Timeout in seconds, default system config value or 60 seconds + * @param string $accept_content supply Accept: header with 'accept_content' as the value + * @param string $cookiejar Path to cookie jar file + * + * @return array With all relevant information, 'body' contains the actual fetched content. + */ public static function fetchUrlFull($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) { return self::curl(