Code

Added sorting to FAIscripts
[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;
59   var $start_pasting_copied_objects = FALSE;
60   var $CopyPasteHandler = FALSE;
62         /* construction/reconstruction 
63          */
64         function faiManagement ($config, $ui)
65         {
66                 /* Set defaults */
67                 $this->dn                       = "";
68                 $this->config   = $config;
69                 $this->ui                       = $ui;  
70     
71     /* Creat dialog object */
72     $this->DivListFai = new divListFai($this->config,$this);
73         }
75         function execute()
76         {
77     /* Call parent execute */
78     plugin::execute();
80     /* Initialise vars and smarty */
81                 $smarty         = get_smarty();
82                 $smarty->assign("BranchName","");
83     
84                 $display        = "";
85     $s_action   = "";
86                 $s_entry        = "";
87     
88     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
89     $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
92     /****************
93       Handle posts 
94      ****************/
96                 /* Check ImageButton posts
97                  * Create new tab ich new_xx is posted
98                  */
99     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
100                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
101                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
102                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
103                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
104                     "/edit_continue/"=>"select_class_name_finished",
105                     "/^multiple_copy_fai/" => "copy_multiple", 
106                     "/^multiple_cut_fai/" => "cut_multiple", 
107                     "/^remove_multiple_fai_objects/" => "del_multiple");
109                 foreach($_POST as $name => $value){
110       foreach($posts as $reg => $act ){
111         if(preg_match($reg,$name)){
112           $s_action = $act;
113         }
114       }
115                         if(preg_match("/^entry_edit_.*/",$name)){
116                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
117                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
118                                 $s_action = "edit";
119                         }elseif(preg_match("/^entry_delete_.*/",$name)){
120                                 $s_entry = preg_replace("/^entry_delete_/","",$name);
121                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
122         $s_action = "delete";
123       }
124     }
126                 if(isset($_GET['edit_entry'])){
127                         $s_entry = $_GET['edit_entry'];
128                         $s_action = "edit";
129                 }
130     
131     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
132       $this->dispNewBranch = false;
133       $this->dispNewFreeze = false;
134     }
137     $type_acl_mapping = array(
138         "FAIpartitionTable"  => "faiPartitionTable", 
139         "FAIpackageList"     => "faiPackage",
140         "FAIscript"          => "faiScript",
141         "FAIvariable"        => "faiVariable",
142         "FAIhook"            => "faiHook",
143         "FAIprofile"         => "faiProfile",
144         "FAItemplate"        => "faiTemplate");
146     /****************
147       Delete confirme dialog 
148      ****************/
150                 if ($s_action=="delete"){
152       /* Get 'dn' from posted termlinst */
153       $this->dn= $this->objects[$s_entry]['dn'];
155                         /* Load permissions for selected 'dn' and check if
156                            we're allowed to remove this 'dn' */
157       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
158       if(preg_match("/d/",$acl)){
160                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
161                                 if (($user= get_lock($this->dn)) != ""){
162                                         return(gen_locked_message ($user, $this->dn));
163                                 }
165                                 /* Lock the current entry, so nobody will edit it during deletion */
166                                 add_lock ($this->dn, $this->ui->dn);
167                                 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
168         $smarty->assign("multiple", false);
169                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
170                         } else {
172                                 /* Obviously the user isn't allowed to delete. Show message and
173                                    clean session. */
174                                 print_red (_("You are not allowed to delete this component!"));
175                         }
176                 }
179     /********************
180       Delete MULTIPLE entries requested, display confirm dialog
181      ********************/
183     if ($s_action=="del_multiple"){
184       $this->dns = array();
185       $ids = $this->list_get_selected_items();
187       if(count($ids)){
189         foreach($ids as $id){
190           $dn = $this->objects[$id]['dn'];
191           if (($user= get_lock($dn)) != ""){
192             return(gen_locked_message ($user, $dn));
193           }
194           $this->dns[$id] = $dn;
195         }
197         $dns_names = "<br><pre>";
198         foreach($this->dns as $dn){
199           add_lock ($dn, $this->ui->dn);
200           $dns_names .= $dn."\n";
201         }
202         $dns_names .="</pre>";
204         /* Lock the current entry, so nobody will edit it during deletion */
205         if (count($this->dns) == 1){
206           $smarty->assign("warning",     sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
207         } else {
208           $smarty->assign("warning",     sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
209         }
210         $smarty->assign("multiple", true);
211         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
212       }
213     }
216     /********************
217       Delete MULTIPLE entries confirmed
218      ********************/
220     /* Confirmation for deletion has been passed. Users should be deleted. */
221     if (isset($_POST['delete_multiple_fai_object_confirm'])){
223       /* Find out more about the object type */
224       $ldap   = $this->config->get_ldap_link();
226       /* Remove user by user and check acls before removeing them */
227       foreach($this->dns as $key => $dn){
229         $ldap->cat($dn, array('objectClass'));
230         $attrs  = $ldap->fetch();
231         $type   = $this->get_type($attrs);
233         $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
234         if(preg_match("/d/",$acl)){
236           $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
237           $this->dialog->set_acl_base($dn);
238           $this->dialog->by_object[$type[1]]->remove_from_parent ();
239           unset ($this->dialog);
240           $this->dialog= NULL;
241           $to_del = clean_up_releases($dn);
242           save_release_changes_now();
244           foreach($to_del as $dn){
245             $ldap->rmdir_recursive($dn);
246           }
248         } else {
250           /* Normally this shouldn't be reached, send some extra
251              logs to notify the administrator */
252           print_red (_("You are not allowed to delete this component!"));
253           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
254         }
256         /* Remove lock file after successfull deletion */
257         del_lock ($dn);
258         unset($this->dns[$key]);
259       }
260     }
263     /********************
264       Delete MULTIPLE entries Canceled
265      ********************/
267     /* Remove lock */
268     if(isset($_POST['delete_multiple_fai_object_cancel'])){
269       foreach($this->dns as $key => $dn){
270         del_lock ($dn);
271         unset($this->dns[$key]);
272       }
273     }
276     /****************
277       Delete aborted  
278      ****************/
280                 /* Delete canceled? */
281                 if (isset($_POST['delete_cancel'])){
282                         del_lock ($this->dn);
283                 }
286     /****************
287       Delete confirmed 
288      ****************/
290                 /* Deltetion was confirmed, so delete this entry
291      */
292     if (isset($_POST['delete_terminal_confirm'])){
294       /* Some nice guy may send this as POST, so we've to check
295          for the permissions again. */
297       /* Find out more about the object type */
298       $ldap       = $this->config->get_ldap_link();
299       $ldap->cat($this->dn, array('objectClass'));
300       if($ldap->count()){
301         $attrs  = $ldap->fetch();
302         $type     = $this->get_type($attrs);                    
304         $acl  = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
305         if(preg_match("/d/",$acl)){
307           $this->dialog = new $type[0]($this->config,   $this->config->data['TABS'][$type[2]], $this->dn,"fai");
308           $this->dialog->set_acl_base($this->dn);
309           $this->dialog->by_object[$type[1]]->remove_from_parent ();
310           unset ($this->dialog);
311           $this->dialog= NULL;
312           $to_del = clean_up_releases($this->dn);
313           save_release_changes_now();
315           foreach($to_del as $dn){
316             $ldap->rmdir_recursive($dn);
317           }
319         } else {
321           /* Normally this shouldn't be reached, send some extra
322              logs to notify the administrator */
323           print_red (_("You are not allowed to delete this component!"));
324           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
325         }
327       }else{
328         print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
329       }
330       /* Remove lock file after successfull deletion */
331       del_lock ($this->dn);
332     }
335     /****************
336       Edit entry 
337      ****************/
339                 if(($s_action == "edit") && (!isset($this->dialog->config))){
340                         $entry    = $this->objects[$s_entry];
341                         $a_setup  = $this->get_type($entry);
342                         $this->dn = $entry['dn'];
344                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
345                         if (($user= get_lock($this->dn)) != ""){
346                                 return(gen_locked_message ($user, $this->dn));
347                         }
348                         add_lock ($this->dn, $this->ui->dn);
350                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
351       $this->dialog->set_acl_base($this->dn);
352                         $this->is_dialog  = true;
354       if($entry['FAIstate'] == "freeze"){
355         #$this->dialog->set_acl(array("*none*"))  ;    
356         echo "Dawn it is freezed.";
357       }
358                         $_SESSION['objectinfo'] = $this->dn;
359                 }
362     /*  Branch handling 
363         09.01.2006
364     */
366     /****************
367       Remove branch
368      ****************/
370     /* Remove branch 
371      */
372     if($s_action == "remove_branch"){
373       $base= $this->DivListFai->selectedBranch;
375       /* Check if we have a post remove method configured
376        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
377        */
378       if("" != search_config($this->config->data,"faiManagement","POSTREMOVE")){
380         /* Load permissions for selected 'dn' and check if
381            we're allowed to remove this 'dn' */
382         $this->set_acl_base($base);
383         if($this->acl_is_removeable()){
385           $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze  '%s'."), $this->DivListFai->selectedBranch));
386           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
387         } else {
388           print_red (_("You are not allowed to delete this release!"));
389         }
390       }
391     }
393     
394     /****************
395       Remove branch confirmed
396      ****************/
398     if(isset($_POST['delete_branch_confirm'])){
400       /* Check if we have a post remove method configured
401        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
402        */
403       if("" != search_config($this->config->data,"faiManagement","POSTREMOVE")){
405         $bb =  $this->DivListFai->selectedBranch;
406         if(!isset($ldap)){
407           $ldap = $this->config->get_ldap_link();
408         }
410         $br = $this->getBranches();
412         if(isset($br[$bb]) && $this->acl_is_removeable()){
413           $name = $br[$bb];
414           $ldap->cd($bb);
415           $ldap->recursive_remove();
416           $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
417           $ldap->recursive_remove();
418           $this->DivListFai->selectedBranch = "main";
420           /* Post remove */
421           $this->lock_name   = $name;
422           $this->lock_dn     = $bb;
423           $this->postremove();
425           new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
426         }
427       }
428     }
431     /****************
432       Create a new branch "insert Name"
433      ****************/
435     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
436       $_SESSION['LASTPOST'] = $_POST;
438       if($this->dispNewBranch){
439         $type = "branch";
440       }else{
441         $type = "freeze";
442       }
444       /* Check branch name */
445       $name = $_POST['BranchName'];
446       $is_ok = true;
447       $smarty->assign("BranchName",$name);
448       $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
450       /* Check used characters */
451       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
452         if($type == "branch"){
453           print_red(_("Specified branch name is invalid."));
454         }else{
455           print_red(_("Specified freeze name is invalid."));
456         }
457         $is_ok = false;
458       }
460       /* Check if this name is already in use */
461       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
462         print_red(_("This name is already in use."));
463         $is_ok = false;
464       }
466       if($is_ok){
467         $_SESSION['LASTPOST']['base'] = $base;
468         $_SESSION['LASTPOST']['type'] = $type;
469         $smarty->assign("iframe", true);
470         $smarty->assign("plugID", $_GET['plug']);
471         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
472         return($display);
473       }
474     }
477     /****************
478       Create a new branch 
479      ****************/
481     if(isset($_GET['PerformBranch'])){
483       if(!$this->acl_is_createable()){
484         print_red(_("You are not allowed to create a new branch."));
485       }else{
487         /* Create it know */
488         $this->dispNewBranch = false;
489         $this->dispNewFreeze = false;
490         $base = $_SESSION['LASTPOST']['base'];
491         $_POST = $_SESSION['LASTPOST'];      
492         $name = $_POST['BranchName'];
494         $type = $_SESSION['LASTPOST']['type'];
495         $ldap = $this->config->get_ldap_link();
497         $baseToUse = $base;
498         if($this->DivListFai->selectedBranch != "main" ){
499           $baseToUse = $this->DivListFai->selectedBranch;
500         }
502         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
504         $CurrentReleases  = $this->getBranches();
505         $NewReleaseName   = $name;
506         if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
507           if($this->DivListFai->selectedBranch != "main"){
508             $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
509             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
510           }else{
511             $NewReleaseName   = $name;
512           }
513         }
515         $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse); 
516         $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ; 
518         $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse); 
519         $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ; 
521         /* Print header to have styles included */
522         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
523           <html>
524           <head>
525           <title></title>
526           <style type="text/css">@import url("themes/default/style.css");</style>
527           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
528           </head>
529           <body style="background: none;margin:3px;color:black">
530           ';
532         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
534         /* Duplicate applications 
535          */
536         $ldap->cat($appsrc,array("dn")) ;
537         if($ldap->count()){
538           $ldap->cd ($appdst);
539           $ldap->recursive_remove();
540           $ldap->cd ($this->config->current['BASE']);
541           $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
542         }
544         /* Duplicate mime types 
545          */
546         $ldap->cat($mimesrc,array("dn")) ;
547         if($ldap->count()){
548           $ldap->cd ($mimedst);
549           $ldap->recursive_remove();
550           $ldap->cd ($this->config->current['BASE']);
551           $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
552         }
554         $attr = array();
555         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
556         $attr['ou']       = $name;
557         $attr['FAIstate'] = $type;
558         $ldap->cd($this->config->current['BASE']);
559         $ldap->cd("ou=".$name.",".$baseToUse);
560         $ldap->cat("ou=".$name.",".$baseToUse);
561         if($ldap->count()){
562           $ldap->modify($attr);
563         }else{
564           $ldap->add($attr);
565         }
567         /* Duplicate fai objects 
568          */
569         //      $ldap->cd ("ou=".$name.",".$baseToUse);
570         //      $ldap->recursive_remove();
571         //      $ldap->cd ($this->config->current['BASE']);
572         //      $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
574         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
575           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
576           </form></div>";
578         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
580         /* Print footer to have valid html */
581         echo "</body></html>";
583         $this->dispNewFreeze = false; 
585         /* Postcreate */ 
587         /* Assign possible attributes */
588         $this->lock_type  = $type; 
589         $this->lock_name  = $name; 
590         $this->lock_dn    = $baseToUse;
591         $this->postcreate();
592         exit();
593       }
594     }
596     /****************
597       Display dialog to enter new Branch name
598      ****************/
600     /* Check if we have a post create method configured
601      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
602      */
603     if("" != search_config($this->config->data,"faiManagement","POSTCREATE")){
604       if(($s_action == "branch_branch")||($this->dispNewBranch)){
605         $this->dispNewBranch=true;
606         $smarty->assign("iframe",false);
607         $display        .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
608         return($display);
609       } 
610     }
612  
613     /****************
614       Display dialog to enter new Freeze name
615      ****************/
617     /* Check if we have a post create method configured
618      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
619      */
620     if("" != search_config($this->config->data,"faiManagement","POSTCREATE")){
621       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
622         $this->dispNewFreeze = true;
623         $smarty->assign("iframe",false);
624         $display        .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
625         return($display);
626       }
627     }
630     /****************
631       Create a new object 
632      ****************/
634     $types = array( "new_partition"     =>  "FAIpartitionTable",
635                     "new_script"        =>  "FAIscript",
636                     "new_hook"          =>  "FAIhook",
637                     "new_variable"      =>  "FAIvariable",
638                     "new_template"      =>  "FAItemplate",
639                     "new_package"       =>  "FAIpackageList");
641     if(isset($types[$s_action])){
642       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
643       if(preg_match("/c/",$acl)){
644         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
645       }else{
646         print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
647       }
648     }
650     /* New Profile */
651     if($s_action == "new_profile"){
652       $this->dn = "new" ;
654       $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
655       if(preg_match("/c/",$acl)){
656         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
657         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
658         $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
660         $this->is_dialog = false;
661       }else{
662         print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
663       }
664     }
667     /****************
668       Get from ask class name dialog 
669      ****************/
671     if($s_action == "select_class_name_finished"){
672       $this->dialog->save_object();
673       if(count($this->dialog->check())!=0){
674         foreach($this->dialog->check() as $msg){
675           print_red($msg);
676         }               
677       }else{
678         $this->dn = "new" ;
679         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
680         $name = $this->dialog->save();
682         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
683         $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
684         $this->dialog->by_object[$a_setup[1]]->cn = $name;
685         $this->is_dialog = true;
686       }         
687     }   
690     /****************
691      Cancel dialogs 
692      ****************/
694                 if(isset($_POST['edit_cancel'])){
695                         unset($this->dialog);
696                         $this->dialog=NULL;
697                         $this->is_dialog = false;
698                         unset($_SESSION['objectinfo']);
699                         del_lock ($this->dn);
700                 }
703     /****************
704       Save sub dialogs 
705      ****************/
707                 /* This check if the given tab could be saved 
708                  * If it was possible to save it, remove dialog object. 
709                  * If it wasn't possible, show errors and keep dialog.
710                  */
711                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
712                         $this->dialog->save_object();
713       $msgs= $this->dialog->check();
714                         if(count($msgs)!=0){
715                                 foreach($msgs as $msg){
716                                         print_red($msg);
717                                 }
718                         }else{
719                                 $this->dialog->save();
720         save_release_changes_now();
721         if (!isset($_POST['edit_apply'])){
722           del_lock ($this->dn);
723           unset($this->dialog);
724           $this->dialog=NULL;
725           $this->is_dialog=false;
726           unset($_SESSION['objectinfo']);
727         }
728                         }
729                 }
732     /****************
733       Display currently open dialog 
734      ****************/
736                 /* If dialog is set, but $this->is_dialog==false, then 
737                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
738                  * If is_dialog == true, we are currently editing tab objects.
739                  *  Here we need both, save and cancel
740                  */ 
742                 if(($this->dialog != NULL) && (isset($this->dialog->config))){
743                         $display .= $this->dialog->execute();
744                         /* Don't show buttons if tab dialog requests this */
746       if(isset($this->dialog->current)){
748         $obj = $this->dialog->by_object[$this->dialog->current];
750         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
752           $display.= "<p style=\"text-align:right\">\n";
753           $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
754           $display.= "&nbsp;\n";
755           if ($this->dn != "new"){
756             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
757             $display.= "&nbsp;\n";
758           }
759           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
760           $display.= "</p>";
761         }elseif(!isset($this->dialog->current)){
762           $display.= "<p style=\"text-align:right\">\n";
763           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
764           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
765           $display.= "</p>";
766         }
767       }else{
768         $display.= "<p style=\"text-align:right\">\n";
769         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
770         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
771         $display.= "</p>";
773       }
774       return($display);
775                 }
776                 
778     /****************
779       Dialog display
780      ****************/
782     /* Check if there is a snapshot dialog open */
783     $base = $this->DivListFai->selectedBase;
784     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
785       return($str);
786     }
788     /* Display dialog with system list */
789     $this->DivListFai->parent = $this;
790     $this->DivListFai->execute();
791     $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
792     $this->reload();
793     $this->DivListFai->setEntries($this->objects);
794     return($this->DivListFai->Draw());
795         }
798   /* Return departments, that will be included within snapshot detection */
799   function get_used_snapshot_bases()
800   {
801     $tmp = array();
802     $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
803     foreach($types as $type){
804       if($this->DivListFai->selectedBranch == "main"){
805         $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
806       }else{
807         $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
808       }
809     }
810     return($tmp);
811   }
814   /* Get available branches for current base */
815   function getBranches($base = false,$prefix = "")
816   {
817     $ret = array("main"=>"/");
818     $ldap = $this->config->get_ldap_link();
819     if(!$base){
820       $base= $_SESSION['CurrentMainBase'];
821     }
822     $tmp = get_all_releases_from_base($base,true);
823     foreach($tmp as $dn => $name){
824       $ret[$dn]=$name;
825     }
826     return ($ret);
827   }
828   
830   function list_get_selected_items()
831   {
832     $ids = array();
833     foreach($_POST as $name => $value){
834       if(preg_match("/^item_selected_[0-9]*$/",$name)){
835         $id   = preg_replace("/^item_selected_/","",$name);
836         $ids[$id] = $id;
837       }
838     }
839     return($ids);
840   }
843   /* reload list of objects */
844   function reload()
845   {
846     /* Variable initialisation */
847     $str            = "";
848     $Regex          = $this->DivListFai->Regex;
849     $this->objects  = array();
851     /* Get base */
852     $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
853     if($this->DivListFai->selectedBranch != "main"){
854       $br = $this->getBranches();
855       if(isset($br[$this->DivListFai->selectedBranch])){
856         $base = $this->DivListFai->selectedBranch;
857       }else{
858         $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
859       }
860     }
862     $this->lock_type = get_release_tag(get_release_dn($base));
864     /* Create a new list of FAI object 
865      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
866      */
867     $ObjectTypes = array(
868         "FAIpartitionTable"  => array("OU"=>"ou=disk,"        , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
869         "FAIpackageList"     => array("OU"=>"ou=packages,"    , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
870         "FAIscript"          => array("OU"=>"ou=scripts,"     , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
871         "FAIvariable"        => array("OU"=>"ou=variables,"   , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
872         "FAIhook"            => array("OU"=>"ou=hooks,"       , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
873         "FAIprofile"         => array("OU"=>"ou=profiles,"    , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
874         "FAItemplate"        => array("OU"=>"ou=templates,"   , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
876     $filter = "";
877     foreach($ObjectTypes as $key => $data){
878       if($this->DivListFai->$data['CHKBOX']){
879         $filter.= "(objectClass=".$key.")";
880       }
881     }
882     $filter = "(&(|".$filter.")(cn=$Regex))";
883     
884     /* Get resolved release dependencies */
885     $tmp = get_all_objects_for_given_base($base,$filter);
887     /* Ge listed ldap objects */
888     $ldap = $this->config->get_ldap_link();
889     $ldap->cd($this->config->current['BASE']);
890     foreach($tmp as $entry){
892       /* Get some more informations about the object */ 
893       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
894       $object  = $ldap->fetch();
896       /* Walk through possible types */
897       foreach($ObjectTypes as $type => $rest){  
899         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
901         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
903           /* Prepare object */
904           unset($object['objectClass']['count']);
905           if(!isset($object['description'][0])){
906             $object['description'][0]="";
907           }
909           /* Clean up object informations */
910           $obj                  = array();
911           $obj['cn']                          = $object['cn'][0];
912           $obj['dn']                          = $object['dn'];
913           $obj['acl']                       = $acl;
914           $obj['description']   = $object['description'][0];
915           $obj['objectClass']   = $object['objectClass'];
917           /* Append type to this string, to be able to check if the selected 
918            * entry is of type 'freeze' or 'branch'
919            */
920           if(!isset($object['FAIstate'])){
921             $obj['FAIstate'] = $this->lock_type;
922           }else{
923             $obj['FAIstate'] = $object['FAIstate'][0]; 
924           }
926           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
927           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
928         }
929                         }
930                 }
932                 ksort($this->objects);
933                 reset ($this->objects);
934         
935                 /* use numeric index, thats a bit more secure */        
936                 $tmp0 = array();
937                 foreach($this->objects as $obj){
938                         $tmp0[]= $obj;
939                 }
940                 $this->objects = array();
941                 $this->objects = $tmp0;
942         }
944         function remove_lock()
945         {
946                 if (isset($this->dn)){
947                         del_lock ($this->dn);
948                 }
949         }
951         function get_type($array){
952                 if(in_array("FAIpartitionTable",$array['objectClass'])){
953                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
954                 }
955                 if(in_array("FAIscript",$array['objectClass'])){
956                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
957                 }
958                 if(in_array("FAItemplate",$array['objectClass'])){
959                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
960                 }
961                 if(in_array("FAIhook",$array['objectClass'])){
962                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
963                 }
964                 if(in_array("FAIvariable",$array['objectClass'])){
965                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
966                 }
967                 if(in_array("FAIprofile",$array['objectClass'])){
968                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
969                 }
970                 
971                 if(in_array("FAIpackageList",$array['objectClass'])){
972                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
973                 }
974         }
976   function CheckNewBranchName($name,$base)
977   {
978     $f = $this->DivListFai->selectedBranch;
979     if($name == ""){
980       return(false);
981     }elseif(in_array($name,$this->getBranches($f))) {
982       return(false);
983     }elseif(is_department_name_reserved($name,$base)){
984       return(false);
985     }
986     return(true);
987   }
989   function save_object()
990   {
991     $this->DivListFai->save_object();
992   }
995   /* Return plugin informations for acl handling */ 
996   function plInfo()
997   {
998     return (array( 
999           "plShortName"   => _("FAI releases"),
1000           "plDescription" => _("FAI release management"),
1001           "plSelfModify"  => FALSE,
1002           "plDepends"     => array(),
1003           "plPriority"    => 0,
1004           "plSection"     => array("administration"),           
1005           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1006                                                  "objectClass" => "FAIclass")),
1007           "plProvidedAcls"=> array()));
1008   }
1010 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1011 ?>