#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
if ($FORM{button} eq "Display the Code") {
if ($FORM{password} eq "password") {
print "Content-type: text/plain\n\n";
if ($FORM{exercise} == 1) {
system ("cat Exercise1.txt");
}
elsif ($FORM{exercise} == 2) {
system ("cat Exercise2.txt");
}
elsif ($FORM{exercise} == 3) {
system ("cat Exercise3.txt");
}
elsif ($FORM{exercise} == 4) {
system ("cat Exercise4.txt");
}
else {
print "\n\n\n No such exercise: $FORM{exercise}";
}
}
else {
print "Content-type: text/html\n\n";
print "<br><br><center><font size='+1'><b>Wrong password: </b>";
print "<i>$FORM{password}</i></font><";
}
}
elsif ($FORM{button} eq "Help") {
print "Content-type: text/html\n\n";
system ("cat help.html");
}
else {
print "Content-type: text/html\n\n";
print "<br><br><center><h2>No such option: ";
print "<i>$FORM{button}</i></h2></center>";
}
|