Code

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