Add inRanges() and validateRanges() methods to IpFilter class

This commit is contained in:
Kijin Sung 2016-03-13 10:18:52 +09:00
parent 2effbea06f
commit 0adb13ca30
7 changed files with 52 additions and 77 deletions

View file

@ -445,13 +445,9 @@ class Debug
return $cache = true;
case 'ip':
$allowed_ip = Config::get('debug.allow');
foreach ($allowed_ip as $range)
if (IpFilter::inRanges(RX_CLIENT_IP, Config::get('debug.allow')))
{
if (IpFilter::inRange(RX_CLIENT_IP, $range))
{
return $cache = true;
}
return $cache = true;
}
return $cache = false;

View file

@ -66,6 +66,25 @@ class IpFilter
}
}
/**
* Check whether the given IP address belongs to a set of ranges.
*
* @param string $ip
* @param array $ranges
* @return bool
*/
public static function inRanges($ip, array $ranges)
{
foreach ($ranges as $range)
{
if (self::inRange($ip, $range))
{
return true;
}
}
return false;
}
/**
* Check whether a range definition is valid.
*
@ -91,6 +110,24 @@ class IpFilter
return false;
}
/**
* Check whether a set of range definitions is valid.
*
* @param array $ranges
* @return bool
*/
public static function validateRanges(array $ranges)
{
foreach ($ranges as $range)
{
if (!self::validateRange($range))
{
return false;
}
}
return true;
}
/**
* Get real IP from CloudFlare headers.
*