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;
52 var $no_save;
53 var $acl_base ="";
54 var $fai_base ="";
55 var $fai_release ="";
56 var $acl_module = array("fai");
57 var $opsi = NULL;
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 /* Check if the opsi plugin is installed.
69 */
70 if(class_available("opsi")){
71 $this->opsi = new opsi($this->config);;
72 }
74 /* Creat dialog object */
75 $this->DivListFai = new divListFai($this->config,$this);
77 /* Copy & Paste handler */
78 if ($this->config->boolValueIsTrue("main", "copyPaste")){
79 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
80 }
82 /* Set default release
83 */
84 $this->acl_base = $this->config->current['BASE'];
85 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
87 if(!session::is_set("fai_filter")){
89 /* Set intial release */
90 $rel = $config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
91 $rels = array_flip($this->getBranches());
92 if(isset($rels[$rel])){
93 $rel = $rels[$rel];
94 }else{
95 $rel = $this->fai_base;
96 }
98 session::set("fai_filter",array("fai_release" => $rel));
99 }
101 $fai_filter = session::get("fai_filter");
102 $this->fai_release = $fai_filter['fai_release'];
103 }
105 function execute()
106 {
107 /* Call parent execute */
108 plugin::execute();
110 /* Initialise vars and smarty */
111 $smarty = get_smarty();
112 $smarty->assign("BranchName","");
114 $display = "";
115 $s_action = "";
116 $s_entry = "";
117 $no_save = FALSE; // hide Apply / Save buttons
119 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
120 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/","/^faiGroupHandle_apply$/"));
122 /****************
123 Handle posts
124 ****************/
126 /* Check ImageButton posts
127 * Create new tab ich new_xx is posted
128 */
129 $posts = array( "/^remove_branch/" =>"remove_branch",
130 "/^branch_branch/" =>"branch_branch",
131 "/^freeze_branch/" =>"freeze_branch",
133 "/^create_partition/i" =>"new_partition",
134 "/^create_script/i" =>"new_script",
135 "/^create_hook/i" =>"new_hook",
136 "/^create_variable/i" =>"new_variable",
137 "/^create_template/i" =>"new_template",
138 "/^create_package/i" =>"new_package",
139 "/^create_profile/i" =>"new_profile",
141 "/^edit_continue$/" => "select_class_name_finished",
143 "/^group_copy/" => "group_copy",
144 "/^group_cut/" => "group_cut",
145 "/^group_edit/" => "group_edit",
146 "/^group_remove/" => "group_remove");
147 foreach($_POST as $name => $value){
148 foreach($posts as $reg => $act ){
149 if(preg_match($reg,$name)){
150 $s_action = $act;
151 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
152 $s_entry = preg_replace("/_.*$/","",$s_entry);
153 break;
154 }
155 }
156 if(preg_match("/^edit_[0-9]*_.*$/",$name)){
157 $i_entryID = preg_replace("/^edit_([0-9]*)_.*$/i","\\1",$name);
158 $s_entryType= preg_replace("/^edit_[0-9]*_([^_]*)_.*$/i","\\1",$name);
159 $s_action = "edit";
160 }
161 }
163 if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
164 if(isset($this->objects[$_GET['id']])){
165 $s_action = "group_edit";
166 $s_entry = $_GET['id'];
167 }
168 }
170 foreach(array("freeze_branch" => "freeze_branch",
171 "branch_branch" => "branch_branch",
172 "remove_branch" => "remove_branch") as $from => $to){
173 if(isset($_GET['act']) && $_GET['act'] == $from){
174 $s_action = $to;
175 }
176 }
178 /* handle C&P from layer menu */
179 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
180 $s_action = "copy_multiple";
181 }
182 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
183 $s_action = "cut_multiple";
184 }
185 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
186 $s_action = "editPaste";
187 }
190 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
191 $this->dispNewBranch = false;
192 $this->dispNewFreeze = false;
193 }
195 /* Create options */
196 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
197 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
198 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
199 }
201 /* handle remove from layers menu */
202 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
203 $s_action = "del_multiple";
204 }
207 if(!empty($s_action)){
208 $this->no_save = $no_save;
209 }
212 /*******************
213 Opsi extension
214 *******************/
216 if($this->opsi instanceof opsi && $this->opsi->enabled()){
217 if($s_action == "opsi_edit"){
218 $name = $this->objects[$s_entry]['cn'];
219 $cfg = $this->opsi->get_product_properties($name);
220 $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
221 if(isset($this->dialog->by_object['opsiProperties'])){
222 $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
223 $this->dialog->by_object['opsiProperties']->set_product($name);
224 }else{
225 trigger_error("Unknown tab, please check config.");
226 }
227 }
228 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
229 $this->dialog = NULL;
230 }
231 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
232 $this->dialog->save_object();
233 $op = $this->dialog->by_object['opsiProperties'];
234 $name = $op->get_product();
235 $cfg = $op->get_cfg();
236 $this->opsi->set_product_properties($name,$cfg);
237 if($this->opsi->is_error()){
238 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
239 }else{
240 $this->dialog = NULL;
241 }
242 }
243 if($this->dialog instanceof tabs_opsiProdConfig){
244 $this->dialog->save_object();
245 return($this->dialog->execute());
246 }
247 }
250 /****************
251 Delete a group of FAI objects
252 (Group = same name & different classes)
253 ****************/
255 if($s_action == "group_remove"){
256 if(isset($this->objects[$s_entry])){
257 $group = $this->objects[$s_entry];
259 /* Do not allow to remove opsi products */
260 foreach(array("opsi_netboot","opsi_local") as $type){
261 if(isset($group[$type])) unset($group[$type]);
262 }
263 if(count($group)){
264 $this->dialog = new faiGroupHandle($group,"remove");
265 }
266 }
267 }elseif($s_action == "group_edit"){
268 if(isset($this->objects[$s_entry])){
269 $group = $this->objects[$s_entry];
270 $this->dialog = new faiGroupHandle($group,"edit");
271 }
272 }elseif($s_action == "group_cut"){
273 if(isset($this->objects[$s_entry])){
274 $group = $this->objects[$s_entry];
275 $this->dialog = new faiGroupHandle($group,"cut");
276 }
277 }elseif($s_action == "group_copy"){
278 if(isset($this->objects[$s_entry])){
279 $group = $this->objects[$s_entry];
280 $this->dialog = new faiGroupHandle($group,"copy");
281 }
282 }
283 if($this->dialog instanceOf faiGroupHandle){
284 $this->dialog->save_object();
285 if($this->dialog->is_open()){
286 return($this->dialog->execute());
287 }elseif($this->dialog->is_canceled() || isset($_POST['cancel_lock'])){
288 $this->dialog = FALSE;
289 }else{
290 if(!count($this->dialog->get_selected())){
291 $this->dialog = FALSE;
292 }
293 }
294 }
296 /********************
297 Copy & Paste
298 ********************/
300 /* Display the copy & paste dialog, if it is currently open */
301 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
302 if($ret){
303 return($ret);
304 }
307 /********************
308 Delete MULTIPLE entries confirmed
309 ********************/
311 /* Confirmation for deletion has been passed. Users should be deleted. */
312 if (isset($_POST['delete_multiple_fai_object_confirm'])){
314 /* Find out more about the object type */
315 $ldap = $this->config->get_ldap_link();
317 /* Remove user by user and check acls before removeing them */
318 foreach($this->dns as $key => $dn){
319 $ldap->cat($dn, array('objectClass'));
320 $attrs = $ldap->fetch();
321 $type = $this->get_type($attrs);
322 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
323 if(preg_match("/d/",$acl)){
324 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
325 $this->dialog->parent = &$this;
326 $this->dialog->set_acl_base($dn);
327 $this->dialog->by_object[$type[1]]->remove_from_parent ();
328 $this->dialog= FALSE;
329 FAI::save_release_changes_now();
330 $to_del = FAI::clean_up_releases($dn);
331 /* Remove sub-objects (e.g. the variable key/value of a FAIvariable) from LDAP entirely */
332 $to_del += FAI::get_child_objects($dn);
333 foreach($to_del as $dn){
334 $ldap->rmdir_recursive($dn);
335 }
336 } else {
338 /* Normally this shouldn't be reached, send some extra
339 logs to notify the administrator */
340 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
341 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
342 }
343 }
345 /* Remove lock file after successfull deletion */
346 $this->remove_lock();
347 $this->dns = array();
348 $this->dialog = FALSE;
349 }
352 /****************
353 Delete confirme dialog
354 ****************/
356 if ($s_action=="del_multiple" ||
357 $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "remove"){
359 /* Collect objects to delete and check if objects are freezed
360 */
361 $dns = array();
362 $errors = "";
363 $this->dns = array();
364 if($this->dialog instanceOf faiGroupHandle){
365 $to_delete = $this->dialog->get_selected();
366 }else{
367 $ids = $this->list_get_selected_items();
368 $to_delete = array();
369 foreach($ids as $id){
370 foreach($this->objects[$id] as $obj) {
371 array_push($to_delete, $obj);
372 }
373 }
374 }
376 foreach($to_delete as $obj){
377 if(isset($obj['type']) && in_array($obj['type'],array("opsi_netboot","opsi_local"))){
378 continue;
379 }
380 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
381 $errors .= $obj['cn'].", ";
382 }else{
383 $this->dns[] = $obj['dn'];
384 }
385 }
387 if($errors != ""){
388 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
389 "<br><br>".trim($errors,", ")),INFO_DIALOG);
390 }
392 /* Check locking
393 */
394 if(count($this->dns)){
395 if ($user= get_multiple_locks($this->dns)){
396 return(gen_locked_message($user,$this->dns));
397 }
398 if(count($this->dns)){
399 $dns_names = array();
400 foreach($this->dns as $dn){
401 add_lock ($dn, $this->ui->dn);
402 $dns_names[] = LDAP::fix($dn);
403 }
404 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
405 $smarty->assign("multiple", true);
406 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
407 }
408 }
409 }
413 /********************
414 Delete MULTIPLE entries Canceled
415 ********************/
417 /* Remove lock */
418 if(isset($_POST['delete_multiple_fai_object_cancel'])){
419 $this->remove_lock();
420 $this->dns = array();
421 }
423 /****************
424 Edit entry
425 ****************/
427 if($s_action == "edit" || $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "edit"){
429 $entry = array();
430 if($this->dialog instanceOf faiGroupHandle){
431 $entries = $this->dialog->get_selected();
432 $entry = array_pop($entries);
433 }elseif(isset($this->objects[$i_entryID][$s_entryType])){
434 $entry = $this->objects[$i_entryID][$s_entryType];
435 }
437 if(count($entry)){
438 $a_setup = $this->get_type($entry);
440 /* Special handling for opsi products
441 */
443 if(in_array($entry['type'],array("opsi_local","opsi_netboot")) &&
444 $this->opsi instanceof opsi && $this->opsi->enabled() ){
446 $name = $entry['cn'];
447 $cfg = $this->opsi->get_product_properties($name);
448 $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
449 if(isset($this->dialog->by_object['opsiProperties'])){
450 $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
451 $this->dialog->by_object['opsiProperties']->set_product($name);
452 }else{
453 trigger_error("Unknown tab, please check config.");
454 }
455 }elseif(count($a_setup)){
457 $this->dn = $entry['dn'];
458 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
459 if (($user= get_lock($this->dn)) != ""){
460 return(gen_locked_message ($user, $this->dn, TRUE));
461 }
462 add_lock ($this->dn, $this->ui->dn);
464 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
465 $this->dialog->parent = &$this;
466 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
467 $this->dialog->set_acl_base($this->dn);
468 $this->is_dialog = true;
469 set_object_info($this->dn);
470 }
471 }
472 }
475 /* Branch handling
476 09.01.2006
477 */
479 /****************
480 Remove branch
481 ****************/
483 /* Remove branch
484 */
485 if($s_action == "remove_branch"){
486 $base= $this->fai_release;
488 /* Check if we have a post remove method configured
489 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
490 */
491 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
492 /* Load permissions for selected 'dn' and check if
493 we're allowed to remove this 'dn' */
494 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
495 $smarty->assign("release_hidden",base64_encode($this->fai_release));
496 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
497 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
498 } else {
499 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
500 }
501 }
502 }
505 /****************
506 Remove branch confirmed
507 ****************/
509 if(isset($_POST['delete_branch_confirm'])){
511 /* Check if we have a post remove method configured
512 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
513 */
514 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
516 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
517 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
518 }else{
520 $bb = $this->fai_release;
521 if(!isset($ldap)){
522 $ldap = $this->config->get_ldap_link();
523 }
525 $br = $this->getBranches();
527 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
528 $name = $br[$bb];
530 $ldap->cd($bb);
531 $ldap->recursive_remove();
532 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
533 $ldap->recursive_remove();
534 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
535 $ldap->recursive_remove();
537 /* Search for all groups with configured application menus.
538 - First search all groups, to ensure that we only remove entries form whithin groups.
539 - The search für menu configuration for the specified release and collect all those dns.
540 - Remove entries
541 */
542 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
543 $ldap->cd($this->config->current['BASE']);
544 $ldap->search("(objectClass=posixGroup)",array("dn"));
546 /* Collect all group dns
547 */
548 $groups = array();
549 while($attrs = $ldap->fetch()){
550 $groups[] = $attrs['dn'];
551 }
553 /* Collect all group menu release dns that match the release we have removed
554 */
555 $dns = array();
556 foreach($groups as $dn){
557 $ldap->cd($dn);
558 $ldap->search("(objectClass=FAIbranch)",array("dn"));
559 while($attrs = $ldap->fetch()){
560 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
561 $dns[] = $attrs['dn'];
562 }
563 }
564 }
566 /* Finally remove collected release dns
567 */
568 foreach($dns as $dn){
569 $ldap->cd($dn);
570 $ldap->recursive_remove();
571 }
573 /* Post remove */
574 $this->fai_release = $this->fai_base;
575 $this->lock_name = $name;
576 $this->lock_dn = $bb;
577 $this->postremove();
579 $fai_filter = session::get("fai_filter");
580 $fai_filter['fai_release'] = $this->fai_release;
581 session::set("fai_filter",$fai_filter);
583 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
584 }
585 }
586 }
587 }
590 /****************
591 Create a new branch "insert Name"
592 ****************/
594 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
595 session::set('LASTPOST',$_POST);
597 if($this->dispNewBranch){
598 $type = "branch";
599 }else{
600 $type = "freeze";
601 }
603 /* Check branch name */
604 $name = $_POST['BranchName'];
605 $is_ok = true;
606 $smarty->assign("BranchName",$name);
607 $base= $this->fai_base;
609 /* Check used characters */
610 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
611 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
612 $is_ok = false;
613 }
615 /* Check if this name is already in use */
616 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
617 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
618 $is_ok = false;
619 }
621 if($is_ok){
623 if(session::is_set('LASTPOST')){
624 $LASTPOST = session::get('LASTPOST');
625 }else{
626 $LASTPOST = array();
627 }
628 $LASTPOST['base'] = $base;
629 $LASTPOST['type'] = $type;
630 session::set('LASTPOST',$LASTPOST);
631 $smarty->assign("iframe", true);
632 $smarty->assign("plugID", $_GET['plug']);
633 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
634 return($display);
635 }
636 }
639 /****************
640 Create a new branch
641 ****************/
643 if(isset($_GET['PerformBranch'])){
645 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
646 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
647 }else{
649 /* In order to see error messages we have to reset the error handler.
650 Due to the exit();
651 */
652 restore_error_handler();
654 /* Create it know */
655 $this->dispNewBranch = false;
656 $this->dispNewFreeze = false;
658 $LASTPOST = session::get('LASTPOST');
659 $base = $LASTPOST['base'];
660 $_POST = session::get('LASTPOST');
661 $name = $_POST['BranchName'];
663 $type = $LASTPOST['type'];
664 $ldap = $this->config->get_ldap_link();
666 $baseToUse = $base;
667 if($this->fai_release != $this->fai_base){
668 $baseToUse = $this->fai_release;
669 }
671 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
673 $CurrentReleases = $this->getBranches();
674 $NewReleaseName = $name;
675 if(isset($CurrentReleases[$this->fai_release])) {
676 if($this->fai_release != $this->fai_base){
677 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
678 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
679 }else{
680 $NewReleaseName = $name;
681 }
682 }
684 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse);
685 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
687 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse);
688 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
690 /* Check if source depeartments exist */
691 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
692 $ldap->cd($this->config->current['BASE']);
693 $ldap->cat($dep);
694 if(!$ldap->count()){
695 $ldap->create_missing_trees($dep);
696 }
697 }
699 /* Print header to have styles included */
700 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
701 <html>
702 <head>
703 <title></title>
704 <style type="text/css">@import url("themes/default/style.css");</style>
705 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
706 </head>
707 <body style="background: none;margin:3px;color:black">
708 ';
710 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
712 /* Duplicate group application releases
713 */
714 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
716 /* Duplicate applications
717 */
718 $ldap->cat($appsrc,array("dn")) ;
719 if($ldap->count()){
720 $ldap->cd ($appdst);
721 $ldap->recursive_remove();
722 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
723 }
725 /* Duplicate mime types
726 */
727 $ldap->cat($mimesrc,array("dn")) ;
728 if($ldap->count()){
729 $ldap->cd ($mimedst);
730 $ldap->recursive_remove();
731 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
732 }
734 $attr = array();
735 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
736 $attr['ou'] = $name;
737 $attr['FAIstate'] = $type;
738 $ldap->cd($this->config->current['BASE']);
739 $ldap->cd("ou=".$name.",".$baseToUse);
740 $ldap->cat("ou=".$name.",".$baseToUse);
741 if($ldap->count()){
742 $ldap->modify($attr);
743 }else{
744 $ldap->add($attr);
745 }
747 /* Duplicate fai objects
748 */
749 // $ldap->cd ("ou=".$name.",".$baseToUse);
750 // $ldap->recursive_remove();
751 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
753 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
754 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
755 <input type='hidden' name='php_c_check' value='1'>
756 </form></div>";
758 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
760 /* Print footer to have valid html */
761 echo "</body></html>";
763 $this->dispNewFreeze = false;
765 /* Postcreate */
767 /* Assign possible attributes */
768 $this->lock_type = $type;
769 $this->lock_name = $name;
770 $this->lock_dn = $baseToUse;
771 $this->postcreate();
774 /* Send daemon event to reload the fai release database
775 */
776 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
777 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
778 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
779 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
780 $tmp = new $evt['CLASS_NAME']($this->config);
781 $tmp->set_type(TRIGGERED_EVENT);
782 $tmp->add_targets(array("GOSA"));
783 $o_queue = new gosaSupportDaemon();
784 if(!$o_queue->append($tmp)){
785 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
786 }
787 }
788 }else{
789 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
790 msg_dialog::display(_("Fatal error"),
791 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
792 FATAL_ERROR_DIALOG);
793 }
794 exit();
795 }
796 }
798 /****************
799 Display dialog to enter new Branch name
800 ****************/
802 /* Check if we have a post create method configured
803 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
804 */
805 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
806 if(($s_action == "branch_branch")||($this->dispNewBranch)){
807 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
808 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
809 }else{
810 $this->dispNewBranch=true;
811 $smarty->assign("iframe",false);
812 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
813 return($display);
814 }
815 }
816 }
819 /****************
820 Display dialog to enter new Freeze name
821 ****************/
823 /* Check if we have a post create method configured
824 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
825 */
826 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
827 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
828 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
829 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
830 }else{
831 $this->dispNewFreeze = true;
832 $smarty->assign("iframe",false);
833 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
834 return($display);
835 }
836 }
837 }
840 /****************
841 Create a new object
842 ****************/
844 $types = array( "new_partition" => "FAIpartitionTable",
845 "new_script" => "FAIscript",
846 "new_hook" => "FAIhook",
847 "new_variable" => "FAIvariable",
848 "new_template" => "FAItemplate",
849 "new_package" => "FAIpackageList");
850 $types_i18n = array( "new_partition" => _("partition table"),
851 "new_script" => _("script"),
852 "new_hook" => _("hook"),
853 "new_variable" => _("variable"),
854 "new_template" => _("template"),
855 "new_package" => _("package list"));
857 if(isset($types[$s_action])){
859 $type_acl_mapping = array(
860 "FAIpartitionTable" => "faiPartitionTable",
861 "FAIpackageList" => "faiPackage",
862 "FAIscript" => "faiScript",
863 "FAIvariable" => "faiVariable",
864 "FAIhook" => "faiHook",
865 "FAIprofile" => "faiProfile",
866 "FAItemplate" => "faiTemplate");
868 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
869 if(preg_match("/c/",$acl)){
870 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
871 $this->dialog->parent = &$this;
872 }else{
873 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
874 }
875 }
877 /* New Profile */
878 if($s_action == "new_profile"){
879 $this->dn = "new" ;
881 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
882 if(preg_match("/c/",$acl)){
883 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
884 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
885 $this->dialog->set_acl_base($this->acl_base);
886 $this->dialog->parent = &$this;
888 $this->is_dialog = false;
889 }else{
890 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
891 }
892 }
895 /****************
896 Get name from ask_class_name dialog
897 ****************/
899 if($s_action == "select_class_name_finished"){
900 $this->dialog->save_object();
901 if(count($this->dialog->check())!=0){
902 foreach($this->dialog->check() as $msg){
903 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
904 }
905 }elseif(isset($this->dialog->objectClass)){
906 $this->dn = "new" ;
907 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
908 $name = $this->dialog->save();
910 if(class_exists($a_setup[0])){
911 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
912 $this->dialog->set_acl_base($this->acl_base);
913 $this->dialog->by_object[$a_setup[1]]->cn = $name;
914 $this->dialog->parent = &$this;
915 $this->is_dialog = true;
916 }
917 }
918 }
921 /****************
922 Cancel dialogs
923 ****************/
925 if(isset($_POST['edit_cancel'])){
926 $this->dialog=FALSE;
927 $this->is_dialog = false;
928 set_object_info();
929 $this->remove_lock();
930 }
933 /****************
934 Handle opsi dialogs
935 ****************/
937 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
938 $this->dialog = NULL;
939 }
940 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
941 $this->dialog->save_object();
942 $op = $this->dialog->by_object['opsiProperties'];
943 $name = $op->get_product();
944 $cfg = $op->get_cfg();
945 $this->opsi->set_product_properties($name,$cfg);
946 if($this->opsi->is_error()){
947 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
948 }else{
949 $this->dialog = NULL;
950 }
951 }
952 if($this->dialog instanceof tabs_opsiProdConfig){
953 $this->dialog->save_object();
954 return($this->dialog->execute());
955 }
958 /****************
959 Save sub dialogs
960 ****************/
962 /* This check if the given tab could be saved
963 * If it was possible to save it, remove dialog object.
964 * If it wasn't possible, show errors and keep dialog.
965 */
966 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
967 $this->dialog->save_object();
968 $msgs= $this->dialog->check();
969 if(count($msgs)!=0){
970 foreach($msgs as $msg){
971 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
972 }
973 }else{
974 $this->dialog->save();
975 FAI::save_release_changes_now();
976 if (!isset($_POST['edit_apply'])){
977 $this->remove_lock();
978 $this->dialog=FALSE;
979 $this->is_dialog=false;
980 set_object_info();
981 }else{
983 /* Reinitialize tab */
984 if($this->dialog instanceof tabs){
985 $this->dialog->re_init();
986 }
987 }
988 }
989 }
992 /****************
993 Display currently open dialog
994 ****************/
996 /* If dialog is set, but $this->is_dialog==false, then
997 * only the "abort" button is shown, this are dialogs that must not be saved.
998 * If is_dialog == true, we are currently editing tab objects.
999 * Here we need both, save and cancel
1000 */
1002 if(is_object($this->dialog)){
1003 $display .= $this->dialog->execute();
1004 /* Don't show buttons if tab dialog requests this */
1006 if(isset($this->dialog->current)){
1008 $obj = $this->dialog->by_object[$this->dialog->current];
1010 if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
1011 $display.= "<p style=\"text-align:right\">
1012 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1013 </p>";
1014 }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1016 $display.= "<p style=\"text-align:right\">\n";
1017 if(!$this->no_save){
1018 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1019 $display.= " \n";
1020 if ($this->dn != "new"){
1021 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1022 $display.= " \n";
1023 }
1024 }
1025 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1026 $display.= "</p>";
1027 }elseif(!isset($this->dialog->current)){
1028 $display.= "<p style=\"text-align:right\">\n";
1029 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1030 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1031 $display.= "</p>";
1032 }
1033 }else{
1034 $display.= "<p style=\"text-align:right\">\n";
1035 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1036 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1037 $display.= "</p>";
1039 }
1040 return($display);
1041 }
1044 /****************
1045 Dialog display
1046 ****************/
1048 /* Check if there is a snapshot dialog open */
1049 $base = $this->fai_base;
1050 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1051 return($str);
1052 }
1054 /* Display dialog with system list */
1055 $this->reload();
1056 $this->DivListFai->parent = &$this;
1057 $this->DivListFai->execute();
1058 $this->DivListFai->setEntries($this->objects);
1059 return($this->DivListFai->Draw());
1060 }
1063 /* Return departments, that will be included within snapshot detection */
1064 function get_used_snapshot_bases()
1065 {
1066 $tmp = array();
1067 $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1068 foreach($types as $type){
1069 $tmp[] = get_ou($type).$this->fai_release;
1070 }
1071 return($tmp);
1072 }
1075 /* Get available branches for current base */
1076 function getBranches($base = false,$prefix = "")
1077 {
1078 $ret = array("/"=>$this->fai_base);
1079 $ldap = $this->config->get_ldap_link();
1080 if(!$base){
1081 $base = $this->fai_base;
1082 }
1083 $tmp = FAI::get_all_releases_from_base($base,true);
1084 foreach($tmp as $dn => $name){
1085 $ret[$name]=$dn;
1086 }
1087 ksort($ret);
1088 $ret = array_flip($ret);
1090 return ($ret);
1091 }
1094 function list_get_selected_items()
1095 {
1096 $ids = array();
1097 foreach($_POST as $name => $value){
1098 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1099 $id = preg_replace("/^item_selected_/","",$name);
1100 $ids[$id] = $id;
1101 }
1102 }
1103 return($ids);
1104 }
1107 /* reload list of objects */
1108 function reload()
1109 {
1110 /* Variable initialisation */
1111 $str = "";
1112 $Regex = $this->DivListFai->Regex;
1113 $this->objects = array();
1115 /* Get base */
1116 $base = $this->fai_base;
1117 if($this->fai_release != $this->fai_base){
1118 $br = $this->getBranches();
1119 if(isset($br[$this->fai_release])){
1120 $base = $this->fai_release;
1121 }else{
1122 $base = $this->fai_base;
1123 }
1124 }
1125 $this->base = $base;
1126 $this->set_acl_base($this->acl_base);
1128 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1130 /* Create a new list of FAI object
1131 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1132 */
1133 $ObjectTypes = array(
1134 "FAIpartitionTable" => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1135 "FAIpackageList" => array("OU"=> get_ou('faiPackageRDN') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1136 "FAIscript" => array("OU"=> get_ou('faiScriptRDN') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1137 "FAIvariable" => array("OU"=> get_ou('faiVariableRDN') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1138 "FAIhook" => array("OU"=> get_ou('faiHookRDN') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1139 "FAIprofile" => array("OU"=> get_ou('faiProfileRDN') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1140 "FAItemplate" => array("OU"=> get_ou('faiTemplateRDN') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1142 $filter = "";
1143 foreach($ObjectTypes as $key => $data){
1144 if($this->DivListFai->$data['CHKBOX']){
1145 $filter.= "(objectClass=".$key.")";
1146 }
1147 }
1148 $filter = "(&(|".$filter.")(cn=$Regex))";
1150 /* Get resolved release dependencies */
1151 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1153 /* Ge listed ldap objects */
1154 $ldap = $this->config->get_ldap_link();
1155 $ldap->cd($this->config->current['BASE']);
1157 foreach($tmp as $entry){
1159 /* Get some more informations about the object */
1160 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1161 $object = $ldap->fetch();
1163 /* Walk through possible types */
1164 foreach($ObjectTypes as $type => $rest){
1166 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1168 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1170 /* Prepare object */
1171 unset($object['objectClass']['count']);
1172 if(!isset($object['description'][0])){
1173 $object['description'][0]="";
1174 }
1176 /* Clean up object informations */
1177 $obj = array();
1178 $obj['cn'] = $object['cn'][0];
1179 $obj['dn'] = $object['dn'];
1180 $obj['acl'] = $acl;
1181 $obj['class'] = $rest ['ACL'];
1182 $obj['FAIstate'] = $entry['FAIstate'];
1183 $obj['description'] = $object['description'][0];
1184 $obj['objectClass'] = $object['objectClass'];
1186 $this->objects[$obj['cn']][$type] = $obj;
1187 $this->objects[$obj['cn']][$type]['type']=$type;
1188 }
1189 }
1190 }
1192 /* Append opsi objects, if opsi is available and if we are on the fai_base
1193 */
1194 if($this->opsi instanceof opsi && $this->opsi->enabled()){
1195 $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1196 if(preg_match("/r/",$opsi_acl)){
1197 $err = FALSE;
1198 if(!$err && $this->DivListFai->ShowOpsiNetboot){
1199 $n_pro = $this->opsi->get_netboot_products();
1200 $err |= $this->opsi->is_error();
1201 foreach($n_pro as $name => $data){
1202 $entry = array(
1203 "cn" => $name,
1204 "description" => $data['DESC'],
1205 "type" => "opsi_netboot");
1206 $this->objects[$name]['opsi_netboot'] = $entry;
1207 }
1208 }
1209 if(!$err && $this->DivListFai->ShowOpsiLocal){
1210 $l_pro = $this->opsi->get_local_products();
1211 $err |= $this->opsi->is_error();
1212 foreach($l_pro as $name => $data){
1213 $entry = array("cn" => $name,
1214 "description" => $data['DESC'],
1215 "type" => "opsi_local");
1216 $this->objects[$name]["opsi_local"] = $entry;
1217 }
1218 }
1219 if($err){
1220 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1221 }
1222 }
1223 }
1225 uksort($this->objects, 'strnatcasecmp');
1226 reset ($this->objects);
1227 $this->objects = array_values($this->objects);
1228 }
1230 function remove_lock()
1231 {
1232 if (isset($this->dn) && !empty($this->dn)){
1233 del_lock ($this->dn);
1234 }
1235 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1236 del_lock ($this->dns);
1237 }
1238 }
1240 function get_type($array){
1241 if(!isset($array['objectClass'])) return(array());
1242 if(in_array("FAIpartitionTable",$array['objectClass'])){
1243 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1244 }
1245 if(in_array("FAIscript",$array['objectClass'])){
1246 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1247 }
1248 if(in_array("FAItemplate",$array['objectClass'])){
1249 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1250 }
1251 if(in_array("FAIhook",$array['objectClass'])){
1252 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1253 }
1254 if(in_array("FAIvariable",$array['objectClass'])){
1255 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1256 }
1257 if(in_array("FAIprofile",$array['objectClass'])){
1258 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1259 }
1261 if(in_array("FAIpackageList",$array['objectClass'])){
1262 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1263 }
1264 return(array());
1265 }
1267 function CheckNewBranchName($name,$base)
1268 {
1269 $f = $this->fai_release;
1270 if($name == ""){
1271 return(false);
1272 }elseif(in_array($name,$this->getBranches($f))) {
1273 return(false);
1274 }elseif(tests::is_department_name_reserved($name,$base)){
1275 return(false);
1276 }
1277 return(true);
1278 }
1280 function save_object()
1281 {
1282 $this->DivListFai->save_object();
1284 /* Get posted release */
1285 $r_releases = array_flip($this->getBranches());
1286 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1288 /* Ensure that we have a valid release selected */
1289 if(!isset($r_releases[get_post('fai_release')])){
1290 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1291 $_POST = array();
1292 $plug =$_GET['plug'];
1293 $_GET = array("plug" => $plug);
1294 $this->fai_release = $this->fai_base;
1295 }else{
1296 $this->fai_release = $r_releases[get_post('fai_release')];
1297 }
1299 $fai_filter = session::get("fai_filter");
1300 $fai_filter['fai_release'] = $this->fai_release;
1301 session::set("fai_filter",$fai_filter);
1302 }
1304 if(is_object($this->CopyPasteHandler)){
1305 $this->CopyPasteHandler->save_object();
1306 }
1307 }
1310 function copyPasteHandling_from_queue($s_action,$s_entry)
1311 {
1312 /* Check if Copy & Paste is disabled */
1313 if(!is_object($this->CopyPasteHandler)){
1314 return("");
1315 }
1317 $ui = get_userinfo();
1319 /* Add a single entry to queue */
1320 if($this->dialog instanceOf faiGroupHandle && !$this->dialog->is_open()){
1322 if(in_array($this->dialog->get_mode(),array("copy"))){
1324 /* Cleanup object queue */
1325 $this->CopyPasteHandler->cleanup_queue();
1326 $group = $this->dialog->get_selected();
1327 foreach($group as $entry){
1328 $a_setup = $this->get_type($entry);
1329 $dn = $entry['dn'];
1330 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1331 $this->CopyPasteHandler->add_to_queue($dn,$this->dialog->get_mode(),$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1332 }
1333 }
1334 $this->dialog = FALSE;
1335 }
1336 }
1338 /* Add entries to queue */
1339 if($s_action == "copy_multiple"){
1341 /* Cleanup object queue */
1342 $this->CopyPasteHandler->cleanup_queue();
1344 /* Add new entries to CP queue */
1345 foreach($this->list_get_selected_items() as $id){
1346 $group = $this->objects[$id];
1347 foreach($group as $entry){
1348 $a_setup = $this->get_type($entry);
1349 $dn = $entry['dn'];
1351 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1352 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1353 }
1354 }
1355 }
1356 }
1358 /* Start pasting entries */
1359 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1360 $this->start_pasting_copied_objects = TRUE;
1361 }
1363 /* Return C&P dialog */
1364 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1366 /* Get dialog */
1367 $this->CopyPasteHandler->SetVar("parent",$this);
1368 $data = $this->CopyPasteHandler->execute();
1370 FAI::save_release_changes_now();
1372 /* Return dialog data */
1373 if(!empty($data)){
1374 return($data);
1375 }
1376 }
1378 /* Automatically disable status for pasting */
1379 if(!$this->CopyPasteHandler->entries_queued()){
1380 $this->start_pasting_copied_objects = FALSE;
1381 }
1382 return("");
1383 }
1386 /* Check if the given FAI class is used in this release
1387 */
1388 static function check_class_name($oc,$name,$dn)
1389 {
1390 $base = FAI::get_release_dn($dn);
1392 if($oc == "FAIprofile"){
1393 $f = "";
1394 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1395 foreach($ocs as $oc){
1396 $f .= "(objectClass=".$oc.")";
1397 }
1398 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
1399 }else{
1400 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1401 }
1402 $delete = array();
1403 $used = array();
1404 foreach($res as $object){
1405 $used[$object['cn'][0]]= $object['cn'][0];
1406 }
1407 return($used);
1408 }
1411 /* Return plugin informations for acl handling */
1412 static function plInfo()
1413 {
1414 return (array(
1415 "plShortName" => _("FAI releases"),
1416 "plDescription" => _("FAI release management"),
1417 "plSelfModify" => FALSE,
1418 "plDepends" => array(),
1419 "plPriority" => 0,
1420 "plSection" => array("administration"),
1421 "plCategory" => array("fai"=> array("description" => _("FAI"),
1422 "objectClass" => "FAIclass")),
1423 "plProvidedAcls"=> array()));
1424 }
1425 }
1426 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1427 ?>