4 commits - config/config.ini.sample lib/Kolab web/index.php
Thomas Brüderli
bruederli at kolabsys.com
Wed Jan 16 17:54:34 CET 2013
config/config.ini.sample | 19 ++++++--
lib/Kolab/FreeBusy/DirectoryLDAP.php | 75 +++++++++++++++++++++++++++++++----
lib/Kolab/FreeBusy/Logger.php | 12 +++--
web/index.php | 8 ---
4 files changed, 89 insertions(+), 25 deletions(-)
New commits:
commit 0054e800228ce53eae18fc531d122976cdac6510
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 16 17:54:17 2013 +0100
Nicer PHP namespace handling
diff --git a/lib/Kolab/FreeBusy/Logger.php b/lib/Kolab/FreeBusy/Logger.php
index abb0060..552c7e0 100644
--- a/lib/Kolab/FreeBusy/Logger.php
+++ b/lib/Kolab/FreeBusy/Logger.php
@@ -2,6 +2,10 @@
namespace Kolab\FreeBusy;
+use Monolog\Logger as Monologger;
+use Monolog\Handler\StreamHandler;
+use Monolog\Handler\NullHandler;
+
/**
* Helper class for creating up Monolog instanced with local configration
*/
@@ -15,20 +19,20 @@ class Logger
public static function get($name, $level = 0)
{
if (!isset(self::$instances[$name])) {
- $logger = new \Monolog\Logger($name);
+ $logger = new Monologger($name);
// TODO: support more log drivers
$config = Config::getInstance();
switch ($config->get('log.driver')) {
case 'file':
$logdir = self::realpath($config->get('log.path'));
- $loglevel = $level ?: $config->get("log.level", \Monolog\Logger::INFO);
- $logger->pushHandler(new \Monolog\Handler\StreamHandler($logdir . $name. '.log', $loglevel));
+ $loglevel = $level ?: $config->get("log.level", Monologger::INFO);
+ $logger->pushHandler(new StreamHandler($logdir . $name. '.log', $loglevel));
break;
default:
// null handler if logging is disabled
- $logger->pushHandler(new \Monolog\Handler\NullHandler);
+ $logger->pushHandler(new NullHandler);
}
self::$instances[$name] = $logger;
commit 9fbb32d9b7f5c289878b8876400debfb4f9ac350
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 16 17:53:46 2013 +0100
Implement LDAP lookup routine; improve ldap logging
diff --git a/lib/Kolab/FreeBusy/DirectoryLDAP.php b/lib/Kolab/FreeBusy/DirectoryLDAP.php
index ae80bfc..1c675f9 100644
--- a/lib/Kolab/FreeBusy/DirectoryLDAP.php
+++ b/lib/Kolab/FreeBusy/DirectoryLDAP.php
@@ -4,6 +4,7 @@ namespace Kolab\FreeBusy;
// PEAR modules operate in global namespace
use \Net_LDAP3;
+use \Monolog\Logger as Monolog;
/**
*
@@ -12,30 +13,64 @@ class DirectoryLDAP extends Directory
{
private $ldap;
private $logger;
+ private $ready = false;
/**
* Default constructor loading directory configuration
*/
public function __construct($config)
{
+ $this->config = $config;
+
+ $host = parse_url($config['host']);
$ldap_config = array(
-
- );
+ 'hosts' => array($host['host']),
+ 'port' => $host['port'] ?: 389,
+ 'use_tls' => $host['scheme'] == 'tls' || $host['scheme'] == 'ldaps',
+ 'root_dn' => $config['base_dn'],
+ 'return_attributes' => (array)$config['attributes'],
+ 'sizelimit' => 0,
+ 'timelimit' => 0,
+ ) + $config;
- $this->logger = Logger::get('ldap');
+ // instantiate Net_LDAP3 and connect with logger
+ $this->logger = Logger::get('ldap', $config['loglevel']);
$this->ldap = new Net_LDAP3($ldap_config);
$this->ldap->config_set('log_hook', array($this, 'log'));
- $this->ldap->connect();
+ $this->ldap->config_set('return_attributes', (array)$config['attributes']);
+
+ // connect + bind to LDAP server
+ if ($this->ldap->connect()) {
+ $this->ready = $this->ldap->bind($config['bind_dn'], $config['bind_pw']);
+ }
+
+ if ($this->ready) {
+ $this->logger->addInfo("Connected to $config[host] with '$config[bind_dn]'");
+ }
+ else {
+ $this->logger->addWarning("Connectiion to $config[host] with '$config[bind_dn]' failed!");
+ }
}
/**
* Callback for Net_LDAP3 logging
*/
- public function log($log)
+ public function log($level, $msg)
{
- // TODO: map $log[0] levels
- $msg = is_array($log[1]) ? join('; ', $log[1]) : strval($log[1]);
- $this->logger->addRecord($log[0], $msg);
+ // map PHP log levels to Monolog levels
+ static $loglevels = array(
+ LOG_DEBUG => Monolog::DEBUG,
+ LOG_NOTICE => Monolog::NOTICE,
+ LOG_INFO => Monolog::INFO,
+ LOG_WARNING => Monolog::WARNING,
+ LOG_ERR => Monolog::ERROR,
+ LOG_CRIT => Monolog::CRITICAL,
+ LOG_ALERT => Monolog::ALERT,
+ LOG_EMERG => Monolog::EMERGENCY,
+ );
+
+ $msg = is_array($msg) ? join('; ', $msg) : strval($msg);
+ $this->logger->addRecord($loglevels[$level], $msg);
}
/**
@@ -45,6 +80,30 @@ class DirectoryLDAP extends Directory
{
$result = array('u' => $user);
+ if ($this->ready) {
+ // search with configured filter
+ $filter = preg_replace('/%u/i', $user, $this->config['filter']);
+ $ldapresult = $this->ldap->search($this->config['base_dn'], $filter, 'sub');
+
+ // got a valid result
+ if ($ldapresult && $ldapresult->count()) {
+ $ldapresult->rewind();
+ $entry = Net_LDAP3::normalize_entry($ldapresult->current()); // get the first entry
+ $this->logger->addInfo("Found " . $ldapresult->count() . " entries for $filter", $entry);
+
+ // convert entry attributes to strings and add them to the final result hash array
+ foreach ($entry as $k => $v) {
+ if (!empty($v)) {
+ $result[$k] = strval(is_array($v) ? $v[0] : $v);
+ }
+ }
+
+ return $result;
+ }
+
+ $this->logger->addInfo("No entry found for $filter");
+ }
+
return false;
}
commit 212bb3330b9a6b034771b2449b0d4ed2dcceaa8a
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 16 17:52:15 2013 +0100
Better sample config
diff --git a/config/config.ini.sample b/config/config.ini.sample
index 1c4cb5c..ce0dbad 100644
--- a/config/config.ini.sample
+++ b/config/config.ini.sample
@@ -16,14 +16,23 @@ allow[] = ::1
[log]
driver = file
path = ./log
-level = 100 ; Warn
+level = 300 ; Warn
; address directories to resolve email addresses and their f/b source locations
-[directory "ldap-1"]
+
+; try local filesystem first
+[directory "local"]
+type = static
+filter = "@yourdomain"
+fbsource = file:/var/lib/kolab-freebusy/%u.ifb
+
+; local Kolab directory server
+[directory "kolab-ldap"]
type = ldap
-host = ldaps://somehost.tld:389
-bind_dn = "uid=anonymous,o=somehost,o=tld"
-bind_pw = <password>
+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=%u)(mail=%u)(alias=%u)))"
attributes[] = mail
fbsource = file:/www/kolab-freebusy/data/%mail.ifb
commit 430a941da05ef9ce8889d916ef82a8703c1a8960
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Wed Jan 16 17:51:02 2013 +0100
Don't return current URL
diff --git a/web/index.php b/web/index.php
index 6f82d91..41286da 100644
--- a/web/index.php
+++ b/web/index.php
@@ -96,13 +96,6 @@ if ($config->isValid()) {
// Should probably be a setting. For now, do 16 weeks into the future
$end = $now + (60 * 60 * 24 * 7 * 16);
- $urlschema = 'http';
- if ((!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') ||
- (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') ||
- $_SERVER['SERVER_PORT'] == '443') {
- $urlschema = 'https';
- }
-
// Return an apparent empty Free/Busy list.
print "BEGIN:VCALENDAR\n";
print "VERSION:2.0\n";
@@ -111,7 +104,6 @@ if ($config->isValid()) {
print "BEGIN:VFREEBUSY\n";
print "ORGANIZER:MAILTO:" . $user . ".ifb\n";
print "DTSTAMP:" . gmdate($dtformat) . "\n";
- print "URL:$urlschema://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n";
print "DTSTART:" . gmdate($dtformat, $start) . "\n";
print "DTEND:" . gmdate($dtformat, $end) . "\n";
print "COMMENT:This is a dummy vfreebusy that indicates an empty calendar\n";
More information about the commits
mailing list