ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); if (isset($argv[1])) { if (!is_file($argv[1])) { echo "Unable to understand {$argv[1]}\n"; die; } $targetfile = $argv[1]; } @mkdir("/home/postfix/logrotate", 0755, true); $q = new mysql(); $hier = $q->HIER(); $targetcompressed = "/home/postfix/logrotate/{$hier}.gz"; $unix = new unix(); if (is_file($targetfile)) { if (!connect_from($targetfile)) { postfix_admin_mysql(0, "FATAL! {$targetfile} connect_from() failed", null, __FILE__, __LINE__); return; } if (!pflogsumm($targetfile)) { postfix_admin_mysql(0, "FATAL! {$targetfile} pflogsumm() failed", null, __FILE__, __LINE__); return; } if (!$unix->compress($targetfile, $targetcompressed)) { @unlink($targetcompressed); return; } @unlink($targetfile); } if (is_file($targetcompressed)) { echo "{$targetcompressed} exists, abort\n";
function compressAndClean() { @unlink("/etc/artica-postfix/POSTFIX_COMPRESS_CLEAN.time"); @file_put_contents("/etc/artica-postfix/POSTFIX_COMPRESS_CLEAN.time", time()); $unix = new unix(); $q = new mysql(); $hier = $q->HIER(); $targetSourceFile = "{$hier}.log"; if (system_is_overloaded(basename(__FILE__))) { postfix_admin_mysql(0, "Overloaded system, aborting rotation compressing", null, __FILE__, __LINE__); return; } $BaseWorkDir = "/home/postfix/logrotate"; $targetcompressed = "/home/postfix/logrotate/{$hier}.gz"; if (!($handle = opendir($BaseWorkDir))) { echo "Failed open {$BaseWorkDir}\n"; return; } while (false !== ($filename = readdir($handle))) { if ($filename == ".") { continue; } if ($filename == "..") { continue; } $targetfile = "{$BaseWorkDir}/{$filename}"; if (strpos($filename, ".gz") > 0) { continue; } if ($filename == $targetSourceFile) { echo "Hier: {$targetSourceFile} was not compressed!\n"; if (is_file($targetfile)) { if (!connect_from($targetfile)) { postfix_admin_mysql(0, "FATAL! {$targetfile} connect_from() failed", null, __FILE__, __LINE__); return; } if (!pflogsumm($targetfile)) { postfix_admin_mysql(0, "FATAL! {$targetfile} pflogsumm() failed", null, __FILE__, __LINE__); return; } if (!$unix->compress($targetfile, $targetcompressed)) { @unlink($targetcompressed); continue; } @unlink($targetfile); } continue; } $ToCompressPath = "{$BaseWorkDir}/{$filename}"; $ToCompressPath = str_replace(".log", ".gz", $ToCompressPath); echo "Compressing {$targetfile} -> {$ToCompressPath}\n"; if (!$unix->compress($targetfile, $ToCompressPath)) { echo "Compressing {$targetfile} -> {$ToCompressPath} - FAILED -\n"; @unlink($ToCompressPath); continue; } else { postfix_admin_mysql(2, "Success compressing {$targetfile}", null, __FILE__, __LINE__); @unlink($targetfile); } } }