Code

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