function subdomains()
{
    $subdomains = "https://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt";
    $MAIN = unserialize(@file_get_contents("/root/ransomwaretracker.db"));
    $curl = new ccurl($subdomains);
    if ($curl->GetFile("/root/RW_DOMBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_DOMBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["DOMAINS"][$line] = true;
        }
    } else {
        echo "{$subdomains} failed\n";
    }
    $ips = "https://ransomwaretracker.abuse.ch/downloads/RW_IPBL.txt";
    $curl = new ccurl($ips);
    if ($curl->GetFile("/root/RW_IPBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_IPBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["IPS"][$line] = true;
        }
    } else {
        echo "{$ips} failed\n";
    }
    $uris = "https://ransomwaretracker.abuse.ch/downloads/RW_URLBL.txt";
    $curl = new ccurl($uris);
    if ($curl->GetFile("/root/RW_URLBL.txt")) {
        $f = explode("\n", @file_get_contents("/root/RW_URLBL.txt"));
        while (list($index, $line) = each($f)) {
            $line = trim($line);
            if (substr($line, 0, 1) == "#") {
                continue;
            }
            $MAIN["URIS"][$line] = true;
        }
    } else {
        echo "{$uris} failed\n";
    }
    $MAIN2["TIME"] = time();
    $MAIN2["MD5"] = md5(serialize($MAIN));
    @file_put_contents("/root/ransomwaretracker.db", serialize($MAIN));
    @file_put_contents("/root/ransomwaretracker.txt", serialize($MAIN2));
    $unix = new unix();
    $unix->compress("/root/ransomwaretracker.db", "/root/ransomwaretracker.gz");
    PushToRepo("/root/ransomwaretracker.txt");
    PushToRepo("/root/ransomwaretracker.gz");
}
function export()
{
    $workdir = dirname(__FILE__) . "/ressources/squid-export";
    if (!is_dir($workdir)) {
        @mkdir($workdir, 0777, true);
    }
    if (!($handle = opendir("/etc/artica-postfix/settings/Daemons"))) {
        @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true);
        die;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetFile = "/etc/artica-postfix/settings/Daemons/{$filename}";
        if ($GLOBALS["VERBOSE"]) {
            echo "Exporting {$filename}\n";
        }
        $array[$filename] = @file_get_contents($targetFile);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo count($array) . " items....\n";
    }
    $finalitems = base64_encode(serialize($array));
    $unix = new unix();
    $tmpf = $unix->FILE_TEMP();
    @file_put_contents($tmpf, $finalitems);
    if ($GLOBALS["VERBOSE"]) {
        echo "compressing in {$workdir}/settingsHD.gz\n";
    }
    if (!$unix->compress($tmpf, "{$workdir}/settingsHD.gz")) {
        @unlink("{$workdir}/settingsHD.gz");
    }
    @chmod("{$workdir}/settingsHD.gz", 0777);
    @unlink($tmpf);
    if ($GLOBALS["VERBOSE"]) {
        echo "compressing in {$workdir}/settingsHD.gz done\n";
    }
}
Beispiel #3
0
function compress_debug()
{
    $unix = new unix();
    $sourcefile = "/var/log/artica-wifidog.log";
    $destfile = "/usr/share/artica-postfix/ressources/logs/web/hotspot.debug.gz";
    @unlink($destfile);
    $unix = new unix();
    $unix->compress($sourcefile, $destfile);
    @chmod($destfile, 0777);
}
function import_backup_file($filepath)
{
    if ($GLOBALS["VERBOSE"]) {
        echo "Import {$filepath}\n";
    }
    $dirname = dirname($filepath);
    $filename = basename($filepath);
    $filecontent = $dirname . "/" . str_replace(".email", ".msg", $filename);
    if (!is_file($filecontent)) {
        echo "{$filecontent} no such file\n";
        @unlink($filepath);
        return true;
    }
    $last_modified = filemtime($filepath);
    //$FinalLog="$Subject|||$Sender|||$recipt|||$body_hash|||$body_length||$rententiontime";
    $F = explode("|||", @file_get_contents($filepath));
    print_r($F);
    if (count($F) < 5) {
        echo "Truncated file index : {$filepath} !\n";
        return false;
    }
    $q = new postgres_sql();
    $zdate = date("Y-m-d H:i:s", $last_modified);
    $subject = str_replace("'", "`", $F[0]);
    $mailfrom = $F[1];
    $mailfrom = str_replace("<", "", $mailfrom);
    $mailfrom = str_replace(">", "", $mailfrom);
    $mailfromz = explode("@", $mailfrom);
    $domainfrom = $mailfromz[1];
    $mailto_line = $F[2];
    $hash = $F[3];
    $retentiontime = $F[5];
    $filesize = @filesize($filecontent);
    $msgmd5 = md5_file($filecontent);
    $final = strtotime("+{$retentiontime} minutes", $last_modified);
    $prefix = "INSERT INTO backupmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
    $mailsTo_array = explode(";", $mailto_line);
    $f = array();
    while (list($a, $mailto) = each($mailsTo_array)) {
        $mailto = trim(strtolower($mailto));
        $mailto = str_replace("<", "", $mailto);
        $mailto = str_replace(">", "", $mailto);
        if ($mailto == null) {
            continue;
        }
        $mailtoz = explode("@", $mailto);
        $domainto = $mailtoz[1];
        $f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
    }
    if (count($f) == 0) {
        echo "No... count(f)=0\n";
        @unlink($filepath);
        @unlink($filecontent);
        return false;
    }
    $final_sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($final_sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$final_sql}\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $filecontent_gz = "{$filecontent}.gz";
    $unix = new unix();
    if (!$unix->compress($filecontent, $filecontent_gz)) {
        @unlink($filecontent_gz);
        echo "No... Compress error\n";
        return;
    }
    @chmod($filecontent_gz, 0777);
    $q->QUERY_SQL("INSERT INTO backupdata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $unix->ToSyslog("from=<{$mailfrom}> [{$subject}] {$filepath} success to backup");
    echo "{$filepath} (success)\n{$filecontent} (success)\n";
    @unlink($filepath);
    @unlink($filecontent);
    @unlink($filecontent_gz);
    return true;
}
function backup()
{
    build_progress_idb("{backup_database}", 20);
    $unix = new unix();
    $targetFilename = "/home/ArticaStatsBackup/backup.db";
    $su = $unix->find_program("su");
    @mkdir("/home/ArticaStatsBackup", 0777, true);
    @chmod("/home/ArticaStatsBackup", 0777);
    if (is_file($targetFilename)) {
        @unlink($targetFilename);
    }
    $InFluxBackupDatabaseDir = @file_get_contents("/etc/artica-postfix/settings/Daemons/InFluxBackupDatabaseDir");
    if ($InFluxBackupDatabaseDir == null) {
        $InFluxBackupDatabaseDir = "/home/artica/influx/backup";
    }
    $CompressFileName = "{$InFluxBackupDatabaseDir}/snapshot." . date("Y-m-d-H-i") . ".gz";
    @mkdir($InFluxBackupDatabaseDir, 0755, true);
    if (is_file($CompressFileName)) {
        build_progress_idb("{backup_database} already exists", 110);
    }
    $cmdline = "{$su} -c \"/usr/local/ArticaStats/bin/pg_dumpall -c --if-exists -S ArticaStats -f {$targetFilename} -h /var/run/ArticaStats\" ArticaStats";
    echo $cmdline . "\n";
    exec($cmdline, $results);
    build_progress_idb("{backup_database}", 30);
    if (!is_file($targetFilename)) {
        echo "{$targetFilename} No such file\n";
        while (list($num, $val) = each($results)) {
            echo "{$val}\n";
        }
        build_progress_idb("{backup_database} {failed}", 110);
        return;
    }
    build_progress_idb("{compressing}", 50);
    echo "Compress {$targetFilename}\n";
    echo "Destination {$CompressFileName}\n";
    if (!$unix->compress($targetFilename, $CompressFileName)) {
        build_progress_idb("{compressing} {failed}", 110);
        squid_admin_mysql(0, "Snaphost BigData database {failed} ( compress )", null, __FILE__, __LINE__);
        @unlink($targetFilename);
        @unlink($CompressFileName);
        return;
    }
    @unlink($targetFilename);
    $size = FormatBytes(@filesize($CompressFileName) / 1024);
    squid_admin_mysql(2, "Backup [" . basename($CompressFileName) . "] BigData database ({$size}) done", null, __FILE__, __LINE__);
    build_progress_idb("{scanning}", 80);
    ScanBackup();
    build_progress_idb("{backup_database} {success}", 100);
}
function range_fichier_source($filepath, $BackupMaxDaysDir, $EXTERN = false)
{
    $syslog = new mysql_storelogs();
    $unix = new unix();
    $ext = $unix->file_extension($filepath);
    $hostname = $unix->hostname_g();
    $sock = new sockets();
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $LogRotateAccess = "{$LogRotatePath}/access";
    $LogRotateAccessFailed = "{$LogRotatePath}/failed";
    $LogRotateAccessMerged = "{$LogRotatePath}/merged";
    $SquidRotateMergeFiles = $sock->GET_INFO("SquidRotateMergeFiles");
    if (!is_numeric($SquidRotateMergeFiles)) {
        $SquidRotateMergeFiles = 1;
    }
    $LogsRotateDeleteSize = intval($sock->GET_INFO("LogsRotateDeleteSize"));
    if ($LogsRotateDeleteSize == 0) {
        $LogsRotateDeleteSize = 5000;
    }
    $basename = basename($filepath);
    if ($basename == "access.merged.log") {
        return;
    }
    $syslog->events("Analyze {$filepath} [{$ext}] ", __FUNCTION__, __LINE__);
    if ($ext == "gz") {
        if (preg_match("#\\.tar\\.gz\$#", $basename)) {
            $syslog->events("{$filepath} is a tarball!", __FUNCTION__, __LINE__);
            return;
        }
        $syslog->events("Extract {$filepath}", __FUNCTION__, __LINE__);
        $ExtractedFile = "{$LogRotateAccess}/{$basename}.log";
        if (!$unix->uncompress($filepath, $ExtractedFile)) {
            @unlink($ExtractedFile);
            $syslog->events("Unable to extract {$filepath} to {$ExtractedFile}", __FUNCTION__, __LINE__);
            return;
        }
        $syslog->events("Removing {$filepath} [{$ext}] ", __FUNCTION__, __LINE__);
        @unlink($filepath);
        $filepath = $ExtractedFile;
    }
    $unix = new unix();
    $ztimes = access_logs_getdates($filepath);
    if (!$ztimes) {
        $syslog->events("Failed to parse {$filepath}", __FUNCTION__, __LINE__);
        @mkdir($LogRotateAccessFailed, 0755, true);
        if (@copy($filepath, "{$LogRotateAccessFailed}/{$basename}")) {
            @unlink($filepath);
        }
        return false;
    }
    $xdatefrom = $ztimes[0];
    $xdateTo = $ztimes[1];
    $dateFrom = date("Y-m-d_H-i-s", $xdatefrom);
    $dateTo = date("Y-m-d_H-i-s", $xdateTo);
    $NewFileName = filename_from_arraydates($ztimes);
    if ($SquidRotateMergeFiles == 1) {
        @mkdir($LogRotateAccessMerged, 0755, true);
        if (!is_dir($LogRotateAccessMerged)) {
            $syslog->events("Unable to create Merged directory {$LogRotateAccessMerged}", __FUNCTION__, __LINE__);
        } else {
            if (!@copy($filepath, "{$LogRotateAccessMerged}/{$basename}")) {
                @unlink("{$LogRotateAccessMerged}/{$basename}");
                $syslog->events("Unable to copy {$filepath} -> {$LogRotateAccessMerged}/{$basename}", __FUNCTION__, __LINE__);
            }
        }
    }
    $FinalDirectory = "{$BackupMaxDaysDir}/proxy/" . date("Y", $xdatefrom) . "/" . date("m", $xdatefrom) . "/" . date("d", $xdatefrom);
    @mkdir($FinalDirectory, 0755, true);
    if (!is_dir($FinalDirectory)) {
        $syslog->events("Unable to create {$FinalDirectory} directory permission denied", __FUNCTION__, __LINE__);
        return;
    }
    if (!$unix->compress($filepath, "{$FinalDirectory}/{$NewFileName}")) {
        @unlink("{$FinalDirectory}/{$NewFileName}");
        $syslog->events("Unable to compress {$FinalDirectory}/{$NewFileName} permission denied", __FUNCTION__, __LINE__);
        return;
    }
    $syslog->events("Success to create {$FinalDirectory}/{$NewFileName}", __FUNCTION__, __LINE__);
    $syslog->events("Removing source file {$filepath}", __FUNCTION__, __LINE__);
    @unlink($filepath);
}
function GetIndex()
{
    $WORKING_DIR = "/home/working_toulouse_databases";
    $WORKING_DOWNLOAD = "{$WORKING_DIR}/dowloads";
    $WORKING_UPLOAD = "{$WORKING_DIR}/uploads";
    @mkdir($WORKING_DOWNLOAD, 0755, true);
    @mkdir($WORKING_UPLOAD, 0755, true);
    $unix = new unix();
    $tar = $unix->find_program("tar");
    $catz = new mysql_catz();
    $tmpfile = $unix->FILE_TEMP();
    $tmpdir = $unix->TEMP_DIR();
    $rm = $unix->find_program("rm");
    $mainuri = "ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib";
    $EXEC_NICE = $unix->EXEC_NICE();
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    $curl = new ccurl("{$mainuri}/MD5SUM.LST");
    if (!$curl->GetFile($tmpfile)) {
        echo "Failed to download MD5SUM.LST\n";
        return;
    }
    $tr = explode("\n", @file_get_contents($tmpfile));
    while (list($index, $line) = each($tr)) {
        if (preg_match("#(.+?)\\s+(.+)#", $line, $re)) {
            $filename = trim($re[1]);
            $md5 = trim($re[2]);
            $array[$md5] = $filename;
        }
    }
    @unlink($tmpfile);
    $q = new mysql_squid_builder();
    $TLSE_CONVERTION = TLSE_CONVERTION();
    $FINAL_ARRAY = array();
    while (list($filename, $md5) = each($array)) {
        $category = str_replace(".tar.gz", "", $filename);
        if (isset($TLSE_CONVERTION[$category])) {
            $FINAL_ARRAY[$filename] = $md5;
        }
    }
    $UPDATED = 0;
    $MAIN_ARRAY = unserialize(base64_decode(@file_get_contents("{$WORKING_UPLOAD}/index.txt")));
    while (list($filename, $md5) = each($FINAL_ARRAY)) {
        $TargetFile = "{$WORKING_DOWNLOAD}/{$filename}";
        $categoryname = str_replace(".tar.gz", "", $filename);
        if ($categoryname == "adult") {
            continue;
        }
        if ($categoryname == "aggressive") {
            continue;
        }
        if ($categoryname == "agressif") {
            continue;
        }
        if ($categoryname == "redirector") {
            continue;
        }
        if ($categoryname == "ads") {
            continue;
        }
        if ($categoryname == "drogue") {
            continue;
        }
        $MyStoreMd5 = md5_file($TargetFile);
        if ($MyStoreMd5 == $md5) {
            echo "Skipping {$filename}\n";
            continue;
        }
        echo "Downloading {$filename}\n";
        $curl = new ccurl("{$mainuri}/{$filename}");
        $tmpfile = $unix->FILE_TEMP();
        if (!$curl->GetFile($tmpfile)) {
            echo "Failed {$curl->error}\n";
            @unlink($tmpfile);
            continue;
        }
        $md5_tmp = md5_file($tmpfile);
        if ($md5_tmp != $md5) {
            echo "Failed Corrupted file\n";
            @unlink($tmpfile);
            continue;
        }
        if (is_file($TargetFile)) {
            @unlink($TargetFile);
        }
        if (!@copy($tmpfile, $TargetFile)) {
            echo "Failed Copy file\n";
            @unlink($tmpfile);
            @unlink($TargetFile);
            continue;
        }
        @unlink($tmpfile);
        $MyStoreMd5 = md5_file($TargetFile);
        if ($MyStoreMd5 != $md5) {
            echo "Failed MD5 file\n";
            @unlink($TargetFile);
            continue;
        }
        @mkdir("{$WORKING_DIR}/{$categoryname}", 0755, true);
        echo "Extracting {$TargetFile}\n";
        $cmd = "{$tar} xvf {$TargetFile} -C {$WORKING_DIR}/{$categoryname}/";
        echo $cmd . "\n";
        system($cmd);
        $SOURCE_DIR = find_sources("{$WORKING_DIR}/{$categoryname}");
        if (!is_file("{$SOURCE_DIR}/domains")) {
            echo "Failed {$SOURCE_DIR}/domains no such file\n";
            @unlink($TargetFile);
            continue;
        }
        $COUNT_OF_DOMAINS = $unix->COUNT_LINES_OF_FILE("{$SOURCE_DIR}/domains");
        echo "{$categoryname} {$COUNT_OF_DOMAINS} domains\n";
        if ($COUNT_OF_DOMAINS == 0) {
            shell_exec("{$rm} -rf {$WORKING_DIR}/{$categoryname}");
            @unlink($TargetFile);
            continue;
        }
        if (is_file("{$SOURCE_DIR}/domains.ufdb")) {
            @unlink("{$SOURCE_DIR}/domains.ufdb");
        }
        if (!is_file("{$SOURCE_DIR}/urls")) {
            @touch("{$SOURCE_DIR}/urls");
        }
        $u = " -u {$SOURCE_DIR}/urls";
        $d = " -d {$SOURCE_DIR}/domains";
        $cmd = "{$EXEC_NICE}{$ufdbGenTable} -n -q -W -t {$categoryname}{$d}{$u}";
        echo $cmd . "\n";
        shell_exec($cmd);
        if (!is_file("{$SOURCE_DIR}/domains.ufdb")) {
            echo "Failed to compile {$categoryname}\n";
            @unlink($TargetFile);
            continue;
        }
        $MD5SRC = md5_file("{$SOURCE_DIR}/domains.ufdb");
        if (is_file("{$WORKING_UPLOAD}/{$categoryname}.gz")) {
            @unlink("{$WORKING_UPLOAD}/{$categoryname}.gz");
        }
        $unix->compress("{$SOURCE_DIR}/domains.ufdb", "{$WORKING_UPLOAD}/{$categoryname}.gz");
        $MD5GZ = md5_file("{$WORKING_UPLOAD}/{$categoryname}.gz");
        $UPDATED++;
        $NOTIFICATIONS[] = "{$categoryname} updated with  {$COUNT_OF_DOMAINS} domains";
        $MAIN_ARRAY[$categoryname]["ROWS"] = $COUNT_OF_DOMAINS;
        $MAIN_ARRAY[$categoryname]["MD5SRC"] = $MD5SRC;
        $MAIN_ARRAY[$categoryname]["MD5GZ"] = $MD5GZ;
        $MAIN_ARRAY[$categoryname]["TIME"] = time();
        $MAIN_ARRAY[$categoryname]["SIZE"] = @filesize("{$WORKING_UPLOAD}/{$categoryname}.gz");
        @file_put_contents("{$WORKING_UPLOAD}/index.txt", base64_encode(serialize($MAIN_ARRAY)));
    }
    if ($UPDATED > 0) {
        PushToRepo_alls();
        sendEmail("{$UPDATED} Toulouse Unversity databases uploaded.", @implode("\n", $NOTIFICATIONS));
    }
}
function ROTATE_DIR($backupdir)
{
    $unix = new unix();
    $cat = $unix->find_program("cat");
    $files = $unix->DirFiles($backupdir);
    $suffix = "influx";
    if (is_file("/usr/local/ArticaStats/bin/postgres")) {
        $suffix = "postgres";
    }
    $today = date("Y-m-d");
    while (list($basename, $subarray) = each($files)) {
        if (preg_match("#^([0-9\\-]+)\\.gz\$#", $basename, $re)) {
            continue;
        }
        if (preg_match("#^([0-9\\-]+)\\.back\$#", $basename, $re)) {
            if ($re[1] != $today) {
                if (!$unix->compress("{$backupdir}/{$basename}", "{$backupdir}/{$re[1]}.gz")) {
                    @unlink("{$backupdir}/{$re[1]}.gz");
                    continue;
                }
                @unlink("{$backupdir}/{$basename}");
            }
            continue;
        }
        if (!preg_match("#^([0-9]+)\\.{$suffix}\\.log\$#", $basename, $re)) {
            echo "{$basename} no match...\n";
            continue;
        }
        $time = $re[1];
        $day = date("Y-m-d", $time);
        $handleOUT = @fopen("{$backupdir}/{$basename}", "r");
        $handleIN = @fopen("{$backupdir}/{$day}.back", "a");
        $c = 0;
        while (!feof($handleOUT)) {
            $line = trim(fgets($handleOUT, 4096));
            @fwrite($handleIN, "{$line}\n");
            $c++;
        }
        events("{$backupdir}/{$basename} {$c} line(s)");
        fclose($handleOUT);
        fclose($handleIN);
        @unlink("{$backupdir}/{$basename}");
    }
}
function import_quarantine($directory)
{
    if (!is_file("{$directory}/ENTIRE_MESSAGE")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$directory}/ENTIRE_MESSAGE no such file\n";
        }
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Scanning directory {$directory}\n";
    }
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $msgmd5 = md5_file("{$directory}/ENTIRE_MESSAGE");
    $last_modified = filemtime("{$directory}/ENTIRE_MESSAGE");
    $filesize = @filesize("{$directory}/ENTIRE_MESSAGE");
    $zdate = date("Y-m-d H:i:s", $last_modified);
    if ($GLOBALS["VERBOSE"]) {
        echo "Message MD5....: {$msgmd5}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Message Date...: {$last_modified} ({$zdate})\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Size...........: {$filesize}\n";
    }
    $MimeDefangMaxQuartime = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/MimeDefangMaxQuartime"));
    if ($MimeDefangMaxQuartime == 0) {
        $MimeDefangMaxQuartime = 129600;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Retention time.: {$MimeDefangMaxQuartime}Mn\n";
    }
    $f = explode("\n", @file_get_contents("{$directory}/HEADERS"));
    while (list($index, $line) = each($f)) {
        if (preg_match("#Subject:\\s+(.*)#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Subject........: {$re[1]}\n";
            }
            $Subject = $re[1];
        }
        if (preg_match("#From:\\s+(.*)#i", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "From...........: {$re[1]}\n";
            }
            $FromHeader = $re[1];
            $FromHeader = str_replace("<", "", $FromHeader);
            $FromHeader = str_replace(">", "", $FromHeader);
            $FromHeader = trim($FromHeader);
            if (preg_match("#(.*?)\\s+#", $FromHeader, $re)) {
                $FromHeader = $re[1];
            }
        }
    }
    $mailsTo_array = array();
    $f = explode("\n", @file_get_contents("{$directory}/RECIPIENTS"));
    while (list($index, $line) = each($f)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $line = str_replace("<", "", $line);
        $line = str_replace(">", "", $line);
        if (strpos($line, "@") == 0) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Recipient......: {$line}\n";
        }
        $mailsTo_array[$line] = $line;
    }
    $mailfrom = trim(@file_get_contents("{$directory}/SENDER"));
    if ($GLOBALS["VERBOSE"]) {
        echo "Sender.........: {$mailfrom}\n";
    }
    if ($mailfrom == null) {
        $mailfrom = $FromHeader;
    }
    $mailfrom = str_replace("<", "", $mailfrom);
    $mailfrom = str_replace(">", "", $mailfrom);
    $q = new postgres_sql();
    $Subject = str_replace("'", "`", $Subject);
    $mailfromz = explode("@", $mailfrom);
    $domainfrom = $mailfromz[1];
    $final = strtotime("+{$MimeDefangMaxQuartime} minutes", $last_modified);
    $prefix = "INSERT INTO quarmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
    $f = array();
    while (list($a, $mailto) = each($mailsTo_array)) {
        $mailto = trim(strtolower($mailto));
        if ($mailto == null) {
            continue;
        }
        $mailtoz = explode("@", $mailto);
        $domainto = $mailtoz[1];
        $f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$Subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
    }
    if (count($f) == 0) {
        echo "No... count(f)=0\n";
        shell_exec("{$rm} -rf \"{$directory}\"");
        return false;
    }
    $final_sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($final_sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$final_sql}\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $filecontent_gz = $unix->FILE_TEMP() . ".gz";
    $unix = new unix();
    if (!$unix->compress("{$directory}/ENTIRE_MESSAGE", $filecontent_gz)) {
        @unlink($filecontent_gz);
        echo "No... Compress error\n";
        return;
    }
    @chmod($filecontent_gz, 0777);
    $q->QUERY_SQL("INSERT INTO quardata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    @unlink($filecontent_gz);
    $unix->ToSyslog("from=<{$mailfrom}> [{$Subject}] {$directory}/ENTIRE_MESSAGE success to Quarantine");
    echo "{$directory}/ENTIRE_MESSAGE (success)\n";
    shell_exec("{$rm} -rf \"{$directory}\"");
    return true;
}
Beispiel #10
0
function check_all_squid()
{
    $sock = new sockets();
    $unix = new unix();
    $syslog = new mysql_storelogs();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = file_get_contents("{$pidfile}");
    if (system_is_overloaded(basename(__FILE__))) {
        die;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timeMin = $unix->PROCCESS_TIME_MIN($pid);
        if ($timeMin > 240) {
            system_admin_events("Too many TTL, {$pid} will be killed", __FUNCTION__, __FILE__, __LINE__, "logrotate");
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        } else {
            die;
        }
    }
    $time = $unix->file_time_min($timefile);
    if ($time < 300) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @file_put_contents($timefile, time());
    $php = $unix->LOCATE_PHP5_BIN();
    $bzip2 = $unix->find_program("bzip2");
    $ALREADYCOMP["gz"] = true;
    $ALREADYCOMP["bz2"] = true;
    $LogRotateCompress = 1;
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    $ApacheLogRotate = $sock->GET_INFO("ApacheLogRotate");
    if (!is_numeric($ApacheLogRotate)) {
        $ApacheLogRotate = 1;
    }
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    foreach (glob("/var/log/squid/*") as $filename) {
        if (is_dir($filename)) {
            continue;
        }
        $size = $unix->file_size($filename);
        $time = $unix->file_time_min($filename);
        $size = round($size / 1024 / 1000, 2);
        if ($size > $LogsRotateDefaultSizeRotation) {
            if ($filename == "/var/log/squid/access.log") {
                events("{$filename} -> is a production log for Squid, launch the rotation procedure.");
                squid_admin_mysql(1, "{$filename} {$size}M exceed {$LogsRotateDefaultSizeRotation}M, launch rotation", null, __FILE__, __LINE__);
                shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --rotate");
                continue;
            }
            $TOROT[$filename] = true;
            events("{$filename} -> Add to queue {$size}M exceed {$LogsRotateDefaultSizeRotation}M");
            continue;
        }
        if ($time > 1440) {
            if ($filename == "/var/log/squid/access.log") {
                events("{$filename} -> is a production log for Squid, launch the rotation procedure.");
                squid_admin_mysql(1, "{$filename} {$size}M exceed {$LogsRotateDefaultSizeRotation}M, launch rotation", null, __FILE__, __LINE__);
                shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --rotate");
                continue;
            }
            events("{$filename} -> Add to queue {$time}mn exceed 1440mn");
            $TOROT[$filename] = true;
            continue;
        }
    }
    if (count($TOROT) == 0) {
        return;
    }
    while (list($filename, $none) = each($TOROT)) {
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        $filedate = date('Y-m-d H:i:s', filemtime($filename));
        $basename = basename($filename);
        if (preg_match("#sarg\\.#", $filename)) {
            shell_exec("{$php5} " . dirname(__FILE__) . "/exec.sarg.php --rotate {$basename} >/dev/null 2>&1 &");
            continue;
        }
        if (preg_match("#access\\.log\\.[0-9]+\$#", $filename)) {
            continue;
        }
        if ($extension != "gz") {
            if (!$unix->compress($filename, "{$filename}.gz")) {
                continue;
            }
            $filename = $filename . ".gz";
            $extension = "gz";
        }
        echo "[{$filedate}]: {$filename} ({$extension})\n";
        if ($syslog->ROTATE_TOMYSQL($filename, $filedate)) {
            @unlink($filename);
        }
    }
    foreach (glob("/home/squid/cache-logs/*") as $filename) {
        $filedate = date('Y-m-d H:i:s', filemtime($filename));
        $filename = $filename . ".gz";
        if ($syslog->ROTATE_TOMYSQL($filename, $filedate)) {
            @unlink($filename);
        }
    }
}
Beispiel #11
0
function BACKUP_PROGRESS()
{
    build_progress_backup("{backup} {rules}", 5);
    $tables[] = "webauth_rules";
    $tables[] = "webauth_settings";
    $tables[] = "hotspot_members";
    $q = new mysql_squid_builder();
    $cmdline = $q->MYSQL_CMDLINES;
    $unix = new unix();
    $mysqldump = $unix->find_program("mysqldump");
    $bzip2 = $unix->find_program("bzip2");
    $bzip2_cmd = "| {$bzip2} ";
    $filename = "/usr/share/artica-postfix/ressources/logs/web/hotspot.rules.backup.sql";
    $fileCompressName = "/usr/share/artica-postfix/ressources/logs/web/hotspot.rules.backup.gz";
    if (is_file($filename)) {
        @unlink($filename);
    }
    build_progress_backup("{backup} {tables}", 50);
    $cmd = "{$mysqldump} {$cmdline} --skip-add-drop-table --insert-ignore --single-transaction --skip-add-locks --skip-lock-tables squidlogs " . @implode(" ", $tables) . "> {$filename} 2>&1";
    echo $cmd . "\n";
    system("{$cmd}");
    if (!is_file($filename)) {
        build_progress_backup("{backup} {failed}", 110);
        return;
    }
    $size = @filesize($filename);
    echo "Size: " . $size . " bytes " . FormatBytes($size / 1024, true) . "\n";
    sleep(3);
    build_progress_backup("{backup} {compress}", 80);
    if (!$unix->compress($filename, $fileCompressName)) {
        @unlink($filename);
        build_progress_backup("{backup} {compress} failed}", 110);
        return;
    }
    @unlink($filename);
    $size = @filesize($fileCompressName);
    echo "Size: ( after compression)  " . $size . " bytes " . FormatBytes($size / 1024, true) . "\n";
    sleep(2);
    build_progress_backup("{backup} {done}", 100);
}
$GLOBALS["deflog_start"] = "Starting......: " . date("H:i:s") . " [INIT]: Milter Greylist Daemon";
$GLOBALS["deflog_sstop"] = "Stopping......: " . date("H:i:s") . " [INIT]: Milter Greylist Daemon";
$GLOBALS["ROOT"] = true;
$GLOBALS["FORCE"] = false;
if (preg_match("#--verbose#", @implode(" ", $argv))) {
    $GLOBALS["FORCE"] = true;
}
$GLOBALS["WHOPROCESS"] = "daemon";
if (!is_file("/root/ftp-hostname")) {
    echo "/root/ftp-hostname No such file...\n";
    die;
}
$unix = new unix();
if (is_file("/etc/artica-postfix/spamassassin-rules1.cf")) {
    @unlink("/etc/artica-postfix/spamassassin-rules1.gz");
    if (!$unix->compress("/etc/artica-postfix/spamassassin-rules1.cf", "/etc/artica-postfix/spamassassin-rules1.gz")) {
        die;
    }
    $MAIN["SPAMASS_1"]["TIME"] = time();
    $MAIN["SPAMASS_1"]["MD5"] = md5_file("/etc/artica-postfix/spamassassin-rules1.gz");
}
if (is_file("/etc/artica-postfix/spamassassin-rules3.cf")) {
    @unlink("/etc/artica-postfix/spamassassin-rules3.gz");
    if (!$unix->compress("/etc/artica-postfix/spamassassin-rules3.cf", "/etc/artica-postfix/spamassassin-rules3.gz")) {
        die;
    }
    $MAIN["SPAMASS_2"]["TIME"] = time();
    $MAIN["SPAMASS_2"]["MD5"] = md5_file("/etc/artica-postfix/spamassassin-rules3.gz");
}
if (is_file("/etc/artica-postfix/spamassassin-rules4.cf")) {
    @unlink("/etc/artica-postfix/spamassassin-rules4.gz");
function SaveCSV($ID)
{
    $unix = new unix();
    $chmod = $unix->find_program("chmod");
    $tablename = "WebTrackMem{$ID}";
    @unlink("/home/squid-work/csv.txt");
    @mkdir("/home/squid-work", 0777);
    $sql = "SELECT * INTO OUTFILE '/home/squid-work/csv.txt' FIELDS TERMINATED BY ',' \n\tOPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM {$tablename};";
    shell_exec("chmod 1777 /home/squid-work");
    $q = new mysql_squid_builder();
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        ufdbguard_admin_events("CSV failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
    $unix->compress("/home/squid-work/csv.txt", "/home/squid-work/csv.txt.gz");
    @unlink("/home/squid-work/csv.txt");
    $f = addslashes(@file_get_contents("/home/squid-work/csv.txt.gz"));
    @unlink("/home/squid-work/csv.txt.gz");
    $sql = "UPDATE TrackMembers SET csvContent='{$f}' WHERE ID='{$ID}'";
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        ufdbguard_admin_events("CSV failed {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "reports");
        return;
    }
}
function CheckOldCachesLog()
{
    @mkdir("/home/squid/cache-logs", 0755, true);
    $unix = new unix();
    foreach (glob("/var/log/squid/cache.log.*") as $filename) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Move {$filename} to /home/squid/cache-logs\n";
        }
        Events("Move {$filename} to /home/squid/cache-logs");
        @copy($filename, "/home/squid/cache-logs/" . basename($filename));
        @unlink($filename);
    }
    foreach (glob("/home/squid/cache-logs/*") as $filename) {
        $ext = $unix->file_ext($filename);
        if (is_numeric($ext)) {
            Events("Compress {$filename} to {$filename}.gz");
            if ($unix->compress($filename, "{$filename}.gz")) {
                @unlink($filename);
            }
            continue;
        }
        if ($ext == "gz") {
            $time = $unix->file_time_min($filename);
            if ($GLOBALS["VERBOSE"]) {
                echo "{$filename}  = {$time}Mn\n";
            }
            if ($time > 4320) {
                Events("Remove {$filename} (exceed 3 days on disk...)");
                @unlink($filename);
                continue;
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "CheckOldCachesLog:: END\n";
    }
}
Beispiel #15
0
function CleanSuricataLogs()
{
    if (!is_dir("/var/log/suricata")) {
        return;
    }
    $unix = new unix();
    $sock = new sockets();
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    @mkdir($BackupMaxDaysDir, 0755, true);
    $echo = $unix->find_program("echo");
    @unlink("/etc/artica-postfix/pids/CleanSuricataLogs.time");
    @file_put_contents("/etc/artica-postfix/pids/CleanSuricataLogs.time", time());
    if ($handle = opendir("/var/log/suricata")) {
        while (false !== ($fileZ = readdir($handle))) {
            if ($fileZ == ".") {
                continue;
            }
            if ($fileZ == "..") {
                continue;
            }
            $path = "/var/log/suricata/{$fileZ}";
            if (preg_match("#unified2\\.alert\\.#", $fileZ)) {
                if ($unix->file_time_min($path) > 30) {
                    @unlink($path);
                }
                continue;
            }
        }
    }
    $f[] = "fast.log";
    $f[] = "http.log";
    $f[] = "keyword_perf.log";
    $f[] = "packet_stats.log";
    $f[] = "rule_perf.log";
    $f[] = "sid_changes.log";
    $f[] = "stats.log";
    $RELOAD = false;
    $pathRange = "{$BackupMaxDaysDir}/" . date("Y") . "/" . date("m") . "/" . date("d");
    while (list($index, $filename) = each($f)) {
        $filepath = "/var/log/suricata/{$filename}";
        $size = @filesize($filepath) / 1024 / 1000;
        echo "{$filepath} {$size}MB <> {$LogsRotateDefaultSizeRotation}M\n";
        if ($size > $LogsRotateDefaultSizeRotation) {
            @mkdir($pathRange, 0755, true);
            $unix->compress($filepath, $pathRange . "/IDS-" . time() . ".{$filename}.gz");
            system_admin_mysql(2, "Rotate file {$filepath} {$size}>{$LogsRotateDefaultSizeRotation}", null, __FILE__, __LINE__);
            shell_exec("{$echo} \"\">{$filepath}");
            $RELOAD = true;
        }
    }
    $size = @filesize("/var/log/suricata/eve.json") / 1024 / 1000;
    if ($size > $LogsRotateDefaultSizeRotation) {
        system_admin_mysql(2, "Rotate file /var/log/suricata/eve.json {$size}>{$LogsRotateDefaultSizeRotation}", null, __FILE__, __LINE__);
        @mkdir($pathRange, 0755, true);
        $unix->compress($filepath, $pathRange . "/IDS-" . time() . ".eve.json.gz");
        shell_exec("{$echo} \"\">/var/log/suricata/eve.json");
        $RELOAD = true;
    }
    if ($RELOAD) {
        shell_exec("/etc/init.d/suricata reload");
    }
}
function ParseDB_FILE($path, $uuid = null, $asmeta = false)
{
    $unix = new unix();
    if (!is_file($path)) {
        return;
    }
    echo "Open {$path}\n";
    $db_con = dba_open($path, "r", "db4");
    if (!$db_con) {
        if ($asmeta) {
            meta_admin_mysql(1, "DB open failed {$path}", null, __FILE__, __LINE__);
        }
        echo "DB open failed\n";
        die;
    }
    $mainkey = dba_firstkey($db_con);
    while ($mainkey != false) {
        $val = 0;
        $data = unserialize(dba_fetch($mainkey, $db_con));
        $mainkey = dba_nextkey($db_con);
        if (!is_array($data)) {
            continue;
        }
        $q = new mysql_squid_builder();
        $qCommon = new mysql_squid_builder();
        if ($uuid != null) {
            $q = new mysql_stats($uuid);
        }
        if ($asmeta) {
            $q = new mysql_meta();
        }
        if (!isset($data["HOURLY"])) {
            continue;
        }
        if (!isset($data["WWW"])) {
            continue;
        }
        $category = null;
        $ipaddr = mysql_escape_string2($data["IPADDR"]);
        if (isset($data["MAC"])) {
            $mac = mysql_escape_string2($data["MAC"]);
        }
        $uid = mysql_escape_string2($data["UID"]);
        $familysite = mysql_escape_string2($data["WWW"]);
        if (isset($data["category"])) {
            $category = mysql_escape_string2($data["category"]);
        }
        if ($uid == null) {
            $uid = $qCommon->UID_FROM_MAC($data["MAC"]);
        }
        if ($uid == null) {
            $uid = $qCommon->UID_FROM_IP($data["IPADDR"]);
        }
        $uid = mysql_escape_string2($uid);
        $length = strlen($ipaddr) + strlen($mac) + strlen($uid) + strlen($familysite);
        if ($length == 0) {
            continue;
        }
        while (list($day, $array) = each($data["HOURLY"])) {
            while (list($hour, $size) = each($array)) {
                $md5 = md5("'{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}'");
                $wwwUH[] = "('{$md5}','{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}')";
                if ($GLOBALS["VERBOSE"]) {
                    echo "('{$md5}','{$ipaddr}','{$mac}','{$uid}','{$familysite}','{$day}','{$hour}','{$size}','{$category}')\n";
                }
            }
        }
    }
    dba_close($db_con);
    $TABLE_WEEK_RTTH = "WEEK_RTTH";
    $ENGINE = "MEMORY";
    if ($asmeta) {
        $TABLE_WEEK_RTTH = "{$uuid}_WEEK_RTTH";
        $ENGINE = "MYISAM";
    }
    if ($asmeta) {
        xmeta_events("DROP TABLE `{$TABLE_WEEK_RTTH}`", __FUNCTION__, __FILE__, __LINE__);
    }
    $q->QUERY_SQL("DROP TABLE `{$TABLE_WEEK_RTTH}`");
    if ($asmeta) {
        xmeta_events("CREATE TABLE `{$TABLE_WEEK_RTTH}`", __FUNCTION__, __FILE__, __LINE__);
    }
    $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `{$TABLE_WEEK_RTTH}` (\n\t\t\t`zmd5` varchar(90) NOT NULL,\n\t\t\t`familysite` varchar(128) NOT NULL,\n\t\t\t`ipaddr` varchar(50) NOT NULL DEFAULT '',\n\t\t\t`day` smallint(2) NOT NULL,\n\t\t\t`hour` smallint(2) NOT NULL,\n\t\t\t`uid` varchar(128) NOT NULL,\n\t\t\t`MAC` varchar(20) NOT NULL,\n\t\t\t`size` BIGINT UNSIGNED NOT NULL,\n\t\t\t`category` varchar(90) NOT NULL,\n\t\t\tPRIMARY KEY `zmd5` (`zmd5`),\n\t\t\tKEY `familysite` (`familysite`),\n\t\t\tKEY `ipaddr` (`ipaddr`),\n\t\t\tKEY `uid` (`uid`),\n\t\t\tKEY `category` (`category`),\n\t\t\tKEY `hour` (`hour`),\n\t\t\tKEY `day` (`day`),\n\t\t\tKEY `MAC` (`MAC`)\n\t) ENGINE={$ENGINE};");
    if (!$q->ok) {
        if ($asmeta) {
            meta_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
        }
        echo $q->mysql_error;
        return;
    }
    $q->QUERY_SQL("INSERT IGNORE INTO `{$TABLE_WEEK_RTTH}` ( `zmd5`,`ipaddr`,`MAC`,`uid`,familysite,`day`,`hour`,`size`,`category`) VALUES " . @implode(",", $wwwUH));
    if (!$q->ok) {
        if ($asmeta) {
            meta_admin_mysql(1, "MySQL error", $q->mysql_error, __FILE__, __LINE__);
        }
        echo $q->mysql_error;
        return;
    }
    if ($asmeta) {
        xmeta_events("Success parsing {$path} adding " . count($wwwUH) . " elements", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $sock = new sockets();
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    $EnableSquidRemoteMySQL = intval($sock->GET_INFO("EnableSquidRemoteMySQL"));
    if ($EnableSquidRemoteMySQL == 1) {
        return;
    }
    if ($EnableArticaMetaClient == 0) {
        return;
    }
    $DIR_TEMP = $unix->TEMP_DIR();
    if (!$unix->compress($path, "{$DIR_TEMP}/SQUID_QUOTASIZE.gz")) {
        meta_admin_mysql(1, "Unable to compress {$path}", null, __FILE__, __LINE__);
        @unlink("{$DIR_TEMP}/SQUID_QUOTASIZE.gz");
        return;
    }
    $artica_meta = new artica_meta();
    if (!$artica_meta->SendFile("{$DIR_TEMP}/SQUID_QUOTASIZE.gz", "SQUID_QUOTASIZE")) {
        meta_admin_mysql(1, "Unable to updload {$DIR_TEMP}/SQUID_QUOTASIZE.gz", null, __FILE__, __LINE__);
    }
    @unlink("{$DIR_TEMP}/SQUID_QUOTASIZE.gz");
}
function scan_categories($aspid = false)
{
    $unix = new unix();
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            die;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $ArticaMetaStorage = $sock->GET_INFO("ArticaMetaStorage");
    if ($ArticaMetaStorage == null) {
        $ArticaMetaStorage = "/home/artica-meta";
    }
    $q = new mysql_meta();
    $sql = "SELECT webfiltering_categories_items.pattern, metagroups_link.uuid, \n\twebfiltering_categories_link.category FROM metagroups_link,webfiltering_categories_link,\n\twebfiltering_categories_items WHERE webfiltering_categories_link.gpid=metagroups_link.gpid \n\tAND webfiltering_categories_items.category=webfiltering_categories_link.category";
    $results = $q->QUERY_SQL($sql);
    if (mysql_num_rows($results) == 0) {
        scan_categories_clean();
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $uuid = $ligne["uuid"];
        $category = $ligne["category"];
        $ARRAY[$uuid][$category]["SITES"][] = $ligne["pattern"];
    }
    $sql = "SELECT webfiltering_categories_urls.pattern, metagroups_link.uuid,\n\twebfiltering_categories_link.category FROM metagroups_link,webfiltering_categories_link,\n\twebfiltering_categories_urls WHERE webfiltering_categories_link.gpid=metagroups_link.gpid\n\tAND webfiltering_categories_urls.category=webfiltering_categories_link.category";
    $results = $q->QUERY_SQL($sql);
    while ($ligne = mysql_fetch_assoc($results)) {
        $uuid = $ligne["uuid"];
        $category = $ligne["category"];
        $ARRAY[$uuid][$category]["URLS"][] = $ligne["pattern"];
    }
    $MAIN_UUID = array();
    while (list($uuid, $FINAL) = each($ARRAY)) {
        @mkdir("{$ArticaMetaStorage}/{$uuid}");
        $SourceFile = "{$ArticaMetaStorage}/{$uuid}/PERSONAL_CATEGORIES";
        $destfile = "{$ArticaMetaStorage}/{$uuid}/PERSONAL_CATEGORIES.gz";
        $MAIN_UUID[$uuid] = true;
        if ($GLOBALS["VERBOSE"]) {
            echo "Saving: {$destfile}\n";
        }
        @file_put_contents($SourceFile, serialize($FINAL));
        if (!$unix->compress($SourceFile, $destfile)) {
            @unlink($SourceFile);
            @unlink($destfile);
            continue;
        }
        ping_host($uuid);
        @unlink($SourceFile);
    }
    if ($aspid) {
        @unlink($pidfile);
    }
    scan_categories_clean($MAIN_UUID);
}
function rotate()
{
    $unix = new unix();
    $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);
        system_admin_mysql(1, "Bandwidthd rotation already executed since {$time}mn", null, __FILE__, __LINE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $mv = $unix->find_program("mv");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    $f[] = "/usr/bandwidthd/log.1.0.cdf";
    $f[] = "/usr/bandwidthd/log.1.1.cdf";
    $f[] = "/usr/bandwidthd/log.1.2.cdf";
    $f[] = "/usr/bandwidthd/log.1.3.cdf";
    $f[] = "/usr/bandwidthd/log.2.0.cdf";
    $f[] = "/usr/bandwidthd/log.2.1.cdf";
    $f[] = "/usr/bandwidthd/log.3.0.cdf";
    $DESTS = array();
    while (list($index, $fileSource) = each($f)) {
        $destination = "{$fileSource}." . time() . "log";
        $DESTS[] = $destination;
        shell_exec("{$mv} {$fileSource} {$destination}");
    }
    system_admin_mysql(2, "Restart bandwidthd in order to rotate events", null, __FILE__, __LINE__);
    shell_exec("/etc/init.d/bandwidthd restart");
    reset($f);
    while (list($index, $fileSource) = each($DESTS)) {
        $basename = basename($fileSource);
        $rotated_source = $fileSource;
        if (!$unix->compress($rotated_source, "{$BackupMaxDaysDir}/{$basename}.gz")) {
            continue;
        }
    }
}
function ACCESS_BACKUP()
{
    $unix = new unix();
    $filetime = "/etc/artica-postfix/pids/migrate_postgres.time";
    $pidfile = "/etc/artica-postfix/pids/migrate_postgres.pid";
    $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogPostGresDir");
    if ($GLOBALS["LogFileDeamonLogDir"] == null) {
        $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid-postgres/realtime-events";
    }
    $unix = new unix();
    if ($unix->process_exists($unix->get_pid_from_file($pidfile), basename(__FILE__))) {
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $TimeExe = $unix->file_time_min($filetime);
    if (!$GLOBALS["FORCE"]) {
        if ($TimeExe < 60) {
            die;
        }
    }
    @unlink($filetime);
    @file_put_contents($filetime, time());
    $FilesCount = 0;
    $TargetDir = "{$GLOBALS["LogFileDeamonLogDir"]}/access-InfluxToPostgresSQL";
    @mkdir($TargetDir, 0755);
    if (system_is_overloaded(basename(__FILE__))) {
        return;
    }
    $PossibleDirs[] = "/home/artica/squid/realtime-events/access-failed";
    $PossibleDirs[] = "/home/artica/squid/realtime-events/failed-backup-longtime";
    while (list($index, $PossibleDirectory) = each($PossibleDirs)) {
        if (!is_dir($PossibleDirectory)) {
            continue;
        }
        $Files = $unix->DirFiles($PossibleDirectory);
        while (list($filename, $none) = each($Files)) {
            squid_admin_mysql(1, "Starting importing {$filename}", null, __FILE__, __LINE__);
            if (ACCESS_BACKUP_SCAN("{$PossibleDirectory}/{$filename}")) {
                $FilesCount++;
                $unix->compress("{$PossibleDirectory}/{$filename}", "{$TargetDir}/{$filename}.gz");
                @unlink("{$PossibleDirectory}/{$filename}");
            }
            if (system_is_overloaded(basename(__FILE__))) {
                squid_admin_mysql(1, "Stopping injection after {$FilesCount} imported files (overloaded)", null, __FILE__, __LINE__);
                return;
            }
        }
    }
    $Directory = "/home/artica/squid/realtime-events/access-backup";
    $Files = $unix->DirFiles($Directory, "\\.gz\$");
    if (!is_dir($Directory)) {
        return;
    }
    while (list($filename, $none) = each($Files)) {
        squid_admin_mysql(1, "Starting importing {$filename}", null, __FILE__, __LINE__);
        if (ACCESS_BACKUP_SCAN("{$Directory}/{$filename}")) {
            $FilesCount++;
            @copy("{$Directory}/{$filename}", "{$TargetDir}/{$filename}");
            @unlink("{$Directory}/{$filename}");
        }
        if (system_is_overloaded(basename(__FILE__))) {
            squid_admin_mysql(1, "Stopping injection after {$FilesCount} imported files (overloaded)", null, __FILE__, __LINE__);
            return;
        }
    }
    if (system_is_overloaded(basename(__FILE__))) {
        squid_admin_mysql(1, "Stopping injection after {$FilesCount} imported files (overloaded)", null, __FILE__, __LINE__);
        return;
    }
    $Files = $unix->DirFiles($Directory, "\\.back\$");
    while (list($filename, $none) = each($Files)) {
        squid_admin_mysql(1, "Starting importing {$filename}", null, __FILE__, __LINE__);
        if (ACCESS_BACKUP_SCAN("{$Directory}/{$filename}")) {
            $FilesCount++;
            $unix->compress("{$Directory}/{$filename}", "{$TargetDir}/{$filename}.gz");
            @unlink("{$Directory}/{$filename}");
        }
        if (system_is_overloaded(basename(__FILE__))) {
            squid_admin_mysql(1, "Stopping injection after {$FilesCount} imported files (overloaded)", null, __FILE__, __LINE__);
            return;
        }
    }
    $Files = $unix->DirFiles($Directory);
    while (list($filename, $none) = each($Files)) {
        if (!preg_match("#^[0-9]+-[0-9]+-[0-9]+\$#", $filename)) {
            if (is_numeric($filename)) {
                @unlink("{$Directory}/{$filename}");
            }
            continue;
        }
        squid_admin_mysql(1, "Starting importing {$filename}", null, __FILE__, __LINE__);
        if (ACCESS_BACKUP_SCAN("{$Directory}/{$filename}")) {
            $FilesCount++;
            @copy("{$Directory}/{$filename}", "{$TargetDir}/{$filename}");
            @unlink("{$Directory}/{$filename}");
        }
        if (system_is_overloaded(basename(__FILE__))) {
            squid_admin_mysql(1, "Stopping injection after {$FilesCount} imported files (overloaded)", null, __FILE__, __LINE__);
            return;
        }
    }
    $Files = $unix->DirFiles($Directory);
    if (count($Files) == 0) {
        @rmdir($Directory);
    }
}
Beispiel #20
0
function backup_ldap()
{
    $unix = new unix();
    $slapcat = $unix->find_program("slapcat");
    if ($slapcat == null) {
        cyrus_admin_mysql(0, "Unable to find slapcat binary", null, __FILE__, __LINE__);
        return false;
    }
    $tempdir = $unix->TEMP_DIR();
    shell_exec("{$slapcat} -l {$tempdir}/ldap.ldif");
    @mkdir("{$GLOBALS["MOUNTED_PATH_FINAL"]}/ldap_backup", 0755, true);
    if (!is_dir("{$GLOBALS["MOUNTED_PATH_FINAL"]}/ldap_backup")) {
        cyrus_admin_mysql(0, "Unable to backup: Permission denied on ressource", null, __FILE__, __LINE__);
        @unlink("{$tempdir}/ldap.ldif");
        return false;
    }
    if ($GLOBALS["CyrusBackupNas"]["COMPRESS_ENABLE"] == 0) {
        if (!@copy("{$tempdir}/ldap.ldif", "{$GLOBALS["MOUNTED_PATH_FINAL"]}/ldap_backup/ldap.ldif")) {
            cyrus_admin_mysql(0, "Unable to backup: Permission denied on ressource", null, __FILE__, __LINE__);
            @unlink("{$tempdir}/ldap.ldif");
            return false;
        }
    }
    if ($GLOBALS["CyrusBackupNas"]["COMPRESS_ENABLE"] == 1) {
        if (!$unix->compress("{$tempdir}/ldap.ldif", "{$GLOBALS["MOUNTED_PATH_FINAL"]}/ldap_backup/ldap.ldif.gz")) {
            cyrus_admin_mysql(0, "Unable to backup: Permission denied on ressource", null, __FILE__, __LINE__);
            @unlink("{$tempdir}/ldap.ldif");
            return false;
        }
    }
    $ldap = new clladp();
    if (!@file_put_contents("{$GLOBALS["MOUNTED_PATH_FINAL"]}/ldap_backup/suffix", $ldap->suffix)) {
        cyrus_admin_mysql(0, "Unable to backup: Permission denied on ressource", null, __FILE__, __LINE__);
    }
    @unlink("{$tempdir}/ldap.ldif");
}
}
@mkdir("/home/postfix/logrotate", 0755, true);
$q = new mysql();
$hier = $q->HIER();
$targetcompressed = "/home/postfix/logrotate/{$hier}.gz";
$unix = new unix();
if (is_file($targetfile)) {
    if (!connect_from($targetfile)) {
        postfix_admin_mysql(0, "FATAL! {$targetfile} connect_from() failed", null, __FILE__, __LINE__);
        return;
    }
    if (!pflogsumm($targetfile)) {
        postfix_admin_mysql(0, "FATAL! {$targetfile} pflogsumm() failed", null, __FILE__, __LINE__);
        return;
    }
    if (!$unix->compress($targetfile, $targetcompressed)) {
        @unlink($targetcompressed);
        return;
    }
    @unlink($targetfile);
}
if (is_file($targetcompressed)) {
    echo "{$targetcompressed} exists, abort\n";
    die;
}
if (!@copy("/var/log/mail.log", $targetfile)) {
    postfix_admin_mysql(0, "FATAL! unable to rotate mail.log", null, __FILE__, __LINE__);
    die;
}
$echo = $unix->find_program("echo");
shell_exec("{$echo} \"\" >/var/log/mail.log");
function scan_backup_dir()
{
    $unix = new unix();
    $sock = new sockets();
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    echo "BackupMaxDaysDir: {$BackupMaxDaysDir}\n";
    build_progress_scandir("{scanning} {$BackupMaxDaysDir}", 20);
    sleep(3);
    $c = 0;
    $find = $unix->find_program("find");
    exec("{$find} {$BackupMaxDaysDir} 2>&1", $results);
    while (list($num, $filename) = each($results)) {
        if (!is_file($filename)) {
            build_progress_scandir("{skip} {$filename}", 30);
            continue;
        }
        $basename = basename($filename);
        if (preg_match("#^cache-#", $basename)) {
            build_progress_scandir("{skip} {$basename}", 30);
            continue;
        }
        if (!preg_match("#^access-tail#", $basename)) {
            build_progress_scandir("{skip} {$basename}", 30);
            continue;
        }
        build_progress_scandir("{importing} {$basename}", 30);
        $c++;
        if (upload_mysql($filename, true)) {
            $c++;
        }
    }
    $unix = new unix();
    $tempdir = $unix->TEMP_DIR();
    $destfile = "{$tempdir}/current-access.log";
    if ($unix->compress("/var/log/squid/access.log", $destfile)) {
        build_progress_scandir("{importing} squid/access.log", 90);
        upload_mysql($destfile, true, true);
        @unlink($destfile);
    }
    if ($c == 0) {
        build_progress_scandir("{failed} 0 {files}", 110);
        return;
    }
    build_progress_scandir("{done} {$c} {files}", 100);
}
function compile()
{
    $unix = new unix();
    $MAIN_CACHE = unserialize(@file_get_contents("/root/UFDB_COMPILE_DATABASES"));
    $q = new mysql_squid_builder();
    $DB_LISTES = TransArray();
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    $WORKDIR = "/home/artica/ufdbv10";
    $OUTPUTDIR = "/home/artica/ufdbv10Export";
    @mkdir($OUTPUTDIR, 0755, true);
    $UPDATED = 0;
    while (list($category_table, $category) = each($DB_LISTES)) {
        echo "Starting Cleaning {$category_table}\n";
        Clean_table($category_table);
        $CountCategoryTableRows = $q->COUNT_ROWS("{$category_table}");
        echo "{$category_table}: {$CountCategoryTableRows} rows\n";
        if ($CountCategoryTableRows == 0) {
            sendEmail("ALERT! {$category_table} NO ROW!");
            continue;
        }
        if (intval($MAIN_CACHE[$category_table]["ROWS"]) == $CountCategoryTableRows) {
            ToSyslog($category_table . " [SKIPPED] {$MAIN_CACHE[$category_table]["ROWS"]} == {$CountCategoryTableRows}");
            echo "{$category_table}: SKIPPED\n";
            continue;
        }
        $workingtempdir = "{$WORKDIR}/{$category_table}";
        $workingtempFile = "{$workingtempdir}/domains";
        @mkdir($workingtempdir, 0777, true);
        $unix->chmod_func(0777, $workingtempdir);
        if (is_file($workingtempFile)) {
            @unlink($workingtempFile);
        }
        $sql = "SELECT pattern FROM {$category_table} ORDER BY pattern INTO OUTFILE '{$workingtempFile}' LINES TERMINATED BY '\n';";
        $q = new mysql_squid_builder();
        $q->QUERY_SQL($sql);
        if (!$q->ok) {
            sendEmail("ALERT! {$category_table} MySQL error", $q->mysql_error);
            die;
        }
        @file_put_contents("{$workingtempdir}/urls", "\n");
        @file_put_contents("{$workingtempdir}/expressions", "\n");
        @unlink("{$workingtempdir}/domains.ufdb");
        $categoryKey = compile_databases_categoryKey($category);
        $u = " -u {$workingtempdir}/urls";
        $d = " -d {$workingtempdir}/domains";
        $cmd = "{$ufdbGenTable} -n -q -W -t {$categoryKey}{$d}{$u} >/dev/null 2>&1";
        echo "[{$category_table}]::{$category} {$cmd}\n";
        $UPDATED++;
        $t = time();
        $resultsCMD[] = $cmd;
        ToSyslog("[FINISH]:: Compiling {$category_table}...");
        exec($cmd, $resultsCMD);
        if (!is_file("{$workingtempdir}/domains.ufdb")) {
            sendEmail("ALERT! {$category_table} domains.ufdb no such file!");
            continue;
        }
        @mkdir("/home/artica/backuped_categories", 0755);
        $unix->compress($workingtempFile, "/home/artica/backuped_categories/{$category_table}.gz");
        echo "[{$category_table}]::{$category} Compressing to {$OUTPUTDIR}/{$category_table}.gz\n";
        if (!$unix->compress("{$workingtempdir}/domains.ufdb", "{$OUTPUTDIR}/{$category_table}.gz")) {
            sendEmail("ALERT! unable to compress {$workingtempdir}/domains.ufdb");
            die;
        }
        @unlink("/home/ufdbcat/{$category_table}/domains.ufdb");
        @copy("{$workingtempdir}/domains.ufdb", "/var/lib/ufdbartica/{$category_table}/domains.ufdb");
        echo "[{$category_table}]::{$category} Indexing....\n";
        $md5file = md5_file("{$workingtempdir}/domains.ufdb");
        $md5zip = md5_file("{$OUTPUTDIR}/{$category_table}.gz");
        ToSyslog("{$OUTPUTDIR}/{$category_table}.gz [UPDATED]");
        $UPDATED_DBS[] = "{$category_table} ({$CountCategoryTableRows})";
        $MAIN_CACHE[$category_table]["ROWS"] = $CountCategoryTableRows;
        $MAIN_CACHE[$category_table]["TIME"] = time();
        $MAIN_CACHE[$category_table]["MD5SRC"] = $md5file;
        $MAIN_CACHE[$category_table]["MD5GZ"] = $md5zip;
    }
    ToSyslog("[FINISH]:: Building indexes {$UPDATED} updated...");
    @file_put_contents("/root/UFDB_COMPILE_DATABASES", serialize($MAIN_CACHE));
    @file_put_contents("{$OUTPUTDIR}/index.txt", base64_encode(serialize($MAIN_CACHE)));
    if ($UPDATED > 0) {
        ToSyslog("[FINISH]:: PushToRepo_alls()");
        PushToRepo_alls();
        sendEmail("{$UPDATED} Official Webfiltering databases updated", @implode("\n", $UPDATED_DBS));
    }
}
        continue;
    }
    if (preg_match("#(blacklist|whitelist)\\s+list\\s+#", $ligne)) {
        continue;
    }
    if (preg_match("#acl whitelist from#", $ligne)) {
        if (strpos($ligne, "*") == 0) {
            continue;
        }
    }
    echo "{$ligne}\n";
    $T[] = $ligne;
}
@file_put_contents("/root/milter-greylist-database.txt", @implode("\n", $T));
$unix = new unix();
if (!$unix->compress("/root/milter-greylist-database.txt", "/root/milter-greylist-database.gz")) {
    die;
}
@unlink("/root/milter-greylist-database.txt");
$md5 = md5_file("/root/milter-greylist-database.gz");
$MAIN["PATTERN"]["TIME"] = time();
$MAIN["PATTERN"]["MD5"] = $md5;
@file_put_contents("/root/milter-greylist-database.txt", serialize($MAIN));
$ftp_serv = @file_get_contents("/root/ftp-hostname");
$ftp_passw = @file_get_contents("/root/ftp-password");
$curl = $unix->find_program("curl");
$ftp_passw = $unix->shellEscapeChars($ftp_passw);
echo "\n ************** FTP WWWW **************\n";
echo "Push to ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/\n";
$cmdline = "{$curl} -T /root/milter-greylist-database.txt ftp://mirror.articatech.net/www.artica.fr/WebfilterDBS/ --user {$ftp_passw}\n";
echo $cmdline . "\n";
Beispiel #25
0
function proxy_pack_debug_compress()
{
    $unix = new unix();
    $filename = "/var/log/apache2/proxy.pack.debug";
    $unix->compress($filename, "/usr/share/artica-postfix/ressources/logs/web/proxy.pack.debug.gz");
}
function support_step2()
{
    $files[] = "/var/log/squid/cache.log";
    $files[] = "/var/log/syslog";
    $files[] = "/var/log/messages";
    $files[] = "/var/log/auth.log";
    $files[] = "/var/log/squid/access.log";
    $files[] = "/var/log/squid/external-acl.log";
    $files[] = "/var/log/squid/logfile_daemon.debug";
    $files[] = "/var/log/php.log";
    $files[] = "/var/log/mail.log";
    $files[] = "/var/log/squid.watchdog.log";
    $files[] = "/var/log/squid/ufdbguardd.log";
    $files[] = "/var/log/samba/log.winbindd";
    $files[] = "/etc/samba/smb.conf";
    $files[] = "/var/log/samba/log.nmbd";
    $files[] = "/var/log/samba/log.smbd";
    $files[] = "/var/run/mysqld/mysqld.err";
    $files[] = "/etc/init.d/artica-ifup";
    $files[] = "/var/log/net-start.log";
    $files[] = "/var/log/artica-ufdb.log";
    $files[] = "/var/log/artica-meta.log";
    $files[] = "/var/log/webfiltering-update.log";
    $files[] = "{$GLOBALS["ARTICALOGDIR"]}/ufdbguard-tail.debug";
    $unix = new unix();
    $cp = $unix->find_program("cp");
    $dmesg = $unix->find_program("dmesg");
    @mkdir("/usr/share/artica-postfix/ressources/support", 0755, true);
    shell_exec("{$dmesg} >/usr/share/artica-postfix/ressources/support/dmesg.txt");
    progress("{get_all_logs}", 45);
    if (is_dir("/etc/squid3")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-squid3", 0755, true);
        $cmd = "/bin/cp -rf /etc/squid3/* /usr/share/artica-postfix/ressources/support/etc-squid3/";
        shell_exec("{$cmd}");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    progress("{get_all_logs}", 46);
    if (is_file("/tmp/squid.conf")) {
        if (is_file($squidbin)) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k parse >/etc-squid3/tmp.squid.conf.log 2>&1");
        }
        @copy("/tmp/squid.conf", "/usr/share/artica-postfix/ressources/support/etc-squid3/tmp.squid.conf");
    }
    progress("{get_all_logs}", 47);
    if (is_dir("/etc/postfix")) {
        @mkdir("/usr/share/artica-postfix/ressources/support/etc-postfix", 0755, true);
        $cmd = "/bin/cp -rf /etc/postfix/* /usr/share/artica-postfix/ressources/support/etc-postfix/";
        shell_exec("{$cmd}");
    }
    progress("{get_all_logs}", 48);
    while (list($a, $b) = each($files)) {
        if (is_file($b)) {
            progress("{get_all_logs}:" . basename($b), 48);
            $destfile = basename("{$b}.gz");
            $unix->compress($b, "/usr/share/artica-postfix/ressources/support/{$destfile}");
        }
    }
    progress("{get_all_logs} lshw", 49);
    $lshw = $unix->find_program("lshw");
    exec("{$lshw} -class network 2>&1", $results);
    progress("{get_all_logs} ifconfig", 50);
    $ifconfig = $unix->find_program("ifconfig");
    exec("{$ifconfig} -a 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} IP", 50);
    $ip = $unix->find_program("ip");
    exec("{$ip} link show 2>&1", $results);
    $results[] = "\n\t***************\n";
    progress("{get_all_logs} Route", 50);
    exec("{$ip} route 2>&1", $results);
    $results[] = "\n\t***************\n";
    $f = explode("\n", @file_get_contents("/etc/iproute2/rt_tables"));
    while (list($a, $line) = each($f)) {
        if (!preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) {
            continue;
        }
        $table_num = $re[1];
        $tablename = $re[2];
        if ($table_num == 0) {
            continue;
        }
        if ($table_num > 252) {
            continue;
        }
        $results[] = "\n\t***** Table route {$table_num} named {$tablename} *****\n";
        exec("{$ip} route show table {$table_num} 2>&1", $results);
        $results[] = "\n\t***************\n";
    }
    progress("{get_all_logs} uname", 51);
    $unix = new unix();
    $uname = $unix->find_program("uname");
    $results[] = "{$uname} -a:";
    exec("{$uname} -a 2>&1", $results);
    $results[] = "\n";
    $results[] = "/bin/bash --version:";
    exec("/bin/bash --version 2>&1", $results);
    $results[] = "\n";
    progress("{get_all_logs} gdb", 52);
    $gdb = $unix->find_program("gdb");
    if (is_file($gdb)) {
        $results[] = "{$gdb} --version:";
        exec("{$gdb} --version 2>&1", $results);
    } else {
        $results[] = "gdb no such binary....";
    }
    $results[] = "\n";
    $smbd = $unix->find_program("smbd");
    if (is_file($smbd)) {
        $results[] = "{$smbd} -V:";
        exec("{$smbd} -V 2>&1", $results);
    } else {
        $results[] = "smbd no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs} {$squidbin}", 53);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
    } else {
        $results[] = "squid no such binary....";
    }
    $results[] = "\n";
    progress("{get_all_logs}", 54);
    if (is_file($squidbin)) {
        $results[] = "{$squidbin} -v:";
        exec("{$squidbin} -v 2>&1", $results);
        squid_watchdog_events("Reconfiguring Proxy parameters...");
        exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results);
        squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results));
        shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-conf-check.txt");
        if (is_file("/tmp/squid.conf")) {
            shell_exec("{$squidbin} -f /tmp/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-temp-check.txt");
        }
    } else {
        $results[] = "squid3 no such binary....";
    }
    progress("{get_all_logs} DF", 55);
    $results[] = "\n";
    $df = $unix->find_program("df");
    if (is_file($df)) {
        $results[] = "{$df} -h:";
        exec("{$df} -h 2>&1", $results);
    } else {
        $results[] = "{$df} no such binary....";
    }
    progress("{get_all_logs}", 56);
    @file_put_contents("/usr/share/artica-postfix/ressources/support/generated.versions.txt", @implode("\n", $results));
}
function compressAndClean()
{
    @unlink("/etc/artica-postfix/POSTFIX_COMPRESS_CLEAN.time");
    @file_put_contents("/etc/artica-postfix/POSTFIX_COMPRESS_CLEAN.time", time());
    $unix = new unix();
    $q = new mysql();
    $hier = $q->HIER();
    $targetSourceFile = "{$hier}.log";
    if (system_is_overloaded(basename(__FILE__))) {
        postfix_admin_mysql(0, "Overloaded system, aborting rotation compressing", null, __FILE__, __LINE__);
        return;
    }
    $BaseWorkDir = "/home/postfix/logrotate";
    $targetcompressed = "/home/postfix/logrotate/{$hier}.gz";
    if (!($handle = opendir($BaseWorkDir))) {
        echo "Failed open {$BaseWorkDir}\n";
        return;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $targetfile = "{$BaseWorkDir}/{$filename}";
        if (strpos($filename, ".gz") > 0) {
            continue;
        }
        if ($filename == $targetSourceFile) {
            echo "Hier: {$targetSourceFile} was not compressed!\n";
            if (is_file($targetfile)) {
                if (!connect_from($targetfile)) {
                    postfix_admin_mysql(0, "FATAL! {$targetfile} connect_from() failed", null, __FILE__, __LINE__);
                    return;
                }
                if (!pflogsumm($targetfile)) {
                    postfix_admin_mysql(0, "FATAL! {$targetfile} pflogsumm() failed", null, __FILE__, __LINE__);
                    return;
                }
                if (!$unix->compress($targetfile, $targetcompressed)) {
                    @unlink($targetcompressed);
                    continue;
                }
                @unlink($targetfile);
            }
            continue;
        }
        $ToCompressPath = "{$BaseWorkDir}/{$filename}";
        $ToCompressPath = str_replace(".log", ".gz", $ToCompressPath);
        echo "Compressing {$targetfile} -> {$ToCompressPath}\n";
        if (!$unix->compress($targetfile, $ToCompressPath)) {
            echo "Compressing {$targetfile} -> {$ToCompressPath} - FAILED -\n";
            @unlink($ToCompressPath);
            continue;
        } else {
            postfix_admin_mysql(2, "Success compressing {$targetfile}", null, __FILE__, __LINE__);
            @unlink($targetfile);
        }
    }
}