Ejemplo n.º 1
0
 private function send_request($url, $user = '', $pwd = '', $method = 'GET', $ssl_version = '')
 {
     //--
     $this->method = (string) strtoupper(trim((string) $method));
     //--
     //--
     $this->connect_timeout = (int) $this->connect_timeout;
     if ($this->connect_timeout < 1) {
         $this->connect_timeout = 1;
     }
     //end if
     if ($this->connect_timeout > 120) {
         $this->connect_timeout = 120;
     }
     //end if
     //--
     //-- log action
     if ($this->debug) {
         $this->log .= '[INF] Get From URL :: is starting ...' . "\n";
     }
     //end if
     //--
     //-- separations
     $this->url_parts = (array) Smart::separe_url_parts($url);
     $protocol = (string) $this->url_parts['protocol'];
     $server = (string) $this->url_parts['server'];
     $port = (string) $this->url_parts['port'];
     $path = (string) $this->url_parts['path'];
     //--
     if ($this->debug) {
         $this->log .= '[INF] Analize of the URL: ' . @print_r($this->url_parts, 1) . "\n";
     }
     //end if
     //--
     //--
     if ((string) $server == '') {
         if ($this->debug) {
             $this->log .= '[ERR] Invalid Server to Browse' . "\n";
         }
         //end if
         Smart::log_warning('LibHTTP // GetFromURL () // Invalid (empty) Server to Browse ...');
         return 0;
     }
     //end if
     //--
     //--
     $browser_protocol = '';
     //--
     if ((string) $protocol == 'https://') {
         //--
         switch (strtolower((string) $ssl_version)) {
             case 'ssl':
                 $browser_protocol = 'ssl://';
                 break;
             case 'sslv3':
                 $browser_protocol = 'sslv3://';
                 break;
             case 'tls':
             default:
                 $browser_protocol = 'tls://';
         }
         //end switch
         //--
         if (!function_exists('openssl_open')) {
             if ($this->debug) {
                 $this->log .= '[ERR] PHP OpenSSL Extension is required to perform SSL requests' . "\n";
             }
             //end if
             Smart::log_warning('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // PHP OpenSSL Extension not installed ...');
             return 0;
         }
         //end if
         //--
     }
     //end if else
     //--
     //--
     $have_cookies = false;
     if (is_array($this->cookies)) {
         if (count($this->cookies) > 0) {
             $have_cookies = true;
         }
         //end if
     }
     //end if
     //--
     $have_post_vars = false;
     if ((string) $this->poststring != '') {
         $have_post_vars = true;
     } elseif (is_array($this->postvars)) {
         if (count($this->postvars) > 0) {
             $have_post_vars = true;
         }
         //end if
     }
     //end if
     //--
     //-- navigate
     if ($this->debug) {
         $this->log .= 'Opening HTTP(S) Browser Connection to: ' . $protocol . $server . ':' . $port . $path . ' using socket protocol: [' . $browser_protocol . ']' . "\n";
         $this->log .= '[INF] HTTP Protocol: ' . $this->protocol . "\n";
         $this->log .= '[INF] Connection TimeOut: ' . $this->connect_timeout . "\n";
     }
     //end if
     //--
     $stream_context = @stream_context_create();
     if ((string) $browser_protocol != '') {
         if (defined('SMART_FRAMEWORK_SSL_CA_PATH')) {
             if ((string) SMART_FRAMEWORK_SSL_CA_PATH != '') {
                 @stream_context_set_option($stream_context, 'ssl', 'capath', Smart::real_path((string) SMART_FRAMEWORK_SSL_CA_PATH));
             }
             //end if
         }
         //end if
         @stream_context_set_option($stream_context, 'ssl', 'ciphers', (string) SMART_FRAMEWORK_SSL_CIPHERS);
         // allow only high ciphers
         @stream_context_set_option($stream_context, 'ssl', 'verify_host', (bool) SMART_FRAMEWORK_SSL_VFY_HOST);
         // allways must be set to true !
         @stream_context_set_option($stream_context, 'ssl', 'verify_peer', (bool) SMART_FRAMEWORK_SSL_VFY_PEER);
         // this may fail with some CAs
         @stream_context_set_option($stream_context, 'ssl', 'verify_peer_name', (bool) SMART_FRAMEWORK_SSL_VFY_PEER_NAME);
         // allow also wildcard names *
         @stream_context_set_option($stream_context, 'ssl', 'allow_self_signed', (bool) SMART_FRAMEWORK_SSL_ALLOW_SELF_SIGNED);
         // must allow self-signed certificates but verified above
         @stream_context_set_option($stream_context, 'ssl', 'disable_compression', (bool) SMART_FRAMEWORK_SSL_DISABLE_COMPRESS);
         // help mitigate the CRIME attack vector
     }
     //end if else
     $this->socket = @stream_socket_client($browser_protocol . $server . ':' . $port, $errno, $errstr, $this->connect_timeout, STREAM_CLIENT_CONNECT, $stream_context);
     //--
     if (!is_resource($this->socket)) {
         if ($this->debug) {
             $this->log .= '[ERR] Could not open connection. Error : ' . $errno . ': ' . $errstr . "\n";
             Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Could not open connection. Error : ' . $errno . ': ' . $errstr . ' #');
         }
         //end if
         return 0;
     }
     //end if
     //--
     if ($this->debug) {
         $this->log .= '[INF] Socket Resource ID: ' . $this->socket . "\n";
     }
     //end if
     //--
     @stream_set_timeout($this->socket, (int) SMART_FRAMEWORK_NETSOCKET_TIMEOUT);
     if ($this->debug) {
         $this->log .= '[INF] Set Socket Stream TimeOut to: ' . SMART_FRAMEWORK_NETSOCKET_TIMEOUT . "\n";
     }
     //end if
     //--
     //-- avoid connect normally if SSL/TLS was explicit required
     $chk_crypto = (array) @stream_get_meta_data($this->socket);
     if ((string) $browser_protocol != '') {
         if (stripos($chk_crypto['stream_type'], '/ssl') === false) {
             // will return something like: tcp_socket/ssl
             if ($this->debug) {
                 $this->log .= '[ERR] Connection CRYPTO CHECK Failed ...' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Connection CRYPTO CHECK Failed ...');
             }
             //end if
             return 0;
         }
         //end if
     }
     //end if
     //--
     //--
     $this->raw_headers['Host'] = $server . ':' . $port;
     //--
     //-- auth
     if ((string) $user != '' and (string) $pwd != '') {
         //--
         if ($this->debug) {
             $this->log .= '[INF] Authentication will be attempted for USERNAME = \'' . $user . '\' ; PASSWORD(' . strlen($pwd) . ') *****' . "\n";
         }
         //end if
         //--
         $this->raw_headers['Authorization'] = 'Basic ' . base64_encode($user . ':' . $pwd);
         //--
     }
     //end if
     //--
     //-- cookies
     $send_cookies = '';
     //--
     if ($have_cookies) {
         //--
         foreach ($this->cookies as $key => $value) {
             if ((string) $key != '') {
                 if ((string) $value != '') {
                     $send_cookies .= (string) SmartHttpUtils::encode_var_cookie($key, $value);
                 }
                 //end if
             }
             //end if
         }
         //end foreach
         //--
         if ((string) $send_cookies != '') {
             $this->raw_headers['Cookie'] = $send_cookies;
             if ($this->debug) {
                 $this->log .= '[INF] Cookies will be SET: ' . $send_cookies . "\n";
             }
             //end if
         }
         //end if
         //--
     }
     //end if
     //--
     //-- request
     if ((string) $this->jsonrequest != '') {
         // json request
         //--
         if ($this->debug) {
             $this->log .= '[INF] JSON Request will be sent to server via: ' . $this->method . "\n";
         }
         //end if
         //--
         $request = $this->method . ' ' . $path . ' HTTP/' . $this->protocol . "\r\n";
         $this->raw_headers['Content-Type'] = 'application/json';
         $this->raw_headers['Content-Length'] = strlen($this->jsonrequest);
         //--
     } elseif ((string) $this->xmlrequest != '') {
         // xml request
         //--
         if ($this->debug) {
             $this->log .= '[INF] XML Request will be sent to server via: ' . $this->method . "\n";
         }
         //end if
         //--
         $request = $this->method . ' ' . $path . ' HTTP/' . $this->protocol . "\r\n";
         $this->raw_headers['Content-Type'] = 'application/xml';
         // may be also: text/xml
         $this->raw_headers['Content-Length'] = strlen($this->xmlrequest);
         //--
     } elseif ($have_post_vars) {
         // post vars
         //--
         if ((string) $this->method == 'GET') {
             $this->method = 'POST';
             // FIX: if GET Method is using PostVars, then set method to POST ; this should not be fixed for other methods like: HEAD, PUT, DELETE ...
         }
         //end if
         //--
         if ($this->debug) {
             $this->log .= '[INF] Variables will be sent to server using POST method' . "\n";
         }
         //end if
         //--
         $post_string = '';
         if ((string) $this->poststring != '') {
             $post_string = (string) $this->poststring;
         } elseif (is_array($this->postvars)) {
             foreach ($this->postvars as $key => $value) {
                 $post_string .= (string) SmartHttpUtils::encode_var_post($key, $value);
             }
             //end foreach
         }
         //end if else
         //--
         $request = $this->method . ' ' . $path . ' HTTP/' . $this->protocol . "\r\n";
         $this->raw_headers['Content-Type'] = 'application/x-www-form-urlencoded';
         $this->raw_headers['Content-Length'] = strlen($post_string);
         //--
     } else {
         // simple request
         //--
         if ($this->debug) {
             $this->log .= '[INF] Simple Request via: ' . $this->method . "\n";
         }
         //end if
         //--
         $request = $this->method . ' ' . $path . ' HTTP/' . $this->protocol . "\r\n";
         //--
     }
     //end if else
     //--
     //-- check
     if (!$this->socket) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] Premature connection end (1.1)' . "\n";
             Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.1) ... ' . $url);
         }
         //end if
         return 0;
         //--
     }
     //end if
     //--
     //--
     if (@fwrite($this->socket, $request) === false) {
         if ($this->debug) {
             $this->log .= '[ERR] Error writing Request type to socket' . "\n";
             Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing Request type to socket ...');
         }
         //end if
         return 0;
     }
     //end if
     //--
     //-- raw headers
     if (!$this->socket) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] Premature connection end (1.2)' . "\n";
             Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.2) ... ' . $url);
         }
         //end if
         return 0;
         //--
     }
     //end if
     //--
     foreach ($this->raw_headers as $key => $value) {
         if (@fwrite($this->socket, $key . ": " . $value . "\r\n") === false) {
             if ($this->debug) {
                 $this->log .= '[ERR] Error writing Raw-Headers to socket' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing Raw-Headers to socket ...');
             }
             //end if
             return 0;
         }
         //end if
     }
     //end foreach
     //--
     //-- end-line or blank line before post / cookies
     if (!$this->socket) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] Premature connection end (1.3)' . "\n";
             Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.3) ... ' . $url);
         }
         //end if
         return 0;
         //--
     }
     //end if
     //--
     if (@fwrite($this->socket, "\r\n") === false) {
         if ($this->debug) {
             $this->log .= '[ERR] Error writing End-Of-Line to socket' . "\n";
             Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing End-Of-Line to socket ...');
         }
         //end if
         return 0;
     }
     //end if
     //--
     //--
     if ((string) $this->jsonrequest != '') {
         // json request
         //--
         if (!$this->socket) {
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] Premature connection end (1.4)' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.4) ... ' . $url);
             }
             //end if
             return 0;
             //--
         }
         //end if
         //--
         if (@fwrite($this->socket, $this->jsonrequest . "\r\n") === false) {
             if ($this->debug) {
                 $this->log .= '[ERR] Error writing JSON Request data to socket' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing JSON Request data to socket ...');
             }
             //end if
             return 0;
         }
         //end if
         //--
     } elseif ((string) $this->xmlrequest != '') {
         // xml request
         //--
         if (!$this->socket) {
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] Premature connection end (1.5)' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.5) ... ' . $url);
             }
             //end if
             return 0;
             //--
         }
         //end if
         //--
         if (@fwrite($this->socket, $this->xmlrequest . "\r\n") === false) {
             if ($this->debug) {
                 $this->log .= '[ERR] Error writing XML Request data to socket' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing XML Request data to socket ...');
             }
             //end if
             return 0;
         }
         //end if
         //--
     } elseif ($have_post_vars) {
         //--
         if (!$this->socket) {
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] Premature connection end (1.6)' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL // Premature connection end (1.6) ... ' . $url);
             }
             //end if
             return 0;
             //--
         }
         //end if
         //--
         if (@fwrite($this->socket, $post_string . "\r\n") === false) {
             if ($this->debug) {
                 $this->log .= '[ERR] Error writing POST data to socket' . "\n";
                 Smart::log_notice('LibHTTP // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // Error writing POST data to socket ...');
             }
             //end if
             return 0;
         }
         //end if
         //--
     }
     //end if else
     //--
     //-- NOTICE: is this necessary ??? appears that not (it was tested a long time without and appear to be faster) ...
     //if(@fwrite($this->socket, "\r\n") === false) {
     //	if($this->debug) {
     //		$this->log .= '[ERR] Error writing EOL to socket'."\n";
     //		Smart::log_notice('LibHTTP // GetFromURL ('.$conex_info.') // Error writing EOL ...'); // FIX: the final \r\n
     //	} //end if
     //} //end if
     //--
     //--
     return 1;
     //--
 }
 public function browse_url($url, $method = 'GET', $ssl_version = '', $user = '', $pwd = '', $proxy = array())
 {
     //-- reset
     $this->reset();
     //--
     //--
     if ($this->debug) {
         $run_time = microtime(true);
     }
     //end if
     //--
     //--
     $this->connect_timeout = (int) $this->connect_timeout;
     if ($this->connect_timeout < 1) {
         $this->connect_timeout = 1;
     }
     //end if
     if ($this->connect_timeout > 120) {
         $this->connect_timeout = 120;
     }
     //end if
     //--
     $this->exec_timeout = (int) $this->exec_timeout;
     if ($this->exec_timeout > 0) {
         if ($this->exec_timeout < 30) {
             $this->exec_timeout = 30;
         }
         //end if
         if ($this->exec_timeout > 300) {
             $this->exec_timeout = 300;
         }
         //end if
     } else {
         $this->exec_timeout = 0;
     }
     //end if else
     //--
     //--
     $this->status = 999;
     //--
     //-- log action
     if ($this->debug) {
         $this->log .= '[INF] CURL HTTP(S)/FTP Robot Browser :: Browse :: url \'' . $url . '\' @ Auth-User: '******' // Auth-Pass-Length: (' . strlen($pwd) . ') // Method: ' . $method . ' // SSLVersion: ' . $ssl_version . "\n";
         $this->log .= '[INF] CURL Protocol: ' . $this->protocol . "\n";
         $this->log .= '[INF] Connection TimeOut: ' . $this->connect_timeout . "\n";
         $this->log .= '[INF] Execution TimeOut: ' . $this->exec_timeout . "\n";
     }
     //end if
     //--
     //-- method
     $this->method = (string) strtoupper(trim((string) $method));
     //--
     //-- separations
     $this->url_parts = (array) Smart::separe_url_parts($url);
     $protocol = (string) $this->url_parts['protocol'];
     $server = (string) $this->url_parts['server'];
     $port = (string) $this->url_parts['port'];
     $path = (string) $this->url_parts['path'];
     //--
     if ($this->debug) {
         $this->log .= '[INF] Analize of the URL: ' . @print_r($this->url_parts, 1) . "\n";
     }
     //end if
     //--
     $is_ftp = false;
     $use_ssl_tls = false;
     switch ((string) $protocol) {
         case 'http://':
             break;
         case 'https://':
             $use_ssl_tls = true;
             break;
         case 'ftp://':
             $is_ftp = true;
             break;
         case 'ftps://':
             $is_ftp = true;
             $use_ssl_tls = true;
             break;
         default:
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] Unsupported URL Type: [' . $protocol . '] for URL: ' . $url . "\n";
             }
             //end if
             //--
             Smart::log_warning('LibCurlHttp(s)Ftp // GetFromURL () // Unsupported URL Type: [' . $protocol . '] for URL: ' . $url);
             //--
             return (array) $this->answer(0, $url, $ssl_version, $user);
             //--
     }
     //end switch
     //--
     //--
     if (!function_exists('curl_init')) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] PHP CURL Extension is missing' . "\n";
         }
         //end if
         //--
         Smart::log_warning('LibCurlHttp(s)Ftp // GetFromURL () // CURL Extension is missing ...');
         //--
         return (array) $this->answer(0, $url, $ssl_version, $user);
         //--
     }
     //end if
     //--
     //--
     $this->curl = @curl_init();
     // Initialise a cURL handle
     //--
     if (!$this->curl) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] PHP CURL Init Failed' . "\n";
         }
         //end if
         //--
         Smart::log_warning('LibCurlHttp(s)Ftp // GetFromURL () // CURL Init Failed ...');
         //--
         return (array) $this->answer(0, $url, $ssl_version, $user);
         //--
     }
     //end if
     //--
     if (Smart::array_size($this->rawheaders) > 0) {
         foreach ($this->rawheaders as $key => $val) {
             $this->raw_headers[] = (string) $key . ': ' . $val;
         }
         //end foreach
     }
     //end if
     //-- set allowed protocols: HTTP / HTTPS / FTP / FTPS
     @curl_setopt($this->curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP | CURLPROTO_FTPS);
     //--
     //-- set user agent
     @curl_setopt($this->curl, CURLOPT_USERAGENT, (string) $this->useragent);
     //--
     //-- timeouts
     @curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, (int) $this->connect_timeout);
     if ($this->exec_timeout > 0) {
         @curl_setopt($this->curl, CURLOPT_TIMEOUT, (int) $this->exec_timeout);
     }
     //end if
     //--
     //-- protocol
     if ((string) $this->protocol == '1.1') {
         $this->raw_headers[] = (string) 'Connection: close';
         @curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     } else {
         // 1.0
         @curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     }
     //end if else
     //--
     //-- proxy
     $is_using_proxy = false;
     if (Smart::array_size($proxy) > 0) {
         // If the $proxy variable is set, then use: $proxy['ip:port'] ; $proxy['type'] ; $proxy['auth-user'] ; $proxy['auth-pass']
         //--
         if ((string) $proxy['ip:port'] != '') {
             //--
             $pxy_type = '';
             switch ((string) strtoupper(trim((string) $proxy['type']))) {
                 case 'SOCKS4':
                     $is_using_proxy = true;
                     $pxy_type = CURLPROXY_SOCKS4;
                     break;
                 case 'SOCKS4A':
                     $is_using_proxy = true;
                     $pxy_type = CURLPROXY_SOCKS4A;
                     break;
                 case 'SOCKS5':
                     $is_using_proxy = true;
                     $pxy_type = CURLPROXY_SOCKS5;
                     break;
                 case 'SOCKS5H':
                     $is_using_proxy = true;
                     $pxy_type = CURLPROXY_SOCKS5_HOSTNAME;
                     break;
                 case 'HTTP':
                 default:
                     if ($is_ftp) {
                         $proxy['type'] = 'N/A';
                     } else {
                         $is_using_proxy = true;
                         $proxy['type'] = 'HTTP';
                     }
                     //end if
                     $pxy_type = CURLPROXY_HTTP;
             }
             //end switch
             //--
             if ($is_using_proxy) {
                 //--
                 if ($this->debug) {
                     $this->log .= '[INF] Using Proxy: ' . $proxy['ip:port'] . ' [Type: ' . $proxy['type'] . ']' . "\n";
                 }
                 //end if
                 //--
                 $this->cproxy = (array) $proxy;
                 if ((string) $this->cproxy['auth-pass'] != '') {
                     $this->cproxy['auth-pass'] = '******' . strlen($proxy['auth-pass']) . ') *****';
                 }
                 //end if
                 //--
                 @curl_setopt($this->curl, CURLOPT_PROXY, (string) $proxy['ip:port']);
                 @curl_setopt($this->curl, CURLOPT_PROXYTYPE, $pxy_type);
                 //--
                 if ((string) $proxy['auth-user'] != '') {
                     //--
                     if ($this->debug) {
                         $this->log .= '[INF] Proxy Authentication will be attempted for USERNAME = \'' . $proxy['auth-user'] . '\' ; PASSWORD(' . strlen($proxy['auth-pass']) . ') *****' . "\n";
                     }
                     //end if
                     //--
                     @curl_setopt($this->curl, CURLOPT_PROXYUSERPWD, (string) $proxy['auth-user'] . ':' . $proxy['auth-pass']);
                     //@curl_setopt($this->curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY); // this does not work at all, thus let CURL choose ...: CURLAUTH_BASIC | CURLAUTH_DIGEST
                     //--
                 }
                 //end if
                 //--
             }
             //end if
             //--
         }
         //end if
         //--
     }
     //end if
     //--
     //-- auth
     if ((string) $user != '') {
         //--
         if ($this->debug) {
             $this->log .= '[INF] Authentication will be attempted for USERNAME = \'' . $user . '\' ; PASSWORD(' . strlen($pwd) . ') *****' . "\n";
         }
         //end if
         //-- $this->raw_headers[] = 'Authorization: Basic '.base64_encode($user.':'.$pwd); // it is better to use as below as it can handle more auth types :-)
         @curl_setopt($this->curl, CURLOPT_USERPWD, (string) $user . ':' . $pwd);
         //@curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // this does not work at all, thus let CURL choose ...: CURLAUTH_BASIC | CURLAUTH_DIGEST
         //--
     }
     //end if
     //--
     //-- SSL/TLS Options
     $browser_protocol = '';
     //--
     if ($use_ssl_tls) {
         //--
         if (!function_exists('openssl_open')) {
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] PHP OpenSSL Extension is required to perform SSL requests' . "\n";
             }
             //end if
             //--
             Smart::log_warning('LibCurlHttp(s)Ftp // GetFromURL (' . $browser_protocol . $server . ':' . $port . $path . ') // PHP OpenSSL Extension not installed ...');
             //--
             return (array) $this->answer(0, $url, $ssl_version, $user);
             //--
         }
         //end if
         //--
         switch (strtolower((string) $ssl_version)) {
             case 'ssl':
                 $browser_protocol = CURL_SSLVERSION_DEFAULT;
                 // default SSL
                 break;
             case 'sslv3':
                 $browser_protocol = CURL_SSLVERSION_SSLv3;
                 // SSLv3
                 break;
             case 'tls':
             default:
                 $browser_protocol = CURL_SSLVERSION_TLSv1;
                 // TLSv1.x
         }
         //end switch
         //--
         @curl_setopt($this->curl, CURLOPT_SSLVERSION, $browser_protocol);
         //--
         if (defined('SMART_FRAMEWORK_SSL_CA_PATH')) {
             if ((string) SMART_FRAMEWORK_SSL_CA_PATH != '') {
                 @curl_setopt($this->curl, CURLOPT_CAPATH, Smart::real_path((string) SMART_FRAMEWORK_SSL_CA_PATH));
             }
             //end if
         }
         //end if
         @curl_setopt($this->curl, CURLOPT_SSL_CIPHER_LIST, (string) SMART_FRAMEWORK_SSL_CIPHERS);
         @curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, (bool) SMART_FRAMEWORK_SSL_VFY_PEER_NAME);
         // FIX: use vfy peer name instead of SMART_FRAMEWORK_SSL_VFY_HOST as there is no fine tunning here ...
         @curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, (bool) SMART_FRAMEWORK_SSL_VFY_PEER);
         // (bool)SMART_FRAMEWORK_SSL_VFY_PEER_NAME 		:: CURL is missing the option to specific allow/dissalow the peer name (allow also wildcard names *)
         // (bool)SMART_FRAMEWORK_SSL_ALLOW_SELF_SIGNED 	:: CURL is missing the option to specific allow/disallow self-signed certificates but verified above
         // (bool)SMART_FRAMEWORK_SSL_DISABLE_COMPRESS 	:: CURL is missing the option to disable SSL/TLS compression (help mitigate the CRIME attack vector)
         //--
     }
     //end if
     //--
     //-- other cURL options that are required
     @curl_setopt($this->curl, CURLOPT_HEADER, true);
     @curl_setopt($this->curl, CURLOPT_COOKIESESSION, true);
     @curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
     @curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     //--
     //--
     if (Smart::array_size($this->cookies) > 0) {
         $send_cookies = '';
         foreach ($this->cookies as $key => $value) {
             if ((string) $key != '') {
                 if ((string) $value != '') {
                     $send_cookies .= (string) SmartHttpUtils::encode_var_cookie($key, $value);
                 }
                 //end if
             }
             //end if
         }
         //end foreach
         if ((string) $send_cookies != '') {
             $this->raw_headers[] = (string) 'Cookie: ' . $send_cookies;
         }
         //end if
         $send_cookies = '';
     }
     //end if
     //--
     $have_post_vars = false;
     if (Smart::array_size($this->postvars) > 0) {
         $post_string = '';
         foreach ((array) $this->postvars as $key => $val) {
             $post_string .= (string) SmartHttpUtils::encode_var_post($key, $val);
         }
         //end foreach
         if ((string) $post_string != '') {
             if ((string) $this->method == 'GET') {
                 $this->method = 'POST';
             }
             //end if
             $have_post_vars = true;
             @curl_setopt($this->curl, CURLOPT_POSTFIELDS, (string) $post_string);
         }
         //end if
         $post_string = '';
     } elseif ((string) $this->poststring != '') {
         if ((string) $this->method == 'GET') {
             $this->method = 'POST';
         }
         //end if
         $have_post_vars = true;
         @curl_setopt($this->curl, CURLOPT_POSTFIELDS, (string) $this->poststring);
     } elseif ((string) $this->jsonrequest != '') {
         $this->raw_headers[] = 'Content-Type: application/json';
         $this->raw_headers[] = 'Content-Length: ' . strlen($this->jsonrequest);
     } elseif ((string) $this->xmlrequest != '') {
         $this->raw_headers[] = 'Content-Type: application/xml';
         $this->raw_headers[] = 'Content-Length: ' . strlen($this->xmlrequest);
     }
     //end if else
     //--
     switch ((string) $this->method) {
         case 'GET':
             break;
         case 'POST':
             if ($have_post_vars) {
                 @curl_setopt($this->curl, CURLOPT_POST, true);
             }
             //end if
             break;
         case 'HEAD':
         case 'PUT':
         case 'DELETE':
         default:
             if ($have_post_vars) {
                 @curl_setopt($this->curl, CURLOPT_POST, true);
             }
             //end if
             @curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, (string) $this->method);
     }
     //end switch
     //--
     if (Smart::array_size($this->raw_headers) > 0) {
         // request headers are constructed above
         @curl_setopt($this->curl, CURLOPT_HTTPHEADER, (array) $this->raw_headers);
     }
     //end if
     //--
     //-- Execute a Curl request
     @curl_setopt($this->curl, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
     @curl_setopt($this->curl, CURLOPT_FRESH_CONNECT, true);
     @curl_setopt($this->curl, CURLOPT_FORBID_REUSE, true);
     @curl_setopt($this->curl, CURLOPT_URL, (string) $url);
     //--
     if (!$this->curl) {
         //--
         if ($this->debug) {
             $this->log .= '[ERR] CURL Aborted before Execution' . "\n";
         }
         //end if
         //--
         Smart::log_warning('LibCurlHttp(s)Ftp // GetFromURL () // CURL Aborted before Execution ...');
         //--
         return (array) $this->answer(0, $url, $ssl_version, $user);
         //--
     }
     //end if
     //--
     $results = @curl_exec($this->curl);
     $error = @curl_errno($this->curl);
     //--
     //-- eval results
     $bw_info = array();
     $is_ok = 0;
     //--
     if ($results) {
         //--
         $is_ok = 1;
         //--
         $bw_info = (array) @curl_getinfo($this->curl);
         //--
         if ($is_ftp) {
             //--
             $this->header = 'CURL Browser :: FTP(s) have no headers ...';
             $this->body = (string) $results;
             //--
         } else {
             // http
             //--
             $hd_len = (int) $bw_info['header_size'];
             // get header length
             //--
             if ($hd_len > 0) {
                 //--
                 $this->header = (string) substr((string) $results, 0, $hd_len);
                 $this->body = (string) substr((string) $results, $hd_len);
                 //--
             } else {
                 //--
                 $this->header = (string) $results;
                 $this->body = '';
                 //--
                 $is_ok = 0;
                 //--
                 if ($this->debug) {
                     Smart::log_notice('LibCurlHttp(s)Ftp // GetFromURL () // CURL Execution Failed to Separe HTTP Header from Body. Reported (invalid) Header size is: [' . $hd_len . ']');
                     $this->log .= '[ERR] CURL Execution Failed to Separe HTTP Header from Body. Invalid Header size: [' . $hd_len . ']' . "\n";
                 }
                 //end if
                 //--
             }
             //end if else
             //--
         }
         //end if else
         //--
         $results = '';
         // free memory
         //--
         $is_unauth = false;
         if ((string) $bw_info['http_code'] == '401') {
             //--
             $is_unauth = true;
             //--
             if ($this->debug) {
                 if ((string) $user != '') {
                     $this->log .= '[ERR] HTTP Authentication Failed for URL: [User='******']: ' . $url . "\n";
                     Smart::log_notice('LibCurlHttp(s)Ftp // GetFromURL // HTTP Authentication Failed for URL: [User='******']: ' . $url);
                 } else {
                     $this->log .= '[ERR] HTTP Authentication is Required for URL: ' . $url . "\n";
                     Smart::log_notice('LibCurlHttp(s)Ftp // GetFromURL // HTTP Authentication is Required for URL: ' . $url);
                 }
                 //end if
             }
             //end if
             //--
         }
         //end if
         //--
         if ($is_unauth and $this->no_content_stop_if_unauth) {
             //--
             $this->body = '';
             // in this case (by settings) no content (response body) should be returned
             //--
         }
         //end if
         //--
         if ($error) {
             //--
             $is_ok = 0;
             //--
             if ($this->debug) {
                 $this->log .= '[ERR] CURL Execution Reported some Errors. ErrorCode: [' . $error . ']' . "\n";
                 Smart::log_notice('LibCurlHttp(s)Ftp // GetFromURL () // CURL Execution Reported some Errors. ErrorCode: [' . $error . ']');
             }
             //end if
             //--
         }
         //end if
         //--
         $this->status = (int) $bw_info['http_code'];
         //--
     } else {
         //--
         $is_ok = 0;
         //--
         $this->log .= '[ERR] CURL Returned No Results. ErrorCode: [' . $error . ']' . "\n";
         //--
     }
     //end if
     //--
     if ($is_unauth) {
         //--
         $is_ok = 0;
         //--
     }
     //end if
     //--
     //--
     $this->close_connection();
     //--
     //--
     if ($this->debug) {
         $run_time = microtime(true) - $run_time;
         $this->log .= '[INF] Total Time: ' . $run_time . ' sec.' . "\n";
     }
     //end if
     //--
     //--
     return (array) $this->answer($is_ok, $url, $ssl_version, $user, $bw_info);
     //--
 }