33fe9dfd6eb6d5f25664760c3aa0fd8629644ceb
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 $tmp = "";
52 if (isset($this->config->data['MAIN']['NOPRIMARYGROUP'])){
53 $tmp = $this->config->data['MAIN']['NOPRIMARYGROUP'];
54 }
55 if(preg_match("/true/i",$tmp)|| (preg_match("/yes/",$tmp))){
56 $this->ShowPrimaryCheckBox = false;
57 } else {
58 $this->ShowPrimaryCheckBox = true;
59 }
61 /* Create dialog object */
62 $this->DivListGroup = new divListGroup($this->config,$this);
63 $this->DivListGroup->DisableCheckBox("ShowPrimaryGroups",$this->ShowPrimaryCheckBox);
64 }
66 function execute()
67 {
68 /* Call parent execute */
69 plugin::execute();
71 /* Store these posts if the current object is locked (used by somebody else)*/
72 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^group_edit_/","/^group_del_/");
74 /* Save data */
75 $s_action = "";
76 $s_entry = "";
78 /* Test Posts */
79 foreach($_POST as $key => $val){
80 // Post for delete
81 if(preg_match("/^group_del.*/",$key)){
82 $s_action = "del";
83 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
84 // Post for edit
85 }elseif(preg_match("/^group_edit_.*/",$key)){
86 $s_action="edit";
87 $s_entry = preg_replace("/group_".$s_action."_/i","",$key);
88 // Post for new
89 }elseif(preg_match("/^group_new.*/",$key)){
90 $s_action="new";
91 }elseif(preg_match("/^dep_home.*/i",$key)){
92 $s_action="home";
93 }elseif(preg_match("/^group_tplnew.*/i",$key)){
94 $s_action="new_tpl";
95 }elseif(preg_match("/^group_chgpw.*/i",$key)){
96 $s_action="change_pw";
97 $s_entry = preg_replace("/group_chgpw_/i","",$key);
98 }elseif(preg_match("/_group_edit_/",$key)){
99 $type = preg_replace("/_group_edit_.*$/","",$key);
100 $s_action="edit";
101 $s_entry = preg_replace("/".$type."_group_edit_/i","",$key);
102 $_POST['arg'] = $type;
103 }elseif(preg_match("/^editPaste.*/i",$key)){
104 $s_action="editPaste";
105 }elseif(preg_match("/^copy_.*/",$key)){
106 $s_action="copy";
107 $s_entry = preg_replace("/^copy_/i","",$key);
108 }elseif(preg_match("/^cut_.*/",$key)){
109 $s_action="cut";
110 $s_entry = preg_replace("/^cut_/i","",$key);
111 }
112 }
113 $s_entry = preg_replace("/_.$/","",$s_entry);
115 /* Check for posted gets */
116 if((isset($_GET['act'])) && ($_GET['act'] == "edit_entry")){
117 $s_entry = $_GET['id'];
118 $s_action = "edit";
119 }
121 $smarty= get_smarty();
123 /********************
124 Copy & Paste Handling ...
125 ********************/
127 /* Only perform copy&paste requests if it is enabled
128 */
129 /* Get 'dn' from posted 'uid' */
130 if(in_array_ics($s_action,array("editPaste","cut","copy"))){
132 if(isset($this->grouplist[trim($s_entry)]['dn'])){
133 $dn= $this->grouplist[trim($s_entry)]['dn'];
134 }else{
135 $dn = $this->DivListGroup->selectedBase;
136 }
138 $acl= get_permissions ($dn, $this->ui->subtreeACL);
139 $acl= get_module_permission($acl, "group", $dn);
141 if($acl != "#all#"){
142 print_red (_("You are not allowed to execute this method!"));
143 }else{
144 /* Display the copy & paste dialog, if it is currently open */
145 $ret = $this->copyPasteHandling($s_action,$s_entry);
146 if($ret){
147 return($ret);
148 }
149 }
150 }
153 /********************
154 Create a new group ...
155 ********************/
157 /* New group? */
158 if ($s_action=="new"){
160 /* By default we set 'dn' to 'new', all relevant plugins will
161 react on this. */
162 $this->dn= "new";
164 /* Create new usertab object */
165 $this->grouptab= new grouptabs($this->config, $this->config->data['TABS']['GROUPTABS'], $this->dn);
167 /* Set up the users ACL's for this 'dn' */
168 $acl= get_permissions ($this->DivListGroup->selectedBase, $this->ui->subtreeACL);
169 $this->grouptab->set_acl($acl);
170 }
173 /********************
174 Save Group Tab/Object Changes
175 ********************/
177 /* Finish group edit is triggered by the tabulator dialog, so
178 the user wants to save edited data. Check and save at this
179 point. */
180 if ((isset($_POST['edit_finish'])) && (isset($this->grouptab->config)) ){
182 /* Check tabs, will feed message array
183 Save, or display error message? */
184 $message= $this->grouptab->check();
185 if (count($message) == 0){
187 /* Save user data to ldap */
188 $this->grouptab->save();
189 gosa_log ("Group object'".$this->dn."' has been saved");
191 /* Group has been saved successfully, remove lock from LDAP. */
192 if ($this->dn != "new"){
193 del_lock ($this->dn);
194 }
196 /* There's no page reload so we have to read new users at this point. */
197 //$this->reload ();
198 unset ($this->grouptab);
199 $this->grouptab= NULL;
200 unset ($_SESSION['objectinfo']);
202 } else {
203 /* Ok. There seem to be errors regarding to the tab data,
204 show message and continue as usual. */
205 show_errors($message);
206 }
207 }
210 /********************
211 Edit existing group
212 ********************/
214 /* User wants to edit data? */
215 if (($s_action=="edit") && (!isset($this->grouptab-> config))){
217 /* Get 'dn' from posted 'uid', must be unique */
218 $this->dn= $this->grouplist[trim($s_entry)]['dn'];
220 /* Check locking & lock entry if required */
221 $user = get_lock($this->dn);
222 if ($user != ""){
223 return(gen_locked_message ($user, $this->dn));
224 }
225 add_lock ($this->dn, $this->ui->dn);
227 /* Set up the users ACL's for this 'dn' */
228 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
230 /* Register grouptab to trigger edit dialog */
231 $this->grouptab= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $this->dn);
232 $this->grouptab->set_acl($acl);
233 $_SESSION['objectinfo']= $this->dn;
234 }
237 /********************
238 Delete group
239 ********************/
241 /* Remove group was requested */
242 if ($s_action=="del"){
244 /* Get 'dn' from posted 'uid' */
245 $this->dn= $this->grouplist[trim($s_entry)]['dn'];
247 /* Load permissions for selected 'dn' and check if
248 we're allowed to remove this 'dn' */
249 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
250 $this->acl= get_module_permission($acl, "group", $this->dn);
251 if (chkacl($this->acl, "delete") == ""){
253 /* Check locking, save current plugin in 'back_plugin', so
254 the dialog knows where to return. */
255 if (($user= get_lock($this->dn)) != ""){
256 return(gen_locked_message ($user, $this->dn));
257 }
259 /* Lock the current entry, so nobody will edit it during deletion */
260 add_lock ($this->dn, $this->ui->dn);
261 $smarty->assign("info", sprintf(_("You're about to delete the group '%s'."), @LDAP::fix($this->dn)));
262 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
264 } else {
266 /* Obviously the user isn't allowed to delete. Show message and clean session. */
267 print_red (_("You are not allowed to delete this group!"));
268 }
269 }
272 /********************
273 Delete group confirmed
274 ********************/
276 /* Confirmation for deletion has been passed. Group should be deleted. */
277 if (isset($_POST['delete_group_confirm'])){
279 /* Some nice guy may send this as POST, so we've to check
280 for the permissions again. */
281 if (chkacl($this->acl, "delete") == ""){
283 /* Delete request is permitted, perform LDAP action */
284 $this->grouptab= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $this->dn);
285 $this->grouptab->set_acl(array($this->acl));
286 $this->grouptab->delete ();
287 gosa_log ("Group object'".$this->dn."' has been removed");
288 unset ($this->grouptab);
289 $this->grouptab= NULL;
291 /* Group list has changed, reload it. */
292 //$this->reload ();
294 } else {
296 /* Normally this shouldn't be reached, send some extra
297 logs to notify the administrator */
298 print_red (_("You are not allowed to delete this group!"));
299 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
300 }
302 /* Remove lock file after successfull deletion */
303 del_lock ($this->dn);
304 unset($_SESSION['objectinfo']);
305 }
308 /********************
309 Delete group canceled
310 ********************/
312 /* Delete group canceled? */
313 if (isset($_POST['delete_cancel'])){
314 del_lock ($this->dn);
315 unset($_SESSION['objectinfo']);
316 }
319 /********************
320 A dialog was canceled
321 ********************/
323 /* Cancel dialogs */
324 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
325 del_lock ($this->grouptab->dn);
326 unset ($this->grouptab);
327 $this->grouptab= NULL;
328 unset($_SESSION['objectinfo']);
329 }
332 /********************
333 If there is currently a dialog open, display it
334 ********************/
336 /* Show tab dialog if object is present */
337 if (isset($this->grouptab->config)){
338 $display= $this->grouptab->execute();
340 /* Don't show buttons if tab dialog requests this */
341 if (!$this->grouptab->by_object[$this->grouptab->current]->dialog){
342 $display.= "<p style=\"text-align:right\">\n";
343 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
344 $display.= " \n";
345 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
346 $display.= "</p>";
347 }
348 return ($display);
349 }
351 /* Display dialog with group list */
352 $this->DivListGroup->parent = $this;
353 $this->DivListGroup->execute();
355 /* Add departments if subsearch is disabled */
356 if(!$this->DivListGroup->SubSearch){
357 $this->DivListGroup->AddDepartments($this->DivListGroup->selectedBase,4);
358 }
359 $this->reload ();
360 $this->DivListGroup->setEntries($this->grouplist);
361 return($this->DivListGroup->Draw());
362 }
364 function reload($CreatePosixsList=false)
365 {
366 $this->grouplist = array();
367 $primaries = array();
368 $functional = array();
369 $error= $error2 = "";
370 $filter = "(objectclass=posixGroup)";
372 $base = $this->DivListGroup->selectedBase;
373 $Regex = $this->DivListGroup->Regex;
374 $UserRegex = $this->DivListGroup->UserRegex;
375 $SubSearch = $this->DivListGroup->SubSearch;
376 $ShowPrimaryGroups = $this->DivListGroup->ShowPrimaryGroups;
377 $ShowSambaGroups = $this->DivListGroup->ShowSambaGroups;
378 $ShowApplicationGroups = $this->DivListGroup->ShowApplicationGroups;
379 $ShowMailGroups = $this->DivListGroup->ShowMailGroups;
380 $ShowFunctionalGroups = $this->DivListGroup->ShowFunctionalGroups;
382 /* Prepare ldap class */
383 $ldap= $this->config->get_ldap_link();
384 $ldap->cd($base);
385 $ldap->set_size_limit($_SESSION['size_limit']);
388 /********************
389 Create filter depending on selected checkboxes
390 ********************/
392 /* Add application groups */
393 if ($ShowApplicationGroups){
394 $filter.= "(objectClass=gosaApplicationGroup)";
395 }
397 /* Add Mail Groups */
398 if ($ShowMailGroups){
399 $filter.= "(objectClass=gosaMailAccount)";
400 }
402 $sfilter= "";
403 if ($this->config->current['SAMBAVERSION'] == 3){
404 if (!$ShowPrimaryGroups){
405 $sfilter= "(objectClass=sambaGroupMapping)";
406 } elseif ($ShowSambaGroups){
407 $filter.= "(objectClass=sambaGroupMapping)";
408 }
409 }
411 /* Prepare filter for given Regex && UserRegex */
412 if ($filter != ""){
413 $filter= "(&(cn=$Regex)(objectClass=posixGroup)(|$filter))";
414 if ($UserRegex != ""){
415 $filter= "(&(|(memberUID=".$UserRegex.")(cn=".$UserRegex."))$filter)";
416 }
417 }
420 /********************
421 Collect some groupids to be able to skip primary & functional groups
422 ********************/
424 /* Collect primary groupIDs to show primary groups
425 if this option is enabled in gosa conf && the checkbox is checked */
426 if ($this->ShowPrimaryCheckBox){
427 $res = get_list("(&(uid=$Regex)(!(uid=*$))(objectClass=posixAccount)(gidNumber=*))", $this->ui->subtreeACL,
428 $base,array("gidNumber", "cn"), GL_SUBSEARCH);
429 foreach ($res as $attrs){
430 $primaries[$attrs['gidNumber'][0]]= $attrs['cn'][0];
431 }
432 }
434 /* Collect all GroupIDs from those groups which are functional.
435 Only perfrom this search if ShowFunctionalGroups is unchecked, else leave arre empty */
436 $ff = "(&(cn=$Regex)(objectClass=posixGroup)(!(|(objectClass=gosaMailAccount)(objectClass=gosaApplicationGroup)$sfilter)))";
437 $res = get_list($ff,$this->ui->subtreeACL,$base,array("gidNumber", "cn", "description"), GL_SUBSEARCH);
438 foreach($res as $attrs){
439 if (!isset($primaries[$attrs['gidNumber'][0]])){
440 $functional[$attrs['gidNumber'][0]]= $attrs['gidNumber'][0];
441 }
442 }
445 /********************
446 Search for the prepared filter
447 ********************/
449 /* Attributes to search for */
450 $attrs = array("cn", "description", "gidNumber", "objectClass");
452 /* If subsearch is activated search for subobjects too */
453 $tmp = search_config($this->config->data,"faiManagement","CLASS");
454 if(!empty($tmp)){
455 $attrs [] = "FAIrelease";
456 }
458 if ($SubSearch){
459 $res= get_list($filter, $this->ui->subtreeACL, $base, $attrs, GL_SIZELIMIT| GL_SUBSEARCH);
460 } else {
461 $res= get_list($filter, $this->ui->subtreeACL, get_groups_ou().$base, $attrs, GL_SIZELIMIT);
462 }
464 /* Sort values into grouplist*/
465 $tmp = $tmp2 = array();
466 foreach ($res as $value){
467 /* Skip functional groups if checkbox isn't checked */
468 if (!$ShowFunctionalGroups && isset($functional[$value['gidNumber'][0]])){
469 continue;
470 }
472 /* If gidNumber is in $primaries skip this entry */
473 if (($ShowPrimaryGroups) || (!$ShowPrimaryGroups && !isset($primaries[$value['gidNumber'][0]]))){
474 $tmp2[$value['cn'][0]] = $value;
475 $tmp [$value['cn'][0]] = $value['cn'][0];
476 }
477 }
478 natcasesort($tmp);
479 foreach($tmp as $name){
480 $this->grouplist[] = $tmp2[$name];
481 }
482 reset ($this->grouplist);
483 }
487 /* Perform copy & paste requests
488 If copy&paste is in progress this returns a dialog to fix required attributes
489 */
490 function copyPasteHandling($s_action,$s_entry)
491 {
492 /* Paste copied/cutted object in here
493 */
494 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
495 $this->CopyPasteHandler->save_object();
496 $this->CopyPasteHandler->SetVar("base",$this->DivListGroup->selectedBase);
497 if($str = $this->CopyPasteHandler->execute()){
498 return( $str);
499 };
500 /* Ensure that the new object is shown in the list now */
501 $this->reload();
502 }
505 /* Copy current object to CopyHandler
506 */
507 if($s_action == "copy"){
508 $this->CopyPasteHandler->Clear();
510 $dn = $this->grouplist[trim($s_entry)]['dn'];
511 $acl = get_permissions ($dn, $this->ui->subtreeACL);
513 $obj = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
514 $objNew = new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], "new");
515 $obj->set_acl($acl);
516 $objNew->set_acl($acl);
517 $this->CopyPasteHandler->Copy($obj,$objNew);
518 }
521 /* Copy current object to CopyHandler
522 */
523 if($s_action == "cut"){
524 $this->CopyPasteHandler->Clear();
525 $dn = $this->grouplist[trim($s_entry)]['dn'];
526 $acl= get_permissions ($dn, $this->ui->subtreeACL);
528 $obj= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $dn);
529 $obj->set_acl($acl);
531 $this->CopyPasteHandler->Cut($obj);
532 }
533 }
535 /* Save data to object */
536 function save_object()
537 {
538 $this->DivListGroup->save_object();
539 }
542 function remove_lock()
543 {
544 if (isset($this->grouptab->dn)){
545 del_lock ($this->grouptab->dn);
546 }
547 }
550 function remove_from_parent()
551 {
552 /* Optionally execute a command after we're done */
553 $this->postremove();
554 }
557 /* Save to LDAP */
558 function save()
559 {
560 /* Optionally execute a command after we're done */
561 $this->postcreate();
562 }
564 /* Unused functions */
565 function check() { }
566 function adapt_from_template($dn) { }
567 function password_change_needed() { }
568 function show_header($button_text, $text, $disabled= FALSE) { }
569 }
570 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
571 ?>