You are here

function _cas_allow_check_for_login in CAS 5.3

Same name and namespace in other branches
  1. 5.4 cas.module \_cas_allow_check_for_login()
  2. 6.3 cas.module \_cas_allow_check_for_login()
  3. 6.2 cas.module \_cas_allow_check_for_login()
  4. 7 cas.module \_cas_allow_check_for_login()
1 call to _cas_allow_check_for_login()
cas_login_check in ./cas.module
Checks to see if the user needs to be logged in

File

./cas.module, line 831

Code

function _cas_allow_check_for_login() {

  // Determine whether we should check for long
  $cas_check_first = variable_get('cas_check_first', 1);
  if (!$cas_check_first) {
    return FALSE;
  }

  // Check to see if we already have.
  if ($_COOKIE['cas_login_checked']) {
    return FALSE;
  }

  // Check to see if we've got a search bot.
  $crawlers = array(
    'Google',
    'msnbot',
    'Rambler',
    'Yahoo',
    'AbachoBOT',
    'accoona',
    'AcoiRobot',
    'ASPSeek',
    'CrocCrawler',
    'Dumbot',
    'FAST-WebCrawler',
    'GeonaBot',
    'Gigabot',
    'Lycos',
    'MSRBOT',
    'Scooter',
    'AltaVista',
    'IDBot',
    'eStyle',
    'Scrubby',
  );

  // Return on the first find.
  foreach ($crawlers as $c) {
    if (stripos($_SERVER['HTTP_USER_AGENT'], $c) !== FALSE) {
      return FALSE;
    }
  }

  // No need if we're on the cas login page.
  list($arg0) = split('/', $_GET['q']);

  // Don't even do the test if we're hitting the cas page
  if ($arg0 == "cas") {
    return FALSE;
  }

  // Don't even do the test if cron.php or xmlrpc.php is invoked.  Don't check for logins.
  if (base_path() . 'cron.php' == $_SERVER['PHP_SELF'] || base_path() . 'xmlrpc.php' == $_SERVER['PHP_SELF']) {
    return FALSE;
  }

  // Drush
  if (stristr($_SERVER['SCRIPT_FILENAME'], 'drush')) {
    return FALSE;
  }

  // Drush
  if (stristr($_SERVER['argv'][0], 'drush')) {
    return FALSE;
  }
  $pages = variable_get('cas_exclude', CAS_EXCLUDE);

  // Test against exclude pages.
  if ($pages) {
    $path = drupal_get_path_alias($_GET['q']);
    $regexp = '/^(' . preg_replace(array(
      '/(\\r\\n?|\\n)/',
      '/\\\\\\*/',
      '/(^|\\|)\\\\<front\\\\>($|\\|)/',
    ), array(
      '|',
      '.*',
      '\\1' . variable_get('site_frontpage', 'node') . '\\2',
    ), preg_quote($pages, '/')) . ')$/';
    $path_match = preg_match($regexp, $path);

    // Alter the default
    if ($path_match) {
      return FALSE;
    }
  }
  return $cas_check_first;
}