Example #1
0
$pidfileTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".MAIN.pid.time";
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
    system_admin_events("Already process {$pid} exists", __FUNCTION__, __FILE__, __LINE__, "clean");
    die;
}
if (system_is_overloaded()) {
    system_admin_events("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__, "clean");
}
$t = time();
system_admin_events("Starting cleaning ipband table...", __FUNCTION__, __FILE__, __LINE__, "clean");
ipband_clean();
system_admin_events("Starting cleaning events table...", __FUNCTION__, __FILE__, __LINE__, "clean");
CleanEvents();
system_admin_events("Starting cleaning maillog table...", __FUNCTION__, __FILE__, __LINE__, "clean");
clean_maillogs();
system_admin_events("Starting cleaning squid statistics table...", __FUNCTION__, __FILE__, __LINE__, "clean");
clean_squid_stats_dbs();
clean_squid_stats_no_items();
$took = $unix->distanceOfTimeInWords($t, time(), true);
system_admin_events("Finish, took {$took}", __FUNCTION__, __FILE__, __LINE__, "clean");
function ipband_clean()
{
    $q = new mysql();
    $sock = new sockets();
    $array = unserialize(base64_decode($sock->GET_INFO("ipbandClean")));
    $MAX_DAY = $array["MAX_DAYS"];
    $MAX_ROWS = $array["MAX_ROWS"];
    if (!is_numeric($MAX_ROWS)) {
        $MAX_ROWS = 1000000;
    }
Example #2
0
function awstats_mail()
{
    $users = new usersMenus();
    if (!$users->POSTFIX_INSTALLED) {
        return;
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $oldpid = @file_get_contents($pidfile);
    if ($unix->process_exists($oldpid, basename(__FILE__))) {
        echo "{$oldpid} is already in memory\n";
        return;
    }
    $pid = posix_getpid();
    echo "running {$pid} PID\n";
    @file_put_contents($pidfile, $pid);
    $tt1 = time();
    $nohup = $unix->find_program("nohup");
    if (!$users->awstats_installed) {
        $unix->send_email_events("awstats is not installed, artica will install it itself", $q->mysql_error, "postfix");
        shell_exec(trim("{$nohup} /usr/share/artica-postfix/bin/artica-make APP_AWSTATS >/dev/null &"));
        return;
    }
    $sock = new sockets();
    $GLOBALS["EnablePostfixMultiInstance"] = $sock->GET_INFO("EnablePostfixMultiInstance");
    $GLOBALS["maillogconvert"] = $unix->LOCATE_maillogconvert();
    $GLOBALS["zcat"] = $unix->find_program("zcat");
    $GLOBALS["perl"] = $unix->find_program("perl");
    $GLOBALS["nice"] = EXEC_NICE();
    $GLOBALS["sed"] = $unix->find_program("sed");
    if ($GLOBALS["VERBOSE"]) {
        echo "maillogconvert..........:{$GLOBALS["maillogconvert"]}\n";
        echo "zcat....................:{$GLOBALS["zcat"]}\n";
        echo "perl....................:{$GLOBALS["perl"]}\n";
        echo "nice....................:{$GLOBALS["nice"]}\n";
        echo "sed.....................:{$GLOBALS["sed"]}\n";
    }
    if (strlen($GLOBALS["maillogconvert"]) == null) {
        echo "maillogconvert.pl, no such file\n";
        return;
    }
    @mkdir("/var/log/mail-backup", 666, true);
    foreach (glob("/var/log/mail.log.*.gz") as $filename) {
        shell_exec("{$GLOBALS["nice"]}{$GLOBALS["zcat"]} {$filename} >/tmp/mail.log");
        $t1 = time();
        prepflog("/tmp/mail.log");
        $distanceOfTimeInWords = distanceOfTimeInWords($t1, time());
        shell_exec("/bin/mv {$filename} /var/log/mail-backup/");
        if ($GLOBALS["VERBOSE"]) {
            echo basename($filename) . " {$distanceOfTimeInWords}\n";
        }
        $ev[] = basename($filename) . " " . $distanceOfTimeInWords;
        @unlink("/tmp/mail.log");
    }
    foreach (glob("/var/log/mail.log.*") as $filename) {
        if (!preg_match("#\\.[0-9]+\$#", basename($filename))) {
            if ($GLOBALS["VERBOSE"]) {
                echo basename($filename) . " SKIP\n";
            }
            continue;
        }
        $t1 = time();
        prepflog($filename);
        $distanceOfTimeInWords = distanceOfTimeInWords($t1, time());
        if ($GLOBALS["VERBOSE"]) {
            echo basename($filename) . " {$distanceOfTimeInWords}\n";
        }
        $ev[] = basename($filename) . " " . $distanceOfTimeInWords;
        shell_exec("/bin/mv {$filename} /var/log/mail-backup/");
    }
    $t1 = time();
    prepflog("/var/log/mail.log");
    $distanceOfTimeInWords = distanceOfTimeInWords($t1, time());
    $ev[] = basename("/var/log/mail.log") . " " . $distanceOfTimeInWords;
    if ($GLOBALS["VERBOSE"]) {
        echo basename("/var/log/mail.log") . " {$distanceOfTimeInWords}\n";
    }
    //$cmd="$nice$perl /usr/share/artica-postfix/bin/prepflog.pl </tmp/mail.log|$nice$perl $maillogconvert standard >>/var/log/artica-postfix/awstats-postfix.stats";
    foreach (glob("/var/log/artica-mail/*.stats") as $filename) {
        if (preg_match("#(.+?)\\.([0-9]+)\\.stats#", basename($filename), $re)) {
            $instance = $re[1];
            $time = $re[2];
            $cmd = "{$GLOBALS["nice"]}{$GLOBALS["perl"]} {$GLOBALS["maillogconvert"]} standard< {$filename} >/var/log/artica-mail/{$instance}.{$time}.aws";
            if ($GLOBALS["VERBOSE"]) {
                echo "{$cmd}\n";
            }
            shell_exec($cmd);
            @unlink($filename);
        }
    }
    $filecount = 0;
    foreach (glob("/var/log/artica-mail/*.aws") as $filename) {
        artica_parse($filename);
        $filecount++;
        $filecountl[] = $filename;
    }
    $distanceOfTimeInWords = distanceOfTimeInWords($tt1, time());
    if ($filecount > 0) {
        $unix->send_email_events("AWSTATS:: Success generating {$filecount} stats files ({$distanceOfTimeInWords})", @implode("\n", $filename), "postfix");
        $cmd = "{$GLOBALS["nice"]}" . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-postfix-events >/dev/null 2>&1 &";
        shell_exec($cmd);
    }
    clean_maillogs();
}