Index: README =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/singlesignon/README,v retrieving revision 1.1.2.1 diff -u -p -r1.1.2.1 README --- README 2 May 2008 03:20:00 -0000 1.1.2.1 +++ README 8 May 2008 02:48:11 -0000 @@ -1,3 +1,5 @@ +/* $Id$ */ + Enables "Single Sign-Ons" between related Drupal sites on one server with a shared database. @@ -42,3 +44,5 @@ $db_prefix = array( link: http://drupal.org/project/singlesignon author: Daniel Convissor +Maintainer: Tim Nelson + Index: singlesignon.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/singlesignon/singlesignon.module,v retrieving revision 1.21.2.14 diff -u -p -r1.21.2.14 singlesignon.module --- singlesignon.module 8 May 2008 10:12:18 -0000 1.21.2.14 +++ singlesignon.module 8 May 2008 10:32:10 -0000 @@ -1,59 +1,17 @@ 'somesitename_', - * 'authmap' => 'shared_', - * 'profile_fields' => 'shared_', - * 'profile_values' => 'shared_', - * 'role' => 'shared_', - * 'sequences' => 'shared_', - * 'sessions' => 'shared_', - * 'users' => 'shared_', - * 'users_roles' => 'shared_', - * 'users_uid_seq' => 'shared_', // for pgsql - * ); - * @endverbatim - * - * @link http://drupal.org/project/singlesignon - * @author Primary Author: Daniel Convissor - * @author Maintainer: Tim Nelson - * @version $Revision: 1.21.2.14 $ */ -// {{{ core functions +/** + * @defgroup singlesignon_core Core functions. + * @{ + */ include_once('sessions_extra.inc'); @@ -83,13 +41,9 @@ function singlesignon_init() { } $_singlesignon_bot_matches = variable_get('singlesignon_bot_matches', $variable_defaults); - if ( - // If the Master URL isn't set, we can't know what to do, so do nothing - (!$master_url) - // Likewise, bots don't sign on - || _singlesignon_is_bot() - ) { - return null; + // If no master URL is set or we are serving a bot, do nothing. + if (!$master_url || _singlesignon_is_bot()) { + return; } $extra_base_url = _singlesignon_base_url(); @@ -101,7 +55,6 @@ function singlesignon_init() { drupal_set_message(t('Cookies are required.'), 'error'); return; } - // This is the user's first hit to a slave site. Take note of their // session ID, since that's how we tell if they've been here or not. // Then go to the master site to see if they are logged in over there. @@ -114,9 +67,7 @@ function singlesignon_init() { // arg() only available if bootstrap has reached PATH. drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); - $arg0 = arg(0); - - switch ($arg0) { + switch (arg(0)) { case 'logout': if ($user->uid) { _singlesignon_session_logout($user->uid); @@ -125,7 +76,7 @@ function singlesignon_init() { case 'singlesignon': if ($extra_base_url == $master_url) { - _singlesignon_master($master_url, $arg0, arg(1)); + _singlesignon_master($master_url, arg(0), arg(1)); } return; @@ -136,7 +87,7 @@ function singlesignon_init() { // checking yet because the login process happens after this module // called. Set a flag telling us to do the master/slave checking // once the login process is done. - $_SESSION['singlesignon_just_loggged_in'] = true; + $_SESSION['singlesignon_just_loggged_in'] = TRUE; return; } } @@ -167,7 +118,7 @@ function _singlesignon_master($master_ur global $user; if (empty($_GET['singlesignon_dest']) || is_array($_GET['singlesignon_dest']) || empty($_GET['slave_session']) || is_array($_GET['slave_session']) || !_singlesignon_validate_sid($_GET['slave_session'])) { - echo t('Thank you for hacking.'); + echo 'Invalid request.'; exit; } @@ -197,29 +148,31 @@ function _singlesignon_master($master_ur } } +/** + * @} End of "defgroup singlesignon_core". + */ -// }}} -// {{{ helper functions +/** + * @defgroup singlesignon_helpers Helper functions. + * @{ + */ /** * Sets up the URL and goes to it */ function _singlesignon_goto_url($master_url, $url) { - // url() only available if bootstrap has reached FULL. - drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); + // url() only available if bootstrap has reached FULL. + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); - $query = 'slave_session='. session_id() .'&singlesignon_dest='. _singlesignon_get_dest(); - _singlesignon_goto($master_url . url($url, $query)); + $query = 'slave_session='. session_id() .'&singlesignon_dest='. _singlesignon_get_dest(); + _singlesignon_goto($master_url . url($url, $query)); } /** * Gets the base url and fixess it up a bit */ function _singlesignon_base_url() { - global $base_url; - - $scheme_authority = preg_replace('@^(https?://[^/]+).*@', '\\1', $base_url); - return ($scheme_authority); + return preg_replace('@^(https?://[^/]+).*@', '\\1', $GLOBALS['base_url']); } @@ -227,9 +180,7 @@ function _singlesignon_base_url() { * Combines $base_url and request_uri() in a safe, portable way. */ function _singlesignon_get_dest() { - global $base_url; - - $scheme_authority = preg_replace('@^(https?://[^/]+).*@', '\\1', $base_url); + $scheme_authority = preg_replace('@^(https?://[^/]+).*@', '\\1', $GLOBALS['base_url']); return rawurlencode($scheme_authority . request_uri()); } @@ -252,20 +203,20 @@ function _singlesignon_goto($uri) { function _singlesignon_validate_sid($sid) { if (is_array($sid)) { if (count($sid) > 100) { - return false; + return FALSE; } foreach ($sid as $value) { if (!ereg('^[A-Za-z0-9]{1,100}$', $value)) { - return false; + return FALSE; } } } else { if (!ereg('^[A-Za-z0-9]{1,100}$', $sid)) { - return false; + return FALSE; } } - return true; + return TRUE; } /** @@ -290,25 +241,25 @@ function _singlesignon_get_default_domai return $domain['scheme'] .'://'. $domain['subdomain']; } -// }}} -// {{{ other hook functions +/** + * @} End of "defgroup singlesignon_helpers". + */ /** * Implementation of hook_menu(). */ -function singlesignon_menu($maycache) { - $items = array( - array( +function singlesignon_menu($may_cache) { + $items = array(); + if ($may_cache) { + $items[] = array( 'path' => 'admin/settings/singlesignon', 'title' => t('Shared Sign-on'), 'description' => t('Shares users and sign-ons between sites (previously called "Single Sign-on"'), 'callback' => 'drupal_get_form', 'callback arguments' => array('singlesignon_admin_settings'), 'access' => user_access('access administration pages'), - 'type' => MENU_NORMAL_ITEM, - ), - ); - + ); + } return $items; } @@ -316,10 +267,6 @@ function singlesignon_menu($maycache) { * Provides user interface necessary to administer this module's settings. */ function singlesignon_admin_settings() { - if (!user_access('access administration pages')) { - return drupal_access_denied(); - } - $form = array(); $use_domain = variable_get('singlesignon_use_domain_module', 0); if (module_exists('domain')) { @@ -347,15 +294,13 @@ function singlesignon_admin_settings() { '#collapsible' => TRUE, '#collapsed' => TRUE, '#tree' => TRUE, - '#description' => << t('Single sign-on does not play well with bots (ie. search engines). The data below will hopefully help the single sign-on module to -recognise bots and let them through (ie. it plays nicely with the recognised bots). -EOT +recognise bots and let them through (ie. it plays nicely with the recognised bots).'), ); $form['singlesignon_bot_matches']['useragents_case'] = array( '#type' => 'textarea', - '#title' => 'Case-sensitive User Agents', + '#title' => t('Case-sensitive User Agents'), '#rows' => 5, '#cols' => 40, '#default_value' => _singlesignon_get_bm_variable('useragents_case'), @@ -363,7 +308,7 @@ EOT ); $form['singlesignon_bot_matches']['useragents_nocase'] = array( '#type' => 'textarea', - '#title' => 'Case-insensitive User Agents', + '#title' => t('Case-insensitive User Agents'), '#rows' => 5, '#cols' => 40, '#default_value' => _singlesignon_get_bm_variable('useragents_nocase'), @@ -371,7 +316,7 @@ EOT ); $form['singlesignon_bot_matches']['client_IP'] = array( '#type' => 'textarea', - '#title' => 'Client IP', + '#title' => t('Client IP'), '#rows' => 5, '#cols' => 40, '#default_value' => _singlesignon_get_bm_variable('client_IP'), @@ -379,29 +324,28 @@ EOT ); $form['singlesignon_bot_matches']['target_url'] = array( '#type' => 'textarea', - '#title' => 'Target URL', + '#title' => t('Target URL'), '#rows' => 5, '#cols' => 40, '#default_value' => _singlesignon_get_bm_variable('target_url'), '#description' => t('A list of case-sensitive strings that might match a referrer. Not recommended (in general; we have a few specific cases here)'), ); - return system_settings_form($form); } /** * Internal function for use of singlesignon_admin_settings; turns | separated string into \n separated string. * - * @param $variable: The short name of the singlesignon bot matching variable - * @param $text: The default text for the variable + * @param $variable + * The short name of the singlesignon bot matching variable + * @param $text + * The default text for the variable */ function _singlesignon_get_bm_variable($variable) { - global $_singlesignon_bot_matches; - return (preg_replace( array("/^\/(.*?)\/i?$/", "/\|/"), array("$1", "\n"), - $_singlesignon_bot_matches[$variable] + $GLOBALS['_singlesignon_bot_matches'][$variable] )); } @@ -409,21 +353,25 @@ function _singlesignon_get_bm_variable($ * Hook for validating a form; verifies the values for singlesignon bot recognition. */ function singlesignon_admin_settings_validate($form_id, $form_values, $form) { + $s = array(); $s['useragents_case'] = _singlesignon_verify_value($form_values, 'useragents_case'); $s['useragents_nocase'] = _singlesignon_verify_value($form_values, 'useragents_nocase', '', 'i'); - $s['client_IP'] = _singlesignon_verify_value($form_values, 'client_IP', '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'); - $s['target_url'] = _singlesignon_verify_value($form_values, 'target_url', '\\\\\/[A-Za-z0-9_\.\*\/\\\\-]*\$$'); - + $s['client_IP'] = _singlesignon_verify_value($form_values, 'client_IP', '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'); + $s['target_url'] = _singlesignon_verify_value($form_values, 'target_url', '\\\\\/[A-Za-z0-9_\.\*\/\\\\-]*\$$'); form_set_value($form['singlesignon_bot_matches'], $s); } /** * Internal function: Verifies one singlesignon bot recognition value. * - * @param $form_values: The values we're validating - * @param $value: The name of the value we're validation - * @param $allowed: A regex specifying what values are allowed - * @param $extras: The regex parameters (ie. 'i' is case insensitive) + * @param $form_values + * The values we're validating. + * @param $value + * The name of the value we're validation. + * @param $allowed + * A regex specifying what values are allowed. + * @param $extras + * The regex parameters (ie. 'i' is case insensitive). */ function _singlesignon_verify_value($form_values, $value, $allowed = '', $extras = '') { if ($allowed == '') { @@ -437,7 +385,7 @@ function _singlesignon_verify_value($for $rvals[] = $val; } else { - form_set_error('', t("The strings in $value contain non-word characters (we allow $allowed at the moment, and '". $val ."' is a problem)")); + form_set_error('', t("The strings in @value contain non-word characters (we allow @allowed at the moment, and '@wrong-value' is a problem)", array('@value' => $value, '@allowed' => $allowed, '@wrong-value' => $val))); } } return ('/'. join('|', $rvals) ."/$extras"); @@ -445,5 +393,4 @@ function _singlesignon_verify_value($for return ($form_values['singlesignon_bot_matches'][$value]); } -// }}}