home ~ back

Michael Edwards - Software - SSI.PL

 

Download the perl script.


Description

This script simulates the basic server-side include (SSI) features of a web server. At the moment however, only the #include part is available (i.e. no #exec, #echo etc., and in fact, I don't have any plans to go any further with this).

This means that you are able to write lines like the follwing in your HTML files:

<!--#include virtual="/include/header2.html"-->

or

<!--#include file="../local_header.html"-->

and at these points the contents of the given files will be spliced in.


'File' and 'Virtual' includes

The difference between file="..." and virtual="..." is that the former path is relative to the current directory and the latter is relative to the server root of the web server (if you don't know what the server root is, then you'll probably only ever want to use the former).


Usage

The script works on entire web sites and single files alike. If you want to process a single file, type something like:

> ssl.pl myhtmlfile.html

The file myhtmlfile.html will now contain the text of the include files and the original file will be copied to myhtmlfile-pre-ssi.html.

If you want to process all the files in a directory and its subdirectories (i.e. a whole web site), then type something like:

> ssl.pl /user/michael/public_html /tmp

Both directories must exist already. The files in the first (source) directory will then be recreated in /tmp/public_html (note that the directory public_html--or whatever the name of the last directory in the source is--will be created inside the given target directory). Qualified files will be processed (i.e. those that are designated as liable to contain SSIs) whereas all other files will be simply copied. You then have an exact mirror of your web site with all of the SSI directives expanded and ready to function on web servers upon which you have no SSI rights.


Configuration

Before using the script, be sure to check the variables at the top of the script where I've written
# Globals. Change these according to your needs.

The variable $ServerRoot is exactly that and should reflect your web server's root directory should you want to use the 'virtual' SSI feature.

The variable @SSIExtensions is a list of the file extensions that may contain SSI directives. Obviously, no GIF file will contain SSIs so these files are simply copied. HTML files may contain SSIs, but some servers are set up to restrict only files with the extension .shtml to having SSI directives. You can do it however you want. If you just want .shtml files to be processed, leave the variable as it is. If you were to want all .shtml, .html and .htm files to be processed, change it to the following.

my @SSIExtensions = ("shtml", "html", "htm");

Note that files with these extensions do not have to contain SSIs, but they will be examined to see if they need processing, whereas all other files will be simply copied.

The variable @Excludes is a list containing the extenstions of files that shouldn't be copied (e.g. large files that you don't always want to copy when testing). E.g.

my @Excludes = ("mp3", "wav");

Don't forget to change the path of your perl executable at the top of the file to reflect the location of perl on your system.