Code

Followup patch for #6056
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
index 4d1eae95178eeb4d55674f218d7f885de763fefb..8d54dde929ed4a3dd3d9c8993e2b29a0b30ff9de 100644 (file)
@@ -7,7 +7,6 @@ class workstartup extends plugin
   var $gotoLdap_inherit   = FALSE;
 
   /* Generic terminal attributes */
-  var $bootmode             = "G";
   var $gotoBootKernel       = "default-inherited";
   var $gotoKernelParameters = "";
   var $gotoLdapServer       = "default-inherited";
@@ -19,7 +18,7 @@ class workstartup extends plugin
 
   /* attribute list for save action */
   var $attributes           = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", 
-                                    "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
+                                    "FAIclass", "FAIstate", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
   var $objectclasses        = array("GOhard", "FAIobject");
 
   /* Share */
@@ -36,6 +35,7 @@ class workstartup extends plugin
   var $FAIclass           = array();  // The currently selected classes 
   var $FAIrelease           = "";
   var $FAIdebianMirror      = "auto";
+  var $FAIstate             = "";
   var $si_active            = FALSE;
   var $si_fai_action_failed = FALSE;
 
@@ -81,6 +81,18 @@ class workstartup extends plugin
         $this->member_of_ogroup = TRUE;
         $attrs = $ldap->fetch();
         $this->o_group_dn = $attrs['dn'];
+        if ($ldap->count() > 1) {
+          $ogroups = array();
+          array_push($ogroups, $attrs['dn']);
+          while ($attrs = $ldap->fetch()) {
+            array_push($ogroups, $attrs['dn']);
+          }
+          $str = "";
+          foreach($ogroups as $dn) {
+            $str .= "<li>".$dn."</li>";
+          }
+          msg_dialog::display(_("Warning"), sprintf(_("This system is member of more than one object group, object group inheritence will not work!")."<br><ul>%s</ul>", $str), WARNING_DIALOG);
+        }
       }
     }
 
@@ -307,6 +319,7 @@ class workstartup extends plugin
          * to our list of classes, abort and show a message.
          */
         foreach($this->FAIclass as $name){
+          # FIXME: Where does FAIclassInfo come from??
           if(isset($this->FAIclassInfo[$name])){
             foreach($this->FAIclassInfo[$name] as $atr){
               if(isset($atr['obj'])){
@@ -389,6 +402,13 @@ class workstartup extends plugin
           if(preg_match("/fai_remove/i",$name)){
             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
             unset($this->FAIclass[$value]);
+            if($this->FAIclass == array()){
+              /* class list is emtpy. Check whether the system is part of an object group and set
+              the FAI mirror to "inherited" in this case. */
+              if ($this->member_of_ogroup){
+                $this->FAIdebianMirror = "inherited";
+              } 
+            }
           }
         }
       }
@@ -619,7 +639,6 @@ class workstartup extends plugin
       $i = 1;
       if($this->acl_is_readable("FAIclass")){
         foreach($tmp as $class){
-
           /* Mark invalid classes. (Not in selected release)
            */
           $marker = "";
@@ -643,27 +662,18 @@ class workstartup extends plugin
           }
           $i ++ ; 
 
-          /* Get Description tag 
-           *  There may be several FAI objects with the same class name, 
-           *   use the description from FAIprofile, if possible.
-           */  
-          $desc = ""; 
-          if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
-            foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
-              if(isset($types['Desc'])){
-                $desc= $types['Desc'];
-                if($types['Type'] == "FAIprofile"){
-                  break;
-                }
-              }
-            }
+          /*  Get used FAI types from the class 
+           */ 
+          if(!$marker) {
+            $types = $this->get_fai_types_string($class, true);
+          }
+          else {
+            $types = "";
           }
-          if(!empty($desc)){
-            $desc = "&nbsp;[".trim($desc)."]";
-          }        
 
           $div->AddEntry(array(
-                array("string"=>$class.$desc.$marker),
+            array("string"=>$class.$marker),
+            array("string"=>$types),
                 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
                 ));
         }  
@@ -671,23 +681,6 @@ class workstartup extends plugin
     }// END FAI output generation 
     $smarty->assign("FAIScriptlist",$div->DrawList()); 
 
-    /* Radio button group */
-    if (preg_match("/G/", $this->bootmode)) {
-      $smarty->assign("graphicalbootup", "checked");
-    } else {
-      $smarty->assign("graphicalbootup", "");
-    }
-    if (preg_match("/T/", $this->bootmode)) {
-      $smarty->assign("textbootup", "checked");
-    } else {
-      $smarty->assign("textbootup", "");
-    }
-    if (preg_match("/D/", $this->bootmode)) {
-      $smarty->assign("debugbootup", "checked");
-    } else {
-      $smarty->assign("debugbootup", "");
-    }
-
     /* Show main page */
     $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
@@ -696,6 +689,18 @@ class workstartup extends plugin
 
   function remove_from_parent()
   {
+    /* Cancel if there's nothing to do here */
+    if ((!$this->acl_is_removeable())){
+      return;
+    }
+
+    /* Remove and write to LDAP */
+    plugin::remove_from_parent();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->dn);
+    $this->cleanup();
+    $this->attrs['gotoModules'] = array();
+    $ldap->modify($this->attrs);
     $this->handle_post_events("remove");
     new log("remove","workstation/".get_class($this),$this->dn);
   }
@@ -714,17 +719,17 @@ class workstartup extends plugin
       }
     }
 
+    /* Clear FAI class list if FAI mirror has been set to inherited */
+    if($this->FAIdebianMirror == "inherited"){
+      $this->FAIclass =array();
+    }
+
     if(isset($_POST['WorkstationStarttabPosted'])){
       if(isset($_POST['gotoLdap_inherit'])){
         $this->gotoLdap_inherit = TRUE;
       }else{
         $this->gotoLdap_inherit = FALSE;
       }
-
-      /* Save group radio buttons */
-      if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
-        $this->bootmode= $_POST["bootmode"];
-      }
     }
   }
 
@@ -786,21 +791,6 @@ class workstartup extends plugin
       }
     }
 
-    if ($this->gotoKernelParameters == "") {
-      /* Add semi automatic values if empty */
-      // FIXME: LDAP Server may not be set here...
-      $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
-      
-      switch ($this->bootmode){
-        case "D":
-          $this->gotoKernelParameters.= " debug";
-        break;
-        case "G":
-          $this->gotoKernelParameters.= " splash=silent";
-        break;
-      }
-    }
-
     plugin::save();
 
     unset( $this->attrs['FAIrelease'] );
@@ -842,7 +832,7 @@ class workstartup extends plugin
       }
     }
 
-    if ($this->attrs['gotoBootKernel'] == "default-inherited"){
+    if ($this->gotoBootKernel == "default-inherited"){
       $this->attrs['gotoBootKernel']= array();
     }
 
@@ -986,11 +976,16 @@ class workstartup extends plugin
   function PrepareForCopyPaste($source)
   {
     plugin::PrepareForCopyPaste($source);    
+
     $source_o = new workstartup ($this->config, $source['dn']);
     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
-          "gotoKernelParameters","gotoShares") as $attr){
+          "FAIstate", "FAIrelease", "gotoKernelParameters","gotoShares",
+          "gotoLdapServers", "gotoLdap_inherit") as $attr){
       $this->$attr = $source_o->$attr;
     }
+    if (isset($source['FAIstate'])) {
+      $this->attrs['FAIstate'] = $source['FAIstate'];
+    }
   }
 
   
@@ -1041,6 +1036,44 @@ class workstartup extends plugin
           ));
   }
 
+  /* Function to find bad classes */
+  function update_bad_classes($release)
+  {
+
+    if(!isset($this->cache['BAD_CLASSES'][$release])) {
+      /* Find "bad" classes */
+      $ui = get_userinfo();
+      $ldap = $this->config->get_ldap_link();
+
+      /* Convert release name to a valid ldap uri component */
+      $release_components = split('/', $release);
+      $release_components = array_reverse($release_components);
+      for($i=0;$i<sizeof($release_components);$i++) {
+        $release_components[$i] = "ou=" . $release_components[$i];
+      }
+      $release_dn_part = join(',', $release_components);
+
+      /* Limit the base to the release in the faiBase */
+      $base = sprintf("%s,%s%s", $release_dn_part, get_ou('faiBaseRDN'), $this->config->current['BASE']);
+
+      /* Build a list of all fai classes, that don't have the unittag of the user
+       * and are not freezed or removed. The classes will be filtered by this
+       * list. Its needed to specify each objectClass (FAIpackageList etc.) because
+       * FAIClass would match sub-objects, too, which would lead to an array that
+       * is much bigger then needed */
+      $filter = sprintf('(&(|(objectClass=FAItemplate)(objectClass=FAIpackageList)(objectClass=FAIprofile)(objectClass=FAIscript)(objectClass=FAIpartitionTable)(objectClass=FAIHook)(objectClass=FAIvariable)(objectClass=FAItemplate))(&(!(gosaUnitTag=%s))(&(!(FAIstate=*removed*))(!(FAIstate=*freeze*)))))', $ui->gosaUnitTag);
+      $ldap->cd($base);
+      $ldap->search(sprintf("$filter", $ui->gosaUnitTag));
+        
+      $this->cache['BAD_CLASSES'][$release] = array(); 
+      while ($entry = $ldap->fetch()) {
+        $classname = $entry['cn'][0];
+        if (!in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
+          array_push($this->cache['BAD_CLASSES'][$release], $classname);
+        }
+      }
+    } 
+   }
 
   /* Updates release dns 
    *  and reads all classes for the current release, 
@@ -1061,7 +1094,7 @@ class workstartup extends plugin
     if($force || !isset($this->cache['SERVERS'])){
 
       $o_queue = new gosaSupportDaemon();
-      $tmp = $o_queue->FAI_get_server();
+      $servers = $o_queue->FAI_get_server();
       if($o_queue->is_error()){
         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
         $this->si_fai_action_failed = TRUE;
@@ -1069,12 +1102,20 @@ class workstartup extends plugin
         return;
       }else{
 
-        foreach($tmp as $entry){
-          $rel = $entry['FAI_RELEASE'];
+        $base = $this->config->current['BASE'];
+        $ldap = $this->config->get_ldap_link();
+        foreach($servers as $server){
+          /* Dont show servers that have a different unittag as the user*/
+          $ui = get_userinfo();
+          if ($ui->gosaUnitTag != $server['TAG']) {
+            continue;
+          }
+        
+          $rel = $server['FAI_RELEASE'];
           $this->cache['SERVERS']['auto'][$rel] = $rel;
-          $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
+          $this->cache['SERVERS'][$server['SERVER']][$rel] = $rel;
           uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
-          uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
+          uksort($this->cache['SERVERS'][$server['SERVER']], 'strnatcasecmp');
         }
       }
     }
@@ -1120,7 +1161,7 @@ class workstartup extends plugin
       /* Get the list of available servers and their releases.
        */
       $o_queue = new gosaSupportDaemon();
-      $tmp = $o_queue->FAI_get_classes($release);
+      $classes = $o_queue->FAI_get_classes($release);
       $this->cache['CLASSES'][$release] = array();
       if($o_queue->is_error()){
         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
@@ -1128,9 +1169,19 @@ class workstartup extends plugin
         $this->cache=array();
         return;
       }else{
-        foreach($tmp as $entry){
-          $class = $entry['CLASS'];
-          $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
+        foreach($classes as $class){
+          $classname = $class['CLASS'];
+          $this->update_bad_classes($release);
+          if(isset($this->cache['BAD_CLASSES'][$release])){
+            /* Skip classes that are in the array of bad classes */
+            if (in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
+              continue;
+            }
+          }
+          if (!isset($this->cache['CLASSES'][$release][$classname])) {
+            $this->cache['CLASSES'][$release][$classname] = array();
+          }
+          array_push($this->cache['CLASSES'][$release][$classname], $this->analyse_fai_object($class));
         }
       }
 
@@ -1193,21 +1244,27 @@ class workstartup extends plugin
     }
   }
 
-
-  /* This function return an array containing all 
-   *  invalid classes for the selected server/release
-   */
-  function get_invalid_classes($classes)
-  {
+  /* Detect the release and get all classes for it */
+  function get_classes() {
     $this->update_fai_cache();
+
     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
-      $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
+      $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
-      $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
+      $classes = $this->cache['CLASSES'][$this->FAIrelease];
     }else{
-      $release_classes = array();
+      $classes = array();
     }
 
+    return $classes;
+  }
+
+  /* This function return an array containing all 
+   *  invalid classes for the selected server/release
+   */
+  function get_invalid_classes($classes)
+  {
+    $release_classes = $this->get_classes();
 
     /* Detect all classes that are not valid 
      *  for the selected release 
@@ -1221,31 +1278,45 @@ class workstartup extends plugin
     return($NA);
   }  
 
-  
+  function get_fai_types_string($class_name, $image=FALSE) {
+    $classes = $this->get_classes();
+
+    $result = array();
+
+    if ($image) {        
+      # Pre-fill the array fields with an empty image so that
+      # everything looks fine if the type in this position
+      # doesn't exist in that class
+      for ($i=0; $i<6; $i++) {
+        $result[$i] = "<img src='images/empty.png' width='17'>&nbsp;";
+      }
+    }
+
+    foreach($classes[$class_name] as $type) {
+      $index = $type['index'];
+      if ($image) {
+        $string = "<img src='".$type['img']."' width='17' title='".$type['desc']."'>&nbsp;";
+      }
+      else {
+        $string = $type['Abbr'];
+      }
+      
+      $result[$index] = $string;
+    }
+    return join(' ', $result);
+
+  }
+
   /* Get all selectable classes for the ui select box
    */
   function selectable_classes()
   {
-    $this->update_fai_cache();
-
-    if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
-      $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
-    }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
-      $classes = $this->cache['CLASSES'][$this->FAIrelease];
-    }else{
-      $classes = array();
-    }
+    $classes = $this->get_classes();
 
-    $Abbr ="";
     $ret= array();
-    foreach($classes as $class_name => $class_types){
-      if(!in_array($class_name,$this->FAIclass)){
-        foreach($class_types as $type){
-          if(!preg_match("/".$type['Abbr']."/",$Abbr)){
-            $Abbr .= $type['Abbr']." ";
-          }
-        }
-        $ret[$class_name] = trim($Abbr);
+    foreach($classes as $class_name => $class_types) {
+      if (!in_array($class_name, $this->FAIclass)) {
+        $ret[$class_name] = $this->get_fai_types_string($class_name);
       }
     }
     uksort($ret, 'strnatcasecmp');
@@ -1258,40 +1329,60 @@ class workstartup extends plugin
    */
   function analyse_fai_object($attr)
   {
-    $tmp = array();
+    $result = array();
     switch($attr['TYPE']){
-
+      case 'FAIpartitionTable':
+        $result["Type"]= 'FAIpartitionTable'; 
+        $result["Abbr"]= 'Pt';
+        $result["img"]= 'plugins/fai/images/fai_partitionTable.png';
+        $result["desc"] = _('Partition table');
+        $result["index"]= 0;
+        break;
       case 'FAIpackageList':
-        $tmp["Type"]= 'FAIpackageList';
-        $tmp["Abbr"]= 'Pl';
+        $result["Type"]= 'FAIpackageList';
+        $result["Abbr"]= 'Pl';
+        $result["img"] = 'plugins/fai/images/fai_packages.png';
+        $result["desc"] = _('Package list');
+        $result["index"] = 1;
         break;
-      case 'FAItemplate': 
-        $tmp["Type"]= 'FAItemplate'; 
-        $tmp["Abbr"]= 'T'; 
+      case 'FAIscript':
+        $result["Type"]= 'FAIscript'; 
+        $result["Abbr"]= 'S'; 
+        $result["img"]= 'plugins/fai/images/fai_script.png';
+        $result["desc"] = _('Scripts');
+        $result["index"] = 2;
         break;
       case 'FAIvariable':
-        $tmp["Type"]= 'FAIvariable'; 
-        $tmp["Abbr"]= 'V'; 
-        break;
-      case 'FAIscript':
-        $tmp["Type"]= 'FAIscript'; 
-        $tmp["Abbr"]= 'S'; 
+        $result["Type"]= 'FAIvariable'; 
+        $result["Abbr"]= 'V';
+        $result["img"]= 'plugins/fai/images/fai_variable.png'; 
+        $result["desc"] = _('Variables');
+        $result["index"]= 3;
         break;
       case 'FAIhook':
-        $tmp["Type"]= 'FAIhook'; 
-        $tmp["Abbr"]= 'H'; 
-        break;
-      case 'FAIpartitionTable':
-        $tmp["Type"]= 'FAIpartitionTable'; 
-        $tmp["Abbr"]= 'Pt'; 
+        $result["Type"]= 'FAIhook'; 
+        $result["Abbr"]= 'H'; 
+        $result["img"]= 'plugins/fai/images/fai_hook.png';
+        $result["desc"] = _('Hooks');
+        $result["index"]= 4;
         break;
       case 'FAIprofile':
-        $tmp["Type"]= 'FAIprofile'; 
-        $tmp["Abbr"]= 'P'; 
+        $result["Type"]= 'FAIprofile'; 
+        $result["Abbr"]= 'P';
+        $result["img"]= 'plugins/fai/images/fai_profile.png';
+        $result["desc"]= _('Profile');
+        $result["index"] = 5;
+        break;
+      case 'FAItemplate': 
+        $result["Type"]= 'FAItemplate'; 
+        $result["Abbr"]= 'T';
+        $result["img"] = 'plugins/fai/images/fai_template.png'; 
+        $result["desc"]= _('Templates');
+        $result["index"] = 6;
         break;
       default: trigger_error("Unknown FAI object type!");;
     }
-    return($tmp);
+    return($result);
   }