#!/usr/bin/perl #==========================================# # Author: Marius Feraru aka AltBlue # # E-Mail: altblue@tuiasi.ro # # URL : http://www.cs.tuiasi.ro/altblue/ # # http://bofh.mednet.ro/altblue/ # #==========================================# # v0.2 $index = 'index.html'; $version = '0.2'; unless($ARGV[0] && -d $ARGV[0] && -W $ARGV[0]) { print < ERROR: directory not found or not writeable. Usage: $0 [v][r][f] v: verbose r: recursive f: force (ignores old index.html files! use w/ care!) USAGE exit 1; } $verbose = $ARGV[1] =~ /v/ ? 1 : 0; $recursive = $ARGV[1] =~ /r/ ? 1 : 0; $force = $ARGV[1] =~ /f/ ? 1 : 0; $directory = $ARGV[0]; verbose("HTML Indexer v.$version by AltBlue "); if($recursive) { abhindex($directory); abtree($directory); } else { abhindex($directory); } exit 0; #### Routines.... #### The Real Indexer ;-> sub abhindex { local $dir = $_[0]; local @files=(); local @dirs=(); local @attr=(); local $decoder; if (-f "$dir/$index") { if($force) { verbose("'$dir/$index' already exists. overwriting."); } else { verbose("'$dir/$index' already exists. skipping."); return undef; } } if(opendir(DIR, $dir)) { verbose("'$dir' succesfully opened. Processing..."); foreach (readdir(DIR)) { next if $_ eq '.' || $_ eq '..' || $_ eq $index; if(-d "$dir/$_") { push(@dirs,$_); } else { push(@files,$_); } } closedir(DIR); } else { verbose("ERROR: couldn't open '$dir' : $!"); return undef; } if(open(INDEX,">$dir/$index")) { verbose("'$dir' processing completed. writing index file."); print INDEX "\n\n\tAltBlue Indexer: $dir\n\n\n
\n\t

$dir index

\n\t
\n
\n\n

\n\t

    \n"; foreach(@dirs) { $decoder = abdecode($_); print INDEX "\t\t
  • $_\n"; } foreach(@files) { $decoder = abdecode($_); @attr = stat("$dir/$_"); print INDEX "\t\t
  • $_ ($attr[7] bytes)\n"; } print INDEX "\t
\n

\n\n

\n\t
\n
\n

\n\t

\n\t\t\n\t\t\t\n\t\t\t\tThis page was produced by a web utility engineered by \n\t\t\t\tAltBlue <altblue\@tuiasi.ro>\n\t\t\t\n\t\t\n\t
\n

\n\n\n"; close(INDEX); verbose("'$dir/$index' was written."); } else { verbose("ERROR: couldn't open index file : $!"); return undef; } } ##### Traversing the directory structure.... sub abtree { local($dir) = shift; local($path); unless (opendir(DIR, $dir)) { warn "Can't open $dir\n"; closedir(DIR); return; } foreach (readdir(DIR)) { next if $_ eq '.' || $_ eq '..'; $path = "$dir/$_"; if (-d $path) { abhindex($path); abtree($path); } } closedir(DIR); } sub verbose { print "@_\n" if $verbose; } ###### Decode strange characters sub abdecode { local $string = $_[0]; $string =~ s/ /%20/g; return $string; }