Next -> Example Scripts
One of the greatest things about scripting, in general, is the new level interactivity it engenders. If you've ever visited a web site where you filled out a form, navigated using a pop-up menu, or were served content based on your browser, you've benefited from scripting. The NPDS scripting system doesn't allow much in the way of actual interaction (YET) but it does have access to several parameters that tell you a bit about who the person is on the other end of the connection.
In implementing SSA, I have made an effort to maintain syntax and variable names that are consistent with other platforms' scripting implementations. This will help users who come to us from other languages (ie Perl) as well as make applicable to NPDS scripting some of the literature on the web that pertains to CGIs.
Being a evolving subset of the Common Gateway Interface, NPDS SSA provides the scripter with the following run-time CGI variables. (Bold Values are literals, others are dynamic values).
Variable
String
Returned
SERVER_SOFTWARE
nHTTPd/2.02 (Newton)
SERVER_NAME
IP Address of Server
SERVER_PROTOCOL
HTTP/1.0
GATEWAY_INTERFACE
CGI/1.0 (NPDS_SSA)
SERVER_PORT
Current Server Port
REMOTE_ADDR
Client IP Address
REMOTE_HOST
Client DNS (If Resolved)
HTTP_USER_AGENT
Client Browser
SCRIPT_NAME
Title of Current Script
Some of these are pretty useless for now but will not be in the future ;-) Note, however, what you DO have access to from your SSI scripts that you can exploit readily.. Client IP Address (DNS as well if it's already been determined) and Client Browser. Can you think of a situation where these might be of use?
Let's go all out here and write an SSI that will show the notes posted via the web but only if the user is coming from within a specific LAN. Furthermore, let's return this listing in two different formats, table and list, depending on the browser/platform. Of course, visitors from outside the LAN are given a polite error message.. How's that for a "Simple" Script ? Getting pretty powerful here, eh?
How do we check to see that an IP is within range? Luckily for you, NPDS has a built-in IP checker method called CheckIP(). To see if the IP "128.174.5.58" is within the range "128.174.4.255" to "128.174.5.255" you would use CheckIP() like so:
|NPDS|:CheckIP("128.174.5.58",
["128.174.4.255", "128.174.5.255"])
The variables returned by the tokens such as SERVER_NAME, etc. are all simple string values. You treat them exactly like they were strings.
If the Remote Address of the Client was
"127.0.0.1" then theAddr:= "REMOTE_ADDR" would evaluate
to theAddr:= "127.0.0.1".
The NoteServ Server Side Includes for displaying HTML-formatted lists of Notes are implemented using a common (and still under development) Method, ReturnNoteList.
In order to return a list of posted notes, you write:
|NoteServ|:ReturnNoteList({order:
'ascending, criteria: 'timestamp}, '|pHTML:MAVON|,
'list)
While a table of the same notes is created by:
|NoteServ|:ReturnNoteList({order:
'ascending, criteria: 'timestamp}, '|pHTML:MAVON|,
'table)
|
Name: Restricted List |
SSI: COOL_LIST |
|
|
|
It's pretty much that easy. Note the syntax of the nested if..then..else statements1 as well as the use of the StrPos()2 method to search for a substring within the user agent field. Finally, make sure to notice the use of the |NoteServ| compiler variable to save us from having to type the full reference to NotePad server GetRoot().|pHTML:MAVON|
1. NPL: 3-1 to 3-3
2. NPR: 23-26