You are here

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

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

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.

1 call to restrict_by_ip_role_check()
sess_read in ./session_restrict_by_ip.inc

File

./restrict_by_ip.module, line 13
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_role_check(&$user) {

  //now do the resrict by ip check, remove roles from above array that should not be there

  //get all possible roles for the given user (other than annonmyous role and )
  $result = db_query('select rip.rid, rip.restrict_by_ip_address from {restrict_by_ip} rip left join {users_roles} ur ON ur.rid = rip.rid where ur.uid = %d', intval($user->uid));
  $ip2check = $_SERVER['REMOTE_ADDR'];
  while ($role = db_fetch_object($result)) {
    $ipaddresses = explode(";", $role->restrict_by_ip_address);
    foreach ($ipaddresses as $ipaddress) {
      if (!_restrict_by_ip_cidrcheck($ip2check, $ipaddress)) {

        //unset a role if its not within the allowed ip range for this role
        unset($user->roles[$role->rid]);
      }
    }
  }
}