gunnar: server/kolab-freebusy/freebusy config.php, 1.1, 1.2 freebusy.php, 1.1, 1.2 pfb.php, 1.1, 1.2
cvs at kolab.org
cvs at kolab.org
Wed Aug 8 15:11:24 CEST 2007
Author: gunnar
Update of /kolabrepository/server/kolab-freebusy/freebusy
In directory doto:/tmp/cvs-serv16738/freebusy
Modified Files:
config.php freebusy.php pfb.php
Log Message:
Some style cleanup moving this closer to Horde code style
Index: config.php
===================================================================
RCS file: /kolabrepository/server/kolab-freebusy/freebusy/config.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- config.php 8 Aug 2007 09:47:29 -0000 1.1
+++ config.php 8 Aug 2007 13:11:22 -0000 1.2
@@ -1,5 +1,39 @@
<?php
+/*
+ * COPYRIGHT
+ * ---------
+ *
+ * See docs/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$
+ *
+ * ABOUT
+ * -----
+ *
+ * This file provides configuration settings for both the
+ * freebusy.php and the pfb.php scripts.
+ *
+ */
+
// Kolab prefix
$params['kolab_prefix'] = '/kolab';
@@ -110,7 +144,7 @@
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// If you modify this file, please do not forget to modify both the
-// template and the source file in kolab-resource-handler.
+// template in kolabd and the source file in kolab-freebusy
//
// In order to check if both are in sync:
//
Index: freebusy.php
===================================================================
RCS file: /kolabrepository/server/kolab-freebusy/freebusy/freebusy.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- freebusy.php 8 Aug 2007 09:47:29 -0000 1.1
+++ freebusy.php 8 Aug 2007 13:11:22 -0000 1.2
@@ -25,14 +25,24 @@
*
* $Revision$
*
+ * ABOUT
+ * -----
+ *
+ * This script displays a users free/busy information.
+ *
*/
require_once('config.php');
require_once('Kolab/Freebusy/freebusycache.class.php');
require_once('Kolab/Freebusy/freebusycollector.class.php');
-if ( empty($params['ldap_classname_suffix'])) $params['ldap_classname_suffix'] = '';
-require_once('Kolab/Freebusy/freebusyldap'.$params['ldap_classname_suffix'].'.class.php');
+if (empty($params['ldap_classname_suffix'])) {
+ $params['ldap_classname_suffix'] = '';
+ }
+
+require_once('Kolab/Freebusy/freebusyldap'
+ . $params['ldap_classname_suffix']
+ . '.class.php');
require_once('Kolab/Freebusy/misc.php');
@@ -44,42 +54,47 @@
$req_cache = false;
$req_extended = false;
-if ( !empty($_REQUEST['cache'])) $req_cache = (bool)$_REQUEST['cache'];
-if ( !empty($_REQUEST['extended'])) $req_extended = (bool)$_REQUEST['extended'];
+if (!empty($_REQUEST['cache'])) {
+ $req_cache = (bool)$_REQUEST['cache'];
+ }
-myLog("---FreeBusy Script starting (".$_SERVER['REQUEST_URI'].")---", RM_LOG_DEBUG );
+if (!empty($_REQUEST['extended'])) {
+ $req_extended = (bool)$_REQUEST['extended'];
+ }
+
+myLog("---FreeBusy Script starting (" . $_SERVER['REQUEST_URI'] . ")---", RM_LOG_DEBUG );
myLog("user=$user, imapuser=$imapuser, req_cache=$req_cache, req_extended=$req_extended", RM_LOG_DEBUG );
$ldap =& new FreeBusyLDAP( $params['ldap_uri'], $params['base_dn'] );
if( !$ldap->bind( $params['bind_dn'], $params['bind_pw'] ) ) {
- notFound( "Bind failed: ".$ldap->error() );
- exit;
-}
+ notFound( "Bind failed: ".$ldap->error() );
+ exit;
+ }
$imapuser = $ldap->mailForUid( $imapuser );
$user = $ldap->mailForUidOrAlias( $user );
$homeserver = $ldap->homeServer( $user );
if( $homeserver === false ) {
- notFound("Resource ".$_SERVER['REQUEST_URI']." (user=$user, req_extended=$req_extended, req_cache=$req_cache) not found");
-}
+ notFound("Resource " .$_SERVER['REQUEST_URI'] . " (user=$user, req_extended=$req_extended, req_cache=$req_cache) not found");
+ }
if( $homeserver != $params['server'] ) {
- $redirect = 'https://'.$homeserver . $_SERVER['REQUEST_URI'];
- if ($params['redirect']) {
- header("Location: $redirect");
- } else {
- header("X-Redirect-To: $redirect");
- $redirect = 'https://' . urlencode($_SERVER['PHP_AUTH_USER']) . ':'
- . urlencode($_SERVER['PHP_AUTH_PW']) . '@' . $homeserver
- . $_SERVER['REQUEST_URI'];
- if (!@readfile($redirect)) {
- unauthorized("Unable to read free/busy information from ".removePassword($redirect));
+ $redirect = 'https://' . $homeserver . $_SERVER['REQUEST_URI'];
+ if ($params['redirect']) {
+ header("Location: $redirect");
+ } else {
+ header("X-Redirect-To: $redirect");
+ $redirect = 'https://' . urlencode($_SERVER['PHP_AUTH_USER']) . ':'
+ . urlencode($_SERVER['PHP_AUTH_PW']) . '@' . $homeserver
+ . $_SERVER['REQUEST_URI'];
+ if (!@readfile($redirect)) {
+ unauthorized("Unable to read free/busy information from " . removePassword($redirect));
+ }
}
- }
- shutdown();
- exit;
-}
+ shutdown();
+ exit;
+ }
$user = strtolower($user);
@@ -89,40 +104,43 @@
$groups = $ldap->distlists( $ldap->dn( $user ) );
for( $i = 0; $i < count($groups); $i++ ) {
- $groups[$i] = $groups[$i].'@'.$params['email_domain'];
-}
+ $groups[$i] = $groups[$i].'@'.$params['email_domain'];
+ }
$pfbs = $cache->findAll( $user, $groups );
$ts = 0;
if( $pfbs === false ) {
- notFound($pfb->error);
-}
+ notFound($pfb->error);
+ }
//myLog("Found pfbs: ".join(",",$pfbs)." for $user",RM_LOG_DEBUG);
if( $req_extended ) {
- // Get accessing users groups
- $imapgroups = $ldap->distlists( $ldap->dn( $imapuser ) );
-}
+ // Get accessing users groups
+ $imapgroups = $ldap->distlists( $ldap->dn( $imapuser ) );
+ }
foreach( $pfbs as $pfb ) {
- $fb = $cache->load( $pfb, $ts2, $acl );
- if( $fb ) myLog("Found fb for $pfb", RM_LOG_DEBUG);
- else myLog("No fb found for $pfb", RM_LOG_DEBUG);
- if( $acl && $req_extended ) {
- $r = $cache->getRights( $acl, $imapuser, $imapgroups );
- if( !$fb || !array_key_exists( 'r', $r ) ) {
- $cache->extended = false; // HACK!
- $fb = $cache->load( $pfb, $ts2, $acl );
- $cache->extended = true;
- myLog("Falling back to non-extended fb", RM_LOG_DEBUG );
+ $fb = $cache->load( $pfb, $ts2, $acl );
+ if( $fb ) {
+ myLog("Found fb for $pfb", RM_LOG_DEBUG);
+ } else {
+ myLog("No fb found for $pfb", RM_LOG_DEBUG);
}
- }
- $ts = max( $ts, $ts2 );
- if( $fb ) {
- if( $collector->addFreebusy( $fb ) == FB_TOO_OLD ) {
- $cache->delete( $pfb );
+ if( $acl && $req_extended ) {
+ $r = $cache->getRights( $acl, $imapuser, $imapgroups );
+ if( !$fb || !array_key_exists( 'r', $r ) ) {
+ $cache->extended = false; // HACK!
+ $fb = $cache->load( $pfb, $ts2, $acl );
+ $cache->extended = true;
+ myLog("Falling back to non-extended fb", RM_LOG_DEBUG );
+ }
+ }
+ $ts = max( $ts, $ts2 );
+ if( $fb ) {
+ if( $collector->addFreebusy( $fb ) == FB_TOO_OLD ) {
+ $cache->delete( $pfb );
+ }
}
- }
}
$vfb = $collector->exportvCalendar();
Index: pfb.php
===================================================================
RCS file: /kolabrepository/server/kolab-freebusy/freebusy/pfb.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pfb.php 8 Aug 2007 09:47:29 -0000 1.1
+++ pfb.php 8 Aug 2007 13:11:22 -0000 1.2
@@ -25,10 +25,19 @@
*
* $Revision$
*
+ * ABOUT
+ * -----
+ *
+ * This script generates partial free/busy information based on a
+ * single calendar folder on the Kolab groupware server. The partial
+ * information is cached an later assembled for display by the
+ * freebusy.php script.
+ *
*/
// Profiling
-function microtime_float() {
+function microtime_float()
+{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
@@ -37,13 +46,17 @@
error_reporting(E_ALL);
$max_execution_time = ini_get('max_execution_time');
-if( $max_execution_time < 200 ) ini_set('max_execution_time', '200');
+if( $max_execution_time < 200 ) {
+ ini_set('max_execution_time', '200');
+ }
require_once('Kolab/Freebusy/misc.php');
require_once('config.php');
if ( empty($params['ldap_classname_suffix'])) $params['ldap_classname_suffix'] = '';
-require_once('Kolab/Freebusy/freebusyldap'.$params['ldap_classname_suffix'].'.class.php');
+require_once('Kolab/Freebusy/freebusyldap'
+ . $params['ldap_classname_suffix']
+ . '.class.php');
require_once('Kolab/Freebusy/freebusycache.class.php');
@@ -54,39 +67,32 @@
$req_cache = isset($_REQUEST['cache'])?(bool)$_REQUEST['cache']:false;
$req_folder = isset($_REQUEST['folder'])?$_REQUEST['folder']:false;
$req_extended = isset($_REQUEST['extended'])?(bool)$_REQUEST['extended']:false;
+
// convert character encoding (stores utf7 folder names also on disc)
require_once "Horde/Util.php";
require_once "Horde/String.php";
$req_folder = String::convertCharset($req_folder, "UTF-8", "UTF7-IMAP");
-/*
-// Debug test values
-$imapuser = "groupware";
-$imappw = "groupware";
-$req_cache = 0;
-$req_folder = "groupware/Kalender";
-$req_extended = 0;
-*/
myLog("pfb.php starting up: user=$imapuser, folder=$req_folder, extended=$req_extended",
RM_LOG_DEBUG);
$ldap =& new FreeBusyLDAP( $params['ldap_uri'], $params['base_dn'] );
if( !$ldap->bind( $params['bind_dn'], $params['bind_pw'] ) ) {
- notFound( "Bind failed: ".$ldap->error() );
- exit;
+ notFound( "Bind failed: ".$ldap->error() );
+ exit;
}
$userinfo = $ldap->userInfo( $imapuser );
if( $userinfo ) {
- if( $userinfo['MAIL'] ) $imapuser = $userinfo['MAIL'];
- //$homeserver = $userinfo['HOMESERVER'];
-}
+ if( $userinfo['MAIL'] ) $imapuser = $userinfo['MAIL'];
+ //$homeserver = $userinfo['HOMESERVER'];
+ }
$folder = explode('/', $req_folder);
if( count($folder) < 1 ) {
- // error
- notFound( _('No such folder ').htmlentities($req_folder) );
+ // error
+ notFound( _('No such folder ') . htmlentities($req_folder) );
}
// Make sure email address is in lowercase
@@ -98,113 +104,116 @@
$homeserver = $uinfo['HOMESERVER'];
if( empty($owner) || false===strpos($owner,'@')) {
// try guessing the domain
- $idx = strpos( $imapuser, '@' );
- if( $idx !== false ) {
- $domain = substr( $imapuser, $idx+1 );
- myLog("Trying to append $domain to ".$folder[0], RM_LOG_DEBUG);
- $uinfo = $ldap->userInfo($folder[0].'@'.$domain);
- $owner = $uinfo['MAIL'];
- }
+ $idx = strpos( $imapuser, '@' );
+ if( $idx !== false ) {
+ $domain = substr( $imapuser, $idx+1 );
+ myLog("Trying to append $domain to ".$folder[0], RM_LOG_DEBUG);
+ $uinfo = $ldap->userInfo($folder[0].'@'.$domain);
+ $owner = $uinfo['MAIL'];
+ }
}
if( $homeserver && $homeserver != $params['server'] ) {
- $redirect = 'https://'.$homeserver . $_SERVER['REQUEST_URI'];
- myLog("Found remote user, redirecting to $homeserver", RM_LOG_DEBUG);
- if ($params['redirect']) {
- header("Location: $redirect");
- } else {
- header("X-Redirect-To: $redirect");
- $redirect = 'https://' . urlencode($_SERVER['PHP_AUTH_USER']) . ':'
- . urlencode($_SERVER['PHP_AUTH_PW']) . '@' . $homeserver
- . $_SERVER['REQUEST_URI'];
- if (!@readfile($redirect)) {
- unauthorized("Unable to read free/busy information from ".removePassword($redirect));
+ $redirect = 'https://'.$homeserver . $_SERVER['REQUEST_URI'];
+ myLog("Found remote user, redirecting to $homeserver", RM_LOG_DEBUG);
+ if ($params['redirect']) {
+ header("Location: $redirect");
+ } else {
+ header("X-Redirect-To: $redirect");
+ $redirect = 'https://' . urlencode($_SERVER['PHP_AUTH_USER']) . ':'
+ . urlencode($_SERVER['PHP_AUTH_PW']) . '@' . $homeserver
+ . $_SERVER['REQUEST_URI'];
+ if (!@readfile($redirect)) {
+ unauthorized("Unable to read free/busy information from ".removePassword($redirect));
+ }
}
- }
- shutdown();
- exit;
-}
+ shutdown();
+ exit;
+ }
$cache =& new FreeBusyCache( $params['cache_dir'], $params['pfb_dbformat'], false );
$xcache =& new FreeBusyCache( $params['cache_dir'], $params['pfb_dbformat'], true );
-
if( $req_cache ) {
- $acl = false;
- if( $req_extended ) {
- $vfb = $xcache->load( $req_folder, $ts, $acl );
- } else {
- $vfb = $cache->load( $req_folder, $ts, $acl );
- }
- if( $acl && $req_extended ) {
- // Check access
- $distlists = $ldap->distlists( $userinfo['DN'] );
- if( $distlists === false ) unauthorized( $req_folder.($req_extended?'.xpfb':'.pfb' ) );
- for( $i = 0; $i < count($distlists); $i++ ) {
- $distlists[$i] = $distlists[$i].'@'.$params['email_domain'];
- }
- $rights = $xcache->getRights( $acl, $imapuser, $distlists );
- if( !$req_extended || $rights['r'] ) {
- // All OK
+ $acl = false;
+ if( $req_extended ) {
+ $vfb = $xcache->load( $req_folder, $ts, $acl );
} else {
- // Nope
- unauthorized( $req_folder.($req_extended?'.xpfb':'.pfb' ) );
+ $vfb = $cache->load( $req_folder, $ts, $acl );
}
- }
- if( !$vfb ) notFound( $req_folder.($req_extended?'.xpfb':'.pfb').' not found in cache');
-} else {
- if( empty($imapuser) ) {
- // Here we really need an authenticated user!
- unauthorized("Please authenticate");
- }
- require_once('Kolab/Freebusy/freebusy.class.php');
-
- if( empty($owner) ) {
- notFound( _('No such account ').htmlentities($folder[0]));
- return false;
- }
- unset($folder[0]);
- $folder = join('/', $folder);
- $fbpast = $ldap->freeBusyPast();
- $fb =& new FreeBusy( $params['cache_dir'], $owner, $imapuser, $imappw, 'localhost', $params['imap_options'], $uinfo['FBFUTURE'], $fbpast );
+ if( $acl && $req_extended ) {
+ // Check access
+ $distlists = $ldap->distlists( $userinfo['DN'] );
+ if( $distlists === false ) {
+ unauthorized( $req_folder.($req_extended?'.xpfb':'.pfb' ) );
+ }
+ for( $i = 0; $i < count($distlists); $i++ ) {
+ $distlists[$i] = $distlists[$i].'@'.$params['email_domain'];
+ }
+ $rights = $xcache->getRights( $acl, $imapuser, $distlists );
+ if( !$req_extended || $rights['r'] ) {
+ // All OK
+ } else {
+ // Nope
+ unauthorized( $req_folder.($req_extended?'.xpfb':'.pfb' ) );
+ }
+ }
+ if( !$vfb ) {
+ notFound( $req_folder.($req_extended?'.xpfb':'.pfb').' not found in cache');
+ }
+ } else {
+ if( empty($imapuser) ) {
+ // Here we really need an authenticated user!
+ unauthorized("Please authenticate");
+ }
+ require_once('Kolab/Freebusy/freebusy.class.php');
+
+ if( empty($owner) ) {
+ notFound( _('No such account ').htmlentities($folder[0]));
+ return false;
+ }
+ unset($folder[0]);
+ $folder = join('/', $folder);
+ $fbpast = $ldap->freeBusyPast();
+ $fb =& new FreeBusy( $params['cache_dir'], $owner, $imapuser, $imappw, 'localhost', $params['imap_options'], $uinfo['FBFUTURE'], $fbpast );
- $fb->default_domain = $params['email_domain'];
- $rc = $fb->imapConnect();
- if( $rc === false ) {
- unauthorized(imap_last_error());
- return false;
- }
- $rc = $fb->imapOpenMailbox(FreeBusy::imapFolderName( $imapuser, $owner,
- $folder, $params['email_domain']));
- if( $rc === false ) {
- notfound( "Folder: ".$fb->foldername.', '.imap_last_error());
- return false;
- }
- $relevance = $fb->getRelevance();
- list($vfb,$xvfb) = $fb->generateFreeBusy();
- $ts = mktime();
- if( PEAR::isError( $vfb ) ) {
- unauthorized($vfb->toString());
- return false;
- }
+ $fb->default_domain = $params['email_domain'];
+ $rc = $fb->imapConnect();
+ if( $rc === false ) {
+ unauthorized(imap_last_error());
+ return false;
+ }
+ $rc = $fb->imapOpenMailbox(FreeBusy::imapFolderName( $imapuser, $owner,
+ $folder, $params['email_domain']));
+ if( $rc === false ) {
+ notfound( "Folder: ".$fb->foldername.', '.imap_last_error());
+ return false;
+ }
+ $relevance = $fb->getRelevance();
+ list($vfb,$xvfb) = $fb->generateFreeBusy();
+ $ts = mktime();
+ if( PEAR::isError( $vfb ) ) {
+ unauthorized($vfb->toString());
+ return false;
+ }
- if(ereg('(.*)@(.*)',$owner,$regs)) {
- $owner = $regs[2].'/'.$regs[1];
- }
+ if(ereg('(.*)@(.*)',$owner,$regs)) {
+ $owner = $regs[2].'/'.$regs[1];
+ }
- $acl = $fb->getACL();
- if( !$cache->store( $owner.'/'.$folder, $vfb, $acl, $relevance ) ) {
- trigger_error('Could not store pfb in cache file '.$owner.'/'.$folder
- .'.pfb: '.$cache->error, E_USER_WARNING);
- }
- if( !$xcache->store( $owner.'/'.$folder, $xvfb, $acl, $relevance ) ) {
- trigger_error('Could not store xpfb in cache file '.$owner.'/'.$folder
- .'.xpfb: '.$cache->error, E_USER_WARNING);
- }
+ $acl = $fb->getACL();
+ if( !$cache->store( $owner.'/'.$folder, $vfb, $acl, $relevance ) ) {
+ trigger_error('Could not store pfb in cache file '.$owner.'/'.$folder
+ .'.pfb: '.$cache->error, E_USER_WARNING);
+ }
+ if( !$xcache->store( $owner.'/'.$folder, $xvfb, $acl, $relevance ) ) {
+ trigger_error('Could not store xpfb in cache file '.$owner.'/'.$folder
+ .'.xpfb: '.$cache->error, E_USER_WARNING);
+ }
- if( $req_extended ) $vfb = $xvfb;
- unset($xvfb);
-}
+ if( $req_extended ) $vfb = $xvfb;
+ unset($xvfb);
+ }
// And finally send it out, ensuring it doesn't get cached along the way
header('Cache-Control: no-store, no-cache, must-revalidate');
@@ -216,17 +225,15 @@
header('Content-Transfer-Encoding: none');
if ($params['send_content_type']) {
header('Content-Type: text/calendar');
-}
+ }
if ($params['send_content_length']) {
header('Content-Length: ' . strlen($vfb));
-}
+ }
if ($params['send_content_disposition']) {
header('Content-Disposition: attachment; filename="' . $user . '.vfb"');
-}
+ }
-#print "folder=$req_folder, cache=$req_cache, extended=$req_extended";
echo $vfb;
-#print_r($acl);
// Finish up
myLog("pfb.php complete, execution time was ".(microtime_float()-$start_time)." secs.", RM_LOG_DEBUG);
More information about the commits
mailing list