Code

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