steffen: server/kolab-resource-handlers/kolab-resource-handlers/resmgr resmgr.conf, 1.2, 1.3 resmgr.php, 1.42, 1.43
cvs at intevation.de
cvs at intevation.de
Fri Oct 29 02:20:22 CEST 2004
Author: steffen
Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr
In directory doto:/tmp/cvs-serv15018/kolab-resource-handlers/kolab-resource-handlers/resmgr
Modified Files:
resmgr.conf resmgr.php
Log Message:
Converted resmgr to use Net_IMAP and made it use the folder-type annotation to discover the primary calendar folder
Index: resmgr.conf
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/resmgr.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- resmgr.conf 13 Jul 2004 01:15:14 -0000 1.2
+++ resmgr.conf 29 Oct 2004 00:20:20 -0000 1.3
@@ -1,4 +1,5 @@
<?php
+// Example conf file for resmgr!
// What is the root directory of our Horde instance?
@define('HORDE_BASE', '/kolab/var/kolab/www/fbview');
@@ -8,7 +9,7 @@
// What is our default mail domain? This is used if any users do not have
// '@domain' specified after their username as part of their email address.
-$params['email_domain'] = 'oberon.co.za';
+$params['email_domain'] = 'example.com';
// Are we using virtual domains with Cyrus?
$params['virtual_domains'] = true;
@@ -17,16 +18,36 @@
// virtual_domains is true, and when using manager accounts.
$params['append_domains'] = false;
+// LDAP data
+// What is the address of the LDAP server address where user objects reside
+$params['ldap_uri'] = 'ldaps://ldap.example.com';
+
+// What is the Base DN of our LDAP database?
+$params['base_dn'] = 'dc=example,dc=com';
+
+// What DN should we use to bind to the LDAP server?
+$params['bind_dn'] = 'cn=nobody,cn=internal,dc=example,dc=com';
+
+// What password should we use with the above DN when binding?
+$params['bind_pw'] = 'xyz';
+
+
// What account should we use to read/write calendar data? This account should
// have access to the calendar mailbox of all resource/group mailboxes.
-//$params['calendar_user'] = 'fb at oberon.co.za';
-//$params['calendar_pass'] = 'fb';
+$params['calendar_user'] = 'calendar@'.$params['email_domain'];
+$params['calendar_pass'] = 'zyx';
+
+// Filename of private key used to decrypt password from LDAP
+$params['priv_key_file'] = '/kolab/etc/kolab/res_priv.pem';
// What is the name of the users' calendar mailbox?
$params['calendar_store'] = 'Calendar';
// Where can we get free/busy information from?
-$params['freebusy_url'] = 'http://oberon/fb2/freebusy/${USER}.vfb';
+$params['freebusy_url'] = 'http://kolab.example.com/freebusy/${USER}.ifb';
+
+// PFB url to trigger creation of pfb
+$params['pfb_trigger_url'] = 'http://@@@fqdnhostname@@@/freebusy/trigger/${USER}/${FOLDER}.xpfb';
// Where are we logging to?
$params['log'] = 'file:/kolab/var/resmgr/resmgr.log'; // File...
@@ -35,20 +56,4 @@
// What level of output should we log? Higher levels give more verbose output.
// One of: RM_LOG_SILENT; RM_LOG_ERROR; RM_LOG_WARN; RM_LOG_INFO or RM_LOG_DEBUG.
$params['log_level'] = RM_LOG_DEBUG;
-
-// Is this script being used for groups? If this is false, the script acts as
-// a plain resource handler.
-// NO LONGER USED: This is now specified through a "-g" command line switch
-// $params['group'] = true;
-
-// What default action should be taken when an event occurs? Can be one of:
-// RM_ACT_ALWAYS_ACCEPT always accept the request
-// RM_ACT_ALWAYS_REJECT always rejects the request
-// RM_ACT_REJECT_IF_CONFLICTS reject if there is a conflict
-//
-// The following are only for groups:
-// RM_ACT_MANUAL_IF_CONFLICTS handle manually if it conflicts
-// RM_ACT_MANUAL always handle manually
-//
-// This is overridden by a "-m" command line switch
-$params['action'] = RM_ACT_REJECT_IF_CONFLICTS;
+?>
\ No newline at end of file
Index: resmgr.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/resmgr.php,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- resmgr.php 28 Oct 2004 00:40:27 -0000 1.42
+++ resmgr.php 29 Oct 2004 00:20:20 -0000 1.43
@@ -41,6 +41,27 @@
// Load our configuration file
$params = array();
require_once '@l_prefix@/etc/resmgr/resmgr.conf';
+require_once 'Net/IMAP.php';
+require_once HORDE_BASE . '/lib/core.php';
+require_once 'Horde/iCalendar.php';
+require_once 'Horde/NLS.php';
+require_once 'Horde/MIME.php';
+require_once 'Horde/MIME/Message.php';
+require_once 'Horde/MIME/Headers.php';
+require_once 'Horde/MIME/Part.php';
+require_once 'Horde/MIME/Structure.php';
+//include_once 'Horde/Kolab.php';
+require_once 'Horde/Text.php';
+
+// Globals
+$imap = NULL;
+$server = '';
+$mailbox = '';
+$calmbox = '';
+$prefix = '';
+$suffix = '';
+$connected = false;
+
function logInit($name = '')
{
@@ -125,7 +146,7 @@
global $imap, $connected;
if (defined($imap) && $imap !== false) {
- @imap_close($imap);
+ $imap->disconnect();
}
$connected = false;
@@ -156,6 +177,7 @@
exit($return);
}
+/*
function testIMAPError()
{
$errors = imap_alerts();
@@ -176,6 +198,7 @@
shutdown();
}
+*/
function init()
{
@@ -480,32 +503,27 @@
function &getFreeBusy() {
global $params;
- return internalGetFreeBusy( $params['ext_freebusy_url']);
+ return internalGetFreeBusy( $params['freebusy_url']);
}
function &triggerFreeBusy() {
global $params;
- return internalGetFreeBusy( $params['xpfb_trigger_url']);
+ return internalGetFreeBusy( $params['pfb_trigger_url']);
}
function &internalGetFreeBusy($url)
{
- global $resource, $params, $ignore;
-
- $url = str_replace('${USER}', urlencode($resource), $url);
- if (!$cache) {
- // We're not caching, so ignore any events with the specified UIDs. This
- // is done to ignore events that are being updated, without actually
- // having to remove the messages from IMAP. This way, if something goes
- // wrong, we still have the original event in tact.
+ global $resource, $params, $calmbox;
- // PENDING(steffen): This cannot work!
- /*foreach ($ignore as $uid) {
- $url .= '&i[]=' . urlencode($uid);
- }*/
+ if( ereg( '/user/[^/].*/(.*)', $calmbox, $regs ) ) {
+ // Folder in INBOX
+ $folder = $regs[1];
+ } else {
+ // Best guess, probably wont work
+ $folder = $calmbox;
}
- //$url .= '&c=' . ($cache ? '1' : '0');
- //myLog("Using f/b URL $url", RM_LOG_DEBUG);
+ $url = str_replace('${USER}', urlencode($resource), $url);
+ $url = str_replace('${FOLDER}', urlencode($folder), $url);
$parsed = parse_url($url);
$parsed['user'] = $params['calendar_user'];
@@ -668,7 +686,7 @@
function imapConnect($inbox = false)
{
- global $resource, $params, $imap, $server, $mailbox, $fullmbox, $prefix, $suffix, $connected;
+ global $resource, $params, $imap, $server, $mailbox, $calmbox, $prefix, $suffix;
// Handle virtual domains
$prefix = $resource;
@@ -692,104 +710,74 @@
//$mailbox = "INBOX/Calendar";
$fullmbox = $server . $mymailbox;
- myLog("Opening connection to $fullmbox for ".$params['calendar_user'], RM_LOG_DEBUG);
- // Open an IMAP connection to the requested users' calendar
- $imap = @imap_open($fullmbox, $params['calendar_user'], $params['calendar_pass'], OP_HALFOPEN);
- testIMAPError();
-
- myLog("Reopening $fullmbox", RM_LOG_DEBUG);
- @imap_reopen($imap, $fullmbox, CL_EXPUNGE);
- $errors = imap_errors();
- if (is_array($errors) && count($errors)) {
- myLog('IMAP Errors from reopen: ' . @join(', ', $errors));
- $must_create = false;
- foreach ($errors as $error) {
- // Why oh why does the IMAP library use text error strings instead
- // of numerical codes?
- if ($error == 'Mailbox does not exist') {
- $must_create = true;
- break;
- }
- }
-
- if ($must_create && !$inbox) {
- // Try create the Calendar folder
- @imap_createmailbox($imap, $fullmbox);
- myLog('IMAP Errors from createmailbox: ' . @join(', ', imap_errors()));
-
- @imap_close($imap);
-
- // Try and set the Kolab folder-type annotation. This shouldn't
- // happen that often so we can justify having this here - it
- // wouldn't be neccessary if the c-client library supported
- // ANNOTATEMORE.
- if ((@include_once 'Net/IMAP.php')) {
- // We should be creating the calendar mailbox using the current
- // resource's credentials, so we rather specify the box as a
- // child of INBOX/ rather than the user/ hierarchy.
- $cal_mbox = 'INBOX/' . $params['calendar_store'];
- $net_imap = &new Net_IMAP($params['server'], 143);
- if (is_a($net_imap, 'PEAR_Error')) {
- myLog('Unable to create Net_IMAP object: ' . $net_imap->getMessage(), RM_LOG_ERROR);
- } else {
- $result = $net_imap->login($params['calendar_user'],
- $params['calendar_pass'], false, false);
- if (is_a($result, 'PEAR_Error')) {
- myLog('Unable to login with the Net_IMAP object: ' . $result->getMessage(),
- RM_LOG_ERROR);
- } else {
- $result = $net_imap->setAnnotation('/vendor/kolab/folder-type',
- array('value.shared' => 'event.default'),
- $cal_mbox);
- if (is_a($result, 'PEAR_Error')) {
- myLog("Unable to set the folder-type annotation on mailbox $mymailbox: "
- . $result->getMessage(), RM_LOG_ERROR);
- }
- }
-
- $net_imap->disconnect();
- }
- }
-
- $imap = @imap_open($fullmbox, $params['calendar_user'], $params['calendar_pass'], OP_HALFOPEN);
- testIMAPError();
-
- $status = @imap_status($imap, $fullmbox, SA_ALL);
- myLog('New folder status: ' . print_r($status, true));
-
- myLog('Trying to reopen calendar box...');
- @imap_reopen($imap, $fullmbox, CL_EXPUNGE);
- testIMAPError();
- }
+ $imap = &new Net_IMAP( $params['server'] );
+ if( PEAR::isError($imap) ) {
+ myLog('Unable to create Net_IMAP object: ' . $imap->getMessage(), RM_LOG_ERROR);
+ return false;
+ }
+ //$imap->setDebug(true);
+ if( PEAR::isError($imap->login($params['calendar_user'], $params['calendar_pass'], true, false)) ) {
+ myLog('Unable to authenticate: ' . $imap->getMessage(), RM_LOG_ERROR);
+ return false;
+ }
+ $mailboxes = $imap->getMailBoxes( "user/$prefix$suffix" );
+ if( PEAR::isError( $mailboxes ) ) {
+ myLog('Unable to get mailbox list: ' . $mailboxes->getMessage(), RM_LOG_ERROR);
+ }
+ $calmbox = false;
+ foreach( $mailboxes as $mailbox ) {
+ $a = $imap->getAnnotation('/vendor/kolab/folder-type',
+ /*array('value.shared' => 'event.default')*/'value.shared',
+ $mailbox);
+ myLog("Annotation for folder $mailbox is ".print_r($a,true), RM_LOG_DEBUG);
+ if( $a == 'event.default' ) {
+ // Found default calendar!
+ $calmbox = $mailbox;
+ break;
+ }
}
- $connected = true;
-}
-
-function imapReopen($mailbox = '')
-{
- global $imap, $server, $mailbox, $fullmbox, $prefix, $suffix, $connected;
-
- // Get our mailbox strings for use in the imap_X functions
- $mymailbox = "user/$prefix/$mailbox$suffix";
- $fullmbox = $server . $mymailbox;
-
- myLog("Repening connection to $fullmbox ($server)", RM_LOG_DEBUG);
+ if( !$calmbox ) {
+ // No default calendar, try to create one
+ $calmbox = "user/$prefix/" . $params['calendar_store'] . "$suffix";
+ $rc = $imap->createMailBox( $calmbox );
+ if( PEAR::isError($rc) ) {
+ myLog('IMAP Errors from createMailBox: ' . $rc->getMessage(), RM_LOG_ERROR );
+ return false;
+ }
+ $rc = $imap->setAnnotation('/vendor/kolab/folder-type',
+ array('value.shared' => 'event.default'),
+ $calmbox);
+ if( PEAR::isError($rc)) {
+ // Non fatal error
+ myLog("Unable to set the folder-type annotation on mailbox $mymailbox: "
+ . $rc->getMessage(), RM_LOG_ERROR);
+ }
+ }
- @imap_reopen($imap, $fullmbox, CL_EXPUNGE);
- testIMAPError();
+ myLog("Selecting $calmbox for ".$params['calendar_user'], RM_LOG_DEBUG);
+ // Open an IMAP connection to the requested users' calendar
+ $rc = $imap->selectMailBox( $calmbox );
+ if( PEAR::isError($rc)) {
+ myLog("Error selecting $calmbox: ".$rc->getMessage(), RM_LOG_ERROR);
+ return false;
+ }
- $connected = true;
+ myLog("Connected to $calmbox, imap object is $imap", RM_LOG_DEBUG);
+ return $imap;
}
function imapAppend($text)
{
- global $imap, $fullmbox;
+ global $imap;
myLog("Appending to $fullmbox", RM_LOG_DEBUG);
- @imap_append($imap, $fullmbox, $text);
- testIMAPError();
+ $rc = $imap->appendMessage($text);
+ if( PEAR::isError( $rc ) ) {
+ myLog("Failed to append message: ".$rc->getMessage(), RM_LOG_ERROR);
+ return false;
+ } else return true;
}
function iCalDate2Kolab($ical_date)
@@ -999,17 +987,6 @@
$params['action'] = RM_ACT_MANUAL;
}
-require_once HORDE_BASE . '/lib/core.php';
-require_once 'Horde/iCalendar.php';
-require_once 'Horde/NLS.php';
-require_once 'Horde/MIME.php';
-require_once 'Horde/MIME/Message.php';
-require_once 'Horde/MIME/Headers.php';
-require_once 'Horde/MIME/Part.php';
-require_once 'Horde/MIME/Structure.php';
-//include_once 'Horde/Kolab.php';
-require_once 'Horde/Text.php';
-
$requestText = '';
// Get our request from stdin
@@ -1050,14 +1027,6 @@
myLog('Event starts on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $dtstart) .
' and ends on ' . strftime('%a, %d %b %Y %H:%M:%S %z', $dtend), RM_LOG_DEBUG);
-$imap = NULL;
-$server = '';
-$mailbox = '';
-$fullmbox = '';
-$prefix = '';
-$suffix = '';
-$connected = false;
-
if ($params['action'] == RM_ACT_ALWAYS_REJECT) {
myLog("Rejecting $method method");
sendITipReply(RM_ITIP_DECLINE);
@@ -1070,17 +1039,26 @@
$is_update = false;
$ignore = array();
-imapConnect();
+$imap = imapConnect();
+$connected = ($imap !== false);
+if( !$connected ) {
+ myLog("Error, could not open calendar folder!", RM_LOG_ERROR);
+ sendSMTP($sender, $resource, $requestText);
+ shutdown(1,'',false);
+}
switch ($method) {
- case 'REQUEST':
+ case 'REQUEST':
if ($params['action'] == RM_ACT_MANUAL) {
myLog("Passing through $method method");
break;
}
// Check if the request is actually an update of an existing event
- $updated_messages = @imap_sort($imap, SORTDATE, 0, SE_UID, 'SUBJECT "' . $uid . '"');
- testIMAPError();
+ $updated_messages = $imap->search('SUBJECT "' . $uid . '"');
+ if( PEAR::isError( $updated_messages ) ) {
+ myLog("Error searching mailbox: ".$updated_messages->getMessage(), RM_LOG_ERROR);
+ $updated_messages = array();
+ }
if (!empty($updated_messages)) {
myLog("Updating message $uid");
$ignore[] = $uid;
@@ -1139,7 +1117,7 @@
}
}
- // At this point there was either no conflict or RM_ACT_ALWAYS_ACCEPT
+ // At this point there was either no conflict or RM_ACT_ALWAYS_ACCEPT
// was specified; either way we add the new event & send an 'ACCEPT'
// iTip reply
@@ -1176,8 +1154,11 @@
);
myLog("Appending message to $fullmbox", RM_LOG_DEBUG);
- @imap_append($imap, $fullmbox, $message);
- testIMAPError();
+ $rc = $imap->appendMessage($message);
+ if( PEAR::isError($rc) ) {
+ myLog("Error appending message: ".$rc->getMessage(), RM_LOG_ERROR);
+ }
+
// Update our status within the iTip request and send the reply
$itip->setAttribute('STATUS', 'CONFIRMED', array(), false);
@@ -1198,7 +1179,7 @@
}
}
- // Re-add all the attendees to the event, using our updates status info
+ // Re-add all the attendees to the event, using our updates status info
$firstatt = array_pop($attendees);
$firstattparams = array_pop($attparams);
$itip->setAttribute('ATTENDEE', $firstatt, $firstattparams, false);
@@ -1210,19 +1191,20 @@
// Delete any old events that we updated
foreach ($updated_messages as $mid) {
- @imap_delete($imap, $mid, FT_UID);
+ $imap->deleteMessages($mid);
}
- @imap_expunge($imap);
+ $imap->expunge();
shutdown(0);
- case 'CANCEL':
+ case 'CANCEL':
myLog("Removing event $uid");
-
- imapConnect();
-
+
// Try to delete the event
- $deleted_messages = @imap_sort($imap, SORTDATE, 0, SE_UID, 'SUBJECT "' . $uid . '"');
- testIMAPError();
+ $deleted_messages = $imap->search('SUBJECT "' . $uid . '"');
+ if( PEAR::isError($deleted_messages) ) {
+ myLog("Error searching mailbox: ".$deleted_messages->getMessage(), RM_LOG_ERROR);
+ $deleted_messages = array();
+ }
if (empty($deleted_messages)) {
myLog("Canceled event $uid is not present in $resource's calendar", RM_LOG_WARN);
$body = sprintf(_("The following event that was canceled is not present in %s's calendar:\r\n\r\n%s"), $resource, $summary);
@@ -1284,9 +1266,9 @@
// Delete the messages from IMAP
foreach ($deleted_messages as $mid) {
- @imap_delete($imap, $mid, FT_UID);
+ $imap->deleteMessages($mid);
}
- @imap_expunge($imap);
+ $imap->expunge();
shutdown(0);
default:
More information about the commits
mailing list