steffen: server/kolab-horde-framework/kolab-horde-framework/Net_IMSP/IMSP Auth.php, NONE, 1.1 Book.php, NONE, 1.1 Options.php, NONE, 1.1 Utils.php, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Fri Oct 14 16:33:10 CEST 2005
Author: steffen
Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/Net_IMSP/IMSP
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/Net_IMSP/IMSP
Added Files:
Auth.php Book.php Options.php Utils.php
Log Message:
Separated Horde Framework from kolab-resource-handlers
--- NEW FILE: Auth.php ---
<?php
require_once 'Net/IMSP.php';
/**
* The Net_IMSP_Auth class abstract class for IMSP authentication.
*
* Required Parameters:
* ====================
* 'username' -- Username to logon to IMSP server as.
* 'password' -- Password for current user.
* 'server' -- The hostname of the IMSP server.
* 'port' -- The port of the IMSP server.
*
* $Horde: framework/Net_IMSP/IMSP/Auth.php,v 1.8 2004/04/19 20:27:37 chuck Exp $
*
* Copyright 2003-2004 Michael Rubinsky <mike at theupstairsroom.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @version $Revision 1.5 $
* @author Michael Rubinsky <mike at theupstairsroom.com>
* @package Net_IMSP
*/
class Net_IMSP_Auth {
/**
* Attempts to login to IMSP server.
*
* @access public
* @param array $params Parameters for Net_IMSP
* @param boolean $login Should we remain logged in after auth?
* @return mixed Returns a Net_IMSP object connected to
* the IMSP server if login is true and
* successful. Returns boolean true if
* successful and login is false. Returns
* PEAR_Error on failure.
*/
function &authenticate($params, $login = true)
{
$_imsp = &$this->_authenticate($params);
if (is_a($_imsp, 'PEAR_Error')) {
return $_imsp;
}
if (!$login) {
$_imsp->logout();
return true;
}
return $_imsp;
}
/**
* Private authentication function. Provides actual authentication
* code.
*
* @abstract
* @access private
* @param array $params Parameters for Net_IMSP_Auth driver.
* @return mixed Returns Net_IMSP object connected to server
* if successful, PEAR_Error on failure.
*/
function &_authenticate($params)
{
}
/**
* Attempts to return a concrete Net_IMSP_Auth instance based on $driver
* Must be called as &Net_IMSP_Auth::factory()
*
* @access public
* @param string $driver Type of Net_IMSP_Auth subclass to return.
* @return mixed The created Net_IMSP_Auth subclass or PEAR_Error.
*/
function &factory($driver)
{
$driver = basename($driver);
if (empty($driver) || (strcmp($driver, 'none') == 0)) {
return $ret = &new IMSP_Auth();
}
if (file_exists(dirname(__FILE__) . '/Auth/' . $driver . '.php')) {
require_once dirname(__FILE__) . '/Auth/' . $driver . '.php';
}
$class = 'Net_IMSP_Auth_' . $driver;
if (class_exists($class)) {
return $ret = &new $class();
} else {
Horde::fatal(PEAR::raiseError(sprintf(_("Unable to load the definition of %s."), $class)), __FILE__, __LINE__);
}
}
/**
* Attempts to return a concrete Net_IMSP_Auth instance based on $driver.
* Will only create a new object if one with the same parameters already
* does not exist.
* Must be called like: $var = &Net_IMSP_Auth::singleton('driver_type');
*
* @param string $driver Type of IMSP_Auth subclass to return.
* @return object Reference to IMSP_Auth subclass.
*/
function &singleton($driver)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$signature = serialize(array($driver));
if (!isset($instances[$signature])) {
$instances[$signature] = &Net_IMSP_Auth::factory($driver);
}
return $instances[$signature];
}
}
--- NEW FILE: Book.php ---
<?php
require_once 'Net/IMSP/Auth.php';
/**
* RegExps that should match the respective server response strings.
*/
define('IMSP_ADDRESSBOOK_RESPONSE', "/^\* ADDRESSBOOK/");
define('IMSP_SEARCHADDRESS_RESPONSE', "/^\* SEARCHADDRESS/");
define('IMSP_FETCHADDRESS_RESPONSE', "/^\* FETCHADDRESS /");
define('IMSP_ACL_RESPONSE', "/^\* ACL ADDRESSBOOK/");
define('IMSP_MYRIGHTS_RESPONSE', "/^\* MYRIGHTS ADDRESSBOOK/");
/**
* Addressbook-specific exit codes.
*/
define('IMSP_ENTRY_LOCKED',
'That addressbook entry is locked or cannot be unlocked.');
[...1419 lines suppressed...]
if (substr($entry[$key], 0, 1) == '"') {
$entry[$key] = substr($entry[$key], 1,
strlen($entry[$key]) - 2);
}
if (substr($entry[$key],
strlen($entry[$key]) - 1, 1) == '"') {
$entry[$key] = substr($entry[$key], 0,
strlen($entry[$key]) - 2);
}
}
}
}
return $entry;
}
}
--- NEW FILE: Options.php ---
<?php
require_once 'Net/IMSP/Auth.php';
// Constants
define('IMSP_GETOPTION_RESPONSE', "/^\* OPTION/");
/**
* Net_IMSP_Options Class - provides an interface to IMSP server-based
* options storage.
*
* Required parameters:
* ====================
* 'username' -- Username to logon to IMSP server as.
* 'password' -- Password for current user.
* 'auth_method' -- The authentication method to use to login.
* 'server' -- The hostname of the IMSP server.
* 'port' -- The port of the IMSP server.
*
* $Horde: framework/Net_IMSP/IMSP/Options.php,v 1.2 2004/04/19 20:27:37 chuck Exp $
*
* Copyright 2004 Michael Rubinsky <mike at theupstairsroom.com>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @version $Revision: 1.1 $
* @author Michael Rubinsky <mike at theupstairsroom.com>
* @package Net_IMSP
*/
class Net_IMSP_Options {
var $_imsp;
var $user = '';
var $pass = '';
var $auth_method = '';
var $server = '';
var $port = '';
var $params;
/**
* Constructor function.
*
* @access public
* @param array $params Hash containing IMSP parameters.
*/
function Net_IMSP_Options($params)
{
$this->params = $params;
}
/**
* Initialization function to be called after object is returned.
* This allows errors to occur and not break the script.
*
* @access public
* @return mixed True on success PEAR_Error on failure.
*/
function init()
{
if (!isset($this->_imsp)) {
$auth = &Net_IMSP_Auth::singleton($this->params['auth_method']);
$this->_imsp = $auth->authenticate($this->params);
}
if (is_a($this->_imsp, 'PEAR_Error')) {
return $this->_imsp;
}
$this->_imsp->writeToLog('Net_IMSP_Options initialized.', __FILE__,
__LINE__, PEAR_LOG_DEBUG);
return true;
}
/**
* Function sends a GET command to IMSP server and retrieves values.
*
* @access public
* @param string $optionName Name of option to retrieve. Accepts '*'
* as wild card.
* @return mixed Associative array containing option=>value pairs or
* PEAR_Error.
*/
function get($optionName)
{
$options = array();
$result = $this->_imsp->imspSend("GET $optionName", true, true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
$server_response = $this->_imsp->imspReceive();
if (is_a($server_response, 'PEAR_Error')) {
return $server_response;
}
while (preg_match(IMSP_GETOPTION_RESPONSE,$server_response)){
/* First, check for a {}. */
if (preg_match(IMSP_OCTET_COUNT, $server_response, $tempArray)){
$temp = split(' ', $server_response);
$options[$temp[2]] = $this->_imsp->receiveStringLiteral($tempArray[2]);
$this->_imsp->imspReceive(); // [READ WRITE]
} else {
$temp = split(' ', $server_response);
$options[$temp[2]] = trim($temp[3]);
$i = 3;
$lastChar = "";
$nextElement = trim($temp[3]);
// Was the value quoted and spaced?
if ((substr($nextElement,0,1) == '"') &&
(substr($nextElement,strlen($nextElement)-1,1) != '"')) {
do {
$nextElement = $temp[$i+1];
$lastChar = substr($nextElement,
strlen($nextElement)-1,1);
$options[$temp[2]] .= ' ' . $nextElement;
if ($lastChar == '"') {
$done = true;
} else {
$done = false;
$lastChar = substr($temp[$i+2],
strlen($temp[$i+2])-1,1);
$i++;
}
} while ($lastChar != '"');
if (!$done) {
$nextElement = $temp[$i+1];
$options[$temp[2]] .= ' ' . $nextElement;
}
}
}
$server_response = $this->_imsp->imspReceive();
if (is_a($server_response, 'PEAR_Error')){
return $server_response;
}
}
if ($server_response != 'OK') {
return $this->_imsp->imspError(IMSP_UNEXPECTED_RESPONSE,
__FILE__,__LINE__);
}
$this->_imsp->writeToLog('GET command OK.', '', '', PEAR_LOG_DEBUG);
return $options;
}
/**
* Function sets an option value on the IMSP server.
*
* @access public
* @param string $optionName Name of option to set.
* @param string $optionValue Value to assign.
* @return mixed True or PEAR_Error.
*/
function set($optionName, $optionValue)
{
// Send the beginning of the command.
$result = $this->_imsp->imspSend("SET $optionName ", true, false);
// Send $optionValue as a literal {}?
if (preg_match(IMSP_MUST_USE_LITERAL, $optionValue)) {
$biValue = sprintf("{%d}",strlen($optionValue));
$result = $this->_imsp->imspSend($biValue,false,true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
if (!preg_match(IMSP_COMMAND_CONTINUATION_RESPONSE,
$this->_imsp->imspReceive())) {
return $this->_imsp->imspError(IMSP_NO_CONTINUATION_RESPONSE,
__FILE__,__LINE__);
}
}
// Now send the rest of the command.
$result = $this->_imsp->imspSend($optionValue, false, true);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
$server_response = $this->_imsp->imspReceive();
if (is_a($server_response, 'PEAR_Error')) {
return $server_response;
} elseif ($server_response != 'OK') {
return $this->_imsp->imspError('The option could not be set on the IMSP server.',__FILE__, __LINE__);
}
$this->_imsp->writeToLog('SET command OK.', '', '', PEAR_LOG_DEBUG);
return true;
}
/**
* Sets the log information in the Net_IMSP object.
*
* @access public
* @param array The log parameters.
* @return mixed True on success PEAR_Error on failure.
*/
function setLogger($params)
{
if (isset($this->_imsp)) {
return $this->_imsp->setLogger($params);
} else {
return $this->_imsp->imspError('The IMSP log could not be initialized.');
}
}
}
--- NEW FILE: Utils.php ---
<?php
/**
* Net_IMSP_Utils::
*
* $Horde: framework/Net_IMSP/IMSP/Utils.php,v 1.2 2004/03/18 16:49:41 chuck Exp $
*
* Copyright 2003-2004 Michael Rubinsky <mike at theupstairsroom.com>
*
* 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 Rubinsky <mike at theupstairsroom.com>
* @package Net_IMSP
*/
class Net_IMSP_Utils {
/**
* Utility function to retrieve the names of all the addressbooks
* that the user has access to, along with the acl for those
* books. For information about the $serverInfo array see
* turba/config/sources.php as this is the cfgSources[] entry for
* the addressbooks.
*
* @param array $serverInfo Information about the server
* and the current user.
*
* @return array Information about all the addressbooks.
*/
function getAllBooks($serverInfo)
{
require_once 'Net/IMSP.php';
$results = array();
$imsp = &Net_IMSP::singleton('Book', $serverInfo['params']);
$result = $imsp->init();
if (is_a($result, 'PEAR_Error')) {
return $result;
}
$books = $imsp->getAddressBookList();
for ($i = 0; $i < count($books); $i++) {
if ($books[$i] != $serverInfo['params']['username']) {
$newBook = $serverInfo;
$newBook['title'] = 'IMSP_' . $books[$i];
$newBook['params']['name'] = $books[$i];
if (strstr($imsp->myRights($books[$i]), 'w')) {
$newBook['readonly'] = false;
} else {
$newBook['readonly'] = true;
}
$results[] = $newBook;
}
}
return $results;
}
}
More information about the commits
mailing list