]>
code.delx.au - cgiproxy/blob - php/proxy.php
3 function debugAndDie() {
9 print_r(apache_request_headers());
14 function debug($msg) {
15 $fp = fopen("/tmp/debug.log", "a");
22 function getUrl($url) {
23 if(isset($_SERVER["PATH_INFO"])) {
24 $url .= $_SERVER["PATH_INFO"];
26 $url = parse_url($url);
27 if(!isset($url["port"])) {
29 if($url["scheme"] == "https") {
33 if(strlen($_SERVER["QUERY_STRING"]) > 0) {
34 $url["path"] = $url["path"] . "?" . $_SERVER["QUERY_STRING"];
39 function generateRequest($rmeth, $host, $path) {
42 $req = $rmeth . " " . $path . " HTTP/1.0" . $crlf;
44 $headers = apache_request_headers();
45 if(isset($headers["Host"])) {
46 $req .= "Host: " . $headers["Host"] . $crlf;
48 if(isset($headers["Cookie"])) {
49 $req .= "Cookie: " . $headers["Cookie"] . $crlf;
51 if(isset($headers["Cookie2"])) {
52 $req .= "Cookie2: " . $headers["Cookie2"] . $crlf;
54 if(isset($headers["Referer"])) {
55 $req .= "Referer: " . $headers["Referer"] . $crlf;
57 if(isset($headers["Content-Length"])) {
58 $req .= "Content-Length: " . $headers["Content-Length"] . $crlf;
60 if(isset($headers["Content-Type"])) {
61 $val = $headers["Content-Type"];
62 $val = str_replace("PHPHACK", "", $val);
63 $req .= "Content-Type: " . $headers["Content-Type"] . $crlf;
71 function doProxy($scheme, $rmeth, $host, $port, $path)
73 $req = generateRequest($rmeth, $host, $path);
75 // Make the HTTP request
76 $fp = fsockopen(($scheme == 'https' ?
'ssl://' : '') . $host, $port);
78 die("Could not connect to internal server!");
81 if($rmeth == "POST") {
82 $fpi = fopen("php://input", "rb");
84 fwrite($fp, fread($fpi, 1024));
91 while(is_resource($fp) && $fp && !feof($fp)) {
97 if(strlen(trim($line)) != 0) {
98 array_push($headers, $line);
101 foreach($headers as $header) {
115 function myPassThru($fp) {
118 $data .= fread($fp, 1024);
120 $data = str_replace("enctype=\"multipart/form-data\"", "enctype=\"PHPHACKmultipart/form-data\"", $data);
124 function main($basePath) {
127 $u = getUrl($basePath);
128 $rmeth = $_SERVER["REQUEST_METHOD"];
129 doProxy($u["scheme"], $rmeth, $u["host"], $u["port"], $u["path"]);
134 die("No forwarding available!");