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 if($ldap->count()){
301 $attrs = $ldap->fetch();
302 $type = $this->get_type($attrs);
304 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
305 if(preg_match("/d/",$acl)){
307 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
308 $this->dialog->set_acl_base($this->dn);
309 $this->dialog->by_object[$type[1]]->remove_from_parent ();
310 unset ($this->dialog);
311 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
312 $this->dialog= NULL;
313 $to_del = clean_up_releases($this->dn);
314 save_release_changes_now();
316 foreach($to_del as $dn){
317 $ldap->rmdir_recursive($dn);
318 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
319 }
321 } else {
323 /* Normally this shouldn't be reached, send some extra
324 logs to notify the administrator */
325 print_red (_("You are not allowed to delete this component!"));
326 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
327 "deletion.");
328 }
330 }else{
331 print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
332 }
333 /* Remove lock file after successfull deletion */
334 del_lock ($this->dn);
335 }
338 /****************
339 Edit entry
340 ****************/
342 if(($s_action == "edit") && (!isset($this->dialog->config))){
343 $entry = $this->objects[$s_entry];
344 $a_setup = $this->get_type($entry);
345 $this->dn = $entry['dn'];
347 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
348 if (($user= get_lock($this->dn)) != ""){
349 return(gen_locked_message ($user, $this->dn));
350 }
351 add_lock ($this->dn, $this->ui->dn);
353 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
354 $this->dialog->set_acl_base($this->dn);
355 $this->is_dialog = true;
357 if($entry['FAIstate'] == "freeze"){
358 #$this->dialog->set_acl(array("*none*")) ;
359 echo "Dawn it is freezed.";
360 }
361 $_SESSION['objectinfo'] = $this->dn;
362 }
365 /* Branch handling
366 09.01.2006
367 */
369 /****************
370 Remove branch
371 ****************/
373 /* Remove branch
374 */
375 if($s_action == "remove_branch"){
376 $base= $this->DivListFai->selectedBranch;
378 /* Load permissions for selected 'dn' and check if
379 we're allowed to remove this 'dn' */
380 $this->set_acl_base($base);
381 if($this->acl_is_removeable()){
383 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
384 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
385 } else {
386 print_red (_("You are not allowed to delete this release!"));
387 }
388 }
391 /****************
392 Remove branch confirmed
393 ****************/
395 if(isset($_POST['delete_branch_confirm'])){
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();
415 }
416 }
419 /****************
420 Create a new branch "insert Name"
421 ****************/
423 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
424 $_SESSION['LASTPOST'] = $_POST;
426 if($this->dispNewBranch){
427 $type = "branch";
428 }else{
429 $type = "freeze";
430 }
432 /* Check branch name */
433 $name = $_POST['BranchName'];
434 $is_ok = true;
435 $smarty->assign("BranchName",$name);
436 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
438 /* Check used characters */
439 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
440 if($type == "branch"){
441 print_red(_("Specified branch name is invalid."));
442 }else{
443 print_red(_("Specified freeze name is invalid."));
444 }
445 $is_ok = false;
446 }
448 /* Check if this name is already in use */
449 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
450 print_red(_("This name is already in use."));
451 $is_ok = false;
452 }
454 if($is_ok){
455 $_SESSION['LASTPOST']['base'] = $base;
456 $_SESSION['LASTPOST']['type'] = $type;
457 $smarty->assign("iframe", true);
458 $smarty->assign("plugID", $_GET['plug']);
459 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
460 return($display);
461 }
462 }
465 /****************
466 Create a new branch
467 ****************/
469 if(isset($_GET['PerformBranch'])){
471 if(!$this->acl_is_createable()){
472 print_red(_("You are not allowed to create a new branch."));
473 }else{
475 /* Create it know */
476 $this->dispNewBranch = false;
477 $this->dispNewFreeze = false;
478 $base = $_SESSION['LASTPOST']['base'];
479 $_POST = $_SESSION['LASTPOST'];
480 $name = $_POST['BranchName'];
482 $type = $_SESSION['LASTPOST']['type'];
483 $ldap = $this->config->get_ldap_link();
485 $baseToUse = $base;
486 if($this->DivListFai->selectedBranch != "main" ){
487 $baseToUse = $this->DivListFai->selectedBranch;
488 }
490 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
492 $CurrentReleases = $this->getBranches();
493 $NewReleaseName = $name;
494 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
495 if($this->DivListFai->selectedBranch != "main"){
496 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
497 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
498 }else{
499 $NewReleaseName = $name;
500 }
501 }
503 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
504 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
506 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
507 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
509 /* Print header to have styles included */
510 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
511 <html>
512 <head>
513 <title></title>
514 <style type="text/css">@import url("themes/default/style.css");</style>
515 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
516 </head>
517 <body style="background: none;margin:3px;color:black">
518 ';
521 /* Duplicate applications
522 */
523 $ldap->cat($appsrc,array("dn")) ;
524 if($ldap->count()){
525 $ldap->cd ($appdst);
526 $ldap->recursive_remove();
527 $ldap->cd ($this->config->current['BASE']);
528 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
529 }
531 /* Duplicate mime types
532 */
533 $ldap->cat($mimesrc,array("dn")) ;
534 if($ldap->count()){
535 $ldap->cd ($appdst);
536 $ldap->recursive_remove();
537 $ldap->cd ($this->config->current['BASE']);
538 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
539 }
541 $attr = array();
542 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
543 $attr['ou'] = $name;
544 $attr['FAIstate'] = $type;
545 $ldap->cd($this->config->current['BASE']);
546 $ldap->cd("ou=".$name.",".$baseToUse);
547 $ldap->cat("ou=".$name.",".$baseToUse);
548 if($ldap->count()){
549 $ldap->modify($attr);
550 }else{
551 $ldap->add($attr);
552 }
554 /* Duplicate fai objects
555 */
556 // $ldap->cd ("ou=".$name.",".$baseToUse);
557 // $ldap->recursive_remove();
558 // $ldap->cd ($this->config->current['BASE']);
559 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
561 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
562 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
563 </form></div>";
565 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
567 /* Print footer to have valid html */
568 echo "</body></html>";
570 $this->dispNewFreeze = false;
572 /* Postcreate */
574 /* Assign possible attributes */
575 $this->lock_type = $type;
576 $this->lock_name = $name;
577 $this->lock_dn = $baseToUse;
578 $this->postcreate();
579 exit();
580 }
581 }
583 /****************
584 Display dialog to enter new Branch name
585 ****************/
587 if(($s_action == "branch_branch")||($this->dispNewBranch)){
588 $this->dispNewBranch=true;
589 $smarty->assign("iframe",false);
590 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
591 return($display);
592 }
595 /****************
596 Display dialog to enter new Freeze name
597 ****************/
599 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
600 $this->dispNewFreeze = true;
601 $smarty->assign("iframe",false);
602 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
603 return($display);
604 }
607 /****************
608 Create a new object
609 ****************/
611 $types = array( "new_partition" => "FAIpartitionTable",
612 "new_script" => "FAIscript",
613 "new_hook" => "FAIhook",
614 "new_variable" => "FAIvariable",
615 "new_template" => "FAItemplate",
616 "new_package" => "FAIpackageList");
618 if(isset($types[$s_action])){
619 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
620 if(preg_match("/c/",$acl)){
621 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
622 }else{
623 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
624 }
625 }
627 /* New Profile */
628 if($s_action == "new_profile"){
629 $this->dn = "new" ;
631 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
632 if(preg_match("/c/",$acl)){
633 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
634 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
635 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
637 $this->is_dialog = false;
638 }else{
639 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
640 }
641 }
644 /****************
645 Get from ask class name dialog
646 ****************/
648 if($s_action == "select_class_name_finished"){
649 $this->dialog->save_object();
650 if(count($this->dialog->check())!=0){
651 foreach($this->dialog->check() as $msg){
652 print_red($msg);
653 }
654 }else{
655 $this->dn = "new" ;
656 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
657 $name = $this->dialog->save();
659 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
660 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
661 $this->dialog->by_object[$a_setup[1]]->cn = $name;
662 $this->is_dialog = true;
663 }
664 }
667 /****************
668 Cancel dialogs
669 ****************/
671 if(isset($_POST['edit_cancel'])){
672 unset($this->dialog);
673 $this->dialog=NULL;
674 $this->is_dialog = false;
675 unset($_SESSION['objectinfo']);
676 del_lock ($this->dn);
677 }
680 /****************
681 Save sub dialogs
682 ****************/
684 /* This check if the given tab could be saved
685 * If it was possible to save it, remove dialog object.
686 * If it wasn't possible, show errors and keep dialog.
687 */
688 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
689 $this->dialog->save_object();
690 $msgs= $this->dialog->check();
691 if(count($msgs)!=0){
692 foreach($msgs as $msg){
693 print_red($msg);
694 }
695 }else{
696 $this->dialog->save();
697 save_release_changes_now();
698 if (!isset($_POST['edit_apply'])){
699 del_lock ($this->dn);
700 unset($this->dialog);
701 $this->dialog=NULL;
702 $this->is_dialog=false;
703 unset($_SESSION['objectinfo']);
704 }
705 }
706 }
709 /****************
710 Display currently open dialog
711 ****************/
713 /* If dialog is set, but $this->is_dialog==false, then
714 * only the "abort" button is shown, this are dialogs that must not be saved.
715 * If is_dialog == true, we are currently editing tab objects.
716 * Here we need both, save and cancel
717 */
719 if(($this->dialog != NULL) && (isset($this->dialog->config))){
720 $display .= $this->dialog->execute();
721 /* Don't show buttons if tab dialog requests this */
723 if(isset($this->dialog->current)){
725 $obj = $this->dialog->by_object[$this->dialog->current];
727 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
729 $display.= "<p style=\"text-align:right\">\n";
730 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
731 $display.= " \n";
732 if ($this->dn != "new"){
733 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
734 $display.= " \n";
735 }
736 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
737 $display.= "</p>";
738 }elseif(!isset($this->dialog->current)){
739 $display.= "<p style=\"text-align:right\">\n";
740 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
741 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
742 $display.= "</p>";
743 }
744 }else{
745 $display.= "<p style=\"text-align:right\">\n";
746 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
747 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
748 $display.= "</p>";
750 }
751 return($display);
752 }
755 /****************
756 Dialog display
757 ****************/
759 /* Check if there is a snapshot dialog open */
760 $base = $this->DivListFai->selectedBase;
761 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
762 return($str);
763 }
765 /* Display dialog with system list */
766 $this->DivListFai->parent = $this;
767 $this->DivListFai->execute();
768 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
769 $this->reload();
770 $this->DivListFai->setEntries($this->objects);
771 return($this->DivListFai->Draw());
772 }
775 /* Return departments, that will be included within snapshot detection */
776 function get_used_snapshot_bases()
777 {
778 $tmp = array();
779 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
780 foreach($types as $type){
781 if($this->DivListFai->selectedBranch == "main"){
782 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
783 }else{
784 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
785 }
786 }
787 return($tmp);
788 }
791 /* Get available branches for current base */
792 function getBranches($base = false,$prefix = "")
793 {
794 $ret = array("main"=>"/");
795 $ldap = $this->config->get_ldap_link();
796 if(!$base){
797 $base= $_SESSION['CurrentMainBase'];
798 }
799 $tmp = get_all_releases_from_base($base,true);
800 foreach($tmp as $dn => $name){
801 $ret[$dn]=$name;
802 }
803 return ($ret);
804 }
807 function list_get_selected_items()
808 {
809 $ids = array();
810 foreach($_POST as $name => $value){
811 if(preg_match("/^item_selected_[0-9]*$/",$name)){
812 $id = preg_replace("/^item_selected_/","",$name);
813 $ids[$id] = $id;
814 }
815 }
816 return($ids);
817 }
820 /* reload list of objects */
821 function reload()
822 {
823 /* Variable initialisation */
824 $str = "";
825 $Regex = $this->DivListFai->Regex;
826 $this->objects = array();
828 /* Get base */
829 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
830 if($this->DivListFai->selectedBranch != "main"){
831 $br = $this->getBranches();
832 if(isset($br[$this->DivListFai->selectedBranch])){
833 $base = $this->DivListFai->selectedBranch;
834 }else{
835 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
836 }
837 }
839 $this->lock_type = get_release_tag(get_release_dn($base));
841 /* Create a new list of FAI object
842 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
843 */
844 $ObjectTypes = array(
845 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
846 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
847 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
848 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
849 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
850 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
851 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
853 $filter = "";
854 foreach($ObjectTypes as $key => $data){
855 if($this->DivListFai->$data['CHKBOX']){
856 $filter.= "(objectClass=".$key.")";
857 }
858 }
859 $filter = "(&(|".$filter.")(cn=$Regex))";
861 /* Get resolved release dependencies */
862 $tmp = get_all_objects_for_given_base($base,$filter);
864 /* Ge listed ldap objects */
865 $ldap = $this->config->get_ldap_link();
866 $ldap->cd($this->config->current['BASE']);
867 foreach($tmp as $entry){
869 /* Get some more informations about the object */
870 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
871 $object = $ldap->fetch();
873 /* Walk through possible types */
874 foreach($ObjectTypes as $type => $rest){
876 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
878 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
880 /* Prepare object */
881 unset($object['objectClass']['count']);
882 if(!isset($object['description'][0])){
883 $object['description'][0]="";
884 }
886 /* Clean up object informations */
887 $obj = array();
888 $obj['cn'] = $object['cn'][0];
889 $obj['dn'] = $object['dn'];
890 $obj['acl'] = $acl;
891 $obj['description'] = $object['description'][0];
892 $obj['objectClass'] = $object['objectClass'];
894 /* Append type to this string, to be able to check if the selected
895 * entry is of type 'freeze' or 'branch'
896 */
897 if(!isset($object['FAIstate'])){
898 $obj['FAIstate'] = $this->lock_type;
899 }else{
900 $obj['FAIstate'] = $object['FAIstate'][0];
901 }
903 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
904 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
905 }
906 }
907 }
909 ksort($this->objects);
910 reset ($this->objects);
912 /* use numeric index, thats a bit more secure */
913 $tmp0 = array();
914 foreach($this->objects as $obj){
915 $tmp0[]= $obj;
916 }
917 $this->objects = array();
918 $this->objects = $tmp0;
919 }
921 function remove_lock()
922 {
923 if (isset($this->dn)){
924 del_lock ($this->dn);
925 }
926 }
928 function get_type($array){
929 if(in_array("FAIpartitionTable",$array['objectClass'])){
930 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
931 }
932 if(in_array("FAIscript",$array['objectClass'])){
933 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
934 }
935 if(in_array("FAItemplate",$array['objectClass'])){
936 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
937 }
938 if(in_array("FAIhook",$array['objectClass'])){
939 return(array("tabsHook","faiHook","FAIHOOKTABS"));
940 }
941 if(in_array("FAIvariable",$array['objectClass'])){
942 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
943 }
944 if(in_array("FAIprofile",$array['objectClass'])){
945 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
946 }
948 if(in_array("FAIpackageList",$array['objectClass'])){
949 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
950 }
951 }
953 function CheckNewBranchName($name,$base)
954 {
955 $f = $this->DivListFai->selectedBranch;
956 if($name == ""){
957 return(false);
958 }elseif(in_array($name,$this->getBranches($f))) {
959 return(false);
960 }elseif(is_department_name_reserved($name,$base)){
961 return(false);
962 }
963 return(true);
964 }
966 function save_object()
967 {
968 $this->DivListFai->save_object();
969 }
972 /* Return plugin informations for acl handling */
973 function plInfo()
974 {
975 return (array(
976 "plShortName" => _("FAI releases"),
977 "plDescription" => _("FAI release management"),
978 "plSelfModify" => FALSE,
979 "plDepends" => array(),
980 "plPriority" => 0,
981 "plSection" => array("administration"),
982 "plCategory" => array("fai"=> array("description" => _("FAI"),
983 "objectClass" => "FAIclass")),
984 "plProvidedAcls"=> array()));
985 }
986 }
987 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
988 ?>