function GetMacToUid($mac) { if (isset($GLOBALS["GetMacToUid"][$mac])) { return $GLOBALS["GetMacToUid"][$mac]; } $sql = "SELECT ruleid,uid FROM hotspot_sessions WHERE MAC='{$mac}'"; if ($GLOBALS["DEBUG_LEVEL"] > 0) { WLOG("GetMacToUid() {$sql}"); } $ligne = @mysql_fetch_array(api_QUERY_SQL($sql)); if ($ligne["uid"] != null) { $ruleid = $ligne["ruleid"]; $GLOBALS["GetMacToUid"][$mac] = array("UID" => $ligne["uid"], "RULE" => $ruleid); } if (!isset($GLOBALS["GetMacToUid"][$mac])) { return array(); } return $GLOBALS["GetMacToUid"][$mac]; }
function api_mysql_COUNT_ROWS($table) { $sql = "show TABLE STATUS WHERE Name='{$table}'"; if ($GLOBALS["DEBUG_UNLOCK"]) { WLOG("api_mysql_COUNT_ROWS::{$sql}"); } $ligne = @mysql_fetch_array(api_QUERY_SQL($sql)); if ($ligne["Rows"] == null) { $ligne["Rows"] = 0; } return $ligne["Rows"]; }
function CheckPattern($name, $gpid, $type) { if (!is_numeric($gpid)) { return; } if (!is_numeric($type)) { return; } if (!isset($GLOBALS["CACHE_CLEAN_MYSQL"])) { $GLOBALS["CACHE_CLEAN_MYSQL"] = time(); } if ($type == 3) { if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\$#", $name)) { return 0; } } try { $sql = "SELECT ID,`value` FROM webfilter_aclsdynamic WHERE gpid={$gpid} AND `type`={$type}"; $results = api_QUERY_SQL($sql); if (mysql_num_rows($results) == 0) { if ($GLOBALS["DEBUG_LEVEL"] > 1) { WLOG("CheckPattern()::{$sql} -> NO ROW"); } return 0; } while ($ligne = mysql_fetch_assoc($results)) { $value = $ligne["value"]; if (preg_match("#re:(.+)#", $value, $re)) { if (preg_match("#{$re[1]}#i", $name)) { return $ligne["ID"]; } continue; } $value = string_to_regex($value); if ($GLOBALS["DEBUG_LEVEL"] > 3) { WLOG("CheckPattern()::Checks `{$value}` with `{$name}`"); } if (preg_match("#{$value}#i", $name)) { if ($GLOBALS["DEBUG_LEVEL"] > 3) { WLOG("CheckPattern()::Match `{$value}` with `{$name}` = {$ligne["ID"]}"); } return $ligne["ID"]; } } if (DistanceInMns($GLOBALS["CACHE_CLEAN_MYSQL"]) > 5) { $GLOBALS["CACHE_CLEAN_MYSQL"] = time(); if ($GLOBALS["DEBUG_LEVEL"] > 3) { WLOG("CheckPattern():: Clean old rules..."); } $sql = "DELETE FROM `webfilter_aclsdynamic` WHERE `duration`>0 AND `maxtime`>" . time(); api_QUERY_SQL($sql); } } catch (Exception $e) { WLOG($e->getMessage()); return 0; } return 0; }