Code

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