gunnar: server/php-kolab/Kolab_Filter/Filter Filter.php, 1.4, 1.5 Incoming.php, 1.6, 1.7 Resource.php, 1.4, 1.5

cvs at kolab.org cvs at kolab.org
Wed Nov 28 16:37:02 CET 2007


Author: gunnar

Update of /kolabrepository/server/php-kolab/Kolab_Filter/Filter
In directory doto:/tmp/cvs-serv28709/php-kolab/Kolab_Filter/Filter

Modified Files:
	Filter.php Incoming.php Resource.php 
Log Message:
 kolab/issue1313 (resmngr cannot create calendar folder in multidomain setup)

Index: Filter.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Filter.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Filter.php	27 Nov 2007 14:21:15 -0000	1.4
+++ Filter.php	28 Nov 2007 15:36:59 -0000	1.5
@@ -232,7 +232,15 @@
                                      OUT_STDOUT | EX_USAGE);
         }
 
-        $this->_sender = strtolower($options['s']);
+        if (empty($options['s'])) {
+            $sender = '';
+        } else if (is_array($options['s'])) {
+            $sender = $options['s'][0];
+        } else {
+            $sender = $options['s'];
+        }
+
+        $this->_sender = strtolower($sender);
 
         $recipients = $options['r'];
 
@@ -351,13 +359,27 @@
         $msg = $result->getMessage() . $id;
 
         /* Log all errors */
-        $frame = $result->getBacktrace(1);
+        $file = __FILE__;
+        $line = __LINE__;
+        
+        $frames = $result->getBacktrace();
+        if (count($frames) > 1) {
+            $frame = $frames[1];
+        } else if (count($frames) == 1) {
+            $frame = $frames[0];
+        }
+        if (isset($frame['file'])) {
+            $file = $frame['file'];
+        }
+        if (isset($frame['line'])) {
+            $line = $frame['line'];
+        }
 
         /* In debugging mode the errors get delivered to the screen
          * without a time stamp (mainly because of unit testint) 
          */
         if (!$this->_debug) {
-            Horde::logMessage($msg, $frame['file'], $frame['line'], PEAR_LOG_ERR);
+            Horde::logMessage($msg, $file, $line, PEAR_LOG_ERR);
         } else {
             $msg .= ' (Line ' . $frame['line'] . ' in ' . basename($frame['file']) . ")\n";
             fwrite(STDOUT, $msg);

Index: Incoming.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Incoming.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Incoming.php	28 Nov 2007 06:06:12 -0000	1.6
+++ Incoming.php	28 Nov 2007 15:36:59 -0000	1.7
@@ -121,7 +121,7 @@
             foreach ($this->_recipients as $recip) {
                 Horde::logMessage(sprintf(_("Calling resmgr_filter(%s, %s, %s, %s)"),
                                           $this->_fqhostname, $this->_sender,
-                                          $this->_recip, $this->tmpfile), 
+                                          $recip, $this->_tmpfile), __FILE__, __LINE__,
                                   PEAR_LOG_DEBUG);
                 $rc = resmgr_filter($this->_fqhostname, $this->_sender, $recip,
                                     $this->_tmpfile);

Index: Resource.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Filter/Filter/Resource.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Resource.php	28 Nov 2007 06:06:12 -0000	1.4
+++ Resource.php	28 Nov 2007 15:36:59 -0000	1.5
@@ -32,8 +32,6 @@
  *
  */
 
-require_once 'Kolab/Filter/misc.php';
-
 require_once 'Net/IMAP.php';
 require_once 'Horde/iCalendar.php';
 require_once 'Horde/MIME.php';
@@ -42,24 +40,14 @@
 require_once 'Horde/MIME/Part.php';
 require_once 'Horde/MIME/Structure.php';
 
-require_once 'Horde/Text.php';
-
-if (!method_exists('Text', 'wrap')) {
-   require_once 'Horde/String.php';
-}
+require_once 'Horde/String.php';
 
 // Required to be able to use the old Horde framework
 function wrap($text) 
 {
-    if (method_exists('Text', 'wrap')) {
-        return Text::wrap($text, 76, "\n");
-    } else {
-        return String::wrap($text, 76, "\n");
-    }
+    return String::wrap($text, 76, "\n");
 }
 
-require_once 'Kolab/Freebusy/recurrence.class.php';
-
 // What actions we can take when receiving an event request
 define('RM_ACT_ALWAYS_ACCEPT',              1);
 define('RM_ACT_REJECT_IF_CONFLICTS',        2);
@@ -84,35 +72,35 @@
 /* Recurrence implementation for looking for
    conflicts between an event and a freebusy list
 */
-class ResmgrRecurrence extends Recurrence {
-    function ResmgrRecurrence() { 
-        $this->conflict = false;
-    }
+// class ResmgrRecurrence extends Recurrence {
+//     function ResmgrRecurrence() { 
+//         $this->conflict = false;
+//     }
 
-    function setBusy( $start, $end, $duration ) {
-        if( $this->conflict ) return;
-        if( is_null($end) ) $end = $start + $duration;
-        foreach ($this->busyperiods as $busyfrom => $busyto) {
-            if ( in_array(base64_decode($this->extraparams[$busyfrom]['X-UID']), $this->ignore) ||
-                 in_array(base64_decode($this->extraparams[$busyfrom]['X-SID']), $this->ignore) ) {
-                // Ignore
-                continue;
-            }
-            if (($busyfrom >= $start && $busyfrom < $end) || ($start >= $busyfrom && $start < $busyto)) {
-                Horde::logMessage('Request overlaps', __FILE__, __LINE__, PEAR_LOG_DEBUG);
-                $this->conflict = true;
-                break;
-            }
-        }
-    }
+//     function setBusy( $start, $end, $duration ) {
+//         if( $this->conflict ) return;
+//         if( is_null($end) ) $end = $start + $duration;
+//         foreach ($this->busyperiods as $busyfrom => $busyto) {
+//             if ( in_array(base64_decode($this->extraparams[$busyfrom]['X-UID']), $this->ignore) ||
+//                  in_array(base64_decode($this->extraparams[$busyfrom]['X-SID']), $this->ignore) ) {
+//                 // Ignore
+//                 continue;
+//             }
+//             if (($busyfrom >= $start && $busyfrom < $end) || ($start >= $busyfrom && $start < $busyto)) {
+//                 Horde::logMessage('Request overlaps', __FILE__, __LINE__, PEAR_LOG_DEBUG);
+//                 $this->conflict = true;
+//                 break;
+//             }
+//         }
+//     }
 
-    function hasConflict() { return $this->conflict; }
+//     function hasConflict() { return $this->conflict; }
 
-    var $busyperiods;
-    var $extraparams;
-    var $ignore;
-    var $conflict;
-};
+//     var $busyperiods;
+//     var $extraparams;
+//     var $ignore;
+//     var $conflict;
+// };
 
 function imapClose()
 {
@@ -202,7 +190,7 @@
     if (!ldap_bind($ldap, $conf['filter']['bind_dn'], $conf['filter']['bind_pw'])) {
         return PEAR::raiseError(sprintf(_("Unable to contact LDAP server: %s"),
                                         ldap_error($ldap)),
-                                OUT_LOG | ERR_TEMPFAIL);
+                                OUT_LOG | EX_TEMPFAIL);
     }
     
     $result = ldap_search($ldap, $conf['filter']['base_dn'],
@@ -212,7 +200,7 @@
     if (!$result) {
         return PEAR::raiseError(sprintf(_("Unable to perform LDAP search: %s"),
                                         ldap_error($ldap)),
-                                OUT_LOG | ERR_TEMPFAIL);
+                                OUT_LOG | EX_TEMPFAIL);
     }
     
     $entries = ldap_get_entries($ldap, $result);
@@ -227,34 +215,6 @@
     $hs = $entries[0]['kolabhomeserver'][0];
     $actions = $entries[0]['kolabinvitationpolicy'];
 
-    /* Encrypted password are not used anymore...
-     * TODO: Clean this code out when we're sure
-     * we don't want to use it... 
-     */
-    $cleartext = false;
-    /*      
-     $encpw = base64_decode($entries[0]['kolabencryptedpassword'][0]);
-     
-     # Now get private key and decrypt the password
-     $pkd = file_get_contents($conf['filter']['priv_key_file']);
-     $pkey = openssl_pkey_get_private($pkd);
-     if ($pkey === false) {
-     while ($msg = openssl_error_string()) {
-     Horde::logMessage(sprintf(_("Error reading private key: %s"),
-     $msg), __FILE__, __LINE__, PEAR_LOG_WARNING);
-     }
-     
-     if (!openssl_private_decrypt($encpw, $cleartext, $pkey)) {
-     while ($msg = openssl_error_string()) {
-     Horde::logMessage(sprintf(_("Error decrypting password: %s"),
-     $msg), __FILE__, __LINE__, PEAR_LOG_WARNING);
-     ldap_free_result( $result );
-     $cleartext = false;
-     }
-
-     openssl_free_key($pkey);
-    */
-
     $policies = array();
     $defaultpolicy = false;
     foreach( $actions as $action ) {
@@ -301,44 +261,9 @@
 
 
     ldap_close($ldap);
-    return array( 'cn' => $cn, 'homeserver' => $hs, 'password' => $cleartext,
-                  'action' => $action );
+    return array( 'cn' => $cn, 'homeserver' => $hs, 'action' => $action );
 }
 
-function getResourceUid($resource)
-{
-    global $conf;
-
-    // Connect to the LDAP server and retrieve the users' password
-    $ldap = ldap_connect($conf['filter']['ldap_uri']);
-    if (!ldap_bind($ldap, $conf['filter']['bind_dn'], $conf['filter']['bind_pw'])) {
-        Horde::logMessage(sprintf(_("Unable to contact LDAP server: %s"),
-                                  ldap_error($ldap)),
-                          __FILE__, __LINE__, PEAR_LOG_WARNING);
-        return false;
-    }
-
-    $result = ldap_search($ldap, $conf['filter']['base_dn'], "(&(objectClass=kolabInetOrgPerson)(mail=$resource))", array("uid"));
-    if (!$result) {
-        Horde::logMessage(sprintf(_("Unable to perform LDAP search: %s"),
-                                  ldap_error($ldap)),
-                          __FILE__, __LINE__, PEAR_LOG_WARNING);
-        return false;
-    }
-
-    $entries = ldap_get_entries($ldap, $result);
-    if ($entries['count'] != 1) {
-        Horde::logMessage(sprintf(_("%s objects returned for %s"),
-                                  $entries['count'], $resource),
-                          __FILE__, __LINE__, PEAR_LOG_WARNING);
-        return false;
-    }
-
-    $ldap_uid = $entries[0]['uid'][0];
-    ldap_close($ldap);
-    if( $ldap_uid ) return $ldap_uid;
-    else return $resource;
-}
 
 function getRequest($filename)
 {
@@ -485,10 +410,18 @@
     Horde::logMessage(sprintf(_("URL = %s"), $url), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
     $parsed = parse_url($url);
-    $parsed['user'] = urlencode($conf['filter']['calendar_user']);
+
+    list($user, $domain) = split('@', $resource);
+    if (empty($domain)) {
+        $domain = $conf['filter']['email_domain'];
+    }
+    $parsed['user'] = urlencode($conf['filter']['calendar_id'] . '@' . $domain);
     $parsed['pass'] = urlencode($conf['filter']['calendar_pass']);
+
     $url = assembleUri($parsed);
 
+    Horde::logMessage(sprintf(_("URL = %s"), $url), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+
     $text = @file_get_contents($url);
     if ($text == false || empty($text)) {
         $parsed = parse_url($url);
@@ -498,7 +431,8 @@
                                   $resource, $url), 
                           __FILE__, __LINE__, PEAR_LOG_ERR);
         //shutdown(1, "Unable to retrieve free/busy information for $resource");
-        return false;
+        $result = false;
+        return $result;
     }
 
     // If this call is purely to cache the f/b list then we don't need to
@@ -513,7 +447,8 @@
                                       $resource), 
                               __FILE__, __LINE__, PEAR_LOG_ERR);
             //shutdown();
-            return false;
+            $result = false;
+            return $result;
         }
 
         $vfb->simplify();
@@ -527,7 +462,7 @@
     global $organiser, $uid, $sid, $is_update;
 
     Horde::logMessage(sprintf(_("sendITipReply(%s, %s, %s, %s)"), 
-                              $cn, $resource, $itip, $type), 
+                              $cn, $resource, get_class($itip), $type), 
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
     // Build the reply.
@@ -687,6 +622,13 @@
     global $conf, $imap, $server, $mailbox, $calmbox, $prefix, $suffix;
 
     // Handle virtual domains
+    list($user, $domain) = split('@', $resource);
+    if (empty($domain)) {
+        $domain = $conf['filter']['email_domain'];
+    }
+    $calendar_user = $conf['filter']['calendar_id'] . '@' . $domain;
+
+    // Handle virtual domains
     $prefix = $resource;
     $suffix = '';
     if ($conf['filter']['virtual_domains']) {
@@ -709,7 +651,7 @@
     $fullmbox = $server . $mymailbox;
 
     Horde::logMessage(sprintf(_("Logging into %s as user %s to access %s"),
-                              $conf['filter']['imap_server'], $conf['filter']['calendar_user'], $mymailbox),
+                              $conf['filter']['imap_server'], $calendar_user, $mymailbox),
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
 
     $imap = &new Net_IMAP( $conf['filter']['imap_server'] );
@@ -720,7 +662,7 @@
         return false;
     }
     //$imap->setDebug(true);
-    $rc = $imap->login($conf['filter']['calendar_user'], $conf['filter']['calendar_pass'], true, false);
+    $rc = $imap->login($calendar_user, $conf['filter']['calendar_pass'], true, false);
     if( PEAR::isError($rc) ) {
         Horde::logMessage(sprintf(_("Unable to authenticate:  %s"),
                                   $rc->getMessage()),
@@ -781,7 +723,7 @@
     }
 
     Horde::logMessage(sprintf(_("Selecting  %s for %s"),
-                              $calmbox, $conf['filter']['calendar_user']),
+                              $calmbox, $calendar_user),
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
     // Open an IMAP connection to the requested users' calendar
     $rc = $imap->selectMailBox( $calmbox );
@@ -792,8 +734,8 @@
         return false;
     }
 
-    Horde::logMessage(sprintf(_("Connected to %s, imap object is %s"),
-                              $calmbox, $imap),
+    Horde::logMessage(sprintf(_("Successfully connected to %s."),
+                              $calmbox),
                       __FILE__, __LINE__, PEAR_LOG_DEBUG);
     return $imap;
 }
@@ -1194,7 +1136,9 @@
         }
     }
 
-    return array($kolab_xml,$recurrence);
+    $result = array($kolab_xml,$recurrence);
+
+    return $result;
 }
 
 
@@ -1218,14 +1162,6 @@
         // Not the users homeserver, ignore
         return true;
     }
-    if( $ldapdata['password'] === false ) {
-        // No decryptable password, use calendar user
-        $conf['filter']['calendar_uid'] = getResourceUid($resource);  
-    } else {
-        $conf['filter']['calendar_user'] = $resource;
-        $conf['filter']['calendar_uid'] = getResourceUid($resource);
-        $conf['filter']['calendar_pass'] = $ldapdata['password'];
-    }
 
     $cn = $ldapdata['cn'];
     $conf['filter']['action'] = $ldapdata['action'];
@@ -1323,7 +1259,7 @@
     $connected = ($imap !== false);
     if( !$connected ) {
         return PEAR::raiseError(_("Error, could not open calendar folder!"),
-                                OUT_LOG | ERR_TEMPFAIL);
+                                OUT_LOG | EX_TEMPFAIL);
     }
     switch ($method) {
     case 'REQUEST':
@@ -1356,6 +1292,8 @@
         }
         list($kolab_xml,$recurrence) = buildKolabEvent($itip);
 
+        $outofperiod=0;
+
         // Don't even bother checking free/busy info if RM_ACT_ALWAYS_ACCEPT
         // is specified
         if ($conf['filter']['action'] != RM_ACT_ALWAYS_ACCEPT) {
@@ -1373,7 +1311,6 @@
                                       $vfbstart, iCalDate2Kolab($vfbstart), $vfbend, iCalDate2Kolab($vfbend)),
                               __FILE__, __LINE__, PEAR_LOG_DEBUG);
 	
-            $outofperiod=0;
             if ($vfbstart && $dtstart > convert2epoch ($vfbend)) {
                 $outofperiod=1;
             } else {
@@ -1604,7 +1541,7 @@
         if (is_a($status, 'PEAR_Error')) {
             return PEAR::raiseError(sprintf(_("Unable to send cancellation reply:  %s"),
                                             $status->getMessage()),
-                                    OUT_LOG | ERR_TEMPFAIL);
+                                    OUT_LOG | EX_TEMPFAIL);
         } else {
             Horde::logMessage(_("Successfully sent cancellation reply"),
                               __FILE__, __LINE__, PEAR_LOG_INFO);





More information about the commits mailing list