annotate doc/www.powerfulproxy.com/public_html/do_it.php @ 924:a5a310ee291e draft

added 1.5.5.0/24 and ASN 992 from wakawaka
author wakawaka <nobody@nowhere>
date Sun, 04 Mar 2012 21:05:56 +0000
parents 2b68d711a063
children a929c6303a71
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
1 <?php
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
2 // Copyright Atiti, 2011
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
3 // Version 0.1-2
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
4 // Heavily modified by Ivo <Ivo@UCIS.nl>
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
5
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
6 if (!isset($_SERVER['PATH_INFO'])) die('PATH_INFO is not set');
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
7 $pall = explode("/", $_SERVER['PATH_INFO']);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
8 if (count($pall) <= 1) die('Unexpected path format');
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
9 array_shift($pall);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
10 $proto = array_shift($pall);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
11 $host = array_shift($pall);
502
60ece78f8b36 added host and IP verification to powerfulproxy
Nick <nick@somerandomnick.ano>
parents: 501
diff changeset
12 $hostparts = explode('.', $host);
504
83bc7f6e03ae bug fix in powerfulproxy
Nick <nick@somerandomnick.ano>
parents: 503
diff changeset
13 if (long2ip(ip2long($host))===$host) {
503
1ca0de1bb813 bugfix in powerfulproxy
Nick <nick@somerandomnick.ano>
parents: 502
diff changeset
14 if ($hostparts[0]!='1') die('Bad IP');
1ca0de1bb813 bugfix in powerfulproxy
Nick <nick@somerandomnick.ano>
parents: 502
diff changeset
15 } elseif (!preg_match("/ano|ntwrk$/",array_pop($hostparts))) die('Bad host');
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
16 $path = implode('/', $pall);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
17 array_pop($pall);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
18 $rp = implode('/', $pall);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
19
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
20 /* CONFIGURATION */
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
21 $SERVICEURL = "http://powerfulproxy.com/do_it.php/";
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
22
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
23 $REWRITE_CONTENT_TYPES = array('text/html', 'text/xml', 'text/plain');
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
24 $REWRITE_PATTERNS = array(
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
25 /* Rewrite complete http/https URLs, enable one of the tree, and no more! */
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
26 // '@(https?)://(([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@i' => $SERVICEURL.'$1/$2',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
27 // '@(src|href|action)\s*=\s*(\'|")(https?)://([^\'"]*)\2@i' => '$1=$2'.$SERVICEURL.'$3/$4$2',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
28 '@(<[^>]*)(src|href|action)\s*=\s*(\'|")(https?)://([^\'"]*)\3@i' => '$1$2=$3'.$SERVICEURL.'$4/$5$3',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
29 /* Rewrite URLs relative to site root, enable one of the tree, and no more! */
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
30 // '@(src|href|action)\s*=\s*(\'|")/([^\'"]*)\2@i' => '$1=$2'.$SERVICEURL.$proto.'/'.$host.'/$3$2',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
31 '@(<[^>]*)(src|href|action)\s*=\s*(\'|")/([^\'"]*)\3@i' => '$1$2=$3'.$SERVICEURL.$proto.'/'.$host.'/$4$3',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
32 );
613
c2879679114d PP (uncommented safe defaults and added useragent pass-through)
Nick <nick@somerandomnick.ano>
parents: 504
diff changeset
33 if (file_exists("do_it.inc")) include "do_it.inc";
c2879679114d PP (uncommented safe defaults and added useragent pass-through)
Nick <nick@somerandomnick.ano>
parents: 504
diff changeset
34 if (!isset($CURL_OPTIONS)) $CURL_OPTIONS = array(
c2879679114d PP (uncommented safe defaults and added useragent pass-through)
Nick <nick@somerandomnick.ano>
parents: 504
diff changeset
35 // CURLOPT_USERAGENT => "AnoNet proxy",
c2879679114d PP (uncommented safe defaults and added useragent pass-through)
Nick <nick@somerandomnick.ano>
parents: 504
diff changeset
36 CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"]." AnoNetProxy",
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
37 CURLOPT_AUTOREFERER => TRUE,
614
2b68d711a063 PP (added referer header)
Nick <nick@somerandomnick.ano>
parents: 613
diff changeset
38 CURLOPT_REFERER => $_SERVER["HTTP_REFERER"],
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
39 CURLOPT_CONNECTTIMEOUT => 15,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
40 CURLOPT_TIMEOUT => 28,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
41 CURLOPT_MAXREDIRS => 10,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
42 CURLOPT_FAILONERROR => FALSE,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
43 CURLOPT_HEADER => 1,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
44 CURLOPT_FOLLOWLOCATION => FALSE,
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
45 // CURLOPT_INTERFACE => '0.0.0.0',
613
c2879679114d PP (uncommented safe defaults and added useragent pass-through)
Nick <nick@somerandomnick.ano>
parents: 504
diff changeset
46 CURLOPT_PROXY => "http://b.polipo.srn.ano:8000/",
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
47 // CURLOPT_PROXYUSERPWD => 'username:password',
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
48 );
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
49 /* END OF CONFIGURATION */
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
50
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
51 $url = $proto."://".$host."/".$path;
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
52 if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING'])) $url .= "?".$_SERVER['QUERY_STRING'];
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
53 $ch = curl_init($url);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
54 curl_setopt_array($ch, $CURL_OPTIONS);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
55 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
56 //curl_setopt($ch, CURLOPT_HEADER, FALSE);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
57 if (count($_POST)) {
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
58 curl_setopt($ch, CURLOPT_POST, TRUE);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
59 curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
60 }
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
61 $response = curl_exec($ch);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
62 list($header, $data) = explode("\r\n\r\n", $response, 2);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
63 if ($error = curl_error($ch)) die('CURL ERROR: '.$error);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
64 $info = curl_getinfo($ch);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
65
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
66 header('Status: '.$info['http_code']);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
67 header('Content-Type: '.$info['content_type']);
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
68
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
69 $redirurl = "";
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
70 if ($info['http_code'] === 301) {
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
71 $headers = explode("\r\n", $header);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
72 foreach($headers as $h) {
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
73 $cur_header = explode(": ", $h);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
74 if ($cur_header[0] == "Location") {
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
75 $redirurl = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $SERVICEURL.str_replace("http://", "http/", "$1"), $cur_header[1]);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
76 $redirurl = str_replace(".php/http://", ".php/http/", $redirurl);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
77 header('Location: '.$redirurl);
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
78 }
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
79 }
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
80 } else {
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
81 if (in_array(strtok($info['content_type'], ';'), $REWRITE_CONTENT_TYPES)) $data = preg_replace(array_keys($REWRITE_PATTERNS), array_values($REWRITE_PATTERNS), $data, -1, $count);
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
82 }
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
83
501
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
84 header('Content-Length: '.strlen($data));
4d73737f40ff new version of powerfulproxy from atiti
Nick <nick@somerandomnick.ano>
parents: 453
diff changeset
85 echo $data;
453
6da2470e59b5 powerfulproxy
Nick <nick@somerandomnick.ano>
parents:
diff changeset
86 ?>