* @param array $params A hash containing any additional configuration or
* connection parameters a subclass might need.
*
- * @return Horde_Lock_Driver The newly created concrete instance.
+ * @return Horde_Lock_Base The newly created concrete instance.
* @throws Horde_Lock_Exception
*/
static public function factory($driver, $params = array())
<?php
/**
- * The Horde_Lock_Driver class defines the Horde_Lock driver API.
+ * The Horde_Lock_Base class defines the Horde_Lock driver API.
*
* Copyright 2008-2010 The Horde Project (http://www.horde.org/)
*
* @category Horde
* @package Lock
*/
-abstract class Horde_Lock_Driver
+abstract class Horde_Lock_Base
{
/**
* Driver parameters.
* @category Horde
* @package Lock
*/
-class Horde_Lock_Null extends Horde_Lock_Driver
+class Horde_Lock_Null extends Horde_Lock_Base
{
/**
* Return an array of information about the requested lock.
* @category Horde
* @package Lock
*/
-class Horde_Lock_Sql extends Horde_Lock_Driver
+class Horde_Lock_Sql extends Horde_Lock_Base
{
/**
* Handle for the current database connection.
/**
* Return an array of information about the requested lock.
*
- * @see Horde_Lock_Driver::getLockInfo()
+ * @see Horde_Lock_Base::getLockInfo()
*/
public function getLockInfo($lockid)
{
* Return a list of valid locks with the option to limit the results
* by principal, scope and/or type.
*
- * @see Horde_Lock_Driver::getLocks()
+ * @see Horde_Lock_Base::getLocks()
*/
public function getLocks($scope = null, $principal = null, $type = null)
{
/**
* Extend the valid lifetime of a valid lock to now + $newtimeout.
*
- * @see Horde_Lock_Driver::resetLock()
+ * @see Horde_Lock_Base::resetLock()
*/
public function resetLock($lockid, $extend)
{
* Sets a lock on the requested principal and returns the generated lock
* ID.
*
- * @see Horde_Lock_Driver::setLock()
+ * @see Horde_Lock_Base::setLock()
*/
public function setLock($requestor, $scope, $principal,
$lifetime = 1, $type = Horde_Lock::TYPE_SHARED)
/**
* Removes a lock given the lock ID.
*
- * @see Horde_Lock_Driver::clearLock()
+ * @see Horde_Lock_Base::clearLock()
*/
public function clearLock($lockid)
{
<?php
/**
- * Horde_SessionHandler:: defines an API for implementing custom PHP session
+ * Horde_SessionHandler defines an API for implementing custom PHP session
* handlers.
*
* Copyright 2002-2010 The Horde Project (http://www.horde.org/)
--- /dev/null
+<?php
+/**
+ * Horde_SessionHandler_Base is the abstract class that all drivers inherit
+ * from.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package SessionHandler
+ */
+abstract class Horde_SessionHandler_Base
+{
+ /**
+ * Hash containing connection parameters.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * Initial session data signature.
+ *
+ * @var string
+ */
+ protected $_sig;
+
+ /**
+ * Force saving the session data?
+ *
+ * @var boolean
+ */
+ protected $_force = false;
+
+ /**
+ * Has a connection been made to the backend?
+ *
+ * @var boolean
+ */
+ protected $_connected = false;
+
+ /**
+ * A logger instance.
+ *
+ * @var Horde_Log_Logger
+ */
+ protected $_logger;
+
+ /**
+ * Session variable name.
+ *
+ * @var string
+ */
+ protected $_session = 'horde_sh';
+
+ /**
+ * Constructor.
+ *
+ * @param array $params Parameters:
+ * <pre>
+ * 'logger' - (Horde_Log_Logger) A logger instance.
+ * 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())
+ {
+ $params = array_merge($this->_params, $params);
+
+ if (isset($params['logger'])) {
+ $this->_logger = $params['logger'];
+ unset($params['logger']);
+ }
+
+ $this->_params = $params;
+
+ register_shutdown_function(array($this, 'shutdown'));
+
+ if (empty($this->_params['noset'])) {
+ ini_set('session.save_handler', 'user');
+ session_set_save_handler(
+ array($this, 'open'),
+ array($this, 'close'),
+ array($this, 'read'),
+ array($this, 'write'),
+ array($this, 'destroy'),
+ array($this, 'gc')
+ );
+ }
+ }
+
+ /**
+ * Destructor.
+ */
+ public function __destruct()
+ {
+ /* This is necessary as of PHP 5.0.5 because objects are not available
+ * when the write() handler is called at the end of a session
+ * access. */
+ session_write_close();
+ }
+
+ /**
+ * Shutdown function.
+ *
+ * Used to determine if we need to write the session to avoid a session
+ * timeout, even though the session is unchanged.
+ * Theory: On initial login, set the current time plus half of the max
+ * lifetime in the session. Then check this timestamp before saving.
+ * If we exceed, force a write of the session and set a new timestamp.
+ * Why half the maxlifetime? It guarantees that if we are accessing the
+ * server via a periodic mechanism (think folder refreshing in IMP) that
+ * we will catch this refresh.
+ */
+ public function shutdown()
+ {
+ $curr_time = time();
+
+ if (!isset($_SESSION[$this->_session]) ||
+ ($curr_time >= $_SESSION[$this->_session])) {
+ $_SESSION[$this->_session] = $curr_time + (ini_get('session.gc_maxlifetime') / 2);
+ $this->_force = true;
+ }
+ }
+
+ /**
+ * Open the backend.
+ *
+ * @param string $save_path The path to the session object.
+ * @param string $session_name The name of the session.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ public function open($save_path = null, $session_name = null)
+ {
+ if (!$this->_connected) {
+ try {
+ $this->_open($save_path, $session_name);
+ } catch (Horde_SessionHandler_Exception $e) {
+ if ($this->_logger) {
+ $this->_logger->log($e, 'ERR');
+ }
+ return false;
+ }
+
+ $this->_connected = true;
+ }
+
+ return true;
+ }
+
+ /**
+ * Open the backend.
+ *
+ * @param string $save_path The path to the session object.
+ * @param string $session_name The name of the session.
+ *
+ * @throws Horde_SessionHandler_Exception
+ */
+ abstract protected function _open($save_path = null, $session_name = null);
+
+ /**
+ * Close the backend.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ public function close()
+ {
+ try {
+ $this->_close();
+ } catch (Horde_SessionHandler_Exception $e) {
+ if ($this->_logger) {
+ $this->_logger->log($e, 'ERR');
+ }
+ return false;
+ }
+
+ $this->_connected = false;
+ return true;
+ }
+
+ /**
+ * Close the backend.
+ *
+ * @throws Horde_SessionHandler_Exception
+ */
+ abstract protected function _close();
+
+ /**
+ * Read the data for a particular session identifier from the backend.
+ * This method should only be called internally by PHP via
+ * session_set_save_handler().
+ *
+ * @param string $id The session identifier.
+ *
+ * @return string The session data.
+ */
+ public function read($id)
+ {
+ $result = $this->_read($id);
+ $this->_sig = md5($result);
+ return $result;
+ }
+
+ /**
+ * Read the data for a particular session identifier from the backend.
+ *
+ * @param string $id The session identifier.
+ *
+ * @return string The session data.
+ */
+ abstract protected function _read($id);
+
+ /**
+ * Write session data to the backend.
+ * This method should only be called internally by PHP via
+ * session_set_save_handler().
+ *
+ * @param string $id The session identifier.
+ * @param string $session_data The session data.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ public function write($id, $session_data)
+ {
+ if (!$this->_force && ($this->_sig == md5($session_data))) {
+ if ($this->_logger) {
+ $this->_logger->log('Session data unchanged (id = ' . $id . ')', 'DEBUG');
+ }
+ return true;
+ }
+
+ return $this->_write($id, $session_data);
+ }
+
+ /**
+ * Write session data to the backend.
+ *
+ * @param string $id The session identifier.
+ * @param string $session_data The session data.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ abstract protected function _write($id, $session_data);
+
+ /**
+ * Destroy the data for a particular session identifier in the backend.
+ * This method should only be called internally by PHP via
+ * session_set_save_handler().
+ *
+ * @param string $id The session identifier.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ abstract public function destroy($id);
+
+ /**
+ * Garbage collect stale sessions from the backend.
+ * This method should only be called internally by PHP via
+ * session_set_save_handler().
+ *
+ * @param integer $maxlifetime The maximum age of a session.
+ *
+ * @return boolean True on success, false otherwise.
+ */
+ abstract public function gc($maxlifetime = 300);
+
+ /**
+ * Get session data read-only.
+ *
+ * @param string $id The session identifier.
+ *
+ * @return string The session data.
+ */
+ protected function _readOnly($id)
+ {
+ return $this->read($id);
+ }
+
+ /**
+ * Get a list of the valid session identifiers.
+ *
+ * @return array A list of valid session identifiers.
+ * @throws Horde_SessionHandler_Exception
+ */
+ abstract public function getSessionIDs();
+
+ /**
+ * Returns a list of authenticated users and data about their session.
+ *
+ * @return array For authenticated users, the sessionid as a key and the
+ * session information as value. If no parsing function
+ * was provided, will always return an empty array.
+ * @throws Horde_SessionHandler_Exception
+ */
+ public function getSessionsInfo()
+ {
+ $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 = call_user_func($this->_params['parse'], $data);
+ if ($data !== false) {
+ $info[$id] = $data;
+ }
+ }
+
+ return $info;
+ }
+
+}
<?php
/**
- * SessionHandler:: implementation for PHP's built-in session handler.
+ * Horde_SessionHandler implementation for PHP's built-in session handler.
* This doesn't do any session handling itself - instead, it exists to allow
* utility features to be used with the built-in PHP handler.
*
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_Builtin extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_Builtin extends Horde_SessionHandler_Base
{
/**
* Constructor.
+++ /dev/null
-<?php
-/**
- * Horde_SessionHandler_Driver:: is the abstract class that all drivers
- * inherit from.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @package SessionHandler
- */
-abstract class Horde_SessionHandler_Driver
-{
- /**
- * Hash containing connection parameters.
- *
- * @var array
- */
- protected $_params = array();
-
- /**
- * Initial session data signature.
- *
- * @var string
- */
- protected $_sig;
-
- /**
- * Force saving the session data?
- *
- * @var boolean
- */
- protected $_force = false;
-
- /**
- * Has a connection been made to the backend?
- *
- * @var boolean
- */
- protected $_connected = false;
-
- /**
- * A logger instance.
- *
- * @var Horde_Log_Logger
- */
- protected $_logger;
-
- /**
- * Session variable name.
- *
- * @var string
- */
- protected $_session = 'horde_sh';
-
- /**
- * Constructor.
- *
- * @param array $params Parameters:
- * <pre>
- * 'logger' - (Horde_Log_Logger) A logger instance.
- * 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())
- {
- $params = array_merge($this->_params, $params);
-
- if (isset($params['logger'])) {
- $this->_logger = $params['logger'];
- unset($params['logger']);
- }
-
- $this->_params = $params;
-
- register_shutdown_function(array($this, 'shutdown'));
-
- if (empty($this->_params['noset'])) {
- ini_set('session.save_handler', 'user');
- session_set_save_handler(
- array($this, 'open'),
- array($this, 'close'),
- array($this, 'read'),
- array($this, 'write'),
- array($this, 'destroy'),
- array($this, 'gc')
- );
- }
- }
-
- /**
- * Destructor.
- */
- public function __destruct()
- {
- /* This is necessary as of PHP 5.0.5 because objects are not available
- * when the write() handler is called at the end of a session
- * access. */
- session_write_close();
- }
-
- /**
- * Shutdown function.
- *
- * Used to determine if we need to write the session to avoid a session
- * timeout, even though the session is unchanged.
- * Theory: On initial login, set the current time plus half of the max
- * lifetime in the session. Then check this timestamp before saving.
- * If we exceed, force a write of the session and set a new timestamp.
- * Why half the maxlifetime? It guarantees that if we are accessing the
- * server via a periodic mechanism (think folder refreshing in IMP) that
- * we will catch this refresh.
- */
- public function shutdown()
- {
- $curr_time = time();
-
- if (!isset($_SESSION[$this->_session]) ||
- ($curr_time >= $_SESSION[$this->_session])) {
- $_SESSION[$this->_session] = $curr_time + (ini_get('session.gc_maxlifetime') / 2);
- $this->_force = true;
- }
- }
-
- /**
- * Open the backend.
- *
- * @param string $save_path The path to the session object.
- * @param string $session_name The name of the session.
- *
- * @return boolean True on success, false otherwise.
- */
- public function open($save_path = null, $session_name = null)
- {
- if (!$this->_connected) {
- try {
- $this->_open($save_path, $session_name);
- } catch (Horde_SessionHandler_Exception $e) {
- if ($this->_logger) {
- $this->_logger->log($e, 'ERR');
- }
- return false;
- }
-
- $this->_connected = true;
- }
-
- return true;
- }
-
- /**
- * Open the backend.
- *
- * @param string $save_path The path to the session object.
- * @param string $session_name The name of the session.
- *
- * @throws Horde_SessionHandler_Exception
- */
- abstract protected function _open($save_path = null, $session_name = null);
-
- /**
- * Close the backend.
- *
- * @return boolean True on success, false otherwise.
- */
- public function close()
- {
- try {
- $this->_close();
- } catch (Horde_SessionHandler_Exception $e) {
- if ($this->_logger) {
- $this->_logger->log($e, 'ERR');
- }
- return false;
- }
-
- $this->_connected = false;
- return true;
- }
-
- /**
- * Close the backend.
- *
- * @throws Horde_SessionHandler_Exception
- */
- abstract protected function _close();
-
- /**
- * Read the data for a particular session identifier from the backend.
- * This method should only be called internally by PHP via
- * session_set_save_handler().
- *
- * @param string $id The session identifier.
- *
- * @return string The session data.
- */
- public function read($id)
- {
- $result = $this->_read($id);
- $this->_sig = md5($result);
- return $result;
- }
-
- /**
- * Read the data for a particular session identifier from the backend.
- *
- * @param string $id The session identifier.
- *
- * @return string The session data.
- */
- abstract protected function _read($id);
-
- /**
- * Write session data to the backend.
- * This method should only be called internally by PHP via
- * session_set_save_handler().
- *
- * @param string $id The session identifier.
- * @param string $session_data The session data.
- *
- * @return boolean True on success, false otherwise.
- */
- public function write($id, $session_data)
- {
- if (!$this->_force && ($this->_sig == md5($session_data))) {
- if ($this->_logger) {
- $this->_logger->log('Session data unchanged (id = ' . $id . ')', 'DEBUG');
- }
- return true;
- }
-
- return $this->_write($id, $session_data);
- }
-
- /**
- * Write session data to the backend.
- *
- * @param string $id The session identifier.
- * @param string $session_data The session data.
- *
- * @return boolean True on success, false otherwise.
- */
- abstract protected function _write($id, $session_data);
-
- /**
- * Destroy the data for a particular session identifier in the backend.
- * This method should only be called internally by PHP via
- * session_set_save_handler().
- *
- * @param string $id The session identifier.
- *
- * @return boolean True on success, false otherwise.
- */
- abstract public function destroy($id);
-
- /**
- * Garbage collect stale sessions from the backend.
- * This method should only be called internally by PHP via
- * session_set_save_handler().
- *
- * @param integer $maxlifetime The maximum age of a session.
- *
- * @return boolean True on success, false otherwise.
- */
- abstract public function gc($maxlifetime = 300);
-
- /**
- * Get session data read-only.
- *
- * @param string $id The session identifier.
- *
- * @return string The session data.
- */
- protected function _readOnly($id)
- {
- return $this->read($id);
- }
-
- /**
- * Get a list of the valid session identifiers.
- *
- * @return array A list of valid session identifiers.
- * @throws Horde_SessionHandler_Exception
- */
- abstract public function getSessionIDs();
-
- /**
- * Returns a list of authenticated users and data about their session.
- *
- * @return array For authenticated users, the sessionid as a key and the
- * session information as value. If no parsing function
- * was provided, will always return an empty array.
- * @throws Horde_SessionHandler_Exception
- */
- public function getSessionsInfo()
- {
- $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 = call_user_func($this->_params['parse'], $data);
- if ($data !== false) {
- $info[$id] = $data;
- }
- }
-
- return $info;
- }
-
-}
<?php
/**
- * Horde_SessionHandler_External:: implements an external save handler defined
+ * Horde_SessionHandler_External implements an external save handler defined
* via driver configuration parameters.
*
* Copyright 2010 The Horde Project (http://www.horde.org/)
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_External extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_External extends Horde_SessionHandler_Base
{
/**
* Constructor.
<?php
/**
- * SessionHandler implementation for LDAP directories.
+ * Horde_SessionHandler implementation for LDAP directories.
*
* This code is adapted from the comments at
* http://www.php.net/session-set-save-handler.
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_Ldap extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_Ldap extends Horde_SessionHandler_Base
{
/**
* Horde_Ldap object.
<?php
/**
- * SessionHandler implementation for memcache.
+ * Horde_SessionHandler implementation for memcache.
*
* Copyright 2005-2010 The Horde Project (http://www.horde.org/)
*
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_Memcache extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_Memcache extends Horde_SessionHandler_Base
{
/**
* Memcache object.
<?php
/**
- * SessionHandler implementation for SQL databases.
+ * Horde_SessionHandler implementation for SQL databases.
*
* The table structure can be found in:
* horde/scripts/sql/horde_sessionhandler.sql.
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_Sql extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_Sql extends Horde_SessionHandler_Base
{
/**
* Handle for the current database connection.
<?php
/**
- * Horde_SessionHandler_Stack:: is an implementation that will loop through
- * a given list of Horde_SessionHandler_Drivers to return the session
+ * Horde_SessionHandler_Stack is an implementation that will loop through a
+ * given list of Horde_SessionHandler drivers to return the session
* information. This driver allows for use of caching backends on top of
* persistent backends.
*
* @category Horde
* @package SessionHandler
*/
-class Horde_SessionHandler_Stack extends Horde_SessionHandler_Driver
+class Horde_SessionHandler_Stack extends Horde_SessionHandler_Base
{
/**
* Stack of sessionhandlers.
<dir name="Horde">
<dir name="SessionHandler">
<file name="Builtin.php" role="php" />
- <file name="Driver.php" role="php" />
+ <file name="Base.php" role="php" />
<file name="Exception.php" role="php" />
<file name="External.php" role="php" />
<file name="Ldap.php" role="php" />
<filelist>
<install as="Horde/SessionHandler.php" name="lib/Horde/SessionHandler.php" />
<install as="Horde/SessionHandler/Builtin.php" name="lib/Horde/SessionHandler/Builtin.php" />
- <install as="Horde/SessionHandler/Driver.php" name="lib/Horde/SessionHandler/Driver.php" />
+ <install as="Horde/SessionHandler/Base.php" name="lib/Horde/SessionHandler/Base.php" />
<install as="Horde/SessionHandler/Exception.php" name="lib/Horde/SessionHandler/Exception.php" />
<install as="Horde/SessionHandler/External.php" name="lib/Horde/SessionHandler/External.php" />
<install as="Horde/SessionHandler/Ldap.php" name="lib/Horde/SessionHandler/Ldap.php" />
--- /dev/null
+<?php
+/**
+ * The Horde_Token_Driver:: class provides a common abstracted interface for
+ * a token driver.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Max Kalika <max@horde.org>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @category Horde
+ * @package Token
+ */
+abstract class Horde_Token_Driver
+{
+ /**
+ * Logger.
+ *
+ * @var Horde_Log_Logger
+ */
+ protected $_logger;
+
+ /**
+ * Hash of parameters necessary to use the chosen backend.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * Constructor.
+ *
+ * @param array $params Optional parameters:
+ * <pre>
+ * 'logger' - (Horde_Log_Logger) A logger object.
+ * </pre>
+ */
+ public function __construct($params)
+ {
+ if (isset($params['logger'])) {
+ $this->_logger = $params['logger'];
+ unset($params['logger']);
+ }
+
+ $this->_params = $params;
+ }
+
+ /**
+ * Checks if the given token has been previously used. First
+ * purges all expired tokens. Then retrieves current tokens for
+ * the given ip address. If the specified token was not found,
+ * adds it.
+ *
+ * @param string $token The value of the token to check.
+ *
+ * @return boolean True if the token has not been used, false otherwise.
+ * @throws Horde_Token_Exception
+ */
+ public function verify($token)
+ {
+ $this->purge();
+
+ if ($this->exists($token)) {
+ return false;
+ }
+
+ $this->add($token);
+ return true;
+ }
+
+ /**
+ * Does the token exist?
+ *
+ * @param string $tokenID Token ID.
+ *
+ * @return boolean True if the token exists.
+ * @throws Horde_Token_Exception
+ */
+ abstract public function exists($tokenID);
+
+ /**
+ * Add a token ID.
+ *
+ * @param string $tokenID Token ID to add.
+ *
+ * @throws Horde_Token_Exception
+ */
+ abstract public function add($tokenID);
+
+ /**
+ * Delete all expired connection IDs.
+ *
+ * @throws Horde_Token_Exception
+ */
+ abstract public function purge();
+
+ /**
+ * Encodes the remote address.
+ *
+ * @return string Encoded address.
+ */
+ protected function _encodeRemoteAddress()
+ {
+ return isset($_SERVER['REMOTE_ADDR'])
+ ? base64_encode($_SERVER['REMOTE_ADDR'])
+ : '';
+ }
+
+
+}
+++ /dev/null
-<?php
-/**
- * The Horde_Token_Driver:: class provides a common abstracted interface for
- * a token driver.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @author Max Kalika <max@horde.org>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @category Horde
- * @package Token
- */
-abstract class Horde_Token_Driver
-{
- /**
- * Logger.
- *
- * @var Horde_Log_Logger
- */
- protected $_logger;
-
- /**
- * Hash of parameters necessary to use the chosen backend.
- *
- * @var array
- */
- protected $_params = array();
-
- /**
- * Constructor.
- *
- * @param array $params Optional parameters:
- * <pre>
- * 'logger' - (Horde_Log_Logger) A logger object.
- * </pre>
- */
- public function __construct($params)
- {
- if (isset($params['logger'])) {
- $this->_logger = $params['logger'];
- unset($params['logger']);
- }
-
- $this->_params = $params;
- }
-
- /**
- * Checks if the given token has been previously used. First
- * purges all expired tokens. Then retrieves current tokens for
- * the given ip address. If the specified token was not found,
- * adds it.
- *
- * @param string $token The value of the token to check.
- *
- * @return boolean True if the token has not been used, false otherwise.
- * @throws Horde_Token_Exception
- */
- public function verify($token)
- {
- $this->purge();
-
- if ($this->exists($token)) {
- return false;
- }
-
- $this->add($token);
- return true;
- }
-
- /**
- * Does the token exist?
- *
- * @param string $tokenID Token ID.
- *
- * @return boolean True if the token exists.
- * @throws Horde_Token_Exception
- */
- abstract public function exists($tokenID);
-
- /**
- * Add a token ID.
- *
- * @param string $tokenID Token ID to add.
- *
- * @throws Horde_Token_Exception
- */
- abstract public function add($tokenID);
-
- /**
- * Delete all expired connection IDs.
- *
- * @throws Horde_Token_Exception
- */
- abstract public function purge();
-
- /**
- * Encodes the remote address.
- *
- * @return string Encoded address.
- */
- protected function _encodeRemoteAddress()
- {
- return isset($_SERVER['REMOTE_ADDR'])
- ? base64_encode($_SERVER['REMOTE_ADDR'])
- : '';
- }
-
-
-}
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>* Add Horde_Token_Exception::.
- * Move driver code into Horde_Token_Driver::.
+ * Move driver code into sub-classes.
* Use exceptions, not PEAR_Errors.
* Initial Horde 4 package.
</notes>
<dir name="lib">
<dir name="Horde">
<dir name="Token">
- <file name="Driver.php" role="php" />
+ <file name="Base.php" role="php" />
<file name="Exception.php" role="php" />
<file name="File.php" role="php" />
<file name="Null.php" role="php" />
</dependencies>
<phprelease>
<filelist>
- <install name="lib/Horde/Token/Driver.php" as="Horde/Token/Driver.php" />
+ <install name="lib/Horde/Token/Base.php" as="Horde/Token/Base.php" />
<install name="lib/Horde/Token/Exception.php" as="Horde/Token/Exception.php" />
<install name="lib/Horde/Token/File.php" as="Horde/Token/File.php" />
<install name="lib/Horde/Token/Null.php" as="Horde/Token/Null.php" />
$timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit');
if ($timelimit !== true) {
$sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail');
- if (!is_subclass_of($sentmail, 'IMP_Sentmail_Driver')) {
+ if (!($sentmail instanceof IMP_Sentmail_Base)) {
Horde::logMessage('The permission for the maximum number of recipients per time period has been enabled, but no backend for the sent-mail logging has been configured for IMP.', 'ERR');
throw new IMP_Compose_Exception(_("The system is not properly configured. A detailed error description has been logged for the administrator."));
}
--- /dev/null
+<?php
+/**
+ * The IMP_Quota_Base:: class is the abstract class that all driver
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/gpl.html GPL
+ * @package IMP
+ */
+abstract class IMP_Quota_Base
+{
+ /**
+ * Driver parameters.
+ *
+ * @var array
+ */
+ protected $_params = array(
+ 'unit' => 'MB'
+ );
+
+ /**
+ * Constructor.
+ *
+ * @param array $params Parameters:
+ * <pre>
+ * 'format' - (string) The formats of the quota messages in the user
+ * interface. Must be a hash with the four possible elements
+ * 'long', 'short', 'nolimit_long', and 'nolimit_short'. The
+ * strings will be passed through sprintf().
+ * 'unit' - (string) What storage unit the quota messages should be
+ * displayed in. Either 'GB', 'MB', or 'KB'.
+ * </pre>
+ */
+ public function __construct(array $params = array())
+ {
+ $this->_params = array_merge($this->_params, $params);
+
+ $this->_params['format'] = array(
+ 'long' => isset($this->_params['format']['long'])
+ ? $this->_params['format']['long']
+ : _("Quota status: %.2f %s / %.2f %s (%.2f%%)"),
+ 'short' => isset($this->_params['format']['short'])
+ ? $this->_params['format']['short']
+ : _("%.0f%% of %.0f %s"),
+ 'nolimit_long' => isset($this->_params['format']['nolimit_long'])
+ ? $this->_params['format']['nolimit_long']
+ : _("Quota status: %.2f %s / NO LIMIT"),
+ 'nolimit_short' => isset($this->_params['format']['nolimit_short'])
+ ? $this->_params['format']['nolimit_short']
+ : _("%.0f %s")
+ );
+ }
+
+ /**
+ * Get quota information (used/allocated), in bytes.
+ *
+ * @return array An array with the following keys:
+ * 'limit' = Maximum quota allowed
+ * 'usage' = Currently used portion of quota (in bytes)
+ * @throws IMP_Exception
+ */
+ abstract public function getQuota();
+
+ /**
+ * Returns the quota messages variants, including sprintf placeholders.
+ *
+ * @return array An array with quota message templates.
+ */
+ public function getMessages()
+ {
+ return $this->_params['format'];
+ }
+
+ /**
+ * Determine the units of storage to display in the quota message.
+ *
+ * @return array An array of size and unit type.
+ */
+ public function getUnit()
+ {
+ $unit = $this->_params['unit'];
+
+ switch ($unit) {
+ case 'GB':
+ $calc = 1024 * 1024 * 1024.0;
+ break;
+
+ case 'KB':
+ $calc = 1024.0;
+ break;
+
+ case 'MB':
+ default:
+ $calc = 1024 * 1024.0;
+ $unit = 'MB';
+ break;
+ }
+
+ return array($calc, $unit);
+ }
+
+}
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Command extends IMP_Quota_Driver
+class IMP_Quota_Command extends IMP_Quota_Base
{
/**
* Constructor.
+++ /dev/null
-<?php
-/**
- * The IMP_Quota_Driver:: class is the abstract class that all driver
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @license http://www.fsf.org/copyleft/gpl.html GPL
- * @package IMP
- */
-abstract class IMP_Quota_Driver
-{
- /**
- * Driver parameters.
- *
- * @var array
- */
- protected $_params = array(
- 'unit' => 'MB'
- );
-
- /**
- * Constructor.
- *
- * @param array $params Parameters:
- * <pre>
- * 'format' - (string) The formats of the quota messages in the user
- * interface. Must be a hash with the four possible elements
- * 'long', 'short', 'nolimit_long', and 'nolimit_short'. The
- * strings will be passed through sprintf().
- * 'unit' - (string) What storage unit the quota messages should be
- * displayed in. Either 'GB', 'MB', or 'KB'.
- * </pre>
- */
- public function __construct(array $params = array())
- {
- $this->_params = array_merge($this->_params, $params);
-
- $this->_params['format'] = array(
- 'long' => isset($this->_params['format']['long'])
- ? $this->_params['format']['long']
- : _("Quota status: %.2f %s / %.2f %s (%.2f%%)"),
- 'short' => isset($this->_params['format']['short'])
- ? $this->_params['format']['short']
- : _("%.0f%% of %.0f %s"),
- 'nolimit_long' => isset($this->_params['format']['nolimit_long'])
- ? $this->_params['format']['nolimit_long']
- : _("Quota status: %.2f %s / NO LIMIT"),
- 'nolimit_short' => isset($this->_params['format']['nolimit_short'])
- ? $this->_params['format']['nolimit_short']
- : _("%.0f %s")
- );
- }
-
- /**
- * Get quota information (used/allocated), in bytes.
- *
- * @return array An array with the following keys:
- * 'limit' = Maximum quota allowed
- * 'usage' = Currently used portion of quota (in bytes)
- * @throws IMP_Exception
- */
- abstract public function getQuota();
-
- /**
- * Returns the quota messages variants, including sprintf placeholders.
- *
- * @return array An array with quota message templates.
- */
- public function getMessages()
- {
- return $this->_params['format'];
- }
-
- /**
- * Determine the units of storage to display in the quota message.
- *
- * @return array An array of size and unit type.
- */
- public function getUnit()
- {
- $unit = $this->_params['unit'];
-
- switch ($unit) {
- case 'GB':
- $calc = 1024 * 1024 * 1024.0;
- break;
-
- case 'KB':
- $calc = 1024.0;
- break;
-
- case 'MB':
- default:
- $calc = 1024 * 1024.0;
- $unit = 'MB';
- break;
- }
-
- return array($calc, $unit);
- }
-
-}
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Hook extends IMP_Quota_Driver
+class IMP_Quota_Hook extends IMP_Quota_Base
{
/**
* Get quota information (used/allocated), in bytes.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Imap extends IMP_Quota_Driver
+class IMP_Quota_Imap extends IMP_Quota_Base
{
/**
* Constructor.
* @package IMP
* @todo Add config param for storage vs message quota
*/
-class IMP_Quota_Maildir extends IMP_Quota_Driver
+class IMP_Quota_Maildir extends IMP_Quota_Base
{
/**
* Constructor.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Mdaemon extends IMP_Quota_Driver
+class IMP_Quota_Mdaemon extends IMP_Quota_Base
{
/**
* Constructor.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Mercury32 extends IMP_Quota_Driver
+class IMP_Quota_Mercury32 extends IMP_Quota_Base
{
/**
* Constructor.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Null extends IMP_Quota_Driver
+class IMP_Quota_Null extends IMP_Quota_Base
{
/**
* Get quota information (used/allocated), in bytes.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Quota_Sql extends IMP_Quota_Driver
+class IMP_Quota_Sql extends IMP_Quota_Base
{
/**
* DB object.
--- /dev/null
+<?php
+/**
+ * The IMP_Sentmail_Base:: class is the abstract class that all driver
+ * implementations inherit from.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package IMP
+ */
+abstract class IMP_Sentmail_Base
+{
+ /**
+ * Hash containing configuration parameters.
+ *
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * Constructor.
+ *
+ * @throws IMP_Exception
+ */
+ public function __construct($params = array())
+ {
+ $this->_params = array_merge($this->_params, $params);
+ }
+
+ /**
+ * Logs an attempt to send a message.
+ *
+ * @param string $action Why the message was sent, i.e. "new",
+ * "reply", "forward", etc.
+ * @param string $message_id The Message-ID.
+ * @param string|array $recipients The list of message recipients.
+ * @param boolean $success Whether the attempt was successful.
+ */
+ public function log($action, $message_id, $recipients, $success = true)
+ {
+ if (!is_array($recipients)) {
+ $recipients = array($recipients);
+ }
+
+ foreach ($recipients as $addresses) {
+ $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true);
+ foreach ($addresses as $recipient) {
+ $this->_log($action, $message_id, $recipient, $success);
+ }
+ }
+ }
+
+ /**
+ * Garbage collect log entries.
+ */
+ public function gc()
+ {
+ $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400));
+ }
+
+ /**
+ * Logs an attempt to send a message per recipient.
+ *
+ * @param string $action Why the message was sent, i.e. "new",
+ * "reply", "forward", etc.
+ * @param string $message_id The Message-ID.
+ * @param string $recipients A message recipient.
+ * @param boolean $success Whether the attempt was successful.
+ */
+ abstract protected function _log($action, $message_id, $recipient,
+ $success);
+
+ /**
+ * Returns the favourite recipients.
+ *
+ * @param integer $limit Return this number of recipients.
+ * @param array $filter A list of messages types that should be returned.
+ * A value of null returns all message types.
+ *
+ * @return array A list with the $limit most favourite recipients.
+ * @throws IMP_Exception
+ */
+ abstract public function favouriteRecipients($limit,
+ $filter = array('new', 'forward', 'reply', 'redirect'));
+
+ /**
+ * Returns the number of recipients within a certain time period.
+ *
+ * @param integer $hours Time period in hours.
+ * @param boolean $user Return the number of recipients for the current
+ * user?
+ *
+ * @return integer The number of recipients in the given time period.
+ * @throws IMP_Exception
+ */
+ abstract public function numberOfRecipients($hours, $user = false);
+
+ /**
+ * Deletes all log entries older than a certain date.
+ *
+ * @param integer $before Unix timestamp before that all log entries
+ * should be deleted.
+ */
+ abstract protected function _deleteOldEntries($before);
+
+}
+++ /dev/null
-<?php
-/**
- * The IMP_Sentmail_Driver:: class is the abstract class that all driver
- * implementations inherit from.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author Jan Schneider <jan@horde.org>
- * @author Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @package IMP
- */
-abstract class IMP_Sentmail_Driver
-{
- /**
- * Hash containing configuration parameters.
- *
- * @var array
- */
- protected $_params = array();
-
- /**
- * Constructor.
- *
- * @throws IMP_Exception
- */
- public function __construct($params = array())
- {
- $this->_params = array_merge($this->_params, $params);
- }
-
- /**
- * Logs an attempt to send a message.
- *
- * @param string $action Why the message was sent, i.e. "new",
- * "reply", "forward", etc.
- * @param string $message_id The Message-ID.
- * @param string|array $recipients The list of message recipients.
- * @param boolean $success Whether the attempt was successful.
- */
- public function log($action, $message_id, $recipients, $success = true)
- {
- if (!is_array($recipients)) {
- $recipients = array($recipients);
- }
-
- foreach ($recipients as $addresses) {
- $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true);
- foreach ($addresses as $recipient) {
- $this->_log($action, $message_id, $recipient, $success);
- }
- }
- }
-
- /**
- * Garbage collect log entries.
- */
- public function gc()
- {
- $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400));
- }
-
- /**
- * Logs an attempt to send a message per recipient.
- *
- * @param string $action Why the message was sent, i.e. "new",
- * "reply", "forward", etc.
- * @param string $message_id The Message-ID.
- * @param string $recipients A message recipient.
- * @param boolean $success Whether the attempt was successful.
- */
- abstract protected function _log($action, $message_id, $recipient,
- $success);
-
- /**
- * Returns the favourite recipients.
- *
- * @param integer $limit Return this number of recipients.
- * @param array $filter A list of messages types that should be returned.
- * A value of null returns all message types.
- *
- * @return array A list with the $limit most favourite recipients.
- * @throws IMP_Exception
- */
- abstract public function favouriteRecipients($limit,
- $filter = array('new', 'forward', 'reply', 'redirect'));
-
- /**
- * Returns the number of recipients within a certain time period.
- *
- * @param integer $hours Time period in hours.
- * @param boolean $user Return the number of recipients for the current
- * user?
- *
- * @return integer The number of recipients in the given time period.
- * @throws IMP_Exception
- */
- abstract public function numberOfRecipients($hours, $user = false);
-
- /**
- * Deletes all log entries older than a certain date.
- *
- * @param integer $before Unix timestamp before that all log entries
- * should be deleted.
- */
- abstract protected function _deleteOldEntries($before);
-
-}
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Sentmail_Null extends IMP_Sentmail_Driver
+class IMP_Sentmail_Null extends IMP_Sentmail_Base
{
/**
* Garbage collect log entries.
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Sentmail_Sql extends IMP_Sentmail_Driver
+class IMP_Sentmail_Sql extends IMP_Sentmail_Base
{
/**
* Handle for the current database connection.