function postqueue_master($instance = "MASTER") { $unix = new unix(); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: analyze {$instance}\n"; } $instance_name = $instance; if ($instance == "MASTER") { $instance = null; } else { $instance = "-{$instance}"; } $postqueue = $unix->find_program("postqueue"); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: {$postqueue} -c /etc/postfix{$instance} -p\n"; } exec("{$postqueue} -c /etc/postfix{$instance} -p", $results); $count = count($results); $array["COUNT"] = postqueue_master_count($instance, $results); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: {$array["COUNT"]} message(s)\n"; } if ($count > 900) { $count = 900; } for ($i = 0; $i <= $count; $i++) { $line = $results[$i]; if (preg_match("#([A-Z0-9]+)\\s+([0-9]+)\\s+(.+?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.+?)\$#", $line, $re)) { $MSGID = $re[1]; $size = $re[2]; $day = $re[3]; $dayNum = $re[4]; $time = $re[5]; $from = $re[6]; $array["LIST"][$MSGID]["DATE"] = "{$day} {$dayNum} {$time}"; $array["LIST"][$MSGID]["FROM"] = "{$from}"; continue; } if (preg_match("#^\\((.+?)\\)\$#", trim($line), $re)) { $array["LIST"][$MSGID]["STATUS"] = $re[1]; continue; } if (preg_match("#^\\s+\\s+\\s+(.+?)\$#", $line, $re)) { $array["LIST"][$MSGID]["TO"] = trim($re[1]); continue; } } @file_put_contents("/var/log/artica-postfix/postqueue.{$instance_name}", serialize($array)); }
function postqueue_master($instance = "MASTER") { $unix = new unix(); $NICE = EXEC_NICE(); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: analyze {$instance}\n"; } $instance_name = $instance; if ($instance == "MASTER") { $instance_text = "master"; $instance = null; } else { $instance = "-{$instance}"; $instance_text = $instance; } $postqueue = $unix->find_program("postqueue"); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: {$postqueue} -c /etc/postfix{$instance} -p\n"; } exec("{$NICE}{$postqueue} -c /etc/postfix{$instance} -p", $results); $count = count($results); $array["COUNT"] = postqueue_master_count($instance, $results); if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . ":: {$instance}:: {$array["COUNT"]} message(s)\n"; } $MSGID = null; for ($i = 0; $i <= $count; $i++) { $line = $results[$i]; $active = false; if (preg_match("#([A-Z0-9\\*]+)\\s+([0-9]+)\\s+(.+?)\\s+([0-9]+)\\s+([0-9:]+)\\s+(.+?)\$#", $line, $re)) { $MSGID = $re[1]; if (strpos($MSGID, "*") > 0) { $active = true; } $MSGID = str_replace("*", "", $MSGID); $size = $re[2]; $day = $re[3]; $dayNum = $re[4]; $time = $re[5]; $from = $re[6]; $timestamp = strtotime("{$day} {$dayNum} {$time}"); $date = date('Y-m-d H:i:s', $timestamp); $array["LIST"][$instance_text][$MSGID]["DATE"] = "{$day} {$dayNum} {$time}"; $array["LIST"][$instance_text][$MSGID]["timestamp"] = $date; $array["LIST"][$instance_text][$MSGID]["FROM"] = "{$from}"; $array["LIST"][$instance_text][$MSGID]["msgsize"] = $size; if ($active) { $array["LIST"][$instance_text][$MSGID]["ACTIVE"] = "YES"; } if (preg_match("#(.+?)@(.+)#", $array["LIST"][$instance_text][$MSGID]["FROM"], $re)) { $array["LIST"][$MSGID]["FROM_DOMAIN"] = $re[2]; } continue; } if (preg_match("#^\\((.+?)\\)\$#", trim($line), $re)) { $array["LIST"][$instance_text][$MSGID]["STATUS"] = $re[1]; continue; } if (preg_match("#^\\s+\\s+\\s+(.+?)\$#", $line, $re)) { $array["LIST"][$instance_text][$MSGID]["TO"][] = trim($re[1]); continue; } } $content = serialize($array); $filename = md5($content); if (!is_dir("/var/log/artica-postfix/postqueue")) { @mkdir("/var/log/artica-postfix/postqueue", 755, true); } @file_put_contents("/var/log/artica-postfix/postqueue/{$filename}.array", $content); }