From: Roland Häder Date: Wed, 13 Jun 2012 13:33:55 +0000 (+0000) Subject: Fixes: Use instead of (old), extracted proxy hostname to variable X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0fe776675e3108d656cbf6a164c93200636966ee;p=mailer.git Fixes: Use instead of (old), extracted proxy hostname to variable --- diff --git a/inc/http-functions.php b/inc/http-functions.php index bc100696a9..2ea26e6b11 100644 --- a/inc/http-functions.php +++ b/inc/http-functions.php @@ -334,28 +334,31 @@ function sendRawRequest ($host, $request) { // Get resolver instance $resolver = new HostnameResolver(); + // Get proxy host + $proxyHost = compileRawCode(getProxyHost()); + // Open connection if (isProxyUsed() === true) { // Resolve hostname into IP address - $ip = $resolver->resolveHostname(compileRawCode(getProxyHost())); + $ip = $resolver->resolveHostname($proxyHost); // Connect to host through proxy connection - $fp = fsockopen($ip, bigintval(getProxyPort()), $errno, $errdesc, 30); + $resource = fsockopen($ip, bigintval(getProxyPort()), $errno, $errdesc, 30); } else { // Resolve hostname into IP address $ip = $resolver->resolveHostname($host); // Connect to host directly - $fp = fsockopen($ip, $port, $errno, $errdesc, 30); + $resource = fsockopen($ip, $port, $errno, $errdesc, 30); } //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ip=' . $ip . ',host=' . $host . ',isProxyUsed()=' . intval(isProxyUsed())); // Is there a link? - if (!is_resource($fp)) { + if (!is_resource($resource)) { // Failed! logDebugMessage(__FUNCTION__, __LINE__, $errdesc . ' (' . $errno . ')'); return $response; - } elseif ((!stream_set_blocking($fp, 0)) || (!stream_set_timeout($fp, 1))) { + } elseif ((!stream_set_blocking($resource, 0)) || (!stream_set_timeout($resource, 1))) { // Cannot set non-blocking mode or timeout logDebugMessage(__FUNCTION__, __LINE__, socket_strerror(socket_last_error())); return $response; @@ -364,7 +367,7 @@ function sendRawRequest ($host, $request) { // Do we use proxy? if (isProxyUsed() === true) { // Setup proxy tunnel - $response = setupProxyTunnel($host, $port, $fp); + $response = setupProxyTunnel($host, $proxyHost, $port, $resource); // If the response is invalid, abort if ((count($response) == 3) && (empty($response[0])) && (empty($response[1])) && (empty($response[2]))) { @@ -375,15 +378,15 @@ function sendRawRequest ($host, $request) { } // END - if // Write request - fwrite($fp, $request); + fwrite($resource, $request); // Start counting $start = microtime(true); // Read response - while (!feof($fp)) { + while (!feof($resource)) { // Get info from stream - $info = stream_get_meta_data($fp); + $info = stream_get_meta_data($resource); // Is it timed out? 15 seconds is a really patient... if (($info['timed_out'] == true) || (microtime(true) - $start) > 15) { @@ -395,7 +398,7 @@ function sendRawRequest ($host, $request) { } // END - if // Get line from stream - $line = fgets($fp, 128); + $line = fgets($resource, 128); // Ignore empty lines because of non-blocking mode if (empty($line)) { @@ -418,7 +421,7 @@ function sendRawRequest ($host, $request) { } // END - while // Close socket - fclose($fp); + fclose($resource); // Time request if debug-mode is enabled if (isDebugModeEnabled()) { @@ -471,13 +474,13 @@ function sendRawRequest ($host, $request) { } // Sets up a proxy tunnel for given hostname and through resource -function setupProxyTunnel ($host, $port, $resource) { +function setupProxyTunnel ($host, $proxyHost, $port, $resource) { // Initialize array $response = array('', '', ''); // Generate CONNECT request header $proxyTunnel = 'CONNECT ' . $host . ':' . $port . ' HTTP/1.0' . getConfig('HTTP_EOL'); - $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL'); + $proxyTunnel .= 'Host: ' . $proxyHost . getConfig('HTTP_EOL'); // Use login data to proxy? (username at least!) if (getProxyUsername() != '') { @@ -491,16 +494,16 @@ function setupProxyTunnel ($host, $port, $resource) { //* DEBUG: */ debugOutput('proxyTunnel=
' . $proxyTunnel.'
'); // Write request - fwrite($fp, $proxyTunnel); + fwrite($resource, $proxyTunnel); // Got response? - if (feof($fp)) { + if (feof($resource)) { // No response received return $response; } // END - if // Read the first line - $resp = trim(fgets($fp, 10240)); + $resp = trim(fgets($resource, 10240)); $respArray = explode(' ', $resp); if ((strtolower($respArray[0]) !== 'http/1.0') || ($respArray[1] != '200')) { // Invalid response!