Code

Fixed size_limit for systems
[gosa.git] / plugins / admin / groups / class_groupManagement.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  */
20 require "tabs_group.inc";
22 class groupManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Groups";
26   var $plDescription= "This does something";
28   /* Dialog attributes */
29   var $grouptab= NULL;
30   var $grouplist= array();
31   var $ui= NULL;
32   var $acl= "";
34   var $CopyPasteHandler  = NULL;
35   var $DivListGroup      = NULL;
37   var $ShowPrimaryCheckBox = false; 
39   function groupManagement ($config, $ui)
40   {
41     /* Save configuration for internal use */
42     $this->config= $config;
43     $this->ui= $ui;
45     /* Copy & Paste enabled ?*/
46     if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
47       $this->CopyPasteHandler = new CopyPasteHandler($this->config);
48     }
50     /* Detect if we have to display the primary group checkbox */
51     if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
52       $this->ShowPrimaryCheckBox = false;
53     } else {
54       $this->ShowPrimaryCheckBox = true;
55     }
57     /* Create dialog object */
58     $this->DivListGroup = new divListGroup($this->config,$this);
59     $this->DivListGroup->DisableCheckBox("ShowPrimaryGroups",$this->ShowPrimaryCheckBox);
60   }
62   function execute()
63   {
64         /* Call parent execute */
65         plugin::execute();
67     /* Store these posts if the current object is locked (used by somebody else)*/
68     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
70     /* Save data */
71     $s_action   = "";
72     $s_entry    = "";
74     /* Test Posts */
75     foreach($_POST as $key => $val){
76       // Post for delete
77       if(preg_match("/^group_del.*/",$key)){
78         $s_action = "del";
79         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
80         // Post for edit
81       }elseif(preg_match("/^group_edit_.*/",$key)){
82         $s_action="edit";
83         $s_entry  = preg_replace("/group_".$s_action."_/i","",$key);
84         // Post for new
85       }elseif(preg_match("/^group_new.*/",$key)){
86         $s_action="new";
87       }elseif(preg_match("/^dep_home.*/i",$key)){
88         $s_action="home";
89       }elseif(preg_match("/^group_tplnew.*/i",$key)){
90         $s_action="new_tpl";
91       }elseif(preg_match("/^group_chgpw.*/i",$key)){
92         $s_action="change_pw";
93         $s_entry  = preg_replace("/group_chgpw_/i","",$key);
94       }elseif(preg_match("/_group_edit_/",$key)){
95         $type = preg_replace("/_group_edit_.*$/","",$key);
96         $s_action="edit";
97         $s_entry  = preg_replace("/".$type."_group_edit_/i","",$key); 
98         $_POST['arg'] = $type;
99       }elseif(preg_match("/^editPaste.*/i",$key)){
100         $s_action="editPaste";
101       }elseif(preg_match("/^copy_.*/",$key)){
102         $s_action="copy";
103         $s_entry  = preg_replace("/^copy_/i","",$key);
104       }elseif(preg_match("/^cut_.*/",$key)){
105         $s_action="cut";
106         $s_entry  = preg_replace("/^cut_/i","",$key);
107       }
108     }
109     $s_entry  = preg_replace("/_.$/","",$s_entry); 
111     /* Check for posted gets */
112     if((isset($_GET['act'])) && ($_GET['act'] == "edit_entry")){
113       $s_entry    = $_GET['id'];
114       $s_action = "edit";
115     }
117     $smarty= get_smarty();
119     /********************
120       Copy & Paste Handling  ...
121      ********************/
123     /* Only perform copy&paste requests if it is enabled
124      */
125     if($this->CopyPasteHandler){
126       if($str = $this->copyPasteHandling($s_action,$s_entry)){
127         return $str;
128       }
129     }
132     /********************
133       Create a new group  ...
134      ********************/
136     /* New group? */
137     if ($s_action=="new"){
139       /* By default we set 'dn' to 'new', all relevant plugins will
140          react on this. */
141       $this->dn= "new";
143       /* Create new usertab object */
144       $this->grouptab= new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $this->dn);
146       /* Set up the users ACL's for this 'dn' */
147       $acl= get_permissions ($this->DivListGroup->selectedBase, $this->ui->subtreeACL);
148       $this->grouptab->set_acl($acl);
149     }
152     /********************
153       Save Group Tab/Object Changes
154      ********************/
156     /* Finish group edit is triggered by the tabulator dialog, so
157        the user wants to save edited data. Check and save at this
158        point. */
159     if ((isset($_POST['edit_finish'])) && (isset($this->grouptab->config)) ){
161       /* Check tabs, will feed message array 
162          Save, or display error message? */
163       $message= $this->grouptab->check();
164       if (count($message) == 0){
166         /* Save user data to ldap */
167         $this->grouptab->save();
168         gosa_log ("Group object'".$this->dn."' has been saved");
170         /* Group has been saved successfully, remove lock from LDAP. */
171         if ($this->dn != "new"){
172           del_lock ($this->dn);
173         }
175         /* There's no page reload so we have to read new users at this point. */
176         //$this->reload ();
177         unset ($this->grouptab);
178         $this->grouptab= NULL;
179         unset ($_SESSION['objectinfo']);
181       } else {
182         /* Ok. There seem to be errors regarding to the tab data,
183            show message and continue as usual. */
184         show_errors($message);
185       }
186     }
189     /********************
190       Edit existing group 
191      ********************/
193     /* User wants to edit data? */
194     if (($s_action=="edit") && (!isset($this->grouptab-> config))){
196       /* Get 'dn' from posted 'uid', must be unique */
197       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
199       /* Check locking & lock entry if required */
200       $user = get_lock($this->dn);
201       if ($user != ""){
202         return(gen_locked_message ($user, $this->dn));
203       }
204       add_lock ($this->dn, $this->ui->dn);
206       /* Set up the users ACL's for this 'dn' */
207       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
209       /* Register grouptab to trigger edit dialog */
210       $this->grouptab= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $this->dn);
211       $this->grouptab->set_acl($acl);
212       $_SESSION['objectinfo']= $this->dn;
213     }
216     /********************
217       Delete group 
218      ********************/
220     /* Remove group was requested */
221     if ($s_action=="del"){
223       /* Get 'dn' from posted 'uid' */
224       $this->dn= $this->grouplist[trim($s_entry)]['dn'];
226       /* Load permissions for selected 'dn' and check if
227          we're allowed to remove this 'dn' */
228       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
229       $this->acl= get_module_permission($acl, "group", $this->dn);
230       if (chkacl($this->acl, "delete") == ""){
232         /* Check locking, save current plugin in 'back_plugin', so
233            the dialog knows where to return. */
234         if (($user= get_lock($this->dn)) != ""){
235           return(gen_locked_message ($user, $this->dn));
236         }
238         /* Lock the current entry, so nobody will edit it during deletion */
239         add_lock ($this->dn, $this->ui->dn);
240         $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), @LDAP::fix($this->dn)));
241         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
243       } else {
244         
245         /* Obviously the user isn't allowed to delete. Show message and clean session. */
246         print_red (_("You are not allowed to delete this group!"));
247       }
248     }
251     /********************
252       Delete group confirmed  
253      ********************/
255     /* Confirmation for deletion has been passed. Group should be deleted. */
256     if (isset($_POST['delete_group_confirm'])){
258       /* Some nice guy may send this as POST, so we've to check
259          for the permissions again. */
260       if (chkacl($this->acl, "delete") == ""){
262         /* Delete request is permitted, perform LDAP action */
263         $this->grouptab= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $this->dn);
264         $this->grouptab->set_acl(array($this->acl));
265         $this->grouptab->delete ();
266         gosa_log ("Group object'".$this->dn."' has been removed");
267         unset ($this->grouptab);
268         $this->grouptab= NULL;
270         /* Group list has changed, reload it. */
271         //$this->reload ();
273       } else {
275         /* Normally this shouldn't be reached, send some extra
276            logs to notify the administrator */
277         print_red (_("You are not allowed to delete this group!"));
278         gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
279       }
281       /* Remove lock file after successfull deletion */
282       del_lock ($this->dn);
283       unset($_SESSION['objectinfo']);
284     }
287     /********************
288       Delete group canceled  
289      ********************/
291     /* Delete group canceled? */
292     if (isset($_POST['delete_cancel'])){
293       del_lock ($this->dn);
294       unset($_SESSION['objectinfo']);
295     }
296     
298     /********************
299       A dialog was canceled  
300      ********************/
302     /* Cancel dialogs */
303     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
304       del_lock ($this->grouptab->dn);
305       unset ($this->grouptab);
306       $this->grouptab= NULL;
307       unset($_SESSION['objectinfo']);
308     }
311     /********************
312       If there is currently a dialog open, display it
313      ********************/
315     /* Show tab dialog if object is present */
316     if (isset($this->grouptab->config)){
317       $display= $this->grouptab->execute();
319       /* Don't show buttons if tab dialog requests this */
320       if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
321         $display.= "<p style=\"text-align:right\">\n";
322         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
323         $display.= "&nbsp;\n";
324         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
325         $display.= "</p>";
326       }
327       return ($display);
328     }
330     /* Display dialog with group list */
331     $this->DivListGroup->execute();
333     /* Add departments if subsearch is disabled */
334     if(!$this->DivListGroup->SubSearch){
335       $this->DivListGroup->AddDepartments($this->DivListGroup->selectedBase,4);
336     }
337     $this->reload ();
338     $this->DivListGroup->setEntries($this->grouplist);
339     return($this->DivListGroup->Draw());
340   }
342   function reload($CreatePosixsList=false)
343   {
344     $this->grouplist        = array();
345     $primaries              = array();
346     $functional             = array();
347     $error= $error2         = "";
348     $filter                 = "(objectclass=posixGroup)";
350     $base                   = $this->DivListGroup->selectedBase;
351     $Regex                  = $this->DivListGroup->Regex;
352     $UserRegex              = $this->DivListGroup->UserRegex;
353     $SubSearch              = $this->DivListGroup->SubSearch;
354     $ShowPrimaryGroups      = $this->DivListGroup->ShowPrimaryGroups;
355     $ShowSambaGroups        = $this->DivListGroup->ShowSambaGroups;
356     $ShowApplicationGroups  = $this->DivListGroup->ShowApplicationGroups;
357     $ShowMailGroups         = $this->DivListGroup->ShowMailGroups;
358     $ShowFunctionalGroups   = $this->DivListGroup->ShowFunctionalGroups;
360     /* Prepare ldap class */
361     $ldap= $this->config->get_ldap_link();
362     $ldap->cd($base);
363     $ldap->set_size_limit($_SESSION['size_limit']);
366     /********************
367       Create filter depending on selected checkboxes 
368      ********************/
370     /* Add Mail Groups */
371     if ($ShowMailGroups){
372       $filter.= "(objectClass=gosaMailAccount)";
373     }
375     /* Add application groups */
376     if ($ShowApplicationGroups){
377       $filter.= "(objectClass=gosaApplicationGroup)";
378     }
380     /*
381        #FIXME Why is "sfilter" or "filter" set ?
382         Please verify && add comment 
383      */
384     $sfilter= "";
385     if ($this->config->current['SAMBAVERSION'] == 3){
386       if (!$ShowPrimaryGroups){
387         $sfilter= "(objectClass=sambaGroupMapping)";
388       } elseif ($ShowSambaGroups){
389         $filter.= "(objectClass=sambaGroupMapping)";
390       }
391     }
393     /* Prepare filter for given Regex && UserRegex */
394     if ($filter != ""){
395       $filter= "(&(cn=$Regex)(objectClass=posixGroup)(|$filter))";
396       if ($UserRegex != ""){
397         $filter= "(&(|(memberUID=".$UserRegex.")(cn=".$UserRegex."))$filter)";
398       }
399     }
402     /********************
403       Collect some groupids to be able to skip primary & functional groups 
404      ********************/
406     /* Collect primary groupIDs to show primary groups 
407         if this option is enabled in gosa conf && the checkbox is checked */  
408     if(($this->ShowPrimaryCheckBox) && ($ShowPrimaryGroups)){
409       $ldap->search("(&(uid=$Regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", array("gidNumber", "cn"));
410       show_ldap_error($ldap->get_error());
411       while ($attrs= $ldap->fetch()){
412         $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
413       }
414     }
415   
416     /* Collect all GroupIDs from those groups which are functional.
417         Only perfrom this search if  ShowFunctionalGroups  is unchecked, else leave arre empty  */ 
418     if(!$ShowFunctionalGroups){ 
419       $ldap->cd(get_groups_ou().$base);
420       $ldap->search("(&(cn=$Regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))", array("cn", "gidNumber", "description"));
421       $error2= $ldap->error;
422       while ($attrs= $ldap->fetch()){
423         if (!isset($primaries[$attrs['gidNumber'][0]])){
424           $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
425         }
426       }
427     }
428     
430     /********************
431       Search for the prepared filter 
432      ********************/
433     
434     /* If subsearch is activated search for subobjects too */
435     $attrs = array("cn", "description", "gidNumber", "objectClass");
437     if ($SubSearch){
438       $res= get_list($filter, $this->ui->subtreeACL, $base, $attrs, GL_SIZELIMIT| GL_SUBSEARCH);
439     } else {
440       $res= get_list($filter, $this->ui->subtreeACL, get_groups_ou().$base, $attrs, GL_SIZELIMIT);
441     }
443     /* Sort values into grouplist*/
444     $tmp = $tmp2 = array();
445     foreach ($res as $value){
447       /* Skip functional groups if checkbox isn't checked */
448       if (!$ShowFunctionalGroups && isset($functional[$value['gidNumber'][0]])){
449         continue;
450       }
451       
452       /* If gidNumber is in $primaries skip this entry */
453       if (!isset($primaries[$value['gidNumber'][0]])){
454         $tmp2[$value['cn'][0]] = $value;
455         $tmp [$value['cn'][0]] = $value['cn'][0];
456       }
457     }
458     natcasesort($tmp);
459     foreach($tmp as $name){
460       $this->grouplist[] = $tmp2[$name]; 
461     }
462     reset ($this->grouplist);
463   }
467   /* Perform copy & paste requests
468      If copy&paste is in progress this returns a dialog to fix required attributes 
469    */ 
470   function copyPasteHandling($s_action,$s_entry)
471   {
472     /* Paste copied/cutted object in here
473      */
474     if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
475       $this->CopyPasteHandler->save_object();
476       $this->CopyPasteHandler->SetVar("base",$this->DivListGroup->selectedBase);
477       if($str = $this->CopyPasteHandler->execute()){
478         return( $str);
479       };
480       /* Ensure that the new object is shown in the list now */
481       $this->relaod();
482     }
485     /* Copy current object to CopyHandler
486      */
487     if($s_action == "copy"){
488       $this->CopyPasteHandler->Clear();
490       $dn     = $this->grouplist[trim($s_entry)]['dn'];
491       $acl    = get_permissions ($dn, $this->ui->subtreeACL);
493       $obj    = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
494       $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
495       $obj->set_acl($acl);
496       $objNew->set_acl($acl);
497       $this->CopyPasteHandler->Copy($obj,$objNew);
498     }
501     /* Copy current object to CopyHandler
502      */
503     if($s_action == "cut"){
504       $this->CopyPasteHandler->Clear();
505       $dn = $this->grouplist[trim($s_entry)]['dn'];
506       $acl= get_permissions ($dn, $this->ui->subtreeACL);
508       $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
509       $obj->set_acl($acl);
511       $this->CopyPasteHandler->Cut($obj);
512     }
513   }
515   /* Save data to object */
516   function save_object()
517   {
518     $this->DivListGroup->save_object();
519   }
522   function remove_lock()
523   {
524     if (isset($this->grouptab->dn)){
525       del_lock ($this->grouptab->dn);
526     }
527   }
530   function remove_from_parent()
531   {
532     /* Optionally execute a command after we're done */
533     $this->postremove();
534   }
537   /* Save to LDAP */
538   function save()
539   {
540     /* Optionally execute a command after we're done */
541     $this->postcreate();
542   }
544   /* Unused functions  */
545   function check()  { }
546   function adapt_from_template($dn) { }
547   function password_change_needed()  { }
548   function show_header($button_text, $text, $disabled= FALSE)  { }
550 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
551 ?>