Code

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