Merged in feature/MAW-855-import-code-into-aws (pull request #2)
code import from pantheon * code import from pantheon
This commit is contained in:
@@ -671,16 +671,21 @@ class wfDiagnostic
|
||||
$message = __('wp_remote_post() test back to this server failed! Response was: ', 'wordfence') . $result->get_error_message();
|
||||
}
|
||||
else {
|
||||
$message = __('wp_remote_post() test back to this server failed! Response was: ', 'wordfence') . $result['response']['code'] . " " . $result['response']['message'] . "\n";
|
||||
$message .= __('This additional info may help you diagnose the issue. The response headers we received were:', 'wordfence') . "\n";
|
||||
$message = __('wp_remote_post() test back to this server failed! Response was: ', 'wordfence') . '<br>' . $result['response']['code'] . " " . $result['response']['message'] . '<br><br>';
|
||||
if ($this->_detectBlockedByCloudflare($result)) {
|
||||
$message .= __('Cloudflare appears to be blocking your site from connecting to itself.', 'wordfence') . '<br>' . sprintf(' <a href="%s" target="_blank" rel="noopener noreferrer">', wfSupportController::esc_supportURL(wfSupportController::ITEM_DIAGNOSTICS_CLOUDFLARE_BLOCK)) . __('Get help with Cloudflare compatibility', 'wordfence') . '</a><br><br>';
|
||||
}
|
||||
$message .= __('This additional info may help you diagnose the issue. The response headers we received were:', 'wordfence') . '<br><br>';
|
||||
if (isset($result['http_response']) && is_object($result['http_response']) && method_exists($result['http_response'], 'get_response_object') && is_object($result['http_response']->get_response_object()) && property_exists($result['http_response']->get_response_object(), 'raw')) {
|
||||
$detail = str_replace("\r\n", "\n", $result['http_response']->get_response_object()->raw);
|
||||
}
|
||||
}
|
||||
|
||||
$message = wp_kses($message, array('a' => array('href' => array(), 'target' => array(), 'rel' => array()), 'span' => array('class' => array()), 'em' => array(), 'code' => array(), 'br' => array()));
|
||||
|
||||
return array(
|
||||
'test' => false,
|
||||
'message' => $message,
|
||||
'message' => array('escaped' => $message),
|
||||
'detail' => $detail,
|
||||
);
|
||||
}
|
||||
@@ -698,11 +703,14 @@ class wfDiagnostic
|
||||
$handle = $interceptor->getHandle();
|
||||
$errorNumber = curl_errno($handle);
|
||||
if ($errorNumber === 6 /* COULDNT_RESOLVE_HOST */) {
|
||||
$detail = sprintf(/* translators: error message from failed request */ __('This likely indicates that the server either does not support IPv6 or does not have an IPv6 address assigned or associated with the domain. Original error message: %s', 'wordfence'), is_array($result['message']) ? $result['message']['escaped'] : $result['message']);
|
||||
$detail = wp_kses($detail, array('a' => array('href' => array(), 'target' => array(), 'rel' => array()), 'span' => array('class' => array()), 'em' => array(), 'code' => array(), 'br' => array()));
|
||||
|
||||
return array(
|
||||
'test' => false,
|
||||
'infoOnly' => true,
|
||||
'message' => __('IPv6 DNS resolution failed', 'wordfence'),
|
||||
'detail' => sprintf(/* translators: error message from failed request */ __('This likely indicates that the server either does not support IPv6 or does not have an IPv6 address assigned or associated with the domain. Original error message: %s', 'wordfence'), $result['message'])
|
||||
'detail' => array('escaped' => $detail),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -721,6 +729,34 @@ class wfDiagnostic
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks for markers in $result that indicate it was challenged/blocked by Cloudflare.
|
||||
*
|
||||
* @param $result
|
||||
* @return bool
|
||||
*/
|
||||
private function _detectBlockedByCloudflare($result) {
|
||||
$headers = $result['headers'];
|
||||
if (isset($headers['cf-mitigated']) && strtolower($headers['cf-mitigated']) == 'challenge' /* managed challenge */) { //$headers is an instance of Requests_Utility_CaseInsensitiveDictionary
|
||||
return true;
|
||||
}
|
||||
|
||||
$body = $result['body'];
|
||||
$search = array(
|
||||
'/cdn-cgi/styles/challenges.css', //managed challenge
|
||||
'/cdn-cgi/challenge-platform', //managed challenge
|
||||
'/cdn-cgi/styles/cf.errors.css', //block
|
||||
'cf-error-details', //block
|
||||
'Cloudflare Ray ID', //block
|
||||
);
|
||||
foreach ($search as $s) {
|
||||
if (stripos($body, $s) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function serverIP() {
|
||||
$serverIPs = wfUtils::serverIPs();
|
||||
return array(
|
||||
|
||||
Reference in New Issue
Block a user