pat_raw_http_request.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 12k
Category:

WEB Mail

Development Platform:

PHP

  1. <?php
  2. /*
  3.  * adapted from Manuel Lemos test page
  4.  *
  5.  */
  6.  
  7. include('./config.php');
  8. $pat_default_ua = 'PAT Http Raw Request by Manuel Lemos - Jean philippe Giot';
  9. /*****************************************************************************
  10.  *
  11.  *
  12.  *  PARSING POST VALUES
  13.  *
  14.  *
  15.  *****************************************************************************/
  16.  
  17. $submit     = $_POST['submit'];
  18. // look for each parameter values from the web and then their defaut
  19. // parse a given url into it's components
  20. if ($submit == 'parse')
  21. {
  22.     // we extract all components from url
  23.     // note : only works with GET requests...
  24.     // this is not affected by an url
  25.     $user_agent = ($_POST['user_agent'])? $_POST['user_agent'] : $pat_default_ua;
  26.     $proxyname  = $_POST['proxyname'];
  27.     $proxyport  = $_POST['proxyport'];    
  28.     $h_no_cache = $_POST['h_no_cache'];
  29.     $request_method = "GET";    
  30.     
  31.     
  32.     $url_components = parse_url($_POST['url2parse']);
  33.     
  34.     
  35.     $hostname   = $url_components['host'];
  36.     $hostport   = $url_components['port'];
  37.     $uri        = $url_components['path'];
  38.     
  39.     // parsing query
  40.     $arguments = explode('&',$url_components['query']);
  41.     
  42.     //var_dump($arguments);
  43.     
  44.     if (@count($arguments))
  45.     {
  46.         $i=1;
  47.         foreach ($arguments as $num => $compressed_arg)
  48.         {
  49.             list($key,$val) = explode('=',$compressed_arg);
  50.             
  51.             $url_arguments_gp['cgv_key_'.$i]    = urldecode($key);
  52.             $url_arguments_gp['cgv_value_'.$i]  = urldecode($val);
  53.             $client_gv[$i] = true;
  54.             $i++;
  55.         }
  56.         $last_known_gv = $i;
  57.     }
  58.     
  59.     //var_dump($url_arguments_gp);
  60.     
  61.     // mapping POST values for get and post arguments
  62.     
  63.     // no need, it already has been done
  64.     // $url_arguments_gp = 
  65.     
  66. }
  67. else
  68. {
  69.     $user_agent = ($_POST['user_agent'])? $_POST['user_agent'] : $pat_default_ua;
  70.     $hostname   = ($_POST['hostname'])? $_POST['hostname'] : "localhost";
  71.     $hostport   = ($_POST['hostport'])? $_POST['hostport'] : "80";
  72.     $proxyname  = $_POST['proxyname'];
  73.     $proxyport  = $_POST['proxyport'];
  74.     $uri        = ($_POST['uri'])? $_POST['uri'] : "/";
  75.     if (strpos($uri,'?'))
  76.         $uri    = substr ($uri,0,strpos($uri,'?'));
  77.     $h_no_cache = $_POST['h_no_cache'];
  78.     $request_method = ($_POST['request_method'])? $_POST['request_method'] : "GET";
  79.     // mapping POST values for get and post arguments
  80.     
  81.     $url_arguments_gp = $_POST;
  82.     
  83. }
  84. $last_known_cookie = 0;
  85. $get_params_string = '?';
  86. foreach ($_POST as $key => $value)
  87. {
  88.     if ('ccookie' == substr($key,0,strlen('ccookie')))
  89.     {
  90.         if ($value)
  91.         {
  92.             $parts   = explode('_',$key);
  93.             $ckey    = $parts[1];
  94.             $cnumber = $parts[2];
  95.         
  96.             $client_cookies[$cnumber][$ckey]=$value;
  97.             if ($cnumber > $last_known_cookie) $last_known_cookie = $cnumber;
  98.         }
  99.     }
  100.     
  101.     if ('cpv' == substr($key,0,strlen('cpv')))
  102.     {
  103.         if ($value)
  104.         {
  105.             $parts   = explode('_',$key);
  106.             $ckey    = $parts[1];
  107.             $cnumber = $parts[2];
  108.             $tmp_post[$cnumber][$ckey] = $value;
  109.         
  110.             $client_pv[$cnumber]=true;
  111.             if ($cnumber > $last_known_pv) $last_known_pv = $cnumber;
  112.         }
  113.     }
  114.     if ('cgv' == substr($key,0,strlen('cgv')))
  115.     {
  116.         if ($value)
  117.         {
  118.             $parts   = explode('_',$key);
  119.             $ckey    = $parts[1];
  120.             $cnumber = $parts[2];
  121.             $tmp_get[$cnumber][$ckey] = $value;
  122.         
  123.             $client_gv[$cnumber]=true;
  124.             if ($cnumber > $last_known_gv) $last_known_gv = $cnumber;
  125.         }
  126.     }    
  127. }
  128. // adding always a new cookie and a last post value
  129. $client_cookies[($last_known_cookie+1)] = true;
  130. $client_pv[($last_known_pv+1)] = true;
  131. $client_gv[($last_known_gv+1)] = true;
  132. /*****************************************************************************
  133.  *
  134.  *
  135.  *  BUILDING OUTPUT
  136.  *
  137.  *
  138.  *****************************************************************************/
  139. send_execute_header('Raw Http Request');
  140. ?><body>
  141. <form method=post action="pat_raw_http_request.php">
  142. <table>
  143. <tr>
  144.   <th>Parse Url</th>
  145.   <td><input type="text" name="url2parse" value="" style="width:300px"></td>
  146. </tr>
  147. <tr>
  148.   <td colspan=2 align=center><input type="submit" name="submit" value="parse"></td>
  149. </tr>
  150. <tr>
  151.   <td colspan=2>&nbsp;</td>
  152. </tr>
  153. <tr>
  154.   <th>Host Name</th>
  155.   <td><input type="text" name="hostname" value="<?php echo $hostname; ?>" style="width:300px"></td>
  156. </tr>
  157. <tr>
  158.   <th>Host Port</th>
  159.   <td><input type="text" name="hostport" value="<?php echo $hostport; ?>" style="width:300px"></td>
  160. </tr>
  161. <tr>
  162.   <th>Proxy Name</th>
  163.   <td><input type="text" name="proxyname" value="<?php echo $proxyname; ?>" style="width:300px"></td>
  164. </tr>
  165. <tr>
  166.   <th>Proxy Port</th>
  167.   <td><input type="text" name="proxyport" value="<?php echo $proxyport; ?>" style="width:300px"></td>
  168. </tr>
  169. <tr>
  170.   <th>URI</th>
  171.   <td><input type="text" name="uri" value="<?php echo $uri; ?>" style="width:300px"></td>
  172. </tr>
  173. <tr>
  174.   <th>Request Method</th>
  175.   <td><input type="radio" name="request_method" value="GET"<?php if($request_method == 'GET') echo ' checked'; else echo ''; ?>> GET 
  176.   <input type="radio" name="request_method" value="POST"<?php if($request_method == 'POST') echo ' checked'; else echo ''; ?>> POST 
  177.   </td>
  178. </tr>
  179. <tr>
  180.   <th>User Agent</th>
  181.   <td><input type="text" name="user_agent" value="<?php echo $user_agent; ?>" style="width:300px"></td>
  182. </tr>
  183. <tr>
  184.   <th>Header : no cache</th>
  185.   <td><input type="checkbox" name="h_no_cache" value="1"<?php if($h_no_cache) echo ' checked'; else echo ''; ?>></td>
  186. </tr>
  187. <?php
  188. /*
  189.  * COOKIES Values
  190.  */
  191. for($i=1;$i<=count($client_cookies);$i++)
  192. {
  193.     echo "<tr>n";
  194.     echo "  <th colspan=2>Cookie $i</th>n";
  195.     echo "</tr>n";
  196.     echo "<tr>n";
  197.     echo "  <td>Name</td>n";
  198.     echo "  <td><input type="text" name="ccookie_name_$i" value="".$_POST['ccookie_name_'.$i]."" style="width:300px"></td>n";
  199.     echo "</tr>n";
  200.     echo "<tr>n";
  201.     echo "  <td>Value</td>n";
  202.     echo "  <td><input type="text" name="ccookie_value_$i" value="".$_POST['ccookie_value_'.$i]."" style="width:300px"></td>n";
  203.     echo "</tr>n";
  204.     echo "<tr>n";
  205.     echo "  <td>Expire Date</td>n";
  206.     echo "  <td><input type="text" name="ccookie_expire_$i" value="".$_POST['ccookie_expire_'.$i]."" style="width:300px"></td>n";
  207.     echo "</tr>n";
  208.     echo "<tr>n";
  209.     echo "  <td>Domain</td>n";
  210.     echo "  <td><input type="text" name="ccookie_domain_$i" value="".$_POST['ccookie_domain_'.$i]."" style="width:300px"></td>n";
  211.     echo "</tr>n";
  212.     echo "<tr>n";
  213.     echo "  <td>Secure</td>n";
  214.     echo "  <td><input type="text" name="ccookie_secure_$i" value="".$_POST['ccookie_secure_'.$i]."" style="width:300px"></td>n";
  215.     echo "</tr>n";
  216.     if ($i == count($client_cookies))
  217.     {
  218.         echo "<tr>n";
  219.         echo "  <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
  220.         echo "</tr>n";     
  221.     }
  222. }
  223. /*
  224.  * POST Values
  225.  */
  226. for($i=1;$i<=count($client_pv);$i++)
  227. {
  228.     echo "<body bgcolor='#CFE3E3'><tr>n";
  229.     echo "  <th colspan=2>Post Value $i</th>n";
  230.     echo "</tr>n";
  231.     echo "<tr>n";
  232.     echo "  <td>Name</td>n";
  233.     echo "  <td><input type="text" name="cpv_key_$i" value="".$url_arguments_gp['cpv_key_'.$i]."" style="width:300px"></td>n";
  234.     echo "</tr>n";
  235.     echo "<tr>n";
  236.     echo "  <td>Value</td>n";
  237.     echo "  <td><input type="text" name="cpv_value_$i" value="".$url_arguments_gp['cpv_value_'.$i]."" style="width:300px"></td>n";
  238.     echo "</tr>n";
  239.     if ($i == count($client_pv))
  240.     {
  241.         echo "<tr>n";
  242.         echo "  <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
  243.         echo "</tr>n";     
  244.     }
  245. }
  246. /*
  247.  * GET Values
  248.  */
  249. for($i=1;$i<=count($client_gv);$i++)
  250. {
  251.     echo "<tr>n";
  252.     echo "  <th colspan=2>Get Value $i</th>n";
  253.     echo "</tr>n";
  254.     echo "<tr>n";
  255.     echo "  <td>Name</td>n";
  256.     echo "  <td><input type="text" name="cgv_key_$i" value="".$url_arguments_gp['cgv_key_'.$i]."" style="width:300px"></td>n";
  257.     echo "</tr>n";
  258.     echo "<tr>n";
  259.     echo "  <td>Value</td>n";
  260.     echo "  <td><input type="text" name="cgv_value_$i" value="".$url_arguments_gp['cgv_value_'.$i]."" style="width:300px"></td>n";
  261.     echo "</tr>n";
  262.     if ($i == count($client_gv))
  263.     {
  264.         echo "<tr>n";
  265.         echo "  <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
  266.         echo "</tr>n";     
  267.     }
  268. }
  269. ?>
  270. </table>
  271. <hr>
  272. <input type=submit name=submit value="Request">
  273. </form>
  274. <hr>
  275. <?php
  276. if (strtolower($submit) == 'request')
  277. {
  278.     // building final  array for post values
  279.     for ($i=1;$i<=count($tmp_post);$i++)
  280.     {
  281.         if ($tmp_post[$i]['key'])
  282.             $req_post_values[$tmp_post[$i]['key']] = $tmp_post[$i]['value'];
  283.     }
  284.     // building final uri
  285.     for ($i=1;$i<=count($tmp_get);$i++)
  286.     {
  287.         if (strlen($get_params_string) != 1) $get_params_string .= '&';
  288.         if ($tmp_get[$i]['key'])
  289.             $get_params_string .= urlencode($tmp_get[$i]['key'])."=".urlencode($tmp_get[$i]['value']);
  290.     }
  291.     if ((!strpos('?',$uri)) && ('?' != $get_params_string))
  292.         $uri .= $get_params_string;    
  293.     
  294.     
  295.     require("./extensions/http.class.php");
  296.     set_time_limit(0);
  297.     $http_connection=new http_class;
  298.     
  299.     if ($hostname)  $connection_array["HostName"] = $hostname;
  300.     if ($hostport)  $connection_array["HostPort"] = $hostport;
  301.     if ($proxyname) $connection_array["ProxyHostName"] = $proxyname;
  302.     if ($proxyport) $connection_array["ProxyHostPort"] = $proxyport;
  303.     
  304.     $error=$http_connection->Open($connection_array);
  305.     if($error=="")
  306.     {
  307.         $headers["Host"] = $host;
  308.         $headers["User-Agent"] = $user_agent;
  309.         
  310.         if ($h_no_cache) $headers["Pragma"] = "no-cache";
  311.         
  312.         $request["RequestURI"] = $uri;
  313.         if ($request_method) $request["RequestMethod"] = $request_method;        
  314.         if (@count($headers)) $request["Headers"] = $headers;
  315.         if (@count($req_post_values)) $request["PostValues"] = $req_post_values;
  316.         
  317.         
  318.         $error=$http_connection->SendRequest($request);
  319.         
  320.         if($error=="")
  321.         {
  322.             echo "<table>n";
  323.             
  324.             echo " <tr>n";
  325.             echo "  <th>Fake Client Sent Headers</th>n";
  326.             echo " </tr>n";
  327.             echo " <tr>n";
  328.             echo "  <td><pre>n";
  329.             // reading log of sent headers
  330.             foreach ($http_connection->log_sending_data as $line => $content)
  331.                 echo $content."n";   
  332.             echo "</pre></td>n";
  333.             echo " </tr>n";            
  334.             
  335.             $headers=array();
  336.             $error=$http_connection->ReadReplyHeaders(&$headers);
  337.             if($error=="")
  338.             {
  339.                 echo " <tr>n";
  340.                 echo "  <th> Recived from Server Headers</th>n";
  341.                 echo " </tr>n";
  342.                 echo " <tr><td><pre>n";
  343.                 for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
  344.                 {
  345.                     $header_name=Key($headers);
  346.                     if(GetType($headers[$header_name])=="array")
  347.                     {
  348.                         for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
  349.                             echo $header_name.": ".$headers[$header_name][$header_value],"rn";
  350.                     }
  351.                     else
  352.                         echo $header_name.": ".$headers[$header_name],"rn";
  353.                 }
  354.                 echo "</pre></td></tr>n";
  355.                 echo " <tr>n";
  356.                 echo "  <th> Recived from Server Body </th>n";
  357.                 echo " </tr>n";
  358.                 echo " <tr>n";
  359.                 echo "  <td><pre>n";
  360.                 for(;;)
  361.                 {
  362.                     $error=$http_connection->ReadReplyBody(&$body,1000);
  363.                     if($error!="" || strlen($body)==0)
  364.                         break;
  365.                     echo HtmlSpecialChars($body);
  366.                 }
  367.                 echo "</pre></td>n";
  368.                 echo " </tr>n";
  369.                 echo "</table>n";
  370.             }
  371.             else echo "<span class="error_box">ERROR : ".$error."</span>n";
  372.         }
  373.         else echo "<span class="error_box">ERROR : ".$error."</span>n";
  374.         
  375.         $http_connection->Close();
  376.     }
  377.     else echo "<span class="error_box">ERROR : ".$error."</span>n";
  378. }
  379. ?>