e1bea00f682d2c537ed9cbb0a4f9ea0489655df9
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";
27 var $plIcon = "plugins/fai/images/plugin.png";
29 /* Headpage attributes */
30 var $lock_type = ""; // should be branch/freeze
31 var $lock_name = "";
32 var $lock_dn = "";
34 /* attribute list for save action */
35 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
36 var $objectclasses= array(); // ObjectClasses which the attributes are related to
37 var $dialog = array(); // This object contains every dialog we have currently opened
39 var $objects = array(); // This array contains all available objects shown in divlist
40 var $is_dialog = false;
42 var $dispNewBranch= false;
43 var $dispNewFreeze= false;
45 var $DivListFai;
46 var $start_pasting_copied_objects = FALSE;
47 var $CopyPasteHandler = FALSE;
49 /* Allow inserting of new elements if freezed releases
50 */
51 var $allow_freeze_object_attach = TRUE;
53 var $no_save;
54 var $fai_base ="";
55 var $fai_release ="";
57 var $acl_module = array("fai");
59 /* construction/reconstruction
60 */
61 function faiManagement (&$config, $ui)
62 {
63 /* Set defaults */
64 $this->dn = "";
65 $this->config = $config;
66 $this->ui = $ui;
68 /* Creat dialog object */
69 $this->DivListFai = new divListFai($this->config,$this);
71 /* Copy & Paste handler */
72 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
73 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
74 }
76 /* Set default release */
77 $this->fai_base = get_ou("faiou").$this->config->current['BASE'];
78 if(!session::is_set("fai_filter")){
80 /* Set intial release */
81 $rel = $config->search("faiManagement","DEFAULT_RELEASE",array("menu"));
82 if(empty($rel)){
83 $rel = $this->fai_base;
84 }
86 session::set("fai_filter",array("fai_release" => $rel));
87 }
89 $fai_filter = session::get("fai_filter");
90 $this->fai_release = $fai_filter['fai_release'];
91 }
93 function execute()
94 {
95 /* Call parent execute */
96 plugin::execute();
98 /* Initialise vars and smarty */
99 $smarty = get_smarty();
100 $smarty->assign("BranchName","");
102 $display = "";
103 $s_action = "";
104 $s_entry = "";
105 $no_save = FALSE; // hide Apply / Save buttons
107 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
108 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/"));
111 /****************
112 Handle posts
113 ****************/
115 /* Check ImageButton posts
116 * Create new tab ich new_xx is posted
117 */
118 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
119 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
120 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
121 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
122 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
123 "/edit_continue/"=>"select_class_name_finished",
124 "/^multiple_copy_fai/" => "copy_multiple",
125 "/^multiple_cut_fai/" => "cut_multiple",
126 "/^copy/" => "copy",
127 "/^remove_multiple_fai_objects/" => "del_multiple");
129 foreach($_POST as $name => $value){
130 foreach($posts as $reg => $act ){
131 if(preg_match($reg,$name)){
132 $s_action = $act;
133 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
134 $s_entry = preg_replace("/_.*$/","",$s_entry);
135 }
136 }
137 if(preg_match("/^entry_edit_.*/",$name)){
138 $s_entry = preg_replace("/^entry_edit_/","",$name);
139 $s_entry = preg_replace("/_.*$/","",$s_entry);
140 $s_action = "edit";
141 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
142 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
143 $s_entry = preg_replace("/_.*$/","",$s_entry);
144 $s_action = "edit";
145 $no_save = TRUE;
146 }elseif(preg_match("/^entry_delete_.*/",$name)){
147 $s_entry = preg_replace("/^entry_delete_/","",$name);
148 $s_entry = preg_replace("/_.*$/","",$s_entry);
149 $s_action = "delete";
150 }
151 }
153 if(isset($_GET['edit_entry'])){
154 $s_entry = $_GET['edit_entry'];
155 $s_action = "edit";
156 }
158 if(isset($_GET['edit_freeze_entry'])){
159 $s_entry = $_GET['edit_freeze_entry'];
160 $s_action = "edit";
161 $no_save = TRUE;
162 }
164 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
165 $s_action = "freeze_branch";
166 }
167 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
168 $s_action = "branch_branch";
169 }
170 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
171 $s_action = "remove_branch";
172 }
174 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
175 $this->dispNewBranch = false;
176 $this->dispNewFreeze = false;
177 }
180 $type_acl_mapping = array(
181 "FAIpartitionTable" => "faiPartitionTable",
182 "FAIpackageList" => "faiPackage",
183 "FAIscript" => "faiScript",
184 "FAIvariable" => "faiVariable",
185 "FAIhook" => "faiHook",
186 "FAIprofile" => "faiProfile",
187 "FAItemplate" => "faiTemplate");
190 /* handle C&P from layers menu */
191 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
192 $s_action = "copy_multiple";
193 }
194 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
195 $s_action = "cut_multiple";
196 }
197 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
198 $s_action = "editPaste";
199 }
201 /* Create options */
202 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
203 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
204 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
205 }
207 /* handle remove from layers menu */
208 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
209 $s_action = "del_multiple";
210 }
213 if(!empty($s_action)){
214 $this->no_save = $no_save;
215 }
217 /********************
218 Copy & Paste
219 ********************/
221 /* Display the copy & paste dialog, if it is currently open */
222 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
223 if($ret){
224 return($ret);
225 }
228 /****************
229 Delete confirme dialog
230 ****************/
232 if ($s_action=="delete"){
234 /* Get 'dn' from posted termlinst */
235 $this->dn= $this->objects[$s_entry]['dn'];
237 /* Load permissions for selected 'dn' and check if
238 we're allowed to remove this 'dn' */
239 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
240 if(preg_match("/d/",$acl)){
242 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
243 if (($user= get_lock($this->dn)) != ""){
244 return(gen_locked_message ($user, $this->dn));
245 }
247 /* Lock the current entry, so nobody will edit it during deletion */
248 add_lock ($this->dn, $this->ui->dn);
249 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
250 $smarty->assign("multiple", false);
251 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
252 } else {
254 /* Obviously the user isn't allowed to delete. Show message and clean session. */
255 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
256 }
257 }
260 /********************
261 Delete MULTIPLE entries requested, display confirm dialog
262 ********************/
264 if ($s_action=="del_multiple"){
265 $this->dns = array();
266 $ids = $this->list_get_selected_items();
268 if(count($ids)){
270 $errors = "";
271 foreach($ids as $id){
272 $dn = $this->objects[$id]['dn'];
273 $cn = $this->objects[$id]['cn'];
274 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
275 $this->dns[$id] = $dn;
276 }else{
277 $errors .= $cn.", ";
278 }
279 }
280 if ($user= get_multiple_locks($this->dns)){
281 return(gen_locked_message($user,$this->dns));
282 }
284 if($errors != ""){
285 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
286 "<br><br>".trim($errors,", ")),INFO_DIALOG);
287 }
289 if(count($this->dns)){
291 $dns_names = array();
292 foreach($this->dns as $dn){
293 add_lock ($dn, $this->ui->dn);
294 $dns_names[] = @LDAP::fix($dn);
295 }
297 /* Lock the current entry, so nobody will edit it during deletion */
298 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
299 $smarty->assign("multiple", true);
300 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
301 }
302 }
303 }
306 /********************
307 Delete MULTIPLE entries confirmed
308 ********************/
310 /* Confirmation for deletion has been passed. Users should be deleted. */
311 if (isset($_POST['delete_multiple_fai_object_confirm'])){
313 /* Find out more about the object type */
314 $ldap = $this->config->get_ldap_link();
316 /* Remove user by user and check acls before removeing them */
317 foreach($this->dns as $key => $dn){
319 $ldap->cat($dn, array('objectClass'));
320 $attrs = $ldap->fetch();
321 $type = $this->get_type($attrs);
323 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
324 if(preg_match("/d/",$acl)){
326 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
327 $this->dialog->parent = &$this;
328 $this->dialog->set_acl_base($dn);
329 $this->dialog->by_object[$type[1]]->remove_from_parent ();
330 unset ($this->dialog);
331 $this->dialog= FALSE;
332 $to_del = FAI::clean_up_releases($dn);
333 FAI::save_release_changes_now();
335 foreach($to_del as $dn){
336 $ldap->rmdir_recursive($dn);
337 }
339 } else {
341 /* Normally this shouldn't be reached, send some extra
342 logs to notify the administrator */
343 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
344 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
345 }
346 }
348 /* Remove lock file after successfull deletion */
349 $this->remove_lock();
350 $this->dns = array();
351 }
354 /********************
355 Delete MULTIPLE entries Canceled
356 ********************/
358 /* Remove lock */
359 if(isset($_POST['delete_multiple_fai_object_cancel'])){
360 $this->dns = array();
361 $this->remove_lock();
362 }
365 /****************
366 Delete aborted
367 ****************/
369 /* Delete canceled? */
370 if (isset($_POST['delete_cancel'])){
371 $this->remove_lock();
372 }
375 /****************
376 Delete confirmed
377 ****************/
379 /* Deltetion was confirmed, so delete this entry
380 */
381 if (isset($_POST['delete_terminal_confirm'])){
383 /* Some nice guy may send this as POST, so we've to check
384 for the permissions again. */
386 /* Find out more about the object type */
387 $ldap = $this->config->get_ldap_link();
388 $ldap->cat($this->dn, array('objectClass'));
389 if($ldap->count()){
390 $attrs = $ldap->fetch();
391 $type = $this->get_type($attrs);
393 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
394 if(preg_match("/d/",$acl)){
396 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
397 $this->dialog->set_acl_base($this->dn);
398 $this->dialog->parent = &$this;
399 $this->dialog->by_object[$type[1]]->remove_from_parent ();
400 unset ($this->dialog);
401 $this->dialog= FALSE;
402 $to_del = FAI::clean_up_releases($this->dn);
403 FAI::save_release_changes_now();
405 foreach($to_del as $dn){
406 $ldap->rmdir_recursive($dn);
407 }
409 } else {
411 /* Normally this shouldn't be reached, send some extra
412 logs to notify the administrator */
413 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
414 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
415 }
417 }else{
418 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
419 }
421 /* Remove lock file after successfull deletion */
422 $this->remove_lock();
423 }
426 /****************
427 Edit entry
428 ****************/
430 if(($s_action == "edit") && (!isset($this->dialog->config))){
431 $entry = $this->objects[$s_entry];
432 $a_setup = $this->get_type($entry);
433 $this->dn = $entry['dn'];
435 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
436 if (($user= get_lock($this->dn)) != ""){
437 return(gen_locked_message ($user, $this->dn));
438 }
439 add_lock ($this->dn, $this->ui->dn);
441 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
442 $this->dialog->parent = &$this;
443 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
444 $this->dialog->set_acl_base($this->dn);
445 $this->is_dialog = true;
446 session::set('objectinfo',$this->dn);
447 }
450 /* Branch handling
451 09.01.2006
452 */
454 /****************
455 Remove branch
456 ****************/
458 /* Remove branch
459 */
460 if($s_action == "remove_branch"){
461 $base= $this->fai_release;
463 /* Check if we have a post remove method configured
464 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
465 */
466 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
467 /* Load permissions for selected 'dn' and check if
468 we're allowed to remove this 'dn' */
469 if($this->acl_is_removeable()){
470 $smarty->assign("release_hidden",base64_encode($this->fai_release));
471 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
472 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
473 } else {
474 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
475 }
476 }
477 }
480 /****************
481 Remove branch confirmed
482 ****************/
484 if(isset($_POST['delete_branch_confirm'])){
486 /* Check if we have a post remove method configured
487 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
488 */
489 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
491 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
492 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
493 }else{
495 $bb = $this->fai_release;
496 if(!isset($ldap)){
497 $ldap = $this->config->get_ldap_link();
498 }
500 $br = $this->getBranches();
502 if(isset($br[$bb]) && $this->acl_is_removeable()){
503 $name = $br[$bb];
505 $ldap->cd($bb);
506 $ldap->recursive_remove();
507 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
508 $ldap->recursive_remove();
509 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('mimetypeou'), $bb));
510 $ldap->recursive_remove();
512 /* Search for all groups with configured application menus.
513 - First search all groups, to ensure that we only remove entries form whithin groups.
514 - The search für menu configuration for the specified release and collect all those dns.
515 - Remove entries
516 */
517 $release_ou = preg_replace("/".normalizePreg(get_ou("faiou")).".*$/","",$bb);
518 $ldap->cd($this->config->current['BASE']);
519 $ldap->search("(objectClass=posixGroup)",array("dn"));
521 /* Collect all group dns
522 */
523 $groups = array();
524 while($attrs = $ldap->fetch()){
525 $groups[] = $attrs['dn'];
526 }
528 /* Collect all group menu release dns that match the release we have removed
529 */
530 $dns = array();
531 foreach($groups as $dn){
532 $ldap->cd($dn);
533 $ldap->search("(objectClass=FAIbranch)",array("dn"));
534 while($attrs = $ldap->fetch()){
535 if(preg_match("/^".normalizePreg($release_ou)."/",$attrs['dn'])){
536 $dns[] = $attrs['dn'];
537 }
538 }
539 }
541 /* Finally remove collected release dns
542 */
543 foreach($dns as $dn){
544 $ldap->cd($dn);
545 $ldap->recursive_remove();
546 }
548 /* Post remove */
549 $this->fai_release = $this->fai_base;
550 $this->lock_name = $name;
551 $this->lock_dn = $bb;
552 $this->postremove();
554 $fai_filter = session::get("fai_filter");
555 $fai_filter['fai_release'] = $this->fai_release;
556 session::set("fai_filter",$fai_filter);
558 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
559 }
560 }
561 }
562 }
565 /****************
566 Create a new branch "insert Name"
567 ****************/
569 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
570 session::set('LASTPOST',$_POST);
572 if($this->dispNewBranch){
573 $type = "branch";
574 }else{
575 $type = "freeze";
576 }
578 /* Check branch name */
579 $name = $_POST['BranchName'];
580 $is_ok = true;
581 $smarty->assign("BranchName",$name);
582 $base= $this->fai_base;
584 /* Check used characters */
585 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
586 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
587 $is_ok = false;
588 }
590 /* Check if this name is already in use */
591 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
592 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
593 $is_ok = false;
594 }
596 if($is_ok){
598 if(session::is_set('LASTPOST')){
599 $LASTPOST = session::get('LASTPOST');
600 }else{
601 $LASTPOST = array();
602 }
603 $LASTPOST['base'] = $base;
604 $LASTPOST['type'] = $type;
605 session::set('LASTPOST',$LASTPOST);
606 $smarty->assign("iframe", true);
607 $smarty->assign("plugID", $_GET['plug']);
608 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
609 return($display);
610 }
611 }
614 /****************
615 Create a new branch
616 ****************/
618 if(isset($_GET['PerformBranch'])){
620 if(!$this->acl_is_createable()){
621 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
622 }else{
624 /* In order to see error messages we have to reset the error handler.
625 Due to the exit();
626 */
627 restore_error_handler();
629 /* Create it know */
630 $this->dispNewBranch = false;
631 $this->dispNewFreeze = false;
633 $LASTPOST = session::get('LASTPOST');
634 $base = $LASTPOST['base'];
635 $_POST = session::get('LASTPOST');
636 $name = $_POST['BranchName'];
638 $type = $LASTPOST['type'];
639 $ldap = $this->config->get_ldap_link();
641 $baseToUse = $base;
642 if($this->fai_release != $this->fai_base){
643 $baseToUse = $this->fai_release;
644 }
646 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
648 $CurrentReleases = $this->getBranches();
649 $NewReleaseName = $name;
650 if(isset($CurrentReleases[$this->fai_release])) {
651 if($this->fai_release != $this->fai_base){
652 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
653 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
654 }else{
655 $NewReleaseName = $name;
656 }
657 }
659 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
660 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
662 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
663 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
665 /* Check if source depeartments exist */
666 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
667 $ldap->cd($this->config->current['BASE']);
668 $ldap->cat($dep);
669 if(!$ldap->count()){
670 $ldap->create_missing_trees($dep);
671 }
672 }
674 /* Print header to have styles included */
675 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
676 <html>
677 <head>
678 <title></title>
679 <style type="text/css">@import url("themes/default/style.css");</style>
680 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
681 </head>
682 <body style="background: none;margin:3px;color:black">
683 ';
685 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
687 /* Duplicate group application releases
688 */
689 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
691 /* Duplicate applications
692 */
693 $ldap->cat($appsrc,array("dn")) ;
694 if($ldap->count()){
695 $ldap->cd ($appdst);
696 $ldap->recursive_remove();
697 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
698 }
700 /* Duplicate mime types
701 */
702 $ldap->cat($mimesrc,array("dn")) ;
703 if($ldap->count()){
704 $ldap->cd ($mimedst);
705 $ldap->recursive_remove();
706 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
707 }
709 $attr = array();
710 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
711 $attr['ou'] = $name;
712 $attr['FAIstate'] = $type;
713 $ldap->cd($this->config->current['BASE']);
714 $ldap->cd("ou=".$name.",".$baseToUse);
715 $ldap->cat("ou=".$name.",".$baseToUse);
716 if($ldap->count()){
717 $ldap->modify($attr);
718 }else{
719 $ldap->add($attr);
720 }
722 /* Duplicate fai objects
723 */
724 // $ldap->cd ("ou=".$name.",".$baseToUse);
725 // $ldap->recursive_remove();
726 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
728 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
729 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
730 </form></div>";
732 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
734 /* Print footer to have valid html */
735 echo "</body></html>";
737 $this->dispNewFreeze = false;
739 /* Postcreate */
741 /* Assign possible attributes */
742 $this->lock_type = $type;
743 $this->lock_name = $name;
744 $this->lock_dn = $baseToUse;
745 $this->postcreate();
748 /* Send daemon event to reload the fai release database
749 */
750 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
751 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
752 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
753 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
754 $tmp = new $evt['CLASS_NAME']($this->config);
755 $tmp->set_type(TRIGGERED_EVENT);
756 $tmp->add_targets(array("GOsa"));
757 $o_queue = new gosaSupportDaemon();
758 if(!$o_queue->append($tmp)){
759 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
760 }
761 }
762 }else{
763 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
764 msg_dialog::display(_("Fatal error"),
765 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
766 FATAL_ERROR_DIALOG);
767 }
768 exit();
769 }
770 }
772 /****************
773 Display dialog to enter new Branch name
774 ****************/
776 /* Check if we have a post create method configured
777 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
778 */
779 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
780 if(($s_action == "branch_branch")||($this->dispNewBranch)){
781 if(!$this->acl_is_createable()){
782 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
783 }else{
784 $this->dispNewBranch=true;
785 $smarty->assign("iframe",false);
786 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
787 return($display);
788 }
789 }
790 }
793 /****************
794 Display dialog to enter new Freeze name
795 ****************/
797 /* Check if we have a post create method configured
798 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
799 */
800 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
801 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
802 if(!$this->acl_is_createable()){
803 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
804 }else{
805 $this->dispNewFreeze = true;
806 $smarty->assign("iframe",false);
807 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
808 return($display);
809 }
810 }
811 }
814 /****************
815 Create a new object
816 ****************/
818 $types = array( "new_partition" => "FAIpartitionTable",
819 "new_script" => "FAIscript",
820 "new_hook" => "FAIhook",
821 "new_variable" => "FAIvariable",
822 "new_template" => "FAItemplate",
823 "new_package" => "FAIpackageList");
824 $types_i18n = array( "new_partition" => _("partition table"),
825 "new_script" => _("script"),
826 "new_hook" => _("hook"),
827 "new_variable" => _("variable"),
828 "new_template" => _("template"),
829 "new_package" => _("package list"));
831 if(isset($types[$s_action])){
832 $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
833 if(preg_match("/c/",$acl)){
834 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
835 $this->dialog->parent = &$this;
836 }else{
837 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
838 }
839 }
841 /* New Profile */
842 if($s_action == "new_profile"){
843 $this->dn = "new" ;
845 $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
846 if(preg_match("/c/",$acl)){
847 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
848 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
849 $this->dialog->set_acl_base($this->base);
850 $this->dialog->parent = &$this;
852 $this->is_dialog = false;
853 }else{
854 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
855 }
856 }
859 /****************
860 Get from ask class name dialog
861 ****************/
863 if($s_action == "select_class_name_finished"){
864 $this->dialog->save_object();
865 if(count($this->dialog->check())!=0){
866 foreach($this->dialog->check() as $msg){
867 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
868 }
869 }elseif(isset($this->dialog->objectClass)){
870 $this->dn = "new" ;
871 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
872 $name = $this->dialog->save();
874 if(class_exists($a_setup[0])){
875 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
876 $this->dialog->set_acl_base($this->base);
877 $this->dialog->by_object[$a_setup[1]]->cn = $name;
878 $this->dialog->parent = &$this;
879 $this->is_dialog = true;
880 }
881 }
882 }
885 /****************
886 Cancel dialogs
887 ****************/
889 if(isset($_POST['edit_cancel'])){
890 $this->dialog=FALSE;
891 $this->is_dialog = false;
892 session::un_set('objectinfo');
893 $this->remove_lock();
894 }
897 /****************
898 Save sub dialogs
899 ****************/
901 /* This check if the given tab could be saved
902 * If it was possible to save it, remove dialog object.
903 * If it wasn't possible, show errors and keep dialog.
904 */
905 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
906 $this->dialog->save_object();
907 $msgs= $this->dialog->check();
908 if(count($msgs)!=0){
909 foreach($msgs as $msg){
910 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
911 }
912 }else{
913 $this->dialog->save();
914 FAI::save_release_changes_now();
915 if (!isset($_POST['edit_apply'])){
916 $this->remove_lock();
917 $this->dialog=FALSE;
918 $this->is_dialog=false;
919 session::un_set('objectinfo');
920 }else{
922 /* Reinitialize tab */
923 if($this->dialog instanceof tabs){
924 $this->dialog->re_init();
925 }
926 }
927 }
928 }
931 /****************
932 Display currently open dialog
933 ****************/
935 /* If dialog is set, but $this->is_dialog==false, then
936 * only the "abort" button is shown, this are dialogs that must not be saved.
937 * If is_dialog == true, we are currently editing tab objects.
938 * Here we need both, save and cancel
939 */
941 if(is_object($this->dialog)){
942 $display .= $this->dialog->execute();
943 /* Don't show buttons if tab dialog requests this */
945 if(isset($this->dialog->current)){
947 $obj = $this->dialog->by_object[$this->dialog->current];
949 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
951 $display.= "<p style=\"text-align:right\">\n";
952 if(!$this->no_save){
953 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
954 $display.= " \n";
955 if ($this->dn != "new"){
956 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
957 $display.= " \n";
958 }
959 }
960 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
961 $display.= "</p>";
962 }elseif(!isset($this->dialog->current)){
963 $display.= "<p style=\"text-align:right\">\n";
964 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
965 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
966 $display.= "</p>";
967 }
968 }else{
969 $display.= "<p style=\"text-align:right\">\n";
970 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
971 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
972 $display.= "</p>";
974 }
975 return($display);
976 }
979 /****************
980 Dialog display
981 ****************/
983 /* Check if there is a snapshot dialog open */
984 $base = $this->fai_base;
985 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
986 return($str);
987 }
989 /* Display dialog with system list */
990 $this->reload();
991 $this->DivListFai->parent = &$this;
992 $this->DivListFai->execute();
993 $this->DivListFai->setEntries($this->objects);
994 return($this->DivListFai->Draw());
995 }
998 /* Return departments, that will be included within snapshot detection */
999 function get_used_snapshot_bases()
1000 {
1001 $tmp = array();
1002 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
1003 foreach($types as $type){
1004 $tmp[] = get_ou($type).$this->fai_release;
1005 }
1006 return($tmp);
1007 }
1010 /* Get available branches for current base */
1011 function getBranches($base = false,$prefix = "")
1012 {
1013 $ret = array("/"=>$this->fai_base);
1014 $ldap = $this->config->get_ldap_link();
1015 if(!$base){
1016 $base = $this->fai_base;
1017 }
1018 $tmp = FAI::get_all_releases_from_base($base,true);
1019 foreach($tmp as $dn => $name){
1020 $ret[$name]=$dn;
1021 }
1022 ksort($ret);
1023 $ret = array_flip($ret);
1025 return ($ret);
1026 }
1029 function list_get_selected_items()
1030 {
1031 $ids = array();
1032 foreach($_POST as $name => $value){
1033 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1034 $id = preg_replace("/^item_selected_/","",$name);
1035 $ids[$id] = $id;
1036 }
1037 }
1038 return($ids);
1039 }
1042 /* reload list of objects */
1043 function reload()
1044 {
1045 /* Variable initialisation */
1046 $str = "";
1047 $Regex = $this->DivListFai->Regex;
1048 $this->objects = array();
1050 /* Get base */
1051 $base = $this->fai_base;
1052 if($this->fai_release != $this->fai_base){
1053 $br = $this->getBranches();
1054 if(isset($br[$this->fai_release])){
1055 $base = $this->fai_release;
1056 }else{
1057 $base = $this->fai_base;
1058 }
1059 }
1060 $this->base = $base;
1061 $this->set_acl_base($this->base);
1063 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1065 /* Create a new list of FAI object
1066 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1067 */
1068 $ObjectTypes = array(
1069 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1070 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1071 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1072 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1073 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1074 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1075 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1077 $filter = "";
1078 foreach($ObjectTypes as $key => $data){
1079 if($this->DivListFai->$data['CHKBOX']){
1080 $filter.= "(objectClass=".$key.")";
1081 }
1082 }
1083 $filter = "(&(|".$filter.")(cn=$Regex))";
1085 /* Get resolved release dependencies */
1086 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1088 /* Ge listed ldap objects */
1089 $ldap = $this->config->get_ldap_link();
1090 $ldap->cd($this->config->current['BASE']);
1092 foreach($tmp as $entry){
1094 /* Get some more informations about the object */
1095 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1096 $object = $ldap->fetch();
1098 /* Walk through possible types */
1099 foreach($ObjectTypes as $type => $rest){
1101 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1103 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1105 /* Prepare object */
1106 unset($object['objectClass']['count']);
1107 if(!isset($object['description'][0])){
1108 $object['description'][0]="";
1109 }
1111 /* Clean up object informations */
1112 $obj = array();
1113 $obj['cn'] = $object['cn'][0];
1114 $obj['dn'] = $object['dn'];
1115 $obj['acl'] = $acl;
1116 $obj['class'] = $rest ['ACL'];
1117 $obj['FAIstate'] = $entry['FAIstate'];
1118 $obj['description'] = $object['description'][0];
1119 $obj['objectClass'] = $object['objectClass'];
1121 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1122 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1123 }
1124 }
1125 }
1127 ksort($this->objects);
1128 reset ($this->objects);
1130 /* use numeric index, thats a bit more secure */
1131 $tmp0 = array();
1132 foreach($this->objects as $obj){
1133 $tmp0[]= $obj;
1134 }
1135 $this->objects = array();
1136 $this->objects = $tmp0;
1137 }
1139 function remove_lock()
1140 {
1141 if (isset($this->dn)){
1142 del_lock ($this->dn);
1143 }
1144 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1145 del_lock ($this->dns);
1146 }
1147 }
1149 function get_type($array){
1150 if(in_array("FAIpartitionTable",$array['objectClass'])){
1151 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1152 }
1153 if(in_array("FAIscript",$array['objectClass'])){
1154 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1155 }
1156 if(in_array("FAItemplate",$array['objectClass'])){
1157 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1158 }
1159 if(in_array("FAIhook",$array['objectClass'])){
1160 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1161 }
1162 if(in_array("FAIvariable",$array['objectClass'])){
1163 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1164 }
1165 if(in_array("FAIprofile",$array['objectClass'])){
1166 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1167 }
1169 if(in_array("FAIpackageList",$array['objectClass'])){
1170 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1171 }
1172 }
1174 function CheckNewBranchName($name,$base)
1175 {
1176 $f = $this->fai_release;
1177 if($name == ""){
1178 return(false);
1179 }elseif(in_array($name,$this->getBranches($f))) {
1180 return(false);
1181 }elseif(tests::is_department_name_reserved($name,$base)){
1182 return(false);
1183 }
1184 return(true);
1185 }
1187 function save_object()
1188 {
1189 $this->DivListFai->save_object();
1191 /* Get posted release */
1192 $r_releases = array_flip($this->getBranches());
1193 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1195 /* Ensure that we have a valid release selected */
1196 if(!isset($r_releases[get_post('fai_release')])){
1197 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1198 $_POST = array();
1199 $plug =$_GET['plug'];
1200 $_GET = array("plug" => $plug);
1201 $this->fai_release = $this->fai_base;
1202 }else{
1203 $this->fai_release = $r_releases[get_post('fai_release')];
1204 }
1206 $fai_filter = session::get("fai_filter");
1207 $fai_filter['fai_release'] = $this->fai_release;
1208 session::set("fai_filter",$fai_filter);
1209 }
1211 if(is_object($this->CopyPasteHandler)){
1212 $this->CopyPasteHandler->save_object();
1213 }
1214 }
1217 function copyPasteHandling_from_queue($s_action,$s_entry)
1218 {
1219 /* Check if Copy & Paste is disabled */
1220 if(!is_object($this->CopyPasteHandler)){
1221 return("");
1222 }
1224 $ui = get_userinfo();
1226 /* Add a single entry to queue */
1227 if($s_action == "copy"){
1229 /* Cleanup object queue */
1230 $this->CopyPasteHandler->cleanup_queue();
1231 $entry = $this->objects[$s_entry];
1232 $a_setup = $this->get_type($entry);
1233 $dn = $entry['dn'];
1235 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1236 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1237 }
1238 }
1240 /* Add entries to queue */
1241 if($s_action == "copy_multiple"){
1243 /* Cleanup object queue */
1244 $this->CopyPasteHandler->cleanup_queue();
1246 /* Add new entries to CP queue */
1247 foreach($this->list_get_selected_items() as $id){
1249 /* Cleanup object queue */
1250 $entry = $this->objects[$id];
1251 $a_setup = $this->get_type($entry);
1252 $dn = $entry['dn'];
1254 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1255 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1256 }
1257 }
1258 }
1260 /* Start pasting entries */
1261 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1262 $this->start_pasting_copied_objects = TRUE;
1263 }
1265 /* Return C&P dialog */
1266 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1268 /* Get dialog */
1269 $this->CopyPasteHandler->SetVar("parent",$this);
1270 $data = $this->CopyPasteHandler->execute();
1272 FAI::save_release_changes_now();
1274 /* Return dialog data */
1275 if(!empty($data)){
1276 return($data);
1277 }
1278 }
1280 /* Automatically disable status for pasting */
1281 if(!$this->CopyPasteHandler->entries_queued()){
1282 $this->start_pasting_copied_objects = FALSE;
1283 }
1284 return("");
1285 }
1288 /* Check if the given FAI class is used in this release
1289 */
1290 static function check_class_name($oc,$name,$dn)
1291 {
1292 $base = FAI::get_release_dn($dn);
1293 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1294 $delete = array();
1295 $used = array();
1296 foreach($res as $object){
1297 $used[$object['cn'][0]]= $object['cn'][0];
1298 }
1299 return($used);
1300 }
1303 /* Return plugin informations for acl handling */
1304 static function plInfo()
1305 {
1306 return (array(
1307 "plShortName" => _("FAI releases"),
1308 "plDescription" => _("FAI release management"),
1309 "plSelfModify" => FALSE,
1310 "plDepends" => array(),
1311 "plPriority" => 0,
1312 "plSection" => array("administration"),
1313 "plCategory" => array("fai"=> array("description" => _("FAI"),
1314 "objectClass" => "FAIclass")),
1315 "plProvidedAcls"=> array()));
1316 }
1317 }
1318 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1319 ?>