Code

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