pmfinger script for all those who wanted it

Chris Schmidt (schmidtc@adsnet.net)
Sun, 29 Oct 95 03:11:44 PST

Hi, folks.

I got so many requests for this script, I'm posting it to the list. It's
only 50 lines or so.

As the (sparse) documentation explains, it uses our mods to radius accounting.
Those mods simply create tab-delimited records from the radius information
and can be found at ftp.adsnet.net/pub/radius.

If you find this useful, please let me know. Actually, if anyone has the
gumption, I'd like to see it re-written in C. My C programming leaves
something to be desired. It would probably run a little faster, especially
through the loop.

Anyway, have at it and let me know of any problems or any modifications
and I'll try to fix or include them, especially if you write it to work on a
non-modified accounting file.

Take care,

Chris
schmidtc@adsnet.net

#!/bin/sh
# pmfinger: A finger utility for the Portmaster
#
# Copyright Advanced Data Systems 1995
#
# This is a little finger utility that queries the radius accounting file
# to determine who is currently logged in.
#
# It uses the ADS mods to radius, which can be found at
# ftp.adsnet.net/pub/radius.
#
# Basically, those mods create tab-delimited records from the Start/Stop
# actions of radius.
#
# This shell script simply looks for the last record in that file for each
# port, and if that record is a Start record, prints out the pertinent
# information.
#
# Now, there are some inherent problems with this, namely a Stop record not
# being generated when the user logs off. However, I've yet to see this
# happen except when the Portmaster is reset during use.
#
# Using this routine, it is probably possible to query a non-modified
# radius acounting file and get the same information but since we use
# a tab-delimited file, that's how we wrote it!
#
# This was written under Solaris 2.4, so your Unix may not have a couple of
# the functions (getent, for example.) But, I wrote it originally without
# getent and it worked fine. It was just a couple more lines of programming.
#
# One of the mods coming up to this script will allow you to pass a parameter
# to tell pmfinger what radius accounting file to query, which is very useful
# if you have more than one portmaster in service.
#
# create a the temporary file variable and the counter variable
TFILE="`date``date '+%S'`.txt"
CNTR=1
# get the last 3000 records from the accounting file, and only get the
# fields we need. Of course, you can query the accouting file directly,
# or change this to a higher or lower number depending on your needs.
tail -3000 /usr/adm/radacct/portmaster1/detail|cut -f1,3,5,6,10>/tmp/"$TFILE"
# Print out some header info, including the date.
date
echo "User Name Port Address Where When"
# Loop through this routine 1-29 times (or 0-29 if you use port 0) and get
# the information
while [ $CNTR -lt 30 ]
do
TLINE=`fgrep " $CNTR " /tmp/"$TFILE" | tail -1|fgrep " Start"|cut -f1,2,3,5`
if [ "$TLINE" != "" ]
then
WHEN=`echo "$TLINE"|cut -f1|cut -b1-16`
USERNAME=`echo "$TLINE"|cut -f2`
REALNAME=`getent passwd $USERNAME|cut -d: -f5`
USERNAME2=`echo "${USERNAME}................."|cut -b1-8`
REALNAME2=`echo "${REALNAME}...................................."|cut -b1-20`
USERPORT1=`echo "$TLINE"|cut -f3`
USERPORT2=`echo "${USERPORT1}....."|cut -b1-4`
USERADDR=`echo "$TLINE"|cut -f4`
echo "$USERNAME2.. $REALNAME2 $USERPORT2 $USERADDR $WHEN"
fi
CNTR=`expr $CNTR + 1`
done
# delete the temporary file
rm /tmp/"$TFILE"
# that's all, folks