3e495a9d5afe58c1e00846d2cbb04b9cb9a0ce80
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 = TRUE;
52 var $no_save;
53 var $fai_base ="";
54 var $fai_release ="";
56 var $acl_module = array("fai");
58 /* construction/reconstruction
59 */
60 function faiManagement (&$config, $ui)
61 {
62 /* Set defaults */
63 $this->dn = "";
64 $this->config = $config;
65 $this->ui = $ui;
67 /* Creat dialog object */
68 $this->DivListFai = new divListFai($this->config,$this);
70 /* Copy & Paste handler */
71 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
72 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
73 }
75 /* Set default release */
76 $this->fai_base = get_ou("faiou").$this->config->current['BASE'];
77 if(!session::is_set("fai_filter")){
78 session::set("fai_filter",array("fai_release" => $this->fai_base));
79 }
81 $fai_filter = session::get("fai_filter");
82 $this->fai_release = $fai_filter['fai_release'];
83 }
85 function execute()
86 {
87 /* Call parent execute */
88 plugin::execute();
90 /* Initialise vars and smarty */
91 $smarty = get_smarty();
92 $smarty->assign("BranchName","");
94 $display = "";
95 $s_action = "";
96 $s_entry = "";
97 $no_save = FALSE; // hide Apply / Save buttons
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 "/^remove_multiple_fai_objects/" => "del_multiple");
121 foreach($_POST as $name => $value){
122 foreach($posts as $reg => $act ){
123 if(preg_match($reg,$name)){
124 $s_action = $act;
125 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
126 $s_entry = preg_replace("/_.*$/","",$s_entry);
127 }
128 }
129 if(preg_match("/^entry_edit_.*/",$name)){
130 $s_entry = preg_replace("/^entry_edit_/","",$name);
131 $s_entry = preg_replace("/_.*$/","",$s_entry);
132 $s_action = "edit";
133 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
134 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
135 $s_entry = preg_replace("/_.*$/","",$s_entry);
136 $s_action = "edit";
137 $no_save = TRUE;
138 }elseif(preg_match("/^entry_delete_.*/",$name)){
139 $s_entry = preg_replace("/^entry_delete_/","",$name);
140 $s_entry = preg_replace("/_.*$/","",$s_entry);
141 $s_action = "delete";
142 }
143 }
145 if(isset($_GET['edit_entry'])){
146 $s_entry = $_GET['edit_entry'];
147 $s_action = "edit";
148 }
150 if(isset($_GET['edit_freeze_entry'])){
151 $s_entry = $_GET['edit_freeze_entry'];
152 $s_action = "edit";
153 $no_save = TRUE;
154 }
156 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
157 $s_action = "freeze_branch";
158 }
159 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
160 $s_action = "branch_branch";
161 }
162 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
163 $s_action = "remove_branch";
164 }
166 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
167 $this->dispNewBranch = false;
168 $this->dispNewFreeze = false;
169 }
172 $type_acl_mapping = array(
173 "FAIpartitionTable" => "faiPartitionTable",
174 "FAIpackageList" => "faiPackage",
175 "FAIscript" => "faiScript",
176 "FAIvariable" => "faiVariable",
177 "FAIhook" => "faiHook",
178 "FAIprofile" => "faiProfile",
179 "FAItemplate" => "faiTemplate");
182 /* handle C&P from layers menu */
183 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
184 $s_action = "copy_multiple";
185 }
186 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
187 $s_action = "cut_multiple";
188 }
189 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
190 $s_action = "editPaste";
191 }
193 /* Create options */
194 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
195 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
196 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
197 }
199 /* handle remove from layers menu */
200 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
201 $s_action = "del_multiple";
202 }
205 if(!empty($s_action)){
206 $this->no_save = $no_save;
207 }
209 /********************
210 Copy & Paste
211 ********************/
213 /* Display the copy & paste dialog, if it is currently open */
214 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
215 if($ret){
216 return($ret);
217 }
220 /****************
221 Delete confirme dialog
222 ****************/
224 if ($s_action=="delete"){
226 /* Get 'dn' from posted termlinst */
227 $this->dn= $this->objects[$s_entry]['dn'];
229 /* Load permissions for selected 'dn' and check if
230 we're allowed to remove this 'dn' */
231 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
232 if(preg_match("/d/",$acl)){
234 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
235 if (($user= get_lock($this->dn)) != ""){
236 return(gen_locked_message ($user, $this->dn));
237 }
239 /* Lock the current entry, so nobody will edit it during deletion */
240 add_lock ($this->dn, $this->ui->dn);
241 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
242 $smarty->assign("multiple", false);
243 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
244 } else {
246 /* Obviously the user isn't allowed to delete. Show message and clean session. */
247 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
248 }
249 }
252 /********************
253 Delete MULTIPLE entries requested, display confirm dialog
254 ********************/
256 if ($s_action=="del_multiple"){
257 $this->dns = array();
258 $ids = $this->list_get_selected_items();
260 if(count($ids)){
262 $errors = "";
263 foreach($ids as $id){
264 $dn = $this->objects[$id]['dn'];
265 $cn = $this->objects[$id]['cn'];
266 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
267 $this->dns[$id] = $dn;
268 }else{
269 $errors .= $cn.", ";
270 }
271 }
272 if ($user= get_multiple_locks($this->dns)){
273 return(gen_locked_message($user,$this->dns));
274 }
276 if($errors != ""){
277 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
278 "<br><br>".trim($errors,", ")),INFO_DIALOG);
279 }
281 if(count($this->dns)){
283 $dns_names = array();
284 foreach($this->dns as $dn){
285 add_lock ($dn, $this->ui->dn);
286 $dns_names[] = @LDAP::fix($dn);
287 }
289 /* Lock the current entry, so nobody will edit it during deletion */
290 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
291 $smarty->assign("multiple", true);
292 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
293 }
294 }
295 }
298 /********************
299 Delete MULTIPLE entries confirmed
300 ********************/
302 /* Confirmation for deletion has been passed. Users should be deleted. */
303 if (isset($_POST['delete_multiple_fai_object_confirm'])){
305 /* Find out more about the object type */
306 $ldap = $this->config->get_ldap_link();
308 /* Remove user by user and check acls before removeing them */
309 foreach($this->dns as $key => $dn){
311 $ldap->cat($dn, array('objectClass'));
312 $attrs = $ldap->fetch();
313 $type = $this->get_type($attrs);
315 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
316 if(preg_match("/d/",$acl)){
318 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
319 $this->dialog->parent = &$this;
320 $this->dialog->set_acl_base($dn);
321 $this->dialog->by_object[$type[1]]->remove_from_parent ();
322 unset ($this->dialog);
323 $this->dialog= FALSE;
324 $to_del = FAI::clean_up_releases($dn);
325 FAI::save_release_changes_now();
327 foreach($to_del as $dn){
328 $ldap->rmdir_recursive($dn);
329 }
331 } else {
333 /* Normally this shouldn't be reached, send some extra
334 logs to notify the administrator */
335 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
336 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
337 }
338 }
340 /* Remove lock file after successfull deletion */
341 $this->remove_lock();
342 $this->dns = array();
343 }
346 /********************
347 Delete MULTIPLE entries Canceled
348 ********************/
350 /* Remove lock */
351 if(isset($_POST['delete_multiple_fai_object_cancel'])){
352 $this->dns = array();
353 $this->remove_lock();
354 }
357 /****************
358 Delete aborted
359 ****************/
361 /* Delete canceled? */
362 if (isset($_POST['delete_cancel'])){
363 $this->remove_lock();
364 }
367 /****************
368 Delete confirmed
369 ****************/
371 /* Deltetion was confirmed, so delete this entry
372 */
373 if (isset($_POST['delete_terminal_confirm'])){
375 /* Some nice guy may send this as POST, so we've to check
376 for the permissions again. */
378 /* Find out more about the object type */
379 $ldap = $this->config->get_ldap_link();
380 $ldap->cat($this->dn, array('objectClass'));
381 if($ldap->count()){
382 $attrs = $ldap->fetch();
383 $type = $this->get_type($attrs);
385 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
386 if(preg_match("/d/",$acl)){
388 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
389 $this->dialog->set_acl_base($this->dn);
390 $this->dialog->parent = &$this;
391 $this->dialog->by_object[$type[1]]->remove_from_parent ();
392 unset ($this->dialog);
393 $this->dialog= FALSE;
394 $to_del = FAI::clean_up_releases($this->dn);
395 FAI::save_release_changes_now();
397 foreach($to_del as $dn){
398 $ldap->rmdir_recursive($dn);
399 }
401 } else {
403 /* Normally this shouldn't be reached, send some extra
404 logs to notify the administrator */
405 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
406 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
407 }
409 }else{
410 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
411 }
413 /* Remove lock file after successfull deletion */
414 $this->remove_lock();
415 }
418 /****************
419 Edit entry
420 ****************/
422 if(($s_action == "edit") && (!isset($this->dialog->config))){
423 $entry = $this->objects[$s_entry];
424 $a_setup = $this->get_type($entry);
425 $this->dn = $entry['dn'];
427 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
428 if (($user= get_lock($this->dn)) != ""){
429 return(gen_locked_message ($user, $this->dn));
430 }
431 add_lock ($this->dn, $this->ui->dn);
433 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
434 $this->dialog->parent = &$this;
435 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];;
436 $this->dialog->set_acl_base($this->dn);
437 $this->is_dialog = true;
439 if(preg_match("/^freeze/", $entry['FAIstate']) || $this->no_save){
440 # $this->dialog->set_acl_base("freezed") ;
441 }
442 session::set('objectinfo',$this->dn);
443 }
446 /* Branch handling
447 09.01.2006
448 */
450 /****************
451 Remove branch
452 ****************/
454 /* Remove branch
455 */
456 if($s_action == "remove_branch"){
457 $base= $this->fai_release;
459 /* Check if we have a post remove method configured
460 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
461 */
462 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
463 /* Load permissions for selected 'dn' and check if
464 we're allowed to remove this 'dn' */
465 if($this->acl_is_removeable()){
466 $smarty->assign("release_hidden",base64_encode($this->fai_release));
467 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
468 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
469 } else {
470 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
471 }
472 }
473 }
476 /****************
477 Remove branch confirmed
478 ****************/
480 if(isset($_POST['delete_branch_confirm'])){
482 /* Check if we have a post remove method configured
483 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
484 */
485 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
487 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
488 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
489 }else{
491 $bb = $this->fai_release;
492 if(!isset($ldap)){
493 $ldap = $this->config->get_ldap_link();
494 }
496 $br = $this->getBranches();
498 if(isset($br[$bb]) && $this->acl_is_removeable()){
499 $name = $br[$bb];
501 $ldap->cd($bb);
502 $ldap->recursive_remove();
503 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
504 $ldap->recursive_remove();
505 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('mimetypeou'), $bb));
506 $ldap->recursive_remove();
508 /* Search for all groups with configured application menus.
509 - First search all groups, to ensure that we only remove entries form whithin groups.
510 - The search für menu configuration for the specified release and collect all those dns.
511 - Remove entries
512 */
513 $release_ou = preg_replace("/".normalizePreg(get_ou("faiou")).".*$/","",$bb);
514 $ldap->cd($this->config->current['BASE']);
515 $ldap->search("(objectClass=posixGroup)",array("dn"));
517 /* Collect all group dns
518 */
519 $groups = array();
520 while($attrs = $ldap->fetch()){
521 $groups[] = $attrs['dn'];
522 }
524 /* Collect all group menu release dns that match the release we have removed
525 */
526 $dns = array();
527 foreach($groups as $dn){
528 $ldap->cd($dn);
529 $ldap->search("(objectClass=FAIbranch)",array("dn"));
530 while($attrs = $ldap->fetch()){
531 if(preg_match("/^".normalizePreg($release_ou)."/",$attrs['dn'])){
532 $dns[] = $attrs['dn'];
533 }
534 }
535 }
537 /* Finally remove collected release dns
538 */
539 foreach($dns as $dn){
540 $ldap->cd($dn);
541 $ldap->recursive_remove();
542 }
544 /* Post remove */
545 $this->fai_release = $this->fai_base;
546 $this->lock_name = $name;
547 $this->lock_dn = $bb;
548 $this->postremove();
550 $fai_filter = session::get("fai_filter");
551 $fai_filter['fai_release'] = $this->fai_release;
552 session::set("fai_filter",$fai_filter);
554 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
555 }
556 }
557 }
558 }
561 /****************
562 Create a new branch "insert Name"
563 ****************/
565 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
566 session::set('LASTPOST',$_POST);
568 if($this->dispNewBranch){
569 $type = "branch";
570 }else{
571 $type = "freeze";
572 }
574 /* Check branch name */
575 $name = $_POST['BranchName'];
576 $is_ok = true;
577 $smarty->assign("BranchName",$name);
578 $base= $this->fai_base;
580 /* Check used characters */
581 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
582 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
583 $is_ok = false;
584 }
586 /* Check if this name is already in use */
587 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
588 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
589 $is_ok = false;
590 }
592 if($is_ok){
594 if(session::is_set('LASTPOST')){
595 $LASTPOST = session::get('LASTPOST');
596 }else{
597 $LASTPOST = array();
598 }
599 $LASTPOST['base'] = $base;
600 $LASTPOST['type'] = $type;
601 session::set('LASTPOST',$LASTPOST);
602 $smarty->assign("iframe", true);
603 $smarty->assign("plugID", $_GET['plug']);
604 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
605 return($display);
606 }
607 }
610 /****************
611 Create a new branch
612 ****************/
614 if(isset($_GET['PerformBranch'])){
616 if(!$this->acl_is_createable()){
617 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
618 }else{
620 /* In order to see error messages we have to reset the error handler.
621 Due to the exit();
622 */
623 restore_error_handler();
625 /* Create it know */
626 $this->dispNewBranch = false;
627 $this->dispNewFreeze = false;
629 $LASTPOST = session::get('LASTPOST');
630 $base = $LASTPOST['base'];
631 $_POST = session::get('LASTPOST');
632 $name = $_POST['BranchName'];
634 $type = $LASTPOST['type'];
635 $ldap = $this->config->get_ldap_link();
637 $baseToUse = $base;
638 if($this->fai_release != $this->fai_base){
639 $baseToUse = $this->fai_release;
640 }
642 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
644 $CurrentReleases = $this->getBranches();
645 $NewReleaseName = $name;
646 if(isset($CurrentReleases[$this->fai_release])) {
647 if($this->fai_release != $this->fai_base){
648 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
649 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
650 }else{
651 $NewReleaseName = $name;
652 }
653 }
655 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
656 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
658 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
659 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
661 /* Check if source depeartments exist */
662 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
663 $ldap->cd($this->config->current['BASE']);
664 $ldap->cat($dep);
665 if(!$ldap->count()){
666 $ldap->create_missing_trees($dep);
667 }
668 }
670 /* Print header to have styles included */
671 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
672 <html>
673 <head>
674 <title></title>
675 <style type="text/css">@import url("themes/default/style.css");</style>
676 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
677 </head>
678 <body style="background: none;margin:3px;color:black">
679 ';
681 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
683 /* Duplicate group application releases
684 */
685 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
687 /* Duplicate applications
688 */
689 $ldap->cat($appsrc,array("dn")) ;
690 if($ldap->count()){
691 $ldap->cd ($appdst);
692 $ldap->recursive_remove();
693 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
694 }
696 /* Duplicate mime types
697 */
698 $ldap->cat($mimesrc,array("dn")) ;
699 if($ldap->count()){
700 $ldap->cd ($mimedst);
701 $ldap->recursive_remove();
702 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
703 }
705 $attr = array();
706 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
707 $attr['ou'] = $name;
708 $attr['FAIstate'] = $type;
709 $ldap->cd($this->config->current['BASE']);
710 $ldap->cd("ou=".$name.",".$baseToUse);
711 $ldap->cat("ou=".$name.",".$baseToUse);
712 if($ldap->count()){
713 $ldap->modify($attr);
714 }else{
715 $ldap->add($attr);
716 }
718 /* Duplicate fai objects
719 */
720 // $ldap->cd ("ou=".$name.",".$baseToUse);
721 // $ldap->recursive_remove();
722 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
724 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
725 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
726 </form></div>";
728 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
730 /* Print footer to have valid html */
731 echo "</body></html>";
733 $this->dispNewFreeze = false;
735 /* Postcreate */
737 /* Assign possible attributes */
738 $this->lock_type = $type;
739 $this->lock_name = $name;
740 $this->lock_dn = $baseToUse;
741 $this->postcreate();
744 /* Send daemon event to reload the fai release database
745 */
746 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
747 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
748 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
749 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
750 $tmp = new $evt['CLASS_NAME']($this->config);
751 $tmp->set_type(TRIGGERED_EVENT);
752 $tmp->add_targets(array("GOsa"));
753 $o_queue = new gosaSupportDaemon();
754 if(!$o_queue->append($tmp)){
755 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
756 }
757 }
758 }else{
759 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
760 }
761 exit();
762 }
763 }
765 /****************
766 Display dialog to enter new Branch name
767 ****************/
769 /* Check if we have a post create method configured
770 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
771 */
772 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
773 if(($s_action == "branch_branch")||($this->dispNewBranch)){
774 if(!$this->acl_is_createable()){
775 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
776 }else{
777 $this->dispNewBranch=true;
778 $smarty->assign("iframe",false);
779 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
780 return($display);
781 }
782 }
783 }
786 /****************
787 Display dialog to enter new Freeze name
788 ****************/
790 /* Check if we have a post create method configured
791 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
792 */
793 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
794 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
795 if(!$this->acl_is_createable()){
796 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
797 }else{
798 $this->dispNewFreeze = true;
799 $smarty->assign("iframe",false);
800 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
801 return($display);
802 }
803 }
804 }
807 /****************
808 Create a new object
809 ****************/
811 $types = array( "new_partition" => "FAIpartitionTable",
812 "new_script" => "FAIscript",
813 "new_hook" => "FAIhook",
814 "new_variable" => "FAIvariable",
815 "new_template" => "FAItemplate",
816 "new_package" => "FAIpackageList");
817 $types_i18n = array( "new_partition" => _("partition table"),
818 "new_script" => _("script"),
819 "new_hook" => _("hook"),
820 "new_variable" => _("variable"),
821 "new_template" => _("template"),
822 "new_package" => _("package list"));
824 if(isset($types[$s_action])){
825 $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
826 if(preg_match("/c/",$acl)){
827 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
828 $this->dialog->parent = &$this;
829 }else{
830 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
831 }
832 }
834 /* New Profile */
835 if($s_action == "new_profile"){
836 $this->dn = "new" ;
838 $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
839 if(preg_match("/c/",$acl)){
840 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
841 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
842 $this->dialog->set_acl_base($this->base);
843 $this->dialog->parent = &$this;
845 $this->is_dialog = false;
846 }else{
847 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
848 }
849 }
852 /****************
853 Get from ask class name dialog
854 ****************/
856 if($s_action == "select_class_name_finished"){
857 $this->dialog->save_object();
858 if(count($this->dialog->check())!=0){
859 foreach($this->dialog->check() as $msg){
860 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
861 }
862 }elseif(isset($this->dialog->objectClass)){
863 $this->dn = "new" ;
864 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
865 $name = $this->dialog->save();
867 if(class_exists($a_setup[0])){
868 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
869 $this->dialog->set_acl_base($this->base);
870 $this->dialog->by_object[$a_setup[1]]->cn = $name;
871 $this->dialog->parent = &$this;
872 $this->is_dialog = true;
873 }
874 }
875 }
878 /****************
879 Cancel dialogs
880 ****************/
882 if(isset($_POST['edit_cancel'])){
883 $this->dialog=FALSE;
884 $this->is_dialog = false;
885 session::un_set('objectinfo');
886 $this->remove_lock();
887 }
890 /****************
891 Save sub dialogs
892 ****************/
894 /* This check if the given tab could be saved
895 * If it was possible to save it, remove dialog object.
896 * If it wasn't possible, show errors and keep dialog.
897 */
898 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
899 $this->dialog->save_object();
900 $msgs= $this->dialog->check();
901 if(count($msgs)!=0){
902 foreach($msgs as $msg){
903 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
904 }
905 }else{
906 $this->dialog->save();
907 FAI::save_release_changes_now();
908 if (!isset($_POST['edit_apply'])){
909 $this->remove_lock();
910 $this->dialog=FALSE;
911 $this->is_dialog=false;
912 session::un_set('objectinfo');
913 }else{
915 /* Reinitialize tab */
916 if($this->dialog instanceof tabs){
917 $this->dialog->re_init();
918 }
919 }
920 }
921 }
924 /****************
925 Display currently open dialog
926 ****************/
928 /* If dialog is set, but $this->is_dialog==false, then
929 * only the "abort" button is shown, this are dialogs that must not be saved.
930 * If is_dialog == true, we are currently editing tab objects.
931 * Here we need both, save and cancel
932 */
934 if(is_object($this->dialog)){
935 $display .= $this->dialog->execute();
936 /* Don't show buttons if tab dialog requests this */
938 if(isset($this->dialog->current)){
940 $obj = $this->dialog->by_object[$this->dialog->current];
942 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
944 $display.= "<p style=\"text-align:right\">\n";
945 if(!$this->no_save){
946 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
947 $display.= " \n";
948 if ($this->dn != "new"){
949 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
950 $display.= " \n";
951 }
952 }
953 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
954 $display.= "</p>";
955 }elseif(!isset($this->dialog->current)){
956 $display.= "<p style=\"text-align:right\">\n";
957 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
958 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
959 $display.= "</p>";
960 }
961 }else{
962 $display.= "<p style=\"text-align:right\">\n";
963 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
964 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
965 $display.= "</p>";
967 }
968 return($display);
969 }
972 /****************
973 Dialog display
974 ****************/
976 /* Check if there is a snapshot dialog open */
977 $base = $this->fai_base;
978 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
979 return($str);
980 }
982 /* Display dialog with system list */
983 $this->reload();
984 $this->DivListFai->parent = &$this;
985 $this->DivListFai->execute();
986 $this->DivListFai->setEntries($this->objects);
987 return($this->DivListFai->Draw());
988 }
991 /* Return departments, that will be included within snapshot detection */
992 function get_used_snapshot_bases()
993 {
994 $tmp = array();
995 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
996 foreach($types as $type){
997 $tmp[] = get_ou($type).$this->fai_release;
998 }
999 return($tmp);
1000 }
1003 /* Get available branches for current base */
1004 function getBranches($base = false,$prefix = "")
1005 {
1006 $ret = array("/"=>$this->fai_base);
1007 $ldap = $this->config->get_ldap_link();
1008 if(!$base){
1009 $base = $this->fai_base;
1010 }
1011 $tmp = FAI::get_all_releases_from_base($base,true);
1012 foreach($tmp as $dn => $name){
1013 $ret[$name]=$dn;
1014 }
1015 ksort($ret);
1016 $ret = array_flip($ret);
1018 return ($ret);
1019 }
1022 function list_get_selected_items()
1023 {
1024 $ids = array();
1025 foreach($_POST as $name => $value){
1026 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1027 $id = preg_replace("/^item_selected_/","",$name);
1028 $ids[$id] = $id;
1029 }
1030 }
1031 return($ids);
1032 }
1035 /* reload list of objects */
1036 function reload()
1037 {
1038 /* Variable initialisation */
1039 $str = "";
1040 $Regex = $this->DivListFai->Regex;
1041 $this->objects = array();
1043 /* Get base */
1044 $base = $this->fai_base;
1045 if($this->fai_release != $this->fai_base){
1046 $br = $this->getBranches();
1047 if(isset($br[$this->fai_release])){
1048 $base = $this->fai_release;
1049 }else{
1050 $base = $this->fai_base;
1051 }
1052 }
1053 $this->base = $base;
1054 $this->set_acl_base($this->base);
1056 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1058 /* Create a new list of FAI object
1059 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1060 */
1061 $ObjectTypes = array(
1062 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1063 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1064 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1065 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1066 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1067 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1068 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1070 $filter = "";
1071 foreach($ObjectTypes as $key => $data){
1072 if($this->DivListFai->$data['CHKBOX']){
1073 $filter.= "(objectClass=".$key.")";
1074 }
1075 }
1076 $filter = "(&(|".$filter.")(cn=$Regex))";
1078 /* Get resolved release dependencies */
1079 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1081 /* Ge listed ldap objects */
1082 $ldap = $this->config->get_ldap_link();
1083 $ldap->cd($this->config->current['BASE']);
1085 foreach($tmp as $entry){
1087 /* Get some more informations about the object */
1088 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1089 $object = $ldap->fetch();
1091 /* Walk through possible types */
1092 foreach($ObjectTypes as $type => $rest){
1094 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1096 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1098 /* Prepare object */
1099 unset($object['objectClass']['count']);
1100 if(!isset($object['description'][0])){
1101 $object['description'][0]="";
1102 }
1104 /* Clean up object informations */
1105 $obj = array();
1106 $obj['cn'] = $object['cn'][0];
1107 $obj['dn'] = $object['dn'];
1108 $obj['acl'] = $acl;
1109 $obj['class'] = $rest ['ACL'];
1110 $obj['FAIstate'] = $entry['FAIstate'];
1111 $obj['description'] = $object['description'][0];
1112 $obj['objectClass'] = $object['objectClass'];
1114 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1115 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1116 }
1117 }
1118 }
1120 ksort($this->objects);
1121 reset ($this->objects);
1123 /* use numeric index, thats a bit more secure */
1124 $tmp0 = array();
1125 foreach($this->objects as $obj){
1126 $tmp0[]= $obj;
1127 }
1128 $this->objects = array();
1129 $this->objects = $tmp0;
1130 }
1132 function remove_lock()
1133 {
1134 if (isset($this->dn)){
1135 del_lock ($this->dn);
1136 }
1137 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1138 del_lock ($this->dns);
1139 }
1140 }
1142 function get_type($array){
1143 if(in_array("FAIpartitionTable",$array['objectClass'])){
1144 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1145 }
1146 if(in_array("FAIscript",$array['objectClass'])){
1147 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1148 }
1149 if(in_array("FAItemplate",$array['objectClass'])){
1150 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1151 }
1152 if(in_array("FAIhook",$array['objectClass'])){
1153 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1154 }
1155 if(in_array("FAIvariable",$array['objectClass'])){
1156 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1157 }
1158 if(in_array("FAIprofile",$array['objectClass'])){
1159 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1160 }
1162 if(in_array("FAIpackageList",$array['objectClass'])){
1163 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1164 }
1165 }
1167 function CheckNewBranchName($name,$base)
1168 {
1169 $f = $this->fai_release;
1170 if($name == ""){
1171 return(false);
1172 }elseif(in_array($name,$this->getBranches($f))) {
1173 return(false);
1174 }elseif(tests::is_department_name_reserved($name,$base)){
1175 return(false);
1176 }
1177 return(true);
1178 }
1180 function save_object()
1181 {
1182 $this->DivListFai->save_object();
1184 /* Get posted release */
1185 $r_releases = array_flip($this->getBranches());
1186 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1188 /* Ensure that we have a valid release selected */
1189 if(!isset($r_releases[get_post('fai_release')])){
1190 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1191 $_POST = array();
1192 $plug =$_GET['plug'];
1193 $_GET = array("plug" => $plug);
1194 $this->fai_release = $this->fai_base;
1195 }else{
1196 $this->fai_release = $r_releases[get_post('fai_release')];
1197 }
1199 $fai_filter = session::get("fai_filter");
1200 $fai_filter['fai_release'] = $this->fai_release;
1201 session::set("fai_filter",$fai_filter);
1202 }
1204 if(is_object($this->CopyPasteHandler)){
1205 $this->CopyPasteHandler->save_object();
1206 }
1207 }
1210 function copyPasteHandling_from_queue($s_action,$s_entry)
1211 {
1212 /* Check if Copy & Paste is disabled */
1213 if(!is_object($this->CopyPasteHandler)){
1214 return("");
1215 }
1217 $ui = get_userinfo();
1219 /* Add a single entry to queue */
1220 if($s_action == "copy"){
1222 /* Cleanup object queue */
1223 $this->CopyPasteHandler->cleanup_queue();
1224 $entry = $this->objects[$s_entry];
1225 $a_setup = $this->get_type($entry);
1226 $dn = $entry['dn'];
1228 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1229 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1230 }
1231 }
1233 /* Add entries to queue */
1234 if($s_action == "copy_multiple"){
1236 /* Cleanup object queue */
1237 $this->CopyPasteHandler->cleanup_queue();
1239 /* Add new entries to CP queue */
1240 foreach($this->list_get_selected_items() as $id){
1242 /* Cleanup object queue */
1243 $entry = $this->objects[$id];
1244 $a_setup = $this->get_type($entry);
1245 $dn = $entry['dn'];
1247 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1248 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1249 }
1250 }
1251 }
1253 /* Start pasting entries */
1254 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1255 $this->start_pasting_copied_objects = TRUE;
1256 }
1258 /* Return C&P dialog */
1259 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1261 /* Get dialog */
1262 $this->CopyPasteHandler->SetVar("parent",$this);
1263 $data = $this->CopyPasteHandler->execute();
1265 FAI::save_release_changes_now();
1267 /* Return dialog data */
1268 if(!empty($data)){
1269 return($data);
1270 }
1271 }
1273 /* Automatically disable status for pasting */
1274 if(!$this->CopyPasteHandler->entries_queued()){
1275 $this->start_pasting_copied_objects = FALSE;
1276 }
1277 return("");
1278 }
1281 /* Check if the given FAI class is used in this release
1282 */
1283 static function check_class_name($oc,$name,$dn)
1284 {
1285 $base = FAI::get_release_dn($dn);
1286 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1287 $delete = array();
1288 $used = array();
1289 foreach($res as $object){
1290 $used[$object['cn'][0]]= $object['cn'][0];
1291 }
1292 return($used);
1293 }
1296 /* Return plugin informations for acl handling */
1297 static function plInfo()
1298 {
1299 return (array(
1300 "plShortName" => _("FAI releases"),
1301 "plDescription" => _("FAI release management"),
1302 "plSelfModify" => FALSE,
1303 "plDepends" => array(),
1304 "plPriority" => 0,
1305 "plSection" => array("administration"),
1306 "plCategory" => array("fai"=> array("description" => _("FAI"),
1307 "objectClass" => "FAIclass")),
1308 "plProvidedAcls"=> array()));
1309 }
1310 }
1311 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1312 ?>