#!/usr/local/bin/perl ############################################################################## $VERSION = "Page Find v2.0 beta 961216"; # pfind v1.12 12-14-96 Dale Bewley dale@bewley.net # pfind v1.1 12-20-95, v.9 ?-8?-95 #----------------------------------------------------------------------------- # This script and others found at http://www.bewley.net/perl/ # # Page finder. Finds almost* all the homepages on a site and creates a # catagorized HTML3 table or VRML SCENE. Now uses group name to catagorize, # # Changes in ver 2.0: # o Much more perl5ish. Sorda. # o Tables are now organized by GID not home dir. You may not want # that if you run RedHat linux where each user has a group. # o VRML is very broken and I haven't had time to play with it. # Changes in ver (1.11b): # o A little closer to the HTML3 spec. # o $FOOTER variable that points to file to append to output. # o Cleaned up some quick hacks. # Changes in this ver (1.1): # o Added -vrml option to ouput to a .wrl file. # o Added -h2v option to convert old html output to vrml. # # Todo: # o Move some options from variables to command line. # o Add more user options for vrml output customization. # o FIX the VRML junk. # o Increase efficiency. Look for better ways to do these quick hacks. # o Write POD docs I suppose. # o You tell me. # # Notes: # * Almost, because if you can not read the user's web dir then # it will not see the page. I think this is a feature not a bug. # # Copyright (C) 1996,1997 Dale Bewley # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ############################################################################## #- User Configurable Variables ----------------------------------------------# $WEBDIR = "www"; # default HTML directory $WEBSERVER = "www.bewley.net"; # local web server $BASE_HREF = "TARGET=_new http://www.bewley.net/"; # filesize saver!!! broken $ULIMIT = -1; # maximum users to read from passwd -1 for all $MAX_COLUMNS = 9; # width of table. $FOOTER = "~/.pfind.footer"; # file printed at the bottom of page $HEADER = "~/.pfind.header"; # file printed at the top of page #----------------------------------------------------------------------------# #- Get command line options -------------------------------------------------# sub getOpts { &getopt('acdflsz'); # these options accept commandline values $FOOTER = $opt_z if ($opt_a); $MAX_COLUMNS = $opt_c if ($opt_c); $WEBDIR = $opt_d if ($opt_d); $BASE_HREF = $opt_f if ($opt_f); $ULIMIT = $opt_l if ($opt_l); $WEBSERVER = $opt_s if ($opt_s); $HEADER = $opt_a if ($opt_z); } #----------------------------------------------------------------------------# #- Help! --------------------------------------------------------------------# sub help { print <<"END_OF_HELP"; $VERSION Dale Bewley http://www.bewley.net/perl/pfind.html Description: This script will create an HTML index of all the homepages on a system. Output is to a HTML table or VRML scene. VRML is broke right now. Usage: $0 [] > file.html Options (Defaults inside [] below): -a File to prepend to output. [$HEADER] -c Maximum columns in table output. [$MAX_COLUMNS] -d Dir in users home containing html. [$WEBDIR] -f Base for each URL on output. [$BASE_HREF] -h This. -l Test first [$ULIMIT] entries in passwd for homepages. -1 for all. -s Webserver name. [$WEBSERVER] -v VRML output. Broke right now. :( -z File to append to output. [$FOOTER] Examples: $0 -a pfind.head -c 5 -d www -l 1000 > pages.html END_OF_HELP 1; } #----------------------------------------------------------------------------# #- Main Program -------------------------------------------------------------# use Getopt::Std; # uncomment the following 2 lines if you have the VRML module #use VRML; #use VRML::VRML2; &getOpts; if ($opt_h) { &help; exit; } @months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); ($sec, $min, $hour, $mday, $mon, $year) = localtime($^T); &findPages; if ($opt_v) { #&introVRML; &printVRML(\%pages, "Testing All Pages") && ($ZGROUP+=5); } else { # default HTML output &introHTML; &printHEADER if $HEADER; &printTable(\%pages); &summary; &printFOOTER if $FOOTER; } #----------------------------------------------------------------------------# #- Print Introductory Information --------------------------------------------# sub introHTML { print "\n\nAlmost all the Homepages on $WEBSERVER"; # Big file size saver!! print "\n\n\n\n"; print "\n"; print "
\n\t

Almost all the Homepages on $WEBSERVER

\n"; print "\t

Of $uCount entries in passwd, $pCount have "; print "homepages.

\n"; print "\tPage generated by $VERSION\n

\n\n"; printf ("\tBegun @ %02s %02d, %02d %02d:%02d:%02d\n", $months[$mon], $mday, $year, $hour, $min, $sec); print "

\n
\n"; } #- Print Introductory VRML Information ---------------------------------------# sub introVRML { #this is taken right from a sample file. needs to be changed print "#VRML V1.0 ascii\n"; print "Separator {\n"; print " DirectionalLight {\n"; print "\tdirection 0 0 -1 # Light shining from viewer into scene\n"; print " }\n"; print " PerspectiveCamera {\n"; print "\tposition -8.6 2.1 5.6\n"; print "\torientation -0.1352 -0.9831 -0.1233 1.1417\n"; print "\tfocalDistance 10.84\n"; print " }\n"; } #- Find User Pages -----------------------------------------------------------# sub findPages { setpwent; while ((@list = getpwent) && ($uCount != $ULIMIT)) { $uCount++; ($login, $gid, $gecos, $home) = @list[0,3,6,7]; if (-r "$home/$WEBDIR") { $pCount++; # Your site may require changes here. # This will create a table for each gid. This may not # be what you want if you run RedHat Linux # comment for gecos version #push(@{ $pages{$gid} }, $login); # uncomment for gecos version $pages{$gid}{$login}=$gecos; } } endpwent; } #- Print Results in Table Format ---------------------------------------------# sub printTable { # Argument passed a ref to a hash of pages my($pageList) = shift; # ref to hash local($colCount) = 0; $groupCount = keys %$pageList; foreach $group (sort keys %$pageList) { @groupInfo = getgrgid($group); $groupName = $groupInfo[0]; # comment for gecos version #$pageCount += $#{ $$pageList{$group} }; # uncomment for gecos version $pageCount = scalar(keys %$pageList); print "

\n\n"; print " \n"; print "\t\t\n "; print "\n \n"; # comment for gecos version #print each member of group #foreach $i (0 .. $#{ $$pageList{$group} } ) { #print "\t\n"; #$colCount++; #if ($colCount == $MAX_COLUMNS) { #print " \n \n"; #$colCount = 0; #} #} # uncomment for gecos version # foreach $group (sort keys %$pageList) { # print "TEST\n"; foreach $username (sort keys %{ $$pageList{$group} } ) { #print "\t\n"; print "\t\n"; $colCount++; if ($colCount == $MAX_COLUMNS) { print " \n \n"; $colCount = 0; } } # } print "\n\n\t\t\n\n

$groupName

$$pageList{$group}[$i]
$$pageList{$group}{$username}$username
"; # comment for gecos version #print $#{ $$pageList{$group} }; print "
\n"; } } #- Print Results in VRML Format ---------------------------------------------# sub printVRML { # Arguments passed are a ref to a hash of pages and a caption. my($pageList) = shift; # ref to hash my($colCount) = 0; my($rowCount)=0; $pageCount = keys %$pageList; $vrml = new VRML; $vrml->begin("Created by $VERSION http://www.bewley.net/perl/pfind.html"); $vrml->title("All the homepages on $WEBSERVER"); $groupCount = keys %$pageList; $group_trans = 1; foreach $group (sort keys %$pageList) { $x=0; $y=0; $z=0; $group_trans++; @groupInfo = getgrgid($group); $groupName = $groupInfo[0]; $pageCount += $#{ $$pageList{$group} }; $vrml->transform_begin("t=$x $y $group_trans"); $vrml->group_begin("$groupName pages"); $vrml->text("$groupName pages", '', '1 '); # $vrml->cube; foreach $i (0 .. $#{ $$pageList{$group} } ) { $pageCount++; $x++; $y++; $z++; if ($x == 10 ) { $x=1; $y=1; $group_trans++; } $vrml->transform_begin("t=$x $y $group_trans"); $vrml->anchor_begin("$BASE_HREF~$$pageList{$group}[$i]/"); $vrml->sphere(.3);#, "tex=/gif/gfx.gif"); $vrml->anchor_end; $vrml->transform_end; } $vrml->group_end; $vrml->transform_end; } $vrml->end; $vrml->print; } #- Print Summary Information -------------------------------------------------# sub summary { ($fsec, $fmin, $fhour, $mday, $mon, $year) = localtime(time); print "

\n"; # compute time to run someday printf ("Finished @ %02s %02d, %02d %02d:%02d:%02d\n", $months[$mon], $mday, $year, $fhour, $fmin, $fsec); print "

\n\n"; } #- Print Header File --------------------------------------------------------# sub printHEADER { open (HEADER, "<$HEADER") || warn "Can not open $HEADER for input. $!"; while (
) { print; } } #- Print Footer File --------------------------------------------------------# sub printFOOTER { open (FOOTER, "<$FOOTER") || warn "Can not open $FOOTER for input. $!"; while (