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 $acl_base ="";
55 var $fai_base ="";
56 var $fai_release ="";
58 var $acl_module = array("fai");
60 var $opsi = NULL;
62 /* construction/reconstruction
63 */
64 function faiManagement (&$config, $ui)
65 {
66 /* Set defaults */
67 $this->dn = "";
68 $this->config = $config;
69 $this->ui = $ui;
71 /* Check if the opsi plugin is installed.
72 */
73 if(class_available("opsi")){
74 $this->opsi = new opsi($this->config);;
75 }
77 /* Creat dialog object */
78 $this->DivListFai = new divListFai($this->config,$this);
80 /* Copy & Paste handler */
81 if ($this->config->boolValueIsTrue("main", "copyPaste")){
82 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
83 }
85 /* Set default release
86 */
87 $this->acl_base = $this->config->current['BASE'];
88 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
90 if(!session::is_set("fai_filter")){
92 /* Set intial release */
93 $rel = $config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
94 $rels = array_flip($this->getBranches());
95 if(isset($rels[$rel])){
96 $rel = $rels[$rel];
97 }else{
98 $rel = $this->fai_base;
99 }
101 session::set("fai_filter",array("fai_release" => $rel));
102 }
104 $fai_filter = session::get("fai_filter");
105 $this->fai_release = $fai_filter['fai_release'];
106 }
108 function execute()
109 {
110 /* Call parent execute */
111 plugin::execute();
114 /* Initialise vars and smarty */
115 $smarty = get_smarty();
116 $smarty->assign("BranchName","");
118 $display = "";
119 $s_action = "";
120 $s_entry = "";
121 $no_save = FALSE; // hide Apply / Save buttons
123 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
124 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/"));
127 /****************
128 Handle posts
129 ****************/
131 /* Check ImageButton posts
132 * Create new tab ich new_xx is posted
133 */
134 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
135 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
136 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
137 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
138 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
139 "/edit_continue/"=>"select_class_name_finished",
140 "/^multiple_copy_fai/" => "copy_multiple",
141 "/^multiple_cut_fai/" => "cut_multiple",
142 "/^copy/" => "copy",
143 "/^remove_multiple_fai_objects/" => "del_multiple");
145 foreach($_POST as $name => $value){
146 foreach($posts as $reg => $act ){
147 if(preg_match($reg,$name)){
148 $s_action = $act;
149 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
150 $s_entry = preg_replace("/_.*$/","",$s_entry);
151 break;
152 }
153 }
154 if(preg_match("/^entry_edit_.*/",$name)){
155 $s_entry = preg_replace("/^entry_edit_/","",$name);
156 $s_entry = preg_replace("/_.*$/","",$s_entry);
157 $s_action = "edit";
158 break;
159 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
160 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
161 $s_entry = preg_replace("/_.*$/","",$s_entry);
162 $s_action = "edit";
163 $no_save = TRUE;
164 break;
165 }elseif(preg_match("/^entry_delete_.*/",$name)){
166 $s_entry = preg_replace("/^entry_delete_/","",$name);
167 $s_entry = preg_replace("/_.*$/","",$s_entry);
168 $s_action = "delete";
169 break;
170 }
172 /* Get posts from opsi onjects
173 */
174 if($this->opsi instanceof opsi && $this->opsi->enabled()){
175 if(preg_match("/^entry_opsi_edit_/",$name)){
176 $s_entry = preg_replace("/^entry_opsi_edit_([0-9]*).*$/","\\1",$name);
177 $s_action = "opsi_edit";
178 break;
179 }
180 }
181 }
183 /* Get posts from opsi objects
184 */
185 if($this->opsi instanceof opsi && $this->opsi->enabled() && isset($_GET['edit_opsi_entry'])){
186 $s_entry = $_GET['edit_opsi_entry'];
187 $s_action = "opsi_edit";
188 }
190 if(isset($_GET['edit_entry'])){
191 $s_entry = $_GET['edit_entry'];
192 $s_action = "edit";
193 }
195 if(isset($_GET['edit_freeze_entry'])){
196 $s_entry = $_GET['edit_freeze_entry'];
197 $s_action = "edit";
198 $no_save = TRUE;
199 }
201 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
202 $s_action = "freeze_branch";
203 }
204 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
205 $s_action = "branch_branch";
206 }
207 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
208 $s_action = "remove_branch";
209 }
211 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
212 $this->dispNewBranch = false;
213 $this->dispNewFreeze = false;
214 }
217 $type_acl_mapping = array(
218 "FAIpartitionTable" => "faiPartitionTable",
219 "FAIpackageList" => "faiPackage",
220 "FAIscript" => "faiScript",
221 "FAIvariable" => "faiVariable",
222 "FAIhook" => "faiHook",
223 "FAIprofile" => "faiProfile",
224 "FAItemplate" => "faiTemplate");
227 /* handle C&P from layers menu */
228 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
229 $s_action = "copy_multiple";
230 }
231 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
232 $s_action = "cut_multiple";
233 }
234 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
235 $s_action = "editPaste";
236 }
238 /* Create options */
239 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
240 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
241 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
242 }
244 /* handle remove from layers menu */
245 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
246 $s_action = "del_multiple";
247 }
250 if(!empty($s_action)){
251 $this->no_save = $no_save;
252 }
254 /********************
255 Copy & Paste
256 ********************/
258 /* Display the copy & paste dialog, if it is currently open */
259 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
260 if($ret){
261 return($ret);
262 }
265 /*******************
266 Opsi extension
267 *******************/
269 if($this->opsi instanceof opsi && $this->opsi->enabled()){
270 if($s_action == "opsi_edit"){
271 $name = $this->objects[$s_entry]['cn'];
272 $cfg = $this->opsi->get_product_properties($name);
273 $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
274 if(isset($this->dialog->by_object['opsiProperties'])){
275 $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
276 $this->dialog->by_object['opsiProperties']->set_product($name);
277 }else{
278 trigger_error("Unknown tab, please check config.");
279 }
280 }
281 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
282 $this->dialog = NULL;
283 }
284 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
285 $this->dialog->save_object();
286 $op = $this->dialog->by_object['opsiProperties'];
287 $name = $op->get_product();
288 $cfg = $op->get_cfg();
289 $this->opsi->set_product_properties($name,$cfg);
290 if($this->opsi->is_error()){
291 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
292 }else{
293 $this->dialog = NULL;
294 }
295 }
296 if($this->dialog instanceof tabs_opsiProdConfig){
297 $this->dialog->save_object();
298 return($this->dialog->execute());
299 }
300 }
303 /****************
304 Delete confirme dialog
305 ****************/
307 if ($s_action=="delete"){
309 /* Get 'dn' from posted termlinst */
310 $this->dn= $this->objects[$s_entry]['dn'];
312 /* Load permissions for selected 'dn' and check if
313 we're allowed to remove this 'dn' */
314 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
315 if(preg_match("/d/",$acl)){
317 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
318 if (($user= get_lock($this->dn)) != ""){
319 return(gen_locked_message ($user, $this->dn));
320 }
322 /* Lock the current entry, so nobody will edit it during deletion */
323 add_lock ($this->dn, $this->ui->dn);
324 $smarty->assign("warning",msgPool::deleteInfo(LDAP::fix($this->dn),_("FAI object")));
325 $smarty->assign("multiple", false);
326 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
327 } else {
329 /* Obviously the user isn't allowed to delete. Show message and clean session. */
330 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
331 }
332 }
335 /********************
336 Delete MULTIPLE entries requested, display confirm dialog
337 ********************/
339 if ($s_action=="del_multiple"){
340 $this->dns = array();
341 $ids = $this->list_get_selected_items();
343 if(count($ids)){
345 $errors = "";
346 foreach($ids as $id){
347 $dn = $this->objects[$id]['dn'];
348 $cn = $this->objects[$id]['cn'];
349 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
350 $this->dns[$id] = $dn;
351 }else{
352 $errors .= $cn.", ";
353 }
354 }
355 if ($user= get_multiple_locks($this->dns)){
356 return(gen_locked_message($user,$this->dns));
357 }
359 if($errors != ""){
360 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
361 "<br><br>".trim($errors,", ")),INFO_DIALOG);
362 }
364 if(count($this->dns)){
366 $dns_names = array();
367 foreach($this->dns as $dn){
368 add_lock ($dn, $this->ui->dn);
369 $dns_names[] = LDAP::fix($dn);
370 }
372 /* Lock the current entry, so nobody will edit it during deletion */
373 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
374 $smarty->assign("multiple", true);
375 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
376 }
377 }
378 }
381 /********************
382 Delete MULTIPLE entries confirmed
383 ********************/
385 /* Confirmation for deletion has been passed. Users should be deleted. */
386 if (isset($_POST['delete_multiple_fai_object_confirm'])){
388 /* Find out more about the object type */
389 $ldap = $this->config->get_ldap_link();
391 /* Remove user by user and check acls before removeing them */
392 foreach($this->dns as $key => $dn){
394 $ldap->cat($dn, array('objectClass'));
395 $attrs = $ldap->fetch();
396 $type = $this->get_type($attrs);
398 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
399 if(preg_match("/d/",$acl)){
401 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
402 $this->dialog->parent = &$this;
403 $this->dialog->set_acl_base($dn);
404 $this->dialog->by_object[$type[1]]->remove_from_parent ();
405 unset ($this->dialog);
406 $this->dialog= FALSE;
407 $to_del = FAI::clean_up_releases($dn);
408 FAI::save_release_changes_now();
410 foreach($to_del as $dn){
411 $ldap->rmdir_recursive($dn);
412 }
414 } else {
416 /* Normally this shouldn't be reached, send some extra
417 logs to notify the administrator */
418 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
419 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
420 }
421 }
423 /* Remove lock file after successfull deletion */
424 $this->remove_lock();
425 $this->dns = array();
426 }
429 /********************
430 Delete MULTIPLE entries Canceled
431 ********************/
433 /* Remove lock */
434 if(isset($_POST['delete_multiple_fai_object_cancel'])){
435 $this->dns = array();
436 $this->remove_lock();
437 }
440 /****************
441 Delete aborted
442 ****************/
444 /* Delete canceled? */
445 if (isset($_POST['delete_cancel'])){
446 $this->remove_lock();
447 }
450 /****************
451 Delete confirmed
452 ****************/
454 /* Deletion was confirmed, so delete this entry
455 */
456 if (isset($_POST['delete_terminal_confirm'])){
458 /* Some nice guy may send this as POST, so we've to check
459 for the permissions again. */
461 /* Find out more about the object type */
462 $ldap = $this->config->get_ldap_link();
463 $ldap->cat($this->dn, array('objectClass'));
464 if($ldap->count()){
465 $attrs = $ldap->fetch();
466 $type = $this->get_type($attrs);
468 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
469 if(preg_match("/d/",$acl)){
471 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
472 $this->dialog->set_acl_base($this->dn);
473 $this->dialog->parent = &$this;
474 $this->dialog->by_object[$type[1]]->remove_from_parent ();
475 unset ($this->dialog);
476 $this->dialog= FALSE;
477 $to_del = FAI::clean_up_releases($this->dn);
478 FAI::save_release_changes_now();
480 foreach($to_del as $dn){
481 $ldap->rmdir_recursive($dn);
482 }
484 } else {
486 /* Normally this shouldn't be reached, send some extra
487 logs to notify the administrator */
488 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
489 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
490 }
492 }else{
493 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
494 }
496 /* Remove lock file after successfull deletion */
497 $this->remove_lock();
498 }
501 /****************
502 Edit entry
503 ****************/
505 if(($s_action == "edit") && (!isset($this->dialog->config))){
506 $entry = $this->objects[$s_entry];
507 $a_setup = $this->get_type($entry);
508 $this->dn = $entry['dn'];
510 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
511 if (($user= get_lock($this->dn)) != ""){
512 return(gen_locked_message ($user, $this->dn, TRUE));
513 }
514 add_lock ($this->dn, $this->ui->dn);
516 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
517 $this->dialog->parent = &$this;
518 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
519 $this->dialog->set_acl_base($this->dn);
520 $this->is_dialog = true;
521 session::set('objectinfo',$this->dn);
522 }
525 /* Branch handling
526 09.01.2006
527 */
529 /****************
530 Remove branch
531 ****************/
533 /* Remove branch
534 */
535 if($s_action == "remove_branch"){
536 $base= $this->fai_release;
538 /* Check if we have a post remove method configured
539 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
540 */
541 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
542 /* Load permissions for selected 'dn' and check if
543 we're allowed to remove this 'dn' */
544 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
545 $smarty->assign("release_hidden",base64_encode($this->fai_release));
546 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
547 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
548 } else {
549 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
550 }
551 }
552 }
555 /****************
556 Remove branch confirmed
557 ****************/
559 if(isset($_POST['delete_branch_confirm'])){
561 /* Check if we have a post remove method configured
562 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
563 */
564 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
566 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
567 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
568 }else{
570 $bb = $this->fai_release;
571 if(!isset($ldap)){
572 $ldap = $this->config->get_ldap_link();
573 }
575 $br = $this->getBranches();
577 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
578 $name = $br[$bb];
580 $ldap->cd($bb);
581 $ldap->recursive_remove();
582 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
583 $ldap->recursive_remove();
584 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
585 $ldap->recursive_remove();
587 /* Search for all groups with configured application menus.
588 - First search all groups, to ensure that we only remove entries form whithin groups.
589 - The search für menu configuration for the specified release and collect all those dns.
590 - Remove entries
591 */
592 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
593 $ldap->cd($this->config->current['BASE']);
594 $ldap->search("(objectClass=posixGroup)",array("dn"));
596 /* Collect all group dns
597 */
598 $groups = array();
599 while($attrs = $ldap->fetch()){
600 $groups[] = $attrs['dn'];
601 }
603 /* Collect all group menu release dns that match the release we have removed
604 */
605 $dns = array();
606 foreach($groups as $dn){
607 $ldap->cd($dn);
608 $ldap->search("(objectClass=FAIbranch)",array("dn"));
609 while($attrs = $ldap->fetch()){
610 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
611 $dns[] = $attrs['dn'];
612 }
613 }
614 }
616 /* Finally remove collected release dns
617 */
618 foreach($dns as $dn){
619 $ldap->cd($dn);
620 $ldap->recursive_remove();
621 }
623 /* Post remove */
624 $this->fai_release = $this->fai_base;
625 $this->lock_name = $name;
626 $this->lock_dn = $bb;
627 $this->postremove();
629 $fai_filter = session::get("fai_filter");
630 $fai_filter['fai_release'] = $this->fai_release;
631 session::set("fai_filter",$fai_filter);
633 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
634 }
635 }
636 }
637 }
640 /****************
641 Create a new branch "insert Name"
642 ****************/
644 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
645 session::set('LASTPOST',$_POST);
647 if($this->dispNewBranch){
648 $type = "branch";
649 }else{
650 $type = "freeze";
651 }
653 /* Check branch name */
654 $name = $_POST['BranchName'];
655 $is_ok = true;
656 $smarty->assign("BranchName",$name);
657 $base= $this->fai_base;
659 /* Check used characters */
660 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
661 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
662 $is_ok = false;
663 }
665 /* Check if this name is already in use */
666 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
667 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
668 $is_ok = false;
669 }
671 if($is_ok){
673 if(session::is_set('LASTPOST')){
674 $LASTPOST = session::get('LASTPOST');
675 }else{
676 $LASTPOST = array();
677 }
678 $LASTPOST['base'] = $base;
679 $LASTPOST['type'] = $type;
680 session::set('LASTPOST',$LASTPOST);
681 $smarty->assign("iframe", true);
682 $smarty->assign("plugID", $_GET['plug']);
683 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
684 return($display);
685 }
686 }
689 /****************
690 Create a new branch
691 ****************/
693 if(isset($_GET['PerformBranch'])){
695 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
696 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
697 }else{
699 /* In order to see error messages we have to reset the error handler.
700 Due to the exit();
701 */
702 restore_error_handler();
704 /* Create it know */
705 $this->dispNewBranch = false;
706 $this->dispNewFreeze = false;
708 $LASTPOST = session::get('LASTPOST');
709 $base = $LASTPOST['base'];
710 $_POST = session::get('LASTPOST');
711 $name = $_POST['BranchName'];
713 $type = $LASTPOST['type'];
714 $ldap = $this->config->get_ldap_link();
716 $baseToUse = $base;
717 if($this->fai_release != $this->fai_base){
718 $baseToUse = $this->fai_release;
719 }
721 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
723 $CurrentReleases = $this->getBranches();
724 $NewReleaseName = $name;
725 if(isset($CurrentReleases[$this->fai_release])) {
726 if($this->fai_release != $this->fai_base){
727 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
728 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
729 }else{
730 $NewReleaseName = $name;
731 }
732 }
734 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse);
735 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
737 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse);
738 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
740 /* Check if source depeartments exist */
741 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
742 $ldap->cd($this->config->current['BASE']);
743 $ldap->cat($dep);
744 if(!$ldap->count()){
745 $ldap->create_missing_trees($dep);
746 }
747 }
749 /* Print header to have styles included */
750 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
751 <html>
752 <head>
753 <title></title>
754 <style type="text/css">@import url("themes/default/style.css");</style>
755 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
756 </head>
757 <body style="background: none;margin:3px;color:black">
758 ';
760 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
762 /* Duplicate group application releases
763 */
764 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
766 /* Duplicate applications
767 */
768 $ldap->cat($appsrc,array("dn")) ;
769 if($ldap->count()){
770 $ldap->cd ($appdst);
771 $ldap->recursive_remove();
772 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
773 }
775 /* Duplicate mime types
776 */
777 $ldap->cat($mimesrc,array("dn")) ;
778 if($ldap->count()){
779 $ldap->cd ($mimedst);
780 $ldap->recursive_remove();
781 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
782 }
784 $attr = array();
785 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
786 $attr['ou'] = $name;
787 $attr['FAIstate'] = $type;
788 $ldap->cd($this->config->current['BASE']);
789 $ldap->cd("ou=".$name.",".$baseToUse);
790 $ldap->cat("ou=".$name.",".$baseToUse);
791 if($ldap->count()){
792 $ldap->modify($attr);
793 }else{
794 $ldap->add($attr);
795 }
797 /* Duplicate fai objects
798 */
799 // $ldap->cd ("ou=".$name.",".$baseToUse);
800 // $ldap->recursive_remove();
801 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
803 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
804 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
805 <input type='hidden' name='php_c_check' value='1'>
806 </form></div>";
808 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
810 /* Print footer to have valid html */
811 echo "</body></html>";
813 $this->dispNewFreeze = false;
815 /* Postcreate */
817 /* Assign possible attributes */
818 $this->lock_type = $type;
819 $this->lock_name = $name;
820 $this->lock_dn = $baseToUse;
821 $this->postcreate();
824 /* Send daemon event to reload the fai release database
825 */
826 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
827 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
828 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
829 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
830 $tmp = new $evt['CLASS_NAME']($this->config);
831 $tmp->set_type(TRIGGERED_EVENT);
832 $tmp->add_targets(array("GOSA"));
833 $o_queue = new gosaSupportDaemon();
834 if(!$o_queue->append($tmp)){
835 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
836 }
837 }
838 }else{
839 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
840 msg_dialog::display(_("Fatal error"),
841 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
842 FATAL_ERROR_DIALOG);
843 }
844 exit();
845 }
846 }
848 /****************
849 Display dialog to enter new Branch name
850 ****************/
852 /* Check if we have a post create method configured
853 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
854 */
855 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
856 if(($s_action == "branch_branch")||($this->dispNewBranch)){
857 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
858 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
859 }else{
860 $this->dispNewBranch=true;
861 $smarty->assign("iframe",false);
862 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
863 return($display);
864 }
865 }
866 }
869 /****************
870 Display dialog to enter new Freeze name
871 ****************/
873 /* Check if we have a post create method configured
874 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
875 */
876 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
877 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
878 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
879 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
880 }else{
881 $this->dispNewFreeze = true;
882 $smarty->assign("iframe",false);
883 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
884 return($display);
885 }
886 }
887 }
890 /****************
891 Create a new object
892 ****************/
894 $types = array( "new_partition" => "FAIpartitionTable",
895 "new_script" => "FAIscript",
896 "new_hook" => "FAIhook",
897 "new_variable" => "FAIvariable",
898 "new_template" => "FAItemplate",
899 "new_package" => "FAIpackageList");
900 $types_i18n = array( "new_partition" => _("partition table"),
901 "new_script" => _("script"),
902 "new_hook" => _("hook"),
903 "new_variable" => _("variable"),
904 "new_template" => _("template"),
905 "new_package" => _("package list"));
907 if(isset($types[$s_action])){
908 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
909 if(preg_match("/c/",$acl)){
910 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
911 $this->dialog->parent = &$this;
912 }else{
913 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
914 }
915 }
917 /* New Profile */
918 if($s_action == "new_profile"){
919 $this->dn = "new" ;
921 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
922 if(preg_match("/c/",$acl)){
923 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
924 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
925 $this->dialog->set_acl_base($this->base);
926 $this->dialog->parent = &$this;
928 $this->is_dialog = false;
929 }else{
930 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
931 }
932 }
935 /****************
936 Get from ask class name dialog
937 ****************/
939 if($s_action == "select_class_name_finished"){
940 $this->dialog->save_object();
941 if(count($this->dialog->check())!=0){
942 foreach($this->dialog->check() as $msg){
943 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
944 }
945 }elseif(isset($this->dialog->objectClass)){
946 $this->dn = "new" ;
947 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
948 $name = $this->dialog->save();
950 if(class_exists($a_setup[0])){
951 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
952 $this->dialog->set_acl_base($this->base);
953 $this->dialog->by_object[$a_setup[1]]->cn = $name;
954 $this->dialog->parent = &$this;
955 $this->is_dialog = true;
956 }
957 }
958 }
961 /****************
962 Cancel dialogs
963 ****************/
965 if(isset($_POST['edit_cancel'])){
966 $this->dialog=FALSE;
967 $this->is_dialog = false;
968 session::un_set('objectinfo');
969 $this->remove_lock();
970 }
973 /****************
974 Save sub dialogs
975 ****************/
977 /* This check if the given tab could be saved
978 * If it was possible to save it, remove dialog object.
979 * If it wasn't possible, show errors and keep dialog.
980 */
981 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
982 $this->dialog->save_object();
983 $msgs= $this->dialog->check();
984 if(count($msgs)!=0){
985 foreach($msgs as $msg){
986 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
987 }
988 }else{
989 $this->dialog->save();
990 FAI::save_release_changes_now();
991 if (!isset($_POST['edit_apply'])){
992 $this->remove_lock();
993 $this->dialog=FALSE;
994 $this->is_dialog=false;
995 session::un_set('objectinfo');
996 }else{
998 /* Reinitialize tab */
999 if($this->dialog instanceof tabs){
1000 $this->dialog->re_init();
1001 }
1002 }
1003 }
1004 }
1007 /****************
1008 Display currently open dialog
1009 ****************/
1011 /* If dialog is set, but $this->is_dialog==false, then
1012 * only the "abort" button is shown, this are dialogs that must not be saved.
1013 * If is_dialog == true, we are currently editing tab objects.
1014 * Here we need both, save and cancel
1015 */
1017 if(is_object($this->dialog)){
1018 $display .= $this->dialog->execute();
1019 /* Don't show buttons if tab dialog requests this */
1021 if(isset($this->dialog->current)){
1023 $obj = $this->dialog->by_object[$this->dialog->current];
1025 if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
1026 $display.= "<p style=\"text-align:right\">
1027 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1028 </p>";
1029 }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1031 $display.= "<p style=\"text-align:right\">\n";
1032 if(!$this->no_save){
1033 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1034 $display.= " \n";
1035 if ($this->dn != "new"){
1036 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1037 $display.= " \n";
1038 }
1039 }
1040 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1041 $display.= "</p>";
1042 }elseif(!isset($this->dialog->current)){
1043 $display.= "<p style=\"text-align:right\">\n";
1044 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1045 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1046 $display.= "</p>";
1047 }
1048 }else{
1049 $display.= "<p style=\"text-align:right\">\n";
1050 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1051 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1052 $display.= "</p>";
1054 }
1055 return($display);
1056 }
1059 /****************
1060 Dialog display
1061 ****************/
1063 /* Check if there is a snapshot dialog open */
1064 $base = $this->fai_base;
1065 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1066 return($str);
1067 }
1069 /* Display dialog with system list */
1070 $this->reload();
1071 $this->DivListFai->parent = &$this;
1072 $this->DivListFai->execute();
1073 $this->DivListFai->setEntries($this->objects);
1074 return($this->DivListFai->Draw());
1075 }
1078 /* Return departments, that will be included within snapshot detection */
1079 function get_used_snapshot_bases()
1080 {
1081 $tmp = array();
1082 $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1083 foreach($types as $type){
1084 $tmp[] = get_ou($type).$this->fai_release;
1085 }
1086 return($tmp);
1087 }
1090 /* Get available branches for current base */
1091 function getBranches($base = false,$prefix = "")
1092 {
1093 $ret = array("/"=>$this->fai_base);
1094 $ldap = $this->config->get_ldap_link();
1095 if(!$base){
1096 $base = $this->fai_base;
1097 }
1098 $tmp = FAI::get_all_releases_from_base($base,true);
1099 foreach($tmp as $dn => $name){
1100 $ret[$name]=$dn;
1101 }
1102 ksort($ret);
1103 $ret = array_flip($ret);
1105 return ($ret);
1106 }
1109 function list_get_selected_items()
1110 {
1111 $ids = array();
1112 foreach($_POST as $name => $value){
1113 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1114 $id = preg_replace("/^item_selected_/","",$name);
1115 $ids[$id] = $id;
1116 }
1117 }
1118 return($ids);
1119 }
1122 /* reload list of objects */
1123 function reload()
1124 {
1125 /* Variable initialisation */
1126 $str = "";
1127 $Regex = $this->DivListFai->Regex;
1128 $this->objects = array();
1130 /* Get base */
1131 $base = $this->fai_base;
1132 if($this->fai_release != $this->fai_base){
1133 $br = $this->getBranches();
1134 if(isset($br[$this->fai_release])){
1135 $base = $this->fai_release;
1136 }else{
1137 $base = $this->fai_base;
1138 }
1139 }
1140 $this->base = $base;
1141 $this->set_acl_base($this->acl_base);
1143 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1145 /* Create a new list of FAI object
1146 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1147 */
1148 $ObjectTypes = array(
1149 "FAIpartitionTable" => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1150 "FAIpackageList" => array("OU"=> get_ou('faiPackageRDN') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1151 "FAIscript" => array("OU"=> get_ou('faiScriptRDN') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1152 "FAIvariable" => array("OU"=> get_ou('faiVariableRDN') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1153 "FAIhook" => array("OU"=> get_ou('faiHookRDN') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1154 "FAIprofile" => array("OU"=> get_ou('faiProfileRDN') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1155 "FAItemplate" => array("OU"=> get_ou('faiTemplateRDN') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1157 $filter = "";
1158 foreach($ObjectTypes as $key => $data){
1159 if($this->DivListFai->$data['CHKBOX']){
1160 $filter.= "(objectClass=".$key.")";
1161 }
1162 }
1163 $filter = "(&(|".$filter.")(cn=$Regex))";
1165 /* Get resolved release dependencies */
1166 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1168 /* Ge listed ldap objects */
1169 $ldap = $this->config->get_ldap_link();
1170 $ldap->cd($this->config->current['BASE']);
1172 foreach($tmp as $entry){
1174 /* Get some more informations about the object */
1175 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1176 $object = $ldap->fetch();
1178 /* Walk through possible types */
1179 foreach($ObjectTypes as $type => $rest){
1181 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1183 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1185 /* Prepare object */
1186 unset($object['objectClass']['count']);
1187 if(!isset($object['description'][0])){
1188 $object['description'][0]="";
1189 }
1191 /* Clean up object informations */
1192 $obj = array();
1193 $obj['cn'] = $object['cn'][0];
1194 $obj['dn'] = $object['dn'];
1195 $obj['acl'] = $acl;
1196 $obj['class'] = $rest ['ACL'];
1197 $obj['FAIstate'] = $entry['FAIstate'];
1198 $obj['description'] = $object['description'][0];
1199 $obj['objectClass'] = $object['objectClass'];
1201 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1202 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1203 }
1204 }
1205 }
1207 /* Append opsi objects, if opsi is available and if we are on the fai_base
1208 */
1209 if($this->opsi instanceof opsi && $this->opsi->enabled()){
1210 $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1211 if(preg_match("/r/",$opsi_acl)){
1212 $err = FALSE;
1213 if(!$err && $this->DivListFai->ShowOpsiNetboot){
1214 $n_pro = $this->opsi->get_netboot_products();
1215 $err |= $this->opsi->is_error();
1216 foreach($n_pro as $name => $data){
1217 $entry = array("cn" => $name,
1218 "description" => $data['DESC'],
1219 "type" => "opsi_netboot");
1220 $this->objects[$name."_opsi_netboot"] = $entry;
1221 }
1222 }
1223 if(!$err && $this->DivListFai->ShowOpsiLocal){
1224 $l_pro = $this->opsi->get_local_products();
1225 $err |= $this->opsi->is_error();
1226 foreach($l_pro as $name => $data){
1227 $entry = array("cn" => $name,
1228 "description" => $data['DESC'],
1229 "type" => "opsi_local");
1230 $this->objects[$name."_opsi_local"] = $entry;
1231 }
1232 }
1233 if($err){
1234 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1235 }
1236 }
1237 }
1239 ksort($this->objects);
1240 reset ($this->objects);
1242 /* use numeric index, thats a bit more secure */
1243 $tmp0 = array();
1244 foreach($this->objects as $obj){
1245 $tmp0[]= $obj;
1246 }
1247 $this->objects = array();
1248 $this->objects = $tmp0;
1249 }
1251 function remove_lock()
1252 {
1253 if (isset($this->dn)){
1254 del_lock ($this->dn);
1255 }
1256 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1257 del_lock ($this->dns);
1258 }
1259 }
1261 function get_type($array){
1262 if(in_array("FAIpartitionTable",$array['objectClass'])){
1263 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1264 }
1265 if(in_array("FAIscript",$array['objectClass'])){
1266 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1267 }
1268 if(in_array("FAItemplate",$array['objectClass'])){
1269 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1270 }
1271 if(in_array("FAIhook",$array['objectClass'])){
1272 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1273 }
1274 if(in_array("FAIvariable",$array['objectClass'])){
1275 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1276 }
1277 if(in_array("FAIprofile",$array['objectClass'])){
1278 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1279 }
1281 if(in_array("FAIpackageList",$array['objectClass'])){
1282 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1283 }
1284 }
1286 function CheckNewBranchName($name,$base)
1287 {
1288 $f = $this->fai_release;
1289 if($name == ""){
1290 return(false);
1291 }elseif(in_array($name,$this->getBranches($f))) {
1292 return(false);
1293 }elseif(tests::is_department_name_reserved($name,$base)){
1294 return(false);
1295 }
1296 return(true);
1297 }
1299 function save_object()
1300 {
1301 $this->DivListFai->save_object();
1303 /* Get posted release */
1304 $r_releases = array_flip($this->getBranches());
1305 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1307 /* Ensure that we have a valid release selected */
1308 if(!isset($r_releases[get_post('fai_release')])){
1309 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1310 $_POST = array();
1311 $plug =$_GET['plug'];
1312 $_GET = array("plug" => $plug);
1313 $this->fai_release = $this->fai_base;
1314 }else{
1315 $this->fai_release = $r_releases[get_post('fai_release')];
1316 }
1318 $fai_filter = session::get("fai_filter");
1319 $fai_filter['fai_release'] = $this->fai_release;
1320 session::set("fai_filter",$fai_filter);
1321 }
1323 if(is_object($this->CopyPasteHandler)){
1324 $this->CopyPasteHandler->save_object();
1325 }
1326 }
1329 function copyPasteHandling_from_queue($s_action,$s_entry)
1330 {
1331 /* Check if Copy & Paste is disabled */
1332 if(!is_object($this->CopyPasteHandler)){
1333 return("");
1334 }
1336 $ui = get_userinfo();
1338 /* Add a single entry to queue */
1339 if($s_action == "copy"){
1341 /* Cleanup object queue */
1342 $this->CopyPasteHandler->cleanup_queue();
1343 $entry = $this->objects[$s_entry];
1344 $a_setup = $this->get_type($entry);
1345 $dn = $entry['dn'];
1347 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1348 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1349 }
1350 }
1352 /* Add entries to queue */
1353 if($s_action == "copy_multiple"){
1355 /* Cleanup object queue */
1356 $this->CopyPasteHandler->cleanup_queue();
1358 /* Add new entries to CP queue */
1359 foreach($this->list_get_selected_items() as $id){
1361 /* Cleanup object queue */
1362 $entry = $this->objects[$id];
1363 $a_setup = $this->get_type($entry);
1364 $dn = $entry['dn'];
1366 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1367 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1368 }
1369 }
1370 }
1372 /* Start pasting entries */
1373 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1374 $this->start_pasting_copied_objects = TRUE;
1375 }
1377 /* Return C&P dialog */
1378 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1380 /* Get dialog */
1381 $this->CopyPasteHandler->SetVar("parent",$this);
1382 $data = $this->CopyPasteHandler->execute();
1384 FAI::save_release_changes_now();
1386 /* Return dialog data */
1387 if(!empty($data)){
1388 return($data);
1389 }
1390 }
1392 /* Automatically disable status for pasting */
1393 if(!$this->CopyPasteHandler->entries_queued()){
1394 $this->start_pasting_copied_objects = FALSE;
1395 }
1396 return("");
1397 }
1400 /* Check if the given FAI class is used in this release
1401 */
1402 static function check_class_name($oc,$name,$dn)
1403 {
1404 $base = FAI::get_release_dn($dn);
1406 if($oc == "FAIprofile"){
1407 $f = "";
1408 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1409 foreach($ocs as $oc){
1410 $f .= "(objectClass=".$oc.")";
1411 }
1412 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
1413 }else{
1414 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1415 }
1416 $delete = array();
1417 $used = array();
1418 foreach($res as $object){
1419 $used[$object['cn'][0]]= $object['cn'][0];
1420 }
1421 return($used);
1422 }
1425 /* Return plugin informations for acl handling */
1426 static function plInfo()
1427 {
1428 return (array(
1429 "plShortName" => _("FAI releases"),
1430 "plDescription" => _("FAI release management"),
1431 "plSelfModify" => FALSE,
1432 "plDepends" => array(),
1433 "plPriority" => 0,
1434 "plSection" => array("administration"),
1435 "plCategory" => array("fai"=> array("description" => _("FAI"),
1436 "objectClass" => "FAIclass")),
1437 "plProvidedAcls"=> array()));
1438 }
1439 }
1440 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1441 ?>