Code

Flattened class detection. This will be done different in 2.6, actually.
[gosa.git] / plugins / admin / systems / class_workstationStartup.inc
1 <?php
3 class workstartup extends plugin
4 {
5   /* Generic terminal attributes */
6   var $bootmode             = "G";
7   var $goLdapServerList     = array();
8   var $gotoBootKernel       = "default-inherited";
9   var $gotoKernelParameters = "";
10   var $gotoLdapServer       = "default-inherited";
11   var $gotoModules          = array();
12   var $gotoAutoFs           = array();
13   var $gotoFilesystem       = array();
14   var $gotoTerminalPath     = "";
15   var $FAIstatus            = "";
16   var $gotoBootKernels      = array();
18   /* attribute list for save action */
19   var $attributes     = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
20   var $objectclasses  = array("GOhard", "FAIobject");
22   /* These vars are required to copy object groups !. */
23   var $CopyPasteVars  = array("gotoModules","gotoShares","customParameters","FAIclass","FAIrelease","FAIdebianMirror"); 
25   /* Share */
26   var $gotoShares         = array();// Currently Share Option
27   var $gotoShare          = "";     // currently selected Share Option
28   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
29   var $gotoAvailableShares= array();// Available Shares for this account
31   /* Helper */
32   var $customParameters   = "";
33   var $orig_dn            = "";
34   var $ignore_account     = TRUE;
35  
36   /* FAI class selection */ 
37   var $FAIclass           = array();
38   var $FAIclasses         = array();
39   var $FAIclassInfo       = array();
40   var $FAIrelease         = "";
41   var $FAIdebianMirror    = "auto";
43   var $unresolved_classes = array();
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   var $fai_activated      = FALSE;
54   var $member_of_ogroup   = FALSE;
56   var $o_group_dn         = "";
58   function workstartup ($config, $dn= NULL, $parent= NULL)
59   {
60     /* Cehck if FAI is activated, else do not save any FAI attributes */
61     $tmp = search_config($config->data,"faiManagement","CLASS");
62     if(!empty($tmp)){
63       $this->fai_activated = TRUE;
64     }else{
65       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
66       $this->objectclasses  = array("GOhard");
67     }
69     plugin::plugin ($config, $dn, $parent);
71     if(!isset($this->parent->by_object['ogroup'])){
72       $ldap = $this->config->get_ldap_link();
73       $ldap->cd ($this->config->current['BASE']);
74       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))",array("cn","dn"));
75       if($ldap->count()){
76         $this->member_of_ogroup = TRUE;
77         $attrs = $ldap->fetch();
78         $this->o_group_dn = $attrs['dn'];
79       }
80     }
82     /* Creating a list of valid Mirrors 
83      * none will not be saved to ldap.
84      */
85     $ldap   = $this->config->get_ldap_link();
86     $ldap->cd($this->config->current['BASE']);
88     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
89       $this->goLdapServerList[$server]= $server; // $this->config->data['SERVERS']['LDAP'];
90     }
92   
93     /* Perform some special FAI stuff, only if it is activated */
94     if($this->fai_activated){
96       $ui = get_userinfo();
97       $res = get_list(          "(|(objectClass=FAIpackageList)".
98           "(objectClass=FAItemplate)".
99           "(objectClass=FAIvariable)".
100           "(objectClass=FAIscript)".
101           "(objectClass=FAIhook)".
102           "(objectClass=FAIprofile)".
103           "(objectClass=FAIpartitionTable))",
104           $ui->subtreeACL,$this->config->current['BASE'],
105           array("cn","objectClass","FAIdebianSection","description"));
107       foreach($res as $attr){
108         $cn = $attr['cn'][0];
110         if(!isset($attr['description'])){
111           $attr['description'][0] = "";
112         }
114         if(in_array('FAIpackageList',$attr['objectClass'])){
115           $tmp2[$cn]['FAIpackageList']['obj']   = 'FAIpackageList'; 
116           $tmp2[$cn]['FAIpackageList']['kzl']   = 'Pl';
117           $tmp2[$cn]['FAIpackageList']['sec']   = $attr['FAIdebianSection'];
118           $tmp2[$cn]['FAIpackageList']['desc']  = $attr['description'];
119           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
120         }
121         if(in_array('FAItemplate',$attr['objectClass'])){
122           $tmp2[$cn]['FAItemplate']['obj']      = 'FAItemplate'; 
123           $tmp2[$cn]['FAItemplate']['kzl']      = 'T'; 
124           $tmp2[$cn]['FAItemplate']['desc']  = $attr['description'];
125           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
126         }
127         if(in_array('FAIvariable',$attr['objectClass'])){
128           $tmp2[$cn]['FAIvariable']['obj']      = 'FAIvariable'; 
129           $tmp2[$cn]['FAIvariable']['kzl']      = 'V'; 
130           $tmp2[$cn]['FAIvariable']['desc']  = $attr['description'];
131           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
132         }
133         if(in_array('FAIscript',$attr['objectClass'])){
134           $tmp2[$cn]['FAIscript']['obj']        = 'FAIscript'; 
135           $tmp2[$cn]['FAIscript']['kzl']        = 'S'; 
136           $tmp2[$cn]['FAIscript']['desc']  = $attr['description'];
137           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
138         }
139         if(in_array('FAIhook',$attr['objectClass'])){
140           $tmp2[$cn]['FAIhook']['obj']          = 'FAIhook'; 
141           $tmp2[$cn]['FAIhook']['kzl']          = 'H'; 
142           $tmp2[$cn]['FAIhook']['desc']  = $attr['description'];
143           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
144         }
145         if(in_array('FAIpartitionTable',$attr['objectClass'])){
146           $tmp2[$cn]['FAIpartitionTable']['obj']= 'FAIpartitionTable'; 
147           $tmp2[$cn]['FAIpartitionTable']['kzl']= 'Pt'; 
148           $tmp2[$cn]['FAIpartitionTable']['desc']  = $attr['description'];
149           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
150         }
151         if(in_array('FAIprofile',$attr['objectClass'])){
152           $tmp2[$cn]['FAIprofile']['obj']= 'FAIprofile'; 
153           $tmp2[$cn]['FAIprofile']['kzl']= 'P'; 
154           $tmp2[$cn]['FAIprofile']['desc']  = $attr['description'];
155           $this->FAIclasses[$attr['cn'][0]]=$attr['cn'][0];
156         }
157       }
158       if(is_array($this->FAIclasses)){
159         natcasesort($this->FAIclasses);
160       }
162       if(isset($tmp2)){
163         $this->FAIclassInfo = $tmp2;
164       } else {
165         $this->FAIclassInfo = array();
166       }
168       /* Build up a release array */
169       $filter= "";
170       $ui= get_userinfo();
171       if (isset($config->current['STRICT_UNITS']) && preg_match('/TRUE/i', $config->current['STRICT_UNITS']) && $ui->gosaUnitTag != ""){                                                                                                                                  $filter= "(gosaUnitTag=".$ui->gosaUnitTag.")";
172       }
173       
174       /* Fill up releases array */
175       $release_bases= array();
176       $res= get_list("(&(objectClass=FAIbranch)$filter)", $ui->subtreeACL, $this->config->current['BASE'], array());
177       foreach ($res as $value){
178         if (!preg_match('/,ou=(apps|mime),/', $value['dn'])){
179           $release_bases[$value['dn']]= $value['dn'];
180         }
181       }
183       /* Load all classes for each release */
184       $releases= array();
185       foreach($release_bases as $base){
186         $tmp= preg_replace('/,ou=fai,ou=configs,ou=systems,.*$/', '', $base);
187         $tmp= explode('ou=', trim(preg_replace('/ou=fai,ou=configs,ou=systems,.*$/', '', $tmp), ','));
188         $release= trim(implode('/', array_reverse($tmp)), '/');
189         foreach (array("disk", "hooks", "scripts", "packages", "profiles", "templates", "variables") as $type){
190           $res= get_list("(&(objectClass=FAIclass)$filter)", $ui->subtreeACL,
191                          "ou=$type,".$base, array(), GL_NONE);
192           foreach ($res as $value){
193             $name= preg_replace('/^[^=]+=([^,]+),.*$/', '\1', $value['dn']);
194             $releases[$release][]= $name;
195           }
196         }
198         sort($releases[$release]);
199         $releases[$release]= array_unique($releases[$release]);
200       }
202       /* Load all classes for this release */
203       $res= get_list("(&(objectClass=FAIbranch)$filter)", $ui->subtreeACL, $this->config->current['BASE'], array());
205       /* Fill up server array */
206       $ldap->search("(&(FAIrepository=*)(objectClass=FAIrepositoryServer)$filter)",array("FAIrepository"));
207       $test = array();
208       while($attr = $ldap->fetch()){
209         if(isset($attr['FAIrepository'])){
210           unset($attr['FAIrepository']['count']);
211           foreach($attr['FAIrepository'] as $rep){
212             list($url, $server, $release, $sections)= split("\|",$rep);
214             /* Assign non-auto releases */
215             $test[$url][$release]['SECTIONS'] = split(',', $sections);
216             $test[$url][$release]['CLASSES'] = isset($releases[$release])?$releases[$release]:array();
218             /* auto gets all releases/classes */
219             $test['auto'][$release]['SECTION'] = $sections;
220             $test['auto'][$release]['CLASSES'] = isset($releases[$release])?$releases[$release]:array();
221           }
222         }
223       }
225       /* Add possible elements from hook */
226       $lines= $this->GetHookElements();
227       foreach ($lines as $hline){
228         $entries= split(";", $hline);
229         if (isset($entries[1]) && !isset($test[$entries[1]])){
230           $test[$entries[1]]= array();
232           /* Split releases */
233           if (isset($entries[2])){
234             $releases= split(",", $entries[2]);
236             foreach ($releases as $release){
237               $rname= preg_replace('/:.*$/', '', $release);
238               $sections= split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release));
239               $classes= split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release));
240               $test[$entries[1]][$rname]= array();
241               $test[$entries[1]][$rname]['SECTION']= $sections;
242               foreach ($classes as $class){
243                 if ($class != ""){
244                   $test[$entries[1]][$rname]['CLASSES'][$class]= $class;
245                 }
246               }
247             }
248           }
249         }
250       }
252       $this->FAIServRepConfig= $test;
253     } // Do FAI stuff end   
255     /* Get arrays */
256     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
257       if (isset($this->attrs["$val"]["count"])){
258         for ($i= 0; $i<$this->attrs["count"]; $i++){
259           if (isset($this->attrs["$val"][$i])){
260             array_push($this->$val, $this->attrs["$val"][$i]);
261           }
262         }
263       }
264       sort ($this->$val);
265       $this->$val= array_unique($this->$val);
266       $this->saved_attributes[$val]= $this->$val;
267     }
269     /* Parse Kernel Parameters to decide what boot mode is enabled */
270     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
271       $this->bootmode= "G";
272     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
273       $this->bootmode= "D";
274     } elseif ($this->gotoKernelParameters == "") {
275       $this->bootmode= "G";
276     } else {
277       $this->bootmode= "T";
278     }
279     if (preg_match("/ o /", $this->gotoKernelParameters)){
280       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
281     } else {
282       $this->customParameters= "";
283     }
285     /* Prepare Shares */
286     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
287       unset($this->attrs['gotoShare']['count']);
288       foreach($this->attrs['gotoShare'] as $share){
289         $tmp = $tmp2 = array();
290         $tmp = split("\|",$share);
291         $tmp2['server']      =$tmp[0];
292         $tmp2['name']        =$tmp[1];
293         $tmp2['mountPoint']  =$tmp[2];
294         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
295       }
296     }
298     $this->gotoShareSelections= $config->getShareList(true);
299     $this->gotoAvailableShares= $config->getShareList(false);
300     $tmp2 = array();
303     /* Again some special FAI stuff */
304     if($this->fai_activated){ 
305       if((isset($this->FAIclass))&&(!is_array($this->FAIclass))){
306         $tmp = array();
307         $tmp = split(" ",$this->FAIclass);
308         $tmp2 =array();  
310         foreach($tmp as $class){
311           if( ":" == $class[0] ) {
312             $this->FAIrelease = substr( $class, 1 );
313           }
314           else
315             $tmp2[$class] = $class;
316         }
317         $this->FAIclass = $tmp2;
318       }
320       if(!is_array($this->FAIclass)){
321         $this->FAIclass =array();
322       }
323     }
325     $this->orig_dn= $this->dn;
327     /* Handle inheritance value "default" */
328     $this->gotoBootKernels= array();
331     /* Load hardware list */
332     if ($this->member_of_ogroup){
334       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
335         $this->FAIdebianMirror = "inherited";
336       }
338       if($this->fai_activated){
339         $map= array("gotoLdapServer","FAIclass","FAIdebianMirror","gotoBootKernel");
340       }else{
341         $map= array("gotoLdapServer","gotoBootKernel");
342       }
344       $ldap = $this->config->get_ldap_link();
345       $ldap->cat($this->o_group_dn);
346       $attrs= $ldap->fetch();
348       foreach ($map as $name){
349         if (!isset($attrs[$name][0])){
350           continue;
351         }
353         switch ($name){
354           case 'gotoLdapServer':
355             $this->goLdapServerList= array_merge(array('default-inherited' => _("inherited").' ['.$attrs[$name][0].']' ), $this->goLdapServerList);
356             break;
358           case 'gotoBootKernel':
359             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
360             break;
362           case 'FAIclass':
363             $str = split(":",$attrs[$name][0]);
364             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
365             $this->InheritedFAIrelease  = trim($str[1]);
366             break;
368           case 'FAIdebianMirror':
369             $this->InheritedFAIdebianMirror = $attrs[$name][0];
370             break;
371         }
372       }
373     }
375     /* Get list of boot kernels */
376     if (isset($this->config->data['TABS'])){
377       $command= search_config($this->config->data['TABS'], get_class($this), "KERNELS");
379       if (!check_command($command)){
380         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
381             get_class($this));
382       } else {
383         
384         $first = false; 
385         $fh= popen($command, "r");
386         while (!feof($fh)) {
387           $buffer= trim(fgets($fh, 256));
388   
389           if(!empty($buffer)){
391             $name=$value = $buffer;
392             if(preg_match("/:/",$buffer)){
393               $name = preg_replace("/:.*$/","",$buffer);
394               $value= preg_replace("/^.*:/","",$buffer);
395               $this->gotoBootKernels[$name]= $name.":".$value;
396             }else{
397               $this->gotoBootKernels[$name]= $value;
398             }
399             if($this->gotoBootKernel =="" ){
400               $this->gotoBootKernel = $name;
401             }
403           }
404         }
405         pclose($fh);
406       }
407     }
409     /* Turn to default, if we've nothing to inherit */
410     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
411       $this->gotoBootKernel= "default";
412     }
414   }
416   
417   /*  Create array to display available classes/profiles in a selectbox 
418    *   This function only displays the available classes.
419    *   If a class is available is defined by these facts : 
420    *     1. Is this class available for the selected release ?
421    *       - if it is available, check if the release is available for the selected server 
422    *         (done by $this->getFAIreleases())
423    *     2. Is this class currently not assigned to $this->FAIclass
424    */
425   function selectFriendlyClasses(){
426     $tmp=array();
428     if($this->FAIdebianMirror == "inherited") return($tmp);
430     /* check if the current release exists,
431         else select the first one ..
432      */
433     $tmp2 = $this->getFAIreleases();
434     if(!isset($tmp2[$this->FAIrelease]) || !$tmp2[$this->FAIrelease]['USE']){
435       foreach($tmp2 as $key => $data){
436         if($data['USE']){
437           $this->FAIrelease = $key;
438         }
439       }
440     }
441     if(!in_array($this->FAIrelease, $tmp2)){  
442     #  $this->FAIrelease = key($tmp2);
443     }
444  
445     /* Get all Packages for this server/release combination
446      */
448     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror][$this->FAIrelease]['CLASSES'])){
449       $pkgs = array();
450       print_red(_("There are packages in your configuration, which can't be resolved with current server/release settings."));
451     }else{
452       $pkgs = $this->FAIServRepConfig[$this->FAIdebianMirror][$this->FAIrelease]['CLASSES'];
453     }
455     /* Check each and every single class name 
456      */
457     foreach($pkgs as $pkg){
458   
459       /* Class already assigned to the classes list ?
460        * If not ... go on
461        */
462       if(!in_array($pkg,$this->FAIclass)){
463         
464         /* Create the displayed list entry value
465             HKLMOP [-Pl P V T-] or something like that 
466          */
467         $str = "";
468         foreach($this->FAIclassInfo[$pkg] as $entry){
469           if(isset($entry['kzl'])){
470             $str .= $entry['kzl']." ";
471           }
472         }
473         
474         /* Append class if everyting was fine
475          */        
476         $tmp[$pkg] = $pkg." [-".trim($str)."-]";
477       }
478     }
479     /* Just sort and return new classes list ...
480        ( possibly we should cache the result ... )
481      */
482     natcasesort ($tmp);
483     return($tmp);
484   }
486   function check()
487   {
488     $messages = array();
489     
490     /* Call common method to give check the hook */
491     $messages= plugin::check();
493     /* If there are packages selected, but no mirror show error */   
494     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
495       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
496     }
498     return($messages);
499   }
501   function execute()
502   {
503         /* Call parent execute */
504         plugin::execute();
506     /* Do we need to flip is_account state? */
507     if (isset($_POST['modify_state'])){
508       $this->is_account= !$this->is_account;
509     }
511     /* Do we represent a valid terminal? */
512     if (!$this->is_account && $this->parent == NULL){
513       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
514         _("This 'dn' has no terminal features.")."</b>";
515       return ($display);
516     }
518     /* Add module */
519     if (isset ($_POST['add_module']) ){
520       if ($_POST['module'] != "" && chkacl ($this->acl, "gotoModule") == ""){
521         $this->add_list ($this->gotoModules, $_POST['module']);
522       }
523     }
525     /* Delete module */
526     if (isset ($_POST['delete_module'])){
527       if (count($_POST['modules_list']) && chkacl ($this->acl, "gotoModule") == ""){
528         $this->del_list ($this->gotoModules, $_POST['modules_list']);
529       }
530     }
531     
532     /* FAI class management */
533     if($this->fai_activated && chkacl($this->acl,"FAIclass") == ""){
535       if((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))){
536         $found = 0 ; 
538         /* If this new class/profile will attach a second partition table
539          * to our list of classes, abort and show a message.
540          */
541         foreach($this->FAIclass as $name){
542           if(isset($this->FAIclassInfo[$name])){
543             foreach($this->FAIclassInfo[$name] as $atr){
544               if(isset($atr['obj'])){
545                 if($atr['obj'] == "FAIpartitionTable"){
546                   $found ++ ; 
547                 }
548               }
549             }
550           }
551         }
553         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
554           print_red(_("There is already a profile in your selection that contain partition table configurations."));
555         }else{
556           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
557         }
558       }
560       $sort = false;
561       foreach($_POST as $name => $val){
562         
563         $sort_type = false;
564         if((preg_match("/sort_up/",$name))&&(!$sort)){
565           $sort_type = "sort_up_";
566         }
567         if((preg_match("/sort_down/",$name))&&(!$sort)){
568           $sort_type = "sort_down_";
569         }
570       
571         if(($sort_type)&&(!$sort)){
572           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
573           $sort = true;
574           
575           $last = -1;
576           $change_down  = -1;
577    
578           /* Create array with numeric index */ 
579           $tmp = array();
580           foreach($this->FAIclass as $class){
581             $tmp [] = $class;
582           }
584           /* Walk trough array */
585           foreach($tmp as $key => $faiName){
586             if($faiName == $value){
587               if($sort_type == "sort_up_"){
588                 if($last != -1){
589                    $change_down= $last;
590                 }
591               }else{
592                 if(isset($tmp[$key+1])){
593                   $change_down = $key;
594                 }
595               }
596             }
597             $last = $key;
598           }
599    
600           $tmp2 = array();
601           $skip = false;    
602     
603           foreach($tmp as $ky => $vl){
605             if($ky == $change_down){
606               $skip = $vl;
607             }else{
608               $tmp2[$vl] = $vl;
609             }
610             if(($skip != false)&&($ky != $change_down)){
611               $tmp2[$skip]  = $skip;
612               $skip =false;
613             }
614           }   
615           $this->FAIclass = $tmp2; 
616         }
617     
618         if(preg_match("/fai_remove/i",$name)){
619           $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
620           unset($this->FAIclass[$value]);
621         }
622       }
623     }
625     /* Show main page */
626     $smarty= get_smarty();
627     $smarty->assign("SelectBoxLdapServer","");
629     /* In this section server shares will be defined
630      * A user can select one of the given shares and a mount point
631      *  and attach this combination to his setup.
632      */
633     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
634     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
636     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
637      * This entry will be, a combination of mountPoint and sharedefinitions
638      */
639     if(isset($_POST['gotoShareAdd']) && chkacl($this->acl,"gotoShare") ==""){
640       /* We assign a share to this user, if we don't know where to mount the share */
641       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
642         print_red(_("You must specify a valid mount point."));
643       }else{
644         if(count($this->gotoAvailableShares)){
645           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
646           $s_mount = $_POST['gotoShareMountPoint'];
647           /* Preparing the new assignment */
648           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
649           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
650         }
651       }
652     }
654     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
655      * If there is no defined share selected, we will abort the deletion without any message
656      */
657     if((isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare'])) && chkacl($this->acl,"gotoShare") ==""){
658       unset($this->gotoShares[$_POST['gotoShare']]);
659     }
661     $smarty->assign("gotoShares",$this->printOutAssignedShares());
662     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
663     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
664     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
666     /* Arrays */
667     $tmp = $this->goLdapServerList;
669     /* Create divSelectBox for ldap server selection
670      */
671     $SelectBoxLdapServer = new divSelectBox("LdapServer");
672     $SelectBoxLdapServer->SetHeight(130);
674     /* Set first entry as selected, if $this->gotoLdapServer is empty
675      *  or given entry is no longer available ... 
676      */
677     $found = false;
678     foreach($tmp as $server){
679       if($this->gotoLdapServer==$server){
680         $found = true;
681       }
682     }
684     /* Add Entries 
685      */
686     foreach($tmp as $key => $server){
687       $use ="";
688       if(($this->gotoLdapServer == $server) || ($found == false)) {
689         $found = true;
690         $use = " checked ";
691       };
693       $use .= chkacl($this->acl,"gotoLdapServer");
695       $display = $server;
697       $SelectBoxLdapServer->AddEntry(
698           array(
699             array("string"=>"<input type='radio' name='gotoLdapServer' value='".$key."' ".$use.">",
700                   "attach"=>"style='border-left:0px;'"),
701             array("string"=>$display)
702             ));
703     }    
705     $smarty->assign("SelectBoxLdapServer",$SelectBoxLdapServer->DrawList());
707     $smarty->assign("gotoLdapServerACL", chkacl($this->acl, "gotoLdapServer"));
708     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
709       $smarty->assign("$val", $this->$val);
710     }
712     /* Values */
713     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
714       $smarty->assign($val, $this->$val);
715       $smarty->assign($val."ACL", chkacl($this->acl, $val));
716     }
718     $smarty->assign("fai_activated",$this->fai_activated);
719     if($this->fai_activated){
720       $smarty->assign("FAIdebianMirrors",$this->getFAIdebianMirrors());
721       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
722       $smarty->assign("FAIreleases",$this->getFAIreleases());
723       $smarty->assign("FAIrelease",$this->FAIrelease);
724       $smarty->assign("FAIclasses",$this->selectFriendlyClasses());
725       $smarty->assign("FAIclassesKeys",array_flip($this->selectFriendlyClasses()));
726       $smarty->assign("FAIclassKeys",$this->FAIclass);
727       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
728     
729       $div = new divSelectBox("WSFAIscriptClasses");
730       $div -> SetHeight("110");
731       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
732       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
733       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
734       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
736       $i = 1;
738       if($this->FAIdebianMirror == "inherited"){
739         $tmp = $this->InheritedFAIclass;
740       }else{
741         $tmp = $this->FAIclass;
742       }
744       foreach($tmp as $class){
746         $marker = "";
747         if(in_array_ics($class,$this->unresolved_classes)){
748           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
749         }
751         if($this->FAIdebianMirror == "inherited"){
752           $str = "";
753         }else{
754           if($i==1){
755             $str = $str_empty.$str_down.$str_remove;
756           }elseif($i == count($this->FAIclass)){
757             $str = $str_up.$str_empty.$str_remove;
758           }else{
759             $str = $str_up.$str_down.$str_remove;
760           }
761         }
762         $i ++ ; 
763   
764         $desc = ""; 
765         foreach($this->FAIclassInfo[$class] as $types ){
766           if(isset($types['desc'][0])){
767             $desc.= $types['desc'][0]." ";
768           }
769         }
770         if(!empty($desc)){
771           $desc = "&nbsp;[".trim($desc)."]";
772         }        
774         $div->AddEntry(array(
775               array("string"=>$class.$desc.$marker),
776               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
777               ));
778       }  
779       $smarty->assign("FAIScriptlist",$div->DrawList()); 
780     }
782     /* Radio button group */
783     if (preg_match("/G/", $this->bootmode)) {
784       $smarty->assign("graphicalbootup", "checked");
785     } else {
786       $smarty->assign("graphicalbootup", "");
787     }
788     if (preg_match("/T/", $this->bootmode)) {
789       $smarty->assign("textbootup", "checked");
790     } else {
791       $smarty->assign("textbootup", "");
792     }
793     if (preg_match("/D/", $this->bootmode)) {
794       $smarty->assign("debugbootup", "checked");
795     } else {
796       $smarty->assign("debugbootup", "");
797     }
799     /* ACL's */
800     foreach (array("gotoKernelParameters", "gotoModules", "gotoFilesystem","FAIclass") as $value){
801       $smarty->assign($value."ACL", chkacl($this->acl, "$value"));
802     }
804     /* Show main page */
805     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
806   }
808   function remove_from_parent()
809   {
810     $this->handle_post_events("remove");
811   }
813   function generateDNSyn($release)
814   {
815     $str = "";
816     $tmp = split("\/",$release);
817     $tmp = array_reverse($tmp);
819     $base = ",ou=fai,";   
820  
821     $arr = array("scripts","hooks","disk","variables","templates","profiles","packages");
823     foreach($tmp as $departmentname){
824       
825       $str .= ",ou=".$departmentname;
826     }
827     $ret = array();
828     foreach($arr as $ar){
829       $ret[] = ",ou=".$ar.$str.$base;
830     }
831     return($ret);
832   }
834   function getFAIdebianMirrors()
835   {
836     $ret = array();
838     /* Only add inherit option, if we are part in an object group 
839      */
840     if($this->member_of_ogroup)    {
841       $ret['inherited']['NAME']="["._("inherited")."]";
842       $ret['inherited']['USE'] = TRUE;
843     }
845     $ret['auto']['NAME']=_("automatic");
846     $ret['auto']['USE'] = TRUE;
847     $secs  = array();
849     /* Walk through all available servers 
850         and check if they support the currently selected classes
851         if not, dont't add them to our list
852      */
853     foreach($this->FAIServRepConfig as $mirror => $rest){
855       /* Automatically selection is available everytime */
856       if($mirror == "auto"){
857         continue;
858       }
860       $use = false;
861       if(count($this->FAIclass) == 0){
862         $use = true;
863       }else{
864         $tmp = $this->getFAIreleases();
865         foreach($tmp as $release => $data){
866           if(isset($rest[$release]) && $release == $this->FAIrelease){
867             $use = $data['USE']; 
868           }
869         } 
870       }
872       /* If current server, doesn't support this class
873           remove it from list
874        */
875       $ret[$mirror]['NAME'] = $mirror;
876       $ret[$mirror]['USE'] = $use;
877     }
878     return($ret);
879   }
881   function getFAIreleases() 
882   {
883     $ret = array();
885     if($this->FAIdebianMirror == "inherited") {
886       return(array());
887     }
889     if(!isset($this->FAIServRepConfig[$this->FAIdebianMirror])){
890       $this->FAIdebianMirror = "auto";
891     }
893     $errorClasses = array();
894     if(isset($this->FAIServRepConfig[$this->FAIdebianMirror])) {
895       foreach($this->FAIServRepConfig[$this->FAIdebianMirror] as $release => $sections){
896         $use = true;
898         if(!count($this->FAIclass) == 0){
899           foreach($this->FAIclass as $class){
900             if(!in_array($class, $sections['CLASSES'])){
901               $use = false;
902               $errorClasses[$class] = $class;
903             }else{
904               if(isset($errorClasses[$class])){
905                 unset($errorClasses[$class]);
906               }
907             }
908           }
909         }
910         $ret[$release]['NAME']=$release;
911         $ret[$release]['USE']=$use;
912       }
913     }
915     if((count($ret) == 0 ) && ($this->FAIdebianMirror != "auto")){
917       $eClasses = " ";
918       foreach($errorClasses as $class){
919         $eClasses .= $class." ";
920       }
922       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));
923       $this->FAIdebianMirror = "auto";
924       return($this->getFAIreleases());
925     }elseif((count($ret) == 0 ) && ($this->FAIdebianMirror == "auto")){
927       $eClasses = " ";
928       foreach($errorClasses as $class){
929         $eClasses .= $class." ";
930       }
932       $this->unresolved_classes = $errorClasses;
933       $this->FAIdebianMirror = "auto";
934       //$this->FAIclass= array();
935       print_red(sprintf(_("Can't resolve the given FAIclass(es) [%s] anyway, please check your FAI configurations, possibly some classes where deleted or renamed. Server was reset to 'auto'."),$eClasses));
936     }
937     return($ret);
938   }
940   /* Save data to object */
941   function save_object()
942   {
943     plugin::save_object();
945     /* Save group radio buttons */
946     if (chkacl ($this->acl, "bootmode") == "" && isset($_POST["bootmode"])){
947       $this->bootmode= $_POST["bootmode"];
948     }
950     /* Save kernel parameters */
951     if (chkacl ($this->acl, "gotoKernelParameters") == "" && isset($_POST["customParameters"])){
952       $this->customParameters= $_POST["customParameters"];
953     }
955   }
958   /* Save to LDAP */
959   function save()
960   {
962     /* Depending on the baseobject (Ogroup / WS) we
963      *  use another set of objectClasses
964      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
965      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
966      */
967     if(isset($this->parent->by_object['ogroup'])){
968       $this->objectclasses = array("gotoWorkstationTemplate");
969     }elseif(isset($this->parent->by_object['workgeneric'])){
970       $this->objectclasses = array("GOhard");
971     }elseif(isset($this->parent->by_object['servgeneric'])){
972       $this->objectclasses = array("GOhard");
973     }else{
974       print "Object Type Configuration : unknown";
975       exit();
976     }
978     if($this->fai_activated){
979       $this->objectclasses [] = "FAIobject";
980     }
982     /* Find proper terminal path for tftp configuration
983        FIXME: This is suboptimal when the default has changed to
984        another location! */
985     if (($this->gotoTerminalPath == "default")){
986       $ldap= $this->config->get_ldap_link();
988       /* Strip relevant part from dn, keep trailing ',' */
989       $tmp= preg_replace("/^cn=[^,]+,ou=terminals,ou=systems,/i", "", $this->dn);
990       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
992       /* Walk from top to base and try to load default values for
993          'gotoTerminalPath'. Abort when an entry is found. */
994       while (TRUE){
995         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
997         $ldap->cat("cn=default,ou=terminals,ou=systems,$tmp".
998             $this->config->current['BASE'], array('gotoTerminalPath'));
999         $attrs= $ldap->fetch();
1000         if (isset($attrs['gotoTerminalPath'])){
1001           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
1002           break;
1003         }
1005         /* Nothing left? */
1006         if ($tmp == ""){
1007           break;
1008         }
1009       }
1010     }
1012     /* Add semi automatic values */
1013     // FIXME: LDAP Server may not be set here...
1014     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
1016     switch ($this->bootmode){
1017       case "D":
1018         $this->gotoKernelParameters.= " debug";
1019       break;
1020       case "G":
1021         $this->gotoKernelParameters.= " splash=silent";
1022       break;
1023     }
1024     if ($this->customParameters != ""){
1025       $this->gotoKernelParameters.= " o ".$this->customParameters;
1026     }
1028     plugin::save();
1031     if($this->fai_activated){
1033       unset( $this->attrs['FAIrelease'] );
1034       
1035       $str = "";
1037       if($this->FAIdebianMirror == "inherited"){
1038     
1039         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
1041       }else{
1043         foreach($this->FAIclass as $class){
1044           $str .= $class." ";
1045         }
1046         $str .= ":" . $this->FAIrelease;
1047         $this->attrs['FAIclass']= "";
1048         $this->attrs['FAIclass']= trim($str);
1050         if(empty($this->attrs['FAIclass'])){
1051           $this->attrs['FAIclass'] = array();
1052         }
1053       }
1055       /* if mirror == none stop saving this attribute */
1056       if($this->FAIdebianMirror == "none"){
1057         $this->FAIdebianMirror = "";
1058       }
1059     }
1061     /* Add missing arrays */
1062     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
1063       if (isset ($this->$val) && count ($this->$val) != 0){
1064     
1065         $this->attrs["$val"]= array_unique($this->$val);
1066       }
1067       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
1068     }
1070     /* Strip out 'default' values */
1071     if ($this->attrs['gotoLdapServer'] == "default-inherited"){
1072       $this->attrs['gotoLdapServer']= array();
1073     }
1075     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
1076       $this->attrs['gotoBootKernel']= array();
1077     }
1079     $ldap= $this->config->get_ldap_link();
1080     $ldap->cd($this->dn);
1082     /* Get FAIstate from object, the generic tab could have changed it during execute */
1083     if($this->fai_activated){
1084       $ldap->cat($this->dn,array("FAIstate"));
1085       $checkFAIstate = $ldap->fetch();
1087       /* Remove FAI objects if no FAI class is selected */ 
1088       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
1089         $this->attrs['FAIclass']        = array();
1090         $this->attrs['FAIdebianMirror'] = array();
1091       }
1092     }
1094     /* prepare share settings */
1095     $tmp = array();
1096     foreach($this->gotoShares as $name => $settings){
1097       $tmp2= split("\|",$name);
1098       $name = $tmp2[0];
1099       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
1100     }
1101     $this->attrs['gotoShare']=$tmp;
1103     $this->cleanup();
1104     $ldap->modify ($this->attrs); 
1106     show_ldap_error($ldap->get_error(), _("Saving workstation startup settings failed"));
1107     $this->handle_post_events("modify");
1108   }
1110   /* Add value to array, check if unique */
1111   function add_list (&$array, $value)
1112   {
1113     if ($value != ""){
1114       $array[]= $value;
1115       sort($array);
1116       array_unique ($array);
1117     }
1118   }
1121   /* Delete value to array, check if unique */
1122   function del_list (&$array, $list)
1123   {
1124     $tmp= array();
1125     foreach ($array as $mod){
1126       if (!in_array($mod, $list)){
1127         $tmp[]= $mod;
1128       }
1129     }
1130     $array= $tmp;
1131   }
1133   /* Generate ListBox frindly output for the defined shares
1134    * Possibly Add or remove an attribute here,
1135    */
1136   function printOutAssignedShares()
1137   {
1138     $a_return = array();
1139     if(is_array($this->gotoShares)){
1140       foreach($this->gotoShares as $share){
1141         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1142       }
1143     }
1144     return($a_return);
1145   }
1148   function GetHookElements()
1149   {
1150     $ret = array();
1151     $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
1152     if(!empty($cmd)){
1153       $res = shell_exec($cmd);
1154       $res2 = trim($res);
1155       if((!$res)){
1156         print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s' please check your gosa.conf."),$cmd));
1157       }elseif(empty($res2)){
1158         print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
1159       }else{
1160         $tmp = split("\n",$res);
1161         foreach($tmp as $line){
1162           if(empty($line)) continue;
1163           $ret[]= $line;
1164         }
1165       }
1166     }
1167     return($ret);
1168   }
1172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1173 ?>