#!/usr/local/bin/perl5 -w # Process Form to Add to Specified Page # require "cgi-lib.pl"; # $basedir ='/npac/server/foxsden00/sroot/droot/psf/FFE/'; $mailprog = '/usr/lib/sendmail'; # $today =`date`; chomp($today); # $statusofread = &ReadParse(*formdata); # # Set up Parameter Defaults $name =''; $email=''; $textinput=''; $formtype=''; $filename=''; # # unless( $statusofread ) { &therewaserror("This is a Server Error -- send email Please"); exit; } # # Process Input Data $name = $formdata{'name'}; $email =$formdata{'email'}; $textinput =$formdata{'textinput'}; $formtype =$formdata{'formtype'}; # # Check for Missing Information &therewaserror("Please Give us your name") unless($name); &therewaserror("Please fill in text input box") unless($textinput); # # Define File $filename =""; $filename ='poANDstor.htm' if $formtype eq 'poANDstor'; $filename ='penpals.htm' if $formtype eq 'penpals'; $filename ='embarrassing.htm' if $formtype eq 'embarrassing'; $filename ='music.htm' if $formtype eq 'music'; &therewaserror("FBI Alerted-file has not been recognized-*alert*") unless($filename); $dbfile = $basedir . $filename; $dbfilelock = $basedir .'lock/' . $filename; # # Edit $textinput if($textinput) { $textinput =~ s%\n%
\n%sg; $textinput =~ s%\015%%sg; $textinput =~ s%\013%%sg; } # # Loop until we can get a sucessful "lock" on the database $count = 0; while (!&LockDatabase($dbfilelock)) { # Sleep for a second sleep(1); ++$count; &therewaserror("Server out to lunch -- please email -- lock stuck") if($count > 20); } # open(DATAFILE,"<$dbfile") || &therewaserror("Server Error Cant Open Data File for Read -- please email"); @data = ; close(DATAFILE); open(DATAFILE,">$dbfile") || &therewaserror("Server Error Cant Open Data File for Rewrite -- please email"); # foreach $line (@data) { # Insert Line if( $line =~ m%^$% ) { $num=1+$1; print DATAFILE "\n"; next; } if( $line =~ m%^$% ) { if($email) { print DATAFILE "$num:${name}\'s Opinion Email:$email $today
\n"; } else { print DATAFILE "$num:${name}\'s Opinion No Email provided $today
\n"; } } if( $line =~ m%^$% ) { if($email) { print DATAFILE "$num:Contribution of $name $email $today
\n"; } else { print DATAFILE "$num:Contribution of $name No Email provided $today
\n"; } print DATAFILE "$textinput\n
\n"; } print DATAFILE $line; } close(DATAFILE); # &UnlockDatabase($dbfilelock); # # End Up print "Location: http://www.foxsden.org/psf/FFE/$filename\n\n"; exit; sub LockDatabase { # PURPOSE: Attempt to "lock" the database by creating a lock file. # INPUTS: Database file name # OUTPUTS: A boolean telling if the lock was successful my ($dbfile) = @_; if (-e "$dbfile.lock") { # DB is already locked return 0; } else { system("touch $dbfile.lock"); # Create the lock file return 1; } } sub UnlockDatabase { # PURPOSE: Attempt to "unlock" the database by deleting the lock file. # INPUTS: Database file name # OUTPUTS: None (but should probably check that the unlock was successful) my ($dbfile) = @_; unless( (unlink("$dbfile.lock")) ) { open (MAIL, "|$mailprog gcf") || (&therewaserror("Server Error Can't Mail -- Please email us")) ; print MAIL < Error in $filename Form Processing!

Error in Processing $filename Update: $mess

Please correct or if it's our fault Mail Complaint

Name

Email

Put your poem or story here:

EOF exit 1; } #