1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
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 /* Include user tab class */
22 require "tabs_user.inc";
25 class userManagement extends plugin
26 {
27 /* Plugin definitions */
28 var $plHeadline= "Users";
29 var $plDescription= "This does something";
31 /* Dialog attributes */
32 var $usertab = NULL;
33 var $ui = NULL;
34 var $templates = array();
35 var $got_uid = false;
36 var $CopyPasteHandler = NULL;
37 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
38 var $DivListUsers;
40 function userManagement($config, $ui)
41 {
42 /* Save configuration for internal use */
43 $this->config= $config;
44 $this->ui= $ui;
46 /* Copy & Paste handler */
47 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
48 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
49 }
51 /* Creat dialog object */
52 $this->DivListUsers = new divListUsers($this->config,$this);
54 }
57 function execute()
58 {
59 /* Call parent execute */
60 plugin::execute();
62 /* LOCK MESSAGE Vars */
63 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
65 $smarty = get_smarty(); // Smarty instance
66 $s_action = ""; // Contains the action to be taken
67 $s_entry = ""; // The value for s_action
69 /* Edit entry button pressed? */
70 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
71 $s_action= "edit";
72 $s_entry= validate($_GET['id']);
73 }
75 /* Test relevant POST values */
76 foreach($_POST as $key => $val){
78 /* Get every possible POST combination and set s_action/s_entry accordingly */
79 foreach(array("del" => "user_del", "edit" => "user_edit",
80 "new" => "user_new",
81 "new_tpl" => "user_tplnew",
82 "del_multiple" => "^remove_multiple_users",
83 "create_user_from_tpl" => "userfrom_tpl",
84 "change_pw" => "user_chgpw",
85 "editPaste" => "editPaste", "copy" => "copy",
86 "cut" => "cut") as $act => $name){
88 if (preg_match("/".$name.".*/", $key)){
89 $s_action= $act;
90 $s_entry= preg_replace("/".$name."_/i", "", $key);
91 break;
92 }
93 }
95 } /* ...Test POST */
97 /* Remove coordinate prefix from POST, required by some browsers */
98 $s_entry= preg_replace("/_.$/", "", $s_entry);
100 /* Seperate possibly encoded tab and entry, default to tab "user" */
101 if(preg_match("/.*-.*/", $s_entry)){
102 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
103 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
104 }else{
105 $s_tab= "user";
106 }
108 if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
109 $s_tab = "user";
110 }
112 /* Display the copy & paste dialog, if it is currently open */
113 $ret = $this->copyPasteHandling($s_action,$s_entry);
114 if($ret){
115 return($ret);
116 }
119 /********************
120 Edit existing entry
121 ********************/
123 /* User wants to edit data? */
124 if (($s_action=="edit") && (!isset($this->usertab->config))){
126 /* Get 'dn' from posted 'uid', must be unique */
127 $this->dn= $this->list[trim($s_entry)]['dn'];
129 /* Check locking, save current plugin in 'back_plugin', so
130 the dialog knows where to return. */
131 if (($user= get_lock($this->dn)) != ""){
132 return(gen_locked_message ($user, $this->dn));
133 }
135 /* Lock the current entry, so everyone will get the
136 above dialog */
137 add_lock ($this->dn, $this->ui->dn);
139 /* Register usertab to trigger edit dialog */
140 $this->usertab= new usertabs($this->config,
141 $this->config->data['TABS']['USERTABS'], $this->dn);
143 /* Switch tab, if it was requested by the user */
144 $this->usertab->current = $s_tab;
146 /* Set ACL and move DN to the headline */
147 $this->usertab->set_acl_base($this->dn);
148 $_SESSION['objectinfo']= $this->dn;
149 }
152 /********************
153 Edit canceled
154 ********************/
156 /* Reset all relevant data, if we get a _cancel request */
157 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
158 if (isset($this->usertab)){
159 del_lock ($this->usertab->dn);
160 unset ($this->usertab);
161 }
162 $this->usertab= NULL;
163 $this->lognames= array();;
164 $this->sn= "";
165 $this->givenName= "";
166 $this->uid= "";
167 unset ($_SESSION['objectinfo']);
168 }
171 /********************
172 Change password requested
173 ********************/
175 /* Password change requested */
176 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
178 if(!empty($this->CPPasswordChange)){
179 $s_entry = $this->CPPasswordChange;
180 $this->CPPasswordChange = "";
181 }
183 /* Get 'dn' from posted 'uid' */
184 $this->dn= $this->list[trim($s_entry)]['dn'];
186 /* Load permissions for selected 'dn' and check if
187 we're allowed to remove this 'dn' */
188 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
190 /* User is allowed to change passwords, save 'dn' and 'acl' for next
191 dialog. */
192 $_SESSION['objectinfo']= $this->dn;
193 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
195 } else {
196 /* User is not allowed. Show message and cancel. */
197 print_red (_("You are not allowed to set this users password!"));
198 }
199 }
202 /********************
203 Change password confirmed
204 ********************/
206 /* Perform password change */
207 if (isset($_POST['password_finish'])){
209 /* For security reasons, check if user is allowed to set password again */
210 $dn = $this->dn;
211 $acl = $this->ui->get_permissions($dn, "users/password");
212 $cacl= $this->ui->get_permissions($dn, "users/user");
214 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
216 /* Check input and feed errors into 'message' */
217 $message= array();
219 /* Sanity checks... */
220 if ($_POST['new_password'] != $_POST['repeated_password']){
222 /* Matching passwords in new and repeated? */
223 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
224 } else {
226 /* Empty password is not permitted by default. */
227 if ($_POST['new_password'] == ""){
228 $message[]= _("The password you've entered as 'New password' is empty.");
229 }
230 }
232 /* Errors, or password change? */
233 if (count($message) != 0){
235 /* Show error message and continue editing */
236 show_errors ($message);
237 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
238 }
240 $config= $this->config;
241 $ldap_ui= $this->config->get_ldap_link();
242 if(isset($this->usertab->dn)){
243 $ldap_ui->cat($this->usertab->dn,array("uid"));
244 $user = $ldap_ui->fetch();
245 }else{
246 $ldap_ui->cat($this->dn,array("uid"));
247 $user = $ldap_ui->fetch();
248 }
249 if((is_array($user))&&(isset($user['uid']))){
250 $username= $user['uid'][0];
251 }
253 /* Set password, perform required steps */
254 if ($this->usertab){
255 if ($this->usertab->password_change_needed()){
256 $obj= $this->usertab->by_object['user'];
257 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
258 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
259 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
260 }
261 @log::log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
262 unset($this->usertab);
263 $this->usertab= NULL;
264 }
265 } else {
266 change_password ($this->dn, $_POST['new_password']);
267 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
268 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
269 }
271 @log::log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
272 }
273 } else {
275 /* Missing permissions, show message */
276 print_red (_("You are not allowed to set this users password!"));
277 }
278 /* Clean session, delete lock */
279 del_lock ($this->dn);
280 unset ($this->usertab);
281 $this->usertab= NULL;
282 $this->lognames= array();;
283 $this->sn= "";
284 $this->givenName= "";
285 $this->uid= "";
286 unset ($_SESSION['objectinfo']);
287 }
290 /********************
291 Delete MULTIPLE entries requested, display confirm dialog
292 ********************/
294 if ($s_action=="del_multiple"){
295 $ids = $this->list_get_selected_items();
297 if(count($ids)){
299 foreach($ids as $id){
300 $dn = $this->list[$id]['dn'];
301 if (($user= get_lock($dn)) != ""){
302 return(gen_locked_message ($user, $dn));
303 }
304 $this->dns[$id] = $dn;
305 }
307 $dns_names = "<br><pre>";
308 foreach($this->dns as $dn){
309 add_lock ($dn, $this->ui->dn);
310 $dns_names .= $dn."\n";
311 }
312 $dns_names .="</pre>";
314 /* Lock the current entry, so nobody will edit it during deletion */
315 if (count($this->dns) == 1){
316 $smarty->assign("info", sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
317 } else {
318 $smarty->assign("info", sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
319 }
320 $smarty->assign("multiple", true);
321 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
322 }
323 }
326 /********************
327 Delete MULTIPLE entries confirmed
328 ********************/
330 /* Confirmation for deletion has been passed. Users should be deleted. */
331 if (isset($_POST['delete_multiple_user_confirm'])){
333 /* Remove user by user and check acls before removeing them */
334 foreach($this->dns as $key => $dn){
336 $acl = $this->ui->get_permissions($dn, "users/user");
337 if (preg_match('/d/', $acl)){
339 /* Delete request is permitted, perform LDAP action */
340 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
341 $this->usertab->set_acl_base();
342 $this->usertab->delete ();
343 unset ($this->usertab);
344 $this->usertab= NULL;
345 } else {
346 print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
347 if(isset($this->ui->uid)){
348 @log::log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
349 }
350 }
351 /* Remove lock file after successfull deletion */
352 del_lock ($dn);
353 unset($this->dns[$key]);
354 }
355 }
358 /********************
359 Delete MULTIPLE entries Canceled
360 ********************/
362 /* Remove lock */
363 if(isset($_POST['delete_multiple_user_cancel'])){
364 foreach($this->dns as $key => $dn){
365 del_lock ($dn);
366 unset($this->dns[$key]);
367 }
368 }
371 /********************
372 Delete entry requested, display confirm dialog
373 ********************/
375 /* Remove user was requested */
376 if ($s_action=="del"){
378 /* Get 'dn' from posted 'uid' */
379 $this->dn= $this->list[trim($s_entry)]['dn'];
381 /* Load permissions for selected 'dn' and check if
382 we're allowed to remove this 'dn' */
384 /* Check locking, save current plugin in 'back_plugin', so
385 the dialog knows where to return. */
386 if (($user= get_lock($this->dn)) != ""){
387 return(gen_locked_message ($user, $this->dn));
388 }
390 /* Lock the current entry, so nobody will edit it during deletion */
391 add_lock ($this->dn, $this->ui->dn);
392 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
393 $smarty->assign("multiple", false);
394 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
395 }
398 /********************
399 Delete entry confirmed
400 ********************/
402 /* Confirmation for deletion has been passed. User should be deleted. */
403 if (isset($_POST['delete_user_confirm'])){
405 /* Some nice guy may send this as POST, so we've to check
406 for the permissions again. */
408 $acl = $this->ui->get_permissions($this->dn, "users/user");
410 if (preg_match('/d/', $acl)){
412 /* Delete request is permitted, perform LDAP action */
413 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
414 $this->usertab->set_acl_base();
415 $this->usertab->delete ();
416 unset ($this->usertab);
417 $this->usertab= NULL;
418 } else {
420 /* Normally this shouldn't be reached, send some extra
421 logs to notify the administrator */
422 print_red (_("You are not allowed to delete this user!"));
424 if(isset($this->ui->uid)){
425 @log::log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
426 }
427 }
429 /* Remove lock file after successfull deletion */
430 del_lock ($this->dn);
431 }
434 /********************
435 Delete entry Canceled
436 ********************/
438 /* Delete user canceled? */
439 if (isset($_POST['delete_cancel'])){
440 del_lock ($this->dn);
441 }
444 /********************
445 Edit entry finished (Save)
446 ********************/
448 /* Finish user edit is triggered by the tabulator dialog, so
449 the user wants to save edited data. Check and save at this
450 point. */
451 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
453 /* Check tabs, will feed message array */
454 $this->usertab->last= $this->usertab->current;
455 $this->usertab->save_object();
456 $message= $this->usertab->check();
458 /* Save, or display error message? */
459 if (count($message) == 0){
461 /* No errors. Go ahead and prepare to ask for a password
462 in case we're creating a new user. 'dn' will be 'new'
463 in this case. It is set to the correct value later. */
464 if ($this->dn == "new"){
465 $set_pass= 1;
466 } else {
467 $set_pass= 0;
468 }
470 /* Save user data to ldap */
471 if($this->usertab->save() == 1){
472 return;
473 }
475 if (!isset($_POST['edit_apply'])){
476 /* User has been saved successfully, remove lock from LDAP. */
477 if ($this->dn != "new"){
478 del_lock ($this->dn);
479 }
481 /* In case of new users, ask for a password, skip this for templates */
482 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
483 $this->dn = $this->usertab->dn;
484 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
485 }
487 unset ($this->usertab);
488 $this->usertab= NULL;
489 unset ($_SESSION['objectinfo']);
490 }
491 } else {
492 /* Ok. There seem to be errors regarding to the tab data,
493 show message and continue as usual. */
494 show_errors($message);
495 }
496 }
499 /********************
500 We want to create a new user, so fetch all available user templates
501 ********************/
503 /* Generate template list */
504 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
506 $this->templates= array();
507 $ldap= $this->config->get_ldap_link();
509 /* Create list of templates */
510 foreach ($this->config->departments as $key => $value){
512 /* Get acls from different ou's */
513 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
515 /* If creation of a new user is allowed, append this template */
516 if (preg_match("/c/",$acl)){
518 /* Search all templates from the current dn */
519 $ldap->cd (get_people_ou().$value);
520 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
522 /* Append */
523 if ($ldap->count() != 0){
524 while ($attrs= $ldap->fetch()){
525 $this->templates[$ldap->getDN()]=
526 $attrs['uid'][0]." - ".@LDAP::fix($key);
527 }
528 $this->templates['none']= _("none");
529 }
530 }
531 }
533 /* Sort templates */
534 natcasesort ($this->templates);
535 reset ($this->templates);
536 }
539 /********************
540 Create a new user,template, user from template
541 ********************/
543 /* Check selected options for template */
544 if (isset($_POST['template_continue'])){
545 $message = array();
546 if(!isset($_POST['template']) || (empty($_POST['template']))){
547 $message[] = _("Please select a valid template.");
548 }
549 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
550 $message[]= _("The required field 'Name' is not set.");
551 }
552 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
553 $message[]= _("The required field 'Given name' is not set.");
554 }
556 /* Show error message / continue editing */
557 if (count($message) > 0){
558 show_errors ($message);
560 foreach(array("sn", "givenName", "uid", "template") as $attr){
561 if(isset($_POST[$attr])){
562 $smarty->assign("$attr", $_POST[$attr]);
563 }else{
564 $smarty->assign("$attr", "");
565 }
566 }
567 $smarty->assign("templates",$this->templates);
568 $smarty->assign("got_uid",$this->got_uid);
569 $smarty->assign("edit_uid",false);
570 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
572 }
573 }
575 /* New user/template request */
576 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
577 /* By default we set 'dn' to 'new', all relevant plugins will
578 react on this. */
579 $this->dn= "new";
581 if (isset($this->config->current['IDGEN'])){
582 $this->got_uid= false;
583 } else {
584 $this->got_uid= true;
585 }
587 /* Create new usertab object */
588 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
589 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
590 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
592 /* Take care about templates */
593 if ($s_action=="new_tpl"){
594 $this->is_template= TRUE;
595 $this->usertab->set_template_mode ();
596 } else {
597 $this->is_template= FALSE;
598 }
600 /* Use template if there are any of them */
601 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
602 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
603 $smarty->assign("$attr", $this->$attr);
604 }
605 if ($s_action=="create_user_from_tpl"){
606 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
607 } else {
608 $smarty->assign("template", "none");
609 }
610 $smarty->assign("edit_uid", "");
611 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
612 }
613 }
615 /********************
616 Template selected continue edit
617 ********************/
619 /* Continue template editing */
620 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
622 $this->sn = $_POST['sn'];
623 $this->givenName = $_POST['givenName'];
625 /* Check for requred values */
626 $message= array();
627 if ($this->sn == "") {
628 $message[]= _("The required field 'Name' is not set.");
629 }
630 if ($this->givenName == "") {
631 $message[]= _("The required field 'Given name' is not set.");
632 }
634 /* Check if dn is used */
635 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
636 $ldap= $this->config->get_ldap_link();
637 $ldap->cd ($dn);
638 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
639 if ($ldap->count () != 0){
640 $message[]= _("A person with the choosen name is already used in this tree.");
641 }
643 /* Show error message / continue editing */
644 if (count($message) > 0){
645 show_errors ($message);
646 } else {
647 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
648 if (isset($this->config->current['IDGEN']) &&
649 $this->config->current['IDGEN'] != ""){
650 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
651 if (count($uids)){
652 $smarty->assign("edit_uid", "false");
653 $smarty->assign("uids", $uids);
654 $this->uid= current($uids);
655 }
656 } else {
657 $smarty->assign("edit_uid", "");
658 $this->uid= "";
659 }
660 $this->got_uid= true;
661 }
663 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
664 $smarty->assign("$attr", $this->$attr);
665 }
666 if (isset($_POST['template'])){
667 $smarty->assign("template", $_POST['template']);
668 }
669 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
670 }
672 /********************
673 No template selected continue edit
674 ********************/
676 /* No template. Ok. Lets fill data into the normal user dialog */
677 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
678 foreach(array("sn", "givenName", "uid") as $attr){
679 if (isset($_POST[$attr])){
680 $this->usertab->by_object['user']->$attr= $_POST[$attr];
681 }
682 }
683 }
686 /********************
687 Template selected continue edit
688 ********************/
690 /* Finish template preamble */
691 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
693 /* Might not be filled if IDGEN is unset */
694 $this->sn = $_POST['sn'];
695 $this->givenName = $_POST['givenName'];
697 /* Move user supplied data to sub plugins */
698 $this->uid = $_POST['uid'];
699 $this->usertab->uid = $this->uid;
700 $this->usertab->sn = $this->sn;
701 $this->usertab->givenName = $this->givenName;
702 $template_dn = $_POST['template'];
703 $this->usertab->adapt_from_template($template_dn);
704 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
705 $this->usertab->by_object['user']->base= $template_base;
706 }
709 /********************
710 If no template was selected set base
711 ********************/
713 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
714 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
715 }
718 /********************
719 Display subdialog
720 ********************/
722 /* Show tab dialog if object is present */
723 if(isset($this->usertab->config)){
724 $display= $this->usertab->execute();
726 /* Don't show buttons if tab dialog requests this */
727 if(isset($this->usertab->by_object)){
728 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
729 $display.= "<p style=\"text-align:right\">\n";
730 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
731 $display.= " \n";
732 if ($this->dn != "new"){
733 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
734 $display.= " \n";
735 }
736 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
737 $display.= "</p>";
738 }
739 }
740 return ($display);
741 }
743 /* Check if there is a snapshot dialog open */
744 $base = $this->DivListUsers->selectedBase;
745 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
746 return($str);
747 }
749 /* Return rendered main page */
750 /* Display dialog with system list */
751 $this->DivListUsers->parent = $this;
752 $this->DivListUsers->execute();
754 /* Add departments if subsearch is disabled */
755 if(!$this->DivListUsers->SubSearch){
756 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
757 }
758 $this->reload();
759 $this->DivListUsers->setEntries($this->list);
760 return($this->DivListUsers->Draw());
761 }
764 /* Return departments, that will be included within snapshot detection */
765 function get_used_snapshot_bases()
766 {
767 return(array(get_people_ou().$this->DivListUsers->selectedBase));
768 }
771 function reload()
772 {
773 /* Set base for all searches */
774 $base= $this->DivListUsers->selectedBase;
775 $this->list =array();
777 /* Get filter configuration */
778 $Regex = $this->DivListUsers->Regex;
779 $SubSearch = $this->DivListUsers->SubSearch;
780 $ShowTemplates = $this->DivListUsers->ShowTemplates;
781 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
782 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
783 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
784 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
785 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
787 /* Setup filter depending on selection */
788 $filter="";
789 if ($this->config->current['SAMBAVERSION'] == 3){
790 $samba= "sambaSamAccount";
791 } else {
792 $samba= "sambaAccount";
793 }
795 if ($ShowFunctionalUsers){
796 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
797 "(objectClass=gosaMailAccount)(objectClass=$samba)".
798 "(objectClass=gosaProxyAccount))))";
799 }
800 if ($ShowUnixUsers){
801 $filter.= "(objectClass=posixAccount)";
802 }
803 if ($ShowMailUsers){
804 $filter.= "(objectClass=gosaMailAccount)";
805 }
806 if ($ShowSambaUsers){
807 $filter.= "(objectClass=$samba)";
808 }
809 if ($ShowProxyUsers){
810 $filter.= "(objectClass=gosaProxyAccount)";
811 }
812 if ($ShowTemplates){
813 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
814 } else {
815 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
816 }
817 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
819 /* Generate userlist */
820 $ldap= $this->config->get_ldap_link(TRUE);
822 if ($SubSearch){
823 $ListTemp = get_list($filter, "users", $base,
824 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
825 } else {
826 $base= get_people_ou().$base;
827 $ListTemp = get_list($filter, "users", $base,
828 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
829 }
830 $SortTemp = array();
831 $List = array();
832 foreach($ListTemp as $Key => $Entry){
834 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
835 * Else winstations will be listed too, if you use the subtree flag.
836 */
837 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
838 continue;
839 }else{
841 // Generate caption for rows
842 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
843 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
844 } else {
845 $display= "[".$Entry["uid"][0]."]";
846 }
848 $display = strtolower($display);
849 $List[$display] = $Entry;
850 $SortTemp[$display] = $display;
851 }
852 }
853 sort($SortTemp);
854 reset($SortTemp);
856 $this->list = array();
857 foreach($SortTemp as $Key){
858 $this->list[] = $List[$Key];
859 }
860 }
862 function remove_lock()
863 {
864 /* Remove user lock if a DN is marked as "currently edited" */
865 if (isset($this->usertab->dn)){
866 del_lock ($this->usertab->dn);
867 }
868 }
871 /* Perform copy & paste requests
872 If copy&paste is in progress this returns a dialog to fix required attributes
873 */
874 function copyPasteHandling($s_action,$s_entry)
875 {
876 /* Only perform copy/paste if it is enabled */
877 if($this->CopyPasteHandler){
879 /* Prepare current object to be pasted */
880 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
882 $this->CopyPasteHandler->save_object();
883 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
885 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
886 us to solve all attribute mismatches for this object.
887 If nothing is returned, copy & paste was succesfully or aborted */
888 if(($ret= $this->CopyPasteHandler->execute())){
889 return ($ret);
890 }
892 /* Use the last dn to search for it's ID in the newly generated list. */
893 $dn= $this->CopyPasteHandler->lastdn;
895 /* Get new user list */
896 $this->reload();
897 foreach($this->list as $id => $entry){
898 if($entry['dn'] == $dn){
899 $s_entry= $id;
900 break;
901 }
902 }
904 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
905 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
906 $this->CPPasswordChange = $s_entry;
907 }
908 }
910 /* Copy selected object
911 Create a new empty object and the current selected object.
912 Send both to copy&paste class*/
913 if($s_action == "copy"){
914 $this->CopyPasteHandler->Clear();
915 $dn= $this->list[trim($s_entry)]['dn'];
917 /* Check acl */
918 $ui = get_userinfo();
919 $acl_all = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
920 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
921 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
922 $obj->set_acl_base($dn);
923 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
924 $objNew->set_acl_base($dn);
926 $this->CopyPasteHandler->Copy($obj,$objNew);
927 }else{
928 print_red("You are not allowed to copy this entry.");
929 }
930 }
932 /* Cut selected object.
933 Open user object and send it to the copy & paste handler */
934 if($s_action == "cut"){
935 $this->CopyPasteHandler->Clear();
936 $dn= $this->list[trim($s_entry)]['dn'];
938 /* Check acl */
939 $acl_all = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
940 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
941 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
942 $obj->set_acl_base($dn);
943 $this->CopyPasteHandler->Cut($obj);
944 }else{
945 print_red("You are not allowed to cut this entry.");
946 }
947 }
948 }
949 }
951 function save_object()
952 {
953 /* Handle divlist filter && department selection*/
954 if(!is_object($this->usertab)){
955 $this->DivListUsers->save_object();
956 }
957 }
960 function list_get_selected_items()
961 {
962 $ids = array();
963 foreach($_POST as $name => $value){
964 if(preg_match("/^item_selected_[0-9]*$/",$name)){
965 $id = preg_replace("/^item_selected_/","",$name);
966 $ids[$id] = $id;
967 }
968 }
969 return($ids);
970 }
973 /* A set of disabled and therefore overloaded functions. They are
974 not needed in this class. */
975 function remove_from_parent() { }
976 function check() { }
977 function save() { }
978 function adapt_from_template($dn) { }
979 function password_change_needed() { }
981 } /* ... class userManagement */
982 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
983 ?>