#!/usr/local/bin/perl # Script to take arguments from ../index.html, use the UNIX sed # command to edit a LaTeX template, and produce a postscript file from this. # # The script can be considered in as consisting of the following parts: # # (1) Read in arguments passed to script. # (2) Read, increment and write id number. Delete old files. # (3) Generate LaTeX and postscript files # (4) Generate return HTML page # # J.Brewer 1998. ############################################################################## # TODO # (1) Put all the latex dvips stuff in a shell script # (2) Protect from #'s and /'s see HERE, also see p229 of cgi programming. ############################################################################## # (1) Read in arguments passed to script. ############################################################################## # Below is from Gundavaram (Nutshell book) $webmaster = "jbrewer\@eso\.org"; &parse_form_data (*ip); ############################################################################## # (2) Read, increment and write id number. Delete old files. ############################################################################## # To avoid problems with netscape caching old PS files, I allocate an # ID number to each file that is generated. This ID number # is also used as a strike counter # Set the name of the id/counter file: $id_file = "strikes"; # Open file and read in current id value... open (FILE, "<" . $id_file) || die "Cannot open $id_file for reading"; $hits = ; close (FILE); # Incremented id value, open file a save new id... $hits++; open (FILE, ">" . $id_file) || die "Cannot open $id_file for writing"; print FILE $hits; close (FILE); # To avoid disk space problems, delete the (n-4)th file... $old = $hits - 4; if(-e "SetUp$old.ps"){unlink "SetUp$old.ps";} ############################################################################## ############################################################################## # (3) Generate LaTeX and postscript files ############################################################################## # # Force a known path (external user has no path to inherit!). $ENV{"PATH"} = ".:/bin:/usr/local/bin"; # Create a LaTeX file with the data... if(-e "SetUp.tex"){unlink "SetUp.tex";} if(-e "SetUp.aux"){unlink "SetUp.aux";} if(-e "SetUp.dvi"){unlink "SetUp.dvi";} if(-e "SetUp.log"){unlink "SetUp.log";} if(-e "SetUp.ps"){unlink "SetUp.ps";} if(-e "junk1"){unlink "junk1";} if(-e "junk2"){unlink "junk2";} if(-e "comments.tex"){unlink "comments.tex";} system("sed -e s/Xobs/\"$ip{'obs'}\"/ \\ -e s/Xdob/\"$ip{'dob'}\"/ -e s/Xper/\"$ip{'per'}\"/ \\ -e s/Xap1/\"$ip{'ap1'}\"/ -e s/Xap2/\"$ip{'ap2'}\"/ \\ -e s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cl1'}\"/ \\ -e s/Xcl2/\"$ip{'cl2'}\"/ -e s/Xcl3/\"$ip{'cl3'}\"/ \\ TEMPLATE > SetUp.tex"); # Dump the comments in a file, include in Latex file with verbatim. system("cat other_h > other.tex"); system("echo \"$ip{'com'}\" >> other.tex"); system("cat other_t >> other.tex"); # Now Latex and produce a postscript file... system("latex SetUp.tex > junk1"); system("dvips -o SetUp$hits.ps SetUp.dvi > junk2"); ############################################################################## # (6) Generate return HTML page ############################################################################## $dateX = `date`; print < DFOSC Set-Up Form
[2p2 Logo]

DFOSC Set Up Form

[DK TN]

DFOSC Set-Up Form

Your Set-Up form has been generated as a postscipt file. To view it, click here.

You may save your DFOSC set-up forming by pressing the shift key and clicking here with the middle mouse button. Please mail the postscript file to 2p2team\@eso.org.


This Page Created:
$dateX
Since 10 Jun.98:
$hits
Comments:
jbrewer\@eso.org
end_of_print exit(0); sub parse_form_data { local (*FORM_DATA) = @_; local ( $request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; # HERE $value =~ tr/"\#"/R/; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{key})) { $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } sub return_error { local($status, $keyword, $message) = @_; print "Content-type: text/html", "\n"; print "Status: ", $status, " ", $keyword, "\n\n"; print <CGI Program -- Unexpected Error

$keyword


$message
Please contact $webmaster for more information. End_of_Error exit(1); }