public static function MoAuthUtilities::check_white_IPs in Google Authenticator / 2 Factor Authentication - 2FA 8.2
Same name and namespace in other branches
- 8 src/MoAuthUtilities.php \Drupal\miniorange_2fa\MoAuthUtilities::check_white_IPs()
Return value
bool
1 call to MoAuthUtilities::check_white_IPs()
File
- src/
MoAuthUtilities.php, line 361 - This file is part of miniOrange 2FA module.
Class
Namespace
Drupal\miniorange_2faCode
public static function check_white_IPs() {
$enable_whitelisted_IP = \Drupal::config('miniorange_2fa.settings')
->get('mo_auth_enable_whitelist_IPs');
if ($enable_whitelisted_IP == FALSE) {
return FALSE;
}
$current_IP_address = self::get_client_ip();
$whitelisted_IP = \Drupal::config('miniorange_2fa.settings')
->get('mo_auth_whitelisted_IP_address');
if (is_null($whitelisted_IP) || empty($whitelisted_IP)) {
return FALSE;
}
$whitelisted_IP_array = explode(";", $whitelisted_IP);
$mo_ip_found = FALSE;
foreach ($whitelisted_IP_array as $key => $value) {
if (stristr($value, '-')) {
/** Search in range of IP address **/
list($lower, $upper) = explode('-', $value, 2);
$lower_range = ip2long($lower);
$upper_range = ip2long($upper);
$current_IP = ip2long($current_IP_address);
if ($lower_range !== FALSE && $upper_range !== FALSE && $current_IP !== FALSE && ($current_IP >= $lower_range && $current_IP <= $upper_range)) {
$mo_ip_found = TRUE;
break;
}
}
else {
/** Compare with single IP address **/
if ($current_IP_address == $value) {
$mo_ip_found = TRUE;
break;
}
}
}
return $mo_ip_found;
}