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