#!/usr/local/bin/perl # # directory indexing script "ls.cgi" # # Reads a directory and builds lists of files and directories # there. Reads a template in from disk. Builds strings of the file # list and directory lists. Applies lists to template and prints to # standard output. # # copyright Bradley Dilger 1998-2001 # distributed under the GNU general public licence # http://www.fsf.org/copyleft/gpl.html # use strict; # dammit alarm(60); # prevent runaway CGI $Time = scalar localtime; # get time for later use ## VARIABLE DECLARATIONS ## # directory to start from $Dir = '/home/clasnet/YourName/public_html/'; # top-level URL of the user $Username = '/~YourName/'; # file name of template to read in for formatting output $Template = $Dir . '/ls.txt'; # name of this script, fully resolved as URL $File_name = $Username . 'cgi/ls.cgi'; # name of readmes to add in to each index $Readme_file = 'README'; # HTML header $HTML = "Content-type: text/html\n\n"; ## MAIN STUFF ## ## You shouldn't have to hack anything beyond this point ## ## ... hopefully :) ## if ($ARGV[0]) { # argument given, copy and process it $Argument = $ARGV[0]; $Argument =~ s![^a-zA-Z0-9\_\-\./]!!g; # allow only certain characters $Argument =~ s/\.\.//g; # kill any .. $Argument =~ s!^/.*!!; # kill start from slash # make name of directory to work with $Directory = $Dir . $Argument; $Argument .= '/'; } else { # no argument given $Argument = ''; $Directory = $Dir; } # read in and prepare the template open (TEMPLATE, $Template) or die "Oops, no template; halted"; @Template =