Code

Updated WorkstationStartup.
[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";
41   var $cache              = array(); // Used as cache in fai mehtods
43   var $FAIstatus          = "";
44   var $FAIclasses         = array();
46   var $view_logged        = FALSE;
47   
48   /* FAI class selection */
49   var $InheritedFAIclass       = array();
50   var $InheritedFAIrelease     = "";
51   var $InheritedFAIdebianMirror= "auto";
53   var $CopyPasteVars    = array("gotoModules","gotoShares");
54   var $fai_activated    = FALSE;
55   var $o_group_dn       = "";
56   var $member_of_ogroup = FALSE;
58   function workstartup (&$config, $dn= NULL, $parent= NULL)
59   {
60     /* Check if FAI is active */
61     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
62     if(!empty($tmp)){
63       $this->fai_activated = TRUE;
64     }else{
65       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
66       $this->objectclasses  = array("GOhard");
67     }
69     plugin::plugin ($config, $dn, $parent);
71     /* Check object group membership */
72     if(!isset($this->parent->by_object['ogroup'])){
73       $ldap = $this->config->get_ldap_link();
74       $ldap->cd ($this->config->current['BASE']);
75       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
76       if($ldap->count()){
77         $this->member_of_ogroup = TRUE;
78         $attrs = $ldap->fetch();
79         $this->o_group_dn = $attrs['dn'];
80       }
81     }
83     /* Creating a list of valid Mirrors 
84      * none will not be saved to ldap.
85      */
86     $ldap   = $this->config->get_ldap_link();
87     $ldap->cd($this->config->current['BASE']);
88     foreach($this->config->data['SERVERS']['LDAP'] as $server) {
89       $this->gotoLdapServerList[]= $server; 
90     }
92     /* Get list of assigned ldap servers 
93      */ 
94     if(isset($this->attrs['gotoLdapServer'])){
95       unset($this->attrs['gotoLdapServer']['count']);
96       sort($this->attrs['gotoLdapServer']);
97       foreach($this->attrs['gotoLdapServer'] as $value){
98         $this->gotoLdapServers[] = preg_replace("/^[0-9]*:/","",$value);
99       }
100     }
101     if(!count($this->gotoLdapServers) && $this->member_of_ogroup){ 
102       $this->gotoLdap_inherit = TRUE;
103     }
105     /* FAI Initialization
106        Skip this if FAI is not activated 
107      */
108     if($this->fai_activated) {
110       $this->update_fai_cache(TRUE);
112       /* Parse used FAIclasses (stored as string).
113        * The single classes are seperated by ' '.
114        * There is also the release type given, after first
115        *  occurrence of ':'.
116        */
117       $this->FAIclass =array();
118       if(isset($this->attrs['FAIclass'][0])){
119         $tmp = split(" ",$this->attrs['FAIclass'][0]);
120         $tmp2 =array();  
122         foreach($tmp as $class){
123           if( ":" == $class[0] ) {
124             $this->FAIrelease = trim(substr($class, 1));
125           }else{
126             $tmp2[$class] = $class;
127           }
128         }
129         $this->FAIclass = $tmp2;
130       }
131     }
133     /* Get arrays */
134     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
135       if (isset($this->attrs["$val"]["count"])){
136         for ($i= 0; $i<$this->attrs["count"]; $i++){
137           if (isset($this->attrs["$val"][$i])){
138             array_push($this->$val, $this->attrs["$val"][$i]);
139           }
140         }
141       }
142       sort ($this->$val);
143       $this->$val= array_unique($this->$val);
144     }
146     /* Parse Kernel Parameters to decide what boot mode is enabled */
147     if (preg_match("/ splash=silent/", $this->gotoKernelParameters)){
148       $this->bootmode= "G";
149     } elseif (preg_match("/ debug/", $this->gotoKernelParameters)){
150       $this->bootmode= "D";
151     } elseif ($this->gotoKernelParameters == "") {
152       $this->bootmode= "G";
153     } else {
154       $this->bootmode= "T";
155     }
156     if (preg_match("/ o /", $this->gotoKernelParameters)){
157       $this->customParameters= preg_replace ("/^.* o /", "", $this->gotoKernelParameters);
158     } else {
159       $this->customParameters= "";
160     }
162     /* Prepare Shares */
163     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
164       unset($this->attrs['gotoShare']['count']);
165       foreach($this->attrs['gotoShare'] as $share){
166         $tmp = $tmp2 = array();
167         $tmp = split("\|",$share);
168         $tmp2['server']      =$tmp[0];
169         $tmp2['name']        =$tmp[1];
170         $tmp2['mountPoint']  =$tmp[2];
171         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
172       }
173     }
175     $this->gotoShareSelections= $config->getShareList(true);
176     $this->gotoAvailableShares= $config->getShareList(false);
177     $tmp2 = array();
178   
180     $this->orig_dn= $this->dn;
182     /* Handle inheritance value "default" */
183     if ($this->member_of_ogroup){
184       $this->gotoBootKernels= array("default-inherited" => '['._("inherited").']'); 
185     }
187     /* If we are member in an object group,
188      *  we have to handle inherited values.
189      * So you can see what is inherited.
190      */
191     if ($this->member_of_ogroup){
193       if(count($this->FAIclass)==0 && $this->FAIrelease == ""){
194         $this->FAIdebianMirror = "inherited";
195       }
197       if($this->fai_activated){
198         $map= array("gotoBootKernel","FAIclass","FAIdebianMirror");
199       }else{
200         $map= array("gotoBootKernel");
201       }
203       $ldap = $this->config->get_ldap_link();
204       $ldap->cat($this->o_group_dn);
205       $attrs= $ldap->fetch();
207       foreach ($map as $name){
208         if (!isset($attrs[$name][0])){
209           continue;
210         }
212         switch ($name){
213           case 'gotoBootKernel':
214             $this->gotoBootKernels['default-inherited']=  _("inherited").' ['.$attrs[$name][0].']' ;
215             break;
217           case 'FAIclass':
218             $str = split(":",$attrs[$name][0]);
219             $this->InheritedFAIclass    = split("\ ",trim($str[0]));
220             $this->InheritedFAIrelease  = trim($str[1]);
221             break;
223           case 'FAIdebianMirror':
224             $this->InheritedFAIdebianMirror = $attrs[$name][0];
225             break;
226         }
227       }
228     }
231     if($this->fai_activated){
233       /* Check if the current mirror is available 
234        */
235       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
236         if(count($this->FAIclass)){
237           msg_dialog(_("Error"), sprintf(_("FAI mirror '%s' is not available - setting to mirror 'auto'!"), $this->FAIdebianMirror), ERROR_DIALOG);
238         }
239         $this->FAIdebianMirror = "auto";
240         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
241         $this->cache =array();
242         $this->update_fai_cache();
243         
244       }
245   
246       /* Check if the current mirror is available 
247        */
248       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
249         $new_release = key($this->cache['SERVERS'][$this->FAIdebianMirror]); 
250         if(count($this->FAIclass)){
251           msg_dialog(_("Error"), sprintf(_("FAI release '%s' is not available on mirror '%s' - setting to release '%s'!"), $this->FAIrelease, $this->FAIdebianmirror), ERROR_DIALOG);
252         }
253         $this->FAIrelease = $new_release;
254         $this->cache =array();
255         $this->update_fai_cache();
256       }
257     }
259     /* Get list of boot kernels */
260     if (isset($this->config->data['TABS'])){
261       $command= $this->config->search(get_class($this), "KERNELS",array('tabs'));
262       if (!check_command($command)){
263         $message[]= sprintf(_("Command '%s', specified as KERNELS hook for plugin '%s' doesn't seem to exist."), $command,
264             get_class($this));
265       } else {
266         $fh= popen($command, "r");
267         while (!feof($fh)) {
268           $buffer= trim(fgets($fh, 256));
269           if(!empty($buffer)){
270             $name=$value = $buffer;
271             if(preg_match("/:/",$buffer)){
272               $name = preg_replace("/:.*$/","",$buffer);
273               $value= preg_replace("/^.*:/","",$buffer);
274               $this->gotoBootKernels[$name]= $name.":".$value;
275             }else{
276               $this->gotoBootKernels[$name]= $value;
277             }
278           }
279         }
280         pclose($fh);
281       }
282     }
284     /* Turn to default, if we've nothing to inherit */
285     if (!isset($this->gotoBootKernels['default-inherited']) && $this->gotoBootKernel == "default-inherited"){
286       $this->gotoBootKernel= "default";
287     }
288   }
290   
291   function check()
292   {
293     $messages = array();
294     
295     /* Call common method to give check the hook */
296     $messages= plugin::check();
298     /* If there are packages selected, but no mirror show error */   
299     if(($this->FAIdebianMirror == "none")&&(count($this->FAIclass)>0)){
300       $messages[]=_("Please select a 'FAI server' or remove the 'FAI classes'.");
301     }
303     return($messages);
304   }
306   function execute()
307   {
308         /* Call parent execute */
309         plugin::execute();
311     if($this->is_account && !$this->view_logged){
312       $this->view_logged = TRUE;
313       new log("view","workstation/".get_class($this),$this->dn);
314     }
316     /* Do we need to flip is_account state? */
317     if(isset($_POST['modify_state'])){
318       if($this->is_account && $this->acl_is_removeable()){
319         $this->is_account= FALSE;
320       }elseif(!$this->is_account && $this->acl_is_createable()){
321         $this->is_account= TRUE;
322       }
323     }
325     /* Do we represent a valid terminal? */
326     if (!$this->is_account && $this->parent === NULL){
327       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
328         msgPool::noValidExtension(_("workstation"))."</b>";
329       return ($display);
330     }
332     /* Add module */
333     if (isset ($_POST['add_module'])){
334       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
335         $this->add_list ($this->gotoModules, $_POST['module']);
336       }
337     }
339     /* Delete module */
340     if (isset ($_POST['delete_module'])){
341       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
342         $this->del_list ($this->gotoModules, $_POST['modules_list']);
343       }
344     }
346     /* FAI class management */
347     if($this->fai_activated){
348       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
349         $found = 0 ; 
351         /* If this new class/profile will attach a second partition table
352          * to our list of classes, abort and show a message.
353          */
354         foreach($this->FAIclass as $name){
355           if(isset($this->FAIclassInfo[$name])){
356             foreach($this->FAIclassInfo[$name] as $atr){
357               if(isset($atr['obj'])){
358                 if($atr['obj'] == "FAIpartitionTable"){
359                   $found ++ ; 
360                 }
361               }
362             }
363           }
364         }
366         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
367           msg_dialog(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
368         }else{
369           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
370         }
371       }
373       $sort = false;
375       /* Move one used class class one position up or down */
376       if($this->acl_is_writeable("FAIclass")){
377         foreach($_POST as $name => $val){
379           $sort_type = false;
380           if((preg_match("/sort_up/",$name))&&(!$sort)){
381             $sort_type = "sort_up_";
382           }
383           if((preg_match("/sort_down/",$name))&&(!$sort)){
384             $sort_type = "sort_down_";
385           }
387           if(($sort_type)&&(!$sort)){
388             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
389             $sort = true;
391             $last = -1;
392             $change_down  = -1;
394             /* Create array with numeric index */ 
395             $tmp = array();
396             foreach($this->FAIclass as $class){
397               $tmp [] = $class;
398             }
400             /* Walk trough array */
401             foreach($tmp as $key => $faiName){
402               if($faiName == $value){
403                 if($sort_type == "sort_up_"){
404                   if($last != -1){
405                     $change_down= $last;
406                   }
407                 }else{
408                   if(isset($tmp[$key+1])){
409                     $change_down = $key;
410                   }
411                 }
412               }
413               $last = $key;
414             }
416             $tmp2 = array();
417             $skip = false;    
419             foreach($tmp as $ky => $vl){
421               if($ky == $change_down){
422                 $skip = $vl;
423               }else{
424                 $tmp2[$vl] = $vl;
425               }
426               if(($skip != false)&&($ky != $change_down)){
427                 $tmp2[$skip]  = $skip;
428                 $skip =false;
429               }
430             }   
431             $this->FAIclass = $tmp2; 
432           }
434           if(preg_match("/fai_remove/i",$name)){
435             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
436             unset($this->FAIclass[$value]);
437           }
438         }
439       }
441       /* Delete selected class from our list */
442       if($this->acl_is_writeable("FAIclass")){
443         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
444           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
445             unset($this->FAIclass[$_POST['FAIclassSel']]);
446           }
447         }
448       }
449     }// END fai handling
451     /* Show main page */
452     $smarty= get_smarty();
454     /* Assign ACLs to smarty */
455     $tmp = $this->plInfo();
456     foreach($tmp['plProvidedAcls'] as $name => $translation){
457       $smarty->assign($name."ACL",$this->getacl($name));
458     } 
460     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
462     /* In this section server shares will be defined
463      * A user can select one of the given shares and a mount point
464      *  and attach this combination to his setup.
465      */
466     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
467     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
469     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
470      * This entry will be, a combination of mountPoint and sharedefinitions
471      */
472     if((isset($_POST['gotoShareAdd'])) && ($this->acl_is_writeable("gotoShare"))) {
473       /* We assign a share to this user, if we don't know where to mount the share */
474       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
475         msg_dialog(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
476       }else{
477         if(count($this->gotoAvailableShares)){
478           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
479           $s_mount = $_POST['gotoShareMountPoint'];
480           /* Preparing the new assignment */
481           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
482           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
483         }
484       }
485     }
487     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
488      * If there is no defined share selected, we will abort the deletion without any message
489      */
490     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
491       unset($this->gotoShares[$_POST['gotoShare']]);
492     }
494     $smarty->assign("gotoShares",$this->printOutAssignedShares());
495     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
496     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
497     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
499     /* Create divSelectBox for ldap server selection
500      */
501     $SelectBoxLdapServer = new divSelectBox("LdapServer");
502     $SelectBoxLdapServer->SetHeight(130);
504     /* Add new ldap server to the list */
505     if(!$this->gotoLdap_inherit && isset($_POST['add_ldap_server']) && isset($_POST['ldap_server_to_add'])){
506       if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
507         $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
508         if(!in_array($to_add,$this->gotoLdapServers)){
509           $this->gotoLdapServers[] = $to_add;
510         }
511       }
512     }
513     
514     /* Move ldap servers up and down */
515     if(!$this->gotoLdap_inherit){
516       foreach($_POST as $name => $value){
517         if(preg_match("/sort_ldap_up_/",$name)){
518           $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
519           $from =  $id;  
520           $to   =  $id -1;
521           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
522           if($tmp){
523             $this->gotoLdapServers = $tmp;
524           }
525           break;
526         }
527         if(preg_match("/sort_ldap_down_/",$name)){
528           $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
529           $from =  $id;  
530           $to   =  $id +1;
531           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
532           if($tmp){
533             $this->gotoLdapServers = $tmp;
534           }
535           break;
536         }
537         if(preg_match("/gotoLdapRemove_/",$name)){
538           $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
539           $value = $this->gotoLdapServers[$id];
540           $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
541           break;
542         }
543       } 
544     }
545   
546     /* Add Entries 
547      */
548     foreach($this->gotoLdapServers as $key => $server){
549       if(!in_array($server,$this->gotoLdapServerList)){
550         $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
551       }
553       $SelectBoxLdapServer->AddEntry(
554           array(array("string" => $server),
555             array("string" => 
556               "<input class='center' type='image' src='images/sort_up.png' name='sort_ldap_up_".$key."'>&nbsp;".
557               "<input class='center' type='image' src='images/sort_down.png' name='sort_ldap_down_".$key."'>&nbsp;".
558               "<input class='center' type='image' src='images/edittrash.png' name='gotoLdapRemove_".$key."'>",
559               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
560     }    
562     if($this->gotoLdap_inherit){
563       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
564     }else{
565       $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
566     }
567     
568     $list = array();
569     foreach($this->gotoLdapServerList as $key => $entry){
570       if(!in_array($entry,$this->gotoLdapServers)){
571         $list[$key] = $entry;
572       }
573     }
574     $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
575     $smarty->assign("gotoLdapServerList", $list);
576     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
577     $smarty->assign("JS",  session::get('js'));
579     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
580       $smarty->assign("$val", $this->$val);
581     }
583     /* Values */
584     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
585       $smarty->assign($val, $this->$val);
586     }
588     $smarty->assign("fai_activated",$this->fai_activated);
590     /* Create FAI output */
591     if($this->fai_activated){
593       $this->update_fai_cache();
595       $smarty->assign("FAIservers"  , $this->cache['SERVERS']);
596       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
597       $smarty->assign("FAIrelease"  , $this->FAIrelease);
598       $smarty->assign("FAIclasses"  , $this->selectable_classes());
600       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
602       $div = new divSelectBox("WSFAIscriptClasses");
603       $div -> SetHeight("110");
604       $str_up     = " &nbsp;<input type='image' src='images/sort_up.png'    name='sort_up_%s'    value='%s'>";
605       $str_down   = " &nbsp;<input type='image' src='images/sort_down.png'  name='sort_down_%s'  value='%s'>";
606       $str_remove = " &nbsp;<input type='image' src='images/edittrash.png'  name='fai_remove_%s' value='%s'>";
607       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
609       /* Get classes */
610       if($this->FAIdebianMirror == "inherited"){
611         $tmp = $this->InheritedFAIclass;
612       }else{
613         $tmp = $this->FAIclass;
614       }
616       /* Get invalid classes */
617       $invalid = $this->get_invalid_classes($tmp);
619       /* Draw every single entry */
620       $i = 1;
621       foreach($tmp as $class){
623         /* Mark invalid classes. (Not in selected release)
624          */
625         $marker = "";
626         if(in_array_ics($class,$invalid)){
627           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
628         }
630         /* Create up/down priority icons  
631          * Skip this, if we have inherited the FAI classes.
632          */
633         if($this->FAIdebianMirror == "inherited"){
634           $str = "";
635         }else{
636           if($i==1){
637             $str = $str_empty.$str_down.$str_remove;
638           }elseif($i == count($this->FAIclass)){
639             $str = $str_up.$str_empty.$str_remove;
640           }else{
641             $str = $str_up.$str_down.$str_remove;
642           }
643         }
644         $i ++ ; 
646         /* Get Description tag 
647          *  There may be several FAI objects with the same class name, 
648          *   use the description from FAIprofile, if possible.
649          */  
650         $desc = ""; 
651         if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
652           foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
653             if(isset($types['Desc'])){
654               $desc= $types['Desc'];
655               if($types['Type'] == "FAIprofile"){
656                 break;
657               }
658             }
659           }
660         }
661         if(!empty($desc)){
662           $desc = "&nbsp;[".trim($desc)."]";
663         }        
665         $div->AddEntry(array(
666               array("string"=>$class.$desc.$marker),
667               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
668               ));
669       }  
670       $smarty->assign("FAIScriptlist",$div->DrawList()); 
671     }// END FAI output generation 
673     /* Radio button group */
674     if (preg_match("/G/", $this->bootmode)) {
675       $smarty->assign("graphicalbootup", "checked");
676     } else {
677       $smarty->assign("graphicalbootup", "");
678     }
679     if (preg_match("/T/", $this->bootmode)) {
680       $smarty->assign("textbootup", "checked");
681     } else {
682       $smarty->assign("textbootup", "");
683     }
684     if (preg_match("/D/", $this->bootmode)) {
685       $smarty->assign("debugbootup", "checked");
686     } else {
687       $smarty->assign("debugbootup", "");
688     }
690     /* Show main page */
691     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
692   }
695   function remove_from_parent()
696   {
697     $this->handle_post_events("remove");
698     new log("remove","workstation/".get_class($this),$this->dn);
699   }
702   /* Save data to object */
703   function save_object()
704   {
705     $old_mirror  = $this->FAIdebianMirror;
706     plugin::save_object();
708     /* Update release */
709     if($old_mirror != $this->FAIdebianMirror){
710       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
711         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
712       }
713     }
715     if(isset($_POST['WorkstationStarttabPosted'])){
716       if(isset($_POST['gotoLdap_inherit'])){
717         $this->gotoLdap_inherit = TRUE;
718       }else{
719         $this->gotoLdap_inherit = FALSE;
720       }
722       /* Save group radio buttons */
723       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
724         $this->bootmode= $_POST["bootmode"];
725       }
727       /* Save kernel parameters */
728       if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
729         $this->customParameters= $_POST["customParameters"];
730       }
731     }
732   }
735   /* Save to LDAP */
736   function save()
737   {
739     /* Depending on the baseobject (Ogroup / WS) we
740      *  use another set of objectClasses
741      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
742      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
743      */
744     if(isset($this->parent->by_object['ogroup'])){
745       $this->objectclasses = array("gotoWorkstationTemplate");
746     }elseif(isset($this->parent->by_object['workgeneric'])){
747       $this->objectclasses = array("GOhard");
748     }elseif(isset($this->parent->by_object['servgeneric'])){
749       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
750     }else{
751       print "Object Type Configuration : unknown";
752       exit();
753     }
755     /* Append FAI class */
756     if($this->fai_activated){
757       $this->objectclasses[]  = "FAIobject";
758     }
760     /* Find proper terminal path for tftp configuration
761        FIXME: This is suboptimal when the default has changed to
762        another location! */
763     if (($this->gotoTerminalPath == "default")){
764       $ldap= $this->config->get_ldap_link();
766       /* Strip relevant part from dn, keep trailing ',' */
767       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalou')."/i", "", $this->dn);
768       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
770       /* Walk from top to base and try to load default values for
771          'gotoTerminalPath'. Abort when an entry is found. */
772       while (TRUE){
773         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
775         $ldap->cat("cn=default,".get_ou('terminalou').$tmp.
776             $this->config->current['BASE'], array('gotoTerminalPath'));
777         $attrs= $ldap->fetch();
778         if (isset($attrs['gotoTerminalPath'])){
779           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
780           break;
781         }
783         /* Nothing left? */
784         if ($tmp == ""){
785           break;
786         }
787       }
788     }
790     /* Add semi automatic values */
791     // FIXME: LDAP Server may not be set here...
792     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
794     switch ($this->bootmode){
795       case "D":
796         $this->gotoKernelParameters.= " debug";
797       break;
798       case "G":
799         $this->gotoKernelParameters.= " splash=silent";
800       break;
801     }
802     if ($this->customParameters != ""){
803       $this->gotoKernelParameters.= " o ".$this->customParameters;
804     }
806     plugin::save();
808     unset( $this->attrs['FAIrelease'] );
809     
810     $str = "";
812     /* Skip FAI attribute handling if not necessary */
813     if($this->fai_activated){
814       if($this->FAIdebianMirror == "inherited"){
815         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array(); 
816       }else{
817         foreach($this->FAIclass as $class){
818           $str .= $class." ";
819         }
820         $str .= ":" . $this->FAIrelease;
821         $this->attrs['FAIclass']= "";
822         $this->attrs['FAIclass']= trim($str);
824         if(empty($this->attrs['FAIclass'])){
825           $this->attrs['FAIclass'] = array();
826         }
827       }
828     }
829   
830     /* Add missing arrays */
831     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
832       if (isset ($this->$val) && count ($this->$val) != 0){
833     
834         $this->attrs["$val"]= array_unique($this->$val);
835       }
836       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
837     }
839     /* Prepare list of ldap servers */
840     $this->attrs['gotoLdapServer'] = array();
841     if(!$this->gotoLdap_inherit){
842       $i = 0;
843       foreach($this->gotoLdapServers as $server){
844         $i ++;
845         $this->attrs['gotoLdapServer'][] = $i.":".$server;
846       }
847     }
849     /* Check if LDAP server has changed */
850     $ldap_changed= (isset($this->attrs['gotoLdapServer'])) && 
851                    (isset($this->saved_attributes['gotoLdapServer'])) &&
852                    ($this->attrs['gotoLdapServer'] != $this->saved_attributes['gotoLdapServer']);
854     if (($this->attrs['gotoBootKernel'] == "default-inherited") || ($this->attrs['gotoBootKernel'] == "%default%")){
855       $this->attrs['gotoBootKernel']= array();
856     }
858     /* if mirror == none stop saving this attribute */
859     if($this->FAIdebianMirror == "none"){
860       $this->FAIdebianMirror = "";
861     }
862    
863     /* Get FAIstate from object, the generic tab could have changed it during execute */
864     $ldap= $this->config->get_ldap_link();
865     $ldap->cd($this->dn);
868     /* Skip FAI attribute handling if not necessary */
869     if($this->fai_activated){
870       $ldap->cat($this->dn,array("FAIstate"));
871       $checkFAIstate = $ldap->fetch();
873       /* Remove FAI objects if no FAI class is selected */ 
874       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
875         $this->attrs['FAIclass']        = array();
876         $this->attrs['FAIdebianMirror'] = array();
877       }
878     }
881     /* prepare share settings */
882     $tmp = array();
883     foreach($this->gotoShares as $name => $settings){
884       $tmp2= split("\|",$name);
885       $name = $tmp2[0];
886       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
887     }
888     $this->attrs['gotoShare']=$tmp;
890     $this->cleanup();
891     $ldap->modify ($this->attrs); 
892     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
894     if (!$ldap->success()){
895       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
896     }
897     $this->handle_post_events("modify");
899     /* Check if LDAP server has changed */
900     if ($ldap_changed && class_available("DaemonEvent")){
901       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
902       $o_queue = new gosaSupportDaemon();
903       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
904         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
905         $macs = array();
906     
907         /* Get list of macAddresses 
908          */
909         if(isset($this->parent->by_object['ogroup'])){
910         
911           /* If we are an object group, add all member macs 
912            */
913           $p = $this->parent->by_object['ogroup'];
914           foreach($p->memberList as $dn => $obj){
915             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
916               $macs[] = $p->objcache[$dn]['macAddress'];
917             }
918           }
919         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
921           /* We are a workstation. Add current mac.
922            */
923           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
924           if(!empty($mac)){
925             $macs[] = $mac;
926           }          
927         }
929         /* Trigger event for all member objects 
930          */
931         foreach($macs as $mac){
932           $tmp = new $evt['CLASS_NAME']($this->config);
933           $tmp->set_type(TRIGGERED_EVENT);
934           $tmp->add_targets(array($mac));
935           if(!$o_queue->append($tmp)){
936             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
937           }
938         }
939       }
940     }
941   }
944   /* Add value to array, check if unique */
945   function add_list (&$array, $value)
946   {
947     if ($value != ""){
948       $array[]= $value;
949       sort($array);
950       array_unique ($array);
951     }
952   }
955   /* Delete value to array, check if unique */
956   function del_list (&$array, $list)
957   {
958     $tmp= array();
959     foreach ($array as $mod){
960       if (!in_array($mod, $list)){
961         $tmp[]= $mod;
962       }
963     }
964     $array= $tmp;
965   }
967   /* Generate ListBox frindly output for the defined shares
968    * Possibly Add or remove an attribute here,
969    */
970   function printOutAssignedShares()
971   {
972     $a_return = array();
973     if(is_array($this->gotoShares)){
974       foreach($this->gotoShares as $share){
975         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
976       }
977     }
978     return($a_return);
979   }
983   function PrepareForCopyPaste($source)
984   {
985     plugin::PrepareForCopyPaste($source);    
986     $source_o = new workstartup ($this->config, $source['dn']);
987     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
988           "gotoKernelParameters","gotoShares","customParameters") as $attr){
989       $this->$attr = $source_o->$attr;
990     }
991   }
993   
994   function array_switch_item($ar,$from,$to)
995   {
996     if(!is_array($ar)){
997       return(false);
998     }
999     if(!isset($ar[$from])){
1000       return(false);
1001     }
1002     if(!isset($ar[$to])){
1003       return(false);
1004     }
1006     $tmp = $ar[$from];
1007     $ar[$from] = $ar[$to];    
1008     $ar[$to] = $tmp;    
1009     return($ar);
1010   }
1013   /* Return plugin informations for acl handling */ 
1014   static function plInfo()
1015   {
1016     return (array( 
1017           "plShortName"   => _("Startup"),
1018           "plDescription" => _("System startup"),
1019           "plSelfModify"  => FALSE,
1020           "plDepends"     => array(),
1021           "plPriority"    => 9,
1022           "plSection"     => array("administration"),           
1023           "plCategory"    => array("workstation","server","ogroups"),
1025           "plProvidedAcls"=> array(
1026             "gotoLdapServer"        => _("Ldap server"),
1027             "gotoBootKernel"        => _("Boot kernel"),
1028             "gotoKernelParameters"  => _("Kernel parameter"),
1030             "gotoModules"           => _("Kernel modules"),
1031             "gotoShare"             => _("Shares"),
1033             "FAIclass"              => _("FAI classes"),
1034             "FAIdebianMirror"       => _("Debian mirror"),
1035             "FAIrelease"            => _("Debian release"),
1037             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1038           ));
1039   }
1042   /* Updates release dns 
1043    *  and reads all classes for the current release, 
1044    *  if not already done ($this->cache).
1045    */
1046   function update_fai_cache($first_call = FALSE)
1047   {
1048     $force = FALSE;
1050     /* Get the list of available servers and their releases. 
1051      */
1052     if($force || !isset($this->cache['SERVERS'])){
1053       $ldap = $this->config->get_ldap_link();
1054       $ldap->cd($this->config->current['BASE']);
1056       $server_list = get_sub_list("(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",
1057                       "",get_ou("serverou"),$this->config->current['BASE'],array("FAIrepository"),GL_NO_ACL_CHECK);
1058      
1059       /* Only add inherit option, if we are part in an object group
1060        */
1061       if($this->member_of_ogroup){
1062         $this->cache['SERVERS']['inherited']=array();
1063       }
1065       /* Add auto value  
1066        */
1067       $this->cache['SERVERS']['auto'] = array();
1068       $sort_by = array("auto");
1069       $server_tmp = array("auto"=>array());
1070       foreach($server_list as $attr){
1071         if(isset($attr['FAIrepository'])){
1072           for($i = 0 ; $i < $attr['FAIrepository']['count'] ; $i ++ ){
1073             $rep = $attr['FAIrepository'][$i];
1074             $tmp = split("\|",$rep);
1075             if(count($tmp)==4){
1076               $sections = split(",",$tmp[3]);
1077               $release  = $tmp[2];
1078               $server   = $tmp[1];
1079               $url      = $tmp[0];
1080               $server_tmp[$url][$release]=$release;
1081               $server_tmp['auto'][$release]=$release;
1082               $sort_by[$url] = $url;
1083             }
1084           }
1085         }
1086       }
1087       natcasesort($sort_by);
1088       foreach($sort_by as $name){
1089         $releases = $server_tmp[$name];
1090         natcasesort($releases);
1091         $this->cache['SERVERS'][$name] = $releases; 
1092       }
1093     }
1095     /* Build up arrays, without checks */
1096     if(!$first_call){
1098       /* Check if the selected mirror is available */
1099       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1100         $this->FAIdebianMirror = "auto";
1101         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1102         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1103       }
1105       /* Check if the selected release is available */
1106       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1107         trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1108         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1109       }
1110     }
1112     /* Get classes for release from cache. 
1113      * Or build cache
1114      */
1115     if($this->FAIdebianMirror == "inherited"){
1116       $release = $this->InheritedFAIrelease;
1117     }else{
1118       $release = $this->FAIrelease;
1119     }
1120     if($force || !isset($this->cache['CLASSES'][$release])){
1122       /*  Create a list of available releases.
1123        *  $this->cache['RELEASE_DNS'][ou=siga...,c=de]         = "siga";
1124        *  $this->cache['RELEASE_DNS'][ou=siga,ou=rc1,...,c=de] = "siga/rc1";
1125        */
1126       if($force || !isset($this->cache['RELEASE_DNS'])){
1127         $this->cache['RELEASE_DNS'] = array();
1128         $fai_ou_parts = preg_replace("/\/.*$/","",$this->FAIrelease);
1130         $tmp = get_sub_list("(objectClass=FAIbranch)","",get_ou("faiou"),
1131                 $this->config->current['BASE'],array("ou"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
1133         foreach($tmp as $attrs){
1134           if(preg_match("/".normalizePreg(get_ou("faiou"))."/",$attrs['dn'])){
1135             $this->cache['RELEASE_DNS'][$attrs['dn']] = $this->dn_to_release_name($attrs['dn']);
1136           }
1137         }
1138       }
1140       /* Create list of available classes for the currenlty selected release.
1141        */
1142       $base = array_search($release,$this->cache['RELEASE_DNS']);
1143       $this->cache['CLASSES'][$release] = array();
1145       if(class_exists("FAI")){
1146         if(!empty($base)){
1147           $filter = "(|(objectClass=FAIpackageList)(objectClass=FAItemplate)(objectClass=FAIvariable)".
1148             "(objectClass=FAIscript)(objectClass=FAIhook)(objectClass=FAIprofile)".
1149             "(objectClass=FAIpartitionTable))";
1150           $list = FAI::get_all_objects_for_given_base($base,$filter,TRUE);
1151           foreach($list as $attrs){
1152             $info = $this->analyse_fai_object($attrs);
1153             if(count($info)){
1154               $this->cache['CLASSES'][$release][$attrs['cn'][0]][] = $info;
1155             }
1156           }
1157         }
1158       }else{
1159         msg_dialog(_("Configuration error"), _("Missing FAI plugin extension!"), ERROR_DIALOG);
1160       }
1162       /* Add object caught from external hook
1163        */
1164       $lines= $this->GetHookElements();
1165       foreach ($lines as $hline){
1166         $entries= split(";", $hline);
1167         $server = $entries['0'];
1168         $url    = $entries['1'];
1169         if (!empty($url)){
1170           
1171           /* Split releases */
1172           if (isset($entries[2])){
1173             $releases= split(",", $entries[2]);
1175             foreach ($releases as $release_data){
1176               $release= preg_replace('/:.*$/', '', $release_data);
1177               $sections = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1178               $classes  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1179               $this->cache['SERVERS'][$url][$release]=$release;
1180               $this->cache['SERVERS']['auto'][$release]=$release; 
1181               foreach ($classes as $class){
1182                 if ($class != ""){
1183                   $this->cache['CLASSES'][$release][$class]= array();
1184                 }
1185               }
1186             }
1187           }
1188         }
1189       }
1190     }
1191   }
1194   /* This function return an array containing all 
1195    *  invalid classes for the selected server/release
1196    */
1197   function get_invalid_classes($classes)
1198   {
1199     $this->update_fai_cache();
1200     if($this->FAIdebianMirror == "inherited"){
1201       $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1202     }else{
1203       $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1204     }
1207     /* Detect all classes that are not valid 
1208      *  for the selected release 
1209      */
1210     $NA = array();
1211     foreach($classes as $class){
1212       if(!isset($release_classes[$class])){
1213         $NA[] = $class;
1214       }
1215     }
1216     return($NA);
1217   }  
1219   
1220   /* Get all selectable classes for the ui select box
1221    */
1222   function selectable_classes()
1223   {
1224     $this->update_fai_cache();
1226     if($this->FAIdebianMirror == "inherited"){
1227       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1228     }else{
1229       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1230     }
1232     $Abbr ="";
1233     $ret= array();
1234     foreach($classes as $class_name => $class_types){
1235       if(!in_array($class_name,$this->FAIclass)){
1236         foreach($class_types as $type){
1237           if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1238             $Abbr .= $type['Abbr']." ";
1239           }
1240         }
1241         $ret[$class_name] = trim($Abbr);
1242       }
1243     }
1244     uksort($ret, 'strnatcasecmp');
1245     return($ret);
1246   }
1249   /* Analyse FAI object and return an array with usefull informations like 
1250    *  FAIobject type.
1251    */
1252   function analyse_fai_object($attr)
1253   {
1254     $tmp2 = array();
1255     if(!isset($attr['description'])){
1256       $attr['description'][0] ="";
1257     }
1258     if(in_array('FAIpackageList',$attr['objectClass'])){
1259       $tmp2["Type"]   = 'FAIpackageList'; 
1260       $tmp2["Abbr"]   = 'Pl';
1261       $tmp2["Desc"]  = $attr['description'][0];
1262     }
1263     if(in_array('FAItemplate',$attr['objectClass'])){
1264       $tmp2["Type"]      = 'FAItemplate'; 
1265       $tmp2["Abbr"]      = 'T'; 
1266       $tmp2["Desc"]  = $attr['description'][0];
1267     }
1268     if(in_array('FAIvariable',$attr['objectClass'])){
1269       $tmp2["Type"]      = 'FAIvariable'; 
1270       $tmp2["Abbr"]      = 'V'; 
1271       $tmp2["Desc"]  = $attr['description'][0];
1272     }
1273     if(in_array('FAIscript',$attr['objectClass'])){
1274       $tmp2["Type"]        = 'FAIscript'; 
1275       $tmp2["Abbr"]        = 'S'; 
1276       $tmp2["Desc"]  = $attr['description'][0];
1277     }
1278     if(in_array('FAIhook',$attr['objectClass'])){
1279       $tmp2["Type"]          = 'FAIhook'; 
1280       $tmp2["Abbr"]          = 'H'; 
1281       $tmp2["Desc"]  = $attr['description'][0];
1282     }
1283     if(in_array('FAIpartitionTable',$attr['objectClass'])){
1284       $tmp2["Type"]= 'FAIpartitionTable'; 
1285       $tmp2["Abbr"]= 'Pt'; 
1286       $tmp2["Desc"]  = $attr['description'][0];
1287     }
1288     if(in_array('FAIprofile',$attr['objectClass'])){
1289       $tmp2["Type"]= 'FAIprofile'; 
1290       $tmp2["Abbr"]= 'P'; 
1291       $tmp2["Desc"]  = $attr['description'][0];
1292     }
1293     return($tmp2);
1294   }
1297   /* Return repository hook output, if possible.
1298    */
1299   function GetHookElements()
1300   {
1301     $ret = array();
1302     $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1303     if(!empty($cmd)){
1304       $res = shell_exec($cmd);
1305       $res2 = trim($res);
1306       if((!$res)){
1307         msg_dialog(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1308       }elseif(empty($res2)){
1309         msg_dialog(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1310       }else{
1311         $tmp = split("\n",$res);
1312         foreach($tmp as $line){
1313           if(empty($line)) continue;
1314           $ret[]= $line;
1315         }
1316       }
1317     }
1318     return($ret);
1319   }
1322   /* This function creates the release name out of a dn 
1323    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1324    */
1325   function dn_to_release_name($dn)
1326   {
1327     $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1328     $parts    = array_reverse(split("\,",$relevant));
1329     $str ="";
1330     foreach($parts as $part){
1331       $str .= preg_replace("/^ou=/","",$part)."/";
1332     }
1333     return(preg_replace("/\/$/","",$str)); 
1334   }
1337 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1338 ?>