summaryrefslogtreecommitdiff
path: root/lib/Kolab
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab')
-rw-r--r--lib/Kolab/FreeBusy/Config.php60
-rw-r--r--lib/Kolab/FreeBusy/Directory.php12
-rw-r--r--lib/Kolab/FreeBusy/DirectoryLDAP.php20
-rw-r--r--lib/Kolab/FreeBusy/DirectoryStatic.php9
-rw-r--r--lib/Kolab/FreeBusy/Logger.php18
-rw-r--r--lib/Kolab/FreeBusy/Source.php10
-rw-r--r--lib/Kolab/FreeBusy/SourceFile.php17
-rw-r--r--lib/Kolab/FreeBusy/SourceIMAP.php6
-rw-r--r--lib/Kolab/FreeBusy/SourceURL.php6
9 files changed, 103 insertions, 55 deletions
diff --git a/lib/Kolab/FreeBusy/Config.php b/lib/Kolab/FreeBusy/Config.php
index c0101e9..d80ef7f 100644
--- a/lib/Kolab/FreeBusy/Config.php
+++ b/lib/Kolab/FreeBusy/Config.php
@@ -1,61 +1,91 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
* Wrapper class for service configuration
*/
-class FBConfig
+class Config
{
private static $instance;
+ private $basedir = '.';
private $data = array();
private $valid = false;
/**
* Singelton getter
+ *
+ * @param string Path to load config from
*/
public static function getInstance($dir = null)
{
if (!isset(self::$instance)) {
- self::$instance = new FBConfig($dir);
+ self::$instance = new Config($dir);
}
- if ($dir && !self::$instance->valid)
- self::$instance->_load($dir);
+ if ($dir && !self::$instance->valid) {
+ self::$instance->load($configdir . '/config.ini');
+ }
return self::$instance;
}
/**
* Default constructor
- *
- * @param string Path to load config from
*/
function __construct($configdir = null)
{
if ($configdir) {
- $this->_load($configdir);
+ $this->basedir = $configdir;
+ $this->load($configdir . '/config.ini');
}
}
-
- private function _load($configdir)
+
+ /**
+ * Load config from the given .ini file
+ */
+ private function load($inifile)
{
- if ($raw = @parse_ini_file($configdir . '/config.ini', true)) {
+ if ($raw = parse_ini_file($inifile, true)) {
foreach ($raw as $section => $values) {
// check for known sections
if (in_array($section, array('httpauth','trustednetworks','log'))) {
- $this->data[$section] = $values;
+ $config[$section] = $values;
}
- else if (isset($values['fbsource'])){
- $this->data['directories'][] = $values;
+ else if (strpos($section, 'directory') === 0 || isset($values['fbsource'])){
+ $config['directories'][] = $values;
}
}
+ $this->register($config);
$this->valid = !empty($this->data['directories']);
}
else {
- trigger_error("Failed to parse configuration from $config_dir/config.ini", E_USER_ERROR);
+ trigger_error("Failed to parse configuration from $inifile", E_USER_ERROR);
+ }
+ }
+
+ /**
+ * Dump the hierarchical structure of config options into a flat list with keys delimited by dots
+ */
+ private function register($config, $prefix = '')
+ {
+ if (empty($prefix)) {
+ $this->data = array_replace_recursive($this->data, $config);
+ }
+ else if (is_array($config)) {
+ $pkey = rtrim($prefix, '.');
+ $this->data[$pkey] = is_array($this->data[$pkey]) ? array_replace_recursive((array)$this->data[$pkey], $config) : $config;
+ }
+
+ foreach ((array)$config as $key => $val) {
+ if (is_array($val)) {
+ $this->register($val, "$prefix$key.");
+ }
+ else {
+ $this->data[$prefix.$key] = $val;
+ }
}
}
diff --git a/lib/Kolab/FreeBusy/Directory.php b/lib/Kolab/FreeBusy/Directory.php
index 25b9038..c16c666 100644
--- a/lib/Kolab/FreeBusy/Directory.php
+++ b/lib/Kolab/FreeBusy/Directory.php
@@ -1,11 +1,11 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
* Abstract class representing an address directory for free/busy data lookups
*/
-abstract class FBDirectory
+abstract class Directory
{
protected $config;
@@ -18,11 +18,11 @@ abstract class FBDirectory
{
switch (strtolower($config['type'])) {
case 'ldap':
- return new FBDirectoryLDAP($config);
+ return new DirectoryLDAP($config);
- case 'default':
+ case 'static':
case 'external':
- return new FBDirectoryDefault($config);
+ return new DirectoryStatic($config);
default:
trigger_error("Invalid directory type '" . $config['type'] . "'!", E_USER_ERROR);
@@ -51,7 +51,7 @@ abstract class FBDirectory
// resolve user record first
if ($user = $this->resolve($user)) {
$fbsource = $this->config['fbsource'];
- if ($source = FBSource::Factory($fbsource)) {
+ if ($source = Source::Factory($fbsource)) {
// foward request to FBSource instance
return $source->getFreeBusyData($user, $extended);
}
diff --git a/lib/Kolab/FreeBusy/DirectoryLDAP.php b/lib/Kolab/FreeBusy/DirectoryLDAP.php
index f7dfb95..ae80bfc 100644
--- a/lib/Kolab/FreeBusy/DirectoryLDAP.php
+++ b/lib/Kolab/FreeBusy/DirectoryLDAP.php
@@ -1,6 +1,6 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
// PEAR modules operate in global namespace
use \Net_LDAP3;
@@ -8,9 +8,10 @@ use \Net_LDAP3;
/**
*
*/
-class FBDirectoryLDAP extends FBDirectory
+class DirectoryLDAP extends Directory
{
private $ldap;
+ private $logger;
/**
* Default constructor loading directory configuration
@@ -21,13 +22,24 @@ class FBDirectoryLDAP extends FBDirectory
);
+ $this->logger = Logger::get('ldap');
$this->ldap = new Net_LDAP3($ldap_config);
- # $this->ldap->config_set_log_hook();
+ $this->ldap->config_set('log_hook', array($this, 'log'));
$this->ldap->connect();
}
/**
- * @see FBDirectory::resolve()
+ * Callback for Net_LDAP3 logging
+ */
+ public function log($log)
+ {
+ // TODO: map $log[0] levels
+ $msg = is_array($log[1]) ? join('; ', $log[1]) : strval($log[1]);
+ $this->logger->addRecord($log[0], $msg);
+ }
+
+ /**
+ * @see Directory::resolve()
*/
public function resolve($user)
{
diff --git a/lib/Kolab/FreeBusy/DirectoryStatic.php b/lib/Kolab/FreeBusy/DirectoryStatic.php
index cb89972..ff55e0e 100644
--- a/lib/Kolab/FreeBusy/DirectoryStatic.php
+++ b/lib/Kolab/FreeBusy/DirectoryStatic.php
@@ -1,11 +1,14 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
+ * Implementation of a static address directory for Free/Busy user lookups.
*
+ * This directory basically pipes the username through with an optional check
+ * whether it matches the configured filter rule
*/
-class FBDirectoryDefault extends FBDirectory
+class DirectoryStatic extends Directory
{
/**
* Default constructor loading directory configuration
@@ -16,7 +19,7 @@ class FBDirectoryDefault extends FBDirectory
}
/**
- * @see FBDirectory::resolve()
+ * @see Directory::resolve()
*/
public function resolve($user)
{
diff --git a/lib/Kolab/FreeBusy/Logger.php b/lib/Kolab/FreeBusy/Logger.php
index 97596c3..abb0060 100644
--- a/lib/Kolab/FreeBusy/Logger.php
+++ b/lib/Kolab/FreeBusy/Logger.php
@@ -1,15 +1,11 @@
<?php
-namespace Kolab;
-
-use Monolog\Logger;
-use Monolog\Handler\NullHandler;
-use Monolog\Handler\StreamHandler;
+namespace Kolab\FreeBusy;
/**
* Helper class for creating up Monolog instanced with local configration
*/
-class FBLogger
+class Logger
{
private static $instances = array();
@@ -19,20 +15,20 @@ class FBLogger
public static function get($name, $level = 0)
{
if (!isset(self::$instances[$name])) {
- $logger = new Logger($name);
+ $logger = new \Monolog\Logger($name);
// TODO: support more log drivers
- $config = FBConfig::getInstance();
+ $config = Config::getInstance();
switch ($config->get('log.driver')) {
case 'file':
$logdir = self::realpath($config->get('log.path'));
- $loglevel = $level ?: $config->get("log.level", Logger::INFO);
- $logger->pushHandler(new StreamHandler($logdir . $name. '.log', $loglevel));
+ $loglevel = $level ?: $config->get("log.level", \Monolog\Logger::INFO);
+ $logger->pushHandler(new \Monolog\Handler\StreamHandler($logdir . $name. '.log', $loglevel));
break;
default:
// null handler if logging is disabled
- $logger->pushHandler(new NullHandler);
+ $logger->pushHandler(new \Monolog\Handler\NullHandler);
}
self::$instances[$name] = $logger;
diff --git a/lib/Kolab/FreeBusy/Source.php b/lib/Kolab/FreeBusy/Source.php
index 6d5d062..c078b48 100644
--- a/lib/Kolab/FreeBusy/Source.php
+++ b/lib/Kolab/FreeBusy/Source.php
@@ -1,11 +1,11 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
* Abstract class to fetch free/busy data from a specific source
*/
-abstract class FBSource
+abstract class Source
{
protected $config = array();
@@ -18,10 +18,10 @@ abstract class FBSource
{
$config = parse_url($url);
switch ($config['scheme']) {
- case 'file': return new FBSourceFile($config);
- case 'imap': return new FBSourceIMAP($config);
+ case 'file': return new SourceFile($config);
+ case 'imap': return new SourceIMAP($config);
case 'http':
- case 'https': return new FBSourceURL($url);
+ case 'https': return new SourceURL($url);
}
trigger_error("Invalid source configuration: " . $url, E_USER_ERROR);
diff --git a/lib/Kolab/FreeBusy/SourceFile.php b/lib/Kolab/FreeBusy/SourceFile.php
index 0cdaf02..29840a6 100644
--- a/lib/Kolab/FreeBusy/SourceFile.php
+++ b/lib/Kolab/FreeBusy/SourceFile.php
@@ -1,19 +1,26 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
- *
+ * Implementation of a Free/Busy data source reading from the local file system
*/
-class FBSourceFile extends FBSource
+class SourceFile extends Source
{
/**
- * @see FBSource::getFreeBusyData()
+ * @see Source::getFreeBusyData()
*/
public function getFreeBusyData($user, $extended)
{
+ // get source config with placeholders replaced
$config = $this->getUserConfig($user);
- // TODO: implement this
+ // deliver file contents if found
+ if (is_readable($config['path'])) {
+ return file_get_contents($config['path']);
+ }
+
+ // not found
+ return false;
}
}
diff --git a/lib/Kolab/FreeBusy/SourceIMAP.php b/lib/Kolab/FreeBusy/SourceIMAP.php
index 90602f8..23200c8 100644
--- a/lib/Kolab/FreeBusy/SourceIMAP.php
+++ b/lib/Kolab/FreeBusy/SourceIMAP.php
@@ -1,14 +1,14 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
*
*/
-class FBSourceIMAP extends FBSource
+class SourceIMAP extends Source
{
/**
- * @see FBSource::getFreeBusyData()
+ * @see Source::getFreeBusyData()
*/
public function getFreeBusyData($user, $extended)
{
diff --git a/lib/Kolab/FreeBusy/SourceURL.php b/lib/Kolab/FreeBusy/SourceURL.php
index ecd0df5..1051dbf 100644
--- a/lib/Kolab/FreeBusy/SourceURL.php
+++ b/lib/Kolab/FreeBusy/SourceURL.php
@@ -1,14 +1,14 @@
<?php
-namespace Kolab;
+namespace Kolab\FreeBusy;
/**
*
*/
-class FBSourceURL extends FBSource
+class SourceURL extends Source
{
/**
- * @see FBSource::getFreeBusyData()
+ * @see Source::getFreeBusyData()
*/
public function getFreeBusyData($user, $extended)
{