]> git.mxchange.org Git - friendica.git/commitdiff
Proper error when rewrite fails during install.
authorAndreas Neustifter <andreas.neustifter@kapsch.net>
Fri, 27 Apr 2018 19:27:55 +0000 (21:27 +0200)
committerAndreas Neustifter <andreas.neustifter@kapsch.net>
Fri, 27 Apr 2018 19:27:55 +0000 (21:27 +0200)
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
src/Util/Network.php
view/install/style.css
view/templates/install_checks.tpl

index eb740c7b64785ad09fa315815d0c4da951344b6d..06f728729c216bf2db7f0f13be34ba61b9c7d9d3 100644 (file)
@@ -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?
index 4a11f9259579e31272b57fdfbe9a1c6d363a8212..91c4b7d395362d26ffad0789fdd30572cb4a578b 100644 (file)
@@ -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']);
        }
 
        /**
index 2f995d5993ebf130774936fd6a5bc48d2f090ef5..d6140a1bb315c517433a09f6641110bb0935ccdc 100644 (file)
@@ -32,6 +32,9 @@ td.help {
 td.help blockquote {\r
        margin-left: 60px;\r
 }\r
+.error_header {\r
+       margin-left: 60px;\r
+}\r
 input[type="submit"] {\r
        margin: 2em 0;\r
 }\r
index 10a197482b9b2689bdaa047f93f8f894649025c4..f960729111f77d862577f1203d31532003c3a68c 100644 (file)
        {{/if}}
        </td><td>{{if $check.required}}(required){{/if}}</td></tr>
        {{if $check.help}}
-       <tr><td class="help" colspan="3"><blockquote>{{$check.help}}</blockquote></td></tr>
+       <tr><td class="help" colspan="3">
+               <blockquote>{{$check.help}}</blockquote>
+               {{if $check.error_msg}}
+               <div class="error_header"><b>{{$check.error_msg.head}}</br><a href="{{$check.error_msg.url}}">{{$check.error_msg.url}}</a></b></div>
+               <blockquote>{{$check.error_msg.msg}}</blockquote>
+               {{/if}}
+       </td></tr>
        {{/if}}
 {{/foreach}}
 </table>