mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-01 00:02:21 +09:00
Add inRanges() and validateRanges() methods to IpFilter class
This commit is contained in:
parent
2effbea06f
commit
0adb13ca30
7 changed files with 52 additions and 77 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue