Code

Added pChart classes and GOsa mapping class to enable auto-include
[gosa.git] / gosa-core / include / class_ldap.inc
index 1a991f1b6e122ba7466593abe2bd1ec1336cda9a..bac40e5e07fd0a947cc96ca68801d06d1f1feb2b 100644 (file)
@@ -60,8 +60,8 @@ class LDAP{
     $this->hostname=$hostname;
 
     /* Check if MAX_LDAP_QUERY_TIME is defined */ 
-    if(is_object($config) && $config->get_cfg_value("ldapMaxQueryTime") != ""){
-      $str = $config->get_cfg_value("ldapMaxQueryTime");
+    if(is_object($config) && $config->get_cfg_value("core","ldapMaxQueryTime") != ""){
+      $str = $config->get_cfg_value("core","ldapMaxQueryTime");
       $this->max_ldap_query_time = (float)($str);
     }
 
@@ -235,6 +235,10 @@ class LDAP{
       }
 
       $this->log("LDAP operation: time=".(microtime(true)-$start)." operation=search('".LDAP::fix($this->basedn)."', '$filter')");
+
+      // Create statistic table entry 
+      stats::log('ldap', $class = get_class($this), $category = array(),  $action = __FUNCTION__, 
+              $amount = 1, $duration = (microtime(TRUE) - $start));
       return($this->sr[$srp]);
     }else{
       $this->error = "Could not connect to LDAP server";
@@ -269,6 +273,10 @@ class LDAP{
 
       $this->log("LDAP operation: time=".(microtime(true) - $start)." operation=ls('".LDAP::fix($basedn)."', '$filter')");
 
+      // Create statistic table entry 
+      stats::log('ldap', $class = get_class($this), $category = array(),  $action = __FUNCTION__, 
+              $amount = 1, $duration = (microtime(TRUE) - $start));
+
       return($this->sr[$srp]);
     }else{
       $this->error = "Could not connect to LDAP server";
@@ -584,12 +592,17 @@ class LDAP{
       return (0);
     }
     if($this->hascon){
+      $start = microtime(TRUE);
       if ($this->reconnect) $this->connect();
       $r = @ldap_modify($this->cid, LDAP::fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
       if(!$this->success()){
         $this->error.= $this->makeReadableErrors($this->error,$attrs);
       }
+
+      // Create statistic table entry 
+      stats::log('ldap', $class = get_class($this), $category = array(),  $action = __FUNCTION__, 
+              $amount = 1, $duration = (microtime(TRUE) - $start));
       return($r ? $r : 0);
     }else{
       $this->error = "Could not connect to LDAP server";
@@ -600,12 +613,18 @@ class LDAP{
   function add($attrs)
   {
     if($this->hascon){
+      $start = microtime(TRUE);
       if ($this->reconnect) $this->connect();
       $r = @ldap_add($this->cid, LDAP::fix($this->basedn), $attrs);
       $this->error = @ldap_error($this->cid);
       if(!$this->success()){
         $this->error.= $this->makeReadableErrors($this->error,$attrs);
       }
+
+      // Create statistic table entry 
+      stats::log('ldap', $class = get_class($this), $category = array(),  $action = __FUNCTION__, 
+              $amount = 1, $duration = (microtime(TRUE) - $start));
+
       return($r ? $r : 0);
     }else{
       $this->error = "Could not connect to LDAP server";
@@ -857,16 +876,29 @@ class LDAP{
   }
 
 
+  /*! \brief  Generates an ldif for all entries matching the filter settings, scope and limit.
+   *  @param  $dn           The entry to export.
+   *  @param  $filter       Limit the exported object to those maching this filter.
+   *  @param  $attributes   Specify the attributes to export here, empty means all.
+   *  @param  $scope        'base', 'sub' .. see manpage for 'ldapmodify' for details.
+   *  @param  $limit        Limits the result.
+   */
   function generateLdif ($dn, $filter= "(objectClass=*)", $attributes= array(), $scope = 'sub', $limit=0)
   {
-    $host = $this->hostname;
-    $attrs  = (count($attributes))?implode($attributes,' '):'';
-    $scope = (!empty($scope))?' -s '.$scope: '';
-    $limit = (!$limit)?'':' -z '.$limit;
-    $cmd = "ldapsearch -x -LLLL '{$filter}' {$limit} {$scope} -H '{$host}' -b '{$dn}' $attrs";
-    exec($cmd, $ret,$code);
-    $res = implode($ret,"\n");
-    return($res);
+      $attrs  = (count($attributes))?implode($attributes,' '):'';
+      $scope = (!empty($scope))?' -s '.$scope: '';
+      $limit = (!$limit)?'':' -z '.$limit;
+      $dn = escapeshellarg($dn);
+      $admin = escapeshellarg($this->binddn);
+      $pwd = escapeshellarg($this->bindpw);
+      $filter = escapeshellarg($filter);
+      $host = escapeshellarg($this->hostname);
+      $cmd = "ldapsearch -x -LLLL -D {$admin} -w {$pwd} {$filter} {$limit} {$scope} -H {$host} -b {$dn} $attrs ";
+      ob_start();
+      passthru($cmd);
+      $res=ob_get_contents();
+      ob_end_clean();
+      return($res);
   }
 
 
@@ -1191,13 +1223,6 @@ class LDAP{
     $objectclasses = array();
     global $config;
 
-    /* Only read schema if it is allowed */
-    if(isset($config) && preg_match("/config/i",get_class($config))){
-      if ($config->get_cfg_value("schemaCheck") != "true"){
-        return($objectclasses);
-      } 
-    }
-
     /* Return the cached results. */
     if(class_available('session') && session::global_is_set("LDAP_CACHE::get_objectclasses") && !$force_reload){
       $objectclasses = session::global_get("LDAP_CACHE::get_objectclasses");