Exemplo n.º 1
0
 /**
  * Add any options, overwrite options etc (a hook for subclasses to modify the request before execution)
  * __request_query_parms is avalable here before the url has been set
  * for post data check the stored post fields
  */
 protected function set_request_options()
 {
     $headers = array();
     $query_str = SPUtils::join_key_values_assoc("=", "&", SPUtils::array_map_assoc($this->__encoding_callback, $this->__request_query_parms));
     $this->__curl_opts[CURLOPT_URL] = SPUtils::url_from_parts($this->__request_url_parts) . ($query_str ? "?{$query_str}" : "");
     if ($this->request_headers && is_array($this->request_headers)) {
         foreach ($this->request_headers as $name => $value) {
             $headers[] = "{$name}: {$value}";
         }
         $this->__curl_opts[CURLOPT_HTTPHEADER] = $headers;
     }
     $this->CURLOPT_FOLLOWLOCATION = $this->auto_redirect;
     if ($this->curl_user_agent) {
         $this->__curl_opts[CURLOPT_USERAGENT] = $this->curl_user_agent;
     }
     if ($this->curl_set_referrer && $this->http_response_location) {
         $this->__curl_opts[CURLOPT_REFERER] = $this->http_response_location;
     }
     if (function_exists("curl_setopt_array")) {
         curl_setopt_array($this->__curl, $this->__curl_opts);
         return;
     }
     foreach ($this->__curl_opts as $key => $value) {
         curl_setopt($this->__curl, $key, $value);
     }
 }
Exemplo n.º 2
0
Arquivo: AOL.php Projeto: bilel99/oge
 protected function GetContactsData()
 {
     $this->client->curl_user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
     if (strpos($this->username, "@aol.com") || strpos($this->username, "@aim.com")) {
         $this->username = current(explode("@", $this->username));
     }
     if (isset($this->username) && trim($this->username) == "" || isset($this->password) && trim($this->password) == "") {
         $this->Error = ContactsResponses::ERROR_NO_USERPASSWORD;
         return false;
     }
     //! attempt login
     if (!$this->client->get("https://my.screenname.aol.com/_cqr/login/login.psp?mcState=initialized&seamless=novl&sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=2&siteState=ver%3a2%7cac%3aWS%7cat%3aSNS%7cld%3awebmail.aol.com%7cuv%3aAOL%7clc%3aen-us")) {
         $this->Error = ContactsResponses::ERROR_UNKNOWN;
         return false;
     }
     $url = "https://my.screenname.aol.com/_cqr/login/login.psp";
     if (preg_match('/<form name="AOLLoginForm".*?action="([^"]*).*?<\\/form>/si', $this->client->http_response_body, $matches)) {
         $url = $matches[1];
         preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)".*?>/si', $matches[0], $matches);
         $params = array_combine($matches[1], $matches[2]);
     } else {
         //! ok not quite unknown, could not find the login form and without the login parms the login won't work and will return misleading error
         $this->Error = ContactsResponses::ERROR_UNKNOWN;
         return false;
     }
     $params['loginId'] = $this->username;
     $params['password'] = $this->password;
     if (!$this->client->post($url, SPUtils::join_key_values_assoc("=", "&", SPUtils::array_map_assoc("rawurlencode", $params)))) {
         $this->Error = ContactsResponses::ERROR_UNKNOWN;
         return false;
     }
     # check if login passed
     if (!preg_match("/'loginForm', 'false', '([^']*)'/si", $this->client->http_response_body, $matches)) {
         #return error if it's not
         $this->Error = ContactsResponses::ERROR_INVALID_LOGIN;
         return false;
     }
     $url = $matches[1];
     if (!$this->client->get($url)) {
         $this->Error = ContactsResponses::ERROR_UNKNOWN;
         return false;
     }
     if (preg_match('/gTargetHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $this->client->http_response_body, $matches) || preg_match('/gPreferredHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $this->client->http_response_body, $matches)) {
         $url = "http://{$matches['1']}{$matches['2']}";
     } else {
         if (preg_match("/'loginForm', 'false', '([^']*)'/si", $this->client->http_response_body, $matches)) {
             $this->client->get($matches[1]);
             $url = $this->client->http_response_location;
         }
         if (preg_match('/gTargetHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $this->client->http_response_body, $matches) || preg_match('/gPreferredHost = "([^"]*)".*?gSuccessPath = "([^"]*)"/si', $this->client->http_response_body, $matches)) {
             $url = "http://{$matches['1']}{$matches['2']}";
         }
         if (preg_match('/gSuccessURL\\s?=\\s?"([^"]+)/si', $this->client->http_response_body, $matches)) {
             $url = $matches[1];
         }
     }
     $opturl = $url;
     //!get settings:
     $opturl = explode("/", $opturl);
     $opturl[count($opturl) - 1] = "common/settings.js.aspx";
     $opturl = implode("/", $opturl);
     $this->client->get($opturl);
     $opturl = explode("/", $url);
     $opturl[count($opturl) - 1] = "AB";
     $opturl = implode("/", $opturl);
     $version = $this->client->get_simple_cookie("Version");
     $auth = $this->client->get_simple_cookie("Auth");
     $usr = "";
     if (preg_match('/"UserUID":"([^"]*)/si', $this->client->http_response_body, $matches) || preg_match('/uid:([^&]*)/si', $auth, $matches)) {
         $usr = $matches[1];
     }
     #get the address book:
     $opturl .= "/addresslist-print.aspx?command=all&undefined&sort=LastFirstNick&sortDir=Ascending&nameFormat=FirstLastNick&version={$version}&user={$usr}";
     if (!$this->client->get($opturl)) {
         $this->Error = ContactsResponses::ERROR_UNKNOWN;
         return false;
     } else {
         $this->RawSource = $this->client->http_response_body;
         return true;
     }
 }
Exemplo n.º 3
0
 /**
  * Build and return cookie header string for the given url
  * @param $url
  */
 function get_cookie($url)
 {
     $url_parts = parse_url($url);
     $host = strrev($url_parts["host"]);
     $path = isset($url_parts["path"]) ? $url_parts["path"] : "/";
     $secure = strtolower($url_parts["scheme"]) == "https";
     $cookies = array();
     ksort($this->__cookies, SORT_STRING);
     foreach ($this->__cookies as $h => $p) {
         if (strpos($host, $h) === 0) {
             ksort($this->__cookies[$h], SORT_STRING);
             foreach ($this->__cookies[$h] as $p => $s) {
                 if (strpos($path, $p) === 0) {
                     if ($secure) {
                         if (isset($s[true])) {
                             $cookies = array_merge($cookies, $s[true]);
                         }
                     }
                     if (isset($s[false])) {
                         $cookies = array_merge($cookies, $s[false]);
                     }
                 }
             }
             //!< end for each path
         }
     }
     //!< end for each host
     return SPUtils::join_key_values_assoc("=", "; ", $cookies);
 }
Exemplo n.º 4
0
 protected function set_request_options()
 {
     $data = $this->__url_encoded_data ? $this->__url_encoded_data : array();
     $query = $this->__request_query_parms ? $this->__request_query_parms : array();
     $auth = $this->base_auth_parms();
     if ($this->request_headers && isset($this->request_headers[$this->auth_header_name])) {
         unset($this->request_headers[$this->auth_header_name]);
     }
     $base_url_array = array_map("strtolower", $this->__request_url_parts);
     if (isset($base_url_array["path"])) {
         $base_url_array["path"] = $this->__request_url_parts["path"];
     }
     $base_url = SPUtils::url_from_parts($base_url_array);
     $base_parm_string = SPOAuthClient::construct_base_string(SPUtils::array_map_assoc($this->__encoding_callback, $query, $data, $auth));
     $this->oauth_signature = SPOAuthClient::sign_base_string($this->oauth_signature_method, SPUtils::join_encoded3896($this->__request_http_method, $base_url, $base_parm_string), $this->oauth_consumer_secret, $this->oauth_token_secret);
     $auth["oauth_signature"] = $this->oauth_signature;
     switch ($this->auth_http_method) {
         case SPConstants::HTTP_METHOD_GET:
             $query = array_merge($query, $auth);
             break;
         case SPConstants::HTTP_METHOD_POST:
             $data = array_merge($data, $auth);
             $this->CURLOPT_POSTFIELDS = SPUtils::join_key_values_assoc("=", "&", SPUtils::array_map_assoc($this->__encoding_callback, $data));
             break;
         case SPOAuthClient::HTTP_AUTH_HEADER:
             $this->request_headers[$this->auth_header_name] = $this->get_auth_header(SPUtils::array_map_assoc($this->__encoding_callback, $auth));
             break;
     }
     $this->__request_query_parms = $query;
     parent::set_request_options();
 }