Code

Replaced "mofify" in handle_post_events(mofify) with "modify".
[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       if($this->is_account && $this->acl_is_removeable()){
461         $this->is_account= FALSE;
462       }elseif(!$this->is_account && $this->acl_is_createable()){
463         $this->is_account= TRUE;
464       }
465     }
467     /* Do we represent a valid terminal? */
468     if (!$this->is_account && $this->parent == NULL){
469       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
470         _("This 'dn' has no terminal features.")."</b>";
471       return ($display);
472     }
474     /* Add module */
475     if (isset ($_POST['add_module'])){
476       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
477         $this->add_list ($this->gotoModules, $_POST['module']);
478       }
479     }
481     /* Delete module */
482     if (isset ($_POST['delete_module'])){
483       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
484         $this->del_list ($this->gotoModules, $_POST['modules_list']);
485       }
486     }
488     /* FAI class management */
489     if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
490       $found = 0 ; 
492       /* If this new class/profile will attach a second partition table
493        * to our list of classes, abort and show a message.
494        */
495       foreach($this->FAIclass as $name){
496         if(isset($this->FAIclassInfo[$name])){
497           foreach($this->FAIclassInfo[$name] as $atr){
498             if(isset($atr['obj'])){
499               if($atr['obj'] == "FAIpartitionTable"){
500                 $found ++ ; 
501               }
502             }
503           }
504         }
505       }
507       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
508         print_red(_("There is already a profile in your selection that contain partition table configurations."));
509       }else{
510         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
511       }
512     }
514     $sort = false;
516     /* Move one used class class one position up or down */
517     if($this->acl_is_writeable("FAIclass")){
518       foreach($_POST as $name => $val){
520         $sort_type = false;
521         if((preg_match("/sort_up/",$name))&&(!$sort)){
522           $sort_type = "sort_up_";
523         }
524         if((preg_match("/sort_down/",$name))&&(!$sort)){
525           $sort_type = "sort_down_";
526         }
528         if(($sort_type)&&(!$sort)){
529           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
530           $sort = true;
532           $last = -1;
533           $change_down  = -1;
535           /* Create array with numeric index */ 
536           $tmp = array();
537           foreach($this->FAIclass as $class){
538             $tmp [] = $class;
539           }
541           /* Walk trough array */
542           foreach($tmp as $key => $faiName){
543             if($faiName == $value){
544               if($sort_type == "sort_up_"){
545                 if($last != -1){
546                   $change_down= $last;
547                 }
548               }else{
549                 if(isset($tmp[$key+1])){
550                   $change_down = $key;
551                 }
552               }
553             }
554             $last = $key;
555           }
557           $tmp2 = array();
558           $skip = false;    
560           foreach($tmp as $ky => $vl){
562             if($ky == $change_down){
563               $skip = $vl;
564             }else{
565               $tmp2[$vl] = $vl;
566             }
567             if(($skip != false)&&($ky != $change_down)){
568               $tmp2[$skip]  = $skip;
569               $skip =false;
570             }
571           }   
572           $this->FAIclass = $tmp2; 
573         }
575         if(preg_match("/fai_remove/i",$name)){
576           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
577           unset($this->FAIclass[$value]);
578         }
579       }
580     }
582     /* Delete selected class from our list */
583     if($this->acl_is_writeable("FAIclass")){
584       if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
585         if(isset($this->FAIclass[$_POST['FAIclassSel']])){
586           unset($this->FAIclass[$_POST['FAIclassSel']]);
587         }
588       }
589     }
591     /* Show main page */
592     $smarty= get_smarty();
594     /* Assign ACLs to smarty */
595     $tmp = $this->plInfo();
596     foreach($tmp['plProvidedAcls'] as $name => $translation){
597       $smarty->assign($name."ACL",$this->getacl($name));
598     } 
600     $smarty->assign("SelectBoxLdapServer","");
602     /* In this section server shares will be defined
603      * A user can select one of the given shares and a mount point
604      *  and attach this combination to his setup.
605      */
606     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
607     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
609     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
610      * This entry will be, a combination of mountPoint and sharedefinitions
611      */
612     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
613       /* We assign a share to this user, if we don't know where to mount the share */
614       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
615         print_red(_("You must specify a valid mount point."));
616       }else{
617         if(count($this->gotoAvailableShares)){
618           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
619           $s_mount = $_POST['gotoShareMountPoint'];
620           /* Preparing the new assignment */
621           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
622           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
623         }
624       }
625     }
627     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
628      * If there is no defined share selected, we will abort the deletion without any message
629      */
630     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
631       unset($this->gotoShares[$_POST['gotoShare']]);
632     }
634     $smarty->assign("gotoShares",$this->printOutAssignedShares());
635     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
636     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
637     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
639     /* Arrays */
640     $tmp = $this->goLdapServerList;
642     /* Create divSelectBox for ldap server selection
643      */
644     $SelectBoxLdapServer = new divSelectBox("LdapServer");
645     $SelectBoxLdapServer->SetHeight(130);
647     /* Set first entry as selected, if $this->gotoLdapServer is empty
648      *  or given entry is no longer available ... 
649      */
650     $found = false;
651     foreach($tmp as $server){
652       if($this->gotoLdapServer==$server){
653         $found = true;
654       }
655     }
657     /* Add Entries 
658      */
659     foreach($tmp as $key => $server){
660       $use ="";
661       if(($this->gotoLdapServer == $server) || ($found == false)) {
662         $found = true;
663         $use = " checked ";
664       };
666       $display = $server;
668       $SelectBoxLdapServer->AddEntry(
669           array(
670             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
671                   "attach"=>"style='border-left:0px;'"),
672             array("string"=>$display)
673             ));
674     }    
676     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
678     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
679       $smarty->assign("$val", $this->$val);
680     }
682     /* Values */
683     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
684       $smarty->assign($val, $this->$val);
685     }
687     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
688     $smarty->assign("FAIreleases",$this->getFAIreleases());
689     $smarty->assign("FAIrelease",$this->FAIrelease);
690     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
691     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
692     $smarty->assign("FAIclassKeys",$this->FAIclass);
693   
694     $inheritedRelease = array();
695     if(!empty($this->InheritedFAIrelease)){
696       $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
697     } 
698     $smarty->assign("InheritedFAIrelease",$inheritedRelease);
699  
700     $div = new divSelectBox("WSFAIscriptClasses");
701     $div -> SetHeight("110");
702     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
703     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
704     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
705     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
707     $i = 1;
709     if($this->FAIdebianMirror == "inherited"){
710       $tmp = $this->InheritedFAIclass;
711     }else{
712       $tmp = $this->FAIclass;
713     }
715     foreach($tmp as $class){
717       if($this->FAIdebianMirror == "inherited"){
718         $str = "";
719       }else{
720         if($i==1){
721           $str = $str_empty.$str_down.$str_remove;
722         }elseif($i == count($this->FAIclass)){
723           $str = $str_up.$str_empty.$str_remove;
724         }else{
725           $str = $str_up.$str_down.$str_remove;
726         }
727       }
728       $i ++ ; 
730       $div->AddEntry(array(
731             array("string"=>$class),
732             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
733             ));
734     }  
736     $smarty->assign("FAIScriptlist",$div->DrawList()); 
738     /* Radio button group */
739     if (preg_match("/G/", $this->bootmode)) {
740       $smarty->assign("graphicalbootup", "checked");
741     } else {
742       $smarty->assign("graphicalbootup", "");
743     }
744     if (preg_match("/T/", $this->bootmode)) {
745       $smarty->assign("textbootup", "checked");
746     } else {
747       $smarty->assign("textbootup", "");
748     }
749     if (preg_match("/D/", $this->bootmode)) {
750       $smarty->assign("debugbootup", "checked");
751     } else {
752       $smarty->assign("debugbootup", "");
753     }
755     /* Show main page */
756     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
757   }
759   function remove_from_parent()
760   {
761     $this->handle_post_events("remove");
762   }
764   function generateDNSyn($release)
765   {
766     $str = "";
767     $tmp = split("\/",$release);
768     $tmp = array_reverse($tmp);
770     $base = "ou=fai,ou=configs,ou=systems,";   
771     foreach($tmp as $departmentname){
772       
773       $str .= ",ou=".$departmentname;
774     }
775     $str = preg_replace("/^,/","",($str.",".$base));
776     
777     return($str);
778   }
780   function getFAIdebianMirrors()
781   {
782     $ret = array();
783     $ret['inherited']="["._("inherited")."]";
784     $ret['auto']=_("automatic");
785     $secs  = array();
787     /* Walk through all available servers 
788         and check if they support the currently selected classes
789         if not, dont't add them to our list
790      */
791     foreach($this->FAIServRepConfig as $mirror => $rest){
793       $use = false;
795       if(count($this->FAIclass) == 0){
796         $use = true;
797       }else{
798         $tmp = $this->getFAIreleases();
799         foreach($tmp as $release){
800           if(isset($rest['RELEASE'][$release])){
801             $use =true;
802           }
803         } 
804       }
806       /* If current server, doesn't support this class
807           remove it from list
808        */
809       if($use){
810         $ret[$mirror] = $mirror;
811       }
812     }
813     return($ret);
814   }
816   function getFAIreleases() 
817   {
818     $ret = array();
820     if($this->FAIdebianMirror == "inherited") return(array());
822     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
823       $this->FAIdebianMirror = "auto";
824     }
826     $errorClasses = array();  
828     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
829     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
830       $use = true;
831       
832       if(!count($this->FAIclass) == 0){
833         foreach($this->FAIclass as $class){
834           if(!in_array($class, $sections['PACKAGES'])){
835             $use = false;
836             $errorClasses[$class] = $class;
837           }else{
838             if(isset($errorClasses[$class])){
839               unset($errorClasses[$class]); 
840             }
841           }
842         }
843       }
844       if($use){
845         $ret[$release]=$release;
846       }
847     } 
848     }
849     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
851       $eClasses = " ";
852       foreach($errorClasses as $class){
853         $eClasses .= $class." ";
854       }
856       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));
857       $this->FAIdebianMirror = "auto";
858       return($this->getFAIreleases());
859     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
861       $eClasses = " ";
862       foreach($errorClasses as $class){
863         $eClasses .= $class." ";
864       }
866       $eClasses = preg_replace("/  */","",$eClasses);
867      
868       if(!empty($eClasses)) {
869         $this->FAIclass= array();
870         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));
871       }
872     }
873     return($ret);
874   }
876   /* Save data to object */
877   function save_object()
878   {
879     plugin::save_object();
881     /* Save group radio buttons */
882     if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
883       $this->bootmode= $_POST["bootmode"];
884     }
886     /* Save kernel parameters */
887     if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
888       $this->customParameters= $_POST["customParameters"];
889     }
891   }
894   /* Save to LDAP */
895   function save()
896   {
898     /* Depending on the baseobject (Ogroup / WS) we
899      *  use another set of objectClasses
900      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
901      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
902      */
903     if(isset($this->parent->by_object['ogroup'])){
904       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
905     }elseif(isset($this->parent->by_object['workgeneric'])){
906       $this->objectclasses = array("GOhard", "FAIobject");
907     }elseif(isset($this->parent->by_object['servgeneric'])){
908       $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
909     }else{
910       print "Object Type Configuration : unknown";
911       exit();
912     }
914     /* Find proper terminal path for tftp configuration
915        FIXME: This is suboptimal when the default has changed to
916        another location! */
917     if (($this->gotoTerminalPath == "default")){
918       $ldap= $this->config->get_ldap_link();
920       /* Strip relevant part from dn, keep trailing ',' */
921       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
922       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
924       /* Walk from top to base and try to load default values for
925          'gotoTerminalPath'. Abort when an entry is found. */
926       while (TRUE){
927         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
929         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
930             $this->config->current['BASE'], array('gotoTerminalPath'));
931         $attrs= $ldap->fetch();
932         if (isset($attrs['gotoTerminalPath'])){
933           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
934           break;
935         }
937         /* Nothing left? */
938         if ($tmp == ""){
939           break;
940         }
941       }
942     }
944     /* Add semi automatic values */
945     // FIXME: LDAP Server may not be set here...
946     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
948     switch ($this->bootmode){
949       case "D":
950         $this->gotoKernelParameters.= " debug";
951       break;
952       case "G":
953         $this->gotoKernelParameters.= " splash=silent";
954       break;
955     }
956     if ($this->customParameters != ""){
957       $this->gotoKernelParameters.= " o ".$this->customParameters;
958     }
960     plugin::save();
962     unset( $this->attrs['FAIrelease'] );
963     
964     $str = "";
966     if($this->FAIdebianMirror == "inherited"){
967   
968       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
970     }else{
972       foreach($this->FAIclass as $class){
973         $str .= $class." ";
974       }
975       $str .= ":" . $this->FAIrelease;
976       $this->attrs['FAIclass']= "";
977       $this->attrs['FAIclass']= trim($str);
979       if(empty($this->attrs['FAIclass'])){
980         $this->attrs['FAIclass'] = array();
981       }
982     }
984     /* Add missing arrays */
985     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
986       if (isset ($this->$val) && count ($this->$val) != 0){
987     
988         $this->attrs["$val"]= array_unique($this->$val);
989       }
990       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
991     }
993     /* Strip out 'default' values */
994     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
995       $this->attrs['gotoLdapServer']= array();
996     }
998     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
999       $this->attrs['gotoBootKernel']= array();
1000     }
1002     /* if mirror == none stop saving this attribute */
1003     if($this->FAIdebianMirror == "none"){
1004       $this->FAIdebianMirror = "";
1005     }
1006    
1007     /* Get FAIstate from object, the generic tab could have changed it during execute */
1008     $ldap= $this->config->get_ldap_link();
1009     $ldap->cd($this->dn);
1010     $ldap->cat($this->dn,array("FAIstate"));
1011     $checkFAIstate = $ldap->fetch();
1013     /* Remove FAI objects if no FAI class is selected */ 
1014     if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1015       $this->attrs['FAIclass']        = array();
1016       $this->attrs['FAIdebianMirror'] = array();
1017     }
1019     /* prepare share settings */
1020     $tmp = array();
1021     foreach($this->gotoShares as $name => $settings){
1022       $tmp2= split("\|",$name);
1023       $name = $tmp2[0];
1024       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1025     }
1026     $this->attrs['gotoShare']=$tmp;
1028     $this->cleanup();
1029     $ldap->modify ($this->attrs); 
1031     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1032     $this->handle_post_events("modify");
1033   }
1035   /* Add value to array, check if unique */
1036   function add_list (&$array, $value)
1037   {
1038     if ($value != ""){
1039       $array[]= $value;
1040       sort($array);
1041       array_unique ($array);
1042     }
1043   }
1046   /* Delete value to array, check if unique */
1047   function del_list (&$array, $list)
1048   {
1049     $tmp= array();
1050     foreach ($array as $mod){
1051       if (!in_array($mod, $list)){
1052         $tmp[]= $mod;
1053       }
1054     }
1055     $array= $tmp;
1056   }
1058   /* Generate ListBox frindly output for the defined shares
1059    * Possibly Add or remove an attribute here,
1060    */
1061   function printOutAssignedShares()
1062   {
1063     $a_return = array();
1064     if(is_array($this->gotoShares)){
1065       foreach($this->gotoShares as $share){
1066         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1067       }
1068     }
1069     return($a_return);
1070   }
1073   function GetHookElements()
1074   {
1075     $ret = array();
1076     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1077     if(!empty($cmd)){
1078       $res = shell_exec($cmd);
1079       $res2 = trim($res);
1080       if((!$res)){
1081         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1082       }elseif(empty($res2)){
1083         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1084       }else{
1085         $tmp = split("\n",$res);
1086         foreach($tmp as $line){
1087           if(empty($line)) continue;
1088           $ret[]= $line;
1089         }
1090       }
1091     }
1092     return($ret);
1093   }
1096   /* Return plugin informations for acl handling */ 
1097   function plInfo()
1098   {
1099     return (array( 
1100           "plShortName"   => _("Startup"),
1101           "plDescription" => _("System startup"),
1102           "plSelfModify"  => FALSE,
1103           "plDepends"     => array(),
1104           "plPriority"    => 0,
1105           "plSection"     => array("administration"),           
1106           "plCategory"    => array("workstation","server","ogroups"),
1108           "plProvidedAcls"=> array(
1109             "gotoLdapServer"        => _("Ldap server"),
1110             "gotoBootKernel"        => _("Boot kernel"),
1111             "gotoKernelParameters"  => _("Kernel parameter"),
1113             "gotoModules"           => _("Kernel modules"),
1114             "gotoShare"             => _("Shares"),
1116             "FAIclass"              => _("FAI classes"),
1117             "FAIdebianMirror"       => _("Debian mirror"),
1118             "FAIrelease"            => _("Debian release"),
1120             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1121           ));
1122   }
1125 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1126 ?>