Using Lisp as a CGI Processor on cubist.cs.washington.edu
This page explains how to use Gnu Common Lisp
(gcl) to implement online conversational agents
There are several things you need to know
about:
-
Accessing your account on our web server:
Each student in the class has or will have an account on cubist.cs.washington.edu.
The account names have been set up by the lab staff according to a class
registration list. To log in on cubist, use your CSE kerberos password.
-
Creating your www directory.
Each student needs to create a subdirectory of their home directory with
the name www. Do this by typing in your home directory:
mkdir www
-
Installing an html page and testing it.
Try creating an ordinary web page with a filename such as index.html and
put it in your www directory. Use a web browser on some other machine
and see if you can access the page. If your user name is joey, then
the URL would be
http://cubist.cs.washington.edu/~joey/index.html
-
Installing a CGI script and testing it.
The next thing to try is installing a simple Lisp program that begins with
the line:
#! /usr/local/bin/gcl.exe -f
and that prints out the correct HTTP header
info before anything else. It's the description of the type of content,
followed by two newline characters. To keep life simple, just use
the following line of Lisp:
(format t "Content-type: text/html~%~%")
Then put in some more FORMAT lines to
create some text in the page. For example, to create a page with
just a heading, you could use
(format t "<html><body><h1>This
is my Lisp CGI script's")
(format t " output!</h1></body></html>~%")
Back in Linux's bash (i.e., on your
regular command line) be sure to type something like
chmod +x mycgi.lsp
(or whatever your filename is, as long
as it ends with .lsp) to make the program executable. Try accessing
that script with your browser with a URL such as
http://cubist.cs.washington.edu/~joey/mycgi.lsp
-
How to process POST requests from the user.
The key here is to read a string from standard input and parse it to obtain
a collection of parameter-value pairs. These pairs are the info sent
by the browser. The example program shows how to do this. You
can run the
sample program and you can examine
the source code. It uses my package
of Lisp CGI and HTML routines.
-
How to set a cookie on the user's browser.
This will allow the next POST or GET to let the server know who the info
is coming from. (See the same example program).
-
How to read a cookie on the user's browser.
Once we have set the cookie, we need to read it in subsequent requests
from the browser. (See the same example program).
-
How to create a session file.
The way to maintain session continuity from one user request to the next
is to keep a file on the server for each session in progress. The
name of the file should be based on the user's unique information, so that
it doesn't get mixed up with session files of other users. (See the same
example program).
-
How to debug your script. "What
do I do when I get `Internal Server Error'?". One thing you can do is look
at the Web server's error messages. Here are today's error
messages with your username.
Some documentation on GCL is available here.
Each student should be aware that CGI script writing involves system
security risks. We all need to cooperate to see to it that we can
all have a successful learning experience and avoid security lapses.
Please read the WWW
Security FAQ to get familiar with basic security issues.
(C) Steven Tanimoto, 2000
tanimoto@cs.washington.edu