Code

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