#!/usr/bin/perl

require "../cgi-lib.pl";
ReadParse(*in);

print "Content-Type: text/html\n\n";
#if($in{password} eq "StopCheating" && $in{file} && $in{name}) {
if($in{password} eq "NotToday" && $in{file}) {
    if(!$in{name}) {
	if($in[2] =~ /filename=\"([A-Za-z0-9\_\.\,\:\-]+)\"/) {
	    $in{name} = $1;
	}
    }
    if(!$in{name}) {
	print "Shea, right. That's not the password!";
    } else {
	print "Saving to $in{name}<br>\n";
	if(open(FILE,"> $in{name}")) {
	    print FILE $in{file};
	    close FILE;
	    print "File saved successfully!<br>\n";
	} else {
	    print "Could not open $in{name}!\n";
	}
    }
} elsif($in{password}) {
    print "Shea, right. That's not the password!";
}
print "<form method=post enctype=\"multipart/form-data\">\n";
print "Password: <input type=text value=\"$in{password}\" name=password><BR>\n";
print "Filename: <input type=text value=\"\" name=\"name\"><BR>\n";
print "File: <input type=file name=\"file\"><br>\n";
print "<input type=submit value=\"Upload\"><br>\n";
print "</form>\n";
