PHP Code:
<?php
// A proxy class for creating a proxy to bypass a filter
class jproxy {
protected $proxyBaseUrl = NULL;
protected $currentUrl = NULL;
protected $pageDomain = NULL;
protected $fullContentType = NULL;
protected $contentType = NULL;
protected $html = NULL;
function __construct($baseUrl) {
$this->setBaseUrl($baseUrl);
}
function setBaseUrl($url) {
$this->proxyBaseUrl = $url;
}
function setUrl($url) {
$this->currentUrl = $url;
}
function getUrl() {
return $this->currentUrl;
}
function fetchHtml() {
if(!$this->getUrl()) {
// no url to grab html for
return false;
}
//
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_URL, $this->getUrl());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $GLOBALS['cookieFile']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $GLOBALS['cookieFile']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($_POST) {
$count = 1;
foreach($_POST as $key => $val) {
$headers .= $key.'='.$val;
if($count != count($_POST)) {
$headers .= "&";
}
$count++;
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $headers);
}
/*foreach($_GET as $key => $val) {
if($key != 'url') {
echo $key . " => " . $val . "<br />";
}
}*/
$this->html = curl_exec($ch);
$this->fullContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
preg_match( '@([\w/+]+)(;\s+charset=(\S+))?@i', $this->fullContentType, $matches );
if(isset($matches[1])) {
$this->contentType = $matches[1];
}
curl_close($ch);
}
function getDomain() {
if($this->pageDomain) {
return $this->pageDomain;
}
else {
preg_match('/http:\/\/(www\.)?([^\/]+)/', $this->currentUrl, $matches);
return "http://".$matches[2]."/";
}
}
protected function modifyHref($url) {
// is a css or favicon file?
if(stripos($url, '.css') || stripos($url, 'style.php') || strpos($url, 'favicon.ico')) {
if(substr($url, 0, 7) == 'http://') {
$new = "href=\"".$this->proxyBaseUrl."?url=".$url."\"";
}
else {
$new = "href=\"".$this->proxyBaseUrl."?url=".$this->getDomain().$url."\"";
}
}
else {
if(substr($url, 0, 7) == 'http://') {
$new = "href=\"".$this->proxyBaseUrl."?url=".$url."\"";
} else {
$new = "href=\"".$this->proxyBaseUrl."?url=".$this->getDomain().$url."\"";
}
}
//$new = str_replace('//','/',$new);
return $new;
}
protected function modifySrc($text) {
if(substr($text, 0, 7) == 'http://') {
$new = "src=\"".$this->proxyBaseUrl."?url=".$text."\"";
} else {
$new = "src=\"".$this->proxyBaseUrl."?url=".$this->getDomain()."/".$text."\"";
}
//$new = str_replace('//','/',$new);
return $new;
}
protected function modifyActions($text) {
if(substr($text, 0, 7) == 'http://')
{
$new = "action=\"".$this->proxyBaseUrl."?url=".$text."\"";
}
else
{
$new = "action=\"".$this->proxyBaseUrl."?url=".$this->getDomain().$text."\"";
}
//$new = str_replace('//','/',$new);
return $new;
}
protected function modifyFlash($text) {
if(substr($text, 0, 7) == 'http://') {
$new = "<param value=\"".$this->proxyBaseUrl."?url=".$text."\"";
}
else {
"<param value=\"?url=".$this->proxyBaseUrl."?url=".$this->getDomain().$text."\"";
}
//$new = str_replace("//","/", $new);
return $new;
}
protected function getExtension() {
preg_match('/\.([^.]+)$/', $this->currentUrl, $matches);
return $matches[0];
}
protected function stripShit() {
$return = str_replace('/','',$this->currentUrl);
$return = str_replace(':','',$return);
$return = str_replace('.','',$return);
return $return;
}
protected function modifyForm($whole, $formAttr, $content) {
$content = '\n\n<!--INSERTED FORM ELEMENT BY PROXY -->\n';
$content .= '<input type=\"hidden\" name=\"url_204s52bg\" value=\"\" />';
$whole = str_replace($content, $myForm.$content, $whole);
return $whole;
}
protected function modifyInlineStyles($props,$content) {
$content = $this->modifyCssLocations($content);
return "<style".$props.">".$content."</style>";
}
protected function modifyLocations() {
// replace href (links, stylesheets, etc.)
$this->html = preg_replace('/href=(\'|")(.+?)\1/ie', '$this->modifyHref("$2")', $this->html);
// replace src (images, etc.)
$this->html = preg_replace('/src=(\'|")(.+?)\1/ie', '$this->modifySrc("$2")', $this->html);
// replace form actions
$this->html = preg_replace('/action=("|\')(.+?)\1/ie', '$this->modifyActions("$2")', $this->html);
// add form url thing
//$this->html = preg_replace('/(<form(.?)>(.?)<\/form>)/', '$this->modifyForm("$1","$2","$3")', $this->hrml);
// replace flash paths
$this->html = preg_replace('/<param value=("|\')(.+?)\1/ie', '$this->modifyFlash("$2")', $this->html);
// replace any @imports in inline stylesheets
$this->html = preg_replace('/<style([^>]*)>(.+?)<\/style>/ie', '$this->modifyInlineStyles("$1","$2")', $this->html);
$this->html = stripslashes($this->html);
}
private function modifyCssUrl($url) {
if(substr($url, 0, 7) == 'http://') {
$return = $this->proxyBaseUrl.'?url='.$url;
}
else {
$return = $this->proxyBaseUrl.'?url='.$this->getDomain().$url;
}
return 'url('.$return.')';
}
private function modifyCssImport($file) {
if(substr($url, 0, 7) == 'http://') {
$return = $this->proxyBaseUrl.'?url='.$file;
}
else {
$return = $this->proxyBaseUrl.'?url='.$this->getDomain().$file;
}
return '@import "'.$return.'";';
}
private function modifyCssLocations($content) {
$content = preg_replace('/url\((.+?)\)/ie', '$this->modifyCssUrl("$1")', $content);
// replace imports
$content = preg_replace('/@import(|\s)(\'|")(.+?)\2;/ie','$this->modifyCssImport("$3")', $content);
return $content;
}
function getHtml() {
return $this->html;
}
function getFormattedPage() {
if(
($this->contentType != NULL) && (stripos($this->contentType,'text/html') === false || stripos($this->contentType,'application/xhtml') != false)
) {
header("Content-Type: ".$this->fullContentType);
if(stripos($this->contentType,'css')) {
// css file, modify that *****
$this->html = $this->modifyCssLocations($this->html);
}
}
else {
// we only want to modify locations if it's a regular old webpage
$this->modifyLocations();
}
//$this->modifyLocations();
return $this->html;
}
}
?>
And I used the class like so:
Bookmarks