function HyperCacheScanDBFile($dbfile, $ID)
{
    $TT = time();
    $filesize = FormatBytes(@filesize($dbfile) / 1024);
    if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
        echo "HyperCacheScanDBFile ---> {$dbfile} [" . __LINE__ . "]\n";
    }
    $db_con = dba_open($dbfile, "r", "db4");
    if (!$db_con) {
        events("{failed}: DB open" . basename($dbfile), $ID, 0, __LINE__);
        return false;
    }
    $HyperCacheRules = HyperCacheRulesLoad();
    if (!isset($HyperCacheRules[$ID])) {
        if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
            events("No rule for ID {$ID}!", 0, 2, __LINE__);
        }
        return;
    }
    $FileTypesArray = unserialize($HyperCacheRules[$ID]["FileTypes"]);
    if (count($FileTypesArray) == 0) {
        events("No Files type defined, aborting", $ID, 0, __LINE__);
        return;
    }
    $urikey = dba_firstkey($db_con);
    $ARRAY_SAVE = array();
    $c = 0;
    $HyPerCacheClass = new HyperCache();
    while ($urikey != false) {
        $FileType = dba_fetch($urikey, $db_con);
        if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
            echo "HyperCacheScanDBFile::[{$FileType}]: {$urikey}\n";
        }
        if ($FileType == "NONE") {
            $FileType = HyperCacheGetMimeType($urikey, $ID);
            if ($FileType == null) {
                $urikey = dba_nextkey($db_con);
                continue;
            }
            $ARRAY_SAVE[$urikey] = $FileType;
        }
        if (!isset($FileTypesArray[$FileType])) {
            if (!$HyPerCacheClass->ChecksOtherRules($urikey, $FileType, $ID)) {
                if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
                    events("{$urikey} {$FileType} No match...", $ID, 3, __LINE__);
                }
                $urikey = dba_nextkey($db_con);
                continue;
            }
        }
        $TargetFile = HyperCacheScanBuildLocalPath($urikey, $ID);
        $FullTargetFile = $GLOBALS["HyperCacheStoragePath"] . "/" . $TargetFile;
        if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
            events("HyperCacheScanDBFile::Local file: {$FullTargetFile}", $ID, 3, __LINE__);
        }
        if (is_file($FullTargetFile)) {
            $urikey = dba_nextkey($db_con);
            continue;
        }
        events("Downloading {$urikey} [{$FileType}]", $ID, 2, __LINE__);
        HyperCacheScanDownload($urikey, $TargetFile, $ID, $FileType);
        $urikey = dba_nextkey($db_con);
    }
    @dba_close($db_con);
    HyperCacheScanDBFile_setbulk($dbfile, $ARRAY_SAVE);
}
function HyperCacheScanDBFile($dbfile, $ID)
{
    $TT = time();
    $unix = new unix();
    $Cache = unserialize(@file_get_contents("/usr/share/squid3/lastScan.array"));
    if (isset($Cache[$ID][$dbfile])) {
        $filemm = filemtime($dbfile);
        if ($filemm == $Cache[$ID][$dbfile]) {
            if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
                echo "HyperCacheScanDBFile {$filemm} == {$Cache[$ID][$dbfile]} [" . __LINE__ . "]\n";
            }
            return;
        }
    }
    $filesize = FormatBytes(@filesize($dbfile) / 1024);
    if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
        echo "HyperCacheScanDBFile ---> {$dbfile} [" . __LINE__ . "]\n";
    }
    $db_con = dba_open($dbfile, "r", "db4");
    if (!$db_con) {
        events("{failed}: DB open" . basename($dbfile), $ID, 0, __LINE__);
        return false;
    }
    $HyperCacheRules = HyperCacheRulesLoad();
    if (!isset($HyperCacheRules[$ID])) {
        if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
            events("No rule for ID {$ID}!", 0, 2, __LINE__);
        }
        return;
    }
    $FileTypesArray = unserialize($HyperCacheRules[$ID]["FileTypes"]);
    if (count($FileTypesArray) == 0) {
        events("No Files type defined, aborting", $ID, 0, __LINE__);
        return;
    }
    $urikey = dba_firstkey($db_con);
    $ARRAY_SAVE = array();
    $c = 0;
    while ($urikey != false) {
        $FileType = dba_fetch($urikey, $db_con);
        $GLOBALS["MAINDB"][$urikey] = $FileType;
        $urikey = dba_nextkey($db_con);
    }
    @dba_close($db_con);
    $GLOBAL["BLACKLISTED"] = array();
    if (!class_exists("HyperCache")) {
        include_once dirname(__FILE__) . "/ressources/class.HyperCache.inc";
    }
    $HyPerCacheClass = new HyperCache();
    if (!function_exists("HyperCacheRulesBlacklist")) {
        include_once dirname(__FILE__) . "/ressources/class.hyperCache-central.inc";
    }
    while (list($urikey, $FileType) = each($GLOBALS["MAINDB"])) {
        if (HyperCacheRulesBlacklist($urikey)) {
            if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
                echo "HyperCacheScanDBFile:: {$urikey} Blacklisted";
            }
            $GLOBAL["BLACKLISTED"][$urikey] = true;
            continue;
        }
        $SCANNED_URL = ifTracker($urikey);
        $H = parse_url($SCANNED_URL);
        $path = $H["path"];
        $filename = basename($path);
        $extention = $unix->file_extension($filename);
        $GetMimeFromExtension = GetMimeFromExtension($extention);
        if ($GetMimeFromExtension != null) {
            if ($FileType != $GetMimeFromExtension) {
                $FileType = $GetMimeFromExtension;
                $ARRAY_SAVE[$urikey] = $FileType;
            }
        } else {
            if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
                echo "HyperCacheScanDBFile:: {$SCANNED_URL} {$filename}/{$FileType} - {$extention} no MIME ??\n";
            }
        }
        if ($FileType == "NONE") {
            $FileType = HyperCacheGetMimeType($urikey, $ID);
            if ($FileType == null) {
                $GLOBAL["BLACKLISTED"][$urikey] = true;
                continue;
            }
            $ARRAY_SAVE[$urikey] = $FileType;
        }
        if (!isset($FileTypesArray[$FileType])) {
            if (!$HyPerCacheClass->ChecksOtherRules($urikey, $FileType, $ID)) {
                $GLOBAL["BLACKLISTED"][$urikey] = true;
                if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
                    events("{$urikey} {$FileType} No match...", $ID, 3, __LINE__);
                }
                continue;
            }
        }
        $TargetFile = HyperCacheScanBuildLocalPath($urikey, $ID);
        $FullTargetFile = $GLOBALS["HyperCacheStoragePath"] . "/" . $TargetFile;
        if (is_file($FullTargetFile)) {
            continue;
        }
        events("Downloading {$urikey} [{$FileType}]", $ID, 2, __LINE__);
        HyperCacheScanDownload($urikey, $TargetFile, $ID, $FileType);
    }
    if (count($GLOBAL["BLACKLISTED"]) > 0) {
        HyperCacheScanDBFile_removebulk($dbfile, $GLOBAL["BLACKLISTED"]);
    }
    HyperCacheScanDBFile_setbulk($dbfile, $ARRAY_SAVE);
    $filemm = filemtime($dbfile);
    $Cache[$ID][$dbfile] = $filemm;
    @file_put_contents("/usr/share/squid3/lastScan.array", serialize($Cache));
}