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