Code

Added several comments
[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       /* Get 'dn' from posted termlinst */
148       $this->dn= $this->objects[$s_entry]['dn'];
150                         /* Load permissions for selected 'dn' and check if
151                            we're allowed to remove this 'dn' */
152       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
153       if(preg_match("/d/",$acl)){
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. */
194       /* Find out more about the object type */
195       $ldap       = $this->config->get_ldap_link();
196       $ldap->cat($this->dn, array('objectClass'));
197       $attrs    = $ldap->fetch();
198       $type       = $this->get_type($attrs);                    
200       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
201       if(preg_match("/d/",$acl)){
203         $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn,"fai");
204         $this->dialog->set_acl_base($this->dn);
205         $this->dialog->by_object[$type[1]]->remove_from_parent ();
206         unset ($this->dialog);
207         gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
208         $this->dialog= NULL;
209         $to_del = clean_up_releases($this->dn);
210         save_release_changes_now();
212         foreach($to_del as $dn){
213           $ldap->rmdir_recursive($dn);
214           gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
215         }
217       } else {
219         /* Normally this shouldn't be reached, send some extra
220            logs to notify the administrator */
221         print_red (_("You are not allowed to delete this component!"));
222         gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
223             "deletion.");
224       }
226       /* Remove lock file after successfull deletion */
227       del_lock ($this->dn);
228     }
231     /****************
232       Edit entry 
233      ****************/
235                 if(($s_action == "edit") && (!isset($this->dialog->config))){
236                         $entry    = $this->objects[$s_entry];
237                         $a_setup  = $this->get_type($entry);
238                         $this->dn = $entry['dn'];
240                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
241                         if (($user= get_lock($this->dn)) != ""){
242                                 return(gen_locked_message ($user, $this->dn));
243                         }
244                         add_lock ($this->dn, $this->ui->dn);
246                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
247       $this->dialog->set_acl_base($this->dn);
248                         $this->is_dialog  = true;
250       if($entry['FAIstate'] == "freeze"){
251         #$this->dialog->set_acl(array("*none*"))  ;    
252         echo "Dawn it is freezed.";
253       }
254                         $_SESSION['objectinfo'] = $this->dn;
255                 }
258     /*  Branch handling 
259         09.01.2006
260     */
262     /****************
263       Remove branch
264      ****************/
266     /* Remove branch 
267      */
268     if($s_action == "remove_branch"){
269       $base= $this->DivListFai->selectedBranch;
271       /* Load permissions for selected 'dn' and check if
272          we're allowed to remove this 'dn' */
273       $this->set_acl_base($base);
274       if($this->acl_is_removeable()){
276         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
277         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
278       } else {
279         print_red (_("You are not allowed to delete this release!"));
280       }
281     }
283     
284     /****************
285       Remove branch confirmed
286      ****************/
288     if(isset($_POST['delete_branch_confirm'])){
289       $bb =  $this->DivListFai->selectedBranch;
290       if(!isset($ldap)){
291         $ldap = $this->config->get_ldap_link();
292       }
294       $br = $this->getBranches();
296       if(isset($br[$bb]) && $this->acl_is_removeable()){
297         $name = $br[$bb];
298         $ldap->cd($bb);
299         $ldap->recursive_remove();
300         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
301         $ldap->recursive_remove();
302         $this->DivListFai->selectedBranch = "main";
304         /* Post remove */
305         $this->lock_name   = $name;
306         $this->lock_dn     = $bb;
307         $this->postremove();
308       }
309     }
312     /****************
313       Create a new branch "insert Name"
314      ****************/
316     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
317       $_SESSION['LASTPOST'] = $_POST;
319       if($this->dispNewBranch){
320         $type = "branch";
321       }else{
322         $type = "freeze";
323       }
325       /* Check branch name */
326       $name = $_POST['BranchName'];
327       $is_ok = true;
328       $smarty->assign("BranchName",$name);
329       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
331       /* Check used characters */
332       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
333         if($type == "branch"){
334           print_red(_("Specified branch name is invalid."));
335         }else{
336           print_red(_("Specified freeze name is invalid."));
337         }
338         $is_ok = false;
339       }
341       /* Check if this name is already in use */
342       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
343         print_red(_("This name is already in use."));
344         $is_ok = false;
345       }
347       if($is_ok){
348         $_SESSION['LASTPOST']['base'] = $base;
349         $_SESSION['LASTPOST']['type'] = $type;
350         $smarty->assign("iframe", true);
351         $smarty->assign("plugID", $_GET['plug']);
352         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
353         return($display);
354       }
355     }
358     /****************
359       Create a new branch 
360      ****************/
362     if(isset($_GET['PerformBranch'])){
364       if(!$this->acl_is_createable()){
365         print_red(_("You are not allowed to create a new branch."));
366       }else{
368         /* Create it know */
369         $this->dispNewBranch = false;
370         $this->dispNewFreeze = false;
371         $base = $_SESSION['LASTPOST']['base'];
372         $_POST = $_SESSION['LASTPOST'];      
373         $name = $_POST['BranchName'];
375         $type = $_SESSION['LASTPOST']['type'];
376         $ldap = $this->config->get_ldap_link();
378         $baseToUse = $base;
379         if($this->DivListFai->selectedBranch != "main" ){
380           $baseToUse = $this->DivListFai->selectedBranch;
381         }
383         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
385         $CurrentReleases  = $this->getBranches();
386         $NewReleaseName   = $name;
387         if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
388           if($this->DivListFai->selectedBranch != "main"){
389             $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
390             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
391           }else{
392             $NewReleaseName   = $name;
393           }
394         }
396         $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
397         $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
399         $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
400         $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
402         /* Print header to have styles included */
403         echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
404         echo "<body style='background-image:none;margin:3px;color:black'>";
406         /* Duplicate applications 
407          */
408         $ldap->cat($appsrc,array("dn")) ;
409         if($ldap->count()){
410           $ldap->cd ($appdst);
411           $ldap->recursive_remove();
412           $ldap->cd ($this->config->current['BASE']);
413           $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
414         }
416         /* Duplicate mime types 
417          */
418         $ldap->cat($mimesrc,array("dn")) ;
419         if($ldap->count()){
420           $ldap->cd ($appdst);
421           $ldap->recursive_remove();
422           $ldap->cd ($this->config->current['BASE']);
423           $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
424         }
426         $attr = array();
427         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
428         $attr['ou']       = $name;
429         $attr['FAIstate'] = $type;
430         $ldap->cd($this->config->current['BASE']);
431         $ldap->cd("ou=".$name.",".$baseToUse);
432         $ldap->cat("ou=".$name.",".$baseToUse);
433         if($ldap->count()){
434           $ldap->modify($attr);
435         }else{
436           $ldap->add($attr);
437         }
439         /* Duplicate fai objects 
440          */
441         //      $ldap->cd ("ou=".$name.",".$baseToUse);
442         //      $ldap->recursive_remove();
443         //      $ldap->cd ($this->config->current['BASE']);
444         //      $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
446         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
447           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
448           </form></div>";
450         /* Print footer to have valid html */
451         echo "</body></html>";
453         $this->dispNewFreeze = false; 
455         /* Postcreate */ 
457         /* Assign possible attributes */
458         $this->lock_type  = $type; 
459         $this->lock_name  = $name; 
460         $this->lock_dn    = $baseToUse;
461         $this->postcreate();
462         exit();
463       }
464     }
466     /****************
467       Display dialog to enter new Branch name
468      ****************/
470     if(($s_action == "branch_branch")||($this->dispNewBranch)){
471       $this->dispNewBranch=true;
472       $smarty->assign("iframe",false);
473                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
474       return($display);
475     }
476    
477  
478     /****************
479       Display dialog to enter new Freeze name
480      ****************/
482     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
483       $this->dispNewFreeze = true;
484       $smarty->assign("iframe",false);
485                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
486       return($display);
487     }
490     /****************
491       Create a new object 
492      ****************/
494     $types = array( "new_partition"     =>  "FAIpartitionTable",
495                     "new_script"        =>  "FAIscript",
496                     "new_hook"          =>  "FAIhook",
497                     "new_variable"      =>  "FAIvariable",
498                     "new_template"      =>  "FAItemplate",
499                     "new_package"       =>  "FAIpackageList");
501     if(isset($types[$s_action])){
502       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
503       if(preg_match("/c/",$acl)){
504         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
505       }else{
506         print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
507       }
508     }
510     /* New Profile */
511     if($s_action == "new_profile"){
512       $this->dn = "new" ;
514       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
515       if(preg_match("/c/",$acl)){
516         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
517         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"faiProfile");
518         $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
520         $this->is_dialog = false;
521       }else{
522         print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
523       }
524     }
527     /****************
528       Get from ask class name dialog 
529      ****************/
531     if($s_action == "select_class_name_finished"){
532       $this->dialog->save_object();
533       if(count($this->dialog->check())!=0){
534         foreach($this->dialog->check() as $msg){
535           print_red($msg);
536         }               
537       }else{
538         $this->dn = "new" ;
539         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
540         $name = $this->dialog->save();
542         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
543         $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
544         $this->dialog->by_object[$a_setup[1]]->cn = $name;
545         $this->is_dialog = true;
546       }         
547     }   
550     /****************
551      Cancel dialogs 
552      ****************/
554                 if(isset($_POST['edit_cancel'])){
555                         unset($this->dialog);
556                         $this->dialog=NULL;
557                         $this->is_dialog = false;
558                         unset($_SESSION['objectinfo']);
559                         del_lock ($this->dn);
560                 }
563     /****************
564       Save sub dialogs 
565      ****************/
567                 /* This check if the given tab could be saved 
568                  * If it was possible to save it, remove dialog object. 
569                  * If it wasn't possible, show errors and keep dialog.
570                  */
571                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
572                         $this->dialog->save_object();
573       $msgs= $this->dialog->check();
574                         if(count($msgs)!=0){
575                                 foreach($msgs as $msg){
576                                         print_red($msg);
577                                 }
578                         }else{
579                                 $this->dialog->save();
580         save_release_changes_now();
581         if (!isset($_POST['edit_apply'])){
582           del_lock ($this->dn);
583           unset($this->dialog);
584           $this->dialog=NULL;
585           $this->is_dialog=false;
586           unset($_SESSION['objectinfo']);
587         }
588                         }
589                 }
592     /****************
593       Display currently open dialog 
594      ****************/
596                 /* If dialog is set, but $this->is_dialog==false, then 
597                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
598                  * If is_dialog == true, we are currently editing tab objects.
599                  *  Here we need both, save and cancel
600                  */ 
602                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
603                         $display .= $this->dialog->execute();
604                         /* Don't show buttons if tab dialog requests this */
606       if(isset($this->dialog->current)){
608         $obj = $this->dialog->by_object[$this->dialog->current];
610         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
612           $display.= "<p style=\"text-align:right\">\n";
613           $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
614           $display.= "&nbsp;\n";
615           if ($this->dn != "new"){
616             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
617             $display.= "&nbsp;\n";
618           }
619           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
620           $display.= "</p>";
621         }elseif(!isset($this->dialog->current)){
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>";
626         }
627       }else{
628         $display.= "<p style=\"text-align:right\">\n";
629         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
630         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
631         $display.= "</p>";
633       }
634       return($display);
635                 }
636                 
638     /****************
639       Dialog display
640      ****************/
642     /* Check if there is a snapshot dialog open */
643     $base = $this->DivListFai->selectedBase;
644     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
645       return($str);
646     }
648     /* Display dialog with system list */
649     $this->DivListFai->parent = $this;
650     $this->DivListFai->execute();
651     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
652     $this->reload();
653     $this->DivListFai->setEntries($this->objects);
654     return($this->DivListFai->Draw());
655         }
658   /* Return departments, that will be included within snapshot detection */
659   function get_used_snapshot_bases()
660   {
661     $tmp = array();
662     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
663     foreach($types as $type){
664       if($this->DivListFai->selectedBranch == "main"){
665         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
666       }else{
667         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
668       }
669     }
670     return($tmp);
671   }
674   /* Get available branches for current base */
675   function getBranches($base = false,$prefix = "")
676   {
677     $ret = array("main"=>"/");
678     $ldap = $this->config->get_ldap_link();
679     if(!$base){
680       $base= $_SESSION['CurrentMainBase'];
681     }
682     $tmp = get_all_releases_from_base($base,true);
683     foreach($tmp as $dn => $name){
684       $ret[$dn]=$name;
685     }
686     return ($ret);
687   }
689   
691   /* reload list of objects */
692   function reload()
693   {
694     /* Variable initialisation */
695     $str            = "";
696     $Regex          = $this->DivListFai->Regex;
697     $this->objects  = array();
699     /* Get base */
700     $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
701     if($this->DivListFai->selectedBranch != "main"){
702       $br = $this->getBranches();
703       if(isset($br[$this->DivListFai->selectedBranch])){
704         $base = $this->DivListFai->selectedBranch;
705       }else{
706         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
707       }
708     }
710     $this->lock_type = get_release_tag(get_release_dn($base));
712     /* Create a new list of FAI object 
713      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
714      */
715     $ObjectTypes = array(
716         "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
717         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
718         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
719         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
720         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
721         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
722         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
724     $filter = "";
725     foreach($ObjectTypes as $key => $data){
726       if($this->DivListFai->$data['CHKBOX']){
727         $filter.= "(objectClass=".$key.")";
728       }
729     }
730     $filter = "(&(|".$filter.")(cn=$Regex))";
731     
732     /* Get resolved release dependencies */
733     $tmp = get_all_objects_for_given_base($base,$filter);
735     /* Ge listed ldap objects */
736     $ldap = $this->config->get_ldap_link();
737     $ldap->cd($this->config->current['BASE']);
738     foreach($tmp as $entry){
740       /* Get some more informations about the object */ 
741       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
742       $object  = $ldap->fetch();
744       /* Walk through possible types */
745       foreach($ObjectTypes as $type => $rest){  
747         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
749         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
751           /* Prepare object */
752           unset($object['objectClass']['count']);
753           if(!isset($object['description'][0])){
754             $object['description'][0]="";
755           }
757           /* Clean up object informations */
758           $obj                  = array();
759           $obj['cn']                          = $object['cn'][0];
760           $obj['dn']                          = $object['dn'];
761           $obj['acl']                       = $acl;
762           $obj['description']   = $object['description'][0];
763           $obj['objectClass']   = $object['objectClass'];
765           /* Append type to this string, to be able to check if the selected 
766            * entry is of type 'freeze' or 'branch'
767            */
768           if(!isset($object['FAIstate'])){
769             $obj['FAIstate'] = $this->lock_type;
770           }else{
771             $obj['FAIstate'] = $object['FAIstate'][0]; 
772           }
774           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
775           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
776         }
777                         }
778                 }
780                 ksort($this->objects);
781                 reset ($this->objects);
782         
783                 /* use numeric index, thats a bit more secure */        
784                 $tmp0 = array();
785                 foreach($this->objects as $obj){
786                         $tmp0[]= $obj;
787                 }
788                 $this->objects = array();
789                 $this->objects = $tmp0;
790         }
792         function remove_lock()
793         {
794                 if (isset($this->dn)){
795                         del_lock ($this->dn);
796                 }
797         }
799         function get_type($array){
800                 if(in_array("FAIpartitionTable",$array['objectClass'])){
801                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
802                 }
803                 if(in_array("FAIscript",$array['objectClass'])){
804                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
805                 }
806                 if(in_array("FAItemplate",$array['objectClass'])){
807                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
808                 }
809                 if(in_array("FAIhook",$array['objectClass'])){
810                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
811                 }
812                 if(in_array("FAIvariable",$array['objectClass'])){
813                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
814                 }
815                 if(in_array("FAIprofile",$array['objectClass'])){
816                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
817                 }
818                 
819                 if(in_array("FAIpackageList",$array['objectClass'])){
820                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
821                 }
822         }
824   function CheckNewBranchName($name,$base)
825   {
826     $f = $this->DivListFai->selectedBranch;
827     if($name == ""){
828       return(false);
829     }elseif(in_array($name,$this->getBranches($f))) {
830       return(false);
831     }elseif(is_department_name_reserved($name,$base)){
832       return(false);
833     }
834     return(true);
835   }
837   function save_object()
838   {
839     $this->DivListFai->save_object();
840   }
843   /* Return plugin informations for acl handling */ 
844   function plInfo()
845   {
846     return (array( 
847           "plShortName"   => _("FAI releases"),
848           "plDescription" => _("FAI release management"),
849           "plSelfModify"  => FALSE,
850           "plDepends"     => array(),
851           "plPriority"    => 0,
852           "plSection"     => array("administration"),           
853           "plCategory"    => array("fai"=> array("description" => _("FAI"),
854                                                  "objectClass" => "FAIclass")),
855           "plProvidedAcls"=> array()));
856   }
858 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
859 ?>