# MP3 Server - by dark2k1(dark2k1.com)
#!usr/local/perl/bin
use strict;
use IO::Socket;
my $port = 8181;
my $directory = "C:\Documents and Settings\John H\Desktop\Dell Backup\Backup\Music\";
my $socket = IO::Socket::INET->new(Proto => 'tcp', LocalPort => $port, Listen => SOMAXCONN, Reuse => 0);
while(my $client = $socket->accept()) {
my $line = <$client>;
if($line =~ /(GET) (.+)download/(.+) (HTTP/1.1|HTTP/1.0)/) {
#my $file_name = (split(/ /, $line))[1];
my $file_name = $line;
$file_name =~ s/GET //;
$file_name =~ s/ (HTTP/1.1|HTTP/1.0)//;
$file_name =~ s/%20/ /g;
$file_name =~ s////g;
$file_name =~ s/download/$directory/;
print "File: " . $file_name;
open(DATA, $file_name);
my($file_data);
while(my $data = <DATA>) {
$file_data = $file_data . $data;
}
my $content = $file_data;
my $content_size = length($content);
my $headers = "HTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: close
Content-Type: application/mp3
Content-Length: $content_size
";
$client->send("$headers$content");
print "File: $file_name File Size: $content_size";
} else {
print "List: " . $line;
opendir DIR, $directory;
my($files);
my $x = 0;
while(my $remaining_files = readdir DIR) {
if($remaining_files ne "." && $remaining_files ne "..") {
$files = $files . "<a href="download/$remaining_files">$remaining_files</a>" . "<br>
";
$x++;
}
}
closedir DIR;
my $body = "<html><h3 style='margin: 0'>MP3 Server. There are $x files.</h3>$files</html>";
my $body_size = length($body);
my $headers = "HTTP/1.1 200 OK
Pragma: no-cache
Connection: close
Content-Type: text/html
Content-Length: $body_size
";
$client->send("$headers$body");
}
sleep(1);
close($client);
}
close($socket);