function watchdog() { $ini = new Bs_IniHandler("/etc/artica-postfix/smtpnotif.conf"); $PostfixQueueEnabled = $ini->get("SMTP", "PostfixQueueEnabled"); $PostfixQueueMaxMails = $ini->get("SMTP", "PostfixQueueMaxMails"); if ($PostfixQueueEnabled == null) { $PostfixQueueEnabled = 1; } if ($PostfixQueueMaxMails == null) { $PostfixQueueMaxMails = 20; } if ($PostfixQueueEnabled != 1) { return; } $postfix_system = new postfix_system(); $array = $postfix_system->getQueuesNumber(); while (list($num, $val) = each($array)) { $logs[] = "{$num}={$val} message(s)"; if (intval($val) > $PostfixQueueMaxMails) { if (is_file("/etc/artica-postfix/croned.1/postfix.{$num}.exceed")) { if (file_time_min("/etc/artica-postfix/croned.1/postfix.{$num}.exceed") < 30) { continue; } } @file_put_contents("/etc/artica-postfix/croned.1/postfix.{$num}.exceed", "#"); $subject = "Postfix queue {$num} exceed limit"; $text = "The {$num} storage queue contains {$val} messages\nIt exceed the maximum {$PostfixQueueMaxMails} messages number..."; send_email_events($subject, $text, 'system'); } } $logs[] = "{$num}={$val} message(s)"; RTMevents(implode(" ", $logs)); }
function UpdateGeoip() { $database = "/usr/share/GeoIP/GeoIP.dat"; if (!is_file($database)) { RTMevents("Unable to stat /usr/share/GeoIP/GeoIP.dat"); installgeoip(); return null; } if (!is_file("/usr/local/share/GeoIP/GeoIPCity.dat")) { if (is_file("/usr/local/share/GeoIP/GeoLiteCity.dat")) { RTMevents("Linking /usr/local/share/GeoIP/GeoLiteCity.dat"); system('/bin/ln -s /usr/local/share/GeoIP/GeoLiteCity.dat /usr/local/share/GeoIP/GeoIPCity.dat >/dev/null 2>&1'); } } if (!is_file("/usr/share/GeoIP/GeoIPCity.dat")) { if (is_file("/usr/share/GeoIP/GeoLiteCity.dat")) { RTMevents("Linking /usr/share/GeoIP/GeoLiteCity.dat"); system('/bin/ln -s /usr/share/GeoIP/GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat >/dev/null 2>&1'); } } if (!function_exists("geoip_record_by_name")) { RTMevents("Unable to sat geoip_record_by_name() function"); installgeoip(); return null; } $db_info = geoip_database_info(GEOIP_COUNTRY_EDITION); RTMevents("Using {$db_info}"); $q = new mysql(); $sql = "SELECT smtp_sender FROM `smtp_logs` WHERE LENGTH(smtp_sender)>0 AND smtp_sender!='127.0.0.1' AND (Country IS NULL or Country='undefined')"; $results = $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { RTMevents("Wrong sql query {$q->mysql_error}"); return null; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { $smtp_sender = $ligne["smtp_sender"]; if ($_GET["smtp_cache"][$smtp_sender]) { continue; } $record = geoip_record_by_name($smtp_sender); if (!$record) { RTMevents("unable to locate this IP {$smtp_sender}"); $_GET["smtp_cache"][$smtp_sender] = true; continue; } $Country = $record["country_name"]; $_GET["smtp_cache"][$smtp_sender] = true; RTMevents("{$smtp_sender} = {$Country}"); updategeo($smtp_sender, $Country); } }