#!/usr/local/bin/tcsh -f

##############################################################################
# 12/29/94 .fingerrc
#
# Chris Alfeld
#  Finds who and from where a finger request comes from
# Notes:
#  The files ~/.fingerlog and ~/adm/fingerrc.log must exist
#  The programs ~/bin/idlookup, ~/.fhba, and ~/bin/findwho must 
#   be executable
##############################################################################

# Find the IP address and port
#  $FROM[1..4] is IP address, $FROM[5] is port
set FROM=`netstat -n | grep 79 | head -1 | awk '{print $5}' | sed 's/\./ /g'`

# Use DNS to find hostname
set LFROM=`/u/usr/calfeld/.fhba $FROM[1].$FROM[2].$FROM[3].$FROM[4]` 

# use ident to find user
set WHO=`~$USER/bin/idlookup $LFROM $FROM[5] 79`

# Handle success/failure
if ( $? == 0 ) then
	set WHO=`echo $WHO | awk '{print $2}'`
	echo "Hello, $WHO"
else
	set WHO=0
endif

# Display finger info
echo "You are fingering from: $LFROM"
cat

# Log to .fingerlog - I reset this every log in
echo "Req: `date`: $LFROM / $WHO" >> .fingerlog 

# Log to adm/fingerrc.log - never reset
echo "Req: `date`: $LFROM / $WHO" >> adm/fingerrc.log

# If ident failed use findwho script
if ( $WHO == 0 ) then
	csh -c "~$USER/bin/findwho $LFROM ~$USER/.fingerlog &" >& /dev/null
endif

