#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
#place to go when successful
$redirect = "http://www.mysite.com/soapopera/start.cgi";
#absolute location of the directory for your images
$Data = "/usr/local/www/virtual/username/soapopera/images";
#file containing usernames and passwords
$datafile = "passes.txt";
#File extensions to allow your visitors to upload.
@good_extensions = ('gif', 'jpg', 'jpeg', 'png');
#maximum file size in Kb
$max_size_main = 25;
#Gives date as "Weekday, Daynumber Month Year"
use POSIX qw(strftime);
$time= strftime("%A, %d %B %Y", localtime);
use CGI;
my $req = new CGI;
my $name = $req->param("name");
my $password = $req->param("password");
my $title = $req->param("title");
my $story = $req->param("story");
my $storyid = $req->param("storyid");
my $image = $req->param("image");
my $next1 = $req->param("next1");
my $next2 = $req->param("next2");
my $chapter = $req->param("chapter");
my $imagename = $image;
$story =~ s/\n/
/gi;
open(PASSFILE, $datafile) or die $!;
@data = ;
close(PASSFILE);
foreach $data(@data){
@eachinfo = split(/\|/, $data);
if ($eachinfo[0] eq $name && $eachinfo[2] eq $password){
$success = 1;
}
}
if (!$success){
print "Sorry
That Name/Password combination is not correct. Press your back button and try again.";
}
if($success){
if($image) {
$imagename =~ s/^.*(\\|\/)//;
$imagename =~ s/ +/\_/g;
$num="";
while(-e "$Data/$num$imagename"){ $num++; }
$imagename = $num.$imagename;
my $proceed_type = 0;
foreach(@good_extensions) {
my $ext = $_;
$ext =~ s/\.//g;
if($imagename =~ /\.$ext$/) {
$proceed_type = 1;
last;
}
}
unless($proceed_type) { push(@was_not_good_type, $imagename); }
if($proceed_type) {
if(open(OUTFILE, ">$Data/$imagename")) {
while (my $bytesread = read($image, my $buffer, 1024)) { print OUTFILE $buffer; }
close (OUTFILE);
push(@file_did_save, $imagename);
} else { push(@did_not_save, $imagename); }
}
if($max_size_main) {
if((-s "$Data/$imagename") > ($max_size_main * 1024)) {
push(@was_too_big, $imagename);
unlink("$Data/$imagename");
}
}
#close if file exists...
if(@file_did_save){
open (TXTFILE, ">>data/$storyid.txt") or die $!;
print TXTFILE "$chapter|$name|$title|$story|$next1|$next2|$imagename|$time\n";
close(TXTFILE);
print $req->redirect($redirect);
} else{
if(@was_not_good_type){ @reason = @was_not_good_type;}
if(@was_too_big){@reason = @was_too_big;}
if(@did_not_save){@reason = @did_not_save;}
print "Content-type: text/html\n\n";
print "An error occured: @reason";
exit;
}
}else{ #no pic uploaded
open (TXTFILE, ">>data/$storyid.txt") or die $!;
print TXTFILE "$chapter|$name|$title|$story|$next1|$next2||$time\n";
close(TXTFILE);
print $req->redirect($redirect);
}
}#successful password