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 $smarty->assign("warning", sprintf(_("You're about to delete the following fai object(s) %s"), @LDAP::fix($dns_names)));
203 $smarty->assign("multiple", true);
204 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
205 }
206 }
209 /********************
210 Delete MULTIPLE entries confirmed
211 ********************/
213 /* Confirmation for deletion has been passed. Users should be deleted. */
214 if (isset($_POST['delete_multiple_fai_object_confirm'])){
216 /* Find out more about the object type */
217 $ldap = $this->config->get_ldap_link();
219 /* Remove user by user and check acls before removeing them */
220 foreach($this->dns as $key => $dn){
222 $ldap->cat($dn, array('objectClass'));
223 $attrs = $ldap->fetch();
224 $type = $this->get_type($attrs);
226 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
227 if(preg_match("/d/",$acl)){
229 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
230 $this->dialog->set_acl_base($dn);
231 $this->dialog->by_object[$type[1]]->remove_from_parent ();
232 unset ($this->dialog);
233 gosa_log ("FAI class '".$dn."' has been tagged as removed");
234 $this->dialog= NULL;
235 $to_del = clean_up_releases($dn);
236 save_release_changes_now();
238 foreach($to_del as $dn){
239 $ldap->rmdir_recursive($dn);
240 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$dn));
241 }
243 } else {
245 /* Normally this shouldn't be reached, send some extra
246 logs to notify the administrator */
247 print_red (_("You are not allowed to delete this component!"));
248 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
249 "deletion.");
250 }
252 /* Remove lock file after successfull deletion */
253 del_lock ($dn);
254 unset($this->dns[$key]);
255 }
256 }
259 /********************
260 Delete MULTIPLE entries Canceled
261 ********************/
263 /* Remove lock */
264 if(isset($_POST['delete_multiple_fai_object_cancel'])){
265 foreach($this->dns as $key => $dn){
266 del_lock ($dn);
267 unset($this->dns[$key]);
268 }
269 }
272 /****************
273 Delete aborted
274 ****************/
276 /* Delete canceled? */
277 if (isset($_POST['delete_cancel'])){
278 del_lock ($this->dn);
279 }
282 /****************
283 Delete confirmed
284 ****************/
286 /* Deltetion was confirmed, so delete this entry
287 */
288 if (isset($_POST['delete_terminal_confirm'])){
290 /* Some nice guy may send this as POST, so we've to check
291 for the permissions again. */
293 /* Find out more about the object type */
294 $ldap = $this->config->get_ldap_link();
295 $ldap->cat($this->dn, array('objectClass'));
296 $attrs = $ldap->fetch();
297 $type = $this->get_type($attrs);
299 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
300 if(preg_match("/d/",$acl)){
302 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
303 $this->dialog->set_acl_base($this->dn);
304 $this->dialog->by_object[$type[1]]->remove_from_parent ();
305 unset ($this->dialog);
306 gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
307 $this->dialog= NULL;
308 $to_del = clean_up_releases($this->dn);
309 save_release_changes_now();
311 foreach($to_del as $dn){
312 $ldap->rmdir_recursive($dn);
313 gosa_log(sprintf(_("Release cleanup : Removing object (tagged as remvoed) that is no longer in use '%s'."),$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 gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
322 "deletion.");
323 }
325 /* Remove lock file after successfull deletion */
326 del_lock ($this->dn);
327 }
330 /****************
331 Edit entry
332 ****************/
334 if(($s_action == "edit") && (!isset($this->dialog->config))){
335 $entry = $this->objects[$s_entry];
336 $a_setup = $this->get_type($entry);
337 $this->dn = $entry['dn'];
339 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
340 if (($user= get_lock($this->dn)) != ""){
341 return(gen_locked_message ($user, $this->dn));
342 }
343 add_lock ($this->dn, $this->ui->dn);
345 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
346 $this->dialog->set_acl_base($this->dn);
347 $this->is_dialog = true;
349 if($entry['FAIstate'] == "freeze"){
350 #$this->dialog->set_acl(array("*none*")) ;
351 echo "Dawn it is freezed.";
352 }
353 $_SESSION['objectinfo'] = $this->dn;
354 }
357 /* Branch handling
358 09.01.2006
359 */
361 /****************
362 Remove branch
363 ****************/
365 /* Remove branch
366 */
367 if($s_action == "remove_branch"){
368 $base= $this->DivListFai->selectedBranch;
370 /* Load permissions for selected 'dn' and check if
371 we're allowed to remove this 'dn' */
372 $this->set_acl_base($base);
373 if($this->acl_is_removeable()){
375 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
376 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
377 } else {
378 print_red (_("You are not allowed to delete this release!"));
379 }
380 }
383 /****************
384 Remove branch confirmed
385 ****************/
387 if(isset($_POST['delete_branch_confirm'])){
388 $bb = $this->DivListFai->selectedBranch;
389 if(!isset($ldap)){
390 $ldap = $this->config->get_ldap_link();
391 }
393 $br = $this->getBranches();
395 if(isset($br[$bb]) && $this->acl_is_removeable()){
396 $name = $br[$bb];
397 $ldap->cd($bb);
398 $ldap->recursive_remove();
399 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
400 $ldap->recursive_remove();
401 $this->DivListFai->selectedBranch = "main";
403 /* Post remove */
404 $this->lock_name = $name;
405 $this->lock_dn = $bb;
406 $this->postremove();
407 }
408 }
411 /****************
412 Create a new branch "insert Name"
413 ****************/
415 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
416 $_SESSION['LASTPOST'] = $_POST;
418 if($this->dispNewBranch){
419 $type = "branch";
420 }else{
421 $type = "freeze";
422 }
424 /* Check branch name */
425 $name = $_POST['BranchName'];
426 $is_ok = true;
427 $smarty->assign("BranchName",$name);
428 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
430 /* Check used characters */
431 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
432 if($type == "branch"){
433 print_red(_("Specified branch name is invalid."));
434 }else{
435 print_red(_("Specified freeze name is invalid."));
436 }
437 $is_ok = false;
438 }
440 /* Check if this name is already in use */
441 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
442 print_red(_("This name is already in use."));
443 $is_ok = false;
444 }
446 if($is_ok){
447 $_SESSION['LASTPOST']['base'] = $base;
448 $_SESSION['LASTPOST']['type'] = $type;
449 $smarty->assign("iframe", true);
450 $smarty->assign("plugID", $_GET['plug']);
451 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
452 return($display);
453 }
454 }
457 /****************
458 Create a new branch
459 ****************/
461 if(isset($_GET['PerformBranch'])){
463 if(!$this->acl_is_createable()){
464 print_red(_("You are not allowed to create a new branch."));
465 }else{
467 /* Create it know */
468 $this->dispNewBranch = false;
469 $this->dispNewFreeze = false;
470 $base = $_SESSION['LASTPOST']['base'];
471 $_POST = $_SESSION['LASTPOST'];
472 $name = $_POST['BranchName'];
474 $type = $_SESSION['LASTPOST']['type'];
475 $ldap = $this->config->get_ldap_link();
477 $baseToUse = $base;
478 if($this->DivListFai->selectedBranch != "main" ){
479 $baseToUse = $this->DivListFai->selectedBranch;
480 }
482 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
484 $CurrentReleases = $this->getBranches();
485 $NewReleaseName = $name;
486 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
487 if($this->DivListFai->selectedBranch != "main"){
488 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
489 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
490 }else{
491 $NewReleaseName = $name;
492 }
493 }
495 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
496 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
498 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
499 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
501 /* Print header to have styles included */
502 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
503 <html>
504 <head>
505 <title></title>
506 <style type="text/css">@import url("themes/default/style.css");</style>
507 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
508 </head>
509 <body style="background: none;margin:3px;color:black">
510 ';
513 /* Duplicate applications
514 */
515 $ldap->cat($appsrc,array("dn")) ;
516 if($ldap->count()){
517 $ldap->cd ($appdst);
518 $ldap->recursive_remove();
519 $ldap->cd ($this->config->current['BASE']);
520 $ldap->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
521 }
523 /* Duplicate mime types
524 */
525 $ldap->cat($mimesrc,array("dn")) ;
526 if($ldap->count()){
527 $ldap->cd ($appdst);
528 $ldap->recursive_remove();
529 $ldap->cd ($this->config->current['BASE']);
530 $ldap->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
531 }
533 $attr = array();
534 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
535 $attr['ou'] = $name;
536 $attr['FAIstate'] = $type;
537 $ldap->cd($this->config->current['BASE']);
538 $ldap->cd("ou=".$name.",".$baseToUse);
539 $ldap->cat("ou=".$name.",".$baseToUse);
540 if($ldap->count()){
541 $ldap->modify($attr);
542 }else{
543 $ldap->add($attr);
544 }
546 /* Duplicate fai objects
547 */
548 // $ldap->cd ("ou=".$name.",".$baseToUse);
549 // $ldap->recursive_remove();
550 // $ldap->cd ($this->config->current['BASE']);
551 // $ldap->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
553 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
554 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
555 </form></div>";
557 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
559 /* Print footer to have valid html */
560 echo "</body></html>";
562 $this->dispNewFreeze = false;
564 /* Postcreate */
566 /* Assign possible attributes */
567 $this->lock_type = $type;
568 $this->lock_name = $name;
569 $this->lock_dn = $baseToUse;
570 $this->postcreate();
571 exit();
572 }
573 }
575 /****************
576 Display dialog to enter new Branch name
577 ****************/
579 if(($s_action == "branch_branch")||($this->dispNewBranch)){
580 $this->dispNewBranch=true;
581 $smarty->assign("iframe",false);
582 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
583 return($display);
584 }
587 /****************
588 Display dialog to enter new Freeze name
589 ****************/
591 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
592 $this->dispNewFreeze = true;
593 $smarty->assign("iframe",false);
594 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
595 return($display);
596 }
599 /****************
600 Create a new object
601 ****************/
603 $types = array( "new_partition" => "FAIpartitionTable",
604 "new_script" => "FAIscript",
605 "new_hook" => "FAIhook",
606 "new_variable" => "FAIvariable",
607 "new_template" => "FAItemplate",
608 "new_package" => "FAIpackageList");
610 if(isset($types[$s_action])){
611 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
612 if(preg_match("/c/",$acl)){
613 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
614 }else{
615 print_red(sprintf(_("You are not allowed to create a new '%s' object."),$types[$s_action]));
616 }
617 }
619 /* New Profile */
620 if($s_action == "new_profile"){
621 $this->dn = "new" ;
623 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
624 if(preg_match("/c/",$acl)){
625 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
626 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
627 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
629 $this->is_dialog = false;
630 }else{
631 print_red(sprintf(_("You are not allowed to create a new '%s' object."),"FAIprofile"));
632 }
633 }
636 /****************
637 Get from ask class name dialog
638 ****************/
640 if($s_action == "select_class_name_finished"){
641 $this->dialog->save_object();
642 if(count($this->dialog->check())!=0){
643 foreach($this->dialog->check() as $msg){
644 print_red($msg);
645 }
646 }else{
647 $this->dn = "new" ;
648 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
649 $name = $this->dialog->save();
651 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
652 $this->dialog->set_acl_base($_SESSION['CurrentMainBase']);
653 $this->dialog->by_object[$a_setup[1]]->cn = $name;
654 $this->is_dialog = true;
655 }
656 }
659 /****************
660 Cancel dialogs
661 ****************/
663 if(isset($_POST['edit_cancel'])){
664 unset($this->dialog);
665 $this->dialog=NULL;
666 $this->is_dialog = false;
667 unset($_SESSION['objectinfo']);
668 del_lock ($this->dn);
669 }
672 /****************
673 Save sub dialogs
674 ****************/
676 /* This check if the given tab could be saved
677 * If it was possible to save it, remove dialog object.
678 * If it wasn't possible, show errors and keep dialog.
679 */
680 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
681 $this->dialog->save_object();
682 $msgs= $this->dialog->check();
683 if(count($msgs)!=0){
684 foreach($msgs as $msg){
685 print_red($msg);
686 }
687 }else{
688 $this->dialog->save();
689 save_release_changes_now();
690 if (!isset($_POST['edit_apply'])){
691 del_lock ($this->dn);
692 unset($this->dialog);
693 $this->dialog=NULL;
694 $this->is_dialog=false;
695 unset($_SESSION['objectinfo']);
696 }
697 }
698 }
701 /****************
702 Display currently open dialog
703 ****************/
705 /* If dialog is set, but $this->is_dialog==false, then
706 * only the "abort" button is shown, this are dialogs that must not be saved.
707 * If is_dialog == true, we are currently editing tab objects.
708 * Here we need both, save and cancel
709 */
711 if(($this->dialog != NULL) && (isset($this->dialog->config))){
712 $display .= $this->dialog->execute();
713 /* Don't show buttons if tab dialog requests this */
715 if(isset($this->dialog->current)){
717 $obj = $this->dialog->by_object[$this->dialog->current];
719 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
721 $display.= "<p style=\"text-align:right\">\n";
722 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
723 $display.= " \n";
724 if ($this->dn != "new"){
725 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
726 $display.= " \n";
727 }
728 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
729 $display.= "</p>";
730 }elseif(!isset($this->dialog->current)){
731 $display.= "<p style=\"text-align:right\">\n";
732 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
733 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
734 $display.= "</p>";
735 }
736 }else{
737 $display.= "<p style=\"text-align:right\">\n";
738 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
739 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
740 $display.= "</p>";
742 }
743 return($display);
744 }
747 /****************
748 Dialog display
749 ****************/
751 /* Check if there is a snapshot dialog open */
752 $base = $this->DivListFai->selectedBase;
753 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
754 return($str);
755 }
757 /* Display dialog with system list */
758 $this->DivListFai->parent = $this;
759 $this->DivListFai->execute();
760 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
761 $this->reload();
762 $this->DivListFai->setEntries($this->objects);
763 return($this->DivListFai->Draw());
764 }
767 /* Return departments, that will be included within snapshot detection */
768 function get_used_snapshot_bases()
769 {
770 $tmp = array();
771 $types = array("hooks","scripts","disk","packages","profiles","templates","variables");
772 foreach($types as $type){
773 if($this->DivListFai->selectedBranch == "main"){
774 $tmp[] = "ou=".$type.",ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
775 }else{
776 $tmp[] = "ou=".$type.",".$this->DivListFai->selectedBranch;
777 }
778 }
779 return($tmp);
780 }
783 /* Get available branches for current base */
784 function getBranches($base = false,$prefix = "")
785 {
786 $ret = array("main"=>"/");
787 $ldap = $this->config->get_ldap_link();
788 if(!$base){
789 $base= $_SESSION['CurrentMainBase'];
790 }
791 $tmp = get_all_releases_from_base($base,true);
792 foreach($tmp as $dn => $name){
793 $ret[$dn]=$name;
794 }
795 return ($ret);
796 }
799 function list_get_selected_items()
800 {
801 $ids = array();
802 foreach($_POST as $name => $value){
803 if(preg_match("/^item_selected_[0-9]*$/",$name)){
804 $id = preg_replace("/^item_selected_/","",$name);
805 $ids[$id] = $id;
806 }
807 }
808 return($ids);
809 }
812 /* reload list of objects */
813 function reload()
814 {
815 /* Variable initialisation */
816 $str = "";
817 $Regex = $this->DivListFai->Regex;
818 $this->objects = array();
820 /* Get base */
821 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
822 if($this->DivListFai->selectedBranch != "main"){
823 $br = $this->getBranches();
824 if(isset($br[$this->DivListFai->selectedBranch])){
825 $base = $this->DivListFai->selectedBranch;
826 }else{
827 $base = "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
828 }
829 }
831 $this->lock_type = get_release_tag(get_release_dn($base));
833 /* Create a new list of FAI object
834 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
835 */
836 $ObjectTypes = array(
837 "FAIpartitionTable" => array("OU"=>"ou=disk," , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
838 "FAIpackageList" => array("OU"=>"ou=packages," , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
839 "FAIscript" => array("OU"=>"ou=scripts," , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
840 "FAIvariable" => array("OU"=>"ou=variables," , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
841 "FAIhook" => array("OU"=>"ou=hooks," , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
842 "FAIprofile" => array("OU"=>"ou=profiles," , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
843 "FAItemplate" => array("OU"=>"ou=templates," , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
845 $filter = "";
846 foreach($ObjectTypes as $key => $data){
847 if($this->DivListFai->$data['CHKBOX']){
848 $filter.= "(objectClass=".$key.")";
849 }
850 }
851 $filter = "(&(|".$filter.")(cn=$Regex))";
853 /* Get resolved release dependencies */
854 $tmp = get_all_objects_for_given_base($base,$filter);
856 /* Ge listed ldap objects */
857 $ldap = $this->config->get_ldap_link();
858 $ldap->cd($this->config->current['BASE']);
859 foreach($tmp as $entry){
861 /* Get some more informations about the object */
862 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
863 $object = $ldap->fetch();
865 /* Walk through possible types */
866 foreach($ObjectTypes as $type => $rest){
868 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
870 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
872 /* Prepare object */
873 unset($object['objectClass']['count']);
874 if(!isset($object['description'][0])){
875 $object['description'][0]="";
876 }
878 /* Clean up object informations */
879 $obj = array();
880 $obj['cn'] = $object['cn'][0];
881 $obj['dn'] = $object['dn'];
882 $obj['acl'] = $acl;
883 $obj['description'] = $object['description'][0];
884 $obj['objectClass'] = $object['objectClass'];
886 /* Append type to this string, to be able to check if the selected
887 * entry is of type 'freeze' or 'branch'
888 */
889 if(!isset($object['FAIstate'])){
890 $obj['FAIstate'] = $this->lock_type;
891 }else{
892 $obj['FAIstate'] = $object['FAIstate'][0];
893 }
895 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
896 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
897 }
898 }
899 }
901 ksort($this->objects);
902 reset ($this->objects);
904 /* use numeric index, thats a bit more secure */
905 $tmp0 = array();
906 foreach($this->objects as $obj){
907 $tmp0[]= $obj;
908 }
909 $this->objects = array();
910 $this->objects = $tmp0;
911 }
913 function remove_lock()
914 {
915 if (isset($this->dn)){
916 del_lock ($this->dn);
917 }
918 }
920 function get_type($array){
921 if(in_array("FAIpartitionTable",$array['objectClass'])){
922 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
923 }
924 if(in_array("FAIscript",$array['objectClass'])){
925 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
926 }
927 if(in_array("FAItemplate",$array['objectClass'])){
928 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
929 }
930 if(in_array("FAIhook",$array['objectClass'])){
931 return(array("tabsHook","faiHook","FAIHOOKTABS"));
932 }
933 if(in_array("FAIvariable",$array['objectClass'])){
934 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
935 }
936 if(in_array("FAIprofile",$array['objectClass'])){
937 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
938 }
940 if(in_array("FAIpackageList",$array['objectClass'])){
941 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
942 }
943 }
945 function CheckNewBranchName($name,$base)
946 {
947 $f = $this->DivListFai->selectedBranch;
948 if($name == ""){
949 return(false);
950 }elseif(in_array($name,$this->getBranches($f))) {
951 return(false);
952 }elseif(is_department_name_reserved($name,$base)){
953 return(false);
954 }
955 return(true);
956 }
958 function save_object()
959 {
960 $this->DivListFai->save_object();
961 }
964 /* Return plugin informations for acl handling */
965 function plInfo()
966 {
967 return (array(
968 "plShortName" => _("FAI releases"),
969 "plDescription" => _("FAI release management"),
970 "plSelfModify" => FALSE,
971 "plDepends" => array(),
972 "plPriority" => 0,
973 "plSection" => array("administration"),
974 "plCategory" => array("fai"=> array("description" => _("FAI"),
975 "objectClass" => "FAIclass")),
976 "plProvidedAcls"=> array()));
977 }
978 }
979 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
980 ?>