Code

21e664edef799d2c507bc12c8bb3782b8ed5cee3
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationStartup.inc
1 <?php
2 class workstartup extends plugin
3 {
4   /* Ldap server list */
5   var $gotoLdapServers    = array();
6   var $gotoLdapServerList = array();
7   var $gotoLdap_inherit   = FALSE;
9   /* Generic terminal attributes */
10   var $bootmode             = "G";
11   var $gotoBootKernel       = "default-inherited";
12   var $gotoKernelParameters = "";
13   var $gotoLdapServer       = "default-inherited";
14   var $gotoModules          = array();
15   var $gotoAutoFs           = array();
16   var $gotoFilesystem       = array();
17   var $gotoTerminalPath     = "";
18   var $gotoBootKernels      = array();
20   /* attribute list for save action */
21   var $attributes           = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", 
22                                     "FAIclass", "FAIstatus", "gotoShare","FAIdebianMirror", "FAIrelease");
23   var $objectclasses        = array("GOhard", "FAIobject");
25   /* Share */
26   var $gotoShares         = array();// Currently Share Option
27   var $gotoShare          = "";     // currently selected Share Option
28   var $gotoShareSelections= array();// Available Shares for this account in Listbox format
29   var $gotoAvailableShares= array();// Available Shares for this account
31   /* Helper */
32   var $customParameters   = "";
33   var $orig_dn            = "";
34   var $ignore_account     = TRUE;
35  
36   /* FAI class selection */ 
37   var $FAIclass           = array();  // The currently selected classes 
38   var $FAIrelease           = "";
39   var $FAIdebianMirror      = "auto";
40   var $si_active            = FALSE;
41   var $si_fai_action_failed = FALSE;
43   var $cache              = array(); // Used as cache in fai mehtods
45   var $FAIstatus          = "";
46   var $FAIclasses         = array();
48   var $view_logged        = FALSE;
49   
50   /* FAI class selection */
51   var $InheritedFAIclass       = array();
52   var $InheritedFAIrelease     = "";
53   var $InheritedFAIdebianMirror= "auto";
55   var $CopyPasteVars    = array("gotoModules","gotoShares");
56   var $fai_activated    = FALSE;
57   var $o_group_dn       = "";
58   var $member_of_ogroup = FALSE;
60   function workstartup (&$config, $dn= NULL, $parent= NULL)
61   {
62     /* Check if FAI is active */
63     $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
64     if(!empty($tmp) && class_available("faiManagement")){
65       $this->fai_activated = TRUE;
66     }else{
67       $this->attributes = array("gotoLdapServer", "gotoBootKernel", "gotoKernelParameters", "gotoShare");
68       $this->objectclasses  = array("GOhard");
69     }
71     plugin::plugin ($config, $dn, $parent);
73     /* Check for si daemon */
74     $this->si_active = $this->config->get_cfg_value("gosaSupportURI") != "";
76     /* Check object group membership */
77     if(!isset($this->parent->by_object['ogroup'])){
78       $ldap = $this->config->get_ldap_link();
79       $ldap->cd ($this->config->current['BASE']);
80       $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn","dn"));
81       if($ldap->count()){
82         $this->member_of_ogroup = TRUE;
83         $attrs = $ldap->fetch();
84         $this->o_group_dn = $attrs['dn'];
85       }
86     }
88     /* Creating a list of valid Mirrors 
89      * none will not be saved to ldap.
90      */
91     $ldap   = $this->config->get_ldap_link();
92     $ldap->cd($this->config->current['BASE']);
93     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 represent a valid terminal? */
323     if (!$this->is_account && $this->parent === NULL){
324       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
325         msgPool::noValidExtension(_("workstation"))."</b>";
326       return ($display);
327     }
329     /* Add module */
330     if (isset ($_POST['add_module'])){
331       if ($_POST['module'] != "" && $this->acl_is_writeable("gotoModule")){
332         $this->add_list ($this->gotoModules, $_POST['module']);
333       }
334     }
336     /* Delete module */
337     if (isset ($_POST['delete_module'])){
338       if (count($_POST['modules_list']) && $this->acl_is_writeable("gotoModule")){
339         $this->del_list ($this->gotoModules, $_POST['modules_list']);
340       }
341     }
343     /* FAI class management */
344     if($this->fai_activated){
345       if(((isset($_POST['AddClass']))&&(isset($_POST['FAIclassesSel']))) && ($this->acl_is_writeable("FAIclass"))){
346         $found = 0 ; 
348         /* If this new class/profile will attach a second partition table
349          * to our list of classes, abort and show a message.
350          */
351         foreach($this->FAIclass as $name){
352           if(isset($this->FAIclassInfo[$name])){
353             foreach($this->FAIclassInfo[$name] as $atr){
354               if(isset($atr['obj'])){
355                 if($atr['obj'] == "FAIpartitionTable"){
356                   $found ++ ; 
357                 }
358               }
359             }
360           }
361         }
363         if((isset($this->FAIclassInfo[$_POST['FAIclassesSel']]['FAIpartitionTable']))&&($found>0)){
364           msg_dialog::display(_("Error"), _("There is already a profile containing a partition table in your configuration!") , ERROR_DIALOG);
365         }else{
366           $this->FAIclass[$_POST['FAIclassesSel']]=$_POST['FAIclassesSel'];
367         }
368       }
370       $sort = false;
372       /* Move one used class class one position up or down */
373       if($this->acl_is_writeable("FAIclass")){
374         foreach($_POST as $name => $val){
376           $sort_type = false;
377           if((preg_match("/sort_up/",$name))&&(!$sort)){
378             $sort_type = "sort_up_";
379           }
380           if((preg_match("/sort_down/",$name))&&(!$sort)){
381             $sort_type = "sort_down_";
382           }
384           if(($sort_type)&&(!$sort)){
385             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/".$sort_type."/i","",$name)));
386             $sort = true;
388             $last = -1;
389             $change_down  = -1;
391             /* Create array with numeric index */ 
392             $tmp = array();
393             foreach($this->FAIclass as $class){
394               $tmp [] = $class;
395             }
397             /* Walk trough array */
398             foreach($tmp as $key => $faiName){
399               if($faiName == $value){
400                 if($sort_type == "sort_up_"){
401                   if($last != -1){
402                     $change_down= $last;
403                   }
404                 }else{
405                   if(isset($tmp[$key+1])){
406                     $change_down = $key;
407                   }
408                 }
409               }
410               $last = $key;
411             }
413             $tmp2 = array();
414             $skip = false;    
416             foreach($tmp as $ky => $vl){
418               if($ky == $change_down){
419                 $skip = $vl;
420               }else{
421                 $tmp2[$vl] = $vl;
422               }
423               if(($skip != false)&&($ky != $change_down)){
424                 $tmp2[$skip]  = $skip;
425                 $skip =false;
426               }
427             }   
428             $this->FAIclass = $tmp2; 
429           }
431           if(preg_match("/fai_remove/i",$name)){
432             $value = base64_decode(preg_replace("/_.*$/i","",preg_replace("/fai_remove_/i","",$name)));
433             unset($this->FAIclass[$value]);
434           }
435         }
436       }
438       /* Delete selected class from our list */
439       if($this->acl_is_writeable("FAIclass")){
440         if((isset($_POST['DelClass']))&&(isset($_POST['FAIclassSel']))){
441           if(isset($this->FAIclass[$_POST['FAIclassSel']])){
442             unset($this->FAIclass[$_POST['FAIclassSel']]);
443           }
444         }
445       }
446     }// END fai handling
448     /* Show main page */
449     $smarty= get_smarty();
451     /* Assign ACLs to smarty */
452     $tmp = $this->plInfo();
453     foreach($tmp['plProvidedAcls'] as $name => $translation){
454       $smarty->assign($name."ACL",$this->getacl($name));
455     } 
457     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
459     /* In this section server shares will be defined
460      * A user can select one of the given shares and a mount point
461      *  and attach this combination to his setup.
462      */
463     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
464     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
466     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
467      * This entry will be, a combination of mountPoint and sharedefinitions
468      */
469     if((isset($_POST['gotoShareAdd'])) && isset($_POST['gotoShareSelection']) && ($this->acl_is_writeable("gotoShare"))) {
470       /* We assign a share to this user, if we don't know where to mount the share */
471       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
472         msg_dialog::display(_("Error"), msgPool::required(_("Mount point")), ERROR_DIALOG);
473       }else{
474     
475         if(isset($this->gotoAvailableShares[$_POST['gotoShareSelection']])){
476           $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
477           $s_mount = $_POST['gotoShareMountPoint'];
478           /* Preparing the new assignment */
479           $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
480           $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
481         }
482       }
483     }
485     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
486      * If there is no defined share selected, we will abort the deletion without any message
487      */
488     if(($this->acl_is_writeable("gotoShare"))&& (isset($_POST['gotoShareDel']))&&(isset($_POST['gotoShare']))){
489       unset($this->gotoShares[$_POST['gotoShare']]);
490     }
492     $smarty->assign("gotoShares",$this->printOutAssignedShares());
493     $smarty->assign("gotoSharesCount",count($this->printOutAssignedShares()));
494     $smarty->assign("gotoShareKeys",array_flip($this->printOutAssignedShares()));
495     $smarty->assign("gotoBootKernels",$this->gotoBootKernels);
497     /* Create divSelectBox for ldap server selection
498      */
499     $SelectBoxLdapServer = new divSelectBox("LdapServer");
500     $SelectBoxLdapServer->SetHeight(130);
502     /* Add new ldap server to the list */
503     if($this->acl_is_writeable("gotoLdapServer") && 
504         !$this->gotoLdap_inherit && 
505         isset($_POST['add_ldap_server']) && 
506         isset($_POST['ldap_server_to_add'])){
507       if(isset($this->gotoLdapServerList[$_POST['ldap_server_to_add']])){
508         $to_add = $this->gotoLdapServerList[$_POST['ldap_server_to_add']];
509         if(!in_array($to_add,$this->gotoLdapServers)){
510           $this->gotoLdapServers[] = $to_add;
511         }
512       }
513     }
514     
515     /* Move ldap servers up and down */
516     if(!$this->gotoLdap_inherit && $this->acl_is_writeable("gotoLdapServer")){
517       foreach($_POST as $name => $value){
518         if(preg_match("/sort_ldap_up_/",$name)){
519           $id = preg_replace("/^sort_ldap_up_([0-9]*)_(x|y)$/","\\1",$name);
520           $from =  $id;  
521           $to   =  $id -1;
522           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
523           if($tmp){
524             $this->gotoLdapServers = $tmp;
525           }
526           break;
527         }
528         if(preg_match("/sort_ldap_down_/",$name)){
529           $id = preg_replace("/^sort_ldap_down_([0-9]*)_(x|y)$/","\\1",$name);
530           $from =  $id;  
531           $to   =  $id +1;
532           $tmp = $this->array_switch_item($this->gotoLdapServers,$from,$to);
533           if($tmp){
534             $this->gotoLdapServers = $tmp;
535           }
536           break;
537         }
538         if(preg_match("/gotoLdapRemove_/",$name)){
539           $id = preg_replace("/^gotoLdapRemove_([0-9]*)_(x|y)$/","\\1",$name);
540           $value = $this->gotoLdapServers[$id];
541           $this->gotoLdapServers = array_remove_entries(array($value),$this->gotoLdapServers);
542           break;
543         }
544       } 
545     }
546   
547     /* Add Entries */
548     if($this->acl_is_readable("gotoLdapServer")){
550       foreach($this->gotoLdapServers as $key => $server){
552         /* Announce missing entries */
553         if(!in_array($server,$this->gotoLdapServerList)){
554           $server = $server."&nbsp;<font style='color:red'>(missing)</font>";
555         }
557         /* Convert old style entry */
558         if (!preg_match('%:ldaps?://%', $server)){
559           $server= "ldap://".preg_replace('/^([^:]+):/', '\1/', $server);
561         /* Beautify new style entries */
562       } else {
563         $server= preg_replace("/^[^:]+:/", "", $server);
564       }
566       $SelectBoxLdapServer->AddEntry(
567           array(array("string" => $server),
568             array("string" => 
569               "<input class='center' type='image' src='images/lists/sort-up.png' name='sort_ldap_up_".$key."'>&nbsp;".
570               "<input class='center' type='image' src='images/lists/sort-down.png' name='sort_ldap_down_".$key."'>&nbsp;".
571               "<input class='center' type='image' src='images/lists/trash.png' name='gotoLdapRemove_".$key."'>",
572               "attach" => "style='text-align:right;width:40px;border-right:0px;'")));
573       }    
574     }    
576     if($this->gotoLdap_inherit){
577       $smarty->assign("gotoLdapServerACL_inherit", preg_replace("/w/","",$this->getacl("gotoLdapServer")));;
578     }else{
579       $smarty->assign("gotoLdapServerACL_inherit", $this->getacl("gotoLdapServer"));
580     }
581     
582     $list = array();
583     foreach($this->gotoLdapServerList as $key => $entry){
584       if(!in_array($entry,$this->gotoLdapServers)){
586         /* Convert old style entry */
587         if (!preg_match('%:ldap[s]*://%', $entry)){
588           $entry= "ldap://".preg_replace('/^([^:]+):/', '\1/', $entry);
590         /* Beautify new style entries */
591         } else {
592           $entry= preg_replace("/^[^:]+:/", "", $entry);
593         }
595         $list[$key] = $entry;
596       }
597     }
598     $smarty->assign("gotoLdapServers",    $SelectBoxLdapServer->DrawList());
599     $smarty->assign("gotoLdapServerList", $list);
600     $smarty->assign("gotoLdap_inherit",   $this->gotoLdap_inherit);
601     $smarty->assign("JS",  session::get('js'));
603     foreach (array("gotoModules", "gotoAutoFs", "gotoFilesystem") as $val){
604       $smarty->assign("$val", $this->$val);
605     }
607     /* Values */
608     foreach(array("gotoBootKernel", "customParameters", "gotoShare","FAIclasses","FAIclass","FAIdebianMirror","FAIrelease") as $val){
609       $smarty->assign($val, $this->$val);
610     }
612     $smarty->assign("fai_activated",$this->fai_activated);
614     /* Create FAI output */
615     $this->update_fai_cache();
616     $smarty->assign("si_fai_action_failed",$this->si_fai_action_failed);
617     $smarty->assign("si_active",$this->si_active);
618   
619     if(!$this->si_fai_action_failed && $this->si_active && $this->fai_activated){
621       $smarty->assign("FAIservers"  , $this->cache['SERVERS']);
622       $smarty->assign("FAIdebianMirror",$this->FAIdebianMirror);
623       $smarty->assign("FAIrelease"  , $this->FAIrelease);
624       $smarty->assign("FAIclasses"  , $this->selectable_classes());
626       /* Get classes for release from cache.
627        * Or build cache
628        */
629       if($this->FAIdebianMirror == "inherited"){
630         $release = $this->InheritedFAIrelease;
631       }else{
632         $release = $this->FAIrelease;
633       }
635       $smarty->assign("gotoBootKernels",$this->cache['KERNELS'][$release]);
636       $smarty->assign("InheritedFAIrelease",$this->InheritedFAIrelease);
638       $div = new divSelectBox("WSFAIscriptClasses");
639       $div -> SetHeight("110");
640       $str_up     = " &nbsp;<input type='image' src='images/lists/sort-up.png'    name='sort_up_%s'    value='%s'>";
641       $str_down   = " &nbsp;<input type='image' src='images/lists/sort-down.png'  name='sort_down_%s'  value='%s'>";
642       $str_remove = " &nbsp;<input type='image' src='images/lists/trash.png'  name='fai_remove_%s' value='%s'>";
643       $str_empty  = " &nbsp;<img src='images/empty.png' alt=\"\" width='7'>"; 
645       /* Get classes */
646       if($this->FAIdebianMirror == "inherited"){
647         $tmp = $this->InheritedFAIclass;
648       }else{
649         $tmp = $this->FAIclass;
650       }
652       /* Get invalid classes */
653       $invalid = $this->get_invalid_classes($tmp);
655       /* Draw every single entry */
656       $i = 1;
657       foreach($tmp as $class){
659         /* Mark invalid classes. (Not in selected release)
660          */
661         $marker = "";
662         if(in_array_ics($class,$invalid)){
663           $marker = "&nbsp;<font color='red'>("._("Not available in current setup").")</font>";
664         }
666         /* Create up/down priority icons  
667          * Skip this, if we have inherited the FAI classes.
668          */
669         if($this->FAIdebianMirror == "inherited"){
670           $str = "";
671         }else{
672           if($i==1){
673             $str = $str_empty.$str_down.$str_remove;
674           }elseif($i == count($this->FAIclass)){
675             $str = $str_up.$str_empty.$str_remove;
676           }else{
677             $str = $str_up.$str_down.$str_remove;
678           }
679         }
680         $i ++ ; 
682         /* Get Description tag 
683          *  There may be several FAI objects with the same class name, 
684          *   use the description from FAIprofile, if possible.
685          */  
686         $desc = ""; 
687         if(isset($this->cache['CLASSES'][$this->FAIrelease][$class])){
688           foreach($this->cache['CLASSES'][$this->FAIrelease][$class] as $types ){
689             if(isset($types['Desc'])){
690               $desc= $types['Desc'];
691               if($types['Type'] == "FAIprofile"){
692                 break;
693               }
694             }
695           }
696         }
697         if(!empty($desc)){
698           $desc = "&nbsp;[".trim($desc)."]";
699         }        
701         $div->AddEntry(array(
702               array("string"=>$class.$desc.$marker),
703               array("string"=>preg_replace("/\%s/",base64_encode($class),$str),"attach"=>"style='width:50px;border-right:none;'")
704               ));
705       }  
706       $smarty->assign("FAIScriptlist",$div->DrawList()); 
707     }// END FAI output generation 
709     /* Radio button group */
710     if (preg_match("/G/", $this->bootmode)) {
711       $smarty->assign("graphicalbootup", "checked");
712     } else {
713       $smarty->assign("graphicalbootup", "");
714     }
715     if (preg_match("/T/", $this->bootmode)) {
716       $smarty->assign("textbootup", "checked");
717     } else {
718       $smarty->assign("textbootup", "");
719     }
720     if (preg_match("/D/", $this->bootmode)) {
721       $smarty->assign("debugbootup", "checked");
722     } else {
723       $smarty->assign("debugbootup", "");
724     }
726     /* Show main page */
727     return($smarty->fetch (get_template_path('workstationStartup.tpl', TRUE,dirname(__FILE__))));
728   }
731   function remove_from_parent()
732   {
733     $this->handle_post_events("remove");
734     new log("remove","workstation/".get_class($this),$this->dn);
735   }
738   /* Save data to object */
739   function save_object()
740   {
741     $old_mirror  = $this->FAIdebianMirror;
742     plugin::save_object();
744     /* Update release */
745     if($old_mirror != $this->FAIdebianMirror){
746       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
747         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
748       }
749     }
751     if(isset($_POST['WorkstationStarttabPosted'])){
752       if(isset($_POST['gotoLdap_inherit'])){
753         $this->gotoLdap_inherit = TRUE;
754       }else{
755         $this->gotoLdap_inherit = FALSE;
756       }
758       /* Save group radio buttons */
759       if ($this->acl_is_writeable("bootmode") && isset($_POST["bootmode"])){
760         $this->bootmode= $_POST["bootmode"];
761       }
763       /* Save kernel parameters */
764       if ($this->acl_is_writeable("gotoKernelParameters") && isset($_POST["customParameters"])){
765         $this->customParameters= $_POST["customParameters"];
766       }
767     }
768   }
771   /* Save to LDAP */
772   function save()
773   {
775     /* Depending on the baseobject (Ogroup / WS) we
776      *  use another set of objectClasses
777      * In case of WS itself, we use  "array("GOhard", "FAIobject");"
778      * if we are currently editing from ogroup menu we use (array("gotWorkstationTemplate","GOhard", "FAIobject"))
779      */
780     if(isset($this->parent->by_object['ogroup'])){
781       $this->objectclasses = array("gotoWorkstationTemplate");
782     }elseif(isset($this->parent->by_object['workgeneric'])){
783       $this->objectclasses = array("GOhard");
784     }elseif(isset($this->parent->by_object['servgeneric'])){
785       $this->objectclasses = array("GOhard","gotoWorkstationTemplate");
786     }else{
787       msg_dialog::display(_("Fatal error"),
788           "Object Type Configuration is unknown. Please contact the GOsa developers.",
789           FATAL_ERROR_DIALOG);
790       exit();
791     }
793     /* Append FAI class */
794     if($this->fai_activated){
795       $this->objectclasses[]  = "FAIobject";
796     }
798     /* Find proper terminal path for tftp configuration
799        FIXME: This is suboptimal when the default has changed to
800        another location! */
801     if (($this->gotoTerminalPath == "default")){
802       $ldap= $this->config->get_ldap_link();
804       /* Strip relevant part from dn, keep trailing ',' */
805       $tmp= preg_replace("/^cn=[^,]+,".get_ou('terminalRDN')."/i", "", $this->dn);
806       $tmp= preg_replace("/".$this->config->current['BASE']."$/i", "", $tmp);
808       /* Walk from top to base and try to load default values for
809          'gotoTerminalPath'. Abort when an entry is found. */
810       while (TRUE){
811         $tmp= preg_replace ("/^[^,]+,/", "", $tmp);
813         $ldap->cat("cn=default,".get_ou('terminalRDN').$tmp.
814             $this->config->current['BASE'], array('gotoTerminalPath'));
815         $attrs= $ldap->fetch();
816         if (isset($attrs['gotoTerminalPath'])){
817           $this->gotoTerminalPath= $attrs['gotoTerminalPath'][0];
818           break;
819         }
821         /* Nothing left? */
822         if ($tmp == ""){
823           break;
824         }
825       }
826     }
828     /* Add semi automatic values */
829     // FIXME: LDAP Server may not be set here...
830     $this->gotoKernelParameters= "ldap=".base64_encode($this->gotoLdapServer);
832     switch ($this->bootmode){
833       case "D":
834         $this->gotoKernelParameters.= " debug";
835       break;
836       case "G":
837         $this->gotoKernelParameters.= " splash=silent";
838       break;
839     }
840     if ($this->customParameters != ""){
841       $this->gotoKernelParameters.= " o ".$this->customParameters;
842     }
844     plugin::save();
846     unset( $this->attrs['FAIrelease'] );
847     $str = "";
849     /* Skip FAI attribute handling if not necessary */
850     if($this->fai_activated && !$this->si_fai_action_failed){
851       if($this->FAIdebianMirror == "inherited"){
852         $this->attrs['FAIclass'] = $this->attrs['FAIrelease'] =  $this->attrs['FAIdebianMirror'] = array();
853       }else{
854         foreach($this->FAIclass as $class){
855           $str .= $class." ";
856         }
857         $str = trim($str);
858         if(empty($this->attrs['FAIclass'])){
859           $this->attrs['FAIclass'] = array();
860         }else{
861           $this->attrs['FAIclass']= $str." :".$this->FAIrelease;
862         }
863       }
864     }
866     /* Add missing arrays */
867     foreach (array("gotoFilesystem", "gotoAutoFs", "gotoModules") as $val){
868       if (isset ($this->$val) && count ($this->$val) != 0){
869     
870         $this->attrs["$val"]= array_unique($this->$val);
871       }
872       if(!isset($this->attrs["$val"])) $this->attrs["$val"]=array();
873     }
875     /* Prepare list of ldap servers */
876     $this->attrs['gotoLdapServer'] = array();
877     if(!$this->gotoLdap_inherit){
878       $i = 0;
879       foreach($this->gotoLdapServers as $server){
880         $i ++;
881         $this->attrs['gotoLdapServer'][] = $i.":".$server;
882       }
883     }
885     if ($this->attrs['gotoBootKernel'] == "default-inherited"){
886       $this->attrs['gotoBootKernel']= array();
887     }
889     /* if mirror == none stop saving this attribute */
890     if($this->FAIdebianMirror == "none"){
891       $this->FAIdebianMirror = "";
892     }
893    
894     /* Get FAIstate from object, the generic tab could have changed it during execute */
895     $ldap= $this->config->get_ldap_link();
896     $ldap->cd($this->dn);
899     /* Skip FAI attribute handling if not necessary */
900     if($this->fai_activated && !$this->si_fai_action_failed && $this->si_active){
901       $ldap->cat($this->dn,array("FAIstate"));
902       $checkFAIstate = $ldap->fetch();
904       /* Remove FAI objects if no FAI class is selected */ 
905       if((count($this->FAIclass)==0) && (!isset($checkFAIstate['FAIstate']))){
906         $this->attrs['FAIclass']        = array();
907         $this->attrs['FAIdebianMirror'] = array();
908       }
909     }else{
911       /* Don't touch FAI objects if something went wrong with the si daemon.
912        */
913       if(isset($this->attrs['FAIclass'])) unset($this->attrs['FAIclass']);
914       if(isset($this->attrs['FAIdebianMirror'])) unset($this->attrs['FAIdebianMirror']);
915     }
917     /* prepare share settings */
918     $tmp = array();
919     foreach($this->gotoShares as $name => $settings){
920       $tmp2= split("\|",$name);
921       $name = $tmp2[0];
922       $tmp[] = $settings['server']."|".$name."|".$settings['mountPoint'];
923     }
924     $this->attrs['gotoShare']=$tmp;
925     $this->cleanup();
926     $ldap->modify ($this->attrs); 
927     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
929     if (!$ldap->success()){
930       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
931     }
932     $this->handle_post_events("modify");
934     /* Check if LDAP server has changed */
935     if ((isset($this->attrs['gotoLdapServer']) && class_available("DaemonEvent")) || $this->gotoLdap_inherit){
936       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
937       $o_queue = new gosaSupportDaemon();
938       if(isset($events['TRIGGERED']['DaemonEvent_reload_ldap_config'])){
939         $evt = $events['TRIGGERED']['DaemonEvent_reload_ldap_config'];
940         $macs = array();
941     
942         /* Get list of macAddresses 
943          */
944         if(isset($this->parent->by_object['ogroup'])){
945         
946           /* If we are an object group, add all member macs 
947            */
948           $p = $this->parent->by_object['ogroup'];
949           foreach($p->memberList as $dn => $obj){
950             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
951               $macs[] = $p->objcache[$dn]['macAddress'];
952             }
953           }
954         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
956           /* We are a workstation. Add current mac.
957            */
958           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
959           if(!empty($mac)){
960             $macs[] = $mac;
961           }          
962         }elseif(isset($this->parent->by_object['servgeneric']->netConfigDNS->macAddress)){
964           /* We are a server. Add current mac.
965            */
966           $mac = $this->parent->by_object['servgeneric']->netConfigDNS->macAddress;
967           if(!empty($mac)){
968             $macs[] = $mac;
969           }          
970         }
972         /* Trigger event for all member objects 
973          */
974         foreach($macs as $mac){
975           $tmp = new $evt['CLASS_NAME']($this->config);
976           $tmp->set_type(TRIGGERED_EVENT);
977           $tmp->add_targets(array($mac));
978           if(!$o_queue->append($tmp)){
979             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
980           }
981         }
982       }
983     }
984   }
987   /* Add value to array, check if unique */
988   function add_list (&$array, $value)
989   {
990     if ($value != ""){
991       $array[]= $value;
992       sort($array);
993       array_unique ($array);
994     }
995   }
998   /* Delete value to array, check if unique */
999   function del_list (&$array, $list)
1000   {
1001     $tmp= array();
1002     foreach ($array as $mod){
1003       if (!in_array($mod, $list)){
1004         $tmp[]= $mod;
1005       }
1006     }
1007     $array= $tmp;
1008   }
1010   /* Generate ListBox frindly output for the defined shares
1011    * Possibly Add or remove an attribute here,
1012    */
1013   function printOutAssignedShares()
1014   {
1015     $a_return = array();
1016     if(is_array($this->gotoShares)){
1017       foreach($this->gotoShares as $share){
1018         $a_return[$share['name']."|".$share['server']]= $share['name']." [".$share['server']."]";
1019       }
1020     }
1021     return($a_return);
1022   }
1026   function PrepareForCopyPaste($source)
1027   {
1028     plugin::PrepareForCopyPaste($source);    
1029     $source_o = new workstartup ($this->config, $source['dn']);
1030     foreach(array("FAIclass","gotoModules", "gotoAutoFs", "gotoFilesystem",
1031           "gotoKernelParameters","gotoShares","customParameters") as $attr){
1032       $this->$attr = $source_o->$attr;
1033     }
1034   }
1036   
1037   function array_switch_item($ar,$from,$to)
1038   {
1039     if(!is_array($ar)){
1040       return(false);
1041     }
1042     if(!isset($ar[$from])){
1043       return(false);
1044     }
1045     if(!isset($ar[$to])){
1046       return(false);
1047     }
1049     $tmp = $ar[$from];
1050     $ar[$from] = $ar[$to];    
1051     $ar[$to] = $tmp;    
1052     return($ar);
1053   }
1056   /* Return plugin informations for acl handling */ 
1057   static function plInfo()
1058   {
1059     return (array( 
1060           "plShortName"   => _("Startup"),
1061           "plDescription" => _("System startup"),
1062           "plSelfModify"  => FALSE,
1063           "plDepends"     => array(),
1064           "plPriority"    => 9,
1065           "plSection"     => array("administration"),           
1066           "plCategory"    => array("workstation","server","ogroups"),
1068           "plProvidedAcls"=> array(
1069             "gotoLdapServer"        => _("Ldap server"),
1070             "gotoBootKernel"        => _("Boot kernel"),
1071             "gotoKernelParameters"  => _("Kernel parameter"),
1073             "gotoModules"           => _("Kernel modules"),
1074             "gotoShare"             => _("Shares"),
1076             "FAIclass"              => _("FAI classes"),
1077             "FAIdebianMirror"       => _("Debian mirror"),
1078             "FAIrelease"            => _("Debian release"),
1080             "FAIstatus"             => _("FAI status flag")) // #FIXME is this acl realy necessary ?
1081           ));
1082   }
1085   /* Updates release dns 
1086    *  and reads all classes for the current release, 
1087    *  if not already done ($this->cache).
1088    */
1089   function update_fai_cache($first_call = FALSE)
1090   {
1091     $force = FALSE;
1092     if(!$this->si_active) return; 
1093     $start = microtime(TRUE);  
1095     if($this->si_fai_action_failed && !isset($_POST['fai_si_retry'])) return;
1097     $this->si_fai_action_failed = FALSE;
1099     /* Get the list of available servers and their releases. 
1100      */
1101     if($force || !isset($this->cache['SERVERS'])){
1103       $o_queue = new gosaSupportDaemon();
1104       $tmp = $o_queue->FAI_get_server();
1105       if($o_queue->is_error()){
1106         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1107         $this->si_fai_action_failed = TRUE;
1108         $this->cache = array();
1109         return;
1110       }else{
1111         foreach($tmp as $entry){
1112           $rel = $entry['RELEASE'];
1113           $this->cache['SERVERS']['auto'][$rel] = $rel;
1114           $this->cache['SERVERS'][$entry['SERVER']][$rel] = $rel;
1115           uksort($this->cache['SERVERS']['auto'], 'strnatcasecmp');
1116           uksort($this->cache['SERVERS'][$entry['SERVER']], 'strnatcasecmp');
1117         }
1118       }
1119     }
1121     /* Ensure that our selection is valid, else we get several PHP warnings 
1122         if there is no FAI configuration at all.
1123      */
1124     if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1125       $this->cache['SERVERS'][$this->FAIdebianMirror][''] ='';
1126     }
1128     /* Build up arrays, without checks */
1129     if(!$first_call){
1131       /* Check if the selected mirror is available */
1132       if(!isset($this->cache['SERVERS'][$this->FAIdebianMirror])){
1133         $this->FAIdebianMirror = "auto";
1134         $this->FAIrelease      = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1135         trigger_error("There was a problem with the selected FAIdebianMirror. This mirror ('".$this->FAIdebianMirror."') is not available");
1136       }
1138       /* Check if the selected release is available */
1139       if($this->FAIdebianMirror != "inherited" && !isset($this->cache['SERVERS'][$this->FAIdebianMirror][$this->FAIrelease])){
1140         trigger_error("There was a problem with the selected FAIrelease. This release ('".$this->FAIrelease."') is not available");
1141         $this->FAIrelease = key($this->cache['SERVERS'][$this->FAIdebianMirror]);
1142       }
1143     }
1145     /* Get classes for release from cache. 
1146      * Or build cache
1147      */
1148     if($this->FAIdebianMirror == "inherited"){
1149       $release = $this->InheritedFAIrelease;
1150     }else{
1151       $release = $this->FAIrelease;
1152     }
1154     if($force || !isset($this->cache['CLASSES'][$release]) && $release != ""){
1156       /* Get the list of available servers and their releases.
1157        */
1158       $o_queue = new gosaSupportDaemon();
1159       $tmp = $o_queue->FAI_get_classes($release);
1160       $this->cache['CLASSES'][$release] = array();
1161       if($o_queue->is_error()){
1162         msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
1163         $this->si_fai_action_failed = TRUE;
1164         $this->cache=array();
1165         return;
1166       }else{
1167         foreach($tmp as $entry){
1168           $class = $entry['CLASS'];
1169           $this->cache['CLASSES'][$release][$class] = $this->analyse_fai_object($entry); 
1170         }
1171       }
1173       /* Add object caught from external hook
1174        */
1175       $lines= $this->GetHookElements();
1176       foreach ($lines as $hline){
1177         $entries= split(";", $hline);
1178         $server = $entries['0'];
1179         $url    = $entries['1'];
1180         if (!empty($url)){
1182           /* Split releases */
1183           if (isset($entries[2])){
1184             $releases= split(",", $entries[2]);
1186             foreach ($releases as $release_data){
1187               $release_c  = preg_replace('/:.*$/', '', $release_data);
1188               $sections_c = split(':', preg_replace('/^[^:]+:([^|]+)|.*$/', '\1', $release_data));
1189               $classes_c  = split('\|', preg_replace('/^[^|]+\|(.*)$/', '\1', $release_data));
1191               if($release_c == $release){
1192                 $this->cache['SERVERS'][$url][$release_c]=$release_c;
1193                 $this->cache['SERVERS']['auto'][$release_c]=$release_c; 
1194                 foreach ($classes_c as $class){
1195                   if ($class != ""){
1196                     $this->cache['CLASSES'][$release_c][$class]= array();
1197                   }
1198                 }
1199               }
1200             }
1201           }
1202         }
1203       }
1204       uksort($this->cache['SERVERS'], 'strnatcasecmp');
1206       /* Only add inherit option, if we are part in an object group
1207        */
1208       if($this->member_of_ogroup){
1209         $this->cache['SERVERS'] = array_merge(array('inherited' => array()),$this->cache['SERVERS']);
1210       }
1211     }
1213     /* Get list of available kernel for this release 
1214      */
1215     if(!isset($this->cache['KERNELS'])) $this->cache['KERNELS'] = array();
1217     if($force || !isset($this->cache['KERNELS'][$release])){
1218       $o_queue = new gosaSupportDaemon();
1219       $tmp = $o_queue->FAI_get_kernels($release);
1220       $this->cache['KERNELS'][$release] = array();
1221       foreach($this->gotoBootKernels as $name => $default){
1222         $this->cache['KERNELS'][$release][$name] = $default;
1223       }
1224       foreach($tmp as $kernel){
1225         if(empty($kernel)) continue;
1226         $this->cache['KERNELS'][$release][$kernel]=$kernel;
1227       }
1228       ksort($this->cache['KERNELS'][$release]);
1229     }
1230   }
1233   /* This function return an array containing all 
1234    *  invalid classes for the selected server/release
1235    */
1236   function get_invalid_classes($classes)
1237   {
1238     $this->update_fai_cache();
1239     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1240       $release_classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1241     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1242       $release_classes = $this->cache['CLASSES'][$this->FAIrelease];
1243     }else{
1244       $release_classes = array();
1245     }
1248     /* Detect all classes that are not valid 
1249      *  for the selected release 
1250      */
1251     $NA = array();
1252     foreach($classes as $class){
1253       if(!isset($release_classes[$class])){
1254         $NA[] = $class;
1255       }
1256     }
1257     return($NA);
1258   }  
1260   
1261   /* Get all selectable classes for the ui select box
1262    */
1263   function selectable_classes()
1264   {
1265     $this->update_fai_cache();
1267     if($this->FAIdebianMirror == "inherited" && isset($this->cache['CLASSES'][$this->InheritedFAIrelease])){
1268       $classes = $this->cache['CLASSES'][$this->InheritedFAIrelease];
1269     }elseif(isset($this->cache['CLASSES'][$this->FAIrelease])){
1270       $classes = $this->cache['CLASSES'][$this->FAIrelease];
1271     }else{
1272       $classes = array();
1273     }
1275     $Abbr ="";
1276     $ret= array();
1277     foreach($classes as $class_name => $class_types){
1278       if(!in_array($class_name,$this->FAIclass)){
1279         foreach($class_types as $type){
1280           if(!preg_match("/".$type['Abbr']."/",$Abbr)){
1281             $Abbr .= $type['Abbr']." ";
1282           }
1283         }
1284         $ret[$class_name] = trim($Abbr);
1285       }
1286     }
1287     uksort($ret, 'strnatcasecmp');
1288     return($ret);
1289   }
1292   /* Analyse FAI object and return an array with usefull informations like 
1293    *  FAIobject type.
1294    */
1295   function analyse_fai_object($attr)
1296   {
1297     $tmp = array();
1298     switch($attr['TYPE']){
1300       case 'FAIpackageList':
1301         $tmp["Type"]= 'FAIpackageList';
1302         $tmp["Abbr"]= 'Pl';
1303         break;
1304       case 'FAItemplate': 
1305         $tmp["Type"]= 'FAItemplate'; 
1306         $tmp["Abbr"]= 'T'; 
1307         break;
1308       case 'FAIvariable':
1309         $tmp["Type"]= 'FAIvariable'; 
1310         $tmp["Abbr"]= 'V'; 
1311         break;
1312       case 'FAIscript':
1313         $tmp["Type"]= 'FAIscript'; 
1314         $tmp["Abbr"]= 'S'; 
1315         break;
1316       case 'FAIhook':
1317         $tmp["Type"]= 'FAIhook'; 
1318         $tmp["Abbr"]= 'H'; 
1319         break;
1320       case 'FAIpartitionTable':
1321         $tmp["Type"]= 'FAIpartitionTable'; 
1322         $tmp["Abbr"]= 'Pt'; 
1323         break;
1324       case 'FAIprofile':
1325         $tmp["Type"]= 'FAIprofile'; 
1326         $tmp["Abbr"]= 'P'; 
1327         break;
1328       default: trigger_error("Unknown FAI object type!");;
1329     }
1330     return($tmp);
1331   }
1334   /* Return repository hook output, if possible.
1335    */
1336   function GetHookElements()
1337   {
1338     $ret = array();
1339     $cmd= $this->config->search("servrepository", "REPOSITORY_HOOK",array('tabs'));
1340     if(!empty($cmd)){
1341       $res = shell_exec($cmd);
1342       $res2 = trim($res);
1343       if((!$res)){
1344         msg_dialog::display(_("Configuration error"), msgPool::cmdexecfailed("REPOSITORY_HOOK", $cmd), ERROR_DIALOG);
1345       }elseif(empty($res2)){
1346         msg_dialog::display(_("Configuration error"), _("REPOSITORY_HOOK returned no result!"), ERROR_DIALOG);
1347       }else{
1348         $tmp = split("\n",$res);
1349         foreach($tmp as $line){
1350           if(empty($line)) continue;
1351           $ret[]= $line;
1352         }
1353       }
1354     }
1355     return($ret);
1356   }
1359   /* This function creates the release name out of a dn 
1360    *  e.g. "ou=1.0rc2,ou=siga,ou=fai,..." => "siga/1.0rc2"
1361    */
1362   function dn_to_release_name($dn)
1363   {
1364     $relevant = preg_replace("/,".normalizePreg(get_ou("faiou")).".*$/","",$dn);
1365     $parts    = array_reverse(split("\,",$relevant));
1366     $str ="";
1367     foreach($parts as $part){
1368       $str .= preg_replace("/^ou=/","",$part)."/";
1369     }
1370     return(preg_replace("/\/$/","",$str)); 
1371   }
1374 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1375 ?>