Code

* Moved external_hook to repository_hook
[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";
13   var $gotoKernelParameters = "";
14   var $gotoLdapServer       = "default";
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   /* Contains all possible server/release/class settings */
45   var $FAIServRepConfig   = array();
47   function workstartup ($config, $dn= NULL)
48   {
49     plugin::plugin ($config, $dn);
51     /* Creating a list of valid Mirrors 
52      * none will not be saved to ldap.
53      */
54     $ldap   = $this->config->get_ldap_link();
55     $ldap->cd($this->config->current['BASE']);
56    
57     $this->goLdapServerList = array("default" =>"["._("inherited")."]");
58    
59     $_SESSION['getAvailableClassesForThisRelease_CACHE'] = array();
60     $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] = array();
62     /* Search all FAI objects */
63     $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn","objectClass","FAIdebianSection"));
64     /* Sort all entries, and attach elementtype.
65      * To be able to show the types in the listbox.
66      */
67     while($attr = $ldap->fetch()){
68       $cn = $attr['cn'][0];
69     
70       $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
71  
72       if(in_array('FAIpackageList',$attr['objectClass'])){
73         $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
74         $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
75         $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
76         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
77       }
78       if(in_array('FAItemplate',$attr['objectClass'])){
79         $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
80         $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
81         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
82       }
83       if(in_array('FAIvariable',$attr['objectClass'])){
84         $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
85         $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
86         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
87       }
88       if(in_array('FAIscript',$attr['objectClass'])){
89         $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
90         $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
91         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
92       }
93       if(in_array('FAIhook',$attr['objectClass'])){
94         $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
95         $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
96         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
97       }
98       if(in_array('FAIpartitionTable',$attr['objectClass'])){
99         $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
100         $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
101         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
102       }
103       if(in_array('FAIprofile',$attr['objectClass'])){
104         $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
105         $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
106         $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
107       }
108     }
109     if(is_array($this->FAIclasses)){
110       natcasesort($this->FAIclasses);
111     }
113     $this->FAIclassInfo = $tmp2;
116     /* Build up an array like this one :
117         [$url]['SERVER'] = 'srv1-002';
118         [$url]['RELEASE']['siga/rc9.0.2']
119                                            ['SECTIONS'][0] "main";
120                                            ['SECTIONS'][1] "non-free";
121         [$url]['RELEASE']['siga/rc9.0.2']
122                                            ['PACKAGES'][0] "pkg1";
123                                            ['PACKAGES'][1] "postfix";
124      */
126     $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",array("FAIrepository"));
127     $test = array();
128     while($attr = $ldap->fetch()){
129       if(isset($attr['FAIrepository'])){
131         unset($attr['FAIrepository']['count']);
133         foreach($attr['FAIrepository'] as $rep){
134           $tmp = split("\|",$rep);
136           if(count($tmp)==4){
137             $sections = split(",",$tmp[3]);
138             $release  = $tmp[2];
139             $server   = $tmp[1];
140             $url      = $tmp[0];
141            
142             $test[$url]['RELEASE'][$release]['SECTIONS'] = $sections;
143     
144             /* Result will be cached
145              */
146             $test[$url]['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
147             $test[$url]['SERVER'] = $server;
149             /* auto gets all releases/classes 
150              */
151             $test['auto']['RELEASE'][$release]['SECTION'] = $sections;
152             $test['auto']['RELEASE'][$release]['PACKAGES'] = $this->getAvailableClassesForThisRelease($release);
153           }
154         }
155       }
156     }
157     
158     /* Add possible elements from hook */
159     $lines= $this->GetHookElements();
160     foreach ($lines as $hline){
161       $entries= split(";", $hline);
162       if (isset($entries[1]) && !isset($test[$entries[1]])){
163         $test[$entries[1]]['RELEASE']= array();
165         /* Split releases */
166         if (isset($entries[2])){
167           $releases= split(",", $entries[2]);
169           foreach ($releases as $release){
170             $rname= preg_replace('/:.*$/', '', $release);
171             $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
172             $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
173             $test[$entries[1]]['RELEASE'][$rname]= array();
174             $test[$entries[1]]['RELEASE'][$rname]['SECTION']= $sections;
175             foreach ($classes as $class){
176               if ($class != ""){
177                 $test[$entries[1]]['RELEASE'][$rname]['PACKAGES'][$class]= $class;
178               }
179             }
180           }
181         }
182       }
183     }
184     
185     $this->FAIServRepConfig= $test;
187     /* Get arrays */
188     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
189       if (isset($this->attrs["$val"]["count"])){
190         for ($i= 0; $i<$this->attrs["count"]; $i++){
191           if (isset($this->attrs["$val"][$i])){
192             array_push($this->$val, $this->attrs["$val"][$i]);
193           }
194         }
195       }
196       sort ($this->$val);
197       $this->$val= array_unique($this->$val);
198     }
200     /* Parse Kernel Parameters to decide what boot mode is enabled */
201     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
202       $this->bootmode= "G";
203     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
204       $this->bootmode= "D";
205     } elseif ($this->gotoKernelParameters == "") {
206       $this->bootmode= "G";
207     } else {
208       $this->bootmode= "T";
209     }
210     if (preg_match("/ o /", $this->gotoKernelParameters)){
211       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
212     } else {
213       $this->customParameters= "";
214     }
216     /* Prepare Shares */
217     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
218       unset($this->attrs['gotoShare']['count']);
219       foreach($this->attrs['gotoShare'] as $share){
220         $tmp = $tmp2 = array();
221         $tmp = split("\|",$share);
222         $tmp2['server']      =$tmp[0];
223         $tmp2['name']        =$tmp[1];
224         $tmp2['mountPoint']  =$tmp[2];
225         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
226       }
227     }
229     $this->gotoShareSelections= $config->getShareList(true);
230     $this->gotoAvailableShares= $config->getShareList(false);
231     $tmp2 = array();
232   
233     if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
234       $tmp = array();
235       $tmp = split(" ",$this->FAIclass);
236       $tmp2 =array();  
237     
238       foreach($tmp as $class){
239         if( ":" == $class[0] ) {
240           $this->FAIrelease = substr( $class, 1 );
241         }
242         else
243           $tmp2[$class] = $class;
244       }
245       $this->FAIclass = $tmp2;
246     }
248     if(!is_array($this->FAIclass)){
249       $this->FAIclass =array();
250     }
252     $this->orig_dn= $this->dn;
254     /* Handle inheritance value "default" */
255     $this->gotoBootKernels= array("%default%" => '['._("inherited").']');
257     /* Get list of boot kernels */
258     if (isset($this->config->data['TABS'])){
259       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
261       if (!check_command($command)){
262         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
263             get_class($this));
264       } else {
265         $fh= popen($command, "r");
266         while (!feof($fh)) {
267           $buffer= trim(fgets($fh, 256));
268           
269           if ($buffer != ""){
270             $this->gotoBootKernels[preg_replace('/:.*$/', '', $buffer)]= $buffer;
271           }
272         }
273         pclose($fh);
274         ksort($this->gotoBootKernels);
275       }
276       
277     }
279   }
281   
282   /* This class is called by the contrucktor ONLY.
283    *   It return the available classes for each 
284    *    Server / Release combination ... 
285    *   (Release specifies which classes are available) 
286    */
287   function getAvailableClassesForThisRelease($release)
288   {
289     /* There could be more than one server providing this release,
290         so use cached result if available
291      */ 
292     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
293       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
294     }
296     /* Create cache with all classes 
297      */
298     if((!isset($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
299        (!is_array($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'])) ||
300        (count($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES']) ==0 )){
302       /* Get ldap connection */
303       $ldap   = $this->config->get_ldap_link();
304       $ldap->cd($this->config->current['BASE']);
306       /* Get possible classes ... 
307          This would be faste with some kind of caching ... 
308        */
309       $ldap->search("(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAIpartitionTable))",array("cn"),true);
310       /* Sort all entries, and attach elementtype.
311        * To be able to show the types in the listbox.
312        */
313       while($attr = $ldap->fetch()){
314         $_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'][] = $attr;
315       }  
316     }
318     /* Walk through cache and get out what we need.
319      *   
320      *   Function od : "$this->generateDNSyn($release)"
321      *    It returns an array like this one :
322      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
323      *            "ou=scripts.. " 
324      *             ...);
325      *   This helps us to select the correct classes for each release. 
326      *   It prevents errors like:  'siga' is selected as release, but all classes
327      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
328      */
329     $tmp2 = $this->generateDNSyn($release)     ; 
330     $test2 = array();
331     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
332       foreach($tmp2 as $dns){
333         if(preg_match("/".$dns."/",$attr['dn'])){
334           $test2[$attr['cn'][0]] = $attr['cn'][0];
335         }
336       }
337     }
338     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
339     return($test2);
340   }
343   /*  Create array to display available classes/profiles in a selectbox 
344    *   This function only displays the available classes.
345    *   If a class is available is defined by these facts : 
346    *     1. Is this class available for the selected release ?
347    *       - if it is available, check if the release is available for the selected server 
348    *         (done by $this->getFAIreleases())
349    *     2. Is this class currently not assigned to $this->FAIclass
350    */
351   function selectFriendlyClasses(){
352     $tmp=array();
354     /* check if the current release exists,
355         else select the first one ..
356      */
357     $tmp2 = $this->getFAIreleases();
358     if(!in_array($this->FAIrelease, $tmp2)){  
359       $this->FAIrelease = key($tmp2);
360     }
361  
362     /* Get all Packages for this server/release combination
363      */
364     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
365       $pkgs = array();
366       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
367     }else{
368       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
369     }
371     /* Check each and every single class name 
372      */
373     foreach($pkgs as $pkg){
374   
375       /* Class already assigned to the classes list ?
376        * If not ... go on
377        */
378       if(!in_array($pkg,$this->FAIclass)){
379         
380         /* Create the displayed list entry value
381             HKLMOP [-Pl P V T-] or something like that 
382          */
383         $str = "";
384         foreach($this->FAIclassInfo[$pkg] as $entry){
385           if(isset($entry['kzl'])){
386             $str .= $entry['kzl']." ";
387           }
388         }
389         
390         /* Append class if everyting was fine
391          */        
392         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
393       }
394     }
395     /* Just sort and return new classes list ...
396        ( possibly we should cache the result ... )
397      */
398     natcasesort ($tmp);
399     return($tmp);
400   }
402   function check()
403   {
404     $messages = array();
405     
406     /* Call common method to give check the hook */
407     $messages= plugin::check();
409     /* If there are packages selected, but no mirror show error */   
410     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
411       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
412     }
414     return($messages);
415   }
417   function execute()
418   {
420         /* Call parent execute */
421         plugin::execute();
423     /* Do we need to flip is_account state? */
424     if (isset($_POST['modify_state'])){
425       $this->is_account= !$this->is_account;
426     }
428     /* Do we represent a valid terminal? */
429     if (!$this->is_account && $this->parent == NULL){
430       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
431         _("This 'dn' has no terminal features.")."</b>";
432       return ($display);
433     }
435     /* Add module */
436     if (isset ($_POST['add_module'])){
437       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
438         $this->add_list ($this->gotoModules, $_POST['module']);
439       }
440     }
442     /* Delete module */
443     if (isset ($_POST['delete_module'])){
444       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
445         $this->del_list ($this->gotoModules, $_POST['modules_list']);
446       }
447     }
449     /* FAI class management */
450     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
451       $found = 0 ; 
453       /* If this new class/profile will attach a second partition table
454        * to our list of classes, abort and show a message.
455        */
456       foreach($this->FAIclass as $name){
457         if(isset($this->FAIclassInfo[$name])){
458           foreach($this->FAIclassInfo[$name] as $atr){
459             if(isset($atr['obj'])){
460               if($atr['obj'] == "FAIpartitionTable"){
461                 $found ++ ; 
462               }
463             }
464           }
465         }
466       }
468       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
469         print_red(_("There is already a profile in your selection that contain partition table configurations."));
470       }else{
471         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
472       }
473     }
475     $sort = false;
476     foreach($_POST as $name => $val){
477       
478       $sort_type = false;
479       if((preg_match("/sort_up/",$name))&&(!$sort)){
480         $sort_type = "sort_up_";
481       }
482       if((preg_match("/sort_down/",$name))&&(!$sort)){
483         $sort_type = "sort_down_";
484       }
485     
486       if(($sort_type)&&(!$sort)){
487         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
488         $sort = true;
489         
490         $last = -1;
491         $change_down  = -1;
492  
493         /* Create array with numeric index */ 
494         $tmp = array();
495         foreach($this->FAIclass as $class){
496           $tmp [] = $class;
497         }
499         /* Walk trough array */
500         foreach($tmp as $key => $faiName){
501           if($faiName == $value){
502             if($sort_type == "sort_up_"){
503               if($last != -1){
504                  $change_down= $last;
505               }
506             }else{
507               if(isset($tmp[$key+1])){
508                 $change_down = $key;
509               }
510             }
511           }
512           $last = $key;
513         }
514  
515         $tmp2 = array();
516         $skip = false;    
517   
518         foreach($tmp as $ky => $vl){
520           if($ky == $change_down){
521             $skip = $vl;
522           }else{
523             $tmp2[$vl] = $vl;
524           }
525           if(($skip != false)&&($ky != $change_down)){
526             $tmp2[$skip]  = $skip;
527             $skip =false;
528           }
529         }   
530         $this->FAIclass = $tmp2; 
531       }
532   
533       if(preg_match("/fai_remove/i",$name)){
534         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
535         unset($this->FAIclass[$value]);
536       }
537     }
539     /* Delete selected class from our list */
540     if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
541       if(isset($this->FAIclass[$_POST['FAIclassSel']])){
542         unset($this->FAIclass[$_POST['FAIclassSel']]);
543       }
544     }
546     /* Show main page */
547     $smarty= get_smarty();
548     $smarty->assign("SelectBoxLdapServer","");
550     /* In this section server shares will be defined
551      * A user can select one of the given shares and a mount point
552      *  and attach this combination to his setup.
553      */
554     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
555     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
557     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
558      * This entry will be, a combination of mountPoint and sharedefinitions
559      */
560     if(isset($_POST['gotoShareAdd'])){
561       /* We assign a share to this user, if we don't know where to mount the share */
562       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
563         print_red(_("You must specify a valid mount point."));
564       }else{
565         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
566         $s_mount = $_POST['gotoShareMountPoint'];
567         /* Preparing the new assignment */
568         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
569         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
570       }
571     }
573     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
574      * If there is no defined share selected, we will abort the deletion without any message
575      */
576     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
577       unset($this->gotoShares[$_POST['gotoShare']]);
578     }
580     $smarty->assign("gotoShares",$this->printOutAssignedShares());
581     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
582     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
584     /* Arrays */
585     $tmp = $this->config->data['SERVERS']['LDAP'];
587     /* Create divSelectBox for ldap server selection
588      */
589     $SelectBoxLdapServer = new divSelectBox("LdapServer");
590     $SelectBoxLdapServer->SetHeight(130);
592     /* Set first entry as selected, if $this->gotoLdapServer is empty
593      *  or given entry is no longer available ... 
594      */
595     $found = false;
596     foreach($tmp as $server){
597       if($this->gotoLdapServer==$server){
598         $found = true;
599       }
600     }
602     /* Add Entries 
603      */
604     foreach($tmp as $server){
605       $use ="";
606       if(($this->gotoLdapServer == $server) || ($found == false)) {
607         $found = true;
608         $use = " checked ";
609       };
611       if($server == "default"){
612         $display = "["._("inherited")."]";
613       }else{
614         $display = $server;
615       }
617       $SelectBoxLdapServer->AddEntry(
618           array(
619             array("string"=>$display),
620             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$server."' ".$use.">",
621                   "attach"=>"style='border-right:0px;'")
622             ));
623     }    
625     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
627     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
628     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
629       $smarty->assign("$val", $this->$val);
630     }
632     /* Values */
633     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
634       $smarty->assign($val, $this->$val);
635       $smarty->assign($val."ACL", chkacl($this->acl, $val));
636     }
638     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
639     $smarty->assign("FAIreleases",$this->getFAIreleases());
640     $smarty->assign("FAIrelease",$this->FAIrelease);
641     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
642     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
643     $smarty->assign("FAIclassKeys",$this->FAIclass);
644     
645     $div = new divSelectBox("WSFAIscriptClasses");
646     $div -> SetHeight("110");
647     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
648     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
649     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
650     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
652     $i = 1;
653     foreach($this->FAIclass as $class){
654       if($i==1){
655         $str = $str_empty.$str_down.$str_remove;
656       }elseif($i == count($this->FAIclass)){
657         $str = $str_up.$str_empty.$str_remove;
658       }else{
659         $str = $str_up.$str_down.$str_remove;
660       }
661       $i ++ ; 
663       $div->AddEntry(array(
664             array("string"=>$class),
665             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
666             ));
667     }  
669     $smarty->assign("FAIScriptlist",$div->DrawList()); 
671     /* Radio button group */
672     if (preg_match("/G/", $this->bootmode)) {
673       $smarty->assign("graphicalbootup", "checked");
674     } else {
675       $smarty->assign("graphicalbootup", "");
676     }
677     if (preg_match("/T/", $this->bootmode)) {
678       $smarty->assign("textbootup", "checked");
679     } else {
680       $smarty->assign("textbootup", "");
681     }
682     if (preg_match("/D/", $this->bootmode)) {
683       $smarty->assign("debugbootup", "checked");
684     } else {
685       $smarty->assign("debugbootup", "");
686     }
688     /* ACL's */
689     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
690       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
691     }
693     /* Show main page */
694     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
695   }
697   function remove_from_parent()
698   {
699     $this->handle_post_events("remove");
700   }
702   function generateDNSyn($release)
703   {
704     $str = "";
705     $tmp = split("\/",$release);
706     $tmp = array_reverse($tmp);
708     $base = ",ou=fai,";   
709  
710     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
712     foreach($tmp as $departmentname){
713       
714       $str .= ",ou=".$departmentname;
715     }
716     $ret = array();
717     foreach($arr as $ar){
718       $ret[] = ",ou=".$ar.$str.$base;
719     }
720     return($ret);
721   }
723   function getFAIdebianMirrors()
724   {
725     $ret = array();
726     $ret['auto']=_("automatic");
727     $secs  = array();
729     /* Walk through all available servers 
730         and check if they support the currently selected classes
731         if not, dont't add them to our list
732      */
733     foreach($this->FAIServRepConfig as $mirror => $rest){
735       $use = false;
737       if(count($this->FAIclass) == 0){
738         $use = true;
739       }else{
740         $tmp = $this->getFAIreleases();
741         foreach($tmp as $release){
742           if(isset($rest['RELEASE'][$release])){
743             $use =true;
744           }
745         } 
746       }
748       /* If current server, doesn't support this class
749           remove it from list
750        */
751       if($use){
752         $ret[$mirror] = $mirror;
753       }
754     }
755     return($ret);
756   }
758   function getFAIreleases() 
759   {
760     $ret = array();
762     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
763       $this->FAIdebianMirror = "auto";
764     }
766     $errorClasses = "";  
767   
768     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
769       $use = true;
770       
771       if(!count($this->FAIclass) == 0){
772         foreach($this->FAIclass as $class){
773           if(!in_array($class, $sections['PACKAGES'])){
774             $use = false;
775             $errorClasses[$class] = $class;
776           }else{
777             if(isset($errorClasses[$class])){
778               unset($errorClasses[$class]); 
779             }
780           }
781         }
782       }
783       if($use){
784         $ret[$release]=$release;
785       }
786     } 
787     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
789       $eClasses = " ";
790       foreach($errorClasses as $class){
791         $eClasses .= $class." ";
792       }
794       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));
795       $this->FAIdebianMirror = "auto";
796       return($this->getFAIreleases());
797     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
799       $eClasses = " ";
800       foreach($errorClasses as $class){
801         $eClasses .= $class." ";
802       }
803       
804       $this->FAIclass= array();
805       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));
806     }
807     return($ret);
808   }
810   /* Save data to object */
811   function save_object()
812   {
813     plugin::save_object();
815     /* Save group radio buttons */
816     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
817       $this->bootmode= $_POST["bootmode"];
818     }
820     /* Save kernel parameters */
821     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
822       $this->customParameters= $_POST["customParameters"];
823     }
824   }
827   /* Save to LDAP */
828   function save()
829   {
831     /* Depending on the baseobject (Ogroup / WS) we
832      *  use another set of objectClasses
833      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
834      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
835      */
836     if(isset($this->parent->by_object['ogroup'])){
837       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
838     }elseif(isset($this->parent->by_object['workgeneric'])){
839       $this->objectclasses = array("GOhard", "FAIobject");
840     }elseif(isset($this->parent->by_object['servgeneric'])){
841       $this->objectclasses = array("GOhard", "FAIobject");
842     }else{
843       print "Object Type Configuration : unknown";
844       exit();
845     }
847     /* Find proper terminal path for tftp configuration
848        FIXME: This is suboptimal when the default has changed to
849        another location! */
850     if ($this->gotoTerminalPath == "default"){
851       $ldap= $this->config->get_ldap_link();
853       /* Strip relevant part from dn, keep trailing ',' */
854       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
855       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
857       /* Walk from top to base and try to load default values for
858          'gotoTerminalPath'. Abort when an entry is found. */
859       while (TRUE){
860         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
862         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
863             $this->config->current['BASE'], array('gotoTerminalPath'));
864         $attrs= $ldap->fetch();
865         if (isset($attrs['gotoTerminalPath'])){
866           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
867           break;
868         }
870         /* Nothing left? */
871         if ($tmp == ""){
872           break;
873         }
874       }
875     }
877     /* Add semi automatic values */
878     // FIXME: LDAP Server may not be set here...
879     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
881     switch ($this->bootmode){
882       case "D":
883         $this->gotoKernelParameters.= " debug";
884       break;
885       case "G":
886         $this->gotoKernelParameters.= " splash=silent";
887       break;
888     }
889     if ($this->customParameters != ""){
890       $this->gotoKernelParameters.= " o ".$this->customParameters;
891     }
893     plugin::save();
895     unset( $this->attrs['FAIrelease'] );
896     
897     $str = "";
898     foreach($this->FAIclass as $class){
899       $str .= $class." ";
900     }
901     $str .= ":" . $this->FAIrelease;
902     $this->attrs['FAIclass']= "";
903     $this->attrs['FAIclass']= trim($str);
905     if(empty($this->attrs['FAIclass'])){
906       $this->attrs['FAIclass'] = array();
907     }
909     /* Add missing arrays */
910     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
911       if (isset ($this->$val) && count ($this->$val) != 0){
912     
913         $this->attrs["$val"]= array_unique($this->$val);
914       }
915       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
916     }
917     /* Strip out 'default' values */
918     if ($this->attrs['gotoLdapServer'] == "default"){
919       $this->attrs['gotoLdapServer']= array();
920     }
922     if ($this->attrs['gotoBootKernel'] == "%default%" || $this->attrs['gotoBootKernel'] == "default"){
923       $this->attrs['gotoBootKernel']= array();
924     }
926     /* if mirror == none stop saving this attribute */
927     if($this->FAIdebianMirror == "none"){
928       $this->FAIdebianMirror = "";
929     }
930    
931     /* Remove FAI objects if no FAI class is selected */ 
932     if(count($this->FAIclass)==0){
933       $tmp = array();
934       foreach($this->attrs['objectClass'] as $class){
935         if($class != "FAIobject"){
936           $tmp[] = $class;
937         }
938       }
939       $this->attrs['objectClass']     = $tmp;
940       $this->attrs['FAIclass']        = array();
941       $this->attrs['FAIdebianMirror'] = array();
942     }
944     /* prepare share settings */
945     $tmp = array();
946     foreach($this->gotoShares as $name => $settings){
947       $tmp2= split("\|",$name);
948       $name = $tmp2[0];
949       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
950     }
951     $this->attrs['gotoShare']=$tmp;
953     $ldap= $this->config->get_ldap_link();
954     $ldap->cd($this->dn);
955     $this->cleanup();
956     $ldap->modify ($this->attrs); 
958     show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
959     $this->handle_post_events("modify");
960   }
962   /* Add value to array, check if unique */
963   function add_list (&$array, $value)
964   {
965     if ($value != ""){
966       $array[]= $value;
967       sort($array);
968       array_unique ($array);
969     }
970   }
973   /* Delete value to array, check if unique */
974   function del_list (&$array, $list)
975   {
976     $tmp= array();
977     foreach ($array as $mod){
978       if (!in_array($mod, $list)){
979         $tmp[]= $mod;
980       }
981     }
982     $array= $tmp;
983   }
985   /* Generate ListBox frindly output for the defined shares
986    * Possibly Add or remove an attribute here,
987    */
988   function printOutAssignedShares()
989   {
990     $a_return = array();
991     if(is_array($this->gotoShares)){
992       foreach($this->gotoShares as $share){
993         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
994       }
995     }
996     return($a_return);
997   }
1000   function GetHookElements()
1001   {
1002     $ret = array();
1003     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1004     if(!empty($cmd)){
1005       $res = shell_exec($cmd);
1006       $res2 = trim($res);
1007       if((!$res)){
1008         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1009       }elseif(empty($res2)){
1010         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1011       }else{
1012         $tmp = split("\n",$res);
1013         foreach($tmp as $line){
1014           if(empty($line)) continue;
1015           $ret[]= $line;
1016         }
1017       }
1018     }
1019     return($ret);
1020   }
1024 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1025 ?>