Index: t3lib/class.t3lib_div.php =================================================================== RCS file: /cvsroot/typo3/TYPO3core/t3lib/class.t3lib_div.php,v retrieving revision 1.95 diff -u -r1.95 class.t3lib_div.php --- t3lib/class.t3lib_div.php 12 Apr 2006 19:42:41 -0000 1.95 +++ t3lib/class.t3lib_div.php 25 Apr 2006 19:30:41 -0000 @@ -2300,20 +2300,27 @@ * * @param string Filepath/URL to read - * @param integer Whether the HTTP header should be fetched or not. 0=disable, 1=fetch header+content, 2=fetch header only (will be ignored when using CURL) + * @param integer Whether the HTTP header should be fetched or not. 0=disable, 1=fetch header+content + * @param array HTTP headers to be used in the request * @return string The content from the resource given as input. */ - function getURL($url, $includeHeader=0) { - $content = ''; + function getURL($url, $includeHeader = 0, $requestHeaders = false) { + $content = false; // (Proxy support implemented by Arco ) - if ((substr($url,0,7)=='http://') && ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse']=='1')) { + if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlUse'] == '1' && preg_match('/^https?:\/\//', $url)) { // External URL without error checking. $ch = curl_init(); - if (!$ch) { return false; } - - curl_setopt ($ch,CURLOPT_URL, $url); - curl_setopt ($ch,CURLOPT_HEADER, $includeHeader?1:0); - curl_setopt ($ch,CURLOPT_RETURNTRANSFER, 1); + if (!$ch) { + return false; + } + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, $includeHeader ? 1 : 0); + curl_setopt($ch, CURLOPT_NOBODY, $includeHeader == 2 ? 1 : 0); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + if (is_array($requestHeaders)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $requestHeaders); + } if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']) { curl_setopt ($ch, CURLOPT_PROXY, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer']); @@ -2326,37 +2333,61 @@ curl_setopt ($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] ); } } - $content=curl_exec ($ch); - curl_close ($ch); - - } elseif ($includeHeader) { + $content = curl_exec($ch); + curl_close($ch); + } elseif ($includeHeader) { $parsedURL = parse_url($url); - if (!t3lib_div::inList('ftp,ftps,http,https,gopher,telnet', $parsedURL['scheme'])) { return false; } - - $fp = @fsockopen($parsedURL['host'], ($parsedURL['port']>0 ? $parsedURL['port'] : 80), $errno, $errstr, $timeout=2); - if (!$fp) { return false; } - - $msg = 'GET '.$parsedURL['path'].($parsedURL['query'] ? '?'.$parsedURL['query'] : '')." HTTP/1.0\r\nHost: ".$parsedURL['host']."\r\n\r\n"; - fputs ($fp, $msg); + if (!t3lib_div::inList('ftp,ftps,http,https,gopher,telnet', $parsedURL['scheme'])) { + return false; + } + + $fp = @fsockopen($parsedURL['host'], ($parsedURL['port'] > 0 ? $parsedURL['port'] : 80), $errno, $errstr, 2.0); + if (!$fp) { + return false; + } + + $msg = 'GET ' . $parsedURL['path'] . + ($parsedURL['query'] ? '?' . $parsedURL['query'] : '') . + ' HTTP/1.0' . chr(13) . chr(10) . 'Host: ' . + $parsedURL['host'] . chr(13) . chr(10) . chr(13) . chr(10); + fputs($fp, $msg); while (!feof($fp)) { - $line = fgets ($fp,2048); - $content.=$line; - if ($includeHeader==2 && !strlen(trim($line))) { break; } // Stop at the first empty line (= end of header) - } - fclose ($fp); - - } elseif (function_exists('file_get_contents')) { - $content = @file_get_contents($url); - - } elseif ($fd = @fopen($url,'rb')) { - while (!feof($fd)) { - $content.=fread($fd, 4096); - } - fclose($fd); - - } else { - return false; - } + $line = fgets($fp, 2048); + $content = $line; + if ($includeHeader == 2 && !strlen(trim($line))) { + // Stop at the first empty line (= end of header) + break; + } + } + fclose($fp); + } else if (is_array($requestHeaders) && function_exists('stream_context_create')) { + $ctx = stream_context_create(array( + 'http' => array( + 'header' => implode(chr(13) . chr(10), $requestHeaders) + ) + ) + ); + if (false !== ($fd = @fopen($url, 'rb', false, $ctx))) { + $content = ''; + while (!feof($fd)) { + $content .= fread($fd, 4096); + } + fclose($fd); + } + elseif (function_exists('file_get_contents')) { + $content = @file_get_contents($url, $ctx); + } + } + else if (false !== ($fd = @fopen($url, 'rb'))) { + $content = ''; + while (!feof($fd)) { + $content .= fread($fd, 4096); + } + fclose($fd); + } + elseif (function_exists('file_get_contents')) { + $content = @file_get_contents($url); + } return $content; } Index: typo3/sysext/cms/tslib/class.tslib_fe.php =================================================================== RCS file: /cvsroot/typo3/TYPO3core/typo3/sysext/cms/tslib/class.tslib_fe.php,v retrieving revision 1.107 diff -u -r1.107 class.tslib_fe.php --- typo3/sysext/cms/tslib/class.tslib_fe.php 23 Apr 2006 16:13:26 -0000 1.107 +++ typo3/sysext/cms/tslib/class.tslib_fe.php 25 Apr 2006 19:30:51 -0000 @@ -1298,8 +1298,25 @@ } exit; } elseif (strlen($code)) { - header('Location: '.t3lib_div::locationHeaderUrl($code)); - exit; + // Check if URL is relative + $url_parts = parse_url($code); + if ($url_parts['host'] == '') { + $url_parts['host'] = t3lib_div::getIndpEnv('HTTP_HOST'); + $code = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . $code; + } + // Prepare headers + $headers = array( + 'Referer: ' . t3lib_div::getIndpEnv('HTTP_USER_AGENT'), + 'User-agent: ' . t3lib_div::getIndpEnv('TYPO3_REQUEST_URL') + ); + if (false === ($content = t3lib_div::getURL($code, 0, $headers))) { + // Last chance -- redirect + header('Location: '.t3lib_div::locationHeaderUrl($code)); + } + else { + echo $content; + } + exit; } else { $this->printError('Error.'.($reason ? ' Reason: '.htmlspecialchars($reason) : '')); exit;