Package: logwatch
Version: 6.1.2-1
Severity: normal
Tags: patch

[CC to [EMAIL PROTECTED]
[E-mail has a spam trap! Remove _s__p__a__m]

Script for pure-ftpd log checking does not catches file transfers
correctly (at least not with spaces in file names).

Attached patch:
- fixes this problem, making the script catch downloads and uploads
  correctly
- removes catching of 'deleted' files (this needs to be reimplemented; I
  can do that if you say that you can't apply the patch without it, but
  I think it's worth applying anyway)
- adds ignoring of moved or renamed files (previously they went to
  Unmatched)
- renames $IngoreUnmatched to $IgnoreUnmatched and initializes it from 
  $ENV{'pureftpd_ignore_unmatched'}
- adds transfer statistics section and variables connected with it:
  $ENV{'show_data_stats'}, $ENV{'min_avg_file_size'}, $ENV{'top_people_nr'}
  (they can be left at their default values)
    
I'm using pure-ftpd 1.0.19-4


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.31-ow1
Locale: LANG=C, LC_CTYPE=pl_PL (charmap=ISO-8859-2)

Versions of packages logwatch depends on:
ii  mailx            1:8.1.2-0.20040524cvs-4 A simple mail user agent
ii  perl             5.8.4-8                 Larry Wall's Practical Extraction 

-- no debconf information

-- 
Piotrek
irc: #debian.pl
Mors Drosophilis melanogastribus!
--- pureftpd.org        2005-07-12 10:22:37.000000000 +0200
+++ pureftpd    2005-07-12 13:40:05.000000000 +0200
@@ -28,8 +28,12 @@
 $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
 $ShowLogins  = $ENV{'show_logins'};
 $ShowLogouts = $ENV{'show_logouts'};
+$ShowDataStats = $ENV{'show_data_stats'};
 $ShowDataTransfers = $ENV{'show_data_transfers'};
 $ShowNewConnections = $ENV{'show_new_connections'};
+$IgnoreUnmatched = $ENV{'pureftpd_ignore_unmatched'};
+$MinAvgSize = 200*1024 if (!defined ($MinAvgSize = $ENV{'min_avg_file_size'}));
+$TopPeopleNr = 3 if (!defined ($TopPeopleNr = $ENV{'top_people_nr'}));
 
 $PureShutdown = 0;
 
@@ -38,6 +42,7 @@ while (defined($ThisLine = <STDIN>)) {
       ( $ThisLine =~ /last message repeated/ ) or
       ( $ThisLine =~ /Timeout/) or
       ( $ThisLine =~ /Can't change directory/) or
+      ( $ThisLine =~ /File successfully renamed or moved/) or
       ( $ThisLine =~ /pure-ftpd startup( |) succeeded/)
    ) {
       #We don't care about these
@@ -51,11 +56,17 @@ while (defined($ThisLine = <STDIN>)) {
       $Logins->{$IP}->{$User}++;
    } elsif (($j,$ConnectionCount,$IP) = ($ThisLine =~ /(.*?)too many 
connections \((.*?)\) from this ip\: \[(.*?)\]/i )) {
       $TooManyConnections->{$ConnectionCount}->{$IP}++;
-   } elsif (($User,$Location,$File,$Direction) = ($ThisLine =~ 
/\((.*?)\@(.*?)\)\s+\[\w+\]\s+(.*?)\s+(\w+)\s+/)) {
-      $Direction->{$User}->{$Location}->{$File}++;
-   } elsif (($User,$Location,$File) = ($ThisLine =~ 
/\((.*?)\@(.*?)\)\s+\[\w+\]\s+ Deleted ([^ ]+)/)) {
-      $Direction = "Deleted";
-      $Direction->{$User}->{$Location}->{$File}++;
+   } elsif (($User,$Location,$File,$Direction, $Size, $Speed) = ($ThisLine =~ 
/\((.*?)\@(.*?)\)\s+\[\w+\]\s+(.*?)\s(downloaded|uploaded)\s+\((\d+) bytes, 
(.+)KB\/sec\)/)) {
+      $Transfers->{$Direction}->{$User}->{$Location}->{$File}++;
+      $Stats->{$Direction}->{"files_count"}++;
+      $Stats->{$Direction}->{"files_size"} += $Size;
+      $Stats->{$Direction}->{"people"}->{$User} += $Size;
+      if ($Size >= $MinAvgSize) {
+         $Stats->{$Direction}->{"speed"}->{"max"} = $Speed
+            if ($Stats->{$Direction}->{"speed"}->{"max"} < $Speed);
+         $Stats->{$Direction}->{"speed"}->{"tmp_size"} += $Size;
+         $Stats->{$Direction}->{"speed"}->{"tmp_time"} += $Size/($Speed*1024);
+      }
    } elsif ($ThisLine =~ m/pure-ftpd shutdown( |) succeeded/) {
       $PureShutdown++;
    } else {
@@ -100,17 +111,35 @@ if (keys %{$TooManyConnections}) {
    }
 }
 
+if ($ShowDataStats) {
+   foreach $Direction (keys %{$Stats}) {
+      print "\nTransfer statistics - $Direction files:\n";
+      
+      print "\t$Stats->{$Direction}->{files_count} $Direction files\n";
+      printf "\t%.2f $Direction MB\n", 
($Stats->{$Direction}->{'files_size'}/1024)/1024;
+      print "\t$Stats->{$Direction}->{speed}->{max}KB max speed\n";
+      printf "\t%.2fKB/s average speed\n", 
$Stats->{$Direction}->{'speed'}->{'tmp_size'}/$Stats->{$Direction}->{'speed'}->{'tmp_time'}/1024;
+      @top_people = sort { $Stats->{$Direction}->{'people'}->{$b} <=> 
$Stats->{$Direction}->{'people'}->{$a} } keys %{ 
$Stats->{$Direction}->{'people'} };
+      if (@top_people) {
+         print "\tTop $TopPeopleNr people:\n";
+         foreach $User (splice @top_people, 0, $TopPeopleNr) {
+            printf "\t\t%7.2fMB $User\n", 
$Stats->{$Direction}->{'people'}->{$User}/1024/1024;
+         }
+      }
+   }
+}
+
 if ($ShowDataTransfers) {
-   if (keys %{$Direction}) {
-      print "\nData Transferred:\n";
-      foreach $User (sort {$a cmp $b} keys %{$Direction}) {
-         foreach $Location (sort {$a cmp $b} keys %{$Direction->{$User}}) {
-            foreach $Filename (sort {$a cmp $b} keys 
%{$Direction->{$User}->{$Location}}) {
+   foreach $Direction (keys %{$Transfers}) {
+      print "\nData $Direction:\n";
+      foreach $User (sort {$a cmp $b} keys %{ $Transfers->{$Direction} }) {
+         foreach $Location (sort {$a cmp $b} keys %{ 
$Transfers->{$Direction}->{$User} }) {
+            foreach $Filename (sort {$a cmp $b} keys %{ 
$Transfers->{$Direction}->{$User}->{$Location}}) {
                print "\tUser " . $User . " " . $Direction . " " . $Filename . 
" from " . $Location . " - ". $Direction->{$User}->{$Location}->{$Filename} . " 
Time(s)\n";
             }
          }
       }
-   }
+   }   
 }
 
 if (keys %SecureAnon) {
@@ -129,7 +158,7 @@ if ($ShowLogouts) {
    }
 }
 
-if (($#OtherList >= 0) and (not $IngoreUnmatched)){
+if (($#OtherList >= 0) and (not $IgnoreUnmatched)){
    print "\n**Unmatched Entries**\n";
    print @OtherList;
 }

Reply via email to