Code

Udpated mime acls
[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";
13   var $gotoKernelParameters = "";
14   var $gotoLdapServer       = "default";
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").']');
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").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
285             break;
287           case 'gotoBootKernel':
288             $this->gotoBootKernels['%default%']=  _("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         
313         $fh= popen($command, "r");
314         while (!feof($fh)) {
315           $buffer= trim(fgets($fh, 256));
316           if ($buffer != ""){
317             $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
318           }
319         }
320         pclose($fh);
321       }
322     }
324     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
325       $this->FAIdebianMirror = "inherited";
326     }
327   }
329   
330   /* This class is called by the contrucktor ONLY.
331    *   It return the available classes for each 
332    *    Server / Release combination ... 
333    *   (Release specifies which classes are available) 
334    */
335   function getAvailableClassesForThisRelease($release)
336   {
337     /* There could be more than one server providing this release,
338         so use cached result if available
339      */ 
340     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
341       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
342     }
344     $test2  = array();
345     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
346     $ldap   = $this->config->get_ldap_link();
347     $ldap->cd($this->config->current['BASE']);
348   
349     /* Get classes fpr given release */
350     $p_classes = get_all_objects_for_given_base($bb,
351         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
352           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
353           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
355     /* Create list of classes */
356     foreach($p_classes as $class){
357       $ldap->cat($class['dn'],array("cn"));
358       $attr = $ldap->fetch();
359       $test2[$attr['cn'][0]] = $attr['cn'][0];
360     }
361     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
362     return($test2);
363   }
366   /*  Create array to display available classes/profiles in a selectbox 
367    *   This function only displays the available classes.
368    *   If a class is available is defined by these facts : 
369    *     1. Is this class available for the selected release ?
370    *       - if it is available, check if the release is available for the selected server 
371    *         (done by $this->getFAIreleases())
372    *     2. Is this class currently not assigned to $this->FAIclass
373    */
374   function selectFriendlyClasses(){
375     $tmp=array();
377     if($this->FAIdebianMirror == "inherited") return($tmp);
379     /* check if the current release exists,
380         else select the first one ..
381      */
382     $tmp2 = $this->getFAIreleases();
383     if(!in_array($this->FAIrelease, $tmp2)){  
384       $this->FAIrelease = key($tmp2);
385     }
387     /* Get all Packages for this server/release combination
388      */
389     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
390       $pkgs = array();
391       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
392     }else{
393       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
394     }
396     /* Check each and every single class name 
397      */
398     foreach($pkgs as $pkg){
399   
400       /* Class already assigned to the classes list ?
401        * If not ... go on
402        */
403       if(!in_array($pkg,$this->FAIclass)){
404         
405         /* Create the displayed list entry value
406             HKLMOP [-Pl P V T-] or something like that 
407          */
408         $str = "";
409         foreach($this->FAIclassInfo[$pkg] as $entry){
410           if(isset($entry['kzl'])){
411             $str .= $entry['kzl']." ";
412           }
413         }
414         
415         /* Append class if everyting was fine
416          */        
417         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
418       }
419     }
420     /* Just sort and return new classes list ...
421        ( possibly we should cache the result ... )
422      */
423     natcasesort ($tmp);
424     return($tmp);
425   }
427   function check()
428   {
429     $messages = array();
430     
431     /* Call common method to give check the hook */
432     $messages= plugin::check();
434     /* If there are packages selected, but no mirror show error */   
435     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
436       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
437     }
439     return($messages);
440   }
442   function execute()
443   {
445         /* Call parent execute */
446         plugin::execute();
448     /* Do we need to flip is_account state? */
449     if (isset($_POST['modify_state'])){
450       $this->is_account= !$this->is_account;
451     }
453     /* Do we represent a valid terminal? */
454     if (!$this->is_account && $this->parent == NULL){
455       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
456         _("This 'dn' has no terminal features.")."</b>";
457       return ($display);
458     }
460     /* Add module */
461     if (isset ($_POST['add_module'])){
462       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
463         $this->add_list ($this->gotoModules, $_POST['module']);
464       }
465     }
467     /* Delete module */
468     if (isset ($_POST['delete_module'])){
469       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
470         $this->del_list ($this->gotoModules, $_POST['modules_list']);
471       }
472     }
474     /* FAI class management */
475     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
476       $found = 0 ; 
478       /* If this new class/profile will attach a second partition table
479        * to our list of classes, abort and show a message.
480        */
481       foreach($this->FAIclass as $name){
482         if(isset($this->FAIclassInfo[$name])){
483           foreach($this->FAIclassInfo[$name] as $atr){
484             if(isset($atr['obj'])){
485               if($atr['obj'] == "FAIpartitionTable"){
486                 $found ++ ; 
487               }
488             }
489           }
490         }
491       }
493       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
494         print_red(_("There is already a profile in your selection that contain partition table configurations."));
495       }else{
496         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
497       }
498     }
500     $sort = false;
501     foreach($_POST as $name => $val){
502       
503       $sort_type = false;
504       if((preg_match("/sort_up/",$name))&&(!$sort)){
505         $sort_type = "sort_up_";
506       }
507       if((preg_match("/sort_down/",$name))&&(!$sort)){
508         $sort_type = "sort_down_";
509       }
510     
511       if(($sort_type)&&(!$sort)){
512         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
513         $sort = true;
514         
515         $last = -1;
516         $change_down  = -1;
517  
518         /* Create array with numeric index */ 
519         $tmp = array();
520         foreach($this->FAIclass as $class){
521           $tmp [] = $class;
522         }
524         /* Walk trough array */
525         foreach($tmp as $key => $faiName){
526           if($faiName == $value){
527             if($sort_type == "sort_up_"){
528               if($last != -1){
529                  $change_down= $last;
530               }
531             }else{
532               if(isset($tmp[$key+1])){
533                 $change_down = $key;
534               }
535             }
536           }
537           $last = $key;
538         }
539  
540         $tmp2 = array();
541         $skip = false;    
542   
543         foreach($tmp as $ky => $vl){
545           if($ky == $change_down){
546             $skip = $vl;
547           }else{
548             $tmp2[$vl] = $vl;
549           }
550           if(($skip != false)&&($ky != $change_down)){
551             $tmp2[$skip]  = $skip;
552             $skip =false;
553           }
554         }   
555         $this->FAIclass = $tmp2; 
556       }
557   
558       if(preg_match("/fai_remove/i",$name)){
559         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
560         unset($this->FAIclass[$value]);
561       }
562     }
564     /* Delete selected class from our list */
565     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
566       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
567         unset($this->FAIclass[$_POST['FAIclassSel']]);
568       }
569     }
571     /* Show main page */
572     $smarty= get_smarty();
573     $smarty->assign("SelectBoxLdapServer","");
575     /* In this section server shares will be defined
576      * A user can select one of the given shares and a mount point
577      *  and attach this combination to his setup.
578      */
579     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
580     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
582     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
583      * This entry will be, a combination of mountPoint and sharedefinitions
584      */
585     if(isset($_POST['gotoShareAdd'])){
586       /* We assign a share to this user, if we don't know where to mount the share */
587       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
588         print_red(_("You must specify a valid mount point."));
589       }else{
590         if(count($this->gotoAvailableShares)){
591           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
592           $s_mount = $_POST['gotoShareMountPoint'];
593           /* Preparing the new assignment */
594           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
595           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
596         }
597       }
598     }
600     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
601      * If there is no defined share selected, we will abort the deletion without any message
602      */
603     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
604       unset($this->gotoShares[$_POST['gotoShare']]);
605     }
607     $smarty->assign("gotoShares",$this->printOutAssignedShares());
608     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
609     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
610     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
612     /* Arrays */
613     $tmp = $this->goLdapServerList;
615     /* Create divSelectBox for ldap server selection
616      */
617     $SelectBoxLdapServer = new divSelectBox("LdapServer");
618     $SelectBoxLdapServer->SetHeight(130);
620     /* Set first entry as selected, if $this->gotoLdapServer is empty
621      *  or given entry is no longer available ... 
622      */
623     $found = false;
624     foreach($tmp as $server){
625       if($this->gotoLdapServer==$server){
626         $found = true;
627       }
628     }
630     /* Add Entries 
631      */
632     foreach($tmp as $key => $server){
633       $use ="";
634       if(($this->gotoLdapServer == $server) || ($found == false)) {
635         $found = true;
636         $use = " checked ";
637       };
639       $display = $server;
641       $SelectBoxLdapServer->AddEntry(
642           array(
643             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
644                   "attach"=>"style='border-left:0px;'"),
645             array("string"=>$display)
646             ));
647     }    
649     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
651     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
652     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
653       $smarty->assign("$val", $this->$val);
654     }
656     /* Values */
657     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
658       $smarty->assign($val, $this->$val);
659       $smarty->assign($val."ACL", chkacl($this->acl, $val));
660     }
662     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
663     $smarty->assign("FAIreleases",$this->getFAIreleases());
664     $smarty->assign("FAIrelease",$this->FAIrelease);
665     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
666     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
667     $smarty->assign("FAIclassKeys",$this->FAIclass);
668     $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
669     
670     $div = new divSelectBox("WSFAIscriptClasses");
671     $div -> SetHeight("110");
672     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
673     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
674     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
675     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
677     $i = 1;
679     if($this->FAIdebianMirror == "inherited"){
680       $tmp = $this->InheritedFAIclass;
681     }else{
682       $tmp = $this->FAIclass;
683     }
685     foreach($tmp as $class){
687       if($this->FAIdebianMirror == "inherited"){
688         $str = "";
689       }else{
690         if($i==1){
691           $str = $str_empty.$str_down.$str_remove;
692         }elseif($i == count($this->FAIclass)){
693           $str = $str_up.$str_empty.$str_remove;
694         }else{
695           $str = $str_up.$str_down.$str_remove;
696         }
697       }
698       $i ++ ; 
700       $div->AddEntry(array(
701             array("string"=>$class),
702             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
703             ));
704     }  
706     $smarty->assign("FAIScriptlist",$div->DrawList()); 
708     /* Radio button group */
709     if (preg_match("/G/", $this->bootmode)) {
710       $smarty->assign("graphicalbootup", "checked");
711     } else {
712       $smarty->assign("graphicalbootup", "");
713     }
714     if (preg_match("/T/", $this->bootmode)) {
715       $smarty->assign("textbootup", "checked");
716     } else {
717       $smarty->assign("textbootup", "");
718     }
719     if (preg_match("/D/", $this->bootmode)) {
720       $smarty->assign("debugbootup", "checked");
721     } else {
722       $smarty->assign("debugbootup", "");
723     }
725     /* ACL's */
726     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
727       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
728     }
730     /* Show main page */
731     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
732   }
734   function remove_from_parent()
735   {
736     $this->handle_post_events("remove");
737   }
739   function generateDNSyn($release)
740   {
741     $str = "";
742     $tmp = split("\/",$release);
743     $tmp = array_reverse($tmp);
745     $base = "ou=fai,ou=configs,ou=systems,";   
746     foreach($tmp as $departmentname){
747       
748       $str .= ",ou=".$departmentname;
749     }
750     $str = preg_replace("/^,/","",($str.",".$base));
751     
752     return($str);
753   }
755   function getFAIdebianMirrors()
756   {
757     $ret = array();
758     $ret['inherited']="["._("inherited")."]";
759     $ret['auto']=_("automatic");
760     $secs  = array();
762     /* Walk through all available servers 
763         and check if they support the currently selected classes
764         if not, dont't add them to our list
765      */
766     foreach($this->FAIServRepConfig as $mirror => $rest){
768       $use = false;
770       if(count($this->FAIclass) == 0){
771         $use = true;
772       }else{
773         $tmp = $this->getFAIreleases();
774         foreach($tmp as $release){
775           if(isset($rest['RELEASE'][$release])){
776             $use =true;
777           }
778         } 
779       }
781       /* If current server, doesn't support this class
782           remove it from list
783        */
784       if($use){
785         $ret[$mirror] = $mirror;
786       }
787     }
788     return($ret);
789   }
791   function getFAIreleases() 
792   {
793     $ret = array();
795     if($this->FAIdebianMirror == "inherited") return(array());
797     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
798       $this->FAIdebianMirror = "auto";
799     }
801     $errorClasses = array();  
803     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
804     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
805       $use = true;
806       
807       if(!count($this->FAIclass) == 0){
808         foreach($this->FAIclass as $class){
809           if(!in_array($class, $sections['PACKAGES'])){
810             $use = false;
811             $errorClasses[$class] = $class;
812           }else{
813             if(isset($errorClasses[$class])){
814               unset($errorClasses[$class]); 
815             }
816           }
817         }
818       }
819       if($use){
820         $ret[$release]=$release;
821       }
822     } 
823     }
824     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
826       $eClasses = " ";
827       foreach($errorClasses as $class){
828         $eClasses .= $class." ";
829       }
831       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));
832       $this->FAIdebianMirror = "auto";
833       return($this->getFAIreleases());
834     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
836       $eClasses = " ";
837       foreach($errorClasses as $class){
838         $eClasses .= $class." ";
839       }
841       $eClasses = preg_replace("/  */","",$eClasses);
842      
843       if(!empty($eClasses)) {
844         $this->FAIclass= array();
845         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));
846       }
847     }
848     return($ret);
849   }
851   /* Save data to object */
852   function save_object()
853   {
854     plugin::save_object();
856     /* Save group radio buttons */
857     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
858       $this->bootmode= $_POST["bootmode"];
859     }
861     /* Save kernel parameters */
862     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
863       $this->customParameters= $_POST["customParameters"];
864     }
866   }
869   /* Save to LDAP */
870   function save()
871   {
873     /* Depending on the baseobject (Ogroup / WS) we
874      *  use another set of objectClasses
875      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
876      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
877      */
878     if(isset($this->parent->by_object['ogroup'])){
879       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
880     }elseif(isset($this->parent->by_object['workgeneric'])){
881       $this->objectclasses = array("GOhard", "FAIobject");
882     }elseif(isset($this->parent->by_object['servgeneric'])){
883       $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
884     }else{
885       print "Object Type Configuration : unknown";
886       exit();
887     }
889     /* Find proper terminal path for tftp configuration
890        FIXME: This is suboptimal when the default has changed to
891        another location! */
892     if (($this->gotoTerminalPath == "default")){
893       $ldap= $this->config->get_ldap_link();
895       /* Strip relevant part from dn, keep trailing ',' */
896       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
897       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
899       /* Walk from top to base and try to load default values for
900          'gotoTerminalPath'. Abort when an entry is found. */
901       while (TRUE){
902         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
904         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
905             $this->config->current['BASE'], array('gotoTerminalPath'));
906         $attrs= $ldap->fetch();
907         if (isset($attrs['gotoTerminalPath'])){
908           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
909           break;
910         }
912         /* Nothing left? */
913         if ($tmp == ""){
914           break;
915         }
916       }
917     }
919     /* Add semi automatic values */
920     // FIXME: LDAP Server may not be set here...
921     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
923     switch ($this->bootmode){
924       case "D":
925         $this->gotoKernelParameters.= " debug";
926       break;
927       case "G":
928         $this->gotoKernelParameters.= " splash=silent";
929       break;
930     }
931     if ($this->customParameters != ""){
932       $this->gotoKernelParameters.= " o ".$this->customParameters;
933     }
935     plugin::save();
937     unset( $this->attrs['FAIrelease'] );
938     
939     $str = "";
941     if($this->FAIdebianMirror == "inherited"){
942   
943       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
945     }else{
947       foreach($this->FAIclass as $class){
948         $str .= $class." ";
949       }
950       $str .= ":" . $this->FAIrelease;
951       $this->attrs['FAIclass']= "";
952       $this->attrs['FAIclass']= trim($str);
954       if(empty($this->attrs['FAIclass'])){
955         $this->attrs['FAIclass'] = array();
956       }
957     }
959     /* Add missing arrays */
960     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
961       if (isset ($this->$val) && count ($this->$val) != 0){
962     
963         $this->attrs["$val"]= array_unique($this->$val);
964       }
965       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
966     }
968     /* Strip out 'default' values */
969     if ($this->attrs['gotoLdapServer'] == "default"){
970       $this->attrs['gotoLdapServer']= array();
971     }
973     if (($this->attrs['gotoBootKernel'] == "default") || ($this->attrs['gotoBootKernel'] == "%default%")){
974       $this->attrs['gotoBootKernel']= array();
975     }
977     /* if mirror == none stop saving this attribute */
978     if($this->FAIdebianMirror == "none"){
979       $this->FAIdebianMirror = "";
980     }
981    
982     /* Get FAIstate from object, the generic tab could have changed it during execute */
983     $ldap= $this->config->get_ldap_link();
984     $ldap->cd($this->dn);
985     $ldap->cat($this->dn,array("FAIstate"));
986     $checkFAIstate = $ldap->fetch();
988     /* Remove FAI objects if no FAI class is selected */ 
989     if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
990       $tmp = array();
991       foreach($this->attrs['objectClass'] as $class){
992         if($class != "FAIobject"){
993           $tmp[] = $class;
994         }
995       }
996       $this->attrs['objectClass']     = $tmp;
997       $this->attrs['FAIclass']        = array();
998       $this->attrs['FAIdebianMirror'] = array();
999     }
1001     /* prepare share settings */
1002     $tmp = array();
1003     foreach($this->gotoShares as $name => $settings){
1004       $tmp2= split("\|",$name);
1005       $name = $tmp2[0];
1006       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1007     }
1008     $this->attrs['gotoShare']=$tmp;
1010     $this->cleanup();
1011     $ldap->modify ($this->attrs); 
1013     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1014     $this->handle_post_events("modify");
1015   }
1017   /* Add value to array, check if unique */
1018   function add_list (&$array, $value)
1019   {
1020     if ($value != ""){
1021       $array[]= $value;
1022       sort($array);
1023       array_unique ($array);
1024     }
1025   }
1028   /* Delete value to array, check if unique */
1029   function del_list (&$array, $list)
1030   {
1031     $tmp= array();
1032     foreach ($array as $mod){
1033       if (!in_array($mod, $list)){
1034         $tmp[]= $mod;
1035       }
1036     }
1037     $array= $tmp;
1038   }
1040   /* Generate ListBox frindly output for the defined shares
1041    * Possibly Add or remove an attribute here,
1042    */
1043   function printOutAssignedShares()
1044   {
1045     $a_return = array();
1046     if(is_array($this->gotoShares)){
1047       foreach($this->gotoShares as $share){
1048         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1049       }
1050     }
1051     return($a_return);
1052   }
1055   function GetHookElements()
1056   {
1057     $ret = array();
1058     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1059     if(!empty($cmd)){
1060       $res = shell_exec($cmd);
1061       $res2 = trim($res);
1062       if((!$res)){
1063         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1064       }elseif(empty($res2)){
1065         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1066       }else{
1067         $tmp = split("\n",$res);
1068         foreach($tmp as $line){
1069           if(empty($line)) continue;
1070           $ret[]= $line;
1071         }
1072       }
1073     }
1074     return($ret);
1075   }
1079 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1080 ?>