Code

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