Code

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