|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /usr/share/logwatch/scripts/services/ |
Upload File : |
##########################################################################
# $Id: ftpd-xferlog,v 1.20 2005/02/24 17:08:04 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 syntax=perl et