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;
53 /* construction/reconstruction
54 */
55 function faiManagement (&$config, $ui)
56 {
57 /* Set defaults */
58 $this->dn = "";
59 $this->config = $config;
60 $this->ui = $ui;
62 /* Creat dialog object */
63 $this->DivListFai = new divListFai($this->config,$this);
64 }
66 function execute()
67 {
68 /* Call parent execute */
69 plugin::execute();
71 /* Initialise vars and smarty */
72 $smarty = get_smarty();
73 $smarty->assign("BranchName","");
75 $display = "";
76 $s_action = "";
77 $s_entry = "";
79 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
80 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
83 /****************
84 Handle posts
85 ****************/
87 /* Check ImageButton posts
88 * Create new tab ich new_xx is posted
89 */
90 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
91 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
92 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
93 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
94 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
95 "/edit_continue/"=>"select_class_name_finished",
96 "/^multiple_copy_fai/" => "copy_multiple",
97 "/^multiple_cut_fai/" => "cut_multiple",
98 "/^remove_multiple_fai_objects/" => "del_multiple");
100 foreach($_POST as $name => $value){
101 foreach($posts as $reg => $act ){
102 if(preg_match($reg,$name)){
103 $s_action = $act;
104 }
105 }
106 if(preg_match("/^entry_edit_.*/",$name)){
107 $s_entry = preg_replace("/^entry_edit_/","",$name);
108 $s_entry = preg_replace("/_.*$/","",$s_entry);
109 $s_action = "edit";
110 }elseif(preg_match("/^entry_delete_.*/",$name)){
111 $s_entry = preg_replace("/^entry_delete_/","",$name);
112 $s_entry = preg_replace("/_.*$/","",$s_entry);
113 $s_action = "delete";
114 }
115 }
117 if(isset($_GET['edit_entry'])){
118 $s_entry = $_GET['edit_entry'];
119 $s_action = "edit";
120 }
122 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
123 $this->dispNewBranch = false;
124 $this->dispNewFreeze = false;
125 }
128 $type_acl_mapping = array(
129 "FAIpartitionTable" => "faiPartitionTable",
130 "FAIpackageList" => "faiPackage",
131 "FAIscript" => "faiScript",
132 "FAIvariable" => "faiVariable",
133 "FAIhook" => "faiHook",
134 "FAIprofile" => "faiProfile",
135 "FAItemplate" => "faiTemplate");
137 /****************
138 Delete confirme dialog
139 ****************/
141 if ($s_action=="delete"){
143 /* Get 'dn' from posted termlinst */
144 $this->dn= $this->objects[$s_entry]['dn'];
146 /* Load permissions for selected 'dn' and check if
147 we're allowed to remove this 'dn' */
148 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
149 if(preg_match("/d/",$acl)){
151 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
152 if (($user= get_lock($this->dn)) != ""){
153 return(gen_locked_message ($user, $this->dn));
154 }
156 /* Lock the current entry, so nobody will edit it during deletion */
157 add_lock ($this->dn, $this->ui->dn);
158 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
159 $smarty->assign("multiple", false);
160 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
161 } else {
163 /* Obviously the user isn't allowed to delete. Show message and
164 clean session. */
165 print_red (_("You are not allowed to delete this component!"));
166 }
167 }
170 /********************
171 Delete MULTIPLE entries requested, display confirm dialog
172 ********************/
174 if ($s_action=="del_multiple"){
175 $this->dns = array();
176 $ids = $this->list_get_selected_items();
178 if(count($ids)){
180 foreach($ids as $id){
181 $dn = $this->objects[$id]['dn'];
182 if (($user= get_lock($dn)) != ""){
183 return(gen_locked_message ($user, $dn));
184 }
185 $this->dns[$id] = $dn;
186 }
188 $dns_names = "<br><pre>";
189 foreach($this->dns as $dn){
190 add_lock ($dn, $this->ui->dn);
191 $dns_names .= $dn."\n";
192 }
193 $dns_names .="</pre>";
195 /* Lock the current entry, so nobody will edit it during deletion */
196 if (count($this->dns) == 1){
197 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
198 } else {
199 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
200 }
201 $smarty->assign("multiple", true);
202 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
203 }
204 }
207 /********************
208 Delete MULTIPLE entries confirmed
209 ********************/
211 /* Confirmation for deletion has been passed. Users should be deleted. */
212 if (isset($_POST['delete_multiple_fai_object_confirm'])){
214 /* Find out more about the object type */
215 $ldap = $this->config->get_ldap_link();
217 /* Remove user by user and check acls before removeing them */
218 foreach($this->dns as $key => $dn){
220 $ldap->cat($dn, array('objectClass'));
221 $attrs = $ldap->fetch();
222 $type = $this->get_type($attrs);
224 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
225 if(preg_match("/d/",$acl)){
227 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
228 $this->dialog->set_acl_base($dn);
229 $this->dialog->by_object[$type[1]]->remove_from_parent ();
230 unset ($this->dialog);
231 $this->dialog= FALSE;
232 $to_del = clean_up_releases($dn);
233 save_release_changes_now();
235 foreach($to_del as $dn){
236 $ldap->rmdir_recursive($dn);
237 }
239 } else {
241 /* Normally this shouldn't be reached, send some extra
242 logs to notify the administrator */
243 print_red (_("You are not allowed to delete this component!"));
244 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
245 }
247 /* Remove lock file after successfull deletion */
248 del_lock ($dn);
249 unset($this->dns[$key]);
250 }
251 }
254 /********************
255 Delete MULTIPLE entries Canceled
256 ********************/
258 /* Remove lock */
259 if(isset($_POST['delete_multiple_fai_object_cancel'])){
260 foreach($this->dns as $key => $dn){
261 del_lock ($dn);
262 unset($this->dns[$key]);
263 }
264 }
267 /****************
268 Delete aborted
269 ****************/
271 /* Delete canceled? */
272 if (isset($_POST['delete_cancel'])){
273 del_lock ($this->dn);
274 }
277 /****************
278 Delete confirmed
279 ****************/
281 /* Deltetion was confirmed, so delete this entry
282 */
283 if (isset($_POST['delete_terminal_confirm'])){
285 /* Some nice guy may send this as POST, so we've to check
286 for the permissions again. */
288 /* Find out more about the object type */
289 $ldap = $this->config->get_ldap_link();
290 $ldap->cat($this->dn, array('objectClass'));
291 if($ldap->count()){
292 $attrs = $ldap->fetch();
293 $type = $this->get_type($attrs);
295 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
296 if(preg_match("/d/",$acl)){
298 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
299 $this->dialog->set_acl_base($this->dn);
300 $this->dialog->by_object[$type[1]]->remove_from_parent ();
301 unset ($this->dialog);
302 $this->dialog= FALSE;
303 $to_del = clean_up_releases($this->dn);
304 save_release_changes_now();
306 foreach($to_del as $dn){
307 $ldap->rmdir_recursive($dn);
308 }
310 } else {
312 /* Normally this shouldn't be reached, send some extra
313 logs to notify the administrator */
314 print_red (_("You are not allowed to delete this component!"));
315 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
316 }
318 }else{
319 print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
320 }
321 /* Remove lock file after successfull deletion */
322 del_lock ($this->dn);
323 }
326 /****************
327 Edit entry
328 ****************/
330 if(($s_action == "edit") && (!isset($this->dialog->config))){
331 $entry = $this->objects[$s_entry];
332 $a_setup = $this->get_type($entry);
333 $this->dn = $entry['dn'];
335 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
336 if (($user= get_lock($this->dn)) != ""){
337 return(gen_locked_message ($user, $this->dn));
338 }
339 add_lock ($this->dn, $this->ui->dn);
341 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
342 $this->dialog->set_acl_base($this->dn);
343 $this->is_dialog = true;
345 if($entry['FAIstate'] == "freeze"){
346 #$this->dialog->set_acl(array("*none*")) ;
347 echo "Dawn it is freezed.";
348 }
349 $_SESSION['objectinfo'] = $this->dn;
350 }
353 /* Branch handling
354 09.01.2006
355 */
357 /****************
358 Remove branch
359 ****************/
361 /* Remove branch
362 */
363 if($s_action == "remove_branch"){
364 $base= $this->DivListFai->selectedBranch;
366 /* Check if we have a post remove method configured
367 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
368 */
369 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
371 /* Load permissions for selected 'dn' and check if
372 we're allowed to remove this 'dn' */
373 $this->set_acl_base($base);
374 if($this->acl_is_removeable()){
376 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
377 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
378 } else {
379 print_red (_("You are not allowed to delete this release!"));
380 }
381 }
382 }
385 /****************
386 Remove branch confirmed
387 ****************/
389 if(isset($_POST['delete_branch_confirm'])){
391 /* Check if we have a post remove method configured
392 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
393 */
394 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
396 $bb = $this->DivListFai->selectedBranch;
397 if(!isset($ldap)){
398 $ldap = $this->config->get_ldap_link();
399 }
401 $br = $this->getBranches();
403 if(isset($br[$bb]) && $this->acl_is_removeable()){
404 $name = $br[$bb];
405 $ldap->cd($bb);
406 $ldap->recursive_remove();
407 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
408 $ldap->recursive_remove();
409 $this->DivListFai->selectedBranch = "main";
411 /* Post remove */
412 $this->lock_name = $name;
413 $this->lock_dn = $bb;
414 $this->postremove();
416 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
417 }
418 }
419 }
422 /****************
423 Create a new branch "insert Name"
424 ****************/
426 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
427 $_SESSION['LASTPOST'] = $_POST;
429 if($this->dispNewBranch){
430 $type = "branch";
431 }else{
432 $type = "freeze";
433 }
435 /* Check branch name */
436 $name = $_POST['BranchName'];
437 $is_ok = true;
438 $smarty->assign("BranchName",$name);
439 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
441 /* Check used characters */
442 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
443 if($type == "branch"){
444 print_red(_("Specified branch name is invalid."));
445 }else{
446 print_red(_("Specified freeze name is invalid."));
447 }
448 $is_ok = false;
449 }
451 /* Check if this name is already in use */
452 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
453 print_red(_("This name is already in use."));
454 $is_ok = false;
455 }
457 if($is_ok){
458 $_SESSION['LASTPOST']['base'] = $base;
459 $_SESSION['LASTPOST']['type'] = $type;
460 $smarty->assign("iframe", true);
461 $smarty->assign("plugID", $_GET['plug']);
462 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
463 return($display);
464 }
465 }
468 /****************
469 Create a new branch
470 ****************/
472 if(isset($_GET['PerformBranch'])){
474 if(!$this->acl_is_createable()){
475 print_red(_("You are not allowed to create a new branch."));
476 }else{
478 /* Create it know */
479 $this->dispNewBranch = false;
480 $this->dispNewFreeze = false;
481 $base = $_SESSION['LASTPOST']['base'];
482 $_POST = $_SESSION['LASTPOST'];
483 $name = $_POST['BranchName'];
485 $type = $_SESSION['LASTPOST']['type'];
486 $ldap = $this->config->get_ldap_link();
488 $baseToUse = $base;
489 if($this->DivListFai->selectedBranch != "main" ){
490 $baseToUse = $this->DivListFai->selectedBranch;
491 }
493 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
495 $CurrentReleases = $this->getBranches();
496 $NewReleaseName = $name;
497 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
498 if($this->DivListFai->selectedBranch != "main"){
499 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
500 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
501 }else{
502 $NewReleaseName = $name;
503 }
504 }
506 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
507 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
509 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
510 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
512 /* Check if source depeartments exist */
513 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
514 $ldap->cd($this->config->current['BASE']);
515 $ldap->cat($dep);
516 if(!$ldap->count()){
517 $ldap->create_missing_trees($dep);
518 }
519 }
521 /* Print header to have styles included */
522 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
523 <html>
524 <head>
525 <title></title>
526 <style type="text/css">@import url("themes/default/style.css");</style>
527 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
528 </head>
529 <body style="background: none;margin:3px;color:black">
530 ';
532 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
534 /* Duplicate applications
535 */
536 $ldap->cat($appsrc,array("dn")) ;
537 if($ldap->count()){
538 $ldap->cd ($appdst);
539 $ldap->recursive_remove();
540 $ldap->cd ($this->config->current['BASE']);
541 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
542 }
544 /* Duplicate mime types
545 */
546 $ldap->cat($mimesrc,array("dn")) ;
547 if($ldap->count()){
548 $ldap->cd ($mimedst);
549 $ldap->recursive_remove();
550 $ldap->cd ($this->config->current['BASE']);
551 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
552 }
554 $attr = array();
555 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
556 $attr['ou'] = $name;
557 $attr['FAIstate'] = $type;
558 $ldap->cd($this->config->current['BASE']);
559 $ldap->cd("ou=".$name.",".$baseToUse);
560 $ldap->cat("ou=".$name.",".$baseToUse);
561 if($ldap->count()){
562 $ldap->modify($attr);
563 }else{
564 $ldap->add($attr);
565 }
567 /* Duplicate fai objects
568 */
569 // $ldap->cd ("ou=".$name.",".$baseToUse);
570 // $ldap->recursive_remove();
571 // $ldap->cd ($this->config->current['BASE']);
572 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
574 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
575 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
576 </form></div>";
578 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
580 /* Print footer to have valid html */
581 echo "</body></html>";
583 $this->dispNewFreeze = false;
585 /* Postcreate */
587 /* Assign possible attributes */
588 $this->lock_type = $type;
589 $this->lock_name = $name;
590 $this->lock_dn = $baseToUse;
591 $this->postcreate();
592 exit();
593 }
594 }
596 /****************
597 Display dialog to enter new Branch name
598 ****************/
600 /* Check if we have a post create method configured
601 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
602 */
603 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
604 if(($s_action == "branch_branch")||($this->dispNewBranch)){
605 $this->dispNewBranch=true;
606 $smarty->assign("iframe",false);
607 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
608 return($display);
609 }
610 }
613 /****************
614 Display dialog to enter new Freeze name
615 ****************/
617 /* Check if we have a post create method configured
618 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
619 */
620 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
621 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
622 $this->dispNewFreeze = true;
623 $smarty->assign("iframe",false);
624 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
625 return($display);
626 }
627 }
630 /****************
631 Create a new object
632 ****************/
634 $types = array( "new_partition" => "FAIpartitionTable",
635 "new_script" => "FAIscript",
636 "new_hook" => "FAIhook",
637 "new_variable" => "FAIvariable",
638 "new_template" => "FAItemplate",
639 "new_package" => "FAIpackageList");
641 if(isset($types[$s_action])){
642 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
643 if(preg_match("/c/",$acl)){
644 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
645 }else{
646 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
647 }
648 }
650 /* New Profile */
651 if($s_action == "new_profile"){
652 $this->dn = "new" ;
654 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
655 if(preg_match("/c/",$acl)){
656 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
657 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
658 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
660 $this->is_dialog = false;
661 }else{
662 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
663 }
664 }
667 /****************
668 Get from ask class name dialog
669 ****************/
671 if($s_action == "select_class_name_finished"){
672 $this->dialog->save_object();
673 if(count($this->dialog->check())!=0){
674 foreach($this->dialog->check() as $msg){
675 print_red($msg);
676 }
677 }else{
678 $this->dn = "new" ;
679 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
680 $name = $this->dialog->save();
682 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
683 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
684 $this->dialog->by_object[$a_setup[1]]->cn = $name;
685 $this->is_dialog = true;
686 }
687 }
690 /****************
691 Cancel dialogs
692 ****************/
694 if(isset($_POST['edit_cancel'])){
695 unset($this->dialog);
696 $this->dialog=FALSE;
697 $this->is_dialog = false;
698 unset($_SESSION['objectinfo']);
699 del_lock ($this->dn);
700 }
703 /****************
704 Save sub dialogs
705 ****************/
707 /* This check if the given tab could be saved
708 * If it was possible to save it, remove dialog object.
709 * If it wasn't possible, show errors and keep dialog.
710 */
711 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
712 $this->dialog->save_object();
713 $msgs= $this->dialog->check();
714 if(count($msgs)!=0){
715 foreach($msgs as $msg){
716 print_red($msg);
717 }
718 }else{
719 $this->dialog->save();
720 save_release_changes_now();
721 if (!isset($_POST['edit_apply'])){
722 del_lock ($this->dn);
723 unset($this->dialog);
724 $this->dialog=FALSE;
725 $this->is_dialog=false;
726 unset($_SESSION['objectinfo']);
727 }
728 }
729 }
732 /****************
733 Display currently open dialog
734 ****************/
736 /* If dialog is set, but $this->is_dialog==false, then
737 * only the "abort" button is shown, this are dialogs that must not be saved.
738 * If is_dialog == true, we are currently editing tab objects.
739 * Here we need both, save and cancel
740 */
742 if(is_object($this->dialog)){
743 $display .= $this->dialog->execute();
744 /* Don't show buttons if tab dialog requests this */
746 if(isset($this->dialog->current)){
748 $obj = $this->dialog->by_object[$this->dialog->current];
750 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
752 $display.= "<p style=\"text-align:right\">\n";
753 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
754 $display.= " \n";
755 if ($this->dn != "new"){
756 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
757 $display.= " \n";
758 }
759 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
760 $display.= "</p>";
761 }elseif(!isset($this->dialog->current)){
762 $display.= "<p style=\"text-align:right\">\n";
763 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
764 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
765 $display.= "</p>";
766 }
767 }else{
768 $display.= "<p style=\"text-align:right\">\n";
769 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
770 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
771 $display.= "</p>";
773 }
774 return($display);
775 }
778 /****************
779 Dialog display
780 ****************/
782 /* Check if there is a snapshot dialog open */
783 $base = $this->DivListFai->selectedBase;
784 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
785 return($str);
786 }
788 /* Display dialog with system list */
789 $this->DivListFai->parent = $this;
790 $this->DivListFai->execute();
791 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
792 $this->reload();
793 $this->DivListFai->setEntries($this->objects);
794 return($this->DivListFai->Draw());
795 }
798 /* Return departments, that will be included within snapshot detection */
799 function get_used_snapshot_bases()
800 {
801 $tmp = array();
802 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
803 foreach($types as $type){
804 if($this->DivListFai->selectedBranch == "main"){
805 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
806 }else{
807 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
808 }
809 }
810 return($tmp);
811 }
814 /* Get available branches for current base */
815 function getBranches($base = false,$prefix = "")
816 {
817 $ret = array("main"=>"/");
818 $ldap = $this->config->get_ldap_link();
819 if(!$base){
820 $base= $_SESSION['CurrentMainBase'];
821 }
822 $tmp = get_all_releases_from_base($base,true);
823 foreach($tmp as $dn => $name){
824 $ret[$dn]=$name;
825 }
826 return ($ret);
827 }
830 function list_get_selected_items()
831 {
832 $ids = array();
833 foreach($_POST as $name => $value){
834 if(preg_match("/^item_selected_[0-9]*$/",$name)){
835 $id = preg_replace("/^item_selected_/","",$name);
836 $ids[$id] = $id;
837 }
838 }
839 return($ids);
840 }
843 /* reload list of objects */
844 function reload()
845 {
846 /* Variable initialisation */
847 $str = "";
848 $Regex = $this->DivListFai->Regex;
849 $this->objects = array();
851 /* Get base */
852 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
853 if($this->DivListFai->selectedBranch != "main"){
854 $br = $this->getBranches();
855 if(isset($br[$this->DivListFai->selectedBranch])){
856 $base = $this->DivListFai->selectedBranch;
857 }else{
858 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
859 }
860 }
862 $this->lock_type = get_release_tag(get_release_dn($base));
864 /* Create a new list of FAI object
865 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
866 */
867 $ObjectTypes = array(
868 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
869 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
870 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
871 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
872 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
873 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
874 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
876 $filter = "";
877 foreach($ObjectTypes as $key => $data){
878 if($this->DivListFai->$data['CHKBOX']){
879 $filter.= "(objectClass=".$key.")";
880 }
881 }
882 $filter = "(&(|".$filter.")(cn=$Regex))";
884 /* Get resolved release dependencies */
885 $tmp = get_all_objects_for_given_base($base,$filter);
887 /* Ge listed ldap objects */
888 $ldap = $this->config->get_ldap_link();
889 $ldap->cd($this->config->current['BASE']);
890 foreach($tmp as $entry){
892 /* Get some more informations about the object */
893 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
894 $object = $ldap->fetch();
896 /* Walk through possible types */
897 foreach($ObjectTypes as $type => $rest){
899 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
901 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
903 /* Prepare object */
904 unset($object['objectClass']['count']);
905 if(!isset($object['description'][0])){
906 $object['description'][0]="";
907 }
909 /* Clean up object informations */
910 $obj = array();
911 $obj['cn'] = $object['cn'][0];
912 $obj['dn'] = $object['dn'];
913 $obj['acl'] = $acl;
914 $obj['description'] = $object['description'][0];
915 $obj['objectClass'] = $object['objectClass'];
917 /* Append type to this string, to be able to check if the selected
918 * entry is of type 'freeze' or 'branch'
919 */
920 if(!isset($object['FAIstate'])){
921 $obj['FAIstate'] = $this->lock_type;
922 }else{
923 $obj['FAIstate'] = $object['FAIstate'][0];
924 }
926 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
927 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
928 }
929 }
930 }
932 ksort($this->objects);
933 reset ($this->objects);
935 /* use numeric index, thats a bit more secure */
936 $tmp0 = array();
937 foreach($this->objects as $obj){
938 $tmp0[]= $obj;
939 }
940 $this->objects = array();
941 $this->objects = $tmp0;
942 }
944 function remove_lock()
945 {
946 if (isset($this->dn)){
947 del_lock ($this->dn);
948 }
949 }
951 function get_type($array){
952 if(in_array("FAIpartitionTable",$array['objectClass'])){
953 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
954 }
955 if(in_array("FAIscript",$array['objectClass'])){
956 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
957 }
958 if(in_array("FAItemplate",$array['objectClass'])){
959 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
960 }
961 if(in_array("FAIhook",$array['objectClass'])){
962 return(array("tabsHook","faiHook","FAIHOOKTABS"));
963 }
964 if(in_array("FAIvariable",$array['objectClass'])){
965 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
966 }
967 if(in_array("FAIprofile",$array['objectClass'])){
968 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
969 }
971 if(in_array("FAIpackageList",$array['objectClass'])){
972 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
973 }
974 }
976 function CheckNewBranchName($name,$base)
977 {
978 $f = $this->DivListFai->selectedBranch;
979 if($name == ""){
980 return(false);
981 }elseif(in_array($name,$this->getBranches($f))) {
982 return(false);
983 }elseif(is_department_name_reserved($name,$base)){
984 return(false);
985 }
986 return(true);
987 }
989 function save_object()
990 {
991 $this->DivListFai->save_object();
992 }
995 /* Return plugin informations for acl handling */
996 function plInfo()
997 {
998 return (array(
999 "plShortName" => _("FAI releases"),
1000 "plDescription" => _("FAI release management"),
1001 "plSelfModify" => FALSE,
1002 "plDepends" => array(),
1003 "plPriority" => 0,
1004 "plSection" => array("administration"),
1005 "plCategory" => array("fai"=> array("description" => _("FAI"),
1006 "objectClass" => "FAIclass")),
1007 "plProvidedAcls"=> array()));
1008 }
1009 }
1010 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1011 ?>