Code

a2761f271853024a2833d33c92880d2ee54e5ac4
[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   
45   /* FAI class selection */
46   var $InheritedFAIclass           = array();
47   var $InheritedFAIrelease         = "";
48   var $InheritedFAIdebianMirror    = "auto";
50   /* Contains all possible server/release/class settings */
51   var $FAIServRepConfig   = array();
53   function workstartup ($config, $dn= NULL)
54   {
55     plugin::plugin ($config, $dn);
57     /* Creating a list of valid Mirrors 
58      * none will not be saved to ldap.
59      */
60     $ldap   = $this->config->get_ldap_link();
61     $ldap->cd($this->config->current['BASE']);
63     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
64       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
65     }
66    
67     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
68     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
70     /* Search all FAI objects */
71     $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
72     /* Sort all entries, and attach elementtype.
73      * To be able to show the types in the listbox.
74      */
75     while($attr = $ldap->fetch()){
76       $cn = $attr['cn'][0];
77     
78       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
79  
80       if(in_array('FAIpackageList',$attr['objectClass'])){
81         $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
82         $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
83         $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
84         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
85       }
86       if(in_array('FAItemplate',$attr['objectClass'])){
87         $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
88         $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
89         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
90       }
91       if(in_array('FAIvariable',$attr['objectClass'])){
92         $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
93         $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
94         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
95       }
96       if(in_array('FAIscript',$attr['objectClass'])){
97         $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
98         $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
99         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
100       }
101       if(in_array('FAIhook',$attr['objectClass'])){
102         $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
103         $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
104         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
105       }
106       if(in_array('FAIpartitionTable',$attr['objectClass'])){
107         $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
108         $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
109         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
110       }
111       if(in_array('FAIprofile',$attr['objectClass'])){
112         $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
113         $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
114         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
115       }
116     }
117     if(is_array($this->FAIclasses)){
118       natcasesort($this->FAIclasses);
119     }
121     if(isset($tmp2)){
122       $this->FAIclassInfo = $tmp2;
123     } else {
124       $this->FAIclassInfo = array();
125     }
127     /* Build up an array like this one :
128         [$url]['SERVER'] = 'srv1-002';
129         [$url]['RELEASE']['siga/rc9.0.2']
130                                            ['SECTIONS'][0] "main";
131                                            ['SECTIONS'][1] "non-free";
132         [$url]['RELEASE']['siga/rc9.0.2']
133                                            ['PACKAGES'][0] "pkg1";
134                                            ['PACKAGES'][1] "postfix";
135      */
137     $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
138     $test = array();
139     while($attr = $ldap->fetch()){
140       if(isset($attr['FAIrepository'])){
142         unset($attr['FAIrepository']['count']);
144         foreach($attr['FAIrepository'] as $rep){
145           $tmp = split("\|",$rep);
147           if(count($tmp)==4){
148             $sections = split(",",$tmp[3]);
149             $release  = $tmp[2];
150             $server   = $tmp[1];
151             $url      = $tmp[0];
152            
153             $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
154     
155             /* Result will be cached
156              */
157             $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
158             $test[$url]['SERVER'] = $server;
160             /* auto gets all releases/classes 
161              */
162             $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
163             $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
164           }
165         }
166       }
167     }
168     
169     /* Add possible elements from hook */
170     $lines= $this->GetHookElements();
171     foreach ($lines as $hline){
172       $entries= split(";", $hline);
173       if (isset($entries[1]) && !isset($test[$entries[1]])){
174         $test[$entries[1]]['RELEASE']= array();
176         /* Split releases */
177         if (isset($entries[2])){
178           $releases= split(",", $entries[2]);
180           foreach ($releases as $release){
181             $rname= preg_replace('/:.*$/', '', $release);
182             $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
183             $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
184             $test[$entries[1]]['RELEASE'][$rname]= array();
185             $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
186             foreach ($classes as $class){
187               if ($class != ""){
188                 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
189               }
190             }
191           }
192         }
193       }
194     }
195     
196     $this->FAIServRepConfig= $test;
198     /* Get arrays */
199     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
200       if (isset($this->attrs["$val"]["count"])){
201         for ($i= 0; $i<$this->attrs["count"]; $i++){
202           if (isset($this->attrs["$val"][$i])){
203             array_push($this->$val, $this->attrs["$val"][$i]);
204           }
205         }
206       }
207       sort ($this->$val);
208       $this->$val= array_unique($this->$val);
209     }
211     /* Parse Kernel Parameters to decide what boot mode is enabled */
212     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
213       $this->bootmode= "G";
214     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
215       $this->bootmode= "D";
216     } elseif ($this->gotoKernelParameters == "") {
217       $this->bootmode= "G";
218     } else {
219       $this->bootmode= "T";
220     }
221     if (preg_match("/ o /", $this->gotoKernelParameters)){
222       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
223     } else {
224       $this->customParameters= "";
225     }
227     /* Prepare Shares */
228     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
229       unset($this->attrs['gotoShare']['count']);
230       foreach($this->attrs['gotoShare'] as $share){
231         $tmp = $tmp2 = array();
232         $tmp = split("\|",$share);
233         $tmp2['server']      =$tmp[0];
234         $tmp2['name']        =$tmp[1];
235         $tmp2['mountPoint']  =$tmp[2];
236         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
237       }
238     }
240     $this->gotoShareSelections= $config->getShareList(true);
241     $this->gotoAvailableShares= $config->getShareList(false);
242     $tmp2 = array();
243   
244     if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
245       $tmp = array();
246       $tmp = split(" ",$this->FAIclass);
247       $tmp2 =array();  
248     
249       foreach($tmp as $class){
250         if( ":" == $class[0] ) {
251           $this->FAIrelease = substr( $class, 1 );
252         }
253         else
254           $tmp2[$class] = $class;
255       }
256       $this->FAIclass = $tmp2;
257     }
259     if(!is_array($this->FAIclass)){
260       $this->FAIclass =array();
261     }
263     $this->orig_dn= $this->dn;
265     /* Handle inheritance value "default" */
266     $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']');
269     /* Load hardware list */
270     $ldap= $this->config->get_ldap_link();
271     $ldap->cd($this->config->current['BASE']);
272     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
273     if ($ldap->count() == 1){
274       $map= array("gotoLdapServer","FAIclass","FAIdebianMirror");
275       $attrs= $ldap->fetch();
277       foreach ($map as $name){
278         if (!isset($attrs[$name][0])){
279           continue;
280         }
282         switch ($name){
283           case 'gotoLdapServer':
284             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
285             break;
287           case 'gotoBootKernel':
288             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
289             break;
291           case 'FAIclass':
292             $str = split(":",$attrs[$name][0]);
293             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
294             $this->InheritedFAIrelease  = trim($str[1]);
295             break;
297           case 'FAIdebianMirror':
298             $this->InheritedFAIdebianMirror = $attrs[$name][0];
299             break;
300         }
301       }
302     }
304     /* Get list of boot kernels */
305     if (isset($this->config->data['TABS'])){
306       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
308       if (!check_command($command)){
309         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
310             get_class($this));
311       } else {
312         $fh= popen($command, "r");
313         while (!feof($fh)) {
314           $buffer= trim(fgets($fh, 256));
316           $name= $value = $buffer;
318           if(preg_match("/:/",$buffer)){
319             $name  = preg_replace("/:.*$/","",$buffer);
320             $value = preg_replace("/^.*:/","",$buffer);
321           }
323           if ($buffer != ""){
324             $this->gotoBootKernels[$name]= $value;
325           }
326         }
327         pclose($fh);
328       }
329     }
331     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
332       $this->FAIdebianMirror = "inherited";
333     }
334   }
336   
337   /* This class is called by the contrucktor ONLY.
338    *   It return the available classes for each 
339    *    Server / Release combination ... 
340    *   (Release specifies which classes are available) 
341    */
342   function getAvailableClassesForThisRelease($release)
343   {
344     /* There could be more than one server providing this release,
345         so use cached result if available
346      */ 
347     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
348       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
349     }
351     $test2  = array();
352     $bb     = $this->generateDNSyn($release).$_SESSION['CurrentMainBase'];
353     $ldap   = $this->config->get_ldap_link();
354     $ldap->cd($this->config->current['BASE']);
355   
356     /* Get classes fpr given release */
357     $p_classes = get_all_objects_for_given_base($bb,
358         "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)".
359           "(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)".
360           "(objectClass=FAIprofile)(objectClass=FAIpartitionTable))");
362     /* Create list of classes */
363     foreach($p_classes as $class){
364       $ldap->cat($class['dn'],array("cn"));
365       $attr = $ldap->fetch();
366       $test2[$attr['cn'][0]] = $attr['cn'][0];
367     }
368     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
369     return($test2);
370   }
373   /*  Create array to display available classes/profiles in a selectbox 
374    *   This function only displays the available classes.
375    *   If a class is available is defined by these facts : 
376    *     1. Is this class available for the selected release ?
377    *       - if it is available, check if the release is available for the selected server 
378    *         (done by $this->getFAIreleases())
379    *     2. Is this class currently not assigned to $this->FAIclass
380    */
381   function selectFriendlyClasses(){
382     $tmp=array();
384     if($this->FAIdebianMirror == "inherited") return($tmp);
386     /* check if the current release exists,
387         else select the first one ..
388      */
389     $tmp2 = $this->getFAIreleases();
390     if(!in_array($this->FAIrelease, $tmp2)){  
391       $this->FAIrelease = key($tmp2);
392     }
394     /* Get all Packages for this server/release combination
395      */
396     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
397       $pkgs = array();
398       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
399     }else{
400       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
401     }
403     /* Check each and every single class name 
404      */
405     foreach($pkgs as $pkg){
406   
407       /* Class already assigned to the classes list ?
408        * If not ... go on
409        */
410       if(!in_array($pkg,$this->FAIclass)){
411         
412         /* Create the displayed list entry value
413             HKLMOP [-Pl P V T-] or something like that 
414          */
415         $str = "";
416         foreach($this->FAIclassInfo[$pkg] as $entry){
417           if(isset($entry['kzl'])){
418             $str .= $entry['kzl']." ";
419           }
420         }
421         
422         /* Append class if everyting was fine
423          */        
424         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
425       }
426     }
427     /* Just sort and return new classes list ...
428        ( possibly we should cache the result ... )
429      */
430     natcasesort ($tmp);
431     return($tmp);
432   }
434   function check()
435   {
436     $messages = array();
437     
438     /* Call common method to give check the hook */
439     $messages= plugin::check();
441     /* If there are packages selected, but no mirror show error */   
442     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
443       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
444     }
446     return($messages);
447   }
449   function execute()
450   {
452         /* Call parent execute */
453         plugin::execute();
455     /* Do we need to flip is_account state? */
456     if (isset($_POST['modify_state'])){
457       $this->is_account= !$this->is_account;
458     }
460     /* Do we represent a valid terminal? */
461     if (!$this->is_account && $this->parent == NULL){
462       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
463         _("This 'dn' has no terminal features.")."</b>";
464       return ($display);
465     }
467     /* Add module */
468     if (isset ($_POST['add_module'])){
469       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
470         $this->add_list ($this->gotoModules, $_POST['module']);
471       }
472     }
474     /* Delete module */
475     if (isset ($_POST['delete_module'])){
476       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
477         $this->del_list ($this->gotoModules, $_POST['modules_list']);
478       }
479     }
481     /* FAI class management */
482     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
483       $found = 0 ; 
485       /* If this new class/profile will attach a second partition table
486        * to our list of classes, abort and show a message.
487        */
488       foreach($this->FAIclass as $name){
489         if(isset($this->FAIclassInfo[$name])){
490           foreach($this->FAIclassInfo[$name] as $atr){
491             if(isset($atr['obj'])){
492               if($atr['obj'] == "FAIpartitionTable"){
493                 $found ++ ; 
494               }
495             }
496           }
497         }
498       }
500       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
501         print_red(_("There is already a profile in your selection that contain partition table configurations."));
502       }else{
503         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
504       }
505     }
507     $sort = false;
508     foreach($_POST as $name => $val){
509       
510       $sort_type = false;
511       if((preg_match("/sort_up/",$name))&&(!$sort)){
512         $sort_type = "sort_up_";
513       }
514       if((preg_match("/sort_down/",$name))&&(!$sort)){
515         $sort_type = "sort_down_";
516       }
517     
518       if(($sort_type)&&(!$sort)){
519         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
520         $sort = true;
521         
522         $last = -1;
523         $change_down  = -1;
524  
525         /* Create array with numeric index */ 
526         $tmp = array();
527         foreach($this->FAIclass as $class){
528           $tmp [] = $class;
529         }
531         /* Walk trough array */
532         foreach($tmp as $key => $faiName){
533           if($faiName == $value){
534             if($sort_type == "sort_up_"){
535               if($last != -1){
536                  $change_down= $last;
537               }
538             }else{
539               if(isset($tmp[$key+1])){
540                 $change_down = $key;
541               }
542             }
543           }
544           $last = $key;
545         }
546  
547         $tmp2 = array();
548         $skip = false;    
549   
550         foreach($tmp as $ky => $vl){
552           if($ky == $change_down){
553             $skip = $vl;
554           }else{
555             $tmp2[$vl] = $vl;
556           }
557           if(($skip != false)&&($ky != $change_down)){
558             $tmp2[$skip]  = $skip;
559             $skip =false;
560           }
561         }   
562         $this->FAIclass = $tmp2; 
563       }
564   
565       if(preg_match("/fai_remove/i",$name)){
566         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
567         unset($this->FAIclass[$value]);
568       }
569     }
571     /* Delete selected class from our list */
572     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
573       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
574         unset($this->FAIclass[$_POST['FAIclassSel']]);
575       }
576     }
578     /* Show main page */
579     $smarty= get_smarty();
580     $smarty->assign("SelectBoxLdapServer","");
582     /* In this section server shares will be defined
583      * A user can select one of the given shares and a mount point
584      *  and attach this combination to his setup.
585      */
586     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
587     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
589     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
590      * This entry will be, a combination of mountPoint and sharedefinitions
591      */
592     if(isset($_POST['gotoShareAdd'])){
593       /* We assign a share to this user, if we don't know where to mount the share */
594       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
595         print_red(_("You must specify a valid mount point."));
596       }else{
597         if(count($this->gotoAvailableShares)){
598           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
599           $s_mount = $_POST['gotoShareMountPoint'];
600           /* Preparing the new assignment */
601           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
602           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
603         }
604       }
605     }
607     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
608      * If there is no defined share selected, we will abort the deletion without any message
609      */
610     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
611       unset($this->gotoShares[$_POST['gotoShare']]);
612     }
614     $smarty->assign("gotoShares",$this->printOutAssignedShares());
615     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
616     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
617     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
619     /* Arrays */
620     $tmp = $this->goLdapServerList;
622     /* Create divSelectBox for ldap server selection
623      */
624     $SelectBoxLdapServer = new divSelectBox("LdapServer");
625     $SelectBoxLdapServer->SetHeight(130);
627     /* Set first entry as selected, if $this->gotoLdapServer is empty
628      *  or given entry is no longer available ... 
629      */
630     $found = false;
631     foreach($tmp as $server){
632       if($this->gotoLdapServer==$server){
633         $found = true;
634       }
635     }
637     /* Add Entries 
638      */
639     foreach($tmp as $key => $server){
640       $use ="";
641       if(($this->gotoLdapServer == $server) || ($found == false)) {
642         $found = true;
643         $use = " checked ";
644       };
646       $display = $server;
648       $SelectBoxLdapServer->AddEntry(
649           array(
650             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
651                   "attach"=>"style='border-left:0px;'"),
652             array("string"=>$display)
653             ));
654     }    
656     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
658     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
659     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
660       $smarty->assign("$val", $this->$val);
661     }
663     /* Values */
664     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
665       $smarty->assign($val, $this->$val);
666       $smarty->assign($val."ACL", chkacl($this->acl, $val));
667     }
669     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
670     $smarty->assign("FAIreleases",$this->getFAIreleases());
671     $smarty->assign("FAIrelease",$this->FAIrelease);
672     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
673     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
674     $smarty->assign("FAIclassKeys",$this->FAIclass);
675     $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
676     
677     $div = new divSelectBox("WSFAIscriptClasses");
678     $div -> SetHeight("110");
679     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
680     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
681     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
682     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
684     $i = 1;
686     if($this->FAIdebianMirror == "inherited"){
687       $tmp = $this->InheritedFAIclass;
688     }else{
689       $tmp = $this->FAIclass;
690     }
692     foreach($tmp as $class){
694       if($this->FAIdebianMirror == "inherited"){
695         $str = "";
696       }else{
697         if($i==1){
698           $str = $str_empty.$str_down.$str_remove;
699         }elseif($i == count($this->FAIclass)){
700           $str = $str_up.$str_empty.$str_remove;
701         }else{
702           $str = $str_up.$str_down.$str_remove;
703         }
704       }
705       $i ++ ; 
707       $div->AddEntry(array(
708             array("string"=>$class),
709             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
710             ));
711     }  
713     $smarty->assign("FAIScriptlist",$div->DrawList()); 
715     /* Radio button group */
716     if (preg_match("/G/", $this->bootmode)) {
717       $smarty->assign("graphicalbootup", "checked");
718     } else {
719       $smarty->assign("graphicalbootup", "");
720     }
721     if (preg_match("/T/", $this->bootmode)) {
722       $smarty->assign("textbootup", "checked");
723     } else {
724       $smarty->assign("textbootup", "");
725     }
726     if (preg_match("/D/", $this->bootmode)) {
727       $smarty->assign("debugbootup", "checked");
728     } else {
729       $smarty->assign("debugbootup", "");
730     }
732     /* ACL's */
733     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
734       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
735     }
737     /* Show main page */
738     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
739   }
741   function remove_from_parent()
742   {
743     $this->handle_post_events("remove");
744   }
746   function generateDNSyn($release)
747   {
748     $str = "";
749     $tmp = split("\/",$release);
750     $tmp = array_reverse($tmp);
752     $base = "ou=fai,ou=configs,ou=systems,";   
753     foreach($tmp as $departmentname){
754       
755       $str .= ",ou=".$departmentname;
756     }
757     $str = preg_replace("/^,/","",($str.",".$base));
758     
759     return($str);
760   }
762   function getFAIdebianMirrors()
763   {
764     $ret = array();
765     $ret['inherited']="["._("inherited")."]";
766     $ret['auto']=_("automatic");
767     $secs  = array();
769     /* Walk through all available servers 
770         and check if they support the currently selected classes
771         if not, dont't add them to our list
772      */
773     foreach($this->FAIServRepConfig as $mirror => $rest){
775       $use = false;
777       if(count($this->FAIclass) == 0){
778         $use = true;
779       }else{
780         $tmp = $this->getFAIreleases();
781         foreach($tmp as $release){
782           if(isset($rest['RELEASE'][$release])){
783             $use =true;
784           }
785         } 
786       }
788       /* If current server, doesn't support this class
789           remove it from list
790        */
791       if($use){
792         $ret[$mirror] = $mirror;
793       }
794     }
795     return($ret);
796   }
798   function getFAIreleases() 
799   {
800     $ret = array();
802     if($this->FAIdebianMirror == "inherited") return(array());
804     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
805       $this->FAIdebianMirror = "auto";
806     }
808     $errorClasses = array();  
810     if(is_array($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'])){
811     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
812       $use = true;
813       
814       if(!count($this->FAIclass) == 0){
815         foreach($this->FAIclass as $class){
816           if(!in_array($class, $sections['PACKAGES'])){
817             $use = false;
818             $errorClasses[$class] = $class;
819           }else{
820             if(isset($errorClasses[$class])){
821               unset($errorClasses[$class]); 
822             }
823           }
824         }
825       }
826       if($use){
827         $ret[$release]=$release;
828       }
829     } 
830     }
831     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
833       $eClasses = " ";
834       foreach($errorClasses as $class){
835         $eClasses .= $class." ";
836       }
838       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));
839       $this->FAIdebianMirror = "auto";
840       return($this->getFAIreleases());
841     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
843       $eClasses = " ";
844       foreach($errorClasses as $class){
845         $eClasses .= $class." ";
846       }
848       $eClasses = preg_replace("/  */","",$eClasses);
849      
850       if(!empty($eClasses)) {
851         $this->FAIclass= array();
852         print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. !All classes have been removed from this account, press cancel if you don't want this to be saved."),$eClasses));
853       }
854     }
855     return($ret);
856   }
858   /* Save data to object */
859   function save_object()
860   {
861     plugin::save_object();
863     /* Save group radio buttons */
864     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
865       $this->bootmode= $_POST["bootmode"];
866     }
868     /* Save kernel parameters */
869     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
870       $this->customParameters= $_POST["customParameters"];
871     }
873   }
876   /* Save to LDAP */
877   function save()
878   {
880     /* Depending on the baseobject (Ogroup / WS) we
881      *  use another set of objectClasses
882      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
883      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
884      */
885     if(isset($this->parent->by_object['ogroup'])){
886       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
887     }elseif(isset($this->parent->by_object['workgeneric'])){
888       $this->objectclasses = array("GOhard", "FAIobject");
889     }elseif(isset($this->parent->by_object['servgeneric'])){
890       $this->objectclasses = array("GOhard", "FAIobject","gotoWorkstationTemplate");
891     }else{
892       print "Object Type Configuration : unknown";
893       exit();
894     }
896     /* Find proper terminal path for tftp configuration
897        FIXME: This is suboptimal when the default has changed to
898        another location! */
899     if (($this->gotoTerminalPath == "default")){
900       $ldap= $this->config->get_ldap_link();
902       /* Strip relevant part from dn, keep trailing ',' */
903       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
904       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
906       /* Walk from top to base and try to load default values for
907          'gotoTerminalPath'. Abort when an entry is found. */
908       while (TRUE){
909         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
911         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
912             $this->config->current['BASE'], array('gotoTerminalPath'));
913         $attrs= $ldap->fetch();
914         if (isset($attrs['gotoTerminalPath'])){
915           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
916           break;
917         }
919         /* Nothing left? */
920         if ($tmp == ""){
921           break;
922         }
923       }
924     }
926     /* Add semi automatic values */
927     // FIXME: LDAP Server may not be set here...
928     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
930     switch ($this->bootmode){
931       case "D":
932         $this->gotoKernelParameters.= " debug";
933       break;
934       case "G":
935         $this->gotoKernelParameters.= " splash=silent";
936       break;
937     }
938     if ($this->customParameters != ""){
939       $this->gotoKernelParameters.= " o ".$this->customParameters;
940     }
942     plugin::save();
944     unset( $this->attrs['FAIrelease'] );
945     
946     $str = "";
948     if($this->FAIdebianMirror == "inherited"){
949   
950       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
952     }else{
954       foreach($this->FAIclass as $class){
955         $str .= $class." ";
956       }
957       $str .= ":" . $this->FAIrelease;
958       $this->attrs['FAIclass']= "";
959       $this->attrs['FAIclass']= trim($str);
961       if(empty($this->attrs['FAIclass'])){
962         $this->attrs['FAIclass'] = array();
963       }
964     }
966     /* Add missing arrays */
967     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
968       if (isset ($this->$val) && count ($this->$val) != 0){
969     
970         $this->attrs["$val"]= array_unique($this->$val);
971       }
972       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
973     }
975     /* Strip out 'default' values */
976     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
977       $this->attrs['gotoLdapServer']= array();
978     }
980     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
981       $this->attrs['gotoBootKernel']= array();
982     }
984     /* if mirror == none stop saving this attribute */
985     if($this->FAIdebianMirror == "none"){
986       $this->FAIdebianMirror = "";
987     }
988    
989     /* Get FAIstate from object, the generic tab could have changed it during execute */
990     $ldap= $this->config->get_ldap_link();
991     $ldap->cd($this->dn);
992     $ldap->cat($this->dn,array("FAIstate"));
993     $checkFAIstate = $ldap->fetch();
995     /* Remove FAI objects if no FAI class is selected */ 
996     if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
997       $tmp = array();
998       foreach($this->attrs['objectClass'] as $class){
999         if($class != "FAIobject"){
1000           $tmp[] = $class;
1001         }
1002       }
1003       $this->attrs['objectClass']     = $tmp;
1004       $this->attrs['FAIclass']        = array();
1005       $this->attrs['FAIdebianMirror'] = array();
1006     }
1008     /* prepare share settings */
1009     $tmp = array();
1010     foreach($this->gotoShares as $name => $settings){
1011       $tmp2= split("\|",$name);
1012       $name = $tmp2[0];
1013       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1014     }
1015     $this->attrs['gotoShare']=$tmp;
1017     $this->cleanup();
1018     $ldap->modify ($this->attrs); 
1020     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/startup with dn '%s' failed."),$this->dn));
1021     $this->handle_post_events("modify");
1022   }
1024   /* Add value to array, check if unique */
1025   function add_list (&$array, $value)
1026   {
1027     if ($value != ""){
1028       $array[]= $value;
1029       sort($array);
1030       array_unique ($array);
1031     }
1032   }
1035   /* Delete value to array, check if unique */
1036   function del_list (&$array, $list)
1037   {
1038     $tmp= array();
1039     foreach ($array as $mod){
1040       if (!in_array($mod, $list)){
1041         $tmp[]= $mod;
1042       }
1043     }
1044     $array= $tmp;
1045   }
1047   /* Generate ListBox frindly output for the defined shares
1048    * Possibly Add or remove an attribute here,
1049    */
1050   function printOutAssignedShares()
1051   {
1052     $a_return = array();
1053     if(is_array($this->gotoShares)){
1054       foreach($this->gotoShares as $share){
1055         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1056       }
1057     }
1058     return($a_return);
1059   }
1062   function GetHookElements()
1063   {
1064     $ret = array();
1065     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1066     if(!empty($cmd)){
1067       $res = shell_exec($cmd);
1068       $res2 = trim($res);
1069       if((!$res)){
1070         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1071       }elseif(empty($res2)){
1072         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1073       }else{
1074         $tmp = split("\n",$res);
1075         foreach($tmp as $line){
1076           if(empty($line)) continue;
1077           $ret[]= $line;
1078         }
1079       }
1080     }
1081     return($ret);
1082   }
1085   /* Return plugin informations for acl handling */ 
1086   function plInfo()
1087   {
1088     return (array( 
1089           "plShortName"   => _("Startup"),
1090           "plDescription" => _("System startup"),
1091           "plSelfModify"  => FALSE,
1092           "plDepends"     => array(),
1093           "plPriority"    => 0,
1094           "plSection"     => array("administration"),           
1095           "plCategory"    => array("workstation","server","ogroups"),
1097           "plProvidedAcls"=> array(
1098             "gotoLdapServer"        => _("Ldap server"),
1099             "gotoBootKernel"        => _("Boot kernel"),
1100             "gotoKernelParameters"  => _("Kernel parameter"),
1101             "FAIclass"              => _("FAI classes"),
1102             "FAIstatus"             => _("FAI status flag"),
1103             "gotoShare"             => _("Shares"),
1104             "FAIdebianMirror"       => _("Debian mirror"),
1105             "FAIrelease"            => _("Debian release"))
1106           ));
1107   }
1110 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1111 ?>