Beispiel #1
0
function clients_hours($nopid = false)
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if (!$nopid) {
        $oldpid = @file_get_contents($pidfile);
        if ($unix->process_exists($oldpid)) {
            die;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    $currenttable = "dansguardian_events_" . date('Ymd');
    $next_table = date('Ymd') . "_hour";
    _clients_hours_perfom($currenttable, $next_table);
    table_days();
    $q = new mysql_squid_builder();
    $sql = "SELECT DATE_FORMAT(zDate,'%Y%m%d') as suffix,tablename FROM tables_day WHERE Hour=0";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        events_tail("{$q->mysql_error}");
        return;
    }
    $num_rows = mysql_num_rows($results);
    if ($num_rows == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "No datas " . __FUNCTION__ . " " . __LINE__ . "\n";
        }
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $next_table = $ligne["suffix"] . "_hour";
        if (!$q->CreateHourTable($next_table)) {
            events_tail("Failed to create {$next_table}");
            return;
        }
        if (!_clients_hours_perfom($ligne["tablename"], $next_table)) {
            events_tail("Failed to process {$ligne["tablename"]} to {$next_table}");
            return;
        }
    }
}
function clients_hours($nopid = false)
{
    if ($GLOBALS["VERBOSE"]) {
        echo "L.[" . __LINE__ . "]: processing clients_hours()\n";
    }
    if (isset($GLOBALS["clients_hours_executed"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo "clients_hours():: Already executed\n";
        }
        return true;
    }
    $GLOBALS["clients_hours_executed"] = true;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if (!$nopid) {
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            writelogs("Already executed pid:{$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    $currenttable = "dansguardian_events_" . date('Ymd');
    $next_table = date('Ymd') . "_hour";
    echo "L.[" . __LINE__ . "]:_clients_hours_perfom({$currenttable},{$next_table})\n";
    _clients_hours_perfom($currenttable, $next_table);
    $q = new mysql_squid_builder();
    $sql = "SELECT DATE_FORMAT(zDate,'%Y%m%d') as suffix,tablename FROM tables_day WHERE Hour=0";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        events_tail("{$q->mysql_error}");
        return;
    }
    $num_rows = mysql_num_rows($results);
    if ($num_rows == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "clients_hours():: No datas " . __FUNCTION__ . " " . __LINE__ . "\n";
        }
        return;
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $next_table = $ligne["suffix"] . "_hour";
        if (!$q->CreateHourTable($next_table)) {
            events_tail("Failed to create {$next_table}");
            return;
        }
        if (!_clients_hours_perfom($ligne["tablename"], $next_table)) {
            events_tail("Failed to process {$ligne["tablename"]} to {$next_table}");
            return;
        }
        $q->QUERY_SQL("UPDATE tables_day SET `Hour`=1 WHERE tablename='{$ligne["tablename"]}'");
    }
}