コード例 #1
0
ファイル: exec.status.php プロジェクト: BillTheBest/1.6.x
function postfix()
{
    $bin_path = $GLOBALS["CLASS_UNIX"]->find_program("postconf");
    if ($bin_path == null) {
        return null;
    }
    if (is_file("/etc/artica-postfix/DO_NOT_DETECT_POSTFIX")) {
        return;
    }
    $EnablePostfixMultiInstance = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnablePostfixMultiInstance");
    $EnableStopPostfix = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableStopPostfix");
    if ($GLOBALS["VERBOSE"]) {
        echo "EnablePostfixMultiInstance=\"{$EnablePostfixMultiInstance}\"\n";
    }
    if (!is_numeric($EnableStopPostfix)) {
        $EnableStopPostfix = 0;
    }
    if (!is_numeric($EnablePostfixMultiInstance)) {
        $EnablePostfixMultiInstance = 0;
    }
    $DisableMessaging = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableMessaging"));
    if ($DisableMessaging == 1) {
        $EnableStopPostfix = 1;
        $EnablePostfixMultiInstance = 0;
    }
    if ($EnablePostfixMultiInstance == 1) {
        $l[] = postfix_multi_status();
    }
    if ($EnableStopPostfix == 1) {
        events("watchdog-postfix:{$EnableStopPostfix} is enabled, stopping postfix", __FUNCTION__, __LINE__);
        $cmd = "{$GLOBALS["nohup"]} /etc/init.d/postfix stop >/dev/null 2>&1 &";
        events("watchdog-postfix:{$EnableStopPostfix} is enabled, stopping postfix -> {$cmd}", __FUNCTION__, __LINE__);
        shell_exec2($cmd);
    }
    if ($EnableStopPostfix == 0) {
        $sendmail_pid_path = $GLOBALS["CLASS_UNIX"]->LOCATE_SENDMAIL_PID_PATH();
        if (strlen($sendmail_pid_path) > 3) {
            $sendmail_pid = file_get_contents($sendmail_pid_path);
            if (is_numeric($sendmail_pid)) {
                events("watchdog-postfix:Sendmail pid detected {$sendmail_pid_path} ({$sendmail_pid})", __FUNCTION__, __LINE__);
                if ($GLOBALS["CLASS_UNIX"]->process_exists($sendmail_pid)) {
                    $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill");
                    $postfix = $GLOBALS["CLASS_UNIX"]->find_program("postfix");
                    $GLOBALS["CLASS_UNIX"]->KILL_PROCESS($sendmail_pid, 9);
                    @unlink($sendmail_pid);
                    $GLOBALS["CLASS_UNIX"]->send_email_events("SendMail (pid {$sendmail_pid}) is running, kill it !!", "This action has been performed to avoid ports conflicts", "smtp");
                    shell_exec2("{$postfix} start  >/dev/null 2>&1 &");
                }
            }
        }
    }
    $postfix_path = $GLOBALS["CLASS_UNIX"]->find_program("postfix");
    $master_pid = $GLOBALS["CLASS_UNIX"]->POSTFIX_PID();
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        exec("{$postfix_path} status 2>&1", $status_results);
        while (list($num, $line) = each($status_results)) {
            if (preg_match("#PID:.+?([0-9]+)#", $line, $re)) {
                $GLOBALS["DEBUG_LOGS"][] = "postfix status: {$line}";
                $master_pid = $re[1];
            }
        }
    }
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        $master_bin_path = $GLOBALS["CLASS_UNIX"]->POSTFIX_MASTER_BIN_PATH();
        $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF($master_bin_path, true);
        events("watchdog-postfix:PIDOF({$master_bin_path},true) -> {$master_pid}", __FUNCTION__, __LINE__);
    }
    $l[] = "[POSTFIX]";
    $l[] = "service_name=APP_POSTFIX";
    $l[] = "master_version=" . postfix_version();
    $l[] = "service_cmd=/etc/init.d/postfix";
    $l[] = "service_disabled=1";
    $l[] = "remove_cmd=--postfix-remove";
    $l[] = "family=postfix";
    $l[] = "watchdog_features=1";
    if ($GLOBALS["ArticaWatchDogList"]["APP_POSTFIX"] == null) {
        $GLOBALS["ArticaWatchDogList"]["APP_POSTFIX"] = 1;
    }
    if ($EnableStopPostfix == 0) {
        if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            if (!$GLOBALS["DISABLE_WATCHDOG"]) {
                $GLOBALS["DEBUG_LOGS"][] = "{$master_pid} does not exists";
                if ($GLOBALS["ArticaWatchDogList"]["APP_POSTFIX"] == 1) {
                    $postfix_path = $GLOBALS["CLASS_UNIX"]->find_program("postfix");
                    $GLOBALS["DEBUG_LOGS"][] = "Postfix bin = {$postfix_path}";
                    exec("{$postfix_path} start -v 2>&1", $pstfix_start);
                    $GLOBALS["CLASS_UNIX"]->send_email_events("APP_POSTFIX stopped (watchdog)", "Artica will try to start it\n" . @implode("\n", $pstfix_start) . "\n" . @implode("\n", $GLOBALS["DEBUG_LOGS"]), "postfix");
                    unset($GLOBALS["DEBUG_LOGS"]);
                }
            }
            $l[] = "";
            return implode("\n", $l);
            return;
        }
    }
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postfix.iptables.php --export-drop >/dev/null 2>&1 &";
    shell_exec2($cmd);
    $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.smtp-senderadv.php >/dev/null 2>&1 &";
    shell_exec2($cmd);
    $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postqueue.watchdog.php >/dev/null 2>&1 &";
    shell_exec2($cmd);
    $timefile = "/etc/artica-postfix/pids/postqueue.clean.time";
    $exTime = $GLOBALS["CLASS_UNIX"]->file_time_min($timefile);
    if ($exTime > 5) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postfix-logger.php --postqueue-clean >/dev/null 2>&1 &";
        shell_exec2($cmd);
    }
    $timefile = "/etc/artica-postfix/pids/postqueue.cnx-errors.time";
    $exTime = $GLOBALS["CLASS_UNIX"]->file_time_min($timefile);
    if ($exTime > 7) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postfix-logger.php --cnx-errors >/dev/null 2>&1 &";
        shell_exec2($cmd);
    }
    $timefile = "/etc/artica-postfix/pids/postqueue.cnx-only.time";
    $exTime = $GLOBALS["CLASS_UNIX"]->file_time_min($timefile);
    if ($exTime > 8) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postfix-logger.php --cnx-only >/dev/null 2>&1 &";
        shell_exec2($cmd);
    }
    $timefile = "/etc/artica-postfix/pids/exec.postfix.stats.hours.php.time";
    $exTime = $GLOBALS["CLASS_UNIX"]->file_time_min($timefile);
    if ($exTime > 60) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.postfix.stats.hours.php >/dev/null 2>&1 &";
        shell_exec2($cmd);
    }
    return implode("\n", $l);
    return;
}
コード例 #2
0
ファイル: exec.status.php プロジェクト: articatech/artica
function postfix_multi_status()
{
    if (!is_array($GLOBALS["MULTI-INSTANCES-LIST"])) {
        $calc = true;
    }
    if ($GLOBALS["MULTI-INSTANCES-TIME"] == null) {
        $cacl = true;
    }
    if (calc_time_min($GLOBALS["MULTI-INSTANCES-TIME"]) > 5) {
        $cacl = true;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "GetVersionOf(postfix) line:" . __LINE__ . "\n";
    }
    $version = postfix_version();
    if ($GLOBALS["VERBOSE"]) {
        echo "calc=\"{$cacl}\" postfix v{$version}\n";
    }
    if ($calc) {
        if ($GLOBALS["VERBOSE"]) {
            echo "POSTFIX_MULTI_INSTANCES_LIST() line:" . __LINE__ . "\n";
        }
        $GLOBALS["MULTI-INSTANCES-LIST"] = $GLOBALS["CLASS_UNIX"]->POSTFIX_MULTI_INSTANCES_LIST();
        $GLOBALS["MULTI-INSTANCES-TIME"] = time();
    }
    if (is_array($GLOBALS["MULTI-INSTANCES-LIST"])) {
        while (list($num, $instance) = each($GLOBALS["MULTI-INSTANCES-LIST"])) {
            if ($instance == null) {
                continue;
            }
            $l[] = "[POSTFIX-MULTI-{$instance}]";
            $l[] = "service_name={$instance}";
            $l[] = "master_version=" . GetVersionOf("postfix");
            $l[] = "service_cmd=postfix-multi";
            $l[] = "service_disabled=1";
            $l[] = "remove_cmd=--postfix-remove";
            $l[] = "family=postfix";
            $master_pid = $GLOBALS["CLASS_UNIX"]->POSTFIX_MULTI_PID($instance);
            if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
                $l[] = "";
                return implode("\n", $l);
                return;
            }
            $l[] = GetMemoriesOf($master_pid);
            $l[] = "";
        }
    }
    if (is_array($l)) {
        return implode("\n", $l);
    }
}