Code

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