}
/**
- * Reads session data to determine if it contains Horde authentication
- * credentials.
- *
- * @param string $session_data The session data.
- * @param boolean $info Return session information. The following
- * information is returned: userid,
- * timestamp, remoteAddr, browser.
- *
- * @return array An array of the user's sesion information if
- * authenticated or false. The following information is
- * returned: userid, timestamp, remoteAddr, browser, apps.
- */
- static public function readSessionData($session_data)
- {
- if (empty($session_data) ||
- (($pos = strpos($session_data, 'horde_auth|')) === false)) {
- return false;
- }
-
- $pos += 11;
- $endpos = $pos + 1;
-
- while ($endpos !== false) {
- $endpos = strpos($session_data, '|', $endpos);
- $data = @unserialize(substr($session_data, $pos, $endpos));
- if (is_array($data)) {
- return empty($data)
- ? false
- : array(
- 'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']),
- 'browser' => $data['browser'],
- 'remoteAddr' => $data['remoteAddr'],
- 'timestamp' => $data['timestamp'],
- 'userid' => $data['userId']
- );
- }
- ++$endpos;
- }
-
- return false;
- }
-
- /**
* Sets the error message for an invalid authentication.
*
* @param string $type The type of error (self::REASON_* constant).
}
$params['logger'] = $logger;
+ $params['parse'] = array($this, 'readSessionData');
return Horde_SessionHandler::factory($driver, $params);
}
{
return false;
}
+
+ /**
+ * Reads session data to determine if it contains Horde authentication
+ * credentials.
+ *
+ * @param string $session_data The session data.
+ *
+ * @return array An array of the user's sesion information if
+ * authenticated or false. The following information is
+ * returned: userid, timestamp, remoteAddr, browser, apps.
+ */
+ public function readSessionData($session_data)
+ {
+ if (empty($session_data) ||
+ (($pos = strpos($session_data, 'horde_auth|')) === false)) {
+ return false;
+ }
+
+ $pos += 11;
+ $endpos = $pos + 1;
+
+ while ($endpos !== false) {
+ $endpos = strpos($session_data, '|', $endpos);
+ $data = @unserialize(substr($session_data, $pos, $endpos));
+ if (is_array($data)) {
+ return empty($data)
+ ? false
+ : array(
+ 'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']),
+ 'browser' => $data['browser'],
+ 'remoteAddr' => $data['remoteAddr'],
+ 'timestamp' => $data['timestamp'],
+ 'userid' => $data['userId']
+ );
+ }
+ ++$endpos;
+ }
+
+ return false;
+ }
+
}
* DEFAULT: No logging
* 'noset' - (boolean) If true, don't set the save handler.
* DEFAULT: false
+ * 'parse' - (callback) A callback function that parses session
+ * information into an array. Is passed the raw session data
+ * as the only argument; expects either false or an array of
+ * session data as a return.
+ * DEFAULT: No
* </pre>
*/
public function __construct(array $params = array())
* Returns a list of authenticated users and data about their session.
*
* @return array For authenticated users, the sessionid as a key and the
- * information returned from Horde_Auth::readSessionData()
- * as values.
+ * session information as value. If no parsing function
+ * was provided, will always return an empty array.
* @throws Horde_SessionHandler_Exception
*/
public function getSessionsInfo()
{
- $sessions = $this->getSessionIDs();
-
$info = array();
+ if (empty($this->_params['parse']) ||
+ !is_callable($this->_params['parse'])) {
+ return $info;
+ }
+
+ $sessions = $this->getSessionIDs();
+
foreach ($sessions as $id) {
try {
$data = $this->_readOnly($id);
} catch (Horde_SessionHandler_Exception $e) {
continue;
}
- $data = Horde_Auth::readSessionData($data, true);
+
+ $data = call_user_func($this->_params['parse'], $data);
if ($data !== false) {
$info[$id] = $data;
}
</required>
<optional>
<package>
- <name>Auth</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>Db</name>
<channel>pear.horde.org</channel>
</package>