Exemple #1
0
function doCurlTest($protocol)
{
    if (!function_exists('curl_init')) {
        echo "<br /><b style='color: #F00;'>CURL is not installed</b>. Asking your hosting provider to install and enable CURL may improve any connection problems.</b><br />\n";
        return;
    }
    echo "<br /><b>STARTING CURL {$protocol} CONNECTION TEST....</b><br />\n";
    global $curlContent;
    $curlContent = "";
    $curl = curl_init($protocol . '://noc1.wordfence.com/');
    if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') && wfUtils::hostNotExcludedFromProxy('noc1.wordfence.com')) {
        curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 0);
        curl_setopt($curl, CURLOPT_PROXY, WP_PROXY_HOST . ':' . WP_PROXY_PORT);
        if (defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD')) {
            curl_setopt($curl, CURLOPT_PROXYUSERPWD, WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD);
        }
    }
    curl_setopt($curl, CURLOPT_TIMEOUT, 900);
    curl_setopt($curl, CURLOPT_USERAGENT, "Wordfence.com UA " . (defined('WORDFENCE_VERSION') ? WORDFENCE_VERSION : '[Unknown version]'));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'curlWrite');
    curl_exec($curl);
    $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if (strpos($curlContent, 'Your site did not send an API key') !== false) {
        echo "Curl connectivity test passed.<br /><br />\n";
    } else {
        $curlErrorNo = curl_errno($curl);
        $curlError = curl_error($curl);
        echo "Curl connectivity test failed with response: <pre>{$curlContent}</pre>";
        echo "<br />Curl HTTP status: {$httpStatus}<br />Curl error code: {$curlErrorNo}<br />Curl Error: {$curlError}<br /><br />\n";
    }
}
 private static function wfsnIsBlocked($IP, $type)
 {
     try {
         $curl = curl_init('http://noc3.wordfence.com:9050/hackAttempt/?k=' . wfConfig::get('apiKey') . '&IP=' . wfUtils::inet_aton($IP) . '&t=' . $type);
         if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') && wfUtils::hostNotExcludedFromProxy('noc3.wordfence.com')) {
             curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 0);
             curl_setopt($curl, CURLOPT_PROXY, WP_PROXY_HOST . ':' . WP_PROXY_PORT);
             if (defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD')) {
                 curl_setopt($curl, CURLOPT_PROXYUSERPWD, WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD);
             }
         }
         curl_setopt($curl, CURLOPT_TIMEOUT, 3);
         curl_setopt($curl, CURLOPT_USERAGENT, "Wordfence.com UA " . (defined('WORDFENCE_VERSION') ? WORDFENCE_VERSION : '[Unknown version]'));
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($curl, CURLOPT_POST, false);
         $result = curl_exec($curl);
         if (preg_match('/BLOCKED:(\\d+)/', $result, $matches) && !self::getLog()->isWhitelisted($IP)) {
             return $matches[1];
         }
         return false;
     } catch (Exception $err) {
         return false;
     }
 }
Exemple #3
0
 public function binCall($func, $postData)
 {
     $url = $this->getAPIURL() . '/v' . WORDFENCE_API_VERSION . '/?' . $this->makeAPIQueryString() . '&action=' . $func;
     if (function_exists('curl_init')) {
         $curl = curl_init($url);
         if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') && wfUtils::hostNotExcludedFromProxy($url)) {
             error_log("BINCALL PROXY");
             curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, 0);
             curl_setopt($curl, CURLOPT_PROXY, WP_PROXY_HOST . ':' . WP_PROXY_PORT);
             if (defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD')) {
                 curl_setopt($curl, CURLOPT_PROXYUSERPWD, WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD);
             }
         }
         curl_setopt($curl, CURLOPT_TIMEOUT, 900);
         //curl_setopt($curl, CURLOPT_VERBOSE, true);
         curl_setopt($curl, CURLOPT_USERAGENT, "Wordfence");
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($curl, CURLOPT_POST, true);
         if ($postData) {
             curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
         } else {
             curl_setopt($curl, CURLOPT_POSTFIELDS, array());
         }
         $data = curl_exec($curl);
         $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         if ($httpStatus != 200) {
             $cError = curl_error($curl);
             curl_close($curl);
             if ($cError) {
                 throw new Exception("We received an error response when trying to fetch binary data from the Wordfence scanning server. The HTTP status was [{$httpStatus}] with error: {$cError}");
             } else {
                 throw new Exception("We received an error HTTP response when trying to fetch binary data from the Wordfence scanning server: [{$httpStatus}]");
             }
         }
     } else {
         $data = $this->fileGet($url, $postData);
         if ($data === false) {
             $err = error_get_last();
             if ($err) {
                 throw new Exception("We received an error response when trying to fetch binary data from the Wordfence scanning server using file_get_contents: {$err}");
             } else {
                 throw new Exception("We received an error when trying to fetch binary data from the Wordfence scanning server using file_get_contents. There was no message explaining the error.");
             }
         }
         $httpStatus = '200';
     }
     if (preg_match('/\\{.*errorMsg/', $data)) {
         $jdat = @json_decode($data, true);
         if (is_array($jdat) && $jdat['errorMsg']) {
             throw new Exception($jdat['errorMsg']);
         }
     }
     return array('code' => $httpStatus, 'data' => $data);
 }