--- loncom/cgi/plot.gif 2001/12/21 16:10:58 1.7 +++ loncom/cgi/plot.gif 2004/06/21 20:04:29 1.11 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: plot.gif,v 1.7 2001/12/21 16:10:58 matthew Exp $ +# $Id: plot.gif,v 1.11 2004/06/21 20:04:29 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,21 +29,46 @@ use strict; $|=1; my $tmpdir = '/home/httpd/perl/tmp/'; -my $filename = $ENV{'QUERY_STRING'}; - -if ($filename =~ /\// | - $filename !~ /_plot.data$/) { - die; +my %data; +foreach (split/&/,$ENV{'QUERY_STRING'}) { + my ($name,$value)=split/=/; + $data{$name}=$value; } +my $filename = $data{'file'}; +# unescape filename +$filename =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; + +die if ($filename =~ /\// || $filename !~ /_plot.data$/); $filename = $tmpdir . $filename; -if (-e $filename) { +die "$data{'file'} does not exist\n" if (! -e $filename); + +my $output = $data{'output'}; +if ($output eq 'gif' || $output eq 'png') { open PLOT, "gnuplot $filename |"; print <<"END"; -Content-type: image/gif +Content-type: image/$output END while ($_=) { print; } -} +} elsif ($output eq 'eps') { + print <<"END"; +Content-type: text/html +eps plot creation + +

Creating eps plot

+ +END + if (! system ("gnuplot $filename")) { + print "

An error occured.

\n". + "I am not going to tell you about it as I have not bothered ". + "to figure out how to get you the error text.\n"; + } else { + print "

EPS file generated successfully.

\n"; + } + print "\n"; +} else { + die "output $output is not a recognized value or has no value\n"; +}