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