Code

Mo-Mo-Mo-Monster Diff - Removed Department selection from managment list and all...
[gosa.git] / gosa-plugins / fai / 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  */
22 class faiManagement extends plugin
23 {
24         /* Definitions */
25   var $plHeadline     = "Software deployment";
26   var $plDescription    = "Manage software packages and deployment reciepes";
28         /* Headpage attributes */
29   var $lock_type    = "";    // should be branch/freeze
30   var $lock_name    = "";
31   var $lock_dn      = "";  
33         /* attribute list for save action */
34         var $attributes         = array("lock_type","lock_name","lock_dn");     //      Attributes Managed by this plugin 
35         var $objectclasses= array();    //      ObjectClasses which the attributes are related to
36         var $dialog                             = array();      //      This object contains every dialog we have currently opened
38         var $objects                    = array();      //      This array contains all available objects shown in divlist
39         var $is_dialog          = false;
41   var $dispNewBranch= false;
42   var $dispNewFreeze= false;
44   var $DivListFai;
45   var $start_pasting_copied_objects = FALSE;
46   var $CopyPasteHandler = FALSE;
48   /* Allow inserting of new elements if freezed releases 
49   */
50   var $allow_freeze_object_attach = FALSE;
52   var $no_save;
53   var $fai_base     ="";
54   var $fai_release  ="";
56         /* construction/reconstruction 
57          */
58         function faiManagement (&$config, $ui)
59         {
60                 /* Set defaults */
61                 $this->dn                       = "";
62                 $this->config   = $config;
63                 $this->ui                       = $ui;  
64     
65     /* Creat dialog object */
66     $this->DivListFai = new divListFai($this->config,$this);
68     /* Copy & Paste handler */
69     if ($this->config->boolValueIsTrue($this->fai_base, "enableCopyPaste")){
70       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
71     }
73     /* Set default release */
74     $this->fai_base = get_ou("faiou")."ou=Direktorium,".$this->config->current['BASE'];
75     if(!session::is_set("fai_filter")){
76       session::set("fai_filter",array("fai_release" => $this->fai_base));
77     }
79     $fai_filter = session::get("fai_filter");
80     $this->fai_release = $fai_filter['fai_release'];
81         }
83         function execute()
84         {
85     /* Call parent execute */
86     plugin::execute();
88     print_a(array($this->fai_base,$this->fai_release));
90     /* Initialise vars and smarty */
91                 $smarty         = get_smarty();
92                 $smarty->assign("BranchName","");
93     
94                 $display        = "";
95     $s_action   = "";
96                 $s_entry        = "";
97     $no_save = FALSE;   // hide Apply / Save buttons
98     
99     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
100     session::set('LOCK_VARS_TO_USE',array("/^edit_freeze_entry$/","/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/"));
103     /****************
104       Handle posts 
105      ****************/
107                 /* Check ImageButton posts
108                  * Create new tab ich new_xx is posted
109                  */
110     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
111                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
112                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
113                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
114                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
115                     "/edit_continue/"=>"select_class_name_finished",
116                     "/^multiple_copy_fai/" => "copy_multiple", 
117                     "/^multiple_cut_fai/" => "cut_multiple", 
118                     "/^copy/" => "copy",
119                     "/^cut/" => "cut",
120                     "/^remove_multiple_fai_objects/" => "del_multiple");
122                 foreach($_POST as $name => $value){
123       foreach($posts as $reg => $act ){
124         if(preg_match($reg,$name)){
125           $s_action = $act;
126           $s_entry = ltrim(preg_replace($reg,"",$name),"_");
127           $s_entry = preg_replace("/_.*$/","",$s_entry);
128         }
129       }
130                         if(preg_match("/^entry_edit_.*/",$name)){
131                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
132                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
133                                 $s_action = "edit";
134                         }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
135                                 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
136                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
137                                 $s_action = "edit";
138         $no_save = TRUE;
139                         }elseif(preg_match("/^entry_delete_.*/",$name)){
140                                 $s_entry = preg_replace("/^entry_delete_/","",$name);
141                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
142         $s_action = "delete";
143       }
144     }
146                 if(isset($_GET['edit_entry'])){
147                         $s_entry = $_GET['edit_entry'];
148                         $s_action = "edit";
149                 }
151                 if(isset($_GET['edit_freeze_entry'])){
152                         $s_entry = $_GET['edit_freeze_entry'];
153                         $s_action = "edit";
154       $no_save = TRUE;
155                 }
157     if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
158       $s_action = "freeze_branch";
159     }
160     if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
161       $s_action = "branch_branch";
162     }
163     if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
164       $s_action = "remove_branch";
165     }
166     
167     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
168       $this->dispNewBranch = false;
169       $this->dispNewFreeze = false;
170     }
173     $type_acl_mapping = array(
174         "FAIpartitionTable"  => "faiPartitionTable", 
175         "FAIpackageList"     => "faiPackage",
176         "FAIscript"          => "faiScript",
177         "FAIvariable"        => "faiVariable",
178         "FAIhook"            => "faiHook",
179         "FAIprofile"         => "faiProfile",
180         "FAItemplate"        => "faiTemplate");
183     /* handle C&P from layers menu */
184     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
185       $s_action = "copy_multiple";
186     }
187     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
188       $s_action = "cut_multiple";
189     }
190     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
191       $s_action = "editPaste";
192     }
194     /* Create options */
195     if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
196       $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
197       $s_entry  = preg_replace("/^Create_/","",$_POST['menu_action']);
198     }
200     /* handle remove from layers menu */
201     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
202       $s_action = "del_multiple";
203     }
206     if(!empty($s_action)){
207       $this->no_save = $no_save;
208     }
210     /********************
211       Copy & Paste
212      ********************/
214     /* Display the copy & paste dialog, if it is currently open */
215     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
216     if($ret){
217       return($ret);
218     }
221     /****************
222       Delete confirme dialog 
223      ****************/
225                 if ($s_action=="delete"){
227       /* Get 'dn' from posted termlinst */
228       $this->dn= $this->objects[$s_entry]['dn'];
230                         /* Load permissions for selected 'dn' and check if
231                            we're allowed to remove this 'dn' */
232       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
233       if(preg_match("/d/",$acl)){
235                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
236                                 if (($user= get_lock($this->dn)) != ""){
237                                         return(gen_locked_message ($user, $this->dn));
238                                 }
240                                 /* Lock the current entry, so nobody will edit it during deletion */
241                                 add_lock ($this->dn, $this->ui->dn);
242                                 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
243         $smarty->assign("multiple", false);
244                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
245                         } else {
247                                 /* Obviously the user isn't allowed to delete. Show message and clean session. */
248         msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
249                         }
250                 }
253     /********************
254       Delete MULTIPLE entries requested, display confirm dialog
255      ********************/
257     if ($s_action=="del_multiple"){
258       $this->dns = array();
259       $ids = $this->list_get_selected_items();
261       if(count($ids)){
263         $errors = "";
264         foreach($ids as $id){
265           $dn = $this->objects[$id]['dn'];
266           $cn = $this->objects[$id]['cn'];
267           if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
268             $this->dns[$id] = $dn;
269           }else{
270             $errors .= $cn.", ";
271           }
272         }
273         if ($user= get_multiple_locks($this->dns)){
274           return(gen_locked_message($user,$this->dns));
275         }
277         if($errors != ""){
278           msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
279             "<br><br>".trim($errors,", ")),INFO_DIALOG);
280         }
282         if(count($this->dns)){
284           $dns_names = array();
285           foreach($this->dns as $dn){
286             add_lock ($dn, $this->ui->dn);
287             $dns_names[] = @LDAP::fix($dn);
288           }
290           /* Lock the current entry, so nobody will edit it during deletion */
291                                   $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
292           $smarty->assign("multiple", true);
293           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
294         }
295       }
296     }
299     /********************
300       Delete MULTIPLE entries confirmed
301      ********************/
303     /* Confirmation for deletion has been passed. Users should be deleted. */
304     if (isset($_POST['delete_multiple_fai_object_confirm'])){
306       /* Find out more about the object type */
307       $ldap   = $this->config->get_ldap_link();
309       /* Remove user by user and check acls before removeing them */
310       foreach($this->dns as $key => $dn){
312         $ldap->cat($dn, array('objectClass'));
313         $attrs  = $ldap->fetch();
314         $type   = $this->get_type($attrs);
316         $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
317         if(preg_match("/d/",$acl)){
319           $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
320           $this->dialog->parent = &$this;
321           $this->dialog->set_acl_base($dn);
322           $this->dialog->by_object[$type[1]]->remove_from_parent ();
323           unset ($this->dialog);
324           $this->dialog= FALSE;
325           $to_del = FAI::clean_up_releases($dn);
326           FAI::save_release_changes_now();
328           foreach($to_del as $dn){
329             $ldap->rmdir_recursive($dn);
330           }
332         } else {
334           /* Normally this shouldn't be reached, send some extra
335              logs to notify the administrator */
336           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
337           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
338         }
340         /* Remove lock file after successfull deletion */
341         del_lock ($dn);
342         unset($this->dns[$key]);
343       }
344     }
347     /********************
348       Delete MULTIPLE entries Canceled
349      ********************/
351     /* Remove lock */
352     if(isset($_POST['delete_multiple_fai_object_cancel'])){
353       foreach($this->dns as $key => $dn){
354         del_lock ($dn);
355         unset($this->dns[$key]);
356       }
357     }
360     /****************
361       Delete aborted  
362      ****************/
364                 /* Delete canceled? */
365                 if (isset($_POST['delete_cancel'])){
366                         del_lock ($this->dn);
367                 }
370     /****************
371       Delete confirmed 
372      ****************/
374                 /* Deltetion was confirmed, so delete this entry
375      */
376     if (isset($_POST['delete_terminal_confirm'])){
378       /* Some nice guy may send this as POST, so we've to check
379          for the permissions again. */
381       /* Find out more about the object type */
382       $ldap       = $this->config->get_ldap_link();
383       $ldap->cat($this->dn, array('objectClass'));
384       if($ldap->count()){
385         $attrs  = $ldap->fetch();
386         $type     = $this->get_type($attrs);                    
388         $acl  = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
389         if(preg_match("/d/",$acl)){
391           $this->dialog = new $type[0]($this->config,   $this->config->data['TABS'][$type[2]], $this->dn,"fai");
392           $this->dialog->set_acl_base($this->dn);
393           $this->dialog->parent = &$this;
394           $this->dialog->by_object[$type[1]]->remove_from_parent ();
395           unset ($this->dialog);
396           $this->dialog= FALSE;
397           $to_del = FAI::clean_up_releases($this->dn);
398           FAI::save_release_changes_now();
400           foreach($to_del as $dn){
401             $ldap->rmdir_recursive($dn);
402           }
404         } else {
406           /* Normally this shouldn't be reached, send some extra
407              logs to notify the administrator */
408           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
409           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
410         }
412       }else{
413         msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
414       }
415       /* Remove lock file after successfull deletion */
416       del_lock ($this->dn);
417     }
420     /****************
421       Edit entry 
422      ****************/
424                 if(($s_action == "edit") && (!isset($this->dialog->config))){
425                         $entry    = $this->objects[$s_entry];
426                         $a_setup  = $this->get_type($entry);
427                         $this->dn = $entry['dn'];
429                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
430                         if (($user= get_lock($this->dn)) != ""){
431                                 return(gen_locked_message ($user, $this->dn));
432                         }
433                         add_lock ($this->dn, $this->ui->dn);
435                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
436       $this->dialog->parent = &$this;
437       $this->dialog->set_acl_base($this->dn);
438                         $this->is_dialog  = true;
440       if(preg_match("/^freeze/", $entry['FAIstate']) || $this->no_save){
441 #        $this->dialog->set_acl_base("freezed")  ;    
442       }
443                         session::set('objectinfo',$this->dn);
444                 }
447     /*  Branch handling 
448         09.01.2006
449     */
451     /****************
452       Remove branch
453      ****************/
455     /* Remove branch 
456      */
457     if($s_action == "remove_branch"){
458       $base= $this->fai_release;
460       /* Check if we have a post remove method configured
461        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
462        */
463       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
464         /* Load permissions for selected 'dn' and check if
465            we're allowed to remove this 'dn' */
466         if($this->acl_is_removeable()){
468           $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
469           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
470         } else {
471           msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
472         }
473       }
474     }
476     
477     /****************
478       Remove branch confirmed
479      ****************/
481     if(isset($_POST['delete_branch_confirm'])){
483       /* Check if we have a post remove method configured
484        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
485        */
486       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
488         $bb =  $this->fai_release;
489         if(!isset($ldap)){
490           $ldap = $this->config->get_ldap_link();
491         }
493         $br = $this->getBranches();
495         if(isset($br[$bb]) && $this->acl_is_removeable()){
496           $name = $br[$bb];
497           $ldap->cd($bb);
498           $ldap->recursive_remove();
499           $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
500           $ldap->recursive_remove();
501           $this->fai_release = $this->fai_base;
503           /* Post remove */
504           $this->lock_name   = $name;
505           $this->lock_dn     = $bb;
506           $this->postremove();
508           new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
509         }
510       }
511     }
514     /****************
515       Create a new branch "insert Name"
516      ****************/
518     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
519       session::set('LASTPOST',$_POST);
521       if($this->dispNewBranch){
522         $type = "branch";
523       }else{
524         $type = "freeze";
525       }
527       /* Check branch name */
528       $name = $_POST['BranchName'];
529       $is_ok = true;
530       $smarty->assign("BranchName",$name);
531       $base= $this->fai_base;
533       /* Check used characters */
534       if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
535         msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z \ö\ä\ü\.-_:,]/i"), ERROR_DIALOG);
536         $is_ok = false;
537       }
539       /* Check if this name is already in use */
540       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
541         msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
542         $is_ok = false;
543       }
545       if($is_ok){
547         if(session::is_set('LASTPOST')){
548           $LASTPOST = session::get('LASTPOST');
549         }else{
550           $LASTPOST = array();
551         }
552         $LASTPOST['base'] = $base;
553         $LASTPOST['type'] = $type;
554         session::set('LASTPOST',$LASTPOST);
555         $smarty->assign("iframe", true);
556         $smarty->assign("plugID", $_GET['plug']);
557         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
558         return($display);
559       }
560     }
563     /****************
564       Create a new branch 
565      ****************/
567     if(isset($_GET['PerformBranch'])){
568     
569       if(!$this->acl_is_createable()){
570         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
571       }else{
573         /* Create it know */
574         $this->dispNewBranch = false;
575         $this->dispNewFreeze = false;
577         $LASTPOST = session::get('LASTPOST');
578         $base = $LASTPOST['base'];
579         $_POST  = session::get('LASTPOST');      
580         $name = $_POST['BranchName'];
582         $type = $LASTPOST['type'];
583         $ldap = $this->config->get_ldap_link();
585         $baseToUse = $base;
586         if($this->fai_release !=  $this->fai_base){
587           $baseToUse = $this->fai_release;
588         }
590         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
592         $CurrentReleases  = $this->getBranches();
593         $NewReleaseName   = $name;
594         if(isset($CurrentReleases[$this->fai_release])) {
595           if($this->fai_release != $this->fai_base){
596             $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
597             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
598           }else{
599             $NewReleaseName   = $name;
600           }
601         }
603         $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse); 
604         $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ; 
606         $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse); 
607         $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ; 
609         /* Check if source depeartments exist */
610         foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
611           $ldap->cd($this->config->current['BASE']);
612           $ldap->cat($dep);
613           if(!$ldap->count()){
614             $ldap->create_missing_trees($dep);
615           }
616         }
618         /* Print header to have styles included */
619         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
620           <html>
621           <head>
622           <title></title>
623           <style type="text/css">@import url("themes/default/style.css");</style>
624           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
625           </head>
626           <body style="background: none;margin:3px;color:black">
627           ';
629         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
631         /* Duplicate group application releases 
632          */
633         FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
635         /* Duplicate applications 
636          */
637         $ldap->cat($appsrc,array("dn")) ;
638         if($ldap->count()){
639           $ldap->cd ($appdst);
640           $ldap->recursive_remove();
641           FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
642         }
644         /* Duplicate mime types 
645          */
646         $ldap->cat($mimesrc,array("dn")) ;
647         if($ldap->count()){
648           $ldap->cd ($mimedst);
649           $ldap->recursive_remove();
650           FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
651         }
653         $attr = array();
654         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
655         $attr['ou']       = $name;
656         $attr['FAIstate'] = $type;
657         $ldap->cd($this->config->current['BASE']);
658         $ldap->cd("ou=".$name.",".$baseToUse);
659         $ldap->cat("ou=".$name.",".$baseToUse);
660         if($ldap->count()){
661           $ldap->modify($attr);
662         }else{
663           $ldap->add($attr);
664         }
666         /* Duplicate fai objects 
667          */
668         //      $ldap->cd ("ou=".$name.",".$baseToUse);
669         //      $ldap->recursive_remove();
670         //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
672         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
673           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
674           </form></div>";
676         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
678         /* Print footer to have valid html */
679         echo "</body></html>";
681         $this->dispNewFreeze = false; 
683         /* Postcreate */ 
685         /* Assign possible attributes */
686         $this->lock_type  = $type; 
687         $this->lock_name  = $name; 
688         $this->lock_dn    = $baseToUse;
689         $this->postcreate();
690         exit();
691       }
692     }
694     /****************
695       Display dialog to enter new Branch name
696      ****************/
698     /* Check if we have a post create method configured
699      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
700      */
701     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
702       if(($s_action == "branch_branch")||($this->dispNewBranch)){
703         if(!$this->acl_is_createable()){
704         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
705         }else{
706           $this->dispNewBranch=true;
707           $smarty->assign("iframe",false);
708           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
709           return($display);
710         }
711       } 
712     }
714  
715     /****************
716       Display dialog to enter new Freeze name
717      ****************/
719     /* Check if we have a post create method configured
720      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
721      */
722     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
723       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
724         if(!$this->acl_is_createable()){
725         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
726         }else{
727           $this->dispNewFreeze = true;
728           $smarty->assign("iframe",false);
729           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
730           return($display);
731         }
732       }
733     }
736     /****************
737       Create a new object 
738      ****************/
740     $types = array( "new_partition"     =>  "FAIpartitionTable",
741                     "new_script"        =>  "FAIscript",
742                     "new_hook"          =>  "FAIhook",
743                     "new_variable"      =>  "FAIvariable",
744                     "new_template"      =>  "FAItemplate",
745                     "new_package"       =>  "FAIpackageList");
746     $types_i18n = array( "new_partition"     =>  _("partition table"),
747                     "new_script"        =>  _("script"),
748                     "new_hook"          =>  _("hook"),
749                     "new_variable"      =>  _("variable"),
750                     "new_template"      =>  _("template"),
751                     "new_package"       =>  _("package list"));
753     if(isset($types[$s_action])){
754       $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
755       if(preg_match("/c/",$acl)){
756         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
757         $this->dialog->parent = &$this;
758       }else{
759         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
760       }
761     }
763     /* New Profile */
764     if($s_action == "new_profile"){
765       $this->dn = "new" ;
767       $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
768       if(preg_match("/c/",$acl)){
769         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
770         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
771         $this->dialog->set_acl_base($this->base);
772         $this->dialog->parent = &$this;
774         $this->is_dialog = false;
775       }else{
776         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
777       }
778     }
781     /****************
782       Get from ask class name dialog 
783      ****************/
785     if($s_action == "select_class_name_finished"){
786       $this->dialog->save_object();
787       if(count($this->dialog->check())!=0){
788         foreach($this->dialog->check() as $msg){
789           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
790         }               
791       }elseif(isset($this->dialog->objectClass)){
792         $this->dn = "new" ;
793         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
794         $name = $this->dialog->save();
796         if(class_exists($a_setup[0])){
797           $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
798           $this->dialog->set_acl_base($this->base);
799           $this->dialog->by_object[$a_setup[1]]->cn = $name;
800           $this->dialog->parent = &$this;
801           $this->is_dialog = true;
802         }
803       }         
804     }   
807     /****************
808      Cancel dialogs 
809      ****************/
811                 if(isset($_POST['edit_cancel'])){
812                         unset($this->dialog);
813                         $this->dialog=FALSE;
814                         $this->is_dialog = false;
815                         session::un_set('objectinfo');
816                         del_lock ($this->dn);
817                 }
820     /****************
821       Save sub dialogs 
822      ****************/
824                 /* This check if the given tab could be saved 
825                  * If it was possible to save it, remove dialog object. 
826                  * If it wasn't possible, show errors and keep dialog.
827                  */
828                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
829                         $this->dialog->save_object();
830       $msgs= $this->dialog->check();
831                         if(count($msgs)!=0){
832                                 foreach($msgs as $msg){
833           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
834                                 }
835                         }else{
836                                 $this->dialog->save();
837         FAI::save_release_changes_now();
838         if (!isset($_POST['edit_apply'])){
839           del_lock ($this->dn);
840           unset($this->dialog);
841           $this->dialog=FALSE;
842           $this->is_dialog=false;
843           session::un_set('objectinfo');
844         }
845                         }
846                 }
849     /****************
850       Display currently open dialog 
851      ****************/
853                 /* If dialog is set, but $this->is_dialog==false, then 
854                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
855                  * If is_dialog == true, we are currently editing tab objects.
856                  *  Here we need both, save and cancel
857                  */ 
859                 if(is_object($this->dialog)){
860                         $display .= $this->dialog->execute();
861                         /* Don't show buttons if tab dialog requests this */
863       if(isset($this->dialog->current)){
865         $obj = $this->dialog->by_object[$this->dialog->current];
867         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
869           $display.= "<p style=\"text-align:right\">\n";
870           if(!$this->no_save){
871             $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
872             $display.= "&nbsp;\n";
873             if ($this->dn != "new"){
874               $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
875               $display.= "&nbsp;\n";
876             }
877           }
878           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
879           $display.= "</p>";
880         }elseif(!isset($this->dialog->current)){
881           $display.= "<p style=\"text-align:right\">\n";
882           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
883           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
884           $display.= "</p>";
885         }
886       }else{
887         $display.= "<p style=\"text-align:right\">\n";
888         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
889         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
890         $display.= "</p>";
892       }
893       return($display);
894                 }
895                 
897     /****************
898       Dialog display
899      ****************/
901     /* Check if there is a snapshot dialog open */
902     $base = $this->fai_base;
903     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
904       return($str);
905     }
907     /* Display dialog with system list */
908     $this->reload();
909     $this->DivListFai->parent = $this;
910     $this->DivListFai->execute();
911     $this->DivListFai->setEntries($this->objects);
912     return($this->DivListFai->Draw());
913         }
916   /* Return departments, that will be included within snapshot detection */
917   function get_used_snapshot_bases()
918   {
919     $tmp = array();
920     $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
921     foreach($types as $type){
922       $tmp[] = get_ou($type).$this->fai_release;
923     }
924     return($tmp);
925   }
928   /* Get available branches for current base */
929   function getBranches($base = false,$prefix = "")
930   {
931     $ret = array("/"=>$this->fai_base);
932     $ldap = $this->config->get_ldap_link();
933     if(!$base){
934       $base = $this->fai_base;
935     }
936     $tmp = FAI::get_all_releases_from_base($base,true);
937     foreach($tmp as $dn => $name){
938       $ret[$name]=$dn;
939     }
940     ksort($ret);
941     $ret = array_flip($ret);
943     return ($ret);
944   }
945   
947   function list_get_selected_items()
948   {
949     $ids = array();
950     foreach($_POST as $name => $value){
951       if(preg_match("/^item_selected_[0-9]*$/",$name)){
952         $id   = preg_replace("/^item_selected_/","",$name);
953         $ids[$id] = $id;
954       }
955     }
956     return($ids);
957   }
960   /* reload list of objects */
961   function reload()
962   {
963     /* Variable initialisation */
964     $str            = "";
965     $Regex          = $this->DivListFai->Regex;
966     $this->objects  = array();
968     /* Get base */
969     $base = $this->fai_base;
970     if($this->fai_release != $this->fai_base){
971       $br = $this->getBranches();
972       if(isset($br[$this->fai_release])){
973         $base = $this->fai_release;
974       }else{
975         $base = $this->fai_base;
976       }
977     }
978     $this->base = $base;
979     $this->set_acl_base($this->base);
981     $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
983     /* Create a new list of FAI object 
984      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
985      */
986     $ObjectTypes = array(
987         "FAIpartitionTable"  => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
988         "FAIpackageList"     => array("OU"=> get_ou('faipackageou')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
989         "FAIscript"          => array("OU"=> get_ou('faiscriptou')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
990         "FAIvariable"        => array("OU"=> get_ou('faivariableou')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
991         "FAIhook"            => array("OU"=> get_ou('faihookou')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
992         "FAIprofile"         => array("OU"=> get_ou('faiprofileou')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
993         "FAItemplate"        => array("OU"=> get_ou('faitemplateou')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
995     $filter = "";
996     foreach($ObjectTypes as $key => $data){
997       if($this->DivListFai->$data['CHKBOX']){
998         $filter.= "(objectClass=".$key.")";
999       }
1000     }
1001     $filter = "(&(|".$filter.")(cn=$Regex))";
1002     
1003     /* Get resolved release dependencies */
1004     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1006     /* Ge listed ldap objects */
1007     $ldap = $this->config->get_ldap_link();
1008     $ldap->cd($this->config->current['BASE']);
1010     /* Get release tag 
1011        If current release is freezed, all objects are freezed to.
1012      */
1013     $ldap->cat($base);
1014     $release_attrs = $ldap->fetch();
1015     $force_freezed = FALSE;
1016     if(isset($release_attrs['FAIstate'][0]) && preg_match("/freeze/i",$release_attrs['FAIstate'][0])){
1017       $force_freezed = TRUE;
1018     }
1020     foreach($tmp as $entry){
1022       /* Get some more informations about the object */ 
1023       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1024       $object  = $ldap->fetch();
1026       /* Walk through possible types */
1027       foreach($ObjectTypes as $type => $rest){  
1029         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1031         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1033           /* Prepare object */
1034           unset($object['objectClass']['count']);
1035           if(!isset($object['description'][0])){
1036             $object['description'][0]="";
1037           }
1039           /* Clean up object informations */
1040           $obj                  = array();
1041           $obj['cn']                          = $object['cn'][0];
1042           $obj['dn']                          = $object['dn'];
1043           $obj['acl']                       = $acl;
1044           $obj['description']   = $object['description'][0];
1045           $obj['objectClass']   = $object['objectClass'];
1047           /* Append type to this string, to be able to check if the selected 
1048            * entry is of type 'freeze' or 'branch'
1049            */
1050           if(!isset($object['FAIstate'])){
1051             $obj['FAIstate'] = $this->lock_type;
1052           }else{
1053             $obj['FAIstate'] = $object['FAIstate'][0]; 
1054           }
1056           if($force_freezed){
1057             $obj['FAIstate'] = "freeze";
1058           }
1060           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1061           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1062         }
1063                         }
1064                 }
1066                 ksort($this->objects);
1067                 reset ($this->objects);
1068         
1069                 /* use numeric index, thats a bit more secure */        
1070                 $tmp0 = array();
1071                 foreach($this->objects as $obj){
1072                         $tmp0[]= $obj;
1073                 }
1074                 $this->objects = array();
1075                 $this->objects = $tmp0;
1076         }
1078         function remove_lock()
1079         {
1080                 if (isset($this->dn)){
1081                         del_lock ($this->dn);
1082                 }
1083         }
1085         function get_type($array){
1086                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1087                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1088                 }
1089                 if(in_array("FAIscript",$array['objectClass'])){
1090                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1091                 }
1092                 if(in_array("FAItemplate",$array['objectClass'])){
1093                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1094                 }
1095                 if(in_array("FAIhook",$array['objectClass'])){
1096                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1097                 }
1098                 if(in_array("FAIvariable",$array['objectClass'])){
1099                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1100                 }
1101                 if(in_array("FAIprofile",$array['objectClass'])){
1102                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1103                 }
1104                 
1105                 if(in_array("FAIpackageList",$array['objectClass'])){
1106                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1107                 }
1108         }
1110   function CheckNewBranchName($name,$base)
1111   {
1112     $f = $this->fai_release;
1113     if($name == ""){
1114       return(false);
1115     }elseif(in_array($name,$this->getBranches($f))) {
1116       return(false);
1117     }elseif(tests::is_department_name_reserved($name,$base)){
1118       return(false);
1119     }
1120     return(true);
1121   }
1123   function save_object()
1124   {
1125     $this->DivListFai->save_object();
1127     /* Get posted release */
1128     $r_releases = array_flip($this->getBranches());
1129     if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1130       $this->fai_release = $r_releases[get_post('fai_release')];
1132       $fai_filter = session::get("fai_filter");
1133       $fai_filter['fai_release'] = $this->fai_release;
1134       session::set("fai_filter",$fai_filter);
1135     }
1137     if(is_object($this->CopyPasteHandler)){
1138       $this->CopyPasteHandler->save_object();
1139     }
1140   }
1143   function copyPasteHandling_from_queue($s_action,$s_entry)
1144   {
1145     /* Check if Copy & Paste is disabled */
1146     if(!is_object($this->CopyPasteHandler)){
1147       return("");
1148     }
1151     /* Add a single entry to queue */
1152     if($s_action == "cut" || $s_action == "copy"){
1154       /* Cleanup object queue */
1155       $this->CopyPasteHandler->cleanup_queue();
1156       $entry    = $this->objects[$s_entry];
1157       $a_setup  = $this->get_type($entry);
1158       $dn = $entry['dn'];
1159       $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1160     }
1162     /* Add entries to queue */
1163     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1165       /* Cleanup object queue */
1166       $this->CopyPasteHandler->cleanup_queue();
1168       /* Add new entries to CP queue */
1169       foreach($this->list_get_selected_items() as $id){
1171         /* Cleanup object queue */
1172         $entry    = $this->objects[$id];
1173         $a_setup  = $this->get_type($entry);
1174         $dn = $entry['dn'];
1177         if($s_action == "copy_multiple"){
1178           $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1179         }
1180         if($s_action == "cut_multiple"){
1181           $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1182         }
1183       }
1184     }
1186     /* Start pasting entries */
1187     if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1188       $this->start_pasting_copied_objects = TRUE;
1189     }
1191     /* Return C&P dialog */
1192     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1194       /* Get dialog */
1195       $data = $this->CopyPasteHandler->execute();
1197       FAI::save_release_changes_now();
1199       /* Return dialog data */
1200       if(!empty($data)){
1201         return($data);
1202       }
1203     }
1205     /* Automatically disable status for pasting */
1206     if(!$this->CopyPasteHandler->entries_queued()){
1207       $this->start_pasting_copied_objects = FALSE;
1208     }
1209     return("");
1210   }
1213   /* Check if the given FAI class is used in this release 
1214    */
1215   static function check_class_name($oc,$name,$dn)
1216   {
1217     $base = FAI::get_release_dn($dn);
1218     $res  = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1219     $delete = array();
1220     $used   = array();
1221     foreach($res as $object){
1222       $used[$object['cn'][0]]= $object['cn'][0];
1223     }
1224     return($used);
1225   }
1228   /* Return plugin informations for acl handling */ 
1229   static function plInfo()
1230   {
1231     return (array( 
1232           "plShortName"   => _("FAI releases"),
1233           "plDescription" => _("FAI release management"),
1234           "plSelfModify"  => FALSE,
1235           "plDepends"     => array(),
1236           "plPriority"    => 0,
1237           "plSection"     => array("administration"),           
1238           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1239                                                  "objectClass" => "FAIclass")),
1240           "plProvidedAcls"=> array()));
1241   }
1243 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1244 ?>