Code

Updated Image Production.
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
3 class workstartup extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage terminal startup options";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* Generic terminal attributes */
11   var $bootmode             = "G";
12   var $goLdapServerList     = array();
13   var $gotoBootKernel       = "default-inherited";
14   var $gotoKernelParameters = "";
15   var $gotoLdapServer       = "default-inherited";
16   var $gotoModules          = array();
17   var $gotoAutoFs           = array();
18   var $gotoFilesystem       = array();
19   var $gotoTerminalPath     = "";
20   var $FAIstatus            = "";
21   var $gotoBootKernels      = array();
23   /* attribute list for save action */
24   var $attributes     = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25   var $objectclasses  = array("GOhard", "FAIobject");
27   /* These vars are required to copy object groups !. */
28   var $CopyPasteVars  = array("gotoModules","gotoShares","customParameters","FAIclass","FAIrelease","FAIdebianMirror"); 
30   /* Share */
31   var $gotoShares         = array();// Currently Share Option
32   var $gotoShare          = "";     // currently selected Share Option
33   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
34   var $gotoAvailableShares= array();// Available Shares for this account
36   /* Helper */
37   var $customParameters   = "";
38   var $orig_dn            = "";
39   var $ignore_account     = TRUE;
40  
41   /* FAI class selection */ 
42   var $FAIclass           = array();
43   var $FAIclasses         = array();
44   var $FAIclassInfo       = array();
45   var $FAIrelease         = "";
46   var $FAIdebianMirror    = "auto";
48   var $unresolved_classes = array();
49   
50   /* FAI class selection */
51   var $InheritedFAIclass           = array();
52   var $InheritedFAIrelease         = "";
53   var $InheritedFAIdebianMirror    = "auto";
55   /* Contains all possible server/release/class settings */
56   var $FAIServRepConfig   = array();
58   var $fai_activated      = FALSE;
60   function workstartup ($config, $dn= NULL, $parent= NULL)
61   {
62     /* Cehck if FAI is activated, else do not save any FAI attributes */
63     $tmp = search_config($config->data,"faiManagement","CLASS");
64     if(!empty($tmp)){
65       $this->fai_activated = TRUE;
66     }else{
67       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
68       $this->objectclasses  = array("GOhard");
69     }
71     plugin::plugin ($config, $dn, $parent);
73     /* Creating a list of valid Mirrors 
74      * none will not be saved to ldap.
75      */
76     $ldap   = $this->config->get_ldap_link();
77     $ldap->cd($this->config->current['BASE']);
79     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
80       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
81     }
83   
84     /* Perform some special FAI stuff, only if it is activated */
85     if($this->fai_activated){
87       $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
88       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
90       $ui = get_userinfo();
91       $res = get_list(          "(|(objectClass=FAIpackageList)".
92           "(objectClass=FAItemplate)".
93           "(objectClass=FAIvariable)".
94           "(objectClass=FAIscript)".
95           "(objectClass=FAIhook)".
96           "(objectClass=FAIprofile)".
97           "(objectClass=FAIpartitionTable))",
98           $ui->subtreeACL,$this->config->current['BASE'],
99           array("cn","objectClass","FAIdebianSection"));
101       foreach($res as $attr){
102         $cn = $attr['cn'][0];
104         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
106         if(in_array('FAIpackageList',$attr['objectClass'])){
107           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
108           $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
109           $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
110           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111         }
112         if(in_array('FAItemplate',$attr['objectClass'])){
113           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
114           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
115           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116         }
117         if(in_array('FAIvariable',$attr['objectClass'])){
118           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
119           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
120           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121         }
122         if(in_array('FAIscript',$attr['objectClass'])){
123           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
124           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
125           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126         }
127         if(in_array('FAIhook',$attr['objectClass'])){
128           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
129           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
130           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131         }
132         if(in_array('FAIpartitionTable',$attr['objectClass'])){
133           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
134           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
135           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
136         }
137         if(in_array('FAIprofile',$attr['objectClass'])){
138           $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
139           $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
140           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
141         }
142       }
143       if(is_array($this->FAIclasses)){
144         natcasesort($this->FAIclasses);
145       }
147       if(isset($tmp2)){
148         $this->FAIclassInfo = $tmp2;
149       } else {
150         $this->FAIclassInfo = array();
151       }
153       /* Build up an array like this one :
154          [$url]['SERVER'] = 'srv1-002';
155          [$url]['RELEASE']['siga/rc9.0.2']
156          ['SECTIONS'][0] "main";
157          ['SECTIONS'][1] "non-free";
158          [$url]['RELEASE']['siga/rc9.0.2']
159          ['PACKAGES'][0] "pkg1";
160          ['PACKAGES'][1] "postfix";
161        */
163       $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
164       $test = array();
165       while($attr = $ldap->fetch()){
166         if(isset($attr['FAIrepository'])){
168           unset($attr['FAIrepository']['count']);
170           foreach($attr['FAIrepository'] as $rep){
171             $tmp = split("\|",$rep);
173             if(count($tmp)==4){
174               $sections = split(",",$tmp[3]);
175               $release  = $tmp[2];
176               $server   = $tmp[1];
177               $url      = $tmp[0];
179               $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
181               /* Result will be cached
182                */
183               $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
184               $test[$url]['SERVER'] = $server;
186               /* auto gets all releases/classes 
187                */
188               $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
189               $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
190             }
191           }
192         }
193       }
195       /* Add possible elements from hook */
196       $lines= $this->GetHookElements();
197       foreach ($lines as $hline){
198         $entries= split(";", $hline);
199         if (isset($entries[1]) && !isset($test[$entries[1]])){
200           $test[$entries[1]]['RELEASE']= array();
202           /* Split releases */
203           if (isset($entries[2])){
204             $releases= split(",", $entries[2]);
206             foreach ($releases as $release){
207               $rname= preg_replace('/:.*$/', '', $release);
208               $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
209               $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
210               $test[$entries[1]]['RELEASE'][$rname]= array();
211               $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
212               foreach ($classes as $class){
213                 if ($class != ""){
214                   $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
215                 }
216               }
217             }
218           }
219         }
220       }
222       $this->FAIServRepConfig= $test;
223     } // Do FAI stuff end   
225     /* Get arrays */
226     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
227       if (isset($this->attrs["$val"]["count"])){
228         for ($i= 0; $i<$this->attrs["count"]; $i++){
229           if (isset($this->attrs["$val"][$i])){
230             array_push($this->$val, $this->attrs["$val"][$i]);
231           }
232         }
233       }
234       sort ($this->$val);
235       $this->$val= array_unique($this->$val);
236     }
238     /* Parse Kernel Parameters to decide what boot mode is enabled */
239     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
240       $this->bootmode= "G";
241     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
242       $this->bootmode= "D";
243     } elseif ($this->gotoKernelParameters == "") {
244       $this->bootmode= "G";
245     } else {
246       $this->bootmode= "T";
247     }
248     if (preg_match("/ o /", $this->gotoKernelParameters)){
249       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
250     } else {
251       $this->customParameters= "";
252     }
254     /* Prepare Shares */
255     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
256       unset($this->attrs['gotoShare']['count']);
257       foreach($this->attrs['gotoShare'] as $share){
258         $tmp = $tmp2 = array();
259         $tmp = split("\|",$share);
260         $tmp2['server']      =$tmp[0];
261         $tmp2['name']        =$tmp[1];
262         $tmp2['mountPoint']  =$tmp[2];
263         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
264       }
265     }
267     $this->gotoShareSelections= $config->getShareList(true);
268     $this->gotoAvailableShares= $config->getShareList(false);
269     $tmp2 = array();
272     /* Again some special FAI stuff */
273     if($this->fai_activated){ 
274       if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
275         $tmp = array();
276         $tmp = split(" ",$this->FAIclass);
277         $tmp2 =array();  
279         foreach($tmp as $class){
280           if( ":" == $class[0] ) {
281             $this->FAIrelease = substr( $class, 1 );
282           }
283           else
284             $tmp2[$class] = $class;
285         }
286         $this->FAIclass = $tmp2;
287       }
289       if(!is_array($this->FAIclass)){
290         $this->FAIclass =array();
291       }
292     }
294     $this->orig_dn= $this->dn;
296     /* Handle inheritance value "default" */
297     $this->gotoBootKernels= array();
300     /* Load hardware list */
301     $ldap= $this->config->get_ldap_link();
302     $ldap->cd($this->config->current['BASE']);
303     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
304     if ($ldap->count() == 1){
307       if($this->fai_activated){
308         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
309       }else{
310         $map= array("gotoLdapServer","gotoBootKernel");
311       }
313       $attrs= $ldap->fetch();
315       foreach ($map as $name){
316         if (!isset($attrs[$name][0])){
317           continue;
318         }
320         switch ($name){
321           case 'gotoLdapServer':
322             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
323             break;
325           case 'gotoBootKernel':
326             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
327             break;
329           case 'FAIclass':
330             $str = split(":",$attrs[$name][0]);
331             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
332             $this->InheritedFAIrelease  = trim($str[1]);
333             break;
335           case 'FAIdebianMirror':
336             $this->InheritedFAIdebianMirror = $attrs[$name][0];
337             break;
338         }
339       }
340     }
342     /* Get list of boot kernels */
343     if (isset($this->config->data['TABS'])){
344       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
346       if (!check_command($command)){
347         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
348             get_class($this));
349       } else {
350         
351         $first = false; 
352         $fh= popen($command, "r");
353         while (!feof($fh)) {
354           $buffer= trim(fgets($fh, 256));
355   
356           if(!empty($buffer)){
358             $name=$value = $buffer;
359             if(preg_match("/:/",$buffer)){
360               $name = preg_replace("/:.*$/","",$buffer);
361               $value= preg_replace("/^.*:/","",$buffer);
362               $this->gotoBootKernels[$name]= $name.":".$value;
363             }else{
364               $this->gotoBootKernels[$name]= $value;
365             }
366             if($this->gotoBootKernel =="" ){
367               $this->gotoBootKernel = $name;
368             }
370           }
371         }
372         pclose($fh);
373       }
374     }
376     /* Turn to default, if we've nothing to inherit */
377     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
378       $this->gotoBootKernel= "default";
379     }
381     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
382       $this->FAIdebianMirror = "inherited";
383     }
384   }
386   
387   /* This class is called by the contrucktor ONLY.
388    *   It return the available classes for each 
389    *    Server / Release combination ... 
390    *   (Release specifies which classes are available) 
391    */
392   function getAvailableClassesForThisRelease($release)
393   {
394     /* There could be more than one server providing this release,
395         so use cached result if available
396      */ 
397     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
398       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
399     }
401     /* Walk through cache and get out what we need.
402      *   
403      *   Function od : "$this->generateDNSyn($release)"
404      *    It returns an array like this one :
405      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
406      *            "ou=scripts.. " 
407      *             ...);
408      *   This helps us to select the correct classes for each release. 
409      *   It prevents errors like:  'siga' is selected as release, but all classes
410      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
411      */
412     $tmp2 = $this->generateDNSyn($release)     ; 
413     $test2 = array();
414     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
415       foreach($tmp2 as $dns){
416         if(preg_match("/".$dns."/",$attr['dn'])){
417           $test2[$attr['cn'][0]] = $attr['cn'][0];
418         }
419       }
420     }
421     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
422     return($test2);
423   }
426   /*  Create array to display available classes/profiles in a selectbox 
427    *   This function only displays the available classes.
428    *   If a class is available is defined by these facts : 
429    *     1. Is this class available for the selected release ?
430    *       - if it is available, check if the release is available for the selected server 
431    *         (done by $this->getFAIreleases())
432    *     2. Is this class currently not assigned to $this->FAIclass
433    */
434   function selectFriendlyClasses(){
435     $tmp=array();
437     if($this->FAIdebianMirror == "inherited") return($tmp);
439     /* check if the current release exists,
440         else select the first one ..
441      */
442     $tmp2 = $this->getFAIreleases();
443     if(!in_array($this->FAIrelease, $tmp2)){  
444       $this->FAIrelease = key($tmp2);
445     }
446  
447     /* Get all Packages for this server/release combination
448      */
449     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
450       $pkgs = array();
451       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
452     }else{
453       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
454     }
456     /* Check each and every single class name 
457      */
458     foreach($pkgs as $pkg){
459   
460       /* Class already assigned to the classes list ?
461        * If not ... go on
462        */
463       if(!in_array($pkg,$this->FAIclass)){
464         
465         /* Create the displayed list entry value
466             HKLMOP [-Pl P V T-] or something like that 
467          */
468         $str = "";
469         foreach($this->FAIclassInfo[$pkg] as $entry){
470           if(isset($entry['kzl'])){
471             $str .= $entry['kzl']." ";
472           }
473         }
474         
475         /* Append class if everyting was fine
476          */        
477         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
478       }
479     }
480     /* Just sort and return new classes list ...
481        ( possibly we should cache the result ... )
482      */
483     natcasesort ($tmp);
484     return($tmp);
485   }
487   function check()
488   {
489     $messages = array();
490     
491     /* Call common method to give check the hook */
492     $messages= plugin::check();
494     /* If there are packages selected, but no mirror show error */   
495     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
496       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
497     }
499     return($messages);
500   }
502   function execute()
503   {
505         /* Call parent execute */
506         plugin::execute();
508     /* Do we need to flip is_account state? */
509     if (isset($_POST['modify_state'])){
510       $this->is_account= !$this->is_account;
511     }
513     /* Do we represent a valid terminal? */
514     if (!$this->is_account && $this->parent == NULL){
515       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
516         _("This 'dn' has no terminal features.")."</b>";
517       return ($display);
518     }
520     /* Add module */
521     if (isset ($_POST['add_module'])){
522       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
523         $this->add_list ($this->gotoModules, $_POST['module']);
524       }
525     }
527     /* Delete module */
528     if (isset ($_POST['delete_module'])){
529       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
530         $this->del_list ($this->gotoModules, $_POST['modules_list']);
531       }
532     }
533     
534     /* FAI class management */
535     if($this->fai_activated){
537       if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
538         $found = 0 ; 
540         /* If this new class/profile will attach a second partition table
541          * to our list of classes, abort and show a message.
542          */
543         foreach($this->FAIclass as $name){
544           if(isset($this->FAIclassInfo[$name])){
545             foreach($this->FAIclassInfo[$name] as $atr){
546               if(isset($atr['obj'])){
547                 if($atr['obj'] == "FAIpartitionTable"){
548                   $found ++ ; 
549                 }
550               }
551             }
552           }
553         }
555         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
556           print_red(_("There is already a profile in your selection that contain partition table configurations."));
557         }else{
558           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
559         }
560       }
562       $sort = false;
563       foreach($_POST as $name => $val){
564         
565         $sort_type = false;
566         if((preg_match("/sort_up/",$name))&&(!$sort)){
567           $sort_type = "sort_up_";
568         }
569         if((preg_match("/sort_down/",$name))&&(!$sort)){
570           $sort_type = "sort_down_";
571         }
572       
573         if(($sort_type)&&(!$sort)){
574           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
575           $sort = true;
576           
577           $last = -1;
578           $change_down  = -1;
579    
580           /* Create array with numeric index */ 
581           $tmp = array();
582           foreach($this->FAIclass as $class){
583             $tmp [] = $class;
584           }
586           /* Walk trough array */
587           foreach($tmp as $key => $faiName){
588             if($faiName == $value){
589               if($sort_type == "sort_up_"){
590                 if($last != -1){
591                    $change_down= $last;
592                 }
593               }else{
594                 if(isset($tmp[$key+1])){
595                   $change_down = $key;
596                 }
597               }
598             }
599             $last = $key;
600           }
601    
602           $tmp2 = array();
603           $skip = false;    
604     
605           foreach($tmp as $ky => $vl){
607             if($ky == $change_down){
608               $skip = $vl;
609             }else{
610               $tmp2[$vl] = $vl;
611             }
612             if(($skip != false)&&($ky != $change_down)){
613               $tmp2[$skip]  = $skip;
614               $skip =false;
615             }
616           }   
617           $this->FAIclass = $tmp2; 
618         }
619     
620         if(preg_match("/fai_remove/i",$name)){
621           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
622           unset($this->FAIclass[$value]);
623         }
624       }
625     }
627     /* Show main page */
628     $smarty= get_smarty();
629     $smarty->assign("SelectBoxLdapServer","");
631     /* In this section server shares will be defined
632      * A user can select one of the given shares and a mount point
633      *  and attach this combination to his setup.
634      */
635     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
636     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
638     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
639      * This entry will be, a combination of mountPoint and sharedefinitions
640      */
641     if(isset($_POST['gotoShareAdd'])){
642       /* We assign a share to this user, if we don't know where to mount the share */
643       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
644         print_red(_("You must specify a valid mount point."));
645       }else{
646         if(count($this->gotoAvailableShares)){
647           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
648           $s_mount = $_POST['gotoShareMountPoint'];
649           /* Preparing the new assignment */
650           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
651           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
652         }
653       }
654     }
656     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
657      * If there is no defined share selected, we will abort the deletion without any message
658      */
659     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
660       unset($this->gotoShares[$_POST['gotoShare']]);
661     }
663     $smarty->assign("gotoShares",$this->printOutAssignedShares());
664     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
665     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
666     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
668     /* Arrays */
669     $tmp = $this->goLdapServerList;
671     /* Create divSelectBox for ldap server selection
672      */
673     $SelectBoxLdapServer = new divSelectBox("LdapServer");
674     $SelectBoxLdapServer->SetHeight(130);
676     /* Set first entry as selected, if $this->gotoLdapServer is empty
677      *  or given entry is no longer available ... 
678      */
679     $found = false;
680     foreach($tmp as $server){
681       if($this->gotoLdapServer==$server){
682         $found = true;
683       }
684     }
686     /* Add Entries 
687      */
688     foreach($tmp as $key => $server){
689       $use ="";
690       if(($this->gotoLdapServer == $server) || ($found == false)) {
691         $found = true;
692         $use = " checked ";
693       };
695       $display = $server;
697       $SelectBoxLdapServer->AddEntry(
698           array(
699             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
700                   "attach"=>"style='border-left:0px;'"),
701             array("string"=>$display)
702             ));
703     }    
705     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
707     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
708     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
709       $smarty->assign("$val", $this->$val);
710     }
712     /* Values */
713     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
714       $smarty->assign($val, $this->$val);
715       $smarty->assign($val."ACL", chkacl($this->acl, $val));
716     }
718     $smarty->assign("fai_activated",$this->fai_activated);
719     if($this->fai_activated){
720       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
721       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
722       $smarty->assign("FAIreleases",$this->getFAIreleases());
723       $smarty->assign("FAIrelease",$this->FAIrelease);
724       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
725       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
726       $smarty->assign("FAIclassKeys",$this->FAIclass);
727       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
728     
729       $div = new divSelectBox("WSFAIscriptClasses");
730       $div -> SetHeight("110");
731       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
732       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
733       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
734       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
736       $i = 1;
738       if($this->FAIdebianMirror == "inherited"){
739         $tmp = $this->InheritedFAIclass;
740       }else{
741         $tmp = $this->FAIclass;
742       }
744       foreach($tmp as $class){
746         $marker = "";
747         if(in_array_ics($class,$this->unresolved_classes)){
748           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
749         }
751         if($this->FAIdebianMirror == "inherited"){
752           $str = "";
753         }else{
754           if($i==1){
755             $str = $str_empty.$str_down.$str_remove;
756           }elseif($i == count($this->FAIclass)){
757             $str = $str_up.$str_empty.$str_remove;
758           }else{
759             $str = $str_up.$str_down.$str_remove;
760           }
761         }
762         $i ++ ; 
764         $div->AddEntry(array(
765               array("string"=>$class.$marker),
766               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
767               ));
768       }  
770       $smarty->assign("FAIScriptlist",$div->DrawList()); 
771     }
773     /* Radio button group */
774     if (preg_match("/G/", $this->bootmode)) {
775       $smarty->assign("graphicalbootup", "checked");
776     } else {
777       $smarty->assign("graphicalbootup", "");
778     }
779     if (preg_match("/T/", $this->bootmode)) {
780       $smarty->assign("textbootup", "checked");
781     } else {
782       $smarty->assign("textbootup", "");
783     }
784     if (preg_match("/D/", $this->bootmode)) {
785       $smarty->assign("debugbootup", "checked");
786     } else {
787       $smarty->assign("debugbootup", "");
788     }
790     /* ACL's */
791     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
792       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
793     }
795     /* Show main page */
796     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
797   }
799   function remove_from_parent()
800   {
801     $this->handle_post_events("remove");
802   }
804   function generateDNSyn($release)
805   {
806     $str = "";
807     $tmp = split("\/",$release);
808     $tmp = array_reverse($tmp);
810     $base = ",ou=fai,";   
811  
812     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
814     foreach($tmp as $departmentname){
815       
816       $str .= ",ou=".$departmentname;
817     }
818     $ret = array();
819     foreach($arr as $ar){
820       $ret[] = ",ou=".$ar.$str.$base;
821     }
822     return($ret);
823   }
825   function getFAIdebianMirrors()
826   {
827     $ret = array();
828     $ret['inherited']="["._("inherited")."]";
829     $ret['auto']=_("automatic");
830     $secs  = array();
832     /* Walk through all available servers 
833         and check if they support the currently selected classes
834         if not, dont't add them to our list
835      */
836     foreach($this->FAIServRepConfig as $mirror => $rest){
838       $use = false;
840       if(count($this->FAIclass) == 0){
841         $use = true;
842       }else{
843         $tmp = $this->getFAIreleases();
844         foreach($tmp as $release){
845           if(isset($rest['RELEASE'][$release])){
846             $use =true;
847           }
848         } 
849       }
851       /* If current server, doesn't support this class
852           remove it from list
853        */
854       if($use){
855         $ret[$mirror] = $mirror;
856       }
857     }
858     return($ret);
859   }
861   function getFAIreleases() 
862   {
863     $ret = array();
865     if($this->FAIdebianMirror == "inherited") return(array());
867     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
868       $this->FAIdebianMirror = "auto";
869     }
871     $errorClasses = array();  
872     if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
873       foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
874         $use = true;
876         if(!count($this->FAIclass) == 0){
877           foreach($this->FAIclass as $class){
878             if(!in_array($class, $sections['PACKAGES'])){
879               $use = false;
880               $errorClasses[$class] = $class;
881             }else{
882               if(isset($errorClasses[$class])){
883                 unset($errorClasses[$class]); 
884               }
885             }
886           }
887         }
888         if($use){
889           $ret[$release]=$release;
890         }
891       }
892     } 
893     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
895       $eClasses = " ";
896       foreach($errorClasses as $class){
897         $eClasses .= $class." ";
898       }
900       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));
901       $this->FAIdebianMirror = "auto";
902       return($this->getFAIreleases());
903     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
905       $eClasses = " ";
906       foreach($errorClasses as $class){
907         $eClasses .= $class." ";
908       }
909       
910       $this->unresolved_classes = $errorClasses;
911       $this->FAIdebianMirror = "auto";
912       //$this->FAIclass= array();
913       print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. Server was reset to 'auto'."),$eClasses));
914     }
915     return($ret);
916   }
918   /* Save data to object */
919   function save_object()
920   {
921     plugin::save_object();
923     /* Save group radio buttons */
924     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
925       $this->bootmode= $_POST["bootmode"];
926     }
928     /* Save kernel parameters */
929     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
930       $this->customParameters= $_POST["customParameters"];
931     }
933   }
936   /* Save to LDAP */
937   function save()
938   {
940     /* Depending on the baseobject (Ogroup / WS) we
941      *  use another set of objectClasses
942      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
943      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
944      */
945     if(isset($this->parent->by_object['ogroup'])){
946       $this->objectclasses = array("gotoWorkstationTemplate");
947     }elseif(isset($this->parent->by_object['workgeneric'])){
948       $this->objectclasses = array("GOhard");
949     }elseif(isset($this->parent->by_object['servgeneric'])){
950       $this->objectclasses = array("GOhard");
951     }else{
952       print "Object Type Configuration : unknown";
953       exit();
954     }
956     if($this->fai_activated){
957       $this->objectclasses [] = "FAIobject";
958     }
960     /* Find proper terminal path for tftp configuration
961        FIXME: This is suboptimal when the default has changed to
962        another location! */
963     if (($this->gotoTerminalPath == "default")){
964       $ldap= $this->config->get_ldap_link();
966       /* Strip relevant part from dn, keep trailing ',' */
967       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
968       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
970       /* Walk from top to base and try to load default values for
971          'gotoTerminalPath'. Abort when an entry is found. */
972       while (TRUE){
973         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
975         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
976             $this->config->current['BASE'], array('gotoTerminalPath'));
977         $attrs= $ldap->fetch();
978         if (isset($attrs['gotoTerminalPath'])){
979           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
980           break;
981         }
983         /* Nothing left? */
984         if ($tmp == ""){
985           break;
986         }
987       }
988     }
990     /* Add semi automatic values */
991     // FIXME: LDAP Server may not be set here...
992     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
994     switch ($this->bootmode){
995       case "D":
996         $this->gotoKernelParameters.= " debug";
997       break;
998       case "G":
999         $this->gotoKernelParameters.= " splash=silent";
1000       break;
1001     }
1002     if ($this->customParameters != ""){
1003       $this->gotoKernelParameters.= " o ".$this->customParameters;
1004     }
1006     plugin::save();
1009     if($this->fai_activated){
1011       unset( $this->attrs['FAIrelease'] );
1012       
1013       $str = "";
1015       if($this->FAIdebianMirror == "inherited"){
1016     
1017         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1019       }else{
1021         foreach($this->FAIclass as $class){
1022           $str .= $class." ";
1023         }
1024         $str .= ":" . $this->FAIrelease;
1025         $this->attrs['FAIclass']= "";
1026         $this->attrs['FAIclass']= trim($str);
1028         if(empty($this->attrs['FAIclass'])){
1029           $this->attrs['FAIclass'] = array();
1030         }
1031       }
1033       /* if mirror == none stop saving this attribute */
1034       if($this->FAIdebianMirror == "none"){
1035         $this->FAIdebianMirror = "";
1036       }
1037     }
1039     /* Add missing arrays */
1040     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1041       if (isset ($this->$val) && count ($this->$val) != 0){
1042     
1043         $this->attrs["$val"]= array_unique($this->$val);
1044       }
1045       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1046     }
1048     /* Strip out 'default' values */
1049     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1050       $this->attrs['gotoLdapServer']= array();
1051     }
1053     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1054       $this->attrs['gotoBootKernel']= array();
1055     }
1057     $ldap= $this->config->get_ldap_link();
1058     $ldap->cd($this->dn);
1060     /* Get FAIstate from object, the generic tab could have changed it during execute */
1061     if($this->fai_activated){
1062       $ldap->cat($this->dn,array("FAIstate"));
1063       $checkFAIstate = $ldap->fetch();
1065       /* Remove FAI objects if no FAI class is selected */ 
1066       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1067         $this->attrs['FAIclass']        = array();
1068         $this->attrs['FAIdebianMirror'] = array();
1069       }
1070     }
1072     /* prepare share settings */
1073     $tmp = array();
1074     foreach($this->gotoShares as $name => $settings){
1075       $tmp2= split("\|",$name);
1076       $name = $tmp2[0];
1077       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1078     }
1079     $this->attrs['gotoShare']=$tmp;
1081     $this->cleanup();
1082     $ldap->modify ($this->attrs); 
1084     show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1085     $this->handle_post_events("modify");
1086   }
1088   /* Add value to array, check if unique */
1089   function add_list (&$array, $value)
1090   {
1091     if ($value != ""){
1092       $array[]= $value;
1093       sort($array);
1094       array_unique ($array);
1095     }
1096   }
1099   /* Delete value to array, check if unique */
1100   function del_list (&$array, $list)
1101   {
1102     $tmp= array();
1103     foreach ($array as $mod){
1104       if (!in_array($mod, $list)){
1105         $tmp[]= $mod;
1106       }
1107     }
1108     $array= $tmp;
1109   }
1111   /* Generate ListBox frindly output for the defined shares
1112    * Possibly Add or remove an attribute here,
1113    */
1114   function printOutAssignedShares()
1115   {
1116     $a_return = array();
1117     if(is_array($this->gotoShares)){
1118       foreach($this->gotoShares as $share){
1119         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1120       }
1121     }
1122     return($a_return);
1123   }
1126   function GetHookElements()
1127   {
1128     $ret = array();
1129     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1130     if(!empty($cmd)){
1131       $res = shell_exec($cmd);
1132       $res2 = trim($res);
1133       if((!$res)){
1134         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1135       }elseif(empty($res2)){
1136         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1137       }else{
1138         $tmp = split("\n",$res);
1139         foreach($tmp as $line){
1140           if(empty($line)) continue;
1141           $ret[]= $line;
1142         }
1143       }
1144     }
1145     return($ret);
1146   }
1150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1151 ?>