Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fierce_sso/README.txt,v
retrieving revision 1.1
diff -u -p -r1.1 README.txt
--- README.txt	22 May 2007 20:07:42 -0000	1.1
+++ README.txt	18 Apr 2008 19:44:21 -0000
@@ -1,3 +1,5 @@
+/* $Id$ */
+
 Fierce_SSO allows you to log on to multiple Drupal sites at one time, 
 even across different domains and no matter which site they're on when
 they enter their password.
@@ -27,8 +29,6 @@ Step 1:
 	you DO NOT share the sessions table. By design, each visitor will 
 	have a different session for each of your sites.
 	
-	Author: Eli Dickinson, FierceMarkets -- eli (at) fiercemarkets.com
-
 Step 2:
 	If you database is set up, unzip and install this module as normal
 	on each of your sites. Then go to:
@@ -42,4 +42,8 @@ Step 3:
 	like "Welcome to Foo.com" on the admin screen. Otherwise, depending
 	on your theme, users may see a weird empty box when they log in
 	(this box is used to serve the hidden images that make this whole
-	 system work).
\ No newline at end of file
+	 system work).
+
+
+Author: Eli Dickinson, FierceMarkets -- eli (at) fiercemarkets.com
+
Index: fierce_sso.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fierce_sso/fierce_sso.info,v
retrieving revision 1.2
diff -u -p -r1.2 fierce_sso.info
--- fierce_sso.info	18 Jun 2007 22:53:42 -0000	1.2
+++ fierce_sso.info	18 Apr 2008 19:41:57 -0000
@@ -1,4 +1,4 @@
-; $Id $
-name = "Fierce SSO"
-description = "Manages log-in to multiple domains."
-package = "Administration"
+; $Id$
+name = Fierce SSO
+description = Manages log-in to multiple domains.
+package = Authentication
Index: fierce_sso.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fierce_sso/fierce_sso.module,v
retrieving revision 1.1
diff -u -p -r1.1 fierce_sso.module
--- fierce_sso.module	22 May 2007 20:07:43 -0000	1.1
+++ fierce_sso.module	18 Apr 2008 20:22:48 -0000
@@ -1,9 +1,10 @@
 <?php
 // $Id: fierce_sso.module,v 1.1 2007/05/22 20:07:43 eli Exp $
 
+
 /**
  * @file
- * Lets users log in to multiple sites at once
+ * Lets users log in to multiple sites at once.
  */
 
 /**
@@ -11,207 +12,227 @@
  */
 function fierce_sso_help($section) {
   switch ($section) {
-    case 'user/help#fierce_sso':
-      return variable_get('fierce_sso_aff_desc', _fierce_sso_help());
-    case 'admin/modules#description':
-      return t('Lets users in another database log in.');
-    case 'admin/settings/drupal':
-      return NULL;
+    case 'admin/build/modules#description':
+      return t('Lets users log in to multiple sites at once.');
   }
 }
 
 /**
- * Helper for hook_help().
- */
-function _fierce_sso_help() {
-  return t('This function lets you log in multiple sites at once.');
-}
-
-/**
  * Implementation of hook_menu().
  */
 function fierce_sso_menu($may_cache) {
   $items = array();
   if (!$may_cache) {
-		$items[] = array('path' => 'fierce_sso/loginimg', 'title' => t('Login Image callback'),
-      'callback' => 'fierce_sso_loginimg', 'access' => TRUE, 'type' => MENU_CALLBACK);      
-		$items[] = array('path' => 'fierce_sso/logoutimg', 'title' => t('Logout Image callback'),
-      'callback' => 'fierce_sso_logoutimg', 'access' => TRUE, 'type' => MENU_CALLBACK);          
-		$items[] = array(
-		'path' => 'admin/settings/fierce_sso',
-		'title' => t('Single Sign-On'),
-		'description' => t('Change how Fierce_SSO behaves.'),
-		'callback' => 'drupal_get_form',
-		'callback arguments' => array('fierce_sso_admin_settings'),
-		'access' => user_access('administer site configuration')
-		);      
+    $items[] = array(
+      'path' => 'fierce_sso/loginimg',
+      'callback' => 'fierce_sso_loginimg',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'fierce_sso/logoutimg',
+      'callback' => 'fierce_sso_logoutimg',
+      'access' => TRUE,
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'admin/settings/fierce_sso',
+      'title' => t('Fierce Single Sign-On'),
+      'description' => t('Change how Fierce_SSO behaves.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('fierce_sso_admin_settings'),
+      'access' => user_access('administer site configuration'),
+    );
   }
   return $items;
 }
 
-
 /**
- * Hook_user('login')
+ * Implementation of hook_user().
  */
 function fierce_sso_user($op, &$edit, &$account, $category = NULL) {
   global $user;
-  if ($op == 'login') { 
-  	// include the magic login IMG calls in the next form dispalyed
-  	drupal_set_message(variable_get('fierce_sso_welcome_msg','') . _fierce_sso_get_login_html());
-	} else if ($op == 'logout' && variable_get('fierce_sso_logout',0)) {
-		$user = drupal_anonymous_user();		
-		drupal_goto('','sso=logout');  // this ends request! (FIXME)
-	}
+  if ($op == 'login') {
+    // Include the magic login IMG calls in the next page displayed.
+    drupal_set_message(variable_get('fierce_sso_welcome_msg', '') . _fierce_sso_get_login_html());
+  }
+  else if ($op == 'logout' && variable_get('fierce_sso_logout', 0)) {
+    $user = drupal_anonymous_user();
+    // This ends request! (FIXME)
+    drupal_goto('', 'sso=logout');
+  }
 }
 
+/**
+ * Form builder function for Fierce SSO settings.
+ */
+function fierce_sso_admin_settings() {
+  $form = array();
+  $form['fierce_sso_domains'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Domains to use for Fierce Single-Sign-On'),
+    '#description' => t('Enter one domain per line.'),
+    '#default_value' => variable_get('fierce_sso_domains', $_SERVER['SERVER_NAME']),
+  );
+  $form['fierce_sso_logout'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Log out from all sites at once too (aka Single Sign-Off) [experimental]'),
+    '#default_value' => variable_get('fierce_sso_logout', FALSE),
+  );
+  $form['fierce_sso_welcome_msg'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Welcome message to display after user logs in'),
+    '#default_value' => variable_get('fierce_sso_welcome_msg', ''),
+  );
+
+  $form['fierce_sso_debug'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable debug output'),
+    '#default_value' => variable_get('fierce_sso_debug', FALSE),
+  );
+  return system_settings_form($form);
+}
 
+/**
+ * Log out a user and return an image.
+ *
+ * @see user_logout(), user.module
+ */
+function fierce_sso_logoutimg() {
+  global $user;
+  if (variable_get('fierce_sso_logout', 0) && $user->uid != 0) {
+    watchdog('user', t('Session closed via SSO image for %name.', array('%name' => $user->name)));
 
+    // Destroy the current session.
+    session_destroy();
+    module_invoke_all('user', 'logout', NULL, $user);
 
-
-function fierce_sso_admin_settings() {
-	$form['fierce_sso_domains'] = array(
-		'#type' => 'textarea',
-		'#title' => t('Domains to use for Single-Sign-On'),
-		'#description' => t('Enter one domain per line.'),
-		'#default_value' => variable_get('fierce_sso_domains', $_SERVER['SERVER_NAME']),
-		//'#size' => 3
-		);
-	$form['fierce_sso_logout'] = array(
-		'#type' => 'checkbox',
-		'#title' => t('Log out from all sites at once too (aka Single Sign-Off) [experimental]'),		
-		'#default_value' => variable_get('fierce_sso_logout', FALSE),
-		//'#size' => 3
-		);
-	$form['fierce_sso_welcome_msg'] = array(
-		'#type' => 'textfield',
-		'#title' => t('Welcome message to display after user logs in'),		
-		'#default_value' => variable_get('fierce_sso_welcome_msg', ''),
-		//'#size' => 3
-		);
-
-	$form['fierce_sso_debug'] = array(
-		'#type' => 'checkbox',
-		'#title' => t('Enable debug output'),
-		//'#description' => t('Enter one domain per line.'),
-		'#default_value' => variable_get('fierce_sso_debug', FALSE),
-		//'#size' => 3
-		);
-	return system_settings_form($form);
+    // Load the anonymous user.
+    $user = drupal_anonymous_user();
+  }
+  _fierce_sso_send_gif();
 }
 
-
-function fierce_sso_logoutimg() {
+/**
+ * Log in a user and return an image.
+ */
+function fierce_sso_loginimg($uid, $token) {
   global $user;
-  if (variable_get('fierce_sso_logout',0) && $user->uid != 0) {
-	  watchdog('user', t('Session closed via SSO image for %name.', array('%name' => $user->name)));
-	
-	  // Destroy the current session:
-	  session_destroy();
-	  module_invoke_all('user', 'logout', NULL, $user);
-	
-	  // Load the anonymous user
-	  $user = drupal_anonymous_user(); 
-  }
-  _fierce_sso_send_gif();	
-}
-
-function fierce_sso_loginimg($uid,$token) {
-	global $user;	
-	
-	//load specified user
-	$new_user = user_load(array('uid' => $uid, 'status' => 1)); 
-	if ($new_user){
-		$token_data = $new_user->sso_tokens;
-		// security check			
-		if ($token_data[$_SERVER['SERVER_NAME']] == $token)	{ 
-
-			//delete token so it can't be used again
-			unset($token_data[$_SERVER['SERVER_NAME']]);
-			
-			//if that was the last token, delete the whole array
-			if (sizeof($token_data)==0) $token_data = NULL; 
-			
-			//save updated token data to DB
-			user_save($new_user, array('sso_tokens' => $token_data)); 
-			
-			// become new user
-			if (!($user->uid) || ($user->uid != $uid)) {
-				$user = $new_user;
-			}
-		} else {
-			// bad token
-			header("HTTP/1.1 403 Forbidden");
-			watchdog('user', t('Failed SSO login attempt (Bad token for user "@user").', array('@user' => $user->name)), WATCHDOG_WARNING);
-		}
-	} else {
-		//couldn't load user
-		header("HTTP/1.1 403 Forbidden");
-		watchdog('user', t('Failed SSO login attempt (@uid is not a valid User ID).', array('@uid' => $uid)), WATCHDOG_WARNING);		
-	}
 
-	_fierce_sso_send_gif();
+  // Load specified user.
+  $new_user = user_load(array('uid' => $uid, 'status' => 1));
+
+  if ($new_user) {
+    $token_data = $new_user->sso_tokens;
+
+    // Security check.
+    if ($token_data[$_SERVER['SERVER_NAME']] == $token) {
+      // Delete token so it can't be used again.
+      unset($token_data[$_SERVER['SERVER_NAME']]);
+
+      // If the given token was the last one, delete the whole array.
+      if (sizeof($token_data) == 0) {
+        $token_data = NULL;
+      }
+
+      // Store updated tokens in the database.
+      user_save($new_user, array('sso_tokens' => $token_data));
+
+      // Switch user to new user.
+      if (!($user->uid) || ($user->uid != $uid)) {
+        $user = $new_user;
+      }
+    }
+    else {
+      // Bad token.
+      header("HTTP/1.1 403 Forbidden");
+      watchdog('user', t('Failed SSO login attempt (Bad token for user %user).', array('%user' => $user->name)), WATCHDOG_WARNING);
+    }
+  }
+  else {
+    // User could not be loaded.
+    header("HTTP/1.1 403 Forbidden");
+    watchdog('user', t('Failed SSO login attempt (@uid is not a valid User ID).', array('@uid' => $uid)), WATCHDOG_WARNING);
+  }
+  _fierce_sso_send_gif();
 }
 
+/**
+ * Implementation of hook_footer().
+ *
+ * Renders log out images for configured domains in the footer.
+ */
 function fierce_sso_footer($main = 0) {
-	global $user;
-	if(variable_get('fierce_sso_logout',0) && $_GET['sso']=='logout' && $user->uid == 0) {
-		$sites_str = variable_get('fierce_sso_domains','');
-		$sites = preg_split('/\r\n?|\n/', $sites_str);	
-		if (sizeof($sites) == 0) return '';
-		$result = '';
-		foreach($sites as $site) {
-			$site = trim($site);
-			if (($site != "") && ($site != $_SERVER['SERVER_NAME'])) { //No need to add a token for the site we're on!				
-				$token = mt_rand(); //to prevent caching on the browser side
-				$result .= "<img src=\"http://$site/fierce_sso/logoutimg/$token\" width=\"1\" height=\"1\"/>";
-			}		
-		}
-		return $result;		
-	}
+  global $user;
+  if (variable_get('fierce_sso_logout', 0) && $_GET['sso'] == 'logout' && $user->uid == 0) {
+    $sites_str = variable_get('fierce_sso_domains', '');
+    $sites = preg_split('/\r\n?|\n/', $sites_str);
+    $result = '';
+    if (empty($sites)) {
+      return $result;
+    }
+    foreach ($sites as $site) {
+      $site = trim($site);
+      // No need to add a token for the site we're on!
+      if (($site != '') && ($site != $_SERVER['SERVER_NAME'])) {
+        // To prevent caching on the browser side.
+        $token = mt_rand();
+        $result .= "<img src=\"http://$site/fierce_sso/logoutimg/$token\" width=\"1\" height=\"1\"/>";
+      }
+    }
+    return $result;
+  }
 }
 
+/**
+ * Generate and send a 1px GIF to the browser.
+ */
 function _fierce_sso_send_gif() {
-	$img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7'); // 1 pixel gif
-	header('Content-Type: image/gif');
-	header('Content-Length: '.strlen($img));
-	header('Cache-Control: no-cache');
-	header('Connection: Close');
-	print $img;
-	flush(); // tell the browser to hang up  
-	
+  // Generate a 1 pixel GIF.
+  $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
+  header('Content-Type: image/gif');
+  header('Content-Length: '. strlen($img));
+  header('Cache-Control: no-cache');
+  header('Connection: Close');
+  print $img;
+  // Tell the browser to hang up.
+  flush();
 }
 
-
 function _fierce_sso_get_login_html() {
-	global $user;
-	$sso_debug = variable_get('fierce_sso_debug',FALSE);
-	$sites_str = variable_get('fierce_sso_domains','');
-	$sites = preg_split('/\r\n?|\n/', $sites_str);	
+  global $user;
+  $sso_debug = variable_get('fierce_sso_debug', FALSE);
+  $sites_str = variable_get('fierce_sso_domains', '');
+  $sites     = preg_split('/\r\n?|\n/', $sites_str);
+  $result    = '';
 
-	if (sizeof($sites) == 0) return '';
+  if (empty($sites)) {
+    return $result;
+  }
 
   if ($user->uid) {
-		$token_data = array();
-		$result = '<span class="fierce_sso">';
-
-		if ($sso_debug) $result .= "FierceSSO Debug Data: [";
-
-		foreach($sites as $site) {
-			$site = trim($site);
-			if (($site != "") && ($site != $_SERVER['SERVER_NAME'])) { //No need to add a token for the site we're on!
-				$token = md5("fierce_sso".mt_rand());
-				$token_data[$site] = $token;
-				if ($sso_debug) $result .= " http://$site/fierce_sso/loginimg/$user->uid/$token ";
-				$result .= "<img src=\"http://$site/fierce_sso/loginimg/$user->uid/$token\" width=\"1\" height=\"1\"/>";
-			}		
-		}
-
-		if ($sso_debug) $result .= "]";
-
-		$result .= "</span>";
-
-		user_save($user, array('sso_tokens' => $token_data)); //save tokens to DB
-  	return $result;
+    $token_data = array();
+    foreach ($sites as $site) {
+      $site = trim($site);
+      // No need to add a token for the site we're on!
+      if ($site && $site != $_SERVER['SERVER_NAME']) {
+        $token = md5("fierce_sso". mt_rand());
+        $token_data[$site] = $token;
+        if ($sso_debug) {
+          $result .= ' http://$site/fierce_sso/loginimg/$user->uid/$token ';
+        }
+        $result .= "<img src=\"http://$site/fierce_sso/loginimg/$user->uid/$token\" width=\"1\" height=\"1\"/>";
+      }
+    }
+
+    if ($sso_debug) {
+      $result = 'FierceSSO Debug Data: ['. $result .']';
+    }
+    $result = '<span class="fierce_sso">'. $result .'</span>';
+
+    // Store tokens in the database.
+    user_save($user, array('sso_tokens' => $token_data));
+    return $result;
   }
-  
-} 
+}
+
