lib/Auth lib/Conf.php lib/ext

Aleksander Machniak machniak at kolabsys.com
Fri Sep 13 13:49:42 CEST 2013


 lib/Auth/LDAP.php     |    9 ++-------
 lib/Conf.php          |   32 ++++++++++++++++++++++++++++++++
 lib/ext/Net/LDAP3.php |    3 ++-
 3 files changed, 36 insertions(+), 8 deletions(-)

New commits:
commit 91afe32e589c11f498aee999ce15c4e517b9c1b0
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Sep 13 13:48:45 2013 +0200

    Support kolab_wap.vlv configuration option

diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index e4245c5..5a9a8a8 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -46,17 +46,12 @@ class LDAP extends Net_LDAP3 {
         $this->config_set("debug", true);
         $this->config_set("log_hook", array($this, "_log"));
 
-        //$this->config_set("vlv", false);
         $this->config_set("config_root_dn", "cn=config");
-
         $this->config_set("service_bind_dn", $this->conf->get("service_bind_dn"));
         $this->config_set("service_bind_pw", $this->conf->get("service_bind_pw"));
 
-        $login_filter = $this->conf->get("kolab_wap", "login_filter");
-
-        if (!empty($login_filter)) {
-            $this->config_set("login_filter", $login_filter);
-        }
+        $this->config_set("login_filter", $this->conf->get("kolab_wap", "login_filter"));
+        $this->config_set("vlv", $this->conf->get("kolab_wap", "vlv", Conf::AUTO));
 
         // See if we are to connect to any domain explicitly defined.
         if (empty($domain)) {
diff --git a/lib/Conf.php b/lib/Conf.php
index 6131850..82c3eea 100644
--- a/lib/Conf.php
+++ b/lib/Conf.php
@@ -34,6 +34,7 @@ class Conf {
     const BOOL   = 1;
     const INT    = 2;
     const FLOAT  = 3;
+    const AUTO   = 4;
 
     /**
      * This implements the 'singleton' design pattern
@@ -70,10 +71,15 @@ class Conf {
         switch ($type) {
             case self::INT:
                 return intval($value);
+
             case self::FLOAT:
                 return floatval($value);
+
             case self::BOOL:
                 return (bool) preg_match('/^(true|1|on|enabled|yes)$/i', $value);
+
+            case self::AUTO:
+                return $this->auto($value);
         }
 
         return (string) $value;
@@ -225,4 +231,30 @@ class Conf {
             }
         }
     }
+
+    /**
+     * Auto-detection and conversion of config value
+     */
+    private function auto($value)
+    {
+        if (preg_match('/^(true|on|enabled|yes|false|off|disabled|no)$/i', $value)) {
+            return (bool) preg_match('/^(true|on|enabled|yes)$/i', $value);
+        }
+
+        if (is_numeric($value)) {
+            if (strpos($value, '.')) {
+                return floatval($value);
+            }
+            else {
+                return intval($value);
+            }
+        }
+
+        // array in JSON format
+        if ($value[0] == '{' || $value[0] == '[') {
+             return json_decode($value, true);
+        }
+
+        return (string) $value;
+    }
 }
diff --git a/lib/ext/Net/LDAP3.php b/lib/ext/Net/LDAP3.php
index 4977aa4..6e0ccc6 100644
--- a/lib/ext/Net/LDAP3.php
+++ b/lib/ext/Net/LDAP3.php
@@ -1899,7 +1899,8 @@ class Net_LDAP3
         if (isset($this->config['vlv'])) {
             if ($this->config['vlv'] === false) {
                 return array();
-            } else {
+            }
+            else if (is_array($this->config['vlv'])) {
                 return $this->config['vlv'];
             }
         }




More information about the commits mailing list