Beispiel #1
0
function amavis_logger($fullpath)
{
    $q = new mysql();
    $ini = new iniFrameWork($fullpath);
    $message_id = $ini->_params["TIME"]["message-id"];
    $time_amavis = $ini->_params["TIME"]["time_amavis"];
    $smtp_sender = $ini->_params["TIME"]["server_from"];
    $mailfrom = $ini->_params["TIME"]["mailfrom"];
    $mailto = $ini->_params["TIME"]["mailto"];
    $Country = $ini->_params["TIME"]["Country"];
    $Region = $ini->_params["TIME"]["Region"];
    $City = $ini->_params["TIME"]["City"];
    $kas = $ini->_params["TIME"]["kas"];
    $banned = $ini->_params["TIME"]["banned"];
    $infected = $ini->_params["TIME"]["infected"];
    $spammy = $ini->_params["TIME"]["spammy"];
    $spam = $ini->_params["TIME"]["spam"];
    $blacklisted = $ini->_params["TIME"]["blacklisted"];
    $whitelisted = $ini->_params["TIME"]["whitelisted"];
    $size = $ini->_params["TIME"]["size"];
    $subject = trim($ini->_params["TIME"]["subject"]);
    events("amavis_logger():: " . basename($fullpath) . " ({$message_id}) from=<{$mailfrom}> to=<{$mailto}>");
    $Region = trim(str_replace("'", '`', $Region));
    $Country = trim(str_replace("'", '`', $Country));
    $City = trim(str_replace("'", '`', $City));
    if ($Country == null) {
        $array_geo = GeoIP($smtp_sender);
        $Country = $array_geo[0];
        $City = $array_geo[1];
        $City = addslashes($City);
        $Country = addslashes($Country);
    }
    if (preg_match('#(.+?)@(.+)#', $mailfrom, $re)) {
        $domain_from = $re[2];
    }
    if (!is_numeric($whitelisted)) {
        $whitelisted = 0;
    }
    if (!is_numeric($blacklisted)) {
        $blacklisted = 0;
    }
    if (!is_numeric($kas)) {
        $kas = 0;
    }
    if (!is_numeric($banned)) {
        $banned = 0;
    }
    if (!is_numeric($infected)) {
        $infected = 0;
    }
    if (!is_numeric($spammy)) {
        $spammy = 0;
    }
    if (!is_numeric($spam)) {
        $spam = 0;
    }
    if (!is_numeric($size)) {
        $size = 0;
    }
    $mailto = str_replace("'", "", $mailto);
    $mailfrom = str_replace("'", '', $mailfrom);
    $mailto = $mailto . ",";
    $mailto_array = explode(",", $mailto);
    if (!is_array($mailto_array)) {
        return null;
    }
    //mb_internal_encoding("UTF-8");
    //$subject = mb_decode_mimeheader($subject);
    events("amavis_logger():: Delete id <{$message_id}> in mysql");
    if ($message_id != null) {
        deleteid_from_messageid($message_id, $q);
    }
    if ($message_id == null) {
        $message_id = md5($ini->toString());
    }
    events("amavis_logger():: Start loop for Recipients number=" . count($mailto_array) . " id=<{$message_id}>");
    $bounce_error = null;
    if ($bounce_error == null) {
        if ($infected == 1) {
            $bounce_error = "INFECTED";
        }
    }
    if ($bounce_error == null) {
        if ($banned == 1) {
            $bounce_error = "BANNED";
        }
    }
    if ($bounce_error == null) {
        if ($spammy == 1) {
            $bounce_error = "SPAM";
        }
    }
    if ($bounce_error == null) {
        if ($spam == 1) {
            $bounce_error = "SPAM";
        }
    }
    if ($bounce_error == null) {
        if ($blacklisted == 1) {
            $bounce_error = "BLACKLISTED";
        }
    }
    if ($bounce_error == null) {
        if ($whitelisted == 1) {
            $bounce_error = "WHITELISTED";
        }
    }
    if ($bounce_error == null) {
        if ($kas > 90) {
            $bounce_error = "KAS3";
        }
    }
    if ($bounce_error == null) {
        $bounce_error = "PASS";
    }
    $prefix = "INSERT INTO amavis_event (`from`,`from_domain`,`to`,`to_domain`,`subject`,`size`,`bounce_error`,`country`,`city`,`zDate`,`ipaddr`) VALUES";
    $subject = addslashes($subject);
    $inserted_number = 0;
    while (list($num, $destataire) = each($mailto_array)) {
        $destataire = trim($destataire);
        if ($message_id == null) {
            continue;
        }
        if ($destataire == null) {
            continue;
        }
        if (preg_match('#(.+?)@(.+)#', $destataire, $re)) {
            $domain_to = $re[2];
        }
        $inserted_number++;
        events("amavis_logger():: {$time_amavis} {$message_id} rcpt=<{$destataire}> From=<{$mailfrom}> {$bounce_error} Geo:{$Country}/{$City}");
        $f[] = "('{$mailfrom}','{$domain_from}','{$destataire}','{$domain_to}','{$subject}','{$size}','{$bounce_error}','{$Country}','{$City}','{$time_amavis}','{$smtp_sender}')";
    }
    $sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        events("amavis_logger():: FAILED {$sql}");
        return null;
    }
    events("amavis_logger():: DELETE {$fullpath}");
    if (!@unlink("{$fullpath}")) {
        events("amavis_logger():: WARNING UNABLE TO DELETE " . basename($fullpath));
    }
}
function amavis_logger($fullpath)
{
    $q = new mysql();
    $ini = new Bs_IniHandler($fullpath);
    $message_id = $ini->_params["TIME"]["message-id"];
    $time_amavis = $ini->_params["TIME"]["time_amavis"];
    $smtp_sender = $ini->_params["TIME"]["server_from"];
    $mailfrom = $ini->_params["TIME"]["mailfrom"];
    $mailto = $ini->_params["TIME"]["mailto"];
    $Country = $ini->_params["TIME"]["Country"];
    $Region = $ini->_params["TIME"]["Region"];
    $City = $ini->_params["TIME"]["City"];
    $kas = $ini->_params["TIME"]["kas"];
    $banned = $ini->_params["TIME"]["banned"];
    $infected = $ini->_params["TIME"]["infected"];
    $spammy = $ini->_params["TIME"]["spammy"];
    $spam = $ini->_params["TIME"]["spam"];
    $blacklisted = $ini->_params["TIME"]["blacklisted"];
    $whitelisted = $ini->_params["TIME"]["whitelisted"];
    events("{$fullpath} ({$message_id}) from=<{$mailfrom}> to=<{$mailto}>");
    $Region = str_replace("'", '`', $Region);
    $Country = str_replace("'", '`', $Country);
    $City = str_replace("'", '`', $City);
    if (preg_match('#(.+?)@(.+)#', $mailfrom, $re)) {
        $domain_from = $re[2];
    }
    if ($kas == null) {
        $kas = 0;
    }
    if ($banned == null) {
        $banned = 0;
    }
    if ($infected == null) {
        $infected = 0;
    }
    if ($spammy == null) {
        $spammy = 0;
    }
    if ($spam == null) {
        $spam = 0;
    }
    if (!is_numeric($whitelisted)) {
        $whitelisted = 0;
    }
    if ($blacklisted == null) {
        $blacklisted = 0;
    }
    if ($whitelisted == null) {
        $whitelisted = 0;
    }
    $mailto = $mailto . ",";
    $mailto_array = explode(",", $mailto);
    if (!is_array($mailto_array)) {
        return null;
    }
    $mailfrom = str_replace("'", '', $mailfrom);
    events("Delete id <{$message_id}>");
    if ($message_id != null) {
        deleteid_from_messageid($message_id, $q);
    }
    events("Start loop for Recipients number=" . count($mailto_array) . " id=<{$message_id}>");
    while (list($num, $destataire) = each($mailto_array)) {
        if ($message_id == null) {
            continue;
        }
        if ($destataire == null) {
            continue;
        }
        if (preg_match('#(.+?)@(.+)#', $destataire, $re)) {
            $domain_to = $re[2];
        }
        events("{$time_amavis} {$messageid} rcpt=<{$destataire}> From=<{$mailfrom}> SQL ID=\"{$id}\" ADD spammy={$spammy}, infected={$infected},spam={$spam}");
        $sql = "INSERT INTO smtp_logs (msg_id_text,sender_user,delivery_user,sender_domain,delivery_domain,time_amavis,Country,Region,kas,infected,\n\t\tspammy,SPAM,blacklisted,whitelisted,smtp_sender,time_connect)\n\t\tVALUES('{$messageid}','{$mailfrom}','{$destataire}','{$domain_from}','{$domain_to}','{$time_amavis}','{$Country}','{$Region}','{$kas}','{$infected}','{$spammy}','{$spam}','{$blacklisted}',\n\t\t'{$whitelisted}','{$smtp_sender}','{$time_amavis}')";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            events("amavis_logger Failed {$sql}");
            return null;
        }
    }
    events("DELETE {$fullpath}");
    if (!@unlink("{$fullpath}")) {
        events("WARNING UNABLE TO DELETE {$fullpath}");
    }
}