]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/proxy_check.php
MediaWiki 1.11.0
[autoinstallsdev/mediawiki.git] / includes / proxy_check.php
1 <?php
2 /**
3  * Command line script to check for an open proxy at a specified location
4  */
5
6 if( php_sapi_name() != 'cli' ) {
7         die( 1 );
8 }
9
10 /**
11  *
12  */
13 $output = '';
14
15 /**
16  * Exit if there are not enough parameters, or if it's not command line mode
17  */
18 if ( ( isset( $_REQUEST ) && array_key_exists( 'argv', $_REQUEST ) ) || count( $argv ) < 4 ) {
19         $output .= "Incorrect parameters\n";
20 } else {
21         /**
22          * Get parameters
23          */
24         $ip = $argv[1];
25         $port = $argv[2];
26         $url = $argv[3];
27         $host = trim(`hostname`);
28         $output = "Connecting to $ip:$port, target $url, this hostname $host\n";
29
30         # Open socket
31         $sock = @fsockopen($ip, $port, $errno, $errstr, 5);
32         if ($errno == 0 ) {
33                 $output .= "Connected\n";
34                 # Send payload
35                 $request = "GET $url HTTP/1.0\r\n";
36 #               $request .= "Proxy-Connection: Keep-Alive\r\n";
37 #               $request .= "Pragma: no-cache\r\n";
38 #               $request .= "Host: ".$url."\r\n";
39 #               $request .= "User-Agent: MediaWiki open proxy check\r\n";
40                 $request .= "\r\n";
41                 @fputs($sock, $request);
42                 $response = fgets($sock, 65536);
43                 $output .= $response;
44                 @fclose($sock);
45         } else {
46                 $output .= "No connection\n";
47         }
48 }
49
50 $output = escapeshellarg( $output );
51
52 #`echo $output >> /home/tstarling/open/proxy.log`;
53
54