function MultiplesInstancesFound($pid = false, $onlystart = false) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $unix = new unix(); if (!$GLOBALS["FORCE"]) { if ($pid) { if ($unix->file_time_min($pidtime) < 2) { if ($GLOBALS["VERBOSE"]) { echo "Minimal 2mn\n"; } return; } $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $processtime = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "Already running pid {$pid}\n"; } if ($processtime < 5) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } } } if (!$GLOBALS["FORCE"]) { @unlink($pidtime); @file_put_contents($pidtime, time()); @file_put_contents($pidfile, getmypid()); } $sock = new sockets(); $uuid = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes")); $sql = "SELECT ValueTEXT,ip_address,ou FROM postfix_multi WHERE `key`='PluginsEnabled' AND uuid='{$uuid}'"; if ($GLOBALS["DEBUG"]) { echo "{$sql}\n"; } $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo __FUNCTION__ . " {$q->mysql_error}\n"; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $array_filters = unserialize(base64_decode($ligne["ValueTEXT"])); if (!isset($array_filters["APP_MILTERGREYLIST"])) { $array_filters["APP_MILTERGREYLIST"] = null; } if ($GLOBALS["DEBUG"]) { echo "{$ligne["ip_address"]} APP_MILTERGREYLIST -> `{$array_filters["APP_MILTERGREYLIST"]}` \n"; } if ($array_filters["APP_MILTERGREYLIST"] == null) { continue; } if ($array_filters["APP_MILTERGREYLIST"] == 0) { continue; } $hostname = MultiplesInstancesGetmyhostname($ligne["ip_address"]); $ou = $ligne["ou"]; if ($GLOBALS["DEBUG"]) { echo "{$hostname} -> {$ou}\n"; } $GLOBALS["hostnames"][$hostname] = $ou; if ($onlystart) { MultiplesInstances_start($hostname, $ou); continue; } MultiplesInstances($hostname, $ou); } }
function MultiplesInstances($hostname = null, $ou = null) { if ($ou == null && $hostname == null) { MultiplesInstancesFound(); return; } if ($ou == null) { echo __FUNCTION__ . " unable to get ou name\n"; return; } if ($hostname == null) { echo __FUNCTION__ . " unable to get hostname name\n"; return; } $mg = new milter_greylist(false, $hostname, $ou); $datas = $mg->BuildConfig(); @mkdir("/etc/milter-greylist/{$hostname}", 0666, true); @mkdir("/var/spool/{$hostname}/run/milter-greylist", 0666, true); $tbl = explode("\n", $datas); while (list($num, $ligne) = each($tbl)) { $ligne = trim($ligne); if ($ligne == null) { continue; } $newf[] = $ligne; } $newf[] = ""; echo "Starting......: writing {$conf_path}\n"; $datas = @implode("\n", $newf); @file_put_contents("/etc/milter-greylist/{$hostname}/greylist.conf", $datas); echo "Starting......: milter-greylist {$hostname} or={$ou} START_ONLY={$GLOBALS["START_ONLY"]},STOP_ONLY={$GLOBALS["STOP_ONLY"]}\n"; if ($GLOBALS["STOP_ONLY"] == 1) { MultiplesInstances_stop($hostname, $ou); } if ($GLOBALS["START_ONLY"] == 1) { MultiplesInstances_start($hostname, $ou); } }