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 = "FAI";
26 var $plDescription = "Fully Automatic Installation - management";
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 /* construction/reconstruction
50 */
51 function faiManagement (&$config, $ui)
52 {
53 /* Set defaults */
54 $this->dn = "";
55 $this->config = $config;
56 $this->ui = $ui;
58 /* Creat dialog object */
59 $this->DivListFai = new divListFai($this->config,$this);
61 /* Copy & Paste handler */
62 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
63 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
64 }
65 }
67 function execute()
68 {
69 /* Call parent execute */
70 plugin::execute();
72 /* Initialise vars and smarty */
73 $smarty = get_smarty();
74 $smarty->assign("BranchName","");
76 $display = "";
77 $s_action = "";
78 $s_entry = "";
80 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
81 session::set('LOCK_VARS_TO_USE',array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/"));
84 /****************
85 Handle posts
86 ****************/
88 /* Check ImageButton posts
89 * Create new tab ich new_xx is posted
90 */
91 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
92 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
93 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
94 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
95 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
96 "/edit_continue/"=>"select_class_name_finished",
97 "/^multiple_copy_fai/" => "copy_multiple",
98 "/^multiple_cut_fai/" => "cut_multiple",
99 "/^copy/" => "copy",
100 "/^cut/" => "cut",
101 "/^remove_multiple_fai_objects/" => "del_multiple");
103 foreach($_POST as $name => $value){
104 foreach($posts as $reg => $act ){
105 if(preg_match($reg,$name)){
106 $s_action = $act;
107 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
108 $s_entry = preg_replace("/_.*$/","",$s_entry);
109 }
110 }
111 if(preg_match("/^entry_edit_.*/",$name)){
112 $s_entry = preg_replace("/^entry_edit_/","",$name);
113 $s_entry = preg_replace("/_.*$/","",$s_entry);
114 $s_action = "edit";
115 }elseif(preg_match("/^entry_delete_.*/",$name)){
116 $s_entry = preg_replace("/^entry_delete_/","",$name);
117 $s_entry = preg_replace("/_.*$/","",$s_entry);
118 $s_action = "delete";
119 }
120 }
122 if(isset($_GET['edit_entry'])){
123 $s_entry = $_GET['edit_entry'];
124 $s_action = "edit";
125 }
127 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
128 $s_action = "freeze_branch";
129 }
130 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
131 $s_action = "branch_branch";
132 }
133 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
134 $s_action = "remove_branch";
135 }
137 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
138 $this->dispNewBranch = false;
139 $this->dispNewFreeze = false;
140 }
143 $type_acl_mapping = array(
144 "FAIpartitionTable" => "faiPartitionTable",
145 "FAIpackageList" => "faiPackage",
146 "FAIscript" => "faiScript",
147 "FAIvariable" => "faiVariable",
148 "FAIhook" => "faiHook",
149 "FAIprofile" => "faiProfile",
150 "FAItemplate" => "faiTemplate");
153 /* handle C&P from layers menu */
154 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
155 $s_action = "copy_multiple";
156 }
157 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
158 $s_action = "cut_multiple";
159 }
160 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
161 $s_action = "editPaste";
162 }
164 /* Create options */
165 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
166 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
167 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
168 }
170 /* handle remove from layers menu */
171 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
172 $s_action = "del_multiple";
173 }
175 /********************
176 Copy & Paste
177 ********************/
179 /* Display the copy & paste dialog, if it is currently open */
180 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
181 if($ret){
182 return($ret);
183 }
186 /****************
187 Delete confirme dialog
188 ****************/
190 if ($s_action=="delete"){
192 /* Get 'dn' from posted termlinst */
193 $this->dn= $this->objects[$s_entry]['dn'];
195 /* Load permissions for selected 'dn' and check if
196 we're allowed to remove this 'dn' */
197 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
198 if(preg_match("/d/",$acl)){
200 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
201 if (($user= get_lock($this->dn)) != ""){
202 return(gen_locked_message ($user, $this->dn));
203 }
205 /* Lock the current entry, so nobody will edit it during deletion */
206 add_lock ($this->dn, $this->ui->dn);
207 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
208 $smarty->assign("multiple", false);
209 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
210 } else {
212 /* Obviously the user isn't allowed to delete. Show message and clean session. */
213 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
214 }
215 }
218 /********************
219 Delete MULTIPLE entries requested, display confirm dialog
220 ********************/
222 if ($s_action=="del_multiple"){
223 $this->dns = array();
224 $ids = $this->list_get_selected_items();
226 if(count($ids)){
228 $errors = "";
229 foreach($ids as $id){
230 $dn = $this->objects[$id]['dn'];
231 $cn = $this->objects[$id]['cn'];
232 if($this->objects[$id]['FAIstate'] != "freeze"){
233 $this->dns[$id] = $dn;
234 }else{
235 $errors .= $cn.", ";
236 }
237 }
238 if ($user= get_multiple_locks($this->dns)){
239 return(gen_locked_message($user,$this->dns));
240 }
242 if($errors != ""){
243 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
244 "<br><br>".trim($errors,", ")),INFO_DIALOG);
245 }
247 if(count($this->dns)){
249 $dns_names = array();
250 foreach($this->dns as $dn){
251 add_lock ($dn, $this->ui->dn);
252 $dns_names[] = @LDAP::fix($dn);
253 }
255 /* Lock the current entry, so nobody will edit it during deletion */
256 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
257 $smarty->assign("multiple", true);
258 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
259 }
260 }
261 }
264 /********************
265 Delete MULTIPLE entries confirmed
266 ********************/
268 /* Confirmation for deletion has been passed. Users should be deleted. */
269 if (isset($_POST['delete_multiple_fai_object_confirm'])){
271 /* Find out more about the object type */
272 $ldap = $this->config->get_ldap_link();
274 /* Remove user by user and check acls before removeing them */
275 foreach($this->dns as $key => $dn){
277 $ldap->cat($dn, array('objectClass'));
278 $attrs = $ldap->fetch();
279 $type = $this->get_type($attrs);
281 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
282 if(preg_match("/d/",$acl)){
284 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
285 $this->dialog->set_acl_base($dn);
286 $this->dialog->by_object[$type[1]]->remove_from_parent ();
287 unset ($this->dialog);
288 $this->dialog= FALSE;
289 $to_del = FAI::clean_up_releases($dn);
290 FAI::save_release_changes_now();
292 foreach($to_del as $dn){
293 $ldap->rmdir_recursive($dn);
294 }
296 } else {
298 /* Normally this shouldn't be reached, send some extra
299 logs to notify the administrator */
300 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
301 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
302 }
304 /* Remove lock file after successfull deletion */
305 del_lock ($dn);
306 unset($this->dns[$key]);
307 }
308 }
311 /********************
312 Delete MULTIPLE entries Canceled
313 ********************/
315 /* Remove lock */
316 if(isset($_POST['delete_multiple_fai_object_cancel'])){
317 foreach($this->dns as $key => $dn){
318 del_lock ($dn);
319 unset($this->dns[$key]);
320 }
321 }
324 /****************
325 Delete aborted
326 ****************/
328 /* Delete canceled? */
329 if (isset($_POST['delete_cancel'])){
330 del_lock ($this->dn);
331 }
334 /****************
335 Delete confirmed
336 ****************/
338 /* Deltetion was confirmed, so delete this entry
339 */
340 if (isset($_POST['delete_terminal_confirm'])){
342 /* Some nice guy may send this as POST, so we've to check
343 for the permissions again. */
345 /* Find out more about the object type */
346 $ldap = $this->config->get_ldap_link();
347 $ldap->cat($this->dn, array('objectClass'));
348 if($ldap->count()){
349 $attrs = $ldap->fetch();
350 $type = $this->get_type($attrs);
352 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
353 if(preg_match("/d/",$acl)){
355 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
356 $this->dialog->set_acl_base($this->dn);
357 $this->dialog->by_object[$type[1]]->remove_from_parent ();
358 unset ($this->dialog);
359 $this->dialog= FALSE;
360 $to_del = FAI::clean_up_releases($this->dn);
361 FAI::save_release_changes_now();
363 foreach($to_del as $dn){
364 $ldap->rmdir_recursive($dn);
365 }
367 } else {
369 /* Normally this shouldn't be reached, send some extra
370 logs to notify the administrator */
371 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
372 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
373 }
375 }else{
376 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
377 }
378 /* Remove lock file after successfull deletion */
379 del_lock ($this->dn);
380 }
383 /****************
384 Edit entry
385 ****************/
387 if(($s_action == "edit") && (!isset($this->dialog->config))){
388 $entry = $this->objects[$s_entry];
389 $a_setup = $this->get_type($entry);
390 $this->dn = $entry['dn'];
392 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
393 if (($user= get_lock($this->dn)) != ""){
394 return(gen_locked_message ($user, $this->dn));
395 }
396 add_lock ($this->dn, $this->ui->dn);
398 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
399 $this->dialog->set_acl_base($this->dn);
400 $this->is_dialog = true;
402 if($entry['FAIstate'] == "freeze"){
403 #$this->dialog->set_acl(array("*none*")) ;
404 }
405 session::set('objectinfo',$this->dn);
406 }
409 /* Branch handling
410 09.01.2006
411 */
413 /****************
414 Remove branch
415 ****************/
417 /* Remove branch
418 */
419 if($s_action == "remove_branch"){
420 $base= $this->DivListFai->selectedBranch;
422 /* Check if we have a post remove method configured
423 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
424 */
425 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
426 /* Load permissions for selected 'dn' and check if
427 we're allowed to remove this 'dn' */
428 if($this->acl_is_removeable()){
430 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->DivListFai->selectedBranch),_("FAI branch/freeze")));
431 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
432 } else {
433 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
434 }
435 }
436 }
439 /****************
440 Remove branch confirmed
441 ****************/
443 if(isset($_POST['delete_branch_confirm'])){
445 /* Check if we have a post remove method configured
446 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
447 */
448 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
450 $bb = $this->DivListFai->selectedBranch;
451 if(!isset($ldap)){
452 $ldap = $this->config->get_ldap_link();
453 }
455 $br = $this->getBranches();
457 if(isset($br[$bb]) && $this->acl_is_removeable()){
458 $name = $br[$bb];
459 $ldap->cd($bb);
460 $ldap->recursive_remove();
461 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
462 $ldap->recursive_remove();
463 $this->DivListFai->selectedBranch = "main";
465 /* Post remove */
466 $this->lock_name = $name;
467 $this->lock_dn = $bb;
468 $this->postremove();
470 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
471 }
472 }
473 }
476 /****************
477 Create a new branch "insert Name"
478 ****************/
480 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
481 session::set('LASTPOST',$_POST);
483 if($this->dispNewBranch){
484 $type = "branch";
485 }else{
486 $type = "freeze";
487 }
489 /* Check branch name */
490 $name = $_POST['BranchName'];
491 $is_ok = true;
492 $smarty->assign("BranchName",$name);
493 $base= get_ou('faiou').$this->DivListFai->selectedBase;
495 /* Check used characters */
496 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
497 if($type == "branch"){
498 msg_dialog::display(_("Error"), _("Branch name is not valid!"), ERROR_DIALOG);
499 }else{
500 msg_dialog::display(_("Error"), _("Freeze name is not valid!"), ERROR_DIALOG);
501 }
502 $is_ok = false;
503 }
505 /* Check if this name is already in use */
506 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
507 msg_dialog::display(_("Error"), _("Name is already in use!"), ERROR_DIALOG);
508 $is_ok = false;
509 }
511 if($is_ok){
513 if(session::is_set('LASTPOST')){
514 $LASTPOST = session::get('LASTPOST');
515 }else{
516 $LASTPOST = array();
517 }
518 $LASTPOST['base'] = $base;
519 $LASTPOST['type'] = $type;
520 session::set('LASTPOST',$LASTPOST);
521 $smarty->assign("iframe", true);
522 $smarty->assign("plugID", $_GET['plug']);
523 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
524 return($display);
525 }
526 }
529 /****************
530 Create a new branch
531 ****************/
533 if(isset($_GET['PerformBranch'])){
535 if(!$this->acl_is_createable()){
536 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
537 }else{
539 /* Create it know */
540 $this->dispNewBranch = false;
541 $this->dispNewFreeze = false;
543 $LASTPOST = session::get('LASTPOST');
544 $base = $LASTPOST['base'];
545 $_POST = session::get('LASTPOST');
546 $name = $_POST['BranchName'];
548 $type = $LASTPOST['type'];
549 $ldap = $this->config->get_ldap_link();
551 $baseToUse = $base;
552 if($this->DivListFai->selectedBranch != "main" ){
553 $baseToUse = $this->DivListFai->selectedBranch;
554 }
556 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
558 $CurrentReleases = $this->getBranches();
559 $NewReleaseName = $name;
560 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
561 if($this->DivListFai->selectedBranch != "main"){
562 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
563 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
564 }else{
565 $NewReleaseName = $name;
566 }
567 }
569 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
570 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
572 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
573 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
575 /* Check if source depeartments exist */
576 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
577 $ldap->cd($this->config->current['BASE']);
578 $ldap->cat($dep);
579 if(!$ldap->count()){
580 $ldap->create_missing_trees($dep);
581 }
582 }
584 /* Print header to have styles included */
585 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
586 <html>
587 <head>
588 <title></title>
589 <style type="text/css">@import url("themes/default/style.css");</style>
590 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
591 </head>
592 <body style="background: none;margin:3px;color:black">
593 ';
595 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
597 /* Duplicate group application releases
598 */
599 FAI::copy_FAI_group_releases($CurrentReleases[$this->DivListFai->selectedBranch],$name,$type);
601 /* Duplicate applications
602 */
603 $ldap->cat($appsrc,array("dn")) ;
604 if($ldap->count()){
605 $ldap->cd ($appdst);
606 $ldap->recursive_remove();
607 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
608 }
610 /* Duplicate mime types
611 */
612 $ldap->cat($mimesrc,array("dn")) ;
613 if($ldap->count()){
614 $ldap->cd ($mimedst);
615 $ldap->recursive_remove();
616 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
617 }
619 $attr = array();
620 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
621 $attr['ou'] = $name;
622 $attr['FAIstate'] = $type;
623 $ldap->cd($this->config->current['BASE']);
624 $ldap->cd("ou=".$name.",".$baseToUse);
625 $ldap->cat("ou=".$name.",".$baseToUse);
626 if($ldap->count()){
627 $ldap->modify($attr);
628 }else{
629 $ldap->add($attr);
630 }
632 /* Duplicate fai objects
633 */
634 // $ldap->cd ("ou=".$name.",".$baseToUse);
635 // $ldap->recursive_remove();
636 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
638 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
639 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
640 </form></div>";
642 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
644 /* Print footer to have valid html */
645 echo "</body></html>";
647 $this->dispNewFreeze = false;
649 /* Postcreate */
651 /* Assign possible attributes */
652 $this->lock_type = $type;
653 $this->lock_name = $name;
654 $this->lock_dn = $baseToUse;
655 $this->postcreate();
656 exit();
657 }
658 }
660 /****************
661 Display dialog to enter new Branch name
662 ****************/
664 /* Check if we have a post create method configured
665 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
666 */
667 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
668 if(($s_action == "branch_branch")||($this->dispNewBranch)){
669 if(!$this->acl_is_createable()){
670 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
671 }else{
672 $this->dispNewBranch=true;
673 $smarty->assign("iframe",false);
674 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
675 return($display);
676 }
677 }
678 }
681 /****************
682 Display dialog to enter new Freeze name
683 ****************/
685 /* Check if we have a post create method configured
686 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
687 */
688 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
689 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
690 if(!$this->acl_is_createable()){
691 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
692 }else{
693 $this->dispNewFreeze = true;
694 $smarty->assign("iframe",false);
695 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
696 return($display);
697 }
698 }
699 }
702 /****************
703 Create a new object
704 ****************/
706 $types = array( "new_partition" => "FAIpartitionTable",
707 "new_script" => "FAIscript",
708 "new_hook" => "FAIhook",
709 "new_variable" => "FAIvariable",
710 "new_template" => "FAItemplate",
711 "new_package" => "FAIpackageList");
712 $types_i18n = array( "new_partition" => _("partition table"),
713 "new_script" => _("script"),
714 "new_hook" => _("hook"),
715 "new_variable" => _("variable"),
716 "new_template" => _("template"),
717 "new_package" => _("package list"));
719 if(isset($types[$s_action])){
720 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
721 if(preg_match("/c/",$acl)){
722 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
723 }else{
724 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
725 }
726 }
728 /* New Profile */
729 if($s_action == "new_profile"){
730 $this->dn = "new" ;
732 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
733 if(preg_match("/c/",$acl)){
734 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
735 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
736 $this->dialog->set_acl_base($this->base);
738 $this->is_dialog = false;
739 }else{
740 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
741 }
742 }
745 /****************
746 Get from ask class name dialog
747 ****************/
749 if($s_action == "select_class_name_finished"){
750 $this->dialog->save_object();
751 if(count($this->dialog->check())!=0){
752 foreach($this->dialog->check() as $msg){
753 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
754 }
755 }elseif(isset($this->dialog->objectClass)){
756 $this->dn = "new" ;
757 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
758 $name = $this->dialog->save();
760 if(class_exists($a_setup[0])){
761 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
762 $this->dialog->set_acl_base($this->base);
763 $this->dialog->by_object[$a_setup[1]]->cn = $name;
764 $this->is_dialog = true;
765 }
766 }
767 }
770 /****************
771 Cancel dialogs
772 ****************/
774 if(isset($_POST['edit_cancel'])){
775 unset($this->dialog);
776 $this->dialog=FALSE;
777 $this->is_dialog = false;
778 session::un_set('objectinfo');
779 del_lock ($this->dn);
780 }
783 /****************
784 Save sub dialogs
785 ****************/
787 /* This check if the given tab could be saved
788 * If it was possible to save it, remove dialog object.
789 * If it wasn't possible, show errors and keep dialog.
790 */
791 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
792 $this->dialog->save_object();
793 $msgs= $this->dialog->check();
794 if(count($msgs)!=0){
795 foreach($msgs as $msg){
796 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
797 }
798 }else{
799 $this->dialog->save();
800 FAI::save_release_changes_now();
801 if (!isset($_POST['edit_apply'])){
802 del_lock ($this->dn);
803 unset($this->dialog);
804 $this->dialog=FALSE;
805 $this->is_dialog=false;
806 session::un_set('objectinfo');
807 }
808 }
809 }
812 /****************
813 Display currently open dialog
814 ****************/
816 /* If dialog is set, but $this->is_dialog==false, then
817 * only the "abort" button is shown, this are dialogs that must not be saved.
818 * If is_dialog == true, we are currently editing tab objects.
819 * Here we need both, save and cancel
820 */
822 if(is_object($this->dialog)){
823 $display .= $this->dialog->execute();
824 /* Don't show buttons if tab dialog requests this */
826 if(isset($this->dialog->current)){
828 $obj = $this->dialog->by_object[$this->dialog->current];
830 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
832 $display.= "<p style=\"text-align:right\">\n";
833 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
834 $display.= " \n";
835 if ($this->dn != "new"){
836 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
837 $display.= " \n";
838 }
839 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
840 $display.= "</p>";
841 }elseif(!isset($this->dialog->current)){
842 $display.= "<p style=\"text-align:right\">\n";
843 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
844 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
845 $display.= "</p>";
846 }
847 }else{
848 $display.= "<p style=\"text-align:right\">\n";
849 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
850 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
851 $display.= "</p>";
853 }
854 return($display);
855 }
858 /****************
859 Dialog display
860 ****************/
862 /* Check if there is a snapshot dialog open */
863 $base = $this->DivListFai->selectedBase;
864 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
865 return($str);
866 }
868 /* Display dialog with system list */
869 $this->DivListFai->parent = $this;
870 $this->DivListFai->execute();
871 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
872 $this->reload();
873 $this->DivListFai->setEntries($this->objects);
874 return($this->DivListFai->Draw());
875 }
878 /* Return departments, that will be included within snapshot detection */
879 function get_used_snapshot_bases()
880 {
881 $tmp = array();
882 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
883 foreach($types as $type){
884 if($this->DivListFai->selectedBranch == "main"){
885 $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase;
886 }else{
887 $tmp[] = get_ou($type).$this->DivListFai->selectedBranch;
888 }
889 }
890 return($tmp);
891 }
894 /* Get available branches for current base */
895 function getBranches($base = false,$prefix = "")
896 {
897 $ret = array("/"=>"main");
898 $ldap = $this->config->get_ldap_link();
899 if(!$base){
900 $base = session::get('CurrentMainBase');
901 }
902 $tmp = FAI::get_all_releases_from_base($base,true);
903 foreach($tmp as $dn => $name){
904 $ret[$name]=$dn;
905 }
906 ksort($ret);
907 $ret = array_flip($ret);
909 return ($ret);
910 }
913 function list_get_selected_items()
914 {
915 $ids = array();
916 foreach($_POST as $name => $value){
917 if(preg_match("/^item_selected_[0-9]*$/",$name)){
918 $id = preg_replace("/^item_selected_/","",$name);
919 $ids[$id] = $id;
920 }
921 }
922 return($ids);
923 }
926 /* reload list of objects */
927 function reload()
928 {
929 /* Variable initialisation */
930 $str = "";
931 $Regex = $this->DivListFai->Regex;
932 $this->objects = array();
934 /* Get base */
935 $base = get_ou('faiou').$this->DivListFai->selectedBase;
936 if($this->DivListFai->selectedBranch != "main"){
937 $br = $this->getBranches();
938 if(isset($br[$this->DivListFai->selectedBranch])){
939 $base = $this->DivListFai->selectedBranch;
940 }else{
941 $base = get_ou('faiou').$this->DivListFai->selectedBase;
942 }
943 }
944 $this->base = $base;
945 $this->set_acl_base($this->base);
947 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
949 /* Create a new list of FAI object
950 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
951 */
952 $ObjectTypes = array(
953 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
954 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
955 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
956 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
957 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
958 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
959 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
961 $filter = "";
962 foreach($ObjectTypes as $key => $data){
963 if($this->DivListFai->$data['CHKBOX']){
964 $filter.= "(objectClass=".$key.")";
965 }
966 }
967 $filter = "(&(|".$filter.")(cn=$Regex))";
969 /* Get resolved release dependencies */
970 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
972 /* Ge listed ldap objects */
973 $ldap = $this->config->get_ldap_link();
974 $ldap->cd($this->config->current['BASE']);
975 foreach($tmp as $entry){
977 /* Get some more informations about the object */
978 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
979 $object = $ldap->fetch();
981 /* Walk through possible types */
982 foreach($ObjectTypes as $type => $rest){
984 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
986 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
988 /* Prepare object */
989 unset($object['objectClass']['count']);
990 if(!isset($object['description'][0])){
991 $object['description'][0]="";
992 }
994 /* Clean up object informations */
995 $obj = array();
996 $obj['cn'] = $object['cn'][0];
997 $obj['dn'] = $object['dn'];
998 $obj['acl'] = $acl;
999 $obj['description'] = $object['description'][0];
1000 $obj['objectClass'] = $object['objectClass'];
1002 /* Append type to this string, to be able to check if the selected
1003 * entry is of type 'freeze' or 'branch'
1004 */
1005 if(!isset($object['FAIstate'])){
1006 $obj['FAIstate'] = $this->lock_type;
1007 }else{
1008 $obj['FAIstate'] = $object['FAIstate'][0];
1009 }
1011 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1012 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1013 }
1014 }
1015 }
1017 ksort($this->objects);
1018 reset ($this->objects);
1020 /* use numeric index, thats a bit more secure */
1021 $tmp0 = array();
1022 foreach($this->objects as $obj){
1023 $tmp0[]= $obj;
1024 }
1025 $this->objects = array();
1026 $this->objects = $tmp0;
1027 }
1029 function remove_lock()
1030 {
1031 if (isset($this->dn)){
1032 del_lock ($this->dn);
1033 }
1034 }
1036 function get_type($array){
1037 if(in_array("FAIpartitionTable",$array['objectClass'])){
1038 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1039 }
1040 if(in_array("FAIscript",$array['objectClass'])){
1041 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1042 }
1043 if(in_array("FAItemplate",$array['objectClass'])){
1044 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1045 }
1046 if(in_array("FAIhook",$array['objectClass'])){
1047 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1048 }
1049 if(in_array("FAIvariable",$array['objectClass'])){
1050 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1051 }
1052 if(in_array("FAIprofile",$array['objectClass'])){
1053 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1054 }
1056 if(in_array("FAIpackageList",$array['objectClass'])){
1057 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1058 }
1059 }
1061 function CheckNewBranchName($name,$base)
1062 {
1063 $f = $this->DivListFai->selectedBranch;
1064 if($name == ""){
1065 return(false);
1066 }elseif(in_array($name,$this->getBranches($f))) {
1067 return(false);
1068 }elseif(tests::is_department_name_reserved($name,$base)){
1069 return(false);
1070 }
1071 return(true);
1072 }
1074 function save_object()
1075 {
1076 $this->DivListFai->save_object();
1077 }
1080 function copyPasteHandling_from_queue($s_action,$s_entry)
1081 {
1082 /* Check if Copy & Paste is disabled */
1083 if(!is_object($this->CopyPasteHandler)){
1084 return("");
1085 }
1087 $base = $this->DivListFai->selectedBranch;
1088 if($base == "main"){
1089 $base = $this->DivListFai->selectedBase;
1090 }
1092 /* Add a single entry to queue */
1093 if($s_action == "cut" || $s_action == "copy"){
1095 /* Cleanup object queue */
1096 $this->CopyPasteHandler->cleanup_queue();
1097 $entry = $this->objects[$s_entry];
1098 $a_setup = $this->get_type($entry);
1099 $dn = $entry['dn'];
1100 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1101 }
1103 /* Add entries to queue */
1104 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1106 /* Cleanup object queue */
1107 $this->CopyPasteHandler->cleanup_queue();
1109 /* Add new entries to CP queue */
1110 foreach($this->list_get_selected_items() as $id){
1112 /* Cleanup object queue */
1113 $entry = $this->objects[$id];
1114 $a_setup = $this->get_type($entry);
1115 $dn = $entry['dn'];
1118 if($s_action == "copy_multiple"){
1119 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1120 }
1121 if($s_action == "cut_multiple"){
1122 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1123 }
1124 }
1125 }
1127 /* Start pasting entries */
1128 if($s_action == "editPaste"){
1129 $this->start_pasting_copied_objects = TRUE;
1130 }
1132 /* Return C&P dialog */
1133 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1135 /* Get dialog */
1136 $data = $this->CopyPasteHandler->execute();
1137 $this->CopyPasteHandler->SetVar("base",$base);
1139 FAI::save_release_changes_now();
1141 /* Return dialog data */
1142 if(!empty($data)){
1143 return($data);
1144 }
1145 }
1147 /* Automatically disable status for pasting */
1148 if(!$this->CopyPasteHandler->entries_queued()){
1149 $this->start_pasting_copied_objects = FALSE;
1150 }
1151 return("");
1152 }
1155 /* Return plugin informations for acl handling */
1156 static function plInfo()
1157 {
1158 return (array(
1159 "plShortName" => _("FAI releases"),
1160 "plDescription" => _("FAI release management"),
1161 "plSelfModify" => FALSE,
1162 "plDepends" => array(),
1163 "plPriority" => 0,
1164 "plSection" => array("administration"),
1165 "plCategory" => array("fai"=> array("description" => _("FAI"),
1166 "objectClass" => "FAIclass")),
1167 "plProvidedAcls"=> array()));
1168 }
1169 }
1170 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1171 ?>