Esempio n. 1
0
 /**
  * @param        $region
  * @param        $params
  * @param        $public_key
  * @param        $private_key
  * @param string $associate_tag
  *
  * @return bool|SimpleXMLElement|string
  */
 private function aws_signed_request($region, $params, $public_key, $private_key, $associate_tag = "")
 {
     if ($public_key !== "" && $private_key !== "" && $associate_tag !== "") {
         $method = "GET";
         // Must be in small case.
         $host = "ecs.amazonaws." . $region;
         $uri = "/onca/xml";
         $params["Service"] = "AWSECommerceService";
         $params["AWSAccessKeyId"] = $public_key;
         $params["AssociateTag"] = $associate_tag;
         $params["Timestamp"] = gmdate("Y-m-d\\TH:i:s\\Z");
         $params["Version"] = "2009-03-31";
         /* The params need to be sorted by the key, as Amazon does this at
         			their end and then generates the hash of the same. If the params
         			are not in order then the generated hash will be different thus
         			failing the authetication process.
         			*/
         ksort($params);
         $canonicalized_query = array();
         foreach ($params as $param => $value) {
             $param = str_replace("%7E", "~", rawurlencode($param));
             $value = str_replace("%7E", "~", rawurlencode($value));
             $canonicalized_query[] = $param . "=" . $value;
         }
         $canonicalized_query = implode("&", $canonicalized_query);
         $string_to_sign = $method . "\n" . $host . "\n" . $uri . "\n" . $canonicalized_query;
         /* Calculate the signature using HMAC with SHA256 and base64-encoding.
          * The 'hash_hmac' function is only available from PHP 5 >= 5.1.2.
          */
         $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
         // Encode the signature for the request.
         $signature = str_replace("%7E", "~", rawurlencode($signature));
         // Create request.
         $request = "http://" . $host . $uri . "?" . $canonicalized_query . "&Signature=" . $signature;
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $request);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         curl_setopt_array($ch, Misc::curlSslContextOptions());
         $xml_response = curl_exec($ch);
         if ($xml_response === False) {
             return False;
         } else {
             // Parse XML.
             $parsed_xml = @simplexml_load_string($xml_response);
             return $parsed_xml === False ? False : $parsed_xml;
         }
     } else {
         return "missingkey";
     }
 }
Esempio n. 2
0
 /**
  * Gets Raw Html
  *
  * @param string $fetchURL
  * @param bool $usePost
  *
  * @return bool
  */
 private function getUrl($fetchURL, $usePost = false)
 {
     if (isset($fetchURL)) {
         $this->_ch = curl_init($fetchURL);
     }
     if ($usePost === true) {
         curl_setopt($this->_ch, CURLOPT_POST, 1);
         curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $this->_postParams);
     }
     curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_ch, CURLOPT_HEADER, 0);
     curl_setopt($this->_ch, CURLOPT_VERBOSE, 0);
     curl_setopt($this->_ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($this->_ch, CURLOPT_FAILONERROR, 1);
     if (isset($this->cookie)) {
         curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->cookie);
         curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->cookie);
     }
     curl_setopt_array($this->_ch, Misc::curlSslContextOptions());
     $this->_response = curl_exec($this->_ch);
     if (!$this->_response) {
         curl_close($this->_ch);
         return false;
     }
     curl_close($this->_ch);
     $this->_html->load($this->_response);
     return true;
 }
Esempio n. 3
0
 /**
  * Gets raw html content using adeurl and any trailing url.
  *
  * @param string $trailing - required
  *
  * @return bool - true if page has content
  */
 private function getUrl($trailing = "")
 {
     if (!empty($trailing)) {
         $this->_ch = curl_init(self::ADE . $trailing);
     }
     if (!empty($this->directLink)) {
         $this->_ch = curl_init($this->directLink);
         $this->directLink = "";
     }
     curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($this->_ch, CURLOPT_HEADER, 0);
     curl_setopt($this->_ch, CURLOPT_VERBOSE, 0);
     curl_setopt($this->_ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($this->_ch, CURLOPT_FAILONERROR, 1);
     curl_setopt_array($this->_ch, Misc::curlSslContextOptions());
     $this->_response = curl_exec($this->_ch);
     if (!$this->_response) {
         curl_close($this->_ch);
         return false;
     }
     curl_close($this->_ch);
     return true;
 }
Esempio n. 4
0
File: ADM.php Progetto: zetas/nZEDb
 /**
  * Get Raw html of webpage
  *
  * @param bool $usepost
  *
  * @return bool
  */
 private function getUrl($usepost = false)
 {
     if (isset($this->_trailUrl)) {
         $ch = curl_init(self::ADMURL . $this->_trailUrl);
     } else {
         $ch = curl_init(self::IF18);
     }
     if ($usepost === true) {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $this->_postParams);
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_VERBOSE, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($ch, CURLOPT_FAILONERROR, 1);
     if (isset($this->cookie)) {
         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
     }
     curl_setopt_array($ch, Misc::curlSslContextOptions());
     $this->_response = curl_exec($ch);
     if (!$this->_response) {
         curl_close($ch);
         return false;
     }
     curl_close($ch);
     $this->_html->load($this->_response);
     return true;
 }
Esempio n. 5
0
File: IAFD.php Progetto: zetas/nZEDb
 private function getUrl()
 {
     if ($this->_doSearch === true) {
         $ch = curl_init(self::IAFDSEARCHURL . urlencode($this->searchTerm));
     } else {
         if (empty($this->_getRedirect)) {
             $ch = curl_init(self::IAFDURL);
         } else {
             $ch = curl_init($this->_getRedirect);
         }
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_VERBOSE, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_USERAGENT, "Firefox/2.0.0.1");
     curl_setopt($ch, CURLOPT_FAILONERROR, 1);
     if (isset($this->cookie)) {
         curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
         curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
     }
     curl_setopt_array($ch, Misc::curlSslContextOptions());
     $this->_response = curl_exec($ch);
     if (!empty($this->_getRedirect)) {
         $this->_getRedirect = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
         curl_close($ch);
         return $this->_getRedirect;
     }
     if (!$this->_response) {
         curl_close($ch);
         return false;
     }
     curl_close($ch);
     if ($this->_doSearch === true) {
         $this->_html->load($this->_response);
         $this->_doSearch = false;
     }
     return true;
 }