Code

Fixed deletion of the last module in list
[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       $this->saved_attributes[$val]= $this->$val;
237     }
239     /* Parse Kernel Parameters to decide what boot mode is enabled */
240     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
241       $this->bootmode= "G";
242     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
243       $this->bootmode= "D";
244     } elseif ($this->gotoKernelParameters == "") {
245       $this->bootmode= "G";
246     } else {
247       $this->bootmode= "T";
248     }
249     if (preg_match("/ o /", $this->gotoKernelParameters)){
250       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
251     } else {
252       $this->customParameters= "";
253     }
255     /* Prepare Shares */
256     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
257       unset($this->attrs['gotoShare']['count']);
258       foreach($this->attrs['gotoShare'] as $share){
259         $tmp = $tmp2 = array();
260         $tmp = split("\|",$share);
261         $tmp2['server']      =$tmp[0];
262         $tmp2['name']        =$tmp[1];
263         $tmp2['mountPoint']  =$tmp[2];
264         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
265       }
266     }
268     $this->gotoShareSelections= $config->getShareList(true);
269     $this->gotoAvailableShares= $config->getShareList(false);
270     $tmp2 = array();
273     /* Again some special FAI stuff */
274     if($this->fai_activated){ 
275       if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
276         $tmp = array();
277         $tmp = split(" ",$this->FAIclass);
278         $tmp2 =array();  
280         foreach($tmp as $class){
281           if( ":" == $class[0] ) {
282             $this->FAIrelease = substr( $class, 1 );
283           }
284           else
285             $tmp2[$class] = $class;
286         }
287         $this->FAIclass = $tmp2;
288       }
290       if(!is_array($this->FAIclass)){
291         $this->FAIclass =array();
292       }
293     }
295     $this->orig_dn= $this->dn;
297     /* Handle inheritance value "default" */
298     $this->gotoBootKernels= array();
301     /* Load hardware list */
302     $ldap= $this->config->get_ldap_link();
303     $ldap->cd($this->config->current['BASE']);
304     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
305     if ($ldap->count() == 1){
308       if($this->fai_activated){
309         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
310       }else{
311         $map= array("gotoLdapServer","gotoBootKernel");
312       }
314       $attrs= $ldap->fetch();
316       foreach ($map as $name){
317         if (!isset($attrs[$name][0])){
318           continue;
319         }
321         switch ($name){
322           case 'gotoLdapServer':
323             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
324             break;
326           case 'gotoBootKernel':
327             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
328             break;
330           case 'FAIclass':
331             $str = split(":",$attrs[$name][0]);
332             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
333             $this->InheritedFAIrelease  = trim($str[1]);
334             break;
336           case 'FAIdebianMirror':
337             $this->InheritedFAIdebianMirror = $attrs[$name][0];
338             break;
339         }
340       }
341     }
343     /* Get list of boot kernels */
344     if (isset($this->config->data['TABS'])){
345       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
347       if (!check_command($command)){
348         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
349             get_class($this));
350       } else {
351         
352         $first = false; 
353         $fh= popen($command, "r");
354         while (!feof($fh)) {
355           $buffer= trim(fgets($fh, 256));
356   
357           if(!empty($buffer)){
359             $name=$value = $buffer;
360             if(preg_match("/:/",$buffer)){
361               $name = preg_replace("/:.*$/","",$buffer);
362               $value= preg_replace("/^.*:/","",$buffer);
363               $this->gotoBootKernels[$name]= $name.":".$value;
364             }else{
365               $this->gotoBootKernels[$name]= $value;
366             }
367             if($this->gotoBootKernel =="" ){
368               $this->gotoBootKernel = $name;
369             }
371           }
372         }
373         pclose($fh);
374       }
375     }
377     /* Turn to default, if we've nothing to inherit */
378     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
379       $this->gotoBootKernel= "default";
380     }
382     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
383       $this->FAIdebianMirror = "inherited";
384     }
385   }
387   
388   /* This class is called by the contrucktor ONLY.
389    *   It return the available classes for each 
390    *    Server / Release combination ... 
391    *   (Release specifies which classes are available) 
392    */
393   function getAvailableClassesForThisRelease($release)
394   {
395     /* There could be more than one server providing this release,
396         so use cached result if available
397      */ 
398     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
399       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
400     }
402     /* Walk through cache and get out what we need.
403      *   
404      *   Function od : "$this->generateDNSyn($release)"
405      *    It returns an array like this one :
406      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
407      *            "ou=scripts.. " 
408      *             ...);
409      *   This helps us to select the correct classes for each release. 
410      *   It prevents errors like:  'siga' is selected as release, but all classes
411      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
412      */
413     $tmp2 = $this->generateDNSyn($release)     ; 
414     $test2 = array();
415     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
416       foreach($tmp2 as $dns){
417         if(preg_match("/".$dns."/",$attr['dn'])){
418           $test2[$attr['cn'][0]] = $attr['cn'][0];
419         }
420       }
421     }
422     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
423     return($test2);
424   }
427   /*  Create array to display available classes/profiles in a selectbox 
428    *   This function only displays the available classes.
429    *   If a class is available is defined by these facts : 
430    *     1. Is this class available for the selected release ?
431    *       - if it is available, check if the release is available for the selected server 
432    *         (done by $this->getFAIreleases())
433    *     2. Is this class currently not assigned to $this->FAIclass
434    */
435   function selectFriendlyClasses(){
436     $tmp=array();
438     if($this->FAIdebianMirror == "inherited") return($tmp);
440     /* check if the current release exists,
441         else select the first one ..
442      */
443     $tmp2 = $this->getFAIreleases();
444     if(!in_array($this->FAIrelease, $tmp2)){  
445       $this->FAIrelease = key($tmp2);
446     }
447  
448     /* Get all Packages for this server/release combination
449      */
450     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
451       $pkgs = array();
452       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
453     }else{
454       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
455     }
457     /* Check each and every single class name 
458      */
459     foreach($pkgs as $pkg){
460   
461       /* Class already assigned to the classes list ?
462        * If not ... go on
463        */
464       if(!in_array($pkg,$this->FAIclass)){
465         
466         /* Create the displayed list entry value
467             HKLMOP [-Pl P V T-] or something like that 
468          */
469         $str = "";
470         foreach($this->FAIclassInfo[$pkg] as $entry){
471           if(isset($entry['kzl'])){
472             $str .= $entry['kzl']." ";
473           }
474         }
475         
476         /* Append class if everyting was fine
477          */        
478         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
479       }
480     }
481     /* Just sort and return new classes list ...
482        ( possibly we should cache the result ... )
483      */
484     natcasesort ($tmp);
485     return($tmp);
486   }
488   function check()
489   {
490     $messages = array();
491     
492     /* Call common method to give check the hook */
493     $messages= plugin::check();
495     /* If there are packages selected, but no mirror show error */   
496     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
497       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
498     }
500     return($messages);
501   }
503   function execute()
504   {
506         /* Call parent execute */
507         plugin::execute();
509     /* Do we need to flip is_account state? */
510     if (isset($_POST['modify_state'])){
511       $this->is_account= !$this->is_account;
512     }
514     /* Do we represent a valid terminal? */
515     if (!$this->is_account && $this->parent == NULL){
516       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
517         _("This 'dn' has no terminal features.")."</b>";
518       return ($display);
519     }
521     /* Add module */
522     if (isset ($_POST['add_module'])){
523       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
524         $this->add_list ($this->gotoModules, $_POST['module']);
525       }
526     }
528     /* Delete module */
529     if (isset ($_POST['delete_module'])){
530       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
531         $this->del_list ($this->gotoModules, $_POST['modules_list']);
532       }
533     }
534     
535     /* FAI class management */
536     if($this->fai_activated){
538       if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
539         $found = 0 ; 
541         /* If this new class/profile will attach a second partition table
542          * to our list of classes, abort and show a message.
543          */
544         foreach($this->FAIclass as $name){
545           if(isset($this->FAIclassInfo[$name])){
546             foreach($this->FAIclassInfo[$name] as $atr){
547               if(isset($atr['obj'])){
548                 if($atr['obj'] == "FAIpartitionTable"){
549                   $found ++ ; 
550                 }
551               }
552             }
553           }
554         }
556         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
557           print_red(_("There is already a profile in your selection that contain partition table configurations."));
558         }else{
559           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
560         }
561       }
563       $sort = false;
564       foreach($_POST as $name => $val){
565         
566         $sort_type = false;
567         if((preg_match("/sort_up/",$name))&&(!$sort)){
568           $sort_type = "sort_up_";
569         }
570         if((preg_match("/sort_down/",$name))&&(!$sort)){
571           $sort_type = "sort_down_";
572         }
573       
574         if(($sort_type)&&(!$sort)){
575           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
576           $sort = true;
577           
578           $last = -1;
579           $change_down  = -1;
580    
581           /* Create array with numeric index */ 
582           $tmp = array();
583           foreach($this->FAIclass as $class){
584             $tmp [] = $class;
585           }
587           /* Walk trough array */
588           foreach($tmp as $key => $faiName){
589             if($faiName == $value){
590               if($sort_type == "sort_up_"){
591                 if($last != -1){
592                    $change_down= $last;
593                 }
594               }else{
595                 if(isset($tmp[$key+1])){
596                   $change_down = $key;
597                 }
598               }
599             }
600             $last = $key;
601           }
602    
603           $tmp2 = array();
604           $skip = false;    
605     
606           foreach($tmp as $ky => $vl){
608             if($ky == $change_down){
609               $skip = $vl;
610             }else{
611               $tmp2[$vl] = $vl;
612             }
613             if(($skip != false)&&($ky != $change_down)){
614               $tmp2[$skip]  = $skip;
615               $skip =false;
616             }
617           }   
618           $this->FAIclass = $tmp2; 
619         }
620     
621         if(preg_match("/fai_remove/i",$name)){
622           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
623           unset($this->FAIclass[$value]);
624         }
625       }
626     }
628     /* Show main page */
629     $smarty= get_smarty();
630     $smarty->assign("SelectBoxLdapServer","");
632     /* In this section server shares will be defined
633      * A user can select one of the given shares and a mount point
634      *  and attach this combination to his setup.
635      */
636     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
637     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
639     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
640      * This entry will be, a combination of mountPoint and sharedefinitions
641      */
642     if(isset($_POST['gotoShareAdd'])){
643       /* We assign a share to this user, if we don't know where to mount the share */
644       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
645         print_red(_("You must specify a valid mount point."));
646       }else{
647         if(count($this->gotoAvailableShares)){
648           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
649           $s_mount = $_POST['gotoShareMountPoint'];
650           /* Preparing the new assignment */
651           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
652           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
653         }
654       }
655     }
657     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
658      * If there is no defined share selected, we will abort the deletion without any message
659      */
660     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
661       unset($this->gotoShares[$_POST['gotoShare']]);
662     }
664     $smarty->assign("gotoShares",$this->printOutAssignedShares());
665     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
666     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
667     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
669     /* Arrays */
670     $tmp = $this->goLdapServerList;
672     /* Create divSelectBox for ldap server selection
673      */
674     $SelectBoxLdapServer = new divSelectBox("LdapServer");
675     $SelectBoxLdapServer->SetHeight(130);
677     /* Set first entry as selected, if $this->gotoLdapServer is empty
678      *  or given entry is no longer available ... 
679      */
680     $found = false;
681     foreach($tmp as $server){
682       if($this->gotoLdapServer==$server){
683         $found = true;
684       }
685     }
687     /* Add Entries 
688      */
689     foreach($tmp as $key => $server){
690       $use ="";
691       if(($this->gotoLdapServer == $server) || ($found == false)) {
692         $found = true;
693         $use = " checked ";
694       };
696       $display = $server;
698       $SelectBoxLdapServer->AddEntry(
699           array(
700             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
701                   "attach"=>"style='border-left:0px;'"),
702             array("string"=>$display)
703             ));
704     }    
706     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
708     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
709     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
710       $smarty->assign("$val", $this->$val);
711     }
713     /* Values */
714     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
715       $smarty->assign($val, $this->$val);
716       $smarty->assign($val."ACL", chkacl($this->acl, $val));
717     }
719     $smarty->assign("fai_activated",$this->fai_activated);
720     if($this->fai_activated){
721       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
722       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
723       $smarty->assign("FAIreleases",$this->getFAIreleases());
724       $smarty->assign("FAIrelease",$this->FAIrelease);
725       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
726       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
727       $smarty->assign("FAIclassKeys",$this->FAIclass);
728       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
729     
730       $div = new divSelectBox("WSFAIscriptClasses");
731       $div -> SetHeight("110");
732       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
733       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
734       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
735       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
737       $i = 1;
739       if($this->FAIdebianMirror == "inherited"){
740         $tmp = $this->InheritedFAIclass;
741       }else{
742         $tmp = $this->FAIclass;
743       }
745       foreach($tmp as $class){
747         $marker = "";
748         if(in_array_ics($class,$this->unresolved_classes)){
749           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
750         }
752         if($this->FAIdebianMirror == "inherited"){
753           $str = "";
754         }else{
755           if($i==1){
756             $str = $str_empty.$str_down.$str_remove;
757           }elseif($i == count($this->FAIclass)){
758             $str = $str_up.$str_empty.$str_remove;
759           }else{
760             $str = $str_up.$str_down.$str_remove;
761           }
762         }
763         $i ++ ; 
765         $div->AddEntry(array(
766               array("string"=>$class.$marker),
767               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
768               ));
769       }  
771       $smarty->assign("FAIScriptlist",$div->DrawList()); 
772     }
774     /* Radio button group */
775     if (preg_match("/G/", $this->bootmode)) {
776       $smarty->assign("graphicalbootup", "checked");
777     } else {
778       $smarty->assign("graphicalbootup", "");
779     }
780     if (preg_match("/T/", $this->bootmode)) {
781       $smarty->assign("textbootup", "checked");
782     } else {
783       $smarty->assign("textbootup", "");
784     }
785     if (preg_match("/D/", $this->bootmode)) {
786       $smarty->assign("debugbootup", "checked");
787     } else {
788       $smarty->assign("debugbootup", "");
789     }
791     /* ACL's */
792     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
793       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
794     }
796     /* Show main page */
797     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
798   }
800   function remove_from_parent()
801   {
802     $this->handle_post_events("remove");
803   }
805   function generateDNSyn($release)
806   {
807     $str = "";
808     $tmp = split("\/",$release);
809     $tmp = array_reverse($tmp);
811     $base = ",ou=fai,";   
812  
813     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
815     foreach($tmp as $departmentname){
816       
817       $str .= ",ou=".$departmentname;
818     }
819     $ret = array();
820     foreach($arr as $ar){
821       $ret[] = ",ou=".$ar.$str.$base;
822     }
823     return($ret);
824   }
826   function getFAIdebianMirrors()
827   {
828     $ret = array();
829     $ret['inherited']="["._("inherited")."]";
830     $ret['auto']=_("automatic");
831     $secs  = array();
833     /* Walk through all available servers 
834         and check if they support the currently selected classes
835         if not, dont't add them to our list
836      */
837     foreach($this->FAIServRepConfig as $mirror => $rest){
839       $use = false;
841       if(count($this->FAIclass) == 0){
842         $use = true;
843       }else{
844         $tmp = $this->getFAIreleases();
845         foreach($tmp as $release){
846           if(isset($rest['RELEASE'][$release])){
847             $use =true;
848           }
849         } 
850       }
852       /* If current server, doesn't support this class
853           remove it from list
854        */
855       if($use){
856         $ret[$mirror] = $mirror;
857       }
858     }
859     return($ret);
860   }
862   function getFAIreleases() 
863   {
864     $ret = array();
866     if($this->FAIdebianMirror == "inherited") return(array());
868     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
869       $this->FAIdebianMirror = "auto";
870     }
872     $errorClasses = array();  
873     if(isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])) {
874       foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
875         $use = true;
877         if(!count($this->FAIclass) == 0){
878           foreach($this->FAIclass as $class){
879             if(!in_array($class, $sections['PACKAGES'])){
880               $use = false;
881               $errorClasses[$class] = $class;
882             }else{
883               if(isset($errorClasses[$class])){
884                 unset($errorClasses[$class]); 
885               }
886             }
887           }
888         }
889         if($use){
890           $ret[$release]=$release;
891         }
892       }
893     } 
894     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
896       $eClasses = " ";
897       foreach($errorClasses as $class){
898         $eClasses .= $class." ";
899       }
901       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));
902       $this->FAIdebianMirror = "auto";
903       return($this->getFAIreleases());
904     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
906       $eClasses = " ";
907       foreach($errorClasses as $class){
908         $eClasses .= $class." ";
909       }
910       
911       $this->unresolved_classes = $errorClasses;
912       $this->FAIdebianMirror = "auto";
913       //$this->FAIclass= array();
914       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));
915     }
916     return($ret);
917   }
919   /* Save data to object */
920   function save_object()
921   {
922     plugin::save_object();
924     /* Save group radio buttons */
925     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
926       $this->bootmode= $_POST["bootmode"];
927     }
929     /* Save kernel parameters */
930     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
931       $this->customParameters= $_POST["customParameters"];
932     }
934   }
937   /* Save to LDAP */
938   function save()
939   {
941     /* Depending on the baseobject (Ogroup / WS) we
942      *  use another set of objectClasses
943      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
944      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
945      */
946     if(isset($this->parent->by_object['ogroup'])){
947       $this->objectclasses = array("gotoWorkstationTemplate");
948     }elseif(isset($this->parent->by_object['workgeneric'])){
949       $this->objectclasses = array("GOhard");
950     }elseif(isset($this->parent->by_object['servgeneric'])){
951       $this->objectclasses = array("GOhard");
952     }else{
953       print "Object Type Configuration : unknown";
954       exit();
955     }
957     if($this->fai_activated){
958       $this->objectclasses [] = "FAIobject";
959     }
961     /* Find proper terminal path for tftp configuration
962        FIXME: This is suboptimal when the default has changed to
963        another location! */
964     if (($this->gotoTerminalPath == "default")){
965       $ldap= $this->config->get_ldap_link();
967       /* Strip relevant part from dn, keep trailing ',' */
968       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
969       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
971       /* Walk from top to base and try to load default values for
972          'gotoTerminalPath'. Abort when an entry is found. */
973       while (TRUE){
974         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
976         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
977             $this->config->current['BASE'], array('gotoTerminalPath'));
978         $attrs= $ldap->fetch();
979         if (isset($attrs['gotoTerminalPath'])){
980           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
981           break;
982         }
984         /* Nothing left? */
985         if ($tmp == ""){
986           break;
987         }
988       }
989     }
991     /* Add semi automatic values */
992     // FIXME: LDAP Server may not be set here...
993     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
995     switch ($this->bootmode){
996       case "D":
997         $this->gotoKernelParameters.= " debug";
998       break;
999       case "G":
1000         $this->gotoKernelParameters.= " splash=silent";
1001       break;
1002     }
1003     if ($this->customParameters != ""){
1004       $this->gotoKernelParameters.= " o ".$this->customParameters;
1005     }
1007     plugin::save();
1010     if($this->fai_activated){
1012       unset( $this->attrs['FAIrelease'] );
1013       
1014       $str = "";
1016       if($this->FAIdebianMirror == "inherited"){
1017     
1018         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1020       }else{
1022         foreach($this->FAIclass as $class){
1023           $str .= $class." ";
1024         }
1025         $str .= ":" . $this->FAIrelease;
1026         $this->attrs['FAIclass']= "";
1027         $this->attrs['FAIclass']= trim($str);
1029         if(empty($this->attrs['FAIclass'])){
1030           $this->attrs['FAIclass'] = array();
1031         }
1032       }
1034       /* if mirror == none stop saving this attribute */
1035       if($this->FAIdebianMirror == "none"){
1036         $this->FAIdebianMirror = "";
1037       }
1038     }
1040     /* Add missing arrays */
1041     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1042       if (isset ($this->$val) && count ($this->$val) != 0){
1043     
1044         $this->attrs["$val"]= array_unique($this->$val);
1045       }
1046       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1047     }
1049     /* Strip out 'default' values */
1050     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1051       $this->attrs['gotoLdapServer']= array();
1052     }
1054     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1055       $this->attrs['gotoBootKernel']= array();
1056     }
1058     $ldap= $this->config->get_ldap_link();
1059     $ldap->cd($this->dn);
1061     /* Get FAIstate from object, the generic tab could have changed it during execute */
1062     if($this->fai_activated){
1063       $ldap->cat($this->dn,array("FAIstate"));
1064       $checkFAIstate = $ldap->fetch();
1066       /* Remove FAI objects if no FAI class is selected */ 
1067       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1068         $this->attrs['FAIclass']        = array();
1069         $this->attrs['FAIdebianMirror'] = array();
1070       }
1071     }
1073     /* prepare share settings */
1074     $tmp = array();
1075     foreach($this->gotoShares as $name => $settings){
1076       $tmp2= split("\|",$name);
1077       $name = $tmp2[0];
1078       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1079     }
1080     $this->attrs['gotoShare']=$tmp;
1082     $this->cleanup();
1083     $ldap->modify ($this->attrs); 
1085     show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1086     $this->handle_post_events("modify");
1087   }
1089   /* Add value to array, check if unique */
1090   function add_list (&$array, $value)
1091   {
1092     if ($value != ""){
1093       $array[]= $value;
1094       sort($array);
1095       array_unique ($array);
1096     }
1097   }
1100   /* Delete value to array, check if unique */
1101   function del_list (&$array, $list)
1102   {
1103     $tmp= array();
1104     foreach ($array as $mod){
1105       if (!in_array($mod, $list)){
1106         $tmp[]= $mod;
1107       }
1108     }
1109     $array= $tmp;
1110   }
1112   /* Generate ListBox frindly output for the defined shares
1113    * Possibly Add or remove an attribute here,
1114    */
1115   function printOutAssignedShares()
1116   {
1117     $a_return = array();
1118     if(is_array($this->gotoShares)){
1119       foreach($this->gotoShares as $share){
1120         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1121       }
1122     }
1123     return($a_return);
1124   }
1127   function GetHookElements()
1128   {
1129     $ret = array();
1130     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1131     if(!empty($cmd)){
1132       $res = shell_exec($cmd);
1133       $res2 = trim($res);
1134       if((!$res)){
1135         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1136       }elseif(empty($res2)){
1137         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1138       }else{
1139         $tmp = split("\n",$res);
1140         foreach($tmp as $line){
1141           if(empty($line)) continue;
1142           $ret[]= $line;
1143         }
1144       }
1145     }
1146     return($ret);
1147   }
1151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1152 ?>