#! /usr/bin/perl -s # # htls --- generate index of HTML directory hierarchy # # $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 -- # $Log: htls,v $ # Revision 1.1 1995/04/13 17:22:42 scg # Initial revision # # Jun 96, added date report $http = "http://www.iam.unibe.ch/~scg/Src/"; #v = "htls v1.0"; #v = "htls v1.1"; # -- fixed title generation $v = "htls v1.2"; # --Oct '95 Willem Mallon added a log of directories # --To prevent recursion. In verbose mode, all earlier # --encountered links will be mentioned 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", "\t-htgrep\t(HTGREP) generate searchable output for htgrep\n"; exit; } if ($htgrep) { $nt = 1; # htgrep => no titles or headings $verbose = 0; # htgrep => quiet } if ($#ARGV >= $[) { &head(join(", ",@ARGV)); foreach $arg (@ARGV) { %encounters = (); &log($arg); &htls($arg); } } else { ($title = `pwd`) =~ s|.*/||; &head($title); &log("."); &htls("."); } if ($htgrep) { } else {print "
\nThis page was generated by $v.\n"; $date = `date`; print "
\n$date", "\n\n\n"; } sub log {local($name) = @_; local($dev,$ino); ($dev,$ino) = stat($name); $encounters{"$dev:$ino"} = $name if (!($encounters{"$dev:$ino"})); } sub occured {local($name)=@_; local($dev,$ino); ($dev,$ino) = stat($name); if ($encounters{"$dev:$ino"} eq ".") {return "the top";} # :-) else { return $encounters{"$dev:$ino"}}; } sub head { local($title) = @_; $date = `date`; unless ($nt) { print "\n\nIndex of Packet Storm Security\n", "\n

Index of Packet Storm Security

\n"; "

\n$date

"; } } sub htls { local($dir) = @_; local($pre, $indent); local($path, $entry, @dirs, @list); local($rname); if ((-l $dir) && ($ns)) { } 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 { local($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__