|
Manual page for Operating_in_CGI_mode(PL)
INVOKING PL AS A CGI PROGRAM
As of version 2.00,
pl
may be invoked directly as a CGI program, to dynamically
create plots without having to write images to temp files.
. CGI mode can produce pseudo-GIF, PNG, JPEG,
SVG or SVGZ
.
To set this up, copy your ploticusexecutable to your cgi-bin (or make
a link), and create a ploticus config file (see below).
The specifics of local CGI bin and file naming conventions vary;
see your local admin if having difficulty.
Then, use a construct such as this in your HTML page:
<img src="http://abc.org/cgi-bin/pl?cgi=1&scat1.pl&-png&-scale&0.8&
TITLE=Trailer%20Tongue%20Technologies">
This is equivalent to command line usage:
ploticus scat1.pl -png -scale 0.8 TITLE="Trailer Tongue Technologies"
cgi=1 should be the first parameter in your URL construct, as shown
in the above example.
After that, the regular
pl command line options and arguments
, including those for
prefabs
,
may be given in the usual order. However, to
conform to URL syntax, a question mark (?) must separate the program name
from the first argument, and ampersand (&) must be used to separate subsequent
arguments. Also, arguments should not be enclosed in quotes. Use %20 to represent
an embedded space, %26 for an embedded ampersand, etc (%XX may be used to represent
any problematic character, where XX is its hex ascii value). Arguments are limited
to a length of 250 chars each and may not contain embedded newlines.
CGI MODE BEHAVIOR
pl automatically goes into CGI mode if it detects the environment variable
REQUEST_URI (set by your web server), and there are no conventional command
line arguments given. ploticus behaves this way when in CGI mode:
-
a
ploticus config file
is required, and the config file must contain a
projectroot setting; other settings are optional. Here is an example
of such a config file:
-
projectroot: /home/steve/proj1
The config file
must have the same name as your ploticus executable, plus a .cnf extension
(if your ploticus executable name ends in .cgi the .cgi is ignored).
If ploticus must be used in several different contexts within the same cgi-bin,
you can make soft links to pl, using other names for the links, and have
a separate config file corresponding with each one. Examples:
ploticus executable name config file name
--------------------------- ---------------------------
/data/cgi-bin/ploticus /data/cgi-bin/ploticus.cnf
/data/cgi-bin/pl /data/cgi-bin/pl.cnf
/data/cgi-bin/plproj1 /data/cgi-bin/plproj1.cnf
/data/cgi-bin/pl.cgi /data/cgi-bin/pl.cnf
-
pl will operate from the projectroot directory. All filenames should
be expressed relative to projectroot. The script file must be
below projectroot. Script file names beginning with slash (/) or
dot (.), or containing double-dot (..) are prohibited. This
restriction does not apply to other files (eg data files).
-
command arguments are extracted from REQUEST_URI (HTML POST method is not supported).
SCRIPT_FILENAME is used to build the config filename.
These are environment variables that are set by your web server before
it invokes CGI programs.
If either of these are not available, ploticus will exit.
-
default output format is GIF, JPEG, or PNG depending on the ploticus build;
this can also be controlled via the arguments list.
-
an appropriate Content-type header is generated based on output format
type. This header as well as image content are written to standard output.
-
output is limited to one image or "page". To do multiple images, temp
files will need to be used.
TROUBLESHOOTING
When using ploticus in CGI mode, debugging is difficult because
diagnostics cannot be viewed, and the image content is being
streamed to standard output. If you are having trouble getting ploticus to work
in CGI mode, try the following:
cd to your cgi bin, deploy a new term window, and in the new window
manually set the REQUEST_URI and SCRIPT_FILENAME environment variables,
eg:
export REQUEST_URI="cgi-bin/pl?scat1.pl&-scale&0.8"
export SCRIPT_FILENAME="/data/cgi-bin/pl"
These exact variable names should be used.
REQUEST_URI should be the full URL, less the http://hostname prefix.
Full pathname should be given in SCRIPT_FILENAME so that ploticus can locate its config file.
Then, in the new window, invoke ploticus by hand, with no command line arguments:
$SCRIPT_FILENAME > out
Any error messages should be visible on screen.
In theory CGI mode should work with PNG, GIF, JPEG and SVG.
I noticed some flakiness with SVG. If the ploticus script argument was
last and I was generating SVG, MSIE wouldn't display it until I added a trailing &
to the URL. And, MSIE didn't understand SVGZs when generated in CGI mode.
CGI SECURITY
You should be fully familiar with CGI security issues and how
they relate to your platform and project,
before putting ploticus into
service as a CGI program. Some thoughts:
-
Anyone can easily view your HTML, including your invocation of CGI programs.
It is also very easy for users to submit modified CGI invocations (especially altered
arguments).
-
If you pass a data file name (or other filename) to ploticus via a varvalue argument,
use the following within your ploticus script to guard against hacks on the file name:
-
#if @DATAFILE inlike /*,.*,*..*
#exit
#endif
-
If you build a shell command from anything passed via a varvalue argument,
remove shell metacharacters from the variables using the
$shellstripchars function
.
-
CGI security worries can be avoided by invoking ploticus via the shell (ie. the old way),
capturing the results into a temp file, then using <img> to access the temp file.
The tradeoff is that this is less efficient due the temp file i/o.
|
 data display engine
Copyright Steve Grubb
|