Exemplo n.º 1
0
function MultiplesInstances_start($hostname, $ou)
{
    $hostname = trim($hostname);
    if ($hostname == null) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$GLOBALS["deflog_start"]} milter-greylist (" . __FUNCTION__ . ") return -> hostname is null\n";
        }
        return;
    }
    $unix = new unix();
    echo "{$GLOBALS["deflog_start"]} milter-greylist hostname:{$hostname} OU:({$ou}) line: " . __LINE__ . "\n";
    $main = new maincf_multi($hostname, $ou);
    $array_filters = unserialize(base64_decode($main->GET_BIGDATA("PluginsEnabled")));
    if ($array_filters["APP_MILTERGREYLIST"] == 0) {
        $enabled = false;
    }
    $pid = MultiplesInstancesPID($hostname);
    if ($unix->process_exists($pid)) {
        echo "{$GLOBALS["deflog_start"]} milter-greylist {$hostname} already running PID {$pid}\n";
        return;
    }
    echo "{$GLOBALS["deflog_start"]} milter-greylist hostname \"{$hostname}\" line: " . __LINE__ . "\n";
    $bin_path = $unix->find_program("milter-greylist");
    @mkdir("/var/spool/postfix/var/run/milter-greylist/{$hostname}", 0755, true);
    @mkdir("/var/milter-greylist/{$hostname}", 666, true);
    if (!is_file("/var/milter-greylist/{$hostname}/greylist.db")) {
        @file_put_contents("/var/milter-greylist/{$hostname}/greylist.db", " ");
    }
    shell_exec("/bin/chmod 644 /var/milter-greylist/{$hostname}/greylist.db");
    if (!is_file("/etc/milter-greylist/{$hostname}/greylist.conf")) {
        echo "{$GLOBALS["deflog_start"]} milter-greylist {$hostname} /etc/milter-greylist/{$hostname}/greylist.conf does not exists\n";
        MultiplesInstances($hostname, $ou);
        return;
    }
    $cmdline = "{$bin_path} -P /var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.pid";
    $cmdline = $cmdline . " -p /var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock";
    $cmdline = $cmdline . " -d /var/milter-greylist/{$hostname}/greylist.db";
    $cmdline = $cmdline . " -f /etc/milter-greylist/{$hostname}/greylist.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$GLOBALS["deflog_start"]} milter-greylist {$cmdline}\n";
    }
    system($cmdline);
    for ($i = 0; $i < 20; $i++) {
        $pid = MultiplesInstancesPID($hostname);
        if ($unix->process_exists($pid)) {
            echo "{$GLOBALS["deflog_start"]} milter-greylist {$hostname} started PID {$pid}\n";
            break;
        }
        sleep(1);
    }
    $pid = MultiplesInstancesPID($hostname);
    if ($unix->process_exists($pid)) {
        $main->ConfigureMilters();
    }
    for ($i = 0; $i < 10; $i++) {
        if (is_file("/var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock")) {
            break;
        }
        echo "{$GLOBALS["deflog_start"]} milter-greylist waiting greylist.sock ({$i}/10)\n";
        sleep(1);
    }
    @chown("/var/spool/postfix/var/run/milter-greylist", "postfix");
    @chgrp("/var/spool/postfix/var/run/milter-greylist", "postfix");
    @chown("/var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock", "postfix");
    @chmod("/var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock", 0777);
    @chmod("/var/spool/postfix/var/run/milter-greylist", 0755);
    $unix->chown_func("postfix", "postfix", "/var/spool/postfix/var/run/milter-greylist/*");
    $unix->chown_func("postfix", "postfix", "/var/spool/postfix/var/run/milter-greylist/{$hostname}");
    $unix->chown_func("postfix", "postfix", "/var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock");
}
Exemplo n.º 2
0
function MultiplesInstances_start($hostname, $ou)
{
    $unix = new unix();
    $main = new maincf_multi($hostname, $ou);
    echo "Starting......: milter-greylist {$hostname} ({$ou})\n";
    $array_filters = unserialize(base64_decode($main->GET_BIGDATA("PluginsEnabled")));
    if ($array_filters["APP_MILTERGREYLIST"] == 0) {
        $enabled = false;
    }
    $pid = MultiplesInstancesPID($hostname);
    if ($unix->process_exists($pid)) {
        echo "Starting......: milter-greylist {$hostname} already running PID {$pid}\n";
        return;
    }
    echo "Starting......: milter-greylist hostname \"{$hostname}\"\n";
    $bin_path = $unix->find_program("milter-greylist");
    @mkdir("/var/spool/postfix/var/run/milter-greylist/{$hostname}", 666, true);
    @mkdir("/var/milter-greylist/{$hostname}", 666, true);
    if (!is_file("/var/milter-greylist/{$hostname}/greylist.db")) {
        @file_put_contents("/var/milter-greylist/{$hostname}/greylist.db", " ");
    }
    shell_exec("/bin/chmod 644 /var/milter-greylist/{$hostname}/greylist.db");
    if (!is_file("/etc/milter-greylist/{$hostname}/greylist.conf")) {
        echo "Starting......: milter-greylist {$hostname} /etc/milter-greylist/{$hostname}/greylist.conf does not exists\n";
        MultiplesInstances($hostname, $ou);
        return;
    }
    $cmdline = "{$bin_path} -P /var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.pid";
    $cmdline = $cmdline . " -p /var/spool/postfix/var/run/milter-greylist/{$hostname}/greylist.sock";
    $cmdline = $cmdline . " -d /var/milter-greylist/{$hostname}/greylist.db";
    $cmdline = $cmdline . " -f /etc/milter-greylist/{$hostname}/greylist.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo $cmdline . "\n";
    }
    system($cmdline);
    for ($i = 0; $i < 20; $i++) {
        $pid = MultiplesInstancesPID($hostname);
        if ($unix->process_exists($pid)) {
            echo "Starting......: milter-greylist {$hostname} started PID {$pid}\n";
            break;
        }
        sleep(1);
    }
    $pid = MultiplesInstancesPID($hostname);
    if ($unix->process_exists($pid)) {
        shell_exec("/bin/chown -R postfix:postfix /var/spool/postfix/var/run");
        shell_exec("/bin/chmod -R 755 /var/spool/postfix/var/run");
        $main->ConfigureMilters();
    }
}