示例#1
0
function build_line($ligne)
{
    $sock = new sockets();
    $unix = new unix();
    $EnablePostfixMultiInstance = $sock->GET_INFO("EnablePostfixMultiInstance");
    $fetchmail_version = fetchmail_version();
    if (!isset($GLOBALS["FetchMailToZarafa"])) {
        $GLOBALS["FetchMailToZarafa"] = $sock->GET_INFO("FetchMailToZarafa");
        if (!is_numeric($GLOBALS["FetchMailToZarafa"])) {
            $GLOBALS["FetchMailToZarafa"] = 1;
        }
    }
    if (!isset($GLOBALS["ZARAFA_D_AGENT_BIN"])) {
        $GLOBALS["ZARAFA_D_AGENT_BIN"] = $unix->find_program("zarafa-dagent");
        if (!is_file($GLOBALS["ZARAFA_D_AGENT_BIN"])) {
            $GLOBALS["FetchMailToZarafa"] = 0;
        }
    }
    if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)#", $fetchmail_version, $re)) {
        $MAJOR = $re[1];
        $MINOR = $re[2];
        $REV = $re[3];
    }
    $ID = $ligne["ID"];
    writelogs("Building fetchmail rule for ID: {$ligne["ID"]},Zarafa Dagent:`{$GLOBALS["ZARAFA_D_AGENT_BIN"]}`  user:{$ligne["uid"]}, FetchMailToZarafa:{$GLOBALS["FetchMailToZarafa"]}", __FUNCTION__, __FILE__, __LINE__);
    $ligne["poll"] = trim($ligne["poll"]);
    if ($ligne["poll"] == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} rule {$ligne["ID"]} as no poll, skip it..\n";
        return;
    }
    if ($ligne["proto"] == null) {
        $ligne["proto"] = "auto";
    }
    if ($ligne["uid"] == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} rule {$ligne["ID"]} as no uid, skip it..\n";
        return;
    }
    writelogs("Building \$user->user({$ligne["uid"]})", __FUNCTION__, __FILE__, __LINE__);
    $user = new user($ligne["uid"]);
    writelogs("Building {$user->mail}", __FUNCTION__, __FILE__, __LINE__);
    if (trim($user->mail) == null) {
        writelogs("Building fetchmail uid has no mail !!!, skip it.. user:{$ligne["uid"]}", __FUNCTION__, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} uid has no mail !!!, skip it..\n";
        $unix->send_email_events("Fetchmail rule for {$ligne["uid"]}/{$ligne["poll"]} has been skipped", "cannot read email address from LDAP", "mailbox");
        return;
    }
    $ligne["is"] = $user->mail;
    $smtphost = null;
    $sslfingerprint = null;
    $fetchall = null;
    $timeout = null;
    $port = null;
    $aka = null;
    $folder = null;
    $tracepolls = null;
    $interval = null;
    $keep = null;
    $fetchall = null;
    $sslcertck = null;
    $limit = null;
    $dropdelivered = null;
    $smtpport = null;
    $multidrop = null;
    if ($ligne["proto"] == "httpp") {
        $ligne["proto"] = "pop3";
    }
    if (!isset($ligne["folder"])) {
        $ligne["folder"] = null;
    }
    if (!is_numeric($ligne["UseDefaultSMTP"])) {
        $ligne["UseDefaultSMTP"] = 1;
    }
    if (trim($ligne["port"]) > 0) {
        $port = "port {$ligne["port"]}";
    }
    if (trim($ligne["aka"]) != null) {
        $aka = "\n\taka {$ligne["aka"]}";
    }
    if ($ligne["ssl"] == 1) {
        $ssl = "\n\tssl\n\tsslproto ''";
    }
    if ($ligne["timeout"] > 0) {
        $timeout = "\n\ttimeout {$ligne["timeout"]}";
    }
    if ($ligne["folder"] != null) {
        $folder = "\n\tfolder {$ligne["folder"]}";
    }
    if ($ligne["tracepolls"] == 1) {
        $tracepolls = "\n\ttracepolls";
    }
    if ($ligne["interval"] > 0) {
        $interval = "\n\tinterval {$ligne["interval"]}";
    }
    if ($ligne["keep"] == 1) {
        $keep = "\n\tkeep ";
    }
    if ($ligne["keep"] == 0) {
        $keep = "\n\tnokeep";
    }
    if ($ligne["multidrop"] == 1) {
        $ligne["is"] = "*";
    }
    if ($ligne["fetchall"] == 1) {
        $fetchall = "\n\tfetchall";
    }
    if (strlen(trim($ligne["sslfingerprint"])) > 10) {
        $sslfingerprint = "\n\tsslfingerprint '{$ligne["sslfingerprint"]}'";
    }
    if ($ligne["sslcertck"] == 1) {
        $sslcertck = "\n\tsslcertck";
    }
    if ($GLOBALS["FetchMailGLobalDropDelivered"] == 1) {
        $ligne["dropdelivered"] = 1;
    }
    if (!is_numeric($ligne["limit"])) {
        $ligne["limit"] = 2097152;
    }
    if ($ligne["limit"] == 0) {
        $ligne["limit"] = 2097152;
    }
    if (!isset($ligne["smtp_port"])) {
        $ligne["smtp_port"] = 25;
    }
    if (!isset($ligne["smtp_host"])) {
        $ligne["smtp_host"] = "127.0.0.1";
    }
    if (!is_numeric($ligne["smtp_port"])) {
        $ligne["smtp_port"] = 25;
    }
    if (trim($ligne["smtp_host"]) == null) {
        $ligne["smtp_host"] = "127.0.0.1";
    }
    if ($ligne["smtp_port"] != 25) {
        $smtpport = "/{$ligne["smtp_port"]}";
    }
    $smtp = "\n\tsmtphost {$ligne["smtp_host"]}{$smtpport}";
    $limit = "\n\tlimit {$ligne["limit"]}";
    if ($ligne["dropdelivered"] == 1) {
        $dropdelivered = "\n\tdropdelivered is {$ligne["is"]} here";
    }
    if ($GLOBALS["FetchMailToZarafa"] == 1) {
        if ($ligne["UseDefaultSMTP"] == 1) {
            $smtp = "\n\tmda \"{$GLOBALS["ZARAFA_D_AGENT_BIN"]} {$ligne["uid"]}\"";
        }
    }
    $tf = array();
    $folders = unserialize(base64_decode($ligne["folders"]));
    if ($GLOBALS["VERBOSE"]) {
        echo "Folder: " . count($folders) . " items\n";
    }
    if (is_array($folders)) {
        if (count($folders) > 0) {
            while (list($md, $fenc) = each($folders)) {
                $fff = base64_decode($fenc);
                if ($GLOBALS["VERBOSE"]) {
                    echo "Folder: `{$fff}`\n";
                }
                $tf[] = "\"{$fff}\"";
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Folder: final -> " . count($folders) . " items\n";
    }
    if (count($tf) > 0) {
        $folder = "\n\tfolder INBOX," . @implode(",", $tf);
    }
    if ($EnablePostfixMultiInstance == 1) {
        if ($GLOBALS["DEBUG"]) {
            echo "multiple instances::poll={$ligne["poll"]} smtp_host={$ligne["smtp_host"]}\n";
        }
        if (strlen(trim($ligne["smtp_host"])) == 0) {
            continue;
        }
        $smtphost = "\n\tsmtphost " . multi_get_smtp_ip($ligne["smtp_host"]);
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} poll {$ligne["poll"]} - version {$MAJOR}.{$MINOR}.{$REV}\n";
    if ($MAJOR < 7) {
        if ($MINOR < 4) {
            if ($REV < 21) {
                if (trim($ssl) == null) {
                    $ssl = "\n\tsslproto ssl23\n\tno ssl";
                }
            }
        }
    }
    $pattern = "poll {$ligne["poll"]}{$tracepolls}\n\tproto {$ligne["proto"]} {$port}{$interval}{$timeout}{$aka}\n\tuser \"{$ligne["user"]}\"\n\tpass {$ligne["pass"]}\n\tis {$ligne["is"]}{$dropdelivered}{$folder}{$ssl}{$fetchall}{$keep}{$multidrop}{$sslfingerprint}{$sslcertck}{$smtphost}{$limit}{$smtp}\n\n";
    if ($GLOBALS["DEBUG"]) {
        echo "{$pattern}\n";
    }
    $GLOBALS["multi_smtp"][$ligne["smtp_host"]][] = $pattern;
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} poll {$ligne["poll"]} -> {$ligne["user"]} limit " . round($ligne["limit"] / 1024) / 1024 . " Mo\n";
    return $pattern;
}
示例#2
0
function fetchmail()
{
    if (!$GLOBALS["CLASS_USERS"]->fetchmail_installed) {
        return null;
    }
    $EnablePostfixMultiInstance = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnablePostfixMultiInstance");
    $EnableFetchmailScheduler = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableFetchmailScheduler");
    $enabled = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableFetchmail");
    if (!is_numeric($enabled)) {
        $enabled = 0;
    }
    if (!is_numeric($EnableFetchmailScheduler)) {
        $EnableFetchmailScheduler = 0;
    }
    if ($EnableFetchmailScheduler == 1) {
        return;
    }
    $DisableMessaging = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableMessaging"));
    if ($DisableMessaging == 1) {
        $enabled = 0;
    }
    if ($EnablePostfixMultiInstance != 1) {
        if (!is_file("/etc/fetchmailrc")) {
            $enabled = 0;
        }
        $master_pid = trim(@file_get_contents("/var/run/fetchmail.pid"));
        if (preg_match("#^([0-9]+)#", $master_pid, $re)) {
            $master_pid = $re[1];
        }
        $l[] = "[FETCHMAIL]";
        $l[] = "service_name=APP_FETCHMAIL";
        $l[] = "master_version=" . fetchmail_version();
        $l[] = "service_cmd=/etc/init.d/fetchmail";
        $l[] = "service_disabled={$enabled}";
        $l[] = "watchdog_features=1";
        $l[] = "family=mailbox";
        if ($enabled == 1) {
            $fetchmail_count_server = fetchmail_count_server();
            if ($GLOBALS["VERBOSE"]) {
                echo "fetchmail_count_server: {$fetchmail_count_server}\n";
            }
            if ($fetchmail_count_server > 0) {
                if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
                    if (!$GLOBALS["DISABLE_WATCHDOG"]) {
                        shell_exec2("{$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.initslapd.php --fetchmail >/dev/null 2>&1");
                        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.fetchmail.php --start >/dev/null 2>&1 &");
                    }
                    $l[] = "running=0\ninstalled=1";
                    $l[] = "";
                    return implode("\n", $l);
                    return;
                }
            }
        }
        if ($enabled == 0) {
            return implode("\n", $l);
            return;
        }
        if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            $l[] = "running=0";
        } else {
            $l[] = "running=1";
            $l[] = GetMemoriesOf($master_pid);
        }
        $l[] = "";
    } else {
        $enabled = 1;
    }
    $master_pid = trim(@file_get_contents("/etc/artica-postfix/exec.fetmaillog.php.pid"));
    $l[] = "[FETCHMAIL_LOGGER]";
    $l[] = "service_name=APP_FETCHMAIL_LOGGER";
    $l[] = "master_version=" . fetchmail_version();
    $l[] = "service_cmd=fetchmail-logger";
    $l[] = "service_disabled={$enabled}";
    $l[] = "watchdog_features=1";
    if ($enabled == 1) {
        if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            $fetchmail_count_server = fetchmail_count_server();
            if ($GLOBALS["VERBOSE"]) {
                echo "fetchmail_count_server: {$fetchmail_count_server}\n";
            }
            if ($fetchmail_count_server > 0) {
                WATCHDOG("APP_FETCHMAIL_LOGGER", "fetchmail-logger");
                $l[] = "running=0\ninstalled=1";
                $l[] = "";
                return implode("\n", $l);
                return;
            } else {
                return implode("\n", $l);
                return;
            }
        }
    }
    if ($enabled == 0) {
        return implode("\n", $l);
        return;
    }
    $l[] = "running=1";
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    return implode("\n", $l);
    return;
}