function GoogleSafeBrowsingInCache($servername) { $dbfile = "/var/log/squid/GoogleSafeBrowsing.db"; $GoogleSafeBrowsingCacheTime = $GLOBALS["GoogleSafeBrowsingCacheTime"]; if (isset($GLOBALS["GoogleSafeBrowsingCache_time"])) { $Since = tool_time_min($GLOBALS["GoogleSafeBrowsingCache_time"]); if ($GLOBALS["GOOGLE_SAFE"]) { events("GoogleSafeBrowsingInCache: {$dbfile} ({$Since}Mn/{$GoogleSafeBrowsingCacheTime}Mn"); } if ($Since > $GoogleSafeBrowsingCacheTime) { $GLOBALS["GoogleSafeBrowsingMEMCache"] = array(); @unlink($dbfile); } } $MD5 = md5($servername); if (isset($GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5])) { if (count($GLOBALS["GoogleSafeBrowsingMEMCache"]) > 64000) { $GLOBALS["GoogleSafeBrowsingMEMCache"] = array(); } return $GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5]; } tool_create_berekley($dbfile); if (!is_file($dbfile)) { return null; } $db_con = @dba_open($dbfile, "r", "db4"); if (!$db_con) { events("GoogleSafeBrowsingInCache:: FATAL!!!::{$dbfile}, unable to open"); return null; } if (!@dba_exists("CREATED", $db_con)) { $GLOBALS["GoogleSafeBrowsingCache_time"] = time(); @dba_replace("CREATED", time(), $db_con); } if (!isset($GLOBALS["GoogleSafeBrowsingCache_time"])) { if (@dba_exists("CREATED", $db_con)) { $GLOBALS["GoogleSafeBrowsingCache_time"] = dba_fetch("CREATED", $db_con); } } if (!@dba_exists($MD5, $db_con)) { @dba_close($db_con); return null; } $result = dba_fetch($MD5, $db_con); $GLOBALS["GoogleSafeBrowsingMEMCache"][$MD5] = $result; @dba_close($db_con); return $result; }
function HyperCacheSizeLog($size) { $dbfile = "/usr/share/squid3/" . date("Ymd") . "_HyperCacheSizeLog.db"; tool_create_berekley($dbfile); $db_con = @dba_open($dbfile, "c", "db4"); if (!$db_con) { events("UserAuthDB:: FATAL!!!::{$GLOBALS["UserAuthDB_path"]}, unable to open"); return false; } $keymd5 = date("Y-m-d H:00:00"); if (!@dba_exists($keymd5, $db_con)) { $array["HITS"] = 1; $array["SIZE"] = $size; @dba_replace($keymd5, serialize($array), $db_con); @dba_close($db_con); return; } $CURRENT = intval(dba_fetch($keymd5, $db_con)); $array = unserialize($CURRENT); $array["HITS"] = $array["HITS"] + 1; $array["SIZE"] = $array["SIZE"] + $size; @dba_replace($keymd5, serialize($array), $db_con); @dba_close($db_con); }