#!/usr/bin/perl -sw # # htls --- generate index of HTML directory hierarchy # http://packetstorm.securify.com/crypt/htls # # original Id: htls,v 1.1 1995/04/13 17:22:42 scg Exp # # Oscar Nierstrasz 9/9/94 # 20/10/94 -- added -htgrep option # # NB: It might be useful to have an option to automatically # create toc.html files in each subdirectory ... # # This script and friends can be found at: # http://www.iam.unibe.ch/~scg/Src/ # # -- RCS log -- # Revision 1.2 2004/09/30 17:17:33 # Fixed perl path # --Oct '95 Willem Mallon added a log of directories # --To prevent recursion. In verbose mode, all earlier # --encountered links will be mentioned # # Revision 1.1 2001/06/02 23:36:22 # fixed title generation # # Revision 1.0 1995/04/13 17:22:42 scg # Initial revision # # Jun 96, added date report use strict; my $h; my $ht; my $htgrep; my $ns; my $r; my $title; my $verbose; my $http = "http://packetstorm.securify.com/crypt/htls"; my $v = "htls v1.2"; my $mypage = "My page title goes here"; my $htmlroot = "/doc/html/htdocs"; # don't print this in URL my $date = `date`; if ($h) { print "Usage: htls []\n", "\t-ht\t(HTml) only list HTML files\n", "\t-d\t(Directories) generate directory links too\n", "\t-r\t(Reverse) reverse directory listing\n", "\t-nt\t(NoTitle) suppress title and heading\n", "\t-verbose\t(Verbose) report all links.\n"; exit (0); } my $arg; my %encounters; if ($#ARGV >= $[) { &head(join(", ", @ARGV)); foreach $arg (@ARGV) { %encounters = (); &log($arg); &htls($arg); } } else { ($title = `pwd`) =~ s|.*/||; &head($title); &log("."); &htls("."); } print "
\nThis page was generated by\n$v.\n"; print "
\n$date", "\n\n\n"; exit(0); sub log { my ($name) = @_; my ($dev, $ino); ($dev, $ino) = stat($name); $encounters{"$dev:$ino"} = $name if (!($encounters{"$dev:$ino"})); } sub occured { my ($name) = @_; my ($dev, $ino); ($dev, $ino) = stat($name); if (defined($encounters{"$dev:$ino"}) && $encounters{"$dev:$ino"} eq ".") { return "the top"; } # :-) else { return $encounters{"$dev:$ino"}; } } sub head { my ($title) = @_; print "\n\nIndex of $mypage\n"; print "\n

Index of $mypage

\n"; print "$date
\n
\n"; } sub htls { my ($dir) = @_; my ($pre, $indent); my ($path, $entry, @dirs, @list); my ($rname); if ((-l $dir) && ($ns)) { 1; } elsif (-f $dir) { @list = ($dir); $pre = ""; } elsif (-d $dir) { if (opendir(DIR, $dir)) { @list = sort(readdir(DIR)); closedir(DIR); if ($dir =~ /^\.$/) { $pre = ""; } else { $pre = "$dir/"; } } else { print "unreadable\n" unless ($htgrep); } } else { return; } # ?! unless ($htgrep) { $indent = $pre; $indent =~ s|[^/]||g; $indent =~ s|/| |g; } print "${indent}\n" unless ($htgrep); } # extract and return the title of a document sub title { my ($file) = @_; local ($/) = "<"; open(FILE, $file) || return "UNREADABLE"; return $file unless ($file =~ /\.html$/); $title = $file; # default, in case no title found while () { /^title>\s*([^<]*)/i && ($title = $1) && last; } close(FILE); $title =~ s/\s*$//; $title =~ s/\n/ /g; $title =~ s/\s+/ /g; return $title; } __END__