/** * @param string $IP Should be in dot or colon notation (127.0.0.1 or ::1) * @return bool */ public function isWhitelisted($IP) { foreach (wfUtils::getIPWhitelist() as $subnet) { if ($subnet instanceof wfUserIPRange) { if ($subnet->isIPInRange($IP)) { return true; } } elseif (wfUtils::subnetContainsIP($subnet, $IP)) { return true; } } return false; }
/** * Generate SQL from the whitelist. Uses the return format from wfUtils::getIPWhitelist * * @see wfUtils::getIPWhitelist * @param array $whitelisted_ips * @return string */ public function getBlockedIPWhitelistWhereClause($whitelisted_ips = null) { if ($whitelisted_ips === null) { $whitelisted_ips = wfUtils::getIPWhitelist(); } if (!is_array($whitelisted_ips)) { return false; } $where = ''; foreach ($whitelisted_ips as $ip_range) { if (!is_a($ip_range, 'wfUserIPRange')) { $ip_range = wfUtils::CIDR2wfUserIPRange($ip_range); } $where .= $ip_range->toSQL('IP') . ' OR '; } if ($where) { // remove the extra ' OR ' $where = substr($where, 0, -4); } return $where; }
/** * @param string $IP Should be in dot or colon notation (127.0.0.1 or ::1) * @param bool $forcedWhitelistEntry If provided, returns whether or not the IP is on a forced whitelist. * @return bool */ public function isWhitelisted($IP, &$forcedWhitelistEntry = null) { if ($forcedWhitelistEntry !== null) { $forcedWhitelistEntry = false; } foreach (wfUtils::getIPWhitelist() as $subnet) { if ($subnet instanceof wfUserIPRange) { if ($subnet->isIPInRange($IP)) { return true; } } elseif (wfUtils::subnetContainsIP($subnet, $IP)) { if ($forcedWhitelistEntry !== null) { $forcedWhitelistEntry = true; } return true; } } return false; }