1
0
0
AN INTRODUCTION TO WRITING WEBSHARE CGI SCRIPTS
+ AN INTRODUCTION TO WRITING WEBSHARE CGI SCRIPTS
0
Melinda Varian
0 Office of Computing and Information Technology
Princeton University
87 Prospect Avenue
Princeton, NJ 08544 USA
--.--
Email: Melinda@Princeton.EDU
Web: http://PUCC.Princeton.EDU/~Melinda
Telephone: 1-609-258-6016
0
VM Workshop
June, 1996
0
Rick Troth, the great builder of VM tools for the Internet, is the
author of a widely-used VM Web server called Webshare. You can get
Webshare from Rick's home page:
0 http://ua1vm.ua.edu/~troth/
0 One of the many nice features of Webshare is that its Common Gateway
Interface (CGI) routines are written as CMS Pipelines filters. Thus, if
+ _____________
you serve Web forms from a Webshare server, you can process the input
from those forms using REXX and CMS Pipelines. In this session, I will
+ _____________
introduce some Pipelines techniques that you may find useful in writing
+ _________
CGIs for Webshare, but much of what I will be discussing here is
applicable to using Pipes for writing service machines in general.
+ _____
0 If you are a Web page novice, there are many places to turn for help:
0 o You will need to learn some HTML (Hyper-Text Markup Language). HTML
is a formatting language rather reminiscent of GML and is so simple
that there is not much to learn. A good place to start is at the NCSA
Web site:
0 http://www.ncsa.uiuc.edu/General/Internet/WWW/HTML.Primer.html
0 That will get you to NCSA's HTML primer. In the primer, you will find
links to other, more advanced papers, including some on HTML forms,
which you will need to learn about before doing a Web page that
invokes a CGI.
0 o You will also want to learn about writing CGI routines in REXX. The
best person to teach you that is Les Cottrell at SLAC:
0 http://www.slac.stanford.edu/~cottrell/rexx/share/
1
0 Page 2 Writing Webshare CGI Scripts
------------------------------------------------------------------------
0
Les has written a very good introduction to the concepts of CGI
routines in general and of REXX CGI routines specifically. Although
his examples are written in uni-REXX, they are quite applicable to VM.
0 o You should also read all of the help files that come with Webshare.
They are sparse, but informative.
0 o You will likely find it useful to subscribe to the WWW-VM mailing
list. You can do that by sending email to listserv@sjuvm.stjohns.edu
and making the body of your mail the words "subscribe www-vm" followed
by your name. WWW-VM is a very good place for asking questions about
implementing Web pages under VM.
0 o You will also want to learn to use an HTML validation service and to
use it to check your forms before you put them into production. One
service that I use is:
0 http://www.webtechs.com/html-val-svc/
0 Now, let's start with the HTML for a very simple Web form:
0 +----------------------------------------------------------------------+
| |
| |
| |
|
Sample Form for Sample CGI |
| |
| |
| |
|
|
| |
|
|
| |
| |
| |
| |
| |
+----------------------------------------------------------------------+
1
0 Writing Webshare CGI Scripts Page 3
------------------------------------------------------------------------
0
This example builds a Web form that prompts the user for two fields, a
userid and a password. When the user clicks on the "Send" button, the
specified action takes place, which means in this case that the Web
server invokes a program named POSTTEST CGI, passing it the information
that the user entered into the form.
0 When your Webshare CGI is invoked, it has four sources of information:
0 1. The primary input stream for your CGI routine contains the data
that the user posted to your Web form. There is one input record per
field, each record in the format: name=value.
0 2. The secondary input stream for your CGI routine contains one record
per HTTP header line; you are not likely to need this information in
the beginning.
0 3. The standard CGI "environment variables" are available to your CGI
through the CMS GLOBALV command. Enter HELP CGI ENVIRONMENT to get a
list of the variables.
0 4. If the URL that addressed your CGI contained a question mark,
anything after that question mark is passed as a calling argument.
You can access it using a REXX Parse Arg instruction.
0 Your CGI routine has a single output stream, in addition to its two
input streams. When you write HTML on that output stream, it is sent to
the client browser to be displayed for the user.
0 Since a Webshare CGI routine is a pipeline stage, you need to understand
the basics of writing a REXX pipeline filter, but little more than that
is absolutely necessary. If you wish, you can simply read the input
records using the CMS Pipelines PEEKTO or READTO commands and write your
+ _____________
responses to the user using OUTPUT commands. The CMSHELP CGI that comes
with Webshare illustrates this technique quite well, so we will
concentrate instead on writing CGI routines that make more interesting
uses of CMS Pipelines.
+ _____________
0 Our simple Web form invoked POSTTEST CGI, which comes with Webshare.
POSTTEST is a good thing to play around with when you are starting to do
your own forms and CGIs. It is invoked from a form to display the
values entered on the form. Here is a portion of POSTTEST:
0 +----------------------------------------------------------------------+
| |
| /* Copyright 1994, Richard M. Troth |
| * |
| * Name: POSTTEST CGI |
| * to verify the correct operation of HTML "forms" |
| * Author: Rick Troth, Houston, Texas, USA |
| * Date: 1994-Aug-15 |
| * last updated for CMS HTTP 1.1.6 and 1.1.6v |
| */ |
| |
1
0 Page 4 Writing Webshare CGI Scripts
------------------------------------------------------------------------
0
| 'OUTPUT' "" /* Start HTML stream. */ |
| |
| . . . |
| |
| 'OUTPUT' "
Results (what you posted, if anything):
" |
| 'CALLPIPE', /* Display posted fields: */ |
| '*: |', /* Stream 0 is posted fields. */ |
| 'change /</ |', /* Make "<" safe to display. */ |
| 'change />/>/ |', /* Make ">" safe to display. */ |
| 'spec 1-* 1 /
/ next |', /*
at end of each line. */ |
| '*:' /* HTML output to browser. */ |
| |
| 'OUTPUT' "
Environment (of the server):
" |
| |
+----------------------------------------------------------------------+
(continued)
1
0 Writing Webshare CGI Scripts Page 5
------------------------------------------------------------------------
0
+----------------------------------------------------------------------+
| |
| 'CALLPIPE', /* Display environment variables: */ |
| 'command GLOBALV SELECT HTTPD LIST |', /* Environment vars. */ |
| 'drop first 1 |', /* Drop title line. */ |
| 'nfind _TYPE.| nfind _PIPE.|', /* Discard uninteresting stuff.*/ |
| 'nfind _GTYPE.| nfind _MTYPE.|', |
| 'sort |', /* Sort by variable name. */ |
| 'change /</ |', /* Make "<" safe to display. */ |
| 'change />/>/ |', /* Make ">" safe to display. */ |
| 'spec 1-* 1 /
/ next |', /*
at end of each line. */ |
| '*:' /* HTML output to browser. */ |
| |
| 'OUTPUT' "
" /* Show end of HTML. */ |
| |
+----------------------------------------------------------------------+
0 POSTTEST first issues an OUTPUT to write a record denoting the beginning
of an HTML file. The next OUTPUT writes the header for a display. Then
a CALLPIPE is used to read the posted fields from the primary input
stream, massage them to encode left and right carets, insert a line
break at the end of each record, and then write them out to the browser,
thus reflecting the data from the form back to the user as HTML.
Another OUTPUT writes another header and another CALLPIPE is used to
issue a CMS GLOBALV command to get the environment variables, which are
formatted as HTML and sent on the output stream to the browser.
Finally, another OUTPUT command writes the record denoting the end of an
HTML stream.
0 Thus, when your form invokes POSTTEST, you can see the data that your
own CGI will receive when you change the form to invoke your CGI rather
than POSTTEST. When you are ready to do that, you might change the
ACTION attribute of the HTML FORM tag as follows:
0