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 require "tabsPartition.inc";
22 require "tabsVariable.inc";
23 require "tabsHook.inc";
24 require "tabsTemplate.inc";
25 require "tabsScript.inc";
26 require "tabsProfile.inc";
27 require "tabsPackage.inc";
30 class faiManagement extends plugin
31 {
32 /* Definitions */
33 var $plHeadline = "FAI";
34 var $plDescription = "Fully Automatic Installation - management";
36 /* CLI vars */
37 var $cli_summary = "Handling of FAI entries";
38 var $cli_description = "This plugin represents a management tool\n
39 which allows us to manage all needed attributes for fully automatic installations (FAI)";
40 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
42 /* Headpage attributes */
43 var $lock_type = ""; // should be branch/freeze
44 var $lock_name = "";
45 var $lock_dn = "";
47 /* attribute list for save action */
48 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
49 var $objectclasses= array(); // ObjectClasses which the attributes are related to
50 var $dialog = array(); // This object contains every dialog we have currently opened
52 var $objects = array(); // This array contains all available objects shown in divlist
53 var $is_dialog = false;
55 var $dispNewBranch= false;
56 var $dispNewFreeze= false;
58 var $DivListFai;
60 /* construction/reconstruction
61 */
62 function faiManagement ($config, $ui)
63 {
64 /* Set defaults */
65 $this->dn = "";
66 $this->config = $config;
67 $this->ui = $ui;
69 /* Creat dialog object */
70 $this->DivListFai = new divListFai($this->config,$this);
71 }
73 function execute()
74 {
75 /* Call parent execute */
76 plugin::execute();
78 /* Initialise vars and smarty */
79 $smarty = get_smarty();
80 $smarty->assign("BranchName","");
82 $display = "";
83 $s_action = "";
84 $s_entry = "";
86 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
87 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
90 /****************
91 Handle posts
92 ****************/
94 /* Check ImageButton posts
95 * Create new tab ich new_xx is posted
96 */
97 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
98 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
99 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
100 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
101 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
102 "/edit_continue/"=>"select_class_name_finished",
104 "/^remove_multiple_fai_objects/" => "del_multiple");
106 foreach($_POST as $name => $value){
107 foreach($posts as $reg => $act ){
108 if(preg_match($reg,$name)){
109 $s_action = $act;
110 }
111 }
112 if(preg_match("/^entry_edit_.*/",$name)){
113 $s_entry = preg_replace("/^entry_edit_/","",$name);
114 $s_entry = preg_replace("/_.*$/","",$s_entry);
115 $s_action = "edit";
116 }elseif(preg_match("/^entry_delete_.*/",$name)){
117 $s_entry = preg_replace("/^entry_delete_/","",$name);
118 $s_entry = preg_replace("/_.*$/","",$s_entry);
119 $s_action = "delete";
120 }
121 }
123 if(isset($_GET['edit_entry'])){
124 $s_entry = $_GET['edit_entry'];
125 $s_action = "edit";
126 }
128 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
129 $this->dispNewBranch = false;
130 $this->dispNewFreeze = false;
131 }
134 $type_acl_mapping = array(
135 "FAIpartitionTable" => "faiPartitionTable",
136 "FAIpackageList" => "faiPackage",
137 "FAIscript" => "faiScript",
138 "FAIvariable" => "faiVariable",
139 "FAIhook" => "faiHook",
140 "FAIprofile" => "faiProfile",
141 "FAItemplate" => "faiTemplate");
143 /****************
144 Delete confirme dialog
145 ****************/
147 if ($s_action=="delete"){
149 /* Get 'dn' from posted termlinst */
150 $this->dn= $this->objects[$s_entry]['dn'];
152 /* Load permissions for selected 'dn' and check if
153 we're allowed to remove this 'dn' */
154 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
155 if(preg_match("/d/",$acl)){
157 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
158 if (($user= get_lock($this->dn)) != ""){
159 return(gen_locked_message ($user, $this->dn));
160 }
162 /* Lock the current entry, so nobody will edit it during deletion */
163 add_lock ($this->dn, $this->ui->dn);
164 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
165 $smarty->assign("multiple", false);
166 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
167 } else {
169 /* Obviously the user isn't allowed to delete. Show message and
170 clean session. */
171 print_red (_("You are not allowed to delete this component!"));
172 }
173 }
176 /********************
177 Delete MULTIPLE entries requested, display confirm dialog
178 ********************/
180 if ($s_action=="del_multiple"){
181 $this->dns = array();
182 $ids = $this->list_get_selected_items();
184 if(count($ids)){
186 foreach($ids as $id){
187 $dn = $this->objects[$id]['dn'];
188 if (($user= get_lock($dn)) != ""){
189 return(gen_locked_message ($user, $dn));
190 }
191 $this->dns[$id] = $dn;
192 }
194 $dns_names = "<br><pre>";
195 foreach($this->dns as $dn){
196 add_lock ($dn, $this->ui->dn);
197 $dns_names .= $dn."\n";
198 }
199 $dns_names .="</pre>";
201 /* Lock the current entry, so nobody will edit it during deletion */
202 if (count($this->dns) == 1){
203 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
204 } else {
205 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
206 }
207 $smarty->assign("multiple", true);
208 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
209 }
210 }
213 /********************
214 Delete MULTIPLE entries confirmed
215 ********************/
217 /* Confirmation for deletion has been passed. Users should be deleted. */
218 if (isset($_POST['delete_multiple_fai_object_confirm'])){
220 /* Find out more about the object type */
221 $ldap = $this->config->get_ldap_link();
223 /* Remove user by user and check acls before removeing them */
224 foreach($this->dns as $key => $dn){
226 $ldap->cat($dn, array('objectClass'));
227 $attrs = $ldap->fetch();
228 $type = $this->get_type($attrs);
230 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
231 if(preg_match("/d/",$acl)){
233 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
234 $this->dialog->set_acl_base($dn);
235 $this->dialog->by_object[$type[1]]->remove_from_parent ();
236 unset ($this->dialog);
237 gosa_log ("FAI class '".$dn."' has been tagged as removed");
238 $this->dialog= NULL;
239 $to_del = clean_up_releases($dn);
240 save_release_changes_now();
242 foreach($to_del as $dn){
243 $ldap->rmdir_recursive($dn);
244 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
245 }
247 } else {
249 /* Normally this shouldn't be reached, send some extra
250 logs to notify the administrator */
251 print_red (_("You are not allowed to delete this component!"));
252 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
253 "deletion.");
254 }
256 /* Remove lock file after successfull deletion */
257 del_lock ($dn);
258 unset($this->dns[$key]);
259 }
260 }
263 /********************
264 Delete MULTIPLE entries Canceled
265 ********************/
267 /* Remove lock */
268 if(isset($_POST['delete_multiple_fai_object_cancel'])){
269 foreach($this->dns as $key => $dn){
270 del_lock ($dn);
271 unset($this->dns[$key]);
272 }
273 }
276 /****************
277 Delete aborted
278 ****************/
280 /* Delete canceled? */
281 if (isset($_POST['delete_cancel'])){
282 del_lock ($this->dn);
283 }
286 /****************
287 Delete confirmed
288 ****************/
290 /* Deltetion was confirmed, so delete this entry
291 */
292 if (isset($_POST['delete_terminal_confirm'])){
294 /* Some nice guy may send this as POST, so we've to check
295 for the permissions again. */
297 /* Find out more about the object type */
298 $ldap = $this->config->get_ldap_link();
299 $ldap->cat($this->dn, array('objectClass'));
300 $attrs = $ldap->fetch();
301 $type = $this->get_type($attrs);
303 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
304 if(preg_match("/d/",$acl)){
306 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
307 $this->dialog->set_acl_base($this->dn);
308 $this->dialog->by_object[$type[1]]->remove_from_parent ();
309 unset ($this->dialog);
310 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
311 $this->dialog= NULL;
312 $to_del = clean_up_releases($this->dn);
313 save_release_changes_now();
315 foreach($to_del as $dn){
316 $ldap->rmdir_recursive($dn);
317 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
318 }
320 } else {
322 /* Normally this shouldn't be reached, send some extra
323 logs to notify the administrator */
324 print_red (_("You are not allowed to delete this component!"));
325 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
326 "deletion.");
327 }
329 /* Remove lock file after successfull deletion */
330 del_lock ($this->dn);
331 }
334 /****************
335 Edit entry
336 ****************/
338 if(($s_action == "edit") && (!isset($this->dialog->config))){
339 $entry = $this->objects[$s_entry];
340 $a_setup = $this->get_type($entry);
341 $this->dn = $entry['dn'];
343 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
344 if (($user= get_lock($this->dn)) != ""){
345 return(gen_locked_message ($user, $this->dn));
346 }
347 add_lock ($this->dn, $this->ui->dn);
349 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
350 $this->dialog->set_acl_base($this->dn);
351 $this->is_dialog = true;
353 if($entry['FAIstate'] == "freeze"){
354 #$this->dialog->set_acl(array("*none*")) ;
355 echo "Dawn it is freezed.";
356 }
357 $_SESSION['objectinfo'] = $this->dn;
358 }
361 /* Branch handling
362 09.01.2006
363 */
365 /****************
366 Remove branch
367 ****************/
369 /* Remove branch
370 */
371 if($s_action == "remove_branch"){
372 $base= $this->DivListFai->selectedBranch;
374 /* Load permissions for selected 'dn' and check if
375 we're allowed to remove this 'dn' */
376 $this->set_acl_base($base);
377 if($this->acl_is_removeable()){
379 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
380 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
381 } else {
382 print_red (_("You are not allowed to delete this release!"));
383 }
384 }
387 /****************
388 Remove branch confirmed
389 ****************/
391 if(isset($_POST['delete_branch_confirm'])){
392 $bb = $this->DivListFai->selectedBranch;
393 if(!isset($ldap)){
394 $ldap = $this->config->get_ldap_link();
395 }
397 $br = $this->getBranches();
399 if(isset($br[$bb]) && $this->acl_is_removeable()){
400 $name = $br[$bb];
401 $ldap->cd($bb);
402 $ldap->recursive_remove();
403 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
404 $ldap->recursive_remove();
405 $this->DivListFai->selectedBranch = "main";
407 /* Post remove */
408 $this->lock_name = $name;
409 $this->lock_dn = $bb;
410 $this->postremove();
411 }
412 }
415 /****************
416 Create a new branch "insert Name"
417 ****************/
419 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
420 $_SESSION['LASTPOST'] = $_POST;
422 if($this->dispNewBranch){
423 $type = "branch";
424 }else{
425 $type = "freeze";
426 }
428 /* Check branch name */
429 $name = $_POST['BranchName'];
430 $is_ok = true;
431 $smarty->assign("BranchName",$name);
432 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
434 /* Check used characters */
435 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
436 if($type == "branch"){
437 print_red(_("Specified branch name is invalid."));
438 }else{
439 print_red(_("Specified freeze name is invalid."));
440 }
441 $is_ok = false;
442 }
444 /* Check if this name is already in use */
445 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
446 print_red(_("This name is already in use."));
447 $is_ok = false;
448 }
450 if($is_ok){
451 $_SESSION['LASTPOST']['base'] = $base;
452 $_SESSION['LASTPOST']['type'] = $type;
453 $smarty->assign("iframe", true);
454 $smarty->assign("plugID", $_GET['plug']);
455 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
456 return($display);
457 }
458 }
461 /****************
462 Create a new branch
463 ****************/
465 if(isset($_GET['PerformBranch'])){
467 if(!$this->acl_is_createable()){
468 print_red(_("You are not allowed to create a new branch."));
469 }else{
471 /* Create it know */
472 $this->dispNewBranch = false;
473 $this->dispNewFreeze = false;
474 $base = $_SESSION['LASTPOST']['base'];
475 $_POST = $_SESSION['LASTPOST'];
476 $name = $_POST['BranchName'];
478 $type = $_SESSION['LASTPOST']['type'];
479 $ldap = $this->config->get_ldap_link();
481 $baseToUse = $base;
482 if($this->DivListFai->selectedBranch != "main" ){
483 $baseToUse = $this->DivListFai->selectedBranch;
484 }
486 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
488 $CurrentReleases = $this->getBranches();
489 $NewReleaseName = $name;
490 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
491 if($this->DivListFai->selectedBranch != "main"){
492 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
493 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
494 }else{
495 $NewReleaseName = $name;
496 }
497 }
499 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
500 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
502 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
503 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
505 /* Print header to have styles included */
506 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
507 <html>
508 <head>
509 <title></title>
510 <style type="text/css">@import url("themes/default/style.css");</style>
511 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
512 </head>
513 <body style="background: none;margin:3px;color:black">
514 ';
517 /* Duplicate applications
518 */
519 $ldap->cat($appsrc,array("dn")) ;
520 if($ldap->count()){
521 $ldap->cd ($appdst);
522 $ldap->recursive_remove();
523 $ldap->cd ($this->config->current['BASE']);
524 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
525 }
527 /* Duplicate mime types
528 */
529 $ldap->cat($mimesrc,array("dn")) ;
530 if($ldap->count()){
531 $ldap->cd ($appdst);
532 $ldap->recursive_remove();
533 $ldap->cd ($this->config->current['BASE']);
534 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
535 }
537 $attr = array();
538 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
539 $attr['ou'] = $name;
540 $attr['FAIstate'] = $type;
541 $ldap->cd($this->config->current['BASE']);
542 $ldap->cd("ou=".$name.",".$baseToUse);
543 $ldap->cat("ou=".$name.",".$baseToUse);
544 if($ldap->count()){
545 $ldap->modify($attr);
546 }else{
547 $ldap->add($attr);
548 }
550 /* Duplicate fai objects
551 */
552 // $ldap->cd ("ou=".$name.",".$baseToUse);
553 // $ldap->recursive_remove();
554 // $ldap->cd ($this->config->current['BASE']);
555 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
557 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
558 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
559 </form></div>";
561 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
563 /* Print footer to have valid html */
564 echo "</body></html>";
566 $this->dispNewFreeze = false;
568 /* Postcreate */
570 /* Assign possible attributes */
571 $this->lock_type = $type;
572 $this->lock_name = $name;
573 $this->lock_dn = $baseToUse;
574 $this->postcreate();
575 exit();
576 }
577 }
579 /****************
580 Display dialog to enter new Branch name
581 ****************/
583 if(($s_action == "branch_branch")||($this->dispNewBranch)){
584 $this->dispNewBranch=true;
585 $smarty->assign("iframe",false);
586 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
587 return($display);
588 }
591 /****************
592 Display dialog to enter new Freeze name
593 ****************/
595 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
596 $this->dispNewFreeze = true;
597 $smarty->assign("iframe",false);
598 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
599 return($display);
600 }
603 /****************
604 Create a new object
605 ****************/
607 $types = array( "new_partition" => "FAIpartitionTable",
608 "new_script" => "FAIscript",
609 "new_hook" => "FAIhook",
610 "new_variable" => "FAIvariable",
611 "new_template" => "FAItemplate",
612 "new_package" => "FAIpackageList");
614 if(isset($types[$s_action])){
615 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
616 if(preg_match("/c/",$acl)){
617 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
618 }else{
619 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
620 }
621 }
623 /* New Profile */
624 if($s_action == "new_profile"){
625 $this->dn = "new" ;
627 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
628 if(preg_match("/c/",$acl)){
629 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
630 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
631 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
633 $this->is_dialog = false;
634 }else{
635 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
636 }
637 }
640 /****************
641 Get from ask class name dialog
642 ****************/
644 if($s_action == "select_class_name_finished"){
645 $this->dialog->save_object();
646 if(count($this->dialog->check())!=0){
647 foreach($this->dialog->check() as $msg){
648 print_red($msg);
649 }
650 }else{
651 $this->dn = "new" ;
652 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
653 $name = $this->dialog->save();
655 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
656 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
657 $this->dialog->by_object[$a_setup[1]]->cn = $name;
658 $this->is_dialog = true;
659 }
660 }
663 /****************
664 Cancel dialogs
665 ****************/
667 if(isset($_POST['edit_cancel'])){
668 unset($this->dialog);
669 $this->dialog=NULL;
670 $this->is_dialog = false;
671 unset($_SESSION['objectinfo']);
672 del_lock ($this->dn);
673 }
676 /****************
677 Save sub dialogs
678 ****************/
680 /* This check if the given tab could be saved
681 * If it was possible to save it, remove dialog object.
682 * If it wasn't possible, show errors and keep dialog.
683 */
684 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
685 $this->dialog->save_object();
686 $msgs= $this->dialog->check();
687 if(count($msgs)!=0){
688 foreach($msgs as $msg){
689 print_red($msg);
690 }
691 }else{
692 $this->dialog->save();
693 save_release_changes_now();
694 if (!isset($_POST['edit_apply'])){
695 del_lock ($this->dn);
696 unset($this->dialog);
697 $this->dialog=NULL;
698 $this->is_dialog=false;
699 unset($_SESSION['objectinfo']);
700 }
701 }
702 }
705 /****************
706 Display currently open dialog
707 ****************/
709 /* If dialog is set, but $this->is_dialog==false, then
710 * only the "abort" button is shown, this are dialogs that must not be saved.
711 * If is_dialog == true, we are currently editing tab objects.
712 * Here we need both, save and cancel
713 */
715 if(($this->dialog != NULL) && (isset($this->dialog->config))){
716 $display .= $this->dialog->execute();
717 /* Don't show buttons if tab dialog requests this */
719 if(isset($this->dialog->current)){
721 $obj = $this->dialog->by_object[$this->dialog->current];
723 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
725 $display.= "<p style=\"text-align:right\">\n";
726 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
727 $display.= " \n";
728 if ($this->dn != "new"){
729 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
730 $display.= " \n";
731 }
732 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
733 $display.= "</p>";
734 }elseif(!isset($this->dialog->current)){
735 $display.= "<p style=\"text-align:right\">\n";
736 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
737 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
738 $display.= "</p>";
739 }
740 }else{
741 $display.= "<p style=\"text-align:right\">\n";
742 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
743 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
744 $display.= "</p>";
746 }
747 return($display);
748 }
751 /****************
752 Dialog display
753 ****************/
755 /* Check if there is a snapshot dialog open */
756 $base = $this->DivListFai->selectedBase;
757 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
758 return($str);
759 }
761 /* Display dialog with system list */
762 $this->DivListFai->parent = $this;
763 $this->DivListFai->execute();
764 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
765 $this->reload();
766 $this->DivListFai->setEntries($this->objects);
767 return($this->DivListFai->Draw());
768 }
771 /* Return departments, that will be included within snapshot detection */
772 function get_used_snapshot_bases()
773 {
774 $tmp = array();
775 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
776 foreach($types as $type){
777 if($this->DivListFai->selectedBranch == "main"){
778 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
779 }else{
780 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
781 }
782 }
783 return($tmp);
784 }
787 /* Get available branches for current base */
788 function getBranches($base = false,$prefix = "")
789 {
790 $ret = array("main"=>"/");
791 $ldap = $this->config->get_ldap_link();
792 if(!$base){
793 $base= $_SESSION['CurrentMainBase'];
794 }
795 $tmp = get_all_releases_from_base($base,true);
796 foreach($tmp as $dn => $name){
797 $ret[$dn]=$name;
798 }
799 return ($ret);
800 }
803 function list_get_selected_items()
804 {
805 $ids = array();
806 foreach($_POST as $name => $value){
807 if(preg_match("/^item_selected_[0-9]*$/",$name)){
808 $id = preg_replace("/^item_selected_/","",$name);
809 $ids[$id] = $id;
810 }
811 }
812 return($ids);
813 }
816 /* reload list of objects */
817 function reload()
818 {
819 /* Variable initialisation */
820 $str = "";
821 $Regex = $this->DivListFai->Regex;
822 $this->objects = array();
824 /* Get base */
825 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
826 if($this->DivListFai->selectedBranch != "main"){
827 $br = $this->getBranches();
828 if(isset($br[$this->DivListFai->selectedBranch])){
829 $base = $this->DivListFai->selectedBranch;
830 }else{
831 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
832 }
833 }
835 $this->lock_type = get_release_tag(get_release_dn($base));
837 /* Create a new list of FAI object
838 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
839 */
840 $ObjectTypes = array(
841 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
842 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
843 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
844 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
845 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
846 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
847 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
849 $filter = "";
850 foreach($ObjectTypes as $key => $data){
851 if($this->DivListFai->$data['CHKBOX']){
852 $filter.= "(objectClass=".$key.")";
853 }
854 }
855 $filter = "(&(|".$filter.")(cn=$Regex))";
857 /* Get resolved release dependencies */
858 $tmp = get_all_objects_for_given_base($base,$filter);
860 /* Ge listed ldap objects */
861 $ldap = $this->config->get_ldap_link();
862 $ldap->cd($this->config->current['BASE']);
863 foreach($tmp as $entry){
865 /* Get some more informations about the object */
866 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
867 $object = $ldap->fetch();
869 /* Walk through possible types */
870 foreach($ObjectTypes as $type => $rest){
872 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
874 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
876 /* Prepare object */
877 unset($object['objectClass']['count']);
878 if(!isset($object['description'][0])){
879 $object['description'][0]="";
880 }
882 /* Clean up object informations */
883 $obj = array();
884 $obj['cn'] = $object['cn'][0];
885 $obj['dn'] = $object['dn'];
886 $obj['acl'] = $acl;
887 $obj['description'] = $object['description'][0];
888 $obj['objectClass'] = $object['objectClass'];
890 /* Append type to this string, to be able to check if the selected
891 * entry is of type 'freeze' or 'branch'
892 */
893 if(!isset($object['FAIstate'])){
894 $obj['FAIstate'] = $this->lock_type;
895 }else{
896 $obj['FAIstate'] = $object['FAIstate'][0];
897 }
899 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
900 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
901 }
902 }
903 }
905 ksort($this->objects);
906 reset ($this->objects);
908 /* use numeric index, thats a bit more secure */
909 $tmp0 = array();
910 foreach($this->objects as $obj){
911 $tmp0[]= $obj;
912 }
913 $this->objects = array();
914 $this->objects = $tmp0;
915 }
917 function remove_lock()
918 {
919 if (isset($this->dn)){
920 del_lock ($this->dn);
921 }
922 }
924 function get_type($array){
925 if(in_array("FAIpartitionTable",$array['objectClass'])){
926 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
927 }
928 if(in_array("FAIscript",$array['objectClass'])){
929 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
930 }
931 if(in_array("FAItemplate",$array['objectClass'])){
932 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
933 }
934 if(in_array("FAIhook",$array['objectClass'])){
935 return(array("tabsHook","faiHook","FAIHOOKTABS"));
936 }
937 if(in_array("FAIvariable",$array['objectClass'])){
938 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
939 }
940 if(in_array("FAIprofile",$array['objectClass'])){
941 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
942 }
944 if(in_array("FAIpackageList",$array['objectClass'])){
945 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
946 }
947 }
949 function CheckNewBranchName($name,$base)
950 {
951 $f = $this->DivListFai->selectedBranch;
952 if($name == ""){
953 return(false);
954 }elseif(in_array($name,$this->getBranches($f))) {
955 return(false);
956 }elseif(is_department_name_reserved($name,$base)){
957 return(false);
958 }
959 return(true);
960 }
962 function save_object()
963 {
964 $this->DivListFai->save_object();
965 }
968 /* Return plugin informations for acl handling */
969 function plInfo()
970 {
971 return (array(
972 "plShortName" => _("FAI releases"),
973 "plDescription" => _("FAI release management"),
974 "plSelfModify" => FALSE,
975 "plDepends" => array(),
976 "plPriority" => 0,
977 "plSection" => array("administration"),
978 "plCategory" => array("fai"=> array("description" => _("FAI"),
979 "objectClass" => "FAIclass")),
980 "plProvidedAcls"=> array()));
981 }
982 }
983 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
984 ?>