[Svn] r2976 - in trunk/roundcubemail: . config program/include

trac at roundcube.net trac at roundcube.net
Mon Sep 21 13:50:53 CEST 2009


Author: alec
Date: 2009-09-21 06:50:53 -0500 (Mon, 21 Sep 2009)
New Revision: 2976

Modified:
   trunk/roundcubemail/CHANGELOG
   trunk/roundcubemail/config/main.inc.php.dist
   trunk/roundcubemail/program/include/rcmail.php
   trunk/roundcubemail/program/include/rcube_ldap.php
Log:
- Added 'ldap_debug' option + small change to not rely on rcube_config inside rcube_ldap class


Modified: trunk/roundcubemail/CHANGELOG
===================================================================
--- trunk/roundcubemail/CHANGELOG	2009-09-20 19:37:40 UTC (rev 2975)
+++ trunk/roundcubemail/CHANGELOG	2009-09-21 11:50:53 UTC (rev 2976)
@@ -1,6 +1,7 @@
 CHANGELOG RoundCube Webmail
 ===========================
 
+- Added 'ldap_debug' option
 - Fix "Empty startup greeting" bug (#1486085)
 - Fix setting user name in 'new_user_identity' plugin (#1486137)
 - Fix incorrect count of new messages in folder list when using multiple IMAP clients (#1485995)

Modified: trunk/roundcubemail/config/main.inc.php.dist
===================================================================
--- trunk/roundcubemail/config/main.inc.php.dist	2009-09-20 19:37:40 UTC (rev 2975)
+++ trunk/roundcubemail/config/main.inc.php.dist	2009-09-21 11:50:53 UTC (rev 2976)
@@ -130,6 +130,9 @@
 // Log IMAP conversation to <log_dir>/imap or to syslog
 $rcmail_config['imap_debug'] = false;
 
+// Log LDAP conversation to <log_dir>/ldap or to syslog
+$rcmail_config['ldap_debug'] = false;
+
 // Log SMTP conversation to <log_dir>/smtp or to syslog
 $rcmail_config['smtp_debug'] = false;
 

Modified: trunk/roundcubemail/program/include/rcmail.php
===================================================================
--- trunk/roundcubemail/program/include/rcmail.php	2009-09-20 19:37:40 UTC (rev 2975)
+++ trunk/roundcubemail/program/include/rcmail.php	2009-09-21 11:50:53 UTC (rev 2976)
@@ -266,7 +266,7 @@
       $contacts = $plugin['instance'];
     }
     else if ($id && $ldap_config[$id]) {
-      $contacts = new rcube_ldap($ldap_config[$id]);
+      $contacts = new rcube_ldap($ldap_config[$id], $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host']));
     }
     else if ($id === '0') {
       $contacts = new rcube_contacts($this->db, $this->user->ID);
@@ -275,7 +275,7 @@
       // Use the first writable LDAP address book.
       foreach ($ldap_config as $id => $prop) {
         if (!$writeable || $prop['writable']) {
-          $contacts = new rcube_ldap($prop);
+          $contacts = new rcube_ldap($prop, $this->config->get('ldap_debug'), $this->config->mail_domain($_SESSION['imap_host']));
           break;
         }
       }

Modified: trunk/roundcubemail/program/include/rcube_ldap.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_ldap.php	2009-09-20 19:37:40 UTC (rev 2975)
+++ trunk/roundcubemail/program/include/rcube_ldap.php	2009-09-21 11:50:53 UTC (rev 2976)
@@ -34,6 +34,8 @@
   var $result = null;
   var $ldap_result = null;
   var $sort_col = '';
+  var $mail_domain = '';
+  var $debug = false;
   
   /** public properties */
   var $primary_key = 'ID';
@@ -46,10 +48,12 @@
   /**
    * Object constructor
    *
-   * @param array LDAP connection properties
+   * @param array 	LDAP connection properties
+   * @param boolean 	Enables debug mode
+   * @param string 	Current user mail domain name
    * @param integer User-ID
    */
-  function __construct($p)
+  function __construct($p, $debug=false, $mail_domain=NULL)
   {
     $this->prop = $p;
 
@@ -65,6 +69,8 @@
       $this->prop['required_fields'][$key] = $this->_attr_name(strtolower($val));
 
     $this->sort_col = $p['sort'];
+    $this->debug = $debug;
+    $this->mail_domain = $mail_domain;
 
     $this->connect();
   }
@@ -91,17 +97,22 @@
 
     foreach ($this->prop['hosts'] as $host)
     {
+      $this->_debug("C: Connect [$host".($this->prop['port'] ? ':'.$this->prop['port'] : '')."]");
+
       if ($lc = @ldap_connect($host, $this->prop['port']))
       {
         if ($this->prop['use_tls']===true)
           if (!ldap_start_tls($lc))
             continue;
 
+        $this->_debug("S: OK");
+
         ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $this->prop['ldap_version']);
         $this->prop['host'] = $host;
         $this->conn = $lc;
         break;
       }
+      $this->_debug("S: NOT OK");
     }
     
     if (is_resource($this->conn))
@@ -152,10 +163,15 @@
       return false;
     }
     
+    $this->_debug("C: Bind [dn: $dn] [pass: $pass]");
+    
     if (@ldap_bind($this->conn, $dn, $pass)) {
+      $this->_debug("S: OK");
       return true;
     }
 
+    $this->_debug("S: ".ldap_error($this->conn));
+
     raise_error(array(
         'code' => ldap_errno($this->conn),
         'type' => 'ldap',
@@ -173,6 +189,7 @@
   {
     if ($this->conn)
     {
+      $this->_debug("C: Close");
       ldap_unbind($this->conn);
       $this->conn = null;
     }
@@ -388,11 +405,17 @@
     $res = null;
     if ($this->conn && $dn)
     {
+      $this->_debug("C: Read [dn: ".base64_decode($dn)."] [(objectclass=*)]");
+    
       if ($this->ldap_result = @ldap_read($this->conn, base64_decode($dn), '(objectclass=*)', array_values($this->fieldmap)))
         $entry = ldap_first_entry($this->conn, $this->ldap_result);
+      else
+        $this->_debug("S: ".ldap_error($this->conn));
 
       if ($entry && ($rec = ldap_get_attributes($this->conn, $entry)))
       {
+        $this->_debug("S: OK");
+
         $rec = array_change_key_case($rec, CASE_LOWER);
 
         // Add in the dn for the entry.
@@ -437,11 +460,17 @@
 
     // Build the new entries DN.
     $dn = $this->prop['LDAP_rdn'].'='.$newentry[$this->prop['LDAP_rdn']].','.$this->prop['base_dn'];
+
+    $this->_debug("C: Add [dn: $dn]: ".print_r($newentry, true));
+
     $res = ldap_add($this->conn, $dn, $newentry);
     if ($res === FALSE) {
+      $this->_debug("S: ".ldap_error($this->conn));
       return false;
     } // end if
 
+    $this->_debug("S: OK");
+
     return base64_encode($dn);
   }
   
@@ -492,8 +521,12 @@
     // Update the entry as required.
     if (!empty($deletedata)) {
       // Delete the fields.
-      if (!ldap_mod_del($this->conn, $dn, $deletedata))
+      $this->_debug("C: Delete [dn: $dn]: ".print_r($deletedata, true));
+      if (!ldap_mod_del($this->conn, $dn, $deletedata)) {
+        $this->_debug("S: ".ldap_error($this->conn));
         return false;
+      }
+      $this->_debug("S: OK");
     } // end if
 
     if (!empty($replacedata)) {
@@ -507,21 +540,33 @@
       }
       // Replace the fields.
       if (!empty($replacedata)) {
-        if (!ldap_mod_replace($this->conn, $dn, $replacedata))
+        $this->_debug("C: Replace [dn: $dn]: ".print_r($replacedata, true));
+        if (!ldap_mod_replace($this->conn, $dn, $replacedata)) {
+          $this->_debug("S: ".ldap_error($this->conn));
           return false;
+	}
+        $this->_debug("S: OK");
       } // end if
     } // end if
 
     if (!empty($newdata)) {
       // Add the fields.
-      if (!ldap_mod_add($this->conn, $dn, $newdata))
+      $this->_debug("C: Add [dn: $dn]: ".print_r($newdata, true));
+      if (!ldap_mod_add($this->conn, $dn, $newdata)) {
+        $this->_debug("S: ".ldap_error($this->conn));
         return false;
+      }
+      $this->_debug("S: OK");
     } // end if
 
     // Handle RDN change
     if (!empty($newrdn)) {
-      if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE))
+      $this->_debug("C: Rename [dn: $dn] [dn: $newrdn]");
+      if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) {
+        $this->_debug("S: ".ldap_error($this->conn));
         return base64_encode($newdn);
+      }
+      $this->_debug("S: OK");
     }
 
     return true;
@@ -543,11 +588,14 @@
 
     foreach ($dns as $id) {
       $dn = base64_decode($id);
+      $this->_debug("C: Delete [dn: $dn]");
       // Delete the record.
       $res = ldap_delete($this->conn, $dn);
       if ($res === FALSE) {
+        $this->_debug("S: ".ldap_error($this->conn));
         return false;
       } // end if
+      $this->_debug("S: OK");
     } // end foreach
 
     return count($dns);
@@ -566,8 +614,13 @@
       $filter = $this->filter ? $this->filter : '(objectclass=*)';
       $function = $this->prop['scope'] == 'sub' ? 'ldap_search' : ($this->prop['scope'] == 'base' ? 'ldap_read' : 'ldap_list');
 
-      if ($this->ldap_result = @$function($this->conn, $this->prop['base_dn'], $filter, array_values($this->fieldmap), 0, 0))
+      $this->_debug("C: Search [".$filter."]");
+
+      if ($this->ldap_result = @$function($this->conn, $this->prop['base_dn'], $filter, array_values($this->fieldmap), 0, 0)) {
+        $this->_debug("S: ".ldap_count_entries($this->conn, $this->ldap_result)." record(s)");
         return true;
+      } else
+        $this->_debug("S: ".ldap_error($this->conn));
     }
     
     return false;
@@ -589,8 +642,8 @@
     foreach ($this->fieldmap as $rf => $lf)
     {
       if ($rec[$lf]['count']) {
-        if ($rf == 'email' && !strpos($rec[$lf][0], '@'))
-          $out[$rf] = sprintf('%s@%s', $rec[$lf][0] , $RCMAIL->config->mail_domain($_SESSION['imap_host']));
+        if ($rf == 'email' && $mail_domain && !strpos($rec[$lf][0], '@'))
+          $out[$rf] = sprintf('%s@%s', $rec[$lf][0], $this->mail_domain);
         else
           $out[$rf] = $rec[$lf][0];
       }
@@ -627,6 +680,16 @@
 
 
   /**
+   * @access private
+   */
+  private function _debug($str)
+  {
+    if ($this->debug)
+      write_log('ldap', $str);
+  }
+  
+
+  /**
    * @static
    */
   function quote_string($str)

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list