gunnar: server/php-kolab/Kolab_Webadmin/Webadmin auth.class.php, 1.5, 1.6 db.php, 1.2, 1.3 ldap.class.php, 1.10, 1.11 menu.php, 1.4, 1.5 object.php, 1.2, 1.3 webadmin.class.php, 1.9, 1.10

cvs at kolab.org cvs at kolab.org
Wed Aug 22 19:33:25 CEST 2007


Author: gunnar

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

Modified Files:
	auth.class.php db.php ldap.class.php menu.php object.php 
	webadmin.class.php 
Log Message:
Basic listing functionality seems to work.

Index: auth.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/auth.class.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- auth.class.php	22 Aug 2007 12:41:09 -0000	1.5
+++ auth.class.php	22 Aug 2007 17:33:23 -0000	1.6
@@ -80,34 +80,50 @@
         if (is_a($auth, 'PEAR_Error')) {
             return $auth;
         }
+
+        $bind_result = false;
         if ($auth) {
             $bind_result = $this->_ldap->bind($_SESSION['auth_dn'], 
                                               $_SESSION['auth_pw']);
-            if ($bind_result) {
-                return true;
-            } else {
+            if (!$bind_result || is_a($bind_result, 'PEAR_Error')) {
                 unset($_SESSION['auth_dn']);
                 unset($_SESSION['auth_pw']);
+                $this->_current_user = false;
+            } else {
+                $dn = $_SESSION['auth_dn'];
             }
         }
             
-        // Anon. bind first
-        if (!$this->_ldap->bind()) {
-            return PEAR::raiseError(sprintf(_("Could not bind to LDAP server: %s"), 
-                                            $this->_ldap->error()));
-        }
+        if (!$bind_result) {
+            // Anon. bind first
+            if (!$this->_ldap->bind()) {
+                return PEAR::raiseError(sprintf(_("Could not bind to LDAP server: %s"), 
+                                                $this->_ldap->error()));
+            }
 
-        // 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'));
+            // 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'));
+            }
+
+            $bind_result = $this->_ldap->bind($dn, $_POST['password']);
+            if (is_a($bind_result, 'PEAR_Error')) {
+                return $bind_result;
+            }
+            if (!$bind_result) {
+                return PEAR::raiseError(_('Incorrect username or password.'));
+            }
+            $_SESSION['auth_dn'] = $dn;
+            $_SESSION['auth_pw'] = $_POST['password'];
+            $_SESSION['remote_ip'] = $_SERVER['REMOTE_ADDR'];
         }
         
         $user = $this->_db->fetch($dn);
@@ -118,16 +134,6 @@
         if (!$user->login_allowed) {
             return PEAR::raiseError(_('User may not log in!'));
         }
-
-        $bind_result = $this->_ldap->bind($dn, $_POST['password']);
-        if (!$bind_result) {
-            return PEAR::raiseError(_('Incorrect username or password.'));
-        }
-
-        // All OK!
-        $_SESSION['auth_dn'] = $dn;
-        $_SESSION['auth_pw'] = $_POST['password'];
-        $_SESSION['remote_ip'] = $_SERVER['REMOTE_ADDR'];
         $this->_current_user = $user;
 
         return $user;

Index: db.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/db.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- db.php	22 Aug 2007 13:25:00 -0000	1.2
+++ db.php	22 Aug 2007 17:33:23 -0000	1.3
@@ -109,7 +109,7 @@
                 return $type;
             }
         } else {
-            if (!in_array($type, $this->_valid_types)) {
+            if (!in_array($type, $this->valid_types)) {
                 return PEAR::raiseError(sprintf(_("Invalid Kolab object type \"%s\"."), 
                                                 $type));
             }
@@ -134,7 +134,7 @@
      */
     function listObjects($type, $base_dn = null, $addfilter = '', $perpage = 50, $page = 1)
     {
-        if (!in_array($type, $this->_valid_types)) {
+        if (!in_array($type, $this->valid_types)) {
             return PEAR::raiseError(sprintf(_("Invalid Kolab object type \"%s\"."), 
                                             $type));
         }
@@ -145,7 +145,7 @@
 
         $class = 'Kolab' . $type;
         $const = get_class_vars($class);
-        if (!empty($addfilter)) {
+        if (empty($addfilter)) {
             $filter = $const['filter'];
         } else {
             $filter = '(&(' . $addfilter . ')(' . $const['filter'] . ')';
@@ -155,6 +155,9 @@
 
         $result = $this->_ldap->getPagedResult($base_dn, $filter, $attributes,
                                                $sort, $perpage, $page);
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
         $entries = array();
         foreach($result as $attrs) {
             $entries[] =&new $class($this->_ldap, null, $attrs);
@@ -172,8 +175,11 @@
     function determineType($dn) 
     {
         $oc = $this->_ldap->getObjectClasses($dn);
+        if (is_a($oc, 'PEAR_Error')) {
+            return $oc;
+        }
         // Not a user type?
-        if (!in_array('kolabInetOrgPerson')) {
+        if (!in_array('kolabInetOrgPerson', $oc)) {
             // Is it a group?
             if (in_array('kolabGroupOfNames')) {
                 return KOLAB_OBJECT_GROUP;
@@ -187,21 +193,30 @@
         }
 
        
-        $filter = '(member=' . $this->escape($dn) . ')';
-        $result = $this->_ldap->search('cn=domain-maintainer,cn=internal,' . 
+        $filter = '(member=' . $this->_ldap->escape($dn) . ')';
+        $result = $this->_ldap->search('cn=admin,cn=internal,' . 
                                        $this->_ldap->base_dn, $filter);
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
         if ($this->_ldap->count($result) > 0) {
-            return KOLAB_OBJECT_DOMAINMAINTAINER;
+            return KOLAB_OBJECT_ADMINISTRATOR;
         }
         $result = $this->_ldap->search('cn=maintainer,cn=internal,' . 
                                        $this->_ldap->base_dn, $filter);
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
         if ($this->_ldap->count($result) > 0) {
             return KOLAB_OBJECT_MAINTAINER;
         }
-        $result = $this->_ldap->search('cn=admin,cn=internal,' . 
+        $result = $this->_ldap->search('cn=domain-maintainer,cn=internal,' . 
                                        $this->_ldap->base_dn, $filter);
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
         if ($this->_ldap->count($result) > 0) {
-            return KOLAB_OBJECT_ADMIN;
+            return KOLAB_OBJECT_DOMAINMAINTAINER;
         }
 
         if (strpos($dn, 'cn=internal') !== false) {

Index: ldap.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/ldap.class.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ldap.class.php	22 Aug 2007 13:25:00 -0000	1.10
+++ ldap.class.php	22 Aug 2007 17:33:23 -0000	1.11
@@ -263,13 +263,13 @@
      */
     function search($base_dn, 
                     $filter,
-                    $attributes = null,
-                    $attrsonly = null,
-                    $sizelimit = null,
-                    $timelimit = null) {
-        $result = @ldap_search($this->_ldap, $base_dn, $filter, $attributes, 
-                               $attrsonly, $sizelimit, $timelimit);
-        if (!$result) {
+                    $attributes = null) {
+        if (isset($attributes)) {
+            $result = ldap_search($this->_ldap, $base_dn, $filter, $attributes);
+        } else {
+            $result = ldap_search($this->_ldap, $base_dn, $filter);
+        }
+        if (!$result && $this->errno()) {
             return PEAR::raiseError(sprintf(_("LDAP Error: Failed to search using filter %s. Error was: %s"),
                                             $filter, $this->error()));
         }
@@ -348,16 +348,19 @@
     function getPagedResult($base_dn, $filter, $attributes, 
                             $sort, $perpage, $page)
     {
-        $result = $ldap->search($base_dn, $filter, $attributes);
+        $result = $this->search($base_dn, $filter, $attributes);
+        if (is_a($result, 'PEAR_Error')) {
+            return $result;
+        }
 
         if( $result ) {
 
-            $this->_ldap->sort($result, $sort);
+            $this->sort($result, $sort);
 
             $from = ($page - 1) * $perpage;
             $to   = $page * $perpage;
 
-            return getEntrySection($result, $from, $to);
+            return $this->getEntrySection($result, $from, $to);
         }
         return array();
     }
@@ -371,16 +374,20 @@
      * PEAR error otherwise
      */
     function read($dn, $attributes = null) {
-        $result = @ldap_read($this->_ldap, $dn, '(objectclass=*)', $attributes);
+        if (isset($attributes)) {
+            $result = @ldap_read($this->_ldap, $dn, '(objectclass=*)', $attributes);
+        } else {
+            $result = @ldap_read($this->_ldap, $dn, '(objectclass=*)');
+        }
         if (!$result) {
-            return PEAR::raiseError(sprintf(_("LDAP Error: No such object: %s. Error was: %s"),
-                                            $dn, $this->error()));
+            return PEAR::raiseError(sprintf(_("LDAP Error: No such object: %s."),
+                                            $dn));
         }
         $entry = @ldap_first_entry($this->_ldap, $result);
         if (!$entry) {
             ldap_free_result($result);
-            return PEAR::raiseError(sprintf(_("LDAP Error: Empy result for: %s. Error was: %s"),
-                                            $dn, $this->error()));
+            return PEAR::raiseError(sprintf(_("LDAP Error: Empty result for: %s."),
+                                            $dn));
         }
         $ldap_object = ldap_get_attributes($this->_ldap, $entry);
         ldap_free_result($result);
@@ -407,11 +414,15 @@
      */
     function getObjectClasses($dn) {
         $ldap_object = $this->read($dn, array('objectClass'));
+        if (is_a($ldap_object, 'PEAR_Error')) {
+            return $ldap_object;
+        }
         if( !$ldap_object && $this->errno()) {
             return PEAR::raiseError(sprintf(_("LDAP Error: No such dn: %s: %s"), 
                                             $dn, $this->error()));
         }
         unset($ldap_object['count']);
+        unset($ldap_object['objectClass']['count']);
         return $ldap_object['objectClass'];
     }
 

Index: menu.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/menu.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- menu.php	22 Aug 2007 12:41:09 -0000	1.4
+++ menu.php	22 Aug 2007 17:33:23 -0000	1.5
@@ -32,16 +32,19 @@
  *
  */
 
+/** Provides handling for the Kolab objects. */
+require_once 'Kolab/Webadmin/db.php';
+
 function generate_menu($user, $topdir)
 {
     $menuitems = array();
 
-    if( $auth->group() == "admin" || 
-        $auth->group() == "maintainer" || 
-        $auth->group() == 'domain-maintainer' ) {
-        $menuitems['user'] = array( 
+    if(in_array($user->group(), array(KOLAB_OBJECT_ADMINISTRATOR,
+                                      KOLAB_OBJECT_MAINTAINER,
+                                      KOLAB_OBJECT_DOMAINMAINTAINER))) {
+        $menuitems[KOLAB_OBJECT_USER] = array( 
             'name'    => _('Users'),
-            'url'     => $topdir . '/user/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_USER,
             'title'   => _('Manage Email Users'),
             'submenu' => array( 
                 array( 
@@ -50,8 +53,30 @@
                 )
             )
         );
+        $menuitems[KOLAB_OBJECT_SHAREDFOLDER] = array( 
+            'name'    => _('Shared Folder'),
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_SHAREDFOLDER,
+            'title'   => _('Manage Shared Folders'),
+            'submenu' => array( 
+                array( 
+                    'name' => _('Add Shared Folder'),
+                    'url'  => 'sf.php?action=create' 
+                )
+            )
+        );  
+        $menuitems[KOLAB_OBJECT_GROUP] = array( 
+            'name'    => _('Distribution Lists'),
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_GROUP,
+            'title'   => _('Manage Distribution Lists'),
+            'submenu' => array(
+                array( 
+                    'name' => _('Create New List'),
+                    'url'  => 'list.php?action=create' 
+                ) 
+            ) 
+        );
     } else {
-        $menuitems['user'] = array( 
+        $menuitems[KOLAB_OBJECT_USER] = array( 
             'name'    => _('My User Settings'),
             'url'     => $topdir . '/user/user.php?action=modify',
             'title'   => _('My User Settings'),
@@ -69,11 +94,11 @@
             )
         );
     }
-    if( $auth->group() == "admin" || 
-        $auth->group() == "maintainer") {
-        $menuitems['addressbook'] = array( 
+    if(in_array($user->group(), array(KOLAB_OBJECT_ADMINISTRATOR,
+                                      KOLAB_OBJECT_MAINTAINER))) {
+        $menuitems[KOLAB_OBJECT_ADDRESS] = array( 
             'name'    => _('Addressbook'),
-            'url'     => $topdir . '/addressbook/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_ADDRESS,
             'title'   => _('Manage Address Book'),
             'submenu' => array( 
                 array( 
@@ -84,42 +109,10 @@
         );
     }
 
-    if( $auth->group() == "admin" || 
-        $auth->group() == "maintainer" || 
-        $auth->group() == 'domain-maintainer') {
-        $menuitems['sf'] = array( 
-            'name'    => _('Shared Folder'),
-            'url'     => $topdir . '/sharedfolder/',
-            'title'   => _('Manage Shared Folders'),
-            'submenu' => array( 
-                array( 
-                    'name' => _('Add Shared Folder'),
-                    'url'  => 'sf.php?action=create' 
-                )
-            )
-        );  
-    }
-
-    if( $auth->group() == 'admin' || 
-        $auth->group() == 'maintainer' || 
-        $auth->group() == 'domain-maintainer') {
-        $menuitems['distlist'] = array( 
-            'name'    => _('Distribution Lists'),
-            'url'     => $topdir . '/distributionlist/',
-            'title'   => _('Manage Distribution Lists'),
-            'submenu' => array(
-                array( 
-                    'name' => _('Create New List'),
-                    'url'  => 'list.php?action=create' 
-                ) 
-            ) 
-        );
-    }
-
-    if( $auth->group() == 'admin' ) {
-        $menuitems['administrator'] = array( 
+    if(in_array($user->group(), array(KOLAB_OBJECT_ADMINISTRATOR))) {
+        $menuitems[KOLAB_OBJECT_ADMINISTRATOR] = array( 
             'name'    => _('Administrators'),
-            'url'     => $topdir . '/administrator/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_ADMINISTRATOR,
             'title'   => _('Manage Administrators'),
             'submenu' => array(
                 array( 
@@ -128,9 +121,9 @@
                 ) 
             ) 
         );
-        $menuitems['domain-maintainer'] = array( 
+        $menuitems[KOLAB_OBJECT_DOMAINMAINTAINER] = array( 
             'name'    => _('Domain Maintainers'),
-            'url'     => $topdir . '/domainmaintainer/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_DOMAINMAINTAINER,
             'title'   => _('Manage Domain Maintainers'),
             'submenu' => array(
                 array( 
@@ -139,9 +132,9 @@
                 ) 
             ) 
         );
-        $menuitems['maintainer'] = array( 
+        $menuitems[KOLAB_OBJECT_MAINTAINER] = array( 
             'name'    => _('Maintainers'),
-            'url'     => $topdir . '/maintainer/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_MAINTAINER,
             'title'   => _('Manage Maintainers'),
             'submenu' => array(
                 array( 
@@ -150,15 +143,20 @@
                 ) 
             ) 
         );
-    } else if ( $auth->group() == 'maintainer' ) {
-        $mdn = $auth->dn();
-        $menuitems['maintainer'] = array( 
+        $menuitems['service'] = array( 
+            'name'  => _('Services'),
+            'url'   => $topdir.'/service/',
+            'title' => _('Manage Services') 
+        );
+    } else if (in_array($user->group(), array(KOLAB_OBJECT_MAINTAINER))) {
+        $mdn = $user->getDn();
+        $menuitems[KOLAB_OBJECT_MAINTAINER] = array( 
             'name'  => _('Maintainers'),
             'url'   => $topdir . '/maintainer/maintainer.php?action=modify&dn=' . urlencode($mdn),
             'title' => _('Manage Maintainer') );  
-        $menuitems['domain-maintainer'] = array( 
+        $menuitems[KOLAB_OBJECT_DOMAINMAINTAINER] = array( 
             'name'    => _('Domain Maintainers'),
-            'url'     => $topdir . '/domainmaintainer/',
+            'url'     => $topdir . '/list.php?type=' . KOLAB_OBJECT_DOMAINMAINTAINER,
             'title'   => _('Manage Domain Maintainers'),
             'submenu' => array(
                 array( 
@@ -167,20 +165,13 @@
                 ) 
             ) 
         );
-    } else if( $auth->group() == 'domain-maintainer' ) {
+    } else if(in_array($user->group(), array(KOLAB_OBJECT_DOMAINMAINTAINER))) {
         $mdn = $auth->dn();
-        $menuitems['domain-maintainer'] = array( 
+        $menuitems[KOLAB_OBJECT_DOMAINMAINTAINER] = array( 
             'name'  => _('Domain Maintainers'),
             'url'   => $topdir . '/domainmaintainer/domainmaintainer.php?action=modify&dn=' . urlencode($mdn),
             'title' => _('Manage Domain Maintainer') );  
     }
-    if( $auth->group() == 'admin' ) {
-        $menuitems['service'] = array( 
-            'name'  => _('Services'),
-            'url'   => $topdir.'/service/',
-            'title' => _('Manage Services') 
-        );
-    }
 
     $menuitems['about'] = array( 
         'name' => _('About Kolab'),
@@ -199,9 +190,9 @@
                    'url'  => 'kde.php' )
         )
     );
-    if( $auth->group() == 'admin' || 
-        $auth->group() == 'maintainer' || 
-        $auth->group() == 'domain-maintainer') {
+    if(in_array($user->group(), array(KOLAB_OBJECT_ADMINISTRATOR,
+                                      KOLAB_OBJECT_MAINTAINER,
+                                      KOLAB_OBJECT_DOMAINMAINTAINER))) {
         $menuitems['about']['submenu'][] = array( 
             'name' => _('<b>Versions</b>'),
             'url'  => 'versions.php' 

Index: object.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/object.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- object.php	22 Aug 2007 13:25:00 -0000	1.2
+++ object.php	22 Aug 2007 17:33:23 -0000	1.3
@@ -100,13 +100,6 @@
     var $list_attributes = array();
 
     /**
-     * All LDAP attributes for this object
-     *
-     * @var array
-     */
-    var $all_attributes = array();
-
-    /**
      * The attributes supported by this class
      *
      * @var array
@@ -140,8 +133,7 @@
      */
     function read()
     {
-        $this->_cache = $this->_ldap->read($this->_dn,
-                                           $this->getAllAttributes());
+        $this->_cache = $this->_ldap->read($this->_dn);
     }
 
     /**

Index: webadmin.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Webadmin/Webadmin/webadmin.class.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- webadmin.class.php	22 Aug 2007 13:25:00 -0000	1.9
+++ webadmin.class.php	22 Aug 2007 17:33:23 -0000	1.10
@@ -217,19 +217,21 @@
             // Show the login page
             $this->assign( 'maincontent', 'login.tpl' );
             if (is_a($authenticated, 'PEAR_Error')) { 
-                $this->assign( 'errors', $authenticated->getMessage());
+                $this->assign( 'errors', array($authenticated->getMessage()));
                 $this->assign( 'page_title', _('Error') );
             }
             if (!$authenticated) {
                 $this->assign( 'page_title', _('Login') );
             }
             // Display and exit
-            $this->display('page.tpl');
+            $this->render();
             exit();
         }
 
         // User is authenticated
         $this->_user = $authenticated;
+        $this->assign( 'uid', $this->_user->getUid() );
+        $this->assign( 'group', $this->_user->group() );
 
         // Get the menu the user is able to see
         $this->_menuitems = generate_menu($this->_user, 
@@ -397,14 +399,14 @@
      */
     function buildAlphaFilter($attr = 'sn')
     {
-        if ($this->_params['alpha_filter_type'] == 'none') {
+        if ($this->_config['alpha_filter_type'] == 'none') {
             return '';
         }
 
         $alphagroup = KolabForm::getRequestVar('alphagroup');
 
 
-        if ($this->_params['alpha_filter_type'] == 'group') {
+        if ($this->_config['alpha_filter_type'] == 'group') {
             switch( $alphagroup ) {
             case 'a': 
                 return $this->alphaFromArray($attr, array('a', 'b', 'c', 'd', 'e', 'f'));
@@ -451,7 +453,7 @@
      */
     function buildUserFilter()
     {
-        if (!$this->_params['allow_user_filter']) {
+        if (!$this->_config['allow_user_filter']) {
             return '';
         }
 
@@ -493,7 +495,7 @@
      */
     function buildDomainFilter()
     {
-        if (!$this->isDomainMaintainer()) {
+        if (!$this->hasGroup(array(KOLAB_OBJECT_DOMAINMAINTAINER))) {
             return '';
         }
 
@@ -520,6 +522,10 @@
             $domainfilter = $this->buildDomainFilter();
         } else {
             $domainfilter = '';
+        }
+	$addfilter = $userfilter . $alphafilter . $domainfilter;
+        if (!empty($addfilter)) {
+            $addfilter = '(&' . $addfilter . ')';
         }
         return $this->_db->listObjects($type, null, $addfilter, 
                                        $this->_config['entries_per_page'],





More information about the commits mailing list