make_dweeblist


#!/usr/bin/perl -w
#
# make index of users' web pages
#

use strict;

my $home;        # my home directory
my $howmany;     # number of entries for current letter
my $lastname;    # user's last name (hopefully)
my $ncols = 3;   # number of columns in index tables
my $nlines;      # number of lines in each table
my $startat;     # where entries for current letter begin in list
my $stopat;      # where entries for next letter begin in list
my $user;        # username
my %nameof;      # username to real name hash
my %seen;        # users to ignore if seen
my ( $ch, $i, $j );    # loop variables
my @idlist;            # list of usernames with public_html directories
my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
my @nameparts;         # words in real name
my @user;              # password entry for user

#
# don't make entries for these users
#
my @ignorelist = qw(
  user1 user2 user3 user4 user5
  user6 user7 goober user8
  user9 user10 user11 user12 user13
);

foreach $user (@ignorelist) {
    if ( getpwnam($user) ) {
        $seen{$user}++;
    }
    else {
        print "make_dweeblist: $user seems to have disappeared ... \n";
    }
}

while ( @user = getpwent ) {
    next if $seen{ $user[0] }++;
    next if ( !-d "$user[7]/public_html" );

    push ( @idlist, $user[0] );

    #
    # change name to "Last, First M" format
    # deal with pesky Sr/Jr/II/etc suffixes semi-sanely
    #
    @nameparts = split ( / /, $user[6] );
    $lastname  = pop   (@nameparts);
    if (   $lastname eq "Sr"
        or $lastname eq "Jr"
        or $lastname eq "II"
        or $lastname eq "IV"
        or $lastname eq "III" )
    {    # anything else?
        $lastname = pop (@nameparts) . " " . $lastname;
    }

    $nameof{ $user[0] } = $lastname . ", " . join ( ' ', @nameparts );
}

$home = ( getpwnam("pas") )[7];
chdir "$home/public_html"
  || die "Can't chdir to html area: $!\n";
open( IND, ">fwd.html" )
  || die "Can't open fwd.html for output: $!\n";
print IND <<"xxxFUNNYxxx";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<HTML>
<HEAD>
<TITLE>UNH CIS Unix Users with Home Pages</TITLE>
<!--#include file="style.html" -->
<LINK REV="made" HREF="mailto:pas\@unh.edu">
</HEAD>

<BODY>
<H1>UNH CIS Unix Users with Home Pages</H1>

<p>
This page contains links to users on our Unix systems with
public_html directories in their home directories. It is
updated automatically every so often. Please note:
<EM>There is no guarantee that what these links point to is
interesting, stylish, inoffensive, or (knowing our user community) even
sensible.  Proceed at your own risk.</EM> Please don't sue us.<p>
<p>
Put more formally: 

<hr>

<p>
Personal Web pages are those created by members of the
University community acting as individuals rather than as
official representatives of the University of New Hampshire. <p>
<p>
In providing links to these pages the University does not preview,
review or routinely monitor the contents of the personal pages of its
faculty, students or staff. Authors of these pages are responsible for
complying with all relevant laws and University policies, including
copyright. Concerns about materials on these pages should be addressed
to the page owner. If that is insufficient to resolve the concerns, the
reader should notify the campus-wide information system management <a
href= "mailto:cwis.admin\@unh.edu">cwis.admin\@unh.edu</a>.

<hr>


<p>
Users who don't want their page listed here should notify
me via e-mail to <KBD><A href="mailto:pas\@unh.edu">pas\@unh.edu</A></KBD>;
Your wishes will be respected.<p>

xxxFUNNYxxx

print IND "There are currently ", scalar(@idlist), " users with\n";
print IND "public_html directories on the pubpages system.\n";

print IND "<HR>\n<p>\n";
foreach $ch (@letters) {
    print IND "<A HREF=\"#$ch\">$ch</A>", ( $ch ne "Z" ) ? " | " : "\n";
}

@idlist = sort { uc( $nameof{$a} ) cmp uc( $nameof{$b} ) } @idlist;

$startat = 0;
foreach $ch (@letters) {
    print IND "<hr><h2><A NAME=\"$ch\">$ch</A></h2><p>\n";

    #
    # scan ahead for next letter or array end
    #
    $stopat = $startat;
    while ( $stopat < $#idlist
        && uc( substr( $nameof{ $idlist[$stopat] }, 0, 1 ) ) le $ch )
    {
        $stopat++;
    }
    $howmany = ( $stopat - $startat );
    next if ( $howmany <= 0 );
    $nlines = int( ( $howmany + $ncols - 1 ) / $ncols );
    print IND "<table width=\"100\%\">\n";
    for ( $i = 0 ; $i < $nlines ; $i++ ) {
        print IND "<tr>";

        for ( $j = 0 ; $j < $ncols ; $j++ ) {
            next if $j * $nlines + $i >= $howmany;
            $user = $idlist[ $startat + $j * $nlines + $i ];
            print IND
"<td><A href=\"http://pubpages.unh.edu/~$user\">$nameof{$user}</A></td>";
        }
        print IND "</tr>\n";
    }
    $startat = $stopat;
    print IND "</table>";
}

print IND "<HR>\n";
print IND "<!--#config timefmt=\"%B %1e %Y %R %Z\" -->\n";
print IND "<p>Last modified: <!--#echo var=\"LAST_MODIFIED\"-->\n";

print IND
"<p><ADDRESS>Paul A. Sand, <A href=\"mailto:pas\@unh.edu\">pas\@unh.edu</A></ADDRESS>";
print IND "</BODY></HTML>\n";
close(IND);
chmod 0755, "fwd.html";
rename "fwd.html", "fellow_web_dweebs.html"
  || die "renaming failed: $!\n";