Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
pat_raw_http_request.php
Package: Generateur_v13.rar [view]
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 12k
Category:
WEB Mail
Development Platform:
PHP
- <?php
- /*
- * adapted from Manuel Lemos test page
- *
- */
- include('./config.php');
- $pat_default_ua = 'PAT Http Raw Request by Manuel Lemos - Jean philippe Giot';
- /*****************************************************************************
- *
- *
- * PARSING POST VALUES
- *
- *
- *****************************************************************************/
- $submit = $_POST['submit'];
- // look for each parameter values from the web and then their defaut
- // parse a given url into it's components
- if ($submit == 'parse')
- {
- // we extract all components from url
- // note : only works with GET requests...
- // this is not affected by an url
- $user_agent = ($_POST['user_agent'])? $_POST['user_agent'] : $pat_default_ua;
- $proxyname = $_POST['proxyname'];
- $proxyport = $_POST['proxyport'];
- $h_no_cache = $_POST['h_no_cache'];
- $request_method = "GET";
- $url_components = parse_url($_POST['url2parse']);
- $hostname = $url_components['host'];
- $hostport = $url_components['port'];
- $uri = $url_components['path'];
- // parsing query
- $arguments = explode('&',$url_components['query']);
- //var_dump($arguments);
- if (@count($arguments))
- {
- $i=1;
- foreach ($arguments as $num => $compressed_arg)
- {
- list($key,$val) = explode('=',$compressed_arg);
- $url_arguments_gp['cgv_key_'.$i] = urldecode($key);
- $url_arguments_gp['cgv_value_'.$i] = urldecode($val);
- $client_gv[$i] = true;
- $i++;
- }
- $last_known_gv = $i;
- }
- //var_dump($url_arguments_gp);
- // mapping POST values for get and post arguments
- // no need, it already has been done
- // $url_arguments_gp =
- }
- else
- {
- $user_agent = ($_POST['user_agent'])? $_POST['user_agent'] : $pat_default_ua;
- $hostname = ($_POST['hostname'])? $_POST['hostname'] : "localhost";
- $hostport = ($_POST['hostport'])? $_POST['hostport'] : "80";
- $proxyname = $_POST['proxyname'];
- $proxyport = $_POST['proxyport'];
- $uri = ($_POST['uri'])? $_POST['uri'] : "/";
- if (strpos($uri,'?'))
- $uri = substr ($uri,0,strpos($uri,'?'));
- $h_no_cache = $_POST['h_no_cache'];
- $request_method = ($_POST['request_method'])? $_POST['request_method'] : "GET";
- // mapping POST values for get and post arguments
- $url_arguments_gp = $_POST;
- }
- $last_known_cookie = 0;
- $get_params_string = '?';
- foreach ($_POST as $key => $value)
- {
- if ('ccookie' == substr($key,0,strlen('ccookie')))
- {
- if ($value)
- {
- $parts = explode('_',$key);
- $ckey = $parts[1];
- $cnumber = $parts[2];
- $client_cookies[$cnumber][$ckey]=$value;
- if ($cnumber > $last_known_cookie) $last_known_cookie = $cnumber;
- }
- }
- if ('cpv' == substr($key,0,strlen('cpv')))
- {
- if ($value)
- {
- $parts = explode('_',$key);
- $ckey = $parts[1];
- $cnumber = $parts[2];
- $tmp_post[$cnumber][$ckey] = $value;
- $client_pv[$cnumber]=true;
- if ($cnumber > $last_known_pv) $last_known_pv = $cnumber;
- }
- }
- if ('cgv' == substr($key,0,strlen('cgv')))
- {
- if ($value)
- {
- $parts = explode('_',$key);
- $ckey = $parts[1];
- $cnumber = $parts[2];
- $tmp_get[$cnumber][$ckey] = $value;
- $client_gv[$cnumber]=true;
- if ($cnumber > $last_known_gv) $last_known_gv = $cnumber;
- }
- }
- }
- // adding always a new cookie and a last post value
- $client_cookies[($last_known_cookie+1)] = true;
- $client_pv[($last_known_pv+1)] = true;
- $client_gv[($last_known_gv+1)] = true;
- /*****************************************************************************
- *
- *
- * BUILDING OUTPUT
- *
- *
- *****************************************************************************/
- send_execute_header('Raw Http Request');
- ?><body>
- <form method=post action="pat_raw_http_request.php">
- <table>
- <tr>
- <th>Parse Url</th>
- <td><input type="text" name="url2parse" value="" style="width:300px"></td>
- </tr>
- <tr>
- <td colspan=2 align=center><input type="submit" name="submit" value="parse"></td>
- </tr>
- <tr>
- <td colspan=2> </td>
- </tr>
- <tr>
- <th>Host Name</th>
- <td><input type="text" name="hostname" value="<?php echo $hostname; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>Host Port</th>
- <td><input type="text" name="hostport" value="<?php echo $hostport; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>Proxy Name</th>
- <td><input type="text" name="proxyname" value="<?php echo $proxyname; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>Proxy Port</th>
- <td><input type="text" name="proxyport" value="<?php echo $proxyport; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>URI</th>
- <td><input type="text" name="uri" value="<?php echo $uri; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>Request Method</th>
- <td><input type="radio" name="request_method" value="GET"<?php if($request_method == 'GET') echo ' checked'; else echo ''; ?>> GET
- <input type="radio" name="request_method" value="POST"<?php if($request_method == 'POST') echo ' checked'; else echo ''; ?>> POST
- </td>
- </tr>
- <tr>
- <th>User Agent</th>
- <td><input type="text" name="user_agent" value="<?php echo $user_agent; ?>" style="width:300px"></td>
- </tr>
- <tr>
- <th>Header : no cache</th>
- <td><input type="checkbox" name="h_no_cache" value="1"<?php if($h_no_cache) echo ' checked'; else echo ''; ?>></td>
- </tr>
- <?php
- /*
- * COOKIES Values
- */
- for($i=1;$i<=count($client_cookies);$i++)
- {
- echo "<tr>n";
- echo " <th colspan=2>Cookie $i</th>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Name</td>n";
- echo " <td><input type="text" name="ccookie_name_$i" value="".$_POST['ccookie_name_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Value</td>n";
- echo " <td><input type="text" name="ccookie_value_$i" value="".$_POST['ccookie_value_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Expire Date</td>n";
- echo " <td><input type="text" name="ccookie_expire_$i" value="".$_POST['ccookie_expire_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Domain</td>n";
- echo " <td><input type="text" name="ccookie_domain_$i" value="".$_POST['ccookie_domain_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Secure</td>n";
- echo " <td><input type="text" name="ccookie_secure_$i" value="".$_POST['ccookie_secure_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- if ($i == count($client_cookies))
- {
- echo "<tr>n";
- echo " <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
- echo "</tr>n";
- }
- }
- /*
- * POST Values
- */
- for($i=1;$i<=count($client_pv);$i++)
- {
- echo "<body bgcolor='#CFE3E3'><tr>n";
- echo " <th colspan=2>Post Value $i</th>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Name</td>n";
- echo " <td><input type="text" name="cpv_key_$i" value="".$url_arguments_gp['cpv_key_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Value</td>n";
- echo " <td><input type="text" name="cpv_value_$i" value="".$url_arguments_gp['cpv_value_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- if ($i == count($client_pv))
- {
- echo "<tr>n";
- echo " <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
- echo "</tr>n";
- }
- }
- /*
- * GET Values
- */
- for($i=1;$i<=count($client_gv);$i++)
- {
- echo "<tr>n";
- echo " <th colspan=2>Get Value $i</th>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Name</td>n";
- echo " <td><input type="text" name="cgv_key_$i" value="".$url_arguments_gp['cgv_key_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- echo "<tr>n";
- echo " <td>Value</td>n";
- echo " <td><input type="text" name="cgv_value_$i" value="".$url_arguments_gp['cgv_value_'.$i]."" style="width:300px"></td>n";
- echo "</tr>n";
- if ($i == count($client_gv))
- {
- echo "<tr>n";
- echo " <td colspan=2 align="center"><input type="submit" name="submit" value="Add"> </td>n";
- echo "</tr>n";
- }
- }
- ?>
- </table>
- <hr>
- <input type=submit name=submit value="Request">
- </form>
- <hr>
- <?php
- if (strtolower($submit) == 'request')
- {
- // building final array for post values
- for ($i=1;$i<=count($tmp_post);$i++)
- {
- if ($tmp_post[$i]['key'])
- $req_post_values[$tmp_post[$i]['key']] = $tmp_post[$i]['value'];
- }
- // building final uri
- for ($i=1;$i<=count($tmp_get);$i++)
- {
- if (strlen($get_params_string) != 1) $get_params_string .= '&';
- if ($tmp_get[$i]['key'])
- $get_params_string .= urlencode($tmp_get[$i]['key'])."=".urlencode($tmp_get[$i]['value']);
- }
- if ((!strpos('?',$uri)) && ('?' != $get_params_string))
- $uri .= $get_params_string;
- require("./extensions/http.class.php");
- set_time_limit(0);
- $http_connection=new http_class;
- if ($hostname) $connection_array["HostName"] = $hostname;
- if ($hostport) $connection_array["HostPort"] = $hostport;
- if ($proxyname) $connection_array["ProxyHostName"] = $proxyname;
- if ($proxyport) $connection_array["ProxyHostPort"] = $proxyport;
- $error=$http_connection->Open($connection_array);
- if($error=="")
- {
- $headers["Host"] = $host;
- $headers["User-Agent"] = $user_agent;
- if ($h_no_cache) $headers["Pragma"] = "no-cache";
- $request["RequestURI"] = $uri;
- if ($request_method) $request["RequestMethod"] = $request_method;
- if (@count($headers)) $request["Headers"] = $headers;
- if (@count($req_post_values)) $request["PostValues"] = $req_post_values;
- $error=$http_connection->SendRequest($request);
- if($error=="")
- {
- echo "<table>n";
- echo " <tr>n";
- echo " <th>Fake Client Sent Headers</th>n";
- echo " </tr>n";
- echo " <tr>n";
- echo " <td><pre>n";
- // reading log of sent headers
- foreach ($http_connection->log_sending_data as $line => $content)
- echo $content."n";
- echo "</pre></td>n";
- echo " </tr>n";
- $headers=array();
- $error=$http_connection->ReadReplyHeaders(&$headers);
- if($error=="")
- {
- echo " <tr>n";
- echo " <th> Recived from Server Headers</th>n";
- echo " </tr>n";
- echo " <tr><td><pre>n";
- for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
- {
- $header_name=Key($headers);
- if(GetType($headers[$header_name])=="array")
- {
- for($header_value=0;$header_value<count($headers[$header_name]);$header_value++)
- echo $header_name.": ".$headers[$header_name][$header_value],"rn";
- }
- else
- echo $header_name.": ".$headers[$header_name],"rn";
- }
- echo "</pre></td></tr>n";
- echo " <tr>n";
- echo " <th> Recived from Server Body </th>n";
- echo " </tr>n";
- echo " <tr>n";
- echo " <td><pre>n";
- for(;;)
- {
- $error=$http_connection->ReadReplyBody(&$body,1000);
- if($error!="" || strlen($body)==0)
- break;
- echo HtmlSpecialChars($body);
- }
- echo "</pre></td>n";
- echo " </tr>n";
- echo "</table>n";
- }
- else echo "<span class="error_box">ERROR : ".$error."</span>n";
- }
- else echo "<span class="error_box">ERROR : ".$error."</span>n";
- $http_connection->Close();
- }
- else echo "<span class="error_box">ERROR : ".$error."</span>n";
- }
- ?>