Exemple #1
0
 /**
  * Send this HTTP request
  *
  * @throws Horde_Http_Exception
  * @return Horde_Http_Response_Base
  */
 public function send()
 {
     // at this time only the curl driver is supported
     $client = new \http\Client('curl');
     $body = new \http\Message\Body();
     $data = $this->data;
     if (is_array($data)) {
         $body->addForm($data);
     } else {
         $body->append($data);
     }
     $httpRequest = new \http\Client\Request($this->method, (string) $this->uri, $this->headers, $body);
     $client->setOptions($this->_httpOptions());
     $client->enqueue($httpRequest);
     try {
         $client->send();
         $httpResponse = $client->getResponse($httpRequest);
     } catch (\http\Exception $e) {
         throw new Horde_Http_Exception($e);
     }
     return new Horde_Http_Response_Peclhttp2((string) $this->uri, $httpResponse);
 }
// Hijack crossdomain.xml.
if ($request->getUrlComponent('path') == '/crossdomain.xml' && getDownstreamOrigin()) {
    header('Content-Type: application/xml');
    $downstream_origin = getDownstreamOrigin();
    print <<<EOF
<?xml version="1.0" ?>
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only"/>
  <allow-access-from domain="{$downstream_origin}"/>
  <allow-http-request-headers-from domain="{$downstream_origin}" headers="*"/>
</cross-domain-policy>
EOF;
    exit;
}
$client = new http\Client();
$client->setOptions(['connecttimeout' => Conf::$proxy_http_request_connecttimeout, 'dns_cache_timeout' => Conf::$proxy_http_request_dns_cache_timeout, 'retrycount' => Conf::$proxy_http_request_retrycount, 'timeout' => Conf::$proxy_http_request_timeout]);
$client->enqueue($request)->send();
$response = new ProxyHttpResponse($client->getResponse(), $request);
$body = $response->getBody();
$headers = $response->getHeaders();
// Default - can be overriden below.
$headers['X-Frame-Options'] = 'SAMEORIGIN';
if (getDownstreamOrigin()) {
    $headers['Access-Control-Allow-Origin'] = getDownstreamOrigin();
    // See http://stackoverflow.com/questions/12409600/error-request-header-field-content-type-is-not-allowed-by-access-control-allow.
    $headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept';
    $headers['X-Frame-Options'] = 'ALLOW-FROM ' . getDownstreamOrigin();
}
header($response->getResponseInfo());
foreach ($headers as $key => $values) {
    // Don't overwrite security headers.
Exemple #3
0
 public function getTransactions($terminal)
 {
     assert(!is_null($terminal));
     assert(isset($terminal->url));
     assert($this->isLoggedIn());
     // Support merged terminal reports, where given an array of URLs instead of string:
     // Just use same method and merge results from all URLs
     if (is_array($terminal->url)) {
         $terminal_simple = clone $terminal;
         $transactions = array();
         foreach ($terminal->url as $url) {
             $terminal_simple->url = $url;
             $transactions += $this->getTransactions($terminal_simple);
         }
         return $transactions;
     }
     // Create HTTP request for single terminal URL ('terminal_simple')
     $request = new \http\Client\Request("GET", $terminal->url, array('User-Agent' => UCS::USER_AGENT, 'Accept' => UCS::ACCEPT, 'Accept-Language' => UCS::ACCEPT_LANGUAGE, 'Host' => UCS::HOST, 'Cookie' => $this->getCookieHeader(), 'Referer' => UCS::URL_REPORTS, 'Upgrade-Insecure-Requests' => 1));
     // Create HTTP client with appropriate TLS version
     $client = new \http\Client();
     $client->setOptions(array("ssl" => ["version" => \http\Client\Curl\SSL_VERSION_TLSv1]));
     // Do the Http request
     $client->enqueue($request)->send();
     // Get Response text
     $re = $client->getResponse($request);
     $html = $re->getBody();
     // Suppress HTML parser warnings
     $xml_error_mode = libxml_use_internal_errors(true);
     // Parse HTML into DOM/XPATH objects
     $dom = new \DomDocument();
     $dom->loadHTML($html);
     $xpath = new \DomXPath($dom);
     // Enumerate per-transaction info table rows
     $transactions = array();
     $rows = $xpath->query("//table//tr");
     for ($rowi = 0; $rowi < $rows->length; $rowi++) {
         $cols = $rows->item($rowi)->getElementsByTagName('td');
         if ($cols->length < 10) {
             continue;
         }
         // Normalize text values in cells
         for ($coli = 0; $coli < $cols->length; $coli++) {
             $cols->item($coli)->normalize();
         }
         // Check if this is header row or invalid row
         $shop = $cols->item(0)->nodeValue;
         $mid = $cols->item(1)->nodeValue;
         if (empty($shop) || !is_numeric($mid)) {
             continue;
         }
         // Get other transaction data
         $tid = $cols->item(2)->nodeValue;
         $date = new \DateTime($cols->item(3)->nodeValue);
         $currency = $cols->item(4)->nodeValue;
         $type = $cols->item(5)->nodeValue;
         $card_type = $cols->item(6)->nodeValue;
         $card_number = $cols->item(7)->nodeValue;
         $amount = floatval(str_replace(" ", "", $cols->item(8)->nodeValue));
         $auth_code = $cols->item(9)->nodeValue;
         // Push terminal data entry
         array_push($transactions, (object) array('terminal_id' => $tid, 'merchant_id' => $mid, 'date' => $date, 'currency' => $currency, 'type' => $type, 'amount' => $amount, 'card_type' => $card_type, 'card_number' => $card_number, 'auth_code' => $auth_code));
     }
     // Reset xml_error_mode
     libxml_use_internal_errors($xml_error_mode);
     return $transactions;
 }