Version 16 of CGI script for directory listing, simple posts and templates

Updated 2013-10-16 16:45:28 by Jorge

JM 29 Dec 2012 - When reading about Templates and subst on this wiki, I came across this web page [L1 ] and wanted to give it a try, on my Windows XP pc.

The apache installation on this machine comes from the xampp [L2 ] bundle and it was installed under: C:\xampp

These are the steps I have taken to setup this script and learn during that process (thanks Andy):

1.- Copied the tcl script [L3 ] to my C:\xampp\cgi-bin folder.
2.- Copied the site.css from [L4 ] in order to get the nice and simple style that you see there.
3.- Created a .htaccess file on my root folder (C:\xampp\htdocs) with the following contents:

# Enable URL rewriting.
RewriteEngine on

# Just let Apache send/process the file if it already exists.  This rule also
# prevents an infinite rewrite loop, since the rewrite maps to an existing file.
RewriteCond %{REQUEST_FILENAME} !-f

# Generate all directory listings, phony files, etc. with a script.
RewriteRule ^ /cgi-bin/site.tcl [L]

# Hide dotfiles.
<Files ~ "^\.">
   Order deny,allow
   Deny from all
</Files>

4.- Modified the site.tcl script to match my "site" (these are the few lines that I modified)

# Configuration.
set ::docroot xampp/htdocs
set ::baseurl http://localhost

Of course, you should also modify the mail and timezone variables for your own page.
5.- Finally, I just made a file called .desc (which are simply lists of three-element lists consisting of a title, an "epoch" time-stamp,see: clock seconds), and templatized HTML) with some dummy posts to see how it works. Here the contents of such file:

{title1 1356737274 "some content"}
{title2 1356737274 {some <a href="http://andy.junkdrome.org/">Andy</a> more content}}
{title3 1356737274 "some more content"}
{title4 1356737274 "and more content"}
{title5 1356737274 "some content"}
{title6 1356737274 "some content"}
{title7 1356737274 "some content"}
{title8 1356737274 "some content"}
{title9 1356737274 "some content"}
{titleA 1356737274 "some content"}
{titleB 1356737274 "some content"}
{titleC 1356737274 "some content"}

Final Notes:

  • .htaccess and .desc files are getting listed on my Windows PC, on Unix though, [glob *] skips dotfiles, at least 8.5.2's [glob] does. (As AMG explained to me). This is not good, but at least, its access is still forbidden. (I Think you could modify the glob statement on the site.tcl script to omit such files)
  • I have not explored yet the templatized html feature included on the script, that is a "to be continued" kind of thing...
  • Also, you will have a slot with a missing image on top of the page, for your site's logo/banner
  • You cannot create a .desc or .htaccess from the file explorer GUI in windows, you can however, create the files from DOS and/or wish

ImgAMGSiteCGI