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