Code

Some fai acls
[gosa.git] / plugins / admin / fai / class_faiManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 require "tabsPartition.inc";
22 require "tabsVariable.inc";
23 require "tabsHook.inc";
24 require "tabsTemplate.inc";
25 require "tabsScript.inc";
26 require "tabsProfile.inc";
27 require "tabsPackage.inc";
30 class faiManagement extends plugin
31 {
32         /* Definitions */
33         var $plHeadline                 = "FAI";
34         var $plDescription              = "Fully Automatic Installation - management";
36         /* CLI vars */
37         var $cli_summary                  = "Handling of FAI entries";
38         var $cli_description    = "This plugin represents a management tool\n
39                 which allows us to manage all needed attributes for fully automatic installations (FAI)";
40         var $cli_parameters             = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
42         /* Headpage attributes */
43   var $lock_type    = "";    // should be branch/freeze
44   var $lock_name    = "";
45   var $lock_dn      = "";  
47         /* attribute list for save action */
48         var $attributes         = array("lock_type","lock_name","lock_dn");     //      Attributes Managed by this plugin 
49         var $objectclasses= array();    //      ObjectClasses which the attributes are related to
50         var $dialog                             = array();      //      This object contains every dialog we have currently opened
52         var $objects                    = array();      //      This array contains all available objects shown in divlist
53         var $is_dialog          = false;
55   var $dispNewBranch= false;
56   var $dispNewFreeze= false;
58   var $DivListFai;
60         /* construction/reconstruction 
61          */
62         function faiManagement ($config, $ui)
63         {
64                 /* Set defaults */
65                 $this->dn                       = "";
66                 $this->config   = $config;
67                 $this->ui                       = $ui;  
68     
69     /* Creat dialog object */
70     $this->DivListFai = new divListFai($this->config,$this);
71         }
73         function execute()
74         {
75     /* Call parent execute */
76     plugin::execute();
78     /* Initialise vars and smarty */
79                 $smarty         = get_smarty();
80                 $smarty->assign("BranchName","");
81     
82                 $display        = "";
83     $s_action   = "";
84                 $s_entry        = "";
85     
86     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
87     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/");
90     /****************
91       Handle posts 
92      ****************/
94                 /* Check ImageButton posts
95                  * Create new tab ich new_xx is posted
96                  */
97     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
98                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
99                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
100                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
101                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
102                     "/edit_continue/"=>"select_class_name_finished");
104                 foreach($_POST as $name => $value){
105       foreach($posts as $reg => $act ){
106         if(preg_match($reg,$name)){
107           $s_action = $act;
108         }
109       }
110                         if(preg_match("/^entry_edit_.*/",$name)){
111                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
112                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
113                                 $s_action = "edit";
114                         }elseif(preg_match("/^entry_delete_.*/",$name)){
115                                 $s_entry = preg_replace("/^entry_delete_/","",$name);
116                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
117         $s_action = "delete";
118       }
119     }
121                 if(isset($_GET['edit_entry'])){
122                         $s_entry = $_GET['edit_entry'];
123                         $s_action = "edit";
124                 }
125     
126     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
127       $this->dispNewBranch = false;
128       $this->dispNewFreeze = false;
129     }
132     $type_acl_mapping = array(
133         "FAIpartitionTable"  => "faiPartitionTable", 
134         "FAIpackageList"     => "faiPackage",
135         "FAIscript"          => "faiScript",
136         "FAIvariable"        => "faiVariable",
137         "FAIhook"            => "faiHook",
138         "FAIprofile"         => "faiProfile",
139         "FAItemplate"        => "faiTemplate");
141     /****************
142       Delete confirme dialog 
143      ****************/
145                 if ($s_action=="delete"){
147                         /* Load permissions for selected 'dn' and check if
148                            we're allowed to remove this 'dn' */
149       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
150       if(preg_match("/d/",$acl)){
152         /* Get 'dn' from posted termlinst */
153         $this->dn= $this->objects[$s_entry]['dn'];
155                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
156                                 if (($user= get_lock($this->dn)) != ""){
157                                         return(gen_locked_message ($user, $this->dn));
158                                 }
160                                 /* Lock the current entry, so nobody will edit it during deletion */
161                                 add_lock ($this->dn, $this->ui->dn);
162                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
163                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
164                         } else {
166                                 /* Obviously the user isn't allowed to delete. Show message and
167                                    clean session. */
168                                 print_red (_("You are not allowed to delete this component!"));
169                         }
170                 }
173     /****************
174       Delete aborted  
175      ****************/
177                 /* Delete canceled? */
178                 if (isset($_POST['delete_cancel'])){
179                         del_lock ($this->dn);
180                 }
183     /****************
184       Delete confirmed 
185      ****************/
187                 /* Deltetion was confirmed, so delete this entry
188                  */
189                 if (isset($_POST['delete_terminal_confirm'])){
191                         /* Some nice guy may send this as POST, so we've to check
192                            for the permissions again. */
193       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
194       if(preg_match("/d/",$acl)){
196                                 /* Find out more about the object type */
197                                 $ldap     = $this->config->get_ldap_link();
198                                 $ldap->cat($this->dn, array('objectClass'));
199                                 $attrs  = $ldap->fetch();
200                                 $type     = $this->get_type($attrs);                    
201                                 $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn);
202                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
203                                 unset ($this->dialog);
204                                 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
205                                 $this->dialog= NULL;
206         $to_del = clean_up_releases($this->dn);
207         save_release_changes_now();
209         foreach($to_del as $dn){
210           $ldap->rmdir_recursive($dn);
211           gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
212         }
214                         } else {
216                                 /* Normally this shouldn't be reached, send some extra
217                                    logs to notify the administrator */
218                                 print_red (_("You are not allowed to delete this component!"));
219                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
220                                                 "deletion.");
221                         }
223                         /* Remove lock file after successfull deletion */
224                         del_lock ($this->dn);
225                 }
228     /****************
229       Edit entry 
230      ****************/
232                 if(($s_action == "edit") && (!isset($this->dialog->config))){
233                         $entry    = $this->objects[$s_entry];
234                         $a_setup  = $this->get_type($entry);
235                         $this->dn = $entry['dn'];
237                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
238                         if (($user= get_lock($this->dn)) != ""){
239                                 return(gen_locked_message ($user, $this->dn));
240                         }
241                         add_lock ($this->dn, $this->ui->dn);
243                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
244                         $this->is_dialog  = true;
246       if($entry['FAIstate'] == "freeze"){
247         #$this->dialog->set_acl(array("*none*"))  ;    
248         echo "Dawn it is freezed.";
249       }
250                         $_SESSION['objectinfo'] = $this->dn;
251                 }
254     /*  Branch handling 
255         09.01.2006
256     */
258     /****************
259       Remove branch
260      ****************/
262     /* Remove branch 
263      */
264     if($s_action == "remove_branch"){
265       $base= $this->DivListFai->selectedBranch;
267       /* Load permissions for selected 'dn' and check if
268          we're allowed to remove this 'dn' */
269       $this->set_acl_base($base);
270       if($this->acl_is_removeable()){
272         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
273         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
274       } else {
275         print_red (_("You are not allowed to delete this release!"));
276       }
277     }
279     
280     /****************
281       Remove branch confirmed
282      ****************/
284     if(isset($_POST['delete_branch_confirm'])){
285       $bb =  $this->DivListFai->selectedBranch;
286       if(!isset($ldap)){
287         $ldap = $this->config->get_ldap_link();
288       }
290       $br = $this->getBranches();
292       if(isset($br[$bb]) && $this->acl_is_removeable()){
293         $name = $br[$bb];
294         $ldap->cd($bb);
295         $ldap->recursive_remove();
296         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
297         $ldap->recursive_remove();
298         $this->DivListFai->selectedBranch = "main";
300         /* Post remove */
301         $this->lock_name   = $name;
302         $this->lock_dn     = $bb;
303         $this->postremove();
304       }
305     }
308     /****************
309       Create a new branch "insert Name"
310      ****************/
312     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
313       $_SESSION['LASTPOST'] = $_POST;
315       if($this->dispNewBranch){
316         $type = "branch";
317       }else{
318         $type = "freeze";
319       }
321       /* Check branch name */
322       $name = $_POST['BranchName'];
323       $is_ok = true;
324       $smarty->assign("BranchName",$name);
325       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
327       /* Check used characters */
328       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
329         if($type == "branch"){
330           print_red(_("Specified branch name is invalid."));
331         }else{
332           print_red(_("Specified freeze name is invalid."));
333         }
334         $is_ok = false;
335       }
337       /* Check if this name is already in use */
338       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
339         print_red(_("This name is already in use."));
340         $is_ok = false;
341       }
343       if($is_ok){
344         $_SESSION['LASTPOST']['base'] = $base;
345         $_SESSION['LASTPOST']['type'] = $type;
346         $smarty->assign("iframe", true);
347         $smarty->assign("plugID", $_GET['plug']);
348         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
349         return($display);
350       }
351     }
354     /****************
355       Create a new branch 
356      ****************/
358     if(isset($_GET['PerformBranch'])){
360       if(!$this->acl_is_createable()){
361         print_red(_("You are not allowed to create a new branch."));
362       }else{
364         /* Create it know */
365         $this->dispNewBranch = false;
366         $this->dispNewFreeze = false;
367         $base = $_SESSION['LASTPOST']['base'];
368         $_POST = $_SESSION['LASTPOST'];      
369         $name = $_POST['BranchName'];
371         $type = $_SESSION['LASTPOST']['type'];
372         $ldap = $this->config->get_ldap_link();
374         $baseToUse = $base;
375         if($this->DivListFai->selectedBranch != "main" ){
376           $baseToUse = $this->DivListFai->selectedBranch;
377         }
379         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
381         $CurrentReleases  = $this->getBranches();
382         $NewReleaseName   = $name;
383         if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
384           if($this->DivListFai->selectedBranch != "main"){
385             $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
386             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
387           }else{
388             $NewReleaseName   = $name;
389           }
390         }
392         $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
393         $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
395         $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
396         $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
398         /* Print header to have styles included */
399         echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
400         echo "<body style='background-image:none;margin:3px;color:black'>";
402         /* Duplicate applications 
403          */
404         $ldap->cat($appsrc,array("dn")) ;
405         if($ldap->count()){
406           $ldap->cd ($appdst);
407           $ldap->recursive_remove();
408           $ldap->cd ($this->config->current['BASE']);
409           $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
410         }
412         /* Duplicate mime types 
413          */
414         $ldap->cat($mimesrc,array("dn")) ;
415         if($ldap->count()){
416           $ldap->cd ($appdst);
417           $ldap->recursive_remove();
418           $ldap->cd ($this->config->current['BASE']);
419           $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
420         }
422         $attr = array();
423         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
424         $attr['ou']       = $name;
425         $attr['FAIstate'] = $type;
426         $ldap->cd($this->config->current['BASE']);
427         $ldap->cd("ou=".$name.",".$baseToUse);
428         $ldap->cat("ou=".$name.",".$baseToUse);
429         if($ldap->count()){
430           $ldap->modify($attr);
431         }else{
432           $ldap->add($attr);
433         }
435         /* Duplicate fai objects 
436          */
437         //      $ldap->cd ("ou=".$name.",".$baseToUse);
438         //      $ldap->recursive_remove();
439         //      $ldap->cd ($this->config->current['BASE']);
440         //      $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
442         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
443           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
444           </form></div>";
446         /* Print footer to have valid html */
447         echo "</body></html>";
449         $this->dispNewFreeze = false; 
451         /* Postcreate */ 
453         /* Assign possible attributes */
454         $this->lock_type  = $type; 
455         $this->lock_name  = $name; 
456         $this->lock_dn    = $baseToUse;
457         $this->postcreate();
458         exit();
459       }
460     }
462     /****************
463       Display dialog to enter new Branch name
464      ****************/
466     if(($s_action == "branch_branch")||($this->dispNewBranch)){
467       $this->dispNewBranch=true;
468       $smarty->assign("iframe",false);
469                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
470       return($display);
471     }
472    
473  
474     /****************
475       Display dialog to enter new Freeze name
476      ****************/
478     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
479       $this->dispNewFreeze = true;
480       $smarty->assign("iframe",false);
481                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
482       return($display);
483     }
486     /****************
487       Create a new object 
488      ****************/
490     $types = array( "new_partition"     =>  "FAIpartitionTable",
491                     "new_script"        =>  "FAIscript",
492                     "new_hook"          =>  "FAIhook",
493                     "new_variable"      =>  "FAIvariable",
494                     "new_template"      =>  "FAItemplate",
495                     "new_package"       =>  "FAIpackageList");
497     if(isset($types[$s_action])){
498       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
499       if(preg_match("/c/",$acl)){
500         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
501       }else{
502         print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
503       }
504     }
506     /* New Profile */
507     if($s_action == "new_profile"){
508       $this->dn = "new" ;
510       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
511       if(preg_match("/c/",$acl)){
512         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
513         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
514         $this->is_dialog = false;
515       }else{
516         print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
517       }
518     }
521     /****************
522       Get from ask class name dialog 
523      ****************/
525     if($s_action == "select_class_name_finished"){
526       $this->dialog->save_object();
527       if(count($this->dialog->check())!=0){
528         foreach($this->dialog->check() as $msg){
529           print_red($msg);
530         }               
531       }else{
532         $this->dn = "new" ;
533         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
534         $name = $this->dialog->save();
536         $this->dialog = new $a_setup[0]($this->config,
537             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
538         $this->dialog->by_object[$a_setup[1]]->cn = $name;
539         $this->is_dialog = true;
540       }         
541     }   
544     /****************
545      Cancel dialogs 
546      ****************/
548                 if(isset($_POST['edit_cancel'])){
549                         unset($this->dialog);
550                         $this->dialog=NULL;
551                         $this->is_dialog = false;
552                         unset($_SESSION['objectinfo']);
553                         del_lock ($this->dn);
554                 }
557     /****************
558       Save sub dialogs 
559      ****************/
561                 /* This check if the given tab could be saved 
562                  * If it was possible to save it, remove dialog object. 
563                  * If it wasn't possible, show errors and keep dialog.
564                  */
565                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
566                         $this->dialog->save_object();
567       $msgs= $this->dialog->check();
568                         if(count($msgs)!=0){
569                                 foreach($msgs as $msg){
570                                         print_red($msg);
571                                 }
572                         }else{
573                                 $this->dialog->save();
574         save_release_changes_now();
575         if (!isset($_POST['edit_apply'])){
576           del_lock ($this->dn);
577           unset($this->dialog);
578           $this->dialog=NULL;
579           $this->is_dialog=false;
580           unset($_SESSION['objectinfo']);
581         }
582                         }
583                 }
586     /****************
587       Display currently open dialog 
588      ****************/
590                 /* If dialog is set, but $this->is_dialog==false, then 
591                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
592                  * If is_dialog == true, we are currently editing tab objects.
593                  *  Here we need both, save and cancel
594                  */ 
596                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
597                         $display .= $this->dialog->execute();
598                         /* Don't show buttons if tab dialog requests this */
600       if(isset($this->dialog->current)){
602         $obj = $this->dialog->by_object[$this->dialog->current];
604         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
606           $display.= "<p style=\"text-align:right\">\n";
607           $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
608           $display.= "&nbsp;\n";
609           if ($this->dn != "new"){
610             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
611             $display.= "&nbsp;\n";
612           }
613           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
614           $display.= "</p>";
615         }elseif(!isset($this->dialog->current)){
616           $display.= "<p style=\"text-align:right\">\n";
617           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
618           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
619           $display.= "</p>";
620         }
621       }else{
622         $display.= "<p style=\"text-align:right\">\n";
623         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
624         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
625         $display.= "</p>";
627       }
628       return($display);
629                 }
630                 
632     /****************
633       Dialog display
634      ****************/
636     /* Check if there is a snapshot dialog open */
637     $base = $this->DivListFai->selectedBase;
638     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
639       return($str);
640     }
642     /* Display dialog with system list */
643     $this->DivListFai->parent = $this;
644     $this->DivListFai->execute();
645     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
646     $this->reload();
647     $this->DivListFai->setEntries($this->objects);
648     return($this->DivListFai->Draw());
649         }
652   /* Return departments, that will be included within snapshot detection */
653   function get_used_snapshot_bases()
654   {
655     $tmp = array();
656     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
657     foreach($types as $type){
658       if($this->DivListFai->selectedBranch == "main"){
659         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
660       }else{
661         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
662       }
663     }
664     return($tmp);
665   }
668   /* Get available branches for current base */
669   function getBranches($base = false,$prefix = "")
670   {
671     $ret = array("main"=>"/");
672     $ldap = $this->config->get_ldap_link();
673     if(!$base){
674       $base= $_SESSION['CurrentMainBase'];
675     }
676     $tmp = get_all_releases_from_base($base,true);
677     foreach($tmp as $dn => $name){
678       $ret[$dn]=$name;
679     }
680     return ($ret);
681   }
683   
685   /* reload list of objects */
686   function reload()
687   {
688     /* Variable initialisation */
689     $str            = "";
690     $Regex          = $this->DivListFai->Regex;
691     $this->objects  = array();
693     /* Get base */
694     $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
695     if($this->DivListFai->selectedBranch != "main"){
696       $br = $this->getBranches();
697       if(isset($br[$this->DivListFai->selectedBranch])){
698         $base = $this->DivListFai->selectedBranch;
699       }else{
700         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
701       }
702     }
704     $this->lock_type = get_release_tag(get_release_dn($base));
706     /* Get resolved release dependencies */
707     $tmp = get_all_objects_for_given_base($base,"(&(|(objectClass=FAIpartitionTable)(objectClass=FAIpackageList)(objectClass=FAIscript)
708       (objectClass=FAIvariable)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAItemplate))(cn=$Regex))");
710     /* Create a new list of FAI object 
711      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
712      */
713     $ObjectTypes = array(
714         "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"),
715         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"),
716         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"),
717         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"),
718         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"),
719         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"),
720         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"));
722     /* Ge listed ldap objects */
723     $ldap = $this->config->get_ldap_link();
724     $ldap->cd($this->config->current['BASE']);
725     foreach($tmp as $entry){
727       /* Get some more informations about the object */ 
728       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
729       $object  = $ldap->fetch();
731       /* Walk through possible types */
732       foreach($ObjectTypes as $type => $rest){  
734         /* Skip all unchecked types */
735         if(! $this->DivListFai->$rest['CHKBOX']){
736           continue;
737         }
739         if(in_array($type,$object['objectClass'])){
741           /* Prepare object */
742           unset($object['objectClass']['count']);
743           if(!isset($object['description'][0])){
744             $object['description'][0]="";
745           }
747           /* Clean up object informations */
748           $obj                  = array();
749           $obj['cn']                          = $object['cn'][0];
750           $obj['dn']                          = $object['dn'];
751           $obj['description']   = $object['description'][0];
752           $obj['objectClass']   = $object['objectClass'];
754           /* Append type to this string, to be able to check if the selected 
755            * entry is of type 'freeze' or 'branch'
756            */
757           if(!isset($object['FAIstate'])){
758             $obj['FAIstate'] = $this->lock_type;
759           }else{
760             $obj['FAIstate'] = $object['FAIstate'][0]; 
761           }
763           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
764           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
765         }
766                         }
767                 }
769                 ksort($this->objects);
770                 reset ($this->objects);
771         
772                 /* use numeric index, thats a bit more secure */        
773                 $tmp0 = array();
774                 foreach($this->objects as $obj){
775                         $tmp0[]= $obj;
776                 }
777                 $this->objects = array();
778                 $this->objects = $tmp0;
779         }
781         function remove_lock()
782         {
783                 if (isset($this->dn)){
784                         del_lock ($this->dn);
785                 }
786         }
788         function get_type($array){
789                 if(in_array("FAIpartitionTable",$array['objectClass'])){
790                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
791                 }
792                 if(in_array("FAIscript",$array['objectClass'])){
793                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
794                 }
795                 if(in_array("FAItemplate",$array['objectClass'])){
796                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
797                 }
798                 if(in_array("FAIhook",$array['objectClass'])){
799                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
800                 }
801                 if(in_array("FAIvariable",$array['objectClass'])){
802                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
803                 }
804                 if(in_array("FAIprofile",$array['objectClass'])){
805                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
806                 }
807                 
808                 if(in_array("FAIpackageList",$array['objectClass'])){
809                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
810                 }
811         }
813   function CheckNewBranchName($name,$base)
814   {
815     $f = $this->DivListFai->selectedBranch;
816     if($name == ""){
817       return(false);
818     }elseif(in_array($name,$this->getBranches($f))) {
819       return(false);
820     }elseif(is_department_name_reserved($name,$base)){
821       return(false);
822     }
823     return(true);
824   }
826   function save_object()
827   {
828     $this->DivListFai->save_object();
829   }
832   /* Return plugin informations for acl handling */ 
833   function plInfo()
834   {
835     return (array( 
836           "plShortName"   => _("FAI releases"),
837           "plDescription" => _("FAI release management"),
838           "plSelfModify"  => FALSE,
839           "plDepends"     => array(),
840           "plPriority"    => 0,
841           "plSection"     => array("administration"),           
842           "plCategory"    => array("fai"=> array("description" => _("FAI"),
843                                                  "objectClass" => "FAIclass")),
844           "plProvidedAcls"=> array()));
845   }
847 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
848 ?>