summaryrefslogtreecommitdiff
path: root/lib/Kolab/FreeBusy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab/FreeBusy')
-rw-r--r--lib/Kolab/FreeBusy/Config.php7
-rw-r--r--lib/Kolab/FreeBusy/Directory.php2
-rw-r--r--lib/Kolab/FreeBusy/DirectoryLDAP.php2
-rw-r--r--lib/Kolab/FreeBusy/Logger.php27
-rw-r--r--lib/Kolab/FreeBusy/Source.php2
-rw-r--r--lib/Kolab/FreeBusy/SourceURL.php11
6 files changed, 27 insertions, 24 deletions
diff --git a/lib/Kolab/FreeBusy/Config.php b/lib/Kolab/FreeBusy/Config.php
index d80ef7f..205a438 100644
--- a/lib/Kolab/FreeBusy/Config.php
+++ b/lib/Kolab/FreeBusy/Config.php
@@ -48,13 +48,16 @@ class Config
private function load($inifile)
{
if ($raw = parse_ini_file($inifile, true)) {
+ $config['directories'] = array();
foreach ($raw as $section => $values) {
// check for known sections
if (in_array($section, array('httpauth','trustednetworks','log'))) {
$config[$section] = $values;
}
- else if (strpos($section, 'directory') === 0 || isset($values['fbsource'])){
- $config['directories'][] = $values;
+ else if (strpos($section, 'directory') === 0 || isset($values['fbsource'])) {
+ $sect = preg_replace('/^directory\s*/', '', $section);
+ $key = strlen($sect) ? $sect : count($config['directories']);
+ $config['directories'][$key] = $values;
}
}
diff --git a/lib/Kolab/FreeBusy/Directory.php b/lib/Kolab/FreeBusy/Directory.php
index a68e5bb..67e6d8d 100644
--- a/lib/Kolab/FreeBusy/Directory.php
+++ b/lib/Kolab/FreeBusy/Directory.php
@@ -25,7 +25,7 @@ abstract class Directory
return new DirectoryStatic($config);
default:
- trigger_error("Invalid directory type '" . $config['type'] . "'!", E_USER_ERROR);
+ Logger::get('directory')->addError("Invalid directory type '" . $config['type'] . "'!");
}
return null;
diff --git a/lib/Kolab/FreeBusy/DirectoryLDAP.php b/lib/Kolab/FreeBusy/DirectoryLDAP.php
index 1c675f9..54709f2 100644
--- a/lib/Kolab/FreeBusy/DirectoryLDAP.php
+++ b/lib/Kolab/FreeBusy/DirectoryLDAP.php
@@ -34,7 +34,7 @@ class DirectoryLDAP extends Directory
) + $config;
// instantiate Net_LDAP3 and connect with logger
- $this->logger = Logger::get('ldap', $config['loglevel']);
+ $this->logger = Logger::get('ldap', intval($config['loglevel']));
$this->ldap = new Net_LDAP3($ldap_config);
$this->ldap->config_set('log_hook', array($this, 'log'));
$this->ldap->config_set('return_attributes', (array)$config['attributes']);
diff --git a/lib/Kolab/FreeBusy/Logger.php b/lib/Kolab/FreeBusy/Logger.php
index 552c7e0..8af607c 100644
--- a/lib/Kolab/FreeBusy/Logger.php
+++ b/lib/Kolab/FreeBusy/Logger.php
@@ -4,6 +4,7 @@ namespace Kolab\FreeBusy;
use Monolog\Logger as Monologger;
use Monolog\Handler\StreamHandler;
+use Monolog\Handler\SyslogHandler;
use Monolog\Handler\NullHandler;
/**
@@ -18,16 +19,22 @@ class Logger
*/
public static function get($name, $level = 0)
{
- if (!isset(self::$instances[$name])) {
+ if (!isset(self::$instances[$name]) || ($level && !self::$instances[$name]->isHandling($level))) {
$logger = new Monologger($name);
- // TODO: support more log drivers
+ // read log config
$config = Config::getInstance();
+ $identity = $config->get('log.name', 'freebusy');
+ $loglevel = $level ?: $config->get('log.level', Monologger::INFO);
+
switch ($config->get('log.driver')) {
case 'file':
- $logdir = self::realpath($config->get('log.path'));
- $loglevel = $level ?: $config->get("log.level", Monologger::INFO);
- $logger->pushHandler(new StreamHandler($logdir . $name. '.log', $loglevel));
+ $logdir = Utils::abspath($config->get('log.path'), '/');
+ $logger->pushHandler(new StreamHandler($logdir . $identity . '.log', $loglevel));
+ break;
+
+ case 'syslog':
+ $logger->pushHahdler(new SyslogHandler($identity, $config->get('log.facility', 'user'), $loglevel));
break;
default:
@@ -41,15 +48,5 @@ class Logger
return self::$instances[$name];
}
- /**
- * Resolve the given directory to a real path ending with a /
- */
- private static function realpath($dirname)
- {
- if ($dirname[0] != '/')
- $dirname = realpath(KOLAB_FREEBUSY_ROOT . '/' . $dirname);
-
- return rtrim($dirname, '/') . '/';
- }
}
diff --git a/lib/Kolab/FreeBusy/Source.php b/lib/Kolab/FreeBusy/Source.php
index 53c4d0f..2d12ebc 100644
--- a/lib/Kolab/FreeBusy/Source.php
+++ b/lib/Kolab/FreeBusy/Source.php
@@ -25,7 +25,7 @@ abstract class Source
case 'https': return new SourceURL($config);
}
- trigger_error("Invalid source configuration: " . $url, E_USER_ERROR);
+ Logger::get('source')->addError("Invalid source configuration: " . $url);
return null;
}
diff --git a/lib/Kolab/FreeBusy/SourceURL.php b/lib/Kolab/FreeBusy/SourceURL.php
index d165bd5..e838640 100644
--- a/lib/Kolab/FreeBusy/SourceURL.php
+++ b/lib/Kolab/FreeBusy/SourceURL.php
@@ -29,18 +29,21 @@ class SourceURL extends Source
'header' => "Authorization: Basic " . base64_encode($config['user'] . ':' . $config['pass']) . "\r\n",
),
));
- $config['url'] = self::getUrl($config); // re-compose url without user:pass
+ $config['url'] = self::composeUrl($config); // re-compose url without user:pass
}
- // TODO: so some logging
+ $data = file_get_contents($config['url'], false, $context);
- return file_get_contents($config['url'], false, $context);
+ // log this...
+ Logger::get('url')->addInfo("Fetching data from " . $config['url'] . ": " . ($data ? 'OK' : 'FAILED'));
+
+ return $data;
}
/**
* Compose a full url from the given config (previously extracted with parse_url())
*/
- private static function getUrl($config)
+ private static function composeUrl($config)
{
$scheme = isset($config['scheme']) ? $config['scheme'] . '://' : '';
$host = isset($config['host']) ? $config['host'] : '';