Code

567fd2f15551ed5b4aaec9467632c95a519c7332
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* CLI vars */
5   var $cli_summary= "Manage terminal startup options";
6   var $cli_description= "Some longer text\nfor help";
7   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* Generic terminal attributes */
10   var $bootmode             = "G";
11   var $goLdapServerList     = array();
12   var $gotoBootKernel       = "default-inherited";
13   var $gotoKernelParameters = "";
14   var $gotoLdapServer       = "default-inherited";
15   var $gotoModules          = array();
16   var $gotoAutoFs           = array();
17   var $gotoFilesystem       = array();
18   var $gotoTerminalPath     = "";
19   var $FAIstatus            = "";
20   var $gotoBootKernels      = array();
22   /* attribute list for save action */
23   var $attributes     = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
24   var $objectclasses  = array("GOhard", "FAIobject");
26   /* Share */
27   var $gotoShares         = array();// Currently Share Option
28   var $gotoShare          = "";     // currently selected Share Option
29   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
30   var $gotoAvailableShares= array();// Available Shares for this account
32   /* Helper */
33   var $customParameters   = "";
34   var $orig_dn            = "";
35   var $ignore_account     = TRUE;
36  
37   /* FAI class selection */ 
38   var $FAIclass           = array();
39   var $FAIclasses         = array();
40   var $FAIclassInfo       = array();
41   var $FAIrelease         = "";
42   var $FAIdebianMirror    = "auto";
44   var $unresolved_classes = array();
45   var $view_logged        = FALSE;
46   
47   /* FAI class selection */
48   var $InheritedFAIclass           = array();
49   var $InheritedFAIrelease         = "";
50   var $InheritedFAIdebianMirror    = "auto";
52   /* Contains all possible server/release/class settings */
53   var $FAIServRepConfig   = array();
55   var $CopyPasteVars = array("gotoModules","gotoShares");
57   var $fai_activated = FALSE;
59   function workstartup ($config, $dn= NULL, $parent= NULL)
60   {
61     /* Check if FAI is active */
62     $tmp = search_config($config->data,"faiManagement","CLASS");
63     if(!empty($tmp)){
64       $this->fai_activated = TRUE;
65     }else{
66       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
67       $this->objectclasses  = array("GOhard");
68     }
70     plugin::plugin ($config, $dn, $parent);
72     /* Creating a list of valid Mirrors 
73      * none will not be saved to ldap.
74      */
75     $ldap   = $this->config->get_ldap_link();
76     $ldap->cd($this->config->current['BASE']);
78     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
79       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
80     }
81   
83     /* FAI Initialization
84        Skip this if FAI is not activated 
85      */
86       if($this->fai_activated) {
88       $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
89       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
91       /* Search all FAI objects */
92       $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
93       /* Sort all entries, and attach elementtype.
94        * To be able to show the types in the listbox.
95        */
96       while($attr = $ldap->fetch()){
97         $cn = $attr['cn'][0];
98       
99         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
100    
101         if(in_array('FAIpackageList',$attr['objectClass'])){
102           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
103           $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
104           $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
105           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
106         }
107         if(in_array('FAItemplate',$attr['objectClass'])){
108           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
109           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
110           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
111         }
112         if(in_array('FAIvariable',$attr['objectClass'])){
113           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
114           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
115           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
116         }
117         if(in_array('FAIscript',$attr['objectClass'])){
118           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
119           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
120           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
121         }
122         if(in_array('FAIhook',$attr['objectClass'])){
123           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
124           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
125           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126         }
127         if(in_array('FAIpartitionTable',$attr['objectClass'])){
128           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
129           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
130           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
131         }
132         if(in_array('FAIprofile',$attr['objectClass'])){
133           $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
134           $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
135           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
136         }
137       }
138       if(is_array($this->FAIclasses)){
139         natcasesort($this->FAIclasses);
140       }
142       if(isset($tmp2)){
143         $this->FAIclassInfo = $tmp2;
144       } else {
145         $this->FAIclassInfo = array();
146       }
148       /* Build up an array like this one :
149           [$url]['SERVER'] = 'srv1-002';
150           [$url]['RELEASE']['siga/rc9.0.2']
151                                              ['SECTIONS'][0] "main";
152                                              ['SECTIONS'][1] "non-free";
153           [$url]['RELEASE']['siga/rc9.0.2']
154                                              ['PACKAGES'][0] "pkg1";
155                                              ['PACKAGES'][1] "postfix";
156        */
158       $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
159       $test = array();
160       while($attr = $ldap->fetch()){
161         if(isset($attr['FAIrepository'])){
163           unset($attr['FAIrepository']['count']);
165           foreach($attr['FAIrepository'] as $rep){
166             $tmp = split("\|",$rep);
168             if(count($tmp)==4){
169               $sections = split(",",$tmp[3]);
170               $release  = $tmp[2];
171               $server   = $tmp[1];
172               $url      = $tmp[0];
173              
174               $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
175       
176               /* Result will be cached
177                */
178               $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
179               $test[$url]['SERVER'] = $server;
181               /* auto gets all releases/classes 
182                */
183               $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
184               $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
185             }
186           }
187         }
188       }
189       
190       /* Add possible elements from hook */
191       $lines= $this->GetHookElements();
192       foreach ($lines as $hline){
193         $entries= split(";", $hline);
194         if (isset($entries[1]) && !isset($test[$entries[1]])){
195           $test[$entries[1]]['RELEASE']= array();
197           /* Split releases */
198           if (isset($entries[2])){
199             $releases= split(",", $entries[2]);
201             foreach ($releases as $release){
202               $rname= preg_replace('/:.*$/', '', $release);
203               $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
204               $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
205               $test[$entries[1]]['RELEASE'][$rname]= array();
206               $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
207               foreach ($classes as $class){
208                 if ($class != ""){
209                   $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
210                 }
211               }
212             }
213           }
214         }
215       }
216       
217       $this->FAIServRepConfig= $test;
219       if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
220         $tmp = array();
221         $tmp = split(" ",$this->FAIclass);
222         $tmp2 =array();  
224         foreach($tmp as $class){
225           if( ":" == $class[0] ) {
226             $this->FAIrelease = substr( $class, 1 );
227           }
228           else
229             $tmp2[$class] = $class;
230         }
231         $this->FAIclass = $tmp2;
232       }
234       if(!is_array($this->FAIclass)){
235         $this->FAIclass =array();
236       }
237     }// END of FAI initialization stuff 
240     /* Get arrays */
241     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
242       if (isset($this->attrs["$val"]["count"])){
243         for ($i= 0; $i<$this->attrs["count"]; $i++){
244           if (isset($this->attrs["$val"][$i])){
245             array_push($this->$val, $this->attrs["$val"][$i]);
246           }
247         }
248       }
249       sort ($this->$val);
250       $this->$val= array_unique($this->$val);
251     }
253     /* Parse Kernel Parameters to decide what boot mode is enabled */
254     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
255       $this->bootmode= "G";
256     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
257       $this->bootmode= "D";
258     } elseif ($this->gotoKernelParameters == "") {
259       $this->bootmode= "G";
260     } else {
261       $this->bootmode= "T";
262     }
263     if (preg_match("/ o /", $this->gotoKernelParameters)){
264       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
265     } else {
266       $this->customParameters= "";
267     }
269     /* Prepare Shares */
270     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
271       unset($this->attrs['gotoShare']['count']);
272       foreach($this->attrs['gotoShare'] as $share){
273         $tmp = $tmp2 = array();
274         $tmp = split("\|",$share);
275         $tmp2['server']      =$tmp[0];
276         $tmp2['name']        =$tmp[1];
277         $tmp2['mountPoint']  =$tmp[2];
278         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
279       }
280     }
282     $this->gotoShareSelections= $config->getShareList(true);
283     $this->gotoAvailableShares= $config->getShareList(false);
284     $tmp2 = array();
285   
287     $this->orig_dn= $this->dn;
289     /* Handle inheritance value "default" */
290     $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
292     /* Load hardware list */
293     $ldap= $this->config->get_ldap_link();
294     $ldap->cd($this->config->current['BASE']);
295     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
296     if ($ldap->count() == 1){
298       if($this->fai_activated){
299         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
300       }else{
301         $map= array("gotoLdapServer");
302       }
303       $attrs= $ldap->fetch();
305       foreach ($map as $name){
306         if (!isset($attrs[$name][0])){
307           continue;
308         }
310         switch ($name){
311           case 'gotoLdapServer':
312             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
313             break;
315           case 'gotoBootKernel':
316             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
317             break;
319           case 'FAIclass':
320             $str = split(":",$attrs[$name][0]);
321             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
322             $this->InheritedFAIrelease  = trim($str[1]);
323             break;
325           case 'FAIdebianMirror':
326             $this->InheritedFAIdebianMirror = $attrs[$name][0];
327             break;
328         }
329       }
330     }
332     /* Get list of boot kernels */
333     if (isset($this->config->data['TABS'])){
334       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
336       if (!check_command($command)){
337         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
338             get_class($this));
339       } else {
340         $fh= popen($command, "r");
341         while (!feof($fh)) {
342           $buffer= trim(fgets($fh, 256));
343           
344           if(!empty($buffer)){
345           
346             $name=$value = $buffer;
348             if(preg_match("/:/",$buffer)){
349               $name = preg_replace("/:.*$/","",$buffer);
350               $value= preg_replace("/^.*:/","",$buffer);
351               $this->gotoBootKernels[$name]= $name.":".$value;
352             }else{
353               $this->gotoBootKernels[$name]= $value;
354             }
355           }
357         }
358         pclose($fh);
359       }
360     }
362     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
363       $this->FAIdebianMirror = "inherited";
364     }
366     /* Turn to default, if we've nothing to inherit */
367     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
368       $this->gotoBootKernel= "default";
369     }
370   }
372   
373   /* This class is called by the contrucktor ONLY.
374    *   It return the available classes for each 
375    *    Server / Release combination ... 
376    *   (Release specifies which classes are available) 
377    */
378   function getAvailableClassesForThisRelease($release)
379   {
380     /* There could be more than one server providing this release,
381         so use cached result if available
382      */ 
383     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
384       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
385     }
387     $test2  = array();
388     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
389     $ldap   = $this->config->get_ldap_link();
390     $ldap->cd($this->config->current['BASE']);
391   
392     /* Get classes fpr given release */
393     $p_classes = get_all_objects_for_given_base($bb,
394         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
395           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
396           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
398     /* Create list of classes */
399     foreach($p_classes as $class){
400       $ldap->cat($class['dn'],array("cn"));
401       $attr = $ldap->fetch();
402       $test2[$attr['cn'][0]] = $attr['cn'][0];
403     }
404     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
405     return($test2);
406   }
409   /*  Create array to display available classes/profiles in a selectbox 
410    *   This function only displays the available classes.
411    *   If a class is available is defined by these facts : 
412    *     1. Is this class available for the selected release ?
413    *       - if it is available, check if the release is available for the selected server 
414    *         (done by $this->getFAIreleases())
415    *     2. Is this class currently not assigned to $this->FAIclass
416    */
417   function selectFriendlyClasses(){
418     $tmp=array();
420     if($this->FAIdebianMirror == "inherited") return($tmp);
422     /* check if the current release exists,
423         else select the first one ..
424      */
425     $tmp2 = $this->getFAIreleases();
426     if(!in_array($this->FAIrelease, $tmp2)){  
427       $this->FAIrelease = key($tmp2);
428     }
430     /* Get all Packages for this server/release combination
431      */
432     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
433       $pkgs = array();
434       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
435     }else{
436       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
437     }
439     /* Check each and every single class name 
440      */
441     foreach($pkgs as $pkg){
442   
443       /* Class already assigned to the classes list ?
444        * If not ... go on
445        */
446       if(!in_array($pkg,$this->FAIclass)){
447         
448         /* Create the displayed list entry value
449             HKLMOP [-Pl P V T-] or something like that 
450          */
451         $str = "";
452         foreach($this->FAIclassInfo[$pkg] as $entry){
453           if(isset($entry['kzl'])){
454             $str .= $entry['kzl']." ";
455           }
456         }
457         
458         /* Append class if everyting was fine
459          */        
460         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
461       }
462     }
463     /* Just sort and return new classes list ...
464        ( possibly we should cache the result ... )
465      */
466     natcasesort ($tmp);
467     return($tmp);
468   }
470   function check()
471   {
472     $messages = array();
473     
474     /* Call common method to give check the hook */
475     $messages= plugin::check();
477     /* If there are packages selected, but no mirror show error */   
478     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
479       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
480     }
482     return($messages);
483   }
485   function execute()
486   {
488         /* Call parent execute */
489         plugin::execute();
491     if($this->is_account && !$this->view_logged){
492       $this->view_logged = TRUE;
493       new log("view","workstation/".get_class($this),$this->dn);
494     }
496     /* Do we need to flip is_account state? */
497     if(isset($_POST['modify_state'])){
498       if($this->is_account && $this->acl_is_removeable()){
499         $this->is_account= FALSE;
500       }elseif(!$this->is_account && $this->acl_is_createable()){
501         $this->is_account= TRUE;
502       }
503     }
505     /* Do we represent a valid terminal? */
506     if (!$this->is_account && $this->parent == NULL){
507       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
508         _("This 'dn' has no terminal features.")."</b>";
509       return ($display);
510     }
512     /* Add module */
513     if (isset ($_POST['add_module'])){
514       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
515         $this->add_list ($this->gotoModules, $_POST['module']);
516       }
517     }
519     /* Delete module */
520     if (isset ($_POST['delete_module'])){
521       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
522         $this->del_list ($this->gotoModules, $_POST['modules_list']);
523       }
524     }
526     /* FAI class management */
527     if($this->fai_activated){
528       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
529         $found = 0 ; 
531         /* If this new class/profile will attach a second partition table
532          * to our list of classes, abort and show a message.
533          */
534         foreach($this->FAIclass as $name){
535           if(isset($this->FAIclassInfo[$name])){
536             foreach($this->FAIclassInfo[$name] as $atr){
537               if(isset($atr['obj'])){
538                 if($atr['obj'] == "FAIpartitionTable"){
539                   $found ++ ; 
540                 }
541               }
542             }
543           }
544         }
546         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
547           print_red(_("There is already a profile in your selection that contain partition table configurations."));
548         }else{
549           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
550         }
551       }
553       $sort = false;
555       /* Move one used class class one position up or down */
556       if($this->acl_is_writeable("FAIclass")){
557         foreach($_POST as $name => $val){
559           $sort_type = false;
560           if((preg_match("/sort_up/",$name))&&(!$sort)){
561             $sort_type = "sort_up_";
562           }
563           if((preg_match("/sort_down/",$name))&&(!$sort)){
564             $sort_type = "sort_down_";
565           }
567           if(($sort_type)&&(!$sort)){
568             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
569             $sort = true;
571             $last = -1;
572             $change_down  = -1;
574             /* Create array with numeric index */ 
575             $tmp = array();
576             foreach($this->FAIclass as $class){
577               $tmp [] = $class;
578             }
580             /* Walk trough array */
581             foreach($tmp as $key => $faiName){
582               if($faiName == $value){
583                 if($sort_type == "sort_up_"){
584                   if($last != -1){
585                     $change_down= $last;
586                   }
587                 }else{
588                   if(isset($tmp[$key+1])){
589                     $change_down = $key;
590                   }
591                 }
592               }
593               $last = $key;
594             }
596             $tmp2 = array();
597             $skip = false;    
599             foreach($tmp as $ky => $vl){
601               if($ky == $change_down){
602                 $skip = $vl;
603               }else{
604                 $tmp2[$vl] = $vl;
605               }
606               if(($skip != false)&&($ky != $change_down)){
607                 $tmp2[$skip]  = $skip;
608                 $skip =false;
609               }
610             }   
611             $this->FAIclass = $tmp2; 
612           }
614           if(preg_match("/fai_remove/i",$name)){
615             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
616             unset($this->FAIclass[$value]);
617           }
618         }
619       }
621       /* Delete selected class from our list */
622       if($this->acl_is_writeable("FAIclass")){
623         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
624           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
625             unset($this->FAIclass[$_POST['FAIclassSel']]);
626           }
627         }
628       }
629     }// END fai handling
631     /* Show main page */
632     $smarty= get_smarty();
634     /* Assign ACLs to smarty */
635     $tmp = $this->plInfo();
636     foreach($tmp['plProvidedAcls'] as $name => $translation){
637       $smarty->assign($name."ACL",$this->getacl($name));
638     } 
640     $smarty->assign("SelectBoxLdapServer","");
642     /* In this section server shares will be defined
643      * A user can select one of the given shares and a mount point
644      *  and attach this combination to his setup.
645      */
646     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
647     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
649     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
650      * This entry will be, a combination of mountPoint and sharedefinitions
651      */
652     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
653       /* We assign a share to this user, if we don't know where to mount the share */
654       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
655         print_red(_("You must specify a valid mount point."));
656       }else{
657         if(count($this->gotoAvailableShares)){
658           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
659           $s_mount = $_POST['gotoShareMountPoint'];
660           /* Preparing the new assignment */
661           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
662           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
663         }
664       }
665     }
667     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
668      * If there is no defined share selected, we will abort the deletion without any message
669      */
670     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
671       unset($this->gotoShares[$_POST['gotoShare']]);
672     }
674     $smarty->assign("gotoShares",$this->printOutAssignedShares());
675     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
676     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
677     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
679     /* Arrays */
680     $tmp = $this->goLdapServerList;
682     /* Create divSelectBox for ldap server selection
683      */
684     $SelectBoxLdapServer = new divSelectBox("LdapServer");
685     $SelectBoxLdapServer->SetHeight(130);
687     /* Set first entry as selected, if $this->gotoLdapServer is empty
688      *  or given entry is no longer available ... 
689      */
690     $found = false;
691     foreach($tmp as $server){
692       if($this->gotoLdapServer==$server){
693         $found = true;
694       }
695     }
697     /* Add Entries 
698      */
699     foreach($tmp as $key => $server){
700       $use ="";
701       if(($this->gotoLdapServer == $server) || ($found == false)) {
702         $found = true;
703         $use = " checked ";
704       };
706       $display = $server;
708       $SelectBoxLdapServer->AddEntry(
709           array(
710             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
711                   "attach"=>"style='border-left:0px;'"),
712             array("string"=>$display)
713             ));
714     }    
716     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
718     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
719       $smarty->assign("$val", $this->$val);
720     }
722     /* Values */
723     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
724       $smarty->assign($val, $this->$val);
725     }
727     $smarty->assign("fai_activated",$this->fai_activated);
729     /* Create FAI output */
730     if($this->fai_activated){
731       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
732       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
733       $smarty->assign("FAIreleases",$this->getFAIreleases());
734       $smarty->assign("FAIrelease",$this->FAIrelease);
735       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
736       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
737       $smarty->assign("FAIclassKeys",$this->FAIclass);
739       $inheritedRelease = array();
740       if(!empty($this->InheritedFAIrelease)){
741         $inheritedRelease[$this->InheritedFAIrelease]= $this->InheritedFAIrelease;
742       } 
743       $smarty->assign("InheritedFAIrelease",$inheritedRelease);
745       $div = new divSelectBox("WSFAIscriptClasses");
746       $div -> SetHeight("110");
747       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
748       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
749       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
750       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
752       $i = 1;
754       if($this->FAIdebianMirror == "inherited"){
755         $tmp = $this->InheritedFAIclass;
756       }else{
757         $tmp = $this->FAIclass;
758       }
760       foreach($tmp as $class){
762         $marker = "";
763         if(in_array_ics($class,$this->unresolved_classes)){
764           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
765         }
767         if($this->FAIdebianMirror == "inherited"){
768           $str = "";
769         }else{
770           if($i==1){
771             $str = $str_empty.$str_down.$str_remove;
772           }elseif($i == count($this->FAIclass)){
773             $str = $str_up.$str_empty.$str_remove;
774           }else{
775             $str = $str_up.$str_down.$str_remove;
776           }
777         }
778         $i ++ ; 
780         $div->AddEntry(array(
781               array("string"=>$class.$marker),
782               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
783               ));
784       }  
786       $smarty->assign("FAIScriptlist",$div->DrawList()); 
787     }// END FAI output generation 
789     /* Radio button group */
790     if (preg_match("/G/", $this->bootmode)) {
791       $smarty->assign("graphicalbootup", "checked");
792     } else {
793       $smarty->assign("graphicalbootup", "");
794     }
795     if (preg_match("/T/", $this->bootmode)) {
796       $smarty->assign("textbootup", "checked");
797     } else {
798       $smarty->assign("textbootup", "");
799     }
800     if (preg_match("/D/", $this->bootmode)) {
801       $smarty->assign("debugbootup", "checked");
802     } else {
803       $smarty->assign("debugbootup", "");
804     }
806     /* Show main page */
807     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
808   }
810   function remove_from_parent()
811   {
812     $this->handle_post_events("remove");
813     new log("remove","workstation/".get_class($this),$this->dn);
814   }
816   function generateDNSyn($release)
817   {
818     $str = "";
819     $tmp = split("\/",$release);
820     $tmp = array_reverse($tmp);
822     $base = "ou=fai,ou=configs,ou=systems,";   
823     foreach($tmp as $departmentname){
824       
825       $str .= ",ou=".$departmentname;
826     }
827     $str = preg_replace("/^,/","",($str.",".$base));
828     
829     return($str);
830   }
832   function getFAIdebianMirrors()
833   {
834     $ret = array();
835     $ret['inherited']="["._("inherited")."]";
836     $ret['auto']=_("automatic");
837     $secs  = array();
839     /* Walk through all available servers 
840         and check if they support the currently selected classes
841         if not, dont't add them to our list
842      */
843     foreach($this->FAIServRepConfig as $mirror => $rest){
845       $use = false;
847       if(count($this->FAIclass) == 0){
848         $use = true;
849       }else{
850         $tmp = $this->getFAIreleases();
851         foreach($tmp as $release){
852           if(isset($rest['RELEASE'][$release])){
853             $use =true;
854           }
855         } 
856       }
858       /* If current server, doesn't support this class
859           remove it from list
860        */
861       if($use){
862         $ret[$mirror] = $mirror;
863       }
864     }
865     return($ret);
866   }
868   function getFAIreleases() 
869   {
870     $ret = array();
872     if($this->FAIdebianMirror == "inherited") return(array());
874     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
875       $this->FAIdebianMirror = "auto";
876     }
878     $errorClasses = array();  
880     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
881     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
882       $use = true;
883       
884       if(!count($this->FAIclass) == 0){
885         foreach($this->FAIclass as $class){
886           if(!in_array($class, $sections['PACKAGES'])){
887             $use = false;
888             $errorClasses[$class] = $class;
889           }else{
890             if(isset($errorClasses[$class])){
891               unset($errorClasses[$class]); 
892             }
893           }
894         }
895       }
896       if($use){
897         $ret[$release]=$release;
898       }
899     } 
900     }
901     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
903       $eClasses = " ";
904       foreach($errorClasses as $class){
905         $eClasses .= $class." ";
906       }
908       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));
909       $this->FAIdebianMirror = "auto";
910       return($this->getFAIreleases());
911     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
913       $eClasses = " ";
914       foreach($errorClasses as $class){
915         $eClasses .= $class." ";
916       }
918       $eClasses = preg_replace("/  */","",$eClasses);
919      
920       if(!empty($eClasses)) {
922         $this->unresolved_classes = $errorClasses;
923         $this->FAIdebianMirror = "auto";
924         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));
925       }
926     }
927     return($ret);
928   }
930   /* Save data to object */
931   function save_object()
932   {
933     plugin::save_object();
935     /* Save group radio buttons */
936     if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
937       $this->bootmode= $_POST["bootmode"];
938     }
940     /* Save kernel parameters */
941     if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
942       $this->customParameters= $_POST["customParameters"];
943     }
945   }
948   /* Save to LDAP */
949   function save()
950   {
952     /* Depending on the baseobject (Ogroup / WS) we
953      *  use another set of objectClasses
954      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
955      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
956      */
957     if(isset($this->parent->by_object['ogroup'])){
958       $this->objectclasses = array("gotoWorkstationTemplate");
959     }elseif(isset($this->parent->by_object['workgeneric'])){
960       $this->objectclasses = array("GOhard");
961     }elseif(isset($this->parent->by_object['servgeneric'])){
962       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
963     }else{
964       print "Object Type Configuration : unknown";
965       exit();
966     }
968     /* Append FAI class */
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();
1021     unset( $this->attrs['FAIrelease'] );
1022     
1023     $str = "";
1025     /* Skip FAI attribute handling if not necessary */
1026     if($this->fai_activated){
1027       if($this->FAIdebianMirror == "inherited"){
1028         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1029       }else{
1030         foreach($this->FAIclass as $class){
1031           $str .= $class." ";
1032         }
1033         $str .= ":" . $this->FAIrelease;
1034         $this->attrs['FAIclass']= "";
1035         $this->attrs['FAIclass']= trim($str);
1037         if(empty($this->attrs['FAIclass'])){
1038           $this->attrs['FAIclass'] = array();
1039         }
1040       }
1041     }
1042   
1043     /* Add missing arrays */
1044     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1045       if (isset ($this->$val) && count ($this->$val) != 0){
1046     
1047         $this->attrs["$val"]= array_unique($this->$val);
1048       }
1049       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1050     }
1052     /* Strip out 'default' values */
1053     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1054       $this->attrs['gotoLdapServer']= array();
1055     }
1057     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1058       $this->attrs['gotoBootKernel']= array();
1059     }
1061     /* if mirror == none stop saving this attribute */
1062     if($this->FAIdebianMirror == "none"){
1063       $this->FAIdebianMirror = "";
1064     }
1065    
1066     /* Get FAIstate from object, the generic tab could have changed it during execute */
1067     $ldap= $this->config->get_ldap_link();
1068     $ldap->cd($this->dn);
1071     /* Skip FAI attribute handling if not necessary */
1072     if($this->fai_activated){
1073       $ldap->cat($this->dn,array("FAIstate"));
1074       $checkFAIstate = $ldap->fetch();
1076       /* Remove FAI objects if no FAI class is selected */ 
1077       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1078         $this->attrs['FAIclass']        = array();
1079         $this->attrs['FAIdebianMirror'] = array();
1080       }
1081     }
1084     /* prepare share settings */
1085     $tmp = array();
1086     foreach($this->gotoShares as $name => $settings){
1087       $tmp2= split("\|",$name);
1088       $name = $tmp2[0];
1089       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1090     }
1091     $this->attrs['gotoShare']=$tmp;
1093     $this->cleanup();
1094     $ldap->modify ($this->attrs); 
1095     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1097     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
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 PrepareForCopyPaste($source)
1163   {
1164     plugin::PrepareForCopyPaste($source);    
1166     $source_o = new workstartup ($this->config, $source['dn']);
1167     
1168     foreach(array("gotoModules", "gotoAutoFs", "gotoFilesystem","gotoKernelParameters","gotoShares","customParameters") as $attr){
1169       $this->$attr = $source_o->$attr;
1170     }
1171   }
1174   /* Return plugin informations for acl handling */ 
1175   function plInfo()
1176   {
1177     return (array( 
1178           "plShortName"   => _("Startup"),
1179           "plDescription" => _("System startup"),
1180           "plSelfModify"  => FALSE,
1181           "plDepends"     => array(),
1182           "plPriority"    => 9,
1183           "plSection"     => array("administration"),           
1184           "plCategory"    => array("workstation","server","ogroups"),
1186           "plProvidedAcls"=> array(
1187             "gotoLdapServer"        => _("Ldap server"),
1188             "gotoBootKernel"        => _("Boot kernel"),
1189             "gotoKernelParameters"  => _("Kernel parameter"),
1191             "gotoModules"           => _("Kernel modules"),
1192             "gotoShare"             => _("Shares"),
1194             "FAIclass"              => _("FAI classes"),
1195             "FAIdebianMirror"       => _("Debian mirror"),
1196             "FAIrelease"            => _("Debian release"),
1198             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1199           ));
1200   }
1203 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1204 ?>