Beispiel #1
0
 /**
  * @return wfWAFCronEvent|bool
  */
 public function reschedule()
 {
     $waf = $this->getWaf();
     if (!$waf) {
         return false;
     }
     $newEvent = new self(time() + 86400 * ($waf->getStorageEngine()->getConfig('isPaid') ? 0.5 : 7));
     if ($this->response) {
         $headers = $this->response->getHeaders();
         if (isset($headers['Expires'])) {
             $timestamp = strtotime($headers['Expires']);
             // Make sure it's at least 2 hours ahead.
             if ($timestamp && $timestamp > time() + 7200) {
                 $newEvent->setFireTime($timestamp);
             }
         }
     }
     return $newEvent;
 }
Beispiel #2
0
 /**
  * @todo Implement wfWAFHTTPTransportStreams::send.
  * @param wfWAFHTTP $request
  * @return mixed
  * @throws wfWAFHTTPTransportException
  */
 public function send($request)
 {
     $timeout = 5;
     $url = $request->getUrl();
     if ($queryString = $request->getQueryString()) {
         if (is_array($queryString)) {
             $queryString = http_build_query($queryString);
         }
         $url .= (wfWAFUtils::strpos($url, '?') !== false ? '&' : '?') . $queryString;
     }
     $urlParsed = parse_url($request->getUrl());
     $headers = "Host: {$urlParsed['host']}\r\n";
     if ($auth = $request->getAuth()) {
         $headers .= 'Authorization: Basic ' . base64_encode($auth['user'] . ':' . $auth['password']) . "\r\n";
     }
     if ($cookies = $request->getCookies()) {
         if (is_array($cookies)) {
             $cookies = self::buildCookieString($cookies);
         }
         $headers .= "Cookie: {$cookies}\r\n";
     }
     $hasUA = false;
     if ($_headers = $request->getHeaders()) {
         if (is_array($_headers)) {
             foreach ($_headers as $header => $value) {
                 if (trim(wfWAFUtils::strtolower($header)) === 'user-agent') {
                     $hasUA = true;
                 }
                 $headers .= $header . ': ' . $value . "\r\n";
             }
         }
     }
     if (!$hasUA) {
         $headers .= "User-Agent: Wordfence Streams UA\r\n";
     }
     $httpOptions = array('method' => $request->getMethod(), 'ignore_errors' => true, 'timeout' => $timeout, 'follow_location' => 1, 'max_redirects' => 5);
     if (wfWAFUtils::strlen($request->getBody()) > 0) {
         $httpOptions['content'] = $request->getBody();
         $headers .= 'Content-Length: ' . wfWAFUtils::strlen($httpOptions['content']) . "\r\n";
     }
     $httpOptions['header'] = $headers;
     $options = array(wfWAFUtils::strtolower($urlParsed['scheme']) => $httpOptions);
     $context = stream_context_create($options);
     $stream = fopen($request->getUrl(), 'r', false, $context);
     if (!is_resource($stream)) {
         return false;
     }
     $metaData = stream_get_meta_data($stream);
     // Get the HTTP response code
     $httpResponse = array_shift($metaData['wrapper_data']);
     if (preg_match_all('/(\\w+\\/\\d\\.\\d) (\\d{3})/', $httpResponse, $matches) !== false) {
         // $protocol = $matches[1][0];
         $status = (int) $matches[2][0];
     } else {
         // $protocol = null;
         $status = null;
     }
     $responseObj = new wfWAFHTTPResponse();
     $responseObj->setHeaders(join("\r\n", $metaData['wrapper_data']));
     $responseObj->setBody(stream_get_contents($stream));
     $responseObj->setStatusCode($status);
     // Close the stream after use
     fclose($stream);
     return $responseObj;
 }