/usr/share/logwatch/scripts/services/imapd is in logwatch 7.4.1-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | #!/usr/bin/perl
##########################################################################
# $Id: imapd 150 2013-06-18 22:19:38Z mtremaine $
##########################################################################
########################################################
# The imap script was written by:
# Pawe³ Go³aszewski <blues@gda.pl>
########################################################
#####################################################
## Copyright (c) 2008 Pawe³ Go³aszewski
## Covered under the included MIT/X-Consortium License:
## http://www.opensource.org/licenses/mit-license.php
## All modifications and contributions by other persons to
## this script are assumed to have been donated to the
## Logwatch project and thus assume the above copyright
## and licensing terms. If you want to make contributions
## under your own copyright or a different license this
## must be explicitly stated in the contribution an the
## Logwatch project reserves the right to not accept such
## contributions. If you have made significant
## contributions to this script and want to claim
## copyright please contact logwatch-devel@lists.sourceforge.net.
#########################################################
my $Debug = $ENV{'LOGWATCH_DEBUG'};
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
if ( $Debug >= 5 ) {
print STDERR "\n\nDEBUG \n\n";
}
while (defined($ThisLine = <STDIN>)) {
if (
($ThisLine =~ /^Initializing */) or
($ThisLine =~ /^spgetpwnam: can't find user: */) or
($ThisLine =~ /^couriertls: read: Connection reset by peer/ ) or
# timeouts are reported in some other scripts - maybe it should be here too?
($ThisLine =~ /^couriertls: read: Connection timed out/ ) or
($ThisLine =~ /^LOGOUT, ip=\[.*\], rcvd=\d+, sent=\d+$/) or
($ThisLine =~ /^Disconnected, ip=\[.*\]/) or
# uw-imapd
($ThisLine =~ /^Moved \d+ bytes of new mail to.*$/) or
($ThisLine =~ /^Unexpected client disconnect, while reading line.*$/)
) {
# Don't care about these...
} elsif ( ($User, $Host) = ( $ThisLine =~ /^Login user=(.*?) host=(.*\[.*\])$/ ) ) {
$Login{$User}{$Host}++;
} elsif ( ($User, $Host) = ( $ThisLine =~ /^LOGIN, user=(.*?), ip=\[([^ ,]+)\](?:, port=\[\d+\])?, protocol=IMAP$/o ) ) {
$Login{$User}{$Host}++;
} elsif ( ($User,$Host) = ( $ThisLine =~ /^Authenticated user=(.*) host=(.*\[.*\]).*$/ ) ) {
$Login{$User}{$Host}++;
} elsif ( ($User,$Host) = ( $ThisLine =~ /^Preauthenticated user=(.*) host=(.*)$/ ) ) {
$Login{$User}{$Host}++;
} elsif ( ($Host) = ( $ThisLine =~ /^imap service init from (.*)$/ ) ) {
$ConnectionNonSSL{$Host}++;
$Connection{$Host}++;
} elsif ( ($Host) = ( $ThisLine =~ /^imaps SSL service init from (.*)$/ ) ) {
$ConnectionSSL{$Host}++;
$Connection{$Host}++;
} elsif ( ($Host) = ( $ThisLine =~ /^Connection, ip=\[(.*)\]$/o ) ) {
$Connection{$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 =~ /^authentication failed for user (.*?) - (.*)/ ) ) {
# $LoginFailed{"$Host ($User)"}++;
} elsif ( ($User, $Host) = ( $ThisLine =~ /^Logout user=(.*?) host=(.*\[.*\])$/) ) {
$Logout{$User}{$Host}++;
$Logout2{$User}++;
# More generic pattern for uw-imapd
} elsif ( ($User, $Host) = ( $ThisLine =~ /^Logout user=(.*?) host=(.*)$/) ) {
$Logout{$User}{$Host}++;
$Logout2{$User}++;
} elsif ( ($dummy, $User, $Host, $DownloadSize1, $DownloadSize2) = ( $ThisLine =~ /^(LOGOUT|TIMEOUT|DISCONNECTED), user=(.*?), ip=\[([^ ,]+)\](?:, port=\[\d+\])?, headers=(\d+), body=(\d+)/o ) ) {
$Logout{$User}{$Host}++;
$Logout2{$User}++;
$DownloadedMessagesSize{$User} += $DownloadSize1 + $DownloadSize2;
if ( ( $ThisLine =~ /, starttls=1/o ) ) {
$ConnectionSSL{$Host}++;
} else {
$Connection{$Host}++;
}
} elsif ( ($User,$Host) = ( $ThisLine =~ /^Autologout user=(.*) host=(.*\[.*\])$/ ) ) {
$AutoLogout{$User}{$Host}++;
$Logout{$User}{$Host}++;
$Logout2{$User}++;
} elsif ( ($Reason,$User,$Host) = ( $ThisLine =~ /^Killed (.*) user=(.*) host=(.*\[.*\])$/ ) ) {
$Logout{$User}{$Host}++;
$Logout2{$User}++;
$KilledSession{$User}{$Reason}++;
} elsif (
(($User,$Host) = ( $ThisLine =~ /^Broken pipe, while reading line user=(.*) host=(.*\[.*\])$/ )) or
(($User,$Host) = ( $ThisLine =~ /^Command stream end of file, while reading line user=(.*) host=(.*\[.*\])$/ )) or
(($User,$Host) = ( $ThisLine =~ /^Connection (?:reset by peer|timed out), while reading line user=(.*) host=(.*\[.*\])$/ )) or
(($User,$Host) = ( $ThisLine =~ /^No route to host, while reading line user=(.*) host=(.*\[.*\])$/ )) or
(($User,$Host) = ( $ThisLine =~ /^Unexpected client disconnect, while reading line user=(.*) host=(.*\[.*\])$/ ))
) {
$Logout{$User}{$Host}++;
$Logout2{$User}++;
$SocketErrors{$Host}++;
} 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 %LoginFailed)) {
print "\n\n[IMAPd] Login failures:".
"\n=========================".
"\n Host (user) | # ".
"\n------------------------------------------------------------- | -----------";
$ConnCount = 0;
foreach $Host (sort keys %LoginFailed) {
$Conns = $LoginFailed{$Host};
$HostLength = length($Host);
$HostSpaceLength = 61 - $HostLength;
$CountLength = length("$Conns");
$CountSpaceLength = 12 - $CountLength;
print "\n" ." " x $HostSpaceLength . $Host . " |" . " " x $CountSpaceLength . $Conns . "";
$ConnCount += $Conns;
}
$CountLength = length("$ConnCount");
$CountSpaceLength = 75 - $CountLength;
print "\n" . "-" x 75;
print "\n" . " " x $CountSpaceLength . "$ConnCount\n\n\n";
}
if ( ( $Detail >= 5 ) and (keys %Connection)) {
print "\n[IMAPd] Connections:".
"\n=========================".
"\n Host | Connections | SSL | Total ".
"\n-------------------------------------- | ----------- | -------- | ---------";
$ConnCount = 0;
$SSLConn = 0;
$TotalConn = 0;
foreach $Host (sort keys %Connection) {
$Total = $Connection{$Host};
if (defined ($ConnectionNonSSL{$Host})) {
$Conns = $ConnectionNonSSL{$Host};
} else {
$Conns = 0;
}
if (defined ($ConnectionSSL{$Host})) {
$SSL = $ConnectionSSL{$Host};
} else {
$SSL = 0;
}
$HostLength = length($Host);
$HostSpaceLength = 38 - $HostLength;
$CountLength = length("$Conns");
$CountSpaceLength = 12 - $CountLength;
$SSLLength = length("$SSL");
$SSLSpaceLength = 9 - $SSLLength;
$TotalLenght = length("$Total");
$TotalSpaceLength = 10 - $TotalLenght;
print "\n" ." " x $HostSpaceLength . $Host . " |" . " " x $CountSpaceLength . $Conns .
" |" . " " x $SSLSpaceLength . $SSL . " |" . " " x $TotalSpaceLength . $Total;
$NonSSLCount += $Conns;
$SSLCount += $SSL;
$TotalCount += $Total;
}
$NonSSLLength = length("$NonSSLCount");
$NonSSLSpaceLength = 52 - $NonSSLLength;
$SSLLength = length("$SSLCount");
$SSLSpaceLength = 9 - $SSLLength;
$TotalLength = length("$TotalCount");
$totalSpaceLength = 10 - $TotalLength;
print "\n" . "-" x 75;
print "\n" . " " x $NonSSLSpaceLength . $NonSSLCount . " |" . " " x $SSLSpaceLength . $SSLCount .
" |" . " " x $totalSpaceLength . $TotalCount . "\n\n\n";
}
if (keys %Logout2) {
print "\n[IMAPd] Logout stats:".
"\n====================".
"\n User | Logouts | Downloaded | Mbox Size".
"\n--------------------------------------- | ------- | ---------- | ----------";
$ConnCount = 0;
$SizeAll = 0;
$DownAll = 0;
foreach $User (sort keys %Logout2) {
$Conns = $Logout2{$User};
$UserLength = length($User);
$UserSpaceLength = 39 - $UserLength;
$CountLength = length("$Conns");
$CountSpaceLength = 8 - $CountLength;
$Down = $DownloadedMessagesSize{$User};
if (! defined $Down) {
$Down = 0; #Hack
}
$DownSpaceLength = 11 - length($Down);
#$Size = $MboxSize{$User};
$Size = 0; #Hack
$SizeSpaceLength = 11 - length($Size);
print "\n" ." " x $UserSpaceLength . $User . " |" . " " x $CountSpaceLength . $Conns . " |" .
" " x $DownSpaceLength . $Down . " |" . " " x $SizeSpaceLength . $Size;
$ConnCount += $Conns;
$SizeAll += $Size;
$DownAll += $Down;
}
$CountLength = length("$ConnCount");
$CountSpaceLength = 49 - $CountLength;
$DownLength = length($DownAll);
$DownSpaceLength = 11 - $DownLength;
$SizeLength = length($SizeAll);
$SizeSpaceLength = 11 - $SizeLength;
print "\n" . "-" x 75;
print "\n" . " " x $CountSpaceLength . "$ConnCount" . " |" . " " x $DownSpaceLength . $DownAll . " |" .
" " x $SizeSpaceLength . $SizeAll . "\n\n\n";
}
if ( ( $Detail >= 10 ) and (keys %Login)) {
print "\n[IMAPd] Successful Logins:\n";
$LoginCount = 0;
foreach my $User (sort 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";
}
if ( ( $Detail >= 10 ) and (keys %AutoLogout)) {
print "\nAutologout:\n";
foreach $User (sort {$a cmp $b} keys %AutoLogout) {
print " $User:\n";
foreach $Host (sort {$a cmp $b} keys %{$AutoLogout{$User}}) {
print " $Host: $AutoLogout{$User}{$Host} Time(s)\n";
}
}
}
if ( ( $Detail >= 10 ) and (keys %KilledSession)) {
print "\nKilled IMAP sessions:\n";
foreach $User (sort {$a cmp $b} keys %KilledSession) {
print " $User:\n";
foreach $Reason (sort {$a cmp $b} keys %{$KilledSession{$User}}) {
print " $Reason: $KilledSession{$User}{$Reason} Time(s)\n";
}
}
}
if ( ( $Detail >= 10 ) and (keys %SocketErrors)) {
print "\nSocket Errors in connections with:\n";
foreach $Host (sort {$a cmp $b} keys %SocketErrors) {
print " $Host: $SocketErrors{$Host} 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 syntax=perl et
# Local Variables:
# mode: perl
# perl-indent-level: 3
# indent-tabs-mode: nil
# End:
|