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'];
79 if(!session::is_set("fai_filter")){
81 /* Set intial release */
82 $rel = $config->search("faiManagement","DEFAULT_RELEASE",array("menu"));
83 $rels = array_flip($this->getBranches());
84 if(isset($rels[$rel])){
85 $rel = $rels[$rel];
86 }else{
87 $rel = $this->fai_base;
88 }
90 session::set("fai_filter",array("fai_release" => $rel));
91 }
93 $fai_filter = session::get("fai_filter");
94 $this->fai_release = $fai_filter['fai_release'];
95 }
97 function execute()
98 {
99 /* Call parent execute */
100 plugin::execute();
103 /* Initialise vars and smarty */
104 $smarty = get_smarty();
105 $smarty->assign("BranchName","");
107 $display = "";
108 $s_action = "";
109 $s_entry = "";
110 $no_save = FALSE; // hide Apply / Save buttons
112 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
113 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/"));
116 /****************
117 Handle posts
118 ****************/
120 /* Check ImageButton posts
121 * Create new tab ich new_xx is posted
122 */
123 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
124 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
125 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
126 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
127 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
128 "/edit_continue/"=>"select_class_name_finished",
129 "/^multiple_copy_fai/" => "copy_multiple",
130 "/^multiple_cut_fai/" => "cut_multiple",
131 "/^copy/" => "copy",
132 "/^remove_multiple_fai_objects/" => "del_multiple");
134 foreach($_POST as $name => $value){
135 foreach($posts as $reg => $act ){
136 if(preg_match($reg,$name)){
137 $s_action = $act;
138 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
139 $s_entry = preg_replace("/_.*$/","",$s_entry);
140 }
141 }
142 if(preg_match("/^entry_edit_.*/",$name)){
143 $s_entry = preg_replace("/^entry_edit_/","",$name);
144 $s_entry = preg_replace("/_.*$/","",$s_entry);
145 $s_action = "edit";
146 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
147 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
148 $s_entry = preg_replace("/_.*$/","",$s_entry);
149 $s_action = "edit";
150 $no_save = TRUE;
151 }elseif(preg_match("/^entry_delete_.*/",$name)){
152 $s_entry = preg_replace("/^entry_delete_/","",$name);
153 $s_entry = preg_replace("/_.*$/","",$s_entry);
154 $s_action = "delete";
155 }
156 }
158 if(isset($_GET['edit_entry'])){
159 $s_entry = $_GET['edit_entry'];
160 $s_action = "edit";
161 }
163 if(isset($_GET['edit_freeze_entry'])){
164 $s_entry = $_GET['edit_freeze_entry'];
165 $s_action = "edit";
166 $no_save = TRUE;
167 }
169 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
170 $s_action = "freeze_branch";
171 }
172 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
173 $s_action = "branch_branch";
174 }
175 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
176 $s_action = "remove_branch";
177 }
179 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
180 $this->dispNewBranch = false;
181 $this->dispNewFreeze = false;
182 }
185 $type_acl_mapping = array(
186 "FAIpartitionTable" => "faiPartitionTable",
187 "FAIpackageList" => "faiPackage",
188 "FAIscript" => "faiScript",
189 "FAIvariable" => "faiVariable",
190 "FAIhook" => "faiHook",
191 "FAIprofile" => "faiProfile",
192 "FAItemplate" => "faiTemplate");
195 /* handle C&P from layers menu */
196 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
197 $s_action = "copy_multiple";
198 }
199 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
200 $s_action = "cut_multiple";
201 }
202 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
203 $s_action = "editPaste";
204 }
206 /* Create options */
207 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
208 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
209 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
210 }
212 /* handle remove from layers menu */
213 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
214 $s_action = "del_multiple";
215 }
218 if(!empty($s_action)){
219 $this->no_save = $no_save;
220 }
222 /********************
223 Copy & Paste
224 ********************/
226 /* Display the copy & paste dialog, if it is currently open */
227 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
228 if($ret){
229 return($ret);
230 }
233 /****************
234 Delete confirme dialog
235 ****************/
237 if ($s_action=="delete"){
239 /* Get 'dn' from posted termlinst */
240 $this->dn= $this->objects[$s_entry]['dn'];
242 /* Load permissions for selected 'dn' and check if
243 we're allowed to remove this 'dn' */
244 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
245 if(preg_match("/d/",$acl)){
247 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
248 if (($user= get_lock($this->dn)) != ""){
249 return(gen_locked_message ($user, $this->dn));
250 }
252 /* Lock the current entry, so nobody will edit it during deletion */
253 add_lock ($this->dn, $this->ui->dn);
254 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
255 $smarty->assign("multiple", false);
256 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
257 } else {
259 /* Obviously the user isn't allowed to delete. Show message and clean session. */
260 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
261 }
262 }
265 /********************
266 Delete MULTIPLE entries requested, display confirm dialog
267 ********************/
269 if ($s_action=="del_multiple"){
270 $this->dns = array();
271 $ids = $this->list_get_selected_items();
273 if(count($ids)){
275 $errors = "";
276 foreach($ids as $id){
277 $dn = $this->objects[$id]['dn'];
278 $cn = $this->objects[$id]['cn'];
279 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
280 $this->dns[$id] = $dn;
281 }else{
282 $errors .= $cn.", ";
283 }
284 }
285 if ($user= get_multiple_locks($this->dns)){
286 return(gen_locked_message($user,$this->dns));
287 }
289 if($errors != ""){
290 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
291 "<br><br>".trim($errors,", ")),INFO_DIALOG);
292 }
294 if(count($this->dns)){
296 $dns_names = array();
297 foreach($this->dns as $dn){
298 add_lock ($dn, $this->ui->dn);
299 $dns_names[] = @LDAP::fix($dn);
300 }
302 /* Lock the current entry, so nobody will edit it during deletion */
303 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
304 $smarty->assign("multiple", true);
305 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
306 }
307 }
308 }
311 /********************
312 Delete MULTIPLE entries confirmed
313 ********************/
315 /* Confirmation for deletion has been passed. Users should be deleted. */
316 if (isset($_POST['delete_multiple_fai_object_confirm'])){
318 /* Find out more about the object type */
319 $ldap = $this->config->get_ldap_link();
321 /* Remove user by user and check acls before removeing them */
322 foreach($this->dns as $key => $dn){
324 $ldap->cat($dn, array('objectClass'));
325 $attrs = $ldap->fetch();
326 $type = $this->get_type($attrs);
328 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
329 if(preg_match("/d/",$acl)){
331 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
332 $this->dialog->parent = &$this;
333 $this->dialog->set_acl_base($dn);
334 $this->dialog->by_object[$type[1]]->remove_from_parent ();
335 unset ($this->dialog);
336 $this->dialog= FALSE;
337 $to_del = FAI::clean_up_releases($dn);
338 FAI::save_release_changes_now();
340 foreach($to_del as $dn){
341 $ldap->rmdir_recursive($dn);
342 }
344 } else {
346 /* Normally this shouldn't be reached, send some extra
347 logs to notify the administrator */
348 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
349 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
350 }
351 }
353 /* Remove lock file after successfull deletion */
354 $this->remove_lock();
355 $this->dns = array();
356 }
359 /********************
360 Delete MULTIPLE entries Canceled
361 ********************/
363 /* Remove lock */
364 if(isset($_POST['delete_multiple_fai_object_cancel'])){
365 $this->dns = array();
366 $this->remove_lock();
367 }
370 /****************
371 Delete aborted
372 ****************/
374 /* Delete canceled? */
375 if (isset($_POST['delete_cancel'])){
376 $this->remove_lock();
377 }
380 /****************
381 Delete confirmed
382 ****************/
384 /* Deltetion was confirmed, so delete this entry
385 */
386 if (isset($_POST['delete_terminal_confirm'])){
388 /* Some nice guy may send this as POST, so we've to check
389 for the permissions again. */
391 /* Find out more about the object type */
392 $ldap = $this->config->get_ldap_link();
393 $ldap->cat($this->dn, array('objectClass'));
394 if($ldap->count()){
395 $attrs = $ldap->fetch();
396 $type = $this->get_type($attrs);
398 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
399 if(preg_match("/d/",$acl)){
401 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
402 $this->dialog->set_acl_base($this->dn);
403 $this->dialog->parent = &$this;
404 $this->dialog->by_object[$type[1]]->remove_from_parent ();
405 unset ($this->dialog);
406 $this->dialog= FALSE;
407 $to_del = FAI::clean_up_releases($this->dn);
408 FAI::save_release_changes_now();
410 foreach($to_del as $dn){
411 $ldap->rmdir_recursive($dn);
412 }
414 } else {
416 /* Normally this shouldn't be reached, send some extra
417 logs to notify the administrator */
418 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
419 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
420 }
422 }else{
423 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
424 }
426 /* Remove lock file after successfull deletion */
427 $this->remove_lock();
428 }
431 /****************
432 Edit entry
433 ****************/
435 if(($s_action == "edit") && (!isset($this->dialog->config))){
436 $entry = $this->objects[$s_entry];
437 $a_setup = $this->get_type($entry);
438 $this->dn = $entry['dn'];
440 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
441 if (($user= get_lock($this->dn)) != ""){
442 return(gen_locked_message ($user, $this->dn));
443 }
444 add_lock ($this->dn, $this->ui->dn);
446 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
447 $this->dialog->parent = &$this;
448 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
449 $this->dialog->set_acl_base($this->dn);
450 $this->is_dialog = true;
451 session::set('objectinfo',$this->dn);
452 }
455 /* Branch handling
456 09.01.2006
457 */
459 /****************
460 Remove branch
461 ****************/
463 /* Remove branch
464 */
465 if($s_action == "remove_branch"){
466 $base= $this->fai_release;
468 /* Check if we have a post remove method configured
469 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
470 */
471 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
472 /* Load permissions for selected 'dn' and check if
473 we're allowed to remove this 'dn' */
474 if($this->acl_is_removeable()){
475 $smarty->assign("release_hidden",base64_encode($this->fai_release));
476 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
477 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
478 } else {
479 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
480 }
481 }
482 }
485 /****************
486 Remove branch confirmed
487 ****************/
489 if(isset($_POST['delete_branch_confirm'])){
491 /* Check if we have a post remove method configured
492 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
493 */
494 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
496 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
497 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
498 }else{
500 $bb = $this->fai_release;
501 if(!isset($ldap)){
502 $ldap = $this->config->get_ldap_link();
503 }
505 $br = $this->getBranches();
507 if(isset($br[$bb]) && $this->acl_is_removeable()){
508 $name = $br[$bb];
510 $ldap->cd($bb);
511 $ldap->recursive_remove();
512 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
513 $ldap->recursive_remove();
514 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('mimetypeou'), $bb));
515 $ldap->recursive_remove();
517 /* Search for all groups with configured application menus.
518 - First search all groups, to ensure that we only remove entries form whithin groups.
519 - The search für menu configuration for the specified release and collect all those dns.
520 - Remove entries
521 */
522 $release_ou = preg_replace("/".normalizePreg(get_ou("faiou")).".*$/","",$bb);
523 $ldap->cd($this->config->current['BASE']);
524 $ldap->search("(objectClass=posixGroup)",array("dn"));
526 /* Collect all group dns
527 */
528 $groups = array();
529 while($attrs = $ldap->fetch()){
530 $groups[] = $attrs['dn'];
531 }
533 /* Collect all group menu release dns that match the release we have removed
534 */
535 $dns = array();
536 foreach($groups as $dn){
537 $ldap->cd($dn);
538 $ldap->search("(objectClass=FAIbranch)",array("dn"));
539 while($attrs = $ldap->fetch()){
540 if(preg_match("/^".normalizePreg($release_ou)."/",$attrs['dn'])){
541 $dns[] = $attrs['dn'];
542 }
543 }
544 }
546 /* Finally remove collected release dns
547 */
548 foreach($dns as $dn){
549 $ldap->cd($dn);
550 $ldap->recursive_remove();
551 }
553 /* Post remove */
554 $this->fai_release = $this->fai_base;
555 $this->lock_name = $name;
556 $this->lock_dn = $bb;
557 $this->postremove();
559 $fai_filter = session::get("fai_filter");
560 $fai_filter['fai_release'] = $this->fai_release;
561 session::set("fai_filter",$fai_filter);
563 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
564 }
565 }
566 }
567 }
570 /****************
571 Create a new branch "insert Name"
572 ****************/
574 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
575 session::set('LASTPOST',$_POST);
577 if($this->dispNewBranch){
578 $type = "branch";
579 }else{
580 $type = "freeze";
581 }
583 /* Check branch name */
584 $name = $_POST['BranchName'];
585 $is_ok = true;
586 $smarty->assign("BranchName",$name);
587 $base= $this->fai_base;
589 /* Check used characters */
590 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
591 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
592 $is_ok = false;
593 }
595 /* Check if this name is already in use */
596 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
597 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
598 $is_ok = false;
599 }
601 if($is_ok){
603 if(session::is_set('LASTPOST')){
604 $LASTPOST = session::get('LASTPOST');
605 }else{
606 $LASTPOST = array();
607 }
608 $LASTPOST['base'] = $base;
609 $LASTPOST['type'] = $type;
610 session::set('LASTPOST',$LASTPOST);
611 $smarty->assign("iframe", true);
612 $smarty->assign("plugID", $_GET['plug']);
613 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
614 return($display);
615 }
616 }
619 /****************
620 Create a new branch
621 ****************/
623 if(isset($_GET['PerformBranch'])){
625 if(!$this->acl_is_createable()){
626 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
627 }else{
629 /* In order to see error messages we have to reset the error handler.
630 Due to the exit();
631 */
632 restore_error_handler();
634 /* Create it know */
635 $this->dispNewBranch = false;
636 $this->dispNewFreeze = false;
638 $LASTPOST = session::get('LASTPOST');
639 $base = $LASTPOST['base'];
640 $_POST = session::get('LASTPOST');
641 $name = $_POST['BranchName'];
643 $type = $LASTPOST['type'];
644 $ldap = $this->config->get_ldap_link();
646 $baseToUse = $base;
647 if($this->fai_release != $this->fai_base){
648 $baseToUse = $this->fai_release;
649 }
651 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
653 $CurrentReleases = $this->getBranches();
654 $NewReleaseName = $name;
655 if(isset($CurrentReleases[$this->fai_release])) {
656 if($this->fai_release != $this->fai_base){
657 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
658 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
659 }else{
660 $NewReleaseName = $name;
661 }
662 }
664 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
665 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
667 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
668 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
670 /* Check if source depeartments exist */
671 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
672 $ldap->cd($this->config->current['BASE']);
673 $ldap->cat($dep);
674 if(!$ldap->count()){
675 $ldap->create_missing_trees($dep);
676 }
677 }
679 /* Print header to have styles included */
680 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
681 <html>
682 <head>
683 <title></title>
684 <style type="text/css">@import url("themes/default/style.css");</style>
685 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
686 </head>
687 <body style="background: none;margin:3px;color:black">
688 ';
690 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
692 /* Duplicate group application releases
693 */
694 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
696 /* Duplicate applications
697 */
698 $ldap->cat($appsrc,array("dn")) ;
699 if($ldap->count()){
700 $ldap->cd ($appdst);
701 $ldap->recursive_remove();
702 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
703 }
705 /* Duplicate mime types
706 */
707 $ldap->cat($mimesrc,array("dn")) ;
708 if($ldap->count()){
709 $ldap->cd ($mimedst);
710 $ldap->recursive_remove();
711 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
712 }
714 $attr = array();
715 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
716 $attr['ou'] = $name;
717 $attr['FAIstate'] = $type;
718 $ldap->cd($this->config->current['BASE']);
719 $ldap->cd("ou=".$name.",".$baseToUse);
720 $ldap->cat("ou=".$name.",".$baseToUse);
721 if($ldap->count()){
722 $ldap->modify($attr);
723 }else{
724 $ldap->add($attr);
725 }
727 /* Duplicate fai objects
728 */
729 // $ldap->cd ("ou=".$name.",".$baseToUse);
730 // $ldap->recursive_remove();
731 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
733 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
734 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
735 </form></div>";
737 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
739 /* Print footer to have valid html */
740 echo "</body></html>";
742 $this->dispNewFreeze = false;
744 /* Postcreate */
746 /* Assign possible attributes */
747 $this->lock_type = $type;
748 $this->lock_name = $name;
749 $this->lock_dn = $baseToUse;
750 $this->postcreate();
753 /* Send daemon event to reload the fai release database
754 */
755 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
756 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
757 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
758 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
759 $tmp = new $evt['CLASS_NAME']($this->config);
760 $tmp->set_type(TRIGGERED_EVENT);
761 $tmp->add_targets(array("GOsa"));
762 $o_queue = new gosaSupportDaemon();
763 if(!$o_queue->append($tmp)){
764 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
765 }
766 }
767 }else{
768 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
769 msg_dialog::display(_("Fatal error"),
770 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
771 FATAL_ERROR_DIALOG);
772 }
773 exit();
774 }
775 }
777 /****************
778 Display dialog to enter new Branch name
779 ****************/
781 /* Check if we have a post create method configured
782 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
783 */
784 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
785 if(($s_action == "branch_branch")||($this->dispNewBranch)){
786 if(!$this->acl_is_createable()){
787 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
788 }else{
789 $this->dispNewBranch=true;
790 $smarty->assign("iframe",false);
791 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
792 return($display);
793 }
794 }
795 }
798 /****************
799 Display dialog to enter new Freeze name
800 ****************/
802 /* Check if we have a post create method configured
803 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
804 */
805 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
806 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
807 if(!$this->acl_is_createable()){
808 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
809 }else{
810 $this->dispNewFreeze = true;
811 $smarty->assign("iframe",false);
812 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
813 return($display);
814 }
815 }
816 }
819 /****************
820 Create a new object
821 ****************/
823 $types = array( "new_partition" => "FAIpartitionTable",
824 "new_script" => "FAIscript",
825 "new_hook" => "FAIhook",
826 "new_variable" => "FAIvariable",
827 "new_template" => "FAItemplate",
828 "new_package" => "FAIpackageList");
829 $types_i18n = array( "new_partition" => _("partition table"),
830 "new_script" => _("script"),
831 "new_hook" => _("hook"),
832 "new_variable" => _("variable"),
833 "new_template" => _("template"),
834 "new_package" => _("package list"));
836 if(isset($types[$s_action])){
837 $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
838 if(preg_match("/c/",$acl)){
839 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
840 $this->dialog->parent = &$this;
841 }else{
842 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
843 }
844 }
846 /* New Profile */
847 if($s_action == "new_profile"){
848 $this->dn = "new" ;
850 $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
851 if(preg_match("/c/",$acl)){
852 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
853 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
854 $this->dialog->set_acl_base($this->base);
855 $this->dialog->parent = &$this;
857 $this->is_dialog = false;
858 }else{
859 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
860 }
861 }
864 /****************
865 Get from ask class name dialog
866 ****************/
868 if($s_action == "select_class_name_finished"){
869 $this->dialog->save_object();
870 if(count($this->dialog->check())!=0){
871 foreach($this->dialog->check() as $msg){
872 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
873 }
874 }elseif(isset($this->dialog->objectClass)){
875 $this->dn = "new" ;
876 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
877 $name = $this->dialog->save();
879 if(class_exists($a_setup[0])){
880 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
881 $this->dialog->set_acl_base($this->base);
882 $this->dialog->by_object[$a_setup[1]]->cn = $name;
883 $this->dialog->parent = &$this;
884 $this->is_dialog = true;
885 }
886 }
887 }
890 /****************
891 Cancel dialogs
892 ****************/
894 if(isset($_POST['edit_cancel'])){
895 $this->dialog=FALSE;
896 $this->is_dialog = false;
897 session::un_set('objectinfo');
898 $this->remove_lock();
899 }
902 /****************
903 Save sub dialogs
904 ****************/
906 /* This check if the given tab could be saved
907 * If it was possible to save it, remove dialog object.
908 * If it wasn't possible, show errors and keep dialog.
909 */
910 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
911 $this->dialog->save_object();
912 $msgs= $this->dialog->check();
913 if(count($msgs)!=0){
914 foreach($msgs as $msg){
915 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
916 }
917 }else{
918 $this->dialog->save();
919 FAI::save_release_changes_now();
920 if (!isset($_POST['edit_apply'])){
921 $this->remove_lock();
922 $this->dialog=FALSE;
923 $this->is_dialog=false;
924 session::un_set('objectinfo');
925 }else{
927 /* Reinitialize tab */
928 if($this->dialog instanceof tabs){
929 $this->dialog->re_init();
930 }
931 }
932 }
933 }
936 /****************
937 Display currently open dialog
938 ****************/
940 /* If dialog is set, but $this->is_dialog==false, then
941 * only the "abort" button is shown, this are dialogs that must not be saved.
942 * If is_dialog == true, we are currently editing tab objects.
943 * Here we need both, save and cancel
944 */
946 if(is_object($this->dialog)){
947 $display .= $this->dialog->execute();
948 /* Don't show buttons if tab dialog requests this */
950 if(isset($this->dialog->current)){
952 $obj = $this->dialog->by_object[$this->dialog->current];
954 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
956 $display.= "<p style=\"text-align:right\">\n";
957 if(!$this->no_save){
958 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
959 $display.= " \n";
960 if ($this->dn != "new"){
961 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
962 $display.= " \n";
963 }
964 }
965 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
966 $display.= "</p>";
967 }elseif(!isset($this->dialog->current)){
968 $display.= "<p style=\"text-align:right\">\n";
969 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
970 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
971 $display.= "</p>";
972 }
973 }else{
974 $display.= "<p style=\"text-align:right\">\n";
975 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
976 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
977 $display.= "</p>";
979 }
980 return($display);
981 }
984 /****************
985 Dialog display
986 ****************/
988 /* Check if there is a snapshot dialog open */
989 $base = $this->fai_base;
990 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
991 return($str);
992 }
994 /* Display dialog with system list */
995 $this->reload();
996 $this->DivListFai->parent = &$this;
997 $this->DivListFai->execute();
998 $this->DivListFai->setEntries($this->objects);
999 return($this->DivListFai->Draw());
1000 }
1003 /* Return departments, that will be included within snapshot detection */
1004 function get_used_snapshot_bases()
1005 {
1006 $tmp = array();
1007 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
1008 foreach($types as $type){
1009 $tmp[] = get_ou($type).$this->fai_release;
1010 }
1011 return($tmp);
1012 }
1015 /* Get available branches for current base */
1016 function getBranches($base = false,$prefix = "")
1017 {
1018 $ret = array("/"=>$this->fai_base);
1019 $ldap = $this->config->get_ldap_link();
1020 if(!$base){
1021 $base = $this->fai_base;
1022 }
1023 $tmp = FAI::get_all_releases_from_base($base,true);
1024 foreach($tmp as $dn => $name){
1025 $ret[$name]=$dn;
1026 }
1027 ksort($ret);
1028 $ret = array_flip($ret);
1030 return ($ret);
1031 }
1034 function list_get_selected_items()
1035 {
1036 $ids = array();
1037 foreach($_POST as $name => $value){
1038 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1039 $id = preg_replace("/^item_selected_/","",$name);
1040 $ids[$id] = $id;
1041 }
1042 }
1043 return($ids);
1044 }
1047 /* reload list of objects */
1048 function reload()
1049 {
1050 /* Variable initialisation */
1051 $str = "";
1052 $Regex = $this->DivListFai->Regex;
1053 $this->objects = array();
1055 /* Get base */
1056 $base = $this->fai_base;
1057 if($this->fai_release != $this->fai_base){
1058 $br = $this->getBranches();
1059 if(isset($br[$this->fai_release])){
1060 $base = $this->fai_release;
1061 }else{
1062 $base = $this->fai_base;
1063 }
1064 }
1065 $this->base = $base;
1066 $this->set_acl_base($this->base);
1068 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1070 /* Create a new list of FAI object
1071 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1072 */
1073 $ObjectTypes = array(
1074 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1075 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1076 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1077 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1078 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1079 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1080 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1082 $filter = "";
1083 foreach($ObjectTypes as $key => $data){
1084 if($this->DivListFai->$data['CHKBOX']){
1085 $filter.= "(objectClass=".$key.")";
1086 }
1087 }
1088 $filter = "(&(|".$filter.")(cn=$Regex))";
1090 /* Get resolved release dependencies */
1091 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1093 /* Ge listed ldap objects */
1094 $ldap = $this->config->get_ldap_link();
1095 $ldap->cd($this->config->current['BASE']);
1097 foreach($tmp as $entry){
1099 /* Get some more informations about the object */
1100 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1101 $object = $ldap->fetch();
1103 /* Walk through possible types */
1104 foreach($ObjectTypes as $type => $rest){
1106 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1108 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1110 /* Prepare object */
1111 unset($object['objectClass']['count']);
1112 if(!isset($object['description'][0])){
1113 $object['description'][0]="";
1114 }
1116 /* Clean up object informations */
1117 $obj = array();
1118 $obj['cn'] = $object['cn'][0];
1119 $obj['dn'] = $object['dn'];
1120 $obj['acl'] = $acl;
1121 $obj['class'] = $rest ['ACL'];
1122 $obj['FAIstate'] = $entry['FAIstate'];
1123 $obj['description'] = $object['description'][0];
1124 $obj['objectClass'] = $object['objectClass'];
1126 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1127 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1128 }
1129 }
1130 }
1132 ksort($this->objects);
1133 reset ($this->objects);
1135 /* use numeric index, thats a bit more secure */
1136 $tmp0 = array();
1137 foreach($this->objects as $obj){
1138 $tmp0[]= $obj;
1139 }
1140 $this->objects = array();
1141 $this->objects = $tmp0;
1142 }
1144 function remove_lock()
1145 {
1146 if (isset($this->dn)){
1147 del_lock ($this->dn);
1148 }
1149 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1150 del_lock ($this->dns);
1151 }
1152 }
1154 function get_type($array){
1155 if(in_array("FAIpartitionTable",$array['objectClass'])){
1156 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1157 }
1158 if(in_array("FAIscript",$array['objectClass'])){
1159 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1160 }
1161 if(in_array("FAItemplate",$array['objectClass'])){
1162 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1163 }
1164 if(in_array("FAIhook",$array['objectClass'])){
1165 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1166 }
1167 if(in_array("FAIvariable",$array['objectClass'])){
1168 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1169 }
1170 if(in_array("FAIprofile",$array['objectClass'])){
1171 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1172 }
1174 if(in_array("FAIpackageList",$array['objectClass'])){
1175 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1176 }
1177 }
1179 function CheckNewBranchName($name,$base)
1180 {
1181 $f = $this->fai_release;
1182 if($name == ""){
1183 return(false);
1184 }elseif(in_array($name,$this->getBranches($f))) {
1185 return(false);
1186 }elseif(tests::is_department_name_reserved($name,$base)){
1187 return(false);
1188 }
1189 return(true);
1190 }
1192 function save_object()
1193 {
1194 $this->DivListFai->save_object();
1196 /* Get posted release */
1197 $r_releases = array_flip($this->getBranches());
1198 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1200 /* Ensure that we have a valid release selected */
1201 if(!isset($r_releases[get_post('fai_release')])){
1202 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1203 $_POST = array();
1204 $plug =$_GET['plug'];
1205 $_GET = array("plug" => $plug);
1206 $this->fai_release = $this->fai_base;
1207 }else{
1208 $this->fai_release = $r_releases[get_post('fai_release')];
1209 }
1211 $fai_filter = session::get("fai_filter");
1212 $fai_filter['fai_release'] = $this->fai_release;
1213 session::set("fai_filter",$fai_filter);
1214 }
1216 if(is_object($this->CopyPasteHandler)){
1217 $this->CopyPasteHandler->save_object();
1218 }
1219 }
1222 function copyPasteHandling_from_queue($s_action,$s_entry)
1223 {
1224 /* Check if Copy & Paste is disabled */
1225 if(!is_object($this->CopyPasteHandler)){
1226 return("");
1227 }
1229 $ui = get_userinfo();
1231 /* Add a single entry to queue */
1232 if($s_action == "copy"){
1234 /* Cleanup object queue */
1235 $this->CopyPasteHandler->cleanup_queue();
1236 $entry = $this->objects[$s_entry];
1237 $a_setup = $this->get_type($entry);
1238 $dn = $entry['dn'];
1240 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1241 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1242 }
1243 }
1245 /* Add entries to queue */
1246 if($s_action == "copy_multiple"){
1248 /* Cleanup object queue */
1249 $this->CopyPasteHandler->cleanup_queue();
1251 /* Add new entries to CP queue */
1252 foreach($this->list_get_selected_items() as $id){
1254 /* Cleanup object queue */
1255 $entry = $this->objects[$id];
1256 $a_setup = $this->get_type($entry);
1257 $dn = $entry['dn'];
1259 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1260 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1261 }
1262 }
1263 }
1265 /* Start pasting entries */
1266 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1267 $this->start_pasting_copied_objects = TRUE;
1268 }
1270 /* Return C&P dialog */
1271 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1273 /* Get dialog */
1274 $this->CopyPasteHandler->SetVar("parent",$this);
1275 $data = $this->CopyPasteHandler->execute();
1277 FAI::save_release_changes_now();
1279 /* Return dialog data */
1280 if(!empty($data)){
1281 return($data);
1282 }
1283 }
1285 /* Automatically disable status for pasting */
1286 if(!$this->CopyPasteHandler->entries_queued()){
1287 $this->start_pasting_copied_objects = FALSE;
1288 }
1289 return("");
1290 }
1293 /* Check if the given FAI class is used in this release
1294 */
1295 static function check_class_name($oc,$name,$dn)
1296 {
1297 $base = FAI::get_release_dn($dn);
1298 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1299 $delete = array();
1300 $used = array();
1301 foreach($res as $object){
1302 $used[$object['cn'][0]]= $object['cn'][0];
1303 }
1304 return($used);
1305 }
1308 /* Return plugin informations for acl handling */
1309 static function plInfo()
1310 {
1311 return (array(
1312 "plShortName" => _("FAI releases"),
1313 "plDescription" => _("FAI release management"),
1314 "plSelfModify" => FALSE,
1315 "plDepends" => array(),
1316 "plPriority" => 0,
1317 "plSection" => array("administration"),
1318 "plCategory" => array("fai"=> array("description" => _("FAI"),
1319 "objectClass" => "FAIclass")),
1320 "plProvidedAcls"=> array()));
1321 }
1322 }
1323 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1324 ?>