Sorry.. there was a bug introduced by the unwinding of previous versions of the php highlighter. I think this fixes it
Code: Select all
<?php
ini_set( 'display_errors', '1' );
error_reporting( E_ALL );
if( !defined( '_DEBUG_' ) ) define( '_DEBUG_', 0 );
if(!empty($_GET['url']))
{
$get = trim($_GET['url']);
if(empty($get))
$_GET['url'] = '';
elseif( !preg_match('#^[a-zA-Z]{3,}://#',$_GET['url']))
$_GET['url'] = 'http://' . $_GET['url'];
}
$output = "<html>\n\t<head>\n\t\t<title>{PAGE_TITLE}</title>\n\t</head>\n\t<body>\n\t\t<div align=\"center\"><form><input type=\"text\" name=\"url\" value=\"".(isset($_GET['url'])?$_GET['url']:'')."\" size=\"50\"><input type=\"submit\" value=\" get \"></form><div>";
if( !empty($_GET['inline']) && !empty( $_GET['url'] ) && ( $data = @getimagesize( $_GET[ 'url' ] ) ) !== false )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$header = '<fieldset><legend style="font-family:sans-serif"> Headers </legend><pre style="text-align:left">%s</pre></fieldset>';
$arr = preg_split("#\n#sS",$raw = curl_exec($ch));
for($x = 0, $y = sizeof($arr); $x < $y; $x++)
{
$arr[$x] = rtrim($arr[$x]);
if(!empty($arr[$x]) && !isset($found))
$headers[] = $arr[$x];
elseif(!empty($arr[$x]))
$data[] = $arr[$x];
else
$found = $x;
}
$headers = sprintf($header,htmlentities(implode("\n",$headers),ENT_QUOTES));
$output .= $headers.'<fieldset><legend style="font-family:sans-serif"> Image </legend><img src="' . $_GET['url'] . '" /></fieldset>' . "\n\t\t";
$output = str_replace('{PAGE_TITLE}', $data['mime'] . ' :: ' . $_GET['url'], $output);
}
elseif(!empty($_GET['inline']))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
}
elseif(!empty($_GET['url']))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//$data = file_get_contents( $_GET[ 'url' ] );
$header = '<fieldset><legend style="font-family:sans-serif"> Headers </legend><pre style="text-align:left">%s</pre></fieldset>';
$arr = preg_split("#\n#sS",$raw = curl_exec($ch));
for($x = 0, $y = sizeof($arr); $x < $y; $x++)
{
$arr[$x] = rtrim($arr[$x]);
if(!empty($arr[$x]) && !isset($found))
$headers[] = $arr[$x];
elseif(!empty($arr[$x]))
$data[] = $arr[$x];
else
$found = $x;
}
$headers = sprintf($header,htmlentities(implode("\n",$headers),ENT_QUOTES));
$data = implode("\n",$data);
curl_close($ch);
if(preg_match('#<\s*title.*?>(.*?)<\s*/\s*title.*?>#is',$data,$title))
{
$output = str_replace('{PAGE_TITLE}', $_GET['url'] . ' :: ' . $title[1], $output);
}
else
{
$output = str_replace('{PAGE_TITLE}', 'No page title', $output);
}
$urls = array( 'href', 'src', 'action', 'background' ); // resolve these attributes from the text
$urls = implode( '|', $urls );
preg_match_all( '#\s+?(' . $urls . ')\s*?=\s*?([\'"]?)(.*?)\\2[\s\>]#is', $data, $matches );
$data = htmlentities( $data, ENT_QUOTES );
$site = $_GET[ 'url' ];
$bits = parse_url( $site );
$root = $bits[ 'scheme' ] . '://' .
( isset( $bits[ 'user' ] ) ? $bits[ 'user' ] : '' ) .
( isset( $bits[ 'password' ] ) ? ':' . $bits[ 'password' ] : '' ) .
( isset( $bits[ 'user' ] ) ? '@' : '' ) .
$bits[ 'host' ] .
( isset( $bits[ 'port' ] ) ? ':' . $bits[ 'port' ] : '' );
$path = (isset($bits[ 'path' ]) ? explode( '/', $bits[ 'path' ] ) : array());
array_pop( $path );
$path = $root . implode( '/', $path ) . '/';
if( _DEBUG_ )
$output .= '<div align="left"><pre>' . var_export($matches, true) . '</pre></div>';
$pos = 0;
foreach($matches[0] as $match)
{
$url = $matches[ 3 ][ $pos ];
if(!empty($url))
{
list( $left, $right ) = explode( $url, $match );
$left = htmlentities( $left, ENT_QUOTES );
$right = htmlentities( $right, ENT_QUOTES );
//echo $left . $right . "<br />";
if( preg_match( '#://#', $url ) )
{ // full url
$newurl = $url;
}
elseif( $url{0} == '/' )
{ // literal
$newurl = $root . $url;
}
elseif( preg_match( '#^[a-z0-9_-]+:#i', $url ) )
{
$pos++;
continue;
}
else
{
$newurl = $path . $url;
}
$data = preg_replace( '^' . preg_quote( htmlentities( $match, ENT_QUOTES ), '^' ) .'^', $left . '<a href="' . $_SERVER['SCRIPT_NAME'] . '?url=' . urlencode( $newurl ) .'">' . $url . '</a>' . $right, $data, 1 );
}
$pos++;
}
$output .= $headers.'<fieldset><legend style="font-family:sans-serif"> HTML </legend><pre style="text-align:left">' . $data . '</pre></fieldset>' . "\n\t\t";
$output .= '<fieldset><legend style="font-family:sans-serif"> Page </legend><iframe src="' . $_SERVER['SCRIPT_NAME'] . '?inline=1&url=' . urlencode($url) . '" width="100%" height="100%">iframe required</iframe></fieldset>';
}
else
$output = str_replace('{PAGE_TITLE}' , 'Welcome to feyd\'s Page Source Browser', $output);
$output .= "</div>\n\t</body>\n</html>";
echo $output;
?>