Code

Removed duplicated addslashes
[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     /****************
133       Delete confirme dialog 
134      ****************/
136                 if ($s_action=="delete"){
138                         /* Get 'dn' from posted termlinst */
139                         $this->dn= $this->objects[$s_entry]['dn'];
141                         /* Load permissions for selected 'dn' and check if
142                            we're allowed to remove this 'dn' */
143                         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
144                         $this->acl= get_module_permission($acl, "FAIclass", $this->dn);
145                         if (chkacl($this->acl, "delete") == ""){
147                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
148                                 if (($user= get_lock($this->dn)) != ""){
149                                         return(gen_locked_message ($user, $this->dn));
150                                 }
152                                 /* Lock the current entry, so nobody will edit it during deletion */
153                                 add_lock ($this->dn, $this->ui->dn);
154                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
155                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
156                         } else {
158                                 /* Obviously the user isn't allowed to delete. Show message and
159                                    clean session. */
160                                 print_red (_("You are not allowed to delete this component!"));
161                         }
162                 }
165     /****************
166       Delete aborted  
167      ****************/
169                 /* Delete canceled? */
170                 if (isset($_POST['delete_cancel'])){
171                         del_lock ($this->dn);
172                 }
175     /****************
176       Delete confirmed 
177      ****************/
179                 /* Deltetion was confirmed, so delete this entry
180                  */
181                 if (isset($_POST['delete_terminal_confirm'])){
183                         /* Some nice guy may send this as POST, so we've to check
184                            for the permissions again. */
185                         if (chkacl($this->acl, "delete") == ""){
187                                 /* Find out more about the object type */
188                                 $ldap     = $this->config->get_ldap_link();
189                                 $ldap->cat($this->dn, array('objectClass'));
190                                 $attrs  = $ldap->fetch();
191                                 $type     = $this->get_type($attrs);                    
192                                 $this->dialog = new $type[0]($this->config,     $this->config->data['TABS'][$type[2]], $this->dn);
193                                 $this->dialog->set_acl(array($this->acl));
195                                 $this->dialog->by_object[$type[1]]->remove_from_parent ();
196                                 unset ($this->dialog);
197                                 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
198                                 $this->dialog= NULL;
199         $to_del = clean_up_releases($this->dn);
200         save_release_changes_now();
202         foreach($to_del as $dn){
203           $ldap->rmdir_recursive($dn);
204           gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
205         }
207                         } else {
209                                 /* Normally this shouldn't be reached, send some extra
210                                    logs to notify the administrator */
211                                 print_red (_("You are not allowed to delete this component!"));
212                                 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
213                                                 "deletion.");
214                         }
216                         /* Remove lock file after successfull deletion */
217                         del_lock ($this->dn);
218                 }
221     /****************
222       Edit entry 
223      ****************/
225                 if(($s_action == "edit") && (!isset($this->dialog->config))){
226                         $entry    = $this->objects[$s_entry];
227                         $a_setup  = $this->get_type($entry);
228                         $this->dn = $entry['dn'];
230                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
231                         if (($user= get_lock($this->dn)) != ""){
232                                 return(gen_locked_message ($user, $this->dn));
233                         }
234                         add_lock ($this->dn, $this->ui->dn);
236                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn);
237                         $this->is_dialog  = true;
239       if($entry['FAIstate'] == "freeze"){
240         $this->dialog->set_acl(array("*none*"))  ;
241       }
242                         $_SESSION['objectinfo'] = $this->dn;
243                 }
246     /*  Branch handling 
247         09.01.2006
248     */
250     /****************
251       Remove branch
252      ****************/
254     /* Remove branch 
255      */
256     if($s_action == "remove_branch"){
257       $base= $this->DivListFai->selectedBranch;
259       /* Load permissions for selected 'dn' and check if
260          we're allowed to remove this 'dn' */
261       $acl= get_permissions ($this->DivListFai->selectedBase, $this->ui->subtreeACL);
262       $this->acl= get_module_permission($acl, "FAIclass", $base);
263       if (chkacl($this->acl, "delete") == ""){
264         $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
265         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
266       } else {
267         print_red (_("You are not allowed to delete this release!"));
268       }
269     }
271     
272     /****************
273       Remove branch confirmed
274      ****************/
276     if(isset($_POST['delete_branch_confirm'])){
277       $bb =  $this->DivListFai->selectedBranch;
278       if(!isset($ldap)){
279         $ldap = $this->config->get_ldap_link();
280       }
282       $br = $this->getBranches();
284       if(isset($br[$bb])){
285         $name = $br[$bb];
286         $ldap->cd($bb);
287         $ldap->recursive_remove();
288         $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
289         $ldap->recursive_remove();
290         $this->DivListFai->selectedBranch = "main";
292         /* Post remove */
293         $this->lock_name   = $name;
294         $this->lock_dn     = $bb;
295         $this->postremove();
296       }
297     }
300     /****************
301       Create a new branch "insert Name"
302      ****************/
304     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
305       $_SESSION['LASTPOST'] = $_POST;
307       if($this->dispNewBranch){
308         $type = "branch";
309       }else{
310         $type = "freeze";
311       }
313       /* Check branch name */
314       $name = $_POST['BranchName'];
315       $is_ok = true;
316       $smarty->assign("BranchName",$name);
317       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
319       /* Check used characters */
320       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
321         if($type == "branch"){
322           print_red(_("Specified branch name is invalid."));
323         }else{
324           print_red(_("Specified freeze name is invalid."));
325         }
326         $is_ok = false;
327       }
329       /* Check if this name is already in use */
330       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
331         print_red(_("This name is already in use."));
332         $is_ok = false;
333       }
335       if($is_ok){
336         $_SESSION['LASTPOST']['base'] = $base;
337         $_SESSION['LASTPOST']['type'] = $type;
338         $smarty->assign("iframe", true);
339         $smarty->assign("plugID", $_GET['plug']);
340         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
341         return($display);
342       }
343     }
346     /****************
347       Create a new branch 
348      ****************/
350     if(isset($_GET['PerformBranch'])){
351       /* Create it know */
352       $this->dispNewBranch = false;
353       $this->dispNewFreeze = false;
354       $base = $_SESSION['LASTPOST']['base'];
355       $_POST = $_SESSION['LASTPOST'];      
356       $name = $_POST['BranchName'];
358       $type = $_SESSION['LASTPOST']['type'];
359       $ldap = $this->config->get_ldap_link();
361       $baseToUse = $base;
362       if($this->DivListFai->selectedBranch != "main" ){
363         $baseToUse = $this->DivListFai->selectedBranch;
364       }
365   
366       /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
367       
368       $CurrentReleases  = $this->getBranches();
369       $NewReleaseName   = $name;
370       if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
371         if($this->DivListFai->selectedBranch != "main"){
372           $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
373           $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
374         }else{
375           $NewReleaseName   = $name;
376         }
377       }
379       $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
380       $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
382       $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
383       $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
385       /* Print header to have styles included */
386       echo "<!-- headers.tpl-->".$smarty->fetch(get_template_path('headers.tpl'));
387       echo "<body style='background-image:none;margin:3px;color:black'>";
389       /* Duplicate applications 
390        */
391       $ldap->cat($appsrc,array("dn")) ;
392       if($ldap->count()){
393         $ldap->cd ($appdst);
394         $ldap->recursive_remove();
395         $ldap->cd ($this->config->current['BASE']);
396         $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
397       }
398   
399       /* Duplicate mime types 
400        */
401       $ldap->cat($mimesrc,array("dn")) ;
402       if($ldap->count()){
403         $ldap->cd ($appdst);
404         $ldap->recursive_remove();
405         $ldap->cd ($this->config->current['BASE']);
406         $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
407       }
409       $attr = array();
410       $attr['objectClass'] = array("organizationalUnit","FAIbranch");
411       $attr['ou']       = $name;
412       $attr['FAIstate'] = $type;
413       $ldap->cd($this->config->current['BASE']);
414       $ldap->cd("ou=".$name.",".$baseToUse);
415       $ldap->cat("ou=".$name.",".$baseToUse);
416       if($ldap->count()){
417         $ldap->modify($attr);
418       }else{
419         $ldap->add($attr);
420       }
422       /* Duplicate fai objects 
423        */
424 //      $ldap->cd ("ou=".$name.",".$baseToUse);
425 //      $ldap->recursive_remove();
426 //      $ldap->cd ($this->config->current['BASE']);
427 //      $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
429       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
430               <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
431             </form></div>";
433       /* Print footer to have valid html */
434       echo "</body></html>";
436       $this->dispNewFreeze = false; 
438       /* Postcreate */ 
440       /* Assign possible attributes */
441       $this->lock_type  = $type; 
442       $this->lock_name  = $name; 
443       $this->lock_dn    = $baseToUse;
444       $this->postcreate();
445       exit();
446     }
449     /****************
450       Display dialog to enter new Branch name
451      ****************/
453     if(($s_action == "branch_branch")||($this->dispNewBranch)){
454       $this->dispNewBranch=true;
455       $smarty->assign("iframe",false);
456                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
457       return($display);
458     }
459    
460  
461     /****************
462       Display dialog to enter new Freeze name
463      ****************/
465     if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
466       $this->dispNewFreeze = true;
467       $smarty->assign("iframe",false);
468                   $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
469       return($display);
470     }
473     /****************
474       Create a new object 
475      ****************/
477     $types = array( "new_partition"     =>  "FAIpartitionTable",
478                     "new_script"        =>  "FAIscript",
479                     "new_hook"          =>  "FAIhook",
480                     "new_variable"      =>  "FAIvariable",
481                     "new_template"      =>  "FAItemplate",
482                     "new_package"       =>  "FAIpackageList");
484     if(isset($types[$s_action])){
485       $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
486     }
488     /* New Profile */
489     if($s_action == "new_profile"){
490       $this->dn = "new" ;
491       $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
493       $this->dialog = new $a_setup[0]($this->config,
494           $this->config->data['TABS'][$a_setup[2]],$this->dn);
495       $this->is_dialog = false;
496     }
499     /****************
500       Get from ask class name dialog 
501      ****************/
503     if($s_action == "select_class_name_finished"){
504       $this->dialog->save_object();
505       if(count($this->dialog->check())!=0){
506         foreach($this->dialog->check() as $msg){
507           print_red($msg);
508         }               
509       }else{
510         $this->dn = "new" ;
511         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
512         $name = $this->dialog->save();
514         $this->dialog = new $a_setup[0]($this->config,
515             $this->config->data['TABS'][$a_setup[2]],$this->dn,$name);
516         $this->dialog->by_object[$a_setup[1]]->cn = $name;
517         $this->is_dialog = true;
518       }         
519     }   
522     /****************
523      Cancel dialogs 
524      ****************/
526                 if(isset($_POST['edit_cancel'])){
527                         unset($this->dialog);
528                         $this->dialog=NULL;
529                         $this->is_dialog = false;
530                         unset($_SESSION['objectinfo']);
531                         del_lock ($this->dn);
532                 }
535     /****************
536       Save sub dialogs 
537      ****************/
539                 /* This check if the given tab could be saved 
540                  * If it was possible to save it, remove dialog object. 
541                  * If it wasn't possible, show errors and keep dialog.
542                  */
543                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
544                         $this->dialog->save_object();
545       $msgs= $this->dialog->check();
546                         if(count($msgs)!=0){
547                                 foreach($msgs as $msg){
548                                         print_red($msg);
549                                 }
550                         }else{
551                                 $this->dialog->save();
552         save_release_changes_now();
553         if (!isset($_POST['edit_apply'])){
554           del_lock ($this->dn);
555           unset($this->dialog);
556           $this->dialog=NULL;
557           $this->is_dialog=false;
558           unset($_SESSION['objectinfo']);
559         }
560                         }
561                 }
564     /****************
565       Display currently open dialog 
566      ****************/
568                 /* If dialog is set, but $this->is_dialog==false, then 
569                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
570                  * If is_dialog == true, we are currently editing tab objects.
571                  *  Here we need both, save and cancel
572                  */ 
574                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
575                         $display .= $this->dialog->execute();
576                         /* Don't show buttons if tab dialog requests this */
578       if(isset($this->dialog->current)){
580         $obj = $this->dialog->by_object[$this->dialog->current];
582         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
584           $display.= "<p style=\"text-align:right\">\n";
585           $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
586           $display.= "&nbsp;\n";
587           if ($this->dn != "new"){
588             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
589             $display.= "&nbsp;\n";
590           }
591           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
592           $display.= "</p>";
593         }elseif(!isset($this->dialog->current)){
594           $display.= "<p style=\"text-align:right\">\n";
595           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
596           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
597           $display.= "</p>";
598         }
599       }else{
600         $display.= "<p style=\"text-align:right\">\n";
601         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
602         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
603         $display.= "</p>";
605       }
606       return($display);
607                 }
608                 
610     /****************
611       Dialog display
612      ****************/
614     /* Check if there is a snapshot dialog open */
615     $base = $this->DivListFai->selectedBase;
616     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
617       return($str);
618     }
620     /* Display dialog with system list */
621     $this->DivListFai->parent = $this;
622     $this->DivListFai->execute();
623     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4);
624     $this->reload();
625     $this->DivListFai->setEntries($this->objects);
626     return($this->DivListFai->Draw());
627         }
630   /* Return departments, that will be included within snapshot detection */
631   function get_used_snapshot_bases()
632   {
633     $tmp = array();
634     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
635     foreach($types as $type){
636       if($this->DivListFai->selectedBranch == "main"){
637         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
638       }else{
639         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
640       }
641     }
642     return($tmp);
643   }
646   /* Get available branches for current base */
647   function getBranches($base = false,$prefix = "")
648   {
649     $ret = array("main"=>"/");
650     $ldap = $this->config->get_ldap_link();
651     if(!$base){
652       $base= $_SESSION['CurrentMainBase'];
653     }
654     $tmp = get_all_releases_from_base($base,true);
655     foreach($tmp as $dn => $name){
656       $ret[$dn]=$name;
657     }
658     return ($ret);
659   }
661   
663   /* reload list of objects */
664   function reload()
665   {
666     /* Variable initialisation */
667     $str            = "";
668     $Regex          = $this->DivListFai->Regex;
669     $this->objects  = array();
671     /* Get base */
672     $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
673     if($this->DivListFai->selectedBranch != "main"){
674       $br = $this->getBranches();
675       if(isset($br[$this->DivListFai->selectedBranch])){
676         $base = $this->DivListFai->selectedBranch;
677       }else{
678         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
679       }
680     }
682     $this->lock_type = get_release_tag(get_release_dn($base));
684     /* Get resolved release dependencies */
685     $tmp = get_all_objects_for_given_base($base,"(&(|(objectClass=FAIpartitionTable)(objectClass=FAIpackageList)(objectClass=FAIscript)
686       (objectClass=FAIvariable)(objectClass=FAIhook)(objectClass=FAIprofile)(objectClass=FAItemplate))(cn=$Regex))");
688     /* Create a new list of FAI object 
689      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
690      */
691     $ObjectTypes = array(
692         "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"),
693         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"),
694         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"),
695         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"),
696         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"),
697         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"),
698         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"));
700     /* Ge listed ldap objects */
701     $ldap = $this->config->get_ldap_link();
702     $ldap->cd($this->config->current['BASE']);
703     foreach($tmp as $entry){
705       /* Get some more informations about the object */ 
706       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
707       $object  = $ldap->fetch();
709       /* Walk through possible types */
710       foreach($ObjectTypes as $type => $rest){  
712         /* Skip all unchecked types */
713         if(! $this->DivListFai->$rest['CHKBOX']){
714           continue;
715         }
717         if(in_array($type,$object['objectClass'])){
719           /* Prepare object */
720           unset($object['objectClass']['count']);
721           if(!isset($object['description'][0])){
722             $object['description'][0]="";
723           }
725           /* Clean up object informations */
726           $obj                  = array();
727           $obj['cn']                          = $object['cn'][0];
728           $obj['dn']                          = $object['dn'];
729           $obj['description']   = $object['description'][0];
730           $obj['objectClass']   = $object['objectClass'];
732           /* Append type to this string, to be able to check if the selected 
733            * entry is of type 'freeze' or 'branch'
734            */
735           if(!isset($object['FAIstate'])){
736             $obj['FAIstate'] = $this->lock_type;
737           }else{
738             $obj['FAIstate'] = $object['FAIstate'][0]; 
739           }
741           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
742           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
743         }
744                         }
745                 }
747                 ksort($this->objects);
748                 reset ($this->objects);
749         
750                 /* use numeric index, thats a bit more secure */        
751                 $tmp0 = array();
752                 foreach($this->objects as $obj){
753                         $tmp0[]= $obj;
754                 }
755                 $this->objects = array();
756                 $this->objects = $tmp0;
757         }
759         function remove_lock()
760         {
761                 if (isset($this->dn)){
762                         del_lock ($this->dn);
763                 }
764         }
766         function get_type($array){
767                 if(in_array("FAIpartitionTable",$array['objectClass'])){
768                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
769                 }
770                 if(in_array("FAIscript",$array['objectClass'])){
771                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
772                 }
773                 if(in_array("FAItemplate",$array['objectClass'])){
774                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
775                 }
776                 if(in_array("FAIhook",$array['objectClass'])){
777                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
778                 }
779                 if(in_array("FAIvariable",$array['objectClass'])){
780                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
781                 }
782                 if(in_array("FAIprofile",$array['objectClass'])){
783                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
784                 }
785                 
786                 if(in_array("FAIpackageList",$array['objectClass'])){
787                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
788                 }
789         }
791   function CheckNewBranchName($name,$base)
792   {
793     $f = $this->DivListFai->selectedBranch;
794     if($name == ""){
795       return(false);
796     }elseif(in_array($name,$this->getBranches($f))) {
797       return(false);
798     }elseif(is_department_name_reserved($name,$base)){
799       return(false);
800     }
801     return(true);
802   }
804   function save_object()
805   {
806     $this->DivListFai->save_object();
807   }
810   /* Return plugin informations for acl handling */ 
811   function plInfo()
812   {
813     return (array( 
814           "plShortName"   => _("Management"),
815           "plDescription" => _("FAI management"),
816           "plSelfModify"  => FALSE,
817           "plDepends"     => array(),
818           "plPriority"    => 0,
819           "plSection"     => array("administration"),           
820           "plCategory"    => array("fai"=> array("description" => _("FAI"),
821                                                  "objectClass" => "FAIclass")),
822           "plProvidedAcls"=> array()));
823   }
825 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
826 ?>