62a17ca7647217996a83852d028b634dd3ed1e4a
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 class applicationManagement extends plugin
22 {
23 /* Definitions */
24 var $plHeadline = "Applications";
25 var $plDescription = "This does something";
26 var $plIcon = "plugins/goto/images/application.png";
28 /* Dialog attributes */
29 var $apptabs = NULL;
30 var $ui = NULL;
31 var $CopyPasteHandler = NULL;
32 var $DivListApplication = NULL;
33 var $applications = array();
34 var $enableReleaseManagement = false;
35 var $start_pasting_copied_objects = FALSE;
37 var $acl_base ="";
38 var $app_base ="";
39 var $app_release ="";
40 var $acl_module = array("application");
42 var $dns = array();
44 function IsReleaseManagementActivated()
45 {
46 /* Check if we should enable the release selection */
47 $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
48 if(!empty($tmp)){
49 return(true);
50 }
51 return(false);
52 }
55 function applicationManagement (&$config, &$ui)
56 {
57 /* Save configuration for internal use */
58 $this->config = &$config;
59 $this->ui = &$ui;
60 $this->acl_base = $this->config->current['BASE'];
62 /* Check if copy & paste is activated */
63 if($this->config->boolValueIsTrue("MAIN","COPYPASTE")){
64 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
65 }
67 /* Creat dialog object */
68 $this->DivListApplication = new divListApplication($this->config,$this);
70 if($this->IsReleaseManagementActivated()){
71 /* Check if we should enable the release selection */
72 $this->enableReleaseManagement = true;
74 /* Hide SubSearch checkbox */
75 $this->DivListApplication->DisableCheckBox("SubSearch");
76 }
78 /* Set default release */
79 if(!$this->IsReleaseManagementActivated()){
80 $this->app_base = get_ou("applicationRDN").$this->config->current['BASE'];
81 if(!session::is_set("app_filter")){
82 session::set("app_filter",array("app_base" => $this->app_base));
83 }
84 $app_filter = session::get("app_filter");
85 }else{
87 /* Set intial release */
88 $this->app_base = get_ou("applicationRDN").$this->config->current['BASE'];
89 $rel = $config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
90 $rels = array_flip($this->getReleases());
91 if(isset($rels[$rel])){
92 $rel = $rels[$rel];
93 }else{
94 $rel = $this->app_base;
95 }
97 if(!session::is_set("app_filter")){
98 session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $rel));
99 }
100 $app_filter = session::get("app_filter");
101 $this->app_base = $app_filter['app_base'];
102 $this->app_release = $app_filter['app_release'];
103 }
104 }
107 function getReleases()
108 {
109 $ldap = $this->config->get_ldap_link();
110 $ret = array();
111 $base = $this->app_base;
113 $ret[$this->app_base] = "/";
114 $ldap->cd($base);
115 $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
116 while($attrs = $ldap->fetch()){
117 $str = str_replace($base,"",$attrs['dn']);
118 $tmp = array_reverse( split("ou=",$str));
119 $str = "";
120 foreach($tmp as $val){
121 $val = trim(preg_replace("/,/","",$val));
122 if(empty($val)) break;
123 $str .= "/".$val;
124 }
125 if(!empty($str)){
126 $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
127 }
128 }
129 asort($ret);
130 return($ret);
131 }
133 function execute()
134 {
135 /* Call parent execute */
136 plugin::execute();
139 /****************
140 Variable init
141 ****************/
143 /* These vars will be stored if you try to open a locked app,
144 to be able to perform your last requests after showing a warning message */
145 session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/","/^menu_action/"));
147 $smarty = get_smarty(); // Smarty instance
148 $s_action = ""; // Contains the action to proceed
149 $s_entry = ""; // The value for s_action
150 $base_back = ""; // The Link for Backbutton
152 /* Test Posts */
153 foreach($_POST as $key => $val){
154 // Post for delete
155 if(preg_match("/appl_del.*/",$key)){
156 $s_action = "del";
157 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
158 // Post for edit
159 }elseif(preg_match("/appl_edit_.*/",$key)){
160 $s_action="edit";
161 $s_entry = preg_replace("/appl_".$s_action."_/i","",$key);
162 // Post for new
163 }elseif(preg_match("/^copy_.*/",$key)){
164 $s_action="copy";
165 $s_entry = preg_replace("/^copy_/i","",$key);
166 }elseif(preg_match("/^cut_.*/",$key)){
167 $s_action="cut";
168 $s_entry = preg_replace("/^cut_/i","",$key);
169 // Post for new
170 }elseif(preg_match("/^appl_new.*/",$key)){
171 $s_action="new";
172 }elseif(preg_match("/^remove_multiple_applications/",$key)){
173 $s_action="del_multiple";
174 }elseif(preg_match("/^editPaste.*/i",$key)){
175 $s_action="editPaste";
176 }elseif(preg_match("/^multiple_copy_groups/",$key)){
177 $s_action = "copy_multiple";
178 }elseif(preg_match("/^multiple_cut_groups/",$key)){
179 $s_action = "cut_multiple";
180 }
181 }
183 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
184 $s_action ="edit";
185 $s_entry = $_GET['id'];
186 }
188 $s_entry = preg_replace("/_.$/","",$s_entry);
191 /* handle C&P from layers menu */
192 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
193 $s_action = "copy_multiple";
194 }
195 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
196 $s_action = "cut_multiple";
197 }
198 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
199 $s_action = "editPaste";
200 }
202 /* Create options */
203 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "appl_new"){
204 $s_action = "new";
205 }
207 /* handle remove from layers menu */
208 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
209 $s_action = "del_multiple";
210 }
212 /****************
213 Copy & Paste handling
214 ****************/
216 /* Display the copy & paste dialog, if it is currently open */
217 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
218 if($ret){
219 return($ret);
220 }
222 /****************
223 Create a new app
224 ****************/
226 /* New application? */
227 if ($s_action=="new"){
229 /* By default we set 'dn' to 'new', all relevant plugins will
230 react on this. */
231 $this->dn= "new";
233 /* Create new usertab object */
234 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
235 $this->apptabs->parent = &$this;
236 $this->apptabs->set_acl_base($this->acl_base);
237 }
240 /****************
241 Edit entry canceled
242 ****************/
244 /* Cancel dialogs */
245 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
246 $this->remove_lock();
247 $this->apptabs= NULL;
248 session::un_set('objectinfo');
249 }
252 /****************
253 Edit entry finished
254 ****************/
256 /* Finish apps edit is triggered by the tabulator dialog, so
257 the user wants to save edited data. Check and save at this
258 point. */
259 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->apptabs->config))){
261 /* Check tabs, will feed message array */
262 $this->apptabs->last= $this->apptabs->current;
263 $this->apptabs->save_object();
264 $message= $this->apptabs->check();
266 /* Save, or display error message? */
267 if (count($message) == 0){
269 /* Save data data to ldap */
270 $this->apptabs->save();
272 if (!isset($_POST['edit_apply'])){
273 /* Application has been saved successfully, remove lock from
274 LDAP. */
275 if ($this->dn != "new"){
276 $this->remove_lock();
277 }
278 $this->apptabs= NULL;
279 session::un_set('objectinfo');
280 }else{
282 /* Reinitialize tab */
283 if($this->apptabs instanceof tabs){
284 $this->apptabs->re_init();
285 }
286 }
287 } else {
288 /* Ok. There seem to be errors regarding to the tab data,
289 show message and continue as usual. */
290 msg_dialog::displayChecks($message);
291 }
292 }
295 /****************
296 Edit entry
297 ****************/
299 /* User wants to edit data? */
300 if (($s_action=="edit") && (!isset($this->apptabs->config))){
302 /* Get 'dn' from posted 'applist', must be unique */
303 $this->dn= $this->applications[$s_entry]['dn'];
305 /* Check locking, save current plugin in 'back_plugin', so
306 the dialog knows where to return. */
307 if (($user= get_lock($this->dn)) != ""){
308 return(gen_locked_message ($user, $this->dn));
309 }
311 /* Lock the current entry, so everyone will get the
312 above dialog */
313 add_lock ($this->dn, $this->ui->dn);
315 /* Register apptabs to trigger edit dialog */
316 $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
317 if($this->IsReleaseManagementActivated()){
318 $this->apptabs->set_FAIstate($this->applications[$s_entry]['FAIstate'][0]);
319 }
320 $this->apptabs->parent = &$this;
321 $this->apptabs->set_acl_base($this->dn);
322 session::set('objectinfo',$this->dn);
323 }
327 /********************
328 Delete MULTIPLE entries requested, display confirm dialog
329 ********************/
331 if ($s_action=="del_multiple"){
332 $ids = $this->list_get_selected_items();
334 if(count($ids)){
335 $this->dns = array();
337 $disallowed = array();
338 foreach($ids as $id){
339 $dn = $this->applications[$id]['dn'];
340 $acl = $this->ui->get_permissions($dn, "application/application");
341 if(preg_match("/d/",$acl)){
342 $this->dns[$id] = $dn;
343 }else{
344 $disallowed[] = $dn;
345 }
346 }
348 if(count($disallowed)){
349 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
350 }
352 if(count($this->dns)){
354 if ($user= get_multiple_locks($this->dns)){
355 return(gen_locked_message($user,$this->dns));
356 }
358 $dns_names = array();
359 foreach($this->dns as $dn){
360 add_lock ($dn, $this->ui->dn);
361 $dns_names[] =LDAP::fix($dn);
362 }
364 /* Lock the current entry, so nobody will edit it during deletion */
365 $smarty->assign("intro", msgPool::deleteInfo($dns_names,_("application")));
366 $smarty->assign("multiple", true);
367 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
368 }
369 }
370 }
373 /********************
374 Delete MULTIPLE entries confirmed
375 ********************/
377 /* Confirmation for deletion has been passed. Users should be deleted. */
378 if (isset($_POST['delete_multiple_application_confirm'])){
380 /* Remove user by user and check acls before removeing them */
381 foreach($this->dns as $key => $dn){
383 $ui = get_userinfo();
384 $acl = $ui->get_permissions($dn ,"application/application");
385 if (preg_match('/d/', $acl)){
387 /* Delete request is permitted, perform LDAP action */
388 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn,"application");
389 $this->apptabs->parent = &$this;
390 $this->apptabs->set_acl_base($dn);
391 $this->apptabs->delete ();
392 unset ($this->apptabs);
393 $this->apptabs= NULL;
395 } else {
396 /* Normally this shouldn't be reached, send some extra
397 logs to notify the administrator */
398 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
399 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
400 }
401 }
403 /* Remove lock file after successfull deletion */
404 $this->remove_lock();
405 $this->dns = array();
406 }
409 /********************
410 Delete MULTIPLE entries Canceled
411 ********************/
413 /* Remove lock */
414 if(isset($_POST['delete_multiple_application_cancel'])){
416 /* Remove lock file after successfull deletion */
417 $this->remove_lock();
418 $this->dns = array();
419 }
421 /****************
422 Delete app
423 ****************/
425 /* Remove user was requested */
426 if ($s_action == "del"){
428 /* Get 'dn' from posted 'uid' */
429 $this->dn= $this->applications[$s_entry]['dn'];
431 /* Load permissions for selected 'dn' and check if
432 we're allowed to remove this 'dn' */
433 $ui = get_userinfo();
434 $acl = $ui->get_permissions($this->dn ,"application/application");
436 if(preg_match("/d/",$acl)){
437 /* Check locking, save current plugin in 'back_plugin', so
438 the dialog knows where to return. */
439 if (($user= get_lock($this->dn)) != ""){
440 return (gen_locked_message ($user, $this->dn));
441 }
443 /* Lock the current entry, so nobody will edit it during deletion */
444 add_lock ($this->dn, $this->ui->dn);
445 $smarty= get_smarty();
446 $smarty->assign("intro",msgPool::deleteInfo(LDAP::fix($this->dn),_("application")));
447 $smarty->assign("multiple", false);
448 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
449 } else {
451 /* Obviously the user isn't allowed to delete. Show message and
452 clean session. */
453 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
454 }
455 }
458 /****************
459 Delete app confirmed
460 ****************/
462 /* Confirmation for deletion has been passed. Group should be deleted. */
463 if (isset($_POST['delete_app_confirm'])){
465 /* Some nice guy may send this as POST, so we've to check
466 for the permissions again. */
467 $ui = get_userinfo();
468 $acl = $ui->get_permissions($this->dn ,"application/application");
470 if(preg_match("/d/",$acl)){
472 /* Delete request is permitted, perform LDAP action */
473 $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
474 $this->apptabs->parent = &$this;
475 $this->apptabs->set_acl_base($this->dn);
476 $this->apptabs->delete ();
477 unset ($this->apptabs);
478 $this->apptabs= NULL;
480 } else {
482 /* Normally this shouldn't be reached, send some extra
483 logs to notify the administrator */
484 msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
485 new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
486 }
488 /* Remove lock file after successfull deletion */
489 $this->remove_lock();
490 }
493 /****************
494 Delete app canceled
495 ****************/
497 /* Delete application canceled? */
498 if (isset($_POST['delete_cancel'])){
499 $this->remove_lock();
500 session::un_set('objectinfo');
501 }
503 /* Show tab dialog if object is present */
504 if (($this->apptabs) && (isset($this->apptabs->config))){
505 $display= $this->apptabs->execute();
507 /* Don't show buttons if tab dialog requests this */
508 if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
509 $display.= "<p style=\"text-align:right\">\n";
511 if(isset($this->apptabs->FAIstate) && !preg_match("/freeze/i",$this->apptabs->FAIstate)){
512 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
513 $display.= " \n";
514 if ($this->dn != "new"){
515 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
516 $display.= " \n";
517 }
518 }
519 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
520 $display.= "</p>";
521 }
522 return ($display);
523 }
526 /****************
527 Dialog display
528 ****************/
530 /* Check if there is a snapshot dialog open */
531 if($this->IsReleaseManagementActivated()){
532 $base = $this->app_release;
533 }else{
534 $base = $this->app_base;
535 }
536 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
537 return($str);
538 }
540 /* Display dialog with system list */
541 $this->DivListApplication->parent = $this;
542 $this->DivListApplication->execute();
543 if(!$this->IsReleaseManagementActivated()){
544 $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
545 }
546 $this->reload();
547 $this->DivListApplication->setEntries($this->applications);
548 return($this->DivListApplication->Draw());
549 }
552 /* Return departments, that will be included within snapshot detection */
553 function get_used_snapshot_bases()
554 {
555 if($this->IsReleaseManagementActivated()){
556 return(array($this->app_release));
557 }else{
558 return(array($this->app_base));
559 }
560 }
563 function reload()
564 {
565 $this->applications= array();
567 /* Set base for all searches */
568 $Regex = $this->DivListApplication->Regex;
569 $SubSearch = $this->DivListApplication->SubSearch;
570 $Flags = GL_NONE | GL_SIZELIMIT;
571 $Filter = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
572 $tmp = array();
574 if(!$this->IsReleaseManagementActivated()){
575 $use_base = $this->app_base;
576 if($SubSearch){
577 $use_base = preg_replace("/^".preg_quote(get_ou("applicationRDN"), '/')."/","",$use_base);
578 }
579 }else{
580 $use_base = $this->app_release;
581 $SubSearch= FALSE;
582 }
584 /* Add FAIstate to the search attributes */
585 $search_attrs = array("cn","description","dn","objectClass");
586 if($this->IsReleaseManagementActivated()) {
587 $search_attrs[] = "FAIstate";
588 }
590 if($SubSearch){
591 $res= get_sub_list($Filter, "application",get_ou("applicationRDN"), $use_base, $search_attrs, $Flags);
592 }else{
593 $res= get_list($Filter, "application",$use_base, $search_attrs, $Flags);
594 }
595 $tmp2 = array();
596 foreach ($res as $val){
597 if(!isset($val['FAIstate'])){
598 $val['FAIstate'][0] = "";
599 }
600 $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
601 $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
602 }
604 natcasesort($tmp2);
605 $this->applications=array();
606 foreach($tmp2 as $val){
607 $this->applications[]=$tmp[$val];
608 }
609 reset ($this->applications);
610 }
612 function remove_from_parent()
613 {
614 /* Optionally execute a command after we're done */
615 $this->postremove();
616 }
619 function copyPasteHandling_from_queue($s_action,$s_entry)
620 {
621 /* Check if Copy & Paste is disabled */
622 if(!is_object($this->CopyPasteHandler)){
623 return("");
624 }
626 $ui = get_userinfo();
628 /* Add a single entry to queue */
629 if($s_action == "cut" || $s_action == "copy"){
631 /* Cleanup object queue */
632 $this->CopyPasteHandler->cleanup_queue();
633 $dn = $this->applications[$s_entry]['dn'];
634 if($s_action == "copy" && $ui->is_copyable($dn,"application","application")){
635 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
636 }
637 if($s_action == "cut" && $ui->is_cutable($dn,"application","application")){
638 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
639 }
640 }
643 /* Add entries to queue */
644 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
646 /* Cleanup object queue */
647 $this->CopyPasteHandler->cleanup_queue();
649 /* Add new entries to CP queue */
650 foreach($this->list_get_selected_items() as $id){
651 $dn = $this->applications[$id]['dn'];
653 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"application","application")){
654 $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
655 }
656 if($s_action == "cut_multiple" && $ui->is_cutable($dn,"application","application")){
657 $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
658 }
659 }
660 }
662 /* Start pasting entries */
663 if($s_action == "editPaste"){
664 $this->start_pasting_copied_objects = TRUE;
665 }
668 /* Return C&P dialog */
669 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
672 /* Get dialog */
673 $this->CopyPasteHandler->SetVar("base",$this->app_base);
674 $this->CopyPasteHandler->SetVar("parent",$this);
675 $data = $this->CopyPasteHandler->execute();
677 /* Return dialog data */
678 if(!empty($data)){
679 return($data);
680 }
681 }
683 /* Automatically disable status for pasting */
684 if(!$this->CopyPasteHandler->entries_queued()){
685 $this->start_pasting_copied_objects = FALSE;
686 }
687 return("");
688 }
691 function list_get_selected_items()
692 {
693 $ids = array();
694 foreach($_POST as $name => $value){
695 if(preg_match("/^item_selected_[0-9]*$/",$name)){
696 $id = preg_replace("/^item_selected_/","",$name);
697 $ids[$id] = $id;
698 }
699 }
700 return($ids);
701 }
704 /* Save to LDAP */
705 function save()
706 {
707 /* Optionally execute a command after we're done */
708 $this->postcreate();
709 }
712 function remove_lock()
713 {
714 if (isset($this->apptabs->dn)){
715 del_lock ($this->apptabs->dn);
716 }
717 if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
718 del_lock($this->dn);
719 }
720 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
721 del_lock($this->dns);
722 }
723 }
726 function save_object()
727 {
728 $this->DivListApplication->save_object();
729 if(is_object($this->CopyPasteHandler)){
730 $this->CopyPasteHandler->save_object();
731 }
733 if($this->IsReleaseManagementActivated() && isset($_POST['app_release'])){
734 $sel_rel = get_post('app_release');
735 $releases = array_flip($this->getReleases());
736 if(isset($releases[$sel_rel])){
737 $this->app_release = $releases[$sel_rel];
738 }
739 $app_filter = session::get("app_filter");
740 $app_filter['app_release'] = $this->app_release;
741 session::set("app_filter",$app_filter);
742 }elseif(!$this->IsReleaseManagementActivated()){
743 $this->app_base = get_ou("applicationRDN").$this->DivListApplication->selectedBase;
744 $app_filter = session::get("app_filter");
745 $app_filter['app_base'] = $this->app_base;
746 session::set("app_filter",$app_filter);
747 }
748 }
750 function check() {}
751 function adapt_from_template($dn, $skip= array()) {}
752 function password_change_needed() {}
753 }
754 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
755 ?>