Code

Updated FAI handling for Templates && Partitions.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 18 Jul 2008 11:42:42 +0000 (11:42 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 18 Jul 2008 11:42:42 +0000 (11:42 +0000)
- Partitions do not work anymore, but i'm working on it.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@11712 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
gosa-plugins/fai/admin/fai/class_faiTemplate.inc

index 20f40827968a50e937c8feaec3fcea3045844559..1beba24fe3f7ce9fd4729e4e80d4c2a266265d0b 100644 (file)
@@ -7,6 +7,10 @@ class faiPartitionTable extends plugin
   var $attributes       = array("cn","description");
   var $objectclasses    = array("top","FAIclass","FAIpartitionTable");
 
+  var $subAttributes = array("cn","description","FAIpartitionNr");
+  var $sub64coded = array();
+  var $subBinary = array();
+
   /* Specific attributes */
   var $cn               = "";       // The class name for this object
   var $description      = "";       // The description for this set of partitions
@@ -23,71 +27,36 @@ class faiPartitionTable extends plugin
     /* Load Attributes */
     plugin::plugin ($config, $dn);
 
-    $this->acl ="#all#";
-
-    $this->ui = get_userinfo();    
-
     /* If "dn==new" we try to create a new entry
      * Else we must read all objects from ldap which belong to this entry.
-     * First read disks from ldap ... and then the partition definitions for the disks.
      */
+    $this->ui = get_userinfo();
     if($dn != "new"){
       $this->dn =$dn;
 
-      /* Read all disks from ldap taht are defined fot this partition table 
+      /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $ldap = $this->config->get_ldap_link();
-      $ldap->cd ($this->dn);
-      $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*"));
-      while($object = $ldap->fetch()){
-
-        /* Skip objects, that are tagged as removed */
-        if(isset($object['FAIstate'][0])){
-          if(preg_match("/removed$/",$object['FAIstate'][0])){
-            continue;
-          }
-        }
-
-        $this->disks[$object['cn'][0]]['status']      = "edited";
-        $this->disks[$object['cn'][0]]['dn']          = $object['dn'];
-        $this->disks[$object['cn'][0]]['cn']          = $object['cn'][0];
-        if(isset($object['description'][0])){
-          $this->disks[$object['cn'][0]]['description'] = $object['description'][0];
-        }else{
-          $this->disks[$object['cn'][0]]['description'] = "";
-        }
-        $this->disks[$object['cn'][0]]['partitions']   = array();
+      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=FAIpartitionTable))");
+      foreach($res as $obj){
+        $objects = array();
+        $objects['status']      = "edited";
+        $objects['dn']          = $obj['dn'];
+        $objects                = $this->get_object_attributes($objects,$this->subAttributes);
+        $this->disks[$objects['cn']] = $objects;
       }
-  
+
       /* read all partitions for each disk 
        */
       foreach($this->disks as $name => $disk){
-        $ldap->cd ($disk['dn']);
-        $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))",array("*"));
-        while($partition = $ldap->fetch()){
-
-          /* Skip objects, that are tagged as removed */
-          if(isset($partition['FAIstate'][0])){
-            if(preg_match("/removed$/",$partition['FAIstate'][0])){
-              continue;
-            }
-          }
 
-          /* remove count ... from ldap result 
-           */
-          foreach($partition as $key=>$val){
-            if((is_numeric($key))||($key=="count")||($key=="dn")){
-              unset($partition[$key]);
-            }else{
-              $partition[$key] = $val[0];
-            }
-          }
-
-          /* Append fetched partitions
-           */
-          $partition['status']="edited";
-          $this->disks[$name]['partitions'][$partition['FAIpartitionNr']] = $partition; 
-        }  
+        $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
+        foreach($res as $obj){
+          $objects = array();
+          $objects['status']      = "edited";
+          $objects['dn']          = $obj['dn'];
+          $objects                = $this->get_object_attributes($objects,$this->subAttributes);
+          $this->disks[$name]['partitions'][$objects['cn']] = $objects;
+        }
       }
     }
     $this->is_new = FALSE;
@@ -116,6 +85,8 @@ class faiPartitionTable extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    print_a($this->disks);
+
     if($this->is_account && !$this->view_logged){
       $this->view_logged = TRUE;
       new log("view","fai/".get_class($this),$this->dn);
@@ -617,6 +588,37 @@ class faiPartitionTable extends plugin
       $this->cn = get_post('cn');
     }
   }
+
+  /* Reload some attributes */
+  function get_object_attributes($object,$attributes)
+  {
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->cat($object['dn'],$attributes);
+    $tmp  = $ldap->fetch();
+
+    foreach($attributes as $attrs){
+      if(isset($tmp[$attrs][0])){
+        $var = $tmp[$attrs][0];
+
+        /* Check if we must decode some attributes */
+        if(in_array_ics($attrs,$this->sub64coded)){
+          $var = base64_decode($var);
+        }
+
+        /*  check if this is a binary entry */
+        if(in_array_ics($attrs,$this->subBinary)){
+          $var = $ldap->get_attribute($object['dn'], $attrs,$r_array=0);
+        }
+
+        /* Fix slashes */
+        $var = addslashes($var);
+        $object[$attrs] = $var;
+      }
+    }
+    return($object);
+  }
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 75ee77434948fb8f7fcae7108fac6ade8be0e479..a96de25dd1116699eed4cb7299383c2e7e63b18f 100644 (file)
@@ -48,30 +48,11 @@ class faiTemplate extends plugin
 
       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $ldap     = $this->config->get_ldap_link();
-      $ldap->cd ($this->dn);
-    
-      $attrs_to_search = $this->subAttributes;
-      $attrs_to_search[] = "FAIstate";
-      $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))",$attrs_to_search);
-
-      $data = array();
-      while($object = $ldap->fetch()){
-        $data[] = $object;
-      }
-      foreach($data as $object){
-
-        /* Skip objects, that are tagged as removed */
-        if(isset($object['FAIstate'][0])){
-          if(preg_match("/removed$/",$object['FAIstate'][0])){
-            continue;
-          }
-        }
-
-        /* Set status for save management */
+      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+      foreach($res as $obj){
         $objects = array();
         $objects['status']      = "FreshLoaded";
-        $objects['dn']          = $object['dn'];
+        $objects['dn']          = $obj['dn'];
         $objects                = $this->get_object_attributes($objects,$this->subAttributes);
         $this->SubObjects[$objects['cn']] = $objects;
       }