#!usr/bin/php
1) $port = trim($argv[1]);
if($argc > 2) $interface = trim($argv[2]);
}
///FUNCTIONS//////////////////////////////////////////////////////////////////////
function send_dir_listing($fp, $directory) {
$num = "0";
//Header
@fwrite($fp, "\n
Index of $directory\n\n");
@fwrite($fp, "Available volumes:
\n");
//Special folders
@fwrite($fp, "[/]\n"); //Server root
@fwrite($fp, "[//]\n"); //Unix root (if running unix)
//Available volumes
$dsks = "cdefghijklmnopqrstuvwxyz"; //Show this volumes (if available)
for($i=0;$i$vol:]\n");
}
//echo($dsks[$i].":");
}
@fwrite($fp, "
\n\n");
//Directory listing
@fwrite($fp, "Directory listing of $directory :
\n\n");
@fwrite($fp, "[DIR] Parent Directory (../)
\n");
$files=opendir ($directory);
while (false!==($file = readdir($files)))
{
if ($file != "." && $file != "..")
{
$num++;
if(is_dir("$directory/$file")) {
fwrite($fp, "$num - [DIR] $file
\n");
} else {
fwrite($fp, "$num - $file
\n");
}
}
}
//Footer
fwrite($fp, "
\nTotal: $num\n\n");
}
///CODE///////////////////////////////////////////////////////////////////////////
echo("\n\tStarting Harvie's HTTPd at:\n\ttcp://$interface:$port\n\n");
//system("title Harvie's HTTPd at tcp://$interface:$port"); //Microsoft Windows only
set_time_limit(0);
$sss = stream_socket_server("tcp://$interface:$port");
while(1) {
@$sfp = stream_socket_accept($sss);
if(!$sfp) continue;
$loop = 1;
while($sfp && !@feof($sfp) && $loop) {
$line = fgets($sfp);
//echo($line);
if(eregi("(GET|POST)", $line)) {
$line = trim($line);
//echo($line);
$line = explode(" ", $line);
$line[1] = trim(urldecode($line[1]));
if($line[1] == "/") {
$line[1] = "./";
} else {
$line[1] = substr($line[1], 1);
}
if(is_file($line[1])) { //200 OK FILE
fwrite($sfp, $okheader);
echo("200 ".$line[1]);
$fp = fopen($line[1], "rb");
while( fwrite($sfp, fgets($fp)) );
@fclose($sfp);
echo(" SENT!\n");
}
elseif(is_dir($line[1])) { //200 OK DIR
if(substr($line[1], strlen($line[1])-1) != "/") { //301 MOV DIR
$header = ("/".$line[1]."/");
echo("301 ".$line[1]." -> $header\n");
$header = str_replace("%DIR%", $header, $dirheader);
//$header = str_replace("./", "./", $dirheader);
//echo($header);
fwrite($sfp, $header);
@fclose($sfp);
break;
}
echo("200 [DIR] ".$line[1]."\n");
send_dir_listing($sfp, $line[1]);
}
else { //404 NOT FOUND
echo("404 ".$line[1]."\n");
fwrite($sfp, $badheader);
fwrite($sfp, $err404);
@fclose($sfp);
}
$loop = 0;
}
}
@fclose($sfp);
}
?>