gunnar: server/php-kolab/Kolab_Webadmin/Webadmin db.php, NONE, 1.1 object.php, NONE, 1.1 address.class.php, 1.2, 1.3 administrator.class.php, 1.2, 1.3 auth.class.php, 1.4, 1.5 domainmaintainer.class.php, 1.3, 1.4 group.class.php, 1.3, 1.4 ldap.class.php, 1.8, 1.9 locale.php, 1.4, 1.5 maintainer.class.php, 1.2, 1.3 menu.php, 1.3, 1.4 sharedfolder.class.php, 1.3, 1.4 user.class.php, 1.5, 1.6 webadmin.class.php, 1.7, 1.8 debug.php, 1.2, NONE

cvs at kolab.org cvs at kolab.org
Wed Aug 22 14:41:12 CEST 2007


Author: gunnar

Update of /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin
In directory doto:/tmp/cvs-serv3677/Webadmin

Modified Files:
	address.class.php administrator.class.php auth.class.php 
	domainmaintainer.class.php group.class.php ldap.class.php 
	locale.php maintainer.class.php menu.php 
	sharedfolder.class.php user.class.php webadmin.class.php 
Added Files:
	db.php object.php 
Removed Files:
	debug.php 
Log Message:
The next draft version for this PEAR package. Most code duplication for listing Kolab objects has been removed now.

--- NEW FILE: db.php ---
<?php
/*  
 *  COPYRIGHT
 *  ---------
 *
 *  See ../AUTHORS file
 *
 *
 *  LICENSE
 *  -------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Revision: 1.1 $
 *
 *  ABOUT
 *  -----
 *
 *  A class for handling Kolab objects in the LDAP db.
 *
 */

/** Provide access to the Kolab specific objects. */
require_once 'Kolab/Webadmin/address.class.php';
require_once 'Kolab/Webadmin/administrator.class.php';
require_once 'Kolab/Webadmin/domainmaintainer.class.php';
require_once 'Kolab/Webadmin/group.class.php';
require_once 'Kolab/Webadmin/maintainer.class.php';
require_once 'Kolab/Webadmin/sharedfolder.class.php';
require_once 'Kolab/Webadmin/user.class.php';

/** Define the different Kolab object types */
define('KOLAB_OBJECT_ADDRESS',          'Address');
define('KOLAB_OBJECT_ADMINISTRATOR',    'Administrator');
define('KOLAB_OBJECT_DOMAINMAINTAINER', 'DomainMaintainer');
define('KOLAB_OBJECT_GROUP',            'Group');
define('KOLAB_OBJECT_MAINTAINER',       'Maintainer');
define('KOLAB_OBJECT_SHAREDFOLDER',     'SharedFolder');
define('KOLAB_OBJECT_USER',             'User');

/**
 * This class provides methods to deal with Kolab objects stored in
 * the LDAP db.
 *
 * $Header: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/db.php,v 1.1 2007/08/22 12:41:09 gunnar Exp $
 *
 * @author  Gunnar Wrobel  <wrobel at pardus.de>
 * @package Kolab_Webadmin
 */
class KolabObjectDb {

    /**
     * Link into the Kolab LDAP db
     *
     * @var KolabLDAP
     */
    var $_ldap;

    /**
     * Valid Kolab object types
     *
     * @var array
     */
    const valid_types = array(
        KOLAB_OBJECT_ADDRESS,
        KOLAB_OBJECT_ADMINISTRATOR,
        KOLAB_OBJECT_DOMAINMAINTAINER,
        KOLAB_OBJECT_GROUP,
        KOLAB_OBJECT_MAINTAINER,
        KOLAB_OBJECT_SHAREDFOLDER,
        KOLAB_OBJECT_USER,
    );

    /**
     * Initialize the Kolab Object DB
     *
     * @param KolabLDAP $ldap The link into the Kolab LDAP db
     */
    function KolabObjectDb($ldap)
    {
        $this->_ldap = $ldap;
    }

    /**
     * Fetch a Kolab object
     *
     * @param string $dn   The DN of the object to fetch
     * @param string $type The type of the object to fetch
     *
     * @return KolabObject The corresponding Kolab object
     */
    function fetch($dn, $type = null)
    {
        if (empty($type)) {
            $type = $this->determineType($dn);
            if (is_a($type, 'PEAR_Error')) {
                return $type;
            }
        } else {
            if (!in_array($type, $this->_valid_types)) {
                return PEAR::raiseError(sprintf(_("Invalid Kolab object type \"%s\"."), 
                                                $type));
            }
        }

        $class = 'Kolab' . $type;
        if (class_exists($class)) {
            $object = &new $class($this->_ldap, $dn);
            return $object;
        } else {
            return PEAR::raiseError(sprintf(_("Failed to load Kolab object type %s"),
                                            $type));
        }
    }

    /**
     * List all objects of a specific type
     *
     * @param string $type The type of the objects to be listed
     *
     * @return mixed An array of Kolab objects or a PEAR error
     */
    function list($type, $base_dn = null, $addfilter = '', $perpage = 50, $page = 1)
    {
        if (!in_array($type, $this->_valid_types)) {
            return PEAR::raiseError(sprintf(_("Invalid Kolab object type \"%s\"."), 
                                            $type));
        }

        if (empty($base_dn)) {
            $base_dn = $this->_ldap->base_dn;
        }

        $class = 'Kolab' . $type;
        if (!empty($addfilter)) {
            $filter = $class::filter;
        } else {
            $filter = '(&(' . $addfilter . ')(' . $class::filter . ')';
        }
        $attributes = $class::list_attributes;
        $sort = $class::sort;

        $result = $this->_ldap->getPagedResult($base_dn, $filter, $attributes,
                                               $sort, $perpage, $page);
        $entries = array();
        foreach($result as $attrs) {
            $entries[] =&new $class($this->_ldap, null, $attrs);
        }
        return $entries;
    }

    /**
     * Determine the type of a Kolab object
     *
     * @param string $dn The DN of the object to fetch
     *
     * @return KolabObject The corresponding Kolab object
     */
    function determineType($dn) 
    {
        $oc = $this->_ldap->getObjectClasses($dn);
        // Not a user type?
        if (!in_array('kolabInetOrgPerson')) {
            // Is it a group?
            if (in_array('kolabGroupOfNames')) {
                return KOLAB_OBJECT_GROUP;
            }
            // Is it a shared Folder?
            if (in_array('kolabSharedFolder')) {
                return KOLAB_OBJECT_SHAREDFOLDER;
            }
            return PEAR::raiseError(sprintf(_("Unkown Kolab object type for DN %s."), 
                                            $dn));
        }

       
        $filter = '(member=' . $this->escape($dn) . ')';
        $result = $this->_ldap->search('cn=domain-maintainer,cn=internal,' . 
                                       $this->_ldap->base_dn, $filter);
        if ($this->_ldap->count($result) > 0) {
            return KOLAB_OBJECT_DOMAINMAINTAINER;
        }
        $result = $this->_ldap->search('cn=maintainer,cn=internal,' . 
                                       $this->_ldap->base_dn, $filter);
        if ($this->_ldap->count($result) > 0) {
            return KOLAB_OBJECT_MAINTAINER;
        }
        $result = $this->_ldap->search('cn=admin,cn=internal,' . 
                                       $this->_ldap->base_dn, $filter);
        if ($this->_ldap->count($result) > 0) {
            return KOLAB_OBJECT_ADMIN;
        }

        if (strpos($dn, 'cn=internal') !== false) {
            return KOLAB_OBJECT_ADDRESS;
        }
        
        return KOLAB_OBJECT_USER;
    }

    /**
     * Identify the DN for the first object found using a specified
     * attribute value.
     *
     * @param string $attr  The name of the attribute used for searching
     * @param string $value The desired value of the attribute
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForAttr($attr, $value) {
        $filter = '(&(objectclass=kolabInetOrgPerson)(' . $attr . 
            '=' . $this->_ldap->escape($value) . '))';
        $result = $this->_ldap->search($this->base_dn, $filter, array());
        if (is_a($result, 'PEAR_Error')) {
            return $result;
        }
        return $this->_ldap->dnFromResult($result);
    }
    
    /**
     * Identify the DN for the first object found with the given uid.
     *
     * @param string $uid  Search for objects with this uid
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForUid($uid) {
        return $this->dnForAttr('uid', $uid);
    }

    /**
     * Identify the DN for the first object found with the given mail.
     *
     * @param string $mail  Search for objects with this mail address.
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForMail($mail) {
        return $this->dnForAttr('mail', $mail);
    }

    /**
     * Identify the DN for the first object found with the given uid or mail
     *
     * @param string $id  Search for objects with this uid/mail
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForUidOrMail($id) {
        $dn = $this->dnForAttr('uid', $id);
        if (!$dn) {
            $dn = $this->dnForAttr('mail', $id);
        }
        return $dn;
    }

    /**
     * Identify the DN for the first object found with the given alias.
     *
     * @param string $mail  Search for objects with this mail alias.
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForAlias($mail) {
        return $this->dnForAttr('alias', $mail);
    }

    /**
     * Identify the DN for the first object found with the given mail
     * address or alias.
     *
     * @param string $mail Search for objects with this mail address
     * or alias.
     *
     * @return mixed The DN or a PEAR error
     */
    function dnForMailOrAlias($mail) {
        return $this->_ldap->dnForFilter('(&(objectclass=kolabInetOrgPerson)(|(mail=' . 
                                         $this->_ldap->escape($mail) . ')(alias=' . 
                                         $this->_ldap->escape($mail) . ')))');
    }
};

?>

--- NEW FILE: object.php ---
<?php
/*  
 *  COPYRIGHT
 *  ---------
 *
 *  See ../AUTHORS file
 *
 *
 *  LICENSE
 *  -------
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Revision: 1.1 $
 *
 *  ABOUT
 *  -----
 *
 *  A generic class for Kolab object management.
 *
 */

/** Define the possible Kolab object attributes */
define('KOLAB_ATTR_SN',      'sn');
define('KOLAB_ATTR_CN',      'cn');
define('KOLAB_ATTR_FN',      'fn');
define('KOLAB_ATTR_MAIL',    'mail');
define('KOLAB_ATTR_UID',     'uid');
define('KOLAB_ATTR_DELETED', 'kolabDeleteFlag');

/**
 * This class provides general methods to deal with Kolab objects.
 *
 * $Header: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/object.php,v 1.1 2007/08/22 12:41:09 gunnar Exp $
 *
 * @author  Gunnar Wrobel  <wrobel at pardus.de>
 * @package Kolab_Webadmin
 */
class KolabObject {

    /**
     * Link into the Kolab LDAP db
     *
     * @var KolabLDAP
     */
    var $_ldap;

    /**
     * DN of this object in the Kolab LDAP db
     *
     * @var string
     */
    var $_dn;

    /**
     * The cached LDAP result
     *
     * @var mixed
     */
    var $_cache = false;

    /**
     * May this object log in to the Kolab system?
     *
     * @var boolean
     */
    const login_allowed = false;

    /**
     * The LDAP filter to retrieve this object type
     *
     * @var string
     */
    const filter = '';

    /**
     * Sort using this attribute by default
     *
     * @var string
     */
    const sort = '';

    /**
     * The LDAP attributes fetched for listing
     *
     * @var array
     */
    const list_attributes = array();

    /**
     * All LDAP attributes for this object
     *
     * @var array
     */
    const all_attributes = array();

    /**
     * The attributes supported by this class
     *
     * @var array
     */
    var $_supported_attributes = array();

    /**
     * Initialize the Kolab Object. Provide either the DN or a
     * LDAP search result
     *
     * @param KolabLDAP $ldap   The link into the Kolab LDAP db
     * @param string    $dn     DN of the object
     * @param string    $result LDAP search result for this object
     */
    function KolabObject($ldap, $dn = null, $result = null)
    {
        $this->_ldap = $ldap;
        if (empty($dn)) {
            if (empty($result)) {
                return PEAR::raiseError(_('Specify either the DN or a search result!'));
            }
            $this->_dn = $result['dn'][0];
            $this->_cache = $result;
        } else {
            $this->_dn = $dn;
        }
    }

    /**
     * Read the object into the cache
     */
    function read()
    {
        $this->_cache = $this->_ldap->read($this->_dn,
                                           $this->getAllAttributes());
    }

    /**
     * Get the DN of this object
     *
     * @return string the DN of this object
     */
    function getDn()
    {
        return $this->_dn;
    }

    /**
     * Get the "sn" attribute of this object
     *
     * @return string the "sn" of this object
     */
    function getSn()
    {
        if (!in_array(KOLAB_ATTR_SN, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                    KOLAB_ATTR_SN));
        }
        if (!$this->_cache) {
            $this->read();
        }
        if (isset($this->_cache[KOLAB_ATTR_SN])) {
            return $this->_cache[KOLAB_ATTR_SN][0];
        }
        return '';
    }

    /**
     * Get the "cn" attribute of this object
     *
     * @return string the "cn" of this object
     */
    function getCn()
    {
        if (!in_array(KOLAB_ATTR_CN, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                    KOLAB_ATTR_CN));
        }
        if (!$this->_cache) {
            $this->read();
        }
        if (isset($this->_cache[KOLAB_ATTR_CN])) {
            return $this->_cache[KOLAB_ATTR_CN][0];
        }
        return '';
    }

    /**
     * Get the "first name" attribute of this object
     *
     * @return string the "first name" of this object
     */
    function getFn()
    {
        if (!in_array(KOLAB_ATTR_FN, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                            KOLAB_ATTR_FN));
        }
        if (!$this->_cache) {
            $this->read();
        }
        $sn = '';
        if (isset($this->_cache[KOLAB_ATTR_SN])) {
            $sn = $this->_cache[KOLAB_ATTR_SN];
        }
        $cn = '';
        if (isset($this->_cache[KOLAB_ATTR_CN])) {
            $cn = $this->_cache[KOLAB_ATTR_CN];
        }
        return $this->_ldap->getFirstName($sn, $cn);
    }
    
    /**
     * Get the "mail" attribute of this object
     *
     * @return string the "mail" of this object
     */
    function getMail()
    {
        if (!in_array(KOLAB_ATTR_MAIL, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                    KOLAB_ATTR_MAIL));
        }
        if (!$this->_cache) {
            $this->read();
        }
        if (isset($this->_cache[KOLAB_ATTR_MAIL])) {
            return $this->_cache[KOLAB_ATTR_MAIL][0];
        }
        return '';
    }

    /**
     * Get the "uid" attribute of this object
     *
     * @return string the "uid" of this object
     */
    function getUid()
    {
        if (!in_array(KOLAB_ATTR_UID, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                    KOLAB_ATTR_UID));
        }
        if (!$this->_cache) {
            $this->read();
        }
        if (isset($this->_cache[KOLAB_ATTR_UID])) {
            return $this->_cache[KOLAB_ATTR_UID][0];
        }
        return '';
    }

    /**
     * Get the "deleted" attribute of this object
     *
     * @return string the "deleted" state of this object
     */
    function getDeleted()
    {
        if (!in_array(KOLAB_ATTR_DELETED, $this->_supported_attributes)) {
            return PEAR::raiseError(sprintf(_("Attribute \"%s\" not supported!"),
                                    KOLAB_ATTR_DELETED));
        }
        if (!$this->_cache) {
            $this->read();
        }
        if (isset($this->_cache[KOLAB_ATTR_DELETED])) {
            return true;
        }
        return false;
    }

    /**
     * Get the group of this object
     *
     * @return string the group of this object
     */
    function group()
    {
        return substr(get_class($this), 5);
    }

};

?>

Index: address.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/address.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- address.class.php	22 Aug 2007 06:53:18 -0000	1.2
+++ address.class.php	22 Aug 2007 12:41:09 -0000	1.3
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods to deal with global address book
  * entries for Kolab.
@@ -42,39 +45,45 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabAddress {
+class KolabAddress extends KolabObject {
 
     /**
-     * Return a list of all addresses
+     * The LDAP filter to retrieve this object type
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var string
+     */
+    const filter = '(&(objectclass=inetOrgPerson)(!(uid=*))(sn=*))';
+
+    /**
+     * Sort using this attribute by default
      *
-     * @return array An array of address information
+     * @var string
      */
-    function getAddresses($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
-    {
-        $filter = "(&$addfilter(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array( 'mail', 'sn', 'cn', 
-                                               'kolabDeleteflag' ),
-                                        'sn', $perpage, $page);
-        
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $fn = $this->_ldap->getFirstName($attrs['sn'][0], $attrs['cn'][0]);
-            $entries[] = array( 'dn' => $attrs['dn'][0],
-                                'sn' => $attrs['sn'][0],
-                                'fn' => $fn,
-                                'mail' => $attrs['mail'][0],
-                                'deleted' => $deleted );
-        }
-        return $entries;
-    }
+    const sort = KOLAB_ATTR_SN;
+
+    /**
+     * The LDAP attributes fetched for listing
+     *
+     * @var array
+     */
+    const list_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_FN,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
 
 };
 

Index: administrator.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/administrator.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- administrator.class.php	22 Aug 2007 06:53:18 -0000	1.2
+++ administrator.class.php	22 Aug 2007 12:41:09 -0000	1.3
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods to deal with administrator
  * entries for Kolab.
@@ -42,40 +45,52 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabAdministrator {
+class KolabAdministrator extends KolabObject {
 
     /**
-     * Return a list of all administrators
+     * The LDAP filter to retrieve this object type
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var string
+     */
+    const filter = '(&(cn=*)(objectclass=inetOrgPerson)(uid=*)(sn=*))';
+
+    /**
+     * Sort using this attribute by default
      *
-     * @return array An array of administrator information
+     * @var string
      */
-    function getAdministrators($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
-    {
-        $filter = "(&$addfilter(cn=*)(objectclass=inetOrgPerson)(uid=*)(sn=*))";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array('uid', 'sn', 
-                                              'cn', 'kolabDeleteflag'),
-                                        'sn', $perpage, $page);
-        
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $fn = $this->_ldap->getFirstName($attrs['sn'][0], $attrs['cn'][0]);
-            $entries[] = array( 'dn' => $attrs['dn'][0],
-                                'sn' => $attrs['sn'][0],
-                                'fn' => $fn,
-                                'uid' => $attrs['uid'][0],
-                                'deleted' => $deleted );
-        }
-        return $entries;
-    }
+    const sort = KOLAB_ATTR_SN;
+
+    /**
+     * May this object log in to the Kolab system?
+     *
+     * @var boolean
+     */
+    const login_allowed = true;
 
+    /**
+     * The LDAP attributes fetched for listing
+     *
+     * @var array
+     */
+    const list_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_FN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
 };
 
 /*

Index: auth.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/auth.class.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- auth.class.php	22 Aug 2007 07:44:08 -0000	1.4
+++ auth.class.php	22 Aug 2007 12:41:09 -0000	1.5
@@ -32,148 +32,130 @@
  *
  */
 
-require_once('debug.php');
-require_once('group.class.php');
+/** The Kolab object db */
+require_once('Kolab/Webadmin/db.php');
 
+/**
+ * This class provides authentication utilities for the Kolab server.
+ *
+ * $Header$
+ *
+ * @author  Steffen Hansen <steffen at klaralvdalens-datakonsult.se>
+ * @author  Gunnar Wrobel  <wrobel at pardus.de>
+ * @package Kolab_Webadmin
+ */
 class KolabAuth {
-    function KolabAuth( $ldap, $params = array() ) {
-	    $this->ldap = $ldap;
-	    $this->error_string = false;
-	    $this->params = $params;
-		if( isset( $_GET['logout'] ) || isset( $_POST['logout'] ) ) {
-			$this->logout();
-		}
-	}
 
-	function authenticate() {
-		$this->error_string = false;
-		if( !isset( $this->ldap ) ) {
-			$this->error_string = _("Server error, no ldap object!");
-			return 0;
-		}
-		// Anon. bind first
-		if( !$this->ldap->bind( $this->params['php_dn'],  $this->params['php_pw'] ) ) {
-			$this->error_string = _("Could not bind to LDAP server: ").$this->ldap->error();
-			return 2; 
-		}
-		if( $this->isAuthenticated() ) {
-			$bind_result = $this->ldap->bind( $_SESSION['auth_dn'], $_SESSION['auth_pw'] );
-		} else {
-			$bind_result = false;
-		}
-		if( !$bind_result ) {
-			// Anon. bind first
-			if( !$this->ldap->bind() ) {
-				$this->error_string = _("Could not bind to LDAP server");
-				return 2; 
-			}
-			// User not logged in, check login/password
-			if( isset( $_POST['username'] ) && isset( $_POST['password'] ) ) {
-				$dn = $this->ldap->dnForUid( $_POST['username'] );
-                if (!$dn) {
-					$dn = $this->ldap->dnForMail( $_POST['username'] ); // try mail attribute
-				}
-				if( $dn ) {
-					$auth_user = $this->ldap->uidForDn( $dn );
-					$auth_group = $this->ldap->groupForUid( $auth_user );
-					$tmp_group = ($auth_user=='manager')?'manager':$auth_group;
-					if( !in_array( $tmp_group, $this->params['allow_user_classes'] ) ) {
-						$this->error_string = _("User class '$tmp_group' is denied access");
-						return 2;					  
-					}
-					$bind_result = $this->ldap->bind( $dn, $_POST['password'] );
-					if( $bind_result ) {
-						// All OK!
-						$_SESSION['auth_dn'] = $dn;
-						$_SESSION['auth_user'] = $auth_user;
-						$_SESSION['auth_pw'] = $_POST['password'];
-						$_SESSION['auth_group'] = $auth_group;
-						$_SESSION['remote_ip'] = $_SERVER['REMOTE_ADDR'];
-						return 1;
-					} else {
-						$this->error_string = _("Wrong username or password");
-						return 2; 
-					}
-				} else {
-					$this->error_string = _("Wrong username or password");
-					//$this->error_string = "Dn not found";
-					return 2; 
-				}
-			} else {
-				//$this->error_string = _('Please log in as a valid user');
-				return 2;
-				// noreturn
-			}
-		} else {
-			// All OK, user already logged in
-			return 1;
-		}
-	}
-  
-	function logout() {
-		session_unset();
-		session_destroy();
-		$this->error_string = false;
-	}
+    /**
+     * The connection to the Kolab LDAP server
+     *
+     * @var KolabLDAP
+     */
+    var $_ldap;
 
-	function handleLogin() {
-		if( isset( $_POST['login'] ) ) {
-			$this->authenticate();
-		} else if( isset( $_POST['logout'] ) ) {
-			$this->logout();
-		}
-	}
+    /**
+     * The connection into the Kolab object db
+     *
+     * @var KolabObjectDb
+     */
+    var $_db;
 
-	// FIXME: This requires knowledge that should be external to this library
-// 	function gotoLoginPage() {
-// 		global $topdir;
-// 		$smarty =& new MySmarty();
-// 		$smarty->assign( 'topdir', $topdir );
-// 		$smarty->assign( 'uid', '' );
-// 		$smarty->assign( 'group', '' );
-// 		$smarty->assign( 'page_title', _('Login') );
-// 		$smarty->assign( 'menuitems', array() );
-// 		if( $this->error() ) $smarty->assign( 'errors', array( $this->error() ) );
-// 		$smarty->assign( 'maincontent', 'login.tpl' );
-// 		$smarty->display('page.tpl');
-// 		exit();
-// 	}
+    /**
+     * The current user object
+     *
+     * @var KolabObject
+     */
+    var $_current_user = false;
 
-	function isAuthenticated() {
-		return isset( $_SESSION['auth_dn'] ) && $_SESSION['remote_ip'] == $_SERVER['REMOTE_ADDR'];
-	}
+    function KolabAuth($ldap) {
+        $this->_ldap = $ldap;
+        $this->_db =& new KolabObjectDb($ldap);
+        if( isset($_GET['logout']) || isset($_POST['logout']) ) {
+            $this->logout();
+        }
+    }
 
-	function dn() {
-		if( $this->isAuthenticated() ) return $_SESSION['auth_dn'];
-		else return false;
-	}
+    function authenticate() {
+        $auth = $this->isAuthenticated();
+        if (is_a($auth, 'PEAR_Error')) {
+            return $auth;
+        }
+        if ($auth) {
+            $bind_result = $this->_ldap->bind($_SESSION['auth_dn'], 
+                                              $_SESSION['auth_pw']);
+            if ($bind_result) {
+                return true;
+            } else {
+                unset($_SESSION['auth_dn']);
+                unset($_SESSION['auth_pw']);
+            }
+        }
+            
+        // Anon. bind first
+        if (!$this->_ldap->bind()) {
+            return PEAR::raiseError(sprintf(_("Could not bind to LDAP server: %s"), 
+                                            $this->_ldap->error()));
+        }
 
-	function uid() {
-		if( $this->isAuthenticated() ) return $_SESSION['auth_user'];
-		else return false;
-	}
+        // Check if we got user and pass
+        if (!isset($_POST['username']) || !isset($_POST['password'])) {
+            return false;
+        }
+        
+        $dn = $this->_db->dnForUidOrMail($_POST['username']);
+        if (is_a($dn, 'PEAR_Error')) {
+            return $dn;
+        }
+        if (!$dn) {
+            return PEAR::raiseError(_('Incorrect username or password'));
+        }
+        
+        $user = $this->_db->fetch($dn);
+        if (is_a($user, 'PEAR_Error')) {
+            return $user;
+        }
 
-	function group() {
-		if( $this->isAuthenticated() ) return $_SESSION['auth_group'];
-	}
+        if (!$user->login_allowed) {
+            return PEAR::raiseError(_('User may not log in!'));
+        }
 
-	function password() {
-		if( $this->isAuthenticated() ) {
-			return $_SESSION['auth_pw'];
-		}
-		else return false;
-	}
+        $bind_result = $this->_ldap->bind($dn, $_POST['password']);
+        if (!$bind_result) {
+            return PEAR::raiseError(_('Incorrect username or password.'));
+        }
 
-	function setDn( $dn ) {$_SESSION['auth_dn'] = $dn;}
-	function setUid( $uid ) {$_SESSION['auth_user'] = $uid;}
-	function setPassword( $pw ) {$_SESSION['auth_pw'] = $pw;}
+        // All OK!
+        $_SESSION['auth_dn'] = $dn;
+        $_SESSION['auth_pw'] = $_POST['password'];
+        $_SESSION['remote_ip'] = $_SERVER['REMOTE_ADDR'];
+        $this->_current_user = $user;
 
-	function error() {
-		return $this->error_string;
-	}
+        return $user;
+    }
+  
+    function logout() {
+        session_unset();
+        session_destroy();
+        $this->error_string = false;
+    }
+
+    function isAuthenticated() {
+        if (!isset($_SESSION['auth_dn'])) {
+            return false;
+        }
+        if ($_SESSION['remote_ip'] != $_SERVER['REMOTE_ADDR']) {
+            unset($_SESSION['auth_dn']);
+            unset($_SESSION['auth_pw']);
+            $this->_current_user = false;
+            return PEAR::raiseError(_('Your IP seems to have changed. Please log in again!'));
+        }
+        return true;
+    }
+
+    function getCurrentUser() {
+        return $this->_current_user;
+    }
 
-	var $error_string = false;
-	var $params;
 };
 /*
   Local variables:

Index: domainmaintainer.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/domainmaintainer.class.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- domainmaintainer.class.php	22 Aug 2007 06:53:18 -0000	1.3
+++ domainmaintainer.class.php	22 Aug 2007 12:41:09 -0000	1.4
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods associated to Kolab domain maintainers.
  *
@@ -41,76 +44,59 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabDomainMaintainer {
+class KolabDomainMaintainer extends KolabObject {
 
     /**
-     * The LDAP server connection
+     * The LDAP filter to retrieve this object type
      *
-     * @var KolabLDAP
+     * @var string
      */
-    var $_ldap;
+    const filter = '(&(cn=*)(objectclass=kolabInetOrgPerson)(!(uid=manager))(sn=*))';
 
     /**
-     * The DN of the domain maintainer
+     * Sort using this attribute by default
      *
      * @var string
      */
-    var $_dn;
+    const sort = KOLAB_ATTR_SN;
 
     /**
-     * Return a list of all domain maintainers
+     * May this object log in to the Kolab system?
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var boolean
+     */
+    const login_allowed = true;
+
+    /**
+     * The LDAP attributes fetched for listing
      *
-     * @return array An array of domain maintainer information
+     * @var array
      */
-    function getDomainMaintainers($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
-    {
-        $filter = "(&$addfilter(cn=*)(objectclass=kolabInetOrgPerson)(!(uid=manager))(sn=*))";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array( 'uid', 'sn', 'cn', 
-                                               'kolabDeleteflag' ),
-                                        'sn', $perpage, $page);
-        
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $fn = $this->_ldap->getFirstName($attrs['sn'][0], $attrs['cn'][0]);
-            $dn = $attrs['dn'][0];
-            $dm =& new KolabDomainMaintainer($ldap, $dn);
-            $domains = join(' ', $dm->domains());
-            $entries[] = array( 'dn' => $dn,
-                                'sn' => $attrs['sn'][0],
-                                'fn' => $fn,
-                                'uid' => $attrs['uid'][0],
-                                'domains' => $domains,
-                                'deleted' => $deleted );
-        }
-        return $entries;
-    }
+    const list_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
 
     /**
-     * Initialize the class.
+     * The attributes supported by this class
      *
-     * @param KolabLDAP $ldap Kolab LDAP connection
-     * @param string    $dn   The DN of the domain maintainer
+     * @var array
      */
-    function KolabDomainMaintainer($ldap, $dn)
-    {
-        $this->_ldap = $ldap;
-        $this->_dn   = $dn;
-    }
-    
+    var $_supported_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_FN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
+
     /**
      * Return the domains that this maintainer maintains
      *
      * @return array The domains belonging to this domain maintainer.
      */
-    function domains() {
+    function getDomains() {
         $domains = array();
         $filter = '(member=' . $this->escape($this->_dn) . ')';
         $result = $this->_ldap->search('cn=domains,cn=internal,' . 

Index: group.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/group.class.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- group.class.php	22 Aug 2007 06:53:18 -0000	1.3
+++ group.class.php	22 Aug 2007 12:41:09 -0000	1.4
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods to deal with groups for Kolab.
  *
@@ -41,59 +44,52 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabGroup {
+class KolabGroup extends KolabObject {
 
     /**
-     * Return a list of all groups
+     * The LDAP filter to retrieve this object type
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var string
+     */
+    const filter = '(&(!(cn=domains))(objectclass=kolabGroupOfNames))';
+
+    /**
+     * Sort using this attribute by default
      *
-     * @return array An array of group information
+     * @var string
      */
-    function getGroups($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
-    {
-        $filter = "(&$addfilter(!(cn=domains))(objectclass=kolabGroupOfNames)";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array( 'mail', 'cn', 
-                                               'kolabDeleteflag' ),
-                                        'cn', $perpage, $page);
-        
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $internal = (strpos($attrs['dn'][0], 'cn=internal') !== false);
-            $entries[] = array( 'dn' => $attrs['dn'][0],
-                                'cn' => $attrs['cn'][0],
-                                'internal' => $internal,
-                                'mail' => $attrs['mail'][0],
-                                'deleted' => $deleted );
-        }
-        return $entries;
-    }
+    const sort = KOLAB_ATTR_CN;
 
-    function groupForUid($uid) {
-        $group = false;
-        if (!$this->_bound) {
-            return false;
-        }
-        $dn = $this->dnForUid($uid);
-        if ($dn) {
-            $group = 'user';
-            $filter = '(member='.$this->escape($dn).')';
-            $result = $this->search('cn=domain-maintainer,cn=internal,'.$this->_base_dn, $filter);     
-            if (ldap_count_entries($this->_ldap, $result) > 0) $group = 'domain-maintainer';     
-            $result = $this->search('cn=maintainer,cn=internal,'.$this->_base_dn, $filter);
-            if (ldap_count_entries($this->_ldap, $result) > 0) $group = 'maintainer';
-            $result = $this->search('cn=admin,cn=internal,'.$this->_params["base_dn"], $filter);
-            if (ldap_count_entries($this->_ldap, $result) > 0) $group = 'admin';
-            if ($result) $this->freeSearchResult();
-        }
-        debug("groupForUid($uid) = $group");
-        return $group;
+    /**
+     * The LDAP attributes fetched for listing
+     *
+     * @var array
+     */
+    const list_attributes = array(
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * Is this an internal group?
+     *
+     * @return boolean True if this is an internal group
+     */
+    function getInternal()
+    {
+        return (strpos($this->_dn, 'cn=internal') !== false);
     }
 
 

Index: ldap.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/ldap.class.php,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ldap.class.php	22 Aug 2007 07:44:08 -0000	1.8
+++ ldap.class.php	22 Aug 2007 12:41:09 -0000	1.9
@@ -370,8 +370,8 @@
      * @return mixed An array of attributes if reading succeeds, a
      * PEAR error otherwise
      */
-    function read($dn) {
-        $result = @ldap_read($this->_ldap, $dn, '(objectclass=*)');
+    function read($dn, $attributes = null) {
+        $result = @ldap_read($this->_ldap, $dn, '(objectclass=*)', $attributes);
         if (!$result) {
             return PEAR::raiseError(sprintf(_("LDAP Error: No such object: %s. Error was: %s"),
                                             $dn, $this->error()));
@@ -507,72 +507,6 @@
         return $this->dnFromResult($result);
     }
 
-    /**
-     * Identify the DN for the first object found using a specified
-     * attribute value.
-     *
-     * @param string $attr  The name of the attribute used for searching
-     * @param string $value The desired value of the attribute
-     *
-     * @return mixed The DN or a PEAR error
-     */
-    function dnForAttr($attr, $value) {
-        $filter = '(&(objectclass=kolabInetOrgPerson)(' . $attr . 
-            '=' . $this->escape($value) . '))';
-        $result = $this->search($this->base_dn, $filter, array());
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-        return $this->dnFromResult($result);
-    }
-    
-    /**
-     * Identify the DN for the first object found with the given uid.
-     *
-     * @param string $uid  Search for objects with this uid
-     *
-     * @return mixed The DN or a PEAR error
-     */
-    function dnForUid($uid) {
-        return $this->dnForAttr('uid', $uid);
-    }
-
-    /**
-     * Identify the DN for the first object found with the given mail.
-     *
-     * @param string $mail  Search for objects with this mail address.
-     *
-     * @return mixed The DN or a PEAR error
-     */
-    function dnForMail($mail) {
-        return $this->dnForAttr('mail', $mail);
-    }
-
-    /**
-     * Identify the DN for the first object found with the given alias.
-     *
-     * @param string $mail  Search for objects with this mail alias.
-     *
-     * @return mixed The DN or a PEAR error
-     */
-    function dnForAlias($mail) {
-        return $this->dnForAttr('alias', $mail);
-    }
-
-    /**
-     * Identify the DN for the first object found with the given mail
-     * address or alias.
-     *
-     * @param string $mail Search for objects with this mail address
-     * or alias.
-     *
-     * @return mixed The DN or a PEAR error
-     */
-    function dnForMailOrAlias($mail) {
-        return $this->dnForFilter('(&(objectclass=kolabInetOrgPerson)(|(mail=' . 
-                                  $this->escape($mail) . ')(alias=' . 
-                                  $this->escape($mail) . ')))');
-    }
 
     /**
      * Count the number of occurences of an email address

Index: locale.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/locale.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- locale.php	17 Aug 2007 18:23:31 -0000	1.4
+++ locale.php	22 Aug 2007 12:41:09 -0000	1.5
@@ -45,26 +45,26 @@
  */
 function offered_languages() 
 {
-	return array( 
-		array( 
-			'name' => 'Deutsch',
-			'code' => 'de_DE' ),
-		array( 
-			'name' => 'English',
-			'code' => 'en_US' ),
-		array( 
-			'name' => 'Français',
-			'code' => 'fr_FR' ),
-		array( 
-			'name' => 'Italiano',
-			'code' => 'it_IT' ),
-		array( 
-			'name' => 'Nederlands',
-			'code' => 'nl_NL' ),
-		array( 
-			'name' => 'Español',
-			'code' => 'es_ES' ),
-	);
+    return array( 
+        array( 
+            'name' => 'Deutsch',
+            'code' => 'de_DE' ),
+        array( 
+            'name' => 'English',
+            'code' => 'en_US' ),
+        array( 
+            'name' => 'Français',
+            'code' => 'fr_FR' ),
+        array( 
+            'name' => 'Italiano',
+            'code' => 'it_IT' ),
+        array( 
+            'name' => 'Nederlands',
+            'code' => 'nl_NL' ),
+        array( 
+            'name' => 'Español',
+            'code' => 'es_ES' ),
+    );
 
 }
 
@@ -83,26 +83,26 @@
 {
     // REMEMBER TO UPDATE THIS WHEN ADDING NEW LANGUAGES
     $a = array("de"    => "de_DE",
-			   "de_de" => "de_DE",
-			   "fr"    => "fr_FR",
-			   "fr_fr" => "fr_FR",
-			   "it"    => "it_IT",
-			   "it_it" => "it_IT",
-			   "nl"    => "nl_NL",
-			   "nl_nl" => "nl_NL",
-			   "en"    => "en_US",
-			   "en_gb" => "en_US",
-			   "en_us" => "en_US",
-			   "es"    => "es_ES",
-			   "es_es" => "es_ES");
+               "de_de" => "de_DE",
+               "fr"    => "fr_FR",
+               "fr_fr" => "fr_FR",
+               "it"    => "it_IT",
+               "it_it" => "it_IT",
+               "nl"    => "nl_NL",
+               "nl_nl" => "nl_NL",
+               "en"    => "en_US",
+               "en_gb" => "en_US",
+               "en_us" => "en_US",
+               "es"    => "es_ES",
+               "es_es" => "es_ES");
 
     // Locales must be in the format xx_YY to be recognized by xgettext
     $lang = strtolower(str_replace('-', '_', $lang));
     if( !array_key_exists( $lang, $a ) ) {
-		return false;
-	} else {
-		return $a[$lang];
-	}
+        return false;
+    } else {
+        return $a[$lang];
+    }
 }
 
 /**
@@ -137,27 +137,27 @@
 function getLanguage()
 {
     if(empty($_SESSION["lang"])) {
-	    $acceptList = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
+        $acceptList = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
         if(empty($acceptList)) {
-			$lang = "en";
+            $lang = "en";
         } else {
-			// In case of multiple accept languages, keep the first one
-			$acceptList = explode(",", $acceptList);
-			foreach($acceptList as $l) {
-				$pos = strpos($l, ';' );
-				if( $pos !== false ) {
-				    $l = explode(';',$l);
-					$l = $l[0];
-				}
-				if( $tmp = supported_lang($l) ) {
-				    $lang = $tmp;
-				    break;
-				}
-			}
+            // In case of multiple accept languages, keep the first one
+            $acceptList = explode(",", $acceptList);
+            foreach($acceptList as $l) {
+                $pos = strpos($l, ';' );
+                if( $pos !== false ) {
+                    $l = explode(';',$l);
+                    $l = $l[0];
+                }
+                if( $tmp = supported_lang($l) ) {
+                    $lang = $tmp;
+                    break;
+                }
+            }
+        }
+        if( !$lang ) {
+            $lang = "en";
         }
-		if( !$lang ) {
-			$lang = "en";
-		}
         setLanguage($lang);
     }    
     return supported_lang($_SESSION["lang"]);

Index: maintainer.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/maintainer.class.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- maintainer.class.php	22 Aug 2007 06:53:18 -0000	1.2
+++ maintainer.class.php	22 Aug 2007 12:41:09 -0000	1.3
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods to deal with maintainer
  * entries for Kolab.
@@ -42,39 +45,52 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabMaintainer {
+class KolabMaintainer extends KolabObject {
 
     /**
-     * Return a list of all maintainers
+     * The LDAP filter to retrieve this object type
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var string
+     */
+    const filter = '(&(cn=*)(objectclass=inetOrgPerson)(!(uid=manager))(sn=*))';
+
+    /**
+     * Sort using this attribute by default
      *
-     * @return array An array of maintainer information
+     * @var string
      */
-    function getMaintainers($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
-    {
-        $filter = "(&$addfilter(cn=*)(objectclass=inetOrgPerson)(!(uid=manager))(sn=*))";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array('uid', 'sn', 
-                                              'cn', 'kolabDeleteflag'),
-                                        'sn', $perpage, $page);
-        
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $fn = $this->_ldap->getFirstName($attrs['sn'][0], $attrs['cn'][0]);
-            $entries[] = array( 'dn' => $attrs['dn'][0],
-                                'sn' => $attrs['sn'][0],
-                                'fn' => $fn,
-                                'uid' => $attrs['uid'][0],
-                                'deleted' => $deleted );
-        }
-        return $entries;
-    }
+    const sort = KOLAB_ATTR_SN;
+
+    /**
+     * May this object log in to the Kolab system?
+     *
+     * @var boolean
+     */
+    const login_allowed = true;
+
+    /**
+     * The LDAP attributes fetched for listing
+     *
+     * @var array
+     */
+    const list_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_FN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_DELETED,
+    );
 
 };
 

Index: menu.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/menu.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- menu.php	17 Aug 2007 05:15:44 -0000	1.3
+++ menu.php	22 Aug 2007 12:41:09 -0000	1.4
@@ -32,7 +32,7 @@
  *
  */
 
-function generate_menu($auth, $topdir)
+function generate_menu($user, $topdir)
 {
     $menuitems = array();
 

Index: sharedfolder.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/sharedfolder.class.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sharedfolder.class.php	22 Aug 2007 06:53:18 -0000	1.3
+++ sharedfolder.class.php	22 Aug 2007 12:41:09 -0000	1.4
@@ -32,6 +32,9 @@
  *
  */
 
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
+
 /**
  * This class provides methods to deal with shared folders
  * entries for Kolab.
@@ -42,45 +45,71 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabSharedFolder {
+class KolabSharedFolder extends KolabObject {
 
     /**
-     * Return a list of all shared folders
+     * The LDAP filter to retrieve this object type
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var string
+     */
+    const filter = '(objectclass=kolabSharedFolder)';
+
+    /**
+     * Sort using this attribute by default
      *
-     * @return array An array of shared folder information
+     * @var string
      */
-    function getSharedFolderss($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
+    const sort = KOLAB_ATTR_CN;
+
+    /**
+     * The LDAP attributes fetched for listing
+     *
+     * @var array
+     */
+    const list_attributes = array(
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_DELETED,
+        'kolabFolderType',
+    );
+
+    /**
+     * The attributes supported by this class
+     *
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * Get the folder type
+     *
+     * @return string The type of this shared folder
+     */
+    function getType()
     {
-        $filter = "(&$addfilter(objectclass=kolabSharedFolder))";
-        $result = $ldap->getPagedResult($base_dn, $filter, 
-                                        array('cn', 'kolabDeleteflag',
-                                              'kolabFolderType'),
-                                        'cn', $perpage, $page);
+        if (!$this->_cache) {
+            $this->read();
+        }
+        $type = '';
+        if (isset($this->_cache['kolabFolderType'])) {
+            $type = $this->_cache['kolabFolderType'][0];
+        }
 
-        $type_map = array(''        => _('Unspecified'), 
-                          'mail'    => _('Mails'), 
-                          'task'    => _('Tasks'), 
-                          'journal' => _('Journals'),
-                          'event'   => _('Events'), 
-                          'contact' => _('Contacts'), 
-                          'note'    => _('Notes'));
+        $type_map = array(''        => 'Unspecified', 
+                          'mail'    => 'Mails', 
+                          'task'    => 'Tasks', 
+                          'journal' => 'Journals',
+                          'event'   => 'Events', 
+                          'contact' => 'Contacts', 
+                          'note'    => 'Notes');
         
-        $entries = array();
-        foreach($result as $attrs) {
-            $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-            $fn = $this->_ldap->getFirstName($attrs['sn'][0], $attrs['cn'][0]);
-            $entries[] = array( 'dn'         => $attrs['dn'][0],
-                                'cn'         => $attrs['cn'][0],
-                                'foldertype' => $type_map[$attrs['kolabFolderType'][0]],
-                                'deleted'    => $deleted );
+        if (isset($type_map[$type])) {
+            return _($type_map[$type]);
+        } else {
+            return _($type_map['']);
         }
-        return $entries;
     }
 
     function deleteSharedFolder($dn, $delete_now = false) 

Index: user.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/user.class.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- user.class.php	22 Aug 2007 06:53:18 -0000	1.5
+++ user.class.php	22 Aug 2007 12:41:09 -0000	1.6
@@ -32,8 +32,8 @@
  *
  */
 
-/** Handle input information. */
-require_once('Kolab/Webadmin/form.class.php');
+/** The basic Kolab object definition */
+require_once('Kolab/Webadmin/object.php');
 
 /**
  * This class combines methods common to most pages of the Kolab web
@@ -45,119 +45,98 @@
  * @author  Gunnar Wrobel  <wrobel at pardus.de>
  * @package Kolab_Webadmin
  */
-class KolabUser {
+class KolabUser extends KolabObject {
 
     /**
-     * A link to the object that handles our ldap connection.
+     * The LDAP filter to retrieve this object type
      *
-     * @var KolabLDAP
+     * @var string
      */
-    var $_ldap;
+    const filter = '(&(objectclass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))';
 
     /**
-     * The configuration options for the Kolab web admin
+     * Sort using this attribute by default
      *
-     * @var array
+     * @var string
      */
-    var $_params;
+    const sort = KOLAB_ATTR_SN;
+
+    /**
+     * May this object log in to the Kolab system?
+     *
+     * @var boolean
+     */
+    const login_allowed = true;
 
     /**
      * The possible selections for invitation policies
      *
      * @var array
      */
-    var $invpol = array('ACT_ALWAYS_ACCEPT', 
-                        'ACT_ALWAYS_REJECT', 
-                        'ACT_REJECT_IF_CONFLICTS', 
-                        'ACT_MANUAL_IF_CONFLICTS', 
-                        'ACT_MANUAL' );
+    var $invpol = array(
+        'ACT_ALWAYS_ACCEPT', 
+        'ACT_ALWAYS_REJECT', 
+        'ACT_REJECT_IF_CONFLICTS', 
+        'ACT_MANUAL_IF_CONFLICTS', 
+        'ACT_MANUAL' 
+    );
 
     /**
      * The possible account types
      *
      * @var array
      */
-    var $acctyp = array('', 
-                        'cn=internal,', 
-                        'cn=groups,', 
-                        'cn=resources,');
+    var $acctyp = array(
+        '', 
+        'cn=internal,', 
+        'cn=groups,', 
+        'cn=resources,'
+    );
+
 
     /**
-     * Initialize the users class
-     *
-     * @param KolabLDAP $ldap An object that wraps the ldap connection.
+     * The LDAP attributes fetched for listing
      *
-     * @return KolabUsers The initialized KolabUsers object
+     * @var array
      */
-    function KolabUsers($ldap, $params)
-    {
-        $this->_ldap = $ldap;
-        $this->_params = $params;
-    }
+    const list_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_CN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
 
     /**
-     * Return a list of all users
+     * The attributes supported by this class
      *
-     * @param KolabLDAP $ldap      The connection to the Kolab LDAP filter.
-     * @param string    $base_dn   Base DN for the search
-     * @param string    $addfilter Additional LDAP filter criteria.
-     * @param int       $perpage   Maximal entries per page
-     * @param int       $page      Start with this page
+     * @var array
+     */
+    var $_supported_attributes = array(
+        KOLAB_ATTR_SN,
+        KOLAB_ATTR_FN,
+        KOLAB_ATTR_UID,
+        KOLAB_ATTR_MAIL,
+        KOLAB_ATTR_DELETED,
+    );
+
+    /**
+     * Get the user type
      *
-     * @return array An array of user information
+     * @return string The type of this user
      */
-    function getUsers($ldap, $base_dn, $addfilter = '', $perpage = 50, $page = 1)
+    function getType()
     {
-        // Get all entries & dynamically split the letters with growing entries
-        $entries = array();
-
-        $privmembers = array_merge( 
-            (array)$this->_ldap->groupMembers( "cn=internal,$base_dn", 'admin' ),
-            (array)$this->_ldap->groupMembers( "cn=internal,$base_dn", 'maintainer' ) 
-        );
-
-        $filter = "(&$addfilter(objectclass=kolabInetOrgPerson)(uid=*)(mail=*)(sn=*))";
-        $result = $ldap->search($base_dn, $filter, 
-                                array( 'uid', 'mail', 'sn', 'cn', 
-                                       'kolabDeleteflag' ));
-        
-        if( $result ) {
-
-            $this->_ldap->sort($result, 'sn');
-
-            $ldap_entries = getEntrySection($result, $perpage, $page);
-
-            $entries = array();
-            foreach($ldap_entries as $attrs) {
-                $dn = $attrs['dn'][0];;
-                // skip admins and maintainers
-                if(!array_key_exists($dn, $privmembers)) {
-                    $dncomp = split(',', $dn);
-                    if( in_array('cn=groups',$dncomp) ) {
-                        $type = 'G';
-                    } else if(in_array('cn=resources',$dncomp)) {
-                        $type = 'R';
-                    } else if(in_array('cn=internal',$dncomp)) {
-                        $type = 'I';
-                    } else {
-                        $type = 'U';
-                    }
-                    $deleted = array_key_exists('kolabDeleteflag', $attrs)?$attrs['kolabDeleteflag'][0]:'FALSE';
-                    $a = strlen($sn);
-                    $b = strlen($cn);
-                    $cn = $attrs['cn'][0];
-                    $fn = substr($cn, 0, $b - $a);
-                    $entries[] = array( 'dn' => $dn,
-                                        'sn' => $attrs['sn'][0],
-                                        'fn' => $fn,
-                                        'type' => $type,
-                                        'mail' => $attrs['mail'][0],
-                                        'uid' => $attrs['uid'][0],
-                                        'deleted' => $deleted );
-                }
-            }
+        $dncomp = split(',', $this->_dn);
+        if( in_array('cn=groups',$dncomp) ) {
+            return 'G';
+        } else if(in_array('cn=resources',$dncomp)) {
+            return 'R';
+        } else if(in_array('cn=internal',$dncomp)) {
+            return 'I';
+        } else {
+            return 'U';
         }
-        return $entries;
     }
 
     /**

Index: webadmin.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/webadmin.class.php,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- webadmin.class.php	22 Aug 2007 06:53:18 -0000	1.7
+++ webadmin.class.php	22 Aug 2007 12:41:09 -0000	1.8
@@ -51,14 +51,8 @@
 /** We need some form tools. */
 require_once 'Kolab/Webadmin/form.class.php';
 
-/** Provide access to the Kolab specific objects. */
-require_once 'Kolab/Webadmin/address.class.php';
-require_once 'Kolab/Webadmin/administrator.class.php';
-require_once 'Kolab/Webadmin/domainmaintainer.class.php';
-require_once 'Kolab/Webadmin/group.class.php';
-require_once 'Kolab/Webadmin/maintainer.class.php';
-require_once 'Kolab/Webadmin/sharedfolder.class.php';
-require_once 'Kolab/Webadmin/user.class.php';
+/** Provides handling for the Kolab objects. */
+require_once 'Kolab/Webadmin/object.class.php';
 
 /**
  * This class combines methods common to most pages of the Kolab web
@@ -80,6 +74,13 @@
     var $_ldap;
 
     /**
+     * The handler for the Kolab objects
+     *
+     * @var KolabObjectDb
+     */
+    var $_db;
+
+    /**
      * A link to the object that handles our authentication
      * information.
      *
@@ -109,11 +110,11 @@
     var $_config;
 
     /**
-     * DN of the user currently logged in.
+     * User currently logged in.
      *
-     * @var string
+     * @var KolabObject
      */
-    var $_dn;
+    var $_user;
 
     /**
      * An array of section accessible to the current user.
@@ -147,6 +148,7 @@
                                       $config['base_dn'],
                                       $config['php_dn'],
                                       $config['php_pw']);
+        $this->_db   =& new KolabObjectDb($this->_ldap);
         $this->_auth =& new KolabAuth($this->_ldap, $config);
 
         /* 
@@ -208,18 +210,17 @@
         $authenticated = $this->_auth->authenticate();
 
         // The user is not authenticated
-        if ($authenticated == 0 || $authenticated == 2) {
+        if (!$authenticated || is_a($authenticated, 'PEAR_Error')) {
             $this->assign( 'uid', '' );
             $this->assign( 'group', '' );
             $this->assign( 'menuitems', array() );
             // Show the login page
             $this->assign( 'maincontent', 'login.tpl' );
-            if ($this->_auth->error()) { 
-                $this->assign( 'errors', $this->_auth->error() );
-            }
-            if ($authenticated == 0) {
+            if (is_a($authenticated, 'PEAR_Error')) { 
+                $this->assign( 'errors', $authenticated->getMessage());
                 $this->assign( 'page_title', _('Error') );
-            } else {
+            }
+            if (!$authenticated) {
                 $this->assign( 'page_title', _('Login') );
             }
             // Display and exit
@@ -228,14 +229,13 @@
         }
 
         // User is authenticated
-        $this->_dn = $this->_auth->dn();
-        $this->assign( 'uid', $this->_auth->uid() );
-        $this->assign( 'group', $this->_auth->group() );
+        $this->_user = $authenticated;
 
         // Get the menu the user is able to see
-        $this->_menuitems = generate_menu($this->_auth, $config['topdir']);
+        $this->_menuitems = generate_menu($this->_user, 
+                                          $config['topdir']);
 
-    $this->_config = $config;
+        $this->_config = $config;
     }
 
     /**
@@ -334,43 +334,27 @@
     }
     
     /**
-     * Check if the current user is the site admin.
-     *
-     * @return boolean true if the current user is the site admin
-     */
-    function isAdmin()
-    {
-        return $this->_auth->group() == 'admin';
-    }
-
-    /**
-     * Check if the current user is a maintainer.
+     * Get the DN of the current user
      *
-     * @return boolean true if the current user is a maintainer
+     * @return string The distinguished name of the current user.
      */
-    function isMaintainer()
+    function getCurrentDn()
     {
-        return $this->_auth->group() == 'maintainer';
+        return $this->_user->getDn();
     }
 
+    
     /**
-     * Check if the current user is a domain maintainer.
+     * Check if the current user is member of one of these groups
      *
-     * @return boolean true if the current user is a domain maintainer
-     */
-    function isDomainMaintainer()
-    {
-        return $this->_auth->group() == 'domain-maintainer';
-    }
-
-    /**
-     * Get the DN of the current user
+     * @param array $groups The possible groups
      *
-     * @return string The distinguished name of the current user.
+     * @return boolean Is the current user member in one of these
+     * groups?
      */
-    function getCurrentDn()
+    function hasGroup($groups)
     {
-        return $this->_dn;
+        return (in_array($this->_user->group(), $groups);
     }
 
     /**
@@ -388,19 +372,6 @@
     }
 
     /**
-     * Return a connection to the users class.
-     */
-    function getUsersInterface()
-    {
-        if (empty($this->_users)) {
-            $this->_users =& new KolabUsers( $this->_ldap,
-                                             $this->_dn,
-                                             $this->_config );
-        }
-        return $this->_users;
-    }
-
-    /**
      * Build a LDAP filter for leading characters based on an array.
      *
      * @param string $attr  The attribute to filter on
@@ -539,88 +510,21 @@
         return $domainfilter . ')';
     }
     
-
-    /**
-     * Return the visible users
-     */
-    function getVisibleUsers()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-        $domainfilter = $this->buildDomainFilter();
-
-        return KolabUser::getUsers("$userfilter$domainfilter$alphafilter");
-    }
-   
-    /**
-     * Return the visible addresses
-     */
-    function getVisibleAddresses()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-
-        return KolabAddress::getAddresses("$userfilter$alphafilter");
-    }
-   
-    /**
-     * Return the visible administrators
-     */
-    function getVisibleAdministrators()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-
-        return KolabAdministrator::getAdministrators("$userfilter$alphafilter");
-    }
-   
-    /**
-     * Return the visible maintainers
-     */
-    function getVisibleMaintainers()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-
-        return KolabMaintainer::getMaintainers("$userfilter$alphafilter");
-    }
-   
-    /**
-     * Return the visible domain maintainers
-     */
-    function getVisibleDomainMaintainers()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-
-        return KolabDomainMaintainer::getDomainMaintainers("$userfilter$alphafilter");
-    }
-   
-    /**
-     * Return the visible groups
-     */
-    function getVisibleGroups()
-    {
-        $userfilter   = $this->buildUserFilter();
-        $alphafilter  = $this->buildAlphaFilter();
-        $domainfilter = $this->buildDomainFilter();
-
-        return KolabGroup::getGroups("$userfilter$alphafilter$domainfilter");
-    }
-   
-    /**
-     * Return the visible shared folders
-     */
-    function getVisibleSharedFolders()
+    function listVisible($type)
     {
         $userfilter   = $this->buildUserFilter();
         $alphafilter  = $this->buildAlphaFilter();
-        $domainfilter = $this->buildDomainFilter();
-
-        return KolabSharedFolders::getSharedFolders("$userfilter$alphafilter$domainfilter");
+        if ($type == KOLAB_OBJECT_USER ||
+            $type == KOLAB_OBJECT_GROUP ||
+            $type == KOLAB_OBJECT_SHAREDFOLDER) {
+            $domainfilter = $this->buildDomainFilter();
+        } else {
+            $domainfilter = '';
+        }
+        return $this->_db->list($type, null, $addfilter, 
+                                $this->_config['entries_per_page'],
+                                KolabForm::getRequestVar('page'));
     }
-   
-
 
     /**
      * Run a text through htmlentities.
@@ -645,20 +549,22 @@
     function inMaintainerDomain($dn) {
 
         // both groups have full access
-        if ($this->isMaintainer() || $this->isAdmin()) {
+        if ($this->hasGroup(array(KOLAB_OBJECT_ADMIN,
+                                  KOLAB_OBJECT_MAINTAINER))) {
             return true;
         }
 
         // user may not maintain anything
-        if ($this->isUser()) {
+        if ($this->hasGroup(array(KOLAB_OBJECT_USER))) {
             return false;
         }
   
         // we have a domain maintainer. Get his domains
-        $domains = $this->_ldap->domainsForMaintainerDn($this->_dn);
+        $domains = $this->_user->domains();
 
         // retrieve the mail for the current dn
-        $mail = $this->_ldap->mailForDn($dn);
+        $user = $this->_db->fetch($dn);
+        $mail = $user->getMail();
 
         $ok = false;
 

--- debug.php DELETED ---





More information about the commits mailing list