コード例 #1
0
    die;
}
if ($argv[1] == "--accounts") {
    accounts();
    die;
}
if ($argv[1] == "--member") {
    member($argv[2]);
    die;
}
if ($argv[1] == "--check") {
    checkTask($argv[2]);
    die;
}
if ($argv[1] == "--folders") {
    mailboxes_folders($argv[2]);
    die;
}
if ($argv[1] == "--schedules") {
    mailboxes_schedules();
    die;
}
function backup_md5($md5)
{
    $sock = new sockets();
    $unix = new unix();
    $q = new mysql();
    $backend_root = "/root/.offlineimap";
    $pidfile = "/var/run/offlineimap-{$md5}.pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
コード例 #2
0
function member($ID)
{
    $sql = "SELECT * FROM mbx_migr_users WHERE zmd5='{$ID}'";
    if ($GLOBALS["VERBOSE"]) {
        echo "ID:{$ID}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$sql}\n";
    }
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    $pid = $ligne["PID"];
    $TASKID = $ligne["mbx_migr_id"];
    $unix = new unix();
    $t1 = time();
    $NICE = EXEC_NICE();
    if ($pid != null) {
        if ($unix->process_exists($pid)) {
            system_admin_events("{$ID}:: {$pid} already executed", __FUNCTION__, __FILE__, __LINE__, "mbximport");
            die;
        }
    }
    $pid = getmypid();
    $offlineimap = $unix->find_program("offlineimap");
    $verbosed = $ligne["verbosed"];
    $debug = null;
    if (!is_numeric($verbosed)) {
        $verbosed = 0;
    }
    $sql = "UPDATE mbx_migr_users SET `PID`='{$pid}',`events`='' WHERE zmd5='{$ID}'";
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        system_admin_events("{$ID}:: {$q->mysql_error} \"{$sql}\"", __FUNCTION__, __FILE__, __LINE__, "mbximport");
        return;
    }
    mailboxes_folders($ID);
    $imap_server = $ligne["imap_server"];
    $cert_fingerprint = $ligne["cert_fingerprint"];
    $uid = $ligne["uid"];
    $usessl = $ligne["usessl"];
    $remote_username = $ligne["username"];
    $ct = new user($uid);
    $tolog[] = "{$ligne["username"]}@{$imap_server} SSL:{$usessl} Port:993/143 fingerprint:{$cert_fingerprint} Using {$offlineimap}";
    $tolog = mailbox_settings($ID, $tolog);
    exec("{$offlineimap} --version 2>&1", $tolog);
    $t = time();
    if (is_file($offlineimap)) {
        if ($verbosed == 1) {
            $debug = " -d ALL";
        }
        $cmd = "{$NICE}{$offlineimap} -u basic -l /etc/artica-postfix/offline-imap/{$ID}.log -c /etc/artica-postfix/offline-imap/{$ID}.cfg{$debug} 2>&1";
        $tolog[] = $cmd;
        if (is_file("/etc/artica-postfix/offline-imap/{$ID}.log")) {
            @unlink("/etc/artica-postfix/offline-imap/{$ID}.log");
        }
        shell_exec("{$cmd}");
        $t2 = time();
        $messages_count = 0;
        if (!is_file("/etc/artica-postfix/offline-imap/{$ID}.log")) {
            $tolog[] = "{$ID}.log no such file";
        }
        $f = file("/etc/artica-postfix/offline-imap/{$ID}.log");
        while (list($num, $pp) = each($f)) {
            $tolog[] = $pp;
            if (preg_match("#Copy message#", $pp)) {
                $messages_count++;
            }
        }
        $tolog[] = "Messages replicated.: {$messages_count}";
        $tolog[] = "Execution time......: " . distanceOfTimeInWords($t1, $t2);
    } else {
        $tolog[] = "UNABLE TO STAT OFFLINEIMAP TOOL !!!";
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    system_admin_events("{$uid} from {$imap_server} done took\n" . @implode("\n", $tolog) . "\n", __FUNCTION__, __FILE__, __LINE__, "mbximport");
    $sql = "UPDATE mbx_migr_users SET events='" . addslashes(@implode("\n", $tolog)) . "',\n\timported=1\n\tWHERE zmd5='{$ID}'";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$sql}\n";
    }
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        writelogs("{$ID}:: {$q->mysql_error} \"{$sql}\"", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    checkTask($TASKID);
}