Code

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