You are here

function ip_login_check_path in IP Login 6.2

Same name and namespace in other branches
  1. 7.3 ip_login.module \ip_login_check_path()
  2. 7.2 ip_login.module \ip_login_check_path()

Checks path of current page matches any set as options on the admin page to see if IP login should occur. Adapted from core Block module's block_list().

Return value

$uid_matched The uid of the matching user account

2 calls to ip_login_check_path()
ip_login_boot in ./ip_login.module
Implementation of hook_boot().
ip_login_login in ./ip_login.module
Performs a login for user with $uid and stores IP Login variables for later

File

./ip_login.module, line 380
Allow user login by IP addresses, ranges or wildcards.

Code

function ip_login_check_path() {
  if (!isset($_GET['ip_login_override_pages'])) {
    $pages = variable_get('ip_login_active_pages', '');
    if ($pages) {
      $page_match = FALSE;

      // first char, if variable set, is 'check_mode' - remainder is paths to match or PHP
      $check_mode = substr($pages, 0, 1);
      $pages = substr($pages, 1);
      if ($check_mode < 2) {

        // Compare with the path with allowed pages.
        // Since this happens in hook_boot, we cannot call drupal_get_path_alias
        // so call our own path matcher code and avoid a DB/alias check
        $path = isset($_GET['q']) ? $_GET['q'] : '';
        $page_match = ip_login_match_path($path, $pages);

        // When $check_mode has a value of 0, the IP check happens on
        // all pages except those listed in $pages. When set to 1, IPs
        // are checked only on those pages listed in $pages.
        $page_match = !($check_mode xor $page_match);
      }
      else {

        // evaluate PHP
        $page_match = drupal_eval($pages);
      }

      // if we don't have a path/PHP match, don't log in
      if (!$page_match) {
        return FALSE;
      }
    }
  }

  // all is well, continue with login.
  return TRUE;
}