function categories_match($gpid, $sitname) { $sitname = trim($sitname); if (preg_match("#^www\\.(.+)#", $sitname, $re)) { $sitname = $re[1]; } if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) { $sitname = $re[1]; } if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: {$gpid} `{$sitname}`"); } $categories_get_memory = categories_get_memory($gpid, $sitname); if ($categories_get_memory != null) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` "); } if ($categories_get_memory == "UNKNOWN") { if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> UNKNOWN"); } return null; } if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> {$categories_get_memory}"); } return $categories_get_memory; } $q = new mysql_catz(); $categoriF = $q->GET_CATEGORIES($sitname); $trans = $q->TransArray(); if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> RESULTS: `{$categoriF}` "); } if ($categoriF == null) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> SET TO `UNKNOWN` "); } categories_set_memory($gpid, $sitname, "UNKNOWN"); return null; } if (strpos($categoriF, ",") > 0) { $categoriT = explode(",", $categoriF); } else { $categoriT[] = $categoriF; } while (list($a, $b) = each($categoriT)) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> category IS: [{$b}] [" . __LINE__ . "]"); } $MAIN[$b] = true; } $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl"; $categories = unserialize(@file_get_contents($filename)); while (list($category_table, $category_rule) = each($categories)) { $category_rule = urlencode($category_rule); $categoryname = $trans[$category_table]; if (isset($MAIN[$categoryname])) { if ($GLOBALS["DEBUG"]) { WLOG("FOUND `{$categoryname}` -> `{$category_rule}` "); } categories_set_memory($gpid, $sitname, $category_rule); return $category_rule; } else { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> {$categoryname} = NO MATCH [" . __LINE__ . "]"); } } } categories_set_memory($gpid, $sitname, "UNKNOWN"); }
function categories_match($gpid, $sitname) { if (preg_match("#^www\\.(.+)#", $sitname, $re)) { $sitname = $re[1]; } if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) { $sitname = $re[1]; } if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Analyze: Group: {$gpid} `{$sitname}`"); } $categories_get_memory = categories_get_memory($gpid, $sitname); if ($categories_get_memory != null) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` "); } if ($categories_get_memory == "UNKNOWN") { return null; } return $categories_get_memory; } $q = new mysql_catz(); if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Group: {$gpid} `{$sitname}` -> CATEGORY ?? [" . __LINE__ . "]"); } $categoriF = $q->GET_CATEGORIES($sitname); $trans = $q->TransArray(); if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Group: {$gpid} `{$sitname}` -> category: `{$categoriF}` "); } if ($categoriF == null) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("squid_familysite()"); } if (!class_exists("squid_familysite")) { include_once dirname(__FILE__) . "/ressources/class.squid.familysites.inc"; } $qF = new squid_familysite(); $familysite = $qF->GetFamilySites($sitname); if ($familysite != $sitname) { $categoriF = $q->GET_CATEGORIES($familysite); if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("Group: {$gpid} `{$sitname}` -> {$familysite} -> category: `{$categoriF}` "); } } } if ($categoriF == null) { categories_set_memory($gpid, $sitname, "UNKNOWN"); return null; } if (strpos($categoriF, ",") > 0) { $categoriT = explode(",", $categoriF); } else { $categoriT[] = $categoriF; } while (list($a, $b) = each($categoriT)) { $MAIN[$b] = true; } $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl"; $categories = unserialize(@file_get_contents($filename)); while (list($category_table, $category_rule) = each($categories)) { $category_rule = urlencode($category_rule); $categoryname = $trans[$category_table]; if (isset($MAIN[$categoryname])) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("FOUND `{$categoryname}` -> `{$category_rule}` "); } categories_set_memory($gpid, $sitname, $category_rule); return $category_rule; } } categories_set_memory($gpid, $sitname, "UNKNOWN"); }
function categories_match($gpid, $sitname, $MD5KEY) { $sitname = trim($sitname); if (preg_match("#^www\\.(.+)#", $sitname, $re)) { $sitname = $re[1]; } if (preg_match("#^(.+):[0-9]+]#", $sitname, $re)) { $sitname = $re[1]; } if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: {$gpid} `{$sitname}`"); } $categories_get_memory = categories_get_memory($gpid, $sitname, $MD5KEY); if ($categories_get_memory == 0) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> MEMORY: `{$categories_get_memory}` "); } categories_logs("{$gpid};MEMORY;UNKNOWN/NONE"); if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> UNKNOWN"); } return false; } if ($categories_get_memory == 1) { categories_logs("{$gpid};MEMORY;TRUE/-"); if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> TRUE"); } return true; } if ($categories_get_memory == 2) { categories_logs("{$gpid};MEMORY;FALSE/-"); if ($GLOBALS["DEBUG"]) { WLOG("Analyze: Group: FROM MEMORY `{$sitname}` -> FALSE"); } return false; } $q = new mysql_catz(); $categoriF = $q->GET_CATEGORIES($sitname); $trans = $q->TransArray(); if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> RESULTS: `{$categoriF}` "); } if ($categoriF == null) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> SET TO `UNKNOWN` "); } categories_logs("{$gpid};QUERY;UNKNOWN/NONE"); categories_set_memory($gpid, $sitname, 0, $MD5KEY); return false; } if (strpos($categoriF, ",") > 0) { $categoriT = explode(",", $categoriF); } else { $categoriT[] = $categoriF; } while (list($a, $b) = each($categoriT)) { if ($GLOBALS["DEBUG"]) { WLOG("Group: {$gpid} `{$sitname}` -> category IS: [{$b}] [" . __LINE__ . "]"); } $MAIN[$b] = true; } if (!isset($GLOBALS["CONFIG"][$gpid])) { $filename = "/etc/squid3/acls/catz_gpid{$gpid}.acl"; $GLOBALS["CONFIG"][$gpid] = unserialize(@file_get_contents($filename)); } $categories = $GLOBALS["CONFIG"][$gpid]; while (list($category_table, $category_rule) = each($categories)) { $category_rule = urlencode($category_rule); $categoryname = $trans[$category_table]; if ($categoryname == null) { $categoryname = $category_rule; } if (isset($MAIN[$categoryname])) { if ($GLOBALS["DEBUG"]) { WLOG("FOUND `{$categoryname}` -> `{$category_rule}` "); } categories_logs("{$gpid};QUERY;TRUE/{$categoryname}"); categories_set_memory($gpid, $sitname, 1, $MD5KEY); return true; } } categories_logs("{$gpid};QUERY;FALSE/" . @implode(",", $categoriT)); categories_set_memory($gpid, $sitname, 2, $MD5KEY); return false; }