All pastes #258370 Raw Edit

Untitled

public text v1 · immutable
#258370 ·published 2006-11-26 13:23 UTC
rendered paste body
use lib 'C:/perl/perlhttp';
require "funct.pm";
@conf = ();
@conf[0]="C:/Perl/PerlHTTP/"; # base directory (root) of http system
@conf[1]="www"; # name of folder containing web files
chdir(@conf[0].@conf[1]) or die("Failed to find root web-directory");
print "Console Operating Colours\n";
print "xn :: x=background, n=foreground :: e.g- 01 (black background behind blue text)\n";
print "0 = black\n1 = blue\n2 = green\n3 = aqua\n4 = red\n5 = purple\n6 = yellow\n7 = grey\n8 = dark-grey\n9 = light-blue\n";
print "A = light-green\nB = light-aqua\nC = light red\nD = light purple\nE = light-yellow\nF = bright-white\n";
print "[use 00 to use current]\n";
print "Select Colours: ";
$colour = <STDIN>;
if ($colour ne "00") { system("color ".$colour); }
use IO::Socket;
my $socket = new IO::Socket::INET (
									LocalHost=>"localhost",
									LocalPort=>80,
									Proto=>tcp,
									Listen=>1,
									Reuse=>1,
									) or die("Couldnt connect");
goto connects;
connects: {
	print "Waiting on http connections...\n";
	my $sock = $socket->accept();
	read($sock,$rawdata,222) or die("Failed reading socket");
	@data = split(" ",$rawdata) or die("Failed to separate data for processing");
	while(<$sock>){
		print "Http connection received...\n";
		print $sock @data[2]." 200 Handling request...\r\n";
		print $sock "Date: dunno .. do you?\r\n";
		print $sock "Server: PerlHTTP V1a\r\n";
		print $sock "MIME-version: 1.0\r\n";
		print $sock "Content-type: text/html;text/text;text/css;image/jpg;image/gif;image/jpeg\r\n";
		print $sock "Last-Modified: when i felt like it\r\n";
		print $sock "\r\n";
		if (@data[0] eq "GET") { 
			if (@data[1] eq "/") {
				if (-e "index.html") {
					@indexfile = getfile("index.html");
					print $sock @indexfile;
				}
				else {
					nofile($sock);
				}
			}
			else {
				if (-e $data[1]) {
					@reqfile = getfile($filereq);
					print $sock @reqfile;
				}
				else {
					if (-e "index.html") {
						@indexfile = getfile("index.html");
						print $sock @indexfile;
					}
					else {
						nofile($sock);
					}
				}
			}
		}
		else {
			print $sock "Method not implemented yet.";
		}		
		open(DATALOG, ">../datalog.txt") or die("failed data log");
		foreach $i (@datanew) { print DATALOG $i . "\n"; }
		close(DATALOG);
		print "Page request dealt with appropriately\n";
		close($sock);
	}
	goto connects;
}