Bug in mail_logs.php

Discussion in 'Developers' Forum' started by ivoks, Nov 27, 2008.

  1. ivoks

    ivoks New Member


    I've noticed a bug in mail_logs.php which generates mail traffic stats. Line in my mail.log:

    Nov 15 14:19:04 xxxx postfix/smtpd[27493]: NOQUEUE: reject: RCPT from
    xxxxxxxxxxxxxx[xxxxxxxxxxx]: 450 4.1.8
    <[email protected]>: Sender address rejected:
    Domain not found; from=<[email protected]>
    to=<[email protected]> proto=ESMTP helo=<xxxxxxxxxxx>

    resulted in '1203725193' being counted as a mail traffic. This was caused by a line in '/root/ispconfig/scripts/shell/mail_logs.php':

    exec("grep -iw ".$mod->system->server_conf["server_mta"]." $dist_mail_log.$datum | grep -iw from | grep -iw $domain | grep -iw $monat_kurz | cut -f2 -d, | cut -f2 -d= > $dist_mail_log.$vhost");

    This is wrong. You guys should really use awk or something. I found that:

    exec("grep -iw ".$mod->system->server_conf["server_mta"]." $dist_mail_log.$datum | grep -iw from | grep -iw $domain | grep -iw $monat_kurz | grep size= | awk -F', size=' '{print $2}' | cut -d\, -f1 > $dist_mail_log.$vhost");

    works much better in my setup (postfix).

    Take care.
    Last edited: Nov 27, 2008
  2. falko

    falko Super Moderator ISPConfig Developer

    I've added this to our bugtracker.
  3. jmroth

    jmroth ISPConfig Developer ISPConfig Developer

    fix in r1109 FS#333

    I see there is a potential fix for the mail size logging.
    1) when awk is not available, the old (potentially flawed) code is used.
    2) additionally, when there is more logging to the mail.log like
    Jan 26 18:19:24 mark5 postfix-policyd: rcpt=10111, throttle=clear(a), host=iii.iii.iii.iii, from=xxx, to=yyy, size=0/999999999, quota=0/100000000, count=1/512(450), rcpt=1/3600(1757), threshold=0%|0%|0%
    additional matches that should not happen do happen.

    In the postfix case one should only consider lines with 'postfix/qmgr'.
    In the sendmail case I wouldn't know what to do, since I don't use sendmail...

    If the problem is that one does not know whether grep/awk etc. exists (with the desired features) on potentially ancient systems like Debian 3.0 etc. one should maybe include the required tools with the installation package.

Share This Page