From eb06639784098222a8108f8d6b4abb495e04a079 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 3 Feb 2014 12:09:58 -0800 Subject: [PATCH] CRM-14126 - CRM_Extension - Add pleasant warning and log message if open_basedir/safe_mode prevents redirects. ---------------------------------------- * CRM-14126: HttpClient.php library used by CiviCRM issues a PHP warning when open_basedir is set http://issues.civicrm.org/jira/browse/CRM-14126 --- CRM/Extension/Downloader.php | 5 +++++ CRM/Utils/HttpClient.php | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CRM/Extension/Downloader.php b/CRM/Extension/Downloader.php index 3c40f0bc30..4a6274efc5 100644 --- a/CRM/Extension/Downloader.php +++ b/CRM/Extension/Downloader.php @@ -84,6 +84,11 @@ class CRM_Extension_Downloader { ); } + if (empty($errors) && ! CRM_Utils_HttpClient::singleton()->isRedirectSupported()) { + CRM_Core_Session::setStatus(ts('WARNING: The downloader may be unable to download files which require HTTP redirection. This may be a configuration issue with PHP\'s open_basedir or safe_mode.')); + CRM_Core_Error::debug_log_message('WARNING: The downloader may be unable to download files which require HTTP redirection. This may be a configuration issue with PHP\'s open_basedir or safe_mode.'); + } + return $errors; } diff --git a/CRM/Utils/HttpClient.php b/CRM/Utils/HttpClient.php index c94b605fd9..d7c5422fc7 100644 --- a/CRM/Utils/HttpClient.php +++ b/CRM/Utils/HttpClient.php @@ -189,7 +189,7 @@ class CRM_Utils_HttpClient { curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); curl_setopt($ch, CURLOPT_VERBOSE, 0); - if (ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off') { + if ($this->isRedirectSupported()) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); } if ($this->connectionTimeout !== NULL) { @@ -202,4 +202,8 @@ class CRM_Utils_HttpClient { return array($ch, $caConfig); } + public function isRedirectSupported() { + return ini_get('open_basedir') == '' && ini_get('safe_mode') == 'Off'; + } + } -- 2.25.1