CHAPTER 4: NetWare CGI Scripts


CGI stands for Common Gateway Interface, that is a mechanism for accessing information other than text documents from the World Wide Web. A CGI program, known as a script, is run by the server to generate a document containing the information. The server then sends this information back to the web browser. Such scripts could return such dynamic information as the current time, server status, a random witty saying, or the results of a query to some database.

CGI scripts can also receive input from HTML forms. These forms allow the user to enter information for processing by the script. HTML forms cover a variety of input mechanisms; including text boxes, pull down menus, and radio buttons. The user's input can be used in scripts which query databases, collect survey information, order products and respond automatically to requests for more information. Scripts such as these greatly increase the flexibility and sophistication of your web pages.

NetBasic CGI Scripts

The simplest and most efficient method of supporting CGI Forms with GLACI-HTTPD is by using the new NetBasic scripting language bundled with it. NetBasic is a powerful Basic style scripting language with built-in features for processing CGI information. Simply place your NetBasic programs in the SYS:\NML\USERS directory. If your fill-in form reference a script with a BAS or NML extension in the /cgi-bin directory, GLACI-HTTPD will pass the request to the memory resident NetBasic interpreter. For example, if you have a fill-in form with the following FORM tag:

<FORM METHOD="POST" ACTION="/cgi-bin/testcgi.nml">

Submitting the form would cause the NetBasic NLM to process the script SYS:\NML\USER\TESTCGI.NML. The CGI environment variables and posted information are easily available to the script (no need to parse the raw input stream). High level functions make generating HTML output easy also. Refer to the NetBasic users manual for specifics on programming NetBasic scripts.

Perl Scripts and NLMs

GLACI-HTTPD also supports CGI scripting via the publicly available Perl NLM. The current revision of the CGI specification, 1.1, is designed primarily for UNIX type operating systems. As a result, some aspects of the specification are difficult to implement under NetWare. The following differences should be noted when writing or porting Perl CGI scripts or writing C/C++ programs to act as CGI backend processors. They do NOT pertain to writing NetBasic scripts

STDIN/STDOUT

The handling of stdin and stdout under GLACI-HTTPD is the biggest deviation from the CGI standard. Because NetWare cannot use I/O streams of one process as stdin/stdout of a spawned process, files must be used instead. The server generates to temporary filenames. It then stores the input, to the script, in one and waits to receive the output, from the script, in the other. The files are then deleted. We are working on a more efficient solution to this problem.

Under NetWare 4.0 and later, this is accomplished using the standard clib redirection when the process is spawned. The script can read and write from stdin/stdout normally and the file access will be done transparently.

If you are using version 3.11 or 3.12 of NetWare things are a little more complicated. In this case you must read input and write output directly to these files. The names of the files are passed in as commandline arguments. The input filename is argv[6], while the output filename is argv[7]. The easiest way to work with these file in 'C' is use the following commands

freopen(argv[6],'r',stdin);
freopen(argv[7],'w',stdout);

These commands will allow you to access the files through stdin and stdout normally through the rest of the program. Simply removing these two lines will leave a script that runs under NetWare 4.0. If you are using Perl, the following lines will do the same thing.

inFile = $ARGV[6];
outFile = '> ' . $ARGV[7];
close(STDIN);
close(STDOUT);
open(STDIN,$inFle);
open(STDOUT,$outFile);

ENVIRONMENT VARIABLES

The CGI specification includes several environment variables which are set by the server and can be user by the script as needed. NetWare does not support environment variables, so a subset of the variable list is passed to the script as command line arguments. The following chart lists the variable, its position in the argument list, and a description of the variable's purpose.


Variable Name    Argument   Description
                     
SCRIPT_NAME      argv[0]    Name of the cgi script
REQUEST_METHOD   argv[1]    HTTP request method, usually get or post.
SERVER_PROTOCOL  argv[2]    Should be HTTP/1.0
REMOTE_ADDR      argv[3]    Internet address of the client
CONTENT_LENGTH   argv[4]    Number of characters being sent by the client.
QUERY_STRING     argv[5]    The unparsed query string sent to the server
 			    as part of the requested URL.

Any variable which does not have a value will contain the string _CGI_NO_VALUE_ .