#!/usr/bin/perl -W
#------------------------------------------------------------------------------
# /usr/local/htdocs/mailmanager/mail_mainlog.cgi - Exim mail log - Viewer
#
# Copyright (c) 2005-2017 Marcus Herleb, marcus(at)herleb(dot)de
# Copyright (c) 2018-2018 The Eisfair Team, team(at)eisfair(dot)org
#
# Creation: 2005-02-06 mh
# Last Update: $Id$
#
# !! Inspired by the "Exim mail log viewer v0.9" from
# !! Dennis Neuhaeuser (http://www.dennisneuhaeuser.de)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version..
#------------------------------------------------------------------------------
sub trim
{
my $string = shift;
for ($string)
{
s/^\s+//;
s/\s+$//;
}
return $string;
}
print qq(
Exim mail log
Exim mail log:
);
if (-e "/var/spool/exim/log/mainlog")
{
open (RESULTS, "/var/spool/exim/log/mainlog") or die ("Unable to open file.");
@results = ;
close (RESULTS);
}
for (@results)
{
if ((not $_ =~ /Start queue run:/) and
(not $_ =~ /End queue run:/) and
(not $_ =~ /exim 4.40 daemon started:/) and
(not $_ =~ /no host name found for IP address/) and
(not $_ =~ /Completed/) and
(not $_ =~ /Message is frozen/)
)
{
if ( ($_ =~ /=>/) or
($_ =~ /<=/)
)
{
$_ =~ s/</g;
$_ =~ s/>/>/g;
@array = split(/ /,($_));
my $count = @array;
if (trim($array[3]) eq '<=')
{
$trcolor = "lightblue";
}
elsif (trim($array[3]) eq '=>')
{
$trcolor = "lightgreen";
}
else
{
$trcolor = "orange";
}
print "";
for ($i = 0; $i < 8; $i++)
{
print "".trim($array[$i])." | ";
}
print " ";
if ($count > 8)
{
print "";
print " | ";
print "";
for ($i = 8; $i < $count; $i++)
{
print $array[$i]." ";
}
print " | ";
}
}
else
{
if ($_ =~ /This message exceeds the spam threshold/)
{
$trcolor = "yellow";
}
elsif ($_ =~ /This message contains malware/)
{
$trcolor = "tomato";
}
else
{
$trcolor = "lightgrey";
}
print "";
$_ =~ s/</g;
$_ =~ s/>/>/g;
@array = split(/ /,$_);
my $count = @array;
print "".trim($array[0])." | ";
print "".trim($array[1])." | ";
if (length($array[2]) == 16)
{
print "".trim($array[2])." | ";
}
else
{
print " | ";
}
print " | ";
print "";
if (length($array[2]) != 16)
{
print $array[2]." ";
}
for ($i = 3; $i < $count; $i++)
{
print $array[$i]." ";
}
print " | ";
}
}
}
print qq(
|
);