Apache allows users to create documents which provide simple information to clients on the fly. Such information can include the current date, the file's last modification date, and the size or last modification of other files. In its more advanced usage, it can provide a powerful interface to CGI and /bin/sh programs.
SSI Issues
Having the server parse documents is a double edged sword. It can be costly for heavily loaded servers to perform parsing of files while sending them. Further, it can be considered a security risk to have average users executing commands as the server's user.SSI Setup
HTML files are not parsed for SSI by default. To tag a file for SSI, rename it ending in .shtml instead of .html or set the 'x' bit on the file (chmod a+x filename). The x bit method is prefered.The SSI Format
All directives to the server are formatted as SGML comments within the document. This is in case the document should ever find itself in the client's hands unparsed. Each directive has the following format:<!--#command tag1="value1" tag2="value2" -->
Each command takes different arguments, most only accept one tag at a time. Here is a breakdown of the commands and their associated tags:
-
configThe config directive controls various aspects of the file parsing. There are two valid tags:
errmsgcontrols what message is sent back to the client if an error includes while parsing the document. When an error occurs, it is logged in the server's error log.timefmtgives the server a new format to use when providing dates. This is a string compatible with thestrftimelibrary call under most versions of UNIX.sizefmtdetermines the formatting to be used when displaying the size of a file. Valid choices arebytes, for a formatted byte count (formatted as 1,234,567), orabbrevfor an abbreviated version displaying the number of kilobytes or megabytes the file occupies.
-
includeinclude will insert the text of a document into the parsed document. Any included file is subject to the usual access control. This command accepts two tags:
virtualgives a virtual path to a document on the server. You must access a normal file this way, you cannot access a CGI script in this fashion. You can, however, access another parsed document.filegives a pathname relative to the current directory. ../ cannot be used in this pathname, nor can absolute paths be used. As above, you can send other parsed documents, but you cannot send CGI scripts.
echoprints the value of one of the include variables (defined below). Any dates are printed subject to the currently configuredtimefmt. The only valid tag to this command isvar, whose value is the name of the variable you wish to echo.fsizeprints the size of the specified file. Valid tags are the same as with theincludecommand. The resulting format of this command is subject to thesizefmtparameter to theconfigcommand.flastmodprints the last modification date of the specified file, subject to the formatting preference given by thetimefmtparameter toconfig. Valid tags are the same as with theincludecommand.-
execexecutes a given shell command or CGI script. It must be activated to be used. Valid tags are:cmdwill execute the given string using /bin/sh. All of the variables defined below are defined, and can be used in the command.cgiwill execute the given virtual path to a CGI script and include its output. The server does not perform error checking to make sure your script didn't output horrible things like a GIF, so be careful. It will, however, interpret any URL Location: header and translate it into an HTML anchor.
SSI Environment Variables
A number of variables are made available to parsed documents. In addition to the CGI variable set, the following variables are made available:DOCUMENT_NAME: The current filename.DOCUMENT_URI: The virtual path to this document (such as /docs/tutorials/foo.shtml).QUERY_STRING_UNESCAPED: The unescaped version of any search query the client sent, with all shell-special characters escaped with \.DATE_LOCAL: The current date, local time zone. Subject to thetimefmtparameter to theconfigcommand.DATE_GMT: Same as DATE_LOCAL but in Greenwich mean time.LAST_MODIFIED: The last modification date of the current document. Subject totimefmtlike the others.