Esempio n. 1
0
$users = new usersMenus();
if (!$users->POSTFIX_INSTALLED) {
    die;
}
$GLOBALS["CLASS_UNIX"] = new unix();
events("Executed " . @implode(" ", $argv));
if ($argv[1] == "--days") {
    STATS_BuildDayTables();
    return;
}
if ($argv[1] == "--month") {
    STATS_BuildMonthTables();
    return;
}
if ($argv[1] == "--hourly-cnx") {
    STATS_hourly_cnx_to_daily_cnx();
    return;
}
function STATS_BuildDayTables()
{
    $unix = new unix();
    $GLOBALS["DAYSTATS"] = 0;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Already PID {$pid} running since {$timepid}mn", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $GLOBALS["Q"] = new mysql_postfix_builder();
    $GLOBALS["Q"]->CheckTables();
Esempio n. 2
0
function STATS_BuildCurrentTable()
{
    $unix = new unix();
    $maxInstances = 3;
    $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__));
    if (count($pids) > $maxInstances) {
        if ($GLOBALS["VERBOSE"]) {
            echo count($pids) . " > {$maxInstances}\n";
        }
        events(count($pids) . " > {$maxInstances}, aborting");
        die;
    }
    $pidefile = "/etc/artica-postfix/pids/exec.postfix-stats.php.STATS_BuildCurrentTable.pid";
    $pid = $unix->get_pid_from_file($pidefile);
    if ($unix->process_exists($pid)) {
        die;
    }
    file_put_contents($pidefile, $pid);
    $unix = new unix();
    $timefile = "/etc/artica-postfix/pids/exec.postfix-stats.php.STATS_BuildCurrentTable.time";
    $timesched = $unix->file_time_min($timefile);
    if ($timesched < 1) {
        events("{$timesched}Mn need at least 1mn");
        return;
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $Files = $unix->DirFiles("/home/artica/postfix/postfix/logger", "^realtime\\.[0-9]+\\.db");
    events(count($Files) . " realtime files to parse...");
    $current = "realtime." . date("YmdHi") . ".db";
    $c = 0;
    while (list($filename, $none) = each($Files)) {
        $c++;
        if ($filename == $current) {
            continue;
        }
        if (!preg_match("#^realtime\\.[0-9]+\\.db\$#", $filename, $re)) {
            continue;
        }
        $path = "/home/artica/postfix/postfix/logger/{$filename}";
        $LOCKFILE = "{$path}.LCK";
        if (isLocked($path)) {
            continue;
        }
        @unlink($LOCKFILE);
        @file_put_contents($LOCKFILE, getmypid());
        if (!STATS_BuildCurrentTable_parse($path)) {
            @unlink($LOCKFILE);
            continue;
        }
        echo "Remove {$path}\n";
        @unlink($path);
        @unlink($LOCKFILE);
    }
    events("STATS_CNX_ACCEPT()");
    STATS_CNX_ACCEPT();
    events("STATS_BuildCurrentWeek()");
    STATS_BuildCurrentWeek();
    events("STATS_hourly_cnx_to_daily_cnx()");
    STATS_hourly_cnx_to_daily_cnx();
}