public function searchcache($needle, &$haystack) { // array in haystack is ip=>reason // searches an array for an ip or an email - uses wildcards, short instances and cidrs // the wlist array is of the form $time->ip $searchname = $this->searchname; if (!is_array($haystack)) { return false; } $needle = strtolower($needle); foreach ($haystack as $search => $reason) { $search = trim(strtolower($search)); if (empty($search)) { continue; } // in case there is a null in the list if ($needle == $search) { return "{$searchname}:{$needle}"; } // four kinds of search, looking for an ip, cidr, wildcard or an email // check for wildcard - both email and ip if (strpos($search, '*') !== false || strpos($search, '?') !== false) { if (be_module::wildcard_match($search, $needle)) { return "{$searchname}:{$reason}:{$needle}"; } //$search=substr($search,0,strpos($search,'*')); //if ($search=substr($needle,0,strlen($search))) return "$searchname:$reason"; } // check for partial both email and ip if (strlen($needle) > strlen($search)) { $n = substr($needle, 0, strlen($search)); if ($n == $search) { return "{$searchname}:{$reason}"; } } if (substr_count($needle, '.') == 3 && strpos($search, '/') !== false) { // searching for an cidr in the list list($ip, $bits) = explode('/', $search); $n = ip2long($needle); if ($n === false) { continue; } $s = ip2long($ip); if ($s === false) { continue; } $num = pow(2, 32 - $bits) - 1; $s = $s | $num; $n = $n | $num; if ($s == $n) { return "{$searchname}:{$reason}"; } } } return false; }