Code

Updated FAI function.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Jan 2008 11:18:13 +0000 (11:18 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Jan 2008 11:18:13 +0000 (11:18 +0000)
-Moved function_FAI.inc to plugins/admin/fai
-Created a class containing all fai helper functions. For dynamic class inclusion.

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

14 files changed:
gosa-core/html/main.php
gosa-core/include/functions_FAI.inc [deleted file]
gosa-core/plugins/admin/fai/class_faiHook.inc
gosa-core/plugins/admin/fai/class_faiManagement.inc
gosa-core/plugins/admin/fai/class_faiPackage.inc
gosa-core/plugins/admin/fai/class_faiPartitionTable.inc
gosa-core/plugins/admin/fai/class_faiProfile.inc
gosa-core/plugins/admin/fai/class_faiProfileEntry.inc
gosa-core/plugins/admin/fai/class_faiScript.inc
gosa-core/plugins/admin/fai/class_faiSummaryTab.inc
gosa-core/plugins/admin/fai/class_faiTemplate.inc
gosa-core/plugins/admin/fai/class_faiVariable.inc
gosa-core/plugins/admin/fai/functions_FAI.inc [new file with mode: 0644]
gosa-core/plugins/admin/systems/class_workstationStartup.inc

index 56f5aa89749deaac493cb8287d31667e69116b3e..fda4f5b6f174a06d3ddfa3daba9a7246afe2c4b9 100644 (file)
@@ -24,7 +24,6 @@ $start = microtime();
 /* Basic setup, remove eventually registered sessions */
 require_once ("../include/php_setup.inc");
 require_once ("functions.inc");
-require_once ("functions_FAI.inc");
 
 /* Set header */
 header("Content-type: text/html; charset=UTF-8");
diff --git a/gosa-core/include/functions_FAI.inc b/gosa-core/include/functions_FAI.inc
deleted file mode 100644 (file)
index b954d61..0000000
+++ /dev/null
@@ -1,738 +0,0 @@
-<?php
-
-define("DEBUG_FAI_FUNC",FALSE);
-
-/* TEST PHASE .... */
-
-/* Returns all object for the given release.
-   This function resolves the releases  
-   from base up to the given dn.
- */
-function get_all_objects_for_given_base($Current_DN,$filter,$detailed = false)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $res = array();
-  $tmp = array();
-
-  if(!is_release_department($Current_DN)) {
-    return($res);
-  }
-
-  /* Collect some basic informations and initialize some variables */ 
-  $base_release       = get_release_dn($Current_DN);
-  $previous_releases  = array_reverse(get_previous_releases_of_this_release($base_release,true));
-
-  /* We must also include the given release dn */
-  $previous_releases[] = $base_release;
-
-  /* Walk through all releases */
-  foreach($previous_releases as $release){
-
-    /* Get fai departments */
-    $deps_to_search = get_FAI_departments($release); 
-
-    /* For every single department  (ou=hoos,ou ..) */
-    foreach($deps_to_search as $fai_base){
-
-      /* Ldap search for fai classes specified in this release */
-      $attributes  = array("dn","objectClass","FAIstate","cn");
-      $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH | GL_SIZELIMIT);
-  
-      /* check the returned objects, and add/replace them in our return variable */
-      foreach($res_tmp as $attr){
-        
-        $buffer = array();
-        $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']);
-
-        if(isset($attr['FAIstate'][0])){
-          if(preg_match("/removed$/",$attr['FAIstate'][0])){
-            if(isset($res[$name])){
-              unset($res[$name]);
-            }
-            continue;
-          }
-        }
-
-        /* In detailed mode are some additonal informations visible */
-        if($detailed){
-
-          /* Create list of parents */
-          if(isset($res[$name])){
-            $buffer = $res[$name];
-            $buffer['parents'][] = $res[$name]['dn'];
-          }else{
-            $buffer['parents'] = array();
-          }
-
-          /* Append objectClass to resulsts */
-          foreach($attributes as $val){
-            if(isset($attr[$val])){
-              $buffer[$val] = $attr[$val];
-            }
-          }
-          unset($buffer['objectClass']['count']);
-        }
-
-        /* Add this object to our list */
-        $buffer['dn']           = $attr['dn'];
-        $res[$name] = $buffer;
-      }
-    }
-  }
-  return($res);
-}
-
-
-/* Return all relevant FAI departments */
-function get_FAI_departments($suffix = "")
-{
-  $arr = array("hooks","scripts","disk","packages","profiles","templates","variables");
-  $tmp = array();
-  if(preg_match("/^,/",$suffix)){
-    $suffix = preg_replace("/^,/","",$suffix);
-  }
-  foreach($arr as $name){
-    if(empty($suffix)){
-      $tmp[$name] = "ou=".$name;
-    }else{
-      $tmp[$name] = "ou=".$name.",".$suffix;
-    }
-  }
-  return($tmp);
-}
-
-
-/* Return all releases within the given base */
-function get_all_releases_from_base($dn,$appendedName=false)
-{
-  global $config;
-    
-  if(!preg_match("/".normalizePreg(get_ou('faiou'))."/",$dn)){
-    $base = get_ou('faiou').$dn;
-  }else{
-    $base = $dn;
-  }
-  $res = array();  
-  
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($base);
-  $ldap->search("(objectClass=FAIbranch)",array("ou","dn"));
-  while($attrs = $ldap->fetch()){
-    if($appendedName){
-      $res[$attrs['dn']] = convert_department_dn(preg_replace("/,".normalizePreg(get_ou('faiou')).".*$/","",$attrs['dn']));
-    }else{
-      $res[$attrs['dn']] = $attrs['ou'][0];
-    }
-  }
-  return($res);
-}
-
-
-/* Add this object to list of objects, that must be checked for release saving */
-function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false)
-{
-  /* Get ldap object */  
-  global $config;
-  $addObj['Current_DN'] = $Current_DN;
-  $addObj['objectAttrs']= $objectAttrs;
-  $addObj['removed']    = $removed;
-  $addObj['diff']       = TRUE;
-
-  if(!$removed){
-    $ldap = $config->get_ldap_link();
-    $ldap->cd($config->current['BASE']);
-
-    /* Get some basic informations */
-    $parent_obj   = get_parent_release_object($Current_DN);
-    if(!empty($parent_obj)){
-      $ldap->cat($parent_obj,array("*"));
-      $attrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
-
-      if(!array_diff_FAI( $attrs,$objectAttrs)){
-        $addObj['diff'] = FALSE;
-      }
-    } 
-  }
-  $FAI_objects_to_save = session::get('FAI_objects_to_save') ;
-  $FAI_objects_to_save[$Current_DN] =  $addObj;
-  session::set('FAI_objects_to_save',$FAI_objects_to_save);
-}
-
-
-/* Detect differences in attribute arrays  */
-function array_diff_FAI($ar1,$ar2)
-{
-
-  if((!isset($ar1['description'])) || (isset($ar1['description']) && (count($ar1['description']) == 0))){
-    $ar1['description'] = "";
-  }
-  if((!isset($ar2['description'])) || (isset($ar2['description']) && (count($ar2['description']) == 0))){
-    $ar2['description'] = "";
-  }
-
-  if(count($ar1) != count($ar2)) {
-    return (true);
-  }
-
-  foreach($ar1 as $key1 => $val1){
-
-    if((is_array($val1)) && (count($val1)==1)){
-      $ar1[$key1] = $val1[0];
-    }
-
-    if((is_array($ar2[$key1])) && (count($ar2[$key1])==1)){
-      $val1 = $val1[0];
-      $ar2[$key1] = $ar2[$key1][0];
-    }
-  }
-  ksort($ar1);
-  ksort($ar2);
-  if(count( array_diff($ar1,$ar2)) || arr_diff($ar1,$ar2)){
-    return(true);
-  }else{
-    return(false);
-  }
-}
-
-
-function arr_diff($ar1,$ar2)
-{
-  foreach($ar1 as $ak1 => $av1){
-    if(!isset($ar2[$ak1]) || (!($av1 === $ar2[$ak1]))){
-      return(true);
-    }elseif(is_array($av1)){
-      return(arr_diff($av1,$ar2[$ak1]));
-    }
-  }
-  return(FALSE);
-}
-
-
-
-
-/* check which objects must be saved, and save them */
-function save_release_changes_now()
-{
-  /* Variable init*/
-  $to_save = array();
-
-  /* check which objects must be saved */
-  $FAI_objects_to_save = session::get('FAI_objects_to_save');
-  foreach($FAI_objects_to_save as $Current_DN => $object){
-    if($object['diff']){
-      $sub_name = $Current_DN;
-      while(isset($FAI_objects_to_save[$sub_name])){
-        $to_save[strlen($sub_name)][$sub_name] = $FAI_objects_to_save[$sub_name]; 
-        unset($FAI_objects_to_save[$sub_name]);
-        $sub_name = preg_replace('/^[^,]+,/', '', $sub_name);
-      }
-    }
-  }
-  session::set('FAI_objects_to_save',$FAI_objects_to_save);
-
-  /* Sort list of objects that must be saved, and ensure that 
-      container   objects are safed, before their childs are saved */
-  ksort($to_save);
-  $tmp = array();
-  foreach($to_save as $SubObjects){
-    foreach($SubObjects as $object){
-      $tmp[] = $object;
-    }
-  }
-  $to_save = $tmp;
-
-  /* Save objects and manage the correct release behavior*/
-  foreach($to_save as $save){
-
-    $Current_DN = $save['Current_DN'];
-    $removed    = $save['removed'];
-    $objectAttrs= $save['objectAttrs'];
-
-    /* Get ldap object */ 
-    global $config;
-    $ldap = $config->get_ldap_link();
-    $ldap->cd($config->current['BASE']);
-
-    /* Get some basic informations */
-    $base_release       = get_release_dn($Current_DN);
-    $sub_releases       = get_sub_releases_of_this_release($base_release,true);
-    $parent_obj         = get_parent_release_object($Current_DN);
-    $following_releases = get_sub_releases_of_this_release($base_release,true);
-    
-    /* Check if given dn exists or if is a new entry */
-    $ldap->cat($Current_DN);
-    if(!$ldap->count()){
-      $is_new = true;
-    }else{
-      $is_new = false;
-    }
-   
-    /* if parameter removed is true, we have to add FAIstate to the current attrs 
-          FAIstate should end with ...|removed after this operation */  
-    if($removed ){
-      $ldap->cat($Current_DN);
-
-      /* Get current object, because we must add the FAIstate ...|removed */
-      if((!$ldap->count()) && !empty($parent_obj)){
-        $ldap->cat($parent_obj);
-      }
-
-      /* Check if we have found a suiteable object */ 
-      if(!$ldap->count()){
-        echo "Error can't remove this object ".$Current_DN;
-        return;
-      }else{
-
-        /* Set FAIstate to current objectAttrs */
-        $objectAttrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
-        if(isset($objectAttrs['FAIstate'][0])){
-          if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){
-            $objectAttrs['FAIstate'][0] .= "|removed";
-          }
-        }else{
-          $objectAttrs['FAIstate'][0] = "|removed";
-        }
-      }
-    }
-   
-    /* Check if this a leaf release or not */ 
-    if(count($following_releases) == 0 ){
-
-      /* This is a leaf object. It isn't inherited by any other object */    
-      if(DEBUG_FAI_FUNC) { 
-        echo "<b>Saving directly, is a leaf object</b><br> ".$Current_DN;
-        print_a($objectAttrs);
-      }
-      save_FAI_object($Current_DN,$objectAttrs);
-    }else{
-
-      /* This object is inherited by some sub releases */  
-
-      /* Get all releases, that inherit this object */ 
-      $r = get_following_releases_that_inherit_this_object($Current_DN);
-
-      /* Get parent object */
-      $ldap->cat($parent_obj);
-      $parent_attrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
-        
-      /* New objects require special handling */
-      if($is_new){
-
-        /* check if there is already an entry named like this,
-            in one of our parent releases */
-        if(!empty($parent_obj)){
-          if(DEBUG_FAI_FUNC) { 
-            echo "There is already an entry named like this.</b><br>";
-
-            echo "<b>Saving main object</b>".$Current_DN;
-            print_a($objectAttrs);
-          }    
-          save_FAI_object($Current_DN,$objectAttrs);
-
-          foreach($r as $key){
-            if(DEBUG_FAI_FUNC) { 
-              echo "<b>Saving parent to following release</b> ".$key;
-              print_a($parent_attrs);
-            }
-            save_FAI_object($key,$parent_attrs);
-          }
-        }else{
-
-          if(DEBUG_FAI_FUNC) { 
-            echo "<b>Saving main object</b>".$Current_DN;
-            print_a($objectAttrs);
-          }
-          save_FAI_object($Current_DN,$objectAttrs);
-
-          if(isset($objectAttrs['FAIstate'])){
-            $objectAttrs['FAIstate'] .= "|removed"; 
-          }else{
-            $objectAttrs['FAIstate'] = "|removed";
-          }
-
-          foreach($r as $key ){
-            if(DEBUG_FAI_FUNC) { 
-              echo "<b>Create an empty placeholder in follwing release</b> ".$key; 
-              print_a($objectAttrs);
-            }
-            save_FAI_object($key,$objectAttrs);
-          }
-        }
-      }else{
-
-        /* check if we must patch the follwing release */
-        if(!empty($r)){
-          foreach($r as $key ){
-            if(DEBUG_FAI_FUNC) { 
-              echo "<b>Copy current objects original attributes to next release</b> ".$key;
-              print_a($parent_attrs);
-            }
-            save_FAI_object($key,$parent_attrs);
-          }
-        }
-
-        if(DEBUG_FAI_FUNC) { 
-          echo "<b>Saving current object</b>".$parent_obj;
-          print_a($objectAttrs);
-        }
-        save_FAI_object($parent_obj,$objectAttrs);
-
-        if(($parent_obj != $Current_DN)){
-          msg_dialog::display(_("Error"), sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN), ERROR_DIALOG);
-        }
-      }
-    }
-  } 
-  session::set('FAI_objects_to_save',array());
-}
-
-
-/* this function will remove all unused (deleted) objects,
-    that have no parent object */
-function clean_up_releases($Current_DN)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-
-  /* Collect some basic informations and initialize some variables */ 
-  $base_release       = get_release_dn($Current_DN);
-  $previous_releases  = array_reverse(get_previous_releases_of_this_release($base_release,true));
-  $Kill = array();
-  $Skip = array();
-
-  /* We must also include the given release dn */
-  $previous_releases[] = $base_release;
-
-  /* Walk through all releases */
-  foreach($previous_releases as $release){
-
-    /* Get fai departments */
-    $deps_to_search = get_FAI_departments($release); 
-
-    /* For every single department  (ou=hoos,ou ..) */
-    foreach($deps_to_search as $fai_base){
-
-      /* Ldap search for fai classes specified in this release */
-      $ldap->cd($fai_base);
-      $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate"));
-
-      /* check the returned objects, and add/replace them in our return variable */
-      while($attr = $ldap->fetch()){
-        
-        $buffer = array();
-#        $name = str_ireplace($release,"",$attr['dn']);
-        $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']);
-
-        if(isset($attr['FAIstate'][0])&&(preg_match("/removed$/",$attr['FAIstate'][0]))){
-
-          /* Check if this object is required somehow */    
-          if(!isset($Skip[$name])){
-            $Kill[$attr['dn']] = $attr['dn'];
-          }
-        }else{
-      
-          /* This object is required (not removed), so do not 
-              delete any following sub releases of this object */
-          $Skip[$name] = $attr['dn'];
-        }
-      }
-    }
-  }
-  return($Kill);
-}
-
-
-/* Remove numeric index and 'count' from ldap->fetch result */
-function prepare_ldap_fetch_to_be_saved($attrs)
-{
-  foreach($attrs as $key => $value){
-    if(is_numeric($key) || ($key == "count") || ($key == "dn")){
-      unset($attrs[$key]);
-    }
-    if(is_array($value) && isset($value['count'])){
-      unset($attrs[$key]['count']);
-    }
-  }
-  return($attrs);
-}
-
-
-/* Save given attrs to specified dn*/
-function save_FAI_object($dn,$attrs)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn));
-  $ldap->cd($dn);
-  $ldap->cat($dn,array("dn"));
-  if($ldap->count()){
-
-    /* Remove FAIstate*/
-    if(!isset($attrs['FAIstate'])){
-      $attrs['FAIstate'] = array();
-    }
-
-    $ldap->modify($attrs);
-  }else{
-  
-    /* Unset description if empty  */
-    if(empty($attrs['description'])){
-      unset($attrs['description']);
-    }    
-
-    $ldap->add($attrs);
-  }
-  show_ldap_error($ldap->get_error(),sprintf(_("Release management failed, can't save '%s'"),$dn));
-}
-
-
-/* Return FAIstate freeze branch or "" for specified release department */
-function get_release_tag($dn)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($dn);
-  $ldap->cat($dn,array("FAIstate"));
-
-  if($ldap->count()){
-  
-    $attr = $ldap->fetch();
-    if(isset($attr['FAIstate'][0])){
-      if(preg_match("/freeze/",$attr['FAIstate'][0])){
-        return("freeze");
-      }elseif(preg_match("/branch/",$attr['FAIstate'][0])){
-        return("branch");
-      }
-    }
-  }
-  return("");
-}
-
-
-function get_following_releases_that_inherit_this_object($dn)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-
-  $ret = array();
-
-  /* Get base release */
-  $base_release = get_release_dn($dn);
-
-  /* Get previous release dns */
-  $sub_releases = get_sub_releases_of_this_release($base_release);
-
-  /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
-#  $dn_suffix = str_ireplace($base_release,"",$dn);
-  $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn);
-
-  /* Check if given object also exists whitin one of these releases */
-  foreach($sub_releases as $p_release => $name){
-
-    $check_dn = $dn_suffix.$p_release;
-  
-    $ldap->cat($check_dn,array("dn","objectClass"));
-    
-    if($ldap->count()){
-      //return($ret);
-    }else{
-      $ret[$check_dn]=$check_dn;
-    }
-  }
-  return($ret);
-}
-
-
-/* Get previous version of the object dn */
-function get_parent_release_object($dn,$include_myself=true)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $previous_releases= array();
-
-  /* Get base release */
-  $base_release = get_release_dn($dn);
-  if($include_myself){
-    $previous_releases[] = $base_release;  
-  }
-
-  /* Get previous release dns */
-  $tmp = get_previous_releases_of_this_release($base_release,true);
-  foreach($tmp as $release){
-    $previous_releases[] = $release;
-  }
-
-  /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
-#  $dn_suffix = str_ireplace($base_release,"",$dn);
-  $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn);
-    
-  /* Check if given object also exists whitin one of these releases */
-  foreach($previous_releases as $p_release){
-    $check_dn = $dn_suffix.$p_release;
-    $ldap->cat($check_dn,array("dn","objectClass"));
-    
-    if($ldap->count()){
-      return($check_dn);
-    }
-  }
-  return("");
-}
-
-
-/* return release names of all parent releases */
-function get_previous_releases_of_this_release($dn,$flat)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $ret = array();
-
-  /* Explode dns into pieces, to be able to build parent dns */
-  $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$dn));
-
-  if(!is_array($dns_to_check)){
-    return;  
-  }
-
-  /* Unset first entry which represents the given dn */
-  unset($dns_to_check['count']); 
-  unset($dns_to_check[key($dns_to_check)]);
-
-  /* Create dns addresses and check if this dn is a release dn */
-  $id = 0;
-  while(count($dns_to_check)){
-
-    /* build parent dn */
-    $new_dn = "";
-    foreach($dns_to_check as $part){
-      $new_dn .= $part.",";
-    }
-    $new_dn .= $config->current['BASE'];
-
-    /* check if this dn is a release */
-    if(is_release_department($new_dn)){
-      if($flat){
-        $ret[$id] = $new_dn; 
-      }else{
-        $ret = array($new_dn=>$ret); 
-      }
-      $id ++;
-    }else{
-      return($ret);
-    }
-    reset($dns_to_check);
-    unset($dns_to_check[key($dns_to_check)]);
-  }
-  return($ret);
-} 
-
-
-/* This function returns all sub release names, recursivly  */
-function get_sub_releases_of_this_release($dn,$flat = false)
-{
-  global $config;
-  $res  = array();
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $ldap->ls("(objectClass=FAIbranch)",$dn,array("objectClass","dn","ou"));
-  while($attr = $ldap->fetch()){
-
-    /* Append department name */
-    if($flat){
-      $res[$attr['dn']] = $attr['ou'][0];
-    }else{
-      $res[$attr['dn']] = array();
-    }
-
-    /* Get sub release departments of this department */
-    if(in_array("FAIbranch",$attr['objectClass'])) {
-      if($flat){
-        $tmp = get_sub_releases_of_this_release($attr['dn'],$flat);
-        foreach($tmp as $dn => $value){
-          $res[$dn]=$value;
-        }
-      }else{
-        $res[$attr['dn']] = get_sub_releases_of_this_release($attr['dn']);
-      }
-    }
-  }
-  return($res);
-}
-
-
-/* Check if the given department is a release department */
-function is_release_department($dn)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-  $ldap->cat($dn,array("objectClass","ou"));
-
-  /* Check objectClasses and name to check if this is a release department */
-  if($ldap->count()){
-    $attrs = $ldap->fetch();
-                       
-    $ou = "";
-    if(isset($attrs['ou'][0])){
-      $ou = $attrs['ou'][0];   
-    }
-       
-    if((in_array("FAIbranch",$attrs['objectClass'])) || ($ou == "fai")){
-      return($attrs['dn']);
-    }
-  }
-  return(false);
-}
-
-
-/* This function returns the dn of the object release */
-function get_release_dn($Current_DN)
-{
-  global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
-
-  /* Split dn into pices */ 
-  $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$Current_DN));
-
-  if(!is_array($dns_to_check)){
-    return;  
-  }
-
-  /* Use dn pieces, to create sub dns like 
-      ou=test,ou=1,ou=0...
-              ou=1,ou=0...
-                   ou=0... 
-    To check which dn is our release container.
-  */
-  unset($dns_to_check['count']); 
-  while(count($dns_to_check)){
-
-    /* Create dn */
-    $new_dn = "";
-    foreach($dns_to_check as $part){
-      $new_dn .= $part.",";
-    }
-    $new_dn .= $config->current['BASE'];
-
-    /* Check if this dn is a release dn */
-    if(is_release_department($new_dn)){
-      return($new_dn);
-    }
-
-    /* Remove first element of dn pieces */
-    reset($dns_to_check);
-    unset($dns_to_check[key($dns_to_check)]);
-  }
-  return("");
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
index 49b49fb74800082d32d7a8277ac2b2b86b09a0f1..6aa43ba98b2c9382b683c6c5ef03ac8d8940a8fc 100644 (file)
@@ -404,7 +404,7 @@ class faiHook extends plugin
     $ldap->cd ($this->dn);
 
     $faifilter = session::get('faifilter');
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
     if($faifilter['branch'] == "main"){
       $use_dn = $this->dn;
     }
@@ -414,7 +414,7 @@ class faiHook extends plugin
     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
 
     foreach($this->SubObjects as $name => $obj){
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
+      $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
       if($faifilter['branch'] == "main"){
         $use_dn = $obj['dn'];
       }
index 31f7c99cce4586e225bfddcd8f5f9cedc442e738..542d9e7146035ac098df8748bce8aa89438b0e54 100644 (file)
@@ -18,6 +18,7 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+
 class faiManagement extends plugin
 {
        /* Definitions */
@@ -283,8 +284,8 @@ class faiManagement extends plugin
           $this->dialog->by_object[$type[1]]->remove_from_parent ();
           unset ($this->dialog);
           $this->dialog= FALSE;
-          $to_del = clean_up_releases($dn);
-          save_release_changes_now();
+          $to_del = fai_func::clean_up_releases($dn);
+          fai_func::save_release_changes_now();
 
           foreach($to_del as $dn){
             $ldap->rmdir_recursive($dn);
@@ -354,8 +355,8 @@ class faiManagement extends plugin
           $this->dialog->by_object[$type[1]]->remove_from_parent ();
           unset ($this->dialog);
           $this->dialog= FALSE;
-          $to_del = clean_up_releases($this->dn);
-          save_release_changes_now();
+          $to_del = fai_func::clean_up_releases($this->dn);
+          fai_func::save_release_changes_now();
 
           foreach($to_del as $dn){
             $ldap->rmdir_recursive($dn);
@@ -785,7 +786,7 @@ class faiManagement extends plugin
                                }
                        }else{
                                $this->dialog->save();
-        save_release_changes_now();
+        fai_func::save_release_changes_now();
         if (!isset($_POST['edit_apply'])){
           del_lock ($this->dn);
           unset($this->dialog);
@@ -887,7 +888,7 @@ class faiManagement extends plugin
     if(!$base){
       $base = session::get('CurrentMainBase');
     }
-    $tmp = get_all_releases_from_base($base,true);
+    $tmp = fai_func::get_all_releases_from_base($base,true);
     foreach($tmp as $dn => $name){
       $ret[$name]=$dn;
     }
@@ -932,7 +933,7 @@ class faiManagement extends plugin
     $this->base = $base;
     $this->set_acl_base($this->base);
 
-    $this->lock_type = get_release_tag(get_release_dn($base));
+    $this->lock_type = fai_func::get_release_tag(fai_func::get_release_dn($base));
 
     /* Create a new list of FAI object 
      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
@@ -955,7 +956,7 @@ class faiManagement extends plugin
     $filter = "(&(|".$filter.")(cn=$Regex))";
     
     /* Get resolved release dependencies */
-    $tmp = get_all_objects_for_given_base($base,$filter);
+    $tmp = fai_func::get_all_objects_for_given_base($base,$filter);
 
     /* Ge listed ldap objects */
     $ldap = $this->config->get_ldap_link();
@@ -1127,7 +1128,7 @@ class faiManagement extends plugin
       /* Get dialog */
       $data = $this->CopyPasteHandler->execute();
 
-      save_release_changes_now();
+      fai_func::save_release_changes_now();
 
       /* Return dialog data */
       if(!empty($data)){
index cd591d1fdbc364338fc40d8f4f86296ea9597c2a..3e4656b424a530512d89b47e9ecede175b0a8aa7 100644 (file)
@@ -336,7 +336,7 @@ class faiPackage extends plugin
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
 
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
     if($faifilter['branch'] == "main"){
       $use_dn = $this->dn;
     }
@@ -348,7 +348,7 @@ class faiPackage extends plugin
     foreach($this->ConfiguredPackages as $pkgname => $attrs){
       foreach($attrs as $name => $attr){
         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
-        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $pkgdn);
+        $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $pkgdn);
         if($faifilter['branch'] == "main"){
           $use_dn = $obj['dn'];
         }
index f75117cd2f7876bc0c46f78fc4852f8fb8218485..29d3c86c94988648e1d863cfb0da82c2a2e5bb8a 100644 (file)
@@ -346,7 +346,7 @@ class faiPartitionTable extends plugin
     $ldap->cd ($this->dn);
 
     $faifilter = session::get('faifilter');
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
     if($faifilter['branch'] == "main"){
       $use_dn = $this->dn;
     }
@@ -358,7 +358,7 @@ class faiPartitionTable extends plugin
     foreach($this->disks as $disk){
 
       $disk_dn = "cn=".$disk['cn'].",".$this->dn;
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $disk_dn);
+      $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $disk_dn);
       if($faifilter['branch'] == "main"){
         $use_dn = $disk_dn;
       }
@@ -367,7 +367,7 @@ class faiPartitionTable extends plugin
       foreach($disk['partitions'] as $key => $partition){    
      
         $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;      
-        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $partition_dn);
+        $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $partition_dn);
         if($faifilter['branch'] == "main"){
           $use_dn = $disk_dn;
         }
index a2f86663d42210a6e924f202121571b147ac3f1d..fb6d1877e5bd54a93a50a389f0100784cbc80232 100644 (file)
@@ -370,7 +370,7 @@ class faiProfile extends plugin
     $ldap->cd ($this->dn);
 
     $faifilter = session::get('faifilter');
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
     if($faifilter['branch'] == "main"){
       $use_dn = $this->dn;
     }
index 81c781cfdf50e3a09d01377a6238fec94b34c992..38dc606b69eb0736ccb833f000580c01931fb8ab 100644 (file)
@@ -32,7 +32,7 @@ class faiProfileEntry extends plugin
     $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)".
                 "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))";
 
-    $FAI_objects = get_all_objects_for_given_base($base,$filter,true);
+    $FAI_objects = fai_func::get_all_objects_for_given_base($base,$filter,true);
 
     /* Create array with categories to be able to sort different types of objects */
     $categories = array("FAIscript"         => "faiScript",
index 33101d560f90e3f196afb6ed7cf013025d0ae66c..af71b587f3b1a0ddedd2d55000af1491cd9864af 100644 (file)
@@ -438,7 +438,7 @@ class faiScript extends plugin
       $ldap = $this->config->get_ldap_link();
       $ldap->cd ($this->dn);
       $faifilter = session::get('faifilter');
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+      $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
       if($faifilter['branch'] == "main"){
         $use_dn = $this->dn;
       }
@@ -448,7 +448,7 @@ class faiScript extends plugin
       prepare_to_save_FAI_object($use_dn,array(),true);
       
       foreach($this->SubObjects as $name => $obj){
-        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
+        $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
         if($faifilter['branch'] == "main"){
           $use_dn = $obj['dn'];
         }
index eccfc0bd046121b3a9570a9d7191dff6047737fa..093378a6884f03192b8f0b3ed50a7896ea3d0f6f 100644 (file)
@@ -162,7 +162,7 @@ class faiSummaryTab extends plugin{
     if(!$base){
       $base = $this->base;
     }
-    return(get_all_releases_from_base($base,true));
+    return(fai_func::get_all_releases_from_base($base,true));
   }
 
 
@@ -383,7 +383,7 @@ class faiSummaryTab extends plugin{
   {
     $ldap                = $this->config->get_ldap_link();
     $dn                    = $this->Releases [$this->Release];
-    $resolvedClasses  = get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(cn=".$class."))");
+    $resolvedClasses  = fai_func::get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(cn=".$class."))");
 
     /* Try to fetch all types of fai objects with the given cn  */
     foreach($resolvedClasses as $obj){
index 9c1699624089dbdb40535d04fdc1fe6433fce642..831f0c42748608ec941010d8524f1c71805d7995 100644 (file)
@@ -388,7 +388,7 @@ class faiTemplate extends plugin
     $ldap->cd ($this->dn);
 
     $faifilter = session::get('faifilter');
-    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
     if($faifilter['branch'] == "main"){
       $use_dn = $this->dn;
     }
@@ -397,7 +397,7 @@ class faiTemplate extends plugin
     new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
 
     foreach($this->SubObjects as $name => $obj){
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
+      $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
       if($faifilter['branch'] == "main"){
         $use_dn = $obj['dn'];
       }
index ce543b15c94441bdccb9c43f99ed44cd1682613a..24a5aed64f6e9aa61069ed52d8eb91a4d0c5bb3a 100644 (file)
@@ -285,7 +285,7 @@ class faiVariable extends plugin
       $ldap->cd ($this->dn);
 
       $faifilter = session::get('faifilter');
-      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
+      $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $this->dn);
       if($faifilter['branch'] == "main"){
         $use_dn = $this->dn;
       }
@@ -294,7 +294,7 @@ class faiVariable extends plugin
       new log("remove","fai/".get_class($this),$use_dn,$this->attributes);
 
       foreach($this->SubObjects as $name => $obj){
-        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
+        $use_dn = preg_replace("/".normalizePreg(fai_func::get_release_dn($this->dn))."/i", $faifilter['branch'], $obj['dn']);
         if($faifilter['branch'] == "main"){
           $use_dn = $obj['dn'];
         }
diff --git a/gosa-core/plugins/admin/fai/functions_FAI.inc b/gosa-core/plugins/admin/fai/functions_FAI.inc
new file mode 100644 (file)
index 0000000..2fd161d
--- /dev/null
@@ -0,0 +1,744 @@
+<?php
+
+define("DEBUG_FAI_FUNC",FALSE);
+
+
+
+
+class fai_func
+{
+
+  /* TEST PHASE .... */
+
+  /* Returns all object for the given release.
+     This function resolves the releases  
+     from base up to the given dn.
+   */
+static function get_all_objects_for_given_base($Current_DN,$filter,$detailed = false)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $res = array();
+    $tmp = array();
+
+    if(!fai_func::is_release_department($Current_DN)) {
+      return($res);
+    }
+
+    /* Collect some basic informations and initialize some variables */ 
+    $base_release       = fai_func::get_release_dn($Current_DN);
+    $previous_releases  = array_reverse(fai_func::             get_previous_releases_of_this_release($base_release,true));
+
+    /* We must also include the given release dn */
+    $previous_releases[] = $base_release;
+
+    /* Walk through all releases */
+    foreach($previous_releases as $release){
+
+      /* Get fai departments */
+      $deps_to_search = fai_func::get_FAI_departments($release); 
+
+      /* For every single department  (ou=hoos,ou ..) */
+      foreach($deps_to_search as $fai_base){
+
+        /* Ldap search for fai classes specified in this release */
+        $attributes  = array("dn","objectClass","FAIstate","cn");
+        $res_tmp = get_list($filter,"fai",$fai_base,$attributes,GL_SUBSEARCH | GL_SIZELIMIT);
+
+        /* check the returned objects, and add/replace them in our return variable */
+        foreach($res_tmp as $attr){
+
+          $buffer = array();
+          $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']);
+
+          if(isset($attr['FAIstate'][0])){
+            if(preg_match("/removed$/",$attr['FAIstate'][0])){
+              if(isset($res[$name])){
+                unset($res[$name]);
+              }
+              continue;
+            }
+          }
+
+          /* In detailed mode are some additonal informations visible */
+          if($detailed){
+
+            /* Create list of parents */
+            if(isset($res[$name])){
+              $buffer = $res[$name];
+              $buffer['parents'][] = $res[$name]['dn'];
+            }else{
+              $buffer['parents'] = array();
+            }
+
+            /* Append objectClass to resulsts */
+            foreach($attributes as $val){
+              if(isset($attr[$val])){
+                $buffer[$val] = $attr[$val];
+              }
+            }
+            unset($buffer['objectClass']['count']);
+          }
+
+          /* Add this object to our list */
+          $buffer['dn']           = $attr['dn'];
+          $res[$name] = $buffer;
+        }
+      }
+    }
+    return($res);
+  }
+
+
+  /* Return all relevant FAI departments */
+static function get_FAI_departments($suffix = "")
+  {
+    $arr = array("hooks","scripts","disk","packages","profiles","templates","variables");
+    $tmp = array();
+    if(preg_match("/^,/",$suffix)){
+      $suffix = preg_replace("/^,/","",$suffix);
+    }
+    foreach($arr as $name){
+      if(empty($suffix)){
+        $tmp[$name] = "ou=".$name;
+      }else{
+        $tmp[$name] = "ou=".$name.",".$suffix;
+      }
+    }
+    return($tmp);
+  }
+
+
+  /* Return all releases within the given base */
+static function get_all_releases_from_base($dn,$appendedName=false)
+  {
+    global $config;
+
+    if(!preg_match("/".normalizePreg(get_ou('faiou'))."/",$dn)){
+      $base = get_ou('faiou').$dn;
+    }else{
+      $base = $dn;
+    }
+    $res = array();  
+
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($base);
+    $ldap->search("(objectClass=FAIbranch)",array("ou","dn"));
+    while($attrs = $ldap->fetch()){
+      if($appendedName){
+        $res[$attrs['dn']] = convert_department_dn(preg_replace("/,".normalizePreg(get_ou('faiou')).".*$/","",$attrs['dn']));
+      }else{
+        $res[$attrs['dn']] = $attrs['ou'][0];
+      }
+    }
+    return($res);
+  }
+
+
+  /* Add this object to list of objects, that must be checked for release saving */
+static function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false)
+  {
+    /* Get ldap object */  
+    global $config;
+    $addObj['Current_DN'] = $Current_DN;
+    $addObj['objectAttrs']= $objectAttrs;
+    $addObj['removed']    = $removed;
+    $addObj['diff']       = TRUE;
+
+    if(!$removed){
+      $ldap = $config->get_ldap_link();
+      $ldap->cd($config->current['BASE']);
+
+      /* Get some basic informations */
+      $parent_obj   = fai_func::get_parent_release_object($Current_DN);
+      if(!empty($parent_obj)){
+        $ldap->cat($parent_obj,array("*"));
+        $attrs = fai_func::                           prepare_ldap_fetch_to_be_saved($ldap->fetch());
+
+        if(!fai_func::array_diff_FAI( $attrs,$objectAttrs)){
+          $addObj['diff'] = FALSE;
+        }
+      } 
+    }
+    $FAI_objects_to_save = session::get('FAI_objects_to_save') ;
+    $FAI_objects_to_save[$Current_DN] =  $addObj;
+    session::set('FAI_objects_to_save',$FAI_objects_to_save);
+  }
+
+
+  /* Detect differences in attribute arrays  */
+static function array_diff_FAI($ar1,$ar2)
+  {
+
+    if((!isset($ar1['description'])) || (isset($ar1['description']) && (count($ar1['description']) == 0))){
+      $ar1['description'] = "";
+    }
+    if((!isset($ar2['description'])) || (isset($ar2['description']) && (count($ar2['description']) == 0))){
+      $ar2['description'] = "";
+    }
+
+    if(count($ar1) != count($ar2)) {
+      return (true);
+    }
+
+    foreach($ar1 as $key1 => $val1){
+
+      if((is_array($val1)) && (count($val1)==1)){
+        $ar1[$key1] = $val1[0];
+      }
+
+      if((is_array($ar2[$key1])) && (count($ar2[$key1])==1)){
+        $val1 = $val1[0];
+        $ar2[$key1] = $ar2[$key1][0];
+      }
+    }
+    ksort($ar1);
+    ksort($ar2);
+    if(count( array_diff($ar1,$ar2)) || fai_func::arr_diff($ar1,$ar2)){
+      return(true);
+    }else{
+      return(false);
+    }
+  }
+
+
+static function arr_diff($ar1,$ar2)
+  {
+    foreach($ar1 as $ak1 => $av1){
+      if(!isset($ar2[$ak1]) || (!($av1 === $ar2[$ak1]))){
+        return(true);
+      }elseif(is_array($av1)){
+        return(fai_func::arr_diff($av1,$ar2[$ak1]));
+      }
+    }
+    return(FALSE);
+  }
+
+
+
+
+  /* check which objects must be saved, and save them */
+static function save_release_changes_now()
+  {
+    /* Variable init*/
+    $to_save = array();
+
+    /* check which objects must be saved */
+    $FAI_objects_to_save = session::get('FAI_objects_to_save');
+    foreach($FAI_objects_to_save as $Current_DN => $object){
+      if($object['diff']){
+        $sub_name = $Current_DN;
+        while(isset($FAI_objects_to_save[$sub_name])){
+          $to_save[strlen($sub_name)][$sub_name] = $FAI_objects_to_save[$sub_name]; 
+          unset($FAI_objects_to_save[$sub_name]);
+          $sub_name = preg_replace('/^[^,]+,/', '', $sub_name);
+        }
+      }
+    }
+    session::set('FAI_objects_to_save',$FAI_objects_to_save);
+
+    /* Sort list of objects that must be saved, and ensure that 
+       container   objects are safed, before their childs are saved */
+    ksort($to_save);
+    $tmp = array();
+    foreach($to_save as $SubObjects){
+      foreach($SubObjects as $object){
+        $tmp[] = $object;
+      }
+    }
+    $to_save = $tmp;
+
+    /* Save objects and manage the correct release behavior*/
+    foreach($to_save as $save){
+
+      $Current_DN = $save['Current_DN'];
+      $removed    = $save['removed'];
+      $objectAttrs= $save['objectAttrs'];
+
+      /* Get ldap object */ 
+      global $config;
+      $ldap = $config->get_ldap_link();
+      $ldap->cd($config->current['BASE']);
+
+      /* Get some basic informations */
+      $base_release       = fai_func::get_release_dn($Current_DN);
+      $sub_releases       = fai_func::                       get_sub_releases_of_this_release($base_release,true);
+      $parent_obj         = fai_func::get_parent_release_object($Current_DN);
+      $following_releases = fai_func::                       get_sub_releases_of_this_release($base_release,true);
+
+      /* Check if given dn exists or if is a new entry */
+      $ldap->cat($Current_DN);
+      if(!$ldap->count()){
+        $is_new = true;
+      }else{
+        $is_new = false;
+      }
+
+      /* if parameter removed is true, we have to add FAIstate to the current attrs 
+         FAIstate should end with ...|removed after this operation */  
+      if($removed ){
+        $ldap->cat($Current_DN);
+
+        /* Get current object, because we must add the FAIstate ...|removed */
+        if((!$ldap->count()) && !empty($parent_obj)){
+          $ldap->cat($parent_obj);
+        }
+
+        /* Check if we have found a suiteable object */ 
+        if(!$ldap->count()){
+          echo "Error can't remove this object ".$Current_DN;
+          return;
+        }else{
+
+          /* Set FAIstate to current objectAttrs */
+          $objectAttrs = fai_func::                           prepare_ldap_fetch_to_be_saved($ldap->fetch());
+          if(isset($objectAttrs['FAIstate'][0])){
+            if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){
+              $objectAttrs['FAIstate'][0] .= "|removed";
+            }
+          }else{
+            $objectAttrs['FAIstate'][0] = "|removed";
+          }
+        }
+      }
+
+      /* Check if this a leaf release or not */ 
+      if(count($following_releases) == 0 ){
+
+        /* This is a leaf object. It isn't inherited by any other object */    
+        if(DEBUG_FAI_FUNC) { 
+          echo "<b>Saving directly, is a leaf object</b><br> ".$Current_DN;
+          print_a($objectAttrs);
+        }
+        fai_func::save_FAI_object($Current_DN,$objectAttrs);
+      }else{
+
+        /* This object is inherited by some sub releases */  
+
+        /* Get all releases, that inherit this object */ 
+        $r = get_following_releases_that_inherit_this_object($Current_DN);
+
+        /* Get parent object */
+        $ldap->cat($parent_obj);
+        $parent_attrs = fai_func::                           prepare_ldap_fetch_to_be_saved($ldap->fetch());
+
+        /* New objects require special handling */
+        if($is_new){
+
+          /* check if there is already an entry named like this,
+             in one of our parent releases */
+          if(!empty($parent_obj)){
+            if(DEBUG_FAI_FUNC) { 
+              echo "There is already an entry named like this.</b><br>";
+
+              echo "<b>Saving main object</b>".$Current_DN;
+              print_a($objectAttrs);
+            }    
+            fai_func::save_FAI_object($Current_DN,$objectAttrs);
+
+            foreach($r as $key){
+              if(DEBUG_FAI_FUNC) { 
+                echo "<b>Saving parent to following release</b> ".$key;
+                print_a($parent_attrs);
+              }
+              fai_func::save_FAI_object($key,$parent_attrs);
+            }
+          }else{
+
+            if(DEBUG_FAI_FUNC) { 
+              echo "<b>Saving main object</b>".$Current_DN;
+              print_a($objectAttrs);
+            }
+            fai_func::save_FAI_object($Current_DN,$objectAttrs);
+
+            if(isset($objectAttrs['FAIstate'])){
+              $objectAttrs['FAIstate'] .= "|removed"; 
+            }else{
+              $objectAttrs['FAIstate'] = "|removed";
+            }
+
+            foreach($r as $key ){
+              if(DEBUG_FAI_FUNC) { 
+                echo "<b>Create an empty placeholder in follwing release</b> ".$key; 
+                print_a($objectAttrs);
+              }
+              fai_func::save_FAI_object($key,$objectAttrs);
+            }
+          }
+        }else{
+
+          /* check if we must patch the follwing release */
+          if(!empty($r)){
+            foreach($r as $key ){
+              if(DEBUG_FAI_FUNC) { 
+                echo "<b>Copy current objects original attributes to next release</b> ".$key;
+                print_a($parent_attrs);
+              }
+              fai_func::save_FAI_object($key,$parent_attrs);
+            }
+          }
+
+          if(DEBUG_FAI_FUNC) { 
+            echo "<b>Saving current object</b>".$parent_obj;
+            print_a($objectAttrs);
+          }
+          fai_func::save_FAI_object($parent_obj,$objectAttrs);
+
+          if(($parent_obj != $Current_DN)){
+            msg_dialog::display(_("Error"), sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN), ERROR_DIALOG);
+          }
+        }
+      }
+    } 
+    session::set('FAI_objects_to_save',array());
+  }
+
+
+  /* this function will remove all unused (deleted) objects,
+     that have no parent object */
+static function clean_up_releases($Current_DN)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* Collect some basic informations and initialize some variables */ 
+    $base_release       = fai_func::get_release_dn($Current_DN);
+    $previous_releases  = array_reverse(fai_func::             get_previous_releases_of_this_release($base_release,true));
+    $Kill = array();
+    $Skip = array();
+
+    /* We must also include the given release dn */
+    $previous_releases[] = $base_release;
+
+    /* Walk through all releases */
+    foreach($previous_releases as $release){
+
+      /* Get fai departments */
+      $deps_to_search = fai_func::get_FAI_departments($release); 
+
+      /* For every single department  (ou=hoos,ou ..) */
+      foreach($deps_to_search as $fai_base){
+
+        /* Ldap search for fai classes specified in this release */
+        $ldap->cd($fai_base);
+        $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate"));
+
+        /* check the returned objects, and add/replace them in our return variable */
+        while($attr = $ldap->fetch()){
+
+          $buffer = array();
+#        $name = str_ireplace($release,"",$attr['dn']);
+          $name = preg_replace("/".normalizePreg($release)."/i","",$attr['dn']);
+
+          if(isset($attr['FAIstate'][0])&&(preg_match("/removed$/",$attr['FAIstate'][0]))){
+
+            /* Check if this object is required somehow */    
+            if(!isset($Skip[$name])){
+              $Kill[$attr['dn']] = $attr['dn'];
+            }
+          }else{
+
+            /* This object is required (not removed), so do not 
+               delete any following sub releases of this object */
+            $Skip[$name] = $attr['dn'];
+          }
+        }
+      }
+    }
+    return($Kill);
+  }
+
+
+  /* Remove numeric index and 'count' from ldap->fetch result */
+static function prepare_ldap_fetch_to_be_saved($attrs)
+  {
+    foreach($attrs as $key => $value){
+      if(is_numeric($key) || ($key == "count") || ($key == "dn")){
+        unset($attrs[$key]);
+      }
+      if(is_array($value) && isset($value['count'])){
+        unset($attrs[$key]['count']);
+      }
+    }
+    return($attrs);
+  }
+
+
+  /* Save given attrs to specified dn*/
+static function save_FAI_object($dn,$attrs)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn));
+    $ldap->cd($dn);
+
+    $ldap->cat($dn,array("dn"));
+    if($ldap->count()){
+
+      /* Remove FAIstate*/
+      if(!isset($attrs['FAIstate'])){
+        $attrs['FAIstate'] = array();
+      }
+
+      $ldap->modify($attrs);
+    }else{
+
+      /* Unset description if empty  */
+      if(empty($attrs['description'])){
+        unset($attrs['description']);
+      }    
+
+      $ldap->add($attrs);
+    }
+    show_ldap_error($ldap->get_error(),sprintf(_("Release management failed, can't save '%s'"),$dn));
+  }
+
+
+  /* Return FAIstate freeze branch or "" for specified release department */
+static function get_release_tag($dn)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($dn);
+    $ldap->cat($dn,array("FAIstate"));
+
+    if($ldap->count()){
+
+      $attr = $ldap->fetch();
+      if(isset($attr['FAIstate'][0])){
+        if(preg_match("/freeze/",$attr['FAIstate'][0])){
+          return("freeze");
+        }elseif(preg_match("/branch/",$attr['FAIstate'][0])){
+          return("branch");
+        }
+      }
+    }
+    return("");
+  }
+
+
+static function get_following_releases_that_inherit_this_object($dn)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    $ret = array();
+
+    /* Get base release */
+    $base_release = fai_func::get_release_dn($dn);
+
+    /* Get previous release dns */
+    $sub_releases = fai_func::                       get_sub_releases_of_this_release($base_release);
+
+    /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
+#  $dn_suffix = str_ireplace($base_release,"",$dn);
+    $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn);
+
+    /* Check if given object also exists whitin one of these releases */
+    foreach($sub_releases as $p_release => $name){
+
+      $check_dn = $dn_suffix.$p_release;
+
+      $ldap->cat($check_dn,array("dn","objectClass"));
+
+      if($ldap->count()){
+        //return($ret);
+      }else{
+        $ret[$check_dn]=$check_dn;
+      }
+    }
+    return($ret);
+  }
+
+
+  /* Get previous version of the object dn */
+static function get_parent_release_object($dn,$include_myself=true)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $previous_releases= array();
+
+    /* Get base release */
+    $base_release = fai_func::get_release_dn($dn);
+    if($include_myself){
+      $previous_releases[] = $base_release;  
+    }
+
+    /* Get previous release dns */
+    $tmp = fai_func::             get_previous_releases_of_this_release($base_release,true);
+    foreach($tmp as $release){
+      $previous_releases[] = $release;
+    }
+
+    /* Get dn suffix. Example  "FAIvairableEntry=keksdose,FAIvariable=Keksregal," */
+#  $dn_suffix = str_ireplace($base_release,"",$dn);
+    $dn_suffix = preg_replace("/".normalizePreg($base_release)."/i","",$dn);
+
+    /* Check if given object also exists whitin one of these releases */
+    foreach($previous_releases as $p_release){
+      $check_dn = $dn_suffix.$p_release;
+      $ldap->cat($check_dn,array("dn","objectClass"));
+
+      if($ldap->count()){
+        return($check_dn);
+      }
+    }
+    return("");
+  }
+
+
+  /* return release names of all parent releases */
+static function get_previous_releases_of_this_release($dn,$flat)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $ret = array();
+
+    /* Explode dns into pieces, to be able to build parent dns */
+    $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$dn));
+
+    if(!is_array($dns_to_check)){
+      return;  
+    }
+
+    /* Unset first entry which represents the given dn */
+    unset($dns_to_check['count']); 
+    unset($dns_to_check[key($dns_to_check)]);
+
+    /* Create dns addresses and check if this dn is a release dn */
+    $id = 0;
+    while(count($dns_to_check)){
+
+      /* build parent dn */
+      $new_dn = "";
+      foreach($dns_to_check as $part){
+        $new_dn .= $part.",";
+      }
+      $new_dn .= $config->current['BASE'];
+
+      /* check if this dn is a release */
+      if(fai_func::is_release_department($new_dn)){
+        if($flat){
+          $ret[$id] = $new_dn; 
+        }else{
+          $ret = array($new_dn=>$ret); 
+        }
+        $id ++;
+      }else{
+        return($ret);
+      }
+      reset($dns_to_check);
+      unset($dns_to_check[key($dns_to_check)]);
+    }
+    return($ret);
+  } 
+
+
+  /* This function returns all sub release names, recursivly  */
+static function get_sub_releases_of_this_release($dn,$flat = false)
+  {
+    global $config;
+    $res  = array();
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $ldap->ls("(objectClass=FAIbranch)",$dn,array("objectClass","dn","ou"));
+    while($attr = $ldap->fetch()){
+
+      /* Append department name */
+      if($flat){
+        $res[$attr['dn']] = $attr['ou'][0];
+      }else{
+        $res[$attr['dn']] = array();
+      }
+
+      /* Get sub release departments of this department */
+      if(in_array("FAIbranch",$attr['objectClass'])) {
+        if($flat){
+          $tmp = fai_func::                       get_sub_releases_of_this_release($attr['dn'],$flat);
+          foreach($tmp as $dn => $value){
+            $res[$dn]=$value;
+          }
+        }else{
+          $res[$attr['dn']] = fai_func::                       get_sub_releases_of_this_release($attr['dn']);
+        }
+      }
+    }
+    return($res);
+  }
+
+
+  /* Check if the given department is a release department */
+static function is_release_department($dn)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+    $ldap->cat($dn,array("objectClass","ou"));
+
+    /* Check objectClasses and name to check if this is a release department */
+    if($ldap->count()){
+      $attrs = $ldap->fetch();
+
+      $ou = "";
+      if(isset($attrs['ou'][0])){
+        $ou = $attrs['ou'][0]; 
+      }
+
+      if((in_array("FAIbranch",$attrs['objectClass'])) || ($ou == "fai")){
+        return($attrs['dn']);
+      }
+    }
+    return(false);
+  }
+
+
+  /* This function returns the dn of the object release */
+static function get_release_dn($Current_DN)
+  {
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* Split dn into pices */ 
+    $dns_to_check = gosa_ldap_explode_dn(preg_replace("/".normalizePreg(",".$config->current['BASE'])."/i","",$Current_DN));
+
+    if(!is_array($dns_to_check)){
+      return;  
+    }
+
+    /* Use dn pieces, to create sub dns like 
+       ou=test,ou=1,ou=0...
+       ou=1,ou=0...
+       ou=0... 
+       To check which dn is our release container.
+     */
+    unset($dns_to_check['count']); 
+    while(count($dns_to_check)){
+
+      /* Create dn */
+      $new_dn = "";
+      foreach($dns_to_check as $part){
+        $new_dn .= $part.",";
+      }
+      $new_dn .= $config->current['BASE'];
+
+      /* Check if this dn is a release dn */
+      if(fai_func::is_release_department($new_dn)){
+        return($new_dn);
+      }
+
+      /* Remove first element of dn pieces */
+      reset($dns_to_check);
+      unset($dns_to_check[key($dns_to_check)]);
+    }
+    return("");
+  }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 0f33aedcb9d34ae13e86bc471d69b36ba43d44d8..97410c8dcf2afad83314ea30f618481ec3f38d0c 100644 (file)
@@ -1101,7 +1101,7 @@ class workstartup extends plugin
         $filter = "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)".
           "(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)".
           "(objectClass=FAIpartitionTable))";
-        $list = get_all_objects_for_given_base($base,$filter,TRUE);
+        $list = fai_func::get_all_objects_for_given_base($base,$filter,TRUE);
         foreach($list as $attrs){
           $info = $this->analyse_fai_object($attrs);
           if(count($info)){