コード例 #1
0
ファイル: gettraffic.php プロジェクト: digideskio/hypervm
function filltraffictable()
{
    global $gbl, $login, $ghtml;
    initProgram('admin');
    $t = "";
    // Fake domain to store the time the last stats finding was done.
    $laccessdom = new Vps(null, null, '__last_access_domain_');
    try {
        $laccess = $laccessdom->getFromList('vpstraffic', '__last_access_domain_');
    } catch (exception $e) {
        dprint("not getting\n");
        $laccess = null;
    }
    if (!$laccess) {
        $laccess = new Vpstraffic(null, null, '__last_access_domain_');
        $oldtime = 0;
        $laccess->parent_clname = 'vps-__last_access_domain_';
        $laccess->dbaction = 'add';
    } else {
        $oldtime = $laccess->timestamp;
    }
    if ($oldtime && time() - $oldtime > 5 * 3600 * 24) {
        $oldtime = time() - 5 * 3600 * 24;
        $laccess->timestamp = $oldtime;
        $laccess->setUpdateSubaction();
        $laccess->write();
    }
    $flag = 0;
    if ($oldtime == 0) {
        // 8 days back
        $oldtime = @mktime(00, 01, 00, date("n"), date("j") - 2, date("Y"));
        // Start of Jan
        //$oldtime  =  mktime( 00 , 01, 00 , 1 ,1, date("Y"));
        $flag = 1;
    }
    // $newtime =   mktime( 00 , 01, 00 , date("n")  , date("j")  ,date("Y"));
    $newtime = time();
    $old = $oldtime;
    $new = $newtime;
    if ($newtime - $oldtime <= 19 * 60 * 60) {
        dprint("Less than a day:");
        dprint("\n\n\n\n");
        return;
    }
    $j = 0;
    for ($i = $newtime; $i >= $oldtime; $i -= 24 * 60 * 60) {
        if ($j > 0) {
            $timearray[] = $new . "-" . $i;
        }
        $new = $i;
        $j++;
    }
    if ($flag != 1) {
        $timearray[] = $new . "-" . $oldtime;
    }
    $timearray = array_reverse($timearray);
    foreach ($timearray as $t1) {
        $t = explode("-", $t1);
        $newtime = $t[0];
        $oldtime = $t[1];
        if ($newtime - $oldtime < 4 * 60 * 60) {
            continue;
        }
        $o = @strftime("%c", $oldtime);
        $n = @strftime("%c", $newtime);
        print "\n\n{$o}  to ... {$n}\n\n";
        findtraffic($oldtime, $newtime);
        // Write every time, otherwise, the traffic calculation breaks off in the middle, it will be left inconsistent.
        $laccess->timestamp = $newtime;
        $laccess->setUpdateSubaction();
        $laccess->write();
    }
    // This is the time at which this was run last time.
    $laccess->timestamp = time();
    $laccess->setUpdateSubaction();
    $laccess->write();
}
コード例 #2
0
ファイル: gettraffic.php プロジェクト: soar-team/kloxo
function filltraffictable()
{
    global $gbl, $login, $ghtml;
    initProgram('admin');
    $login->loadAllObjects('client');
    $clist = $login->getList('client');
    $t = "";
    // Fake domain to store the time the last stats finding was done.
    $laccessdom = new Domain(null, null, '__last_access_domain_');
    try {
        $laccess = $laccessdom->getFromList('domaintraffic', '__last_access_domain_');
    } catch (exception $e) {
        dprint("not getting\n");
        $laccess = null;
    }
    if (!$laccess) {
        $laccess = new Domaintraffic(null, null, '__last_access_domain_');
        $oldtime = 0;
        $laccess->parent_clname = 'domain-__last_access_domain_';
        $laccess->dbaction = 'add';
    } else {
        $oldtime = $laccess->timestamp;
    }
    if ($oldtime && time() - $oldtime > 12 * 3600 * 24) {
        $oldtime = time() - 12 * 3600 * 24;
        $laccess->timestamp = $oldtime;
        $laccess->setUpdateSubaction();
        $laccess->write();
    }
    foreach ($clist as $c) {
        $domlist = $c->getList('domain');
        foreach ((array) $domlist as $domain) {
            if (!$domain->isDomainVirtual()) {
                continue;
            }
            $web = $domain->getObject('web');
            $mmail = $domain->getObject('mmail');
            $globaldomlist[$domain->nname] = $domain;
            $weblist[$web->syncserver][] = $domain;
            $mmaillist[$mmail->syncserver][] = $mmail;
        }
    }
    $flag = 0;
    if ($oldtime == 0) {
        // 8 days back
        $oldtime = @mktime(00, 01, 00, date("n"), date("j") - 10, date("Y"));
        // Start of Jan
        //$oldtime  =  mktime( 00 , 01, 00 , 1 ,1, date("Y"));
        $flag = 1;
    }
    // $newtime =   mktime( 00 , 01, 00 , date("n")  , date("j")  ,date("Y"));
    $newtime = time();
    $old = $oldtime;
    $new = $newtime;
    if ($newtime - $oldtime >= 19 * 60 * 60) {
        if ($flag == 1) {
            $old = @mktime(00, 01, 00, @date("n"), @date("j"), @date("Y"));
            $timearray[0] = $newtime . "-" . $old;
            $newtime = $old;
        }
        $j = 0;
        for ($i = $newtime; $i >= $oldtime; $i -= 24 * 60 * 60) {
            if ($j > 0) {
                $timearray[] = $new . "-" . $i;
            }
            $new = $i;
            $j++;
        }
        if ($flag != 1) {
            $timearray[] = "{$new}-{$oldtime}";
        }
        $timearray = array_reverse($timearray);
        foreach ($timearray as $t1) {
            $t = explode("-", $t1);
            $newtime = $t[0];
            $oldtime = $t[1];
            if ($newtime - $oldtime < 4 * 60 * 60) {
                continue;
            }
            $o = @strftime("%c", $oldtime);
            $n = @strftime("%c", $newtime);
            print "\n\n{$o}  to ... {$n}\n\n";
            findtraffic($weblist, $mmaillist, $globaldomlist, $oldtime, $newtime);
            $laccess->timestamp = $newtime;
            $laccess->setUpdateSubaction();
            $laccess->write();
        }
        // This is the time at which this was run last time.
        $laccess->timestamp = time();
        $laccess->setUpdateSubaction();
        $laccess->write();
    } else {
        dprint("Less than a day:");
        dprint("\n\n\n\n");
    }
}