Code

9c12a77f64930f8e7e1a42c7044a9baa72ad73a2
[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("default");
12   var $gotoBootKernel       = "";
13   var $gotoKernelParameters = "";
14   var $gotoLdapServer       = "";
15   var $gotoModules          = array();
16   var $gotoAutoFs           = array();
17   var $gotoFilesystem       = array();
18   var $gotoTerminalPath     = "";
19   var $FAIstatus            = "";
20   var $gotoBootKernels      = array("default");
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   /* Contains all possible server/release/class settings */
45   var $FAIServRepConfig   = array();
47   function workstartup ($config, $dn= NULL)
48   {
49     plugin::plugin ($config, $dn);
51     /* Creating a list of valid Mirrors 
52      * none will not be saved to ldap.
53      */
54     $ldap   = $this->config->get_ldap_link();
55     $ldap->cd($this->config->current['BASE']);
56     
57     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
58     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
60     /* Search all FAI objects */
61     $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
62     /* Sort all entries, and attach elementtype.
63      * To be able to show the types in the listbox.
64      */
65     while($attr = $ldap->fetch()){
66       $cn = $attr['cn'][0];
67     
68       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
69  
70       if(in_array('FAIpackageList',$attr['objectClass'])){
71         $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
72         $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
73         $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
74         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
75       }
76       if(in_array('FAItemplate',$attr['objectClass'])){
77         $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
78         $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
79         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
80       }
81       if(in_array('FAIvariable',$attr['objectClass'])){
82         $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
83         $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
84         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
85       }
86       if(in_array('FAIscript',$attr['objectClass'])){
87         $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
88         $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
89         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
90       }
91       if(in_array('FAIhook',$attr['objectClass'])){
92         $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
93         $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
94         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
95       }
96       if(in_array('FAIpartitionTable',$attr['objectClass'])){
97         $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
98         $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
99         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
100       }
101       if(in_array('FAIprofile',$attr['objectClass'])){
102         $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
103         $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
104         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
105       }
106     }
107     if(is_array($this->FAIclasses)){
108       natcasesort($this->FAIclasses);
109     }
111     $this->FAIclassInfo = $tmp2;
114     /* Build up an array like this one :
115         [$url]['SERVER'] = 'srv1-002';
116         [$url]['RELEASE']['siga/rc9.0.2']
117                                            ['SECTIONS'][0] "main";
118                                            ['SECTIONS'][1] "non-free";
119         [$url]['RELEASE']['siga/rc9.0.2']
120                                            ['PACKAGES'][0] "pkg1";
121                                            ['PACKAGES'][1] "postfix";
122      */
124     $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
125     $test = array();
126     while($attr = $ldap->fetch()){
127       if(isset($attr['FAIrepository'])){
129         unset($attr['FAIrepository']['count']);
131         foreach($attr['FAIrepository'] as $rep){
132           $tmp = split("\|",$rep);
134           if(count($tmp)==4){
135             $sections = split(",",$tmp[3]);
136             $release  = $tmp[2];
137             $server   = $tmp[1];
138             $url      = $tmp[0];
139            
140             $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
141     
142             /* Result will be cached
143              */
144             $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
145             $test[$url]['SERVER'] = $server;
147             /* auto gets all releases/classes 
148              */
149             $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
150             $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
151           }
152         }
153       }
154     }
155     $this->FAIServRepConfig =$test;
157     /* Get arrays */
158     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
159       if (isset($this->attrs["$val"]["count"])){
160         for ($i= 0; $i<$this->attrs["count"]; $i++){
161           if (isset($this->attrs["$val"][$i])){
162             array_push($this->$val, $this->attrs["$val"][$i]);
163           }
164         }
165       }
166       sort ($this->$val);
167       $this->$val= array_unique($this->$val);
168     }
170     /* Parse Kernel Parameters to decide what boot mode is enabled */
171     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
172       $this->bootmode= "G";
173     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
174       $this->bootmode= "D";
175     } elseif ($this->gotoKernelParameters == "") {
176       $this->bootmode= "G";
177     } else {
178       $this->bootmode= "T";
179     }
180     if (preg_match("/ o /", $this->gotoKernelParameters)){
181       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
182     } else {
183       $this->customParameters= "";
184     }
186     /* Prepare Shares */
187     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
188       unset($this->attrs['gotoShare']['count']);
189       foreach($this->attrs['gotoShare'] as $share){
190         $tmp = $tmp2 = array();
191         $tmp = split("\|",$share);
192         $tmp2['server']      =$tmp[0];
193         $tmp2['name']        =$tmp[1];
194         $tmp2['mountPoint']  =$tmp[2];
195         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
196       }
197     }
199     $this->gotoShareSelections= $config->getShareList(true);
200     $this->gotoAvailableShares= $config->getShareList(false);
201     $tmp2 = array();
202   
203     if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
204       $tmp = array();
205       $tmp = split(" ",$this->FAIclass);
206       $tmp2 =array();  
207     
208       foreach($tmp as $class){
209         if( ":" == $class[0] ) {
210           $this->FAIrelease = substr( $class, 1 );
211         }
212         else
213           $tmp2[$class] = $class;
214       }
215       $this->FAIclass = $tmp2;
216     }
218     if(!is_array($this->FAIclass)){
219       $this->FAIclass =array();
220     }
222     $this->orig_dn= $this->dn;
224     /* Get list of boot kernels */
225     if (isset($this->config->data['TABS'])){
226       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
228       if (!check_command($command)){
229         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
230             get_class($this));
231       } else {
232         $fh= popen($command, "r");
233         while (!feof($fh)) {
234           $buffer= trim(fgets($fh, 256));
235           
236           if ($buffer != ""){
237             $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
238           }
239         }
240         pclose($fh);
241         sort($this->gotoBootKernels);
242       }
243       
244     }
245   }
247   
248   /* This class is called by the contrucktor ONLY.
249    *   It return the available classes for each 
250    *    Server / Release combination ... 
251    *   (Release specifies which classes are available) 
252    */
253   function getAvailableClassesForThisRelease($release)
254   {
255     /* There could be more than one server providing this release,
256         so use cached result if available
257      */ 
258     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
259       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
260     }
262     /* Create cache with all classes 
263      */
264     if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
265        (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
266        (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
268       /* Get ldap connection */
269       $ldap   = $this->config->get_ldap_link();
270       $ldap->cd($this->config->current['BASE']);
272       /* Get possible classes ... 
273          This would be faste with some kind of caching ... 
274        */
275       $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
276       /* Sort all entries, and attach elementtype.
277        * To be able to show the types in the listbox.
278        */
279       while($attr = $ldap->fetch()){
280         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
281       }  
282     }
284     /* Walk through cache and get out what we need.
285      *   
286      *   Function od : "$this->generateDNSyn($release)"
287      *    It returns an array like this one :
288      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
289      *            "ou=scripts.. " 
290      *             ...);
291      *   This helps us to select the correct classes for each release. 
292      *   It prevents errors like:  'siga' is selected as release, but all classes
293      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
294      */
295     $tmp2 = $this->generateDNSyn($release)     ; 
296     $test2 = array();
297     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
298       foreach($tmp2 as $dns){
299         if(preg_match("/".$dns."/",$attr['dn'])){
300           $test2[$attr['cn'][0]] = $attr['cn'][0];
301         }
302       }
303     }
304     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
305     return($test2);
306   }
309   /*  Create array to display available classes/profiles in a selectbox 
310    *   This function only displays the available classes.
311    *   If a class is available is defined by these facts : 
312    *     1. Is this class available for the selected release ?
313    *       - if it is available, check if the release is available for the selected server 
314    *         (done by $this->getFAIreleases())
315    *     2. Is this class currently not assigned to $this->FAIclass
316    */
317   function selectFriendlyClasses(){
318     $tmp=array();
320     /* check if the current release exists,
321         else select the first one ..
322      */
323     $tmp2 = $this->getFAIreleases();
324     if(!in_array($this->FAIrelease, $tmp2)){  
325       $this->FAIrelease = key($tmp2);
326     }
327  
328     /* Get all Packages for this server/release combination
329      */
330     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
331       $pkgs = array();
332       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
333     }else{
334       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
335     }
337     /* Check each and every single class name 
338      */
339     foreach($pkgs as $pkg){
340   
341       /* Class already assigned to the classes list ?
342        * If not ... go on
343        */
344       if(!in_array($pkg,$this->FAIclass)){
345         
346         /* Create the displayed list entry value
347             HKLMOP [-Pl P V T-] or something like that 
348          */
349         $str = "";
350         foreach($this->FAIclassInfo[$pkg] as $entry){
351           if(isset($entry['kzl'])){
352             $str .= $entry['kzl']." ";
353           }
354         }
355         
356         /* Append class if everyting was fine
357          */        
358         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
359       }
360     }
361     /* Just sort and return new classes list ...
362        ( possibly we should cache the result ... )
363      */
364     natcasesort ($tmp);
365     return($tmp);
366   }
368   function check()
369   {
370     $messages = array();
371     
372     /* Call common method to give check the hook */
373     $messages= plugin::check();
375     /* If there are packages selected, but no mirror show error */   
376     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
377       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
378     }
380     return($messages);
381   }
383   function execute()
384   {
386         /* Call parent execute */
387         plugin::execute();
389     /* Do we need to flip is_account state? */
390     if (isset($_POST['modify_state'])){
391       $this->is_account= !$this->is_account;
392     }
394     /* Do we represent a valid terminal? */
395     if (!$this->is_account && $this->parent == NULL){
396       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
397         _("This 'dn' has no terminal features.")."</b>";
398       return ($display);
399     }
401     /* Add module */
402     if (isset ($_POST['add_module'])){
403       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
404         $this->add_list ($this->gotoModules, $_POST['module']);
405       }
406     }
408     /* Delete module */
409     if (isset ($_POST['delete_module'])){
410       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
411         $this->del_list ($this->gotoModules, $_POST['modules_list']);
412       }
413     }
415     /* FAI class management */
416     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
417       $found = 0 ; 
419       /* If this new class/profile will attach a second partition table
420        * to our list of classes, abort and show a message.
421        */
422       foreach($this->FAIclass as $name){
423         if(isset($this->FAIclassInfo[$name])){
424           foreach($this->FAIclassInfo[$name] as $atr){
425             if(isset($atr['obj'])){
426               if($atr['obj'] == "FAIpartitionTable"){
427                 $found ++ ; 
428               }
429             }
430           }
431         }
432       }
434       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
435         print_red(_("There is already a profile in your selection that contain partition table configurations."));
436       }else{
437         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
438       }
439     }
441     $sort = false;
442     foreach($_POST as $name => $val){
443       
444       $sort_type = false;
445       if((preg_match("/sort_up/",$name))&&(!$sort)){
446         $sort_type = "sort_up_";
447       }
448       if((preg_match("/sort_down/",$name))&&(!$sort)){
449         $sort_type = "sort_down_";
450       }
451     
452       if(($sort_type)&&(!$sort)){
453         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
454         $sort = true;
455         
456         $last = -1;
457         $change_down  = -1;
458  
459         /* Create array with numeric index */ 
460         $tmp = array();
461         foreach($this->FAIclass as $class){
462           $tmp [] = $class;
463         }
465         /* Walk trough array */
466         foreach($tmp as $key => $faiName){
467           if($faiName == $value){
468             if($sort_type == "sort_up_"){
469               if($last != -1){
470                  $change_down= $last;
471               }
472             }else{
473               if(isset($tmp[$key+1])){
474                 $change_down = $key;
475               }
476             }
477           }
478           $last = $key;
479         }
480  
481         $tmp2 = array();
482         $skip = false;    
483   
484         foreach($tmp as $ky => $vl){
486           if($ky == $change_down){
487             $skip = $vl;
488           }else{
489             $tmp2[$vl] = $vl;
490           }
491           if(($skip != false)&&($ky != $change_down)){
492             $tmp2[$skip]  = $skip;
493             $skip =false;
494           }
495         }   
496         $this->FAIclass = $tmp2; 
497       }
498   
499       if(preg_match("/fai_remove/i",$name)){
500         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
501         unset($this->FAIclass[$value]);
502       }
503     }
505     /* Delete selected class from our list */
506     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
507       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
508         unset($this->FAIclass[$_POST['FAIclassSel']]);
509       }
510     }
512     /* Show main page */
513     $smarty= get_smarty();
514     $smarty->assign("SelectBoxLdapServer","");
516     /* In this section server shares will be defined
517      * A user can select one of the given shares and a mount point
518      *  and attach this combination to his setup.
519      */
520     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
521     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
523     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
524      * This entry will be, a combination of mountPoint and sharedefinitions
525      */
526     if(isset($_POST['gotoShareAdd'])){
527       /* We assign a share to this user, if we don't know where to mount the share */
528       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
529         print_red(_("You must specify a valid mount point."));
530       }else{
531         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
532         $s_mount = $_POST['gotoShareMountPoint'];
533         /* Preparing the new assignment */
534         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
535         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
536       }
537     }
539     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
540      * If there is no defined share selected, we will abort the deletion without any message
541      */
542     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
543       unset($this->gotoShares[$_POST['gotoShare']]);
544     }
546     $smarty->assign("gotoShares",$this->printOutAssignedShares());
547     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
548     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
550     /* Arrays */
551     $tmp = $this->config->data['SERVERS']['LDAP'];
553     /* Create divSelectBox for ldap server selection
554      */
555     $SelectBoxLdapServer = new divSelectBox("LdapServer");
556     $SelectBoxLdapServer->SetHeight(80);
558     /* Set first entry as selected, if $this->gotoLdapServer is empty
559      *  or given entry is no longer available ... 
560      */
561     $found = false;
562     foreach($tmp as $server){
563       if($this->gotoLdapServer==$server){
564         $found = true;
565       }
566     }
568     /* Add Entries 
569      */
570     foreach($tmp as $server){
571       $use ="";
572       if(($this->gotoLdapServer == $server) || ($found == false)) {
573         $found = true;
574         $use = " checked ";
575       };
577       $SelectBoxLdapServer->AddEntry(
578           array(
579             array("string"=>$server),
580             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
581                   "attach"=>"style='border-right:0px;'")
582             ));
583     }    
585     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
587     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
588     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
589       $smarty->assign("$val", $this->$val);
590     }
592     /* Values */
593     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
594       $smarty->assign($val, $this->$val);
595       $smarty->assign($val."ACL", chkacl($this->acl, $val));
596     }
598     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
599     $smarty->assign("FAIreleases",$this->getFAIreleases());
600     $smarty->assign("FAIrelease",$this->FAIrelease);
601     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
602     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
603     $smarty->assign("FAIclassKeys",$this->FAIclass);
604     
605     $div = new divSelectBox("WSFAIscriptClasses");
606     $div -> SetHeight("110");
607     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
608     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
609     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
610     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
612     $i = 1;
613     foreach($this->FAIclass as $class){
614       if($i==1){
615         $str = $str_empty.$str_down.$str_remove;
616       }elseif($i == count($this->FAIclass)){
617         $str = $str_up.$str_empty.$str_remove;
618       }else{
619         $str = $str_up.$str_down.$str_remove;
620       }
621       $i ++ ; 
623       $div->AddEntry(array(
624             array("string"=>$class),
625             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
626             ));
627     }  
629     $smarty->assign("FAIScriptlist",$div->DrawList()); 
631     /* Radio button group */
632     if (preg_match("/G/", $this->bootmode)) {
633       $smarty->assign("graphicalbootup", "checked");
634     } else {
635       $smarty->assign("graphicalbootup", "");
636     }
637     if (preg_match("/T/", $this->bootmode)) {
638       $smarty->assign("textbootup", "checked");
639     } else {
640       $smarty->assign("textbootup", "");
641     }
642     if (preg_match("/D/", $this->bootmode)) {
643       $smarty->assign("debugbootup", "checked");
644     } else {
645       $smarty->assign("debugbootup", "");
646     }
648     /* ACL's */
649     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
650       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
651     }
653     /* Show main page */
654     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
655   }
657   function remove_from_parent()
658   {
659     $this->handle_post_events("remove");
660   }
662   function generateDNSyn($release)
663   {
664     $str = "";
665     $tmp = split("\/",$release);
666     $tmp = array_reverse($tmp);
668     $base = ",ou=fai,";   
669  
670     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
672     foreach($tmp as $departmentname){
673       
674       $str .= ",ou=".$departmentname;
675     }
676     $ret = array();
677     foreach($arr as $ar){
678       $ret[] = ",ou=".$ar.$str.$base;
679     }
680     return($ret);
681   }
683   function getFAIdebianMirrors()
684   {
685     $ret = array();
686     $ret['auto']=_("automatic");
687     $secs  = array();
689     /* Walk through all available servers 
690         and check if they support the currently selected classes
691         if not, dont't add them to our list
692      */
693     foreach($this->FAIServRepConfig as $mirror => $rest){
695       $use = false;
697       if(count($this->FAIclass) == 0){
698         $use = true;
699       }else{
700         $tmp = $this->getFAIreleases();
701         foreach($tmp as $release){
702           if(isset($rest['RELEASE'][$release])){
703             $use =true;
704           }
705         } 
706       }
708       /* If current server, doesn't support this class
709           remove it from list
710        */
711       if($use){
712         $ret[$mirror] = $mirror;
713       }
714     }
715     return($ret);
716   }
718   function getFAIreleases() 
719   {
720     $ret = array();
722     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
723       $this->FAIdebianMirror = "auto";
724     }
726     $errorClasses = "";  
727   
728     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
729       $use = true;
730       
731       if(!count($this->FAIclass) == 0){
732         foreach($this->FAIclass as $class){
733           if(!in_array($class, $sections['PACKAGES'])){
734             $use = false;
735             $errorClasses[$class] = $class;
736           }else{
737             if(isset($errorClasses[$class])){
738               unset($errorClasses[$class]); 
739             }
740           }
741         }
742       }
743       if($use){
744         $ret[$release]=$release;
745       }
746     } 
747     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
749       $eClasses = " ";
750       foreach($errorClasses as $class){
751         $eClasses .= $class." ";
752       }
754       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));
755       $this->FAIdebianMirror = "auto";
756       return($this->getFAIreleases());
757     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
759       $eClasses = " ";
760       foreach($errorClasses as $class){
761         $eClasses .= $class." ";
762       }
763       
764       $this->FAIclass= array();
765       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));
766     }
767     return($ret);
768   }
770   /* Save data to object */
771   function save_object()
772   {
773     plugin::save_object();
775     /* Save group radio buttons */
776     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
777       $this->bootmode= $_POST["bootmode"];
778     }
780     /* Save kernel parameters */
781     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
782       $this->customParameters= $_POST["customParameters"];
783     }
784   }
787   /* Save to LDAP */
788   function save()
789   {
791     /* Depending on the baseobject (Ogroup / WS) we
792      *  use another set of objectClasses
793      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
794      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
795      */
796     if(isset($this->parent->by_object['ogroup'])){
797       $this->objectclasses = array("gotoWorkstationTemplate","GOhard", "FAIobject");
798     }elseif(isset($this->parent->by_object['workgeneric'])){
799       $this->objectclasses = array("GOhard", "FAIobject");
800     }else{
801       print "Object Type Configuration : unknown";
802       exit();
803     }
805     /* Find proper terminal path for tftp configuration
806        FIXME: This is suboptimal when the default has changed to
807        another location! */
808     if ($this->gotoTerminalPath == "default"){
809       $ldap= $this->config->get_ldap_link();
811       /* Strip relevant part from dn, keep trailing ',' */
812       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
813       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
815       /* Walk from top to base and try to load default values for
816          'gotoTerminalPath'. Abort when an entry is found. */
817       while (TRUE){
818         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
820         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
821             $this->config->current['BASE']);
822         $attrs= $ldap->fetch();
823         if (isset($attrs['gotoTerminalPath'])){
824           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
825           break;
826         }
828         /* Nothing left? */
829         if ($tmp == ""){
830           break;
831         }
832       }
833     }
835     /* Add semi automatic values */
836     // FIXME: LDAP Server may not be set here...
837     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
839     switch ($this->bootmode){
840       case "D":
841         $this->gotoKernelParameters.= " debug";
842       break;
843       case "G":
844         $this->gotoKernelParameters.= " splash=silent";
845       break;
846     }
847     if ($this->customParameters != ""){
848       $this->gotoKernelParameters.= " o ".$this->customParameters;
849     }
851     plugin::save();
853     unset( $this->attrs['FAIrelease'] );
854     
855     $str = "";
856     foreach($this->FAIclass as $class){
857       $str .= $class." ";
858     }
859     $str .= ":" . $this->FAIrelease;
860     $this->attrs['FAIclass']= "";
861     $this->attrs['FAIclass']= trim($str);
863     if(empty($this->attrs['FAIclass'])){
864       $this->attrs['FAIclass'] = array();
865     }
867     /* Add missing arrays */
868     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
869       if (isset ($this->$val) && count ($this->$val) != 0){
870     
871         $this->attrs["$val"]= array_unique($this->$val);
872       }
873       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
874     }
875     /* Strip out 'default' values */
876     if ($this->attrs['gotoLdapServer'] == "default"){
877       unset ($this->attrs['gotoLdapServer']);
878     }
880     /* if mirror == none stop saving this attribute */
881     if($this->FAIdebianMirror == "none"){
882       $this->FAIdebianMirror = "";
883     }
884     
885     if((count($this->attrs['FAIclass'])==0)&&(empty($this->FAIdebianMirror))){
886       $tmp = array();
887       foreach($this->attrs['objectClass'] as $class){
888         if($class != "FAIobject"){
889           $tmp[] = $class;
890         }
891       }
892       $this->attrs['objectClass']     = $tmp;
893       $this->attrs['FAIclass']        = array();
894       $this->attrs['FAIdebianMirror'] = array();
895     }
897     /* prepare share settings */
898     $tmp = array();
899     foreach($this->gotoShares as $name => $settings){
900       $tmp2= split("\|",$name);
901       $name = $tmp2[0];
902       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
903     }
904     $this->attrs['gotoShare']=$tmp;
906     $ldap= $this->config->get_ldap_link();
907     $ldap->cd($this->dn);
908     $this->cleanup();
909 $ldap->modify ($this->attrs); 
911     show_ldap_error($ldap->get_error());
912     $this->handle_post_events("modify");
913   }
915   /* Add value to array, check if unique */
916   function add_list (&$array, $value)
917   {
918     if ($value != ""){
919       $array[]= $value;
920       sort($array);
921       array_unique ($array);
922     }
923   }
926   /* Delete value to array, check if unique */
927   function del_list (&$array, $list)
928   {
929     $tmp= array();
930     foreach ($array as $mod){
931       if (!in_array($mod, $list)){
932         $tmp[]= $mod;
933       }
934     }
935     $array= $tmp;
936   }
938   /* Generate ListBox frindly output for the defined shares
939    * Possibly Add or remove an attribute here,
940    */
941   function printOutAssignedShares()
942   {
943     $a_return = array();
944     if(is_array($this->gotoShares)){
945       foreach($this->gotoShares as $share){
946         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
947       }
948     }
949     return($a_return);
950   }
954 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
955 ?>