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 IfFileTime($file, $min = 10) { if (file_time_min($file) > $min) { return true; } return false; }
function CleanArticaUpdateLogs() { foreach (glob("/var/log/artica-postfix/artica-update-*.debug") as $filename) { $file_time_min = file_time_min($filename); if (file_time_min($filename) > 5752) { @unlink($filename); } } }
function fetchtimeout($server, $port, $ip, $buffer) { $file = "/etc/artica-postfix/cron.1/" . md5(__FILE__) . "-" . md5("{$server},{$port},{$ip}"); if (file_time_min($file) < 15) { return null; } send_email_events("fetchmail network error on {$server} {$port}", "fetchmail claim \"{$buffer}\", please set the right server for fetching messages", 'system'); @unlink($file); @file_put_contents("#", $file); }
function launch_tests() { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { return; } if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded, aborting task...", __FUNCTION__, __FILE__, __LINE__, "system"); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__); return; } @file_put_contents($pidfile, getmypid()); $datafile = "/etc/artica-postfix/settings/Daemons/HdparmInfos"; writelogs("Testing hard drives ({$datafile})", __FUNCTION__, __FILE__, __LINE__); $timenum = file_time_min($datafile); if (is_file($datafile)) { if (file_time_min($datafile) < 61) { writelogs("{$timenum}Mn executed, waiting 60Mn", __FUNCTION__, __FILE__, __LINE__); die; } } if ($GLOBALS["FIND_HDPARM"] == null) { writelogs("Unable to stat 'hdparm'", __FUNCTION__, __FILE__, __LINE__); die; } $disks = GetDisks(); if (!is_array($disks)) { return null; } while (list($index, $line) = each($disks)) { unset($results); exec("{$GLOBALS["FIND_HDPARM"]} -t {$index}", $results); while (list($num, $line_result) = each($results)) { if (preg_match("#=\\s+([0-9\\.]+)\\s+MB\\/sec\$#", $line_result, $re)) { if (preg_match("#.+?\\/(.+)\$#", $index, $ri)) { system_admin_events("{$ri[1]}:{$re[1]}MB/sec", __FUNCTION__, __FILE__, __LINE__, "system"); writelogs("testing disk {$ri[1]}:{$re[1]}MB/sec...", __FUNCTION__, __FILE__, __LINE__); $array[$ri[1]] = $re[1]; } } } } @unlink($datafile); @file_put_contents($datafile, base64_encode(serialize($array))); if (!is_file($datafile)) { writelogs("{$datafile} no such file or directory", __FUNCTION__, __FILE__, __LINE__); } }
function launch_tests() { $datafile = "/etc/artica-postfix/settings/Daemons/HdparmInfos"; writelogs("Testing hard drives ({$datafile})", __FUNCTION__, __FILE__, __LINE__); $timenum = file_time_min($datafile); if (is_file($datafile)) { if (file_time_min($datafile) < 60) { writelogs("{$timenum}Mn executed, waiting 60Mn", __FUNCTION__, __FILE__, __LINE__); die; } } if ($GLOBALS["FIND_HDPARM"] == null) { writelogs("Unable to stat 'hdparm'", __FUNCTION__, __FILE__, __LINE__); die; } $disks = GetDisks(); if (!is_array($disks)) { return null; } while (list($index, $line) = each($disks)) { unset($results); exec("{$GLOBALS["FIND_HDPARM"]} -t {$index}", $results); while (list($num, $line_result) = each($results)) { if (preg_match("#=\\s+([0-9\\.]+)\\s+MB\\/sec\$#", $line_result, $re)) { if (preg_match("#.+?\\/(.+)\$#", $index, $ri)) { writelogs("testing disk {$ri[1]}:{$re[1]}MB/sec...", __FUNCTION__, __FILE__, __LINE__); $array[$ri[1]] = $re[1]; } } } } @unlink($datafile); @file_put_contents($datafile, base64_encode(serialize($array))); if (!is_file($datafile)) { writelogs("{$datafile} no such file or directory", __FUNCTION__, __FILE__, __LINE__); } }
function ChecksDNSBL($iptocheck = null, $output = false, $increment = false) { if (trim($iptocheck == "--force")) { $iptocheck = null; $output = false; } $textip = null; if ($iptocheck == null) { $myip = GetMyIp(); } else { $myip = $iptocheck; } if (!preg_match("#[0-9+]\\.[0-9+]\\.[0-9+]\\.[0-9+]#", $myip)) { $textip = " ({$myip}) "; $myip = gethostbyname($myip); if ($GLOBALS["VERBOSE"]) { echo "Checking {$myip}...........: was{$textip}\n"; } } $sock = new sockets(); $unix = new unix(); $RBLCheckFrequency = $sock->GET_INFO("RBLCheckFrequency"); $RBLCheckNotification = $sock->GET_INFO("RBLCheckNotification"); if (!is_numeric($RBLCheckFrequency)) { $RBLCheckFrequency = 60; } if (!is_numeric($RBLCheckNotification)) { $RBLCheckNotification = 0; } if ($GLOBALS["VERBOSE"]) { echo "Checking {$myip}{$textip}...........: RBLCheckFrequency...: {$RBLCheckFrequency}\n"; echo "Checking {$myip}{$textip}...........: RBLCheckNotification: {$RBLCheckNotification}\n"; } if (!$GLOBALS["FORCE"]) { $md = md5($myip); $timefile = "/etc/artica-postfix/cron.1/ChecksDNSBL.{$md}.time"; if (!$GLOBALS["VERBOSE"]) { $time = file_time_min($timefile); if ($time < $RBLCheckFrequency) { echo @file_get_contents($timefile); return; } } @unlink($timefile); @file_put_contents($timefile, "#"); } include_once 'Net/DNSBL.php'; $dnsbl = new Net_DNSBL(); if (!isset($GLOBALS["DDNS"])) { $sql = "SELECT * FROM rbl_servers WHERE enabled=1 ORDER BY `rbl`"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); if ($q->ok) { while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $GLOBALS["DDNS"][] = $ligne["rbl"]; } } } if (count($GLOBALS["DDNS"]) == 0) { $GLOBALS["DDNS"][] = "b.barracudacentral.org"; $GLOBALS["DDNS"][] = "bl.deadbeef.com"; $GLOBALS["DDNS"][] = "bl.emailbasura.org"; $GLOBALS["DDNS"][] = "bl.spamcannibal.org"; $GLOBALS["DDNS"][] = "bl.spamcop.net"; //$dnss[]="blackholes.five-ten-sg.com"; $GLOBALS["DDNS"][] = "blacklist.woody.ch"; $GLOBALS["DDNS"][] = "bogons.cymru.com"; $GLOBALS["DDNS"][] = "cbl.abuseat.org"; $GLOBALS["DDNS"][] = "cdl.anti-spam.org.cn"; $GLOBALS["DDNS"][] = "combined.abuse.ch"; $GLOBALS["DDNS"][] = "combined.rbl.msrbl.net"; $GLOBALS["DDNS"][] = "db.wpbl.info"; $GLOBALS["DDNS"][] = "dnsbl-1.uceprotect.net"; $GLOBALS["DDNS"][] = "dnsbl-2.uceprotect.net"; $GLOBALS["DDNS"][] = "dnsbl-3.uceprotect.net"; $GLOBALS["DDNS"][] = "dnsbl.ahbl.org"; $GLOBALS["DDNS"][] = "dnsbl.cyberlogic.net"; $GLOBALS["DDNS"][] = "dnsbl.inps.de"; $GLOBALS["DDNS"][] = "dnsbl.njabl.org"; $GLOBALS["DDNS"][] = "dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "drone.abuse.ch"; $GLOBALS["DDNS"][] = "drone.abuse.ch"; $GLOBALS["DDNS"][] = "duinv.aupads.org"; $GLOBALS["DDNS"][] = "dul.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "dul.ru"; $GLOBALS["DDNS"][] = "dyna.spamrats.com"; $GLOBALS["DDNS"][] = "dynip.rothen.com"; $GLOBALS["DDNS"][] = "fl.chickenboner.biz"; $GLOBALS["DDNS"][] = "http.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "images.rbl.msrbl.net"; $GLOBALS["DDNS"][] = "ips.backscatterer.org"; $GLOBALS["DDNS"][] = "ix.dnsbl.manitu.net"; $GLOBALS["DDNS"][] = "korea.services.net"; $GLOBALS["DDNS"][] = "misc.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "noptr.spamrats.com"; $GLOBALS["DDNS"][] = "ohps.dnsbl.net.au"; $GLOBALS["DDNS"][] = "omrs.dnsbl.net.au"; $GLOBALS["DDNS"][] = "orvedb.aupads.org"; $GLOBALS["DDNS"][] = "osps.dnsbl.net.au"; $GLOBALS["DDNS"][] = "osrs.dnsbl.net.au"; $GLOBALS["DDNS"][] = "owfs.dnsbl.net.au"; $GLOBALS["DDNS"][] = "owps.dnsbl.net.au"; $GLOBALS["DDNS"][] = "pbl.spamhaus.org"; $GLOBALS["DDNS"][] = "phishing.rbl.msrbl.net"; $GLOBALS["DDNS"][] = "probes.dnsbl.net.au"; $GLOBALS["DDNS"][] = "proxy.bl.gweep.ca"; $GLOBALS["DDNS"][] = "proxy.block.transip.nl"; $GLOBALS["DDNS"][] = "psbl.surriel.com"; $GLOBALS["DDNS"][] = "rbl.interserver.net"; $GLOBALS["DDNS"][] = "rdts.dnsbl.net.au"; $GLOBALS["DDNS"][] = "relays.bl.gweep.ca"; $GLOBALS["DDNS"][] = "relays.bl.kundenserver.de"; $GLOBALS["DDNS"][] = "relays.nether.net"; $GLOBALS["DDNS"][] = "residential.block.transip.nl"; $GLOBALS["DDNS"][] = "ricn.dnsbl.net.au"; $GLOBALS["DDNS"][] = "rmst.dnsbl.net.au"; $GLOBALS["DDNS"][] = "sbl.spamhaus.org"; $GLOBALS["DDNS"][] = "short.rbl.jp"; $GLOBALS["DDNS"][] = "smtp.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "socks.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "spam.abuse.ch"; $GLOBALS["DDNS"][] = "spam.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "spam.rbl.msrbl.net"; $GLOBALS["DDNS"][] = "spam.spamrats.com"; $GLOBALS["DDNS"][] = "spamlist.or.kr"; $GLOBALS["DDNS"][] = "spamrbl.imp.ch"; $GLOBALS["DDNS"][] = "t3direct.dnsbl.net.au"; $GLOBALS["DDNS"][] = "tor.ahbl.org"; $GLOBALS["DDNS"][] = "tor.dnsbl.sectoor.de"; $GLOBALS["DDNS"][] = "torserver.tor.dnsbl.sectoor.de"; $GLOBALS["DDNS"][] = "ubl.lashback.com"; $GLOBALS["DDNS"][] = "ubl.unsubscore.com"; $GLOBALS["DDNS"][] = "virbl.bit.nl"; $GLOBALS["DDNS"][] = "virus.rbl.jp"; $GLOBALS["DDNS"][] = "virus.rbl.msrbl.net"; $GLOBALS["DDNS"][] = "web.dnsbl.sorbs.net"; $GLOBALS["DDNS"][] = "wormrbl.imp.ch"; $GLOBALS["DDNS"][] = "xbl.spamhaus.org"; $GLOBALS["DDNS"][] = "zen.spamhaus.org"; $GLOBALS["DDNS"][] = "zombie.dnsbl.sorbs.net"; } if ($GLOBALS["VERBOSE"]) { echo "Checking {$myip}{$textip}...........: checking............: " . count($GLOBALS["DDNS"]) . " rbls servers\n"; echo "Checking {$myip}{$textip}...........: Output..............: {$output}\n"; } if ($GLOBALS["VERBOSE"]) { echo "checking " . count($GLOBALS["DDNS"]) . " rbls servers\n"; } if ($GLOBALS["VERBOSE"]) { echo "Checking {$myip}...........: ->setBlacklists();\n"; } reset($GLOBALS["DDNS"]); $dnsbl->setBlacklists($GLOBALS["DDNS"]); if (!$output) { if (!$increment) { if ($GLOBALS["VERBOSE"]) { echo "Delete /usr/share/artica-postfix/ressources/logs/web/blacklisted.html\n"; } @unlink("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html"); } } if ($output) { if ($dnsbl->isListed($myip)) { $blacklist = $dnsbl->getListingBl($myip); $detail = $dnsbl->getDetails($myip); $final = "{$blacklist};{$detail["txt"][0]}"; @file_put_contents($timefile, $final); echo $final; } return; } $date = date('l F H:i'); if ($GLOBALS["VERBOSE"]) { echo "Checking {$myip}{$textip}...........: Output..............: {$date}\n"; } if (!$increment) { @unlink("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html"); @unlink("/usr/share/artica-postfix/ressources/logs/web/Notblacklisted.html"); } if ($dnsbl->isListed($myip)) { $blacklist = $dnsbl->getListingBl($myip); if ($RBLCheckNotification == 1) { $unix->send_email_events("Your server ({$myip}{$textip}) is blacklisted from {$blacklist}", "This is the result of checking your server from " . count($GLOBALS["DDNS"]) . " black list servers.\n It seems your server (ip:{$myip}{$textip}) is blacklisted from {$blacklist}\n If you trying to send mails from this server, it should be rejected from many SMTP servers that use \"{$blacklist}\" for check senders IP addresses.\n ", "postfix"); } echo "{$myip}: blacklisted from {$blacklist} write \"/usr/share/artica-postfix/ressources/logs/web/blacklisted.html\"\n"; $p = Paragraphe('danger64.png', "{WARN_BLACKLISTED}", "{$myip}{$textip} {IS_BLACKLISTED_FROM} {$blacklist} ({$date})", "javascript:Loadjs('system.rbl.check.php')", "{$myip} {IS_BLACKLISTED_FROM} {$blacklist}", 300, 80); if ($increment) { $p = @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html") . $p; } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html", $p); shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/web/blacklisted.html >/dev/null 2>&1"); return; } else { if ($GLOBALS["VERBOSE"]) { echo "checking " . count($GLOBALS["DDNS"]) . " rbls servers success\n"; } } $dnsbl = new Net_DNSBL(); reset($GLOBALS["DDNS"]); $dnsbl->setBlacklists($GLOBALS["DDNS"]); if ($dnsbl->isListed($myip)) { $blacklist = $dnsbl->getListingBl($myip); if ($RBLCheckNotification == 1) { send_email_events("Your server ({$myip}{$textip}) is blacklisted from {$blacklist}", "This is the result of checking your server from " . count($GLOBALS["DDNS"]) . " black list servers.\n\t It seems your server (ip:{$myip}{$textip}) is blacklisted from {$blacklist}\n\t If you trying to send mails from this server, it should be rejected from many SMTP servers that use \"{$blacklist}\" for check senders IP addresses.\n\t ", "postfix"); } echo "{$myip}{$textip}: blacklisted from {$blacklist} write \"/usr/share/artica-postfix/ressources/logs/web/blacklisted.html\"\n"; $p = Paragraphe('danger64.png', "{WARN_BLACKLISTED}", "{$myip}{$textip} {IS_BLACKLISTED_FROM} {$blacklist} ({$date})", "javascript:Loadjs('system.rbl.check.php')", "{$myip}{$textip} {IS_BLACKLISTED_FROM} {$blacklist}", 300, 80); if ($increment) { $p = @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html") . $p; } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/blacklisted.html", $p); shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/web/blacklisted.html >/dev/null 2>&1"); return; } else { if ($GLOBALS["VERBOSE"]) { echo "checking " . count($GLOBALS["DDNS"]) . " rbls servers success\n"; } } $p = Paragraphe('ok64.png', "{NOT_BLACKLISTED}", "{$myip}{$textip} {IS_NOT_BLACKLISTED } ({$date})", "javascript:Loadjs('system.rbl.check.php')", null, 300, 80); if ($increment) { $p = @file_get_contents("/usr/share/artica-postfix/ressources/logs/web/Notblacklisted.html") . $p; } @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/Notblacklisted.html", $p); shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/web/Notblacklisted.html >/dev/null 2>&1"); }
$GLOBALS["FORCE"] = true; } if ($argv[1] == "--chassis") { if (!$GLOBALS["FORCE"]) { if (is_file("/etc/artica-postfix/dmidecode.cache")) { $datas = @file_get_contents("/etc/artica-postfix/dmidecode.cache"); $newdatas = urlencode(base64_encode($datas)); @file_put_contents("/etc/artica-postfix/dmidecode.cache.url", $newdatas); die; } } } $cache_file = "/etc/artica-postfix/dmidecode.cache"; if (!$GLOBALS["VERBOSE"]) { if (is_file($cache_file)) { $mem = file_time_min($cache_file); if ($mem < 240) { return null; } } } $unix = new unix(); $dmidecode = $unix->find_program("dmidecode"); $virtwhat = $unix->find_program("virt-what"); if (is_file($dmidecode)) { exec("{$dmidecode} --type 1 2>&1", $results); while (list($index, $line) = each($results)) { if (preg_match("#Manufacturer:\\s+(.+)#", $line, $re)) { $Manufacturer = $re[1]; } if (preg_match("#Product Name:\\s+(.+)#", $line, $re)) {
function IfFileTime($file,$min=10){ $time=file_time_min($file); events("$file = {$time}Mn Max:$min"); if($time>$min){return true;} return false; }
function Global_Applications_Status() { if (isset($_GET["status-forced"])) { sys_THREAD_COMMAND_SET('/usr/share/artica-postfix/bin/artica-install --generate-status --forced'); return; } if (!is_file('/usr/share/artica-postfix/ressources/logs/global.versions.conf')) { sys_exec('/usr/share/artica-postfix/bin/artica-install -versions > /usr/share/artica-postfix/ressources/logs/global.versions.conf 2>&1'); } if (!is_file('/usr/share/artica-postfix/ressources/logs/global.status.ini')) { sys_exec('/usr/share/artica-postfix/bin/artica-install --status > /usr/share/artica-postfix/ressources/logs/global.status.ini 2>&1'); } $datas = @file_get_contents('/usr/share/artica-postfix/ressources/logs/global.status.ini'); $datas2 = @file_get_contents('/usr/share/artica-postfix/ressources/logs/global.versions.conf'); if (file_time_min('/usr/share/artica-postfix/ressources/logs/global.status.ini') > 10) { @unlink('/usr/share/artica-postfix/ressources/logs/global.status.ini'); @unlink('/usr/share/artica-postfix/ressources/logs/global.versions.conf'); sys_THREAD_COMMAND_SET('/usr/share/artica-postfix/bin/artica-install --write-versions'); sys_THREAD_COMMAND_SET('/usr/share/artica-postfix/bin/artica-install --generate-status'); } $unix = new unix(); $tmp = $unix->FILE_TEMP(); exec("/bin/chmod 755 /usr/share/artica-postfix/ressources/logs/global.* >{$tmp} 2>&1"); @unlink($tmp); writelogs_framework("datas=" . strlen($datas) . " bytes datas2=" . strlen($datas) . " bytes", __FUNCTION__, __FILE__, __LINE__); echo "<articadatascgi>" . base64_encode("{$datas}\n{$datas2}") . "</articadatascgi>"; }
function ParseLastEvents() { $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $timeF = file_time_min($timefile); if ($timeF < 240) { if ($GLOBALS["VERBOSE"]) { echo "{$timeF} minutes, need to wait 240\n"; } return; } @file_put_contents($timefile, "#"); $unix = new unix(); $iptables = $unix->find_program("iptables"); if ($GLOBALS["VERBOSE"]) { echo "Loading Whitelist\n"; } $whitelist = load_whitelist(); if ($GLOBALS["VERBOSE"]) { echo "Loading Whitelist " . count($whitelist) . " items\n"; } $sock = new sockets(); $PostfixInstantIptablesLastDays = $sock->GET_INFO("PostfixInstantIptablesLastDays"); $PostfixInstantIptablesMaxEvents = $sock->GET_INFO("PostfixInstantIptablesMaxEvents"); if (!is_numeric($PostfixInstantIptablesLastDays)) { $PostfixInstantIptablesLastDays = 7; } if (!is_numeric($PostfixInstantIptablesMaxEvents)) { $PostfixInstantIptablesMaxEvents = 50; } $sql = "SELECT COUNT(ipaddr) as tcount,ipaddr,smtp_err,hostname \n\tFROM mail_con_err_stats WHERE zDate<DATE_SUB(NOW(),INTERVAL 1 DAY) \n\tAND zDate>=DATE_SUB(NOW(),INTERVAL {$PostfixInstantIptablesLastDays} DAY) \n\tGROUP BY ipaddr,smtp_err,hostname ORDER BY COUNT(ipaddr) DESC"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); $newarray = array(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $count_events = $ligne["tcount"]; if ($count_events < 3) { break; } $ipaddr = $ligne["ipaddr"]; $error = $ligne["smtp_err"]; $server_name = $ligne["hostname"]; if ($whitelist[$server_name]) { echo "Whitelisted {$server_name}\n"; continue; } if ($whitelist[$ipaddr]) { echo "Whitelisted {$ipaddr}\n"; continue; } $newarray[$ipaddr]["HOST"] = $server_name; $newarray[$ipaddr]["EVENTS_TEXT"][] = "{$server_name} [{$ipaddr}] - {$count_events} {$error}"; if (isset($newarray[$ipaddr])) { $newarray[$ipaddr]["EVENTS"] = $newarray[$ipaddr]["EVENTS"] + $count_events; } else { $newarray[$ipaddr]["EVENTS"] = $newarray[$ipaddr]["EVENTS"]; } } if (!is_array($newarray)) { return; } $newarray2 = $newarray; while (list($ipaddr, $ligne) = each($newarray)) { $count = $ligne["EVENTS"]; if ($count < $PostfixInstantIptablesMaxEvents) { unset($newarray2[$ipaddr]); //if($GLOBALS["VERBOSE"]){echo "skipping $ipaddr {$ligne["HOST"]} $count events\n";} continue; } } if ($GLOBALS["VERBOSE"]) { echo count($newarray2) . " items -> Array:newarray2\n"; } if (count($newarray2) == 0) { return; } $ipCount = 0; while (list($ipaddr, $ipaddrARR) = each($newarray2)) { $sql = "SELECT rulemd5 FROM iptables WHERE serverip='{$ipaddr}' AND local_port='25'"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup")); if ($ligne["rulemd5"] != null) { if ($GLOBALS["VERBOSE"]) { echo "Skip {$ipaddr} already added\n"; } continue; } $EVENTS = "{$ipaddrARR["EVENTS"]} refused connexions:\n" . @implode("\n", $ipaddrARR["EVENTS_TEXT"]); $cmd = "{$iptables} -A INPUT -s {$ipaddr} -p tcp --destination-port 25 -j DROP -m comment --comment \"ArticaInstantPostfix\""; $iptablesClass = new iptables_chains(); $iptablesClass->serverip = $ipaddr; $iptablesClass->servername = $server_name; $iptablesClass->rule_string = $cmd; $iptablesClass->EventsToAdd = $EVENTS; if (!$iptablesClass->addPostfix_chain()) { $FAILED = "FAILED TO add {$ipaddr} "; } $notifs[] = $EVENTS; shell_exec($cmd); if ($GLOBALS["VERBOSE"]) { echo $cmd . "\n"; } $ipCount++; } if ($ipCount > 0) { $unix->send_email_events("Instant Iptables {$ipCount} addresse(s) added", "Calculation since {$PostfixInstantIptablesLastDays} days and for {$PostfixInstantIptablesMaxEvents} minimal blocks events\n" . @implode("\n", $notifs), "postfix"); } }
function net_ads_info() { if ($_GET["reconnect"] == "yes") { shell_exec(LOCATE_PHP5_BIN2() . " /usr/share/artica-postfix/exec.samba.php --ads"); } $cachefile = "/etc/artica-postfix/NetADSInfo.cache"; $cachefilesize = filesize($cachefile); writelogs_framework("{$cachefile} {$cachefilesize}", __FUNCTION__, __FILE__, __LINE__); if (is_file("/etc/artica-postfix/NetADSInfo.cache")) { $filetime = file_time_min($cachefile); if ($filetime < 30) { writelogs_framework("{$cachefile} {$filetime}Mn", __FUNCTION__, __FILE__, __LINE__); $results = explode("\n", @file_get_contents($cachefile)); } } writelogs_framework("results= " . count($results) . " rows", __FUNCTION__, __FILE__, __LINE__); if (!is_array($results)) { $unix = new unix(); $net = $unix->LOCATE_NET_BIN_PATH(); if (!is_file($net)) { $unix->send_email_events("Unable to locate net binary !!", "", "system"); return; } writelogs_framework("{$net} ads info 2>&1", __FUNCTION__, __FILE__, __LINE__); exec("{$net} ads info 2>&1", $results); @file_put_contents($cachefile, @implode("\n", $results)); } while (list($index, $line) = each($results)) { if (preg_match("#^(.+?):(.+)#", trim($line), $re)) { writelogs_framework(trim($re[1]) . "=" . trim($re[2]), __FUNCTION__, __FILE__, __LINE__); $array[trim($re[1])] = trim($re[2]); } } echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>"; }
function loadavg_old(){ $unix=new unix(); @mkdir("/etc/artica-postfix/croned.1",0666,true); $unix=new unix(); $pidfile="/etc/artica-postfix/".basename(__FILE__).".".__FUNCTION__.".pid"; $pid=trim(@file_get_contents($pidfile)); if($unix->process_exists($pid)){die();} $pid=getmypid(); @file_put_contents($pidfile,$pid); $timefile="/etc/artica-postfix/croned.1/".basename(__FILE__).__FUNCTION__; if(file_time_min($timefile)<15){return null;} @unlink($timefile); @file_put_contents($timefile,"#"); $array_load=sys_getloadavg(); $internal_load=$array_load[0]; $datas=loadavg_table(); if($GLOBALS["VERBOSE"]){echo strlen($datas)." bytes body text\n";} $unix->send_email_events("System Load - $internal_load - exceed rule ",$datas,"system"); checkProcess1(); }
function ActiveDirectorySync() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $cache_file = "/etc/artica-postfix/pids/mailboxes.sync.ad.cache"; $sock = new sockets(); $unix = new unix(); $users = new usersMenus(); if (!$users->cyrus_imapd_installed) { echo "Sync client:: Cyrus-imapd is not installed\n"; return; } $CyrusToAD = $sock->GET_INFO("CyrusToAD"); if (!is_numeric($CyrusToAD)) { echo "Sync client:: Connexion to Active Directory is not enabled\n"; return; } if ($CyrusToAD == 0) { echo "Sync client:: Connexion to Active Directory is not enabled\n"; return; } $oldpid = @file_get_contents($pidfile); if ($unix->process_exists($oldpid)) { echo "Sync client:: Already {$oldpid} process executed\n"; return; } @file_put_contents($pidfile, getmypid()); $CyrusToADSyncTime = $sock->GET_INFO("CyrusToADSyncTime"); if (!is_numeric($CyrusToADSyncTime)) { $CyrusToADSyncTime = 10; } if ($CyrusToADSyncTime < 3) { $CyrusToADSyncTime = 3; } if (!$GLOBALS["FORCE"]) { $time = file_time_min($cache_file); if ($time < $CyrusToADSyncTime) { echo "Sync client:: {$time}Mn, need {$CyrusToADSyncTime}Mn, aborting\n"; return; } } @unlink($cache_file); $ldap = new clladp(); $hashUsers = $ldap->Hash_GetALLUsers(); if (!is_array($hashUsers)) { echo "Sync client:: no users\n"; } $failed = 0; while (list($uid, $emailaddr) = each($hashUsers)) { if ($emailaddr == null) { echo "Sync client:: {$uid} skip (no email address set)\n"; continue; } $cyrus = new cyrus(); if ($cyrus->MailBoxExists($uid)) { echo "Sync client:: {$uid} Mailbox already exists\n"; continue; } echo "Sync client:: {$uid} Creating mailbox\n"; if ($cyrus->CreateMailbox($uid)) { $array[$uid] = "OK"; } else { $array[$uid] = "Failed"; $failed++; } } if (count($array) > 0) { while (list($uid, $rr) = each($array)) { $result[] = "{$uid}:{$rr}"; } $unix = new unix(); if ($failed > 0) { $failed_text = " {$failed} failed"; } $unix->send_email_events(count($array) . " new created mailboxes {$failed_text} ", @implode("\n", $result), "mailboxes"); } }
function Group2() { $fileTime = "/etc/artica-postfix/cron.2/executor." . __FUNCTION__; if (file_time_min($fileTime) < 2) { return; } $array[] = "exec.dhcpd-leases.php"; $array[] = "exec.mailbackup.php"; if ($GLOBALS["DANSGUARDIAN_INSTALLED"]) { $array[] = "exec.dansguardian.injector.php"; } if (is_array($array)) { while (list($index, $file) = each($array)) { $cmd = "{$_GET["PHP5"]} /usr/share/artica-postfix/{$file}"; sys_THREAD_COMMAND_SET($cmd); } } if (is_array($array2)) { while (list($index, $file) = each($array2)) { $cmd = "/usr/share/artica-postfix/bin/{$file}"; sys_THREAD_COMMAND_SET($cmd); } } @unlink($fileTime); @file_put_contents($fileTime, "#"); }
function find($pattern) { $SEARCH["PATTERN"] = $pattern; $md5Pattern = md5($pattern); $pattern = str_replace(".", "\\.", $pattern); $pattern = str_replace("*", ".+?", $pattern); $MONTHS = array("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12); $POSTIDS = array(); $unix = new unix(); $sock = new sockets(); $BackupMailLogPath = $sock->GET_INFO("BackupMailLogPath"); if ($BackupMailLogPath == null) { $BackupMailLogPath = "/home/logrotate_backup"; } if ($GLOBALS["VERBOSE"]) { echo "BackupMailLogPath={$BackupMailLogPath}\n"; } $filecache = "{$BackupMailLogPath}/{$md5Pattern}.search"; $sql = "UPDATE postfinder SET finish=-1 WHERE `md5`='{$md5Pattern}'"; $q = new mysql(); $q->QUERY_SQL($sql, 'artica_events'); if (!$q->ok) { echo $q->mysql_error; } $grep = $unix->find_program("grep"); $cmd = "{$grep} -E \"{$pattern}\" {$BackupMailLogPath}/*.log 2>&1 >{$filecache}"; if (!is_file($filecache)) { if ($GLOBALS["VERBOSE"]) { echo "{$filecache} no such file -> {$cmd} \n"; } shell_exec($cmd); } else { $timefile = file_time_min($filecache); if ($timefile > 10) { shell_exec($cmd); } } $DATES = array(); $handle = @fopen("{$filecache}", "r"); // Open file form read. if ($handle) { while (!feof($handle)) { $ligne = fgets($handle, 4096); if (preg_match("#:([A-Za-z]+)\\s+([0-9]+)\\s+([0-9:]+)\\s+.+?\\[[0-9]+\\]:\\s+([0-9A-Z]+):#", $ligne, $re)) { $month = $MONTHS[$re[1]]; if (strpos($ligne, "KASINFO") > 0) { continue; } if (strlen($month) == 1) { $month = "0{$month}"; } $year = date('Y'); if (strlen($re[2])) { $re[2] = "0{$re['2']}"; } $date = "{$year}-{$month}-{$re[2]} {$re[3]}"; $time = strtotime($date); $postid = $re[4]; if ($postid == "NOQUEUE") { if ($GLOBALS["VERBOSE"]) { echo "{$ligne} skip\n"; } $POSTIDS[$time][md5($ligne)][] = $ligne; continue; } $DATES[$time] = $postid; } } } else { if ($GLOBALS["VERBOSE"]) { echo "{$filecache} unable to read\n"; } } if (count($DATES) > 0) { krsort($DATES); while (list($time, $msg_id) = each($DATES)) { $results = array(); $cmd = "{$grep} -h \"{$msg_id}\" {$BackupMailLogPath}/*.log 2>&1"; exec($cmd, $results); $POSTIDS[$time][$msg_id] = $results; } } $cc = 0; while (list($time, $msg_id) = each($POSTIDS)) { $cc++; } reset($POSTIDS); krsort($POSTIDS); $finals = addslashes(serialize($POSTIDS)); $now = date('Y-m-d H:i:s'); $sql = "UPDATE postfinder SET finish=1, date_end='{$now}', search_datas='{$finals}',msg_num={$cc} WHERE `md5`='{$md5Pattern}'"; $q = new mysql(); $q->QUERY_SQL($sql, 'artica_events'); if (!$q->ok) { echo $q->mysql_error; } }
include_once(dirname(__FILE__).'/ressources/class.users.menus.inc'); $GLOBALS["ADDLOG"]="/var/log/artica-postfix/".basename(__FILE__).".log"; $users=new usersMenus(); if(!$users->SQUID_INSTALLED){die();} $file="/usr/share/artica-postfix/ressources/databases/UserAgents.txt"; if(!is_file($file)){die();} $pidfile="/etc/artica-postfix/".basename(__FILE__).".pid"; $unix=new unix(); if($unix->process_exists(trim(@file_get_contents($pidfile)))){ writelogs("Another instance ". @file_get_contents($pidfile). " Exists... abort","MAIN",__FILE__,__LINE__); die(); } $pid=getmypid(); @file_put_contents($pidfile,$pid); $time=file_time_min("/etc/artica-postfix/UserAgents.cache"); if($time<10080){die();} $f=@file_get_contents($file); $md5=md5($f); $oldMd5=md5(trim(@file_get_contents("/etc/artica-postfix/UserAgents.cache"))); writelogs("$md5 == $oldMd5","MAIN",__FILE__,__LINE__); if($md5==$oldMd5){ writelogs("No changes","MAIN",__FILE__,__LINE__); die(); } @file_put_contents("/etc/artica-postfix/UserAgents.cache","$md5"); $q=new mysql();
function DeleteMysqlError() { foreach (glob("{$GLOBALS["ARTICALOGDIR"]}/mysql-error.*.err") as $filename) { if (file_time_min($filename) > 5) { @unlink($filename); } } }
function export_dns() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $oldpid = @file_get_contents($pidfile); if ($unix->process_exists($oldpid)) { $ptime = $unix->PROCESS_TTL($oldpid); if ($ptime > $GLOBALS["MAXTTL"]) { events("export_dns():: killing process {$oldpid} ttl:{$ptime} minutes"); shell_exec("/bin/kill -9 {$oldpid}"); } else { events("export_dns():: already executed, process {$oldpid}"); die; } } $time = file_time_min($pidfile); events("{$pidfile}={$time}Mn", __FUNCTION__, __FILE__, __LINE__); if ($time == 0) { events("Cannot replicate DNS before one minute...", __FUNCTION__, __FILE__, __LINE__); return; } @file_put_contents($pidfile, getmypid()); $ldap = new clladp(); $http = new httpget(); $sock = new sockets(); $meta = new artica_meta(); $pattern = "(&(objectclass=*)(arecord=*))"; $sr = ldap_search($ldap->ldap_connection, "ou=dns,{$ldap->suffix}", $pattern, array()); $cachefile = "/etc/artica-postfix/dns.cache"; if ($sr) { $hash = ldap_get_entries($ldap->ldap_connection, $sr); for ($i = 0; $i < $hash["count"]; $i++) { $macrecord = $hash[$i]["macrecord"][0]; $arecord = $hash[$i]["arecord"][0]; if ($arecord == "127.0.0.1") { continue; } if ($arecord == null) { continue; } echo "{$macrecord} {$arecord}\n"; $array[$arecord] = array("MAC" => $macrecord, "NAMES" => $hash[$i]["associateddomain"]); $arecord = null; $macrecord = null; } } else { events("LDAP link failed", __FUNCTION__, __FILE__, __LINE__); return; } if (!is_array($array)) { return; } @file_put_contents($cachefile, base64_encode(serialize($array))); $http->uploads["DNS_COMPUTERS"] = $cachefile; $body = $http->send("{$meta->ArticaMetaHostname}/lic.users.import.php", "post", array("DATAS" => base64_encode(serialize($meta->GLOBAL_ARRAY)))); if (!preg_match("#<RESULTS>OK</RESULTS>#is", $body)) { events(count($array) . " DNS failed to be exported to global Management console", __FUNCTION__, __FILE__, __LINE__); return; } else { events(count($array) . " DNS exported to global Management console", __FUNCTION__, __FILE__, __LINE__); send_email_events(count($array) . " DNS exported to global Management console", null, "CLOUD"); @unlink($cachefile); } }
function smbtree(){ $unix=new unix(); $timefile="/etc/artica-postfix/smbtree.cache"; $smbtree=$unix->find_program("smbtree"); if(!is_file($smbtree)){return;} $time=file_time_min($timefile); if($time>5){ exec("$smbtree -N 2>&1",$results); @file_put_contents($timefile,serialize($results)); } $results=unserialize(@file_get_contents($timefile)); $final=array(); while (list ($index, $ligne) = each ($results)){ $ligne=trim($ligne); if($GLOBALS["VERBOSE"]){echo "check \"$ligne\"\n";} if(preg_match("#^([A-Za-z0-9\_\-]+)$#",$ligne,$re)){ if($GLOBALS["VERBOSE"]){echo "Found DOMAIN {$re[1]}\n";} $DOMAIN=$re[1]; continue; } $tr=explode('\\',$ligne); if(count($tr)>0){ unset($tr[0]); unset($tr[1]); if(count($tr)>1){ $final[$DOMAIN][$tr[2]]["IP"]=nmblookup($tr[2],null); $final[$DOMAIN][$tr[2]]["SHARES"][]=$tr[3]; } } } @file_put_contents("/usr/share/artica-postfix/ressources/logs/smbtree.array",serialize($final)); shell_exec("/bin/chmod 777 /usr/share/artica-postfix/ressources/logs/smbtree.array"); }
function Parseline($buffer) { $buffer = trim($buffer); if ($buffer == null) { return null; } if (dustbin($buffer)) { return null; } if (!isset($GLOBALS["CHMOD"])) { $unix = new unix(); $GLOBALS["CHMOD"] = $unix->find_program("chmod"); } if ($GLOBALS["VERBOSE"]) { events(" - > " . __LINE__); } if (count($GLOBALS["DNSISSUES"]) > 1) { $curdate = date("YmdHi"); $curcount = count($GLOBALS["DNSISSUES"][$curdate]); unset($GLOBALS["DNSISSUES"]); $GLOBALS["DNSISSUES"][$curdate] = $curcount; } $GLOBALS["COUNTLINES"]++; if ($GLOBALS["COUNTLINES"] > 20) { @unlink("/etc/artica-postfix/pids/squid-cache-logs.time"); @file_put_contents("/etc/artica-postfix/pids/squid-cache-logs.time", time()); $GLOBALS["COUNTLINES"] = 0; } if (preg_match("#FD [0-9]+ Closing HTTP connection#", $buffer)) { return; } if (preg_match("#temporary disabling.*?digest from#", $buffer)) { return; } if (preg_match("#kid[0-9]+\\| .*?\\/[0-9]+ exists#", $buffer)) { return; } //******************************************************************************************************************* if (preg_match("#logfileHandleWrite:.*?error(.+)#", $buffer, $re)) { squid_admin_mysql(1, "Artica logger issue {$re[1]} [action=warn]", $buffer, __FILE__, __LINE__); return; } //******************************************************************************************************************* if (preg_match("#FATAL: Cannot open SNMP receiving Port#", $buffer, $re)) { squid_admin_mysql(0, "SNMP option issue! [action=disable SNMP]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --disable-snmp >/dev/null 2>&1"); return; } //******************************************************************************************************************* if (preg_match("#FATAL: The\\s+(.*?)\\s+helpers are crashing too rapidly, need help#", $buffer, $re)) { squid_admin_mysql(0, "Herlpers [{$re[1]}] issue! [action=emergency!]", "The proxy claims about an helper that crashing, Artica pass your proxy service into emergency mode!\n{$buffer}", __FILE__, __LINE__); @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidUrgency", 1); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &"); } //******************************************************************************************************************* if (preg_match("#FATAL: I don't handle this error well#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/squid.did.handle.error.well"; $timefile = file_time_min($file); if ($timefile > 10) { squid_admin_mysql(0, "Error that proxy did not handle very well! [action=restart-forced]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --force --cache-logs >/dev/null 2>&1 &"); @unlink($file); @file_put_contents($file, time()); } return; } //******************************************************************************************************************* if (preg_match("#WARNING: All [0-9]+\\/([0-9]+)\\s+BasicFakeAuth processes are busy#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/squid.external.BasicFakeAuth.queue.overload"; $timefile = file_time_min($file); if ($timefile > 3) { $SquidClientParams = unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidClientParams"))); if (!is_numeric($SquidClientParams["external_acl_children"])) { $SquidClientParams["external_acl_children"] = 5; } if (!is_numeric($SquidClientParams["external_acl_startup"])) { $SquidClientParams["external_acl_startup"] = 1; } if (!is_numeric($SquidClientParams["external_acl_idle"])) { $SquidClientParams["external_acl_idle"] = 1; } $SquidClientParams["external_acl_children"] = $SquidClientParams["external_acl_children"] + 2; $SquidClientParams["external_acl_startup"] = $SquidClientParams["external_acl_startup"] + 2; $SquidClientParams["external_acl_idle"] = $SquidClientParams["external_acl_idle"] + 2; $GLOBALS["CLASS_SOCKETS"]->SaveConfigFile(base64_encode(serialize($SquidClientParams)), "SquidClientParams"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &"); $text = "{$buffer}\n\t\t\tNew parameters has been set and the proxy service was reconfigurer with:\n\t\t\texternal_acl_children = {$SquidClientParams["external_acl_children"]}\n\t\t\texternal_acl_startup = {$SquidClientParams["external_acl_startup"]}\n\t\t\texternal_acl_idle = {$SquidClientParams["external_acl_idle"]}\n\t\t\t"; squid_admin_mysql(1, "BasicFakeAuth ACL queue overloaded increase it", "{$text}"); @unlink($file); @file_put_contents($file, time()); return; } return; } //******************************************************************************************************************* if (preg_match("#\\/swap\\.state:.*?Read-only file system#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "{$re[1]} File system in read-only! suggest to reboot the server !", $buffer, __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#Open FD READ\\/WRITE\\s+[0-9]+\\s+(.+?)\\s+#", $buffer, $re)) { if (preg_match("#DNS\\s+#", $buffer)) { return; } if (preg_match("#ufdbgclient#", $re[1])) { return; } if (preg_match("#Idle server#", $re[1])) { return; } if (preg_match("#Idle client#", $re[1])) { return; } if (preg_match("#DNS#", $re[1])) { return; } if (preg_match("#ntlm_auth#", $re[1])) { return; } if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "`{$re[1]}` File descriptors issue, you should increase file descriptors [action: None]", $buffer, __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#FATAL: Unable to open HTTP Socket#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Port conflicts ! [action: force-restart]", null, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force --kill-all >/dev/null 2>&1 &"); return; } squid_admin_mysql(0, "Port conflicts ! [action: none - Timed out]", null, __FILE__, __LINE__); } //******************************************************************************************************************* if (preg_match("#FATAL: UFSSwapDir::openLog: Failed to open swap log#", $buffer, $re)) { squid_admin_mysql(0, "UFSSwapDir Proxy cannot open it's cache !! [action: None]", null, __FILE__, __LINE__); return; } //******************************************************************************************************************* if (preg_match("#Ipc::Mem::Segment::open failed to shm_open.*?No such file or directory#", $buffer, $re)) { squid_admin_mysql(0, "SMP Proxy cannot be linked to the system !! [action: None]", null, __FILE__, __LINE__); return; } //******************************************************************************************************************* if (preg_match("#kid([0-9]+).*?Preparing for shutdown after\\s+([0-9]+)\\s+requests#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(2, "Process CPU.{$re[1]} is stopping [action: None]", null, __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#kid([0-9]+).*?Squid Cache.*?: Exiting normally#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "Process CPU.{$re[1]} was stopped [action: None]", null, __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#kid([0-9]+).*?Process Roles:\\s+(.+?)#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(2, "Process CPU.{$re[1]} was started in {$re[2]} mode [action: None]", null, __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#ERROR: NTLM Authentication validating user\\. Error returned 'BH NT_STATUS_ACCESS_DENIED'#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 10)) { squid_admin_mysql(0, "Active directory link failed NT_STATUS_ACCESS_DENIED [action: Relink]", $buffer, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.kerbauth.php --join --force >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#Detected DEAD Parent: Peer([0-9]+)#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "Parent proxy number {$re[1]} is dead [action: None]", null, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --peer-status --force >/dev/null 2>&1 &"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --dead-parent \"{$re[1]}\" >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#TCP connection to (.+?)\\/([0-9]+)\\s+failed#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(1, "Connecting to Peer {$re[1]}:{$re[2]} failed [action: None]", null, __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --peer-status --force >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#commBind: Cannot bind socket FD [0-9]+ to ([0-9\\.]+):.*?Cannot assign requested address#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Proxy service Unable to hook {$re[1]} network address [action: Reconfigure]", "Proxy claim\n{$buffer}\nArtica will reconfigure the service\nPlease follow this issue, newt check will be in 5mn", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#Squid Cache.*?:\\s+Exiting normally#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 1)) { squid_admin_mysql(2, "Proxy service was normally stopped", "Proxy claim\n{$buffer}\n", __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#FATAL: Received Bus Error...dying#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Bus Error !", "Proxy claim\n{$buffer}\nThis caused by an hardware issue or a proxy bug ( please contact our support team)\nArtica will try to start Proxy if it is not running", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --start {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#FATAL: Unable to open HTTPS Socket#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Port conflict issue on HTTPS socket -> Restart proxy service", "{$buffer}\n", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#FATAL: The basicauthenticator helpers are crashing too rapidly, need help#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { $text[] = $buffer; $f = explode("\n", @file_get_contents("/etc/squid3/squid.conf")); while (list($num, $line) = each($f)) { if (preg_match("#auth_param basic program#", $line)) { $text[] = "basicauthenticator: {$line}"; } } squid_admin_mysql(0, "basicauthenticator extension is crashing", @implode("\n", $text), __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#ERROR: URL-rewrite produces invalid request:#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Redirector Web filter miss-configured, reconfigure Web filter", "{$buffer}\n", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squidguard.php --build --force --restart {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &"); } return; } //******************************************************************************************************************* if (preg_match("#assertion failed: mem\\.cc:([0-9]+):\\s+\"(.+?)\"#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 1)) { squid_admin_mysql(1, "Memory assertion failed mem.cc Line {$re[1]} - {$re[2]}", "{$buffer}\n", __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#optional ICAP service is down after an options fetch failure:\\s+icap:\\/\\/(.+?):([0-9]+)\\/(.+?)\\s+#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(1, "ICAP service {$re[3]} down {$re[1]}:{$re[2]}", "{$buffer}\n", __FILE__, __LINE__); } return; } //******************************************************************************************************************* if (preg_match("#logfileHandleWrite: daemon:: error writing\\s+(.*)#", $buffer, $re)) { squid_admin_mysql(2, "Error writing to Artica statistics dameon", "{$buffer}\n", __FILE__, __LINE__); return; } //******************************************************************************************************************* if (preg_match("#kid([0-9]+)\\|\\s+Reconfiguring Squid Cache#", $buffer, $re)) { events("CPU.{$re[1]} Reconfiguring Proxy service", __LINE__); squid_admin_mysql(2, "CPU.{$re[1]} Reconfiguring Proxy service", "{$buffer}\n", __FILE__, __LINE__); } //******************************************************************************************************************* if (preg_match("#WARNING: Unexpected change of authentication scheme.*?client\\s+(.*?)\\)#", $buffer, $re)) { events("{$re[1]} Unexpected change of authentication scheme", __LINE__); squid_admin_mysql(1, "Computer {$re[1]} Unexpected change of authentication scheme", "{$buffer}\n", __FILE__, __LINE__); return; } //******************************************************************************************************************* if (preg_match("#WARNING: All [0-9]+\\/([0-9]+) redirector processes are busy#", $buffer, $re)) { events("{$re[1]} Process reached for Web filtering daemon, Artica will increase the value...", __LINE__); squid_admin_mysql(2, "{$re[1]} Process reached for Web filtering daemon, Artica will increase the value", "{$buffer}\n", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --redirectors-more >/dev/null 2>&1 &"); return; } //******************************************************************************************************************* if (preg_match("#\\| WARNING: HTTP header contains NULL characters \\{Host:\\s+(.+)#i", $buffer, $re)) { events("{$re[1]} seems to crash", __LINE__); squid_admin_mysql(0, "Webserver \"{$re[1]}\" seems to crashing", "script of this source server seems broken\n{$buffer}\n", __FILE__, __LINE__); return; } // ******************************************************************************************************************* if (preg_match("#squidaio_queue_request: WARNING - Queue congestion#i", $buffer)) { events("squidaio_queue_request error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(2, "Queue congestion", "{$buffer}\n" . @file_get_contents("/usr/share/artica-postfix/ressources/databases/SQUID_ERROR_QUEUE_CONGESTION.db"), __FILE__, __LINE__); } return; } // ******************************************************************************************************************* if (preg_match("#WARNING: Consider increasing the number of ads_group processes in your config file#i", $buffer)) { events("ads_group error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(125, 2)) { squid_admin_mysql(0, "Queue overload on external ACL ads_group add more.", "{$buffer}\n", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --external-acl-children-more >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#WARNING: external ACL 'ads_group' queue overload. Using stale result#i", $buffer)) { events("ads_group error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(125, 2)) { squid_admin_mysql(0, "Queue overload on external ACL ads_group add more.", "{$buffer}\n", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --external-acl-children-more >/dev/null 2>&1 &"); } } // ******************************************************************************************************************* if (preg_match("#PHP Startup: Unable to load dynamic library#i", $buffer)) { shell_exec("/usr/share/artica-postfix/bin/artica-install --php-include"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid reload --cache-logs >/dev/null 2>&1"); } // ******************************************************************************************************************* if (preg_match("#errorTryLoadText:\\s+'(.+?)':.*?Permission denied#", $buffer, $re)) { @chown($re[1], "squid"); return; } // ******************************************************************************************************************* if (preg_match("#PHP Warning.*?Unable to load dynamic library '(.+?)'.*?undefined symbol#", $buffer, $re)) { if (is_file($re[1])) { @copy($re[1], $re[1] . "." . time() . ".bak"); @unlink($re[1]); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/artica-webconsole restart >/dev/null 2>&1"); } return; } // ******************************************************************************************************************* if (preg_match("#FATAL: Rock cache_dir at\\s+(.+?)\\s+failed to open db file#", $buffer, $re)) { events("disk write error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(__LINE__, 10)) { squid_admin_mysql(0, "Rock cache_dir issue", "{$buffer}\nrun cache -Z", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#basic_ldap_auth: WARNING, could not bind to binddn.*?Can.*?contact LDAP server#", $buffer, $re)) { events("basic_ldap_auth error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "Remote LDAP server issue unable to contact specified LDAP Port", "{$buffer}\n", __FILE__, __LINE__); } return; } // ******************************************************************************************************************* if (preg_match("#diskHandleWrite:\\s+FD\\s+.*?disk write error:.*?No space left on device#", $buffer, $re)) { events("disk write error issue ->`{$buffer}`", __LINE__); if (TimeStampTTL(__LINE__, 10)) { squid_admin_mysql(0, "No space left on device, rebuild all caches", "{$buffer}\nIt seems the one of caches or all caches handle your disk space.\nReconstruct caches procedure as been executed.", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#commBind:\\s+Cannot bind socket FD\\s+[0-9]+\\s+to.*?(::1|127\\.0\\.0\\.1)\\]:.*?Cannot assign requested address#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 1)) { events("127.0.0.1 issue", __LINE__); squid_admin_mysql(0, "Loopback interface issue - {$re[1]}", "{$buffer}\nArtica will reconfigure loopback"); shell_exec("{$GLOBALS["IFCONFIG"]} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1"); shell_exec("/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]}"); return; } } // ******************************************************************************************************************* if (preg_match("#Uninitialized SSL certificate database directory:\\s+(.+?)\\.#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 1)) { $Directory = $re[1]; events("SSL issue on `{$Directory}`", __LINE__); squid_admin_mysql(0, "Uninitialized SSL certificate database directory", "{$buffer}\nArtica will initalize `{$Directory}` with `{$GLOBALS["sslcrtd_program"]}`"); shell_exec("{$GLOBALS["RM"]} -rf {$Directory} >/dev/null 2>&1"); shell_exec("{$GLOBALS["sslcrtd_program"]} -c -s {$Directory} >/dev/null 2>&1"); shell_exec("{$GLOBALS["CHOWN"]} -R squid:squid {$Directory} >/dev/null 2>&1"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --cache-logs >/dev/null 2>&1 &"); return; } } // ******************************************************************************************************************* if (preg_match("#FATAL: Ipc::Mem::Segment::open failed to shm_open.*?squid-squid-page-pool\\.shm.*?No such file or directory#", $buffer)) { if (TimeStampTTL(__LINE__, 1)) { events("Ipc::Mem::Segment:: issue on squid-squid-page-pool.shm -> restart" . __LINE__); squid_admin_mysql(0, "SMP Memory issue", "{$buffer}\nThe proxy service will be restarted"); squid_admin_notifs("Warning, SMP Memory issue.\n{$buffer}\nThe proxy service will be restarted", __FUNCTION__, __FILE__, __LINE__, "watchdog"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --cache-logs >/dev/null 2>&1 &"); } events("Ipc::Mem::Segment:: issue on squid-squid-page-pool.shm need to wait 1mn" . __LINE__); } // ******************************************************************************************************************* if (preg_match("#TCP connection to\\s+127\\.0\\.0\\.1\\/{$GLOBALS["HAARP_PORT"]}\\s+failed#", $buffer)) { events("HTTP connection failed to Haarp cache system times Line:" . __LINE__); if (TimeStampTTL(__LINE__, 3)) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableHaarp", 0); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build >/dev/null 2>&1 &"); squid_admin_mysql(0, "Haarp issues", "Proxy service have issues with haarp,disable it\n{$buffer}\n the Haarp service will be restarted"); squid_admin_notifs("Warning, Haarp issues.\nProxy service have issues with haarp,\n{$buffer}\n the Haarp service will be restarted"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/haarp restart >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#Detected DEAD Parent.*?HaarpPeer#", $buffer)) { events("HTTP connection failed to Haarp cache system times Line:" . __LINE__); if (TimeStampTTL(__LINE__, 3)) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableHaarp", 0); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build >/dev/null 2>&1 &"); squid_admin_mysql(0, "Haarp issues", "Proxy service have issues with haarp,service will be disabled\n{$buffer}\n the Haarp service will be restarted"); squid_admin_notifs("Warning, Haarp issues.\nProxy service have issues with haarp,\n{$buffer}\n the service will be restarted"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/haarp restart >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#cannot connect to ufdbguardd daemon socket#", $buffer, $re)) { if ($GLOBALS["MonitConfig"]["watchdog"] == 0) { squid_admin_mysql(1, "Web filtering issue -> ufdbguardd daemon socket [action=none]", "{$buffer}\nWeb filtering will be disabled when reach 4", __FILE__, __LINE__); return; } if ($GLOBALS["MonitConfig"]["DisableWebFilteringNetFailed"] == 0) { squid_admin_mysql(1, "Web filtering issue -> ufdbguardd daemon socket [action=none]", "{$buffer}\nWeb filtering will be disabled when reach 4", __FILE__, __LINE__); return; } if (TimeStampTTL(__LINE__, 5)) { $GLOBALS["WEBFISSUE"]++; squid_admin_mysql(0, "Web filtering issue {$GLOBALS["WEBFISSUE"]}/4", "{$buffer}\nWeb filtering will be disabled when reach 2 times each 5mn", __FILE__, __LINE__); if ($GLOBALS["WEBFISSUE"] > 2) { squid_admin_mysql(0, "Web filtering issue MAX reached [action=remove]", "{$buffer}\nWeb filtering will be disabled", __FILE__, __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --disableUFDB >/dev/null 2>&1 &"); $GLOBALS["WEBFISSUE"] = 0; } } return; } // ******************************************************************************************************************* if (preg_match("#ERROR: URL-rewrite produces invalid request#", $buffer, $re)) { if ($GLOBALS["MonitConfig"]["watchdog"] == 0) { return; } if ($GLOBALS["MonitConfig"]["DisableWebFilteringNetFailed"] == 0) { return; } if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Web filtering compatiblity issue", "Proxy claim:\n{$buffer}\nWeb filtering will be disabled for compatibilities issues\nreturn back to 3.3x versions\nWe currently investigate on the compatibility"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --disableUFDB >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#TCP connection to (.+?)\\/([0-9]+)\\s+failed#", $buffer, $re)) { if (!isset($GLOBALS["CNXFAILED"][$re[1]])) { $GLOBALS["CNXFAILED"][$re[1]] = 0; } $GLOBALS["CNXFAILED"][$re[1]] = $GLOBALS["CNXFAILED"][$re[1]] + 1; events("{$re[1]} HTTP connection failed ({$GLOBALS["CNXFAILED"][$re[1]]}) times Line:" . __LINE__); } // ******************************************************************************************************************* if (preg_match("#ipcacheParse: No Address records in response to '(.+?)'#", $buffer, $re)) { if ($GLOBALS["MonitConfig"]["NotifyDNSIssues"] == 0) { reset($GLOBAL["DNSISSUES"]); return; } $curdate = date("YmdHi"); $GLOBALS["DNSISSUES"][$curdate][$re[1]] = true; if (count($GLOBALS["DNSISSUES"][$curdate] + 1) > $GLOBALS["MonitConfig"]["DNSIssuesMAX"]) { while (list($num, $ligne) = each($GLOBALS["DNSISSUES"][$curdate])) { $t[] = $num; } reset($GLOBALS["DNSISSUES"]); $report = NETWORK_REPORT(); squid_admin_mysql(1, "DNS issues", "Proxy service have issues to Resolve these websites::\n" . @implode("\n", $t) . "\n{$report}"); squid_admin_notifs("Warning, " . count($t) . " DNS issues.\nProxy service have issues to Resolve these websites::\n" . @implode("\n", $t) . "\n{$report}", __FUNCTION__, __FILE__, __LINE__, "watchdog"); } return; } // ******************************************************************************************************************* if (preg_match("#commBind: Cannot bind socket FD.*?Address already in use#", $buffer)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(0, "Bind Socket issue", "{$buffer}\nProxy service have issues to bind port\n{$buffer}\nArtica will restart the proxy service"); squid_admin_notifs("Warning, Bind Socket issue.\n{$buffer}\nProxy service have issues to bind port\n{$buffer}\nArtica will restart the proxy service", __FUNCTION__, __FILE__, __LINE__, "watchdog"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --crashed >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#FATAL: kid[0-9]+ registration timed out#", $buffer)) { @mkdir("/var/run/squid", 0755, true); shell_exec("{$GLOBALS["CHOWN"]} -R squid:squid /var/run/squid"); $GLOBALS["WEBPROCISSUE"]++; squid_admin_mysql(0, "Warning, Processor issue count:{$GLOBALS["WEBPROCISSUE"]} (max {$GLOBALS["MonitConfig"]["WEBPROCISSUE"]} times)", $buffer, __FILE__, __LINE__); if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(0, "Processor issue!!: SMP is disabled, you should consider return back to 1 CPU", "The detected error was:\n{$buffer}\n", __FILE__, __LINE__); } return; } // ******************************************************************************************************************* if (preg_match("#abandoning local=(.*?):.*?remote=(.*?):#", $buffer, $re)) { $client = $re[2]; $hostname = gethostbyaddr($re[2]); events("{$client} [{$hostname}] KeepAlive session was disconnected from this user Line:" . __LINE__); return; } //******************************************************************************************************************* if (preg_match("#ERROR:\\s+(.+?)\\/00: \\(2\\) No such file or directory#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { $dirname = trim($re[1]); events("{$dirname} -> no cache created -> squid-z Line:" . __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &"); return; } } // ******************************************************************************************************************* if (preg_match("#FATAL:\\s+Failed to make swap directory\\s+(.+?):.*?13.*?Permission denied#", $buffer, $re)) { $dirname = trim($re[1]); $basename = basename($dirname); if (is_numeric($basename)) { $dirname = dirname($dirname); } events("{$dirname} -> squid:squid {$re[1]}/0755 Permisssions... Line:" . __LINE__); @chown($dirname, "squid"); @chgrp($dirname, "squid"); @chmod($re[1], 0755); events("{$dirname} ({$basename}) Permisssions denied... Line:" . __LINE__); return; } // ******************************************************************************************************************* if (preg_match("#\\/home\\/squid\\/cache\\/MemBooster([0-9]+)\\/.*?No space left on device#", $buffer, $re)) { events("No space left on Memory Booster MemBooster{$re[1]}: line:" . __LINE__); if (TimeStampTTL(__LINE__ . $re[1], 3)) { squid_admin_mysql(1, "Memory cache full", "The cache memory MemBooster({$re[1]}) will be flushed to 0 and the proxy service will be restarted"); squid_admin_notifs("Warning, Memory cache, full\nThe cache memory MemBooster({$re[1]}) will be flushed to 0 and the proxy service will be restarted", __FUNCTION__, __FILE__, __LINE__, "watchdog"); shell_exec("{$GLOBALS["UMOUNT"]} -l /home/squid/cache/MemBooster{$re[1]}"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid restart --force --cache-logs 2>&1"); } return; } // ******************************************************************************************************************* if (preg_match("#FATAL: Write failure.*?check your disk space#", $buffer)) { events("Fatal: Write failure: Disk space over limit (cannot determine which path) Line:" . __LINE__); if (TimeStampTTL(__LINE__, 10)) { exec("{$GLOBALS["DF"]} -h 2>&1", $defres); squid_admin_mysql(0, "Write failure - disk space issue", "check your disk space for Proxy cache service.\nHere the status of your storage system:" . @implode("\n", $defres)); squid_admin_notifs("Warning, check your disk space for Proxy cache service.\nHere the status of your storage system:" . @implode("\n", $defres), __FUNCTION__, __FILE__, __LINE__, "watchdog"); } return; } // ******************************************************************************************************************* if (preg_match("#WARNING: Disk space over limit#", $buffer)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(1, "Disk space over limit", "{$buffer}\nswapstate will be executed"); events("Disk space over limit Line: refresh swap.state" . __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --swapstate >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#errorTryLoadText: '(.+?)':\\s+\\(13\\) Permission denied#i", $buffer, $re)) { if (!is_file($re[1])) { @file_put_contents($re[1], "\n"); } @chmod($re[1], 0777); @chown($re[1], "squid"); @chown(dirname($re[1]), "squid"); return; } // ******************************************************************************************************************* if (preg_match("#Squid Cache.*?Terminated abnormally#", $buffer)) { if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) { exec("{$GLOBALS["TAIL"]} -n 50 /var/log/squid/cache.log 2>&1", $results); squid_admin_mysql(0, "Squid Cache Terminated Abnormally", "squid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...\n" . @implode("\n", $results), __FILE__, __LINE__); squid_admin_notifs("Squid Cache Terminated Abnormally.\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } if (TimeStampTTL(__LINE__, 5)) { exec("{$GLOBALS["TAIL"]} -n 50 /var/log/squid/cache.log 2>&1", $results); squid_admin_mysql(1, "Squid Cache Terminated Abnormally", "squid-cache claim\r\n{$buffer}\r\nArtica will restart the proxy service.\nPiece of logs:" . @implode("\n", $results)); squid_admin_notifs("Squid Cache Terminated abnormally.\n{$buffer}\nProxy service have issues\n{$buffer}\nArtica will start the proxy service\nPiece of logs:" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "watchdog"); shell_exec("{$GLOBALS["NOHUP"]} /etc/init.d/squid start --crashed >/dev/null 2>&1 &"); } return; } // ******************************************************************************************************************* if (preg_match("#WARNING: external ACL.*?queue overload. Request rejected#i", $buffer, $re)) { $file = "/etc/artica-postfix/pids/squid.external.ACL.queue.overload"; $timefile = file_time_min($file); if ($timefile > 3) { $SquidClientParams = unserialize(base64_decode($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidClientParams"))); if (!is_numeric($SquidClientParams["external_acl_children"])) { $SquidClientParams["external_acl_children"] = 5; } if (!is_numeric($SquidClientParams["external_acl_startup"])) { $SquidClientParams["external_acl_startup"] = 1; } if (!is_numeric($SquidClientParams["external_acl_idle"])) { $SquidClientParams["external_acl_idle"] = 1; } $SquidClientParams["external_acl_children"] = $SquidClientParams["external_acl_children"] + 1; $SquidClientParams["external_acl_startup"] = $SquidClientParams["external_acl_startup"] + 1; $SquidClientParams["external_acl_idle"] = $SquidClientParams["external_acl_idle"] + 1; $GLOBALS["CLASS_SOCKETS"]->SaveConfigFile(base64_encode(serialize($SquidClientParams)), "SquidClientParams"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &"); events("external ACL (queue overload) Increase: external_acl_children:{$SquidClientParams["external_acl_children"]},external_acl_startup:{$SquidClientParams["external_acl_startup"]}, external_acl_idle:{$SquidClientParams["external_acl_idle"]} Line:" . __LINE__); $text = "{$buffer}\n\t\t\tNew parameters has been set and the proxy service was reconfigurer with:\n\t\t\texternal_acl_children = {$SquidClientParams["external_acl_children"]}\n\t\t\texternal_acl_startup = {$SquidClientParams["external_acl_startup"]}\n\t\t\texternal_acl_idle = {$SquidClientParams["external_acl_idle"]}\n\t\t\t"; squid_admin_notifs($text, __FUNCTION__, __FILE__, __LINE__, "watchdog"); squid_admin_mysql(1, "external ACL queue overload", "{$text}"); @unlink($file); @file_put_contents($file, time()); return; } events("external ACL (queue overload) timeout ({$timefile}mn) line:" . __LINE__); return; } // ******************************************************************************************************************* if (preg_match("#kid[0-9]+.*?ERROR opening swap log\\s+(.+?)\\/swap\\.state: \\(13\\) Permission denied#", $buffer, $re)) { $dirname = $re[1]; $file = "/etc/artica-postfix/pids/opening.swap.state." . md5($dirname); events("{$dirname} ERROR opening swap log... Line:" . __LINE__); $timefile = file_time_min($file); if ($timefile > 3) { swapstate($dirname); if (!isset($GLOBALS["CHMOD"])) { $unix = new unix(); $GLOBALS["CHMOD"] = $unix->find_program("chmod"); } if (!isset($GLOBALS["CHOWN"])) { $unix = new unix(); $GLOBALS["CHOWN"] = $unix->find_program("chown"); } if (!isset($GLOBALS["SQUIDBIN"])) { $unix = new unix(); $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN(); } $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHMOD"]} -R 0755 {$dirname} >/dev/null 2>&1 &"; shell_exec($cmd); events("{$cmd}" . __LINE__); squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}"); squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHOWN"]} -R squid:squid {$dirname} >/dev/null 2>&1 &"; shell_exec("/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]}"); events("{$cmd}" . __LINE__); shell_exec($cmd); @unlink($file); @file_put_contents($file, time()); } else { events("{$dirname} Timeout {$timefile}Mn need to wait 3mn Line chown just swap.state :" . __LINE__); swapstate($dirname); if (!isset($GLOBALS["SQUIDBIN"])) { $unix = new unix(); $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN(); } squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}"); squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); $cmd = "/etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &"; events("{$cmd}" . __LINE__); shell_exec($cmd); } return; } // ******************************************************************************************************************* if (preg_match("#ERROR opening swap log (.+?)\\/swap\\.state: \\(13\\) Permission denied#", $buffer, $re)) { $dirname = $re[1]; $file = "/etc/artica-postfix/pids/opening.swap.state." . md5($dirname); events("{$dirname} ERROR opening swap log... Line:" . __LINE__); $timefile = file_time_min($file); if ($timefile > 3) { swapstate($dirname); if (!isset($GLOBALS["CHMOD"])) { $unix = new unix(); $GLOBALS["CHMOD"] = $unix->find_program("chmod"); } if (!isset($GLOBALS["CHOWN"])) { $unix = new unix(); $GLOBALS["CHOWN"] = $unix->find_program("chown"); } if (!isset($GLOBALS["SQUIDBIN"])) { $unix = new unix(); $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN(); } $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHMOD"]} -R 0775 {$dirname} >/dev/null 2>&1 &"; shell_exec($cmd); events("{$cmd}" . __LINE__); squid_admin_mysql(1, "Permission denied: Reconfiguring squid-cache", "Permission as been set to {$dirname}"); $cmd = "{$GLOBALS["NOHUP"]} {$GLOBALS["CHOWN"]} -R squid:squid {$dirname} && /etc/init.d/squid reload {$GLOBALS["SCRIPT_SUFFIX"]} >/dev/null 2>&1 &"; events("{$cmd}" . __LINE__); shell_exec($cmd); @unlink($file); @file_put_contents($file, time()); } else { events("{$dirname} Timeout {$timefile}Mn need to wait 3mn Line:" . __LINE__); swapstate($dirname); } return; } // ******************************************************************************************************************* if (preg_match("#Detected DEAD Parent:\\s+(.+)#", $buffer, $re)) { events("DEAD Parent {$re[1]} -> exec.squid.watchdog.php --dead-parent {$re[1]}" . __LINE__); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --dead-parent \"{$re[1]}\" >/dev/null 2>&1 &"); return; } // ******************************************************************************************************************* if (preg_match("#kid[0-9]+.*?ERROR:\\s+(.+):\\s+\\(2\\)\\s+No such file or directory#i", $buffer, $re)) { if (TimeStampTTL(__LINE__, 5)) { squid_admin_mysql(2, "Missing object {$dirname} [action: None]", "squid-cache claim\r\n{$buffer}\r\nArtica have automatically created this directory...."); } return; } // ******************************************************************************************************************* if (preg_match("#Preparing for shutdown after\\s+([0-9]+)\\s+requests#", $buffer, $re)) { squid_admin_mysql(2, "Proxy will be stopped after {$re[1]} requests", "{$buffer}"); return; } // ******************************************************************************************************************* if (preg_match("#Store rebuilding is\\s+([0-9\\.,]+)#", $buffer, $re)) { if ($re[1] == "0.00") { return; } squid_admin_mysql(2, "Store rebuilding {$re[1]}%", "{$buffer}"); $intval = intval($re[1]); if ($intval > 100) { $file = "/etc/artica-postfix/pids/Squid.Store.rebuilding"; $timefile = file_time_min($file); if ($timefile > 10) { squid_admin_mysql(0, "Store rebuilding task {$re[1]}% is over 100% - Reset caches", "{$buffer}"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php --reindex >/dev/null 2>&1 &"); @unlink($file); @file_put_contents($file, time()); return; } } events("Store rebuilding is: {$re[1]}% = {$intval} swap.state [do nothing] line:" . __LINE__); return; } // ******************************************************************************************************************* if (preg_match("#commBind: Cannot bind socket FD [0-9]+ to\\s+(.*?)\\s+\\([0-9]+\\) No such file or directory#", $buffer, $re)) { if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(1, "Cannot bind socket to {$re[1]}", "{$buffer}", __FILE__, __LINE__); } return; } // ******************************************************************************************************************* if (preg_match("#\\|\\s+(.+?):\\s+\\(2\\)\\s+No such file or directory#", $buffer, $re)) { if (preg_match("#\\/usr\\/share\\/squid3#i", $buffer)) { return; } if (TimeStampTTL(__LINE__, 2)) { squid_admin_mysql(1, "{$re[1]} No such file or directory", "{$buffer}", __FILE__, __LINE__); } return; } // ******************************************************************************************************************* if (preg_match("#kid[0-9]+\\|\\s+\\/(.+?)\\/[0-9]+\\/[0-9A-Z]+\$#", $buffer)) { return; } // ******************************************************************************************************************* if (preg_match("#storeDirClean:\\s+(.+?):\\s+\\(2\\)\\s+No such file or directory#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/" . md5("storeDirCleanNo::NoSuchFileOrDirectory"); $fileMail = "/etc/artica-postfix/pids/squid.miss_dir"; $timefile = file_time_min($file); $dirname = trim($re[1]); events("{$dirname} No such file or directory... Line:" . __LINE__); @mkdir("{$dirname}", 0755); @chown($dirname, "squid"); @chgrp($dirname, "squid"); if ($timefile > 5) { $timefile = file_time_min($fileMail); if ($timefile > 10) { squid_admin_mysql(1, "Suspicious removed object {$dirname}", "Suspicious removed object {$dirname}\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that this cache directory was removed after the started service\r\nChecks that your have created your caches \"outside\" /var/cache/squid*\r\n"); squid_admin_notifs("Suspicious removed object {$dirname}\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that this cache directory was removed after the started service\r\nChecks that your have created your caches \"outside\" /var/cache/squid*\r\n", __FUNCTION__, __FILE__, __LINE__, "proxy"); @unlink($fileMail); @file_put_contents($file, time()); } @unlink($file); @file_put_contents($file, time()); } return; } // ******************************************************************************************************************* if (preg_match("#DiskThreadsDiskFile::openDone:.*?No such file or directory#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/" . md5("DiskThreadsDiskFile::openDone:NoSuchFileOrDirectory"); $timefile = file_time_min($file); $fileMail = "/etc/artica-postfix/pids/squid.miss_dir"; events("DiskThreadsDiskFile:: \"{$buffer}\" [do nothing]"); if ($timefile < 15) { return; } squid_admin_mysql(1, "Cache object issue on disk", "squid-cache claim\r\n{$buffer}\r\nIt seems that some caches objects was removed after the started service\r\nJust an information, nothing will be done."); $timefile = file_time_min($fileMail); @unlink($file); @file_put_contents($file, time()); return; } // ******************************************************************************************************************* if (preg_match("#Failed to verify one of the swap directories#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/" . md5("Failed to verify one of the swap directories"); $timefile = file_time_min($file); $fileMail = "/etc/artica-postfix/pids/squid.miss_dir"; events("Failed to verify one of the swap directories [ - squid -z ?]"); if ($timefile < 5) { return; } $timefile = file_time_min($fileMail); if ($timefile > 10) { squid_admin_mysql(0, "Missing Caches !!", "squid-cache claim\r\n{$buffer}\r\nIt seems that caches directory was removed after the started service\r\nArtica start the procedure to verify caches..\r\n"); squid_admin_notifs("Missing Caches !!\r\nsquid-cache claim\r\n{$buffer}\r\nIt seems that caches directory was removed after the started service\r\nArtica start the procedure to verify caches..\r\nr", __FUNCTION__, __FILE__, __LINE__, "proxy"); @unlink($file); @file_put_contents($file, time()); } @unlink($file); @file_put_contents($file, time()); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &"); return; } // ******************************************************************************************************************* if (preg_match("#kid[0-9]+\\|\\s+\\/home\\/squid\\/cache\\/MemBooster[0-9]+\\/#", $buffer, $re)) { $file = "/etc/artica-postfix/pids/" . md5("MemBoosterFailed"); $timefile = file_time_min($file); if ($timefile < 15) { return; } squid_admin_mysql(1, "Cache object issue MemBoosters", "squid-cache claim\r\n{$buffer}\r\nIt seems that some caches objects was removed after the started service\r\nJust an information, nothing will be done."); @unlink($file); @file_put_contents($file, time()); //shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --CleanMemBoosters >/dev/null 2>&1"); } // ******************************************************************************************************************* if (strpos($buffer, "Old swap file detected") > 0) { events("Old swap file detected..." . __LINE__); //squid_admin_notifs("Missing some caches directories\r\nsquid-cache claim\r\n$buffer\r\nArtica will reset all caches", __FUNCTION__, __FILE__, __LINE__, "proxy"); //shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rebuild.caches.php"); return; } // ******************************************************************************************************************* if (strpos($buffer, "Run 'squid -z' to create swap directories")) { $file = "/etc/artica-postfix/pids/" . md5("Run 'squid -z' to create swap directories"); $timefile = file_time_min($file); if ($timefile > 5) { events("SQUID -Z !!!... Line:" . __LINE__); squid_admin_mysql(0, "Missing Caches !!", "squid-cache claim\r\n{$buffer}\r\nArtica will launch the directory creation"); squid_admin_notifs("Missing some caches directories\r\nsquid-cache claim\r\n{$buffer}\r\nArtica will launch the directory creation", __FUNCTION__, __FILE__, __LINE__, "proxy"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.smp.php --squid-z-fly >/dev/null 2>&1 &"); @unlink($file); @file_put_contents($file, time()); } else { events("SQUID -Z !!!... TIMEOUT Line:" . __LINE__); } return; } // ******************************************************************************************************************* if (strpos($buffer, "| Reconfiguring Squid Cache") > 0) { $file = "/etc/artica-postfix/pids/" . md5("Reconfiguring Squid Cache"); $timefile = file_time_min($file); if ($timefile > 1) { events("Reconfiguring Squid Cache Line:" . __LINE__); @unlink($file); @file_put_contents($file, time()); } return; } // ******************************************************************************************************************* if (strpos($buffer, "Fatal: Bungled squid.conf line")) { events("Bad configuration file!" . __LINE__); squid_admin_mysql(0, "Bad configuration file", "squid-cache claim\r\n{$buffer}\r\nTry to run the configuration compilation on Artica or contact our support team..."); squid_admin_notifs("Bad configuration file!\r\nsquid-cache claim\r\n{$buffer}\r\nTry to run the configuration compilation on Artica or contact our support team...", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } // ******************************************************************************************************************* if (preg_match("#FATAL ERROR: cannot connect to ufdbguardd daemon socket: Connection timed out#", $buffer)) { $file = "/etc/artica-postfix/pids/" . md5("Fatal:ufdbguardd daemon socket: Connection timed out"); $timefile = file_time_min($file); if ($timefile > 5) { events("Fatal: ufdbguardd daemon socket:timed out " . __LINE__); squid_admin_mysql(0, "Issue on Webfiltering Daemon!", "squid-cache claim\r\n{$buffer}\r\nThe Webfiltering Dameon will disconnected from proxy service will be reloaded"); squid_admin_notifs("Issue on Webfiltering Daemon!\r\nsquid-cache claim\r\n{$buffer}\r\nThe Webfiltering Dameon will disconnected from proxy service will be reloaded", __FUNCTION__, __FILE__, __LINE__, "proxy"); @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.php --build --force >/dev/null 2>&1 &"); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/bin/artica-make APP_UFDBGUARD >/dev/null 2>&1 &"); @unlink($file); @file_put_contents($file, time()); return; } events("Fatal: ufdbguardd daemon socket:timed out " . __LINE__); return; } // ******************************************************************************************************************* if (preg_match("#:\\s+(.+?):\\s+\\(13\\)\\s+Permission denied#", $buffer, $re)) { @chown($re[1], "squid"); @chgrp($re[1], "squid"); events("Add squid:squid permission on `{$re[1]}` " . __LINE__); if (preg_match("#pinger\$#", $re[1])) { events("Add chmod 04755 on `{$re[1]}` " . __LINE__); shell_exec("{$GLOBALS["CHOWN"]} root {$re[1]}"); shell_exec("{$GLOBALS["CHMOD"]} 4755 {$re[1]}"); } return; } // ******************************************************************************************************************* if (preg_match("#FATAL: Received Segment Violation\\.\\.\\.dying#", $buffer)) { $file = "/etc/artica-postfix/pids/" . md5("Fatal: Received Segment Violation"); $timefile = file_time_min($file); events("Fatal: Received Segment Violation " . __LINE__); if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) { squid_admin_mysql(1, "Received Segment Violation", "squid-cache claim\r\n{$buffer}"); squid_admin_notifs("Received Segment Violation\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } } if (preg_match("#optional ICAP service is down after an options fetch failure:\\s+icap:.*?1344\\/av\\/reqmod#", $buffer)) { $file = "/etc/artica-postfix/pids/" . md5("KasperskyIcapDown"); $timefile = file_time_min($file); if ($timefile > 2) { squid_admin_mysql(1, "ICAP service is down, reloading squid-cache service", "{$buffer}"); port1344_notavailable(); @unlink($file); @file_put_contents($file, time()); shell_exec("{$GLOBALS["NOHUP"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.watchdog.php --reload --force --exec-status=" . __LINE__ . " >/dev/null 2>&1 &"); return; } events("ICAP service is down after an options (1344) -> timeout Line:" . __LINE__); return; } if (strpos($buffer, "Terminated abnormally")) { if ($GLOBALS["MonitConfig"]["RestartWhenCrashes"] == 0) { squid_admin_mysql(1, "Squid Terminated abnormally", "{$buffer}"); squid_admin_notifs("Squid Terminated abnormally\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } $file = "/etc/artica-postfix/pids/" . md5("Terminated abnormally"); $timefile = file_time_min($file); if ($timefile > 1) { events("Terminated abnormally " . __LINE__); squid_admin_mysql(0, "Squid Terminated abnormally", "{$buffer}\nProxy will be restarted"); squid_admin_notifs("Squid Terminated abnormally\r\nsquid-cache claim\r\n{$buffer}\r\nThis just a notification, Artica will checks your settings and determine what is the issue...", __FUNCTION__, __FILE__, __LINE__, "proxy"); @unlink($file); @file_put_contents($file, time()); } return; } events("Not Filtered \"{$buffer}\" Line:" . __LINE__); }
function zarafa_rebuild_db($table, $buffer) { $file = "/etc/artica-postfix/cron.1/" . __FUNCTION__; if (file_time_min($file) < 15) { events("Zarafa missing table <{$table}>, time-out"); return null; } @unlink($file); email_events("Zarafa missing Mysql table {$table}", "Service Zarafa claim \"{$buffer}\" artica will destroy the zarafa database in order to let the Zarafa service create a new one' ", 'mailbox'); THREAD_COMMAND_SET("{$GLOBALS["PHP5_BIN"]} " . dirname(__FILE__) . "/exec.mysql.build.php --rebuild-zarafa"); @file_put_contents($file, "#"); return; }
function APTCHECK() { if (!is_file("/usr/lib/update-notifier/apt-check")) { if ($GLOBALS["VERBOSE"]) { echo "/usr/lib/update-notifier/apt-check no such file \n"; } events("/usr/lib/update-notifier/apt-check no such file ", __FUNCTION__, __FILE__, __LINE__); $datas = ZYPPER_CHECK(); if (strlen($datas) > 10) { return $datas; } return; } $cache_file = "/etc/artica-postfix/artica-meta-apt-check.cache"; $timen = file_time_min($cache_file); if (!$GLOBALS["VERBOSE"]) { if ($timen < 30) { return @file_get_contents($cache_file); } } $EXEC_NICE = EXEC_NICE(); $cmd = "{$EXEC_NICE}/usr/lib/update-notifier/apt-check 2>&1"; exec($cmd, $results); while (list($index, $line) = each($results)) { usleep(35000); events("Found: {$line}", __FUNCTION__, __FILE__, __LINE__); if (preg_match("#([0-9]+);([0-9]+)#", $line, $re)) { $array["UPDATE_PACKAGES"] = $re[1]; $array["SECURITY_PACKAGES"] = $re[2]; } } if ($array["UPDATE_PACKAGES"] > 0) { exec("{$EXEC_NICE}/usr/lib/update-notifier/apt-check -p 2>&1", $results2); while (list($index, $line) = each($results2)) { usleep(35000); if (trim($line) == null) { continue; } if (preg_match("#Reading package lists#", $line)) { continue; } if (preg_match("#Building dependency#", $line)) { continue; } if (preg_match("#Reading state information#", $line)) { continue; } $pkg[] = $line; } } if (is_array($pkg)) { $array["UPDATE_PACKAGES_LIST"] = @implode(";", $pkg); } events("UPDATE_PACKAGES_LIST: {$array["UPDATE_PACKAGES_LIST"]}", __FUNCTION__, __FILE__, __LINE__); events("UPDATE_PACKAGES.....: {$array["UPDATE_PACKAGES"]}", __FUNCTION__, __FILE__, __LINE__); events("SECURITY_PACKAGES...: {$array["SECURITY_PACKAGES"]}", __FUNCTION__, __FILE__, __LINE__); @file_put_contents($cache_file, base64_encode(serialize($array))); return base64_encode(serialize($array)); }
function bandwith(){ $file="/usr/share/artica-postfix/ressources/logs/web/bandwith-mon.txt"; $ftime=file_time_min($file); events("$ftime ". basename($file),__FUNCTION__,__LINE__); if($ftime<10){return;} exec("/usr/share/artica-postfix/bin/bandwith.pl 2>&1",$results); $text=@implode("",$results); if(!preg_match("#([0-9\.,]+)#",$text,$re)){ events("$text unable to preg_match",__FUNCTION__,__LINE__); return; } $re[1]=str_replace(",",".",$re[1]); $mbs=round($re[1],0); events("$mbs MB/S bandwith",__FUNCTION__,__LINE__); $sql="INSERT INTO bandwith_stats (`zDate`,`bandwith`) VALUES(NOW(),'$mbs');"; $q=new mysql(); $q->QUERY_SQL($sql,"artica_events"); if(!$q->ok){events("$q->mysql_error \"$sql\"",__FUNCTION__,__LINE__);} @unlink($file); @file_put_contents($file,$mbs); @chmod($file,0770); }
function optimizetable() { $file = "/etc/artica-postfix/table.smtp.logs.optimize"; $filetime = intval(file_time_min($file)); events("optimizetable:: {$file}={$filetime} mn"); if ($filetime < 2880) { events("optimizetable:: Need to wait 2880Mn"); return null; } @unlink($file); file_put_contents($file, date("y-m-d H:i:s")); $q = new mysql(); events("OPTIMIZE TABLE"); $sql = "OPTIMIZE TABLE `smtp_logs`"; $q->QUERY_SQL($sql, "artica_events"); $sql = "OPTIMIZE TABLE `postqueue`"; $q->QUERY_SQL($sql, "artica_events"); events("OPTIMIZE TABLE DONE"); }
$datas = @file_get_contents("/var/lib/dhcp3/dhcpd.leases"); $md5Tampon = md5($datas); $md5Local = md5(trim(@file_get_contents("/etc/artica-postfix/dhcpd.leases.dmp"))); if ($GLOBALS["VERBOSE"]) { echo " -->{$md5Local} / {$md5Tampon}\n"; } if (!$GLOBALS["FORCE"]) { if ($md5Local == $md5Tampon) { if ($GLOBALS["VERBOSE"]) { echo " -->{$md5Local} == {$md5Tampon}, abort\n"; } die; } } if (!$GLOBALS["FORCE"]) { if (file_time_min($cache_file) < 10) { die; } } @unlink($cache_file); @file_put_contents($cache_file, $md5Tampon); writelogs("LOCAL:{$md5Local} !== REMOTE:{$md5Tampon}", "MAIN", __FILE__, __LINE__); write_syslog("integrity of dhcpd.leases has been modified ( from {$md5Local} to {$md5Tampon}), analyze the leases", basename(__FILE__)); if ($GLOBALS["VERBOSE"]) { echo " --> CleanFile()\n"; } CleanFile(); if ($GLOBALS["VERBOSE"]) { echo " --> /var/lib/dhcp3/dhcpd.leases\n"; } $datas = @file_get_contents("/var/lib/dhcp3/dhcpd.leases");
function amavis_sa_update($buffer) { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = "{$nohup} {$php} /usr/share/artica-postfix/exec.spamassassin.php --sa-update >/dev/null 2>&1 &"; $file = "/etc/artica-postfix/pids/" . __FUNCTION__ . ".error.time"; if (file_time_min($file) < 15) { events("-> detected {$buffer}, need to wait 15mn"); return null; } @unlink($file); @file_put_contents($file, "#"); shell_exec(trim($cmd)); events("{$cmd}"); return; }
function AutomaticInjection() { $users = new usersMenus(); if (!$users->OCSI_INSTALLED) { return; } $file = "/etc/artica-postfix/cron.2/AutomaticInjection.pid"; $sock = new sockets(); $OCSImportToLdap = $sock->GET_INFO("OCSImportToLdap"); if ($OCSImportToLdap == null) { $OCSImportToLdap = 60; } if ($OCSImportToLdap == 0) { return; } if (!$GLOBALS["FORCE"]) { $filetime = file_time_min($file); if ($GLOBALS["VERBOSE"]) { echo "{$file}={$filetime} against {$OCSImportToLdap} minutes\n"; } if (!$GLOBALS["VERBOSE"]) { if ($filetime < $OCSImportToLdap) { return; } } } writelogs("Starting OCS injection from OCS database", __FUNCTION__, __FILE__, __LINE__); $ocs = new ocs(); $sql = $ocs->COMPUTER_SEARCH_QUERY(null, 1); if ($GLOBALS["VERBOSE"]) { echo $sql . "\n"; } $q = new mysql(); $results = $q->QUERY_SQL($sql, "ocsweb"); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["IPADDRESS"] == "0.0.0.0") { continue; } if ($ligne["MACADDR"] == "00:00:00:00:00:00") { continue; } if ($already[$ligne["MACADDR"]]) { continue; } $already[$ligne["MACADDR"]] = true; $f = new computers(); $uid = $f->ComputerIDFromMAC($ligne["MACADDR"]); if ($GLOBALS["VERBOSE"]) { echo "Check {$ligne["MACADDR"]} against {$uid}\n"; } if ($uid == null) { writelogs("uid is null for {$ligne["MACADDR"]}, add it into LDAP", __FUNCTION__, __FILE__, __LINE__); AutomaticInjectionAdd($ligne["MACADDR"]); continue; } $update = false; $f = new computers($uid); if ($GLOBALS["VERBOSE"]) { echo "Checking uid={$uid} NAME={$f->ComputerRealName}; IP={$f->ComputerIP}; OS={$f->ComputerOS}\n"; } $ComputerIP = trim($f->ComputerIP); $ComputerOS = trim($f->ComputerOS); $OSNAME = trim(utf8_encode($ligne["OSNAME"])); $PROCESSORT = trim($ligne["PROCESSORT"]); if ($GLOBALS["VERBOSE"]) { echo "OCS SOURCE {$ligne["MACADDR"]} IP={$ligne["IPSRC"]}; OS={$OSNAME} CPU={$PROCESSORT}\n"; } if ($ComputerIP != $ligne["IPSRC"]) { $f->ComputerIP = $ligne["IPSRC"]; if ($GLOBALS["VERBOSE"]) { echo "IPSRC not match ({$ComputerIP})\n"; } $update = true; } if ($PROCESSORT != null) { if (trim($f->ComputerCPU) != $ligne["PROCESSORT"]) { if ($GLOBALS["VERBOSE"]) { echo "PROCESSORT not match\n"; } $f->ComputerOS = $ligne["PROCESSORT"]; $update = true; } } if ($update) { echo "update {$ligne["MACADDR"]}\n"; $f->Add(); } } @unlink($file); @file_put_contents($file, getmypid()); writelogs("Finish OCS injection from OCS database", __FUNCTION__, __FILE__, __LINE__); }
function watchdog_artica_status() { if (is_file("/var/log/artica-postfix/status-daemon.log")) { $time = file_time_min("/var/log/artica-postfix/status-daemon.log"); if ($time > 5) { events("artica-status seems freeze, restart daemon", __FUNCTION__, __LINE__); sys_THREAD_COMMAND_SET("/etc/init.d/artica-postfix restart artica-status"); @unlink("/var/log/artica-postfix/status-daemon.log"); events("done...", __FUNCTION__, __LINE__); } } }
function TestCron($pidfile) { $unix = new unix(); $pid = trim(@file_get_contents($pidfile)); if ($unix->process_exists($pid)) { $time = file_time_min($pidfile); if ($time > 30) { events("Already executed pid {$pid} since {$time}Mn (timeout), kill this task", __FUNCTION__, __FILE__, __LINE__); $kill = $unix->find_program("kill"); $cmd = "{$kill} -9 {$pid}"; events("{$cmd}", __FUNCTION__, __FILE__, __LINE__); exec("{$kill} -9 {$pid}", $results); sleep(2); if ($unix->process_exists($pid)) { events("kill {$pid} failed", __FUNCTION__, __FILE__, __LINE__); return false; } else { return true; } } events("Already executed pid {$pid} since {$time}Mn (pid file:{$pidfile}), aborting", __FUNCTION__, __FILE__, __LINE__); return false; } return true; }