Commands for the server to parse are stored as comments in the body of the HTML page. If the server cannot parse the file (for example, if the execute permission is not set) it returns the unparsed HTML to the browser.
The commands have this format:
<!--#command arg="value" -->
Each command accepts different arguments. For example, this command includes a separate file within the page:
<!--#include virtual="../includes/header.txt" -->
Only the #config
command allows you to specify more than one argument (separated by spaces) on the line.
Here is a list of the commands you can use and their arguments:
The #config
command controls how the file is parsed. These are the arguments it accepts:
errmsg
defines a message to be sent back to the browser if an error occurs while parsing the document. If an error occurs, it is also logged in the server's error log.
timefmt
defines a format the server will use to display dates and time for the #flastmod
command and any environment or special variables that contain a date or time. This is a string compatible with the strftime
library call under most versions of UNIX. See page 6 for a summary of the formats you can use. The default format is Fri Nov 03 17:23:07 1996
(%a %b %d %H:%M:%S %Y
).
sizefmt
determines the format for the output of the #fsize
command. You can use "bytes
" for a byte count (such as 1,234,567) or "abbrev
" to use an abbreviation of KB or MB.
Examples: <!--#config errmsg="File could not be parsed" -->
<!--#config sizefmt="bytes" timefmt="%A %b %d"-->
The #echo
command includes the value of one of the environment variables defined for CGI programs (see page 18) or one of the special variables listed on page 7. The only argument is "var
", whose value is the name of the variable you want to output.
Example: <!--#echo var="HTTP_USER_AGENT" -->
The #exec
command runs a shell command or CGI program. The valid arguments are:
cmd
" runs the string you specify using /bin/sh
. All of the environment variables defined for CGI programs (see page 18) and in the next section can be used in the command.
cgi
" runs the CGI program you specify and includes its output in the page. The server does not check to make sure your CGI program outputs text or HTML. However, your program can output an HTTP Location: header and the server will translate it into an HTML anchor. The file reference should be relative to the pages directory of this virtual server.
Note: You can disable the #exec
command by using the NoExec option in the Map parameter in the server setup pages. You may want to disable this command for security reasons.
Examples: <!--#exec cmd="ls -ltr" -->
<!--#exec cgi="cgi-bin/fill_in" -->
The #include
command inserts the contents of the file you specify at the location of the #include
command. The user must have read access to the file that gets included. If the file that is included has a file extension or location that causes it to be parsed by the server, that file can in turn include other files.
Make sure files you include contain only tags that are appropriate in the context of the files that include them. For example, don't use the <HTML>, <HEAD>, or <BODY> tags (or their end tags) in a file that will be included in another file that already contains these tags.
The #include
command accepts either of the following arguments:
file
" gives a relative reference to the file you want to include. The path is relative to the directory containing the file that uses the #include
command. You cannot use absolute paths with this argument. To keep your non-public directories secure, a page cannot use relative paths that traverse upward through the directory structure (that is, it cannot use paths that contain ../
).
virtual
" gives the path to a file relative to the page root directory for the server.
One difference between these two arguments is that "file
" uses the physical file structure on the server machine, while "virtual
" uses the structure seen from the outside by those accessing the server.
Examples: <!--#include file="include.txt" -->
<!--#include virtual="/doc/cust/include.txt" -->
The #flastmod
command prints the last modification date of the file you specify. It uses the format specified with the timefmt
argument to the #config
command. The valid arguments are virtual
and file
, which have the same functions as they do for the #include
command.
Example: <!--#flastmod file="/sub/myfile.html" -->
The #fsize
command prints the size of the file you specify. It uses the format specified with the sizefmt
argument to the #config
command. The valid arguments are virtual
and file
, which have the same functions as they do for the #include
command.
Example: <!--#fsize virtual="/sales/sub/myfile.html" -->
The #nstcl
command executes a Tcl script. Its only argument is script
, whose value is the Tcl function, along with its corresponding arguments, that you want to execute. For example, you can execute a one-line script in an HTML page as follows:
<!--#nstcl script="ns_info build" -->
Here is a more complex example of a script to be executed in an HTML page. This Tcl script queries the database and returns an HTML unnumbered list of the results:
<HTML> <HEAD> <TITLE>All Employees</TITLE> </HEAD> <BODY> <H1>All Employees</H1> <!--#nstcl script=" # This example queries a database in the default # pool and returns a list of all the employees listed # in the employees table. It assumes a table called # employees exists with the column emp_name. You can # use the /NS/Db/Admin to create the table. # # Note: You must have database services activated in your # virtual server for this example to work. set ul {<UL>} set db [ns_db gethandle] set row [ns_db select $db \ {select emp_name from employees order by emp_name;}] while { [ns_db getrow $db $row] } { append ul <LI>[ns_set get $row emp_name]\n } append ul {</UL>} set ul" --> </BODY> </HTML>
Note that since the entire Tcl script must be surrounded with double quotes ("), you cannot use any double quotes in the script itself.
Note that if the "NoExec" option is set in the Map parameter, the #nstcl command is disabled.
This table shows some of the formats you can use to create the date/time format for the timefmt
argument to the #config
command. (See the strftime
UNIX man page for more details.) In addition, you can use any punctuation in the formatting string, including %t for a tab and %n for a line break.