8ea8a9028031d8c8ea516aef59c911022434de00
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= NULL;
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= NULL;
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("" != search_config($this->config->data,"faiManagement","POSTREMOVE")){
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("" != search_config($this->config->data,"faiManagement","POSTREMOVE")){
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 /* Print header to have styles included */
513 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
514 <html>
515 <head>
516 <title></title>
517 <style type="text/css">@import url("themes/default/style.css");</style>
518 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
519 </head>
520 <body style="background: none;margin:3px;color:black">
521 ';
523 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
525 /* Duplicate applications
526 */
527 $ldap->cat($appsrc,array("dn")) ;
528 if($ldap->count()){
529 $ldap->cd ($appdst);
530 $ldap->recursive_remove();
531 $ldap->cd ($this->config->current['BASE']);
532 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
533 }
535 /* Duplicate mime types
536 */
537 $ldap->cat($mimesrc,array("dn")) ;
538 if($ldap->count()){
539 $ldap->cd ($mimedst);
540 $ldap->recursive_remove();
541 $ldap->cd ($this->config->current['BASE']);
542 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
543 }
545 $attr = array();
546 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
547 $attr['ou'] = $name;
548 $attr['FAIstate'] = $type;
549 $ldap->cd($this->config->current['BASE']);
550 $ldap->cd("ou=".$name.",".$baseToUse);
551 $ldap->cat("ou=".$name.",".$baseToUse);
552 if($ldap->count()){
553 $ldap->modify($attr);
554 }else{
555 $ldap->add($attr);
556 }
558 /* Duplicate fai objects
559 */
560 // $ldap->cd ("ou=".$name.",".$baseToUse);
561 // $ldap->recursive_remove();
562 // $ldap->cd ($this->config->current['BASE']);
563 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
565 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
566 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
567 </form></div>";
569 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
571 /* Print footer to have valid html */
572 echo "</body></html>";
574 $this->dispNewFreeze = false;
576 /* Postcreate */
578 /* Assign possible attributes */
579 $this->lock_type = $type;
580 $this->lock_name = $name;
581 $this->lock_dn = $baseToUse;
582 $this->postcreate();
583 exit();
584 }
585 }
587 /****************
588 Display dialog to enter new Branch name
589 ****************/
591 /* Check if we have a post create method configured
592 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
593 */
594 if("" != search_config($this->config->data,"faiManagement","POSTCREATE")){
595 if(($s_action == "branch_branch")||($this->dispNewBranch)){
596 $this->dispNewBranch=true;
597 $smarty->assign("iframe",false);
598 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
599 return($display);
600 }
601 }
604 /****************
605 Display dialog to enter new Freeze name
606 ****************/
608 /* Check if we have a post create method configured
609 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
610 */
611 if("" != search_config($this->config->data,"faiManagement","POSTCREATE")){
612 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
613 $this->dispNewFreeze = true;
614 $smarty->assign("iframe",false);
615 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
616 return($display);
617 }
618 }
621 /****************
622 Create a new object
623 ****************/
625 $types = array( "new_partition" => "FAIpartitionTable",
626 "new_script" => "FAIscript",
627 "new_hook" => "FAIhook",
628 "new_variable" => "FAIvariable",
629 "new_template" => "FAItemplate",
630 "new_package" => "FAIpackageList");
632 if(isset($types[$s_action])){
633 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
634 if(preg_match("/c/",$acl)){
635 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
636 }else{
637 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
638 }
639 }
641 /* New Profile */
642 if($s_action == "new_profile"){
643 $this->dn = "new" ;
645 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
646 if(preg_match("/c/",$acl)){
647 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
648 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
649 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
651 $this->is_dialog = false;
652 }else{
653 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
654 }
655 }
658 /****************
659 Get from ask class name dialog
660 ****************/
662 if($s_action == "select_class_name_finished"){
663 $this->dialog->save_object();
664 if(count($this->dialog->check())!=0){
665 foreach($this->dialog->check() as $msg){
666 print_red($msg);
667 }
668 }else{
669 $this->dn = "new" ;
670 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
671 $name = $this->dialog->save();
673 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
674 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
675 $this->dialog->by_object[$a_setup[1]]->cn = $name;
676 $this->is_dialog = true;
677 }
678 }
681 /****************
682 Cancel dialogs
683 ****************/
685 if(isset($_POST['edit_cancel'])){
686 unset($this->dialog);
687 $this->dialog=NULL;
688 $this->is_dialog = false;
689 unset($_SESSION['objectinfo']);
690 del_lock ($this->dn);
691 }
694 /****************
695 Save sub dialogs
696 ****************/
698 /* This check if the given tab could be saved
699 * If it was possible to save it, remove dialog object.
700 * If it wasn't possible, show errors and keep dialog.
701 */
702 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
703 $this->dialog->save_object();
704 $msgs= $this->dialog->check();
705 if(count($msgs)!=0){
706 foreach($msgs as $msg){
707 print_red($msg);
708 }
709 }else{
710 $this->dialog->save();
711 save_release_changes_now();
712 if (!isset($_POST['edit_apply'])){
713 del_lock ($this->dn);
714 unset($this->dialog);
715 $this->dialog=NULL;
716 $this->is_dialog=false;
717 unset($_SESSION['objectinfo']);
718 }
719 }
720 }
723 /****************
724 Display currently open dialog
725 ****************/
727 /* If dialog is set, but $this->is_dialog==false, then
728 * only the "abort" button is shown, this are dialogs that must not be saved.
729 * If is_dialog == true, we are currently editing tab objects.
730 * Here we need both, save and cancel
731 */
733 if(($this->dialog != NULL) && (isset($this->dialog->config))){
734 $display .= $this->dialog->execute();
735 /* Don't show buttons if tab dialog requests this */
737 if(isset($this->dialog->current)){
739 $obj = $this->dialog->by_object[$this->dialog->current];
741 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
743 $display.= "<p style=\"text-align:right\">\n";
744 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
745 $display.= " \n";
746 if ($this->dn != "new"){
747 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
748 $display.= " \n";
749 }
750 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
751 $display.= "</p>";
752 }elseif(!isset($this->dialog->current)){
753 $display.= "<p style=\"text-align:right\">\n";
754 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
755 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
756 $display.= "</p>";
757 }
758 }else{
759 $display.= "<p style=\"text-align:right\">\n";
760 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
761 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
762 $display.= "</p>";
764 }
765 return($display);
766 }
769 /****************
770 Dialog display
771 ****************/
773 /* Check if there is a snapshot dialog open */
774 $base = $this->DivListFai->selectedBase;
775 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
776 return($str);
777 }
779 /* Display dialog with system list */
780 $this->DivListFai->parent = $this;
781 $this->DivListFai->execute();
782 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
783 $this->reload();
784 $this->DivListFai->setEntries($this->objects);
785 return($this->DivListFai->Draw());
786 }
789 /* Return departments, that will be included within snapshot detection */
790 function get_used_snapshot_bases()
791 {
792 $tmp = array();
793 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
794 foreach($types as $type){
795 if($this->DivListFai->selectedBranch == "main"){
796 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
797 }else{
798 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
799 }
800 }
801 return($tmp);
802 }
805 /* Get available branches for current base */
806 function getBranches($base = false,$prefix = "")
807 {
808 $ret = array("main"=>"/");
809 $ldap = $this->config->get_ldap_link();
810 if(!$base){
811 $base= $_SESSION['CurrentMainBase'];
812 }
813 $tmp = get_all_releases_from_base($base,true);
814 foreach($tmp as $dn => $name){
815 $ret[$dn]=$name;
816 }
817 return ($ret);
818 }
821 function list_get_selected_items()
822 {
823 $ids = array();
824 foreach($_POST as $name => $value){
825 if(preg_match("/^item_selected_[0-9]*$/",$name)){
826 $id = preg_replace("/^item_selected_/","",$name);
827 $ids[$id] = $id;
828 }
829 }
830 return($ids);
831 }
834 /* reload list of objects */
835 function reload()
836 {
837 /* Variable initialisation */
838 $str = "";
839 $Regex = $this->DivListFai->Regex;
840 $this->objects = array();
842 /* Get base */
843 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
844 if($this->DivListFai->selectedBranch != "main"){
845 $br = $this->getBranches();
846 if(isset($br[$this->DivListFai->selectedBranch])){
847 $base = $this->DivListFai->selectedBranch;
848 }else{
849 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
850 }
851 }
853 $this->lock_type = get_release_tag(get_release_dn($base));
855 /* Create a new list of FAI object
856 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
857 */
858 $ObjectTypes = array(
859 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
860 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
861 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
862 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
863 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
864 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
865 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
867 $filter = "";
868 foreach($ObjectTypes as $key => $data){
869 if($this->DivListFai->$data['CHKBOX']){
870 $filter.= "(objectClass=".$key.")";
871 }
872 }
873 $filter = "(&(|".$filter.")(cn=$Regex))";
875 /* Get resolved release dependencies */
876 $tmp = get_all_objects_for_given_base($base,$filter);
878 /* Ge listed ldap objects */
879 $ldap = $this->config->get_ldap_link();
880 $ldap->cd($this->config->current['BASE']);
881 foreach($tmp as $entry){
883 /* Get some more informations about the object */
884 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
885 $object = $ldap->fetch();
887 /* Walk through possible types */
888 foreach($ObjectTypes as $type => $rest){
890 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
892 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
894 /* Prepare object */
895 unset($object['objectClass']['count']);
896 if(!isset($object['description'][0])){
897 $object['description'][0]="";
898 }
900 /* Clean up object informations */
901 $obj = array();
902 $obj['cn'] = $object['cn'][0];
903 $obj['dn'] = $object['dn'];
904 $obj['acl'] = $acl;
905 $obj['description'] = $object['description'][0];
906 $obj['objectClass'] = $object['objectClass'];
908 /* Append type to this string, to be able to check if the selected
909 * entry is of type 'freeze' or 'branch'
910 */
911 if(!isset($object['FAIstate'])){
912 $obj['FAIstate'] = $this->lock_type;
913 }else{
914 $obj['FAIstate'] = $object['FAIstate'][0];
915 }
917 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
918 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
919 }
920 }
921 }
923 ksort($this->objects);
924 reset ($this->objects);
926 /* use numeric index, thats a bit more secure */
927 $tmp0 = array();
928 foreach($this->objects as $obj){
929 $tmp0[]= $obj;
930 }
931 $this->objects = array();
932 $this->objects = $tmp0;
933 }
935 function remove_lock()
936 {
937 if (isset($this->dn)){
938 del_lock ($this->dn);
939 }
940 }
942 function get_type($array){
943 if(in_array("FAIpartitionTable",$array['objectClass'])){
944 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
945 }
946 if(in_array("FAIscript",$array['objectClass'])){
947 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
948 }
949 if(in_array("FAItemplate",$array['objectClass'])){
950 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
951 }
952 if(in_array("FAIhook",$array['objectClass'])){
953 return(array("tabsHook","faiHook","FAIHOOKTABS"));
954 }
955 if(in_array("FAIvariable",$array['objectClass'])){
956 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
957 }
958 if(in_array("FAIprofile",$array['objectClass'])){
959 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
960 }
962 if(in_array("FAIpackageList",$array['objectClass'])){
963 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
964 }
965 }
967 function CheckNewBranchName($name,$base)
968 {
969 $f = $this->DivListFai->selectedBranch;
970 if($name == ""){
971 return(false);
972 }elseif(in_array($name,$this->getBranches($f))) {
973 return(false);
974 }elseif(is_department_name_reserved($name,$base)){
975 return(false);
976 }
977 return(true);
978 }
980 function save_object()
981 {
982 $this->DivListFai->save_object();
983 }
986 /* Return plugin informations for acl handling */
987 function plInfo()
988 {
989 return (array(
990 "plShortName" => _("FAI releases"),
991 "plDescription" => _("FAI release management"),
992 "plSelfModify" => FALSE,
993 "plDepends" => array(),
994 "plPriority" => 0,
995 "plSection" => array("administration"),
996 "plCategory" => array("fai"=> array("description" => _("FAI"),
997 "objectClass" => "FAIclass")),
998 "plProvidedAcls"=> array()));
999 }
1000 }
1001 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1002 ?>