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 */
21 class faiManagement extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "FAI";
25 var $plDescription = "Fully Automatic Installation - management";
27 /* CLI vars */
28 var $cli_summary = "Handling of FAI entries";
29 var $cli_description = "This plugin represents a management tool\n
30 which allows us to manage all needed attributes for fully automatic installations (FAI)";
31 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* Headpage attributes */
34 var $lock_type = ""; // should be branch/freeze
35 var $lock_name = "";
36 var $lock_dn = "";
38 /* attribute list for save action */
39 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
40 var $objectclasses= array(); // ObjectClasses which the attributes are related to
41 var $dialog = array(); // This object contains every dialog we have currently opened
43 var $objects = array(); // This array contains all available objects shown in divlist
44 var $is_dialog = false;
46 var $dispNewBranch= false;
47 var $dispNewFreeze= false;
49 var $DivListFai;
50 var $start_pasting_copied_objects = FALSE;
51 var $CopyPasteHandler = FALSE;
52 var $base = "";
54 /* construction/reconstruction
55 */
56 function faiManagement (&$config, $ui)
57 {
58 /* Set defaults */
59 $this->dn = "";
60 $this->config = $config;
61 $this->ui = $ui;
63 /* Creat dialog object */
64 $this->DivListFai = new divListFai($this->config,$this);
66 /* Copy & Paste handler */
67 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
68 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
69 }
70 }
72 function execute()
73 {
74 /* Call parent execute */
75 plugin::execute();
77 /* Initialise vars and smarty */
78 $smarty = get_smarty();
79 $smarty->assign("BranchName","");
81 $display = "";
82 $s_action = "";
83 $s_entry = "";
85 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
86 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
89 /****************
90 Handle posts
91 ****************/
93 /* Check ImageButton posts
94 * Create new tab ich new_xx is posted
95 */
96 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
97 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
98 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
99 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
100 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
101 "/edit_continue/"=>"select_class_name_finished",
102 "/^multiple_copy_fai/" => "copy_multiple",
103 "/^multiple_cut_fai/" => "cut_multiple",
104 "/^copy/" => "copy",
105 "/^cut/" => "cut",
106 "/^remove_multiple_fai_objects/" => "del_multiple");
108 foreach($_POST as $name => $value){
109 foreach($posts as $reg => $act ){
110 if(preg_match($reg,$name)){
111 $s_action = $act;
112 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
113 $s_entry = preg_replace("/_.*$/","",$s_entry);
114 }
115 }
116 if(preg_match("/^entry_edit_.*/",$name)){
117 $s_entry = preg_replace("/^entry_edit_/","",$name);
118 $s_entry = preg_replace("/_.*$/","",$s_entry);
119 $s_action = "edit";
120 }elseif(preg_match("/^entry_delete_.*/",$name)){
121 $s_entry = preg_replace("/^entry_delete_/","",$name);
122 $s_entry = preg_replace("/_.*$/","",$s_entry);
123 $s_action = "delete";
124 }
125 }
127 if(isset($_GET['edit_entry'])){
128 $s_entry = $_GET['edit_entry'];
129 $s_action = "edit";
130 }
132 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
133 $s_action = "freeze_branch";
134 }
135 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
136 $s_action = "branch_branch";
137 }
138 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
139 $s_action = "remove_branch";
140 }
142 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
143 $this->dispNewBranch = false;
144 $this->dispNewFreeze = false;
145 }
148 $type_acl_mapping = array(
149 "FAIpartitionTable" => "faiPartitionTable",
150 "FAIpackageList" => "faiPackage",
151 "FAIscript" => "faiScript",
152 "FAIvariable" => "faiVariable",
153 "FAIhook" => "faiHook",
154 "FAIprofile" => "faiProfile",
155 "FAItemplate" => "faiTemplate");
158 /* handle C&P from layers menu */
159 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
160 $s_action = "copy_multiple";
161 }
162 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
163 $s_action = "cut_multiple";
164 }
165 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
166 $s_action = "editPaste";
167 }
169 /* Create options */
170 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
171 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
172 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
173 }
175 /* handle remove from layers menu */
176 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
177 $s_action = "del_multiple";
178 }
180 /********************
181 Copy & Paste
182 ********************/
184 /* Display the copy & paste dialog, if it is currently open */
185 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
186 if($ret){
187 return($ret);
188 }
191 /****************
192 Delete confirme dialog
193 ****************/
195 if ($s_action=="delete"){
197 /* Get 'dn' from posted termlinst */
198 $this->dn= $this->objects[$s_entry]['dn'];
200 /* Load permissions for selected 'dn' and check if
201 we're allowed to remove this 'dn' */
202 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
203 if(preg_match("/d/",$acl)){
205 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
206 if (($user= get_lock($this->dn)) != ""){
207 return(gen_locked_message ($user, $this->dn));
208 }
210 /* Lock the current entry, so nobody will edit it during deletion */
211 add_lock ($this->dn, $this->ui->dn);
212 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
213 $smarty->assign("multiple", false);
214 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
215 } else {
217 /* Obviously the user isn't allowed to delete. Show message and
218 clean session. */
219 print_red (_("You are not allowed to delete this component!"));
220 }
221 }
224 /********************
225 Delete MULTIPLE entries requested, display confirm dialog
226 ********************/
228 if ($s_action=="del_multiple"){
229 $this->dns = array();
230 $ids = $this->list_get_selected_items();
232 if(count($ids)){
234 foreach($ids as $id){
235 $dn = $this->objects[$id]['dn'];
236 if (($user= get_lock($dn)) != ""){
237 return(gen_locked_message ($user, $dn));
238 }
239 $this->dns[$id] = $dn;
240 }
242 $dns_names = "<br><pre>";
243 foreach($this->dns as $dn){
244 add_lock ($dn, $this->ui->dn);
245 $dns_names .= $dn."\n";
246 }
247 $dns_names .="</pre>";
249 /* Lock the current entry, so nobody will edit it during deletion */
250 if (count($this->dns) == 1){
251 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
252 } else {
253 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
254 }
255 $smarty->assign("multiple", true);
256 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
257 }
258 }
261 /********************
262 Delete MULTIPLE entries confirmed
263 ********************/
265 /* Confirmation for deletion has been passed. Users should be deleted. */
266 if (isset($_POST['delete_multiple_fai_object_confirm'])){
268 /* Find out more about the object type */
269 $ldap = $this->config->get_ldap_link();
271 /* Remove user by user and check acls before removeing them */
272 foreach($this->dns as $key => $dn){
274 $ldap->cat($dn, array('objectClass'));
275 $attrs = $ldap->fetch();
276 $type = $this->get_type($attrs);
278 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
279 if(preg_match("/d/",$acl)){
281 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
282 $this->dialog->set_acl_base($dn);
283 $this->dialog->by_object[$type[1]]->remove_from_parent ();
284 unset ($this->dialog);
285 $this->dialog= FALSE;
286 $to_del = clean_up_releases($dn);
287 save_release_changes_now();
289 foreach($to_del as $dn){
290 $ldap->rmdir_recursive($dn);
291 }
293 } else {
295 /* Normally this shouldn't be reached, send some extra
296 logs to notify the administrator */
297 print_red (_("You are not allowed to delete this component!"));
298 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
299 }
301 /* Remove lock file after successfull deletion */
302 del_lock ($dn);
303 unset($this->dns[$key]);
304 }
305 }
308 /********************
309 Delete MULTIPLE entries Canceled
310 ********************/
312 /* Remove lock */
313 if(isset($_POST['delete_multiple_fai_object_cancel'])){
314 foreach($this->dns as $key => $dn){
315 del_lock ($dn);
316 unset($this->dns[$key]);
317 }
318 }
321 /****************
322 Delete aborted
323 ****************/
325 /* Delete canceled? */
326 if (isset($_POST['delete_cancel'])){
327 del_lock ($this->dn);
328 }
331 /****************
332 Delete confirmed
333 ****************/
335 /* Deltetion was confirmed, so delete this entry
336 */
337 if (isset($_POST['delete_terminal_confirm'])){
339 /* Some nice guy may send this as POST, so we've to check
340 for the permissions again. */
342 /* Find out more about the object type */
343 $ldap = $this->config->get_ldap_link();
344 $ldap->cat($this->dn, array('objectClass'));
345 if($ldap->count()){
346 $attrs = $ldap->fetch();
347 $type = $this->get_type($attrs);
349 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
350 if(preg_match("/d/",$acl)){
352 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
353 $this->dialog->set_acl_base($this->dn);
354 $this->dialog->by_object[$type[1]]->remove_from_parent ();
355 unset ($this->dialog);
356 $this->dialog= FALSE;
357 $to_del = clean_up_releases($this->dn);
358 save_release_changes_now();
360 foreach($to_del as $dn){
361 $ldap->rmdir_recursive($dn);
362 }
364 } else {
366 /* Normally this shouldn't be reached, send some extra
367 logs to notify the administrator */
368 print_red (_("You are not allowed to delete this component!"));
369 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
370 }
372 }else{
373 print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
374 }
375 /* Remove lock file after successfull deletion */
376 del_lock ($this->dn);
377 }
380 /****************
381 Edit entry
382 ****************/
384 if(($s_action == "edit") && (!isset($this->dialog->config))){
385 $entry = $this->objects[$s_entry];
386 $a_setup = $this->get_type($entry);
387 $this->dn = $entry['dn'];
389 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
390 if (($user= get_lock($this->dn)) != ""){
391 return(gen_locked_message ($user, $this->dn));
392 }
393 add_lock ($this->dn, $this->ui->dn);
395 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
396 $this->dialog->set_acl_base($this->dn);
397 $this->is_dialog = true;
399 if($entry['FAIstate'] == "freeze"){
400 #$this->dialog->set_acl(array("*none*")) ;
401 echo "Dawn it is freezed.";
402 }
403 $_SESSION['objectinfo'] = $this->dn;
404 }
407 /* Branch handling
408 09.01.2006
409 */
411 /****************
412 Remove branch
413 ****************/
415 /* Remove branch
416 */
417 if($s_action == "remove_branch"){
418 $base= $this->DivListFai->selectedBranch;
420 /* Check if we have a post remove method configured
421 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
422 */
423 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
424 /* Load permissions for selected 'dn' and check if
425 we're allowed to remove this 'dn' */
426 if($this->acl_is_removeable()){
428 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
429 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
430 } else {
431 print_red (_("You are not allowed to delete this release!"));
432 }
433 }
434 }
437 /****************
438 Remove branch confirmed
439 ****************/
441 if(isset($_POST['delete_branch_confirm'])){
443 /* Check if we have a post remove method configured
444 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
445 */
446 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
448 $bb = $this->DivListFai->selectedBranch;
449 if(!isset($ldap)){
450 $ldap = $this->config->get_ldap_link();
451 }
453 $br = $this->getBranches();
455 if(isset($br[$bb]) && $this->acl_is_removeable()){
456 $name = $br[$bb];
457 $ldap->cd($bb);
458 $ldap->recursive_remove();
459 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
460 $ldap->recursive_remove();
461 $this->DivListFai->selectedBranch = "main";
463 /* Post remove */
464 $this->lock_name = $name;
465 $this->lock_dn = $bb;
466 $this->postremove();
468 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
469 }
470 }
471 }
474 /****************
475 Create a new branch "insert Name"
476 ****************/
478 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
479 $_SESSION['LASTPOST'] = $_POST;
481 if($this->dispNewBranch){
482 $type = "branch";
483 }else{
484 $type = "freeze";
485 }
487 /* Check branch name */
488 $name = $_POST['BranchName'];
489 $is_ok = true;
490 $smarty->assign("BranchName",$name);
491 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
493 /* Check used characters */
494 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
495 if($type == "branch"){
496 print_red(_("Specified branch name is invalid."));
497 }else{
498 print_red(_("Specified freeze name is invalid."));
499 }
500 $is_ok = false;
501 }
503 /* Check if this name is already in use */
504 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
505 print_red(_("This name is already in use."));
506 $is_ok = false;
507 }
509 if($is_ok){
510 $_SESSION['LASTPOST']['base'] = $base;
511 $_SESSION['LASTPOST']['type'] = $type;
512 $smarty->assign("iframe", true);
513 $smarty->assign("plugID", $_GET['plug']);
514 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
515 return($display);
516 }
517 }
520 /****************
521 Create a new branch
522 ****************/
524 if(isset($_GET['PerformBranch'])){
526 if(!$this->acl_is_createable()){
527 print_red(_("You are not allowed to create a new branch."));
528 }else{
530 /* Create it know */
531 $this->dispNewBranch = false;
532 $this->dispNewFreeze = false;
533 $base = $_SESSION['LASTPOST']['base'];
534 $_POST = $_SESSION['LASTPOST'];
535 $name = $_POST['BranchName'];
537 $type = $_SESSION['LASTPOST']['type'];
538 $ldap = $this->config->get_ldap_link();
540 $baseToUse = $base;
541 if($this->DivListFai->selectedBranch != "main" ){
542 $baseToUse = $this->DivListFai->selectedBranch;
543 }
545 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
547 $CurrentReleases = $this->getBranches();
548 $NewReleaseName = $name;
549 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
550 if($this->DivListFai->selectedBranch != "main"){
551 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
552 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
553 }else{
554 $NewReleaseName = $name;
555 }
556 }
558 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
559 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
561 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
562 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
564 /* Check if source depeartments exist */
565 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
566 $ldap->cd($this->config->current['BASE']);
567 $ldap->cat($dep);
568 if(!$ldap->count()){
569 $ldap->create_missing_trees($dep);
570 }
571 }
573 /* Print header to have styles included */
574 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
575 <html>
576 <head>
577 <title></title>
578 <style type="text/css">@import url("themes/default/style.css");</style>
579 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
580 </head>
581 <body style="background: none;margin:3px;color:black">
582 ';
584 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
586 /* Duplicate applications
587 */
588 $ldap->cat($appsrc,array("dn")) ;
589 if($ldap->count()){
590 $ldap->cd ($appdst);
591 $ldap->recursive_remove();
592 $ldap->cd ($this->config->current['BASE']);
593 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
594 }
596 /* Duplicate mime types
597 */
598 $ldap->cat($mimesrc,array("dn")) ;
599 if($ldap->count()){
600 $ldap->cd ($mimedst);
601 $ldap->recursive_remove();
602 $ldap->cd ($this->config->current['BASE']);
603 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
604 }
606 $attr = array();
607 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
608 $attr['ou'] = $name;
609 $attr['FAIstate'] = $type;
610 $ldap->cd($this->config->current['BASE']);
611 $ldap->cd("ou=".$name.",".$baseToUse);
612 $ldap->cat("ou=".$name.",".$baseToUse);
613 if($ldap->count()){
614 $ldap->modify($attr);
615 }else{
616 $ldap->add($attr);
617 }
619 /* Duplicate fai objects
620 */
621 // $ldap->cd ("ou=".$name.",".$baseToUse);
622 // $ldap->recursive_remove();
623 // $ldap->cd ($this->config->current['BASE']);
624 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
626 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
627 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
628 </form></div>";
630 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
632 /* Print footer to have valid html */
633 echo "</body></html>";
635 $this->dispNewFreeze = false;
637 /* Postcreate */
639 /* Assign possible attributes */
640 $this->lock_type = $type;
641 $this->lock_name = $name;
642 $this->lock_dn = $baseToUse;
643 $this->postcreate();
644 exit();
645 }
646 }
648 /****************
649 Display dialog to enter new Branch name
650 ****************/
652 /* Check if we have a post create method configured
653 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
654 */
655 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
656 if(($s_action == "branch_branch")||($this->dispNewBranch)){
657 if(!$this->acl_is_createable()){
658 print_red(_("You are not allowed to create a new branch."));
659 }else{
660 $this->dispNewBranch=true;
661 $smarty->assign("iframe",false);
662 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
663 return($display);
664 }
665 }
666 }
669 /****************
670 Display dialog to enter new Freeze name
671 ****************/
673 /* Check if we have a post create method configured
674 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
675 */
676 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
677 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
678 if(!$this->acl_is_createable()){
679 print_red(_("You are not allowed to create a new branch."));
680 }else{
681 $this->dispNewFreeze = true;
682 $smarty->assign("iframe",false);
683 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
684 return($display);
685 }
686 }
687 }
690 /****************
691 Create a new object
692 ****************/
694 $types = array( "new_partition" => "FAIpartitionTable",
695 "new_script" => "FAIscript",
696 "new_hook" => "FAIhook",
697 "new_variable" => "FAIvariable",
698 "new_template" => "FAItemplate",
699 "new_package" => "FAIpackageList");
701 if(isset($types[$s_action])){
702 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
703 if(preg_match("/c/",$acl)){
704 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
705 }else{
706 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
707 }
708 }
710 /* New Profile */
711 if($s_action == "new_profile"){
712 $this->dn = "new" ;
714 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
715 if(preg_match("/c/",$acl)){
716 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
717 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
718 $this->dialog->set_acl_base($this->base);
720 $this->is_dialog = false;
721 }else{
722 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
723 }
724 }
727 /****************
728 Get from ask class name dialog
729 ****************/
731 if($s_action == "select_class_name_finished"){
732 $this->dialog->save_object();
733 if(count($this->dialog->check())!=0){
734 foreach($this->dialog->check() as $msg){
735 print_red($msg);
736 }
737 }elseif(isset($this->dialog->objectClass)){
738 $this->dn = "new" ;
739 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
740 $name = $this->dialog->save();
742 if(class_exists($a_setup[0])){
743 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
744 $this->dialog->set_acl_base($this->base);
745 $this->dialog->by_object[$a_setup[1]]->cn = $name;
746 $this->is_dialog = true;
747 }
748 }
749 }
752 /****************
753 Cancel dialogs
754 ****************/
756 if(isset($_POST['edit_cancel'])){
757 unset($this->dialog);
758 $this->dialog=FALSE;
759 $this->is_dialog = false;
760 unset($_SESSION['objectinfo']);
761 del_lock ($this->dn);
762 }
765 /****************
766 Save sub dialogs
767 ****************/
769 /* This check if the given tab could be saved
770 * If it was possible to save it, remove dialog object.
771 * If it wasn't possible, show errors and keep dialog.
772 */
773 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
774 $this->dialog->save_object();
775 $msgs= $this->dialog->check();
776 if(count($msgs)!=0){
777 foreach($msgs as $msg){
778 print_red($msg);
779 }
780 }else{
781 $this->dialog->save();
782 save_release_changes_now();
783 if (!isset($_POST['edit_apply'])){
784 del_lock ($this->dn);
785 unset($this->dialog);
786 $this->dialog=FALSE;
787 $this->is_dialog=false;
788 unset($_SESSION['objectinfo']);
789 }
790 }
791 }
794 /****************
795 Display currently open dialog
796 ****************/
798 /* If dialog is set, but $this->is_dialog==false, then
799 * only the "abort" button is shown, this are dialogs that must not be saved.
800 * If is_dialog == true, we are currently editing tab objects.
801 * Here we need both, save and cancel
802 */
804 if(is_object($this->dialog)){
805 $display .= $this->dialog->execute();
806 /* Don't show buttons if tab dialog requests this */
808 if(isset($this->dialog->current)){
810 $obj = $this->dialog->by_object[$this->dialog->current];
812 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
814 $display.= "<p style=\"text-align:right\">\n";
815 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
816 $display.= " \n";
817 if ($this->dn != "new"){
818 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
819 $display.= " \n";
820 }
821 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
822 $display.= "</p>";
823 }elseif(!isset($this->dialog->current)){
824 $display.= "<p style=\"text-align:right\">\n";
825 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
826 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
827 $display.= "</p>";
828 }
829 }else{
830 $display.= "<p style=\"text-align:right\">\n";
831 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
832 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
833 $display.= "</p>";
835 }
836 return($display);
837 }
840 /****************
841 Dialog display
842 ****************/
844 /* Check if there is a snapshot dialog open */
845 $base = $this->DivListFai->selectedBase;
846 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
847 return($str);
848 }
850 /* Display dialog with system list */
851 $this->DivListFai->parent = $this;
852 $this->DivListFai->execute();
853 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
854 $this->reload();
855 $this->DivListFai->setEntries($this->objects);
856 return($this->DivListFai->Draw());
857 }
860 /* Return departments, that will be included within snapshot detection */
861 function get_used_snapshot_bases()
862 {
863 $tmp = array();
864 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
865 foreach($types as $type){
866 if($this->DivListFai->selectedBranch == "main"){
867 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
868 }else{
869 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
870 }
871 }
872 return($tmp);
873 }
876 /* Get available branches for current base */
877 function getBranches($base = false,$prefix = "")
878 {
879 $ret = array("/"=>"main");
880 $ldap = $this->config->get_ldap_link();
881 if(!$base){
882 $base= $_SESSION['CurrentMainBase'];
883 }
884 $tmp = get_all_releases_from_base($base,true);
885 foreach($tmp as $dn => $name){
886 $ret[$name]=$dn;
887 }
888 ksort($ret);
889 $ret = array_flip($ret);
891 return ($ret);
892 }
895 function list_get_selected_items()
896 {
897 $ids = array();
898 foreach($_POST as $name => $value){
899 if(preg_match("/^item_selected_[0-9]*$/",$name)){
900 $id = preg_replace("/^item_selected_/","",$name);
901 $ids[$id] = $id;
902 }
903 }
904 return($ids);
905 }
908 /* reload list of objects */
909 function reload()
910 {
911 /* Variable initialisation */
912 $str = "";
913 $Regex = $this->DivListFai->Regex;
914 $this->objects = array();
916 /* Get base */
917 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
918 if($this->DivListFai->selectedBranch != "main"){
919 $br = $this->getBranches();
920 if(isset($br[$this->DivListFai->selectedBranch])){
921 $base = $this->DivListFai->selectedBranch;
922 }else{
923 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
924 }
925 }
926 $this->base = $base;
927 $this->set_acl_base($this->base);
929 $this->lock_type = get_release_tag(get_release_dn($base));
931 /* Create a new list of FAI object
932 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
933 */
934 $ObjectTypes = array(
935 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
936 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
937 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
938 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
939 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
940 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
941 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
943 $filter = "";
944 foreach($ObjectTypes as $key => $data){
945 if($this->DivListFai->$data['CHKBOX']){
946 $filter.= "(objectClass=".$key.")";
947 }
948 }
949 $filter = "(&(|".$filter.")(cn=$Regex))";
951 /* Get resolved release dependencies */
952 $tmp = get_all_objects_for_given_base($base,$filter);
954 /* Ge listed ldap objects */
955 $ldap = $this->config->get_ldap_link();
956 $ldap->cd($this->config->current['BASE']);
957 foreach($tmp as $entry){
959 /* Get some more informations about the object */
960 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
961 $object = $ldap->fetch();
963 /* Walk through possible types */
964 foreach($ObjectTypes as $type => $rest){
966 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
968 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
970 /* Prepare object */
971 unset($object['objectClass']['count']);
972 if(!isset($object['description'][0])){
973 $object['description'][0]="";
974 }
976 /* Clean up object informations */
977 $obj = array();
978 $obj['cn'] = $object['cn'][0];
979 $obj['dn'] = $object['dn'];
980 $obj['acl'] = $acl;
981 $obj['description'] = $object['description'][0];
982 $obj['objectClass'] = $object['objectClass'];
984 /* Append type to this string, to be able to check if the selected
985 * entry is of type 'freeze' or 'branch'
986 */
987 if(!isset($object['FAIstate'])){
988 $obj['FAIstate'] = $this->lock_type;
989 }else{
990 $obj['FAIstate'] = $object['FAIstate'][0];
991 }
993 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
994 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
995 }
996 }
997 }
999 ksort($this->objects);
1000 reset ($this->objects);
1002 /* use numeric index, thats a bit more secure */
1003 $tmp0 = array();
1004 foreach($this->objects as $obj){
1005 $tmp0[]= $obj;
1006 }
1007 $this->objects = array();
1008 $this->objects = $tmp0;
1009 }
1011 function remove_lock()
1012 {
1013 if (isset($this->dn)){
1014 del_lock ($this->dn);
1015 }
1016 }
1018 function get_type($array){
1019 if(in_array("FAIpartitionTable",$array['objectClass'])){
1020 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1021 }
1022 if(in_array("FAIscript",$array['objectClass'])){
1023 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1024 }
1025 if(in_array("FAItemplate",$array['objectClass'])){
1026 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1027 }
1028 if(in_array("FAIhook",$array['objectClass'])){
1029 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1030 }
1031 if(in_array("FAIvariable",$array['objectClass'])){
1032 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1033 }
1034 if(in_array("FAIprofile",$array['objectClass'])){
1035 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1036 }
1038 if(in_array("FAIpackageList",$array['objectClass'])){
1039 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1040 }
1041 }
1043 function CheckNewBranchName($name,$base)
1044 {
1045 $f = $this->DivListFai->selectedBranch;
1046 if($name == ""){
1047 return(false);
1048 }elseif(in_array($name,$this->getBranches($f))) {
1049 return(false);
1050 }elseif(is_department_name_reserved($name,$base)){
1051 return(false);
1052 }
1053 return(true);
1054 }
1056 function save_object()
1057 {
1058 $this->DivListFai->save_object();
1059 }
1062 function copyPasteHandling_from_queue($s_action,$s_entry)
1063 {
1064 /* Check if Copy & Paste is disabled */
1065 if(!is_object($this->CopyPasteHandler)){
1066 return("");
1067 }
1069 $base = $this->DivListFai->selectedBranch;
1070 if($base == "main"){
1071 $base = $this->DivListFai->selectedBase;
1072 }
1074 /* Add a single entry to queue */
1075 if($s_action == "cut" || $s_action == "copy"){
1077 /* Cleanup object queue */
1078 $this->CopyPasteHandler->cleanup_queue();
1079 $entry = $this->objects[$s_entry];
1080 $a_setup = $this->get_type($entry);
1081 $dn = $entry['dn'];
1082 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1083 }
1085 /* Add entries to queue */
1086 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1088 /* Cleanup object queue */
1089 $this->CopyPasteHandler->cleanup_queue();
1091 /* Add new entries to CP queue */
1092 foreach($this->list_get_selected_items() as $id){
1094 /* Cleanup object queue */
1095 $entry = $this->objects[$id];
1096 $a_setup = $this->get_type($entry);
1097 $dn = $entry['dn'];
1100 if($s_action == "copy_multiple"){
1101 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1102 }
1103 if($s_action == "cut_multiple"){
1104 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1105 }
1106 }
1107 }
1109 /* Start pasting entries */
1110 if($s_action == "editPaste"){
1111 $this->start_pasting_copied_objects = TRUE;
1112 }
1114 /* Return C&P dialog */
1115 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1117 /* Load entry from queue and set base */
1118 $this->CopyPasteHandler->load_entry_from_queue();
1119 $this->CopyPasteHandler->SetVar("base",$base);
1121 /* Get dialog */
1122 $data = $this->CopyPasteHandler->execute();
1124 save_release_changes_now();
1126 /* Return dialog data */
1127 if(!empty($data)){
1128 return($data);
1129 }
1130 }
1132 /* Automatically disable status for pasting */
1133 if(!$this->CopyPasteHandler->entries_queued()){
1134 $this->start_pasting_copied_objects = FALSE;
1135 }
1136 return("");
1137 }
1140 /* Return plugin informations for acl handling */
1141 static function plInfo()
1142 {
1143 return (array(
1144 "plShortName" => _("FAI releases"),
1145 "plDescription" => _("FAI release management"),
1146 "plSelfModify" => FALSE,
1147 "plDepends" => array(),
1148 "plPriority" => 0,
1149 "plSection" => array("administration"),
1150 "plCategory" => array("fai"=> array("description" => _("FAI"),
1151 "objectClass" => "FAIclass")),
1152 "plProvidedAcls"=> array()));
1153 }
1154 }
1155 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1156 ?>