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); }
function MiltergreyList_days() { $unix = new unix(); ///etc/artica-postfix/pids/exec.postfix.miltergrey.stats.php.MiltergreyList_days.time $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); @mkdir("/home/artica/postfix/milter-greylist/logger", 0755, true); @chmod("/home/artica/postfix/milter-greylist", 0755, true); @chown("/home/artica/postfix/milter-greylist", "postfix"); @chgrp("/home/artica/postfix/milter-greylist", "postfix"); @chmod("/home/artica/postfix/milter-greylist/logger", 0755, true); @chown("/home/artica/postfix/milter-greylist/logger", "postfix"); @chgrp("/home/artica/postfix/milter-greylist/logger", "postfix"); if ($unix->process_exists($pid, basename(__FILE__))) { $pidTime = $unix->PROCCESS_TIME_MIN($pid); system_admin_events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } if (!$GLOBALS["VERBOSE"]) { if (!$GLOBALS["FORCE"]) { if ($unix->file_time_min($timeFile) < 60) { die; } } } @unlink($timeFile); @file_put_contents($timeFile, time()); @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["FORCE"]) { if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } } $q = new mysql_postfix_builder(); if ($GLOBALS["VERBOSE"]) { echo "Scanning tables...\n"; } $tables = $q->LIST_MILTERGREYLIST_HOUR_TABLES(); $currentHour = date("Y-m-d H"); $tt = 0; if (is_array($tables)) { while (list($tablesource, $time) = each($tables)) { $tt++; if (date("Y", $time) == "1970") { $q->QUERY_SQL("DROP TABLE {$tablesource}"); continue; } if (date("Y-m-d H", $time) == $currentHour) { if ($GLOBALS["VERBOSE"]) { echo "Skipping {$currentHour}\n"; } continue; } if ($GLOBALS["VERBOSE"]) { echo "Processing {$tablesource}: " . date("Y-m-d H", $time) . "[" . __LINE__ . "]\n"; } if (MiltergreyList_scan($tablesource, $time)) { if ($GLOBALS["VERBOSE"]) { echo "DUMP_TABLE {$tablesource}: " . date("Y-m-d H", $time) . "\n"; } if ($q->DUMP_TABLE($tablesource)) { $q->QUERY_SQL("DROP TABLE {$tablesource}"); } } else { if ($GLOBALS["VERBOSE"]) { echo "{$tablesource} failed...\n"; } } if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting task after {$tt} processed tables ", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } } } if (!$GLOBALS["FORCE"]) { if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } } $yesterday = $q->HIER(); $tables = $q->LIST_MILTERGREYLIST_DAY_TABLES(); if (is_array($tables)) { while (list($tablesource, $time) = each($tables)) { if (date("Y-m-d", $time) == date("Y-m-d")) { if ($GLOBALS["VERBOSE"]) { echo "Skipping {$currentHour}\n"; } continue; } if (date("Y-m-d", $time) == $yesterday) { if ($GLOBALS["VERBOSE"]) { echo "Skipping {$currentHour}\n"; } continue; } if ($GLOBALS["VERBOSE"]) { echo "Processing {$tablesource}: " . date("Y-m-d", $time) . "[" . __LINE__ . "]\n"; } if (MiltergreyList_month($tablesource, $time)) { if ($GLOBALS["VERBOSE"]) { echo "DUMP_TABLE {$tablesource}: " . date("Y-m-d H", $time) . "\n"; } if ($q->DUMP_TABLE($tablesource)) { $q->QUERY_SQL("DROP TABLE {$tablesource}"); } } else { if ($GLOBALS["VERBOSE"]) { echo "{$tablesource}: {failed}\n"; } } } } }