#!/usr/local/bin/perl # # user_links_sort --- User Home Page Links # # Search all the users home directories for a wide world web public # directory and output the ``User Supplied Home Pages'' document to be # directly sent to the caller. # # Example Usage: CIT, Griffith University, Australia # http://www.cit.gu.edu.au/cgi-bin/user-links # # This program currently knows about and looks for the following html # document files in users WWW public directory. ( "public_html"? ) # # index.html The mail home page of the user, if not present # the user is not presented in the list thus allowing # hidden homepages to exist. # comment.html A short comment about this users WWW home to be # included. # personal.html personal information about this user specifically. # # NOTE: this program ignores all input arguments making it very secure. # # Programmer: Anthony Thyssen 29 May 94 # http://www.cit.gu.edu.au/~anthony/ # # --------------------------------------------------------------------------- # The following constants is used to determine the directories and files # the might supply. Only the user's WWW directory must exist and be # readable by the httpd user `nobody'. The other files is optional. # # For best effect the user should also supply a summery file ``comment.html'' # and an initial index (home page) file ``index.html''. $USER_DIR="www"; # Name of directory to look for in users homes # default "public_html", set in httpd configs @USER_INDEX= ( "index.html", # list of valid index files "index.htm", # user home pages (must be present) "index.shtml" ); # $USER_SUMMERY="comment.html"; # the short summery to include in the output. $USER_PERSONAL="personal.html"; # the users personal details page $USER_PUBS="publications.html"; # publications by the user (not used) $MIN_UID=100; # the smallest USER_ID a user can have $HELP_DOC=' Installing a WWW Homepage '; $WEBMASTER=' webmaster@cit.gu.edu.au'; # --------------------------------------------------------------------------- # Print the top part of the user links document print <<"EOF"; Content-type: text/html User Home Pages

User Home Pages

The following is a list of local users who have provided public information maintained by that individual. I can not make any guarantee as to the quality, accuracy and/or the working status of this information.

This list is automatically collected whenever a request is made by the server. Staff members who wish to create a personal home page or information area can read $HELP_DOC (please read it) which explains how to do this. For more information or if you are experiencing problems contact $WEBMASTER

NOTE: This list is now sorted by the the users surname (You can thank Rodney for this) instead of the order in the password file. If this is not to your liking please contact the WebMaster and let your feelings be known. All suggestions are welcome.


EOF # For each user on this machine determine if they provide a WWW directory open(PASSWD, "/etc/passwd") || die "Can't open passwd file: $!\n"; while( $userrec = ) { ($login,$pass,$uid,$gid,$gcos,$home,$shell) = split(/:/, $userrec); $fullname = $gcos; #$fullname =~ s/^[^,]*-(.*)\(.*/$1/ || $fullname =~ s/,.*//; if ( $fullname =~ /&/) { # you don't want to know. $name = $login; substr($name,0,1) =~ tr/a-z/A-Z/; $fullname =~ s/&/$name/; } # remove system, disabled, demo accounts and users without a homepage next if $uid < $MIN_UID # Ignore the system accounts || $home eq "" # no home directory given || $home eq "/" # home is root || $shell eq "" # no shell || $shell =~ "NOSHELL" # DISABLED account || $shell =~ "SECURE" # SECURED account ; for $index ( @USER_INDEX ) { if( -f "$home/$USER_DIR/$index" && -r _ ) { $links_found++; $fullname =~ s/\(.*\)//; $fullname =~ s/[(),_;].*$//; $fullname =~ s/^\s+//; $fullname =~ s/\s+$//; ($first,$last) = $fullname =~ /^(.*)\s+(\S+)$/; # store it into an array (unique and alphabetical sortable) $user{join(' ', $last, $first, $login)} = join(':', $login, $first, $last, "$home/$USER_DIR"); last; # finished with this user } # if index file has been found } # for each index file type } close(PASSWD); if ( ! $links_found ) { print "Sorry no home pages have been found on the system at this\n"; print "time, try again latter or contact the webmaster.

\n\n"; } else { print "

\n"; for $user ( sort keys %user ) { ($login, $first, $last, $dir) = split(/:/, $user{$user}); # Surname first print "
$last, $first,\n"; print " <$login\@cit.gu.edu.au>\n"; # Given name first #print "
$first $last,\n"; #print " <$login\@cit.gu.edu.au>\n"; # if the user has some personal details provide a link to this too if ( -f "$dir/$USER_PERSONAL" && -r _ ) { print " Personal Details\n"; } # add user summery if present (presumably it is only about two lines) if ( -f "$dir/$USER_SUMMERY" && -r _ ) { open( COMMENT, "$dir/$USER_SUMMERY" ) || next; print "
"; while( $line = ) { print $line; } close COMMENT; } } print "

\n\n"; } print <<"EOF";


Program: ``user_links_sort'' -- User Home Page Linker
Created: 26th November 1993
Sorting added: 30th April 1995
Modified: 7th August 1997
Written: Anthony Thyssen, < anthony\@cit.gu.edu.au>
Send comments, errors and suggestions to $WEBMASTER
EOF