Code

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