Code

gotoLpdEnable wasn't saved as "Yes/No" it was saved as 1/0
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
3 class workstartup extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage terminal startup options";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Generic terminal attributes */
11   var $bootmode             = "G";
12   var $goLdapServerList     = array();
13   var $gotoBootKernel       = "default-inherited";
14   var $gotoKernelParameters = "";
15   var $gotoLdapServer       = "default-inherited";
16   var $gotoModules          = array();
17   var $gotoAutoFs           = array();
18   var $gotoFilesystem       = array();
19   var $gotoTerminalPath     = "";
20   var $FAIstatus            = "";
21   var $gotoBootKernels      = array();
23   /* attribute list for save action */
24   var $attributes     = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25   var $objectclasses  = array("GOhard", "FAIobject");
27   /* These vars are required to copy object groups !. */
28   var $CopyPasteVars  = array("gotoModules","gotoShares","customParameters","FAIclass","FAIrelease","FAIdebianMirror"); 
30   /* Share */
31   var $gotoShares         = array();// Currently Share Option
32   var $gotoShare          = "";     // currently selected Share Option
33   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34   var $gotoAvailableShares= array();// Available Shares for this account
36   /* Helper */
37   var $customParameters   = "";
38   var $orig_dn            = "";
39   var $ignore_account     = TRUE;
40  
41   /* FAI class selection */ 
42   var $FAIclass           = array();
43   var $FAIclasses         = array();
44   var $FAIclassInfo       = array();
45   var $FAIrelease         = "";
46   var $FAIdebianMirror    = "auto";
48   var $unresolved_classes = array();
49   
50   /* FAI class selection */
51   var $InheritedFAIclass           = array();
52   var $InheritedFAIrelease         = "";
53   var $InheritedFAIdebianMirror    = "auto";
55   /* Contains all possible server/release/class settings */
56   var $FAIServRepConfig   = array();
58   function workstartup ($config, $dn= NULL, $parent= NULL)
59   {
60     plugin::plugin ($config, $dn, $parent);
62     /* Creating a list of valid Mirrors 
63      * none will not be saved to ldap.
64      */
65     $ldap   = $this->config->get_ldap_link();
66     $ldap->cd($this->config->current['BASE']);
68     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
69       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
70     }
71    
72     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
73     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
75     $ui = get_userinfo();
76     $res = get_list(          "(|(objectClass=FAIpackageList)".
77         "(objectClass=FAItemplate)".
78         "(objectClass=FAIvariable)".
79         "(objectClass=FAIscript)".
80         "(objectClass=FAIhook)".
81         "(objectClass=FAIprofile)".
82         "(objectClass=FAIpartitionTable))",
83         $ui->subtreeACL,$this->config->current['BASE'],
84         array("cn","objectClass","FAIdebianSection"));
85     
86     foreach($res as $attr){
87       $cn = $attr['cn'][0];
88     
89       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
90  
91       if(in_array('FAIpackageList',$attr['objectClass'])){
92         $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
93         $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
94         $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
95         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
96       }
97       if(in_array('FAItemplate',$attr['objectClass'])){
98         $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
99         $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
100         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
101       }
102       if(in_array('FAIvariable',$attr['objectClass'])){
103         $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
104         $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
105         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106       }
107       if(in_array('FAIscript',$attr['objectClass'])){
108         $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
109         $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
110         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111       }
112       if(in_array('FAIhook',$attr['objectClass'])){
113         $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
114         $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
115         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116       }
117       if(in_array('FAIpartitionTable',$attr['objectClass'])){
118         $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
119         $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
120         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121       }
122       if(in_array('FAIprofile',$attr['objectClass'])){
123         $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
124         $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
125         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126       }
127     }
128     if(is_array($this->FAIclasses)){
129       natcasesort($this->FAIclasses);
130     }
132     if(isset($tmp2)){
133       $this->FAIclassInfo = $tmp2;
134     } else {
135       $this->FAIclassInfo = array();
136     }
138     /* Build up an array like this one :
139         [$url]['SERVER'] = 'srv1-002';
140         [$url]['RELEASE']['siga/rc9.0.2']
141                                            ['SECTIONS'][0] "main";
142                                            ['SECTIONS'][1] "non-free";
143         [$url]['RELEASE']['siga/rc9.0.2']
144                                            ['PACKAGES'][0] "pkg1";
145                                            ['PACKAGES'][1] "postfix";
146      */
148     $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
149     $test = array();
150     while($attr = $ldap->fetch()){
151       if(isset($attr['FAIrepository'])){
153         unset($attr['FAIrepository']['count']);
155         foreach($attr['FAIrepository'] as $rep){
156           $tmp = split("\|",$rep);
158           if(count($tmp)==4){
159             $sections = split(",",$tmp[3]);
160             $release  = $tmp[2];
161             $server   = $tmp[1];
162             $url      = $tmp[0];
163            
164             $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
165     
166             /* Result will be cached
167              */
168             $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
169             $test[$url]['SERVER'] = $server;
171             /* auto gets all releases/classes 
172              */
173             $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
174             $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
175           }
176         }
177       }
178     }
179     
180     /* Add possible elements from hook */
181     $lines= $this->GetHookElements();
182     foreach ($lines as $hline){
183       $entries= split(";", $hline);
184       if (isset($entries[1]) && !isset($test[$entries[1]])){
185         $test[$entries[1]]['RELEASE']= array();
187         /* Split releases */
188         if (isset($entries[2])){
189           $releases= split(",", $entries[2]);
191           foreach ($releases as $release){
192             $rname= preg_replace('/:.*$/', '', $release);
193             $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
194             $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
195             $test[$entries[1]]['RELEASE'][$rname]= array();
196             $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
197             foreach ($classes as $class){
198               if ($class != ""){
199                 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
200               }
201             }
202           }
203         }
204       }
205     }
206     
207     $this->FAIServRepConfig= $test;
209     /* Get arrays */
210     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
211       if (isset($this->attrs["$val"]["count"])){
212         for ($i= 0; $i<$this->attrs["count"]; $i++){
213           if (isset($this->attrs["$val"][$i])){
214             array_push($this->$val, $this->attrs["$val"][$i]);
215           }
216         }
217       }
218       sort ($this->$val);
219       $this->$val= array_unique($this->$val);
220     }
222     /* Parse Kernel Parameters to decide what boot mode is enabled */
223     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
224       $this->bootmode= "G";
225     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
226       $this->bootmode= "D";
227     } elseif ($this->gotoKernelParameters == "") {
228       $this->bootmode= "G";
229     } else {
230       $this->bootmode= "T";
231     }
232     if (preg_match("/ o /", $this->gotoKernelParameters)){
233       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
234     } else {
235       $this->customParameters= "";
236     }
238     /* Prepare Shares */
239     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
240       unset($this->attrs['gotoShare']['count']);
241       foreach($this->attrs['gotoShare'] as $share){
242         $tmp = $tmp2 = array();
243         $tmp = split("\|",$share);
244         $tmp2['server']      =$tmp[0];
245         $tmp2['name']        =$tmp[1];
246         $tmp2['mountPoint']  =$tmp[2];
247         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
248       }
249     }
251     $this->gotoShareSelections= $config->getShareList(true);
252     $this->gotoAvailableShares= $config->getShareList(false);
253     $tmp2 = array();
254   
255     if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
256       $tmp = array();
257       $tmp = split(" ",$this->FAIclass);
258       $tmp2 =array();  
259     
260       foreach($tmp as $class){
261         if( ":" == $class[0] ) {
262           $this->FAIrelease = substr( $class, 1 );
263         }
264         else
265           $tmp2[$class] = $class;
266       }
267       $this->FAIclass = $tmp2;
268     }
270     if(!is_array($this->FAIclass)){
271       $this->FAIclass =array();
272     }
274     $this->orig_dn= $this->dn;
276     /* Handle inheritance value "default" */
277     $this->gotoBootKernels= array();
280     /* Load hardware list */
281     $ldap= $this->config->get_ldap_link();
282     $ldap->cd($this->config->current['BASE']);
283     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
284     if ($ldap->count() == 1){
285       $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
286       $attrs= $ldap->fetch();
288       foreach ($map as $name){
289         if (!isset($attrs[$name][0])){
290           continue;
291         }
293         switch ($name){
294           case 'gotoLdapServer':
295             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
296             break;
298           case 'gotoBootKernel':
299             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
300             break;
302           case 'FAIclass':
303             $str = split(":",$attrs[$name][0]);
304             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
305             $this->InheritedFAIrelease  = trim($str[1]);
306             break;
308           case 'FAIdebianMirror':
309             $this->InheritedFAIdebianMirror = $attrs[$name][0];
310             break;
311         }
312       }
313     }
315     /* Get list of boot kernels */
316     if (isset($this->config->data['TABS'])){
317       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
319       if (!check_command($command)){
320         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
321             get_class($this));
322       } else {
323         
324         $first = false; 
325         $fh= popen($command, "r");
326         while (!feof($fh)) {
327           $buffer= trim(fgets($fh, 256));
328   
329           if(!empty($buffer)){
331             $name=$value = $buffer;
332             if(preg_match("/:/",$buffer)){
333               $name = preg_replace("/:.*$/","",$buffer);
334               $value= preg_replace("/^.*:/","",$buffer);
335               $this->gotoBootKernels[$name]= $name.":".$value;
336             }else{
337               $this->gotoBootKernels[$name]= $value;
338             }
339             if($this->gotoBootKernel =="" ){
340               $this->gotoBootKernel = $name;
341             }
343           }
344         }
345         pclose($fh);
346       }
347     }
349     /* Turn to default, if we've nothing to inherit */
350     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
351       $this->gotoBootKernel= "default";
352     }
354     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
355       $this->FAIdebianMirror = "inherited";
356     }
357   }
359   
360   /* This class is called by the contrucktor ONLY.
361    *   It return the available classes for each 
362    *    Server / Release combination ... 
363    *   (Release specifies which classes are available) 
364    */
365   function getAvailableClassesForThisRelease($release)
366   {
367     /* There could be more than one server providing this release,
368         so use cached result if available
369      */ 
370     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
371       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
372     }
374     /* Walk through cache and get out what we need.
375      *   
376      *   Function od : "$this->generateDNSyn($release)"
377      *    It returns an array like this one :
378      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
379      *            "ou=scripts.. " 
380      *             ...);
381      *   This helps us to select the correct classes for each release. 
382      *   It prevents errors like:  'siga' is selected as release, but all classes
383      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
384      */
385     $tmp2 = $this->generateDNSyn($release)     ; 
386     $test2 = array();
387     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
388       foreach($tmp2 as $dns){
389         if(preg_match("/".$dns."/",$attr['dn'])){
390           $test2[$attr['cn'][0]] = $attr['cn'][0];
391         }
392       }
393     }
394     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
395     return($test2);
396   }
399   /*  Create array to display available classes/profiles in a selectbox 
400    *   This function only displays the available classes.
401    *   If a class is available is defined by these facts : 
402    *     1. Is this class available for the selected release ?
403    *       - if it is available, check if the release is available for the selected server 
404    *         (done by $this->getFAIreleases())
405    *     2. Is this class currently not assigned to $this->FAIclass
406    */
407   function selectFriendlyClasses(){
408     $tmp=array();
410     if($this->FAIdebianMirror == "inherited") return($tmp);
412     /* check if the current release exists,
413         else select the first one ..
414      */
415     $tmp2 = $this->getFAIreleases();
416     if(!in_array($this->FAIrelease, $tmp2)){  
417       $this->FAIrelease = key($tmp2);
418     }
419  
420     /* Get all Packages for this server/release combination
421      */
422     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
423       $pkgs = array();
424       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
425     }else{
426       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
427     }
429     /* Check each and every single class name 
430      */
431     foreach($pkgs as $pkg){
432   
433       /* Class already assigned to the classes list ?
434        * If not ... go on
435        */
436       if(!in_array($pkg,$this->FAIclass)){
437         
438         /* Create the displayed list entry value
439             HKLMOP [-Pl P V T-] or something like that 
440          */
441         $str = "";
442         foreach($this->FAIclassInfo[$pkg] as $entry){
443           if(isset($entry['kzl'])){
444             $str .= $entry['kzl']." ";
445           }
446         }
447         
448         /* Append class if everyting was fine
449          */        
450         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
451       }
452     }
453     /* Just sort and return new classes list ...
454        ( possibly we should cache the result ... )
455      */
456     natcasesort ($tmp);
457     return($tmp);
458   }
460   function check()
461   {
462     $messages = array();
463     
464     /* Call common method to give check the hook */
465     $messages= plugin::check();
467     /* If there are packages selected, but no mirror show error */   
468     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
469       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
470     }
472     return($messages);
473   }
475   function execute()
476   {
478         /* Call parent execute */
479         plugin::execute();
481     /* Do we need to flip is_account state? */
482     if (isset($_POST['modify_state'])){
483       $this->is_account= !$this->is_account;
484     }
486     /* Do we represent a valid terminal? */
487     if (!$this->is_account && $this->parent == NULL){
488       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
489         _("This 'dn' has no terminal features.")."</b>";
490       return ($display);
491     }
493     /* Add module */
494     if (isset ($_POST['add_module'])){
495       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
496         $this->add_list ($this->gotoModules, $_POST['module']);
497       }
498     }
500     /* Delete module */
501     if (isset ($_POST['delete_module'])){
502       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
503         $this->del_list ($this->gotoModules, $_POST['modules_list']);
504       }
505     }
507     /* FAI class management */
508     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
509       $found = 0 ; 
511       /* If this new class/profile will attach a second partition table
512        * to our list of classes, abort and show a message.
513        */
514       foreach($this->FAIclass as $name){
515         if(isset($this->FAIclassInfo[$name])){
516           foreach($this->FAIclassInfo[$name] as $atr){
517             if(isset($atr['obj'])){
518               if($atr['obj'] == "FAIpartitionTable"){
519                 $found ++ ; 
520               }
521             }
522           }
523         }
524       }
526       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
527         print_red(_("There is already a profile in your selection that contain partition table configurations."));
528       }else{
529         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
530       }
531     }
533     $sort = false;
534     foreach($_POST as $name => $val){
535       
536       $sort_type = false;
537       if((preg_match("/sort_up/",$name))&&(!$sort)){
538         $sort_type = "sort_up_";
539       }
540       if((preg_match("/sort_down/",$name))&&(!$sort)){
541         $sort_type = "sort_down_";
542       }
543     
544       if(($sort_type)&&(!$sort)){
545         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
546         $sort = true;
547         
548         $last = -1;
549         $change_down  = -1;
550  
551         /* Create array with numeric index */ 
552         $tmp = array();
553         foreach($this->FAIclass as $class){
554           $tmp [] = $class;
555         }
557         /* Walk trough array */
558         foreach($tmp as $key => $faiName){
559           if($faiName == $value){
560             if($sort_type == "sort_up_"){
561               if($last != -1){
562                  $change_down= $last;
563               }
564             }else{
565               if(isset($tmp[$key+1])){
566                 $change_down = $key;
567               }
568             }
569           }
570           $last = $key;
571         }
572  
573         $tmp2 = array();
574         $skip = false;    
575   
576         foreach($tmp as $ky => $vl){
578           if($ky == $change_down){
579             $skip = $vl;
580           }else{
581             $tmp2[$vl] = $vl;
582           }
583           if(($skip != false)&&($ky != $change_down)){
584             $tmp2[$skip]  = $skip;
585             $skip =false;
586           }
587         }   
588         $this->FAIclass = $tmp2; 
589       }
590   
591       if(preg_match("/fai_remove/i",$name)){
592         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
593         unset($this->FAIclass[$value]);
594       }
595     }
597     /* Show main page */
598     $smarty= get_smarty();
599     $smarty->assign("SelectBoxLdapServer","");
601     /* In this section server shares will be defined
602      * A user can select one of the given shares and a mount point
603      *  and attach this combination to his setup.
604      */
605     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
606     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
608     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
609      * This entry will be, a combination of mountPoint and sharedefinitions
610      */
611     if(isset($_POST['gotoShareAdd'])){
612       /* We assign a share to this user, if we don't know where to mount the share */
613       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
614         print_red(_("You must specify a valid mount point."));
615       }else{
616         if(count($this->gotoAvailableShares)){
617           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
618           $s_mount = $_POST['gotoShareMountPoint'];
619           /* Preparing the new assignment */
620           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
621           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
622         }
623       }
624     }
626     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
627      * If there is no defined share selected, we will abort the deletion without any message
628      */
629     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
630       unset($this->gotoShares[$_POST['gotoShare']]);
631     }
633     $smarty->assign("gotoShares",$this->printOutAssignedShares());
634     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
635     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
636     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
638     /* Arrays */
639     $tmp = $this->goLdapServerList;
641     /* Create divSelectBox for ldap server selection
642      */
643     $SelectBoxLdapServer = new divSelectBox("LdapServer");
644     $SelectBoxLdapServer->SetHeight(130);
646     /* Set first entry as selected, if $this->gotoLdapServer is empty
647      *  or given entry is no longer available ... 
648      */
649     $found = false;
650     foreach($tmp as $server){
651       if($this->gotoLdapServer==$server){
652         $found = true;
653       }
654     }
656     /* Add Entries 
657      */
658     foreach($tmp as $key => $server){
659       $use ="";
660       if(($this->gotoLdapServer == $server) || ($found == false)) {
661         $found = true;
662         $use = " checked ";
663       };
665       $display = $server;
667       $SelectBoxLdapServer->AddEntry(
668           array(
669             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
670                   "attach"=>"style='border-left:0px;'"),
671             array("string"=>$display)
672             ));
673     }    
675     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
677     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
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       $smarty->assign($val."ACL", chkacl($this->acl, $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     $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
696     
697     $div = new divSelectBox("WSFAIscriptClasses");
698     $div -> SetHeight("110");
699     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
700     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
701     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
702     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
704     $i = 1;
706     if($this->FAIdebianMirror == "inherited"){
707       $tmp = $this->InheritedFAIclass;
708     }else{
709       $tmp = $this->FAIclass;
710     }
712     foreach($tmp as $class){
714       $marker = "";
715       if(in_array_ics($class,$this->unresolved_classes)){
716         $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
717       }
719       if($this->FAIdebianMirror == "inherited"){
720         $str = "";
721       }else{
722         if($i==1){
723           $str = $str_empty.$str_down.$str_remove;
724         }elseif($i == count($this->FAIclass)){
725           $str = $str_up.$str_empty.$str_remove;
726         }else{
727           $str = $str_up.$str_down.$str_remove;
728         }
729       }
730       $i ++ ; 
732       $div->AddEntry(array(
733             array("string"=>$class.$marker),
734             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
735             ));
736     }  
738     $smarty->assign("FAIScriptlist",$div->DrawList()); 
740     /* Radio button group */
741     if (preg_match("/G/", $this->bootmode)) {
742       $smarty->assign("graphicalbootup", "checked");
743     } else {
744       $smarty->assign("graphicalbootup", "");
745     }
746     if (preg_match("/T/", $this->bootmode)) {
747       $smarty->assign("textbootup", "checked");
748     } else {
749       $smarty->assign("textbootup", "");
750     }
751     if (preg_match("/D/", $this->bootmode)) {
752       $smarty->assign("debugbootup", "checked");
753     } else {
754       $smarty->assign("debugbootup", "");
755     }
757     /* ACL's */
758     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
759       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
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,";   
778  
779     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
781     foreach($tmp as $departmentname){
782       
783       $str .= ",ou=".$departmentname;
784     }
785     $ret = array();
786     foreach($arr as $ar){
787       $ret[] = ",ou=".$ar.$str.$base;
788     }
789     return($ret);
790   }
792   function getFAIdebianMirrors()
793   {
794     $ret = array();
795     $ret['inherited']="["._("inherited")."]";
796     $ret['auto']=_("automatic");
797     $secs  = array();
799     /* Walk through all available servers 
800         and check if they support the currently selected classes
801         if not, dont't add them to our list
802      */
803     foreach($this->FAIServRepConfig as $mirror => $rest){
805       $use = false;
807       if(count($this->FAIclass) == 0){
808         $use = true;
809       }else{
810         $tmp = $this->getFAIreleases();
811         foreach($tmp as $release){
812           if(isset($rest['RELEASE'][$release])){
813             $use =true;
814           }
815         } 
816       }
818       /* If current server, doesn't support this class
819           remove it from list
820        */
821       if($use){
822         $ret[$mirror] = $mirror;
823       }
824     }
825     return($ret);
826   }
828   function getFAIreleases() 
829   {
830     $ret = array();
832     if($this->FAIdebianMirror == "inherited") return(array());
834     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
835       $this->FAIdebianMirror = "auto";
836     }
838     $errorClasses = array();  
839     if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
840       foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
841         $use = true;
843         if(!count($this->FAIclass) == 0){
844           foreach($this->FAIclass as $class){
845             if(!in_array($class, $sections['PACKAGES'])){
846               $use = false;
847               $errorClasses[$class] = $class;
848             }else{
849               if(isset($errorClasses[$class])){
850                 unset($errorClasses[$class]); 
851               }
852             }
853           }
854         }
855         if($use){
856           $ret[$release]=$release;
857         }
858       }
859     } 
860     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
862       $eClasses = " ";
863       foreach($errorClasses as $class){
864         $eClasses .= $class." ";
865       }
867       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));
868       $this->FAIdebianMirror = "auto";
869       return($this->getFAIreleases());
870     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
872       $eClasses = " ";
873       foreach($errorClasses as $class){
874         $eClasses .= $class." ";
875       }
876       
877       $this->unresolved_classes = $errorClasses;
878       $this->FAIdebianMirror = "auto";
879       //$this->FAIclass= array();
880       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));
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 (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
892       $this->bootmode= $_POST["bootmode"];
893     }
895     /* Save kernel parameters */
896     if (chkacl ($this->acl, "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");
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(), _("Saving workstation startup settings failed"));
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   }
1106 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1107 ?>