Code

Updated workstation startup
[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         # This is disabled as long there is no possiblilty to set these parameters
11   #var $bootmode             = "G";
12   var $bootmode             = "";
13   var $gotoBootKernel       = "default-inherited";
14   var $gotoKernelParameters = "";
15   var $gotoLdapServer       = "default-inherited";
16   var $gotoModules          = array();
17   var $gotoAutoFs           = array();
18   var $gotoFilesystem       = array();
19   var $gotoTerminalPath     = "";
20   var $gotoBootKernels      = array();
22   /* attribute list for save action */
23   var $attributes           = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", 
24                                     "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
25   var $objectclasses        = array("GOhard", "FAIobject");
27   /* Share */
28   var $gotoShares         = array();// Currently Share Option
29   var $gotoShare          = "";     // currently selected Share Option
30   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
31   var $gotoAvailableShares= array();// Available Shares for this account
33   /* Helper */
34   var $customParameters   = "";
35   var $orig_dn            = "";
36   var $ignore_account     = TRUE;
37  
38   /* FAI class selection */ 
39   var $FAIclass           = array();  // The currently selected classes 
40   var $FAIrelease           = "";
41   var $FAIdebianMirror      = "auto";
42   var $si_active            = FALSE;
43   var $si_fai_action_failed = FALSE;
45   var $cache              = array(); // Used as cache in fai mehtods
47   var $FAIstatus          = "";
48   var $FAIclasses         = array();
50   var $view_logged        = FALSE;
51   
52   /* FAI class selection */
53   var $InheritedFAIclass       = array();
54   var $InheritedFAIrelease     = "";
55   var $InheritedFAIdebianMirror= "auto";
57   var $CopyPasteVars    = array("gotoModules","gotoShares");
58   var $fai_activated    = FALSE;
59   var $o_group_dn       = "";
60   var $member_of_ogroup = FALSE;
62   function workstartup (&$config, $dn= NULL, $parent= NULL)
63   {
64     /* Check if FAI is active */
65     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
66     if(!empty($tmp) && class_available("faiManagement")){
67       $this->fai_activated = TRUE;
68     }else{
69       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
70       $this->objectclasses  = array("GOhard");
71     }
73     plugin::plugin ($config, $dn, $parent);
75     /* Check for si daemon */
76     $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
78     /* Check object group membership */
79     if(!isset($this->parent->by_object['ogroup'])){
80       $ldap = $this->config->get_ldap_link();
81       $ldap->cd ($this->config->current['BASE']);
82       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
83       if($ldap->count()){
84         $this->member_of_ogroup = TRUE;
85         $attrs = $ldap->fetch();
86         $this->o_group_dn = $attrs['dn'];
87       }
88     }
90     /* Creating a list of valid Mirrors 
91      * none will not be saved to ldap.
92      */
93     $ldap   = $this->config->get_ldap_link();
94     $ldap->cd($this->config->current['BASE']);
95     $ui = get_userinfo();
96     foreach($this->config->data['SERVERS']['LDAP'] as $dn => $data){
97       if($ui->get_category_permissions($data['dn'],"server",TRUE)){
98         for($i = 0; $i < $data['goLdapBase']['count']; $i ++){
99           $name = $data["cn"][0].":".$data["goLdapBase"][$i];
100           $this->gotoLdapServerList[]= $name; 
101         }
102       }
103     }
105     /* Get list of assigned ldap servers 
106      */ 
107     if(isset($this->attrs['gotoLdapServer'])){
108       unset($this->attrs['gotoLdapServer']['count']);
109       sort($this->attrs['gotoLdapServer']);
110       foreach($this->attrs['gotoLdapServer'] as $value){
111         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
112       }
113     } 
114     natcasesort($this->gotoLdapServerList);
116     if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ 
117       $this->gotoLdap_inherit = TRUE;
118     }
120     /* FAI Initialization
121        Skip this if FAI is not activated 
122      */
123     if($this->fai_activated) {
125       /* Parse used FAIclasses (stored as string).
126        * The single classes are seperated by ' '.
127        * There is also the release type given, after first
128        *  occurrence of ':'.
129        */
130       $this->FAIclass =array();
131       if(isset($this->attrs['FAIclass'][0])){
132         $tmp = split(" ",$this->attrs['FAIclass'][0]);
133         $tmp2 =array();  
135         foreach($tmp as $class){
136           if( ":" == $class[0] ) {
137             $this->FAIrelease = trim(substr($class, 1));
138           }else{
139             $tmp2[$class] = $class;
140           }
141         }
142         $this->FAIclass = $tmp2;
143       }
144     }
146     /* Get arrays */
147     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
148       if (isset($this->attrs["$val"]["count"])){
149         for ($i= 0; $i<$this->attrs["count"]; $i++){
150           if (isset($this->attrs["$val"][$i])){
151             array_push($this->$val, $this->attrs["$val"][$i]);
152           }
153         }
154       }
155       sort ($this->$val);
156       $this->$val= array_unique($this->$val);
157     }
159     /* Parse Kernel Parameters to decide what boot mode is enabled */
160     #if (preg_match("/ splash/", $this->gotoKernelParameters)){
161     #  $this->bootmode= "G";
162     #} elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
163     #  $this->bootmode= "D";
164     #} elseif ($this->gotoKernelParameters == "") {
165     #  $this->bootmode= "G";
166     #} else {
167     #  $this->bootmode= "T";
168     #}
169     #if (preg_match("/ o /", $this->gotoKernelParameters)){
170     #  $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
171     #} else {
172     #  $this->customParameters= "";
173     #}
174     $this->customParameters= preg_replace ("/^o /", "", $this->gotoKernelParameters);
176     /* Prepare Shares */
177     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
178       unset($this->attrs['gotoShare']['count']);
179       foreach($this->attrs['gotoShare'] as $share){
180         $tmp = $tmp2 = array();
181         $tmp = split("\|",$share);
182         $tmp2['server']      =$tmp[0];
183         $tmp2['name']        =$tmp[1];
184         $tmp2['mountPoint']  =$tmp[2];
185         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
186       }
187     }
189     $this->gotoShareSelections= $config->getShareList(true);
190     $this->gotoAvailableShares= $config->getShareList(false);
191     $tmp2 = array();
192   
194     $this->orig_dn= $this->dn;
196     /* Handle inheritance value "default" */
197     if ($this->member_of_ogroup){
198       $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); 
199     }
201     /* If we are member in an object group,
202      *  we have to handle inherited values.
203      * So you can see what is inherited.
204      */
205     if ($this->member_of_ogroup){
207       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
208         $this->FAIdebianMirror = "inherited";
209       }
211       if($this->fai_activated){
212         $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
213       }else{
214         $map= array("gotoBootKernel");
215       }
217       $ldap = $this->config->get_ldap_link();
218       $ldap->cat($this->o_group_dn);
219       $attrs= $ldap->fetch();
221       foreach ($map as $name){
222         if (!isset($attrs[$name][0])){
223           continue;
224         }
226         switch ($name){
227           case 'gotoBootKernel':
228             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
229             break;
231           case 'FAIclass':
232             $str = split(":",$attrs[$name][0]);
233             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
234             $this->InheritedFAIrelease  = trim($str[1]);
235             break;
237           case 'FAIdebianMirror':
238             $this->InheritedFAIdebianMirror = $attrs[$name][0];
239             break;
240         }
241       }
242     }
244     $this->update_fai_cache();
246     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
248       /* Check if the current mirror is available 
249        */
250       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
251         if(count($this->FAIclass)){
252           msg_dialog::display(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
253         }
254         $this->FAIdebianMirror = "auto";
255         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
256         $this->cache['CLASSES'] = array();
257         $this->update_fai_cache();
258       }
259   
260       /* Check if the current mirror is available 
261        */
262       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
263         $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); 
264         if(count($this->FAIclass)){
265           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);
266         }
267         $this->FAIrelease = $new_release;
268         $this->cache['CLASSES'] = array();
269         $this->update_fai_cache();
270       }
271     }
272   }
274   
275   function check()
276   {
277     $messages = array();
278     
279     /* Call common method to give check the hook */
280     $messages= plugin::check();
282     /* If there are packages selected, but no mirror show error */   
283     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
284       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
285     }
287     return($messages);
288   }
290   function execute()
291   {
292         /* Call parent execute */
293         plugin::execute();
295     if($this->is_account && !$this->view_logged){
296       $this->view_logged = TRUE;
297       new log("view","workstation/".get_class($this),$this->dn);
298     }
300     /* Do we represent a valid terminal? */
301     if (!$this->is_account && $this->parent === NULL){
302       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
303         msgPool::noValidExtension(_("workstation"))."</b>";
304       return ($display);
305     }
307     /* Add module */
308     if (isset ($_POST['add_module'])){
309       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModules")){
310         $this->add_list ($this->gotoModules, $_POST['module']);
311       }
312     }
314     /* Delete module */
315     if (isset ($_POST['delete_module'])){
316       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModules")){
317         $this->del_list ($this->gotoModules, $_POST['modules_list']);
318       }
319     }
321     /* FAI class management */
322     if($this->fai_activated){
323       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
324         $found = 0 ; 
326         /* If this new class/profile will attach a second partition table
327          * to our list of classes, abort and show a message.
328          */
329         foreach($this->FAIclass as $name){
330           if(isset($this->FAIclassInfo[$name])){
331             foreach($this->FAIclassInfo[$name] as $atr){
332               if(isset($atr['obj'])){
333                 if($atr['obj'] == "FAIpartitionTable"){
334                   $found ++ ; 
335                 }
336               }
337             }
338           }
339         }
341         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
342           msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
343         }else{
344           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
345         }
346       }
348       $sort = false;
350       /* Move one used class class one position up or down */
351       if($this->acl_is_writeable("FAIclass")){
352         foreach($_POST as $name => $val){
354           $sort_type = false;
355           if((preg_match("/sort_up/",$name))&&(!$sort)){
356             $sort_type = "sort_up_";
357           }
358           if((preg_match("/sort_down/",$name))&&(!$sort)){
359             $sort_type = "sort_down_";
360           }
362           if(($sort_type)&&(!$sort)){
363             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
364             $sort = true;
366             $last = -1;
367             $change_down  = -1;
369             /* Create array with numeric index */ 
370             $tmp = array();
371             foreach($this->FAIclass as $class){
372               $tmp [] = $class;
373             }
375             /* Walk trough array */
376             foreach($tmp as $key => $faiName){
377               if($faiName == $value){
378                 if($sort_type == "sort_up_"){
379                   if($last != -1){
380                     $change_down= $last;
381                   }
382                 }else{
383                   if(isset($tmp[$key+1])){
384                     $change_down = $key;
385                   }
386                 }
387               }
388               $last = $key;
389             }
391             $tmp2 = array();
392             $skip = false;    
394             foreach($tmp as $ky => $vl){
396               if($ky == $change_down){
397                 $skip = $vl;
398               }else{
399                 $tmp2[$vl] = $vl;
400               }
401               if(($skip != false)&&($ky != $change_down)){
402                 $tmp2[$skip]  = $skip;
403                 $skip =false;
404               }
405             }   
406             $this->FAIclass = $tmp2; 
407           }
409           if(preg_match("/fai_remove/i",$name)){
410             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
411             unset($this->FAIclass[$value]);
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", "customParameters", "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){
643           /* Mark invalid classes. (Not in selected release)
644            */
645           $marker = "";
646           if(in_array_ics($class,$invalid)){
647             $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
648           }
650           /* Create up/down priority icons  
651            * Skip this, if we have inherited the FAI classes.
652            */
653           if($this->FAIdebianMirror == "inherited"){
654             $str = "";
655           }else{
656             if($i==1){
657               $str = $str_empty.$str_down.$str_remove;
658             }elseif($i == count($this->FAIclass)){
659               $str = $str_up.$str_empty.$str_remove;
660             }else{
661               $str = $str_up.$str_down.$str_remove;
662             }
663           }
664           $i ++ ; 
666           /* Get Description tag 
667            *  There may be several FAI objects with the same class name, 
668            *   use the description from FAIprofile, if possible.
669            */  
670           $desc = ""; 
671           if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
672             foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
673               if(isset($types['Desc'])){
674                 $desc= $types['Desc'];
675                 if($types['Type'] == "FAIprofile"){
676                   break;
677                 }
678               }
679             }
680           }
681           if(!empty($desc)){
682             $desc = "&nbsp;[".trim($desc)."]";
683           }        
685           $div->AddEntry(array(
686                 array("string"=>$class.$desc.$marker),
687                 array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
688                 ));
689         }  
690       }// END FAI output generation 
691     }// END FAI output generation 
692     $smarty->assign("FAIScriptlist",$div->DrawList()); 
694     /* Radio button group */
695     if (preg_match("/G/", $this->bootmode)) {
696       $smarty->assign("graphicalbootup", "checked");
697     } else {
698       $smarty->assign("graphicalbootup", "");
699     }
700     if (preg_match("/T/", $this->bootmode)) {
701       $smarty->assign("textbootup", "checked");
702     } else {
703       $smarty->assign("textbootup", "");
704     }
705     if (preg_match("/D/", $this->bootmode)) {
706       $smarty->assign("debugbootup", "checked");
707     } else {
708       $smarty->assign("debugbootup", "");
709     }
711     /* Show main page */
712     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
713   }
716   function remove_from_parent()
717   {
718     $this->handle_post_events("remove");
719     new log("remove","workstation/".get_class($this),$this->dn);
720   }
723   /* Save data to object */
724   function save_object()
725   {
726     $old_mirror  = $this->FAIdebianMirror;
727     plugin::save_object();
729     /* Update release */
730     if($old_mirror != $this->FAIdebianMirror){
731       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
732         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
733       }
734     }
736     if(isset($_POST['WorkstationStarttabPosted'])){
737       if(isset($_POST['gotoLdap_inherit'])){
738         $this->gotoLdap_inherit = TRUE;
739       }else{
740         $this->gotoLdap_inherit = FALSE;
741       }
743       /* Save group radio buttons */
744       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
745         $this->bootmode= $_POST["bootmode"];
746       }
748       /* Save kernel parameters */
749       if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
750         $this->customParameters= $_POST["customParameters"];
751       }
752     }
753   }
756   /* Save to LDAP */
757   function save()
758   {
760     /* Depending on the baseobject (Ogroup / WS) we
761      *  use another set of objectClasses
762      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
763      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
764      */
765     if(isset($this->parent->by_object['ogroup'])){
766       $this->objectclasses = array("gotoWorkstationTemplate");
767     }elseif(isset($this->parent->by_object['workgeneric'])){
768       $this->objectclasses = array("GOhard");
769     }elseif(isset($this->parent->by_object['servgeneric'])){
770       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
771     }else{
772       msg_dialog::display(_("Fatal error"),
773           "Object Type Configuration is unknown. Please contact the GOsa developers.",
774           FATAL_ERROR_DIALOG);
775       exit();
776     }
778     /* Append FAI class */
779     if($this->fai_activated){
780       $this->objectclasses[]  = "FAIobject";
781     }
783     /* Find proper terminal path for tftp configuration
784        FIXME: This is suboptimal when the default has changed to
785        another location! */
786     if (($this->gotoTerminalPath == "default")){
787       $ldap= $this->config->get_ldap_link();
789       /* Strip relevant part from dn, keep trailing ',' */
790       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
791       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
793       /* Walk from top to base and try to load default values for
794          'gotoTerminalPath'. Abort when an entry is found. */
795       while (TRUE){
796         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
798         $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
799             $this->config->current['BASE'], array('gotoTerminalPath'));
800         $attrs= $ldap->fetch();
801         if (isset($attrs['gotoTerminalPath'])){
802           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
803           break;
804         }
806         /* Nothing left? */
807         if ($tmp == ""){
808           break;
809         }
810       }
811     }
813     /* Add semi automatic values */
814     $this->gotoKernelParameters= "";
816     switch ($this->bootmode){
817       case "D":
818         $this->gotoKernelParameters.= " debug";
819       break;
820       case "G":
821         $this->gotoKernelParameters.= " splash quiet";
822       break;
823     }
824     if ($this->customParameters != ""){
825                         # This should be enabled after boot-mode is available again
826       #$this->gotoKernelParameters.= " o ".$this->customParameters;
827       $this->gotoKernelParameters= $this->customParameters;
828     }
830     plugin::save();
832     unset( $this->attrs['FAIrelease'] );
833     $str = "";
835     /* Skip FAI attribute handling if not necessary */
836     if($this->fai_activated && !$this->si_fai_action_failed){
837       if($this->FAIdebianMirror == "inherited"){
838         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
839       }else{
840         foreach($this->FAIclass as $class){
841           $str .= $class." ";
842         }
843         $str = trim($str);
844         if(empty($this->attrs['FAIclass'])){
845           $this->attrs['FAIclass'] = array();
846         }else{
847           $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
848         }
849       }
850     }
852     /* Add missing arrays */
853     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
854       if (isset ($this->$val) && count ($this->$val) != 0){
855     
856         $this->attrs["$val"]= array_unique($this->$val);
857       }
858       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
859     }
861     /* Prepare list of ldap servers */
862     $this->attrs['gotoLdapServer'] = array();
863     if(!$this->gotoLdap_inherit){
864       $i = 0;
865       foreach($this->gotoLdapServers as $server){
866         $i ++;
867         $this->attrs['gotoLdapServer'][] = $i.":".$server;
868       }
869     }
871     if ($this->attrs['gotoBootKernel'] == "default-inherited"){
872       $this->attrs['gotoBootKernel']= array();
873     }
875     /* if mirror == none stop saving this attribute */
876     if($this->FAIdebianMirror == "none"){
877       $this->FAIdebianMirror = "";
878     }
879    
880     /* Get FAIstate from object, the generic tab could have changed it during execute */
881     $ldap= $this->config->get_ldap_link();
882     $ldap->cd($this->dn);
885     /* Skip FAI attribute handling if not necessary */
886     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
887       $ldap->cat($this->dn,array("FAIstate"));
888       $checkFAIstate = $ldap->fetch();
890       /* Remove FAI objects if no FAI class is selected */ 
891       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
892         $this->attrs['FAIclass']        = array();
893         $this->attrs['FAIdebianMirror'] = array();
894       }
895     }else{
897       /* Don't touch FAI objects if something went wrong with the si daemon.
898        */
899       if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
900       if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
901     }
903     /* prepare share settings */
904     $tmp = array();
905     foreach($this->gotoShares as $name => $settings){
906       $tmp2= split("\|",$name);
907       $name = $tmp2[0];
908       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
909     }
910     $this->attrs['gotoShare']=$tmp;
911     $this->cleanup();
912     $ldap->modify ($this->attrs); 
913     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
915     if (!$ldap->success()){
916       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
917     }
918     $this->handle_post_events("modify");
920     /* Check if LDAP server has changed */
921     if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
922       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
923       $o_queue = new gosaSupportDaemon();
924       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
925         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
926         $macs = array();
927     
928         /* Get list of macAddresses 
929          */
930         if(isset($this->parent->by_object['ogroup'])){
931         
932           /* If we are an object group, add all member macs 
933            */
934           $p = $this->parent->by_object['ogroup'];
935           foreach($p->memberList as $dn => $obj){
936             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
937               $macs[] = $p->objcache[$dn]['macAddress'];
938             }
939           }
940         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
942           /* We are a workstation. Add current mac.
943            */
944           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
945           if(!empty($mac)){
946             $macs[] = $mac;
947           }          
948         }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
950           /* We are a server. Add current mac.
951            */
952           $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
953           if(!empty($mac)){
954             $macs[] = $mac;
955           }          
956         }
958         /* Trigger event for all member objects 
959          */
960         foreach($macs as $mac){
961           $tmp = new $evt['CLASS_NAME']($this->config);
962           $tmp->set_type(TRIGGERED_EVENT);
963           $tmp->add_targets(array($mac));
964           if(!$o_queue->append($tmp)){
965             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
966           }
967         }
968       }
969     }
970   }
973   /* Add value to array, check if unique */
974   function add_list (&$array, $value)
975   {
976     if ($value != ""){
977       $array[]= $value;
978       sort($array);
979       array_unique ($array);
980     }
981   }
984   /* Delete value to array, check if unique */
985   function del_list (&$array, $list)
986   {
987     $tmp= array();
988     foreach ($array as $mod){
989       if (!in_array($mod, $list)){
990         $tmp[]= $mod;
991       }
992     }
993     $array= $tmp;
994   }
996   /* Generate ListBox frindly output for the defined shares
997    * Possibly Add or remove an attribute here,
998    */
999   function printOutAssignedShares()
1000   {
1001     $a_return = array();
1002     if(is_array($this->gotoShares)){
1003       foreach($this->gotoShares as $share){
1004         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1005       }
1006     }
1007     return($a_return);
1008   }
1012   function PrepareForCopyPaste($source)
1013   {
1014     plugin::PrepareForCopyPaste($source);    
1015     $source_o = new workstartup ($this->config, $source['dn']);
1016     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1017           "gotoKernelParameters","gotoShares","customParameters") as $attr){
1018       $this->$attr = $source_o->$attr;
1019     }
1020   }
1022   
1023   function array_switch_item($ar,$from,$to)
1024   {
1025     if(!is_array($ar)){
1026       return(false);
1027     }
1028     if(!isset($ar[$from])){
1029       return(false);
1030     }
1031     if(!isset($ar[$to])){
1032       return(false);
1033     }
1035     $tmp = $ar[$from];
1036     $ar[$from] = $ar[$to];    
1037     $ar[$to] = $tmp;    
1038     return($ar);
1039   }
1042   /* Return plugin informations for acl handling */ 
1043   static function plInfo()
1044   {
1045     return (array( 
1046           "plShortName"   => _("Startup"),
1047           "plDescription" => _("System startup"),
1048           "plSelfModify"  => FALSE,
1049           "plDepends"     => array(),
1050           "plPriority"    => 9,
1051           "plSection"     => array("administration"),           
1052           "plCategory"    => array("workstation","server","ogroups"),
1054           "plProvidedAcls"=> array(
1055             "gotoLdapServer"        => _("Ldap server"),
1056             "gotoBootKernel"        => _("Boot kernel"),
1057             "gotoKernelParameters"  => _("Kernel parameter"),
1059             "gotoModules"           => _("Kernel modules"),
1060             "gotoShare"             => _("Shares"),
1062             "FAIclass"              => _("FAI classes"),
1063             "FAIdebianMirror"       => _("Debian mirror"),
1064             "FAIrelease"            => _("Debian release"),
1066             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1067           ));
1068   }
1071   /* Updates release dns 
1072    *  and reads all classes for the current release, 
1073    *  if not already done ($this->cache).
1074    */
1075   function update_fai_cache($first_call = FALSE)
1076   {
1077     $force = FALSE;
1078     if(!$this->si_active) return; 
1079     $start = microtime(TRUE);  
1081     if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1083     $this->si_fai_action_failed = FALSE;
1085     /* Get the list of available servers and their releases. 
1086      */
1087     if($force || !isset($this->cache['SERVERS'])){
1089       $o_queue = new gosaSupportDaemon();
1090       $tmp = $o_queue->FAI_get_server();
1091       if($o_queue->is_error()){
1092         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1093         $this->si_fai_action_failed = TRUE;
1094         $this->cache = array();
1095         return;
1096       }else{
1098         foreach($tmp as $entry){
1099           $rel = $entry['FAI_RELEASE'];
1100           $this->cache['SERVERS']['auto'][$rel] = $rel;
1101           $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1102           uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1103           uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1104         }
1105       }
1106     }
1108     /* Ensure that our selection is valid, else we get several PHP warnings 
1109         if there is no FAI configuration at all.
1110      */
1111     if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1112       $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1113     }
1115     /* Build up arrays, without checks */
1116     if(!$first_call){
1118       /* Check if the selected mirror is available */
1119       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1120         $this->FAIdebianMirror = "auto";
1121         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1122         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1123       }
1125       /* Check if the selected release is available */
1126       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1128         if($this->FAIrelease != ""){
1129           trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1130         }
1131         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1132       }
1133     }
1135     /* Get classes for release from cache. 
1136      * Or build cache
1137      */
1138     if($this->FAIdebianMirror == "inherited"){
1139       $release = $this->InheritedFAIrelease;
1140     }else{
1141       $release = $this->FAIrelease;
1142     }
1144     if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1146       /* Get the list of available servers and their releases.
1147        */
1148       $o_queue = new gosaSupportDaemon();
1149       $tmp = $o_queue->FAI_get_classes($release);
1150       $this->cache['CLASSES'][$release] = array();
1151       if($o_queue->is_error()){
1152         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1153         $this->si_fai_action_failed = TRUE;
1154         $this->cache=array();
1155         return;
1156       }else{
1157         foreach($tmp as $entry){
1158           $class = $entry['CLASS'];
1159           $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
1160         }
1161       }
1163       /* Add object caught from external hook
1164        */
1165       $lines= $this->GetHookElements();
1166       foreach ($lines as $hline){
1167         $entries= split(";", $hline);
1168         $server = $entries['0'];
1169         $url    = $entries['1'];
1170         if (!empty($url)){
1172           /* Split releases */
1173           if (isset($entries[2])){
1174             $releases= split(",", $entries[2]);
1176             foreach ($releases as $release_data){
1177               $release_c  = preg_replace('/:.*$/', '', $release_data);
1178               $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1179               $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1181               if($release_c == $release){
1182                 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1183                 $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
1184                 foreach ($classes_c as $class){
1185                   if ($class != ""){
1186                     $this->cache['CLASSES'][$release_c][$class]= array();
1187                   }
1188                 }
1189               }
1190             }
1191           }
1192         }
1193       }
1194       uksort($this->cache['SERVERS'], 'strnatcasecmp');
1196       /* Only add inherit option, if we are part in an object group
1197        */
1198       if($this->member_of_ogroup){
1199         $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1200       }
1201     }
1203     /* Get list of available kernel for this release 
1204      */
1205     if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1207     if($force || !isset($this->cache['KERNELS'][$release])){
1208       $o_queue = new gosaSupportDaemon();
1209       $tmp = $o_queue->FAI_get_kernels($release);
1210       $this->cache['KERNELS'][$release] = array();
1211       foreach($this->gotoBootKernels as $name => $default){
1212         $this->cache['KERNELS'][$release][$name] = $default;
1213       }
1214       foreach($tmp as $kernel){
1215         if(empty($kernel)) continue;
1216         $this->cache['KERNELS'][$release][$kernel]=$kernel;
1217       }
1218       ksort($this->cache['KERNELS'][$release]);
1219     }
1220   }
1223   /* This function return an array containing all 
1224    *  invalid classes for the selected server/release
1225    */
1226   function get_invalid_classes($classes)
1227   {
1228     $this->update_fai_cache();
1229     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1230       $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1231     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1232       $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1233     }else{
1234       $release_classes = array();
1235     }
1238     /* Detect all classes that are not valid 
1239      *  for the selected release 
1240      */
1241     $NA = array();
1242     foreach($classes as $class){
1243       if(!isset($release_classes[$class])){
1244         $NA[] = $class;
1245       }
1246     }
1247     return($NA);
1248   }  
1250   
1251   /* Get all selectable classes for the ui select box
1252    */
1253   function selectable_classes()
1254   {
1255     $this->update_fai_cache();
1257     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1258       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1259     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1260       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1261     }else{
1262       $classes = array();
1263     }
1265     $Abbr ="";
1266     $ret= array();
1267     foreach($classes as $class_name => $class_types){
1268       if(!in_array($class_name,$this->FAIclass)){
1269         foreach($class_types as $type){
1270           if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1271             $Abbr .= $type['Abbr']." ";
1272           }
1273         }
1274         $ret[$class_name] = trim($Abbr);
1275       }
1276     }
1277     uksort($ret, 'strnatcasecmp');
1278     return($ret);
1279   }
1282   /* Analyse FAI object and return an array with usefull informations like 
1283    *  FAIobject type.
1284    */
1285   function analyse_fai_object($attr)
1286   {
1287     $tmp = array();
1288     switch($attr['TYPE']){
1290       case 'FAIpackageList':
1291         $tmp["Type"]= 'FAIpackageList';
1292         $tmp["Abbr"]= 'Pl';
1293         break;
1294       case 'FAItemplate': 
1295         $tmp["Type"]= 'FAItemplate'; 
1296         $tmp["Abbr"]= 'T'; 
1297         break;
1298       case 'FAIvariable':
1299         $tmp["Type"]= 'FAIvariable'; 
1300         $tmp["Abbr"]= 'V'; 
1301         break;
1302       case 'FAIscript':
1303         $tmp["Type"]= 'FAIscript'; 
1304         $tmp["Abbr"]= 'S'; 
1305         break;
1306       case 'FAIhook':
1307         $tmp["Type"]= 'FAIhook'; 
1308         $tmp["Abbr"]= 'H'; 
1309         break;
1310       case 'FAIpartitionTable':
1311         $tmp["Type"]= 'FAIpartitionTable'; 
1312         $tmp["Abbr"]= 'Pt'; 
1313         break;
1314       case 'FAIprofile':
1315         $tmp["Type"]= 'FAIprofile'; 
1316         $tmp["Abbr"]= 'P'; 
1317         break;
1318       default: trigger_error("Unknown FAI object type!");;
1319     }
1320     return($tmp);
1321   }
1324   /* Return repository hook output, if possible.
1325    */
1326   function GetHookElements()
1327   {
1328     $ret = array();
1329     $cmd= $this->config->search("servrepository", "repositoryBranchHook",array('tabs'));
1330     if(!empty($cmd)){
1331       $res = shell_exec($cmd);
1332       $res2 = trim($res);
1333       if((!$res)){
1334         msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("repositoryBranchHook", $cmd), ERROR_DIALOG);
1335       }elseif(empty($res2)){
1336         msg_dialog::display(_("Configuration error"), _("'repositoryBranchHook' returned no result!"), ERROR_DIALOG);
1337       }else{
1338         $tmp = split("\n",$res);
1339         foreach($tmp as $line){
1340           if(empty($line)) continue;
1341           $ret[]= $line;
1342         }
1343       }
1344     }
1345     return($ret);
1346   }
1349   /* This function creates the release name out of a dn 
1350    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1351    */
1352   function dn_to_release_name($dn)
1353   {
1354     $relevant = preg_replace("/,".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$dn);
1355     $parts    = array_reverse(split("\,",$relevant));
1356     $str ="";
1357     foreach($parts as $part){
1358       $str .= preg_replace("/^ou=/","",$part)."/";
1359     }
1360     return(preg_replace("/\/$/","",$str)); 
1361   }
1364 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1365 ?>