c71edce821a4dff7a8b5c7235cc226c2aaa14ea8
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")){
79 session::set("fai_filter",array("fai_release" => $this->fai_base));
80 }
82 $fai_filter = session::get("fai_filter");
83 $this->fai_release = $fai_filter['fai_release'];
84 }
86 function execute()
87 {
88 /* Call parent execute */
89 plugin::execute();
91 /* Initialise vars and smarty */
92 $smarty = get_smarty();
93 $smarty->assign("BranchName","");
95 $display = "";
96 $s_action = "";
97 $s_entry = "";
98 $no_save = FALSE; // hide Apply / Save buttons
100 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
101 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/"));
104 /****************
105 Handle posts
106 ****************/
108 /* Check ImageButton posts
109 * Create new tab ich new_xx is posted
110 */
111 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
112 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
113 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
114 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
115 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
116 "/edit_continue/"=>"select_class_name_finished",
117 "/^multiple_copy_fai/" => "copy_multiple",
118 "/^multiple_cut_fai/" => "cut_multiple",
119 "/^copy/" => "copy",
120 "/^remove_multiple_fai_objects/" => "del_multiple");
122 foreach($_POST as $name => $value){
123 foreach($posts as $reg => $act ){
124 if(preg_match($reg,$name)){
125 $s_action = $act;
126 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
127 $s_entry = preg_replace("/_.*$/","",$s_entry);
128 }
129 }
130 if(preg_match("/^entry_edit_.*/",$name)){
131 $s_entry = preg_replace("/^entry_edit_/","",$name);
132 $s_entry = preg_replace("/_.*$/","",$s_entry);
133 $s_action = "edit";
134 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
135 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
136 $s_entry = preg_replace("/_.*$/","",$s_entry);
137 $s_action = "edit";
138 $no_save = TRUE;
139 }elseif(preg_match("/^entry_delete_.*/",$name)){
140 $s_entry = preg_replace("/^entry_delete_/","",$name);
141 $s_entry = preg_replace("/_.*$/","",$s_entry);
142 $s_action = "delete";
143 }
144 }
146 if(isset($_GET['edit_entry'])){
147 $s_entry = $_GET['edit_entry'];
148 $s_action = "edit";
149 }
151 if(isset($_GET['edit_freeze_entry'])){
152 $s_entry = $_GET['edit_freeze_entry'];
153 $s_action = "edit";
154 $no_save = TRUE;
155 }
157 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
158 $s_action = "freeze_branch";
159 }
160 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
161 $s_action = "branch_branch";
162 }
163 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
164 $s_action = "remove_branch";
165 }
167 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
168 $this->dispNewBranch = false;
169 $this->dispNewFreeze = false;
170 }
173 $type_acl_mapping = array(
174 "FAIpartitionTable" => "faiPartitionTable",
175 "FAIpackageList" => "faiPackage",
176 "FAIscript" => "faiScript",
177 "FAIvariable" => "faiVariable",
178 "FAIhook" => "faiHook",
179 "FAIprofile" => "faiProfile",
180 "FAItemplate" => "faiTemplate");
183 /* handle C&P from layers menu */
184 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
185 $s_action = "copy_multiple";
186 }
187 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
188 $s_action = "cut_multiple";
189 }
190 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
191 $s_action = "editPaste";
192 }
194 /* Create options */
195 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
196 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
197 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
198 }
200 /* handle remove from layers menu */
201 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
202 $s_action = "del_multiple";
203 }
206 if(!empty($s_action)){
207 $this->no_save = $no_save;
208 }
210 /********************
211 Copy & Paste
212 ********************/
214 /* Display the copy & paste dialog, if it is currently open */
215 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
216 if($ret){
217 return($ret);
218 }
221 /****************
222 Delete confirme dialog
223 ****************/
225 if ($s_action=="delete"){
227 /* Get 'dn' from posted termlinst */
228 $this->dn= $this->objects[$s_entry]['dn'];
230 /* Load permissions for selected 'dn' and check if
231 we're allowed to remove this 'dn' */
232 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
233 if(preg_match("/d/",$acl)){
235 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
236 if (($user= get_lock($this->dn)) != ""){
237 return(gen_locked_message ($user, $this->dn));
238 }
240 /* Lock the current entry, so nobody will edit it during deletion */
241 add_lock ($this->dn, $this->ui->dn);
242 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
243 $smarty->assign("multiple", false);
244 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
245 } else {
247 /* Obviously the user isn't allowed to delete. Show message and clean session. */
248 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
249 }
250 }
253 /********************
254 Delete MULTIPLE entries requested, display confirm dialog
255 ********************/
257 if ($s_action=="del_multiple"){
258 $this->dns = array();
259 $ids = $this->list_get_selected_items();
261 if(count($ids)){
263 $errors = "";
264 foreach($ids as $id){
265 $dn = $this->objects[$id]['dn'];
266 $cn = $this->objects[$id]['cn'];
267 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
268 $this->dns[$id] = $dn;
269 }else{
270 $errors .= $cn.", ";
271 }
272 }
273 if ($user= get_multiple_locks($this->dns)){
274 return(gen_locked_message($user,$this->dns));
275 }
277 if($errors != ""){
278 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
279 "<br><br>".trim($errors,", ")),INFO_DIALOG);
280 }
282 if(count($this->dns)){
284 $dns_names = array();
285 foreach($this->dns as $dn){
286 add_lock ($dn, $this->ui->dn);
287 $dns_names[] = @LDAP::fix($dn);
288 }
290 /* Lock the current entry, so nobody will edit it during deletion */
291 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
292 $smarty->assign("multiple", true);
293 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
294 }
295 }
296 }
299 /********************
300 Delete MULTIPLE entries confirmed
301 ********************/
303 /* Confirmation for deletion has been passed. Users should be deleted. */
304 if (isset($_POST['delete_multiple_fai_object_confirm'])){
306 /* Find out more about the object type */
307 $ldap = $this->config->get_ldap_link();
309 /* Remove user by user and check acls before removeing them */
310 foreach($this->dns as $key => $dn){
312 $ldap->cat($dn, array('objectClass'));
313 $attrs = $ldap->fetch();
314 $type = $this->get_type($attrs);
316 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
317 if(preg_match("/d/",$acl)){
319 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
320 $this->dialog->parent = &$this;
321 $this->dialog->set_acl_base($dn);
322 $this->dialog->by_object[$type[1]]->remove_from_parent ();
323 unset ($this->dialog);
324 $this->dialog= FALSE;
325 $to_del = FAI::clean_up_releases($dn);
326 FAI::save_release_changes_now();
328 foreach($to_del as $dn){
329 $ldap->rmdir_recursive($dn);
330 }
332 } else {
334 /* Normally this shouldn't be reached, send some extra
335 logs to notify the administrator */
336 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
337 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
338 }
339 }
341 /* Remove lock file after successfull deletion */
342 $this->remove_lock();
343 $this->dns = array();
344 }
347 /********************
348 Delete MULTIPLE entries Canceled
349 ********************/
351 /* Remove lock */
352 if(isset($_POST['delete_multiple_fai_object_cancel'])){
353 $this->dns = array();
354 $this->remove_lock();
355 }
358 /****************
359 Delete aborted
360 ****************/
362 /* Delete canceled? */
363 if (isset($_POST['delete_cancel'])){
364 $this->remove_lock();
365 }
368 /****************
369 Delete confirmed
370 ****************/
372 /* Deltetion was confirmed, so delete this entry
373 */
374 if (isset($_POST['delete_terminal_confirm'])){
376 /* Some nice guy may send this as POST, so we've to check
377 for the permissions again. */
379 /* Find out more about the object type */
380 $ldap = $this->config->get_ldap_link();
381 $ldap->cat($this->dn, array('objectClass'));
382 if($ldap->count()){
383 $attrs = $ldap->fetch();
384 $type = $this->get_type($attrs);
386 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
387 if(preg_match("/d/",$acl)){
389 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
390 $this->dialog->set_acl_base($this->dn);
391 $this->dialog->parent = &$this;
392 $this->dialog->by_object[$type[1]]->remove_from_parent ();
393 unset ($this->dialog);
394 $this->dialog= FALSE;
395 $to_del = FAI::clean_up_releases($this->dn);
396 FAI::save_release_changes_now();
398 foreach($to_del as $dn){
399 $ldap->rmdir_recursive($dn);
400 }
402 } else {
404 /* Normally this shouldn't be reached, send some extra
405 logs to notify the administrator */
406 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
407 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
408 }
410 }else{
411 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
412 }
414 /* Remove lock file after successfull deletion */
415 $this->remove_lock();
416 }
419 /****************
420 Edit entry
421 ****************/
423 if(($s_action == "edit") && (!isset($this->dialog->config))){
424 $entry = $this->objects[$s_entry];
425 $a_setup = $this->get_type($entry);
426 $this->dn = $entry['dn'];
428 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
429 if (($user= get_lock($this->dn)) != ""){
430 return(gen_locked_message ($user, $this->dn));
431 }
432 add_lock ($this->dn, $this->ui->dn);
434 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
435 $this->dialog->parent = &$this;
436 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
437 $this->dialog->set_acl_base($this->dn);
438 $this->is_dialog = true;
439 session::set('objectinfo',$this->dn);
440 }
443 /* Branch handling
444 09.01.2006
445 */
447 /****************
448 Remove branch
449 ****************/
451 /* Remove branch
452 */
453 if($s_action == "remove_branch"){
454 $base= $this->fai_release;
456 /* Check if we have a post remove method configured
457 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
458 */
459 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
460 /* Load permissions for selected 'dn' and check if
461 we're allowed to remove this 'dn' */
462 if($this->acl_is_removeable()){
463 $smarty->assign("release_hidden",base64_encode($this->fai_release));
464 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
465 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
466 } else {
467 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
468 }
469 }
470 }
473 /****************
474 Remove branch confirmed
475 ****************/
477 if(isset($_POST['delete_branch_confirm'])){
479 /* Check if we have a post remove method configured
480 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
481 */
482 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
484 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
485 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
486 }else{
488 $bb = $this->fai_release;
489 if(!isset($ldap)){
490 $ldap = $this->config->get_ldap_link();
491 }
493 $br = $this->getBranches();
495 if(isset($br[$bb]) && $this->acl_is_removeable()){
496 $name = $br[$bb];
498 $ldap->cd($bb);
499 $ldap->recursive_remove();
500 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
501 $ldap->recursive_remove();
502 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('mimetypeou'), $bb));
503 $ldap->recursive_remove();
505 /* Search for all groups with configured application menus.
506 - First search all groups, to ensure that we only remove entries form whithin groups.
507 - The search für menu configuration for the specified release and collect all those dns.
508 - Remove entries
509 */
510 $release_ou = preg_replace("/".normalizePreg(get_ou("faiou")).".*$/","",$bb);
511 $ldap->cd($this->config->current['BASE']);
512 $ldap->search("(objectClass=posixGroup)",array("dn"));
514 /* Collect all group dns
515 */
516 $groups = array();
517 while($attrs = $ldap->fetch()){
518 $groups[] = $attrs['dn'];
519 }
521 /* Collect all group menu release dns that match the release we have removed
522 */
523 $dns = array();
524 foreach($groups as $dn){
525 $ldap->cd($dn);
526 $ldap->search("(objectClass=FAIbranch)",array("dn"));
527 while($attrs = $ldap->fetch()){
528 if(preg_match("/^".normalizePreg($release_ou)."/",$attrs['dn'])){
529 $dns[] = $attrs['dn'];
530 }
531 }
532 }
534 /* Finally remove collected release dns
535 */
536 foreach($dns as $dn){
537 $ldap->cd($dn);
538 $ldap->recursive_remove();
539 }
541 /* Post remove */
542 $this->fai_release = $this->fai_base;
543 $this->lock_name = $name;
544 $this->lock_dn = $bb;
545 $this->postremove();
547 $fai_filter = session::get("fai_filter");
548 $fai_filter['fai_release'] = $this->fai_release;
549 session::set("fai_filter",$fai_filter);
551 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
552 }
553 }
554 }
555 }
558 /****************
559 Create a new branch "insert Name"
560 ****************/
562 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
563 session::set('LASTPOST',$_POST);
565 if($this->dispNewBranch){
566 $type = "branch";
567 }else{
568 $type = "freeze";
569 }
571 /* Check branch name */
572 $name = $_POST['BranchName'];
573 $is_ok = true;
574 $smarty->assign("BranchName",$name);
575 $base= $this->fai_base;
577 /* Check used characters */
578 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
579 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
580 $is_ok = false;
581 }
583 /* Check if this name is already in use */
584 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
585 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
586 $is_ok = false;
587 }
589 if($is_ok){
591 if(session::is_set('LASTPOST')){
592 $LASTPOST = session::get('LASTPOST');
593 }else{
594 $LASTPOST = array();
595 }
596 $LASTPOST['base'] = $base;
597 $LASTPOST['type'] = $type;
598 session::set('LASTPOST',$LASTPOST);
599 $smarty->assign("iframe", true);
600 $smarty->assign("plugID", $_GET['plug']);
601 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
602 return($display);
603 }
604 }
607 /****************
608 Create a new branch
609 ****************/
611 if(isset($_GET['PerformBranch'])){
613 if(!$this->acl_is_createable()){
614 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
615 }else{
617 /* In order to see error messages we have to reset the error handler.
618 Due to the exit();
619 */
620 restore_error_handler();
622 /* Create it know */
623 $this->dispNewBranch = false;
624 $this->dispNewFreeze = false;
626 $LASTPOST = session::get('LASTPOST');
627 $base = $LASTPOST['base'];
628 $_POST = session::get('LASTPOST');
629 $name = $_POST['BranchName'];
631 $type = $LASTPOST['type'];
632 $ldap = $this->config->get_ldap_link();
634 $baseToUse = $base;
635 if($this->fai_release != $this->fai_base){
636 $baseToUse = $this->fai_release;
637 }
639 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
641 $CurrentReleases = $this->getBranches();
642 $NewReleaseName = $name;
643 if(isset($CurrentReleases[$this->fai_release])) {
644 if($this->fai_release != $this->fai_base){
645 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
646 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
647 }else{
648 $NewReleaseName = $name;
649 }
650 }
652 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
653 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
655 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
656 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
658 /* Check if source depeartments exist */
659 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
660 $ldap->cd($this->config->current['BASE']);
661 $ldap->cat($dep);
662 if(!$ldap->count()){
663 $ldap->create_missing_trees($dep);
664 }
665 }
667 /* Print header to have styles included */
668 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
669 <html>
670 <head>
671 <title></title>
672 <style type="text/css">@import url("themes/default/style.css");</style>
673 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
674 </head>
675 <body style="background: none;margin:3px;color:black">
676 ';
678 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
680 /* Duplicate group application releases
681 */
682 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
684 /* Duplicate applications
685 */
686 $ldap->cat($appsrc,array("dn")) ;
687 if($ldap->count()){
688 $ldap->cd ($appdst);
689 $ldap->recursive_remove();
690 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
691 }
693 /* Duplicate mime types
694 */
695 $ldap->cat($mimesrc,array("dn")) ;
696 if($ldap->count()){
697 $ldap->cd ($mimedst);
698 $ldap->recursive_remove();
699 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
700 }
702 $attr = array();
703 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
704 $attr['ou'] = $name;
705 $attr['FAIstate'] = $type;
706 $ldap->cd($this->config->current['BASE']);
707 $ldap->cd("ou=".$name.",".$baseToUse);
708 $ldap->cat("ou=".$name.",".$baseToUse);
709 if($ldap->count()){
710 $ldap->modify($attr);
711 }else{
712 $ldap->add($attr);
713 }
715 /* Duplicate fai objects
716 */
717 // $ldap->cd ("ou=".$name.",".$baseToUse);
718 // $ldap->recursive_remove();
719 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
721 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
722 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
723 </form></div>";
725 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
727 /* Print footer to have valid html */
728 echo "</body></html>";
730 $this->dispNewFreeze = false;
732 /* Postcreate */
734 /* Assign possible attributes */
735 $this->lock_type = $type;
736 $this->lock_name = $name;
737 $this->lock_dn = $baseToUse;
738 $this->postcreate();
741 /* Send daemon event to reload the fai release database
742 */
743 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
744 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
745 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
746 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
747 $tmp = new $evt['CLASS_NAME']($this->config);
748 $tmp->set_type(TRIGGERED_EVENT);
749 $tmp->add_targets(array("GOsa"));
750 $o_queue = new gosaSupportDaemon();
751 if(!$o_queue->append($tmp)){
752 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
753 }
754 }
755 }else{
756 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
757 }
758 exit();
759 }
760 }
762 /****************
763 Display dialog to enter new Branch name
764 ****************/
766 /* Check if we have a post create method configured
767 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
768 */
769 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
770 if(($s_action == "branch_branch")||($this->dispNewBranch)){
771 if(!$this->acl_is_createable()){
772 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
773 }else{
774 $this->dispNewBranch=true;
775 $smarty->assign("iframe",false);
776 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
777 return($display);
778 }
779 }
780 }
783 /****************
784 Display dialog to enter new Freeze name
785 ****************/
787 /* Check if we have a post create method configured
788 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
789 */
790 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
791 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
792 if(!$this->acl_is_createable()){
793 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
794 }else{
795 $this->dispNewFreeze = true;
796 $smarty->assign("iframe",false);
797 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
798 return($display);
799 }
800 }
801 }
804 /****************
805 Create a new object
806 ****************/
808 $types = array( "new_partition" => "FAIpartitionTable",
809 "new_script" => "FAIscript",
810 "new_hook" => "FAIhook",
811 "new_variable" => "FAIvariable",
812 "new_template" => "FAItemplate",
813 "new_package" => "FAIpackageList");
814 $types_i18n = array( "new_partition" => _("partition table"),
815 "new_script" => _("script"),
816 "new_hook" => _("hook"),
817 "new_variable" => _("variable"),
818 "new_template" => _("template"),
819 "new_package" => _("package list"));
821 if(isset($types[$s_action])){
822 $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
823 if(preg_match("/c/",$acl)){
824 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
825 $this->dialog->parent = &$this;
826 }else{
827 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
828 }
829 }
831 /* New Profile */
832 if($s_action == "new_profile"){
833 $this->dn = "new" ;
835 $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
836 if(preg_match("/c/",$acl)){
837 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
838 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
839 $this->dialog->set_acl_base($this->base);
840 $this->dialog->parent = &$this;
842 $this->is_dialog = false;
843 }else{
844 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
845 }
846 }
849 /****************
850 Get from ask class name dialog
851 ****************/
853 if($s_action == "select_class_name_finished"){
854 $this->dialog->save_object();
855 if(count($this->dialog->check())!=0){
856 foreach($this->dialog->check() as $msg){
857 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
858 }
859 }elseif(isset($this->dialog->objectClass)){
860 $this->dn = "new" ;
861 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
862 $name = $this->dialog->save();
864 if(class_exists($a_setup[0])){
865 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
866 $this->dialog->set_acl_base($this->base);
867 $this->dialog->by_object[$a_setup[1]]->cn = $name;
868 $this->dialog->parent = &$this;
869 $this->is_dialog = true;
870 }
871 }
872 }
875 /****************
876 Cancel dialogs
877 ****************/
879 if(isset($_POST['edit_cancel'])){
880 $this->dialog=FALSE;
881 $this->is_dialog = false;
882 session::un_set('objectinfo');
883 $this->remove_lock();
884 }
887 /****************
888 Save sub dialogs
889 ****************/
891 /* This check if the given tab could be saved
892 * If it was possible to save it, remove dialog object.
893 * If it wasn't possible, show errors and keep dialog.
894 */
895 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
896 $this->dialog->save_object();
897 $msgs= $this->dialog->check();
898 if(count($msgs)!=0){
899 foreach($msgs as $msg){
900 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
901 }
902 }else{
903 $this->dialog->save();
904 FAI::save_release_changes_now();
905 if (!isset($_POST['edit_apply'])){
906 $this->remove_lock();
907 $this->dialog=FALSE;
908 $this->is_dialog=false;
909 session::un_set('objectinfo');
910 }else{
912 /* Reinitialize tab */
913 if($this->dialog instanceof tabs){
914 $this->dialog->re_init();
915 }
916 }
917 }
918 }
921 /****************
922 Display currently open dialog
923 ****************/
925 /* If dialog is set, but $this->is_dialog==false, then
926 * only the "abort" button is shown, this are dialogs that must not be saved.
927 * If is_dialog == true, we are currently editing tab objects.
928 * Here we need both, save and cancel
929 */
931 if(is_object($this->dialog)){
932 $display .= $this->dialog->execute();
933 /* Don't show buttons if tab dialog requests this */
935 if(isset($this->dialog->current)){
937 $obj = $this->dialog->by_object[$this->dialog->current];
939 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
941 $display.= "<p style=\"text-align:right\">\n";
942 if(!$this->no_save){
943 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
944 $display.= " \n";
945 if ($this->dn != "new"){
946 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
947 $display.= " \n";
948 }
949 }
950 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
951 $display.= "</p>";
952 }elseif(!isset($this->dialog->current)){
953 $display.= "<p style=\"text-align:right\">\n";
954 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
955 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
956 $display.= "</p>";
957 }
958 }else{
959 $display.= "<p style=\"text-align:right\">\n";
960 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
961 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
962 $display.= "</p>";
964 }
965 return($display);
966 }
969 /****************
970 Dialog display
971 ****************/
973 /* Check if there is a snapshot dialog open */
974 $base = $this->fai_base;
975 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
976 return($str);
977 }
979 /* Display dialog with system list */
980 $this->reload();
981 $this->DivListFai->parent = &$this;
982 $this->DivListFai->execute();
983 $this->DivListFai->setEntries($this->objects);
984 return($this->DivListFai->Draw());
985 }
988 /* Return departments, that will be included within snapshot detection */
989 function get_used_snapshot_bases()
990 {
991 $tmp = array();
992 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
993 foreach($types as $type){
994 $tmp[] = get_ou($type).$this->fai_release;
995 }
996 return($tmp);
997 }
1000 /* Get available branches for current base */
1001 function getBranches($base = false,$prefix = "")
1002 {
1003 $ret = array("/"=>$this->fai_base);
1004 $ldap = $this->config->get_ldap_link();
1005 if(!$base){
1006 $base = $this->fai_base;
1007 }
1008 $tmp = FAI::get_all_releases_from_base($base,true);
1009 foreach($tmp as $dn => $name){
1010 $ret[$name]=$dn;
1011 }
1012 ksort($ret);
1013 $ret = array_flip($ret);
1015 return ($ret);
1016 }
1019 function list_get_selected_items()
1020 {
1021 $ids = array();
1022 foreach($_POST as $name => $value){
1023 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1024 $id = preg_replace("/^item_selected_/","",$name);
1025 $ids[$id] = $id;
1026 }
1027 }
1028 return($ids);
1029 }
1032 /* reload list of objects */
1033 function reload()
1034 {
1035 /* Variable initialisation */
1036 $str = "";
1037 $Regex = $this->DivListFai->Regex;
1038 $this->objects = array();
1040 /* Get base */
1041 $base = $this->fai_base;
1042 if($this->fai_release != $this->fai_base){
1043 $br = $this->getBranches();
1044 if(isset($br[$this->fai_release])){
1045 $base = $this->fai_release;
1046 }else{
1047 $base = $this->fai_base;
1048 }
1049 }
1050 $this->base = $base;
1051 $this->set_acl_base($this->base);
1053 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1055 /* Create a new list of FAI object
1056 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1057 */
1058 $ObjectTypes = array(
1059 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1060 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1061 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1062 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1063 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1064 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1065 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1067 $filter = "";
1068 foreach($ObjectTypes as $key => $data){
1069 if($this->DivListFai->$data['CHKBOX']){
1070 $filter.= "(objectClass=".$key.")";
1071 }
1072 }
1073 $filter = "(&(|".$filter.")(cn=$Regex))";
1075 /* Get resolved release dependencies */
1076 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1078 /* Ge listed ldap objects */
1079 $ldap = $this->config->get_ldap_link();
1080 $ldap->cd($this->config->current['BASE']);
1082 foreach($tmp as $entry){
1084 /* Get some more informations about the object */
1085 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1086 $object = $ldap->fetch();
1088 /* Walk through possible types */
1089 foreach($ObjectTypes as $type => $rest){
1091 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1093 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1095 /* Prepare object */
1096 unset($object['objectClass']['count']);
1097 if(!isset($object['description'][0])){
1098 $object['description'][0]="";
1099 }
1101 /* Clean up object informations */
1102 $obj = array();
1103 $obj['cn'] = $object['cn'][0];
1104 $obj['dn'] = $object['dn'];
1105 $obj['acl'] = $acl;
1106 $obj['class'] = $rest ['ACL'];
1107 $obj['FAIstate'] = $entry['FAIstate'];
1108 $obj['description'] = $object['description'][0];
1109 $obj['objectClass'] = $object['objectClass'];
1111 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1112 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1113 }
1114 }
1115 }
1117 ksort($this->objects);
1118 reset ($this->objects);
1120 /* use numeric index, thats a bit more secure */
1121 $tmp0 = array();
1122 foreach($this->objects as $obj){
1123 $tmp0[]= $obj;
1124 }
1125 $this->objects = array();
1126 $this->objects = $tmp0;
1127 }
1129 function remove_lock()
1130 {
1131 if (isset($this->dn)){
1132 del_lock ($this->dn);
1133 }
1134 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1135 del_lock ($this->dns);
1136 }
1137 }
1139 function get_type($array){
1140 if(in_array("FAIpartitionTable",$array['objectClass'])){
1141 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1142 }
1143 if(in_array("FAIscript",$array['objectClass'])){
1144 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1145 }
1146 if(in_array("FAItemplate",$array['objectClass'])){
1147 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1148 }
1149 if(in_array("FAIhook",$array['objectClass'])){
1150 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1151 }
1152 if(in_array("FAIvariable",$array['objectClass'])){
1153 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1154 }
1155 if(in_array("FAIprofile",$array['objectClass'])){
1156 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1157 }
1159 if(in_array("FAIpackageList",$array['objectClass'])){
1160 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1161 }
1162 }
1164 function CheckNewBranchName($name,$base)
1165 {
1166 $f = $this->fai_release;
1167 if($name == ""){
1168 return(false);
1169 }elseif(in_array($name,$this->getBranches($f))) {
1170 return(false);
1171 }elseif(tests::is_department_name_reserved($name,$base)){
1172 return(false);
1173 }
1174 return(true);
1175 }
1177 function save_object()
1178 {
1179 $this->DivListFai->save_object();
1181 /* Get posted release */
1182 $r_releases = array_flip($this->getBranches());
1183 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1185 /* Ensure that we have a valid release selected */
1186 if(!isset($r_releases[get_post('fai_release')])){
1187 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1188 $_POST = array();
1189 $plug =$_GET['plug'];
1190 $_GET = array("plug" => $plug);
1191 $this->fai_release = $this->fai_base;
1192 }else{
1193 $this->fai_release = $r_releases[get_post('fai_release')];
1194 }
1196 $fai_filter = session::get("fai_filter");
1197 $fai_filter['fai_release'] = $this->fai_release;
1198 session::set("fai_filter",$fai_filter);
1199 }
1201 if(is_object($this->CopyPasteHandler)){
1202 $this->CopyPasteHandler->save_object();
1203 }
1204 }
1207 function copyPasteHandling_from_queue($s_action,$s_entry)
1208 {
1209 /* Check if Copy & Paste is disabled */
1210 if(!is_object($this->CopyPasteHandler)){
1211 return("");
1212 }
1214 $ui = get_userinfo();
1216 /* Add a single entry to queue */
1217 if($s_action == "copy"){
1219 /* Cleanup object queue */
1220 $this->CopyPasteHandler->cleanup_queue();
1221 $entry = $this->objects[$s_entry];
1222 $a_setup = $this->get_type($entry);
1223 $dn = $entry['dn'];
1225 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1226 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1227 }
1228 }
1230 /* Add entries to queue */
1231 if($s_action == "copy_multiple"){
1233 /* Cleanup object queue */
1234 $this->CopyPasteHandler->cleanup_queue();
1236 /* Add new entries to CP queue */
1237 foreach($this->list_get_selected_items() as $id){
1239 /* Cleanup object queue */
1240 $entry = $this->objects[$id];
1241 $a_setup = $this->get_type($entry);
1242 $dn = $entry['dn'];
1244 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1245 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1246 }
1247 }
1248 }
1250 /* Start pasting entries */
1251 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1252 $this->start_pasting_copied_objects = TRUE;
1253 }
1255 /* Return C&P dialog */
1256 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1258 /* Get dialog */
1259 $this->CopyPasteHandler->SetVar("parent",$this);
1260 $data = $this->CopyPasteHandler->execute();
1262 FAI::save_release_changes_now();
1264 /* Return dialog data */
1265 if(!empty($data)){
1266 return($data);
1267 }
1268 }
1270 /* Automatically disable status for pasting */
1271 if(!$this->CopyPasteHandler->entries_queued()){
1272 $this->start_pasting_copied_objects = FALSE;
1273 }
1274 return("");
1275 }
1278 /* Check if the given FAI class is used in this release
1279 */
1280 static function check_class_name($oc,$name,$dn)
1281 {
1282 $base = FAI::get_release_dn($dn);
1283 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1284 $delete = array();
1285 $used = array();
1286 foreach($res as $object){
1287 $used[$object['cn'][0]]= $object['cn'][0];
1288 }
1289 return($used);
1290 }
1293 /* Return plugin informations for acl handling */
1294 static function plInfo()
1295 {
1296 return (array(
1297 "plShortName" => _("FAI releases"),
1298 "plDescription" => _("FAI release management"),
1299 "plSelfModify" => FALSE,
1300 "plDepends" => array(),
1301 "plPriority" => 0,
1302 "plSection" => array("administration"),
1303 "plCategory" => array("fai"=> array("description" => _("FAI"),
1304 "objectClass" => "FAIclass")),
1305 "plProvidedAcls"=> array()));
1306 }
1307 }
1308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1309 ?>