Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2528117
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/composer.json b/composer.json
index 4343c2a..3dae001 100644
--- a/composer.json
+++ b/composer.json
@@ -1,25 +1,27 @@
{
"name": "kolab/free-busy",
"description": "Kolab Free/Busy Service",
"license": "AGPL-3.0",
"version": "0.1-alpha",
"repositories": [
{
"type": "pear",
"url": "http://pear.php.net/"
},
{
"type": "vcs",
"url": "git://git.kolab.org/git/pear/Net_LDAP3"
}
],
"autoload": {
"psr-0": { "": "lib/" }
},
"require": {
"php": ">=5.3.3",
"monolog/monolog": "1.2.*",
- "kolab/Net_LDAP3": "dev-master"
+ "kolab/Net_LDAP3": "dev-master",
+ "desarrolla2/cache": "dev-master",
+ "sabre/vobject" : "2.0.*"
},
"minimum-stability": "dev"
}
\ No newline at end of file
diff --git a/config/config.ini.sample b/config/config.ini.sample
index 3dfe7cf..fbcbdfa 100644
--- a/config/config.ini.sample
+++ b/config/config.ini.sample
@@ -1,53 +1,60 @@
;; Kolab Free/Busy Service configuration
;; Require HTTP authentication to access this service
[httpauth]
;; Example for static auth credentials
; type = static
; username = "<user>"
; password = "<pass>"
;; Example for LDAP-based authentication
; type = ldap
; host = ldap://localhost:389
; bind_dn = "uid=kolab-service,ou=Special Users,dc=yourdomain,dc=com"
; bind_pw = "<service-bind-pw>"
; base_dn = "dc=yourdomain,dc=com"
; filter = "(&(|(mail=%s)(alias=%s)(uid=%s))(objectclass=inetorgperson))" ; optional, %s is replaced by the username
;; Allow privileged access from these IPs
[trustednetworks]
allow[] = 127.0.0.1
allow[] = 192.168.0.0/16
allow[] = 10.10.*
allow[] = ::1
;; Logging configuration
[log]
driver = file ; supported drivers: file, syslog
path = ./log
name = freebusy
level = 300 ; (100 = Debug, 200 = Info, 300 = Warn, 400 = Error, 500 = Critical)
;; Directories to resolve email addresses and their f/b source locations
;; try local filesystem first
[directory "local"]
type = static
filter = "@yourdomain"
fbsource = file:/var/lib/kolab-freebusy/%s.ifb
;; local Kolab directory server
[directory "kolab-ldap"]
type = ldap
host = ldap://localhost:389
bind_dn = "uid=kolab-service,ou=Special Users,dc=yourdomain,dc=com"
bind_pw = "<service-bind-pw>"
base_dn = "dc=yourdomain,dc=com"
filter = "(&(objectClass=kolabInetOrgPerson)(|(uid=%s)(mail=%s)(alias=%s)))"
attributes[] = mail
fbsource = file:/www/kolab-freebusy/data/%mail.ifb
loglevel = 100 ; Debug
+;; external MS Exchange 2010 server
+[directory "exchange"]
+type = static
+filter = "@microsoft.com$"
+fbsource = https://externalhost/free-busy/%s.ics
+format = Exchange2010
+
diff --git a/lib/Kolab/FreeBusy/Directory.php b/lib/Kolab/FreeBusy/Directory.php
index 67e6d8d..97fee75 100644
--- a/lib/Kolab/FreeBusy/Directory.php
+++ b/lib/Kolab/FreeBusy/Directory.php
@@ -1,63 +1,69 @@
<?php
namespace Kolab\FreeBusy;
/**
* Abstract class representing an address directory for free/busy data lookups
*/
abstract class Directory
{
protected $config;
/**
* Factory method creating an instace of Directory according to config
*
* @param array Hash array with config
*/
public static function factory($config)
{
switch (strtolower($config['type'])) {
case 'ldap':
return new DirectoryLDAP($config);
case 'static':
case 'external':
return new DirectoryStatic($config);
default:
Logger::get('directory')->addError("Invalid directory type '" . $config['type'] . "'!");
}
return null;
}
/**
* Resolve the given username to a Entity object
*
* @param string Username/Email to resolve
* @return object Entity if found, otherwise False
*/
abstract public function resolve($user);
/**
* Retrieve free/busy data for the given user.
*
* @param string Username or email to resolve
* @param boolean Get extemded free-busy if possible
* @return string VCalendar container if found, False otherwise
*/
public function getFreeBusyData($user, $extended = false)
{
// resolve user record first
if ($user = $this->resolve($user)) {
$fbsource = $this->config['fbsource'];
if ($source = Source::Factory($fbsource)) {
- // foward request to Source instance
- return $source->getFreeBusyData($user, $extended);
+ // forward request to Source instance
+ if ($data = $source->getFreeBusyData($user, $extended)) {
+ // send data through the according format converter
+ $converter = Format::factory($this->config['format']);
+ $data = $converter->toVCalendar($data);
+ }
+
+ return $data;
}
}
return false;
}
}
\ No newline at end of file
diff --git a/lib/Kolab/FreeBusy/Format.php b/lib/Kolab/FreeBusy/Format.php
new file mode 100644
index 0000000..b5ebfda
--- /dev/null
+++ b/lib/Kolab/FreeBusy/Format.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Kolab\FreeBusy;
+
+/**
+ * Base class to handle free/busy data format conversion
+ */
+class Format
+{
+ protected $config;
+
+ /**
+ * Factory method creating an instace of Format according to the given type
+ *
+ * @param string Format identifier
+ */
+ public static function factory($type)
+ {
+ switch (strtolower($type)) {
+ case 'exchange2010':
+ return new FormatExchange2010;
+
+ default:
+ if (!empty($type)) {
+ Logger::get('format')->addError("Unknown format type '$type'!");
+ }
+ return new Format;
+ }
+
+ return null;
+ }
+
+ /**
+ * Convert the given free/busy data stream to iCal format
+ *
+ * @param string Input data stream
+ * @return string iCal formatted free/busy list
+ */
+ public function toVCalendar($input)
+ {
+ // default: no format changes
+ return $input;
+ }
+
+
+}
\ No newline at end of file
diff --git a/lib/Kolab/FreeBusy/FormatExchange2010.php b/lib/Kolab/FreeBusy/FormatExchange2010.php
new file mode 100644
index 0000000..8aec7e4
--- /dev/null
+++ b/lib/Kolab/FreeBusy/FormatExchange2010.php
@@ -0,0 +1,135 @@
+<?php
+
+namespace Kolab\FreeBusy;
+
+use Sabre\VObject\Reader as VCalReader;
+use Sabre\VObject\FreeBusyGenerator;
+use Sabre\VObject\ParseException;
+use Desarrolla2\Cache\Cache;
+use Desarrolla2\Cache\Adapter\File as FileCache;
+use \SimpleXMLElement;
+
+
+/**
+ * Implementation of a data converter reading Exchange 2010 Internet Calendar Publishing files
+ */
+class FormatExchange2010 extends Format
+{
+ private $tzmap;
+
+ /**
+ * @see Format::toVCalendar()
+ */
+ public function toVCalendar($input)
+ {
+ // convert Microsoft timezone identifiers to Olson standard
+ // do this before parsing to create correct DateTime values
+ $input = preg_replace_callback('/(TZID[=:])([-\w ]+)\b/i', array($this, 'convertTZID'), $input);
+
+ try {
+ // parse vcalendar data
+ $calendar = VCalReader::read($input);
+
+ // map X-MICROSOFT-CDO-* attributes into iCal equivalents
+ foreach ($calendar->VEVENT as $vevent) {
+ if ($busystatus = reset($vevent->select('X-MICROSOFT-CDO-BUSYSTATUS'))) {
+ $vevent->STATUS->value = $busystatus->value;
+ }
+ }
+
+ // feed the calendar object into the free/busy generator
+ // we must specify a start and end date, because recurring events are expanded. nice!
+ $fbgen = new FreeBusyGenerator(
+ new \DateTime('now - 8 weeks'),
+ new \DateTime('now + 16 weeks'),
+ $calendar
+ );
+
+ // get the freebusy report
+ $freebusy = $fbgen->getResult();
+ $freebusy->PRODID->value = '-//kolab.org//NONSGML Kolab Server 3//EN';
+
+ // serialize to VCALENDAR format
+ return $freebusy->serialize();
+ }
+ catch (ParseException $e) {
+ Logger::get('format.Exchange2010')->addError("iCal parse error: " . $e->getMessage());
+ }
+
+ return false;
+ }
+
+ /**
+ * preg_replace callback function to map Timezone identifiers
+ */
+ private function convertTZID($m)
+ {
+ if (!isset($this->tzmap)) {
+ $this->getTZMAP();
+ }
+
+ $key = strtolower($m[2]);
+ if ($this->tzmap[$key]) {
+ $m[2] = $this->tzmap[$key];
+ }
+
+ return $m[1] . $m[2] . $m[3];
+ }
+
+ /**
+ * Generate a Microsoft => Olson Timezone mapping table from an official source
+ */
+ private function getTZMAP()
+ {
+ if (!isset($this->tzmap)) {
+ $log = Logger::get('format.Exchange2010');
+ $cache = new Cache(new FileCache(sys_get_temp_dir()));
+
+ // read from cache
+ $this->tzmap = $cache->get('windows-timezones');
+
+ // fetch timezones map from source
+ if (empty($this->tzmap)) {
+ $this->tzmap = array();
+ $zones_url = 'http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml';
+ if ($xml = @file_get_contents($zones_url)) {
+ try {
+ $zonedata = new SimpleXMLElement($xml, LIBXML_NOWARNING | LIBXML_NOERROR);
+ foreach ($zonedata->windowsZones[0]->mapTimezones[0]->mapZone as $map) {
+ $other = strtolower(strval($map['other']));
+ $region = strval($map['territory']);
+ $words = explode(' ', $other);
+ $olson = explode(' ', strval($map['type']));
+
+ // skip invalid entries
+ if (empty($other) || empty($olson))
+ continue;
+
+ // create an entry for all substrings
+ for ($i = 1; $i <= count($words); $i++) {
+ $last = $i == count($words);
+ $key = join(' ', array_slice($words, 0, $i));
+ if ($region == '001' || ($last && empty($this->tzmap[$key]))) {
+ $this->tzmap[$key] = $olson[0];
+ }
+ }
+ }
+
+ // cache the mapping for one week
+ $cache->set('windows-timezones', $this->tzmap, 7 * 86400);
+
+ $log->addInfo("Updated Windows Timezones Map from source", array($zones_url));
+ }
+ catch (\Exception $e) {
+ $log->addError("Failed parse Windows Timezones Map: " . $e->getMessage());
+ }
+ }
+ else {
+ $log->addError("Failed to load Windows Timezones Map from source", array($zones_url));
+ }
+ }
+ }
+
+ return $this->tzmap;
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Feb 1, 2:32 AM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
426605
Default Alt Text
(9 KB)
Attached To
Mode
R28 freebusy
Attached
Detach File
Event Timeline
Log In to Comment