Code

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