summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-30 11:52:34 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-30 11:52:34 +0100
commit171b2d1f1e104c9c1110a722c7bc62fe1c407c8f (patch)
treeb3afa6e83b2ddad39f3f5dc3570fc6453ac7411a
parentc4dc4b95a25ff2961f8ec8339e28e7a33f72869a (diff)
downloadwebadmin-171b2d1f1e104c9c1110a722c7bc62fe1c407c8f.tar.gz
Improve configuration handling
-rw-r--r--lib/Auth/LDAP.php15
-rw-r--r--lib/Conf.php38
2 files changed, 42 insertions, 11 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 3c2e96e..7c5b658 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -64,8 +64,19 @@ class LDAP
{
$this->conf = Conf::get_instance();
+ // See if we are to connect to any domain explicitly defined.
+ if (!isset($domain) || empty($domain)) {
+ // If not, attempt to get the domain from the session.
+ if (isset($_SESSION['user'])) {
+ $domain = $_SESSION['user']->get_domain();
+ }
+ }
+
+ // Continue and default to the primary domain.
$this->domain = $domain ? $domain : $this->conf->get('primary_domain');
- $this->_ldap_uri = $this->conf->get('uri');
+
+ $this->_ldap_uri = $this->conf->get('ldap_uri');
+
$this->_ldap_server = parse_url($this->_ldap_uri, PHP_URL_HOST);
$this->_ldap_port = parse_url($this->_ldap_uri, PHP_URL_PORT);
$this->_ldap_scheme = parse_url($this->_ldap_uri, PHP_URL_SCHEME);
@@ -955,7 +966,7 @@ class LDAP
if (empty($search) || !is_array($search) || empty($search['params'])) {
return null;
}
-
+
$filter = '';
foreach ((array) $search['params'] as $field => $param) {
$value = self::_quote_string($param['value']);
diff --git a/lib/Conf.php b/lib/Conf.php
index 704c3c4..d843cdd 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -99,19 +99,39 @@ class Conf {
}
}
- // Simple (global) settings may be obtained by calling the key and omitting
- // the section. This goes for sections 'kolab', and whatever is the equivalent
- // of 'kolab', 'auth_mechanism'.
-// echo "<pre>";
-// print_r($this->_conf);
-// echo "</pre>";
+ // Simple (global) settings may be obtained by calling the key and
+ // omitting the section. This goes for sections 'kolab', and whatever
+ // is the equivalent of 'kolab', 'auth_mechanism', such as getting
+ // 'ldap_uri', which is in the [$domain] section, or in section 'ldap',
+ // and we can try and iterate over it.
+
+ // First, try the most exotic.
+ if (isset($_SESSION['user'])) {
+ $domain_section_name = $_SESSION['user']->get_domain();
+ if (isset($this->_conf[$domain_section_name][$key1])) {
+ return $this->_conf[$domain_section_name][$key1];
+ }
+ }
+
+ // Fall back to whatever is the equivalent of auth_mechanism as the
+ // section (i.e. 'ldap', or 'sql')
+ $auth_mech = $this->_conf['kolab']['auth_mechanism'];
+ if (isset($this->_conf[$auth_mech])) {
+ if (isset($this->_conf[$auth_mech][$key1])) {
+ return $this->_conf[$auth_mech][$key1];
+ }
+ }
+ // Fall back to global settings in the 'kolab' section.
if (isset($this->_conf['kolab'][$key1])) {
return $this->_conf['kolab'][$key1];
}
- else if (isset($this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1])) {
- return $this->_conf[$this->_conf['kolab']['auth_mechanism']][$key1];
- }
+
+ error_log("Could not find setting for \$key1: " . $key1 .
+ " with \$key2: " . $key2
+ );
+
+ return null;
}
public function expand($str, $custom = FALSE)