Code

2fbda70488236f0ae6e09bed98af62f0c586c684
[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     }
366     /* Turn to default, if we've nothing to inherit */
367     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
368       $this->gotoBootKernel= "default";
369     }
371     if($this->is_account){
372       @log::log("view","workstation/".get_class($this),$this->dn);
373     }
374   }
376   
377   /* This class is called by the contrucktor ONLY.
378    *   It return the available classes for each 
379    *    Server / Release combination ... 
380    *   (Release specifies which classes are available) 
381    */
382   function getAvailableClassesForThisRelease($release)
383   {
384     /* There could be more than one server providing this release,
385         so use cached result if available
386      */ 
387     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
388       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
389     }
391     $test2  = array();
392     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
393     $ldap   = $this->config->get_ldap_link();
394     $ldap->cd($this->config->current['BASE']);
395   
396     /* Get classes fpr given release */
397     $p_classes = get_all_objects_for_given_base($bb,
398         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
399           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
400           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
402     /* Create list of classes */
403     foreach($p_classes as $class){
404       $ldap->cat($class['dn'],array("cn"));
405       $attr = $ldap->fetch();
406       $test2[$attr['cn'][0]] = $attr['cn'][0];
407     }
408     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
409     return($test2);
410   }
413   /*  Create array to display available classes/profiles in a selectbox 
414    *   This function only displays the available classes.
415    *   If a class is available is defined by these facts : 
416    *     1. Is this class available for the selected release ?
417    *       - if it is available, check if the release is available for the selected server 
418    *         (done by $this->getFAIreleases())
419    *     2. Is this class currently not assigned to $this->FAIclass
420    */
421   function selectFriendlyClasses(){
422     $tmp=array();
424     if($this->FAIdebianMirror == "inherited") return($tmp);
426     /* check if the current release exists,
427         else select the first one ..
428      */
429     $tmp2 = $this->getFAIreleases();
430     if(!in_array($this->FAIrelease, $tmp2)){  
431       $this->FAIrelease = key($tmp2);
432     }
434     /* Get all Packages for this server/release combination
435      */
436     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
437       $pkgs = array();
438       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
439     }else{
440       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
441     }
443     /* Check each and every single class name 
444      */
445     foreach($pkgs as $pkg){
446   
447       /* Class already assigned to the classes list ?
448        * If not ... go on
449        */
450       if(!in_array($pkg,$this->FAIclass)){
451         
452         /* Create the displayed list entry value
453             HKLMOP [-Pl P V T-] or something like that 
454          */
455         $str = "";
456         foreach($this->FAIclassInfo[$pkg] as $entry){
457           if(isset($entry['kzl'])){
458             $str .= $entry['kzl']." ";
459           }
460         }
461         
462         /* Append class if everyting was fine
463          */        
464         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
465       }
466     }
467     /* Just sort and return new classes list ...
468        ( possibly we should cache the result ... )
469      */
470     natcasesort ($tmp);
471     return($tmp);
472   }
474   function check()
475   {
476     $messages = array();
477     
478     /* Call common method to give check the hook */
479     $messages= plugin::check();
481     /* If there are packages selected, but no mirror show error */   
482     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
483       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
484     }
486     return($messages);
487   }
489   function execute()
490   {
492         /* Call parent execute */
493         plugin::execute();
495     /* Do we need to flip is_account state? */
496     if(isset($_POST['modify_state'])){
497       if($this->is_account && $this->acl_is_removeable()){
498         $this->is_account= FALSE;
499       }elseif(!$this->is_account && $this->acl_is_createable()){
500         $this->is_account= TRUE;
501       }
502     }
504     /* Do we represent a valid terminal? */
505     if (!$this->is_account && $this->parent == NULL){
506       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
507         _("This 'dn' has no terminal features.")."</b>";
508       return ($display);
509     }
511     /* Add module */
512     if (isset ($_POST['add_module'])){
513       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
514         $this->add_list ($this->gotoModules, $_POST['module']);
515       }
516     }
518     /* Delete module */
519     if (isset ($_POST['delete_module'])){
520       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
521         $this->del_list ($this->gotoModules, $_POST['modules_list']);
522       }
523     }
525     /* FAI class management */
526     if($this->fai_activated){
527       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
528         $found = 0 ; 
530         /* If this new class/profile will attach a second partition table
531          * to our list of classes, abort and show a message.
532          */
533         foreach($this->FAIclass as $name){
534           if(isset($this->FAIclassInfo[$name])){
535             foreach($this->FAIclassInfo[$name] as $atr){
536               if(isset($atr['obj'])){
537                 if($atr['obj'] == "FAIpartitionTable"){
538                   $found ++ ; 
539                 }
540               }
541             }
542           }
543         }
545         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
546           print_red(_("There is already a profile in your selection that contain partition table configurations."));
547         }else{
548           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
549         }
550       }
552       $sort = false;
554       /* Move one used class class one position up or down */
555       if($this->acl_is_writeable("FAIclass")){
556         foreach($_POST as $name => $val){
558           $sort_type = false;
559           if((preg_match("/sort_up/",$name))&&(!$sort)){
560             $sort_type = "sort_up_";
561           }
562           if((preg_match("/sort_down/",$name))&&(!$sort)){
563             $sort_type = "sort_down_";
564           }
566           if(($sort_type)&&(!$sort)){
567             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
568             $sort = true;
570             $last = -1;
571             $change_down  = -1;
573             /* Create array with numeric index */ 
574             $tmp = array();
575             foreach($this->FAIclass as $class){
576               $tmp [] = $class;
577             }
579             /* Walk trough array */
580             foreach($tmp as $key => $faiName){
581               if($faiName == $value){
582                 if($sort_type == "sort_up_"){
583                   if($last != -1){
584                     $change_down= $last;
585                   }
586                 }else{
587                   if(isset($tmp[$key+1])){
588                     $change_down = $key;
589                   }
590                 }
591               }
592               $last = $key;
593             }
595             $tmp2 = array();
596             $skip = false;    
598             foreach($tmp as $ky => $vl){
600               if($ky == $change_down){
601                 $skip = $vl;
602               }else{
603                 $tmp2[$vl] = $vl;
604               }
605               if(($skip != false)&&($ky != $change_down)){
606                 $tmp2[$skip]  = $skip;
607                 $skip =false;
608               }
609             }   
610             $this->FAIclass = $tmp2; 
611           }
613           if(preg_match("/fai_remove/i",$name)){
614             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
615             unset($this->FAIclass[$value]);
616           }
617         }
618       }
620       /* Delete selected class from our list */
621       if($this->acl_is_writeable("FAIclass")){
622         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
623           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
624             unset($this->FAIclass[$_POST['FAIclassSel']]);
625           }
626         }
627       }
628     }// END fai handling
630     /* Show main page */
631     $smarty= get_smarty();
633     /* Assign ACLs to smarty */
634     $tmp = $this->plInfo();
635     foreach($tmp['plProvidedAcls'] as $name => $translation){
636       $smarty->assign($name."ACL",$this->getacl($name));
637     } 
639     $smarty->assign("SelectBoxLdapServer","");
641     /* In this section server shares will be defined
642      * A user can select one of the given shares and a mount point
643      *  and attach this combination to his setup.
644      */
645     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
646     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
648     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
649      * This entry will be, a combination of mountPoint and sharedefinitions
650      */
651     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
652       /* We assign a share to this user, if we don't know where to mount the share */
653       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
654         print_red(_("You must specify a valid mount point."));
655       }else{
656         if(count($this->gotoAvailableShares)){
657           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
658           $s_mount = $_POST['gotoShareMountPoint'];
659           /* Preparing the new assignment */
660           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
661           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
662         }
663       }
664     }
666     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
667      * If there is no defined share selected, we will abort the deletion without any message
668      */
669     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
670       unset($this->gotoShares[$_POST['gotoShare']]);
671     }
673     $smarty->assign("gotoShares",$this->printOutAssignedShares());
674     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
675     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
676     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
678     /* Arrays */
679     $tmp = $this->goLdapServerList;
681     /* Create divSelectBox for ldap server selection
682      */
683     $SelectBoxLdapServer = new divSelectBox("LdapServer");
684     $SelectBoxLdapServer->SetHeight(130);
686     /* Set first entry as selected, if $this->gotoLdapServer is empty
687      *  or given entry is no longer available ... 
688      */
689     $found = false;
690     foreach($tmp as $server){
691       if($this->gotoLdapServer==$server){
692         $found = true;
693       }
694     }
696     /* Add Entries 
697      */
698     foreach($tmp as $key => $server){
699       $use ="";
700       if(($this->gotoLdapServer == $server) || ($found == false)) {
701         $found = true;
702         $use = " checked ";
703       };
705       $display = $server;
707       $SelectBoxLdapServer->AddEntry(
708           array(
709             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
710                   "attach"=>"style='border-left:0px;'"),
711             array("string"=>$display)
712             ));
713     }    
715     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
717     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
718       $smarty->assign("$val", $this->$val);
719     }
721     /* Values */
722     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
723       $smarty->assign($val, $this->$val);
724     }
726     $smarty->assign("fai_activated",$this->fai_activated);
728     /* Create FAI output */
729     if($this->fai_activated){
730       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
731       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
732       $smarty->assign("FAIreleases",$this->getFAIreleases());
733       $smarty->assign("FAIrelease",$this->FAIrelease);
734       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
735       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
736       $smarty->assign("FAIclassKeys",$this->FAIclass);
738       $inheritedRelease = array();
739       if(!empty($this->InheritedFAIrelease)){
740         $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
741       } 
742       $smarty->assign("InheritedFAIrelease",$inheritedRelease);
744       $div = new divSelectBox("WSFAIscriptClasses");
745       $div -> SetHeight("110");
746       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
747       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
748       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
749       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
751       $i = 1;
753       if($this->FAIdebianMirror == "inherited"){
754         $tmp = $this->InheritedFAIclass;
755       }else{
756         $tmp = $this->FAIclass;
757       }
759       foreach($tmp as $class){
761         $marker = "";
762         if(in_array_ics($class,$this->unresolved_classes)){
763           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
764         }
766         if($this->FAIdebianMirror == "inherited"){
767           $str = "";
768         }else{
769           if($i==1){
770             $str = $str_empty.$str_down.$str_remove;
771           }elseif($i == count($this->FAIclass)){
772             $str = $str_up.$str_empty.$str_remove;
773           }else{
774             $str = $str_up.$str_down.$str_remove;
775           }
776         }
777         $i ++ ; 
779         $div->AddEntry(array(
780               array("string"=>$class.$marker),
781               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
782               ));
783       }  
785       $smarty->assign("FAIScriptlist",$div->DrawList()); 
786     }// END FAI output generation 
788     /* Radio button group */
789     if (preg_match("/G/", $this->bootmode)) {
790       $smarty->assign("graphicalbootup", "checked");
791     } else {
792       $smarty->assign("graphicalbootup", "");
793     }
794     if (preg_match("/T/", $this->bootmode)) {
795       $smarty->assign("textbootup", "checked");
796     } else {
797       $smarty->assign("textbootup", "");
798     }
799     if (preg_match("/D/", $this->bootmode)) {
800       $smarty->assign("debugbootup", "checked");
801     } else {
802       $smarty->assign("debugbootup", "");
803     }
805     /* Show main page */
806     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
807   }
809   function remove_from_parent()
810   {
811     $this->handle_post_events("remove");
812     @log::log("remove","workstation/".get_class($this),$this->dn);
813   }
815   function generateDNSyn($release)
816   {
817     $str = "";
818     $tmp = split("\/",$release);
819     $tmp = array_reverse($tmp);
821     $base = "ou=fai,ou=configs,ou=systems,";   
822     foreach($tmp as $departmentname){
823       
824       $str .= ",ou=".$departmentname;
825     }
826     $str = preg_replace("/^,/","",($str.",".$base));
827     
828     return($str);
829   }
831   function getFAIdebianMirrors()
832   {
833     $ret = array();
834     $ret['inherited']="["._("inherited")."]";
835     $ret['auto']=_("automatic");
836     $secs  = array();
838     /* Walk through all available servers 
839         and check if they support the currently selected classes
840         if not, dont't add them to our list
841      */
842     foreach($this->FAIServRepConfig as $mirror => $rest){
844       $use = false;
846       if(count($this->FAIclass) == 0){
847         $use = true;
848       }else{
849         $tmp = $this->getFAIreleases();
850         foreach($tmp as $release){
851           if(isset($rest['RELEASE'][$release])){
852             $use =true;
853           }
854         } 
855       }
857       /* If current server, doesn't support this class
858           remove it from list
859        */
860       if($use){
861         $ret[$mirror] = $mirror;
862       }
863     }
864     return($ret);
865   }
867   function getFAIreleases() 
868   {
869     $ret = array();
871     if($this->FAIdebianMirror == "inherited") return(array());
873     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
874       $this->FAIdebianMirror = "auto";
875     }
877     $errorClasses = array();  
879     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
880     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
881       $use = true;
882       
883       if(!count($this->FAIclass) == 0){
884         foreach($this->FAIclass as $class){
885           if(!in_array($class, $sections['PACKAGES'])){
886             $use = false;
887             $errorClasses[$class] = $class;
888           }else{
889             if(isset($errorClasses[$class])){
890               unset($errorClasses[$class]); 
891             }
892           }
893         }
894       }
895       if($use){
896         $ret[$release]=$release;
897       }
898     } 
899     }
900     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
902       $eClasses = " ";
903       foreach($errorClasses as $class){
904         $eClasses .= $class." ";
905       }
907       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));
908       $this->FAIdebianMirror = "auto";
909       return($this->getFAIreleases());
910     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
912       $eClasses = " ";
913       foreach($errorClasses as $class){
914         $eClasses .= $class." ";
915       }
917       $eClasses = preg_replace("/  */","",$eClasses);
918      
919       if(!empty($eClasses)) {
921         $this->unresolved_classes = $errorClasses;
922         $this->FAIdebianMirror = "auto";
923         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));
924       }
925     }
926     return($ret);
927   }
929   /* Save data to object */
930   function save_object()
931   {
932     plugin::save_object();
934     /* Save group radio buttons */
935     if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
936       $this->bootmode= $_POST["bootmode"];
937     }
939     /* Save kernel parameters */
940     if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
941       $this->customParameters= $_POST["customParameters"];
942     }
944   }
947   /* Save to LDAP */
948   function save()
949   {
951     /* Depending on the baseobject (Ogroup / WS) we
952      *  use another set of objectClasses
953      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
954      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
955      */
956     if(isset($this->parent->by_object['ogroup'])){
957       $this->objectclasses = array("gotoWorkstationTemplate");
958     }elseif(isset($this->parent->by_object['workgeneric'])){
959       $this->objectclasses = array("GOhard");
960     }elseif(isset($this->parent->by_object['servgeneric'])){
961       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
962     }else{
963       print "Object Type Configuration : unknown";
964       exit();
965     }
967     /* Append FAI class */
968     if($this->fai_activated){
969       $this->objectclasses[]  = "FAIobject";
970     }
972     /* Find proper terminal path for tftp configuration
973        FIXME: This is suboptimal when the default has changed to
974        another location! */
975     if (($this->gotoTerminalPath == "default")){
976       $ldap= $this->config->get_ldap_link();
978       /* Strip relevant part from dn, keep trailing ',' */
979       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
980       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
982       /* Walk from top to base and try to load default values for
983          'gotoTerminalPath'. Abort when an entry is found. */
984       while (TRUE){
985         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
987         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
988             $this->config->current['BASE'], array('gotoTerminalPath'));
989         $attrs= $ldap->fetch();
990         if (isset($attrs['gotoTerminalPath'])){
991           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
992           break;
993         }
995         /* Nothing left? */
996         if ($tmp == ""){
997           break;
998         }
999       }
1000     }
1002     /* Add semi automatic values */
1003     // FIXME: LDAP Server may not be set here...
1004     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1006     switch ($this->bootmode){
1007       case "D":
1008         $this->gotoKernelParameters.= " debug";
1009       break;
1010       case "G":
1011         $this->gotoKernelParameters.= " splash=silent";
1012       break;
1013     }
1014     if ($this->customParameters != ""){
1015       $this->gotoKernelParameters.= " o ".$this->customParameters;
1016     }
1018     plugin::save();
1020     unset( $this->attrs['FAIrelease'] );
1021     
1022     $str = "";
1024     /* Skip FAI attribute handling if not necessary */
1025     if($this->fai_activated){
1026       if($this->FAIdebianMirror == "inherited"){
1027         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1028       }else{
1029         foreach($this->FAIclass as $class){
1030           $str .= $class." ";
1031         }
1032         $str .= ":" . $this->FAIrelease;
1033         $this->attrs['FAIclass']= "";
1034         $this->attrs['FAIclass']= trim($str);
1036         if(empty($this->attrs['FAIclass'])){
1037           $this->attrs['FAIclass'] = array();
1038         }
1039       }
1040     }
1041   
1042     /* Add missing arrays */
1043     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1044       if (isset ($this->$val) && count ($this->$val) != 0){
1045     
1046         $this->attrs["$val"]= array_unique($this->$val);
1047       }
1048       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1049     }
1051     /* Strip out 'default' values */
1052     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1053       $this->attrs['gotoLdapServer']= array();
1054     }
1056     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1057       $this->attrs['gotoBootKernel']= array();
1058     }
1060     /* if mirror == none stop saving this attribute */
1061     if($this->FAIdebianMirror == "none"){
1062       $this->FAIdebianMirror = "";
1063     }
1064    
1065     /* Get FAIstate from object, the generic tab could have changed it during execute */
1066     $ldap= $this->config->get_ldap_link();
1067     $ldap->cd($this->dn);
1070     /* Skip FAI attribute handling if not necessary */
1071     if($this->fai_activated){
1072       $ldap->cat($this->dn,array("FAIstate"));
1073       $checkFAIstate = $ldap->fetch();
1075       /* Remove FAI objects if no FAI class is selected */ 
1076       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1077         $this->attrs['FAIclass']        = array();
1078         $this->attrs['FAIdebianMirror'] = array();
1079       }
1080     }
1083     /* prepare share settings */
1084     $tmp = array();
1085     foreach($this->gotoShares as $name => $settings){
1086       $tmp2= split("\|",$name);
1087       $name = $tmp2[0];
1088       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1089     }
1090     $this->attrs['gotoShare']=$tmp;
1092     $this->cleanup();
1093     $ldap->modify ($this->attrs); 
1094     @log::log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1096     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1097     $this->handle_post_events("modify");
1098   }
1100   /* Add value to array, check if unique */
1101   function add_list (&$array, $value)
1102   {
1103     if ($value != ""){
1104       $array[]= $value;
1105       sort($array);
1106       array_unique ($array);
1107     }
1108   }
1111   /* Delete value to array, check if unique */
1112   function del_list (&$array, $list)
1113   {
1114     $tmp= array();
1115     foreach ($array as $mod){
1116       if (!in_array($mod, $list)){
1117         $tmp[]= $mod;
1118       }
1119     }
1120     $array= $tmp;
1121   }
1123   /* Generate ListBox frindly output for the defined shares
1124    * Possibly Add or remove an attribute here,
1125    */
1126   function printOutAssignedShares()
1127   {
1128     $a_return = array();
1129     if(is_array($this->gotoShares)){
1130       foreach($this->gotoShares as $share){
1131         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1132       }
1133     }
1134     return($a_return);
1135   }
1138   function GetHookElements()
1139   {
1140     $ret = array();
1141     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1142     if(!empty($cmd)){
1143       $res = shell_exec($cmd);
1144       $res2 = trim($res);
1145       if((!$res)){
1146         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1147       }elseif(empty($res2)){
1148         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1149       }else{
1150         $tmp = split("\n",$res);
1151         foreach($tmp as $line){
1152           if(empty($line)) continue;
1153           $ret[]= $line;
1154         }
1155       }
1156     }
1157     return($ret);
1158   }
1161   /* Return plugin informations for acl handling */ 
1162   function plInfo()
1163   {
1164     return (array( 
1165           "plShortName"   => _("Startup"),
1166           "plDescription" => _("System startup"),
1167           "plSelfModify"  => FALSE,
1168           "plDepends"     => array(),
1169           "plPriority"    => 9,
1170           "plSection"     => array("administration"),           
1171           "plCategory"    => array("workstation","server","ogroups"),
1173           "plProvidedAcls"=> array(
1174             "gotoLdapServer"        => _("Ldap server"),
1175             "gotoBootKernel"        => _("Boot kernel"),
1176             "gotoKernelParameters"  => _("Kernel parameter"),
1178             "gotoModules"           => _("Kernel modules"),
1179             "gotoShare"             => _("Shares"),
1181             "FAIclass"              => _("FAI classes"),
1182             "FAIdebianMirror"       => _("Debian mirror"),
1183             "FAIrelease"            => _("Debian release"),
1185             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1186           ));
1187   }
1190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1191 ?>