PRT
print HTMLFILE "
Current NetWare Logins
$datetime
Click on any name below to show People Finder results.
\n";
print HTMLFILE "
\n";
PRT
}
# Work out the number of people logged in
$num_logins = $#people_sorted;
# Specify the number of columns
$num_cols=3;
# Count Number of Columns written
$column=0;
# Work out the number of people per column:
$column_limit = int($num_logins/$num_cols)+1;
#Initialise a counter for number of people displayed
$peoplecount=0;
#Initialise a counter for dividing into columns
$people_in_column=0;
foreach (@people_sorted){
# Check if the person's name happens to be on the excluded list
$name_of_user = $_;
# Set a flag on whether we exclude a user or not
$exclude=0;
foreach (@excludedusers){
if (/($name_of_user)/i){
$exclude=1;
}
}
#From fullname, identify surname to be used in LDAP search:
&lookup_name($_);
# Print person's name if *not* excluded
if ($exclude==0){
$people_in_column++;
$peoplecount++;
# Handle the end-of-columns condition
if ($people_in_column==$column_limit) {
# Reset the people-per-column counter
$people_in_column=0;
# Increment the current column number
$column++;
# Close preceding DIV, if we're on DIV 2 or 3:
if ($column>=1) {
# columns are 0,1 & 2. For columns 1 & 2, need to close the preceding DIV.
print HTMLFILE "
\n";
}
# And start a new DIV:
print HTMLFILE "
\n
$_\n";
} else {
# Print in current column of existing DIV:
print HTMLFILE "
$_\n";
}
}
} # end of foreach(@people_sorted)
# Finish the table holding logged-in users
if (length($htmlfile) >4) {
print HTMLFILE <
Script author: Dr. Duncan J. Potter (source code)
NDS Containers Scanned: $num_of_contexts
Raw NLIST Lines: $#users
People Identified: $#people_sorted
"
PRT
# Error handling code:
if ($peoplecount==0){
print HTMLFILE "
Script exits after zero people were displayed as being logged in.";
close HTMLFILE;
exit(0);
}
close HTMLFILE;
}
} #end of subroutine
#----------------
sub INT_handler {
# close all files.
# send error message to log file.
print "Closing ...\n";
exit(0);
}
sub lookup_name {
# Splits the $fullname string and identifies the surname, used for hyperlink to HW email lookup.
# Can have fullnames of:
# Type 1. James Jones
# Type2. James E. Jones
# Type3. James Jones (PhD Stud)
my $fullname= @_[0];
# $` returns everything before the matched string. $' returns everything after the matched string
if ( $fullname =~ m/\(/) {
# Student name found with a '('
# Trim down text to that before the matchd character:
$fullname_trim = $`;
#Split the name by spaces
@names = split/\s/, $fullname_trim;
#Surname will be the last item in the array - which has index $#names
$fullname_lookup = $names[$#names];
return $fullname_lookup;
}
@names = split/\s/, $fullname;
$fullname_lookup = $names[$#names];
return $fullname_lookup;
}
Using the Script Yourself
The above script may be freely copied and modified for use on your own site, only please retain the author information.
It is provided as is without warranty or support in the interests of sharing helpful information.
The script is hard coded to refer to paths in use at this site but shouldn't be difficult to adapt to your own environment.
The contexts.txt file simply lists the NDS/eDirectory contexts to be scanned, one per line, e.g.
.mycontext.myOU.myORG
.myOthercontext.myOU.myORG
and the exclude.txt is simply a list of full names not to be displayed (not usernames, but the full name) e.g.
Dave Smith
Boris Kharlof
Running the Script Periodically
A variety of mechanisms may be used to call the script periodically. The one used here is to emply the
(free) Sinc32
utility to call the Perl script every minute from a DOS batch file (this proved the easiest way). The format of the sinctab.stf file in
which one specifies the items to be run is as follows:
# From left to right the time fields are:
#- minute
#- hour
#- day of month
#- month
#- day of week
# Process to run
#
# Execute the Staff Logins batch file every minute.
* * * * * C:\stafflogins\stafflogins.bat
Good luck! :-)