Poor Man's Site Mapper


Websites can have alot of content, usually accesible through the directory structure. Sometimes it's hard to know what you have in the big picture through a vt100. There exists a need for a visual representation of how your website is setup. There's probably other and better programs out there to make site maps, so this one was a rainy day exercise for me. Basically, I wanted to return a web-friendly listing of sections of my site. So, Perl to the rescue.

Here's the path taken:

They may be some areas within your site which you do not wish to have outputted for various reasons. An extra hook was then added in the code, creating a list of excluded directories which are not displayed

Script overview:

Quick hacks can always be improved. One thing which would be fun is to map out the dirtree structure on the page, although there are probably tools out there which can do this if you search the web.

     1	#!/usr/bin/perl -w
     2	
     3	use strict;
     4	use File::Find ();
     5	
     6	use vars qw($name @files @exclude $col_width $counter);
     7	
     8	$col_width = 4;
     9	$counter   = 0;
    10	
    11	@exclude = qw(keep_out private_area);
    12	
    13	chdir $ENV{DOCUMENT_ROOT} or die "$ENV{DOCUMENT_ROOT}: $!\n";
    14	
    15	@ARGV = qw(.) unless @ARGV;
    16	sub find(&@) { &File::Find::find }
    17	*name = *File::Find::name;
    18	find { push @files, $name if -d } @ARGV;
    19	
    20	print "Content-type:text/html\n\n";
    21	
    22	print <<ENDBEGIN;
    23	<HTML>
    24	 <HEAD>
    25	  <LINK REL="stylesheet" HREF="/lib/libcss.css" TYPE="text/css">
    26	  <TITLE>Site Map for $ENV{SERVER_NAME}</TITLE>
    27	 </HEAD>
    28	
    29	 <BODY>
    30	
    31	  <H2>Site Map for $ENV{SERVER_NAME}</H2>
    32	
    33	  <TABLE BGCOLOR="black">
    34	   <TR>
    35	    <TD>
    36	     <TABLE BGCOLOR="silver">
    37	      <TR>
    38	ENDBEGIN
    39	
    40	foreach my $file(sort @files) {
    41	  my $flag = 0;
    42	  $file =~ s/.//;
    43	  foreach my $out(@exclude) {
    44	    if ($file =~ $out) {
    45	      $flag = 1;
    46	    }
    47	  }
    48	  if ($flag == 0) {
    49	    $counter++;
    50	    print "       <TD><A HREF=\"$file/\">$file/</A></TD>\n"; 
    51	    if ((($counter % $col_width) == 0) && $counter != 0) {
    52	      print "      </TR>\n\n      <TR>\n"; 
    53	    }
    54	  }
    55	}
    56	
    57	print <<END;
    58	      </TR>
    59	     </TABLE>
    60	    </TD>
    61	   </TR>
    62	  </TABLE>
    63	 </BODY>
    64	</HTML>
    65	
    66	END