Code

cf0ca57859be926af756894445f528c6c4b78545
[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));
323           $name= $value = $buffer;
325           if(preg_match("/:/",$buffer)){
326             $name  = preg_replace("/:.*$/","",$buffer);
327             $value = preg_replace("/^.*:/","",$buffer);
328           }
330           if ($buffer != ""){
331             $this->gotoBootKernels[$name]= $value;
332           }
333         }
334         pclose($fh);
335       }
336     }
338     if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
339       $this->FAIdebianMirror = "inherited";
340     }
341   }
343   
344   /* This class is called by the contrucktor ONLY.
345    *   It return the available classes for each 
346    *    Server / Release combination ... 
347    *   (Release specifies which classes are available) 
348    */
349   function getAvailableClassesForThisRelease($release)
350   {
351     /* There could be more than one server providing this release,
352         so use cached result if available
353      */ 
354     if(isset($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]))  {
355       return($_SESSION['getAvailableClassesForThisRelease_CACHE'][$release]);
356     }
358     /* Walk through cache and get out what we need.
359      *   
360      *   Function od : "$this->generateDNSyn($release)"
361      *    It returns an array like this one :
362      *       array("ou=packges,ou=rc0.9.2,ou=siga,", 
363      *            "ou=scripts.. " 
364      *             ...);
365      *   This helps us to select the correct classes for each release. 
366      *   It prevents errors like:  'siga' is selected as release, but all classes
367      *     with ou='siga' in their dn are shown, also ou=rc...,ou=siga...  
368      */
369     $tmp2 = $this->generateDNSyn($release)     ; 
370     $test2 = array();
371     foreach($_SESSION['getAvailableClassesForThisRelease_CACHED_CLASSES'] as $attr){  
372       foreach($tmp2 as $dns){
373         if(preg_match("/".$dns."/",$attr['dn'])){
374           $test2[$attr['cn'][0]] = $attr['cn'][0];
375         }
376       }
377     }
378     $_SESSION['getAvailableClassesForThisRelease_CACHE'][$release] = $test2;
379     return($test2);
380   }
383   /*  Create array to display available classes/profiles in a selectbox 
384    *   This function only displays the available classes.
385    *   If a class is available is defined by these facts : 
386    *     1. Is this class available for the selected release ?
387    *       - if it is available, check if the release is available for the selected server 
388    *         (done by $this->getFAIreleases())
389    *     2. Is this class currently not assigned to $this->FAIclass
390    */
391   function selectFriendlyClasses(){
392     $tmp=array();
394     if($this->FAIdebianMirror == "inherited") return($tmp);
396     /* check if the current release exists,
397         else select the first one ..
398      */
399     $tmp2 = $this->getFAIreleases();
400     if(!in_array($this->FAIrelease, $tmp2)){  
401       $this->FAIrelease = key($tmp2);
402     }
403  
404     /* Get all Packages for this server/release combination
405      */
406     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'])){
407       $pkgs = array();
408       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
409     }else{
410       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'][$this->FAIrelease]['PACKAGES'];
411     }
413     /* Check each and every single class name 
414      */
415     foreach($pkgs as $pkg){
416   
417       /* Class already assigned to the classes list ?
418        * If not ... go on
419        */
420       if(!in_array($pkg,$this->FAIclass)){
421         
422         /* Create the displayed list entry value
423             HKLMOP [-Pl P V T-] or something like that 
424          */
425         $str = "";
426         foreach($this->FAIclassInfo[$pkg] as $entry){
427           if(isset($entry['kzl'])){
428             $str .= $entry['kzl']." ";
429           }
430         }
431         
432         /* Append class if everyting was fine
433          */        
434         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
435       }
436     }
437     /* Just sort and return new classes list ...
438        ( possibly we should cache the result ... )
439      */
440     natcasesort ($tmp);
441     return($tmp);
442   }
444   function check()
445   {
446     $messages = array();
447     
448     /* Call common method to give check the hook */
449     $messages= plugin::check();
451     /* If there are packages selected, but no mirror show error */   
452     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
453       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
454     }
456     return($messages);
457   }
459   function execute()
460   {
462         /* Call parent execute */
463         plugin::execute();
465     /* Do we need to flip is_account state? */
466     if (isset($_POST['modify_state'])){
467       $this->is_account= !$this->is_account;
468     }
470     /* Do we represent a valid terminal? */
471     if (!$this->is_account && $this->parent == NULL){
472       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
473         _("This 'dn' has no terminal features.")."</b>";
474       return ($display);
475     }
477     /* Add module */
478     if (isset ($_POST['add_module'])){
479       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
480         $this->add_list ($this->gotoModules, $_POST['module']);
481       }
482     }
484     /* Delete module */
485     if (isset ($_POST['delete_module'])){
486       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
487         $this->del_list ($this->gotoModules, $_POST['modules_list']);
488       }
489     }
491     /* FAI class management */
492     if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
493       $found = 0 ; 
495       /* If this new class/profile will attach a second partition table
496        * to our list of classes, abort and show a message.
497        */
498       foreach($this->FAIclass as $name){
499         if(isset($this->FAIclassInfo[$name])){
500           foreach($this->FAIclassInfo[$name] as $atr){
501             if(isset($atr['obj'])){
502               if($atr['obj'] == "FAIpartitionTable"){
503                 $found ++ ; 
504               }
505             }
506           }
507         }
508       }
510       if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
511         print_red(_("There is already a profile in your selection that contain partition table configurations."));
512       }else{
513         $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
514       }
515     }
517     $sort = false;
518     foreach($_POST as $name => $val){
519       
520       $sort_type = false;
521       if((preg_match("/sort_up/",$name))&&(!$sort)){
522         $sort_type = "sort_up_";
523       }
524       if((preg_match("/sort_down/",$name))&&(!$sort)){
525         $sort_type = "sort_down_";
526       }
527     
528       if(($sort_type)&&(!$sort)){
529         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
530         $sort = true;
531         
532         $last = -1;
533         $change_down  = -1;
534  
535         /* Create array with numeric index */ 
536         $tmp = array();
537         foreach($this->FAIclass as $class){
538           $tmp [] = $class;
539         }
541         /* Walk trough array */
542         foreach($tmp as $key => $faiName){
543           if($faiName == $value){
544             if($sort_type == "sort_up_"){
545               if($last != -1){
546                  $change_down= $last;
547               }
548             }else{
549               if(isset($tmp[$key+1])){
550                 $change_down = $key;
551               }
552             }
553           }
554           $last = $key;
555         }
556  
557         $tmp2 = array();
558         $skip = false;    
559   
560         foreach($tmp as $ky => $vl){
562           if($ky == $change_down){
563             $skip = $vl;
564           }else{
565             $tmp2[$vl] = $vl;
566           }
567           if(($skip != false)&&($ky != $change_down)){
568             $tmp2[$skip]  = $skip;
569             $skip =false;
570           }
571         }   
572         $this->FAIclass = $tmp2; 
573       }
574   
575       if(preg_match("/fai_remove/i",$name)){
576         $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
577         unset($this->FAIclass[$value]);
578       }
579     }
581     /* Show main page */
582     $smarty= get_smarty();
583     $smarty->assign("SelectBoxLdapServer","");
585     /* In this section server shares will be defined
586      * A user can select one of the given shares and a mount point
587      *  and attach this combination to his setup.
588      */
589     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
590     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
592     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
593      * This entry will be, a combination of mountPoint and sharedefinitions
594      */
595     if(isset($_POST['gotoShareAdd'])){
596       /* We assign a share to this user, if we don't know where to mount the share */
597       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
598         print_red(_("You must specify a valid mount point."));
599       }else{
600         if(count($this->gotoAvailableShares)){
601           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
602           $s_mount = $_POST['gotoShareMountPoint'];
603           /* Preparing the new assignment */
604           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
605           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
606         }
607       }
608     }
610     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
611      * If there is no defined share selected, we will abort the deletion without any message
612      */
613     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
614       unset($this->gotoShares[$_POST['gotoShare']]);
615     }
617     $smarty->assign("gotoShares",$this->printOutAssignedShares());
618     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
619     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
620     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
622     /* Arrays */
623     $tmp = $this->goLdapServerList;
625     /* Create divSelectBox for ldap server selection
626      */
627     $SelectBoxLdapServer = new divSelectBox("LdapServer");
628     $SelectBoxLdapServer->SetHeight(130);
630     /* Set first entry as selected, if $this->gotoLdapServer is empty
631      *  or given entry is no longer available ... 
632      */
633     $found = false;
634     foreach($tmp as $server){
635       if($this->gotoLdapServer==$server){
636         $found = true;
637       }
638     }
640     /* Add Entries 
641      */
642     foreach($tmp as $key => $server){
643       $use ="";
644       if(($this->gotoLdapServer == $server) || ($found == false)) {
645         $found = true;
646         $use = " checked ";
647       };
649       $display = $server;
651       $SelectBoxLdapServer->AddEntry(
652           array(
653             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
654                   "attach"=>"style='border-left:0px;'"),
655             array("string"=>$display)
656             ));
657     }    
659     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
661     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
662     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
663       $smarty->assign("$val", $this->$val);
664     }
666     /* Values */
667     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
668       $smarty->assign($val, $this->$val);
669       $smarty->assign($val."ACL", chkacl($this->acl, $val));
670     }
672     $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
673     $smarty->assign("FAIreleases",$this->getFAIreleases());
674     $smarty->assign("FAIrelease",$this->FAIrelease);
675     $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
676     $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
677     $smarty->assign("FAIclassKeys",$this->FAIclass);
678     $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
679     
680     $div = new divSelectBox("WSFAIscriptClasses");
681     $div -> SetHeight("110");
682     $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
683     $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
684     $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
685     $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
687     $i = 1;
689     if($this->FAIdebianMirror == "inherited"){
690       $tmp = $this->InheritedFAIclass;
691     }else{
692       $tmp = $this->FAIclass;
693     }
695     foreach($tmp as $class){
697       if($this->FAIdebianMirror == "inherited"){
698         $str = "";
699       }else{
700         if($i==1){
701           $str = $str_empty.$str_down.$str_remove;
702         }elseif($i == count($this->FAIclass)){
703           $str = $str_up.$str_empty.$str_remove;
704         }else{
705           $str = $str_up.$str_down.$str_remove;
706         }
707       }
708       $i ++ ; 
710       $div->AddEntry(array(
711             array("string"=>$class),
712             array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
713             ));
714     }  
716     $smarty->assign("FAIScriptlist",$div->DrawList()); 
718     /* Radio button group */
719     if (preg_match("/G/", $this->bootmode)) {
720       $smarty->assign("graphicalbootup", "checked");
721     } else {
722       $smarty->assign("graphicalbootup", "");
723     }
724     if (preg_match("/T/", $this->bootmode)) {
725       $smarty->assign("textbootup", "checked");
726     } else {
727       $smarty->assign("textbootup", "");
728     }
729     if (preg_match("/D/", $this->bootmode)) {
730       $smarty->assign("debugbootup", "checked");
731     } else {
732       $smarty->assign("debugbootup", "");
733     }
735     /* ACL's */
736     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
737       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
738     }
740     /* Show main page */
741     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
742   }
744   function remove_from_parent()
745   {
746     $this->handle_post_events("remove");
747   }
749   function generateDNSyn($release)
750   {
751     $str = "";
752     $tmp = split("\/",$release);
753     $tmp = array_reverse($tmp);
755     $base = ",ou=fai,";   
756  
757     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
759     foreach($tmp as $departmentname){
760       
761       $str .= ",ou=".$departmentname;
762     }
763     $ret = array();
764     foreach($arr as $ar){
765       $ret[] = ",ou=".$ar.$str.$base;
766     }
767     return($ret);
768   }
770   function getFAIdebianMirrors()
771   {
772     $ret = array();
773     $ret['inherited']="["._("inherited")."]";
774     $ret['auto']=_("automatic");
775     $secs  = array();
777     /* Walk through all available servers 
778         and check if they support the currently selected classes
779         if not, dont't add them to our list
780      */
781     foreach($this->FAIServRepConfig as $mirror => $rest){
783       $use = false;
785       if(count($this->FAIclass) == 0){
786         $use = true;
787       }else{
788         $tmp = $this->getFAIreleases();
789         foreach($tmp as $release){
790           if(isset($rest['RELEASE'][$release])){
791             $use =true;
792           }
793         } 
794       }
796       /* If current server, doesn't support this class
797           remove it from list
798        */
799       if($use){
800         $ret[$mirror] = $mirror;
801       }
802     }
803     return($ret);
804   }
806   function getFAIreleases() 
807   {
808     $ret = array();
810     if($this->FAIdebianMirror == "inherited") return(array());
812     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
813       $this->FAIdebianMirror = "auto";
814     }
816     $errorClasses = "";  
817   
818     foreach($this->FAIServRepConfig[$this->FAIdebianMirror]['RELEASE'] as $release => $sections){
819       $use = true;
820       
821       if(!count($this->FAIclass) == 0){
822         foreach($this->FAIclass as $class){
823           if(!in_array($class, $sections['PACKAGES'])){
824             $use = false;
825             $errorClasses[$class] = $class;
826           }else{
827             if(isset($errorClasses[$class])){
828               unset($errorClasses[$class]); 
829             }
830           }
831         }
832       }
833       if($use){
834         $ret[$release]=$release;
835       }
836     } 
837     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
839       $eClasses = " ";
840       foreach($errorClasses as $class){
841         $eClasses .= $class." ";
842       }
844       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));
845       $this->FAIdebianMirror = "auto";
846       return($this->getFAIreleases());
847     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
849       $eClasses = " ";
850       foreach($errorClasses as $class){
851         $eClasses .= $class." ";
852       }
853       
854       $this->FAIclass= array();
855       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));
856     }
857     return($ret);
858   }
860   /* Save data to object */
861   function save_object()
862   {
863     plugin::save_object();
865     /* Save group radio buttons */
866     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
867       $this->bootmode= $_POST["bootmode"];
868     }
870     /* Save kernel parameters */
871     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
872       $this->customParameters= $_POST["customParameters"];
873     }
875   }
878   /* Save to LDAP */
879   function save()
880   {
882     /* Depending on the baseobject (Ogroup / WS) we
883      *  use another set of objectClasses
884      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
885      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
886      */
887     if(isset($this->parent->by_object['ogroup'])){
888       $this->objectclasses = array("gotoWorkstationTemplate", "FAIobject");
889     }elseif(isset($this->parent->by_object['workgeneric'])){
890       $this->objectclasses = array("GOhard", "FAIobject");
891     }elseif(isset($this->parent->by_object['servgeneric'])){
892       $this->objectclasses = array("GOhard", "FAIobject");
893     }else{
894       print "Object Type Configuration : unknown";
895       exit();
896     }
898     /* Find proper terminal path for tftp configuration
899        FIXME: This is suboptimal when the default has changed to
900        another location! */
901     if (($this->gotoTerminalPath == "default")){
902       $ldap= $this->config->get_ldap_link();
904       /* Strip relevant part from dn, keep trailing ',' */
905       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
906       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
908       /* Walk from top to base and try to load default values for
909          'gotoTerminalPath'. Abort when an entry is found. */
910       while (TRUE){
911         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
913         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
914             $this->config->current['BASE'], array('gotoTerminalPath'));
915         $attrs= $ldap->fetch();
916         if (isset($attrs['gotoTerminalPath'])){
917           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
918           break;
919         }
921         /* Nothing left? */
922         if ($tmp == ""){
923           break;
924         }
925       }
926     }
928     /* Add semi automatic values */
929     // FIXME: LDAP Server may not be set here...
930     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
932     switch ($this->bootmode){
933       case "D":
934         $this->gotoKernelParameters.= " debug";
935       break;
936       case "G":
937         $this->gotoKernelParameters.= " splash=silent";
938       break;
939     }
940     if ($this->customParameters != ""){
941       $this->gotoKernelParameters.= " o ".$this->customParameters;
942     }
944     plugin::save();
946     unset( $this->attrs['FAIrelease'] );
947     
948     $str = "";
950     if($this->FAIdebianMirror == "inherited"){
951   
952       $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
954     }else{
956       foreach($this->FAIclass as $class){
957         $str .= $class." ";
958       }
959       $str .= ":" . $this->FAIrelease;
960       $this->attrs['FAIclass']= "";
961       $this->attrs['FAIclass']= trim($str);
963       if(empty($this->attrs['FAIclass'])){
964         $this->attrs['FAIclass'] = array();
965       }
966     }
968     /* Add missing arrays */
969     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
970       if (isset ($this->$val) && count ($this->$val) != 0){
971     
972         $this->attrs["$val"]= array_unique($this->$val);
973       }
974       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
975     }
977     /* Strip out 'default' values */
978     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
979       $this->attrs['gotoLdapServer']= array();
980     }
982     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
983       $this->attrs['gotoBootKernel']= array();
984     }
986     /* if mirror == none stop saving this attribute */
987     if($this->FAIdebianMirror == "none"){
988       $this->FAIdebianMirror = "";
989     }
990    
991     /* Get FAIstate from object, the generic tab could have changed it during execute */
992     $ldap= $this->config->get_ldap_link();
993     $ldap->cd($this->dn);
994     $ldap->cat($this->dn,array("FAIstate"));
995     $checkFAIstate = $ldap->fetch();
997     /* Remove FAI objects if no FAI class is selected */ 
998     if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
999       $tmp = array();
1000       foreach($this->attrs['objectClass'] as $class){
1001         if($class != "FAIobject"){
1002           $tmp[] = $class;
1003         }
1004       }
1005       $this->attrs['objectClass']     = $tmp;
1006       $this->attrs['FAIclass']        = array();
1007       $this->attrs['FAIdebianMirror'] = array();
1008     }
1010     /* prepare share settings */
1011     $tmp = array();
1012     foreach($this->gotoShares as $name => $settings){
1013       $tmp2= split("\|",$name);
1014       $name = $tmp2[0];
1015       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1016     }
1017     $this->attrs['gotoShare']=$tmp;
1019     $this->cleanup();
1020     $ldap->modify ($this->attrs); 
1022     show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1023     $this->handle_post_events("modify");
1024   }
1026   /* Add value to array, check if unique */
1027   function add_list (&$array, $value)
1028   {
1029     if ($value != ""){
1030       $array[]= $value;
1031       sort($array);
1032       array_unique ($array);
1033     }
1034   }
1037   /* Delete value to array, check if unique */
1038   function del_list (&$array, $list)
1039   {
1040     $tmp= array();
1041     foreach ($array as $mod){
1042       if (!in_array($mod, $list)){
1043         $tmp[]= $mod;
1044       }
1045     }
1046     $array= $tmp;
1047   }
1049   /* Generate ListBox frindly output for the defined shares
1050    * Possibly Add or remove an attribute here,
1051    */
1052   function printOutAssignedShares()
1053   {
1054     $a_return = array();
1055     if(is_array($this->gotoShares)){
1056       foreach($this->gotoShares as $share){
1057         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1058       }
1059     }
1060     return($a_return);
1061   }
1064   function GetHookElements()
1065   {
1066     $ret = array();
1067     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1068     if(!empty($cmd)){
1069       $res = shell_exec($cmd);
1070       $res2 = trim($res);
1071       if((!$res)){
1072         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1073       }elseif(empty($res2)){
1074         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1075       }else{
1076         $tmp = split("\n",$res);
1077         foreach($tmp as $line){
1078           if(empty($line)) continue;
1079           $ret[]= $line;
1080         }
1081       }
1082     }
1083     return($ret);
1084   }
1088 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1089 ?>