Ozzy47
Well-known member
So I have a option in my addon to whitelist IP addresses. It works great, but I want to add the ability to add wildcard and CIDR ranges.
This is what I have now in my PHP file:
Now what I would like to be able to do is add a wildcard or a CIDR range like so in my option, Wildcard format 99.89.123.* and CIDR format 99.89.123/24
How would I go about that in my PHP file?
This is what I have now in my PHP file:
PHP:
public function actionForm()
{
//Set parent
$parent = parent::actionForm();
// Get Options
$options = \XF::options();
// Option enabled
$enable = $options->ozzmodzAdvancedACPipFirewall['enableFirewall'];
// Allowed IP option
$allowed = $options->ozzmodzAdvancedACPipFirewallip['AllowedIP'];
// Let's get the users IP
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
if($enable)
{
if(!$ip)
{
return $this->noPermission();
}
$allowedIPs = preg_split('#\s+|,|;|(\r\n|\n|\r)#s', $allowed, -1, PREG_SPLIT_NO_EMPTY);
if (!in_array($ip, $allowedIPs))
{
return $this->noPermission();
}
}
return $parent;
}
Now what I would like to be able to do is add a wildcard or a CIDR range like so in my option, Wildcard format 99.89.123.* and CIDR format 99.89.123/24
How would I go about that in my PHP file?