Code

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