#!/usr/bin/perl # Department of Physics & Astronomy # Quantum Lottery Processing Script # Author : John Pullen # Date : May 7th, 1996 # Contact : John.Pullen@ed.ac.uk # Copyright : None # minor changes by kcb: June 21st, 25th, 28th, 1996; trmorris 06/03/2000; nje 26/1/2007 #initialise the files &initialize; #get the POST values &ReadParse; #pattern is name=field $pat = $in{name}; #Prevent two simultaneous accesses. &lockFile; #Open files open(FILE1, ">>$entries") || die "Sorry - Unavailable"; open(FILE2, ">>$interestFileSQL") || die "Sorry - Unavailable"; #Create Entry $addition = "Name : $in{Name}\n"; $addition .= "Affiliation: $in{Affiliation}\n"; $addition .= "Address : $in{Address}\n"; $addition .= "Email : $in{Email}\n"; $addition .= "Talk : $in{Talk}\n"; $addition .= "Title : $in{Title}\n"; $addition .= "Companions : $in{Companions}\n"; $addition .= "Transport : $in{Transport}\n"; $addition .= "Arrive : $in{Arrive}\n"; $addition .= "Depart : $in{Depart}\n"; #print entry to files print FILE1 $addition; print FILE2 $addition; #close files close(FILE1); close(FILE2); #unlock the file &unlockFile; #Create WWW response $response = "Content-type: text/html\n\n"; $response .= "\n"; $response .= "\n"; $response .= " Second Conference on the Exact Renormalization Group "; $response .= "\n"; $response .= "\n "; $response .= "

"; #print header information print($response); #Generate a reply $answer ="We note your interest in ERG2.
"; $answer.="The following details have been entered in our database
"; $answer.="and mailed to you at $in{Email}
"; #print reply print($answer); print("

$addition
"); #print footer since won't be added by server $response = ""; $response .= "ERG2
"; $response .= ""; $response .= "Last Updated Monday, 6th March, 2000

"; $response .= " erg2\@hep.phys.soton.ac.uk"; $response .= ""; $response .= ""; print($response); &send_mail; #exit script exit0; die $@ if $@; #----------------------------------- #Subroutines - Usually stolen from others # #---------------------------------------------------------- # ReadParse # Reads in GET or POST data, converts it to unescaped text, and puts # one key=value in each member of the list "@in" # Also creates key/value pairs in %in, using '\0' to separate multiple # selections # If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse, # information is stored there, rather than in $in, @in, and %in. sub ReadParse { if (@_) { local (*in) = @_; } local ($i, $loc, $key, $val); # Read in text if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'}; } elsif ($ENV{'REQUEST_METHOD'} eq "POST") { for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) { $in .= getc; } } @in = split(/&/,$in); foreach $i (0 .. $#in) { # Convert plus's to spaces $in[$i] =~ s/\+/ /g; # Convert %XX from hex numbers to alphanumeric $in[$i] =~ s/%(..)/pack("c",hex($1))/ge; # Split into key and value. $loc = index($in[$i],"="); $key = substr($in[$i],0,$loc); $val = substr($in[$i],$loc+1); $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple separator $in{$key} .= $val; } return 1; # just for fun } #---------------------------------------------------------- sub initialize { # two files - plain in case of emergencies # sql file for secretaries to *play* with $interestFilePlain = "buildout"; $interestFileSQL = "buildout2"; $lockFilename= "/tmp/erg2.lock"; $mailprog ="/usr/lib/sendmail"; } #---------------------------------------------------------- sub unlockFile { unlink("$lockFilename"); } #---------------------------------------------------------- sub lockFile { $lockCount = 0; while (-f "$lockFilename") { if ($lockCount > $lockWait) { $count = 0; return 1; # forget it (would be nice to log though) } sleep 1; $lockCount++; } open(LOCK,">$lockFilename") || die("Can't open $counterFile.lock: $!\n"); return 0; } #---------------------------------------------------------- sub send_mail { $reply = "To: $in{Email}\n"; $reply .= "From: erg2\@hep.phys.soton.ac.uk\n"; $reply .= "Subject: ERG2 - Notification of Interest \n"; $reply .= "Cc: erg2\@hep.phys.soton.ac.uk\n"; $reply .= "Bcc: trmorris\n"; $reply .= "We note your interest in the Second Conference on the Exact Renormalization Group\n"; $reply .= "\n"; $reply .= "Name : $in{Name}\n"; $reply .= "Affiliation: $in{Affiliation}\n"; $reply .= "Address : $in{Address}\n"; $reply .= "Email : $in{Email}\n"; $reply .= "Talk : $in{Talk}\n"; $reply .= "Title : $in{Title}\n"; $reply .= "Companions : $in{Companions}\n"; $reply .= "Transport : $in{Transport}\n"; $reply .= "Arrive : $in{Arrive}\n"; $reply .= "Depart : $in{Depart}\n"; open (MAIL, "|$mailprog -t"); print MAIL $reply; close(MAIL); }