#!/usr/bin/perl -w
##########################################################################
# $Id: mountd,v 1.3 1998/09/08 14:01:37 kirk Exp $
##########################################################################
# $Log: mountd,v $
# Revision 1.3  1998/09/08 14:01:37  kirk
# Prepping for Version 1.4.5
#
# Revision 1.2  1998/02/23 01:16:57  kirk
# Getting ready for a first distribution
#
# Revision 1.1  1998/02/23 00:53:43  kirk
# Finished init and modprobe, and added mountd
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
#
########################################################

#$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

sub LookupIP {
   my ($name, $a1, $a2,$a3,$a4,$PackedAddr,$Addr);
   $Addr = $_[0];
   ($a1,$a2,$a3,$a4) = split /\./,$Addr;
   $PackedAddr = pack('C4',$a1,$a2,$a3,$a4);
   if ($name = gethostbyaddr ($PackedAddr,2)) {
      return ($name . " (" . $Addr . ")");
   } else {
      return ($Addr);
   }
}

while (defined($ThisLine = <STDIN>)) {
    if ( ($ThisLine =~ /^Unauthorized access by NFS client .*$/ ) or 
         ($ThisLine =~ /^NFS client [^ ]+ tried to access .*$/ ) ) {
	# don't care about this, as the next line reports the IP again
    }
    elsif ( ($IP,$Mount) = ($ThisLine =~ /^Blocked attempt of ([0123456789]+\.[0123456789]+\.[0123456789]+\.[0123456789]+) to mount (.*)$/) ) {
	$Name = LookupIP ($IP);
	$Mount = "      " . $Mount . "\n";
	push @{$Rejected{$Name}}, $Mount;
    }
    else {
	# Report any unmatched entries...
	push @OtherList,$ThisLine;
    }
}

if ( ($#OtherList >= 0) or (keys %Rejected) ) {

    print "\n\n --------------------- Mountd Begin ------------------------ \n";
 
    if (keys %Rejected) {
	print "\nRefused NFS mount attempts:\n";
	foreach $ThisOne (keys %Rejected) {
	    print "   " . $ThisOne . ":\n";
	    print @{$Rejected{$Name}};
	}
    }
	
    if ($#OtherList >= 0) {
	print "\n**Unmatched Entries**\n";
	print @OtherList;
    }
	
    print "\n\n ---------------------- Mountd End ------------------------- \n\n";

}
    
exit(0);



