File: pop3

package info (click to toggle)
logwatch 5.2.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,112 kB
  • ctags: 42
  • sloc: perl: 9,032; sh: 65; makefile: 54
file content (247 lines) | stat: -rw-r--r-- 8,419 bytes parent folder | download
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/perl
##########################################################################
# $Id: pop3,v 1.1 2004/06/21 14:59:05 kirk Exp $
##########################################################################

########################################################
# Logwatch was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# The pop-3 script was written by:
#    Pawe Goaszewski <blues@gda.pl>
#
########################################################

my $Debug = $ENV{'LOGWATCH_DEBUG'};
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

#Make pseudo IPv6 to IPv4
sub LookupIPv46 {
   my $IPv4Addr;
   my $Addr = $_[0];
   if ( ($IPv4Addr) = ($Addr =~ /::ffff:([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/ ) ) {
#      print "$IPv4Addr\n";
      return $IPv4Addr;
      
      }
   else {
#      print $Addr;
      return $Addr;
      
      }
}
   
if ( $Debug >= 5 ) {
    print STDERR "\n\nDEBUG \n\n";
}

while (defined($ThisLine = <STDIN>)) {
   if (
      ($ThisLine =~ /^auth: PAM error: Authentication failure$/) or
      ($ThisLine =~ /^getpeername: Socket operation on non-socket$/) or
      ($ThisLine =~ /^Initializing */) or
      ($ThisLine =~ /^Installing */) or
      ($ThisLine =~ /^(mailbox: )?open: No such file or directory$/) or
      ($ThisLine =~ /^(sktbuff|maildrop): write: Broken pipe$/) or
      ($ThisLine =~ /^maildrop: can't read message$/) or
      ($ThisLine =~ /^maildrop: can't write to socket$/) or
      ($ThisLine =~ /^mailbox: mailbox content has been changed$/) or
      ($ThisLine =~ /^maildrop: write: Connection reset by peer$/) or
      ($ThisLine =~ /^(sktbuff|maildrop): write: Connection timed out$/) or
      ($ThisLine =~ /^open: Permission denied$/) or
      ($ThisLine =~ /^read: Broken pipe$/) or
      ($ThisLine =~ /^read: Connection reset by peer$/) or
      ($ThisLine =~ /^spgetpwnam: can't find user: */) or
      ($ThisLine =~ /^sptls: SSL_accept error: (-|)\d+$/) or
      ($ThisLine =~ /^sptls: do need at least RSA or DSA cert\/key data$/)
   ) {
      # Don't care about these...
   } elsif ( ($User, $Host) = ( $ThisLine =~ /^user (.*?) authenticated - (.*)$/ ) ) {
      $Login{$User}{$Host}++;
   } elsif ( ($User,$Downloaded,$DownloadSize,$Left,$LeftSize) = ( $ThisLine =~ /^Stats: (.*?) (.*?) (.*?) (.*?) (.*?)$/) ) {
      $DownloadedMessages{$User} += $Downloaded;
      $DownloadedMessagesSize{$User} += $DownloadSize;
      $MessagesLeft{$User} = $Left;
      $MboxSize{$User} = $LeftSize;
   } elsif ( ($User, $Host) = ( $ThisLine =~ /^session ended for user (.*?) - (.*)/) ) {
      $Logout{$User}{$Host}++;
      $Logout2{$User}++;
      $Connection{$Host}++;
   } elsif  ( ($Host) = ( $ThisLine =~ /^session ended - (.*)$/) ) {
      $Logout{"UNKNOWN"}{$Host}++;
      $Connection{$Host}++;
   } elsif ( ($User,$Host) = ( $ThisLine =~ /^authentication failed for user (.*?) - (.*)/ ) ) {
      $LoginFailed{"$Host ($User)"}++;
   } elsif ( ($User,$Host) = ( $ThisLine =~ /^authentication failed: no such user: (.*?) - (.*)/ ) ) {
      $LoginFailed{"$Host (UNKNOWN: $User)"}++;
   } elsif ( ($Mechanism) = ( $ThisLine =~ /^sptls: TLS connection established: (.*)$/ ) ) {
      $sslMechanism{$Mechanism}++;
   } elsif ($ThisLine =~ /^sptls: created \d+bit temporary [^ ].* key$/ ) {
      $sslTempkey++;
   } elsif ( ($Host) = ( $ThisLine =~ /^autologout time elapsed - (.*)$/ ) ) {
      $AutoLogout{$Host}++;
   } elsif (
      (($File) = ( $ThisLine =~ /^can't open or create file: (.*)$/ )) or
      (($File) = ( $ThisLine =~ /^mailbox: can't open mailbox file: (.*)$/ ))
   ) {
      $PermissionDenied{$File}++;
   } elsif ( ($User, $Host) = ( $ThisLine =~ /^can't find APOP secret for user (.*?) - (.*)$/ ) ) {
      $NoApopSecret{$User}++;
      $Logout{$User}{$Host}++;
      $Connection{$Host}++;
      $Logout2{$User}++;
   } elsif ($ThisLine =~ /^mailbox: no memory available$/ ) {
      $OutOfMemory++;
   } else {
      # Report any unmatched entries...
      # remove PID from named messages

      $ThisLine =~ s/^(client [.0-9]+)\S+/$1/;
      chomp($ThisLine);
      $OtherList{$ThisLine}++;
   }
   $LastLine = $ThisLine;
}

################################################

if ( ( $Detail >= 0 ) and (keys %PermissionDenied)) {
   print "WARNING:\n";
   print "Can't open or create files:\n";
   foreach $File (sort {$a cmp $b} keys %PermissionDenied) {
      print "   $File: $PermissionDenied{$File} Time(s)\n";
   }
}

if ( ( $Detail >= 0 ) and ($OutOfMemory > 0) ) {
   print "\nPOP3 processes were running out of memory $OutOfMemory Time(s)\n";
}

if ( ( $Detail >= 0 ) and (keys %LoginFailed)) {
   print     "\n\n[POP3] Login failures:".
             "\n=========================".
             "\n                                                  Host (user) |          # ".
             "\n------------------------------------------------------------- | -----------";
  
   $ConnCount = 0;
   foreach $Host (sort keys %LoginFailed) {
      $Conns = $LoginFailed{$Host};
      printf "\n%61s | %11.0f", $Host, $Conns;
      $ConnCount += $Conns;
   }
   print "\n" . "-" x 75;
   printf "\n%75s\n\n\n", $ConnCount;
}

if ( ( $Detail >= 5 ) and (keys %Connection)) {
   print     "\n[POP3] Connections:".
             "\n=========================".
             "\n                                                         Host | Connections".
             "\n------------------------------------------------------------- | -----------";
  
   $ConnCount = 0;
   foreach $Host (sort keys %Connection) {
      $Conns = $Connection{$Host};
      printf "\n%61s | %11.0f", $Host, $Conns;
      $ConnCount += $Conns;
   }
   print "\n" . "-" x 75;
   printf "\n%75s\n\n\n", $ConnCount;
}



if (keys %Logout2) {
   print     "\n[POP3] Logout stats (in MB):".
             "\n============================".
             "\n                                   User | Logouts | Downloaded |  Mbox Size".
             "\n--------------------------------------- | ------- | ---------- | ----------";
  
   $ConnCount = 0;
   $SizeAll = 0;
   $DownAll = 0;
   foreach $User (sort keys %Logout2) {
      $Conns = $Logout2{$User};
      $Down = $DownloadedMessagesSize{$User}/(1024*1024);
      $Size = $MboxSize{$User}/(1024*1024);
      printf "\n%39s | %7d | ", $User, $Conns;
      if ($Down > 0) {
         printf "%10.2f | ",$Down;
      } else {
         printf "%10.0f | ",$Down;
      }
      if ($Size > 0) {
         printf "%10.2f",$Size;
      } else {
         printf "%10.0f",$Size;
      }
      $ConnCount += $Conns;
      $SizeAll += $Size;
      $DownAll += $Down;
   }
   print "\n" . "-" x 75;
   printf "\n%49d | %10.2f | %10.2f\n\n\n",$ConnCount,$DownAll,$SizeAll;
}


if ( ( $Detail >= 10 ) and (keys %Login)) {
   print "\n[POP3] Successful Logins:\n";
   $LoginCount = 0;
   foreach my $User (keys %Login) {
      print "  User $User: \n";
      $UserCount = 0;
      foreach $Host (keys %{$Login{$User}}) {
         $HostCount = $Login{$User}{$Host};
         print "    From $Host: $HostCount Time(s)\n";
         $UserCount += $HostCount;
      }
      $LoginCount += $UserCount;
      print "  Total $UserCount Time(s)\n";
      print "\n";
   }
   print "Total $LoginCount successful logins\n\n\n";
}

if ($sslTempkey > 0) {
   print "\nTemporary SSL key created and used $sslTempkey Time(s)\n";
}

if ( ( $Detail >= 5 ) and (keys %sslMechanism)) {
   print "\nTLS Connection types:\n";
   $TotalConnections = 0;
   foreach $Mechanism (keys %sslMechanism) {
      print "   $Mechanism $sslMechanism{$Mechanism} Time(s)\n";
      $TotalConnections += $sslMechanism{$Mechanism};
   }
   print "Total TLS connections: $TotalConnections Time(s)\n";
}

if ( ( $Detail >= 5 ) and (keys %AutoLogout)) {
   print "\nAutologout:\n";
   foreach $Host (sort {$a cmp $b} keys %AutoLogout) {
      print "   $Host: $AutoLogout{$Host} Time(s)\n";
   }
}

if ( ( $Detail >= 5 ) and (keys %NoApopSecret)) {
   print "\nCan't find APOP secret:\n";
   $TotalAPOP = 0;
   foreach $User (keys %NoApopSecret) {
      print "   $User: $NoApopSecret{$User} Time(s)\n";
      $TotalAPOP += $NoApopSecret{$User};
   }
   print "Total APOP errors: $TotalAPOP Time(s)\n";
}

if (keys %OtherList) {
   print "\n**Unmatched Entries**\n";
   foreach $line (sort {$a cmp $b} keys %OtherList) {
      print "   $line: $OtherList{$line} Time(s)\n";
   }
}

exit(0);


# vi: shiftwidth=3 tabstop=3 et