Code

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