- phpDocumentor headers and improved docu about class methods

- coding stylite cleanup
This commit is contained in:
Ralf Becker 2009-08-22 06:58:38 +00:00
parent 109c50fecf
commit 19e6159a4a
2 changed files with 353 additions and 351 deletions

View File

@ -1,32 +1,22 @@
<?php <?php
/**************************************************************************\ /**
* eGroupWare API - Accounts manager for LDAP * * API - LDAP connection handling
* This file written by Lars Kneschke <l.kneschke@metaways.de> * *
* View and manipulate contact records using LDAP * * @link http://www.egroupware.org
* ------------------------------------------------------------------------ * * @author Lars Kneschke <l.kneschke@metaways.de>
* This library is part of the eGroupWare API * * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* http://www.egroupware.org/api * *
* -------------------------------------------- * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* This program is free software; you can redistribute it and/or modify it * * @package api
* under the terms of the GNU General Public License as published by the * * @subpackage ldap
* Free Software Foundation; version 2 of the License. * * @version $Id$
\**************************************************************************/
/* $Id$ */
/*!
@class contacts
@abstract Contact List System
@discussion Author: jengo/Milosch <br>
This class provides a contact database scheme. <br>
It attempts to be based on the vcard 2.1 standard, with mods as needed to make for more reasonable sql storage. <br>
The LDAP schema used here may require installation of schema files available in the phpgwapi/doc/ldap dir.
Please see the README file there.
Syntax: CreateObject('phpgwapi.contacts'); <br>
Example1: $contacts = CreateObject('phpgwapi.contacts');
*/ */
class ldap
{ /**
* LDAP connection handling
*/
class ldap
{
/** /**
* @var resource $ds holds the LDAP link identifier * @var resource $ds holds the LDAP link identifier
*/ */
@ -40,7 +30,8 @@
/** /**
* the constructor for this class * the constructor for this class
*/ */
function ldap() { function __construct()
{
$this->restoreSessionData(); $this->restoreSessionData();
} }
@ -51,13 +42,14 @@
* It's actually a PHP-Bug, that we have to escape space. * It's actually a PHP-Bug, that we have to escape space.
* For all other Characters, refer to RFC2254. * For all other Characters, refer to RFC2254.
* @param $string either a string to be escaped, or an array of values to be escaped * @param $string either a string to be escaped, or an array of values to be escaped
* @return ldapserverinfo|boolean
*/ */
function getLDAPServerInfo($_host) function getLDAPServerInfo($_host)
{ {
if(is_a($this->ldapServerInfo[$_host], 'ldapserverinfo')) { if(is_a($this->ldapServerInfo[$_host], 'ldapserverinfo'))
{
return $this->ldapServerInfo[$_host]; return $this->ldapServerInfo[$_host];
} }
return false; return false;
} }
@ -68,9 +60,10 @@
* It's actually a PHP-Bug, that we have to escape space. * It's actually a PHP-Bug, that we have to escape space.
* For all other Characters, refer to RFC2254. * For all other Characters, refer to RFC2254.
* *
* @param string/array $string either a string to be escaped, or an array of values to be escaped * @param string|array $string either a string to be escaped, or an array of values to be escaped
* @return string
*/ */
function quote($string) static function quote($string)
{ {
return str_replace(array('\\','*','(',')','\0',' '),array('\\\\','\*','\(','\)','\\0','\20'),$string); return str_replace(array('\\','*','(',')','\0',' '),array('\\\\','\*','\(','\)','\\0','\20'),$string);
} }
@ -81,6 +74,7 @@
* @param $host ldap host * @param $host ldap host
* @param $dn ldap dn * @param $dn ldap dn
* @param $passwd ldap pw * @param $passwd ldap pw
* @return resource|boolean resource from ldap_connect() or false on error
*/ */
function ldapConnect($host='', $dn='', $passwd='') function ldapConnect($host='', $dn='', $passwd='')
{ {
@ -126,36 +120,46 @@
return False; return False;
} }
if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { if(ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3))
{
$supportedLDAPVersion = 3; $supportedLDAPVersion = 3;
} else { }
else
{
$supportedLDAPVersion = 2; $supportedLDAPVersion = 2;
} }
if(!isset($this->ldapServerInfo[$host])) { if(!isset($this->ldapServerInfo[$host]))
{
//error_log("no ldap server info found"); //error_log("no ldap server info found");
$ldapbind = @ldap_bind($this->ds, $GLOBALS['egw_info']['server']['ldap_root_dn'], $GLOBALS['egw_info']['server']['ldap_root_pw']); $ldapbind = @ldap_bind($this->ds, $GLOBALS['egw_info']['server']['ldap_root_dn'], $GLOBALS['egw_info']['server']['ldap_root_pw']);
$filter='(objectclass=*)'; $filter='(objectclass=*)';
$justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry'); $justthese = array('structuralObjectClass','namingContexts','supportedLDAPVersion','subschemaSubentry');
if(($sr = @ldap_read($this->ds, '', $filter, $justthese))) { if(($sr = @ldap_read($this->ds, '', $filter, $justthese)))
if($info = ldap_get_entries($this->ds, $sr)) { {
if($info = ldap_get_entries($this->ds, $sr))
{
$ldapServerInfo = new ldapserverinfo(); $ldapServerInfo = new ldapserverinfo();
$ldapServerInfo->setVersion($supportedLDAPVersion); $ldapServerInfo->setVersion($supportedLDAPVersion);
// check for naming contexts // check for naming contexts
if($info[0]['namingcontexts']) { if($info[0]['namingcontexts'])
for($i=0; $i<$info[0]['namingcontexts']['count']; $i++) { {
for($i=0; $i<$info[0]['namingcontexts']['count']; $i++)
{
$namingcontexts[] = $info[0]['namingcontexts'][$i]; $namingcontexts[] = $info[0]['namingcontexts'][$i];
} }
$ldapServerInfo->setNamingContexts($namingcontexts); $ldapServerInfo->setNamingContexts($namingcontexts);
} }
// check for ldap server type // check for ldap server type
if($info[0]['structuralobjectclass']) { if($info[0]['structuralobjectclass'])
switch($info[0]['structuralobjectclass'][0]) { {
switch($info[0]['structuralobjectclass'][0])
{
case 'OpenLDAProotDSE': case 'OpenLDAProotDSE':
$ldapServerType = OPENLDAP_LDAPSERVER; $ldapServerType = OPENLDAP_LDAPSERVER;
break; break;
@ -167,47 +171,58 @@
} }
// check for subschema entry dn // check for subschema entry dn
if($info[0]['subschemasubentry']) { if($info[0]['subschemasubentry'])
{
$subschemasubentry = $info[0]['subschemasubentry'][0]; $subschemasubentry = $info[0]['subschemasubentry'][0];
$ldapServerInfo->setSubSchemaEntry($subschemasubentry); $ldapServerInfo->setSubSchemaEntry($subschemasubentry);
} }
// create list of supported objetclasses // create list of supported objetclasses
if(!empty($subschemasubentry)) { if(!empty($subschemasubentry))
{
$filter='(objectclass=*)'; $filter='(objectclass=*)';
$justthese = array('objectClasses'); $justthese = array('objectClasses');
if($sr=ldap_read($this->ds, $subschemasubentry, $filter, $justthese)) { if($sr=ldap_read($this->ds, $subschemasubentry, $filter, $justthese))
if($info = ldap_get_entries($this->ds, $sr)) { {
if($info = ldap_get_entries($this->ds, $sr))
{
if($info[0]['objectclasses']) { if($info[0]['objectclasses']) {
for($i=0; $i<$info[0]['objectclasses']['count']; $i++) { for($i=0; $i<$info[0]['objectclasses']['count']; $i++)
{
$pattern = '/^\( (.*) NAME \'(\w*)\' /'; $pattern = '/^\( (.*) NAME \'(\w*)\' /';
if(preg_match($pattern, $info[0]['objectclasses'][$i], $matches)) { if(preg_match($pattern, $info[0]['objectclasses'][$i], $matches))
{
#_debug_array($matches); #_debug_array($matches);
if(count($matches) == 3) { if(count($matches) == 3)
{
$supportedObjectClasses[$matches[1]] = strtolower($matches[2]); $supportedObjectClasses[$matches[1]] = strtolower($matches[2]);
} }
} }
} }
$ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses); $ldapServerInfo->setSupportedObjectClasses($supportedObjectClasses);
} }
} }
} }
} }
$this->ldapServerInfo[$host] = $ldapServerInfo; $this->ldapServerInfo[$host] = $ldapServerInfo;
} }
} else { }
else
{
$this->ldapServerInfo[$host] = false; $this->ldapServerInfo[$host] = false;
} }
$this->saveSessionData(); $this->saveSessionData();
} else { }
else
{
$ldapServerInfo = $this->ldapServerInfo[$host]; $ldapServerInfo = $this->ldapServerInfo[$host];
} }
if(!@ldap_bind($this->ds, $dn, $passwd)) { if(!@ldap_bind($this->ds, $dn, $passwd))
if(isset($GLOBALS['egw']->log)) { {
if(isset($GLOBALS['egw']->log))
{
$GLOBALS['egw']->log->message('F-Abort, Failed binding to LDAP server'); $GLOBALS['egw']->log->message('F-Abort, Failed binding to LDAP server');
$GLOBALS['egw']->log->commit(); $GLOBALS['egw']->log->commit();
} }
@ -250,6 +265,4 @@
$GLOBALS['egw']->session->appsession('ldapServerInfo','',serialize($this->ldapServerInfo)); $GLOBALS['egw']->session->appsession('ldapServerInfo','',serialize($this->ldapServerInfo));
} }
} }
}
}
?>

View File

@ -1,35 +1,24 @@
<?php <?php
/**************************************************************************\ /**
* eGroupWare API - Accounts manager for LDAP * * API - LDAP server information
* This file written by Lars Kneschke <l.kneschke@metaways.de> * *
* View and manipulate contact records using LDAP * * @link http://www.egroupware.org
* ------------------------------------------------------------------------ * * @author Lars Kneschke <l.kneschke@metaways.de>
* This library is part of the eGroupWare API * *
* http://www.egroupware.org/api * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* -------------------------------------------- * * @package api
* This program is free software; you can redistribute it and/or modify it * * @subpackage ldap
* under the terms of the GNU General Public License as published by the * * @version $Id$
* Free Software Foundation; version 2 of the License. *
\**************************************************************************/
/* $Id$ */
define('UNKNOWN_LDAPSERVER',0);
define('OPENLDAP_LDAPSERVER',1);
/*!
@class contacts
@abstract Contact List System
@discussion Author: jengo/Milosch <br>
This class provides a contact database scheme. <br>
It attempts to be based on the vcard 2.1 standard, with mods as needed to make for more reasonable sql storage. <br>
The LDAP schema used here may require installation of schema files available in the phpgwapi/doc/ldap dir.
Please see the README file there.
Syntax: CreateObject('phpgwapi.contacts'); <br>
Example1: $contacts = CreateObject('phpgwapi.contacts');
*/ */
class ldapserverinfo
{ define('UNKNOWN_LDAPSERVER',0);
define('OPENLDAP_LDAPSERVER',1);
/**
* Class to store and retrieve information (eg. supported object classes) of a connected ldap server
*/
class ldapserverinfo
{
/** /**
* @var array $namingContext holds the supported namingcontexts * @var array $namingContext holds the supported namingcontexts
*/ */
@ -60,18 +49,13 @@
*/ */
var $supportedOIDs = array(); var $supportedOIDs = array();
/**
* the constructor for this class
*/
/*function ldapserverinfo() {
}*/
/** /**
* gets the version * gets the version
* *
* @return integer the supported ldap version * @return integer the supported ldap version
*/ */
function getVersion() { function getVersion()
{
return $this->version; return $this->version;
} }
@ -80,7 +64,8 @@
* *
* @param array $_namingContext the supported namingcontexts * @param array $_namingContext the supported namingcontexts
*/ */
function setNamingContexts($_namingContext) { function setNamingContexts($_namingContext)
{
$this->namingContext = $_namingContext; $this->namingContext = $_namingContext;
} }
@ -89,7 +74,8 @@
* *
* @param integer $_serverType the type of ldap server * @param integer $_serverType the type of ldap server
*/ */
function setServerType($_serverType) { function setServerType($_serverType)
{
$this->serverType = $_serverType; $this->serverType = $_serverType;
} }
@ -98,7 +84,8 @@
* *
* @param string $_subSchemaEntry the subschema entry DN * @param string $_subSchemaEntry the subschema entry DN
*/ */
function setSubSchemaEntry($_subSchemaEntry) { function setSubSchemaEntry($_subSchemaEntry)
{
$this->subSchemaEntry = $_subSchemaEntry; $this->subSchemaEntry = $_subSchemaEntry;
} }
@ -107,7 +94,8 @@
* *
* @param array $_supportedObjectClasses the supported objectclasses * @param array $_supportedObjectClasses the supported objectclasses
*/ */
function setSupportedObjectClasses($_supportedObjectClasses) { function setSupportedObjectClasses($_supportedObjectClasses)
{
$this->supportedOIDs = $_supportedObjectClasses; $this->supportedOIDs = $_supportedObjectClasses;
$this->supportedObjectClasses = array_flip($_supportedObjectClasses); $this->supportedObjectClasses = array_flip($_supportedObjectClasses);
} }
@ -117,7 +105,8 @@
* *
* @param integer $_version the supported ldap version * @param integer $_version the supported ldap version
*/ */
function setVersion($_version) { function setVersion($_version)
{
$this->version = $_version; $this->version = $_version;
} }
@ -126,12 +115,12 @@
* *
* @return bool returns true if the ldap server supports this objectclass * @return bool returns true if the ldap server supports this objectclass
*/ */
function supportsObjectClass($_objectClass) { function supportsObjectClass($_objectClass)
if($this->supportedObjectClasses[strtolower($_objectClass)]) { {
if($this->supportedObjectClasses[strtolower($_objectClass)])
{
return true; return true;
} else { }
return false; return false;
} }
} }
}
?>