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;
59 var $start_pasting_copied_objects = FALSE;
60 var $CopyPasteHandler = FALSE;
62 /* construction/reconstruction
63 */
64 function faiManagement ($config, $ui)
65 {
66 /* Set defaults */
67 $this->dn = "";
68 $this->config = $config;
69 $this->ui = $ui;
71 /* Creat dialog object */
72 $this->DivListFai = new divListFai($this->config,$this);
73 }
75 function execute()
76 {
77 /* Call parent execute */
78 plugin::execute();
80 /* Initialise vars and smarty */
81 $smarty = get_smarty();
82 $smarty->assign("BranchName","");
84 $display = "";
85 $s_action = "";
86 $s_entry = "";
88 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
89 $_SESSION['LOCK_VARS_TO_USE'] = array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/");
92 /****************
93 Handle posts
94 ****************/
96 /* Check ImageButton posts
97 * Create new tab ich new_xx is posted
98 */
99 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
100 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
101 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
102 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
103 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
104 "/edit_continue/"=>"select_class_name_finished",
105 "/^multiple_copy_fai/" => "copy_multiple",
106 "/^multiple_cut_fai/" => "cut_multiple",
107 "/^remove_multiple_fai_objects/" => "del_multiple");
109 foreach($_POST as $name => $value){
110 foreach($posts as $reg => $act ){
111 if(preg_match($reg,$name)){
112 $s_action = $act;
113 }
114 }
115 if(preg_match("/^entry_edit_.*/",$name)){
116 $s_entry = preg_replace("/^entry_edit_/","",$name);
117 $s_entry = preg_replace("/_.*$/","",$s_entry);
118 $s_action = "edit";
119 }elseif(preg_match("/^entry_delete_.*/",$name)){
120 $s_entry = preg_replace("/^entry_delete_/","",$name);
121 $s_entry = preg_replace("/_.*$/","",$s_entry);
122 $s_action = "delete";
123 }
124 }
126 if(isset($_GET['edit_entry'])){
127 $s_entry = $_GET['edit_entry'];
128 $s_action = "edit";
129 }
131 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
132 $this->dispNewBranch = false;
133 $this->dispNewFreeze = false;
134 }
137 $type_acl_mapping = array(
138 "FAIpartitionTable" => "faiPartitionTable",
139 "FAIpackageList" => "faiPackage",
140 "FAIscript" => "faiScript",
141 "FAIvariable" => "faiVariable",
142 "FAIhook" => "faiHook",
143 "FAIprofile" => "faiProfile",
144 "FAItemplate" => "faiTemplate");
146 /****************
147 Delete confirme dialog
148 ****************/
150 if ($s_action=="delete"){
152 /* Get 'dn' from posted termlinst */
153 $this->dn= $this->objects[$s_entry]['dn'];
155 /* Load permissions for selected 'dn' and check if
156 we're allowed to remove this 'dn' */
157 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
158 if(preg_match("/d/",$acl)){
160 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
161 if (($user= get_lock($this->dn)) != ""){
162 return(gen_locked_message ($user, $this->dn));
163 }
165 /* Lock the current entry, so nobody will edit it during deletion */
166 add_lock ($this->dn, $this->ui->dn);
167 $smarty->assign("warning", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
168 $smarty->assign("multiple", false);
169 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
170 } else {
172 /* Obviously the user isn't allowed to delete. Show message and
173 clean session. */
174 print_red (_("You are not allowed to delete this component!"));
175 }
176 }
179 /********************
180 Delete MULTIPLE entries requested, display confirm dialog
181 ********************/
183 if ($s_action=="del_multiple"){
184 $this->dns = array();
185 $ids = $this->list_get_selected_items();
187 if(count($ids)){
189 foreach($ids as $id){
190 $dn = $this->objects[$id]['dn'];
191 if (($user= get_lock($dn)) != ""){
192 return(gen_locked_message ($user, $dn));
193 }
194 $this->dns[$id] = $dn;
195 }
197 $dns_names = "<br><pre>";
198 foreach($this->dns as $dn){
199 add_lock ($dn, $this->ui->dn);
200 $dns_names .= $dn."\n";
201 }
202 $dns_names .="</pre>";
204 /* Lock the current entry, so nobody will edit it during deletion */
205 if (count($this->dns) == 1){
206 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
207 } else {
208 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
209 }
210 $smarty->assign("multiple", true);
211 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
212 }
213 }
216 /********************
217 Delete MULTIPLE entries confirmed
218 ********************/
220 /* Confirmation for deletion has been passed. Users should be deleted. */
221 if (isset($_POST['delete_multiple_fai_object_confirm'])){
223 /* Find out more about the object type */
224 $ldap = $this->config->get_ldap_link();
226 /* Remove user by user and check acls before removeing them */
227 foreach($this->dns as $key => $dn){
229 $ldap->cat($dn, array('objectClass'));
230 $attrs = $ldap->fetch();
231 $type = $this->get_type($attrs);
233 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
234 if(preg_match("/d/",$acl)){
236 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
237 $this->dialog->set_acl_base($dn);
238 $this->dialog->by_object[$type[1]]->remove_from_parent ();
239 unset ($this->dialog);
240 $this->dialog= NULL;
241 $to_del = clean_up_releases($dn);
242 save_release_changes_now();
244 foreach($to_del as $dn){
245 $ldap->rmdir_recursive($dn);
246 }
248 } else {
250 /* Normally this shouldn't be reached, send some extra
251 logs to notify the administrator */
252 print_red (_("You are not allowed to delete this component!"));
253 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick 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 $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 }
319 } else {
321 /* Normally this shouldn't be reached, send some extra
322 logs to notify the administrator */
323 print_red (_("You are not allowed to delete this component!"));
324 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
325 }
327 }else{
328 print_red(sprintf(_("Object could not be deleted '%s', object does not exist."),$this->dn));
329 }
330 /* Remove lock file after successfull deletion */
331 del_lock ($this->dn);
332 }
335 /****************
336 Edit entry
337 ****************/
339 if(($s_action == "edit") && (!isset($this->dialog->config))){
340 $entry = $this->objects[$s_entry];
341 $a_setup = $this->get_type($entry);
342 $this->dn = $entry['dn'];
344 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
345 if (($user= get_lock($this->dn)) != ""){
346 return(gen_locked_message ($user, $this->dn));
347 }
348 add_lock ($this->dn, $this->ui->dn);
350 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
351 $this->dialog->set_acl_base($this->dn);
352 $this->is_dialog = true;
354 if($entry['FAIstate'] == "freeze"){
355 #$this->dialog->set_acl(array("*none*")) ;
356 echo "Dawn it is freezed.";
357 }
358 $_SESSION['objectinfo'] = $this->dn;
359 }
362 /* Branch handling
363 09.01.2006
364 */
366 /****************
367 Remove branch
368 ****************/
370 /* Remove branch
371 */
372 if($s_action == "remove_branch"){
373 $base= $this->DivListFai->selectedBranch;
375 /* Load permissions for selected 'dn' and check if
376 we're allowed to remove this 'dn' */
377 $this->set_acl_base($base);
378 if($this->acl_is_removeable()){
380 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
381 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
382 } else {
383 print_red (_("You are not allowed to delete this release!"));
384 }
385 }
388 /****************
389 Remove branch confirmed
390 ****************/
392 if(isset($_POST['delete_branch_confirm'])){
393 $bb = $this->DivListFai->selectedBranch;
394 if(!isset($ldap)){
395 $ldap = $this->config->get_ldap_link();
396 }
398 $br = $this->getBranches();
400 if(isset($br[$bb]) && $this->acl_is_removeable()){
401 $name = $br[$bb];
402 $ldap->cd($bb);
403 $ldap->recursive_remove();
404 $ldap->cd(preg_replace('/,ou=fai,ou=configs,ou=systems,/', ',ou=apps,', $bb));
405 $ldap->recursive_remove();
406 $this->DivListFai->selectedBranch = "main";
408 /* Post remove */
409 $this->lock_name = $name;
410 $this->lock_dn = $bb;
411 $this->postremove();
413 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
414 }
415 }
418 /****************
419 Create a new branch "insert Name"
420 ****************/
422 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
423 $_SESSION['LASTPOST'] = $_POST;
425 if($this->dispNewBranch){
426 $type = "branch";
427 }else{
428 $type = "freeze";
429 }
431 /* Check branch name */
432 $name = $_POST['BranchName'];
433 $is_ok = true;
434 $smarty->assign("BranchName",$name);
435 $base= "ou=fai,ou=configs,ou=systems,".$this->DivListFai->selectedBase;
437 /* Check used characters */
438 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
439 if($type == "branch"){
440 print_red(_("Specified branch name is invalid."));
441 }else{
442 print_red(_("Specified freeze name is invalid."));
443 }
444 $is_ok = false;
445 }
447 /* Check if this name is already in use */
448 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
449 print_red(_("This name is already in use."));
450 $is_ok = false;
451 }
453 if($is_ok){
454 $_SESSION['LASTPOST']['base'] = $base;
455 $_SESSION['LASTPOST']['type'] = $type;
456 $smarty->assign("iframe", true);
457 $smarty->assign("plugID", $_GET['plug']);
458 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
459 return($display);
460 }
461 }
464 /****************
465 Create a new branch
466 ****************/
468 if(isset($_GET['PerformBranch'])){
470 if(!$this->acl_is_createable()){
471 print_red(_("You are not allowed to create a new branch."));
472 }else{
474 /* Create it know */
475 $this->dispNewBranch = false;
476 $this->dispNewFreeze = false;
477 $base = $_SESSION['LASTPOST']['base'];
478 $_POST = $_SESSION['LASTPOST'];
479 $name = $_POST['BranchName'];
481 $type = $_SESSION['LASTPOST']['type'];
482 $ldap = $this->config->get_ldap_link();
484 $baseToUse = $base;
485 if($this->DivListFai->selectedBranch != "main" ){
486 $baseToUse = $this->DivListFai->selectedBranch;
487 }
489 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
491 $CurrentReleases = $this->getBranches();
492 $NewReleaseName = $name;
493 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
494 if($this->DivListFai->selectedBranch != "main"){
495 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
496 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
497 }else{
498 $NewReleaseName = $name;
499 }
500 }
502 $appsrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,",$baseToUse);
503 $appdst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=apps,","ou=".$name.",".$baseToUse) ;
505 $mimesrc = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,",$baseToUse);
506 $mimedst = preg_replace("/ou=fai,ou=configs,ou=systems,/","ou=mime,","ou=".$name.",".$baseToUse) ;
508 /* Print header to have styles included */
509 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
510 <html>
511 <head>
512 <title></title>
513 <style type="text/css">@import url("themes/default/style.css");</style>
514 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
515 </head>
516 <body style="background: none;margin:3px;color:black">
517 ';
519 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
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 ?>