PHP Classes
Icontem

File: proxy_class_for_php4.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrey Nikishaev  >  Little PHP Proxy  >  proxy_class_for_php4.php  
File: proxy_class_for_php4.php
Role: Class source
Content type: text/plain
Description: proxy class for php4
Class: Little PHP Proxy
Show remote pages as if they from the current site
 

Contents

Class file image Download
<?php
/*

  Little PHP Proxy V1.071

*/
class little_php_proxy {
       var 
$DOMAIN;
       var 
$POSTURL;
       var 
$PURL=array();
       var 
$RESPONSE=array();

       function 
little_php_proxy() {
             
define(HOST,$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']);
       }

       function 
close() {
               
unlink(session_id());session_destroy();header('Location: /');
       }

       function 
query($U,$POST,$GET,$FILES,$COOKIE='') {


            if(
count($POST)) {

                foreach(
$POST as $key => $value) {
                if(
$key!='u' && $key!='c'$POSTVARS.=$key."=".$value."&";
                }
                if(
$POSTVARS$posted=1;
            }

            if(
count($FILES)) {
                
$files=1;
                foreach(
$FILES as $key => $value) {
                
$POSTVARS.=$key."=@".$value['tmp_name']."&";
                }
            }

            
$POSTVARS=$POSTVARS?substr($POSTVARS,0,-1):'';

            
$U=urldecode($U);
            if(!
eregi('[.]+',$U)) $U=base64_decode($U);
            if(!
eregi('^(http|ftp|https)',$U)) $U='http://'.$U;
            
$this->POSTURL=$U;
            foreach(
$GET as $k=>$v) {
            if(
$k!='u' && $k!='c'$this->POSTURL.='&'.$k.'='.$v;
            }
            if(!
eregi('[\-_a-z0-9]+\.[\-_a-z0-9]+',$U)) die('<h1 style="font-family:Arial">Url <span  style="color:red">'.$U.'</span> is not valid.</span>');
            
            
$this->PURL=parse_url($U);
            
$this->DOMAIN=$this->PURL['host'].$this->PURL['path'];
            if(
ereg('.',$this->PURL['path'])) $this->DOMAIN=ereg_replace('/[^\/]*$','',$this->DOMAIN);
             
define(PHOST,$this->PURL['host']);
             
define(DOMAIN,$this->DOMAIN);
             
$ch curl_init($this->POSTURL);
             if(
$postedcurl_setopt($chCURLOPT_POST,                                                0);
                           
curl_setopt($chCURLOPT_VERBOSE,                                          0);
                         
curl_setopt($chCURLOPT_USERAGENT,                      $_SERVER['user-agent']);
             if(
$postedcurl_setopt($chCURLOPT_POSTFIELDS,                                $POSTVARS);
             if(
$files)  curl_setopt($chCURLOPT_UPLOAD,                                            1);
                         
curl_setopt($chCURLOPT_FOLLOWLOCATION,                                    1);
                         
curl_setopt($chCURLOPT_BINARYTRANSFER,                                     1);
                         
curl_setopt($chCURLOPT_SSL_VERIFYPEER,                                     0);
                         
curl_setopt($chCURLOPT_SSL_VERIFYHOST,                                     0);
                         
curl_setopt($chCURLOPT_REFERER,                               "http://".$this->DOMAIN);
                         
curl_setopt($chCURLOPT_CONNECTTIMEOUT,                                     0);
                         
curl_setopt($chCURLOPT_AUTOREFERER,                                        0);
                         
curl_setopt($chCURLOPT_COOKIEJAR,                       'ses_'.session_id());
                         
curl_setopt($chCURLOPT_COOKIEFILE,                       'ses_'.session_id());
                         if(
strlen($COOKIE)>0curl_setopt($chCURLOPT_COOKIE,          $COOKIE);
                         
curl_setopt($chCURLOPT_RETURNTRANSFER,                                    1);
                         
curl_setopt($chCURLOPT_FAILONERROR,                                      1);


             if(!
$this->CONTENT curl_exec($ch)) die('<h1 style="font-family:Arial">Site not exists or it has to many redirects.</span>');
            
             
$this->RESPONSE=curl_getinfo($ch);
             
curl_close($ch);
       }

       function 
getPage() {
                if(
ereg('html',$this->RESPONSE['content_type'])) {
                     
$this->get_html();
                     
$this->get_css();
             } elseif (
ereg('image',$this->RESPONSE['content_type'])){
                    
$this->get_image();
             } elseif (
ereg('javascript',$this->RESPONSE['content_type'])){
                    
$this->get_javascript();
             } elseif (
ereg('css',$this->RESPONSE['content_type'])){
                    
$this->get_css();
             } else {
                    
$this->get_file();
             }
             
header("Content-Type: ".$this->RESPONSE['content_type']);
             if(
eregi('image/([a-z]+)',$this->RESPONSE['content_type'],$type)) {
                  
$newImg imagecreatefromstring($this->CONTENT);
                 if(
$type[1]="jpeg")imagejpeg($newImg,'',100);
                 if(
$type[1]="png")imagegif($newImg,'',100);
                 if(
$type[1]="gif")imagepng($newImg,'',100);
             } else {
                 echo 
$this->CONTENT;
             }
       }

       function 
get_file() {

       }

       function 
get_image() {

       }

       function 
get_javascript() {
            
$patern=array(
            
'/([\"]+)([^\"\s]*)([\"]+)/i',
            
'/([\']+)([^\'\s]*)([\']+)/i'
             
);
            function 
replace_js($m) {
                  
$d='';
                  if(
eregi('^\/',$m[2])) {
                          
$d='http://'.PHOST;$ok=1;
                  } else {
                            if(!
eregi('^(htt|ftp)',$m[2]) && eregi('/',$m[2])) {$d='http://'.DOMAIN.'/';$ok=1;}
                  }
                  if(
$ok) {
                          return 
$m[1].'http://'.HOST.'?u='.base64_encode($d.$m[2]).$m[1];
                  } else {
                        return 
$m[1].$m[2].$m[1];
                  }

             }
            
$this->CONTENT=preg_replace_callback($patern,"replace_js",$this->CONTENT);
       }

       function 
get_css() {
              
$patern=array(
              
'/url\([\s]*[\'\"\`]?([^\)\s\'\"\`]+)[\'\"\`]?[\s]*\)/i'
              
);
              function 
replace_css($m) {
                  
$d='';
                  if(
eregi('^\/',$m[1])) {
                          
$d='http://'.PHOST;$ok=1;
                  } else {
                            if(!
eregi('^(htt|ftp)',$m[1])) {
                            
$d='http://'.DOMAIN.'/';$ok=1;
                        } else {
                            
$ok=1;
                        }
                  }

              if(
$ok) {
                      return 
'url(http://'.HOST.'?u='.base64_encode($d.$m[1]).')';
              }


             }
            
$this->CONTENT=preg_replace_callback($patern,"replace_css",$this->CONTENT);
       }

       function 
get_html() {
               
$patern=array(
            
'/[\s]+(src|href|url|location|background|action)[\s]*=[\s]*([\'\"\`])?[\s]*([^\'\"\`\s>]+)([\'\"\`>])?/i',
            
'/([\"]+)(\/[^\"\s]*)([\"]+)/i',
            
'/([\']+)(\/[^\'\s]*)([\']+)/i'
             
);
             function 
replace_html($m) {
              
$d='';
            if(
$m[1]=='"' || $m[1]=="'") {
            if(
eregi('^\/',$m[2])) {
                  
$d='http://'.PHOST;$ok=1;
              } else {
                    if(!
eregi('^(htt|ftp)',$m[2]) && eregi('/',$m[2])) {$d='http://'.DOMAIN.'/';$ok=1;}
              }
             if(
$ok) {return $m[1].'http://'.HOST.'?u='.base64_encode($d.$m[2]).$m[1];}
                else {
                    return 
$m[1].$m[2].$m[1];
            }

            } else {
              if(
$m[4]=='>'$e=">";
              if(
eregi('^\/',$m[3])) {
                  
$d='http://'.PHOST;
             } else {
                    if(!
eregi('^(htt|ftp)',$m[3])) $d='http://'.DOMAIN.'/';
              }
            if(!
ereg('^java',$m[3])) {
                    return 
' '.$m[1].'="http://'.HOST.'?u='.base64_encode($d.$m[3]).'"'.$e;
            } else {
                    return 
' '.$m[1].'="'.$m[3].'"';
            }
            }
             }
             
$this->CONTENT=preg_replace_callback($patern,'replace_html',$this->CONTENT);
       }
}

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products