added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / http_server_old.php
1 #!usr/bin/php
2 <?php
3 //Harvie's HTTPd 0.5
4 /*
5 Allows you to binary safe download any file from remote pc
6 http://server:port/file
7 http://server:port//etc/passwd
8 http://server:port/C:\dir\file
9 http://server:port/C:/dir/file
10 You can also play multimedia like streams (using XMMS, Winamp, etc...)
11 But this can serve only one file a time
12 (if you are streaming or downloading, you can download/browse anything other,
13 but you can use download manager to download file by file...)
14 You can change port or interface by passing arguments
15 Usage: (httpd.php [port] [interface_IP])
16 This is very nice utility to use in your zombie.
17 */
18
19 //////////////////////////////////////////////////////////////////////////////////
20 $interface = "127.0.0.1";
21 $port = 81;
22 $index = "index.html";
23
24 //////////////////////////////////////////////////////////////////////////////////
25 $okheader = //Header 200
26 "HTTP/1.0 200 OK\n".
27 "Server: Harvie's HTTPd\n".
28 "Connection: close\n\n";
29
30 $badheader = //Header 404
31 "HTTP/1.0 404 File not found!\n".
32 "Server: Harvie's HTTPd\n".
33 "Connection: close\n\n";
34
35 $err404 = "ERR 404 - NOT FOUND!"; //Error 404
36
37 //////////////////////////////////////////////////////////////////////////////////
38 if(isset($argc)) {
39 if($argc > 1) $port = trim($argv[1]);
40 if($argc > 2) $interface = trim($argv[2]);
41 }
42
43 echo("\n\tStarting Harvie's HTTPd at:\n\ttcp://$interface:$port\n\n");
44 //system("title Harvie's HTTPd at tcp://$interface:$port"); //Microsoft Windows only
45 set_time_limit(0);
46 $sss = stream_socket_server("tcp://$interface:$port");
47
48 while(1) {
49 @$sfp = stream_socket_accept($sss);
50 if(!$sfp) continue;
51
52 $loop = 1;
53 while($sfp && !@feof($sfp) && $loop) {
54 $line = fgets($sfp);
55 //echo($line);
56 if(eregi("(GET|POST)", $line)) {
57 $line = trim($line);
58 //echo($line);
59 $line = explode(" ", $line);
60
61 $line[1] = urldecode($line[1]);
62
63 if($line[1] == "/") {
64 $line[1] = $index;
65 } else {
66 $line[1] = substr($line[1], 1);
67 }
68
69 if(is_file($line[1])) { //200 OK
70 fwrite($sfp, $okheader);
71 echo("200 ".$line[1]."\n");
72 $fp = fopen($line[1], "rb");
73 while( fwrite($sfp, fgets($fp)) );
74 @fclose($sfp);
75 } else { //404 NOT FOUND
76 echo("404 ".$line[1]."\n");
77 fwrite($sfp, $badheader);
78 fwrite($sfp, $err404);
79 @fclose($sfp);
80 }
81
82 $loop = 0;
83 }
84 }
85 @fclose($sfp);
86 }
87
88 ?>
This page took 1.25576 seconds and 4 git commands to generate.