Code

ACL: Skip listing system snapshot that we are not able to restore.
[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   function workstartup ($config, $dn= NULL, $parent= NULL)
58   {
59     plugin::plugin ($config, $dn, $parent);
61     /* Creating a list of valid Mirrors 
62      * none will not be saved to ldap.
63      */
64     $ldap   = $this->config->get_ldap_link();
65     $ldap->cd($this->config->current['BASE']);
67     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
68       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
69     }
70    
71     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
72     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
74     /* Search all FAI objects */
75     $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
76     /* Sort all entries, and attach elementtype.
77      * To be able to show the types in the listbox.
78      */
79     while($attr = $ldap->fetch()){
80       $cn = $attr['cn'][0];
81     
82       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
83  
84       if(in_array('FAIpackageList',$attr['objectClass'])){
85         $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
86         $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
87         $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
88         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
89       }
90       if(in_array('FAItemplate',$attr['objectClass'])){
91         $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
92         $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
93         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
94       }
95       if(in_array('FAIvariable',$attr['objectClass'])){
96         $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
97         $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
98         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
99       }
100       if(in_array('FAIscript',$attr['objectClass'])){
101         $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
102         $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
103         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
104       }
105       if(in_array('FAIhook',$attr['objectClass'])){
106         $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
107         $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
108         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
109       }
110       if(in_array('FAIpartitionTable',$attr['objectClass'])){
111         $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
112         $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
113         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
114       }
115       if(in_array('FAIprofile',$attr['objectClass'])){
116         $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
117         $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
118         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
119       }
120     }
121     if(is_array($this->FAIclasses)){
122       natcasesort($this->FAIclasses);
123     }
125     if(isset($tmp2)){
126       $this->FAIclassInfo = $tmp2;
127     } else {
128       $this->FAIclassInfo = array();
129     }
131     /* Build up an array like this one :
132         [$url]['SERVER'] = 'srv1-002';
133         [$url]['RELEASE']['siga/rc9.0.2']
134                                            ['SECTIONS'][0] "main";
135                                            ['SECTIONS'][1] "non-free";
136         [$url]['RELEASE']['siga/rc9.0.2']
137                                            ['PACKAGES'][0] "pkg1";
138                                            ['PACKAGES'][1] "postfix";
139      */
141     $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
142     $test = array();
143     while($attr = $ldap->fetch()){
144       if(isset($attr['FAIrepository'])){
146         unset($attr['FAIrepository']['count']);
148         foreach($attr['FAIrepository'] as $rep){
149           $tmp = split("\|",$rep);
151           if(count($tmp)==4){
152             $sections = split(",",$tmp[3]);
153             $release  = $tmp[2];
154             $server   = $tmp[1];
155             $url      = $tmp[0];
156            
157             $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
158     
159             /* Result will be cached
160              */
161             $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
162             $test[$url]['SERVER'] = $server;
164             /* auto gets all releases/classes 
165              */
166             $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
167             $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
168           }
169         }
170       }
171     }
172     
173     /* Add possible elements from hook */
174     $lines= $this->GetHookElements();
175     foreach ($lines as $hline){
176       $entries= split(";", $hline);
177       if (isset($entries[1]) && !isset($test[$entries[1]])){
178         $test[$entries[1]]['RELEASE']= array();
180         /* Split releases */
181         if (isset($entries[2])){
182           $releases= split(",", $entries[2]);
184           foreach ($releases as $release){
185             $rname= preg_replace('/:.*$/', '', $release);
186             $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
187             $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
188             $test[$entries[1]]['RELEASE'][$rname]= array();
189             $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
190             foreach ($classes as $class){
191               if ($class != ""){
192                 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
193               }
194             }
195           }
196         }
197       }
198     }
199     
200     $this->FAIServRepConfig= $test;
202     /* Get arrays */
203     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
204       if (isset($this->attrs["$val"]["count"])){
205         for ($i= 0; $i<$this->attrs["count"]; $i++){
206           if (isset($this->attrs["$val"][$i])){
207             array_push($this->$val, $this->attrs["$val"][$i]);
208           }
209         }
210       }
211       sort ($this->$val);
212       $this->$val= array_unique($this->$val);
213     }
215     /* Parse Kernel Parameters to decide what boot mode is enabled */
216     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
217       $this->bootmode= "G";
218     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
219       $this->bootmode= "D";
220     } elseif ($this->gotoKernelParameters == "") {
221       $this->bootmode= "G";
222     } else {
223       $this->bootmode= "T";
224     }
225     if (preg_match("/ o /", $this->gotoKernelParameters)){
226       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
227     } else {
228       $this->customParameters= "";
229     }
231     /* Prepare Shares */
232     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
233       unset($this->attrs['gotoShare']['count']);
234       foreach($this->attrs['gotoShare'] as $share){
235         $tmp = $tmp2 = array();
236         $tmp = split("\|",$share);
237         $tmp2['server']      =$tmp[0];
238         $tmp2['name']        =$tmp[1];
239         $tmp2['mountPoint']  =$tmp[2];
240         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
241       }
242     }
244     $this->gotoShareSelections= $config->getShareList(true);
245     $this->gotoAvailableShares= $config->getShareList(false);
246     $tmp2 = array();
247   
248     if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
249       $tmp = array();
250       $tmp = split(" ",$this->FAIclass);
251       $tmp2 =array();  
252     
253       foreach($tmp as $class){
254         if( ":" == $class[0] ) {
255           $this->FAIrelease = substr( $class, 1 );
256         }
257         else
258           $tmp2[$class] = $class;
259       }
260       $this->FAIclass = $tmp2;
261     }
263     if(!is_array($this->FAIclass)){
264       $this->FAIclass =array();
265     }
267     $this->orig_dn= $this->dn;
269     /* Handle inheritance value "default" */
270     $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
272     /* Load hardware list */
273     $ldap= $this->config->get_ldap_link();
274     $ldap->cd($this->config->current['BASE']);
275     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
276     if ($ldap->count() == 1){
277       $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
278       $attrs= $ldap->fetch();
280       foreach ($map as $name){
281         if (!isset($attrs[$name][0])){
282           continue;
283         }
285         switch ($name){
286           case 'gotoLdapServer':
287             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
288             break;
290           case 'gotoBootKernel':
291             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
292             break;
294           case 'FAIclass':
295             $str = split(":",$attrs[$name][0]);
296             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
297             $this->InheritedFAIrelease  = trim($str[1]);
298             break;
300           case 'FAIdebianMirror':
301             $this->InheritedFAIdebianMirror = $attrs[$name][0];
302             break;
303         }
304       }
305     }
307     /* Get list of boot kernels */
308     if (isset($this->config->data['TABS'])){
309       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
311       if (!check_command($command)){
312         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
313             get_class($this));
314       } else {
315         $fh= popen($command, "r");
316         while (!feof($fh)) {
317           $buffer= trim(fgets($fh, 256));
318           
319           if(!empty($buffer)){
320           
321             $name=$value = $buffer;
323             if(preg_match("/:/",$buffer)){
324               $name = preg_replace("/:.*$/","",$buffer);
325               $value= preg_replace("/^.*:/","",$buffer);
326               $this->gotoBootKernels[$name]= $name.":".$value;
327             }else{
328               $this->gotoBootKernels[$name]= $value;
329             }
330           }
332         }
333         pclose($fh);
334       }
335     }
337     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
338       $this->FAIdebianMirror = "inherited";
339     }
340   }
342   
343   /* This class is called by the contrucktor ONLY.
344    *   It return the available classes for each 
345    *    Server / Release combination ... 
346    *   (Release specifies which classes are available) 
347    */
348   function getAvailableClassesForThisRelease($release)
349   {
350     /* There could be more than one server providing this release,
351         so use cached result if available
352      */ 
353     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
354       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
355     }
357     $test2  = array();
358     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
359     $ldap   = $this->config->get_ldap_link();
360     $ldap->cd($this->config->current['BASE']);
361   
362     /* Get classes fpr given release */
363     $p_classes = get_all_objects_for_given_base($bb,
364         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
365           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
366           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
368     /* Create list of classes */
369     foreach($p_classes as $class){
370       $ldap->cat($class['dn'],array("cn"));
371       $attr = $ldap->fetch();
372       $test2[$attr['cn'][0]] = $attr['cn'][0];
373     }
374     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
375     return($test2);
376   }
379   /*  Create array to display available classes/profiles in a selectbox 
380    *   This function only displays the available classes.
381    *   If a class is available is defined by these facts : 
382    *     1. Is this class available for the selected release ?
383    *       - if it is available, check if the release is available for the selected server 
384    *         (done by $this->getFAIreleases())
385    *     2. Is this class currently not assigned to $this->FAIclass
386    */
387   function selectFriendlyClasses(){
388     $tmp=array();
390     if($this->FAIdebianMirror == "inherited") return($tmp);
392     /* check if the current release exists,
393         else select the first one ..
394      */
395     $tmp2 = $this->getFAIreleases();
396     if(!in_array($this->FAIrelease, $tmp2)){  
397       $this->FAIrelease = key($tmp2);
398     }
400     /* Get all Packages for this server/release combination
401      */
402     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
403       $pkgs = array();
404       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
405     }else{
406       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
407     }
409     /* Check each and every single class name 
410      */
411     foreach($pkgs as $pkg){
412   
413       /* Class already assigned to the classes list ?
414        * If not ... go on
415        */
416       if(!in_array($pkg,$this->FAIclass)){
417         
418         /* Create the displayed list entry value
419             HKLMOP [-Pl P V T-] or something like that 
420          */
421         $str = "";
422         foreach($this->FAIclassInfo[$pkg] as $entry){
423           if(isset($entry['kzl'])){
424             $str .= $entry['kzl']." ";
425           }
426         }
427         
428         /* Append class if everyting was fine
429          */        
430         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
431       }
432     }
433     /* Just sort and return new classes list ...
434        ( possibly we should cache the result ... )
435      */
436     natcasesort ($tmp);
437     return($tmp);
438   }
440   function check()
441   {
442     $messages = array();
443     
444     /* Call common method to give check the hook */
445     $messages= plugin::check();
447     /* If there are packages selected, but no mirror show error */   
448     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
449       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
450     }
452     return($messages);
453   }
455   function execute()
456   {
458         /* Call parent execute */
459         plugin::execute();
461     /* Do we need to flip is_account state? */
462     if(isset($_POST['modify_state'])){
463       if($this->is_account && $this->acl_is_removeable()){
464         $this->is_account= FALSE;
465       }elseif(!$this->is_account && $this->acl_is_createable()){
466         $this->is_account= TRUE;
467       }
468     }
470     /* Do we represent a valid terminal? */
471     if (!$this->is_account && $this->parent == NULL){
472       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
473         _("This 'dn' has no terminal features.")."</b>";
474       return ($display);
475     }
477     /* Add module */
478     if (isset ($_POST['add_module'])){
479       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
480         $this->add_list ($this->gotoModules, $_POST['module']);
481       }
482     }
484     /* Delete module */
485     if (isset ($_POST['delete_module'])){
486       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
487         $this->del_list ($this->gotoModules, $_POST['modules_list']);
488       }
489     }
491     /* FAI class management */
492     if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
493       $found = 0 ; 
495       /* If this new class/profile will attach a second partition table
496        * to our list of classes, abort and show a message.
497        */
498       foreach($this->FAIclass as $name){
499         if(isset($this->FAIclassInfo[$name])){
500           foreach($this->FAIclassInfo[$name] as $atr){
501             if(isset($atr['obj'])){
502               if($atr['obj'] == "FAIpartitionTable"){
503                 $found ++ ; 
504               }
505             }
506           }
507         }
508       }
510       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
511         print_red(_("There is already a profile in your selection that contain partition table configurations."));
512       }else{
513         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
514       }
515     }
517     $sort = false;
519     /* Move one used class class one position up or down */
520     if($this->acl_is_writeable("FAIclass")){
521       foreach($_POST as $name => $val){
523         $sort_type = false;
524         if((preg_match("/sort_up/",$name))&&(!$sort)){
525           $sort_type = "sort_up_";
526         }
527         if((preg_match("/sort_down/",$name))&&(!$sort)){
528           $sort_type = "sort_down_";
529         }
531         if(($sort_type)&&(!$sort)){
532           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
533           $sort = true;
535           $last = -1;
536           $change_down  = -1;
538           /* Create array with numeric index */ 
539           $tmp = array();
540           foreach($this->FAIclass as $class){
541             $tmp [] = $class;
542           }
544           /* Walk trough array */
545           foreach($tmp as $key => $faiName){
546             if($faiName == $value){
547               if($sort_type == "sort_up_"){
548                 if($last != -1){
549                   $change_down= $last;
550                 }
551               }else{
552                 if(isset($tmp[$key+1])){
553                   $change_down = $key;
554                 }
555               }
556             }
557             $last = $key;
558           }
560           $tmp2 = array();
561           $skip = false;    
563           foreach($tmp as $ky => $vl){
565             if($ky == $change_down){
566               $skip = $vl;
567             }else{
568               $tmp2[$vl] = $vl;
569             }
570             if(($skip != false)&&($ky != $change_down)){
571               $tmp2[$skip]  = $skip;
572               $skip =false;
573             }
574           }   
575           $this->FAIclass = $tmp2; 
576         }
578         if(preg_match("/fai_remove/i",$name)){
579           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
580           unset($this->FAIclass[$value]);
581         }
582       }
583     }
585     /* Delete selected class from our list */
586     if($this->acl_is_writeable("FAIclass")){
587       if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
588         if(isset($this->FAIclass[$_POST['FAIclassSel']])){
589           unset($this->FAIclass[$_POST['FAIclassSel']]);
590         }
591       }
592     }
594     /* Show main page */
595     $smarty= get_smarty();
597     /* Assign ACLs to smarty */
598     $tmp = $this->plInfo();
599     foreach($tmp['plProvidedAcls'] as $name => $translation){
600       $smarty->assign($name."ACL",$this->getacl($name));
601     } 
603     $smarty->assign("SelectBoxLdapServer","");
605     /* In this section server shares will be defined
606      * A user can select one of the given shares and a mount point
607      *  and attach this combination to his setup.
608      */
609     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
610     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
612     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
613      * This entry will be, a combination of mountPoint and sharedefinitions
614      */
615     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
616       /* We assign a share to this user, if we don't know where to mount the share */
617       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
618         print_red(_("You must specify a valid mount point."));
619       }else{
620         if(count($this->gotoAvailableShares)){
621           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
622           $s_mount = $_POST['gotoShareMountPoint'];
623           /* Preparing the new assignment */
624           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
625           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
626         }
627       }
628     }
630     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
631      * If there is no defined share selected, we will abort the deletion without any message
632      */
633     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
634       unset($this->gotoShares[$_POST['gotoShare']]);
635     }
637     $smarty->assign("gotoShares",$this->printOutAssignedShares());
638     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
639     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
640     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
642     /* Arrays */
643     $tmp = $this->goLdapServerList;
645     /* Create divSelectBox for ldap server selection
646      */
647     $SelectBoxLdapServer = new divSelectBox("LdapServer");
648     $SelectBoxLdapServer->SetHeight(130);
650     /* Set first entry as selected, if $this->gotoLdapServer is empty
651      *  or given entry is no longer available ... 
652      */
653     $found = false;
654     foreach($tmp as $server){
655       if($this->gotoLdapServer==$server){
656         $found = true;
657       }
658     }
660     /* Add Entries 
661      */
662     foreach($tmp as $key => $server){
663       $use ="";
664       if(($this->gotoLdapServer == $server) || ($found == false)) {
665         $found = true;
666         $use = " checked ";
667       };
669       $display = $server;
671       $SelectBoxLdapServer->AddEntry(
672           array(
673             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
674                   "attach"=>"style='border-left:0px;'"),
675             array("string"=>$display)
676             ));
677     }    
679     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
681     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
682       $smarty->assign("$val", $this->$val);
683     }
685     /* Values */
686     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
687       $smarty->assign($val, $this->$val);
688     }
690     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
691     $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
692     $smarty->assign("FAIreleases",$this->getFAIreleases());
693     $smarty->assign("FAIrelease",$this->FAIrelease);
694     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
695     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
696     $smarty->assign("FAIclassKeys",$this->FAIclass);
697   
698     $inheritedRelease = array();
699     if(!empty($this->InheritedFAIrelease)){
700       $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
701     } 
702     $smarty->assign("InheritedFAIrelease",$inheritedRelease);
703  
704     $div = new divSelectBox("WSFAIscriptClasses");
705     $div -> SetHeight("110");
706     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
707     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
708     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
709     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
711     $i = 1;
713     if($this->FAIdebianMirror == "inherited"){
714       $tmp = $this->InheritedFAIclass;
715     }else{
716       $tmp = $this->FAIclass;
717     }
719     foreach($tmp as $class){
721       $marker = "";
722       if(in_array_ics($class,$this->unresolved_classes)){
723         $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
724       }
726       if($this->FAIdebianMirror == "inherited"){
727         $str = "";
728       }else{
729         if($i==1){
730           $str = $str_empty.$str_down.$str_remove;
731         }elseif($i == count($this->FAIclass)){
732           $str = $str_up.$str_empty.$str_remove;
733         }else{
734           $str = $str_up.$str_down.$str_remove;
735         }
736       }
737       $i ++ ; 
739       $div->AddEntry(array(
740             array("string"=>$class.$marker),
741             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
742             ));
743     }  
745     $smarty->assign("FAIScriptlist",$div->DrawList()); 
747     /* Radio button group */
748     if (preg_match("/G/", $this->bootmode)) {
749       $smarty->assign("graphicalbootup", "checked");
750     } else {
751       $smarty->assign("graphicalbootup", "");
752     }
753     if (preg_match("/T/", $this->bootmode)) {
754       $smarty->assign("textbootup", "checked");
755     } else {
756       $smarty->assign("textbootup", "");
757     }
758     if (preg_match("/D/", $this->bootmode)) {
759       $smarty->assign("debugbootup", "checked");
760     } else {
761       $smarty->assign("debugbootup", "");
762     }
764     /* Show main page */
765     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
766   }
768   function remove_from_parent()
769   {
770     $this->handle_post_events("remove");
771   }
773   function generateDNSyn($release)
774   {
775     $str = "";
776     $tmp = split("\/",$release);
777     $tmp = array_reverse($tmp);
779     $base = "ou=fai,ou=configs,ou=systems,";   
780     foreach($tmp as $departmentname){
781       
782       $str .= ",ou=".$departmentname;
783     }
784     $str = preg_replace("/^,/","",($str.",".$base));
785     
786     return($str);
787   }
789   function getFAIdebianMirrors()
790   {
791     $ret = array();
792     $ret['inherited']="["._("inherited")."]";
793     $ret['auto']=_("automatic");
794     $secs  = array();
796     /* Walk through all available servers 
797         and check if they support the currently selected classes
798         if not, dont't add them to our list
799      */
800     foreach($this->FAIServRepConfig as $mirror => $rest){
802       $use = false;
804       if(count($this->FAIclass) == 0){
805         $use = true;
806       }else{
807         $tmp = $this->getFAIreleases();
808         foreach($tmp as $release){
809           if(isset($rest['RELEASE'][$release])){
810             $use =true;
811           }
812         } 
813       }
815       /* If current server, doesn't support this class
816           remove it from list
817        */
818       if($use){
819         $ret[$mirror] = $mirror;
820       }
821     }
822     return($ret);
823   }
825   function getFAIreleases() 
826   {
827     $ret = array();
829     if($this->FAIdebianMirror == "inherited") return(array());
831     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
832       $this->FAIdebianMirror = "auto";
833     }
835     $errorClasses = array();  
837     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
838     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
839       $use = true;
840       
841       if(!count($this->FAIclass) == 0){
842         foreach($this->FAIclass as $class){
843           if(!in_array($class, $sections['PACKAGES'])){
844             $use = false;
845             $errorClasses[$class] = $class;
846           }else{
847             if(isset($errorClasses[$class])){
848               unset($errorClasses[$class]); 
849             }
850           }
851         }
852       }
853       if($use){
854         $ret[$release]=$release;
855       }
856     } 
857     }
858     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
860       $eClasses = " ";
861       foreach($errorClasses as $class){
862         $eClasses .= $class." ";
863       }
865       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));
866       $this->FAIdebianMirror = "auto";
867       return($this->getFAIreleases());
868     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
870       $eClasses = " ";
871       foreach($errorClasses as $class){
872         $eClasses .= $class." ";
873       }
875       $eClasses = preg_replace("/  */","",$eClasses);
876      
877       if(!empty($eClasses)) {
879         $this->unresolved_classes = $errorClasses;
880         $this->FAIdebianMirror = "auto";
881         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));
882       }
883     }
884     return($ret);
885   }
887   /* Save data to object */
888   function save_object()
889   {
890     plugin::save_object();
892     /* Save group radio buttons */
893     if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
894       $this->bootmode= $_POST["bootmode"];
895     }
897     /* Save kernel parameters */
898     if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
899       $this->customParameters= $_POST["customParameters"];
900     }
902   }
905   /* Save to LDAP */
906   function save()
907   {
909     /* Depending on the baseobject (Ogroup / WS) we
910      *  use another set of objectClasses
911      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
912      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
913      */
914     if(isset($this->parent->by_object['ogroup'])){
915       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
916     }elseif(isset($this->parent->by_object['workgeneric'])){
917       $this->objectclasses = array("GOhard", "FAIobject");
918     }elseif(isset($this->parent->by_object['servgeneric'])){
919       $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
920     }else{
921       print "Object Type Configuration : unknown";
922       exit();
923     }
925     /* Find proper terminal path for tftp configuration
926        FIXME: This is suboptimal when the default has changed to
927        another location! */
928     if (($this->gotoTerminalPath == "default")){
929       $ldap= $this->config->get_ldap_link();
931       /* Strip relevant part from dn, keep trailing ',' */
932       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
933       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
935       /* Walk from top to base and try to load default values for
936          'gotoTerminalPath'. Abort when an entry is found. */
937       while (TRUE){
938         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
940         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
941             $this->config->current['BASE'], array('gotoTerminalPath'));
942         $attrs= $ldap->fetch();
943         if (isset($attrs['gotoTerminalPath'])){
944           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
945           break;
946         }
948         /* Nothing left? */
949         if ($tmp == ""){
950           break;
951         }
952       }
953     }
955     /* Add semi automatic values */
956     // FIXME: LDAP Server may not be set here...
957     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
959     switch ($this->bootmode){
960       case "D":
961         $this->gotoKernelParameters.= " debug";
962       break;
963       case "G":
964         $this->gotoKernelParameters.= " splash=silent";
965       break;
966     }
967     if ($this->customParameters != ""){
968       $this->gotoKernelParameters.= " o ".$this->customParameters;
969     }
971     plugin::save();
973     unset( $this->attrs['FAIrelease'] );
974     
975     $str = "";
977     if($this->FAIdebianMirror == "inherited"){
978   
979       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
981     }else{
983       foreach($this->FAIclass as $class){
984         $str .= $class." ";
985       }
986       $str .= ":" . $this->FAIrelease;
987       $this->attrs['FAIclass']= "";
988       $this->attrs['FAIclass']= trim($str);
990       if(empty($this->attrs['FAIclass'])){
991         $this->attrs['FAIclass'] = array();
992       }
993     }
995     /* Add missing arrays */
996     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
997       if (isset ($this->$val) && count ($this->$val) != 0){
998     
999         $this->attrs["$val"]= array_unique($this->$val);
1000       }
1001       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1002     }
1004     /* Strip out 'default' values */
1005     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1006       $this->attrs['gotoLdapServer']= array();
1007     }
1009     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1010       $this->attrs['gotoBootKernel']= array();
1011     }
1013     /* if mirror == none stop saving this attribute */
1014     if($this->FAIdebianMirror == "none"){
1015       $this->FAIdebianMirror = "";
1016     }
1017    
1018     /* Get FAIstate from object, the generic tab could have changed it during execute */
1019     $ldap= $this->config->get_ldap_link();
1020     $ldap->cd($this->dn);
1021     $ldap->cat($this->dn,array("FAIstate"));
1022     $checkFAIstate = $ldap->fetch();
1024     /* Remove FAI objects if no FAI class is selected */ 
1025     if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1026       $this->attrs['FAIclass']        = array();
1027       $this->attrs['FAIdebianMirror'] = array();
1028     }
1030     /* prepare share settings */
1031     $tmp = array();
1032     foreach($this->gotoShares as $name => $settings){
1033       $tmp2= split("\|",$name);
1034       $name = $tmp2[0];
1035       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1036     }
1037     $this->attrs['gotoShare']=$tmp;
1039     $this->cleanup();
1040     $ldap->modify ($this->attrs); 
1042     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1043     $this->handle_post_events("modify");
1044   }
1046   /* Add value to array, check if unique */
1047   function add_list (&$array, $value)
1048   {
1049     if ($value != ""){
1050       $array[]= $value;
1051       sort($array);
1052       array_unique ($array);
1053     }
1054   }
1057   /* Delete value to array, check if unique */
1058   function del_list (&$array, $list)
1059   {
1060     $tmp= array();
1061     foreach ($array as $mod){
1062       if (!in_array($mod, $list)){
1063         $tmp[]= $mod;
1064       }
1065     }
1066     $array= $tmp;
1067   }
1069   /* Generate ListBox frindly output for the defined shares
1070    * Possibly Add or remove an attribute here,
1071    */
1072   function printOutAssignedShares()
1073   {
1074     $a_return = array();
1075     if(is_array($this->gotoShares)){
1076       foreach($this->gotoShares as $share){
1077         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1078       }
1079     }
1080     return($a_return);
1081   }
1084   function GetHookElements()
1085   {
1086     $ret = array();
1087     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1088     if(!empty($cmd)){
1089       $res = shell_exec($cmd);
1090       $res2 = trim($res);
1091       if((!$res)){
1092         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1093       }elseif(empty($res2)){
1094         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1095       }else{
1096         $tmp = split("\n",$res);
1097         foreach($tmp as $line){
1098           if(empty($line)) continue;
1099           $ret[]= $line;
1100         }
1101       }
1102     }
1103     return($ret);
1104   }
1107   /* Return plugin informations for acl handling */ 
1108   function plInfo()
1109   {
1110     return (array( 
1111           "plShortName"   => _("Startup"),
1112           "plDescription" => _("System startup"),
1113           "plSelfModify"  => FALSE,
1114           "plDepends"     => array(),
1115           "plPriority"    => 9,
1116           "plSection"     => array("administration"),           
1117           "plCategory"    => array("workstation","server","ogroups"),
1119           "plProvidedAcls"=> array(
1120             "gotoLdapServer"        => _("Ldap server"),
1121             "gotoBootKernel"        => _("Boot kernel"),
1122             "gotoKernelParameters"  => _("Kernel parameter"),
1124             "gotoModules"           => _("Kernel modules"),
1125             "gotoShare"             => _("Shares"),
1127             "FAIclass"              => _("FAI classes"),
1128             "FAIdebianMirror"       => _("Debian mirror"),
1129             "FAIrelease"            => _("Debian release"),
1131             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1132           ));
1133   }
1136 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1137 ?>