Advertisement
Guest User

The Pirate Bay Proxy v0.1

a guest
Feb 1st, 2012
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.77 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3.  
  4. $BaseUrl = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
  5.  
  6. $QueryString = $_SERVER["QUERY_STRING"];
  7.  
  8. if (strpos($QueryString, 'torrents.thepiratebay.org') !== false)
  9. {
  10.         preg_match('/http.*\/.*\/.*\/(.*?).torrent$$/', $QueryString, $matches);
  11.         $name = $matches[1] . '.torrent';
  12.  
  13.         $torrent = get_data($QueryString);
  14.         header("Cache-Control: public");
  15.         header("Content-Description: File Transfer");
  16.         header("Content-Disposition: attachment; filename=".$name );
  17.         header("Content-Type: application/x-bittorrent");
  18.         header("Content-Transfer-Encoding: binary");
  19.         echo $torrent;
  20.         exit;
  21. }
  22.  
  23. if (strpos($QueryString, 'q=') !== false)
  24.         $QueryString = "/s/?" . $QueryString;
  25.  
  26. $Url = get_furl("http://thepiratebay.org" . $QueryString);
  27. if (strpos($Url, 'thepiratebay.org') === false)
  28. {
  29.         header("location: " . $BaseUrl . '?' . $Url);
  30.         exit;
  31. }
  32.  
  33. $Url = "http://thepiratebay.org" . $QueryString;
  34.  
  35. $Content = get_data($Url);
  36. $Content = preg_replace('/a href="(?!magnet)(.*?)"/is', 'a href="' . $BaseUrl . '?\1"', $Content);
  37. $Content = preg_replace('/<iframe.*?>/is', '', $Content);
  38. $Content = preg_replace('/div:content -->.*?<\/html>/is', '<\/html>', $Content);
  39. $Content = preg_replace('/action="\/s\/"/si', 'action="'.$BaseUrl.'?/s/"', $Content);
  40. $Content = preg_replace('/<script type="text\/javascript">.*?<\/script>/si', '', $Content);
  41.  
  42. echo $Content;
  43.  
  44.  
  45. function get_data($url)
  46. {
  47.   $ch = curl_init();
  48.   curl_setopt($ch, CURLOPT_URL, $url);
  49.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  50.   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  51.   curl_setopt($ch, CURLOPT_HEADER, 0);
  52.   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  53.   $data = curl_exec($ch);
  54.   curl_close($ch);
  55.   return $data;
  56. }
  57.  
  58. function get_furl($url)
  59. {
  60.     $furl = false;
  61.  
  62.     // First check response headers
  63.     $headers = get_headers($url);
  64.    
  65.     // Test for 301 or 302
  66.     if(preg_match('/^HTTP\/\d\.\d\s+(301|302)/',$headers[0]))
  67.     {
  68.         foreach($headers as $value)
  69.         {
  70.             if(substr(strtolower($value), 0, 9) == "location:")
  71.             {
  72.                 $furl = trim(substr($value, 9, strlen($value)));
  73.             }
  74.         }
  75.     }
  76.     // Set final URL
  77.     $furl = ($furl) ? $furl : $url;
  78.  
  79.     return $furl;
  80. }
  81. ?>
  82. <?php
  83. error_reporting(E_ALL);
  84.  
  85. $BaseUrl = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
  86.  
  87. $QueryString = $_SERVER["QUERY_STRING"];
  88.  
  89. if (strpos($QueryString, 'torrents.thepiratebay.org') !== false)
  90. {
  91.         preg_match('/http.*\/.*\/.*\/(.*?).torrent$$/', $QueryString, $matches);
  92.         $name = $matches[1] . '.torrent';
  93.  
  94.         $torrent = get_data($QueryString);
  95.         header("Cache-Control: public");
  96.         header("Content-Description: File Transfer");
  97.         header("Content-Disposition: attachment; filename=".$name );
  98.         header("Content-Type: application/x-bittorrent");
  99.         header("Content-Transfer-Encoding: binary");
  100.         echo $torrent;
  101.         exit;
  102. }
  103.  
  104. if (strpos($QueryString, 'q=') !== false)
  105.         $QueryString = "/s/?" . $QueryString;
  106.  
  107. $Url = get_furl("http://thepiratebay.org" . $QueryString);
  108. if (strpos($Url, 'thepiratebay.org') === false)
  109. {
  110.         header("location: " . $BaseUrl . '?' . $Url);
  111.         exit;
  112. }
  113.  
  114. $Url = "http://thepiratebay.org" . $QueryString;
  115.  
  116. $Content = get_data($Url);
  117. $Content = preg_replace('/a href="(?!magnet)(.*?)"/is', 'a href="' . $BaseUrl . '?\1"', $Content);
  118. $Content = preg_replace('/<iframe.*?>/is', '', $Content);
  119. $Content = preg_replace('/div:content -->.*?<\/html>/is', '<\/html>', $Content);
  120. $Content = preg_replace('/action="\/s\/"/si', 'action="'.$BaseUrl.'?/s/"', $Content);
  121. $Content = preg_replace('/<script type="text\/javascript">.*?<\/script>/si', '', $Content);
  122.  
  123. echo $Content;
  124.  
  125.  
  126. function get_data($url)
  127. {
  128.   $ch = curl_init();
  129.   curl_setopt($ch, CURLOPT_URL, $url);
  130.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  131.   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  132.   curl_setopt($ch, CURLOPT_HEADER, 0);
  133.   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  134.   $data = curl_exec($ch);
  135.   curl_close($ch);
  136.   return $data;
  137. }
  138.  
  139. function get_furl($url)
  140. {
  141.     $furl = false;
  142.  
  143.     // First check response headers
  144.     $headers = get_headers($url);
  145.    
  146.     // Test for 301 or 302
  147.     if(preg_match('/^HTTP\/\d\.\d\s+(301|302)/',$headers[0]))
  148.     {
  149.         foreach($headers as $value)
  150.         {
  151.             if(substr(strtolower($value), 0, 9) == "location:")
  152.             {
  153.                 $furl = trim(substr($value, 9, strlen($value)));
  154.             }
  155.         }
  156.     }
  157.     // Set final URL
  158.     $furl = ($furl) ? $furl : $url;
  159.  
  160.     return $furl;
  161. }
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement