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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/usr/bin/perl -w
##########################################################################
# $Id: ftpd-xferlog,v 1.17 2004/06/21 13:46:21 kirk Exp $
##########################################################################
########################################################
# This was written and is maintained by:
# Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
# etc, to kirk@kaybee.org.
########################################################
sub remove_dups {
my(@info)=sort @_;
my(%count,@out,$i);
foreach $i (@info) {
$count{$i}++;
}
foreach $i (keys %count) {
my($j)=$i;
$j =~ s/\n//;
if ($count{$i} > 1) {
push @out, $j . " (".$count{$i}." Times)\n";
} else {
push @out, "$j\n";
}
}
return @out;
}
$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
$FTPDetail = $ENV{'detail_transfer'};
$TotalBytesOut = 0;
$TotalBytesIn = 0;
while (defined($ThisLine = <STDIN>)) {
# Remove transfer time if it is there
if ( ($RemoteHost,$Size,$FileName,$Direction,$AccessMode,$UserName) =
( $ThisLine =~ /^([^ ]+) (\d+) (.*) . . (.) (.) (.*) ftp . .*$/ ) ) {
if ( $AccessMode eq 'a' ) {
# Anonymous transfers
if ( $Direction eq 'o' ) {
# File was outgoing
$TotalBytesOut += $Size;
if ($Detail >= 15) {
$Temp = ' ' . $FileName . ' -> ' . $RemoteHost . ' (Email: ' . $UserName . ")\n";
}
else {
$Temp = ' ' . $FileName . ' -> ' . $RemoteHost . "\n";
}
push @AnonOut, $Temp;
$FilesOut{$FileName}++;
} elsif ( $Direction eq 'd' ) {
$Temp = ' ' . $FileName . ' Deleted ' . $RemoteHost . ' (Email: ' . $UserName . ")\n";
push @DeletedFiles, $Temp;
} else {
# File was incoming
$TotalBytesIn += $Size;
if ($Detail >= 15) {
$Temp = ' ' . $RemoteHost . ' -> ' . $FileName . ' (User: ' . $UserName . ")\n";
}
else {
$Temp = ' ' . $RemoteHost . ' -> ' . $FileName . "\n";
}
push @AnonIn, $Temp;
}
} elsif ( $AccessMode eq 'g' ) {
# Guest transfers
if ( $Direction eq 'o' ) {
# File was outgoing
$TotalBytesOut += $Size;
$Temp = ' ' . $FileName . ' -> ' . $RemoteHost . ' (User: ' . $UserName . ")\n";
push @GuestOut, $Temp;
} elsif ( $Direction eq 'd' ) {
$Temp = ' ' . $FileName . ' Deleted ' . $RemoteHost . ' (User: ' . $UserName . ")\n";
push @DeletedFiles, $Temp;
} else {
# File was incoming
$TotalBytesIn += $Size;
$Temp = ' ' . $RemoteHost . ' -> ' . $FileName . ' (User: ' . $UserName . ")\n";
push @GuestIn, $Temp;
}
} elsif ( $AccessMode eq 'r' ) {
# User transfers
if ( $Direction eq 'o' ) {
# File was outgoing
$TotalBytesOut += $Size;
$Temp = ' ' . $FileName . ' -> ' . $RemoteHost . ' (User: ' . $UserName . ")\n";
push @UserOut, $Temp;
} elsif ( $Direction eq 'd' ) {
$Temp = ' ' . $FileName . ' Deleted ' . $RemoteHost . ' (User: ' . $UserName . ")\n";
push @DeletedFiles, $Temp;
} else {
# File was incoming
$TotalBytesIn += $Size;
$Temp = ' ' . $RemoteHost . ' -> ' . $FileName . ' (User: ' . $UserName . ")\n";
push @UserIn, $Temp;
}
}
} else {
# Report any unmatched entries...
push @OtherList, $ThisLine;
}
}
@AnonOut=&remove_dups(@AnonOut);
@AnonIn=&remove_dups(@AnonIn);
@GuestOut=&remove_dups(@GuestOut);
@GuestIn=&remove_dups(@GuestIn);
@UserOut=&remove_dups(@UserOut);
@UserIn=&remove_dups(@UserIn);
@OtherList=&remove_dups(@OtherList);
@DeletedFiles=&remove_dups(@DeletedFiles);
$TotalKBytesOut = int $TotalBytesOut/1000;
$TotalKBytesIn = int $TotalBytesIn/1000;
$TotalMBytesOut = int $TotalKBytesOut/1000;
$TotalMBytesIn = int $TotalKBytesIn/1000;
($TotalKBytesOut > 0) and print "TOTAL KB OUT: " . $TotalKBytesOut . "KB (" . $TotalMBytesOut . "MB)\n";
($TotalKBytesIn > 0) and print "TOTAL KB IN: " . $TotalKBytesIn . "KB (" . $TotalMBytesIn . "MB)\n";
if (@AnonIn) {
print "\nIncoming Anonymous FTP Transfers:\n";
print @AnonIn;
}
if ( (keys %FilesOut) and ($Detail >= 5) and ($Detail < 10) ) {
print "\nOutgoing Anonymous FTP Transfers (By File):\n";
foreach (sort keys %FilesOut) {
print " $_: $FilesOut{$_} Time(s)\n";
}
}
if ( (@GuestIn) and ($Detail >= 10) and ($FTPDetail > 0)) {
print "\nIncoming Guest FTP Transfers:\n";
print @GuestIn;
}
if ( (@GuestOut) and ($Detail >= 10) and ($FTPDetail > 0)) {
print "\nOutgoing Guest FTP Transfers:\n";
print @GuestOut;
}
if ( (@AnonOut) and ($Detail >= 10) ) {
print "\nOutgoing Anonymous FTP Transfers:\n";
print @AnonOut;
}
if ( (@UserIn) and ($Detail >= 10) and ($FTPDetail > 0)) {
print "\nIncoming User FTP Transfers:\n";
print @UserIn;
}
if ( (@UserOut) and ($Detail >= 10) and ($FTPDetail > 0)) {
print "\nOutgoing User FTP Transfers:\n";
print @UserOut;
}
if ( (@DeletedFiles) and ($Detail >= 10) and ($FTPDetail > 0)) {
print "\nDeleted Files:\n";
print @DeletedFiles;
}
if ($#OtherList >= 0) {
print "\n**Unmatched Entries**\n";
print @OtherList;
}
exit(0);
# vi: shiftwidth=3 tabstop=3 et
|