1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/usr/bin/perl -w
###########################################################################
# $Id: sudo,v 1.5 2003/12/15 18:09:23 kirk Exp $
###########################################################################
###########################################################################
# sudo: A logwatch script to collate and format sudo log entries from
# the secure log. Entries are broken down by the user who issued
# the command, and further by the effective user of the command.
#
# Detail Levels:
# 0: Just print the command
# 20: Include the current directory when the command was executed
# (on a separate line)
# 30: Include the TTY on the directory line
###########################################################################
use strict;
#require 5.6.0; # our
our ($Debug, $Detail, %byUser);
our @OtherList;
BEGIN {
$Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 20;
if ($Debug >= 5) {
print "Inside sudo-filter\n";
}
}
while (defined(my $line=<STDIN>)){
chomp $line;
if ( my($user, $tty, $dir, $euser, $cmd)
= ( $line =~ /^\s*(\w+) : TTY=(\S+) ; PWD=(.*?) ; USER=(\S+) ; COMMAND=(.*)/)) {
push @{$byUser{$user}{$euser}}, [$cmd, $dir, $tty];
}
else
{
push @OtherList, $line;
}
}
END {
foreach my $user (sort keys %byUser) {
print "=" x 78, "\n";
foreach my $euser (sort keys %{$byUser{$user}}) {
print "$user => $euser\n", "-" x 78, "\n";
foreach my $row (@{$byUser{$user}{$euser}}) {
my ($cmd, $dir, $tty) = @$row;
# make long commands easier to read
$cmd =~ s/(?=.{74,})(.{1,74}) /${1} \\\n /g
if (length($cmd) > 75);
print "$cmd\n";
if ($Detail > 20) {
my $ttydetail = "";
$ttydetail = "($tty) " if $Detail >= 30;
print "\t$ttydetail$dir\n";
} # if $Detail
} # foreach $row
} # foreach $euser
} # foreach $user
if ( @OtherList > 0 ){
print "Unmatched Entries:\n";
foreach my $unml (sort @OtherList) {
print "$unml\n";
}
}
} # END
# vi: shiftwidth=3 tabstop=3 et
|