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 $this->dialog= NULL;
238 $to_del = clean_up_releases($dn);
239 save_release_changes_now();
241 foreach($to_del as $dn){
242 $ldap->rmdir_recursive($dn);
243 }
245 } else {
247 /* Normally this shouldn't be reached, send some extra
248 logs to notify the administrator */
249 print_red (_("You are not allowed to delete this component!"));
250 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
251 }
253 /* Remove lock file after successfull deletion */
254 del_lock ($dn);
255 unset($this->dns[$key]);
256 }
257 }
260 /********************
261 Delete MULTIPLE entries Canceled
262 ********************/
264 /* Remove lock */
265 if(isset($_POST['delete_multiple_fai_object_cancel'])){
266 foreach($this->dns as $key => $dn){
267 del_lock ($dn);
268 unset($this->dns[$key]);
269 }
270 }
273 /****************
274 Delete aborted
275 ****************/
277 /* Delete canceled? */
278 if (isset($_POST['delete_cancel'])){
279 del_lock ($this->dn);
280 }
283 /****************
284 Delete confirmed
285 ****************/
287 /* Deltetion was confirmed, so delete this entry
288 */
289 if (isset($_POST['delete_terminal_confirm'])){
291 /* Some nice guy may send this as POST, so we've to check
292 for the permissions again. */
294 /* Find out more about the object type */
295 $ldap = $this->config->get_ldap_link();
296 $ldap->cat($this->dn, array('objectClass'));
297 if($ldap->count()){
298 $attrs = $ldap->fetch();
299 $type = $this->get_type($attrs);
301 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
302 if(preg_match("/d/",$acl)){
304 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
305 $this->dialog->set_acl_base($this->dn);
306 $this->dialog->by_object[$type[1]]->remove_from_parent ();
307 unset ($this->dialog);
308 $this->dialog= NULL;
309 $to_del = clean_up_releases($this->dn);
310 save_release_changes_now();
312 foreach($to_del as $dn){
313 $ldap->rmdir_recursive($dn);
314 }
316 } else {
318 /* Normally this shouldn't be reached, send some extra
319 logs to notify the administrator */
320 print_red (_("You are not allowed to delete this component!"));
321 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
322 }
324 }else{
325 print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
326 }
327 /* Remove lock file after successfull deletion */
328 del_lock ($this->dn);
329 }
332 /****************
333 Edit entry
334 ****************/
336 if(($s_action == "edit") && (!isset($this->dialog->config))){
337 $entry = $this->objects[$s_entry];
338 $a_setup = $this->get_type($entry);
339 $this->dn = $entry['dn'];
341 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
342 if (($user= get_lock($this->dn)) != ""){
343 return(gen_locked_message ($user, $this->dn));
344 }
345 add_lock ($this->dn, $this->ui->dn);
347 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
348 $this->dialog->set_acl_base($this->dn);
349 $this->is_dialog = true;
351 if($entry['FAIstate'] == "freeze"){
352 #$this->dialog->set_acl(array("*none*")) ;
353 echo "Dawn it is freezed.";
354 }
355 $_SESSION['objectinfo'] = $this->dn;
356 }
359 /* Branch handling
360 09.01.2006
361 */
363 /****************
364 Remove branch
365 ****************/
367 /* Remove branch
368 */
369 if($s_action == "remove_branch"){
370 $base= $this->DivListFai->selectedBranch;
372 /* Load permissions for selected 'dn' and check if
373 we're allowed to remove this 'dn' */
374 $this->set_acl_base($base);
375 if($this->acl_is_removeable()){
377 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
378 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
379 } else {
380 print_red (_("You are not allowed to delete this release!"));
381 }
382 }
385 /****************
386 Remove branch confirmed
387 ****************/
389 if(isset($_POST['delete_branch_confirm'])){
390 $bb = $this->DivListFai->selectedBranch;
391 if(!isset($ldap)){
392 $ldap = $this->config->get_ldap_link();
393 }
395 $br = $this->getBranches();
397 if(isset($br[$bb]) && $this->acl_is_removeable()){
398 $name = $br[$bb];
399 $ldap->cd($bb);
400 $ldap->recursive_remove();
401 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
402 $ldap->recursive_remove();
403 $this->DivListFai->selectedBranch = "main";
405 /* Post remove */
406 $this->lock_name = $name;
407 $this->lock_dn = $bb;
408 $this->postremove();
410 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
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 ';
516 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
518 /* Duplicate applications
519 */
520 $ldap->cat($appsrc,array("dn")) ;
521 if($ldap->count()){
522 $ldap->cd ($appdst);
523 $ldap->recursive_remove();
524 $ldap->cd ($this->config->current['BASE']);
525 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
526 }
528 /* Duplicate mime types
529 */
530 $ldap->cat($mimesrc,array("dn")) ;
531 if($ldap->count()){
532 $ldap->cd ($appdst);
533 $ldap->recursive_remove();
534 $ldap->cd ($this->config->current['BASE']);
535 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
536 }
538 $attr = array();
539 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
540 $attr['ou'] = $name;
541 $attr['FAIstate'] = $type;
542 $ldap->cd($this->config->current['BASE']);
543 $ldap->cd("ou=".$name.",".$baseToUse);
544 $ldap->cat("ou=".$name.",".$baseToUse);
545 if($ldap->count()){
546 $ldap->modify($attr);
547 }else{
548 $ldap->add($attr);
549 }
551 /* Duplicate fai objects
552 */
553 // $ldap->cd ("ou=".$name.",".$baseToUse);
554 // $ldap->recursive_remove();
555 // $ldap->cd ($this->config->current['BASE']);
556 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
558 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
559 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
560 </form></div>";
562 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
564 /* Print footer to have valid html */
565 echo "</body></html>";
567 $this->dispNewFreeze = false;
569 /* Postcreate */
571 /* Assign possible attributes */
572 $this->lock_type = $type;
573 $this->lock_name = $name;
574 $this->lock_dn = $baseToUse;
575 $this->postcreate();
576 exit();
577 }
578 }
580 /****************
581 Display dialog to enter new Branch name
582 ****************/
584 if(($s_action == "branch_branch")||($this->dispNewBranch)){
585 $this->dispNewBranch=true;
586 $smarty->assign("iframe",false);
587 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
588 return($display);
589 }
592 /****************
593 Display dialog to enter new Freeze name
594 ****************/
596 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
597 $this->dispNewFreeze = true;
598 $smarty->assign("iframe",false);
599 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
600 return($display);
601 }
604 /****************
605 Create a new object
606 ****************/
608 $types = array( "new_partition" => "FAIpartitionTable",
609 "new_script" => "FAIscript",
610 "new_hook" => "FAIhook",
611 "new_variable" => "FAIvariable",
612 "new_template" => "FAItemplate",
613 "new_package" => "FAIpackageList");
615 if(isset($types[$s_action])){
616 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
617 if(preg_match("/c/",$acl)){
618 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
619 }else{
620 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
621 }
622 }
624 /* New Profile */
625 if($s_action == "new_profile"){
626 $this->dn = "new" ;
628 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
629 if(preg_match("/c/",$acl)){
630 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
631 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
632 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
634 $this->is_dialog = false;
635 }else{
636 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
637 }
638 }
641 /****************
642 Get from ask class name dialog
643 ****************/
645 if($s_action == "select_class_name_finished"){
646 $this->dialog->save_object();
647 if(count($this->dialog->check())!=0){
648 foreach($this->dialog->check() as $msg){
649 print_red($msg);
650 }
651 }else{
652 $this->dn = "new" ;
653 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
654 $name = $this->dialog->save();
656 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
657 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
658 $this->dialog->by_object[$a_setup[1]]->cn = $name;
659 $this->is_dialog = true;
660 }
661 }
664 /****************
665 Cancel dialogs
666 ****************/
668 if(isset($_POST['edit_cancel'])){
669 unset($this->dialog);
670 $this->dialog=NULL;
671 $this->is_dialog = false;
672 unset($_SESSION['objectinfo']);
673 del_lock ($this->dn);
674 }
677 /****************
678 Save sub dialogs
679 ****************/
681 /* This check if the given tab could be saved
682 * If it was possible to save it, remove dialog object.
683 * If it wasn't possible, show errors and keep dialog.
684 */
685 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
686 $this->dialog->save_object();
687 $msgs= $this->dialog->check();
688 if(count($msgs)!=0){
689 foreach($msgs as $msg){
690 print_red($msg);
691 }
692 }else{
693 $this->dialog->save();
694 save_release_changes_now();
695 if (!isset($_POST['edit_apply'])){
696 del_lock ($this->dn);
697 unset($this->dialog);
698 $this->dialog=NULL;
699 $this->is_dialog=false;
700 unset($_SESSION['objectinfo']);
701 }
702 }
703 }
706 /****************
707 Display currently open dialog
708 ****************/
710 /* If dialog is set, but $this->is_dialog==false, then
711 * only the "abort" button is shown, this are dialogs that must not be saved.
712 * If is_dialog == true, we are currently editing tab objects.
713 * Here we need both, save and cancel
714 */
716 if(($this->dialog != NULL) && (isset($this->dialog->config))){
717 $display .= $this->dialog->execute();
718 /* Don't show buttons if tab dialog requests this */
720 if(isset($this->dialog->current)){
722 $obj = $this->dialog->by_object[$this->dialog->current];
724 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
726 $display.= "<p style=\"text-align:right\">\n";
727 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
728 $display.= " \n";
729 if ($this->dn != "new"){
730 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
731 $display.= " \n";
732 }
733 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
734 $display.= "</p>";
735 }elseif(!isset($this->dialog->current)){
736 $display.= "<p style=\"text-align:right\">\n";
737 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
738 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
739 $display.= "</p>";
740 }
741 }else{
742 $display.= "<p style=\"text-align:right\">\n";
743 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
744 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
745 $display.= "</p>";
747 }
748 return($display);
749 }
752 /****************
753 Dialog display
754 ****************/
756 /* Check if there is a snapshot dialog open */
757 $base = $this->DivListFai->selectedBase;
758 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
759 return($str);
760 }
762 /* Display dialog with system list */
763 $this->DivListFai->parent = $this;
764 $this->DivListFai->execute();
765 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
766 $this->reload();
767 $this->DivListFai->setEntries($this->objects);
768 return($this->DivListFai->Draw());
769 }
772 /* Return departments, that will be included within snapshot detection */
773 function get_used_snapshot_bases()
774 {
775 $tmp = array();
776 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
777 foreach($types as $type){
778 if($this->DivListFai->selectedBranch == "main"){
779 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
780 }else{
781 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
782 }
783 }
784 return($tmp);
785 }
788 /* Get available branches for current base */
789 function getBranches($base = false,$prefix = "")
790 {
791 $ret = array("main"=>"/");
792 $ldap = $this->config->get_ldap_link();
793 if(!$base){
794 $base= $_SESSION['CurrentMainBase'];
795 }
796 $tmp = get_all_releases_from_base($base,true);
797 foreach($tmp as $dn => $name){
798 $ret[$dn]=$name;
799 }
800 return ($ret);
801 }
804 function list_get_selected_items()
805 {
806 $ids = array();
807 foreach($_POST as $name => $value){
808 if(preg_match("/^item_selected_[0-9]*$/",$name)){
809 $id = preg_replace("/^item_selected_/","",$name);
810 $ids[$id] = $id;
811 }
812 }
813 return($ids);
814 }
817 /* reload list of objects */
818 function reload()
819 {
820 /* Variable initialisation */
821 $str = "";
822 $Regex = $this->DivListFai->Regex;
823 $this->objects = array();
825 /* Get base */
826 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
827 if($this->DivListFai->selectedBranch != "main"){
828 $br = $this->getBranches();
829 if(isset($br[$this->DivListFai->selectedBranch])){
830 $base = $this->DivListFai->selectedBranch;
831 }else{
832 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
833 }
834 }
836 $this->lock_type = get_release_tag(get_release_dn($base));
838 /* Create a new list of FAI object
839 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
840 */
841 $ObjectTypes = array(
842 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
843 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
844 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
845 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
846 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
847 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
848 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
850 $filter = "";
851 foreach($ObjectTypes as $key => $data){
852 if($this->DivListFai->$data['CHKBOX']){
853 $filter.= "(objectClass=".$key.")";
854 }
855 }
856 $filter = "(&(|".$filter.")(cn=$Regex))";
858 /* Get resolved release dependencies */
859 $tmp = get_all_objects_for_given_base($base,$filter);
861 /* Ge listed ldap objects */
862 $ldap = $this->config->get_ldap_link();
863 $ldap->cd($this->config->current['BASE']);
864 foreach($tmp as $entry){
866 /* Get some more informations about the object */
867 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
868 $object = $ldap->fetch();
870 /* Walk through possible types */
871 foreach($ObjectTypes as $type => $rest){
873 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
875 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
877 /* Prepare object */
878 unset($object['objectClass']['count']);
879 if(!isset($object['description'][0])){
880 $object['description'][0]="";
881 }
883 /* Clean up object informations */
884 $obj = array();
885 $obj['cn'] = $object['cn'][0];
886 $obj['dn'] = $object['dn'];
887 $obj['acl'] = $acl;
888 $obj['description'] = $object['description'][0];
889 $obj['objectClass'] = $object['objectClass'];
891 /* Append type to this string, to be able to check if the selected
892 * entry is of type 'freeze' or 'branch'
893 */
894 if(!isset($object['FAIstate'])){
895 $obj['FAIstate'] = $this->lock_type;
896 }else{
897 $obj['FAIstate'] = $object['FAIstate'][0];
898 }
900 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
901 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
902 }
903 }
904 }
906 ksort($this->objects);
907 reset ($this->objects);
909 /* use numeric index, thats a bit more secure */
910 $tmp0 = array();
911 foreach($this->objects as $obj){
912 $tmp0[]= $obj;
913 }
914 $this->objects = array();
915 $this->objects = $tmp0;
916 }
918 function remove_lock()
919 {
920 if (isset($this->dn)){
921 del_lock ($this->dn);
922 }
923 }
925 function get_type($array){
926 if(in_array("FAIpartitionTable",$array['objectClass'])){
927 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
928 }
929 if(in_array("FAIscript",$array['objectClass'])){
930 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
931 }
932 if(in_array("FAItemplate",$array['objectClass'])){
933 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
934 }
935 if(in_array("FAIhook",$array['objectClass'])){
936 return(array("tabsHook","faiHook","FAIHOOKTABS"));
937 }
938 if(in_array("FAIvariable",$array['objectClass'])){
939 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
940 }
941 if(in_array("FAIprofile",$array['objectClass'])){
942 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
943 }
945 if(in_array("FAIpackageList",$array['objectClass'])){
946 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
947 }
948 }
950 function CheckNewBranchName($name,$base)
951 {
952 $f = $this->DivListFai->selectedBranch;
953 if($name == ""){
954 return(false);
955 }elseif(in_array($name,$this->getBranches($f))) {
956 return(false);
957 }elseif(is_department_name_reserved($name,$base)){
958 return(false);
959 }
960 return(true);
961 }
963 function save_object()
964 {
965 $this->DivListFai->save_object();
966 }
969 /* Return plugin informations for acl handling */
970 function plInfo()
971 {
972 return (array(
973 "plShortName" => _("FAI releases"),
974 "plDescription" => _("FAI release management"),
975 "plSelfModify" => FALSE,
976 "plDepends" => array(),
977 "plPriority" => 0,
978 "plSection" => array("administration"),
979 "plCategory" => array("fai"=> array("description" => _("FAI"),
980 "objectClass" => "FAIclass")),
981 "plProvidedAcls"=> array()));
982 }
983 }
984 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
985 ?>