Code

Remove kerberos keys too
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationManagement.inc
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";
27   /* Dialog attributes */
28   var $apptabs                  = NULL;
29   var $ui                       = NULL;
30   var $CopyPasteHandler         = NULL;
31   var $DivListApplication       = NULL;
32   var $applications             = array();
33   var $enableReleaseManagement  = false;
34   var $start_pasting_copied_objects = FALSE;
36   var $app_base     ="";
37   var $app_release  ="";
38   var $acl_module   = array("application");  
40   var $dns = array();
42   function IsReleaseManagementActivated()
43   {
44     /* Check if we should enable the release selection */
45     $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
46     if(!empty($tmp)){
47       return(true);
48     }
49     return(false);
50   }
53   function applicationManagement (&$config, &$ui)
54   {
55     /* Save configuration for internal use */
56     $this->config   = &$config;
57     $this->ui       = &$ui;
59     /* Check if copy & paste is activated */
60     if($this->config->boolValueIsTrue("MAIN","ENABLECOPYPASTE")){
61       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
62     }
64     /* Creat dialog object */
65     $this->DivListApplication = new divListApplication($this->config,$this);
67     if($this->IsReleaseManagementActivated()){
68     /* Check if we should enable the release selection */
69       $this->enableReleaseManagement = true;
71       /* Hide SubSearch checkbox */
72       $this->DivListApplication->DisableCheckBox("SubSearch");
73     }
75     /* Set default release */
76     if(!$this->IsReleaseManagementActivated()){
77       $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
78       if(!session::is_set("app_filter")){
79         session::set("app_filter",array("app_base" => $this->app_base));
80       }
81       $app_filter     = session::get("app_filter");
82       $this->app_base = $app_filter['app_base'];
83     }else{
84       $this->app_base = get_ou("applicationou").$this->config->current['BASE'];
85       if(!session::is_set("app_filter")){
86         session::set("app_filter",array("app_base" => $this->app_base,"app_release" => $this->app_base));
87       }
88       $app_filter         = session::get("app_filter");
89       $this->app_base     = $app_filter['app_base'];
90       $this->app_release  = $app_filter['app_release'];
91     }
92   }
95   function getReleases()
96   {
97     $ldap = $this->config->get_ldap_link();
98     $ret  = array();
99     $base = $this->app_base; 
101     $ret[$this->app_base] = "/";
102     $ldap->cd($base);
103     $ldap->search("(&(objectClass=organizationalUnit)(objectClass=FAIbranch))",array("ou"));
104     while($attrs = $ldap->fetch()){
105       $str = str_replace($base,"",$attrs['dn']);
106       $tmp = array_reverse( split("ou=",$str));
107       $str = "";
108       foreach($tmp as $val){
109         $val = trim(preg_replace("/,/","",$val));
110         if(empty($val)) break;
111         $str .= "/".$val;
112       } 
113       if(!empty($str)){
114         $ret[$attrs['dn']]= preg_replace("/^\//","",$str);
115       }
116     }
117     asort($ret);
118     return($ret);
119   }
121   function execute()
122   {
123     /* Call parent execute */
124     plugin::execute();
127     /**************** 
128       Variable init 
129      ****************/
131     /* These vars will be stored if you try to open a locked app, 
132         to be able to perform your last requests after showing a warning message */
133     session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^appl_edit_/","/^appl_del_/","/^item_selected/","/^remove_multiple_applications/","/^menu_action/"));
135     $smarty       = get_smarty();             // Smarty instance
136     $s_action     = "";                       // Contains the action to proceed
137     $s_entry      = "";                       // The value for s_action
138     $base_back    = "";                       // The Link for Backbutton
139     
140     /* Test Posts */
141     foreach($_POST as $key => $val){
142       // Post for delete
143       if(preg_match("/appl_del.*/",$key)){
144         $s_action = "del";
145         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
146         // Post for edit
147       }elseif(preg_match("/appl_edit_.*/",$key)){
148         $s_action="edit";
149         $s_entry  = preg_replace("/appl_".$s_action."_/i","",$key);
150         // Post for new
151       }elseif(preg_match("/^copy_.*/",$key)){
152         $s_action="copy";
153         $s_entry  = preg_replace("/^copy_/i","",$key);
154       }elseif(preg_match("/^cut_.*/",$key)){
155         $s_action="cut";
156         $s_entry  = preg_replace("/^cut_/i","",$key);
157         // Post for new
158       }elseif(preg_match("/^appl_new.*/",$key)){
159         $s_action="new";
160       }elseif(preg_match("/^remove_multiple_applications/",$key)){
161         $s_action="del_multiple";
162       }elseif(preg_match("/^editPaste.*/i",$key)){
163         $s_action="editPaste";
164       }elseif(preg_match("/^multiple_copy_groups/",$key)){
165         $s_action = "copy_multiple";
166       }elseif(preg_match("/^multiple_cut_groups/",$key)){
167         $s_action = "cut_multiple";
168       }
169     }
171     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
172       $s_action ="edit";
173       $s_entry  = $_GET['id'];
174     }
176     $s_entry  = preg_replace("/_.$/","",$s_entry);
179     /* handle C&P from layers menu */
180     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
181       $s_action = "copy_multiple";
182     }
183     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
184       $s_action = "cut_multiple";
185     }
186     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
187       $s_action = "editPaste";
188     }
190     /* Create options */
191     if(isset($_POST['menu_action']) && $_POST['menu_action'] == "appl_new"){
192       $s_action = "new";
193     }
195     /* handle remove from layers menu */
196     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
197       $s_action = "del_multiple";
198     }
200     /**************** 
201       Copy & Paste handling  
202      ****************/
204     /* Display the copy & paste dialog, if it is currently open */
205     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
206     if($ret){
207       return($ret);
208     }
210     /**************** 
211       Create a new app 
212      ****************/
214     /* New application? */
215     if ($s_action=="new"){
217       /* By default we set 'dn' to 'new', all relevant plugins will
218          react on this. */
219       $this->dn= "new";
221       /* Create new usertab object */
222       $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
223       $this->apptabs->parent = &$this;
224       $this->apptabs->set_acl_base($this->app_base);
225     }
228     /**************** 
229       Edit entry canceled 
230      ****************/
232     /* Cancel dialogs */
233     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
234       $this->remove_lock();
235       $this->apptabs= NULL;
236       session::un_set('objectinfo');
237     }
240     /**************** 
241       Edit entry finished 
242      ****************/
244     /* Finish apps edit is triggered by the tabulator dialog, so
245        the user wants to save edited data. Check and save at this
246        point. */
247     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply']) ) && (isset($this->apptabs->config))){
249       /* Check tabs, will feed message array */
250       $this->apptabs->last= $this->apptabs->current;
251       $this->apptabs->save_object();
252       $message= $this->apptabs->check();
254       /* Save, or display error message? */
255       if (count($message) == 0){
257         /* Save data data to ldap */
258         $this->apptabs->save();
260         if (!isset($_POST['edit_apply'])){
261           /* Application has been saved successfully, remove lock from
262              LDAP. */
263           if ($this->dn != "new"){
264             $this->remove_lock();
265           }
266           $this->apptabs= NULL;
267           session::un_set('objectinfo');
268         }else{
270           /* Reinitialize tab */
271           if($this->apptabs instanceof tabs){
272             $this->apptabs->re_init();
273           }
274         }
275       } else {
276         /* Ok. There seem to be errors regarding to the tab data,
277            show message and continue as usual. */
278         msg_dialog::displayChecks($message);
279       }
280     }
283     /**************** 
284       Edit entry  
285      ****************/
287     /* User wants to edit data? */
288     if (($s_action=="edit") && (!isset($this->apptabs->config))){
290       /* Get 'dn' from posted 'applist', must be unique */
291       $this->dn= $this->applications[$s_entry]['dn'];
293       /* Check locking, save current plugin in 'back_plugin', so
294          the dialog knows where to return. */
295       if (($user= get_lock($this->dn)) != ""){
296         return(gen_locked_message ($user, $this->dn));
297       }
299       /* Lock the current entry, so everyone will get the
300          above dialog */
301       add_lock ($this->dn, $this->ui->dn);
303       /* Register apptabs to trigger edit dialog */
304       $this->apptabs= new apptabs($this->config,$this->config->data['TABS']['APPSTABS'], $this->dn,"application");
305       $this->apptabs->parent = &$this;
306       $this->apptabs->set_acl_base($this->dn);
307       session::set('objectinfo',$this->dn);
308     }
312     /********************
313       Delete MULTIPLE entries requested, display confirm dialog
314      ********************/
316     if ($s_action=="del_multiple"){
317       $ids = $this->list_get_selected_items();
319       if(count($ids)){
320         $this->dns = array();
322         $disallowed = array();
323         foreach($ids as $id){
324           $dn = $this->applications[$id]['dn'];
325           $acl = $this->ui->get_permissions($dn, "application/application");
326           if(preg_match("/d/",$acl)){
327             $this->dns[$id] = $dn;
328           }else{
329             $disallowed[] = $dn;
330           }
331         }
333         if(count($disallowed)){
334           msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
335         }
337         if(count($this->dns)){
339           if ($user= get_multiple_locks($this->dns)){
340             return(gen_locked_message($user,$this->dns));
341           }
343           $dns_names = array();
344           foreach($this->dns as $dn){
345             add_lock ($dn, $this->ui->dn);
346             $dns_names[] =@LDAP::fix($dn);
347           }
349           /* Lock the current entry, so nobody will edit it during deletion */
350           $smarty->assign("intro",  msgPool::deleteInfo($dns_names,_("application")));
351           $smarty->assign("multiple", true);
352           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
353         }
354       }
355     }
358     /********************
359       Delete MULTIPLE entries confirmed
360      ********************/
362     /* Confirmation for deletion has been passed. Users should be deleted. */
363     if (isset($_POST['delete_multiple_application_confirm'])){
365       /* Remove user by user and check acls before removeing them */
366       foreach($this->dns as $key => $dn){
368         $ui = get_userinfo();
369         $acl = $ui->get_permissions($dn ,"application/application");
370         if (preg_match('/d/', $acl)){
372           /* Delete request is permitted, perform LDAP action */
373           $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $dn,"application");
374           $this->apptabs->parent = &$this;
375           $this->apptabs->set_acl_base($dn);
376           $this->apptabs->delete ();
377           unset ($this->apptabs);
378           $this->apptabs= NULL;
380         } else {
381           /* Normally this shouldn't be reached, send some extra
382              logs to notify the administrator */
383           msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
384           new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
385         }
386       }
388       /* Remove lock file after successfull deletion */
389       $this->remove_lock();
390       $this->dns = array();
391     }
394     /********************
395       Delete MULTIPLE entries Canceled
396      ********************/
398     /* Remove lock */
399     if(isset($_POST['delete_multiple_application_cancel'])){
401       /* Remove lock file after successfull deletion */
402       $this->remove_lock();
403       $this->dns = array();
404     }
406     /**************** 
407       Delete app 
408      ****************/
410     /* Remove user was requested */
411     if ($s_action == "del"){
413       /* Get 'dn' from posted 'uid' */
414       $this->dn= $this->applications[$s_entry]['dn'];
416       /* Load permissions for selected 'dn' and check if
417          we're allowed to remove this 'dn' */
418       $ui = get_userinfo();
419       $acl = $ui->get_permissions($this->dn ,"application/application");
421       if(preg_match("/d/",$acl)){
422         /* Check locking, save current plugin in 'back_plugin', so
423            the dialog knows where to return. */
424         if (($user= get_lock($this->dn)) != ""){
425           return (gen_locked_message ($user, $this->dn));
426         }
428         /* Lock the current entry, so nobody will edit it during deletion */
429         add_lock ($this->dn, $this->ui->dn);
430         $smarty= get_smarty();
431         $smarty->assign("intro",msgPool::deleteInfo(@LDAP::fix($this->dn),_("application")));
432         $smarty->assign("multiple", false);
433         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
434       } else {
436         /* Obviously the user isn't allowed to delete. Show message and
437            clean session. */
438         msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
439       }
440     }
443     /**************** 
444       Delete app confirmed 
445      ****************/
447     /* Confirmation for deletion has been passed. Group should be deleted. */
448     if (isset($_POST['delete_app_confirm'])){
450       /* Some nice guy may send this as POST, so we've to check
451          for the permissions again. */
452       $ui = get_userinfo();
453       $acl = $ui->get_permissions($this->dn ,"application/application");
455       if(preg_match("/d/",$acl)){
457         /* Delete request is permitted, perform LDAP action */
458         $this->apptabs= new apptabs($this->config, $this->config->data['TABS']['APPSTABS'], $this->dn,"application");
459         $this->apptabs->parent = &$this;
460         $this->apptabs->set_acl_base($this->dn);
461         $this->apptabs->delete ();
462         unset ($this->apptabs);
463         $this->apptabs= NULL;
465       } else {
467         /* Normally this shouldn't be reached, send some extra
468            logs to notify the administrator */
469         msg_dialog::display(_("Permission error"), msgPool::permDelete(), INFO_DIALOG);
470         new log("security","application/".get_class($this),$dn,array(),"Tried to trick deletion.");
471       }
473       /* Remove lock file after successfull deletion */
474       $this->remove_lock();
475     }
478     /**************** 
479       Delete app canceled 
480      ****************/
482     /* Delete application canceled? */
483     if (isset($_POST['delete_cancel'])){
484       $this->remove_lock();
485       session::un_set('objectinfo');
486     }
488     /* Show tab dialog if object is present */
489     if (($this->apptabs) && (isset($this->apptabs->config))){
490       $display= $this->apptabs->execute();
492       /* Don't show buttons if tab dialog requests this */
493       if (!$this->apptabs->by_object[$this->apptabs->current]->dialog){
494         $display.= "<p style=\"text-align:right\">\n";
495         $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
496         $display.= "&nbsp;\n";
497         if ($this->dn != "new"){
498           $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
499           $display.= "&nbsp;\n";
500         }
501         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
502         $display.= "</p>";
503       }
504       return ($display);
505     }
508     /****************
509       Dialog display
510      ****************/
512     /* Check if there is a snapshot dialog open */
513     if($this->IsReleaseManagementActivated()){
514       $base = $this->app_release;  
515     }else{
516       $base = $this->app_base;  
517     }
518     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
519       return($str);
520     }
522     /* Display dialog with system list */
523     $this->DivListApplication->parent = $this;
524     $this->DivListApplication->execute();
525     if(!$this->IsReleaseManagementActivated()){
526       $this->DivListApplication->AddDepartments($this->DivListApplication->selectedBase,3,1);
527     } 
528     $this->reload();
529     $this->DivListApplication->setEntries($this->applications);
530     return($this->DivListApplication->Draw());
531   }
534   /* Return departments, that will be included within snapshot detection */
535   function get_used_snapshot_bases()
536   {
537     if($this->IsReleaseManagementActivated()){
538       return(array($this->app_release));  
539     }else{
540       return(array($this->app_base));  
541     }
542   }
545   function reload()
546   {
547     $this->applications= array();
549     /* Set base for all searches */
550     $Regex      = $this->DivListApplication->Regex;
551     $SubSearch  = $this->DivListApplication->SubSearch; 
552     $Flags      =  GL_NONE | GL_SIZELIMIT;
553     $Filter     = "(&(cn=".$Regex.")(objectClass=gosaApplication))";
554     $tmp        = array();
556     if(!$this->IsReleaseManagementActivated()){
557       $use_base = $this->app_base;
558       if($SubSearch){
559         $use_base = preg_replace("/^".normalizePreg(get_ou("applicationou"))."/","",$use_base);
560       }
561     }else{
562       $use_base = $this->app_release;
563       $SubSearch= FALSE;
564     }
565   
566     if($SubSearch){ 
567       $res= get_sub_list($Filter, "application",get_ou("applicationou"), $use_base, array("cn","description","dn","objectClass"), $Flags);
568     }else{
569       $res= get_list($Filter, "application",$use_base, array("cn","description","dn","objectClass"), $Flags);
570     }
571     $tmp2 = array();
572     foreach ($res as $val){
573       $tmp[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']]=$val;
574       $tmp2[strtolower($val['cn'][0]).$val['cn'][0].$val['dn']] = strtolower($val['cn'][0]).$val['cn'][0].$val['dn'];
575     }
577     natcasesort($tmp2);
578     $this->applications=array();
579     foreach($tmp2 as $val){
580       $this->applications[]=$tmp[$val];
581     }
582     reset ($this->applications);
583   }
585   function remove_from_parent()
586   {
587     /* Optionally execute a command after we're done */
588     $this->postremove();
589   }
592   function copyPasteHandling_from_queue($s_action,$s_entry)
593   {
594     /* Check if Copy & Paste is disabled */
595     if(!is_object($this->CopyPasteHandler)){
596       return("");
597     }
599     $ui = get_userinfo();
601     /* Add a single entry to queue */
602     if($s_action == "cut" || $s_action == "copy"){
604       /* Cleanup object queue */
605       $this->CopyPasteHandler->cleanup_queue();
606       $dn = $this->applications[$s_entry]['dn'];
607       if($s_action == "copy" && $ui->is_copyable($dn,"application","application")){
608         $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
609       }
610       if($s_action == "cut" && $ui->is_cutable($dn,"application","application")){ 
611         $this->CopyPasteHandler->add_to_queue($dn,$s_action,"apptabs","APPSTABS","application");
612       }
613     }
616     /* Add entries to queue */
617     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
619       /* Cleanup object queue */
620       $this->CopyPasteHandler->cleanup_queue();
622       /* Add new entries to CP queue */
623       foreach($this->list_get_selected_items() as $id){
624         $dn = $this->applications[$id]['dn'];
626         if($s_action == "copy_multiple" && $ui->is_copyable($dn,"application","application")){ 
627           $this->CopyPasteHandler->add_to_queue($dn,"copy","apptabs","APPSTABS","application");
628         }
629         if($s_action == "cut_multiple" && $ui->is_cutable($dn,"application","application")){
630           $this->CopyPasteHandler->add_to_queue($dn,"cut","apptabs","APPSTABS","application");
631         }
632       }
633     }
635     /* Start pasting entries */
636     if($s_action == "editPaste"){
637       $this->start_pasting_copied_objects = TRUE;
638     }
641     /* Return C&P dialog */
642     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
645       /* Get dialog */
646       $this->CopyPasteHandler->SetVar("base",$this->app_base);
647       $this->CopyPasteHandler->SetVar("parent",$this);
648       $data = $this->CopyPasteHandler->execute();
650       /* Return dialog data */
651       if(!empty($data)){
652         return($data);
653       }
654     }
656     /* Automatically disable status for pasting */
657     if(!$this->CopyPasteHandler->entries_queued()){
658       $this->start_pasting_copied_objects = FALSE;
659     }
660     return("");
661   }
664   function list_get_selected_items()
665   {
666     $ids = array();
667     foreach($_POST as $name => $value){
668       if(preg_match("/^item_selected_[0-9]*$/",$name)){
669         $id   = preg_replace("/^item_selected_/","",$name);
670         $ids[$id] = $id;
671       }
672     }
673     return($ids);
674   }
677   /* Save to LDAP */
678   function save()
679   {
680     /* Optionally execute a command after we're done */
681     $this->postcreate();
682   }
685   function remove_lock()
686   {
687     if (isset($this->apptabs->dn)){
688       del_lock ($this->apptabs->dn);
689     }
690     if(isset($this->dn) && !empty($this->dn) && $this->dn != "new"){
691       del_lock($this->dn);
692     }
693     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
694       del_lock($this->dns);
695     }
696   }
699   function save_object() 
700   {
701     $this->DivListApplication->save_object();
702     if(is_object($this->CopyPasteHandler)){
703       $this->CopyPasteHandler->save_object();
704     }
705     
706     if($this->IsReleaseManagementActivated() && isset($_POST['app_release'])){
707       $sel_rel = get_post('app_release');
708       $releases = array_flip($this->getReleases());
709       if(isset($releases[$sel_rel])){
710         $this->app_release = $releases[$sel_rel];
711       }
712       $app_filter     = session::get("app_filter");
713       $app_filter['app_release'] = $this->app_release;
714       session::set("app_filter",$app_filter);
715     }elseif(!$this->IsReleaseManagementActivated()){
716       $this->app_base = get_ou("applicationou").$this->DivListApplication->selectedBase;
717       $app_filter     = session::get("app_filter");
718       $app_filter['app_base'] = $this->app_base;
719       session::set("app_filter",$app_filter);
720     }
721   }
723   function check() {}
724   function adapt_from_template($dn, $skip= array()) {}
725   function password_change_needed() {}
727 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
728 ?>