1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 class faiManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Software deployment";
26 var $plDescription = "Manage software packages and deployment reciepes";
28 /* Headpage attributes */
29 var $lock_type = ""; // should be branch/freeze
30 var $lock_name = "";
31 var $lock_dn = "";
33 /* attribute list for save action */
34 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
35 var $objectclasses= array(); // ObjectClasses which the attributes are related to
36 var $dialog = array(); // This object contains every dialog we have currently opened
38 var $objects = array(); // This array contains all available objects shown in divlist
39 var $is_dialog = false;
41 var $dispNewBranch= false;
42 var $dispNewFreeze= false;
44 var $DivListFai;
45 var $start_pasting_copied_objects = FALSE;
46 var $CopyPasteHandler = FALSE;
48 /* Allow inserting of new elements if freezed releases
49 */
50 var $allow_freeze_object_attach = FALSE;
52 var $no_save;
53 var $fai_base ="";
54 var $fai_release ="";
56 /* construction/reconstruction
57 */
58 function faiManagement (&$config, $ui)
59 {
60 /* Set defaults */
61 $this->dn = "";
62 $this->config = $config;
63 $this->ui = $ui;
65 /* Creat dialog object */
66 $this->DivListFai = new divListFai($this->config,$this);
68 /* Copy & Paste handler */
69 if ($this->config->boolValueIsTrue($this->fai_base, "enableCopyPaste")){
70 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
71 }
73 /* Set default release */
74 $this->fai_base = get_ou("faiou").$this->config->current['BASE'];
75 if(!session::is_set("fai_filter")){
76 session::set("fai_filter",array("fai_release" => $this->fai_base));
77 }
79 $fai_filter = session::get("fai_filter");
80 $this->fai_release = $fai_filter['fai_release'];
81 }
83 function execute()
84 {
85 /* Call parent execute */
86 plugin::execute();
88 /* Initialise vars and smarty */
89 $smarty = get_smarty();
90 $smarty->assign("BranchName","");
92 $display = "";
93 $s_action = "";
94 $s_entry = "";
95 $no_save = FALSE; // hide Apply / Save buttons
97 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
98 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/"));
101 /****************
102 Handle posts
103 ****************/
105 /* Check ImageButton posts
106 * Create new tab ich new_xx is posted
107 */
108 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
109 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
110 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
111 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
112 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
113 "/edit_continue/"=>"select_class_name_finished",
114 "/^multiple_copy_fai/" => "copy_multiple",
115 "/^multiple_cut_fai/" => "cut_multiple",
116 "/^copy/" => "copy",
117 "/^cut/" => "cut",
118 "/^remove_multiple_fai_objects/" => "del_multiple");
120 foreach($_POST as $name => $value){
121 foreach($posts as $reg => $act ){
122 if(preg_match($reg,$name)){
123 $s_action = $act;
124 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
125 $s_entry = preg_replace("/_.*$/","",$s_entry);
126 }
127 }
128 if(preg_match("/^entry_edit_.*/",$name)){
129 $s_entry = preg_replace("/^entry_edit_/","",$name);
130 $s_entry = preg_replace("/_.*$/","",$s_entry);
131 $s_action = "edit";
132 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
133 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
134 $s_entry = preg_replace("/_.*$/","",$s_entry);
135 $s_action = "edit";
136 $no_save = TRUE;
137 }elseif(preg_match("/^entry_delete_.*/",$name)){
138 $s_entry = preg_replace("/^entry_delete_/","",$name);
139 $s_entry = preg_replace("/_.*$/","",$s_entry);
140 $s_action = "delete";
141 }
142 }
144 if(isset($_GET['edit_entry'])){
145 $s_entry = $_GET['edit_entry'];
146 $s_action = "edit";
147 }
149 if(isset($_GET['edit_freeze_entry'])){
150 $s_entry = $_GET['edit_freeze_entry'];
151 $s_action = "edit";
152 $no_save = TRUE;
153 }
155 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
156 $s_action = "freeze_branch";
157 }
158 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
159 $s_action = "branch_branch";
160 }
161 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
162 $s_action = "remove_branch";
163 }
165 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
166 $this->dispNewBranch = false;
167 $this->dispNewFreeze = false;
168 }
171 $type_acl_mapping = array(
172 "FAIpartitionTable" => "faiPartitionTable",
173 "FAIpackageList" => "faiPackage",
174 "FAIscript" => "faiScript",
175 "FAIvariable" => "faiVariable",
176 "FAIhook" => "faiHook",
177 "FAIprofile" => "faiProfile",
178 "FAItemplate" => "faiTemplate");
181 /* handle C&P from layers menu */
182 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
183 $s_action = "copy_multiple";
184 }
185 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
186 $s_action = "cut_multiple";
187 }
188 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
189 $s_action = "editPaste";
190 }
192 /* Create options */
193 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
194 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
195 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
196 }
198 /* handle remove from layers menu */
199 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
200 $s_action = "del_multiple";
201 }
204 if(!empty($s_action)){
205 $this->no_save = $no_save;
206 }
208 /********************
209 Copy & Paste
210 ********************/
212 /* Display the copy & paste dialog, if it is currently open */
213 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
214 if($ret){
215 return($ret);
216 }
219 /****************
220 Delete confirme dialog
221 ****************/
223 if ($s_action=="delete"){
225 /* Get 'dn' from posted termlinst */
226 $this->dn= $this->objects[$s_entry]['dn'];
228 /* Load permissions for selected 'dn' and check if
229 we're allowed to remove this 'dn' */
230 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
231 if(preg_match("/d/",$acl)){
233 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
234 if (($user= get_lock($this->dn)) != ""){
235 return(gen_locked_message ($user, $this->dn));
236 }
238 /* Lock the current entry, so nobody will edit it during deletion */
239 add_lock ($this->dn, $this->ui->dn);
240 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
241 $smarty->assign("multiple", false);
242 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
243 } else {
245 /* Obviously the user isn't allowed to delete. Show message and clean session. */
246 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
247 }
248 }
251 /********************
252 Delete MULTIPLE entries requested, display confirm dialog
253 ********************/
255 if ($s_action=="del_multiple"){
256 $this->dns = array();
257 $ids = $this->list_get_selected_items();
259 if(count($ids)){
261 $errors = "";
262 foreach($ids as $id){
263 $dn = $this->objects[$id]['dn'];
264 $cn = $this->objects[$id]['cn'];
265 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
266 $this->dns[$id] = $dn;
267 }else{
268 $errors .= $cn.", ";
269 }
270 }
271 if ($user= get_multiple_locks($this->dns)){
272 return(gen_locked_message($user,$this->dns));
273 }
275 if($errors != ""){
276 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
277 "<br><br>".trim($errors,", ")),INFO_DIALOG);
278 }
280 if(count($this->dns)){
282 $dns_names = array();
283 foreach($this->dns as $dn){
284 add_lock ($dn, $this->ui->dn);
285 $dns_names[] = @LDAP::fix($dn);
286 }
288 /* Lock the current entry, so nobody will edit it during deletion */
289 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
290 $smarty->assign("multiple", true);
291 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
292 }
293 }
294 }
297 /********************
298 Delete MULTIPLE entries confirmed
299 ********************/
301 /* Confirmation for deletion has been passed. Users should be deleted. */
302 if (isset($_POST['delete_multiple_fai_object_confirm'])){
304 /* Find out more about the object type */
305 $ldap = $this->config->get_ldap_link();
307 /* Remove user by user and check acls before removeing them */
308 foreach($this->dns as $key => $dn){
310 $ldap->cat($dn, array('objectClass'));
311 $attrs = $ldap->fetch();
312 $type = $this->get_type($attrs);
314 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
315 if(preg_match("/d/",$acl)){
317 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
318 $this->dialog->parent = &$this;
319 $this->dialog->set_acl_base($dn);
320 $this->dialog->by_object[$type[1]]->remove_from_parent ();
321 unset ($this->dialog);
322 $this->dialog= FALSE;
323 $to_del = FAI::clean_up_releases($dn);
324 FAI::save_release_changes_now();
326 foreach($to_del as $dn){
327 $ldap->rmdir_recursive($dn);
328 }
330 } else {
332 /* Normally this shouldn't be reached, send some extra
333 logs to notify the administrator */
334 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
335 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
336 }
338 /* Remove lock file after successfull deletion */
339 del_lock ($dn);
340 unset($this->dns[$key]);
341 }
342 }
345 /********************
346 Delete MULTIPLE entries Canceled
347 ********************/
349 /* Remove lock */
350 if(isset($_POST['delete_multiple_fai_object_cancel'])){
351 foreach($this->dns as $key => $dn){
352 del_lock ($dn);
353 unset($this->dns[$key]);
354 }
355 }
358 /****************
359 Delete aborted
360 ****************/
362 /* Delete canceled? */
363 if (isset($_POST['delete_cancel'])){
364 del_lock ($this->dn);
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 }
413 /* Remove lock file after successfull deletion */
414 del_lock ($this->dn);
415 }
418 /****************
419 Edit entry
420 ****************/
422 if(($s_action == "edit") && (!isset($this->dialog->config))){
423 $entry = $this->objects[$s_entry];
424 $a_setup = $this->get_type($entry);
425 $this->dn = $entry['dn'];
427 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
428 if (($user= get_lock($this->dn)) != ""){
429 return(gen_locked_message ($user, $this->dn));
430 }
431 add_lock ($this->dn, $this->ui->dn);
433 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
434 $this->dialog->parent = &$this;
435 $this->dialog->set_acl_base($this->dn);
436 $this->is_dialog = true;
438 if(preg_match("/^freeze/", $entry['FAIstate']) || $this->no_save){
439 # $this->dialog->set_acl_base("freezed") ;
440 }
441 session::set('objectinfo',$this->dn);
442 }
445 /* Branch handling
446 09.01.2006
447 */
449 /****************
450 Remove branch
451 ****************/
453 /* Remove branch
454 */
455 if($s_action == "remove_branch"){
456 $base= $this->fai_release;
458 /* Check if we have a post remove method configured
459 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
460 */
461 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
462 /* Load permissions for selected 'dn' and check if
463 we're allowed to remove this 'dn' */
464 if($this->acl_is_removeable()){
466 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->fai_release),_("FAI branch/freeze")));
467 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
468 } else {
469 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
470 }
471 }
472 }
475 /****************
476 Remove branch confirmed
477 ****************/
479 if(isset($_POST['delete_branch_confirm'])){
481 /* Check if we have a post remove method configured
482 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
483 */
484 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
486 $bb = $this->fai_release;
487 if(!isset($ldap)){
488 $ldap = $this->config->get_ldap_link();
489 }
491 $br = $this->getBranches();
493 if(isset($br[$bb]) && $this->acl_is_removeable()){
494 $name = $br[$bb];
495 $ldap->cd($bb);
496 $ldap->recursive_remove();
497 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
498 $ldap->recursive_remove();
499 $this->fai_release = $this->fai_base;
501 /* Post remove */
502 $this->lock_name = $name;
503 $this->lock_dn = $bb;
504 $this->postremove();
506 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
507 }
508 }
509 }
512 /****************
513 Create a new branch "insert Name"
514 ****************/
516 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
517 session::set('LASTPOST',$_POST);
519 if($this->dispNewBranch){
520 $type = "branch";
521 }else{
522 $type = "freeze";
523 }
525 /* Check branch name */
526 $name = $_POST['BranchName'];
527 $is_ok = true;
528 $smarty->assign("BranchName",$name);
529 $base= $this->fai_base;
531 /* Check used characters */
532 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
533 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z \ö\ä\ü\.-_:,]/i"), ERROR_DIALOG);
534 $is_ok = false;
535 }
537 /* Check if this name is already in use */
538 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
539 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
540 $is_ok = false;
541 }
543 if($is_ok){
545 if(session::is_set('LASTPOST')){
546 $LASTPOST = session::get('LASTPOST');
547 }else{
548 $LASTPOST = array();
549 }
550 $LASTPOST['base'] = $base;
551 $LASTPOST['type'] = $type;
552 session::set('LASTPOST',$LASTPOST);
553 $smarty->assign("iframe", true);
554 $smarty->assign("plugID", $_GET['plug']);
555 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
556 return($display);
557 }
558 }
561 /****************
562 Create a new branch
563 ****************/
565 if(isset($_GET['PerformBranch'])){
567 if(!$this->acl_is_createable()){
568 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
569 }else{
571 /* Create it know */
572 $this->dispNewBranch = false;
573 $this->dispNewFreeze = false;
575 $LASTPOST = session::get('LASTPOST');
576 $base = $LASTPOST['base'];
577 $_POST = session::get('LASTPOST');
578 $name = $_POST['BranchName'];
580 $type = $LASTPOST['type'];
581 $ldap = $this->config->get_ldap_link();
583 $baseToUse = $base;
584 if($this->fai_release != $this->fai_base){
585 $baseToUse = $this->fai_release;
586 }
588 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
590 $CurrentReleases = $this->getBranches();
591 $NewReleaseName = $name;
592 if(isset($CurrentReleases[$this->fai_release])) {
593 if($this->fai_release != $this->fai_base){
594 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
595 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
596 }else{
597 $NewReleaseName = $name;
598 }
599 }
601 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
602 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
604 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
605 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
607 /* Check if source depeartments exist */
608 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
609 $ldap->cd($this->config->current['BASE']);
610 $ldap->cat($dep);
611 if(!$ldap->count()){
612 $ldap->create_missing_trees($dep);
613 }
614 }
616 /* Print header to have styles included */
617 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
618 <html>
619 <head>
620 <title></title>
621 <style type="text/css">@import url("themes/default/style.css");</style>
622 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
623 </head>
624 <body style="background: none;margin:3px;color:black">
625 ';
627 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
629 /* Duplicate group application releases
630 */
631 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
633 /* Duplicate applications
634 */
635 $ldap->cat($appsrc,array("dn")) ;
636 if($ldap->count()){
637 $ldap->cd ($appdst);
638 $ldap->recursive_remove();
639 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
640 }
642 /* Duplicate mime types
643 */
644 $ldap->cat($mimesrc,array("dn")) ;
645 if($ldap->count()){
646 $ldap->cd ($mimedst);
647 $ldap->recursive_remove();
648 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
649 }
651 $attr = array();
652 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
653 $attr['ou'] = $name;
654 $attr['FAIstate'] = $type;
655 $ldap->cd($this->config->current['BASE']);
656 $ldap->cd("ou=".$name.",".$baseToUse);
657 $ldap->cat("ou=".$name.",".$baseToUse);
658 if($ldap->count()){
659 $ldap->modify($attr);
660 }else{
661 $ldap->add($attr);
662 }
664 /* Duplicate fai objects
665 */
666 // $ldap->cd ("ou=".$name.",".$baseToUse);
667 // $ldap->recursive_remove();
668 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
670 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
671 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
672 </form></div>";
674 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
676 /* Print footer to have valid html */
677 echo "</body></html>";
679 $this->dispNewFreeze = false;
681 /* Postcreate */
683 /* Assign possible attributes */
684 $this->lock_type = $type;
685 $this->lock_name = $name;
686 $this->lock_dn = $baseToUse;
687 $this->postcreate();
688 exit();
689 }
690 }
692 /****************
693 Display dialog to enter new Branch name
694 ****************/
696 /* Check if we have a post create method configured
697 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
698 */
699 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
700 if(($s_action == "branch_branch")||($this->dispNewBranch)){
701 if(!$this->acl_is_createable()){
702 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
703 }else{
704 $this->dispNewBranch=true;
705 $smarty->assign("iframe",false);
706 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
707 return($display);
708 }
709 }
710 }
713 /****************
714 Display dialog to enter new Freeze name
715 ****************/
717 /* Check if we have a post create method configured
718 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
719 */
720 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
721 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
722 if(!$this->acl_is_createable()){
723 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
724 }else{
725 $this->dispNewFreeze = true;
726 $smarty->assign("iframe",false);
727 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
728 return($display);
729 }
730 }
731 }
734 /****************
735 Create a new object
736 ****************/
738 $types = array( "new_partition" => "FAIpartitionTable",
739 "new_script" => "FAIscript",
740 "new_hook" => "FAIhook",
741 "new_variable" => "FAIvariable",
742 "new_template" => "FAItemplate",
743 "new_package" => "FAIpackageList");
744 $types_i18n = array( "new_partition" => _("partition table"),
745 "new_script" => _("script"),
746 "new_hook" => _("hook"),
747 "new_variable" => _("variable"),
748 "new_template" => _("template"),
749 "new_package" => _("package list"));
751 if(isset($types[$s_action])){
752 $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
753 if(preg_match("/c/",$acl)){
754 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
755 $this->dialog->parent = &$this;
756 }else{
757 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
758 }
759 }
761 /* New Profile */
762 if($s_action == "new_profile"){
763 $this->dn = "new" ;
765 $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
766 if(preg_match("/c/",$acl)){
767 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
768 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
769 $this->dialog->set_acl_base($this->base);
770 $this->dialog->parent = &$this;
772 $this->is_dialog = false;
773 }else{
774 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
775 }
776 }
779 /****************
780 Get from ask class name dialog
781 ****************/
783 if($s_action == "select_class_name_finished"){
784 $this->dialog->save_object();
785 if(count($this->dialog->check())!=0){
786 foreach($this->dialog->check() as $msg){
787 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
788 }
789 }elseif(isset($this->dialog->objectClass)){
790 $this->dn = "new" ;
791 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
792 $name = $this->dialog->save();
794 if(class_exists($a_setup[0])){
795 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
796 $this->dialog->set_acl_base($this->base);
797 $this->dialog->by_object[$a_setup[1]]->cn = $name;
798 $this->dialog->parent = &$this;
799 $this->is_dialog = true;
800 }
801 }
802 }
805 /****************
806 Cancel dialogs
807 ****************/
809 if(isset($_POST['edit_cancel'])){
810 unset($this->dialog);
811 $this->dialog=FALSE;
812 $this->is_dialog = false;
813 session::un_set('objectinfo');
814 del_lock ($this->dn);
815 }
818 /****************
819 Save sub dialogs
820 ****************/
822 /* This check if the given tab could be saved
823 * If it was possible to save it, remove dialog object.
824 * If it wasn't possible, show errors and keep dialog.
825 */
826 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
827 $this->dialog->save_object();
828 $msgs= $this->dialog->check();
829 if(count($msgs)!=0){
830 foreach($msgs as $msg){
831 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
832 }
833 }else{
834 $this->dialog->save();
835 FAI::save_release_changes_now();
836 if (!isset($_POST['edit_apply'])){
837 del_lock ($this->dn);
838 unset($this->dialog);
839 $this->dialog=FALSE;
840 $this->is_dialog=false;
841 session::un_set('objectinfo');
842 }
843 }
844 }
847 /****************
848 Display currently open dialog
849 ****************/
851 /* If dialog is set, but $this->is_dialog==false, then
852 * only the "abort" button is shown, this are dialogs that must not be saved.
853 * If is_dialog == true, we are currently editing tab objects.
854 * Here we need both, save and cancel
855 */
857 if(is_object($this->dialog)){
858 $display .= $this->dialog->execute();
859 /* Don't show buttons if tab dialog requests this */
861 if(isset($this->dialog->current)){
863 $obj = $this->dialog->by_object[$this->dialog->current];
865 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
867 $display.= "<p style=\"text-align:right\">\n";
868 if(!$this->no_save){
869 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
870 $display.= " \n";
871 if ($this->dn != "new"){
872 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
873 $display.= " \n";
874 }
875 }
876 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
877 $display.= "</p>";
878 }elseif(!isset($this->dialog->current)){
879 $display.= "<p style=\"text-align:right\">\n";
880 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
881 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
882 $display.= "</p>";
883 }
884 }else{
885 $display.= "<p style=\"text-align:right\">\n";
886 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
887 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
888 $display.= "</p>";
890 }
891 return($display);
892 }
895 /****************
896 Dialog display
897 ****************/
899 /* Check if there is a snapshot dialog open */
900 $base = $this->fai_base;
901 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
902 return($str);
903 }
905 /* Display dialog with system list */
906 $this->reload();
907 $this->DivListFai->parent = $this;
908 $this->DivListFai->execute();
909 $this->DivListFai->setEntries($this->objects);
910 return($this->DivListFai->Draw());
911 }
914 /* Return departments, that will be included within snapshot detection */
915 function get_used_snapshot_bases()
916 {
917 $tmp = array();
918 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
919 foreach($types as $type){
920 $tmp[] = get_ou($type).$this->fai_release;
921 }
922 return($tmp);
923 }
926 /* Get available branches for current base */
927 function getBranches($base = false,$prefix = "")
928 {
929 $ret = array("/"=>$this->fai_base);
930 $ldap = $this->config->get_ldap_link();
931 if(!$base){
932 $base = $this->fai_base;
933 }
934 $tmp = FAI::get_all_releases_from_base($base,true);
935 foreach($tmp as $dn => $name){
936 $ret[$name]=$dn;
937 }
938 ksort($ret);
939 $ret = array_flip($ret);
941 /* Ensure that we have a valid release selected */
942 if(!in_array($this->fai_release,$ret)){
943 $this->fai_release = $this->fai_base;
944 }
946 return ($ret);
947 }
950 function list_get_selected_items()
951 {
952 $ids = array();
953 foreach($_POST as $name => $value){
954 if(preg_match("/^item_selected_[0-9]*$/",$name)){
955 $id = preg_replace("/^item_selected_/","",$name);
956 $ids[$id] = $id;
957 }
958 }
959 return($ids);
960 }
963 /* reload list of objects */
964 function reload()
965 {
966 /* Variable initialisation */
967 $str = "";
968 $Regex = $this->DivListFai->Regex;
969 $this->objects = array();
971 /* Get base */
972 $base = $this->fai_base;
973 if($this->fai_release != $this->fai_base){
974 $br = $this->getBranches();
975 if(isset($br[$this->fai_release])){
976 $base = $this->fai_release;
977 }else{
978 $base = $this->fai_base;
979 }
980 }
981 $this->base = $base;
982 $this->set_acl_base($this->base);
984 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
986 /* Create a new list of FAI object
987 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
988 */
989 $ObjectTypes = array(
990 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
991 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
992 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
993 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
994 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
995 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
996 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
998 $filter = "";
999 foreach($ObjectTypes as $key => $data){
1000 if($this->DivListFai->$data['CHKBOX']){
1001 $filter.= "(objectClass=".$key.")";
1002 }
1003 }
1004 $filter = "(&(|".$filter.")(cn=$Regex))";
1006 /* Get resolved release dependencies */
1007 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1009 /* Ge listed ldap objects */
1010 $ldap = $this->config->get_ldap_link();
1011 $ldap->cd($this->config->current['BASE']);
1013 /* Get release tag
1014 If current release is freezed, all objects are freezed to.
1015 */
1016 $ldap->cat($base);
1017 $release_attrs = $ldap->fetch();
1018 $force_freezed = FALSE;
1019 if(isset($release_attrs['FAIstate'][0]) && preg_match("/freeze/i",$release_attrs['FAIstate'][0])){
1020 $force_freezed = TRUE;
1021 }
1023 foreach($tmp as $entry){
1025 /* Get some more informations about the object */
1026 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1027 $object = $ldap->fetch();
1029 /* Walk through possible types */
1030 foreach($ObjectTypes as $type => $rest){
1032 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1034 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1036 /* Prepare object */
1037 unset($object['objectClass']['count']);
1038 if(!isset($object['description'][0])){
1039 $object['description'][0]="";
1040 }
1042 /* Clean up object informations */
1043 $obj = array();
1044 $obj['cn'] = $object['cn'][0];
1045 $obj['dn'] = $object['dn'];
1046 $obj['acl'] = $acl;
1047 $obj['description'] = $object['description'][0];
1048 $obj['objectClass'] = $object['objectClass'];
1050 /* Append type to this string, to be able to check if the selected
1051 * entry is of type 'freeze' or 'branch'
1052 */
1053 if(!isset($object['FAIstate'])){
1054 $obj['FAIstate'] = $this->lock_type;
1055 }else{
1056 $obj['FAIstate'] = $object['FAIstate'][0];
1057 }
1059 if($force_freezed){
1060 $obj['FAIstate'] = "freeze";
1061 }
1063 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1064 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1065 }
1066 }
1067 }
1069 ksort($this->objects);
1070 reset ($this->objects);
1072 /* use numeric index, thats a bit more secure */
1073 $tmp0 = array();
1074 foreach($this->objects as $obj){
1075 $tmp0[]= $obj;
1076 }
1077 $this->objects = array();
1078 $this->objects = $tmp0;
1079 }
1081 function remove_lock()
1082 {
1083 if (isset($this->dn)){
1084 del_lock ($this->dn);
1085 }
1086 }
1088 function get_type($array){
1089 if(in_array("FAIpartitionTable",$array['objectClass'])){
1090 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1091 }
1092 if(in_array("FAIscript",$array['objectClass'])){
1093 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1094 }
1095 if(in_array("FAItemplate",$array['objectClass'])){
1096 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1097 }
1098 if(in_array("FAIhook",$array['objectClass'])){
1099 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1100 }
1101 if(in_array("FAIvariable",$array['objectClass'])){
1102 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1103 }
1104 if(in_array("FAIprofile",$array['objectClass'])){
1105 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1106 }
1108 if(in_array("FAIpackageList",$array['objectClass'])){
1109 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1110 }
1111 }
1113 function CheckNewBranchName($name,$base)
1114 {
1115 $f = $this->fai_release;
1116 if($name == ""){
1117 return(false);
1118 }elseif(in_array($name,$this->getBranches($f))) {
1119 return(false);
1120 }elseif(tests::is_department_name_reserved($name,$base)){
1121 return(false);
1122 }
1123 return(true);
1124 }
1126 function save_object()
1127 {
1128 $this->DivListFai->save_object();
1130 /* Get posted release */
1131 $r_releases = array_flip($this->getBranches());
1132 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1133 $this->fai_release = $r_releases[get_post('fai_release')];
1135 $fai_filter = session::get("fai_filter");
1136 $fai_filter['fai_release'] = $this->fai_release;
1137 session::set("fai_filter",$fai_filter);
1138 }
1140 if(is_object($this->CopyPasteHandler)){
1141 $this->CopyPasteHandler->save_object();
1142 }
1143 }
1146 function copyPasteHandling_from_queue($s_action,$s_entry)
1147 {
1148 /* Check if Copy & Paste is disabled */
1149 if(!is_object($this->CopyPasteHandler)){
1150 return("");
1151 }
1154 /* Add a single entry to queue */
1155 if($s_action == "cut" || $s_action == "copy"){
1157 /* Cleanup object queue */
1158 $this->CopyPasteHandler->cleanup_queue();
1159 $entry = $this->objects[$s_entry];
1160 $a_setup = $this->get_type($entry);
1161 $dn = $entry['dn'];
1162 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1163 }
1165 /* Add entries to queue */
1166 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1168 /* Cleanup object queue */
1169 $this->CopyPasteHandler->cleanup_queue();
1171 /* Add new entries to CP queue */
1172 foreach($this->list_get_selected_items() as $id){
1174 /* Cleanup object queue */
1175 $entry = $this->objects[$id];
1176 $a_setup = $this->get_type($entry);
1177 $dn = $entry['dn'];
1180 if($s_action == "copy_multiple"){
1181 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1182 }
1183 if($s_action == "cut_multiple"){
1184 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1185 }
1186 }
1187 }
1189 /* Start pasting entries */
1190 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1191 $this->start_pasting_copied_objects = TRUE;
1192 }
1194 /* Return C&P dialog */
1195 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1197 /* Get dialog */
1198 $data = $this->CopyPasteHandler->execute();
1200 FAI::save_release_changes_now();
1202 /* Return dialog data */
1203 if(!empty($data)){
1204 return($data);
1205 }
1206 }
1208 /* Automatically disable status for pasting */
1209 if(!$this->CopyPasteHandler->entries_queued()){
1210 $this->start_pasting_copied_objects = FALSE;
1211 }
1212 return("");
1213 }
1216 /* Check if the given FAI class is used in this release
1217 */
1218 static function check_class_name($oc,$name,$dn)
1219 {
1220 $base = FAI::get_release_dn($dn);
1221 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1222 $delete = array();
1223 $used = array();
1224 foreach($res as $object){
1225 $used[$object['cn'][0]]= $object['cn'][0];
1226 }
1227 return($used);
1228 }
1231 /* Return plugin informations for acl handling */
1232 static function plInfo()
1233 {
1234 return (array(
1235 "plShortName" => _("FAI releases"),
1236 "plDescription" => _("FAI release management"),
1237 "plSelfModify" => FALSE,
1238 "plDepends" => array(),
1239 "plPriority" => 0,
1240 "plSection" => array("administration"),
1241 "plCategory" => array("fai"=> array("description" => _("FAI"),
1242 "objectClass" => "FAIclass")),
1243 "plProvidedAcls"=> array()));
1244 }
1245 }
1246 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1247 ?>