URL = $URL; $this->currentServer = $currentServer; $this->static = $static; $this->relDir = $relDir; $this->pageData = ""; $this->varName = $varName; $this->scriptName = $scriptName; } /*openLink***************************************\ * Function for connecting to the URL and getting * * the headers. * * * * Note: The connection is closed by * * getRawPageData or processPage, whichever comes * * first. * \************************************************/ function openLink(){ $this->fp = fopen($this->URL, "rb"); array_shift($http_response_header); $this->headers = $http_response_header; } /*getHeaders*************************************\ * Function returns an array containing the * * headers that resulted from the page. * \************************************************/ function getHeaders(){ return $this->headers; } /*getRawPageData*********************************\ * Prints out the $fp as a stream without * * processing (for images/such) * \************************************************/ function getRawPageData(){ fpassthru($this->fp); fclose($this->fp); return; } /*getPageData************************************\ * Function returns a string containing the * * page data. processPageData must be used * * before this function is called. * \************************************************/ function getPageData(){ return $this->updatedPageData; } /*processPageData********************************\ * Function process the page, fixing links and * * images to use the proxy as specified by the * * class. * * * * Note: Add items here if you want to add extra * * prefixes or delims. * \************************************************/ function processPageData(){ $this->pageData = ""; while( !feof( $this->fp)){ $this->pageData .= fgets($this->fp, 4096); } fclose($this->fp); $delim[]='"'; $delim[]="'"; $delim[]=""; $pre[]="src="; $pre[]="background="; $pre[]="href="; $pre[]="url\("; $pre[]="codebase="; $pre[]="url="; $pre[]="archive="; $this->redirect($pre,$delim); } /*fileName***************************************\ * Function returns the name of the file that the * * URL specifies. * \************************************************/ function fileName(){ return eregi_replace("[#?].*$", "", eregi_replace("^.*/", "", $this->URL)); } /*encodeHTML*************************************\ * Fix Me: * * This is not done yet but the idea is to change * * all the html charcters to their special char * * information (to keep people from stealing your * * source and using it) * \************************************************/ function encodeHTML(){ // Not Done Yet } /*encryptPage************************************\ * Function changes updatedPageData so that the * * file is encrypted while sending. * \************************************************/ function encryptPage(){ $data2 = ""; foreach (split("\n",eregi_replace("\r","",$this->updatedPageData)) as $a){ $data = $this->encrypt(chop($a)); $data = str_replace( "\\", "\\\\", $data); $data = str_replace( "\"", "\\\"", $data); $data2 .= "document.write( c(\"".$data."\") );\n"; } $this->updatedPageData = "" . "\n" . "\n"; } /*redirect***************************************\ * Private Function, DO NOT USE FROM PUBLIC SCOPE * * Basically converts the prefixes in * * $prefixArray and the delim in $delimArray to a * * string and uses it to fix links within the * * page. * \************************************************/ function redirect($prefixArray,$delimArray){ $a = $this->pageData; $name = $this->currentServer; $fileDir = $this->relDir; foreach($prefixArray as $prefix){ $start2 = stripslashes($prefix); $start = $prefix . "[ ]*"; foreach($delimArray as $delim){ if(eregi($prefix . "[ ]*" . $delim, $a) && ($delim == "" ? eregi($prefix . "[ ]*" . "[a-z,A-Z,/,0-9]", $a) : 1)){ $a = eregi_replace($start . $delim . "//", $start2 . '\a' . "//", $a); $a = eregi_replace($start . $delim . "/", $start2 . $delim . $name . "/" . $this->scriptName . "?" . $this->varName . "=/", $a); $a = eregi_replace($start . $delim . "http://", $start2 . '\a' . "http://", $a); $a = eregi_replace($start . $delim . "mailto:", $start2 . '\a' . "mailto:", $a); $a = eregi_replace($start . $delim . "#", $start2 . '\a' . "#", $a); $a = eregi_replace($start . $delim . "javascript:", $start2 . '\a' . "javascript:", $a); $a = eregi_replace($start . $delim, $start2 . $delim . $name . "/" . $this->scriptName . "?" . $this->varName . "=" . $fileDir , $a); $a = eregi_replace($start . '[\]a', $start2 . $delim, $a); } } } $this->updatedPageData = $a; } /*encrypt****************************************\ * This function encrypts the page before it is * * sent out. * * Returns the file as a string, encrypted * \************************************************/ function encrypt( $string ){ for( $i = 0; $i < strlen( $string ) - 1; $i += 2 ){ $temp = $string[$i]; $string[$i] = $string[$i+1]; $string[$i+1] = $temp; } return $string; } } ?>