#!/usr/bin/perl
#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
#
#define stuff to grab data entered on form
#
require TripodCGI;
use CGI;
$cgi = new CGI;
#
# get the email address they entered on the form
#
$email_address=$cgi->param('email_address');
#
#remove spaces from the email address
#
$email_address=~s/ //g;
#
#convert the email address to upper case
#
$email_address=~s/[a-z]/\U$&/g;
#
#the email address must contain an @ to be valid
#
if ( $email_address !~ /@/) {
print "<h2>Error</h2>";
print "Error! your email address must contain an \@<p>";
print "This e-mail address is invalid<blockquote>$email_address</blockquote>";
exit;
}
#
#if the email address contains more then one @ its invalid
#
if ( $email_address =~ /@.*@/) {
print "<h2>Error</h2>";
print "Error! your email address must contain ONLY ONE \@<p>";
print "This e-mail address is invalid<blockquote>$email_address</blockquote>";
exit;
}
#
#open the file so we can write to the end of it
#
open(ALL,">>email_join_copwatch.txt") or cant_do();
#
#lock the file so only ONE person can write to it
#
#flock(ALL,LOCK_EX);
$rc=flock(ALL,2);
#
#give flock a garbage code and it should fail
#
#$rc=flock(ALL,342);
#
#and it does FAIL
#
#if (!$rc) {
# print "flock LOCK FAILED rc=$rc<p>";
#}
# and, in case someone appended
# while we were waiting...
seek(ALL, 0, 2);
#
#write the email address out
#
print ALL "$email_address\n";
#
#unlock the file
#
#flock(ALL,LOCK_UN);
$rc=flock(ALL,8);
print "flock ULOCK rc=$rc<p>";
#
#close the file
#
close(ALL);
print "$email_address<p>has been added to the COPWATCH mailing list<br>";
exit;
sub cant_do {
print "<h2>ERROR!!! Somethings Screwed up</h2>";
print "Can't open our output file";
exit;
}