Пример #1
0
function localdbsize()
{
    $unix = new unix();
    $cachefile = "/usr/share/artica-postfix/LocalDatabases/dbsize.xp";
    if (is_file($cachefile)) {
        $time = $unix->file_time_min($cachefile);
        if ($time > 30) {
            @unlink($cachefile);
        }
    }
    if (!is_file($cachefile)) {
        $size = $unix->DIRSIZE_KO("/usr/share/artica-postfix/LocalDatabases");
        if ($size > 1000) {
            @file_put_contents($cachefile, $size);
        }
    } else {
        $size = @file_get_contents($cachefile);
    }
    echo "<articadatascgi>{$size}</articadatascgi>";
}
Пример #2
0
function InfluxDbSize()
{
    $dir = "/home/ArticaStatsDB";
    $unix = new unix();
    $size = $unix->DIRSIZE_KO($dir);
    $partition = $unix->DIRPART_INFO($dir);
    $TOT = $partition["TOT"];
    $percent = $size / $TOT * 100;
    $percent = round($percent, 3);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$dir}: {$size} Partition {$TOT}\n";
    }
    $ARRAY["PERCENTAGE"] = $percent;
    $ARRAY["SIZEKB"] = $size;
    $ARRAY["PART"] = $TOT;
    if ($GLOBALS["VERBOSE"]) {
        print_r($ARRAY);
    }
    @unlink("/usr/share/artica-postfix/ressources/logs/web/InfluxDB.state");
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/InfluxDB.state", serialize($ARRAY));
}
Пример #3
0
function status($aspid = false)
{
    $unix = new unix();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $filetime = "/etc/artica-postfix/settings/Daemons/SargDirStatus";
    $sock = new sockets();
    $SargOutputDir = $sock->GET_INFO("SargOutputDir");
    if ($SargOutputDir == null) {
        $SargOutputDir = "/var/www/html/squid-reports";
    }
    $SIZE = $unix->DIRSIZE_KO($SargOutputDir);
    $FILES = $unix->DIR_COUNT_OF_FILES($SargOutputDir);
    $AIV = $unix->DIRECTORY_FREEM($SargOutputDir);
    $array["SIZE"] = $SIZE;
    $array["FILES"] = $FILES;
    $array["FREE"] = $AIV;
    $array["F_FREE"] = $unix->DIRECTORY_FREE_FILES($SargOutputDir);
    @unlink($filetime);
    @file_put_contents($filetime, serialize($array));
    @chmod($filetime, 0755);
}
Пример #4
0
function restore_process_array()
{
    $unix = new unix();
    $pid = $unix->PIDOF_PATTERN("exec.zarafa-db.php --restorefrom");
    if ($unix->process_exists($pid)) {
        $WORKDIR = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/ZarafaDedicateMySQLWorkDir"));
        if ($WORKDIR == null) {
            $WORKDIR = "/home/zarafa-db";
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        $ARRAY["PID"] = $pid;
        $ARRAY["TIME"] = $time;
        $ARRAY["SIZE"] = $unix->DIRSIZE_KO("{$WORKDIR}/data/zarafa");
        echo "<articadatascgi>" . base64_encode(serialize($ARRAY)) . "</articadatascgi>";
    }
}
Пример #5
0
function build()
{
    $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    // /etc/artica-postfix/pids/exec.squid.rotate.php.build.time
    $sock = new sockets();
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Already PID {$pid} is running\n";
        die;
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($timefile);
        if ($time < 60) {
            echo "Only each 60mn\n";
            die;
        }
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    $syslog = new mysql_storelogs();
    $SquidLogRotateFreq = intval($sock->GET_INFO("SquidLogRotateFreq"));
    if ($SquidLogRotateFreq < 10) {
        $SquidLogRotateFreq = 1440;
    }
    $LastRotate = $unix->file_time_min("/etc/artica-postfix/pids/squid-rotate-cache.time");
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    $SquidRotateOnlySchedule = intval($sock->GET_INFO("SquidRotateOnlySchedule"));
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $LogsRotateDeleteSize = intval($sock->GET_INFO("LogsRotateDeleteSize"));
    if ($LogsRotateDeleteSize == 0) {
        $LogsRotateDeleteSize = 5000;
    }
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    $BackupSquidLogsUseNas = intval($sock->GET_INFO("BackupSquidLogsUseNas"));
    $SquidRotateMergeFiles = $sock->GET_INFO("SquidRotateMergeFiles");
    if (!is_numeric($SquidRotateMergeFiles)) {
        $SquidRotateMergeFiles = 1;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $hostname = $unix->hostname_g();
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $LogRotateAccess = "{$LogRotatePath}/access";
    $LogRotateCache = "{$LogRotatePath}/cache";
    $syslog->events("Launch rotation only by schedule.: {$SquidRotateOnlySchedule}", __FUNCTION__, __LINE__);
    $syslog->events("SquidLogRotateFreq...............: {$SquidLogRotateFreq}Mn", __FUNCTION__, __LINE__);
    $syslog->events("LastRotate.......................: {$LastRotate}Mn", __FUNCTION__, __LINE__);
    $syslog->events("Working directory................: {$LogRotatePath}", __FUNCTION__, __LINE__);
    $syslog->events("Launch rotation when exceed......: {$LogsRotateDefaultSizeRotation}M", __FUNCTION__, __LINE__);
    $syslog->events("Delete the file when exceed......: {$LogsRotateDeleteSize}M", __FUNCTION__, __LINE__);
    $syslog->events("Final storage directory..........: {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
    $syslog->events("Merge rotated files to a big file: {$SquidRotateMergeFiles}", __FUNCTION__, __LINE__);
    $syslog->events("Backup files to a NAS............: {$BackupSquidLogsUseNas}", __FUNCTION__, __LINE__);
    if ($handle = opendir("/var/run/squid")) {
        while (false !== ($file = readdir($handle))) {
            if ($file == ".") {
                continue;
            }
            if ($file == "..") {
                continue;
            }
            $path = "/var/run/squid/{$file}";
            if (preg_match("#\\.[0-9]+\\.status\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
            if (preg_match("#\\.[0-9]+\\.state\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
        }
    }
    $size = @filesize("/var/log/squid/access.log");
    $size = $size / 1024;
    $size = $size / 1024;
    $syslog->events("/var/log/squid/access.log........: {$size}M", __FUNCTION__, __LINE__);
    $syslog->events("Analyze /var/log/squid directory for cache.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^cache\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotateCache}", 0755, true);
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            $destfile = "{$LogRotateCache}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    $syslog->events("Analyze /var/log/squid directory for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^access\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotatePath}", 0755, true);
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    @mkdir($LogRotateAccess, 0755, true);
    $syslog->events("Analyze {$LogRotateAccess} for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir($LogRotateAccess))) {
        $syslog->events("Unable to open {$LogRotateAccess} directory.", __FUNCTION__, __LINE__);
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "{$LogRotateAccess}/{$file}";
            echo "OPEN {$path}\n";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^access\\.log#", $file)) {
                continue;
            }
            range_fichier_source($path, $BackupMaxDaysDir);
        }
    }
    $q = new mysql();
    $sql = "CREATE TABLE IF NOT EXISTS `backuped_logs` (\n\t\t\t  `path` CHAR(255)  NOT NULL,\n\t\t\t  `zDate`  DATETIME,\n\t\t\t  `size` INT UNSIGNED NOT NULL,\n\t\t\t  PRIMARY KEY (`path`),\n\t\t\t  KEY `zDate` (`zDate`)\n\t\t\t)  ENGINE = MYISAM;";
    $q->QUERY_SQL($sql, "artica_events");
    $syslog->events("Analyze /home/logrotate/work for access.log", __FUNCTION__, __LINE__);
    analyze_directory("/home/logrotate/work", $BackupMaxDaysDir);
    analyze_cache_directory($LogRotateCache, $BackupMaxDaysDir);
    analyze_cache_directory("/home/logrotate/work", $BackupMaxDaysDir);
    analyze_cache_directory("/home/squid/cache-logs", $BackupMaxDaysDir);
    if ($SquidRotateMergeFiles == 1) {
        Merge_files();
    }
    if ($BackupSquidLogsUseNas == 1) {
        BackupToNas($BackupMaxDaysDir);
        $q->QUERY_SQL("TRUNCATE TABLE backuped_logs", "artica_events");
    } else {
        analyze_destination_directory($BackupMaxDaysDir);
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", $unix->DIRSIZE_KO($BackupMaxDaysDir));
    @chmod("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", 0777);
    return;
}
Пример #6
0
function ArticaSettingsrestore()
{
    $unix = new unix();
    $tmp = $unix->FILE_TEMP();
    events("restore Artica settings operations");
    events("restore Artica settings operations");
    $size = $unix->DIRSIZE_KO("{$_GET["PATH_RESTORE"]}/etc-artica-postfix");
    events("restore Artica settingssize={$size} Ko");
    if ($size == 0) {
        events("restore Artica settings failed, directory {$_GET["PATH_RESTORE"]}/etc-artica-postfix...");
        return null;
    }
    shell_exec("/bin/cp -rf {$_GET["PATH_RESTORE"]}/etc-artica-postfix/artica-postfix/* /etc/artica-postfix/");
    shell_exec("/usr/share/artica-postfix/bin/process1 --force " . md5(date('Y-m-d H:i:s')));
    @unlink("/etc/artica-postfix/FROM_ISO");
    @unlink("/etc/artica-postfix/artica-postfix.pid");
    @unlink("/etc/artica-postfix/mon.pid");
    shell_exec("/etc/init.d/artica-postfix restart daemon");
    @unlink("/etc/artica-postfix/settings/Daemons/SystemCpuNumber");
    events("restore Artica settings done...");
}
Пример #7
0
function build()
{
    $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    // /etc/artica-postfix/pids/exec.squid.rotate.php.build.time
    $sock = new sockets();
    $unix = new unix();
    $ls = $unix->find_program("ls");
    $pid = $unix->PIDOF_PATTERN(basename(__FILE__));
    $MyPid = getmypid();
    if ($MyPid != $pid) {
        if ($unix->process_exists($pid)) {
            $timeFile = $unix->PROCESS_TIME_INT($pid);
            $pidCmdline = @file_get_contents("/proc/{$pid}/cmdline");
            if ($timeFile < 30) {
                echo "Already PID {$pid} is running since {$timeFile}Mn\n";
                squid_admin_mysql(1, "[LOG ROTATION]: Skip task, already running {$pid} since {$timeFile}Mn", "Running: {$pidCmdline}", __FILE__, __LINE__);
                die;
            } else {
                squid_admin_mysql(1, "[LOG ROTATION]: Killing old task {$pid} running more than 30mn ({$timeFile}Mn)", "Running: {$pidCmdline}", __FILE__, __LINE__);
                $unix->KILL_PROCESS($pid);
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($timefile);
        if ($time < 60) {
            echo "Only each 60mn\n";
            die;
        }
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    $syslog = new mysql_storelogs();
    $SquidLogRotateFreq = intval($sock->GET_INFO("SquidLogRotateFreq"));
    if ($SquidLogRotateFreq < 10) {
        $SquidLogRotateFreq = 1440;
    }
    $LastRotate = $unix->file_time_min("/etc/artica-postfix/pids/squid-rotate-cache.time");
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    $SquidRotateOnlySchedule = intval($sock->GET_INFO("SquidRotateOnlySchedule"));
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    $BackupSquidLogsUseNas = intval($sock->GET_INFO("BackupSquidLogsUseNas"));
    $SquidRotateAutomount = intval($sock->GET_INFO("SquidRotateAutomount"));
    $SquidRotateClean = intval($sock->GET_INFO("SquidRotateClean"));
    $SquidRotateAutomountRes = $sock->GET_INFO("SquidRotateAutomountRes");
    $SquidRotateAutomountFolder = $sock->GET_INFO("SquidRotateAutomountFolder");
    if ($SquidRotateAutomount == 1) {
        shell_exec("{$ls} /automounts/{$SquidRotateAutomountRes} >/dev/null 2>&1");
        if (ifdirMounted("/automounts/{$SquidRotateAutomountRes}")) {
            $BackupSquidLogsUseNas = 0;
            $BackupMaxDaysDir = "/automounts/{$SquidRotateAutomountRes}/{$SquidRotateAutomountFolder}";
        } else {
            $syslog->events("/automounts/{$SquidRotateAutomountRes} not mounted", __FUNCTION__, __LINE__);
            squid_admin_mysql(1, "[ROTATE],Auto-mount {$SquidRotateAutomountRes} not mounted", null, __FILE__, __LINE__);
        }
    }
    $BackupMaxDaysDir = str_replace("//", "/", $BackupMaxDaysDir);
    $BackupMaxDaysDir = str_replace("\\", "/", $BackupMaxDaysDir);
    if (!is_dir($BackupMaxDaysDir)) {
        @mkdir($BackupMaxDaysDir, 0755, true);
    }
    if (!is_dir($BackupMaxDaysDir)) {
        $syslog->events("{$BackupMaxDaysDir} not such directory or permission denied", __FUNCTION__, __LINE__);
        squid_admin_mysql(1, "[ROTATE],{$BackupMaxDaysDir} not such directory or permission denied", null, __FILE__, __LINE__);
        if ($SquidRotateAutomount == 1) {
            $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
            if ($BackupMaxDaysDir == null) {
                $BackupMaxDaysDir = "/home/logrotate_backup";
            }
            if (!is_dir($BackupMaxDaysDir)) {
                @mkdir($BackupMaxDaysDir, 0755, true);
            }
            $syslog->events("Return back to {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
        } else {
            return;
        }
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $hostname = $unix->hostname_g();
    $InFluxBackupDatabaseDir = $sock->GET_INFO("InFluxBackupDatabaseDir");
    if ($InFluxBackupDatabaseDir == null) {
        $InFluxBackupDatabaseDir = "/home/artica/influx/backup";
    }
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $LogRotateAccess = "{$LogRotatePath}/access";
    $LogRotateTail = "{$LogRotatePath}/tail";
    $LogRotateCache = "{$LogRotatePath}/cache";
    $syslog->events("Launch rotation only by schedule.: {$SquidRotateOnlySchedule}", __FUNCTION__, __LINE__);
    $syslog->events("SquidLogRotateFreq...............: {$SquidLogRotateFreq}Mn", __FUNCTION__, __LINE__);
    $syslog->events("LastRotate.......................: {$LastRotate}Mn", __FUNCTION__, __LINE__);
    $syslog->events("Working directory................: {$LogRotatePath}", __FUNCTION__, __LINE__);
    $syslog->events("Launch rotation when exceed......: {$LogsRotateDefaultSizeRotation}M", __FUNCTION__, __LINE__);
    $syslog->events("Final storage directory..........: {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
    $syslog->events("Backup files to a NAS............: {$BackupSquidLogsUseNas}", __FUNCTION__, __LINE__);
    ss5_log($BackupMaxDaysDir);
    if ($handle = opendir("/var/run/squid")) {
        while (false !== ($file = readdir($handle))) {
            if ($file == ".") {
                continue;
            }
            if ($file == "..") {
                continue;
            }
            $path = "/var/run/squid/{$file}";
            if (preg_match("#\\.[0-9]+\\.status\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
            if (preg_match("#\\.[0-9]+\\.state\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
        }
    }
    $size = @filesize("/var/log/squid/access.log");
    $size = $size / 1024;
    $size = $size / 1024;
    $syslog->events("/var/log/squid/access.log........: {$size}M", __FUNCTION__, __LINE__);
    $syslog->events("Analyze /var/log/squid directory for cache.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        build_progress_rotation("Unable to open /var/log/squid", 110);
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    build_progress_rotation("Scanning /var/log/squid", 40);
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^cache\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotateCache}", 0755, true);
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            $destfile = "{$LogRotateCache}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    $syslog->events("Analyze /var/log/squid directory for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    @mkdir($LogRotateAccess, 0755, true);
    @mkdir($LogRotateTail, 0755, true);
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (preg_match("#^childs-access\\.log\\.[0-9]+\$#", $file)) {
                $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log";
                if (!@copy($path, $destfile)) {
                    $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                    @unlink($destfile);
                    continue;
                }
                $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
                @unlink($path);
                continue;
            }
            $syslog->events("Analyze {$file} ^squidtail\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__);
            if (preg_match("#^squidtail\\.log\\.[0-9]+\$#", $file)) {
                $destfile = "{$LogRotateTail}/{$file}";
                if (!@copy($path, $destfile)) {
                    $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                    @unlink($destfile);
                    continue;
                }
                $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
                @unlink($path);
                continue;
            }
            $syslog->events("Analyze {$file} ^access\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__);
            if (!preg_match("#^access\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotatePath}", 0755, true);
            $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    $syslog->events("Analyze {$LogRotateAccess} for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir($LogRotateAccess))) {
        $syslog->events("Unable to open {$LogRotateAccess} directory.", __FUNCTION__, __LINE__);
        return;
    }
    $ROTATED = false;
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "{$LogRotateAccess}/{$file}";
            echo "OPEN {$path}\n";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^access\\.log#", $file)) {
                continue;
            }
            range_fichier_source($path, $BackupMaxDaysDir);
            $ROTATED = true;
        }
    }
    if ($handle = opendir($LogRotateTail)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $path = "{$LogRotateTail}/{$file}";
                echo "OPEN {$path}\n";
                if (is_dir($path)) {
                    continue;
                }
                if (!preg_match("#^squidtail\\.log#", $file)) {
                    continue;
                }
                range_fichier_tail($path, $BackupMaxDaysDir);
                $ROTATED = true;
            }
        }
    }
    if (!$ROTATED) {
        return;
    }
    $q = new mysql();
    $sql = "CREATE TABLE IF NOT EXISTS `backuped_logs` (\n\t\t\t  `path` CHAR(255)  NOT NULL,\n\t\t\t  `zDate`  DATETIME,\n\t\t\t  `size` INT UNSIGNED NOT NULL,\n\t\t\t  PRIMARY KEY (`path`),\n\t\t\t  KEY `zDate` (`zDate`)\n\t\t\t)  ENGINE = MYISAM;";
    $q->QUERY_SQL($sql, "artica_events");
    $syslog->events("Analyze /home/logrotate/work for access.log", __FUNCTION__, __LINE__);
    build_progress_rotation("Scanning /home/logrotate/work", 45);
    analyze_directory("/home/logrotate/work", $BackupMaxDaysDir);
    $BackupMaxDaysDir2 = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir2 == null) {
        $BackupMaxDaysDir2 = "/home/logrotate_backup";
    }
    if ($BackupMaxDaysDir2 != $BackupMaxDaysDir) {
        build_progress_rotation("Scanning {$BackupMaxDaysDir2}", 46);
        $syslog->events("{$BackupMaxDaysDir2} is different of {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
        analyze_directory($BackupMaxDaysDir2, $BackupMaxDaysDir);
    }
    build_progress_rotation("Scanning /home/logrotate/merged", 47);
    analyze_garbage_directory("/home/logrotate/merged", $BackupMaxDaysDir, 1440);
    build_progress_rotation("Scanning {$LogRotateCache}", 48);
    analyze_cache_directory($LogRotateCache, $BackupMaxDaysDir);
    build_progress_rotation("Scanning /home/logrotate/work", 49);
    analyze_cache_directory("/home/logrotate/work", $BackupMaxDaysDir);
    build_progress_rotation("Scanning /home/squid/cache-logs", 49);
    analyze_cache_directory("/home/squid/cache-logs", $BackupMaxDaysDir);
    if ($GLOBALS["VERBOSE"]) {
        echo "TRUNCATE TABLE backuped_logs !!!\n";
    }
    $q->QUERY_SQL("TRUNCATE TABLE backuped_logs", "artica_events");
    if ($BackupSquidLogsUseNas == 1) {
        build_progress_rotation("Backup to N.A.S", 50);
        BackupToNas($BackupMaxDaysDir);
        build_progress_rotation("Backup to N.A.S BigData backups", 50);
        BackupToNas($InFluxBackupDatabaseDir, false);
    } else {
        build_progress_rotation("Scanning {$BackupMaxDaysDir}", 50);
        analyze_destination_directory($BackupMaxDaysDir);
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", $unix->DIRSIZE_KO($BackupMaxDaysDir));
    @chmod("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", 0777);
    return;
}
Пример #8
0
function critical_paths_locations()
{
    $unix = new unix();
    $f["/var/log/squid"] = true;
    $f["/home/logs-backup"] = true;
    $f["/home/c-icap/blacklists"] = true;
    $f["/var/log/artica-postfix"] = true;
    while (list($path, $val) = each($f)) {
        $newpath = $path;
        if (is_link($newpath)) {
            $newpath = readlink($newpath);
        }
        $size = $unix->DIRSIZE_KO($newpath);
        $ARRAY[$path]["SIZE"] = $size;
        $ARRAY[$path]["PATH"] = $newpath;
    }
    echo "<articadatascgi>" . base64_encode(serialize($ARRAY)) . "</articadatascgi>";
}
Пример #9
0
function sizes_backup()
{
    $sock = new sockets();
    $WordpressBackupParams = unserialize(base64_decode($sock->GET_INFO("WordpressBackupParams")));
    if (!isset($WordpressBackupParams["FTP_ENABLE"])) {
        $WordpressBackupParams["FTP_ENABLE"] = 0;
    }
    if (!isset($WordpressBackupParams["DEST"])) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    if ($WordpressBackupParams["DEST"] == null) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    if (!is_dir($WordpressBackupParams["DEST"])) {
        return;
    }
    $unix = new unix();
    $size = $unix->DIRSIZE_KO($WordpressBackupParams["DEST"]);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/WordpressBackupSize", $size);
    @chmod("/etc/artica-postfix/settings/Daemons/WordpressBackupSize", 0755);
}
Пример #10
0
function purge($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $workdir = "/var/lib/c_icap/temporary";
    if (is_link($workdir)) {
        $workdir = readlink($workdir);
    }
    if (!is_dir($workdir)) {
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $rm = $unix->find_program("rm");
    if ($GLOBALS["VERBOSE"]) {
        echo "pidfile: {$pidfile}\n";
        echo "pidTime: {$pidTime}\n";
    }
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    if (!$GLOBALS["FORCE"]) {
        if (isset($GLOBALS["SCHEDULE"])) {
            $Time = $unix->file_time_min($pidTime);
            if ($GLOBALS["VERBOSE"]) {
                echo "Time:{$Time}Mn\n";
            }
            if ($Time < 20) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "Time:{$Time}Mn < 20 -> Die();\n";
                }
                return;
            }
        }
    }
    if ($GLOBALS["FORCE"]) {
        $Time = $unix->file_time_min($pidTime);
        if ($Time < 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Time:{$Time}Mn < 1 -> Die();\n";
            }
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $MaxCICAPWorkTimeMin = $sock->GET_INFO("MaxCICAPWorkTimeMin");
    $MaxCICAPWorkSize = $sock->GET_INFO("MaxCICAPWorkSize");
    if (!is_numeric($MaxCICAPWorkTimeMin)) {
        $MaxCICAPWorkTimeMin = 1440;
    }
    if (!is_numeric($MaxCICAPWorkSize)) {
        $MaxCICAPWorkSize = 5000;
    }
    $size = round($unix->DIRSIZE_KO($workdir) / 1024, 2);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service `{$workdir}` {$size}MB/{$MaxCICAPWorkSize}\n";
    }
    @file_put_contents($pidfile, getmypid());
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $sync = $unix->find_program("sync");
    if ($size > $MaxCICAPWorkSize) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service {$size}MB exceed size!\n";
        }
        squid_admin_mysql(0, "C-ICAP: `{$workdir}` {$size}MB exceed size!", "Artica will remove all files..\n", __FILE__, __LINE__);
        shell_exec("{$rm} {$workdir}/*");
        shell_exec($sync);
        stop(true);
        start(true);
        squid_admin_mysql(2, "Reconfiguring proxy service\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
        return;
    }
    if ($GLOBALS["ALL"]) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service {$size}MB exceed size!\n";
        }
        squid_admin_mysql(0, "C-ICAP: `{$workdir}` {$size}MB exceed size!", "Artica will remove all files..\n", __FILE__, __LINE__);
        shell_exec("{$rm} {$workdir}/*");
        shell_exec($sync);
        stop(true);
        start(true);
        squid_admin_mysql(2, "Reconfiguring proxy service\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
        return;
    }
    if (!($handle = opendir($workdir))) {
        return;
    }
    while (false !== ($file = readdir($handle))) {
        if ($file == ".") {
            continue;
        }
        if ($file == "..") {
            continue;
        }
        if (is_dir($workdir)) {
            continue;
        }
        $path = "{$workdir}/{$file}";
        $size = @filesize($path);
        $size = $size / 1024;
        $size = $size / 1024;
        if ($unix->is_socket($path)) {
            continue;
        }
        $time = $unix->file_time_min($path);
        if ($GLOBALS["ALL"]) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service removing `{$path}` ( {$size}M )\n";
            }
            @unlink($path);
            continue;
        }
        if ($time > $MaxCICAPWorkTimeMin) {
            squid_admin_mysql(1, "C-ICAP: Removing temporary file {$path} ( {$time}Mn/{$size}M )", "It exceed rule of {$MaxCICAPWorkTimeMin}Mn ( {$time}Mn )", __FILE__, __LINE__);
            @unlink($path);
            continue;
        }
    }
    $REMOVED = false;
    $workdir = "/var/clamav/tmp";
    if (is_dir($workdir)) {
        if (!($handle = opendir($workdir))) {
            return;
        }
        while (false !== ($file = readdir($handle))) {
            if ($file == ".") {
                continue;
            }
            if ($file == "..") {
                continue;
            }
            if (is_dir($workdir)) {
                continue;
            }
            $path = "{$workdir}/{$file}";
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            if ($unix->is_socket($path)) {
                continue;
            }
            $time = $unix->file_time_min($path);
            if ($GLOBALS["ALL"]) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: c-icap service removing `{$path}` ( {$size}M )\n";
                }
                $REMOVED = true;
                @unlink($path);
                continue;
            }
            if ($time > $MaxCICAPWorkTimeMin) {
                squid_admin_mysql(1, "C-ICAP: Removing temporary file {$path} ( {$time}Mn/{$size}M )", "It exceed rule of {$MaxCICAPWorkTimeMin}Mn ( {$time}Mn )", __FILE__, __LINE__);
                $REMOVED = true;
                @unlink($path);
                continue;
            }
        }
    }
    if ($REMOVED) {
        shell_exec($sync);
    }
}