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>{mymessaging}</H1>\n\t\t<p>{mymessaging_text}</p>\n\t\t<div id='statistics-{$t}'></div>\n\t</div>\t\n\t<div id='messaging-left'></div>\n\t\n\t<script>\n\t\tLoadAjax('messaging-left','{$page}?messaging-left=yes');\n\t\t{$jsadd}\n\t</script>\n\t"; echo $tpl->_ENGINE_parse_body($html); }
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); }
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); }