e855f87757f4c8298f6a5f8784494a9da71103a6
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;
47 var $base = "";
49 var $no_save;
51 /* construction/reconstruction
52 */
53 function faiManagement (&$config, $ui)
54 {
55 /* Set defaults */
56 $this->dn = "";
57 $this->config = $config;
58 $this->ui = $ui;
60 /* Creat dialog object */
61 $this->DivListFai = new divListFai($this->config,$this);
63 /* Copy & Paste handler */
64 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
65 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
66 }
67 }
69 function execute()
70 {
71 /* Call parent execute */
72 plugin::execute();
74 /* Initialise vars and smarty */
75 $smarty = get_smarty();
76 $smarty->assign("BranchName","");
78 $display = "";
79 $s_action = "";
80 $s_entry = "";
81 $no_save = FALSE; // hide Apply / Save buttons
83 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
84 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/"));
87 /****************
88 Handle posts
89 ****************/
91 /* Check ImageButton posts
92 * Create new tab ich new_xx is posted
93 */
94 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
95 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
96 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
97 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
98 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
99 "/edit_continue/"=>"select_class_name_finished",
100 "/^multiple_copy_fai/" => "copy_multiple",
101 "/^multiple_cut_fai/" => "cut_multiple",
102 "/^copy/" => "copy",
103 "/^cut/" => "cut",
104 "/^remove_multiple_fai_objects/" => "del_multiple");
106 foreach($_POST as $name => $value){
107 foreach($posts as $reg => $act ){
108 if(preg_match($reg,$name)){
109 $s_action = $act;
110 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
111 $s_entry = preg_replace("/_.*$/","",$s_entry);
112 }
113 }
114 if(preg_match("/^entry_edit_.*/",$name)){
115 $s_entry = preg_replace("/^entry_edit_/","",$name);
116 $s_entry = preg_replace("/_.*$/","",$s_entry);
117 $s_action = "edit";
118 }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
119 $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
120 $s_entry = preg_replace("/_.*$/","",$s_entry);
121 $s_action = "edit";
122 $no_save = TRUE;
123 }elseif(preg_match("/^entry_delete_.*/",$name)){
124 $s_entry = preg_replace("/^entry_delete_/","",$name);
125 $s_entry = preg_replace("/_.*$/","",$s_entry);
126 $s_action = "delete";
127 }
128 }
130 if(isset($_GET['edit_entry'])){
131 $s_entry = $_GET['edit_entry'];
132 $s_action = "edit";
133 }
135 if(isset($_GET['edit_freeze_entry'])){
136 $s_entry = $_GET['edit_freeze_entry'];
137 $s_action = "edit";
138 $no_save = TRUE;
139 }
141 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
142 $s_action = "freeze_branch";
143 }
144 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
145 $s_action = "branch_branch";
146 }
147 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
148 $s_action = "remove_branch";
149 }
151 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
152 $this->dispNewBranch = false;
153 $this->dispNewFreeze = false;
154 }
157 $type_acl_mapping = array(
158 "FAIpartitionTable" => "faiPartitionTable",
159 "FAIpackageList" => "faiPackage",
160 "FAIscript" => "faiScript",
161 "FAIvariable" => "faiVariable",
162 "FAIhook" => "faiHook",
163 "FAIprofile" => "faiProfile",
164 "FAItemplate" => "faiTemplate");
167 /* handle C&P from layers menu */
168 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
169 $s_action = "copy_multiple";
170 }
171 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
172 $s_action = "cut_multiple";
173 }
174 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
175 $s_action = "editPaste";
176 }
178 /* Create options */
179 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
180 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
181 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
182 }
184 /* handle remove from layers menu */
185 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
186 $s_action = "del_multiple";
187 }
190 if(!empty($s_action)){
191 $this->no_save = $no_save;
192 }
194 /********************
195 Copy & Paste
196 ********************/
198 /* Display the copy & paste dialog, if it is currently open */
199 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
200 if($ret){
201 return($ret);
202 }
205 /****************
206 Delete confirme dialog
207 ****************/
209 if ($s_action=="delete"){
211 /* Get 'dn' from posted termlinst */
212 $this->dn= $this->objects[$s_entry]['dn'];
214 /* Load permissions for selected 'dn' and check if
215 we're allowed to remove this 'dn' */
216 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
217 if(preg_match("/d/",$acl)){
219 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
220 if (($user= get_lock($this->dn)) != ""){
221 return(gen_locked_message ($user, $this->dn));
222 }
224 /* Lock the current entry, so nobody will edit it during deletion */
225 add_lock ($this->dn, $this->ui->dn);
226 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
227 $smarty->assign("multiple", false);
228 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
229 } else {
231 /* Obviously the user isn't allowed to delete. Show message and clean session. */
232 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
233 }
234 }
237 /********************
238 Delete MULTIPLE entries requested, display confirm dialog
239 ********************/
241 if ($s_action=="del_multiple"){
242 $this->dns = array();
243 $ids = $this->list_get_selected_items();
245 if(count($ids)){
247 $errors = "";
248 foreach($ids as $id){
249 $dn = $this->objects[$id]['dn'];
250 $cn = $this->objects[$id]['cn'];
251 if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
252 $this->dns[$id] = $dn;
253 }else{
254 $errors .= $cn.", ";
255 }
256 }
257 if ($user= get_multiple_locks($this->dns)){
258 return(gen_locked_message($user,$this->dns));
259 }
261 if($errors != ""){
262 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
263 "<br><br>".trim($errors,", ")),INFO_DIALOG);
264 }
266 if(count($this->dns)){
268 $dns_names = array();
269 foreach($this->dns as $dn){
270 add_lock ($dn, $this->ui->dn);
271 $dns_names[] = @LDAP::fix($dn);
272 }
274 /* Lock the current entry, so nobody will edit it during deletion */
275 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
276 $smarty->assign("multiple", true);
277 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
278 }
279 }
280 }
283 /********************
284 Delete MULTIPLE entries confirmed
285 ********************/
287 /* Confirmation for deletion has been passed. Users should be deleted. */
288 if (isset($_POST['delete_multiple_fai_object_confirm'])){
290 /* Find out more about the object type */
291 $ldap = $this->config->get_ldap_link();
293 /* Remove user by user and check acls before removeing them */
294 foreach($this->dns as $key => $dn){
296 $ldap->cat($dn, array('objectClass'));
297 $attrs = $ldap->fetch();
298 $type = $this->get_type($attrs);
300 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
301 if(preg_match("/d/",$acl)){
303 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
304 $this->dialog->set_acl_base($dn);
305 $this->dialog->by_object[$type[1]]->remove_from_parent ();
306 unset ($this->dialog);
307 $this->dialog= FALSE;
308 $to_del = FAI::clean_up_releases($dn);
309 FAI::save_release_changes_now();
311 foreach($to_del as $dn){
312 $ldap->rmdir_recursive($dn);
313 }
315 } else {
317 /* Normally this shouldn't be reached, send some extra
318 logs to notify the administrator */
319 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
320 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
321 }
323 /* Remove lock file after successfull deletion */
324 del_lock ($dn);
325 unset($this->dns[$key]);
326 }
327 }
330 /********************
331 Delete MULTIPLE entries Canceled
332 ********************/
334 /* Remove lock */
335 if(isset($_POST['delete_multiple_fai_object_cancel'])){
336 foreach($this->dns as $key => $dn){
337 del_lock ($dn);
338 unset($this->dns[$key]);
339 }
340 }
343 /****************
344 Delete aborted
345 ****************/
347 /* Delete canceled? */
348 if (isset($_POST['delete_cancel'])){
349 del_lock ($this->dn);
350 }
353 /****************
354 Delete confirmed
355 ****************/
357 /* Deltetion was confirmed, so delete this entry
358 */
359 if (isset($_POST['delete_terminal_confirm'])){
361 /* Some nice guy may send this as POST, so we've to check
362 for the permissions again. */
364 /* Find out more about the object type */
365 $ldap = $this->config->get_ldap_link();
366 $ldap->cat($this->dn, array('objectClass'));
367 if($ldap->count()){
368 $attrs = $ldap->fetch();
369 $type = $this->get_type($attrs);
371 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
372 if(preg_match("/d/",$acl)){
374 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
375 $this->dialog->set_acl_base($this->dn);
376 $this->dialog->by_object[$type[1]]->remove_from_parent ();
377 unset ($this->dialog);
378 $this->dialog= FALSE;
379 $to_del = FAI::clean_up_releases($this->dn);
380 FAI::save_release_changes_now();
382 foreach($to_del as $dn){
383 $ldap->rmdir_recursive($dn);
384 }
386 } else {
388 /* Normally this shouldn't be reached, send some extra
389 logs to notify the administrator */
390 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
391 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
392 }
394 }else{
395 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
396 }
397 /* Remove lock file after successfull deletion */
398 del_lock ($this->dn);
399 }
402 /****************
403 Edit entry
404 ****************/
406 if(($s_action == "edit") && (!isset($this->dialog->config))){
407 $entry = $this->objects[$s_entry];
408 $a_setup = $this->get_type($entry);
409 $this->dn = $entry['dn'];
411 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
412 if (($user= get_lock($this->dn)) != ""){
413 return(gen_locked_message ($user, $this->dn));
414 }
415 add_lock ($this->dn, $this->ui->dn);
417 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
419 $this->dialog->set_acl_base($this->dn);
420 $this->is_dialog = true;
422 if(preg_match("/^freeze/", $entry['FAIstate']) || $this->no_save){
423 # $this->dialog->set_acl_base("freezed") ;
424 }
425 session::set('objectinfo',$this->dn);
426 }
429 /* Branch handling
430 09.01.2006
431 */
433 /****************
434 Remove branch
435 ****************/
437 /* Remove branch
438 */
439 if($s_action == "remove_branch"){
440 $base= $this->DivListFai->selectedBranch;
442 /* Check if we have a post remove method configured
443 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
444 */
445 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
446 /* Load permissions for selected 'dn' and check if
447 we're allowed to remove this 'dn' */
448 if($this->acl_is_removeable()){
450 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->DivListFai->selectedBranch),_("FAI branch/freeze")));
451 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
452 } else {
453 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
454 }
455 }
456 }
459 /****************
460 Remove branch confirmed
461 ****************/
463 if(isset($_POST['delete_branch_confirm'])){
465 /* Check if we have a post remove method configured
466 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
467 */
468 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
470 $bb = $this->DivListFai->selectedBranch;
471 if(!isset($ldap)){
472 $ldap = $this->config->get_ldap_link();
473 }
475 $br = $this->getBranches();
477 if(isset($br[$bb]) && $this->acl_is_removeable()){
478 $name = $br[$bb];
479 $ldap->cd($bb);
480 $ldap->recursive_remove();
481 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
482 $ldap->recursive_remove();
483 $this->DivListFai->selectedBranch = "main";
485 /* Post remove */
486 $this->lock_name = $name;
487 $this->lock_dn = $bb;
488 $this->postremove();
490 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
491 }
492 }
493 }
496 /****************
497 Create a new branch "insert Name"
498 ****************/
500 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
501 session::set('LASTPOST',$_POST);
503 if($this->dispNewBranch){
504 $type = "branch";
505 }else{
506 $type = "freeze";
507 }
509 /* Check branch name */
510 $name = $_POST['BranchName'];
511 $is_ok = true;
512 $smarty->assign("BranchName",$name);
513 $base= get_ou('faiou').$this->DivListFai->selectedBase;
515 /* Check used characters */
516 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
517 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z \ö\ä\ü\.-_:,]/i"), ERROR_DIALOG);
518 $is_ok = false;
519 }
521 /* Check if this name is already in use */
522 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
523 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
524 $is_ok = false;
525 }
527 if($is_ok){
529 if(session::is_set('LASTPOST')){
530 $LASTPOST = session::get('LASTPOST');
531 }else{
532 $LASTPOST = array();
533 }
534 $LASTPOST['base'] = $base;
535 $LASTPOST['type'] = $type;
536 session::set('LASTPOST',$LASTPOST);
537 $smarty->assign("iframe", true);
538 $smarty->assign("plugID", $_GET['plug']);
539 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
540 return($display);
541 }
542 }
545 /****************
546 Create a new branch
547 ****************/
549 if(isset($_GET['PerformBranch'])){
551 if(!$this->acl_is_createable()){
552 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
553 }else{
555 /* Create it know */
556 $this->dispNewBranch = false;
557 $this->dispNewFreeze = false;
559 $LASTPOST = session::get('LASTPOST');
560 $base = $LASTPOST['base'];
561 $_POST = session::get('LASTPOST');
562 $name = $_POST['BranchName'];
564 $type = $LASTPOST['type'];
565 $ldap = $this->config->get_ldap_link();
567 $baseToUse = $base;
568 if($this->DivListFai->selectedBranch != "main" ){
569 $baseToUse = $this->DivListFai->selectedBranch;
570 }
572 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
574 $CurrentReleases = $this->getBranches();
575 $NewReleaseName = $name;
576 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
577 if($this->DivListFai->selectedBranch != "main"){
578 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
579 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
580 }else{
581 $NewReleaseName = $name;
582 }
583 }
585 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
586 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
588 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
589 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
591 /* Check if source depeartments exist */
592 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
593 $ldap->cd($this->config->current['BASE']);
594 $ldap->cat($dep);
595 if(!$ldap->count()){
596 $ldap->create_missing_trees($dep);
597 }
598 }
600 /* Print header to have styles included */
601 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
602 <html>
603 <head>
604 <title></title>
605 <style type="text/css">@import url("themes/default/style.css");</style>
606 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
607 </head>
608 <body style="background: none;margin:3px;color:black">
609 ';
611 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
613 /* Duplicate group application releases
614 */
615 FAI::copy_FAI_group_releases($CurrentReleases[$this->DivListFai->selectedBranch],$name,$type);
617 /* Duplicate applications
618 */
619 $ldap->cat($appsrc,array("dn")) ;
620 if($ldap->count()){
621 $ldap->cd ($appdst);
622 $ldap->recursive_remove();
623 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
624 }
626 /* Duplicate mime types
627 */
628 $ldap->cat($mimesrc,array("dn")) ;
629 if($ldap->count()){
630 $ldap->cd ($mimedst);
631 $ldap->recursive_remove();
632 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
633 }
635 $attr = array();
636 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
637 $attr['ou'] = $name;
638 $attr['FAIstate'] = $type;
639 $ldap->cd($this->config->current['BASE']);
640 $ldap->cd("ou=".$name.",".$baseToUse);
641 $ldap->cat("ou=".$name.",".$baseToUse);
642 if($ldap->count()){
643 $ldap->modify($attr);
644 }else{
645 $ldap->add($attr);
646 }
648 /* Duplicate fai objects
649 */
650 // $ldap->cd ("ou=".$name.",".$baseToUse);
651 // $ldap->recursive_remove();
652 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
654 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
655 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
656 </form></div>";
658 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
660 /* Print footer to have valid html */
661 echo "</body></html>";
663 $this->dispNewFreeze = false;
665 /* Postcreate */
667 /* Assign possible attributes */
668 $this->lock_type = $type;
669 $this->lock_name = $name;
670 $this->lock_dn = $baseToUse;
671 $this->postcreate();
672 exit();
673 }
674 }
676 /****************
677 Display dialog to enter new Branch name
678 ****************/
680 /* Check if we have a post create method configured
681 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
682 */
683 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
684 if(($s_action == "branch_branch")||($this->dispNewBranch)){
685 if(!$this->acl_is_createable()){
686 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
687 }else{
688 $this->dispNewBranch=true;
689 $smarty->assign("iframe",false);
690 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
691 return($display);
692 }
693 }
694 }
697 /****************
698 Display dialog to enter new Freeze name
699 ****************/
701 /* Check if we have a post create method configured
702 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
703 */
704 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
705 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
706 if(!$this->acl_is_createable()){
707 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
708 }else{
709 $this->dispNewFreeze = true;
710 $smarty->assign("iframe",false);
711 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
712 return($display);
713 }
714 }
715 }
718 /****************
719 Create a new object
720 ****************/
722 $types = array( "new_partition" => "FAIpartitionTable",
723 "new_script" => "FAIscript",
724 "new_hook" => "FAIhook",
725 "new_variable" => "FAIvariable",
726 "new_template" => "FAItemplate",
727 "new_package" => "FAIpackageList");
728 $types_i18n = array( "new_partition" => _("partition table"),
729 "new_script" => _("script"),
730 "new_hook" => _("hook"),
731 "new_variable" => _("variable"),
732 "new_template" => _("template"),
733 "new_package" => _("package list"));
735 if(isset($types[$s_action])){
736 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
737 if(preg_match("/c/",$acl)){
738 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
739 }else{
740 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
741 }
742 }
744 /* New Profile */
745 if($s_action == "new_profile"){
746 $this->dn = "new" ;
748 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
749 if(preg_match("/c/",$acl)){
750 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
751 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
752 $this->dialog->set_acl_base($this->base);
754 $this->is_dialog = false;
755 }else{
756 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
757 }
758 }
761 /****************
762 Get from ask class name dialog
763 ****************/
765 if($s_action == "select_class_name_finished"){
766 $this->dialog->save_object();
767 if(count($this->dialog->check())!=0){
768 foreach($this->dialog->check() as $msg){
769 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
770 }
771 }elseif(isset($this->dialog->objectClass)){
772 $this->dn = "new" ;
773 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
774 $name = $this->dialog->save();
776 if(class_exists($a_setup[0])){
777 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
778 $this->dialog->set_acl_base($this->base);
779 $this->dialog->by_object[$a_setup[1]]->cn = $name;
780 $this->is_dialog = true;
781 }
782 }
783 }
786 /****************
787 Cancel dialogs
788 ****************/
790 if(isset($_POST['edit_cancel'])){
791 unset($this->dialog);
792 $this->dialog=FALSE;
793 $this->is_dialog = false;
794 session::un_set('objectinfo');
795 del_lock ($this->dn);
796 }
799 /****************
800 Save sub dialogs
801 ****************/
803 /* This check if the given tab could be saved
804 * If it was possible to save it, remove dialog object.
805 * If it wasn't possible, show errors and keep dialog.
806 */
807 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
808 $this->dialog->save_object();
809 $msgs= $this->dialog->check();
810 if(count($msgs)!=0){
811 foreach($msgs as $msg){
812 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
813 }
814 }else{
815 $this->dialog->save();
816 FAI::save_release_changes_now();
817 if (!isset($_POST['edit_apply'])){
818 del_lock ($this->dn);
819 unset($this->dialog);
820 $this->dialog=FALSE;
821 $this->is_dialog=false;
822 session::un_set('objectinfo');
823 }
824 }
825 }
828 /****************
829 Display currently open dialog
830 ****************/
832 /* If dialog is set, but $this->is_dialog==false, then
833 * only the "abort" button is shown, this are dialogs that must not be saved.
834 * If is_dialog == true, we are currently editing tab objects.
835 * Here we need both, save and cancel
836 */
838 if(is_object($this->dialog)){
839 $display .= $this->dialog->execute();
840 /* Don't show buttons if tab dialog requests this */
842 if(isset($this->dialog->current)){
844 $obj = $this->dialog->by_object[$this->dialog->current];
846 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
848 $display.= "<p style=\"text-align:right\">\n";
849 if(!$this->no_save){
850 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
851 $display.= " \n";
852 if ($this->dn != "new"){
853 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
854 $display.= " \n";
855 }
856 }
857 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
858 $display.= "</p>";
859 }elseif(!isset($this->dialog->current)){
860 $display.= "<p style=\"text-align:right\">\n";
861 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
862 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
863 $display.= "</p>";
864 }
865 }else{
866 $display.= "<p style=\"text-align:right\">\n";
867 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
868 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
869 $display.= "</p>";
871 }
872 return($display);
873 }
876 /****************
877 Dialog display
878 ****************/
880 /* Check if there is a snapshot dialog open */
881 $base = $this->DivListFai->selectedBase;
882 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
883 return($str);
884 }
886 /* Display dialog with system list */
887 $this->DivListFai->parent = $this;
888 $this->DivListFai->execute();
889 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
890 $this->reload();
891 $this->DivListFai->setEntries($this->objects);
892 return($this->DivListFai->Draw());
893 }
896 /* Return departments, that will be included within snapshot detection */
897 function get_used_snapshot_bases()
898 {
899 $tmp = array();
900 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
901 foreach($types as $type){
902 if($this->DivListFai->selectedBranch == "main"){
903 $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase;
904 }else{
905 $tmp[] = get_ou($type).$this->DivListFai->selectedBranch;
906 }
907 }
908 return($tmp);
909 }
912 /* Get available branches for current base */
913 function getBranches($base = false,$prefix = "")
914 {
915 $ret = array("/"=>"main");
916 $ldap = $this->config->get_ldap_link();
917 if(!$base){
918 $base = session::get('CurrentMainBase');
919 }
920 $tmp = FAI::get_all_releases_from_base($base,true);
921 foreach($tmp as $dn => $name){
922 $ret[$name]=$dn;
923 }
924 ksort($ret);
925 $ret = array_flip($ret);
927 return ($ret);
928 }
931 function list_get_selected_items()
932 {
933 $ids = array();
934 foreach($_POST as $name => $value){
935 if(preg_match("/^item_selected_[0-9]*$/",$name)){
936 $id = preg_replace("/^item_selected_/","",$name);
937 $ids[$id] = $id;
938 }
939 }
940 return($ids);
941 }
944 /* reload list of objects */
945 function reload()
946 {
947 /* Variable initialisation */
948 $str = "";
949 $Regex = $this->DivListFai->Regex;
950 $this->objects = array();
952 /* Get base */
953 $base = get_ou('faiou').$this->DivListFai->selectedBase;
954 if($this->DivListFai->selectedBranch != "main"){
955 $br = $this->getBranches();
956 if(isset($br[$this->DivListFai->selectedBranch])){
957 $base = $this->DivListFai->selectedBranch;
958 }else{
959 $base = get_ou('faiou').$this->DivListFai->selectedBase;
960 }
961 }
962 $this->base = $base;
963 $this->set_acl_base($this->base);
965 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
967 /* Create a new list of FAI object
968 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
969 */
970 $ObjectTypes = array(
971 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
972 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
973 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
974 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
975 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
976 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
977 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
979 $filter = "";
980 foreach($ObjectTypes as $key => $data){
981 if($this->DivListFai->$data['CHKBOX']){
982 $filter.= "(objectClass=".$key.")";
983 }
984 }
985 $filter = "(&(|".$filter.")(cn=$Regex))";
987 /* Get resolved release dependencies */
988 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
990 /* Ge listed ldap objects */
991 $ldap = $this->config->get_ldap_link();
992 $ldap->cd($this->config->current['BASE']);
994 /* Get release tag
995 If current release is freezed, all objects are freezed to.
996 */
997 $ldap->cat($base);
998 $release_attrs = $ldap->fetch();
999 $force_freezed = FALSE;
1000 if(isset($release_attrs['FAIstate'][0]) && preg_match("/freeze/i",$release_attrs['FAIstate'][0])){
1001 $force_freezed = TRUE;
1002 }
1004 foreach($tmp as $entry){
1006 /* Get some more informations about the object */
1007 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1008 $object = $ldap->fetch();
1010 /* Walk through possible types */
1011 foreach($ObjectTypes as $type => $rest){
1013 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1015 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1017 /* Prepare object */
1018 unset($object['objectClass']['count']);
1019 if(!isset($object['description'][0])){
1020 $object['description'][0]="";
1021 }
1023 /* Clean up object informations */
1024 $obj = array();
1025 $obj['cn'] = $object['cn'][0];
1026 $obj['dn'] = $object['dn'];
1027 $obj['acl'] = $acl;
1028 $obj['description'] = $object['description'][0];
1029 $obj['objectClass'] = $object['objectClass'];
1031 /* Append type to this string, to be able to check if the selected
1032 * entry is of type 'freeze' or 'branch'
1033 */
1034 if(!isset($object['FAIstate'])){
1035 $obj['FAIstate'] = $this->lock_type;
1036 }else{
1037 $obj['FAIstate'] = $object['FAIstate'][0];
1038 }
1040 if($force_freezed){
1041 $obj['FAIstate'] = "freeze";
1042 }
1044 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1045 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1046 }
1047 }
1048 }
1050 ksort($this->objects);
1051 reset ($this->objects);
1053 /* use numeric index, thats a bit more secure */
1054 $tmp0 = array();
1055 foreach($this->objects as $obj){
1056 $tmp0[]= $obj;
1057 }
1058 $this->objects = array();
1059 $this->objects = $tmp0;
1060 }
1062 function remove_lock()
1063 {
1064 if (isset($this->dn)){
1065 del_lock ($this->dn);
1066 }
1067 }
1069 function get_type($array){
1070 if(in_array("FAIpartitionTable",$array['objectClass'])){
1071 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1072 }
1073 if(in_array("FAIscript",$array['objectClass'])){
1074 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1075 }
1076 if(in_array("FAItemplate",$array['objectClass'])){
1077 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1078 }
1079 if(in_array("FAIhook",$array['objectClass'])){
1080 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1081 }
1082 if(in_array("FAIvariable",$array['objectClass'])){
1083 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1084 }
1085 if(in_array("FAIprofile",$array['objectClass'])){
1086 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1087 }
1089 if(in_array("FAIpackageList",$array['objectClass'])){
1090 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1091 }
1092 }
1094 function CheckNewBranchName($name,$base)
1095 {
1096 $f = $this->DivListFai->selectedBranch;
1097 if($name == ""){
1098 return(false);
1099 }elseif(in_array($name,$this->getBranches($f))) {
1100 return(false);
1101 }elseif(tests::is_department_name_reserved($name,$base)){
1102 return(false);
1103 }
1104 return(true);
1105 }
1107 function save_object()
1108 {
1109 $this->DivListFai->save_object();
1111 if(is_object($this->CopyPasteHandler)){
1112 $this->CopyPasteHandler->save_object();
1113 }
1114 }
1117 function copyPasteHandling_from_queue($s_action,$s_entry)
1118 {
1119 /* Check if Copy & Paste is disabled */
1120 if(!is_object($this->CopyPasteHandler)){
1121 return("");
1122 }
1124 $base = $this->DivListFai->selectedBranch;
1125 if($base == "main"){
1126 $base = $this->DivListFai->selectedBase;
1127 }
1129 /* Add a single entry to queue */
1130 if($s_action == "cut" || $s_action == "copy"){
1132 /* Cleanup object queue */
1133 $this->CopyPasteHandler->cleanup_queue();
1134 $entry = $this->objects[$s_entry];
1135 $a_setup = $this->get_type($entry);
1136 $dn = $entry['dn'];
1137 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1138 }
1140 /* Add entries to queue */
1141 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1143 /* Cleanup object queue */
1144 $this->CopyPasteHandler->cleanup_queue();
1146 /* Add new entries to CP queue */
1147 foreach($this->list_get_selected_items() as $id){
1149 /* Cleanup object queue */
1150 $entry = $this->objects[$id];
1151 $a_setup = $this->get_type($entry);
1152 $dn = $entry['dn'];
1155 if($s_action == "copy_multiple"){
1156 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1157 }
1158 if($s_action == "cut_multiple"){
1159 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1160 }
1161 }
1162 }
1164 /* Start pasting entries */
1165 if($s_action == "editPaste"){
1166 $this->start_pasting_copied_objects = TRUE;
1167 }
1169 /* Return C&P dialog */
1170 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1172 /* Get dialog */
1173 $data = $this->CopyPasteHandler->execute();
1174 $this->CopyPasteHandler->SetVar("base",$base);
1176 FAI::save_release_changes_now();
1178 /* Return dialog data */
1179 if(!empty($data)){
1180 return($data);
1181 }
1182 }
1184 /* Automatically disable status for pasting */
1185 if(!$this->CopyPasteHandler->entries_queued()){
1186 $this->start_pasting_copied_objects = FALSE;
1187 }
1188 return("");
1189 }
1192 /* Check if the given FAI class is used in this release
1193 */
1194 static function check_class_name($oc,$name,$dn)
1195 {
1196 $base = FAI::get_release_dn($dn);
1197 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1198 $delete = array();
1199 $used = array();
1200 foreach($res as $object){
1201 $used[$object['cn'][0]]= $object['cn'][0];
1202 }
1203 return($used);
1204 }
1207 /* Return plugin informations for acl handling */
1208 static function plInfo()
1209 {
1210 return (array(
1211 "plShortName" => _("FAI releases"),
1212 "plDescription" => _("FAI release management"),
1213 "plSelfModify" => FALSE,
1214 "plDepends" => array(),
1215 "plPriority" => 0,
1216 "plSection" => array("administration"),
1217 "plCategory" => array("fai"=> array("description" => _("FAI"),
1218 "objectClass" => "FAIclass")),
1219 "plProvidedAcls"=> array()));
1220 }
1221 }
1222 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1223 ?>