Code

Fixed sort to ksort
[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" => "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         ksort($this->gotoBootKernels);
242       }
243       
244     }
246   }
248   
249   /* This class is called by the contrucktor ONLY.
250    *   It return the available classes for each 
251    *    Server / Release combination ... 
252    *   (Release specifies which classes are available) 
253    */
254   function getAvailableClassesForThisRelease($release)
255   {
256     /* There could be more than one server providing this release,
257         so use cached result if available
258      */ 
259     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
260       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
261     }
263     /* Create cache with all classes 
264      */
265     if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
266        (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
267        (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
269       /* Get ldap connection */
270       $ldap   = $this->config->get_ldap_link();
271       $ldap->cd($this->config->current['BASE']);
273       /* Get possible classes ... 
274          This would be faste with some kind of caching ... 
275        */
276       $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
277       /* Sort all entries, and attach elementtype.
278        * To be able to show the types in the listbox.
279        */
280       while($attr = $ldap->fetch()){
281         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
282       }  
283     }
285     /* Walk through cache and get out what we need.
286      *   
287      *   Function od : "$this->generateDNSyn($release)"
288      *    It returns an array like this one :
289      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
290      *            "ou=scripts.. " 
291      *             ...);
292      *   This helps us to select the correct classes for each release. 
293      *   It prevents errors like:  'siga' is selected as release, but all classes
294      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
295      */
296     $tmp2 = $this->generateDNSyn($release)     ; 
297     $test2 = array();
298     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
299       foreach($tmp2 as $dns){
300         if(preg_match("/".$dns."/",$attr['dn'])){
301           $test2[$attr['cn'][0]] = $attr['cn'][0];
302         }
303       }
304     }
305     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
306     return($test2);
307   }
310   /*  Create array to display available classes/profiles in a selectbox 
311    *   This function only displays the available classes.
312    *   If a class is available is defined by these facts : 
313    *     1. Is this class available for the selected release ?
314    *       - if it is available, check if the release is available for the selected server 
315    *         (done by $this->getFAIreleases())
316    *     2. Is this class currently not assigned to $this->FAIclass
317    */
318   function selectFriendlyClasses(){
319     $tmp=array();
321     /* check if the current release exists,
322         else select the first one ..
323      */
324     $tmp2 = $this->getFAIreleases();
325     if(!in_array($this->FAIrelease, $tmp2)){  
326       $this->FAIrelease = key($tmp2);
327     }
328  
329     /* Get all Packages for this server/release combination
330      */
331     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
332       $pkgs = array();
333       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
334     }else{
335       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
336     }
338     /* Check each and every single class name 
339      */
340     foreach($pkgs as $pkg){
341   
342       /* Class already assigned to the classes list ?
343        * If not ... go on
344        */
345       if(!in_array($pkg,$this->FAIclass)){
346         
347         /* Create the displayed list entry value
348             HKLMOP [-Pl P V T-] or something like that 
349          */
350         $str = "";
351         foreach($this->FAIclassInfo[$pkg] as $entry){
352           if(isset($entry['kzl'])){
353             $str .= $entry['kzl']." ";
354           }
355         }
356         
357         /* Append class if everyting was fine
358          */        
359         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
360       }
361     }
362     /* Just sort and return new classes list ...
363        ( possibly we should cache the result ... )
364      */
365     natcasesort ($tmp);
366     return($tmp);
367   }
369   function check()
370   {
371     $messages = array();
372     
373     /* Call common method to give check the hook */
374     $messages= plugin::check();
376     /* If there are packages selected, but no mirror show error */   
377     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
378       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
379     }
381     return($messages);
382   }
384   function execute()
385   {
387         /* Call parent execute */
388         plugin::execute();
390     /* Do we need to flip is_account state? */
391     if (isset($_POST['modify_state'])){
392       $this->is_account= !$this->is_account;
393     }
395     /* Do we represent a valid terminal? */
396     if (!$this->is_account && $this->parent == NULL){
397       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
398         _("This 'dn' has no terminal features.")."</b>";
399       return ($display);
400     }
402     /* Add module */
403     if (isset ($_POST['add_module'])){
404       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
405         $this->add_list ($this->gotoModules, $_POST['module']);
406       }
407     }
409     /* Delete module */
410     if (isset ($_POST['delete_module'])){
411       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
412         $this->del_list ($this->gotoModules, $_POST['modules_list']);
413       }
414     }
416     /* FAI class management */
417     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
418       $found = 0 ; 
420       /* If this new class/profile will attach a second partition table
421        * to our list of classes, abort and show a message.
422        */
423       foreach($this->FAIclass as $name){
424         if(isset($this->FAIclassInfo[$name])){
425           foreach($this->FAIclassInfo[$name] as $atr){
426             if(isset($atr['obj'])){
427               if($atr['obj'] == "FAIpartitionTable"){
428                 $found ++ ; 
429               }
430             }
431           }
432         }
433       }
435       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
436         print_red(_("There is already a profile in your selection that contain partition table configurations."));
437       }else{
438         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
439       }
440     }
442     $sort = false;
443     foreach($_POST as $name => $val){
444       
445       $sort_type = false;
446       if((preg_match("/sort_up/",$name))&&(!$sort)){
447         $sort_type = "sort_up_";
448       }
449       if((preg_match("/sort_down/",$name))&&(!$sort)){
450         $sort_type = "sort_down_";
451       }
452     
453       if(($sort_type)&&(!$sort)){
454         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
455         $sort = true;
456         
457         $last = -1;
458         $change_down  = -1;
459  
460         /* Create array with numeric index */ 
461         $tmp = array();
462         foreach($this->FAIclass as $class){
463           $tmp [] = $class;
464         }
466         /* Walk trough array */
467         foreach($tmp as $key => $faiName){
468           if($faiName == $value){
469             if($sort_type == "sort_up_"){
470               if($last != -1){
471                  $change_down= $last;
472               }
473             }else{
474               if(isset($tmp[$key+1])){
475                 $change_down = $key;
476               }
477             }
478           }
479           $last = $key;
480         }
481  
482         $tmp2 = array();
483         $skip = false;    
484   
485         foreach($tmp as $ky => $vl){
487           if($ky == $change_down){
488             $skip = $vl;
489           }else{
490             $tmp2[$vl] = $vl;
491           }
492           if(($skip != false)&&($ky != $change_down)){
493             $tmp2[$skip]  = $skip;
494             $skip =false;
495           }
496         }   
497         $this->FAIclass = $tmp2; 
498       }
499   
500       if(preg_match("/fai_remove/i",$name)){
501         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
502         unset($this->FAIclass[$value]);
503       }
504     }
506     /* Delete selected class from our list */
507     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
508       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
509         unset($this->FAIclass[$_POST['FAIclassSel']]);
510       }
511     }
513     /* Show main page */
514     $smarty= get_smarty();
515     $smarty->assign("SelectBoxLdapServer","");
517     /* In this section server shares will be defined
518      * A user can select one of the given shares and a mount point
519      *  and attach this combination to his setup.
520      */
521     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
522     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
524     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
525      * This entry will be, a combination of mountPoint and sharedefinitions
526      */
527     if(isset($_POST['gotoShareAdd'])){
528       /* We assign a share to this user, if we don't know where to mount the share */
529       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
530         print_red(_("You must specify a valid mount point."));
531       }else{
532         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
533         $s_mount = $_POST['gotoShareMountPoint'];
534         /* Preparing the new assignment */
535         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
536         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
537       }
538     }
540     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
541      * If there is no defined share selected, we will abort the deletion without any message
542      */
543     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
544       unset($this->gotoShares[$_POST['gotoShare']]);
545     }
547     $smarty->assign("gotoShares",$this->printOutAssignedShares());
548     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
549     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
551     /* Arrays */
552     $tmp = $this->config->data['SERVERS']['LDAP'];
554     /* Create divSelectBox for ldap server selection
555      */
556     $SelectBoxLdapServer = new divSelectBox("LdapServer");
557     $SelectBoxLdapServer->SetHeight(80);
559     /* Set first entry as selected, if $this->gotoLdapServer is empty
560      *  or given entry is no longer available ... 
561      */
562     $found = false;
563     foreach($tmp as $server){
564       if($this->gotoLdapServer==$server){
565         $found = true;
566       }
567     }
569     /* Add Entries 
570      */
571     foreach($tmp as $server){
572       $use ="";
573       if(($this->gotoLdapServer == $server) || ($found == false)) {
574         $found = true;
575         $use = " checked ";
576       };
578       $SelectBoxLdapServer->AddEntry(
579           array(
580             array("string"=>$server),
581             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
582                   "attach"=>"style='border-right:0px;'")
583             ));
584     }    
586     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
588     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
589     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
590       $smarty->assign("$val", $this->$val);
591     }
593     /* Values */
594     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
595       $smarty->assign($val, $this->$val);
596       $smarty->assign($val."ACL", chkacl($this->acl, $val));
597     }
599     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
600     $smarty->assign("FAIreleases",$this->getFAIreleases());
601     $smarty->assign("FAIrelease",$this->FAIrelease);
602     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
603     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
604     $smarty->assign("FAIclassKeys",$this->FAIclass);
605     
606     $div = new divSelectBox("WSFAIscriptClasses");
607     $div -> SetHeight("110");
608     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
609     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
610     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
611     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
613     $i = 1;
614     foreach($this->FAIclass as $class){
615       if($i==1){
616         $str = $str_empty.$str_down.$str_remove;
617       }elseif($i == count($this->FAIclass)){
618         $str = $str_up.$str_empty.$str_remove;
619       }else{
620         $str = $str_up.$str_down.$str_remove;
621       }
622       $i ++ ; 
624       $div->AddEntry(array(
625             array("string"=>$class),
626             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
627             ));
628     }  
630     $smarty->assign("FAIScriptlist",$div->DrawList()); 
632     /* Radio button group */
633     if (preg_match("/G/", $this->bootmode)) {
634       $smarty->assign("graphicalbootup", "checked");
635     } else {
636       $smarty->assign("graphicalbootup", "");
637     }
638     if (preg_match("/T/", $this->bootmode)) {
639       $smarty->assign("textbootup", "checked");
640     } else {
641       $smarty->assign("textbootup", "");
642     }
643     if (preg_match("/D/", $this->bootmode)) {
644       $smarty->assign("debugbootup", "checked");
645     } else {
646       $smarty->assign("debugbootup", "");
647     }
649     /* ACL's */
650     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
651       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
652     }
654     /* Show main page */
655     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
656   }
658   function remove_from_parent()
659   {
660     $this->handle_post_events("remove");
661   }
663   function generateDNSyn($release)
664   {
665     $str = "";
666     $tmp = split("\/",$release);
667     $tmp = array_reverse($tmp);
669     $base = ",ou=fai,";   
670  
671     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
673     foreach($tmp as $departmentname){
674       
675       $str .= ",ou=".$departmentname;
676     }
677     $ret = array();
678     foreach($arr as $ar){
679       $ret[] = ",ou=".$ar.$str.$base;
680     }
681     return($ret);
682   }
684   function getFAIdebianMirrors()
685   {
686     $ret = array();
687     $ret['auto']=_("automatic");
688     $secs  = array();
690     /* Walk through all available servers 
691         and check if they support the currently selected classes
692         if not, dont't add them to our list
693      */
694     foreach($this->FAIServRepConfig as $mirror => $rest){
696       $use = false;
698       if(count($this->FAIclass) == 0){
699         $use = true;
700       }else{
701         $tmp = $this->getFAIreleases();
702         foreach($tmp as $release){
703           if(isset($rest['RELEASE'][$release])){
704             $use =true;
705           }
706         } 
707       }
709       /* If current server, doesn't support this class
710           remove it from list
711        */
712       if($use){
713         $ret[$mirror] = $mirror;
714       }
715     }
716     return($ret);
717   }
719   function getFAIreleases() 
720   {
721     $ret = array();
723     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
724       $this->FAIdebianMirror = "auto";
725     }
727     $errorClasses = "";  
728   
729     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
730       $use = true;
731       
732       if(!count($this->FAIclass) == 0){
733         foreach($this->FAIclass as $class){
734           if(!in_array($class, $sections['PACKAGES'])){
735             $use = false;
736             $errorClasses[$class] = $class;
737           }else{
738             if(isset($errorClasses[$class])){
739               unset($errorClasses[$class]); 
740             }
741           }
742         }
743       }
744       if($use){
745         $ret[$release]=$release;
746       }
747     } 
748     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
750       $eClasses = " ";
751       foreach($errorClasses as $class){
752         $eClasses .= $class." ";
753       }
755       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));
756       $this->FAIdebianMirror = "auto";
757       return($this->getFAIreleases());
758     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
760       $eClasses = " ";
761       foreach($errorClasses as $class){
762         $eClasses .= $class." ";
763       }
764       
765       $this->FAIclass= array();
766       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));
767     }
768     return($ret);
769   }
771   /* Save data to object */
772   function save_object()
773   {
774     plugin::save_object();
776     /* Save group radio buttons */
777     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
778       $this->bootmode= $_POST["bootmode"];
779     }
781     /* Save kernel parameters */
782     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
783       $this->customParameters= $_POST["customParameters"];
784     }
785   }
788   /* Save to LDAP */
789   function save()
790   {
792     /* Depending on the baseobject (Ogroup / WS) we
793      *  use another set of objectClasses
794      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
795      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
796      */
797     if(isset($this->parent->by_object['ogroup'])){
798       $this->objectclasses = array("gotoWorkstationTemplate","GOhard", "FAIobject");
799     }elseif(isset($this->parent->by_object['workgeneric'])){
800       $this->objectclasses = array("GOhard", "FAIobject");
801     }else{
802       print "Object Type Configuration : unknown";
803       exit();
804     }
806     /* Find proper terminal path for tftp configuration
807        FIXME: This is suboptimal when the default has changed to
808        another location! */
809     if ($this->gotoTerminalPath == "default"){
810       $ldap= $this->config->get_ldap_link();
812       /* Strip relevant part from dn, keep trailing ',' */
813       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
814       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
816       /* Walk from top to base and try to load default values for
817          'gotoTerminalPath'. Abort when an entry is found. */
818       while (TRUE){
819         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
821         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
822             $this->config->current['BASE']);
823         $attrs= $ldap->fetch();
824         if (isset($attrs['gotoTerminalPath'])){
825           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
826           break;
827         }
829         /* Nothing left? */
830         if ($tmp == ""){
831           break;
832         }
833       }
834     }
836     /* Add semi automatic values */
837     // FIXME: LDAP Server may not be set here...
838     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
840     switch ($this->bootmode){
841       case "D":
842         $this->gotoKernelParameters.= " debug";
843       break;
844       case "G":
845         $this->gotoKernelParameters.= " splash=silent";
846       break;
847     }
848     if ($this->customParameters != ""){
849       $this->gotoKernelParameters.= " o ".$this->customParameters;
850     }
852     plugin::save();
854     unset( $this->attrs['FAIrelease'] );
855     
856     $str = "";
857     foreach($this->FAIclass as $class){
858       $str .= $class." ";
859     }
860     $str .= ":" . $this->FAIrelease;
861     $this->attrs['FAIclass']= "";
862     $this->attrs['FAIclass']= trim($str);
864     if(empty($this->attrs['FAIclass'])){
865       $this->attrs['FAIclass'] = array();
866     }
868     /* Add missing arrays */
869     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
870       if (isset ($this->$val) && count ($this->$val) != 0){
871     
872         $this->attrs["$val"]= array_unique($this->$val);
873       }
874       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
875     }
876     /* Strip out 'default' values */
877     if ($this->attrs['gotoLdapServer'] == "default"){
878       unset ($this->attrs['gotoLdapServer']);
879     }
881     /* if mirror == none stop saving this attribute */
882     if($this->FAIdebianMirror == "none"){
883       $this->FAIdebianMirror = "";
884     }
885     
886     if((count($this->attrs['FAIclass'])==0)&&(empty($this->FAIdebianMirror))){
887       $tmp = array();
888       foreach($this->attrs['objectClass'] as $class){
889         if($class != "FAIobject"){
890           $tmp[] = $class;
891         }
892       }
893       $this->attrs['objectClass']     = $tmp;
894       $this->attrs['FAIclass']        = array();
895       $this->attrs['FAIdebianMirror'] = array();
896     }
898     /* prepare share settings */
899     $tmp = array();
900     foreach($this->gotoShares as $name => $settings){
901       $tmp2= split("\|",$name);
902       $name = $tmp2[0];
903       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
904     }
905     $this->attrs['gotoShare']=$tmp;
907     $ldap= $this->config->get_ldap_link();
908     $ldap->cd($this->dn);
909     $this->cleanup();
910 $ldap->modify ($this->attrs); 
912     show_ldap_error($ldap->get_error());
913     $this->handle_post_events("modify");
914   }
916   /* Add value to array, check if unique */
917   function add_list (&$array, $value)
918   {
919     if ($value != ""){
920       $array[]= $value;
921       sort($array);
922       array_unique ($array);
923     }
924   }
927   /* Delete value to array, check if unique */
928   function del_list (&$array, $list)
929   {
930     $tmp= array();
931     foreach ($array as $mod){
932       if (!in_array($mod, $list)){
933         $tmp[]= $mod;
934       }
935     }
936     $array= $tmp;
937   }
939   /* Generate ListBox frindly output for the defined shares
940    * Possibly Add or remove an attribute here,
941    */
942   function printOutAssignedShares()
943   {
944     $a_return = array();
945     if(is_array($this->gotoShares)){
946       foreach($this->gotoShares as $share){
947         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
948       }
949     }
950     return($a_return);
951   }
955 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
956 ?>