function content()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $t = time();
    $q = new mysql_postfix_builder();
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT DATE_SUB(NOW(),INTERVAL 1 HOUR) as tdate"));
    $currenthour = date("YmdH", strtotime($ligne["tdate"])) . "_hour";
    $rows = $q->COUNT_ROWS($currenthour);
    $jsadd = null;
    if ($rows > 0) {
        $jsadd = "LoadAjax('statistics-{$t}','{$page}?messaging-stats=yes');";
    }
    $html = "\n\t<div class=BodyContent>\n\t\t<div style='font-size:14px'><a href=\"miniadm.index.php\">{myaccount}</a></div>\n\t\t<H1>&laquo;{$_SESSION["ou"]}&raquo; {messaging}</H1>\n\t\t<p>{mymessaging_text}</p>\n\t</div>\t\n\t<div id='messaging-left'></div>\n\t\n\t<script>\n\t\tLoadAjax('messaging-left','{$page}?tabs=yes');\n\t\t//LoadAjax('messaging-left','domains.manage.org.index.php?org_section=postfix&SwitchOrgTabs={$_SESSION["ou"]}&ou={$_SESSION["ou"]}&mem=yes&dn=');\n\t</script>\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
Esempio n. 2
0
function MiltergreyList_inject($array)
{
    if (count($array) == 0) {
        events("MiltergreyList_inject():: Nothing to do...", __FILE__);
        return;
    }
    $q = new mysql_postfix_builder();
    events("MiltergreyList_inject():: Analyze " . count($array) . " rows", __FILE__);
    while (list($tablename, $sqls) = each($array)) {
        events("MiltergreyList_inject():: build-sql {$tablename} > " . count($array) . " rows", __FILE__);
        $q->milter_BuildHourTable($tablename);
        if (!$q->TABLE_EXISTS($tablename)) {
            events("MiltergreyList_inject():: {$tablename} no such table", __FILE__);
        }
        $prefix = "INSERT IGNORE INTO {$tablename} (`zmd5`,`ztime`,`zhour`,`mailfrom`,`instancename`,`mailto`,`domainfrom`,`domainto`,`senderhost`,`failed`) VALUES ";
        $q->QUERY_SQL($prefix . @implode(",", $sqls));
        if (!$q->ok) {
            events("MiltergreyList_inject():: {$q->mysql_error}", __FILE__);
        }
    }
    events("MiltergreyList_inject():: Finish...", __FILE__);
}
Esempio n. 3
0
function _STATS_hourly_cnx_to_daily_cnx($sourcetable, $desttable, $HOUR_FIELD)
{
    $q = new mysql_postfix_builder();
    $sql = "SELECT COUNT(zmd5) as tcount,HOUR(zDate) as thour,hostname,domain,ipaddr FROM {$sourcetable} GROUP BY thour,hostname,domain,ipaddr ";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $prefix = "INSERT IGNORE INTO `{$desttable}` (`zmd5`,`Hour`,`cnx`,`hostname`,`domain`,`ipaddr`) VALUES ";
    if (mysql_num_rows($results) == 0) {
        return true;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $md5 = md5(serialize($ligne));
        $f[] = "('{$md5}','{$ligne["thour"]}','{$ligne["tcount"]}','{$ligne["hostname"]}','{$ligne["domain"]}','{$ligne["ipaddr"]}')";
        if (count($f) > 500) {
            $q->QUERY_SQL($prefix . @implode(",", $f));
            if (!$q->ok) {
                system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
                return false;
            }
            $f = array();
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL($prefix . @implode(",", $f));
        if (!$q->ok) {
            system_admin_events($q->mysql_error, __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
            return false;
        }
        $f = array();
    }
    return true;
}
function ParseFile($filename, $instancename = null)
{
    events("Parsing  {$filename}, instance={$instancename}");
    $f = explode("\n", @file_get_contents($filename));
    $q = new mysql_postfix_builder();
    @mkdir("/var/log/artica-postfix/Postfix-sql-error", 0755, true);
    while (list($num, $line) = each($f)) {
        if (trim($line) == null) {
            continue;
        }
        usleep(500);
        if (preg_match("#(.+?)\\s+([0-9\\:]+)\\s+(.+?)\\s+(.+?)\\s+(.+)\\s+(.*?)\\s+SMTP\\s+-\\s+([0-9]+)\\s+([0-9]+)#i", $line, $re)) {
            while (list($num, $line) = each($re)) {
                $line = str_replace("'", "", $line);
                $line = mysql_escape_string2($line);
                $re[$num] = $line;
            }
            $md5 = md5(@implode("", $re));
            $zDate = "{$re[1]} {$re[2]}";
            $time = strtotime($zDate);
            $year = date("Y", $time);
            if ($year != date("Y")) {
                $zDate = date("Y") . "-" . date("m-d", $time) . " " . date("H:i:s", $time);
                $time = strtotime($zDate);
            }
            $month = date("m", $time);
            if ($month != date("m")) {
                $zDate = date("Y") . "-" . date("m") . "-" . date("d", $time) . " " . date("H:i:s", $time);
                $time = strtotime($zDate);
            }
            $table_hour = date("YmdH", $time) . "_hour";
            if ($re[3] == "<>") {
                $re[3] = "unknown";
            }
            if ($re[4] == "<>") {
                $re[4] = "unknown";
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "{$table_hour}:{$time}  From:{$re[3]} to {$re[4]}\n";
            }
            $from = $re[3];
            $to = $re[4];
            $from_domain = null;
            $to_domain = null;
            if (strpos($from, "@") > 0) {
                $tb = explode("@", $from);
                $from_domain = $tb[1];
            }
            if (strpos($to, "@") > 0) {
                $tb = explode("@", $to);
                $to_domain = $tb[1];
            }
            $hour = date("H", $time);
            $senderHost = $re[5];
            $recipientHost = $re[6];
            $SMTPCode = $re[7];
            $MailSize = $re[8];
            $from = strtolower(str_replace("'", "", $from));
            $to = strtolower(str_replace("'", "", $to));
            $from_domain = strtolower(str_replace("'", "", $from_domain));
            $to_domain = strtolower(str_replace("'", "", $to_domain));
            $SQL_ARRAY[$table_hour][] = "('{$md5}','{$zDate}','{$hour}','{$from}','{$to}','{$from_domain}','{$to_domain}','{$senderHost}','{$recipientHost}','{$MailSize}','{$SMTPCode}','{$instancename}')";
            if (count($SQL_ARRAY[$table_hour]) > 5000) {
                if (!$q->BuildHourTable($table_hour)) {
                    echo "Unable to build table {$table_hour} {$q->mysql_error}\n";
                    return;
                }
                $sql = "INSERT IGNORE INTO `{$table_hour}` (zmd5,ztime,zhour,mailfrom,mailto,domainfrom,domainto,senderhost,recipienthost,mailsize,smtpcode,instancename) VALUES " . @implode(",", $SQL_ARRAY[$table_hour]);
                if (!$q->QUERY_SQL($sql)) {
                    echo $q->mysql_error . "\n";
                    @file_put_contents("/var/log/artica-postfix/Postfix-sql-error/" . md5($sql), $sql);
                    return;
                }
                $SQL_ARRAY[$table_hour] = array();
            }
            continue;
        }
        if (preg_match("#(.+?)\\s+([0-9\\:]+)\\s+(.+?)\\s+(.+?)\\s+(.+?)\\s+(.*?)\\s+SMTP\\s+-\\s+([0-9]+)\\s+\\?#i", $line, $re)) {
            while (list($num, $line) = each($re)) {
                $line = str_replace("'", "", $line);
                $line = mysql_escape_string2($line);
                $re[$num] = $line;
            }
            $md5 = md5(@implode("", $re));
            $zDate = "{$re[1]} {$re[2]}";
            $time = strtotime($zDate);
            $year = date("Y", $time);
            if ($year != date("Y")) {
                $zDate = date("Y") . "-" . date("m-d", $time) . " " . date("H:i:s", $time);
                $time = strtotime($zDate);
            }
            $month = date("m", $time);
            if ($month != date("m")) {
                $zDate = date("Y") . "-" . date("m") . "-" . date("d", $time) . " " . date("H:i:s", $time);
                $time = strtotime($zDate);
            }
            $table_hour = date("YmdH", $time) . "_hour";
            $hour = date("H", $time);
            $from = $re[3];
            $tb = explode("@", $from);
            $from_domain = $tb[1];
            $to = $re[4];
            $tb = explode("@", $to);
            $to_domain = $tb[1];
            $senderHost = $re[5];
            $SMTPCode = $re[7];
            $recipientHost = null;
            $from = strtolower(str_replace("'", "", $from));
            $to = strtolower(str_replace("'", "", $to));
            $from_domain = strtolower(str_replace("'", "", $from_domain));
            $to_domain = strtolower(str_replace("'", "", $to_domain));
            $MailSize = 0;
            $SQL_ARRAY[$table_hour][] = "('{$md5}','{$zDate}','{$hour}','{$from}','{$to}','{$from_domain}','{$to_domain}','{$senderHost}','{$recipientHost}','{$MailSize}','{$SMTPCode}','{$instancename}')";
            if (count($SQL_ARRAY[$table_hour]) > 5000) {
                if (!$q->BuildHourTable($table_hour)) {
                    echo "Unable to build table {$table_hour} {$q->mysql_error}\n";
                    return;
                }
                $sql = "INSERT IGNORE INTO `{$table_hour}` (zmd5,ztime,zhour,mailfrom,mailto,domainfrom,domainto,senderhost,recipienthost,mailsize,smtpcode,instancename) VALUES " . @implode(",", $SQL_ARRAY[$table_hour]);
                if (!$q->QUERY_SQL($sql)) {
                    events($q->mysql_error);
                    @file_put_contents("/var/log/artica-postfix/Postfix-sql-error/" . md5($sql), $sql);
                    return;
                }
                $SQL_ARRAY[$table_hour] = array();
            }
            continue;
        }
    }
    while (list($table_hour, $s) = each($SQL_ARRAY)) {
        if (count($s) > 0) {
            if (!$q->BuildHourTable($table_hour)) {
                events("Unable to build table {$table_hour} {$q->mysql_error}");
                return;
            }
            $count = $q->COUNT_ROWS($table_hour);
            $sql = "INSERT IGNORE INTO `{$table_hour}` (zmd5,ztime,zhour,mailfrom,mailto,domainfrom,domainto,senderhost,recipienthost,mailsize,smtpcode,instancename) VALUES " . @implode(",", $s);
            if (!$q->QUERY_SQL($sql)) {
                @file_put_contents("/var/log/artica-postfix/Postfix-sql-error/" . md5($sql), $sql);
                events($q->mysql_error);
                return;
            }
            $count2 = $q->COUNT_ROWS($table_hour);
            $Allelements = count($s);
            $AddedElements = $count2 - $count;
            events("{$table_hour} {$Allelements} elements ({$AddedElements} new added elements)");
        }
    }
    events("removing {$filename}");
    @unlink($filename);
}
function list_table()
{
    $Now = false;
    $MyPage = CurrentPageName();
    $page = 1;
    $tpl = new templates();
    if (!isset($_GET["failed"])) {
        $_GET["failed"] = null;
    }
    $table = "mgreyd_" . date("Ymd");
    $q = new mysql_postfix_builder();
    if (isset($_GET["hier"])) {
        $hier = strtotime($q->HIER() . " 00:00:00");
        $table = "mgreyd_" . date("Ymd", $hier);
    }
    if (isset($_GET["now"])) {
        $Now = true;
        $table = "MGREY_RTT";
    }
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table} no such table");
    }
    $t = $_GET["t"];
    $database = null;
    $FORCE_FILTER = 1;
    if ($_GET["failed"] != null) {
        $FORCE_FILTER = "`failed`='{$_GET["failed"]}'";
    }
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("No item");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error}");
        }
        $total = $ligne["TCOUNT"];
        if ($total == 0) {
            json_error_show("No rows for {$searchstring}");
        }
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 1;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}<hr>{$sql}<hr>");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No data...", 1);
    }
    $today = date('Y-m-d');
    $style = "font-size:14px;";
    $color = "black";
    $unknown = $tpl->_ENGINE_parse_body("{unknown}");
    $arrayA["accept"] = $tpl->javascript_parse_text("{sent}");
    $arrayA["tempfail"] = $tpl->javascript_parse_text("{greylist}");
    $arrayA["reject"] = $tpl->javascript_parse_text("{blacklist}");
    //Hour | cnx | hostname                                       | domain                    |
    while ($ligne = mysql_fetch_assoc($results)) {
        $style = "background-color:#03BA2F;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        $failed = $ligne["failed"];
        if ($failed == "tempfail") {
            $style = "background-color:#949494;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        }
        if ($failed == "reject") {
            $style = "background-color:#DD1212;color:#FFFFFF;margin:-5px;padding:5px;font-weight:bold;text-transform:capitalize;font-size:14px;";
        }
        if ($Now) {
            $ligne["hits"] = 1;
        }
        $text_hour = "{$ligne["zhour"]}h";
        if ($Now) {
            $text_hour = date("H:i:s", strtotime($ligne["ztime"]));
        }
        $md = md5(serialize($ligne));
        $cells = array();
        $cells[] = "<span style='font-size:14px;'>{$text_hour}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["hits"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["senderhost"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["mailfrom"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["mailto"]}</span>";
        $cells[] = "<span style='font-size:14px;'><div style='{$style}'>{$arrayA[$failed]}</div></span>";
        $data['rows'][] = array('id' => $line["zmd5"], 'cell' => $cells);
    }
    echo json_encode($data);
}
Esempio n. 6
0
function STATS_CNX_ACCEPT_parse($path)
{
    if ($GLOBALS["VERBOSE"]) {
        echo "Parsing {$path}\n";
    }
    $db_con = dba_open($path, "r", "db4");
    if (!$db_con) {
        echo "DB open {$path} failed\n";
        return false;
    }
    $fam = new familysite();
    $SQL1 = array();
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $data = dba_fetch($mainkey, $db_con);
        $ARRAY = unserialize($data);
        if ($ARRAY["IPADDR"] == "127.0.0.1") {
            $mainkey = dba_nextkey($db_con);
            continue;
        }
        $zmd5 = md5($data);
        if ($ARRAY["HOSTNAME"] == null) {
            $ARRAY["HOSTNAME"] = $fam->GetComputerName($ARRAY["IPADDR"]);
        }
        $familysite = $fam->GetFamilySites($ARRAY["HOSTNAME"]);
        $SQL1[date("YmdH", $ARRAY["TIME"])][] = "('{$zmd5}','{$ARRAY["DATE"]}','{$ARRAY["HOSTNAME"]}','{$familysite}','{$ARRAY["IPADDR"]}')";
        if ($GLOBALS["VERBOSE"]) {
            echo "('{$zmd5}','{$ARRAY["DATE"]}','{$ARRAY["HOSTNAME"]}','{$familysite}','{$ARRAY["IPADDR"]}')\n";
        }
        $mainkey = dba_nextkey($db_con);
    }
    dba_close($db_con);
    if (count($SQL1) > 0) {
        $q = new mysql_postfix_builder();
        while (list($TIMESTAMP, $rows) = each($SQL1)) {
            $q->postfix_buildhour_connections($TIMESTAMP);
            $sql = "INSERT IGNORE INTO {$TIMESTAMP}_hcnx (`zmd5`,`zDate`,`hostname`,`domain`,`ipaddr`) VALUES " . @implode(",", $rows);
            $q->QUERY_SQL($sql);
            if (!$q->ok) {
                echo $q->mysql_error;
                return false;
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Parsing {$path} END\n";
    }
    return true;
}
function MiltergreyList_month($tablesource, $time)
{
    $q = new mysql_postfix_builder();
    if (date("Y-m-d") == date("Y-m-d", $time)) {
        return false;
    }
    $NextTable = "mgreym_" . date("Ym", $time);
    if ($GLOBALS["VERBOSE"]) {
        echo "Processing {$tablesource} -> {$NextTable}\n";
    }
    if (!$q->milter_BuildMonthTable($NextTable)) {
        return false;
    }
    $database = $q->database;
    $prefix = "INSERT IGNORE INTO {$NextTable}\n\t(zmd5,hits,zday,mailfrom,instancename,mailto,domainfrom,domainto,senderhost,`failed`) VALUES ";
    $sql = "SELECT SUM(hits) as hits,mailfrom,instancename,mailto,domainfrom,domainto,senderhost,failed FROM {$tablesource}\n\tGROUP BY mailfrom,instancename,mailto,domainfrom,domainto,senderhost,failed";
    $results = $q->QUERY_SQL($sql, $database);
    $f = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        $zday = date("Y-m-d", $time);
        $zmd5 = md5(serialize($ligne) . $zday);
        $hits = $ligne["hits"];
        $mailfrom = mysql_escape_string2($ligne["mailfrom"]);
        $instancename = mysql_escape_string2($ligne["instancename"]);
        $mailfrom = mysql_escape_string2($ligne["mailfrom"]);
        $mailto = mysql_escape_string2($ligne["mailto"]);
        $domainfrom = mysql_escape_string2($ligne["domainfrom"]);
        $domainto = mysql_escape_string2($ligne["domainto"]);
        $mailto = mysql_escape_string2($ligne["mailto"]);
        $senderhost = mysql_escape_string2($ligne["senderhost"]);
        $failed = $ligne["failed"];
        $f[] = "('{$zmd5}','{$hits}','{$zday}','{$mailfrom}','{$instancename}','{$mailto}','{$domainfrom}','{$domainto}','{$senderhost}','{$failed}')";
        if (count($f) > 500) {
            $q->QUERY_SQL($prefix . @implode(",", $f), $database);
            if (!$q->ok) {
                return false;
            }
            $f = array();
        }
    }
    if (count($f) > 0) {
        $q->QUERY_SQL($prefix . @implode(",", $f), $database);
        if (!$q->ok) {
            return false;
        }
        $f = array();
    }
    return true;
}
function list_table()
{
    $MyPage = CurrentPageName();
    $page = 1;
    $tpl = new templates();
    $table = date("Ymd") . "_dcnx";
    $q = new mysql_postfix_builder();
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table} no such table");
    }
    $t = $_GET["t"];
    $database = null;
    $FORCE_FILTER = 1;
    if ($q->COUNT_ROWS($table, $database) == 0) {
        json_error_show("No item");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        if (!$q->ok) {
            json_error_show("{$q->mysql_error}");
        }
        $total = $ligne["TCOUNT"];
        if ($total == 0) {
            json_error_show("No rows for {$searchstring}");
        }
    } else {
        $total = $q->COUNT_ROWS($table, $database);
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (!is_numeric($rp)) {
        $rp = 1;
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE {$FORCE_FILTER} {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (!$q->ok) {
        json_error_show("{$q->mysql_error}<hr>{$sql}<hr>");
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (mysql_num_rows($results) == 0) {
        json_error_show("No data...", 1);
    }
    $today = date('Y-m-d');
    $style = "font-size:14px;";
    $unknown = $tpl->_ENGINE_parse_body("{unknown}");
    //Hour | cnx | hostname                                       | domain                    |
    while ($ligne = mysql_fetch_assoc($results)) {
        $md = md5(serialize($ligne));
        $cells = array();
        $cells[] = "<span style='font-size:14px;'>{$ligne["Hour"]}h</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["cnx"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["hostname"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["domain"]}</span>";
        $cells[] = "<span style='font-size:14px;'>{$ligne["ipaddr"]}</span>";
        $data['rows'][] = array('id' => $line["zmd5"], 'cell' => $cells);
    }
    echo json_encode($data);
}
Esempio n. 9
0
function messaging_stats()
{
    $q = new mysql_postfix_builder();
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT DATE_SUB(NOW(),INTERVAL 1 HOUR) as tdate"));
    $currenthour = date("YmdH", strtotime($ligne["tdate"])) . "_hour";
    $timeAffiche = date("H", strtotime($ligne["tdate"]));
    $tpl = new templates();
    $ct = new user($_SESSION["uid"]);
    $mails = $ct->HASH_ALL_MAILS;
    while (list($index, $message) = each($mails)) {
        $q1[] = " (`mailto`='{$message}')";
        $q2[] = " (`mailfrom`='{$message}')";
    }
    $sql = "SELECT COUNT(zmd5) as hits, SUM(mailsize) as size FROM (SELECT zmd5,mailsize from {$currenthour}\n\t WHERE " . @implode("OR", $q1) . ") as t";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    $size = FormatBytes($ligne["size"] / 1024);
    $messages_recieved = $ligne["hits"];
    $f[] = "<strong>{your_messaging_statistics} ({$timeAffiche}h)</strong>:&nbsp;";
    $f[] = "<strong>{$messages_recieved}</strong> {received_messages} ({$size})&nbsp;|&nbsp;";
    $sql = "SELECT COUNT(zmd5) as hits, SUM(mailsize) as size FROM (SELECT zmd5,mailsize from {$currenthour}\n\t WHERE " . @implode("OR", $q2) . ") as t";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    $size = FormatBytes($ligne["size"] / 1024);
    $messages_recieved = $ligne["hits"];
    $f[] = "<strong>{$messages_recieved}</strong> {sended_messages} ({$size})&nbsp;|&nbsp;";
    echo $tpl->_ENGINE_parse_body(@implode("", $f));
}
function greylistm_items()
{
    $month = $_GET["month"];
    $t = $_GET["t"];
    if (!is_numeric($month)) {
        $month = date("Ym");
    }
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_postfix_builder();
    $ct = new user($_SESSION["uid"]);
    $mails = $ct->HASH_ALL_MAILS;
    while (list($index, $message) = each($mails)) {
        $q1[] = " (`mailto`='{$message}')";
    }
    $search = '%';
    $table = "mgreym_{$month}";
    $database = "artica_backup";
    $page = 1;
    $FORCE_FILTER = " AND (" . @implode("OR", $q1) . ")";
    if (!$q->TABLE_EXISTS($table)) {
        json_error_show("{$table}: No such table", 0, true);
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $zmd5 = md5($ligne["filename"]);
        $color = "#D90505";
        $res = strtolower(trim($ligne["failed"]));
        if ($res == "accept") {
            $color = "#00922B";
        }
        $delete = imgsimple("delete-24.png", "", "DeleteFileNameHosting{$t}('{$ligne["filename"]}','{$zmd5}')");
        $ztime = strtotime($ligne["zday"] . " 00:00:00");
        $zday = $tpl->_ENGINE_parse_body(date("{l} d", $ztime));
        $ligne["failed"] = $tpl->_ENGINE_parse_body("{{$ligne["failed"]}}");
        $data['rows'][] = array('id' => "D{$zmd5}", 'cell' => array("<span style='font-size:14px;color:black'>{$zday}</a></span>", "<span style='font-size:14px;color:black'>{$ligne["hits"]}</a></span>", "<span style='font-size:14px;color:black'>{$urljs}{$ligne["mailfrom"]}</a></span>", "<span style='font-size:14px;color:{$color}'>{$urljs}{$ligne["failed"]}</a></span>"));
    }
    echo json_encode($data);
}