You are here

private function LoginFirewall::checkIpRestriction in Restrict Login or Role Access by IP Address 8.4

Given IP restrictions, validate the current users IP is among them.

Parameters

string $ip: A semi-colon delimited list of IP address ranges in CIDR notation.

Return value

bool Whether the current users IP is in any given IP address range.

2 calls to LoginFirewall::checkIpRestriction()
LoginFirewall::checkGlobalRestriction in src/LoginFirewall.php
Validates the global IP restrictions, if set.
LoginFirewall::checkUserRestriction in src/LoginFirewall.php
Validates the user IP restrictions, if set.

File

src/LoginFirewall.php, line 137

Class

LoginFirewall
Class LoginFirewall.

Namespace

Drupal\restrict_by_ip

Code

private function checkIpRestriction($ip) {
  $user_ip = $this->ipTools
    ->getUserIP();
  $valid = FALSE;
  $ranges = explode(';', $ip);
  foreach ($ranges as $range) {
    try {
      $this->ipTools
        ->validateCIDR($user_ip, $range);
    } catch (IPOutOfRangeException $e) {
      continue;
    }
    $valid = TRUE;
  }
  return $valid;
}