Nomad and HTTP and CGI, Oh My!

Part IV: A simple web page, a simple CGI program

Well great, you've got a spanking new web server and all it does is display some advertisement for some other company. How do you make the web server display your own custom web pages?

Webshare is set up to display the file INDEX HTML as the default web page. So by editing INDEX HTML, you can start to build your web site.

Webshare allows you to execute CMS commands from the web server console while the webserver is running, which makes for a great interactive edit/test environment. Of course the webserver won't serve pages while your CMS commands are executing (i.e. if you are sitting in Xedit) so you wouldn't want to do this on a production webserver, but it's great on a test server.

So, you can start customizing your web site by XEDITing INDEX HTML right at the Webshare console. I'm not going to go into HTML in this series, but you can find a good HTML tutorial at http://www.boutell.com/faq/#authoring.

Webshare uses the concept of FILELISTs to determine what files are "published" from your webserver. FILELISTs are simply lists of files. You can list other FILELISTs within FILELISTs to build a Unix-like or SFS-like structure of directories and sub-directories.

The default installation of Webshare provides a reference to a LOCAL FILELIST, all we need to do is list our files in LOCAL FILELIST and they will appear to be stored a subdirectory called LOCAL.

From the Webshare console create the file LOCAL FILELIST as shown below.

*Column 1 must have a space or use a * for comments
 WEBPAGE1 HTML *
 WEBCGI1 *CGI *

This will set us up for a web page and a CGI script, which we will write shortly. Note that each line must start with a space or an * and that *s are used for comments.

Our first web page will simply provide a link to our first CGI script, so that we can begin to see dynamic output from our web site. Again, from the Webshare console create the file WEBPAGE1 HTML as shown below.

<HTML>
<BODY>
<A HREF="WEBCGI1">Click here to run your CGI script</A>
</BODY>
</HTML>

And now it's time to write our first CGI script. I suppose now is also a good time to explain what CGI is. We'll start with the acronym itself, CGI stands for Common Gateway Interface. Well, that told us nothing! Think of your web browser as nothing more than a really fancy TYPE command. You know, you sit at a CMS Ready; prompt and enter TYPE PROFILE EXEC and the file PROFILE EXEC fills your screen. A web browser is the same thing, you can use it to display the contents of a file that resides on your computer, your web server or somebody else's web server half-way around the world. The point is, all a web browser does is display the contents of a pre-existing file.

What CGI does is allow a web browser to request that a program be executed on the web server. So rather than TYPE PROFILE EXEC the web browser performs an EXEC PROFILE EXEC and the output from the program is sent half-way around the world to somebody's web browser.

In the Webshare world CGI scripts are just CMS Rexx EXECs with a filetype of CGI (it's really more than that, but we'll cover it later.) We are going to create a simple CGI that just sends the current time to the browser. From the Webshare console create the file WEBCGI1 CGI as shown below.

/* Rexx needs a comment */
'OUTPUT' DATE() TIME()

Or course, if this were a regular Rexx EXEC you would have used the SAY command to send the output of the DATE and TIME functions to the console, but here we use the 'OUTPUT' command to send the output across the network to the web browser.

Exit your editor so that Webshare can begin serving web pages again, fire-up your web browser and enter http://vm.testing.com:8080/local/webpage1.html (of course you'll substitute vm.testing.com:8080 with your VM host and port.) You should be greeted with a stark web page that looks something like:

Click here to run your CGI script
Clicking the link should bring you an equally stark page showing the current date and time on your web server. Something like:
30 Sep 1997 01:59:41

Use your browser's "back" button to select the link again and convince yourself that the output is dynamically changing every second!

Let's spice up our CGI output a little to get an idea of how a CGI script can mix HTML and standard program flow control. Modify WEBCGI1 CGI as shown below.

/* Rexx needs a comment */
'OUTPUT <HTML>'
'OUTPUT <H1><CENTER>'
IF TIME('H') < 12 THEN DO
   'OUTPUT Good Morning'
   END
ELSE IF TIME('H') < 17 THEN DO
   'OUTPUT Good Afternoon'
   END
ELSE DO
   'OUTPUT Good Evening'
   END
'OUTPUT </CENTER></H1>'
'OUTPUT It is' DATE() TIME()
'OUTPUT </HTML>

And again use your browser to execute your program.

We've learned that Webshare can cause a Rexx EXEC to execute and send its output to the web. Many of you probably have experience writing Rexx EXECs that cause Nomad programs to run either as batch jobs or interactively. Could we simply write a Rexx CGI that calls a Nomad program and have its output sent to the web?

This series was never completed, work shifted to the Nomad Server Pages (NSP) project available in the Downloads library.


Back

Feel free to send questions or other feedback to me, also drop me a line if you'd like e-mail notification of new installments in this series.

©1997 Don DeCosta, All Rights Reserved