#!/usr/bin/perl

open LOG, $ENV{'LOGCAT'} ;
open REPORT, ">$ENV{'LOGREPORT'}" ;
open FILTER, ">$ENV{'LOGFILTER'}" ;

my %report ;
my %b_report ;
while ( <LOG> ) {
	chomp ;
	if ( m/passwd.*\[\d+\]: password changed for (.+) on/ ) {
		print FILTER ;
		print FILTER "\n" ;
		$report{$1}++ ;
		next ;
	}
	if ( m/passwd.*\[\d+\]: password not changed for (.+) on/ ) {
		print FILTER ;
		print FILTER "\n" ;
		$b_report{$1}++ ;
	}
}
close LOG ;
close FILTER ;

if ( %b_report ) {
	print REPORT "<h4>Password change failures</h4>\n" ;
	print REPORT "<table width='100%' rules='cols' cellpadding='2'>\n" ;
	my $c = 0 ;
	foreach $k ( keys %b_report ) {
		print REPORT "<tr" . ( $c%2 == 0 ? " bgcolor='#dddddd'" : "" ) .">" ;
		print REPORT "<td>$k  (" . $b_report{$k} . ")</td></tr>\n" ;
		$c++ ;
	}
	print REPORT "</table>\n" ;
}

if ( %report ) {
	print REPORT "<h4>Passwords changed</h4>\n" ;
	print REPORT "<table width='100%' rules='cols' cellpadding='2'>\n" ;
	my $c = 0 ;
	foreach $k ( keys %report ) {
		print REPORT "<tr" . ( $c%2 == 0 ? " bgcolor='#dddddd'" : "" ) .">" ;
		print REPORT "<td>$k  (" . $report{$k} . ")</td></tr>\n" ;
		$c++ ;
	}
	print REPORT "</table>\n" ;
}
close REPORT ;
