451f6d0e06bf8c2f4f23fc9b96282d71b51b7a00
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 */
22 class faiManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "FAI";
26 var $plDescription = "Fully Automatic Installation - management";
28 /* Headpage attributes */
29 var $lock_type = ""; // should be branch/freeze
30 var $lock_name = "";
31 var $lock_dn = "";
33 /* attribute list for save action */
34 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
35 var $objectclasses= array(); // ObjectClasses which the attributes are related to
36 var $dialog = array(); // This object contains every dialog we have currently opened
38 var $objects = array(); // This array contains all available objects shown in divlist
39 var $is_dialog = false;
41 var $dispNewBranch= false;
42 var $dispNewFreeze= false;
44 var $DivListFai;
45 var $start_pasting_copied_objects = FALSE;
46 var $CopyPasteHandler = FALSE;
47 var $base = "";
49 /* construction/reconstruction
50 */
51 function faiManagement (&$config, $ui)
52 {
53 /* Set defaults */
54 $this->dn = "";
55 $this->config = $config;
56 $this->ui = $ui;
58 /* Creat dialog object */
59 $this->DivListFai = new divListFai($this->config,$this);
61 /* Copy & Paste handler */
62 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
63 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
64 }
65 }
67 function execute()
68 {
69 /* Call parent execute */
70 plugin::execute();
72 /* Initialise vars and smarty */
73 $smarty = get_smarty();
74 $smarty->assign("BranchName","");
76 $display = "";
77 $s_action = "";
78 $s_entry = "";
80 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
81 session::set('LOCK_VARS_TO_USE',array("/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/"));
84 /****************
85 Handle posts
86 ****************/
88 /* Check ImageButton posts
89 * Create new tab ich new_xx is posted
90 */
91 $posts = array( "/remove_branch/"=>"remove_branch", "/branch_branch/"=>"branch_branch",
92 "/freeze_branch/"=>"freeze_branch", "/create_partition/i"=>"new_partition",
93 "/create_script/i"=>"new_script", "/create_hook/i"=>"new_hook",
94 "/create_variable/i"=>"new_variable", "/create_template/i"=>"new_template",
95 "/create_package/i"=>"new_package", "/create_profile/i"=>"new_profile",
96 "/edit_continue/"=>"select_class_name_finished",
97 "/^multiple_copy_fai/" => "copy_multiple",
98 "/^multiple_cut_fai/" => "cut_multiple",
99 "/^copy/" => "copy",
100 "/^cut/" => "cut",
101 "/^remove_multiple_fai_objects/" => "del_multiple");
103 foreach($_POST as $name => $value){
104 foreach($posts as $reg => $act ){
105 if(preg_match($reg,$name)){
106 $s_action = $act;
107 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
108 $s_entry = preg_replace("/_.*$/","",$s_entry);
109 }
110 }
111 if(preg_match("/^entry_edit_.*/",$name)){
112 $s_entry = preg_replace("/^entry_edit_/","",$name);
113 $s_entry = preg_replace("/_.*$/","",$s_entry);
114 $s_action = "edit";
115 }elseif(preg_match("/^entry_delete_.*/",$name)){
116 $s_entry = preg_replace("/^entry_delete_/","",$name);
117 $s_entry = preg_replace("/_.*$/","",$s_entry);
118 $s_action = "delete";
119 }
120 }
122 if(isset($_GET['edit_entry'])){
123 $s_entry = $_GET['edit_entry'];
124 $s_action = "edit";
125 }
127 if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
128 $s_action = "freeze_branch";
129 }
130 if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
131 $s_action = "branch_branch";
132 }
133 if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
134 $s_action = "remove_branch";
135 }
137 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
138 $this->dispNewBranch = false;
139 $this->dispNewFreeze = false;
140 }
143 $type_acl_mapping = array(
144 "FAIpartitionTable" => "faiPartitionTable",
145 "FAIpackageList" => "faiPackage",
146 "FAIscript" => "faiScript",
147 "FAIvariable" => "faiVariable",
148 "FAIhook" => "faiHook",
149 "FAIprofile" => "faiProfile",
150 "FAItemplate" => "faiTemplate");
153 /* handle C&P from layers menu */
154 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
155 $s_action = "copy_multiple";
156 }
157 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
158 $s_action = "cut_multiple";
159 }
160 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
161 $s_action = "editPaste";
162 }
164 /* Create options */
165 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
166 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
167 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
168 }
170 /* handle remove from layers menu */
171 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
172 $s_action = "del_multiple";
173 }
175 /********************
176 Copy & Paste
177 ********************/
179 /* Display the copy & paste dialog, if it is currently open */
180 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
181 if($ret){
182 return($ret);
183 }
186 /****************
187 Delete confirme dialog
188 ****************/
190 if ($s_action=="delete"){
192 /* Get 'dn' from posted termlinst */
193 $this->dn= $this->objects[$s_entry]['dn'];
195 /* Load permissions for selected 'dn' and check if
196 we're allowed to remove this 'dn' */
197 $acl = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
198 if(preg_match("/d/",$acl)){
200 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
201 if (($user= get_lock($this->dn)) != ""){
202 return(gen_locked_message ($user, $this->dn));
203 }
205 /* Lock the current entry, so nobody will edit it during deletion */
206 add_lock ($this->dn, $this->ui->dn);
207 $smarty->assign("warning",msgPool::deleteInfo(@LDAP::fix($this->dn),_("FAI object")));
208 $smarty->assign("multiple", false);
209 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
210 } else {
212 /* Obviously the user isn't allowed to delete. Show message and clean session. */
213 msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
214 }
215 }
218 /********************
219 Delete MULTIPLE entries requested, display confirm dialog
220 ********************/
222 if ($s_action=="del_multiple"){
223 $this->dns = array();
224 $ids = $this->list_get_selected_items();
226 if(count($ids)){
228 $errors = "";
229 foreach($ids as $id){
230 $dn = $this->objects[$id]['dn'];
231 $cn = $this->objects[$id]['cn'];
232 if($this->objects[$id]['FAIstate'] != "freeze"){
233 $this->dns[$id] = $dn;
234 }else{
235 $errors .= $cn.", ";
236 }
237 }
238 if ($user= get_multiple_locks($this->dns)){
239 return(gen_locked_message($user,$this->dns));
240 }
242 if($errors != ""){
243 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
244 "<br><br>".trim($errors,", ")),INFO_DIALOG);
245 }
247 if(count($this->dns)){
249 $dns_names = array();
250 foreach($this->dns as $dn){
251 add_lock ($dn, $this->ui->dn);
252 $dns_names[] = @LDAP::fix($dn);
253 }
255 /* Lock the current entry, so nobody will edit it during deletion */
256 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
257 $smarty->assign("multiple", true);
258 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
259 }
260 }
261 }
264 /********************
265 Delete MULTIPLE entries confirmed
266 ********************/
268 /* Confirmation for deletion has been passed. Users should be deleted. */
269 if (isset($_POST['delete_multiple_fai_object_confirm'])){
271 /* Find out more about the object type */
272 $ldap = $this->config->get_ldap_link();
274 /* Remove user by user and check acls before removeing them */
275 foreach($this->dns as $key => $dn){
277 $ldap->cat($dn, array('objectClass'));
278 $attrs = $ldap->fetch();
279 $type = $this->get_type($attrs);
281 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
282 if(preg_match("/d/",$acl)){
284 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
285 $this->dialog->set_acl_base($dn);
286 $this->dialog->by_object[$type[1]]->remove_from_parent ();
287 unset ($this->dialog);
288 $this->dialog= FALSE;
289 $to_del = FAI::clean_up_releases($dn);
290 FAI::save_release_changes_now();
292 foreach($to_del as $dn){
293 $ldap->rmdir_recursive($dn);
294 }
296 } else {
298 /* Normally this shouldn't be reached, send some extra
299 logs to notify the administrator */
300 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
301 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
302 }
304 /* Remove lock file after successfull deletion */
305 del_lock ($dn);
306 unset($this->dns[$key]);
307 }
308 }
311 /********************
312 Delete MULTIPLE entries Canceled
313 ********************/
315 /* Remove lock */
316 if(isset($_POST['delete_multiple_fai_object_cancel'])){
317 foreach($this->dns as $key => $dn){
318 del_lock ($dn);
319 unset($this->dns[$key]);
320 }
321 }
324 /****************
325 Delete aborted
326 ****************/
328 /* Delete canceled? */
329 if (isset($_POST['delete_cancel'])){
330 del_lock ($this->dn);
331 }
334 /****************
335 Delete confirmed
336 ****************/
338 /* Deltetion was confirmed, so delete this entry
339 */
340 if (isset($_POST['delete_terminal_confirm'])){
342 /* Some nice guy may send this as POST, so we've to check
343 for the permissions again. */
345 /* Find out more about the object type */
346 $ldap = $this->config->get_ldap_link();
347 $ldap->cat($this->dn, array('objectClass'));
348 if($ldap->count()){
349 $attrs = $ldap->fetch();
350 $type = $this->get_type($attrs);
352 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
353 if(preg_match("/d/",$acl)){
355 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
356 $this->dialog->set_acl_base($this->dn);
357 $this->dialog->by_object[$type[1]]->remove_from_parent ();
358 unset ($this->dialog);
359 $this->dialog= FALSE;
360 $to_del = FAI::clean_up_releases($this->dn);
361 FAI::save_release_changes_now();
363 foreach($to_del as $dn){
364 $ldap->rmdir_recursive($dn);
365 }
367 } else {
369 /* Normally this shouldn't be reached, send some extra
370 logs to notify the administrator */
371 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
372 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
373 }
375 }else{
376 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
377 }
378 /* Remove lock file after successfull deletion */
379 del_lock ($this->dn);
380 }
383 /****************
384 Edit entry
385 ****************/
387 if(($s_action == "edit") && (!isset($this->dialog->config))){
388 $entry = $this->objects[$s_entry];
389 $a_setup = $this->get_type($entry);
390 $this->dn = $entry['dn'];
392 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
393 if (($user= get_lock($this->dn)) != ""){
394 return(gen_locked_message ($user, $this->dn));
395 }
396 add_lock ($this->dn, $this->ui->dn);
398 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
399 $this->dialog->set_acl_base($this->dn);
400 $this->is_dialog = true;
402 if($entry['FAIstate'] == "freeze"){
403 #$this->dialog->set_acl(array("*none*")) ;
404 }
405 session::set('objectinfo',$this->dn);
406 }
409 /* Branch handling
410 09.01.2006
411 */
413 /****************
414 Remove branch
415 ****************/
417 /* Remove branch
418 */
419 if($s_action == "remove_branch"){
420 $base= $this->DivListFai->selectedBranch;
422 /* Check if we have a post remove method configured
423 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
424 */
425 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
426 /* Load permissions for selected 'dn' and check if
427 we're allowed to remove this 'dn' */
428 if($this->acl_is_removeable()){
430 $smarty->assign("info", msgPool::deleteInfo(@LDAP::fix($this->DivListFai->selectedBranch),_("FAI branch/freeze")));
431 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
432 } else {
433 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
434 }
435 }
436 }
439 /****************
440 Remove branch confirmed
441 ****************/
443 if(isset($_POST['delete_branch_confirm'])){
445 /* Check if we have a post remove method configured
446 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
447 */
448 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
450 $bb = $this->DivListFai->selectedBranch;
451 if(!isset($ldap)){
452 $ldap = $this->config->get_ldap_link();
453 }
455 $br = $this->getBranches();
457 if(isset($br[$bb]) && $this->acl_is_removeable()){
458 $name = $br[$bb];
459 $ldap->cd($bb);
460 $ldap->recursive_remove();
461 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
462 $ldap->recursive_remove();
463 $this->DivListFai->selectedBranch = "main";
465 /* Post remove */
466 $this->lock_name = $name;
467 $this->lock_dn = $bb;
468 $this->postremove();
470 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
471 }
472 }
473 }
476 /****************
477 Create a new branch "insert Name"
478 ****************/
480 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
481 session::set('LASTPOST',$_POST);
483 if($this->dispNewBranch){
484 $type = "branch";
485 }else{
486 $type = "freeze";
487 }
489 /* Check branch name */
490 $name = $_POST['BranchName'];
491 $is_ok = true;
492 $smarty->assign("BranchName",$name);
493 $base= get_ou('faiou').$this->DivListFai->selectedBase;
495 /* Check used characters */
496 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
497 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z \ö\ä\ü\.-_:,]/i"), ERROR_DIALOG);
498 $is_ok = false;
499 }
501 /* Check if this name is already in use */
502 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
503 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
504 $is_ok = false;
505 }
507 if($is_ok){
509 if(session::is_set('LASTPOST')){
510 $LASTPOST = session::get('LASTPOST');
511 }else{
512 $LASTPOST = array();
513 }
514 $LASTPOST['base'] = $base;
515 $LASTPOST['type'] = $type;
516 session::set('LASTPOST',$LASTPOST);
517 $smarty->assign("iframe", true);
518 $smarty->assign("plugID", $_GET['plug']);
519 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
520 return($display);
521 }
522 }
525 /****************
526 Create a new branch
527 ****************/
529 if(isset($_GET['PerformBranch'])){
531 if(!$this->acl_is_createable()){
532 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
533 }else{
535 /* Create it know */
536 $this->dispNewBranch = false;
537 $this->dispNewFreeze = false;
539 $LASTPOST = session::get('LASTPOST');
540 $base = $LASTPOST['base'];
541 $_POST = session::get('LASTPOST');
542 $name = $_POST['BranchName'];
544 $type = $LASTPOST['type'];
545 $ldap = $this->config->get_ldap_link();
547 $baseToUse = $base;
548 if($this->DivListFai->selectedBranch != "main" ){
549 $baseToUse = $this->DivListFai->selectedBranch;
550 }
552 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
554 $CurrentReleases = $this->getBranches();
555 $NewReleaseName = $name;
556 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
557 if($this->DivListFai->selectedBranch != "main"){
558 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
559 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
560 }else{
561 $NewReleaseName = $name;
562 }
563 }
565 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
566 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
568 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
569 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
571 /* Check if source depeartments exist */
572 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
573 $ldap->cd($this->config->current['BASE']);
574 $ldap->cat($dep);
575 if(!$ldap->count()){
576 $ldap->create_missing_trees($dep);
577 }
578 }
580 /* Print header to have styles included */
581 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
582 <html>
583 <head>
584 <title></title>
585 <style type="text/css">@import url("themes/default/style.css");</style>
586 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
587 </head>
588 <body style="background: none;margin:3px;color:black">
589 ';
591 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
593 /* Duplicate group application releases
594 */
595 FAI::copy_FAI_group_releases($CurrentReleases[$this->DivListFai->selectedBranch],$name,$type);
597 /* Duplicate applications
598 */
599 $ldap->cat($appsrc,array("dn")) ;
600 if($ldap->count()){
601 $ldap->cd ($appdst);
602 $ldap->recursive_remove();
603 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
604 }
606 /* Duplicate mime types
607 */
608 $ldap->cat($mimesrc,array("dn")) ;
609 if($ldap->count()){
610 $ldap->cd ($mimedst);
611 $ldap->recursive_remove();
612 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
613 }
615 $attr = array();
616 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
617 $attr['ou'] = $name;
618 $attr['FAIstate'] = $type;
619 $ldap->cd($this->config->current['BASE']);
620 $ldap->cd("ou=".$name.",".$baseToUse);
621 $ldap->cat("ou=".$name.",".$baseToUse);
622 if($ldap->count()){
623 $ldap->modify($attr);
624 }else{
625 $ldap->add($attr);
626 }
628 /* Duplicate fai objects
629 */
630 // $ldap->cd ("ou=".$name.",".$baseToUse);
631 // $ldap->recursive_remove();
632 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
634 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
635 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
636 </form></div>";
638 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
640 /* Print footer to have valid html */
641 echo "</body></html>";
643 $this->dispNewFreeze = false;
645 /* Postcreate */
647 /* Assign possible attributes */
648 $this->lock_type = $type;
649 $this->lock_name = $name;
650 $this->lock_dn = $baseToUse;
651 $this->postcreate();
652 exit();
653 }
654 }
656 /****************
657 Display dialog to enter new Branch name
658 ****************/
660 /* Check if we have a post create method configured
661 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
662 */
663 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
664 if(($s_action == "branch_branch")||($this->dispNewBranch)){
665 if(!$this->acl_is_createable()){
666 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
667 }else{
668 $this->dispNewBranch=true;
669 $smarty->assign("iframe",false);
670 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
671 return($display);
672 }
673 }
674 }
677 /****************
678 Display dialog to enter new Freeze name
679 ****************/
681 /* Check if we have a post create method configured
682 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
683 */
684 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
685 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
686 if(!$this->acl_is_createable()){
687 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
688 }else{
689 $this->dispNewFreeze = true;
690 $smarty->assign("iframe",false);
691 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
692 return($display);
693 }
694 }
695 }
698 /****************
699 Create a new object
700 ****************/
702 $types = array( "new_partition" => "FAIpartitionTable",
703 "new_script" => "FAIscript",
704 "new_hook" => "FAIhook",
705 "new_variable" => "FAIvariable",
706 "new_template" => "FAItemplate",
707 "new_package" => "FAIpackageList");
708 $types_i18n = array( "new_partition" => _("partition table"),
709 "new_script" => _("script"),
710 "new_hook" => _("hook"),
711 "new_variable" => _("variable"),
712 "new_template" => _("template"),
713 "new_package" => _("package list"));
715 if(isset($types[$s_action])){
716 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
717 if(preg_match("/c/",$acl)){
718 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
719 }else{
720 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
721 }
722 }
724 /* New Profile */
725 if($s_action == "new_profile"){
726 $this->dn = "new" ;
728 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
729 if(preg_match("/c/",$acl)){
730 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
731 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
732 $this->dialog->set_acl_base($this->base);
734 $this->is_dialog = false;
735 }else{
736 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
737 }
738 }
741 /****************
742 Get from ask class name dialog
743 ****************/
745 if($s_action == "select_class_name_finished"){
746 $this->dialog->save_object();
747 if(count($this->dialog->check())!=0){
748 foreach($this->dialog->check() as $msg){
749 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
750 }
751 }elseif(isset($this->dialog->objectClass)){
752 $this->dn = "new" ;
753 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
754 $name = $this->dialog->save();
756 if(class_exists($a_setup[0])){
757 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
758 $this->dialog->set_acl_base($this->base);
759 $this->dialog->by_object[$a_setup[1]]->cn = $name;
760 $this->is_dialog = true;
761 }
762 }
763 }
766 /****************
767 Cancel dialogs
768 ****************/
770 if(isset($_POST['edit_cancel'])){
771 unset($this->dialog);
772 $this->dialog=FALSE;
773 $this->is_dialog = false;
774 session::un_set('objectinfo');
775 del_lock ($this->dn);
776 }
779 /****************
780 Save sub dialogs
781 ****************/
783 /* This check if the given tab could be saved
784 * If it was possible to save it, remove dialog object.
785 * If it wasn't possible, show errors and keep dialog.
786 */
787 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
788 $this->dialog->save_object();
789 $msgs= $this->dialog->check();
790 if(count($msgs)!=0){
791 foreach($msgs as $msg){
792 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
793 }
794 }else{
795 $this->dialog->save();
796 FAI::save_release_changes_now();
797 if (!isset($_POST['edit_apply'])){
798 del_lock ($this->dn);
799 unset($this->dialog);
800 $this->dialog=FALSE;
801 $this->is_dialog=false;
802 session::un_set('objectinfo');
803 }
804 }
805 }
808 /****************
809 Display currently open dialog
810 ****************/
812 /* If dialog is set, but $this->is_dialog==false, then
813 * only the "abort" button is shown, this are dialogs that must not be saved.
814 * If is_dialog == true, we are currently editing tab objects.
815 * Here we need both, save and cancel
816 */
818 if(is_object($this->dialog)){
819 $display .= $this->dialog->execute();
820 /* Don't show buttons if tab dialog requests this */
822 if(isset($this->dialog->current)){
824 $obj = $this->dialog->by_object[$this->dialog->current];
826 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
828 $display.= "<p style=\"text-align:right\">\n";
829 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
830 $display.= " \n";
831 if ($this->dn != "new"){
832 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
833 $display.= " \n";
834 }
835 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
836 $display.= "</p>";
837 }elseif(!isset($this->dialog->current)){
838 $display.= "<p style=\"text-align:right\">\n";
839 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
840 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
841 $display.= "</p>";
842 }
843 }else{
844 $display.= "<p style=\"text-align:right\">\n";
845 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
846 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
847 $display.= "</p>";
849 }
850 return($display);
851 }
854 /****************
855 Dialog display
856 ****************/
858 /* Check if there is a snapshot dialog open */
859 $base = $this->DivListFai->selectedBase;
860 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
861 return($str);
862 }
864 /* Display dialog with system list */
865 $this->DivListFai->parent = $this;
866 $this->DivListFai->execute();
867 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
868 $this->reload();
869 $this->DivListFai->setEntries($this->objects);
870 return($this->DivListFai->Draw());
871 }
874 /* Return departments, that will be included within snapshot detection */
875 function get_used_snapshot_bases()
876 {
877 $tmp = array();
878 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
879 foreach($types as $type){
880 if($this->DivListFai->selectedBranch == "main"){
881 $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase;
882 }else{
883 $tmp[] = get_ou($type).$this->DivListFai->selectedBranch;
884 }
885 }
886 return($tmp);
887 }
890 /* Get available branches for current base */
891 function getBranches($base = false,$prefix = "")
892 {
893 $ret = array("/"=>"main");
894 $ldap = $this->config->get_ldap_link();
895 if(!$base){
896 $base = session::get('CurrentMainBase');
897 }
898 $tmp = FAI::get_all_releases_from_base($base,true);
899 foreach($tmp as $dn => $name){
900 $ret[$name]=$dn;
901 }
902 ksort($ret);
903 $ret = array_flip($ret);
905 return ($ret);
906 }
909 function list_get_selected_items()
910 {
911 $ids = array();
912 foreach($_POST as $name => $value){
913 if(preg_match("/^item_selected_[0-9]*$/",$name)){
914 $id = preg_replace("/^item_selected_/","",$name);
915 $ids[$id] = $id;
916 }
917 }
918 return($ids);
919 }
922 /* reload list of objects */
923 function reload()
924 {
925 /* Variable initialisation */
926 $str = "";
927 $Regex = $this->DivListFai->Regex;
928 $this->objects = array();
930 /* Get base */
931 $base = get_ou('faiou').$this->DivListFai->selectedBase;
932 if($this->DivListFai->selectedBranch != "main"){
933 $br = $this->getBranches();
934 if(isset($br[$this->DivListFai->selectedBranch])){
935 $base = $this->DivListFai->selectedBranch;
936 }else{
937 $base = get_ou('faiou').$this->DivListFai->selectedBase;
938 }
939 }
940 $this->base = $base;
941 $this->set_acl_base($this->base);
943 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
945 /* Create a new list of FAI object
946 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
947 */
948 $ObjectTypes = array(
949 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
950 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
951 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
952 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
953 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
954 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
955 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
957 $filter = "";
958 foreach($ObjectTypes as $key => $data){
959 if($this->DivListFai->$data['CHKBOX']){
960 $filter.= "(objectClass=".$key.")";
961 }
962 }
963 $filter = "(&(|".$filter.")(cn=$Regex))";
965 /* Get resolved release dependencies */
966 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
968 /* Ge listed ldap objects */
969 $ldap = $this->config->get_ldap_link();
970 $ldap->cd($this->config->current['BASE']);
971 foreach($tmp as $entry){
973 /* Get some more informations about the object */
974 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
975 $object = $ldap->fetch();
977 /* Walk through possible types */
978 foreach($ObjectTypes as $type => $rest){
980 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
982 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
984 /* Prepare object */
985 unset($object['objectClass']['count']);
986 if(!isset($object['description'][0])){
987 $object['description'][0]="";
988 }
990 /* Clean up object informations */
991 $obj = array();
992 $obj['cn'] = $object['cn'][0];
993 $obj['dn'] = $object['dn'];
994 $obj['acl'] = $acl;
995 $obj['description'] = $object['description'][0];
996 $obj['objectClass'] = $object['objectClass'];
998 /* Append type to this string, to be able to check if the selected
999 * entry is of type 'freeze' or 'branch'
1000 */
1001 if(!isset($object['FAIstate'])){
1002 $obj['FAIstate'] = $this->lock_type;
1003 }else{
1004 $obj['FAIstate'] = $object['FAIstate'][0];
1005 }
1007 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1008 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1009 }
1010 }
1011 }
1013 ksort($this->objects);
1014 reset ($this->objects);
1016 /* use numeric index, thats a bit more secure */
1017 $tmp0 = array();
1018 foreach($this->objects as $obj){
1019 $tmp0[]= $obj;
1020 }
1021 $this->objects = array();
1022 $this->objects = $tmp0;
1023 }
1025 function remove_lock()
1026 {
1027 if (isset($this->dn)){
1028 del_lock ($this->dn);
1029 }
1030 }
1032 function get_type($array){
1033 if(in_array("FAIpartitionTable",$array['objectClass'])){
1034 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1035 }
1036 if(in_array("FAIscript",$array['objectClass'])){
1037 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1038 }
1039 if(in_array("FAItemplate",$array['objectClass'])){
1040 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1041 }
1042 if(in_array("FAIhook",$array['objectClass'])){
1043 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1044 }
1045 if(in_array("FAIvariable",$array['objectClass'])){
1046 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1047 }
1048 if(in_array("FAIprofile",$array['objectClass'])){
1049 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1050 }
1052 if(in_array("FAIpackageList",$array['objectClass'])){
1053 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1054 }
1055 }
1057 function CheckNewBranchName($name,$base)
1058 {
1059 $f = $this->DivListFai->selectedBranch;
1060 if($name == ""){
1061 return(false);
1062 }elseif(in_array($name,$this->getBranches($f))) {
1063 return(false);
1064 }elseif(tests::is_department_name_reserved($name,$base)){
1065 return(false);
1066 }
1067 return(true);
1068 }
1070 function save_object()
1071 {
1072 $this->DivListFai->save_object();
1074 if(is_object($this->CopyPasteHandler)){
1075 $this->CopyPasteHandler->save_object();
1076 }
1077 }
1080 function copyPasteHandling_from_queue($s_action,$s_entry)
1081 {
1082 /* Check if Copy & Paste is disabled */
1083 if(!is_object($this->CopyPasteHandler)){
1084 return("");
1085 }
1087 $base = $this->DivListFai->selectedBranch;
1088 if($base == "main"){
1089 $base = $this->DivListFai->selectedBase;
1090 }
1092 /* Add a single entry to queue */
1093 if($s_action == "cut" || $s_action == "copy"){
1095 /* Cleanup object queue */
1096 $this->CopyPasteHandler->cleanup_queue();
1097 $entry = $this->objects[$s_entry];
1098 $a_setup = $this->get_type($entry);
1099 $dn = $entry['dn'];
1100 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1101 }
1103 /* Add entries to queue */
1104 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1106 /* Cleanup object queue */
1107 $this->CopyPasteHandler->cleanup_queue();
1109 /* Add new entries to CP queue */
1110 foreach($this->list_get_selected_items() as $id){
1112 /* Cleanup object queue */
1113 $entry = $this->objects[$id];
1114 $a_setup = $this->get_type($entry);
1115 $dn = $entry['dn'];
1118 if($s_action == "copy_multiple"){
1119 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1120 }
1121 if($s_action == "cut_multiple"){
1122 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1123 }
1124 }
1125 }
1127 /* Start pasting entries */
1128 if($s_action == "editPaste"){
1129 $this->start_pasting_copied_objects = TRUE;
1130 }
1132 /* Return C&P dialog */
1133 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1135 /* Get dialog */
1136 $data = $this->CopyPasteHandler->execute();
1137 $this->CopyPasteHandler->SetVar("base",$base);
1139 FAI::save_release_changes_now();
1141 /* Return dialog data */
1142 if(!empty($data)){
1143 return($data);
1144 }
1145 }
1147 /* Automatically disable status for pasting */
1148 if(!$this->CopyPasteHandler->entries_queued()){
1149 $this->start_pasting_copied_objects = FALSE;
1150 }
1151 return("");
1152 }
1155 /* Return plugin informations for acl handling */
1156 static function plInfo()
1157 {
1158 return (array(
1159 "plShortName" => _("FAI releases"),
1160 "plDescription" => _("FAI release management"),
1161 "plSelfModify" => FALSE,
1162 "plDepends" => array(),
1163 "plPriority" => 0,
1164 "plSection" => array("administration"),
1165 "plCategory" => array("fai"=> array("description" => _("FAI"),
1166 "objectClass" => "FAIclass")),
1167 "plProvidedAcls"=> array()));
1168 }
1169 }
1170 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1171 ?>