Code

Followup commit for #3020
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* Ldap server list */
5   var $gotoLdapServers    = array();
6   var $gotoLdapServerList = array();
7   var $gotoLdap_inherit   = FALSE;
9   /* Generic terminal attributes */
10   var $bootmode             = "G";
11   var $gotoBootKernel       = "default-inherited";
12   var $gotoKernelParameters = "";
13   var $gotoLdapServer       = "default-inherited";
14   var $gotoModules          = array();
15   var $gotoAutoFs           = array();
16   var $gotoFilesystem       = array();
17   var $gotoTerminalPath     = "";
18   var $gotoBootKernels      = array();
20   /* attribute list for save action */
21   var $attributes           = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", 
22                                     "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
23   var $objectclasses        = array("GOhard", "FAIobject");
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 $orig_dn            = "";
33   var $ignore_account     = TRUE;
34  
35   /* FAI class selection */ 
36   var $FAIclass           = array();  // The currently selected classes 
37   var $FAIrelease           = "";
38   var $FAIdebianMirror      = "auto";
39   var $si_active            = FALSE;
40   var $si_fai_action_failed = FALSE;
42   var $cache              = array(); // Used as cache in fai mehtods
44   var $FAIstatus          = "";
45   var $FAIclasses         = array();
47   var $view_logged        = FALSE;
48   
49   /* FAI class selection */
50   var $InheritedFAIclass       = array();
51   var $InheritedFAIrelease     = "";
52   var $InheritedFAIdebianMirror= "auto";
54   var $CopyPasteVars    = array("gotoModules","gotoShares");
55   var $fai_activated    = FALSE;
56   var $o_group_dn       = "";
57   var $member_of_ogroup = FALSE;
59   function workstartup (&$config, $dn= NULL, $parent= NULL)
60   {
61     /* Check if FAI is active */
62     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
63     if(!empty($tmp) && class_available("faiManagement")){
64       $this->fai_activated = TRUE;
65     }else{
66       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
67       $this->objectclasses  = array("GOhard");
68     }
70     plugin::plugin ($config, $dn, $parent);
72     /* Check for si daemon */
73     $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
75     /* Check object group membership */
76     if(!isset($this->parent->by_object['ogroup'])){
77       $ldap = $this->config->get_ldap_link();
78       $ldap->cd ($this->config->current['BASE']);
79       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
80       if($ldap->count()){
81         $this->member_of_ogroup = TRUE;
82         $attrs = $ldap->fetch();
83         $this->o_group_dn = $attrs['dn'];
84       }
85     }
87     /* Creating a list of valid Mirrors 
88      * none will not be saved to ldap.
89      */
90     $ldap   = $this->config->get_ldap_link();
91     $ldap->cd($this->config->current['BASE']);
92     $ui = get_userinfo();
93     foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
94       if($ui->get_category_permissions($data['dn'],"server",TRUE)){
95         for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
96           $name = $data["cn"][0].":".$data["goLdapBase"][$i];
97           $this->gotoLdapServerList[]= $name; 
98         }
99       }
100     }
102     /* Get list of assigned ldap servers 
103      */ 
104     if(isset($this->attrs['gotoLdapServer'])){
105       unset($this->attrs['gotoLdapServer']['count']);
106       sort($this->attrs['gotoLdapServer']);
107       foreach($this->attrs['gotoLdapServer'] as $value){
108         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
109       }
110     } 
111     natcasesort($this->gotoLdapServerList);
113     if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ 
114       $this->gotoLdap_inherit = TRUE;
115     }
117     /* FAI Initialization
118        Skip this if FAI is not activated 
119      */
120     if($this->fai_activated) {
122       /* Parse used FAIclasses (stored as string).
123        * The single classes are seperated by ' '.
124        * There is also the release type given, after first
125        *  occurrence of ':'.
126        */
127       $this->FAIclass =array();
128       if(isset($this->attrs['FAIclass'][0])){
129         $tmp = split(" ",$this->attrs['FAIclass'][0]);
130         $tmp2 =array();  
132         foreach($tmp as $class){
133           if( ":" == $class[0] ) {
134             $this->FAIrelease = trim(substr($class, 1));
135           }else{
136             $tmp2[$class] = $class;
137           }
138         }
139         $this->FAIclass = $tmp2;
140       }
141     }
143     /* Get arrays */
144     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
145       if (isset($this->attrs["$val"]["count"])){
146         for ($i= 0; $i<$this->attrs["count"]; $i++){
147           if (isset($this->attrs["$val"][$i])){
148             array_push($this->$val, $this->attrs["$val"][$i]);
149           }
150         }
151       }
152       sort ($this->$val);
153       $this->$val= array_unique($this->$val);
154     }
156     /* Prepare Shares */
157     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
158       unset($this->attrs['gotoShare']['count']);
159       foreach($this->attrs['gotoShare'] as $share){
160         $tmp = $tmp2 = array();
161         $tmp = split("\|",$share);
162         $tmp2['server']      =$tmp[0];
163         $tmp2['name']        =$tmp[1];
164         $tmp2['mountPoint']  =$tmp[2];
165         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
166       }
167     }
169     $this->gotoShareSelections= $config->getShareList(true);
170     $this->gotoAvailableShares= $config->getShareList(false);
171     $tmp2 = array();
172   
174     $this->orig_dn= $this->dn;
176     /* Handle inheritance value "default" */
177     if ($this->member_of_ogroup){
178       $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); 
179     }
181     /* If we are member in an object group,
182      *  we have to handle inherited values.
183      * So you can see what is inherited.
184      */
185     if ($this->member_of_ogroup){
187       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
188         $this->FAIdebianMirror = "inherited";
189       }
191       if($this->fai_activated){
192         $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
193       }else{
194         $map= array("gotoBootKernel");
195       }
197       $ldap = $this->config->get_ldap_link();
198       $ldap->cat($this->o_group_dn);
199       $attrs= $ldap->fetch();
201       foreach ($map as $name){
202         if (!isset($attrs[$name][0])){
203           continue;
204         }
206         switch ($name){
207           case 'gotoBootKernel':
208             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
209             break;
211           case 'FAIclass':
212             $str = split(":",$attrs[$name][0]);
213             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
214             $this->InheritedFAIrelease  = trim($str[1]);
215             break;
217           case 'FAIdebianMirror':
218             $this->InheritedFAIdebianMirror = $attrs[$name][0];
219             break;
220         }
221       }
222     }
224     $this->update_fai_cache();
226     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
228       /* Check if the current mirror is available 
229        */
230       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
231         if(count($this->FAIclass)){
232           msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
233         }
234         $this->FAIdebianMirror = "auto";
235         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
236         $this->cache['CLASSES'] = array();
237         $this->update_fai_cache();
238       }
239   
240       /* Check if the current mirror is available 
241        */
242       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
243         $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); 
244         if(count($this->FAIclass)){
245           msg_dialog::display(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianMirror,$new_release), ERROR_DIALOG);
246         }
247         $this->FAIrelease = $new_release;
248         $this->cache['CLASSES'] = array();
249         $this->update_fai_cache();
250       }
251     }
252   }
254   
255   function check()
256   {
257     $messages = array();
258     
259     /* Call common method to give check the hook */
260     $messages= plugin::check();
262     /* If there are packages selected, but no mirror show error */   
263     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
264       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
265     }
267     return($messages);
268   }
270   function execute()
271   {
272         /* Call parent execute */
273         plugin::execute();
275     if($this->is_account && !$this->view_logged){
276       $this->view_logged = TRUE;
277       new log("view","workstation/".get_class($this),$this->dn);
278     }
280     /* Do we represent a valid terminal? */
281     if (!$this->is_account && $this->parent === NULL){
282       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
283         msgPool::noValidExtension(_("workstation"))."</b>";
284       return ($display);
285     }
287     /* Add module */
288     if (isset ($_POST['add_module'])){
289       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
290         $this->add_list ($this->gotoModules, $_POST['module']);
291       }
292     }
294     /* Delete module */
295     if (isset ($_POST['delete_module'])){
296       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
297         $this->del_list ($this->gotoModules, $_POST['modules_list']);
298       }
299     }
301     /* FAI class management */
302     if($this->fai_activated){
303       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
304         $found = 0 ; 
306         /* If this new class/profile will attach a second partition table
307          * to our list of classes, abort and show a message.
308          */
309         foreach($this->FAIclass as $name){
310           # FIXME: Where does FAIclassInfo come from??
311           if(isset($this->FAIclassInfo[$name])){
312             foreach($this->FAIclassInfo[$name] as $atr){
313               if(isset($atr['obj'])){
314                 if($atr['obj'] == "FAIpartitionTable"){
315                   $found ++ ; 
316                 }
317               }
318             }
319           }
320         }
322         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
323           msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
324         }else{
325           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
326         }
327       }
329       $sort = false;
331       /* Move one used class class one position up or down */
332       if($this->acl_is_writeable("FAIclass")){
333         foreach($_POST as $name => $val){
335           $sort_type = false;
336           if((preg_match("/sort_up/",$name))&&(!$sort)){
337             $sort_type = "sort_up_";
338           }
339           if((preg_match("/sort_down/",$name))&&(!$sort)){
340             $sort_type = "sort_down_";
341           }
343           if(($sort_type)&&(!$sort)){
344             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
345             $sort = true;
347             $last = -1;
348             $change_down  = -1;
350             /* Create array with numeric index */ 
351             $tmp = array();
352             foreach($this->FAIclass as $class){
353               $tmp [] = $class;
354             }
356             /* Walk trough array */
357             foreach($tmp as $key => $faiName){
358               if($faiName == $value){
359                 if($sort_type == "sort_up_"){
360                   if($last != -1){
361                     $change_down= $last;
362                   }
363                 }else{
364                   if(isset($tmp[$key+1])){
365                     $change_down = $key;
366                   }
367                 }
368               }
369               $last = $key;
370             }
372             $tmp2 = array();
373             $skip = false;    
375             foreach($tmp as $ky => $vl){
377               if($ky == $change_down){
378                 $skip = $vl;
379               }else{
380                 $tmp2[$vl] = $vl;
381               }
382               if(($skip != false)&&($ky != $change_down)){
383                 $tmp2[$skip]  = $skip;
384                 $skip =false;
385               }
386             }   
387             $this->FAIclass = $tmp2; 
388           }
390           if(preg_match("/fai_remove/i",$name)){
391             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
392             unset($this->FAIclass[$value]);
393             if($this->FAIclass == array()){
394               /* class list is emtpy. Check whether the system is part of an object group and set
395               the FAI mirror to "inherited" in this case. */
396               if ($this->member_of_ogroup){
397                 $this->FAIdebianMirror = "inherited";
398               } 
399             }
400           }
401         }
402       }
404       /* Delete selected class from our list */
405       if($this->acl_is_writeable("FAIclass")){
406         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
407           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
408             unset($this->FAIclass[$_POST['FAIclassSel']]);
409           }
410         }
411       }
412     }// END fai handling
414     /* Show main page */
415     $smarty= get_smarty();
417     /* Assign ACLs to smarty */
418     $tmp = $this->plInfo();
419     foreach($tmp['plProvidedAcls'] as $name => $translation){
420       $smarty->assign($name."ACL",$this->getacl($name));
421     } 
423     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
425     /* In this section server shares will be defined
426      * A user can select one of the given shares and a mount point
427      *  and attach this combination to his setup.
428      */
429     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
430     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
432     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
433      * This entry will be, a combination of mountPoint and sharedefinitions
434      */
435     if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
436       /* We assign a share to this user, if we don't know where to mount the share */
437       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
438         msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
439       }else{
440     
441         if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
442           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
443           $s_mount = $_POST['gotoShareMountPoint'];
444           /* Preparing the new assignment */
445           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
446           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
447         }
448       }
449     }
451     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
452      * If there is no defined share selected, we will abort the deletion without any message
453      */
454     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
455       unset($this->gotoShares[$_POST['gotoShare']]);
456     }
458     $smarty->assign("gotoShares",$this->printOutAssignedShares());
459     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
460     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
461     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
463     /* Create divSelectBox for ldap server selection
464      */
465     $SelectBoxLdapServer = new divSelectBox("LdapServer");
466     $SelectBoxLdapServer->SetHeight(130);
468     /* Add new ldap server to the list */
469     if($this->acl_is_writeable("gotoLdapServer") && 
470         !$this->gotoLdap_inherit && 
471         isset($_POST['add_ldap_server']) && 
472         isset($_POST['ldap_server_to_add'])){
473       if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
474         $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
475         if(!in_array($to_add,$this->gotoLdapServers)){
476           $this->gotoLdapServers[] = $to_add;
477         }
478       }
479     }
480     
481     /* Move ldap servers up and down */
482     if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
483       foreach($_POST as $name => $value){
484         if(preg_match("/sort_ldap_up_/",$name)){
485           $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
486           $from =  $id;  
487           $to   =  $id -1;
488           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
489           if($tmp){
490             $this->gotoLdapServers = $tmp;
491           }
492           break;
493         }
494         if(preg_match("/sort_ldap_down_/",$name)){
495           $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
496           $from =  $id;  
497           $to   =  $id +1;
498           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
499           if($tmp){
500             $this->gotoLdapServers = $tmp;
501           }
502           break;
503         }
504         if(preg_match("/gotoLdapRemove_/",$name)){
505           $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
506           $value = $this->gotoLdapServers[$id];
507           $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
508           break;
509         }
510       } 
511     }
512   
513     /* Add Entries */
514     if($this->acl_is_readable("gotoLdapServer")){
516       foreach($this->gotoLdapServers as $key => $server){
518         /* Announce missing entries */
519         if(!in_array($server,$this->gotoLdapServerList)){
520           $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
521         }
523         /* Convert old style entry */
524         if (!preg_match('%:ldaps?://%', $server)){
525           $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
527         /* Beautify new style entries */
528       } else {
529         $server= preg_replace("/^[^:]+:/", "", $server);
530       }
532       $SelectBoxLdapServer->AddEntry(
533           array(array("string" => $server),
534             array("string" => 
535               "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'>&nbsp;".
536               "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'>&nbsp;".
537               "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
538               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
539       }    
540     }    
542     if($this->gotoLdap_inherit){
543       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
544     }else{
545       $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
546     }
547     
548     $list = array();
549     foreach($this->gotoLdapServerList as $key => $entry){
550       if(!in_array($entry,$this->gotoLdapServers)){
552         /* Convert old style entry */
553         if (!preg_match('%:ldap[s]*://%', $entry)){
554           $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
556         /* Beautify new style entries */
557         } else {
558           $entry= preg_replace("/^[^:]+:/", "", $entry);
559         }
561         $list[$key] = $entry;
562       }
563     }
564     $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
565     $smarty->assign("gotoLdapServerList", $list);
566     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
567     $smarty->assign("JS",  session::get('js'));
569     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
570       $smarty->assign("$val", $this->$val);
571     }
573     /* Values */
574     foreach(array("gotoBootKernel","gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
575       $smarty->assign($val, $this->$val);
576     }
578     $smarty->assign("fai_activated",$this->fai_activated);
580     /* Create FAI output */
581     $this->update_fai_cache();
582     $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
583     $smarty->assign("si_active",$this->si_active);
585     $div = new divSelectBox("WSFAIscriptClasses");
586     $div -> SetHeight("110");
587   
588     if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
590       $smarty->assign("FAIservers"  , $this->cache['SERVERS']);
591       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
592       $smarty->assign("FAIrelease"  , $this->FAIrelease);
593       $smarty->assign("FAIclasses"  , $this->selectable_classes());
595       /* Get classes for release from cache.
596        * Or build cache
597        */
598       if($this->FAIdebianMirror == "inherited"){
599         $release = $this->InheritedFAIrelease;
600       }else{
601         $release = $this->FAIrelease;
602       }
604       $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
605       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
607       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
608       if($this->acl_is_writeable("FAIclass")){
609         $str_up     = " &nbsp;<input type='image' src='images/lists/sort-up.png'    name='sort_up_%s'    value='%s'>";
610         $str_down   = " &nbsp;<input type='image' src='images/lists/sort-down.png'  name='sort_down_%s'  value='%s'>";
611         $str_remove = " &nbsp;<input type='image' src='images/lists/trash.png'  name='fai_remove_%s' value='%s'>";
612       }else{
613         $str_up=$str_down=$str_remove=$str_empty;
614       }
616       /* Get classes */
617       if($this->FAIdebianMirror == "inherited"){
618         $tmp = $this->InheritedFAIclass;
619       }else{
620         $tmp = $this->FAIclass;
621       }
623       /* Get invalid classes */
624       $invalid = $this->get_invalid_classes($tmp);
626       /* Draw every single entry */
627       $i = 1;
628       if($this->acl_is_readable("FAIclass")){
629         foreach($tmp as $class){
630           /* Mark invalid classes. (Not in selected release)
631            */
632           $marker = "";
633           if(in_array_ics($class,$invalid)){
634             $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
635           }
637           /* Create up/down priority icons  
638            * Skip this, if we have inherited the FAI classes.
639            */
640           if($this->FAIdebianMirror == "inherited"){
641             $str = "";
642           }else{
643             if($i==1){
644               $str = $str_empty.$str_down.$str_remove;
645             }elseif($i == count($this->FAIclass)){
646               $str = $str_up.$str_empty.$str_remove;
647             }else{
648               $str = $str_up.$str_down.$str_remove;
649             }
650           }
651           $i ++ ; 
653           /*  Get used FAI types from the class 
654            */ 
655           if(!$marker) {
656             $types = $this->get_fai_types_string($class, true);
657           }
658           else {
659             $types = "";
660           }
662           $div->AddEntry(array(
663             array("string"=>$class.$marker),
664             array("string"=>$types),
665                 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
666                 ));
667         }  
668       }// END FAI output generation 
669     }// END FAI output generation 
670     $smarty->assign("FAIScriptlist",$div->DrawList()); 
672     /* Radio button group */
673     if (preg_match("/G/", $this->bootmode)) {
674       $smarty->assign("graphicalbootup", "checked");
675     } else {
676       $smarty->assign("graphicalbootup", "");
677     }
678     if (preg_match("/T/", $this->bootmode)) {
679       $smarty->assign("textbootup", "checked");
680     } else {
681       $smarty->assign("textbootup", "");
682     }
683     if (preg_match("/D/", $this->bootmode)) {
684       $smarty->assign("debugbootup", "checked");
685     } else {
686       $smarty->assign("debugbootup", "");
687     }
689     /* Show main page */
690     $smarty->assign("gotoKernelParameters",$this->gotoKernelParameters);
691     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
692   }
695   function remove_from_parent()
696   {
697     $this->handle_post_events("remove");
698     new log("remove","workstation/".get_class($this),$this->dn);
699   }
702   /* Save data to object */
703   function save_object()
704   {
705     $old_mirror  = $this->FAIdebianMirror;
706     plugin::save_object();
708     /* Update release */
709     if($old_mirror != $this->FAIdebianMirror){
710       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
711         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
712       }
713     }
715     /* Clear FAI class list if FAI mirror has been set to inherited */
716     if($this->FAIdebianMirror == "inherited"){
717       $this->FAIclass =array();
718     }
720     if(isset($_POST['WorkstationStarttabPosted'])){
721       if(isset($_POST['gotoLdap_inherit'])){
722         $this->gotoLdap_inherit = TRUE;
723       }else{
724         $this->gotoLdap_inherit = FALSE;
725       }
727       /* Save group radio buttons */
728       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
729         $this->bootmode= $_POST["bootmode"];
730       }
731     }
732   }
735   /* Save to LDAP */
736   function save()
737   {
739     /* Depending on the baseobject (Ogroup / WS) we
740      *  use another set of objectClasses
741      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
742      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
743      */
744     if(isset($this->parent->by_object['ogroup'])){
745       $this->objectclasses = array("gotoWorkstationTemplate");
746     }elseif(isset($this->parent->by_object['workgeneric'])){
747       $this->objectclasses = array("GOhard");
748     }elseif(isset($this->parent->by_object['servgeneric'])){
749       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
750     }else{
751       msg_dialog::display(_("Fatal error"),
752           "Object Type Configuration is unknown. Please contact the GOsa developers.",
753           FATAL_ERROR_DIALOG);
754       exit();
755     }
757     /* Append FAI class */
758     if($this->fai_activated){
759       $this->objectclasses[]  = "FAIobject";
760     }
762     /* Find proper terminal path for tftp configuration
763        FIXME: This is suboptimal when the default has changed to
764        another location! */
765     if (($this->gotoTerminalPath == "default")){
766       $ldap= $this->config->get_ldap_link();
768       /* Strip relevant part from dn, keep trailing ',' */
769       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
770       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
772       /* Walk from top to base and try to load default values for
773          'gotoTerminalPath'. Abort when an entry is found. */
774       while (TRUE){
775         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
777         $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
778             $this->config->current['BASE'], array('gotoTerminalPath'));
779         $attrs= $ldap->fetch();
780         if (isset($attrs['gotoTerminalPath'])){
781           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
782           break;
783         }
785         /* Nothing left? */
786         if ($tmp == ""){
787           break;
788         }
789       }
790     }
792     if ($this->gotoKernelParameters == "") {
793       /* Add semi automatic values if empty */
794       // FIXME: LDAP Server may not be set here...
795       $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
796       
797       switch ($this->bootmode){
798         case "D":
799           $this->gotoKernelParameters.= " debug";
800         break;
801         case "G":
802           $this->gotoKernelParameters.= " splash=silent";
803         break;
804       }
805     }
807     plugin::save();
809     unset( $this->attrs['FAIrelease'] );
810     $str = "";
812     /* Skip FAI attribute handling if not necessary */
813     if($this->fai_activated && !$this->si_fai_action_failed){
814       if($this->FAIdebianMirror == "inherited"){
815         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
816       }else{
817         foreach($this->FAIclass as $class){
818           $str .= $class." ";
819         }
820         $str = trim($str);
821         if(empty($this->attrs['FAIclass'])){
822           $this->attrs['FAIclass'] = array();
823         }else{
824           $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
825         }
826       }
827     }
829     /* Add missing arrays */
830     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
831       if (isset ($this->$val) && count ($this->$val) != 0){
832     
833         $this->attrs["$val"]= array_unique($this->$val);
834       }
835       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
836     }
838     /* Prepare list of ldap servers */
839     $this->attrs['gotoLdapServer'] = array();
840     if(!$this->gotoLdap_inherit){
841       $i = 0;
842       foreach($this->gotoLdapServers as $server){
843         $i ++;
844         $this->attrs['gotoLdapServer'][] = $i.":".$server;
845       }
846     }
848     if ($this->attrs['gotoBootKernel'] == "default-inherited"){
849       $this->attrs['gotoBootKernel']= array();
850     }
852     /* if mirror == none stop saving this attribute */
853     if($this->FAIdebianMirror == "none"){
854       $this->FAIdebianMirror = "";
855     }
856    
857     /* Get FAIstate from object, the generic tab could have changed it during execute */
858     $ldap= $this->config->get_ldap_link();
859     $ldap->cd($this->dn);
862     /* Skip FAI attribute handling if not necessary */
863     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
864       $ldap->cat($this->dn,array("FAIstate"));
865       $checkFAIstate = $ldap->fetch();
867       /* Remove FAI objects if no FAI class is selected */ 
868       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
869         $this->attrs['FAIclass']        = array();
870         $this->attrs['FAIdebianMirror'] = array();
871       }
872     }else{
874       /* Don't touch FAI objects if something went wrong with the si daemon.
875        */
876       if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
877       if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
878     }
880     /* prepare share settings */
881     $tmp = array();
882     foreach($this->gotoShares as $name => $settings){
883       $tmp2= split("\|",$name);
884       $name = $tmp2[0];
885       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
886     }
887     $this->attrs['gotoShare']=$tmp;
888     $this->cleanup();
889     $ldap->modify ($this->attrs); 
890     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
892     if (!$ldap->success()){
893       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
894     }
895     $this->handle_post_events("modify");
897     /* Check if LDAP server has changed */
898     if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
899       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
900       $o_queue = new gosaSupportDaemon();
901       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
902         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
903         $macs = array();
904     
905         /* Get list of macAddresses 
906          */
907         if(isset($this->parent->by_object['ogroup'])){
908         
909           /* If we are an object group, add all member macs 
910            */
911           $p = $this->parent->by_object['ogroup'];
912           foreach($p->memberList as $dn => $obj){
913             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
914               $macs[] = $p->objcache[$dn]['macAddress'];
915             }
916           }
917         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
919           /* We are a workstation. Add current mac.
920            */
921           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
922           if(!empty($mac)){
923             $macs[] = $mac;
924           }          
925         }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
927           /* We are a server. Add current mac.
928            */
929           $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
930           if(!empty($mac)){
931             $macs[] = $mac;
932           }          
933         }
935         /* Trigger event for all member objects 
936          */
937         foreach($macs as $mac){
938           $tmp = new $evt['CLASS_NAME']($this->config);
939           $tmp->set_type(TRIGGERED_EVENT);
940           $tmp->add_targets(array($mac));
941           if(!$o_queue->append($tmp)){
942             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
943           }
944         }
945       }
946     }
947   }
950   /* Add value to array, check if unique */
951   function add_list (&$array, $value)
952   {
953     if ($value != ""){
954       $array[]= $value;
955       sort($array);
956       array_unique ($array);
957     }
958   }
961   /* Delete value to array, check if unique */
962   function del_list (&$array, $list)
963   {
964     $tmp= array();
965     foreach ($array as $mod){
966       if (!in_array($mod, $list)){
967         $tmp[]= $mod;
968       }
969     }
970     $array= $tmp;
971   }
973   /* Generate ListBox frindly output for the defined shares
974    * Possibly Add or remove an attribute here,
975    */
976   function printOutAssignedShares()
977   {
978     $a_return = array();
979     if(is_array($this->gotoShares)){
980       foreach($this->gotoShares as $share){
981         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
982       }
983     }
984     return($a_return);
985   }
989   function PrepareForCopyPaste($source)
990   {
991     plugin::PrepareForCopyPaste($source);    
992     $source_o = new workstartup ($this->config, $source['dn']);
993     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
994           "gotoKernelParameters","gotoShares") as $attr){
995       $this->$attr = $source_o->$attr;
996     }
997   }
999   
1000   function array_switch_item($ar,$from,$to)
1001   {
1002     if(!is_array($ar)){
1003       return(false);
1004     }
1005     if(!isset($ar[$from])){
1006       return(false);
1007     }
1008     if(!isset($ar[$to])){
1009       return(false);
1010     }
1012     $tmp = $ar[$from];
1013     $ar[$from] = $ar[$to];    
1014     $ar[$to] = $tmp;    
1015     return($ar);
1016   }
1019   /* Return plugin informations for acl handling */ 
1020   static function plInfo()
1021   {
1022     return (array( 
1023           "plShortName"   => _("Startup"),
1024           "plDescription" => _("System startup"),
1025           "plSelfModify"  => FALSE,
1026           "plDepends"     => array(),
1027           "plPriority"    => 9,
1028           "plSection"     => array("administration"),           
1029           "plCategory"    => array("workstation","server","ogroups"),
1031           "plProvidedAcls"=> array(
1032             "gotoLdapServer"        => _("Ldap server"),
1033             "gotoBootKernel"        => _("Boot kernel"),
1034             "gotoKernelParameters"  => _("Kernel parameter"),
1036             "gotoModules"           => _("Kernel modules"),
1037             "gotoShare"             => _("Shares"),
1039             "FAIclass"              => _("FAI classes"),
1040             "FAIdebianMirror"       => _("Debian mirror"),
1041             "FAIrelease"            => _("Debian release"),
1043             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1044           ));
1045   }
1047   /* Function to find bad classes */
1048   function update_bad_classes($release)
1049   {
1051     if(!isset($this->cache['BAD_CLASSES'][$release])) {
1052       /* Find "bad" classes */
1053       $ui = get_userinfo();
1054       $ldap = $this->config->get_ldap_link();
1056       /* Convert release name to a valid ldap uri component */
1057       $release_components = split('/', $release);
1058       $release_components = array_reverse($release_components);
1059       for($i=0;$i<sizeof($release_components);$i++) {
1060         $release_components[$i] = "ou=" . $release_components[$i];
1061       }
1062       $release_dn_part = join(',', $release_components);
1064       /* Limit the base to the release in the faiBase */
1065       $base = sprintf("%s,%s%s", $release_dn_part, get_ou('faiBaseRDN'), $this->config->current['BASE']);
1067       /* Build a list of all fai classes, that don't have the unittag of the user
1068        * and are not freezed or removed. The classes will be filtered by this
1069        * list. Its needed to specify each objectClass (FAIpackageList etc.) because
1070        * FAIClass would match sub-objects, too, which would lead to an array that
1071        * is much bigger then needed */
1072       $filter = sprintf('(&(|(objectClass=FAItemplate)(objectClass=FAIpackageList)(objectClass=FAIprofile)(objectClass=FAIscript)(objectClass=FAIpartitionTable)(objectClass=FAIHook)(objectClass=FAIvariable)(objectClass=FAItemplate))(&(!(gosaUnitTag=%s))(&(!(FAIstate=*removed*))(!(FAIstate=*freeze*)))))', $ui->gosaUnitTag);
1073       $ldap->cd($base);
1074       $ldap->search(sprintf("$filter", $ui->gosaUnitTag));
1075         
1076       $this->cache['BAD_CLASSES'][$release] = array(); 
1077       while ($entry = $ldap->fetch()) {
1078         $classname = $entry['cn'][0];
1079         if (!in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
1080           array_push($this->cache['BAD_CLASSES'][$release], $classname);
1081         }
1082       }
1083     } 
1084    }
1086   /* Updates release dns 
1087    *  and reads all classes for the current release, 
1088    *  if not already done ($this->cache).
1089    */
1090   function update_fai_cache($first_call = FALSE)
1091   {
1092     $force = FALSE;
1093     if(!$this->si_active) return; 
1094     $start = microtime(TRUE);  
1096     if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1098     $this->si_fai_action_failed = FALSE;
1100     /* Get the list of available servers and their releases. 
1101      */
1102     if($force || !isset($this->cache['SERVERS'])){
1104       $o_queue = new gosaSupportDaemon();
1105       $servers = $o_queue->FAI_get_server();
1106       if($o_queue->is_error()){
1107         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1108         $this->si_fai_action_failed = TRUE;
1109         $this->cache = array();
1110         return;
1111       }else{
1113         $base = $this->config->current['BASE'];
1114         $ldap = $this->config->get_ldap_link();
1115         foreach($servers as $server){
1116           /* Dont show servers that have a different unittag as the user*/
1117           $ui = get_userinfo();
1118           if ($ui->gosaUnitTag != $server['TAG']) {
1119             continue;
1120           }
1121         
1122           $rel = $server['FAI_RELEASE'];
1123           $this->cache['SERVERS']['auto'][$rel] = $rel;
1124           $this->cache['SERVERS'][$server['SERVER']][$rel] = $rel;
1125           uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1126           uksort($this->cache['SERVERS'][$server['SERVER']], 'strnatcasecmp');
1127         }
1128       }
1129     }
1131     /* Ensure that our selection is valid, else we get several PHP warnings 
1132         if there is no FAI configuration at all.
1133      */
1134     if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1135       $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1136     }
1138     /* Build up arrays, without checks */
1139     if(!$first_call){
1141       /* Check if the selected mirror is available */
1142       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1143         $this->FAIdebianMirror = "auto";
1144         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1145         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1146       }
1148       /* Check if the selected release is available */
1149       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1151         if($this->FAIrelease != ""){
1152           trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1153         }
1154         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1155       }
1156     }
1158     /* Get classes for release from cache. 
1159      * Or build cache
1160      */
1161     if($this->FAIdebianMirror == "inherited"){
1162       $release = $this->InheritedFAIrelease;
1163     }else{
1164       $release = $this->FAIrelease;
1165     }
1167     if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1169       /* Get the list of available servers and their releases.
1170        */
1171       $o_queue = new gosaSupportDaemon();
1172       $classes = $o_queue->FAI_get_classes($release);
1173       $this->cache['CLASSES'][$release] = array();
1174       if($o_queue->is_error()){
1175         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1176         $this->si_fai_action_failed = TRUE;
1177         $this->cache=array();
1178         return;
1179       }else{
1180         foreach($classes as $class){
1181           $classname = $class['CLASS'];
1182           $this->update_bad_classes($release);
1183           if(isset($this->cache['BAD_CLASSES'][$release])){
1184             /* Skip classes that are in the array of bad classes */
1185             if (in_array($classname, $this->cache['BAD_CLASSES'][$release])) {
1186               continue;
1187             }
1188           }
1189           if (!isset($this->cache['CLASSES'][$release][$classname])) {
1190             $this->cache['CLASSES'][$release][$classname] = array();
1191           }
1192           array_push($this->cache['CLASSES'][$release][$classname], $this->analyse_fai_object($class));
1193         }
1194       }
1196       /* Add object caught from external hook
1197        */
1198       $lines= $this->GetHookElements();
1199       foreach ($lines as $hline){
1200         $entries= split(";", $hline);
1201         $server = $entries['0'];
1202         $url    = $entries['1'];
1203         if (!empty($url)){
1205           /* Split releases */
1206           if (isset($entries[2])){
1207             $releases= split(",", $entries[2]);
1209             foreach ($releases as $release_data){
1210               $release_c  = preg_replace('/:.*$/', '', $release_data);
1211               $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1212               $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1214               if($release_c == $release){
1215                 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1216                 $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
1217                 foreach ($classes_c as $class){
1218                   if ($class != ""){
1219                     $this->cache['CLASSES'][$release_c][$class]= array();
1220                   }
1221                 }
1222               }
1223             }
1224           }
1225         }
1226       }
1227       uksort($this->cache['SERVERS'], 'strnatcasecmp');
1229       /* Only add inherit option, if we are part in an object group
1230        */
1231       if($this->member_of_ogroup){
1232         $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1233       }
1234     }
1236     /* Get list of available kernel for this release 
1237      */
1238     if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1240     if($force || !isset($this->cache['KERNELS'][$release])){
1241       $o_queue = new gosaSupportDaemon();
1242       $tmp = $o_queue->FAI_get_kernels($release);
1243       $this->cache['KERNELS'][$release] = array();
1244       foreach($this->gotoBootKernels as $name => $default){
1245         $this->cache['KERNELS'][$release][$name] = $default;
1246       }
1247       foreach($tmp as $kernel){
1248         if(empty($kernel)) continue;
1249         $this->cache['KERNELS'][$release][$kernel]=$kernel;
1250       }
1251       ksort($this->cache['KERNELS'][$release]);
1252     }
1253   }
1255   /* Detect the release and get all classes for it */
1256   function get_classes() {
1257     $this->update_fai_cache();
1259     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1260       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1261     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1262       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1263     }else{
1264       $classes = array();
1265     }
1267     return $classes;
1268   }
1270   /* This function return an array containing all 
1271    *  invalid classes for the selected server/release
1272    */
1273   function get_invalid_classes($classes)
1274   {
1275     $release_classes = $this->get_classes();
1277     /* Detect all classes that are not valid 
1278      *  for the selected release 
1279      */
1280     $NA = array();
1281     foreach($classes as $class){
1282       if(!isset($release_classes[$class])){
1283         $NA[] = $class;
1284       }
1285     }
1286     return($NA);
1287   }  
1289   function get_fai_types_string($class_name, $image=FALSE) {
1290     $classes = $this->get_classes();
1292     $result = array();
1294     if ($image) {        
1295       # Pre-fill the array fields with an empty image so that
1296       # everything looks fine if the type in this position
1297       # doesn't exist in that class
1298       for ($i=0; $i<6; $i++) {
1299         $result[$i] = "<img src='images/empty.png' width='17'>&nbsp;";
1300       }
1301     }
1303     foreach($classes[$class_name] as $type) {
1304       $index = $type['index'];
1305       if ($image) {
1306         $string = "<img src='".$type['img']."' width='17' title='".$type['desc']."'>&nbsp;";
1307       }
1308       else {
1309         $string = $type['Abbr'];
1310       }
1311       
1312       $result[$index] = $string;
1313     }
1314     return join(' ', $result);
1316   }
1318   /* Get all selectable classes for the ui select box
1319    */
1320   function selectable_classes()
1321   {
1322     $classes = $this->get_classes();
1324     $ret= array();
1325     foreach($classes as $class_name => $class_types) {
1326       if (!in_array($class_name, $this->FAIclass)) {
1327         $ret[$class_name] = $this->get_fai_types_string($class_name);
1328       }
1329     }
1330     uksort($ret, 'strnatcasecmp');
1331     return($ret);
1332   }
1335   /* Analyse FAI object and return an array with usefull informations like 
1336    *  FAIobject type.
1337    */
1338   function analyse_fai_object($attr)
1339   {
1340     $result = array();
1341     switch($attr['TYPE']){
1342       case 'FAIpartitionTable':
1343         $result["Type"]= 'FAIpartitionTable'; 
1344         $result["Abbr"]= 'Pt';
1345         $result["img"]= 'plugins/fai/images/fai_partitionTable.png';
1346         $result["desc"] = _('Partition table');
1347         $result["index"]= 0;
1348         break;
1349       case 'FAIpackageList':
1350         $result["Type"]= 'FAIpackageList';
1351         $result["Abbr"]= 'Pl';
1352         $result["img"] = 'plugins/fai/images/fai_packages.png';
1353         $result["desc"] = _('Package list');
1354         $result["index"] = 1;
1355         break;
1356       case 'FAIscript':
1357         $result["Type"]= 'FAIscript'; 
1358         $result["Abbr"]= 'S'; 
1359         $result["img"]= 'plugins/fai/images/fai_script.png';
1360         $result["desc"] = _('Scripts');
1361         $result["index"] = 2;
1362         break;
1363       case 'FAIvariable':
1364         $result["Type"]= 'FAIvariable'; 
1365         $result["Abbr"]= 'V';
1366         $result["img"]= 'plugins/fai/images/fai_variable.png'; 
1367         $result["desc"] = _('Variables');
1368         $result["index"]= 3;
1369         break;
1370       case 'FAIhook':
1371         $result["Type"]= 'FAIhook'; 
1372         $result["Abbr"]= 'H'; 
1373         $result["img"]= 'plugins/fai/images/fai_hook.png';
1374         $result["desc"] = _('Hooks');
1375         $result["index"]= 4;
1376         break;
1377       case 'FAIprofile':
1378         $result["Type"]= 'FAIprofile'; 
1379         $result["Abbr"]= 'P';
1380         $result["img"]= 'plugins/fai/images/fai_profile.png';
1381         $result["desc"]= _('Profile');
1382         $result["index"] = 5;
1383         break;
1384       case 'FAItemplate': 
1385         $result["Type"]= 'FAItemplate'; 
1386         $result["Abbr"]= 'T';
1387         $result["img"] = 'plugins/fai/images/fai_template.png'; 
1388         $result["desc"]= _('Templates');
1389         $result["index"] = 6;
1390         break;
1391       default: trigger_error("Unknown FAI object type!");;
1392     }
1393     return($result);
1394   }
1397   /* Return repository hook output, if possible.
1398    */
1399   function GetHookElements()
1400   {
1401     $ret = array();
1402     $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1403     if(!empty($cmd)){
1404       $res = shell_exec($cmd);
1405       $res2 = trim($res);
1406       if((!$res)){
1407         msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1408       }elseif(empty($res2)){
1409         msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1410       }else{
1411         $tmp = split("\n",$res);
1412         foreach($tmp as $line){
1413           if(empty($line)) continue;
1414           $ret[]= $line;
1415         }
1416       }
1417     }
1418     return($ret);
1419   }
1422   /* This function creates the release name out of a dn 
1423    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1424    */
1425   function dn_to_release_name($dn)
1426   {
1427     $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$dn);
1428     $parts    = array_reverse(split("\,",$relevant));
1429     $str ="";
1430     foreach($parts as $part){
1431       $str .= preg_replace("/^ou=/","",$part)."/";
1432     }
1433     return(preg_replace("/\/$/","",$str)); 
1434   }
1437 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1438 ?>