예제 #1
0
function CleanDirLogs($path)
{
    return;
    if ($GLOBALS["VERBOSE"]) {
        echo "CleanDirLogs({$path})\n";
    }
    $BigSize = false;
    if ($path == '/var/log') {
        $BigSize = true;
    }
    if ($GLOBALS["ArticaMaxLogsSize"] < 100) {
        $GLOBALS["ArticaMaxLogsSize"] = 100;
    }
    $maxday = $GLOBALS["MaxTempLogFilesDay"] * 24;
    $maxday = $maxday * 60;
    $users = new usersMenus();
    $maillog_path = $users->maillog_path;
    $unix = new unix();
    $sock = new sockets();
    $restartSyslog = false;
    if ($path == null) {
        return;
    }
    $countfile = 0;
    foreach (glob("{$path}/*") as $filepath) {
        if ($filepath == null) {
            continue;
        }
        if (is_link($filepath)) {
            continue;
        }
        if (is_dir($filepath)) {
            continue;
        }
        if ($filepath == $maillog_path) {
            continue;
        }
        if (preg_match("#\\/log\\/artica-postfix\\/#", $filepath)) {
            continue;
        }
        $countfile++;
        if ($countfile > 500) {
            if (is_overloaded()) {
                $unix->send_email_events("Clean Files: [{$path}/*] System is overloaded ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}", "The clean logs function is stopped and wait a new schedule with best performances", "logs_cleaning");
                die;
            }
            $countfile = 0;
        }
        usleep(300);
        $size = round(unix_file_size("{$filepath}") / 1024);
        $time = $unix->file_time_min($filepath);
        $unix->events("{$filepath} {$size} Ko, {$time}Mn/{$maxday}Mn TTL");
        if ($size > $GLOBALS["ArticaMaxLogsSize"]) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Delete {$filepath}\n";
            }
            $restartSyslog = true;
            $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $size;
            $GLOBALS["DELETED_FILES"] = $GLOBALS["DELETED_FILES"] + 1;
            $GLOBALS["UNLINKED"][] = $filepath;
            @unlink($filepath);
            continue;
        }
        if ($time > $maxday) {
            $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $size;
            $GLOBALS["DELETED_FILES"] = $GLOBALS["DELETED_FILES"] + 1;
            if ($GLOBALS["VERBOSE"]) {
                echo "Delete {$filepath}\n";
            }
            @unlink($filepath);
            $GLOBALS["UNLINKED"][] = $filepath;
            $restartSyslog = true;
            continue;
        }
    }
    if ($restartSyslog) {
        $unix->send_email_events("System log will be restarted", "Logs files was deleted and log daemons will be restarted\n\t\t\t" . @implode("\n", $GLOBALS["UNLINKED"]), "logs_cleaning");
        $unix->RESTART_SYSLOG();
    }
}
예제 #2
0
function debian_size()
{
    $sock = new sockets();
    $unix = new unix();
    $MirrorEnableDebian = $sock->GET_INFO("MirrorEnableDebian");
    $MirrorDebianDir = $sock->GET_INFO("MirrorDebianDir");
    $MirrorDebianBW = $sock->GET_INFO("MirrorDebianBW");
    if (!is_numeric($MirrorEnableDebian)) {
        $MirrorEnableDebian = 0;
    }
    if (!is_numeric($MirrorDebianBW)) {
        $MirrorDebianBW = 500;
    }
    if ($MirrorDebianDir == null) {
        $MirrorDebianDir = "/home/mirrors/Debian";
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $extime = $unix->file_time_min($pidTime);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$extime}Mn\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        writelogs("Already process exists pid {$pid} running since {$time}mn", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        $TIME = $unix->file_time_min($pidTime);
        if ($unix->file_time_min($pidTime) < 30) {
            writelogs("`{$pidTime}` {$TIME}mn, require 30mn, aborting", __FUNCTION__, __FILE__, __LINE__);
            ChecksLogs();
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    if (is_overloaded()) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Overloaded system...\n";
        }
        return;
    }
    $nice = $unix->EXEC_NICE();
    $du = $unix->find_program("du");
    if ($GLOBALS["VERBOSE"]) {
        echo "{$nice} {$du} -s -b {$MirrorDebianDir} 2>&1\n";
    }
    writelogs("{$nice} {$du} -s -b {$MirrorDebianDir} 2>&1", __FUNCTION__, __FILE__, __LINE__);
    exec("{$nice} {$du} -s -b {$MirrorDebianDir} 2>&1", $results);
    writelogs("Done...", __FUNCTION__, __FILE__, __LINE__);
    while (list($num, $val) = each($results)) {
        if (!preg_match("#^([0-9\\.]+)\\s+#", $val, $re)) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$re[1]} Bytes...\n";
        }
        $sock->SET_INFO("MirrorDebianDirSize", $re[1]);
    }
    ChecksLogs();
}