Code

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