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", sprintf(_("You're about to delete all information about the FAI class at '%s'."), @LDAP::fix($this->dn)));
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"), _("You have no permission to delete this entry!"), 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 = "<br><pre>";
250 foreach($this->dns as $dn){
251 add_lock ($dn, $this->ui->dn);
252 $dns_names .= $dn."\n";
253 }
254 $dns_names .="</pre>";
256 /* Lock the current entry, so nobody will edit it during deletion */
257 if (count($this->dns) == 1){
258 $smarty->assign("warning", sprintf(_("You're about to delete the following entry %s"), @LDAP::fix($dns_names)));
259 } else {
260 $smarty->assign("warning", sprintf(_("You're about to delete the following entries %s"), @LDAP::fix($dns_names)));
261 }
262 $smarty->assign("multiple", true);
263 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
264 }
265 }
266 }
269 /********************
270 Delete MULTIPLE entries confirmed
271 ********************/
273 /* Confirmation for deletion has been passed. Users should be deleted. */
274 if (isset($_POST['delete_multiple_fai_object_confirm'])){
276 /* Find out more about the object type */
277 $ldap = $this->config->get_ldap_link();
279 /* Remove user by user and check acls before removeing them */
280 foreach($this->dns as $key => $dn){
282 $ldap->cat($dn, array('objectClass'));
283 $attrs = $ldap->fetch();
284 $type = $this->get_type($attrs);
286 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
287 if(preg_match("/d/",$acl)){
289 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
290 $this->dialog->set_acl_base($dn);
291 $this->dialog->by_object[$type[1]]->remove_from_parent ();
292 unset ($this->dialog);
293 $this->dialog= FALSE;
294 $to_del = FAI::clean_up_releases($dn);
295 FAI::save_release_changes_now();
297 foreach($to_del as $dn){
298 $ldap->rmdir_recursive($dn);
299 }
301 } else {
303 /* Normally this shouldn't be reached, send some extra
304 logs to notify the administrator */
305 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
306 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
307 }
309 /* Remove lock file after successfull deletion */
310 del_lock ($dn);
311 unset($this->dns[$key]);
312 }
313 }
316 /********************
317 Delete MULTIPLE entries Canceled
318 ********************/
320 /* Remove lock */
321 if(isset($_POST['delete_multiple_fai_object_cancel'])){
322 foreach($this->dns as $key => $dn){
323 del_lock ($dn);
324 unset($this->dns[$key]);
325 }
326 }
329 /****************
330 Delete aborted
331 ****************/
333 /* Delete canceled? */
334 if (isset($_POST['delete_cancel'])){
335 del_lock ($this->dn);
336 }
339 /****************
340 Delete confirmed
341 ****************/
343 /* Deltetion was confirmed, so delete this entry
344 */
345 if (isset($_POST['delete_terminal_confirm'])){
347 /* Some nice guy may send this as POST, so we've to check
348 for the permissions again. */
350 /* Find out more about the object type */
351 $ldap = $this->config->get_ldap_link();
352 $ldap->cat($this->dn, array('objectClass'));
353 if($ldap->count()){
354 $attrs = $ldap->fetch();
355 $type = $this->get_type($attrs);
357 $acl = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
358 if(preg_match("/d/",$acl)){
360 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $this->dn,"fai");
361 $this->dialog->set_acl_base($this->dn);
362 $this->dialog->by_object[$type[1]]->remove_from_parent ();
363 unset ($this->dialog);
364 $this->dialog= FALSE;
365 $to_del = FAI::clean_up_releases($this->dn);
366 FAI::save_release_changes_now();
368 foreach($to_del as $dn){
369 $ldap->rmdir_recursive($dn);
370 }
372 } else {
374 /* Normally this shouldn't be reached, send some extra
375 logs to notify the administrator */
376 msg_dialog::display(_("Permission error"), _("You have no permission to delete this entry!"), ERROR_DIALOG);
377 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
378 }
380 }else{
381 msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
382 }
383 /* Remove lock file after successfull deletion */
384 del_lock ($this->dn);
385 }
388 /****************
389 Edit entry
390 ****************/
392 if(($s_action == "edit") && (!isset($this->dialog->config))){
393 $entry = $this->objects[$s_entry];
394 $a_setup = $this->get_type($entry);
395 $this->dn = $entry['dn'];
397 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
398 if (($user= get_lock($this->dn)) != ""){
399 return(gen_locked_message ($user, $this->dn));
400 }
401 add_lock ($this->dn, $this->ui->dn);
403 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
404 $this->dialog->set_acl_base($this->dn);
405 $this->is_dialog = true;
407 if($entry['FAIstate'] == "freeze"){
408 #$this->dialog->set_acl(array("*none*")) ;
409 }
410 session::set('objectinfo',$this->dn);
411 }
414 /* Branch handling
415 09.01.2006
416 */
418 /****************
419 Remove branch
420 ****************/
422 /* Remove branch
423 */
424 if($s_action == "remove_branch"){
425 $base= $this->DivListFai->selectedBranch;
427 /* Check if we have a post remove method configured
428 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
429 */
430 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
431 /* Load permissions for selected 'dn' and check if
432 we're allowed to remove this 'dn' */
433 if($this->acl_is_removeable()){
435 $smarty->assign("info", sprintf(_("You're about to delete a fai branch / freeze '%s'."), $this->DivListFai->selectedBranch));
436 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
437 } else {
438 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
439 }
440 }
441 }
444 /****************
445 Remove branch confirmed
446 ****************/
448 if(isset($_POST['delete_branch_confirm'])){
450 /* Check if we have a post remove method configured
451 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
452 */
453 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
455 $bb = $this->DivListFai->selectedBranch;
456 if(!isset($ldap)){
457 $ldap = $this->config->get_ldap_link();
458 }
460 $br = $this->getBranches();
462 if(isset($br[$bb]) && $this->acl_is_removeable()){
463 $name = $br[$bb];
464 $ldap->cd($bb);
465 $ldap->recursive_remove();
466 $ldap->cd(preg_replace('/,'.normalizePreg(get_ou('faiou')).'/', ','.get_ou('applicationou'), $bb));
467 $ldap->recursive_remove();
468 $this->DivListFai->selectedBranch = "main";
470 /* Post remove */
471 $this->lock_name = $name;
472 $this->lock_dn = $bb;
473 $this->postremove();
475 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
476 }
477 }
478 }
481 /****************
482 Create a new branch "insert Name"
483 ****************/
485 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
486 session::set('LASTPOST',$_POST);
488 if($this->dispNewBranch){
489 $type = "branch";
490 }else{
491 $type = "freeze";
492 }
494 /* Check branch name */
495 $name = $_POST['BranchName'];
496 $is_ok = true;
497 $smarty->assign("BranchName",$name);
498 $base= get_ou('faiou').$this->DivListFai->selectedBase;
500 /* Check used characters */
501 if(preg_match("/[^0-9a-z \ö\ä\ü\.-_:,]/i",$name)){
502 if($type == "branch"){
503 msg_dialog::display(_("Error"), _("Branch name is not valid!"), ERROR_DIALOG);
504 }else{
505 msg_dialog::display(_("Error"), _("Freeze name is not valid!"), ERROR_DIALOG);
506 }
507 $is_ok = false;
508 }
510 /* Check if this name is already in use */
511 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->DivListFai->selectedBranch)){
512 msg_dialog::display(_("Error"), _("Name is already in use!"), ERROR_DIALOG);
513 $is_ok = false;
514 }
516 if($is_ok){
518 if(session::is_set('LASTPOST')){
519 $LASTPOST = session::get('LASTPOST');
520 }else{
521 $LASTPOST = array();
522 }
523 $LASTPOST['base'] = $base;
524 $LASTPOST['type'] = $type;
525 session::set('LASTPOST',$LASTPOST);
526 $smarty->assign("iframe", true);
527 $smarty->assign("plugID", $_GET['plug']);
528 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
529 return($display);
530 }
531 }
534 /****************
535 Create a new branch
536 ****************/
538 if(isset($_GET['PerformBranch'])){
540 if(!$this->acl_is_createable()){
541 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
542 }else{
544 /* Create it know */
545 $this->dispNewBranch = false;
546 $this->dispNewFreeze = false;
548 $LASTPOST = session::get('LASTPOST');
549 $base = $LASTPOST['base'];
550 $_POST = session::get('LASTPOST');
551 $name = $_POST['BranchName'];
553 $type = $LASTPOST['type'];
554 $ldap = $this->config->get_ldap_link();
556 $baseToUse = $base;
557 if($this->DivListFai->selectedBranch != "main" ){
558 $baseToUse = $this->DivListFai->selectedBranch;
559 }
561 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
563 $CurrentReleases = $this->getBranches();
564 $NewReleaseName = $name;
565 if(isset($CurrentReleases[$this->DivListFai->selectedBranch])) {
566 if($this->DivListFai->selectedBranch != "main"){
567 $NewReleaseName = $CurrentReleases[$this->DivListFai->selectedBranch]."/".$name;
568 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
569 }else{
570 $NewReleaseName = $name;
571 }
572 }
574 $appsrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),$baseToUse);
575 $appdst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('applicationou'),"ou=".$name.",".$baseToUse) ;
577 $mimesrc = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),$baseToUse);
578 $mimedst = preg_replace("/".normalizePreg(get_ou('faiou'))."/",get_ou('mimetypeou'),"ou=".$name.",".$baseToUse) ;
580 /* Check if source depeartments exist */
581 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
582 $ldap->cd($this->config->current['BASE']);
583 $ldap->cat($dep);
584 if(!$ldap->count()){
585 $ldap->create_missing_trees($dep);
586 }
587 }
589 /* Print header to have styles included */
590 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
591 <html>
592 <head>
593 <title></title>
594 <style type="text/css">@import url("themes/default/style.css");</style>
595 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
596 </head>
597 <body style="background: none;margin:3px;color:black">
598 ';
600 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
602 /* Duplicate group application releases
603 */
604 FAI::copy_FAI_group_releases($CurrentReleases[$this->DivListFai->selectedBranch],$name,$type);
606 /* Duplicate applications
607 */
608 $ldap->cat($appsrc,array("dn")) ;
609 if($ldap->count()){
610 $ldap->cd ($appdst);
611 $ldap->recursive_remove();
612 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
613 }
615 /* Duplicate mime types
616 */
617 $ldap->cat($mimesrc,array("dn")) ;
618 if($ldap->count()){
619 $ldap->cd ($mimedst);
620 $ldap->recursive_remove();
621 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
622 }
624 $attr = array();
625 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
626 $attr['ou'] = $name;
627 $attr['FAIstate'] = $type;
628 $ldap->cd($this->config->current['BASE']);
629 $ldap->cd("ou=".$name.",".$baseToUse);
630 $ldap->cat("ou=".$name.",".$baseToUse);
631 if($ldap->count()){
632 $ldap->modify($attr);
633 }else{
634 $ldap->add($attr);
635 }
637 /* Duplicate fai objects
638 */
639 // $ldap->cd ("ou=".$name.",".$baseToUse);
640 // $ldap->recursive_remove();
641 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
643 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
644 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
645 </form></div>";
647 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
649 /* Print footer to have valid html */
650 echo "</body></html>";
652 $this->dispNewFreeze = false;
654 /* Postcreate */
656 /* Assign possible attributes */
657 $this->lock_type = $type;
658 $this->lock_name = $name;
659 $this->lock_dn = $baseToUse;
660 $this->postcreate();
661 exit();
662 }
663 }
665 /****************
666 Display dialog to enter new Branch name
667 ****************/
669 /* Check if we have a post create method configured
670 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
671 */
672 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
673 if(($s_action == "branch_branch")||($this->dispNewBranch)){
674 if(!$this->acl_is_createable()){
675 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
676 }else{
677 $this->dispNewBranch=true;
678 $smarty->assign("iframe",false);
679 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
680 return($display);
681 }
682 }
683 }
686 /****************
687 Display dialog to enter new Freeze name
688 ****************/
690 /* Check if we have a post create method configured
691 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
692 */
693 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
694 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
695 if(!$this->acl_is_createable()){
696 msg_dialog::display(_("Permission error"), _("You have no permission to create a new branch!"), ERROR_DIALOG);
697 }else{
698 $this->dispNewFreeze = true;
699 $smarty->assign("iframe",false);
700 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
701 return($display);
702 }
703 }
704 }
707 /****************
708 Create a new object
709 ****************/
711 $types = array( "new_partition" => "FAIpartitionTable",
712 "new_script" => "FAIscript",
713 "new_hook" => "FAIhook",
714 "new_variable" => "FAIvariable",
715 "new_template" => "FAItemplate",
716 "new_package" => "FAIpackageList");
717 $types_i18n = array( "new_partition" => _("partition table"),
718 "new_script" => _("script"),
719 "new_hook" => _("hook"),
720 "new_variable" => _("variable"),
721 "new_template" => _("template"),
722 "new_package" => _("package list"));
724 if(isset($types[$s_action])){
725 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/".$type_acl_mapping[$types[$s_action]]);
726 if(preg_match("/c/",$acl)){
727 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
728 }else{
729 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
730 }
731 }
733 /* New Profile */
734 if($s_action == "new_profile"){
735 $this->dn = "new" ;
737 $acl = $this->ui->get_permissions($this->DivListFai->selectedBase,"fai/faiProfile");
738 if(preg_match("/c/",$acl)){
739 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
740 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
741 $this->dialog->set_acl_base($this->base);
743 $this->is_dialog = false;
744 }else{
745 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
746 }
747 }
750 /****************
751 Get from ask class name dialog
752 ****************/
754 if($s_action == "select_class_name_finished"){
755 $this->dialog->save_object();
756 if(count($this->dialog->check())!=0){
757 foreach($this->dialog->check() as $msg){
758 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
759 }
760 }elseif(isset($this->dialog->objectClass)){
761 $this->dn = "new" ;
762 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
763 $name = $this->dialog->save();
765 if(class_exists($a_setup[0])){
766 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
767 $this->dialog->set_acl_base($this->base);
768 $this->dialog->by_object[$a_setup[1]]->cn = $name;
769 $this->is_dialog = true;
770 }
771 }
772 }
775 /****************
776 Cancel dialogs
777 ****************/
779 if(isset($_POST['edit_cancel'])){
780 unset($this->dialog);
781 $this->dialog=FALSE;
782 $this->is_dialog = false;
783 session::un_set('objectinfo');
784 del_lock ($this->dn);
785 }
788 /****************
789 Save sub dialogs
790 ****************/
792 /* This check if the given tab could be saved
793 * If it was possible to save it, remove dialog object.
794 * If it wasn't possible, show errors and keep dialog.
795 */
796 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
797 $this->dialog->save_object();
798 $msgs= $this->dialog->check();
799 if(count($msgs)!=0){
800 foreach($msgs as $msg){
801 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
802 }
803 }else{
804 $this->dialog->save();
805 FAI::save_release_changes_now();
806 if (!isset($_POST['edit_apply'])){
807 del_lock ($this->dn);
808 unset($this->dialog);
809 $this->dialog=FALSE;
810 $this->is_dialog=false;
811 session::un_set('objectinfo');
812 }
813 }
814 }
817 /****************
818 Display currently open dialog
819 ****************/
821 /* If dialog is set, but $this->is_dialog==false, then
822 * only the "abort" button is shown, this are dialogs that must not be saved.
823 * If is_dialog == true, we are currently editing tab objects.
824 * Here we need both, save and cancel
825 */
827 if(is_object($this->dialog)){
828 $display .= $this->dialog->execute();
829 /* Don't show buttons if tab dialog requests this */
831 if(isset($this->dialog->current)){
833 $obj = $this->dialog->by_object[$this->dialog->current];
835 if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
837 $display.= "<p style=\"text-align:right\">\n";
838 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
839 $display.= " \n";
840 if ($this->dn != "new"){
841 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
842 $display.= " \n";
843 }
844 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
845 $display.= "</p>";
846 }elseif(!isset($this->dialog->current)){
847 $display.= "<p style=\"text-align:right\">\n";
848 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
849 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
850 $display.= "</p>";
851 }
852 }else{
853 $display.= "<p style=\"text-align:right\">\n";
854 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
855 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
856 $display.= "</p>";
858 }
859 return($display);
860 }
863 /****************
864 Dialog display
865 ****************/
867 /* Check if there is a snapshot dialog open */
868 $base = $this->DivListFai->selectedBase;
869 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
870 return($str);
871 }
873 /* Display dialog with system list */
874 $this->DivListFai->parent = $this;
875 $this->DivListFai->execute();
876 $this->DivListFai->AddDepartments($this->DivListFai->selectedBase,4,1);
877 $this->reload();
878 $this->DivListFai->setEntries($this->objects);
879 return($this->DivListFai->Draw());
880 }
883 /* Return departments, that will be included within snapshot detection */
884 function get_used_snapshot_bases()
885 {
886 $tmp = array();
887 $types = array("faipartitionou","faiscriptou","faitemplateou","faihookou","faiprofileou","faivariableou","faipackageou");
888 foreach($types as $type){
889 if($this->DivListFai->selectedBranch == "main"){
890 $tmp[] = get_ou($type).get_ou('faiou').$this->DivListFai->selectedBase;
891 }else{
892 $tmp[] = get_ou($type).$this->DivListFai->selectedBranch;
893 }
894 }
895 return($tmp);
896 }
899 /* Get available branches for current base */
900 function getBranches($base = false,$prefix = "")
901 {
902 $ret = array("/"=>"main");
903 $ldap = $this->config->get_ldap_link();
904 if(!$base){
905 $base = session::get('CurrentMainBase');
906 }
907 $tmp = FAI::get_all_releases_from_base($base,true);
908 foreach($tmp as $dn => $name){
909 $ret[$name]=$dn;
910 }
911 ksort($ret);
912 $ret = array_flip($ret);
914 return ($ret);
915 }
918 function list_get_selected_items()
919 {
920 $ids = array();
921 foreach($_POST as $name => $value){
922 if(preg_match("/^item_selected_[0-9]*$/",$name)){
923 $id = preg_replace("/^item_selected_/","",$name);
924 $ids[$id] = $id;
925 }
926 }
927 return($ids);
928 }
931 /* reload list of objects */
932 function reload()
933 {
934 /* Variable initialisation */
935 $str = "";
936 $Regex = $this->DivListFai->Regex;
937 $this->objects = array();
939 /* Get base */
940 $base = get_ou('faiou').$this->DivListFai->selectedBase;
941 if($this->DivListFai->selectedBranch != "main"){
942 $br = $this->getBranches();
943 if(isset($br[$this->DivListFai->selectedBranch])){
944 $base = $this->DivListFai->selectedBranch;
945 }else{
946 $base = get_ou('faiou').$this->DivListFai->selectedBase;
947 }
948 }
949 $this->base = $base;
950 $this->set_acl_base($this->base);
952 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
954 /* Create a new list of FAI object
955 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
956 */
957 $ObjectTypes = array(
958 "FAIpartitionTable" => array("OU"=> get_ou('faipartitionou') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
959 "FAIpackageList" => array("OU"=> get_ou('faipackageou') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
960 "FAIscript" => array("OU"=> get_ou('faiscriptou') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
961 "FAIvariable" => array("OU"=> get_ou('faivariableou') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
962 "FAIhook" => array("OU"=> get_ou('faihookou') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
963 "FAIprofile" => array("OU"=> get_ou('faiprofileou') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
964 "FAItemplate" => array("OU"=> get_ou('faitemplateou') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
966 $filter = "";
967 foreach($ObjectTypes as $key => $data){
968 if($this->DivListFai->$data['CHKBOX']){
969 $filter.= "(objectClass=".$key.")";
970 }
971 }
972 $filter = "(&(|".$filter.")(cn=$Regex))";
974 /* Get resolved release dependencies */
975 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
977 /* Ge listed ldap objects */
978 $ldap = $this->config->get_ldap_link();
979 $ldap->cd($this->config->current['BASE']);
980 foreach($tmp as $entry){
982 /* Get some more informations about the object */
983 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
984 $object = $ldap->fetch();
986 /* Walk through possible types */
987 foreach($ObjectTypes as $type => $rest){
989 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
991 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
993 /* Prepare object */
994 unset($object['objectClass']['count']);
995 if(!isset($object['description'][0])){
996 $object['description'][0]="";
997 }
999 /* Clean up object informations */
1000 $obj = array();
1001 $obj['cn'] = $object['cn'][0];
1002 $obj['dn'] = $object['dn'];
1003 $obj['acl'] = $acl;
1004 $obj['description'] = $object['description'][0];
1005 $obj['objectClass'] = $object['objectClass'];
1007 /* Append type to this string, to be able to check if the selected
1008 * entry is of type 'freeze' or 'branch'
1009 */
1010 if(!isset($object['FAIstate'])){
1011 $obj['FAIstate'] = $this->lock_type;
1012 }else{
1013 $obj['FAIstate'] = $object['FAIstate'][0];
1014 }
1016 $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1017 $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1018 }
1019 }
1020 }
1022 ksort($this->objects);
1023 reset ($this->objects);
1025 /* use numeric index, thats a bit more secure */
1026 $tmp0 = array();
1027 foreach($this->objects as $obj){
1028 $tmp0[]= $obj;
1029 }
1030 $this->objects = array();
1031 $this->objects = $tmp0;
1032 }
1034 function remove_lock()
1035 {
1036 if (isset($this->dn)){
1037 del_lock ($this->dn);
1038 }
1039 }
1041 function get_type($array){
1042 if(in_array("FAIpartitionTable",$array['objectClass'])){
1043 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1044 }
1045 if(in_array("FAIscript",$array['objectClass'])){
1046 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1047 }
1048 if(in_array("FAItemplate",$array['objectClass'])){
1049 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1050 }
1051 if(in_array("FAIhook",$array['objectClass'])){
1052 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1053 }
1054 if(in_array("FAIvariable",$array['objectClass'])){
1055 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1056 }
1057 if(in_array("FAIprofile",$array['objectClass'])){
1058 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1059 }
1061 if(in_array("FAIpackageList",$array['objectClass'])){
1062 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1063 }
1064 }
1066 function CheckNewBranchName($name,$base)
1067 {
1068 $f = $this->DivListFai->selectedBranch;
1069 if($name == ""){
1070 return(false);
1071 }elseif(in_array($name,$this->getBranches($f))) {
1072 return(false);
1073 }elseif(tests::is_department_name_reserved($name,$base)){
1074 return(false);
1075 }
1076 return(true);
1077 }
1079 function save_object()
1080 {
1081 $this->DivListFai->save_object();
1082 }
1085 function copyPasteHandling_from_queue($s_action,$s_entry)
1086 {
1087 /* Check if Copy & Paste is disabled */
1088 if(!is_object($this->CopyPasteHandler)){
1089 return("");
1090 }
1092 $base = $this->DivListFai->selectedBranch;
1093 if($base == "main"){
1094 $base = $this->DivListFai->selectedBase;
1095 }
1097 /* Add a single entry to queue */
1098 if($s_action == "cut" || $s_action == "copy"){
1100 /* Cleanup object queue */
1101 $this->CopyPasteHandler->cleanup_queue();
1102 $entry = $this->objects[$s_entry];
1103 $a_setup = $this->get_type($entry);
1104 $dn = $entry['dn'];
1105 $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1106 }
1108 /* Add entries to queue */
1109 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1111 /* Cleanup object queue */
1112 $this->CopyPasteHandler->cleanup_queue();
1114 /* Add new entries to CP queue */
1115 foreach($this->list_get_selected_items() as $id){
1117 /* Cleanup object queue */
1118 $entry = $this->objects[$id];
1119 $a_setup = $this->get_type($entry);
1120 $dn = $entry['dn'];
1123 if($s_action == "copy_multiple"){
1124 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1125 }
1126 if($s_action == "cut_multiple"){
1127 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1128 }
1129 }
1130 }
1132 /* Start pasting entries */
1133 if($s_action == "editPaste"){
1134 $this->start_pasting_copied_objects = TRUE;
1135 }
1137 /* Return C&P dialog */
1138 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1140 /* Get dialog */
1141 $data = $this->CopyPasteHandler->execute();
1142 $this->CopyPasteHandler->SetVar("base",$base);
1144 FAI::save_release_changes_now();
1146 /* Return dialog data */
1147 if(!empty($data)){
1148 return($data);
1149 }
1150 }
1152 /* Automatically disable status for pasting */
1153 if(!$this->CopyPasteHandler->entries_queued()){
1154 $this->start_pasting_copied_objects = FALSE;
1155 }
1156 return("");
1157 }
1160 /* Return plugin informations for acl handling */
1161 static function plInfo()
1162 {
1163 return (array(
1164 "plShortName" => _("FAI releases"),
1165 "plDescription" => _("FAI release management"),
1166 "plSelfModify" => FALSE,
1167 "plDepends" => array(),
1168 "plPriority" => 0,
1169 "plSection" => array("administration"),
1170 "plCategory" => array("fai"=> array("description" => _("FAI"),
1171 "objectClass" => "FAIclass")),
1172 "plProvidedAcls"=> array()));
1173 }
1174 }
1175 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1176 ?>