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 msg_dialog::display(_("Fatal error"),
758 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
759 FATAL_ERROR_DIALOG);
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 ?>