Code

Fixed FAI.schmea dependencies 2/2
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Manage terminal startup options";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Generic terminal attributes */
10   var $bootmode             = "G";
11   var $goLdapServerList     = array();
12   var $gotoBootKernel       = "default-inherited";
13   var $gotoKernelParameters = "";
14   var $gotoLdapServer       = "default-inherited";
15   var $gotoModules          = array();
16   var $gotoAutoFs           = array();
17   var $gotoFilesystem       = array();
18   var $gotoTerminalPath     = "";
19   var $FAIstatus            = "";
20   var $gotoBootKernels      = array();
22   /* attribute list for save action */
23   var $attributes     = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
24   var $objectclasses  = array("GOhard", "FAIobject");
26   /* Share */
27   var $gotoShares         = array();// Currently Share Option
28   var $gotoShare          = "";     // currently selected Share Option
29   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30   var $gotoAvailableShares= array();// Available Shares for this account
32   /* Helper */
33   var $customParameters   = "";
34   var $orig_dn            = "";
35   var $ignore_account     = TRUE;
36  
37   /* FAI class selection */ 
38   var $FAIclass           = array();
39   var $FAIclasses         = array();
40   var $FAIclassInfo       = array();
41   var $FAIrelease         = "";
42   var $FAIdebianMirror    = "auto";
44   var $unresolved_classes = array();
46   
47   /* FAI class selection */
48   var $InheritedFAIclass           = array();
49   var $InheritedFAIrelease         = "";
50   var $InheritedFAIdebianMirror    = "auto";
52   /* Contains all possible server/release/class settings */
53   var $FAIServRepConfig   = array();
55   var $CopyPasteVars = array("gotoModules","gotoShares");
57   var $fai_activated = FALSE;
59   function workstartup ($config, $dn= NULL, $parent= NULL)
60   {
61     /* Check if FAI is active */
62     $tmp = search_config($config->data,"faiManagement","CLASS");
63     if(!empty($tmp)){
64       $this->fai_activated = TRUE;
65     }else{
66       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
67       $this->objectclasses  = array("GOhard");
68     }
70     plugin::plugin ($config, $dn, $parent);
72     /* Creating a list of valid Mirrors 
73      * none will not be saved to ldap.
74      */
75     $ldap   = $this->config->get_ldap_link();
76     $ldap->cd($this->config->current['BASE']);
78     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
79       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
80     }
81   
83     /* FAI Initialization
84        Skip this if FAI is not activated 
85      */
86       if($this->fai_activated) {
88       $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
89       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
91       /* Search all FAI objects */
92       $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
93       /* Sort all entries, and attach elementtype.
94        * To be able to show the types in the listbox.
95        */
96       while($attr = $ldap->fetch()){
97         $cn = $attr['cn'][0];
98       
99         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
100    
101         if(in_array('FAIpackageList',$attr['objectClass'])){
102           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
103           $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
104           $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
105           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106         }
107         if(in_array('FAItemplate',$attr['objectClass'])){
108           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
109           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
110           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111         }
112         if(in_array('FAIvariable',$attr['objectClass'])){
113           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
114           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
115           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116         }
117         if(in_array('FAIscript',$attr['objectClass'])){
118           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
119           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
120           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121         }
122         if(in_array('FAIhook',$attr['objectClass'])){
123           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
124           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
125           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126         }
127         if(in_array('FAIpartitionTable',$attr['objectClass'])){
128           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
129           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
130           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131         }
132         if(in_array('FAIprofile',$attr['objectClass'])){
133           $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
134           $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
135           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
136         }
137       }
138       if(is_array($this->FAIclasses)){
139         natcasesort($this->FAIclasses);
140       }
142       if(isset($tmp2)){
143         $this->FAIclassInfo = $tmp2;
144       } else {
145         $this->FAIclassInfo = array();
146       }
148       /* Build up an array like this one :
149           [$url]['SERVER'] = 'srv1-002';
150           [$url]['RELEASE']['siga/rc9.0.2']
151                                              ['SECTIONS'][0] "main";
152                                              ['SECTIONS'][1] "non-free";
153           [$url]['RELEASE']['siga/rc9.0.2']
154                                              ['PACKAGES'][0] "pkg1";
155                                              ['PACKAGES'][1] "postfix";
156        */
158       $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
159       $test = array();
160       while($attr = $ldap->fetch()){
161         if(isset($attr['FAIrepository'])){
163           unset($attr['FAIrepository']['count']);
165           foreach($attr['FAIrepository'] as $rep){
166             $tmp = split("\|",$rep);
168             if(count($tmp)==4){
169               $sections = split(",",$tmp[3]);
170               $release  = $tmp[2];
171               $server   = $tmp[1];
172               $url      = $tmp[0];
173              
174               $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
175       
176               /* Result will be cached
177                */
178               $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
179               $test[$url]['SERVER'] = $server;
181               /* auto gets all releases/classes 
182                */
183               $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
184               $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
185             }
186           }
187         }
188       }
189       
190       /* Add possible elements from hook */
191       $lines= $this->GetHookElements();
192       foreach ($lines as $hline){
193         $entries= split(";", $hline);
194         if (isset($entries[1]) && !isset($test[$entries[1]])){
195           $test[$entries[1]]['RELEASE']= array();
197           /* Split releases */
198           if (isset($entries[2])){
199             $releases= split(",", $entries[2]);
201             foreach ($releases as $release){
202               $rname= preg_replace('/:.*$/', '', $release);
203               $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
204               $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
205               $test[$entries[1]]['RELEASE'][$rname]= array();
206               $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
207               foreach ($classes as $class){
208                 if ($class != ""){
209                   $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
210                 }
211               }
212             }
213           }
214         }
215       }
216       
217       $this->FAIServRepConfig= $test;
219       if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
220         $tmp = array();
221         $tmp = split(" ",$this->FAIclass);
222         $tmp2 =array();  
224         foreach($tmp as $class){
225           if( ":" == $class[0] ) {
226             $this->FAIrelease = substr( $class, 1 );
227           }
228           else
229             $tmp2[$class] = $class;
230         }
231         $this->FAIclass = $tmp2;
232       }
234       if(!is_array($this->FAIclass)){
235         $this->FAIclass =array();
236       }
237     }// END of FAI initialization stuff 
240     /* Get arrays */
241     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
242       if (isset($this->attrs["$val"]["count"])){
243         for ($i= 0; $i<$this->attrs["count"]; $i++){
244           if (isset($this->attrs["$val"][$i])){
245             array_push($this->$val, $this->attrs["$val"][$i]);
246           }
247         }
248       }
249       sort ($this->$val);
250       $this->$val= array_unique($this->$val);
251     }
253     /* Parse Kernel Parameters to decide what boot mode is enabled */
254     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
255       $this->bootmode= "G";
256     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
257       $this->bootmode= "D";
258     } elseif ($this->gotoKernelParameters == "") {
259       $this->bootmode= "G";
260     } else {
261       $this->bootmode= "T";
262     }
263     if (preg_match("/ o /", $this->gotoKernelParameters)){
264       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
265     } else {
266       $this->customParameters= "";
267     }
269     /* Prepare Shares */
270     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
271       unset($this->attrs['gotoShare']['count']);
272       foreach($this->attrs['gotoShare'] as $share){
273         $tmp = $tmp2 = array();
274         $tmp = split("\|",$share);
275         $tmp2['server']      =$tmp[0];
276         $tmp2['name']        =$tmp[1];
277         $tmp2['mountPoint']  =$tmp[2];
278         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
279       }
280     }
282     $this->gotoShareSelections= $config->getShareList(true);
283     $this->gotoAvailableShares= $config->getShareList(false);
284     $tmp2 = array();
285   
287     $this->orig_dn= $this->dn;
289     /* Handle inheritance value "default" */
290     $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
292     /* Load hardware list */
293     $ldap= $this->config->get_ldap_link();
294     $ldap->cd($this->config->current['BASE']);
295     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
296     if ($ldap->count() == 1){
298       if($this->fai_activated){
299         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
300       }else{
301         $map= array("gotoLdapServer");
302       }
303       $attrs= $ldap->fetch();
305       foreach ($map as $name){
306         if (!isset($attrs[$name][0])){
307           continue;
308         }
310         switch ($name){
311           case 'gotoLdapServer':
312             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
313             break;
315           case 'gotoBootKernel':
316             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
317             break;
319           case 'FAIclass':
320             $str = split(":",$attrs[$name][0]);
321             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
322             $this->InheritedFAIrelease  = trim($str[1]);
323             break;
325           case 'FAIdebianMirror':
326             $this->InheritedFAIdebianMirror = $attrs[$name][0];
327             break;
328         }
329       }
330     }
332     /* Get list of boot kernels */
333     if (isset($this->config->data['TABS'])){
334       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
336       if (!check_command($command)){
337         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
338             get_class($this));
339       } else {
340         $fh= popen($command, "r");
341         while (!feof($fh)) {
342           $buffer= trim(fgets($fh, 256));
343           
344           if(!empty($buffer)){
345           
346             $name=$value = $buffer;
348             if(preg_match("/:/",$buffer)){
349               $name = preg_replace("/:.*$/","",$buffer);
350               $value= preg_replace("/^.*:/","",$buffer);
351               $this->gotoBootKernels[$name]= $name.":".$value;
352             }else{
353               $this->gotoBootKernels[$name]= $value;
354             }
355           }
357         }
358         pclose($fh);
359       }
360     }
362     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
363       $this->FAIdebianMirror = "inherited";
364     }
365   }
367   
368   /* This class is called by the contrucktor ONLY.
369    *   It return the available classes for each 
370    *    Server / Release combination ... 
371    *   (Release specifies which classes are available) 
372    */
373   function getAvailableClassesForThisRelease($release)
374   {
375     /* There could be more than one server providing this release,
376         so use cached result if available
377      */ 
378     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
379       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
380     }
382     $test2  = array();
383     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
384     $ldap   = $this->config->get_ldap_link();
385     $ldap->cd($this->config->current['BASE']);
386   
387     /* Get classes fpr given release */
388     $p_classes = get_all_objects_for_given_base($bb,
389         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
390           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
391           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
393     /* Create list of classes */
394     foreach($p_classes as $class){
395       $ldap->cat($class['dn'],array("cn"));
396       $attr = $ldap->fetch();
397       $test2[$attr['cn'][0]] = $attr['cn'][0];
398     }
399     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
400     return($test2);
401   }
404   /*  Create array to display available classes/profiles in a selectbox 
405    *   This function only displays the available classes.
406    *   If a class is available is defined by these facts : 
407    *     1. Is this class available for the selected release ?
408    *       - if it is available, check if the release is available for the selected server 
409    *         (done by $this->getFAIreleases())
410    *     2. Is this class currently not assigned to $this->FAIclass
411    */
412   function selectFriendlyClasses(){
413     $tmp=array();
415     if($this->FAIdebianMirror == "inherited") return($tmp);
417     /* check if the current release exists,
418         else select the first one ..
419      */
420     $tmp2 = $this->getFAIreleases();
421     if(!in_array($this->FAIrelease, $tmp2)){  
422       $this->FAIrelease = key($tmp2);
423     }
425     /* Get all Packages for this server/release combination
426      */
427     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
428       $pkgs = array();
429       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
430     }else{
431       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
432     }
434     /* Check each and every single class name 
435      */
436     foreach($pkgs as $pkg){
437   
438       /* Class already assigned to the classes list ?
439        * If not ... go on
440        */
441       if(!in_array($pkg,$this->FAIclass)){
442         
443         /* Create the displayed list entry value
444             HKLMOP [-Pl P V T-] or something like that 
445          */
446         $str = "";
447         foreach($this->FAIclassInfo[$pkg] as $entry){
448           if(isset($entry['kzl'])){
449             $str .= $entry['kzl']." ";
450           }
451         }
452         
453         /* Append class if everyting was fine
454          */        
455         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
456       }
457     }
458     /* Just sort and return new classes list ...
459        ( possibly we should cache the result ... )
460      */
461     natcasesort ($tmp);
462     return($tmp);
463   }
465   function check()
466   {
467     $messages = array();
468     
469     /* Call common method to give check the hook */
470     $messages= plugin::check();
472     /* If there are packages selected, but no mirror show error */   
473     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
474       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
475     }
477     return($messages);
478   }
480   function execute()
481   {
483         /* Call parent execute */
484         plugin::execute();
486     /* Do we need to flip is_account state? */
487     if(isset($_POST['modify_state'])){
488       if($this->is_account && $this->acl_is_removeable()){
489         $this->is_account= FALSE;
490       }elseif(!$this->is_account && $this->acl_is_createable()){
491         $this->is_account= TRUE;
492       }
493     }
495     /* Do we represent a valid terminal? */
496     if (!$this->is_account && $this->parent == NULL){
497       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
498         _("This 'dn' has no terminal features.")."</b>";
499       return ($display);
500     }
502     /* Add module */
503     if (isset ($_POST['add_module'])){
504       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
505         $this->add_list ($this->gotoModules, $_POST['module']);
506       }
507     }
509     /* Delete module */
510     if (isset ($_POST['delete_module'])){
511       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
512         $this->del_list ($this->gotoModules, $_POST['modules_list']);
513       }
514     }
516     /* FAI class management */
517     if($this->fai_activated){
518       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
519         $found = 0 ; 
521         /* If this new class/profile will attach a second partition table
522          * to our list of classes, abort and show a message.
523          */
524         foreach($this->FAIclass as $name){
525           if(isset($this->FAIclassInfo[$name])){
526             foreach($this->FAIclassInfo[$name] as $atr){
527               if(isset($atr['obj'])){
528                 if($atr['obj'] == "FAIpartitionTable"){
529                   $found ++ ; 
530                 }
531               }
532             }
533           }
534         }
536         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
537           print_red(_("There is already a profile in your selection that contain partition table configurations."));
538         }else{
539           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
540         }
541       }
543       $sort = false;
545       /* Move one used class class one position up or down */
546       if($this->acl_is_writeable("FAIclass")){
547         foreach($_POST as $name => $val){
549           $sort_type = false;
550           if((preg_match("/sort_up/",$name))&&(!$sort)){
551             $sort_type = "sort_up_";
552           }
553           if((preg_match("/sort_down/",$name))&&(!$sort)){
554             $sort_type = "sort_down_";
555           }
557           if(($sort_type)&&(!$sort)){
558             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
559             $sort = true;
561             $last = -1;
562             $change_down  = -1;
564             /* Create array with numeric index */ 
565             $tmp = array();
566             foreach($this->FAIclass as $class){
567               $tmp [] = $class;
568             }
570             /* Walk trough array */
571             foreach($tmp as $key => $faiName){
572               if($faiName == $value){
573                 if($sort_type == "sort_up_"){
574                   if($last != -1){
575                     $change_down= $last;
576                   }
577                 }else{
578                   if(isset($tmp[$key+1])){
579                     $change_down = $key;
580                   }
581                 }
582               }
583               $last = $key;
584             }
586             $tmp2 = array();
587             $skip = false;    
589             foreach($tmp as $ky => $vl){
591               if($ky == $change_down){
592                 $skip = $vl;
593               }else{
594                 $tmp2[$vl] = $vl;
595               }
596               if(($skip != false)&&($ky != $change_down)){
597                 $tmp2[$skip]  = $skip;
598                 $skip =false;
599               }
600             }   
601             $this->FAIclass = $tmp2; 
602           }
604           if(preg_match("/fai_remove/i",$name)){
605             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
606             unset($this->FAIclass[$value]);
607           }
608         }
609       }
611       /* Delete selected class from our list */
612       if($this->acl_is_writeable("FAIclass")){
613         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
614           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
615             unset($this->FAIclass[$_POST['FAIclassSel']]);
616           }
617         }
618       }
619     }// END fai handling
621     /* Show main page */
622     $smarty= get_smarty();
624     /* Assign ACLs to smarty */
625     $tmp = $this->plInfo();
626     foreach($tmp['plProvidedAcls'] as $name => $translation){
627       $smarty->assign($name."ACL",$this->getacl($name));
628     } 
630     $smarty->assign("SelectBoxLdapServer","");
632     /* In this section server shares will be defined
633      * A user can select one of the given shares and a mount point
634      *  and attach this combination to his setup.
635      */
636     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
637     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
639     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
640      * This entry will be, a combination of mountPoint and sharedefinitions
641      */
642     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
643       /* We assign a share to this user, if we don't know where to mount the share */
644       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
645         print_red(_("You must specify a valid mount point."));
646       }else{
647         if(count($this->gotoAvailableShares)){
648           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
649           $s_mount = $_POST['gotoShareMountPoint'];
650           /* Preparing the new assignment */
651           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
652           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
653         }
654       }
655     }
657     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
658      * If there is no defined share selected, we will abort the deletion without any message
659      */
660     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
661       unset($this->gotoShares[$_POST['gotoShare']]);
662     }
664     $smarty->assign("gotoShares",$this->printOutAssignedShares());
665     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
666     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
667     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
669     /* Arrays */
670     $tmp = $this->goLdapServerList;
672     /* Create divSelectBox for ldap server selection
673      */
674     $SelectBoxLdapServer = new divSelectBox("LdapServer");
675     $SelectBoxLdapServer->SetHeight(130);
677     /* Set first entry as selected, if $this->gotoLdapServer is empty
678      *  or given entry is no longer available ... 
679      */
680     $found = false;
681     foreach($tmp as $server){
682       if($this->gotoLdapServer==$server){
683         $found = true;
684       }
685     }
687     /* Add Entries 
688      */
689     foreach($tmp as $key => $server){
690       $use ="";
691       if(($this->gotoLdapServer == $server) || ($found == false)) {
692         $found = true;
693         $use = " checked ";
694       };
696       $display = $server;
698       $SelectBoxLdapServer->AddEntry(
699           array(
700             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
701                   "attach"=>"style='border-left:0px;'"),
702             array("string"=>$display)
703             ));
704     }    
706     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
708     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
709       $smarty->assign("$val", $this->$val);
710     }
712     /* Values */
713     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
714       $smarty->assign($val, $this->$val);
715     }
717     $smarty->assign("fai_activated",$this->fai_activated);
719     /* Create FAI output */
720     if($this->fai_activated){
721       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
722       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
723       $smarty->assign("FAIreleases",$this->getFAIreleases());
724       $smarty->assign("FAIrelease",$this->FAIrelease);
725       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
726       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
727       $smarty->assign("FAIclassKeys",$this->FAIclass);
729       $inheritedRelease = array();
730       if(!empty($this->InheritedFAIrelease)){
731         $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
732       } 
733       $smarty->assign("InheritedFAIrelease",$inheritedRelease);
735       $div = new divSelectBox("WSFAIscriptClasses");
736       $div -> SetHeight("110");
737       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
738       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
739       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
740       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
742       $i = 1;
744       if($this->FAIdebianMirror == "inherited"){
745         $tmp = $this->InheritedFAIclass;
746       }else{
747         $tmp = $this->FAIclass;
748       }
750       foreach($tmp as $class){
752         $marker = "";
753         if(in_array_ics($class,$this->unresolved_classes)){
754           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
755         }
757         if($this->FAIdebianMirror == "inherited"){
758           $str = "";
759         }else{
760           if($i==1){
761             $str = $str_empty.$str_down.$str_remove;
762           }elseif($i == count($this->FAIclass)){
763             $str = $str_up.$str_empty.$str_remove;
764           }else{
765             $str = $str_up.$str_down.$str_remove;
766           }
767         }
768         $i ++ ; 
770         $div->AddEntry(array(
771               array("string"=>$class.$marker),
772               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
773               ));
774       }  
776       $smarty->assign("FAIScriptlist",$div->DrawList()); 
777     }// END FAI output generation 
779     /* Radio button group */
780     if (preg_match("/G/", $this->bootmode)) {
781       $smarty->assign("graphicalbootup", "checked");
782     } else {
783       $smarty->assign("graphicalbootup", "");
784     }
785     if (preg_match("/T/", $this->bootmode)) {
786       $smarty->assign("textbootup", "checked");
787     } else {
788       $smarty->assign("textbootup", "");
789     }
790     if (preg_match("/D/", $this->bootmode)) {
791       $smarty->assign("debugbootup", "checked");
792     } else {
793       $smarty->assign("debugbootup", "");
794     }
796     /* Show main page */
797     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
798   }
800   function remove_from_parent()
801   {
802     $this->handle_post_events("remove");
803   }
805   function generateDNSyn($release)
806   {
807     $str = "";
808     $tmp = split("\/",$release);
809     $tmp = array_reverse($tmp);
811     $base = "ou=fai,ou=configs,ou=systems,";   
812     foreach($tmp as $departmentname){
813       
814       $str .= ",ou=".$departmentname;
815     }
816     $str = preg_replace("/^,/","",($str.",".$base));
817     
818     return($str);
819   }
821   function getFAIdebianMirrors()
822   {
823     $ret = array();
824     $ret['inherited']="["._("inherited")."]";
825     $ret['auto']=_("automatic");
826     $secs  = array();
828     /* Walk through all available servers 
829         and check if they support the currently selected classes
830         if not, dont't add them to our list
831      */
832     foreach($this->FAIServRepConfig as $mirror => $rest){
834       $use = false;
836       if(count($this->FAIclass) == 0){
837         $use = true;
838       }else{
839         $tmp = $this->getFAIreleases();
840         foreach($tmp as $release){
841           if(isset($rest['RELEASE'][$release])){
842             $use =true;
843           }
844         } 
845       }
847       /* If current server, doesn't support this class
848           remove it from list
849        */
850       if($use){
851         $ret[$mirror] = $mirror;
852       }
853     }
854     return($ret);
855   }
857   function getFAIreleases() 
858   {
859     $ret = array();
861     if($this->FAIdebianMirror == "inherited") return(array());
863     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
864       $this->FAIdebianMirror = "auto";
865     }
867     $errorClasses = array();  
869     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
870     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
871       $use = true;
872       
873       if(!count($this->FAIclass) == 0){
874         foreach($this->FAIclass as $class){
875           if(!in_array($class, $sections['PACKAGES'])){
876             $use = false;
877             $errorClasses[$class] = $class;
878           }else{
879             if(isset($errorClasses[$class])){
880               unset($errorClasses[$class]); 
881             }
882           }
883         }
884       }
885       if($use){
886         $ret[$release]=$release;
887       }
888     } 
889     }
890     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
892       $eClasses = " ";
893       foreach($errorClasses as $class){
894         $eClasses .= $class." ";
895       }
897       print_red(sprintf(_("Can't resolve one or more of the given FAIclass(es) [%s] in FAI server '%s'. Server was reset to 'auto'."),$eClasses, $this->FAIdebianMirror));
898       $this->FAIdebianMirror = "auto";
899       return($this->getFAIreleases());
900     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
902       $eClasses = " ";
903       foreach($errorClasses as $class){
904         $eClasses .= $class." ";
905       }
907       $eClasses = preg_replace("/  */","",$eClasses);
908      
909       if(!empty($eClasses)) {
911         $this->unresolved_classes = $errorClasses;
912         $this->FAIdebianMirror = "auto";
913         print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. Server was reset to 'auto'."),$eClasses));
914       }
915     }
916     return($ret);
917   }
919   /* Save data to object */
920   function save_object()
921   {
922     plugin::save_object();
924     /* Save group radio buttons */
925     if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
926       $this->bootmode= $_POST["bootmode"];
927     }
929     /* Save kernel parameters */
930     if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
931       $this->customParameters= $_POST["customParameters"];
932     }
934   }
937   /* Save to LDAP */
938   function save()
939   {
941     /* Depending on the baseobject (Ogroup / WS) we
942      *  use another set of objectClasses
943      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
944      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
945      */
946     if(isset($this->parent->by_object['ogroup'])){
947       $this->objectclasses = array("gotoWorkstationTemplate");
948     }elseif(isset($this->parent->by_object['workgeneric'])){
949       $this->objectclasses = array("GOhard");
950     }elseif(isset($this->parent->by_object['servgeneric'])){
951       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
952     }else{
953       print "Object Type Configuration : unknown";
954       exit();
955     }
957     /* Append FAI class */
958     if($this->fai_activated){
959       $this->objectclasses[]  = "FAIobject";
960     }
962     /* Find proper terminal path for tftp configuration
963        FIXME: This is suboptimal when the default has changed to
964        another location! */
965     if (($this->gotoTerminalPath == "default")){
966       $ldap= $this->config->get_ldap_link();
968       /* Strip relevant part from dn, keep trailing ',' */
969       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
970       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
972       /* Walk from top to base and try to load default values for
973          'gotoTerminalPath'. Abort when an entry is found. */
974       while (TRUE){
975         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
977         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
978             $this->config->current['BASE'], array('gotoTerminalPath'));
979         $attrs= $ldap->fetch();
980         if (isset($attrs['gotoTerminalPath'])){
981           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
982           break;
983         }
985         /* Nothing left? */
986         if ($tmp == ""){
987           break;
988         }
989       }
990     }
992     /* Add semi automatic values */
993     // FIXME: LDAP Server may not be set here...
994     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
996     switch ($this->bootmode){
997       case "D":
998         $this->gotoKernelParameters.= " debug";
999       break;
1000       case "G":
1001         $this->gotoKernelParameters.= " splash=silent";
1002       break;
1003     }
1004     if ($this->customParameters != ""){
1005       $this->gotoKernelParameters.= " o ".$this->customParameters;
1006     }
1008     plugin::save();
1010     unset( $this->attrs['FAIrelease'] );
1011     
1012     $str = "";
1014     /* Skip FAI attribute handling if not necessary */
1015     if($this->fai_activated){
1016       if($this->FAIdebianMirror == "inherited"){
1017         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1018       }else{
1019         foreach($this->FAIclass as $class){
1020           $str .= $class." ";
1021         }
1022         $str .= ":" . $this->FAIrelease;
1023         $this->attrs['FAIclass']= "";
1024         $this->attrs['FAIclass']= trim($str);
1026         if(empty($this->attrs['FAIclass'])){
1027           $this->attrs['FAIclass'] = array();
1028         }
1029       }
1030     }
1031   
1032     /* Add missing arrays */
1033     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1034       if (isset ($this->$val) && count ($this->$val) != 0){
1035     
1036         $this->attrs["$val"]= array_unique($this->$val);
1037       }
1038       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1039     }
1041     /* Strip out 'default' values */
1042     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1043       $this->attrs['gotoLdapServer']= array();
1044     }
1046     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1047       $this->attrs['gotoBootKernel']= array();
1048     }
1050     /* if mirror == none stop saving this attribute */
1051     if($this->FAIdebianMirror == "none"){
1052       $this->FAIdebianMirror = "";
1053     }
1054    
1055     /* Get FAIstate from object, the generic tab could have changed it during execute */
1056     $ldap= $this->config->get_ldap_link();
1057     $ldap->cd($this->dn);
1060     /* Skip FAI attribute handling if not necessary */
1061     if($this->fai_activated){
1062       $ldap->cat($this->dn,array("FAIstate"));
1063       $checkFAIstate = $ldap->fetch();
1065       /* Remove FAI objects if no FAI class is selected */ 
1066       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1067         $this->attrs['FAIclass']        = array();
1068         $this->attrs['FAIdebianMirror'] = array();
1069       }
1070     }
1073     /* prepare share settings */
1074     $tmp = array();
1075     foreach($this->gotoShares as $name => $settings){
1076       $tmp2= split("\|",$name);
1077       $name = $tmp2[0];
1078       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1079     }
1080     $this->attrs['gotoShare']=$tmp;
1082     $this->cleanup();
1083     $ldap->modify ($this->attrs); 
1085     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1086     $this->handle_post_events("modify");
1087   }
1089   /* Add value to array, check if unique */
1090   function add_list (&$array, $value)
1091   {
1092     if ($value != ""){
1093       $array[]= $value;
1094       sort($array);
1095       array_unique ($array);
1096     }
1097   }
1100   /* Delete value to array, check if unique */
1101   function del_list (&$array, $list)
1102   {
1103     $tmp= array();
1104     foreach ($array as $mod){
1105       if (!in_array($mod, $list)){
1106         $tmp[]= $mod;
1107       }
1108     }
1109     $array= $tmp;
1110   }
1112   /* Generate ListBox frindly output for the defined shares
1113    * Possibly Add or remove an attribute here,
1114    */
1115   function printOutAssignedShares()
1116   {
1117     $a_return = array();
1118     if(is_array($this->gotoShares)){
1119       foreach($this->gotoShares as $share){
1120         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1121       }
1122     }
1123     return($a_return);
1124   }
1127   function GetHookElements()
1128   {
1129     $ret = array();
1130     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1131     if(!empty($cmd)){
1132       $res = shell_exec($cmd);
1133       $res2 = trim($res);
1134       if((!$res)){
1135         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1136       }elseif(empty($res2)){
1137         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1138       }else{
1139         $tmp = split("\n",$res);
1140         foreach($tmp as $line){
1141           if(empty($line)) continue;
1142           $ret[]= $line;
1143         }
1144       }
1145     }
1146     return($ret);
1147   }
1150   /* Return plugin informations for acl handling */ 
1151   function plInfo()
1152   {
1153     return (array( 
1154           "plShortName"   => _("Startup"),
1155           "plDescription" => _("System startup"),
1156           "plSelfModify"  => FALSE,
1157           "plDepends"     => array(),
1158           "plPriority"    => 9,
1159           "plSection"     => array("administration"),           
1160           "plCategory"    => array("workstation","server","ogroups"),
1162           "plProvidedAcls"=> array(
1163             "gotoLdapServer"        => _("Ldap server"),
1164             "gotoBootKernel"        => _("Boot kernel"),
1165             "gotoKernelParameters"  => _("Kernel parameter"),
1167             "gotoModules"           => _("Kernel modules"),
1168             "gotoShare"             => _("Shares"),
1170             "FAIclass"              => _("FAI classes"),
1171             "FAIdebianMirror"       => _("Debian mirror"),
1172             "FAIrelease"            => _("Debian release"),
1174             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1175           ));
1176   }
1179 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1180 ?>