You are here

function _restrict_by_ip_cidrcheck in Restrict Login or Role Access by IP Address 6.2

Same name and namespace in other branches
  1. 6.3 restrict_by_ip.module \_restrict_by_ip_cidrcheck()
  2. 7.3 restrict_by_ip.module \_restrict_by_ip_cidrcheck()

Check ip address against a network in cidr notation. E.g: _restrict_by_ip_cidrcheck('192.168.10.100','192.168.10.0/24'); returns 1 _restrict_by_ip_cidrcheck('192.168.10.100','192.168.12.0/24'); returns 0

2 calls to _restrict_by_ip_cidrcheck()
restrict_by_ip_role_check in ./restrict_by_ip.module
This just checks the database for any roles associated with that user that are in the restrict_by_ip table. From there it does a ip check on each one of them to see if they are within the range of ip's allowed for that role.
_restrict_by_ip_login in ./restrict_by_ip.module
Login function Checks the user's ip address on login If they are not restricted, or logging in from the appropriate address allow logon to continue. If not redirect to a designated page

File

./restrict_by_ip.module, line 414
Allows the admin to select which ip addresses role or a user can login from for this site Some of the code below is taken from the cck_ipaddress_module

Code

function _restrict_by_ip_cidrcheck($iptocheck, $ipslashcidr) {

  // Seperate ip address and cidr mask
  $netmask = explode("/", $ipslashcidr);

  // Get valid network as long
  $ip_net = ip2long($netmask[0]);

  // Get valid network mask as long
  $ip_mask = ~((1 << 32 - $netmask[1]) - 1);

  // Get ip address to check as long
  $ip_ip = ip2long($iptocheck);

  // Mask ip address to check to get subnet
  $ip_ip_net = $ip_ip & $ip_mask;

  // Only returns 1 if the valid network

  //and the subnet of the ip address

  //to check are the same
  return $ip_ip_net == $ip_net;
}