Code

Reverte 8071, because it has drawbacks that I don't want to debug right now. Moving...
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
index c624f017c42ad2ad4509a102b6aed4ccea985c4f..0f47013a881e76eb534cea75ce53d47d1120e4e5 100644 (file)
@@ -2,11 +2,6 @@
 
 class workstartup extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage terminal startup options";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Generic terminal attributes */
   var $bootmode             = "G";
   var $goLdapServerList     = array();
@@ -56,6 +51,9 @@ class workstartup extends plugin
   var $FAIServRepConfig   = array();
 
   var $fai_activated      = FALSE;
+  var $member_of_ogroup   = FALSE;
+
+  var $o_group_dn         = "";
 
   function workstartup ($config, $dn= NULL, $parent= NULL)
   {
@@ -70,6 +68,17 @@ class workstartup extends plugin
 
     plugin::plugin ($config, $dn, $parent);
 
+    if(!isset($this->parent->by_object['ogroup'])){
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cd ($this->config->current['BASE']);
+      $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))",array("cn","dn"));
+      if($ldap->count()){
+        $this->member_of_ogroup = TRUE;
+        $attrs = $ldap->fetch();
+        $this->o_group_dn = $attrs['dn'];
+      }
+    }
+
     /* Creating a list of valid Mirrors 
      * none will not be saved to ldap.
      */
@@ -96,47 +105,58 @@ class workstartup extends plugin
           "(objectClass=FAIprofile)".
           "(objectClass=FAIpartitionTable))",
           $ui->subtreeACL,$this->config->current['BASE'],
-          array("cn","objectClass","FAIdebianSection"));
+          array("cn","objectClass","FAIdebianSection","description"));
 
       foreach($res as $attr){
         $cn = $attr['cn'][0];
 
         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
 
+        if(!isset($attr['description'])){
+          $attr['description'][0] = "";
+        }
+
         if(in_array('FAIpackageList',$attr['objectClass'])){
           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
           $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
           $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
+          $tmp2[$cn]['FAIpackageList']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAItemplate',$attr['objectClass'])){
           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
+          $tmp2[$cn]['FAItemplate']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAIvariable',$attr['objectClass'])){
           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
+          $tmp2[$cn]['FAIvariable']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAIscript',$attr['objectClass'])){
           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
+          $tmp2[$cn]['FAIscript']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAIhook',$attr['objectClass'])){
           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
+          $tmp2[$cn]['FAIhook']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAIpartitionTable',$attr['objectClass'])){
           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
+          $tmp2[$cn]['FAIpartitionTable']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
         if(in_array('FAIprofile',$attr['objectClass'])){
           $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
           $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
+          $tmp2[$cn]['FAIprofile']['desc']  = $attr['description'];
           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
         }
       }
@@ -159,8 +179,10 @@ class workstartup extends plugin
          ['PACKAGES'][0] "pkg1";
          ['PACKAGES'][1] "postfix";
        */
-
-      $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
+      $filter= "";
+      $ui= get_userinfo();
+      if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){                                                                                                                                  $filter= "(gosaUnitTag=".$ui->gosaUnitTag.")";
+      }                                                                                                                                $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer)$filter)",array("FAIrepository"));
       $test = array();
       while($attr = $ldap->fetch()){
         if(isset($attr['FAIrepository'])){
@@ -233,6 +255,7 @@ class workstartup extends plugin
       }
       sort ($this->$val);
       $this->$val= array_unique($this->$val);
+      $this->saved_attributes[$val]= $this->$val;
     }
 
     /* Parse Kernel Parameters to decide what boot mode is enabled */
@@ -298,11 +321,11 @@ class workstartup extends plugin
 
 
     /* Load hardware list */
-    $ldap= $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
-    if ($ldap->count() == 1){
+    if ($this->member_of_ogroup){
 
+      if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
+        $this->FAIdebianMirror = "inherited";
+      }
 
       if($this->fai_activated){
         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
@@ -310,6 +333,8 @@ class workstartup extends plugin
         $map= array("gotoLdapServer","gotoBootKernel");
       }
 
+      $ldap = $this->config->get_ldap_link();
+      $ldap->cat($this->o_group_dn);
       $attrs= $ldap->fetch();
 
       foreach ($map as $name){
@@ -378,9 +403,6 @@ class workstartup extends plugin
       $this->gotoBootKernel= "default";
     }
 
-    if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
-      $this->FAIdebianMirror = "inherited";
-    }
   }
 
   
@@ -440,12 +462,20 @@ class workstartup extends plugin
         else select the first one ..
      */
     $tmp2 = $this->getFAIreleases();
+    if(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
+      foreach($tmp2 as $key => $data){
+        if($data['USE']){
+          $this->FAIrelease = $key;
+        }
+      }
+    }
     if(!in_array($this->FAIrelease, $tmp2)){  
-      $this->FAIrelease = key($tmp2);
+    #  $this->FAIrelease = key($tmp2);
     }
  
     /* Get all Packages for this server/release combination
      */
+
     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
       $pkgs = array();
       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
@@ -501,7 +531,6 @@ class workstartup extends plugin
 
   function execute()
   {
-
        /* Call parent execute */
        plugin::execute();
 
@@ -518,7 +547,7 @@ class workstartup extends plugin
     }
 
     /* Add module */
-    if (isset ($_POST['add_module'])){
+    if (isset ($_POST['add_module']) ){
       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
         $this->add_list ($this->gotoModules, $_POST['module']);
       }
@@ -532,7 +561,7 @@ class workstartup extends plugin
     }
     
     /* FAI class management */
-    if($this->fai_activated){
+    if($this->fai_activated && chkacl($this->acl,"FAIclass") == ""){
 
       if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
         $found = 0 ; 
@@ -638,7 +667,7 @@ class workstartup extends plugin
     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
      * This entry will be, a combination of mountPoint and sharedefinitions
      */
-    if(isset($_POST['gotoShareAdd'])){
+    if(isset($_POST['gotoShareAdd']) && chkacl($this->acl,"gotoShare") ==""){
       /* We assign a share to this user, if we don't know where to mount the share */
       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
         print_red(_("You must specify a valid mount point."));
@@ -656,7 +685,7 @@ class workstartup extends plugin
     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
      * If there is no defined share selected, we will abort the deletion without any message
      */
-    if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
+    if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && chkacl($this->acl,"gotoShare") ==""){
       unset($this->gotoShares[$_POST['gotoShare']]);
     }
 
@@ -692,6 +721,8 @@ class workstartup extends plugin
         $use = " checked ";
       };
 
+      $use .= chkacl($this->acl,"gotoLdapServer");
+
       $display = $server;
 
       $SelectBoxLdapServer->AddEntry(
@@ -760,13 +791,22 @@ class workstartup extends plugin
           }
         }
         $i ++ ; 
+  
+        $desc = ""; 
+        foreach($this->FAIclassInfo[$class] as $types ){
+          if(isset($types['desc'][0])){
+            $desc.= $types['desc'][0]." ";
+          }
+        }
+        if(!empty($desc)){
+          $desc = " [".trim($desc)."]";
+        }        
 
         $div->AddEntry(array(
-              array("string"=>$class.$marker),
+              array("string"=>$class.$desc.$marker),
               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
               ));
       }  
-
       $smarty->assign("FAIScriptlist",$div->DrawList()); 
     }
 
@@ -825,8 +865,16 @@ class workstartup extends plugin
   function getFAIdebianMirrors()
   {
     $ret = array();
-    $ret['inherited']="["._("inherited")."]";
-    $ret['auto']=_("automatic");
+
+    /* Only add inherit option, if we are part in an object group 
+     */
+    if($this->member_of_ogroup)    {
+      $ret['inherited']['NAME']="["._("inherited")."]";
+      $ret['inherited']['USE'] = TRUE;
+    }
+
+    $ret['auto']['NAME']=_("automatic");
+    $ret['auto']['USE'] = TRUE;
     $secs  = array();
 
     /* Walk through all available servers 
@@ -835,15 +883,19 @@ class workstartup extends plugin
      */
     foreach($this->FAIServRepConfig as $mirror => $rest){
 
-      $use = false;
+      /* Automatically selection is available everytime */
+      if($mirror == "auto"){
+        continue;
+      }
 
+      $use = false;
       if(count($this->FAIclass) == 0){
         $use = true;
       }else{
         $tmp = $this->getFAIreleases();
-        foreach($tmp as $release){
-          if(isset($rest['RELEASE'][$release])){
-            $use =true;
+        foreach($tmp as $release => $data){
+          if(isset($rest['RELEASE'][$release]) && $release == $this->FAIrelease){
+            $use = $data['USE']; 
           }
         } 
       }
@@ -851,9 +903,8 @@ class workstartup extends plugin
       /* If current server, doesn't support this class
           remove it from list
        */
-      if($use){
-        $ret[$mirror] = $mirror;
-      }
+      $ret[$mirror]['NAME'] = $mirror;
+      $ret[$mirror]['USE'] = $use;
     }
     return($ret);
   }
@@ -862,13 +913,15 @@ class workstartup extends plugin
   {
     $ret = array();
 
-    if($this->FAIdebianMirror == "inherited") return(array());
+    if($this->FAIdebianMirror == "inherited") {
+      return(array());
+    }
 
     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
       $this->FAIdebianMirror = "auto";
     }
 
-    $errorClasses = array();  
+    $errorClasses = array();
     if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
       foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
         $use = true;
@@ -880,16 +933,16 @@ class workstartup extends plugin
               $errorClasses[$class] = $class;
             }else{
               if(isset($errorClasses[$class])){
-                unset($errorClasses[$class]); 
+                unset($errorClasses[$class]);
               }
             }
           }
         }
-        if($use){
-          $ret[$release]=$release;
-        }
+        $ret[$release]['NAME']=$release;
+        $ret[$release]['USE']=$use;
       }
-    } 
+    }
+
     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
 
       $eClasses = " ";
@@ -906,7 +959,7 @@ class workstartup extends plugin
       foreach($errorClasses as $class){
         $eClasses .= $class." ";
       }
-      
+
       $this->unresolved_classes = $errorClasses;
       $this->FAIdebianMirror = "auto";
       //$this->FAIclass= array();