Code

New bunch of value changes
[gosa.git] / 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 $customParameters   = "";
33   var $orig_dn            = "";
34   var $ignore_account     = TRUE;
35  
36   /* FAI class selection */ 
37   var $FAIclass           = array();  // The currently selected classes 
38   var $FAIrelease           = "";
39   var $FAIdebianMirror      = "auto";
40   var $si_active            = FALSE;
41   var $si_fai_action_failed = FALSE;
43   var $cache              = array(); // Used as cache in fai mehtods
45   var $FAIstatus          = "";
46   var $FAIclasses         = array();
48   var $view_logged        = FALSE;
49   
50   /* FAI class selection */
51   var $InheritedFAIclass       = array();
52   var $InheritedFAIrelease     = "";
53   var $InheritedFAIdebianMirror= "auto";
55   var $CopyPasteVars    = array("gotoModules","gotoShares");
56   var $fai_activated    = FALSE;
57   var $o_group_dn       = "";
58   var $member_of_ogroup = FALSE;
60   function workstartup (&$config, $dn= NULL, $parent= NULL)
61   {
62     /* Check if FAI is active */
63     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
64     if(!empty($tmp)){
65       $this->fai_activated = TRUE;
66     }else{
67       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
68       $this->objectclasses  = array("GOhard");
69     }
71     plugin::plugin ($config, $dn, $parent);
73     /* Check for si daemon */
74     $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
76     /* Check object group membership */
77     if(!isset($this->parent->by_object['ogroup'])){
78       $ldap = $this->config->get_ldap_link();
79       $ldap->cd ($this->config->current['BASE']);
80       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
81       if($ldap->count()){
82         $this->member_of_ogroup = TRUE;
83         $attrs = $ldap->fetch();
84         $this->o_group_dn = $attrs['dn'];
85       }
86     }
88     /* Creating a list of valid Mirrors 
89      * none will not be saved to ldap.
90      */
91     $ldap   = $this->config->get_ldap_link();
92     $ldap->cd($this->config->current['BASE']);
93     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
94       $this->gotoLdapServerList[]= $server; 
95     }
97     /* Get list of assigned ldap servers 
98      */ 
99     if(isset($this->attrs['gotoLdapServer'])){
100       unset($this->attrs['gotoLdapServer']['count']);
101       sort($this->attrs['gotoLdapServer']);
102       foreach($this->attrs['gotoLdapServer'] as $value){
103         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
104       }
105     } 
106     natcasesort($this->gotoLdapServerList);
108     if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ 
109       $this->gotoLdap_inherit = TRUE;
110     }
112     /* FAI Initialization
113        Skip this if FAI is not activated 
114      */
115     if($this->fai_activated) {
117       $this->update_fai_cache(TRUE);
119       /* Parse used FAIclasses (stored as string).
120        * The single classes are seperated by ' '.
121        * There is also the release type given, after first
122        *  occurrence of ':'.
123        */
124       $this->FAIclass =array();
125       if(isset($this->attrs['FAIclass'][0])){
126         $tmp = split(" ",$this->attrs['FAIclass'][0]);
127         $tmp2 =array();  
129         foreach($tmp as $class){
130           if( ":" == $class[0] ) {
131             $this->FAIrelease = trim(substr($class, 1));
132           }else{
133             $tmp2[$class] = $class;
134           }
135         }
136         $this->FAIclass = $tmp2;
137       }
138     }
140     /* Get arrays */
141     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
142       if (isset($this->attrs["$val"]["count"])){
143         for ($i= 0; $i<$this->attrs["count"]; $i++){
144           if (isset($this->attrs["$val"][$i])){
145             array_push($this->$val, $this->attrs["$val"][$i]);
146           }
147         }
148       }
149       sort ($this->$val);
150       $this->$val= array_unique($this->$val);
151     }
153     /* Parse Kernel Parameters to decide what boot mode is enabled */
154     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
155       $this->bootmode= "G";
156     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
157       $this->bootmode= "D";
158     } elseif ($this->gotoKernelParameters == "") {
159       $this->bootmode= "G";
160     } else {
161       $this->bootmode= "T";
162     }
163     if (preg_match("/ o /", $this->gotoKernelParameters)){
164       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
165     } else {
166       $this->customParameters= "";
167     }
169     /* Prepare Shares */
170     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
171       unset($this->attrs['gotoShare']['count']);
172       foreach($this->attrs['gotoShare'] as $share){
173         $tmp = $tmp2 = array();
174         $tmp = split("\|",$share);
175         $tmp2['server']      =$tmp[0];
176         $tmp2['name']        =$tmp[1];
177         $tmp2['mountPoint']  =$tmp[2];
178         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
179       }
180     }
182     $this->otoShareSelections= $config->getShareList(true);
183     $this->gotoAvailableShares= $config->getShareList(false);
184     $tmp2 = array();
185   
187     $this->orig_dn= $this->dn;
189     /* Handle inheritance value "default" */
190     if ($this->member_of_ogroup){
191       $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); 
192     }
194     /* If we are member in an object group,
195      *  we have to handle inherited values.
196      * So you can see what is inherited.
197      */
198     if ($this->member_of_ogroup){
200       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
201         $this->FAIdebianMirror = "inherited";
202       }
204       if($this->fai_activated){
205         $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
206       }else{
207         $map= array("gotoBootKernel");
208       }
210       $ldap = $this->config->get_ldap_link();
211       $ldap->cat($this->o_group_dn);
212       $attrs= $ldap->fetch();
214       foreach ($map as $name){
215         if (!isset($attrs[$name][0])){
216           continue;
217         }
219         switch ($name){
220           case 'gotoBootKernel':
221             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
222             break;
224           case 'FAIclass':
225             $str = split(":",$attrs[$name][0]);
226             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
227             $this->InheritedFAIrelease  = trim($str[1]);
228             break;
230           case 'FAIdebianMirror':
231             $this->InheritedFAIdebianMirror = $attrs[$name][0];
232             break;
233         }
234       }
235     }
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     }
265 #   /* Get list of boot kernels */
266 #   if (isset($this->config->data['TABS'])){
267 #     $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
268 #     if (!check_command($command)){
269 #       $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
270 #           get_class($this));
271 #     } else {
272 #       $fh= popen($command, "r");
273 #       while (!feof($fh)) {
274 #         $buffer= trim(fgets($fh, 256));
275 #         if(!empty($buffer)){
276 #           $name=$value = $buffer;
277 #           if(preg_match("/:/",$buffer)){
278 #             $name = preg_replace("/:.*$/","",$buffer);
279 #             $value= preg_replace("/^.*:/","",$buffer);
280 #             $this->gotoBootKernels[$name]= $name.":".$value;
281 #           }else{
282 #             $this->gotoBootKernels[$name]= $value;
283 #           }
284 #         }
285 #       }
286 #       pclose($fh);
287 #     }
288 #   }
290 #    /* Turn to default, if we've nothing to inherit */
291 #    if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
292 #      $this->gotoBootKernel= "default";
293 #    }
294   }
296   
297   function check()
298   {
299     $messages = array();
300     
301     /* Call common method to give check the hook */
302     $messages= plugin::check();
304     /* If there are packages selected, but no mirror show error */   
305     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
306       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
307     }
309     return($messages);
310   }
312   function execute()
313   {
314         /* Call parent execute */
315         plugin::execute();
317     if($this->is_account && !$this->view_logged){
318       $this->view_logged = TRUE;
319       new log("view","workstation/".get_class($this),$this->dn);
320     }
322     /* Do we represent a valid terminal? */
323     if (!$this->is_account && $this->parent === NULL){
324       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
325         msgPool::noValidExtension(_("workstation"))."</b>";
326       return ($display);
327     }
329     /* Add module */
330     if (isset ($_POST['add_module'])){
331       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
332         $this->add_list ($this->gotoModules, $_POST['module']);
333       }
334     }
336     /* Delete module */
337     if (isset ($_POST['delete_module'])){
338       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
339         $this->del_list ($this->gotoModules, $_POST['modules_list']);
340       }
341     }
343     /* FAI class management */
344     if($this->fai_activated){
345       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
346         $found = 0 ; 
348         /* If this new class/profile will attach a second partition table
349          * to our list of classes, abort and show a message.
350          */
351         foreach($this->FAIclass as $name){
352           if(isset($this->FAIclassInfo[$name])){
353             foreach($this->FAIclassInfo[$name] as $atr){
354               if(isset($atr['obj'])){
355                 if($atr['obj'] == "FAIpartitionTable"){
356                   $found ++ ; 
357                 }
358               }
359             }
360           }
361         }
363         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
364           msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
365         }else{
366           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
367         }
368       }
370       $sort = false;
372       /* Move one used class class one position up or down */
373       if($this->acl_is_writeable("FAIclass")){
374         foreach($_POST as $name => $val){
376           $sort_type = false;
377           if((preg_match("/sort_up/",$name))&&(!$sort)){
378             $sort_type = "sort_up_";
379           }
380           if((preg_match("/sort_down/",$name))&&(!$sort)){
381             $sort_type = "sort_down_";
382           }
384           if(($sort_type)&&(!$sort)){
385             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
386             $sort = true;
388             $last = -1;
389             $change_down  = -1;
391             /* Create array with numeric index */ 
392             $tmp = array();
393             foreach($this->FAIclass as $class){
394               $tmp [] = $class;
395             }
397             /* Walk trough array */
398             foreach($tmp as $key => $faiName){
399               if($faiName == $value){
400                 if($sort_type == "sort_up_"){
401                   if($last != -1){
402                     $change_down= $last;
403                   }
404                 }else{
405                   if(isset($tmp[$key+1])){
406                     $change_down = $key;
407                   }
408                 }
409               }
410               $last = $key;
411             }
413             $tmp2 = array();
414             $skip = false;    
416             foreach($tmp as $ky => $vl){
418               if($ky == $change_down){
419                 $skip = $vl;
420               }else{
421                 $tmp2[$vl] = $vl;
422               }
423               if(($skip != false)&&($ky != $change_down)){
424                 $tmp2[$skip]  = $skip;
425                 $skip =false;
426               }
427             }   
428             $this->FAIclass = $tmp2; 
429           }
431           if(preg_match("/fai_remove/i",$name)){
432             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
433             unset($this->FAIclass[$value]);
434           }
435         }
436       }
438       /* Delete selected class from our list */
439       if($this->acl_is_writeable("FAIclass")){
440         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
441           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
442             unset($this->FAIclass[$_POST['FAIclassSel']]);
443           }
444         }
445       }
446     }// END fai handling
448     /* Show main page */
449     $smarty= get_smarty();
451     /* Assign ACLs to smarty */
452     $tmp = $this->plInfo();
453     foreach($tmp['plProvidedAcls'] as $name => $translation){
454       $smarty->assign($name."ACL",$this->getacl($name));
455     } 
457     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
459     /* In this section server shares will be defined
460      * A user can select one of the given shares and a mount point
461      *  and attach this combination to his setup.
462      */
463     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
464     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
466     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
467      * This entry will be, a combination of mountPoint and sharedefinitions
468      */
469     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
470       /* We assign a share to this user, if we don't know where to mount the share */
471       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
472         msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
473       }else{
474         if(count($this->gotoAvailableShares)){
475           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
476           $s_mount = $_POST['gotoShareMountPoint'];
477           /* Preparing the new assignment */
478           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
479           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
480         }
481       }
482     }
484     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
485      * If there is no defined share selected, we will abort the deletion without any message
486      */
487     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
488       unset($this->gotoShares[$_POST['gotoShare']]);
489     }
491     $smarty->assign("gotoShares",$this->printOutAssignedShares());
492     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
493     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
494     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
496     /* Create divSelectBox for ldap server selection
497      */
498     $SelectBoxLdapServer = new divSelectBox("LdapServer");
499     $SelectBoxLdapServer->SetHeight(130);
501     /* Add new ldap server to the list */
502     if($this->acl_is_writeable("gotoLdapServer") && 
503         !$this->gotoLdap_inherit && 
504         isset($_POST['add_ldap_server']) && 
505         isset($_POST['ldap_server_to_add'])){
506       if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
507         $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
508         if(!in_array($to_add,$this->gotoLdapServers)){
509           $this->gotoLdapServers[] = $to_add;
510         }
511       }
512     }
513     
514     /* Move ldap servers up and down */
515     if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
516       foreach($_POST as $name => $value){
517         if(preg_match("/sort_ldap_up_/",$name)){
518           $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
519           $from =  $id;  
520           $to   =  $id -1;
521           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
522           if($tmp){
523             $this->gotoLdapServers = $tmp;
524           }
525           break;
526         }
527         if(preg_match("/sort_ldap_down_/",$name)){
528           $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
529           $from =  $id;  
530           $to   =  $id +1;
531           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
532           if($tmp){
533             $this->gotoLdapServers = $tmp;
534           }
535           break;
536         }
537         if(preg_match("/gotoLdapRemove_/",$name)){
538           $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
539           $value = $this->gotoLdapServers[$id];
540           $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
541           break;
542         }
543       } 
544     }
545   
546     /* Add Entries */
547     if($this->acl_is_readable("gotoLdapServer")){
549       foreach($this->gotoLdapServers as $key => $server){
551         /* Announce missing entries */
552         if(!in_array($server,$this->gotoLdapServerList)){
553           $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
554         }
556         /* Convert old style entry */
557         if (!preg_match('%:ldaps?://%', $server)){
558           $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
560         /* Beautify new style entries */
561       } else {
562         $server= preg_replace("/^[^:]+:/", "", $server);
563       }
565       $SelectBoxLdapServer->AddEntry(
566           array(array("string" => $server),
567             array("string" => 
568               "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'>&nbsp;".
569               "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'>&nbsp;".
570               "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
571               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
572       }    
573     }    
575     if($this->gotoLdap_inherit){
576       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
577     }else{
578       $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
579     }
580     
581     $list = array();
582     foreach($this->gotoLdapServerList as $key => $entry){
583       if(!in_array($entry,$this->gotoLdapServers)){
585         /* Convert old style entry */
586         if (!preg_match('%:ldap[s]*://%', $entry)){
587           $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
589         /* Beautify new style entries */
590         } else {
591           $entry= preg_replace("/^[^:]+:/", "", $entry);
592         }
594         $list[$key] = $entry;
595       }
596     }
597     $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
598     $smarty->assign("gotoLdapServerList", $list);
599     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
600     $smarty->assign("JS",  session::get('js'));
602     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
603       $smarty->assign("$val", $this->$val);
604     }
606     /* Values */
607     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
608       $smarty->assign($val, $this->$val);
609     }
611     $smarty->assign("fai_activated",$this->fai_activated);
613     /* Create FAI output */
614     $this->update_fai_cache();
615     $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
616     $smarty->assign("si_active",$this->si_active);
617   
618     if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
620       $smarty->assign("FAIservers"  , $this->cache['SERVERS']);
621       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
622       $smarty->assign("FAIrelease"  , $this->FAIrelease);
623       $smarty->assign("FAIclasses"  , $this->selectable_classes());
625       /* Get classes for release from cache.
626        * Or build cache
627        */
628       if($this->FAIdebianMirror == "inherited"){
629         $release = $this->InheritedFAIrelease;
630       }else{
631         $release = $this->FAIrelease;
632       }
634       $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
635       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
637       $div = new divSelectBox("WSFAIscriptClasses");
638       $div -> SetHeight("110");
639       $str_up     = " &nbsp;<input type='image' src='images/lists/sort-up.png'    name='sort_up_%s'    value='%s'>";
640       $str_down   = " &nbsp;<input type='image' src='images/lists/sort-down.png'  name='sort_down_%s'  value='%s'>";
641       $str_remove = " &nbsp;<input type='image' src='images/lists/trash.png'  name='fai_remove_%s' value='%s'>";
642       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
644       /* Get classes */
645       if($this->FAIdebianMirror == "inherited"){
646         $tmp = $this->InheritedFAIclass;
647       }else{
648         $tmp = $this->FAIclass;
649       }
651       /* Get invalid classes */
652       $invalid = $this->get_invalid_classes($tmp);
654       /* Draw every single entry */
655       $i = 1;
656       foreach($tmp as $class){
658         /* Mark invalid classes. (Not in selected release)
659          */
660         $marker = "";
661         if(in_array_ics($class,$invalid)){
662           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
663         }
665         /* Create up/down priority icons  
666          * Skip this, if we have inherited the FAI classes.
667          */
668         if($this->FAIdebianMirror == "inherited"){
669           $str = "";
670         }else{
671           if($i==1){
672             $str = $str_empty.$str_down.$str_remove;
673           }elseif($i == count($this->FAIclass)){
674             $str = $str_up.$str_empty.$str_remove;
675           }else{
676             $str = $str_up.$str_down.$str_remove;
677           }
678         }
679         $i ++ ; 
681         /* Get Description tag 
682          *  There may be several FAI objects with the same class name, 
683          *   use the description from FAIprofile, if possible.
684          */  
685         $desc = ""; 
686         if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
687           foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
688             if(isset($types['Desc'])){
689               $desc= $types['Desc'];
690               if($types['Type'] == "FAIprofile"){
691                 break;
692               }
693             }
694           }
695         }
696         if(!empty($desc)){
697           $desc = "&nbsp;[".trim($desc)."]";
698         }        
700         $div->AddEntry(array(
701               array("string"=>$class.$desc.$marker),
702               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
703               ));
704       }  
705       $smarty->assign("FAIScriptlist",$div->DrawList()); 
706     }// END FAI output generation 
708     /* Radio button group */
709     if (preg_match("/G/", $this->bootmode)) {
710       $smarty->assign("graphicalbootup", "checked");
711     } else {
712       $smarty->assign("graphicalbootup", "");
713     }
714     if (preg_match("/T/", $this->bootmode)) {
715       $smarty->assign("textbootup", "checked");
716     } else {
717       $smarty->assign("textbootup", "");
718     }
719     if (preg_match("/D/", $this->bootmode)) {
720       $smarty->assign("debugbootup", "checked");
721     } else {
722       $smarty->assign("debugbootup", "");
723     }
725     /* Show main page */
726     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
727   }
730   function remove_from_parent()
731   {
732     $this->handle_post_events("remove");
733     new log("remove","workstation/".get_class($this),$this->dn);
734   }
737   /* Save data to object */
738   function save_object()
739   {
740     $old_mirror  = $this->FAIdebianMirror;
741     plugin::save_object();
743     /* Update release */
744     if($old_mirror != $this->FAIdebianMirror){
745       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
746         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
747       }
748     }
750     if(isset($_POST['WorkstationStarttabPosted'])){
751       if(isset($_POST['gotoLdap_inherit'])){
752         $this->gotoLdap_inherit = TRUE;
753       }else{
754         $this->gotoLdap_inherit = FALSE;
755       }
757       /* Save group radio buttons */
758       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
759         $this->bootmode= $_POST["bootmode"];
760       }
762       /* Save kernel parameters */
763       if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
764         $this->customParameters= $_POST["customParameters"];
765       }
766     }
767   }
770   /* Save to LDAP */
771   function save()
772   {
774     /* Depending on the baseobject (Ogroup / WS) we
775      *  use another set of objectClasses
776      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
777      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
778      */
779     if(isset($this->parent->by_object['ogroup'])){
780       $this->objectclasses = array("gotoWorkstationTemplate");
781     }elseif(isset($this->parent->by_object['workgeneric'])){
782       $this->objectclasses = array("GOhard");
783     }elseif(isset($this->parent->by_object['servgeneric'])){
784       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
785     }else{
786       msg_dialog::display(_("Fatal error"),
787           "Object Type Configuration is unknown. Please contact the GOsa developers.",
788           FATAL_ERROR_DIALOG);
789       exit();
790     }
792     /* Append FAI class */
793     if($this->fai_activated){
794       $this->objectclasses[]  = "FAIobject";
795     }
797     /* Find proper terminal path for tftp configuration
798        FIXME: This is suboptimal when the default has changed to
799        another location! */
800     if (($this->gotoTerminalPath == "default")){
801       $ldap= $this->config->get_ldap_link();
803       /* Strip relevant part from dn, keep trailing ',' */
804       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
805       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
807       /* Walk from top to base and try to load default values for
808          'gotoTerminalPath'. Abort when an entry is found. */
809       while (TRUE){
810         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
812         $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
813             $this->config->current['BASE'], array('gotoTerminalPath'));
814         $attrs= $ldap->fetch();
815         if (isset($attrs['gotoTerminalPath'])){
816           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
817           break;
818         }
820         /* Nothing left? */
821         if ($tmp == ""){
822           break;
823         }
824       }
825     }
827     /* Add semi automatic values */
828     // FIXME: LDAP Server may not be set here...
829     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
831     switch ($this->bootmode){
832       case "D":
833         $this->gotoKernelParameters.= " debug";
834       break;
835       case "G":
836         $this->gotoKernelParameters.= " splash=silent";
837       break;
838     }
839     if ($this->customParameters != ""){
840       $this->gotoKernelParameters.= " o ".$this->customParameters;
841     }
843     plugin::save();
845     unset( $this->attrs['FAIrelease'] );
846     $str = "";
848     /* Skip FAI attribute handling if not necessary */
849     if($this->fai_activated && !$this->si_fai_action_failed){
850       if($this->FAIdebianMirror == "inherited"){
851         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
852       }else{
853         foreach($this->FAIclass as $class){
854           $str .= $class." ";
855         }
856         $str = trim($str);
857         if(empty($this->attrs['FAIclass'])){
858           $this->attrs['FAIclass'] = array();
859         }else{
860           $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
861         }
862       }
863     }
865     /* Add missing arrays */
866     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
867       if (isset ($this->$val) && count ($this->$val) != 0){
868     
869         $this->attrs["$val"]= array_unique($this->$val);
870       }
871       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
872     }
874     /* Prepare list of ldap servers */
875     $this->attrs['gotoLdapServer'] = array();
876     if(!$this->gotoLdap_inherit){
877       $i = 0;
878       foreach($this->gotoLdapServers as $server){
879         $i ++;
880         $this->attrs['gotoLdapServer'][] = $i.":".$server;
881       }
882     }
884     if ($this->attrs['gotoBootKernel'] == "default-inherited"){
885       $this->attrs['gotoBootKernel']= array();
886     }
888     /* if mirror == none stop saving this attribute */
889     if($this->FAIdebianMirror == "none"){
890       $this->FAIdebianMirror = "";
891     }
892    
893     /* Get FAIstate from object, the generic tab could have changed it during execute */
894     $ldap= $this->config->get_ldap_link();
895     $ldap->cd($this->dn);
898     /* Skip FAI attribute handling if not necessary */
899     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
900       $ldap->cat($this->dn,array("FAIstate"));
901       $checkFAIstate = $ldap->fetch();
903       /* Remove FAI objects if no FAI class is selected */ 
904       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
905         $this->attrs['FAIclass']        = array();
906         $this->attrs['FAIdebianMirror'] = array();
907       }
908     }else{
910       /* Don't touch FAI objects if something went wrong with the si daemon.
911        */
912       if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
913       if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
914     }
916     /* prepare share settings */
917     $tmp = array();
918     foreach($this->gotoShares as $name => $settings){
919       $tmp2= split("\|",$name);
920       $name = $tmp2[0];
921       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
922     }
923     $this->attrs['gotoShare']=$tmp;
924     $this->cleanup();
925     $ldap->modify ($this->attrs); 
926     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
928     if (!$ldap->success()){
929       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
930     }
931     $this->handle_post_events("modify");
933     /* Check if LDAP server has changed */
934     if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
935       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
936       $o_queue = new gosaSupportDaemon();
937       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
938         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
939         $macs = array();
940     
941         /* Get list of macAddresses 
942          */
943         if(isset($this->parent->by_object['ogroup'])){
944         
945           /* If we are an object group, add all member macs 
946            */
947           $p = $this->parent->by_object['ogroup'];
948           foreach($p->memberList as $dn => $obj){
949             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
950               $macs[] = $p->objcache[$dn]['macAddress'];
951             }
952           }
953         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
955           /* We are a workstation. Add current mac.
956            */
957           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
958           if(!empty($mac)){
959             $macs[] = $mac;
960           }          
961         }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
963           /* We are a server. Add current mac.
964            */
965           $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
966           if(!empty($mac)){
967             $macs[] = $mac;
968           }          
969         }
971         /* Trigger event for all member objects 
972          */
973         foreach($macs as $mac){
974           $tmp = new $evt['CLASS_NAME']($this->config);
975           $tmp->set_type(TRIGGERED_EVENT);
976           $tmp->add_targets(array($mac));
977           if(!$o_queue->append($tmp)){
978             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
979           }
980         }
981       }
982     }
983   }
986   /* Add value to array, check if unique */
987   function add_list (&$array, $value)
988   {
989     if ($value != ""){
990       $array[]= $value;
991       sort($array);
992       array_unique ($array);
993     }
994   }
997   /* Delete value to array, check if unique */
998   function del_list (&$array, $list)
999   {
1000     $tmp= array();
1001     foreach ($array as $mod){
1002       if (!in_array($mod, $list)){
1003         $tmp[]= $mod;
1004       }
1005     }
1006     $array= $tmp;
1007   }
1009   /* Generate ListBox frindly output for the defined shares
1010    * Possibly Add or remove an attribute here,
1011    */
1012   function printOutAssignedShares()
1013   {
1014     $a_return = array();
1015     if(is_array($this->gotoShares)){
1016       foreach($this->gotoShares as $share){
1017         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1018       }
1019     }
1020     return($a_return);
1021   }
1025   function PrepareForCopyPaste($source)
1026   {
1027     plugin::PrepareForCopyPaste($source);    
1028     $source_o = new workstartup ($this->config, $source['dn']);
1029     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1030           "gotoKernelParameters","gotoShares","customParameters") as $attr){
1031       $this->$attr = $source_o->$attr;
1032     }
1033   }
1035   
1036   function array_switch_item($ar,$from,$to)
1037   {
1038     if(!is_array($ar)){
1039       return(false);
1040     }
1041     if(!isset($ar[$from])){
1042       return(false);
1043     }
1044     if(!isset($ar[$to])){
1045       return(false);
1046     }
1048     $tmp = $ar[$from];
1049     $ar[$from] = $ar[$to];    
1050     $ar[$to] = $tmp;    
1051     return($ar);
1052   }
1055   /* Return plugin informations for acl handling */ 
1056   static function plInfo()
1057   {
1058     return (array( 
1059           "plShortName"   => _("Startup"),
1060           "plDescription" => _("System startup"),
1061           "plSelfModify"  => FALSE,
1062           "plDepends"     => array(),
1063           "plPriority"    => 9,
1064           "plSection"     => array("administration"),           
1065           "plCategory"    => array("workstation","server","ogroups"),
1067           "plProvidedAcls"=> array(
1068             "gotoLdapServer"        => _("Ldap server"),
1069             "gotoBootKernel"        => _("Boot kernel"),
1070             "gotoKernelParameters"  => _("Kernel parameter"),
1072             "gotoModules"           => _("Kernel modules"),
1073             "gotoShare"             => _("Shares"),
1075             "FAIclass"              => _("FAI classes"),
1076             "FAIdebianMirror"       => _("Debian mirror"),
1077             "FAIrelease"            => _("Debian release"),
1079             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1080           ));
1081   }
1084   /* Updates release dns 
1085    *  and reads all classes for the current release, 
1086    *  if not already done ($this->cache).
1087    */
1088   function update_fai_cache($first_call = FALSE)
1089   {
1090     $force = FALSE;
1091     if(!$this->si_active) return; 
1092     $start = microtime(TRUE);  
1094     if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1096     $this->si_fai_action_failed = FALSE;
1098     /* Get the list of available servers and their releases. 
1099      */
1100     if($force || !isset($this->cache['SERVERS'])){
1102       $o_queue = new gosaSupportDaemon();
1103       $tmp = $o_queue->FAI_get_server();
1104       if($o_queue->is_error()){
1105         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1106         $this->si_fai_action_failed = TRUE;
1107         $this->cache = array();
1108         return;
1109       }else{
1110         foreach($tmp as $entry){
1111           $rel = $entry['RELEASE'];
1112           $this->cache['SERVERS']['auto'][$rel] = $rel;
1113           $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1114           uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1115           uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1116         }
1117       }
1118     }
1120     /* Ensure that our selection is valid, else we get several PHP warnings 
1121         if there is no FAI configuration at all.
1122      */
1123     if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1124       $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1125     }
1127     /* Build up arrays, without checks */
1128     if(!$first_call){
1130       /* Check if the selected mirror is available */
1131       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1132         $this->FAIdebianMirror = "auto";
1133         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1134         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1135       }
1137       /* Check if the selected release is available */
1138       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1139         trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1140         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1141       }
1142     }
1144     /* Get classes for release from cache. 
1145      * Or build cache
1146      */
1147     if($this->FAIdebianMirror == "inherited"){
1148       $release = $this->InheritedFAIrelease;
1149     }else{
1150       $release = $this->FAIrelease;
1151     }
1153     if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1155       /* Get the list of available servers and their releases.
1156        */
1157       $o_queue = new gosaSupportDaemon();
1158       $tmp = $o_queue->FAI_get_classes($release);
1159       $this->cache['CLASSES'][$release] = array();
1160       if($o_queue->is_error()){
1161         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1162         $this->si_fai_action_failed = TRUE;
1163         $this->cache=array();
1164         return;
1165       }else{
1166         foreach($tmp as $entry){
1167           $class = $entry['CLASS'];
1168           $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
1169         }
1170       }
1172       /* Add object caught from external hook
1173        */
1174       $lines= $this->GetHookElements();
1175       foreach ($lines as $hline){
1176         $entries= split(";", $hline);
1177         $server = $entries['0'];
1178         $url    = $entries['1'];
1179         if (!empty($url)){
1181           /* Split releases */
1182           if (isset($entries[2])){
1183             $releases= split(",", $entries[2]);
1185             foreach ($releases as $release_data){
1186               $release_c  = preg_replace('/:.*$/', '', $release_data);
1187               $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1188               $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1190               if($release_c == $release){
1191                 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1192                 $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
1193                 foreach ($classes_c as $class){
1194                   if ($class != ""){
1195                     $this->cache['CLASSES'][$release_c][$class]= array();
1196                   }
1197                 }
1198               }
1199             }
1200           }
1201         }
1202       }
1203       uksort($this->cache['SERVERS'], 'strnatcasecmp');
1205       /* Only add inherit option, if we are part in an object group
1206        */
1207       if($this->member_of_ogroup){
1208         $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1209       }
1210     }
1212     /* Get list of available kernel for this release 
1213      */
1214     if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1216     if($force || !isset($this->cache['KERNELS'][$release])){
1217       $o_queue = new gosaSupportDaemon();
1218       $tmp = $o_queue->FAI_get_kernels($release);
1219       $this->cache['KERNELS'][$release] = array();
1220       foreach($this->gotoBootKernels as $name => $default){
1221         $this->cache['KERNELS'][$release][$name] = $default;
1222       }
1223       foreach($tmp as $kernel){
1224         if(empty($kernel)) continue;
1225         $this->cache['KERNELS'][$release][$kernel]=$kernel;
1226       }
1227       ksort($this->cache['KERNELS'][$release]);
1228     }
1229   }
1232   /* This function return an array containing all 
1233    *  invalid classes for the selected server/release
1234    */
1235   function get_invalid_classes($classes)
1236   {
1237     $this->update_fai_cache();
1238     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1239       $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1240     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1241       $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1242     }else{
1243       $release_classes = array();
1244     }
1247     /* Detect all classes that are not valid 
1248      *  for the selected release 
1249      */
1250     $NA = array();
1251     foreach($classes as $class){
1252       if(!isset($release_classes[$class])){
1253         $NA[] = $class;
1254       }
1255     }
1256     return($NA);
1257   }  
1259   
1260   /* Get all selectable classes for the ui select box
1261    */
1262   function selectable_classes()
1263   {
1264     $this->update_fai_cache();
1266     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1267       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1268     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1269       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1270     }else{
1271       $classes = array();
1272     }
1274     $Abbr ="";
1275     $ret= array();
1276     foreach($classes as $class_name => $class_types){
1277       if(!in_array($class_name,$this->FAIclass)){
1278         foreach($class_types as $type){
1279           if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1280             $Abbr .= $type['Abbr']." ";
1281           }
1282         }
1283         $ret[$class_name] = trim($Abbr);
1284       }
1285     }
1286     uksort($ret, 'strnatcasecmp');
1287     return($ret);
1288   }
1291   /* Analyse FAI object and return an array with usefull informations like 
1292    *  FAIobject type.
1293    */
1294   function analyse_fai_object($attr)
1295   {
1296     $tmp = array();
1297     switch($attr['TYPE']){
1299       case 'FAIpackageList':
1300         $tmp["Type"]= 'FAIpackageList';
1301         $tmp["Abbr"]= 'Pl';
1302         break;
1303       case 'FAItemplate': 
1304         $tmp["Type"]= 'FAItemplate'; 
1305         $tmp["Abbr"]= 'T'; 
1306         break;
1307       case 'FAIvariable':
1308         $tmp["Type"]= 'FAIvariable'; 
1309         $tmp["Abbr"]= 'V'; 
1310         break;
1311       case 'FAIscript':
1312         $tmp["Type"]= 'FAIscript'; 
1313         $tmp["Abbr"]= 'S'; 
1314         break;
1315       case 'FAIhook':
1316         $tmp["Type"]= 'FAIhook'; 
1317         $tmp["Abbr"]= 'H'; 
1318         break;
1319       case 'FAIpartitionTable':
1320         $tmp["Type"]= 'FAIpartitionTable'; 
1321         $tmp["Abbr"]= 'Pt'; 
1322         break;
1323       case 'FAIprofile':
1324         $tmp["Type"]= 'FAIprofile'; 
1325         $tmp["Abbr"]= 'P'; 
1326         break;
1327       default: trigger_error("Unknown FAI object type!");;
1328     }
1329     return($tmp);
1330   }
1333   /* Return repository hook output, if possible.
1334    */
1335   function GetHookElements()
1336   {
1337     $ret = array();
1338     $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1339     if(!empty($cmd)){
1340       $res = shell_exec($cmd);
1341       $res2 = trim($res);
1342       if((!$res)){
1343         msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1344       }elseif(empty($res2)){
1345         msg_dialog::display(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1346       }else{
1347         $tmp = split("\n",$res);
1348         foreach($tmp as $line){
1349           if(empty($line)) continue;
1350           $ret[]= $line;
1351         }
1352       }
1353     }
1354     return($ret);
1355   }
1358   /* This function creates the release name out of a dn 
1359    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1360    */
1361   function dn_to_release_name($dn)
1362   {
1363     $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1364     $parts    = array_reverse(split("\,",$relevant));
1365     $str ="";
1366     foreach($parts as $part){
1367       $str .= preg_replace("/^ou=/","",$part)."/";
1368     }
1369     return(preg_replace("/\/$/","",$str)); 
1370   }
1373 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1374 ?>