bcf05f4aca6a44941124b866700c68d61f579041
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 $acl = "";
35 var $templates = array();
36 var $got_uid = false;
37 var $CopyPasteHandler = NULL;
38 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
39 var $DivListUsers;
41 function userManagement($config, $ui)
42 {
43 /* Save configuration for internal use */
44 $this->config= $config;
45 $this->ui= $ui;
47 /* Copy & Paste handler */
48 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
49 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
50 }
52 /* Creat dialog object */
53 $this->DivListUsers = new divListUsers($this->config,$this);
55 }
58 function execute()
59 {
60 /* Call parent execute */
61 plugin::execute();
63 /* LOCK MESSAGE Vars */
64 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
66 $smarty = get_smarty(); // Smarty instance
67 $s_action = ""; // Contains the action to be taken
68 $s_entry = ""; // The value for s_action
70 /* Edit entry button pressed? */
71 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
72 $s_action= "edit";
73 $s_entry= validate($_GET['id']);
74 }
76 /* Test relevant POST values */
77 foreach($_POST as $key => $val){
79 /* Get every possible POST combination and set s_action/s_entry accordingly */
80 foreach(array("del" => "user_del", "edit" => "user_edit",
81 "new" => "user_new",
82 "new_tpl" => "user_tplnew",
83 "create_user_from_tpl" => "userfrom_tpl",
84 "change_pw" => "user_chgpw",
85 "editPaste" => "editPaste", "copy" => "copy",
86 "cut" => "cut",
87 "toggle_lock_status" => "toggle_lock_status" ) as $act => $name){
89 if (preg_match("/".$name.".*/", $key)){
90 $s_action= $act;
91 $s_entry= preg_replace("/".$name."_/i", "", $key);
92 break;
93 }
94 }
96 } /* ...Test POST */
98 /* Remove coordinate prefix from POST, required by some browsers */
99 $s_entry= preg_replace("/_.$/", "", $s_entry);
101 /* Seperate possibly encoded tab and entry, default to tab "user" */
102 if(preg_match("/.*-.*/", $s_entry)){
103 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
104 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
105 }else{
106 $s_tab= "user";
107 }
109 /* Some may be active but diabled in gosa.conf. */
110 if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
111 $s_tab = "user";
112 }
114 /* Get 'dn' from posted 'uid' */
115 if(in_array_ics($s_action,array("editPaste","cut","copy")) || ($this->CopyPasteHandler && $this->CopyPasteHandler->stillOpen())){
117 if(isset($this->list[trim($s_entry)]['dn'])){
118 $dn= $this->list[trim($s_entry)]['dn'];
119 }else{
120 $dn = $this->DivListUsers->selectedBase;
121 }
123 $acl= get_permissions ($dn, $this->ui->subtreeACL);
124 $acl= get_module_permission($acl, "user", $dn);
126 if($acl != "#all#"){
127 print_red (_("You are not allowed to execute this method!"));
128 }else{
129 /* Display the copy & paste dialog, if it is currently open */
130 $ret = $this->copyPasteHandling($s_action,$s_entry);
131 if($ret){
132 return($ret);
133 }
134 }
135 }
138 /********************
139 Toggle lock status for user
140 ********************/
142 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
144 /* Get entry check current status */
145 $val = $this->list[$s_entry];
146 $pwd = $val['userPassword'][0];
148 if(!preg_match("/^\{[^\}]/",$pwd)){
149 trigger_error("Can not deactivate user which is using clear password encryption.");
150 }else{
152 $locked = false;
153 if(preg_match("/^[^\}]*+\}!/",$pwd)){
154 $locked = true;
155 }
157 /* Create ldap array to update status */
158 $attrs = array("userPassword" => $pwd);
159 if($locked){
160 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
161 }else{
162 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
163 }
165 /* Write new status back to ldap */
166 $ldap = $this->config->get_ldap_link();
167 $ldap->cd($val['dn']);
168 $ldap->modify($attrs);
169 if($locked){
170 show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
171 }else{
172 show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
173 }
174 }
175 }
178 /********************
179 Edit existing entry
180 ********************/
182 /* User wants to edit data? */
183 if (($s_action=="edit") && (!isset($this->usertab->config))){
185 /* Get 'dn' from posted 'uid', must be unique */
186 $this->dn= $this->list[trim($s_entry)]['dn'];
188 /* Check locking, save current plugin in 'back_plugin', so
189 the dialog knows where to return. */
190 if (($user= get_lock($this->dn)) != ""){
191 return(gen_locked_message ($user, $this->dn));
192 }
194 /* Lock the current entry, so everyone will get the
195 above dialog */
196 add_lock ($this->dn, $this->ui->dn);
198 /* Set up the users ACL's for this 'dn' */
199 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
201 /* Register usertab to trigger edit dialog */
202 $this->usertab= new usertabs($this->config,
203 $this->config->data['TABS']['USERTABS'], $this->dn);
205 /* Switch tab, if it was requested by the user */
206 $this->usertab->current = $s_tab;
208 /* Set ACL and move DN to the headline */
209 $this->usertab->set_acl($acl);
210 $_SESSION['objectinfo']= $this->dn;
211 }
214 /********************
215 Edit canceled
216 ********************/
218 /* Reset all relevant data, if we get a _cancel request */
219 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
220 if (isset($this->usertab)){
221 del_lock ($this->usertab->dn);
222 unset ($this->usertab);
223 }
224 $this->usertab= NULL;
225 $this->lognames= array();;
226 $this->sn= "";
227 $this->givenName= "";
228 $this->uid= "";
229 unset ($_SESSION['objectinfo']);
230 }
233 /********************
234 Change password requested
235 ********************/
237 /* Password change requested */
238 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
240 if(!empty($this->CPPasswordChange)){
241 $s_entry = $this->CPPasswordChange;
242 $this->CPPasswordChange = "";
243 }
245 /* Get 'dn' from posted 'uid' */
246 $this->dn= $this->list[trim($s_entry)]['dn'];
248 /* Load permissions for selected 'dn' and check if
249 we're allowed to remove this 'dn' */
250 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
251 $acl= get_module_permission($acl, "user", $this->dn);
252 if (chkacl($acl, "password") == ""){
254 /* User is allowed to change passwords, save 'dn' and 'acl' for next
255 dialog. */
256 $this->acl= $acl;
257 $_SESSION['objectinfo']= $this->dn;
258 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
260 } else {
261 /* User is not allowed. Show message and cancel. */
262 print_red (_("You are not allowed to set this users password!"));
263 }
264 }
267 /********************
268 Change password confirmed
269 ********************/
271 /* Perform password change */
272 if (isset($_POST['password_finish'])){
274 /* For security reasons, check if user is allowed to set password again */
275 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
277 /* Check input and feed errors into 'message' */
278 $message= array();
280 /* Sanity checks... */
281 if ($_POST['new_password'] != $_POST['repeated_password']){
283 /* Matching passwords in new and repeated? */
284 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
285 } else {
287 /* Empty password is not permitted by default. */
288 if ($_POST['new_password'] == ""){
289 $message[]= _("The password you've entered as 'New password' is empty.");
290 }
291 }
293 /* Errors, or password change? */
294 if (count($message) != 0){
296 /* Show error message and continue editing */
297 show_errors ($message);
298 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
299 }
301 $config= $this->config;
302 $ldap_ui= $this->config->get_ldap_link();
303 if(isset($this->usertab->dn)){
304 $ldap_ui->cat($this->usertab->dn,array("uid"));
305 $user = $ldap_ui->fetch();
306 }else{
307 $ldap_ui->cat($this->dn,array("uid"));
308 $user = $ldap_ui->fetch();
309 }
310 if((is_array($user))&&(isset($user['uid']))){
311 $username= $user['uid'][0];
312 }
314 /* Set password, perform required steps */
315 if ($this->usertab){
316 if ($this->usertab->password_change_needed()){
317 $obj= $this->usertab->by_object['user'];
318 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
319 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
320 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
321 }
323 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
324 unset($this->usertab);
325 $this->usertab= NULL;
326 }
327 } else {
328 change_password ($this->dn, $_POST['new_password']);
329 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
330 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
331 }
333 gosa_log ("Password for '".$this->dn."' has been changed");
334 }
335 } else {
337 /* Missing permissions, show message */
338 print_red (_("You are not allowed to set this users password!"));
339 }
341 /* Clean session, delete lock */
342 del_lock ($this->dn);
343 unset ($this->usertab);
344 $this->usertab= NULL;
345 $this->lognames= array();;
346 $this->sn= "";
347 $this->givenName= "";
348 $this->uid= "";
349 unset ($_SESSION['objectinfo']);
350 }
353 /********************
354 Delete entry requested, display confirm dialog
355 ********************/
357 /* Remove user was requested */
358 if ($s_action=="del"){
360 /* Get 'dn' from posted 'uid' */
361 $this->dn= $this->list[trim($s_entry)]['dn'];
363 /* Load permissions for selected 'dn' and check if
364 we're allowed to remove this 'dn' */
365 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
366 $this->acl= get_module_permission($acl, "user", $this->dn);
367 if (chkacl($this->acl, "delete") == ""){
369 /* Check locking, save current plugin in 'back_plugin', so
370 the dialog knows where to return. */
371 if (($user= get_lock($this->dn)) != ""){
372 return(gen_locked_message ($user, $this->dn));
373 }
375 /* Lock the current entry, so nobody will edit it during deletion */
376 add_lock ($this->dn, $this->ui->dn);
377 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
378 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
379 } else {
381 /* Obviously the user isn't allowed to delete. Show message and
382 clean session. */
383 print_red (_("You are not allowed to delete this user!"));
384 }
385 }
388 /********************
389 Delete entry confirmed
390 ********************/
392 /* Confirmation for deletion has been passed. User should be deleted. */
393 if (isset($_POST['delete_user_confirm'])){
395 /* Some nice guy may send this as POST, so we've to check
396 for the permissions again. */
397 if (chkacl($this->acl, "delete") == ""){
399 /* Delete request is permitted, perform LDAP action */
400 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
401 $this->usertab->set_acl(array($this->acl));
402 $this->usertab->delete ();
403 gosa_log ("User object '".$this->dn."' has been removed");
404 unset ($this->usertab);
405 $this->usertab= NULL;
406 } else {
408 /* Normally this shouldn't be reached, send some extra
409 logs to notify the administrator */
410 print_red (_("You are not allowed to delete this user!"));
412 if(isset($this->ui->uid)){
413 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
414 }
415 }
417 /* Remove lock file after successfull deletion */
418 del_lock ($this->dn);
419 }
422 /********************
423 Delete entry Canceled
424 ********************/
426 /* Delete user canceled? */
427 if (isset($_POST['delete_cancel'])){
428 del_lock ($this->dn);
429 }
432 /********************
433 Edit entry finished (Save)
434 ********************/
436 /* Finish user edit is triggered by the tabulator dialog, so
437 the user wants to save edited data. Check and save at this
438 point. */
439 if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){
441 /* Check tabs, will feed message array */
442 $this->usertab->last= $this->usertab->current;
443 $this->usertab->save_object();
444 $message= $this->usertab->check();
446 /* Save, or display error message? */
447 if (count($message) == 0){
449 /* No errors. Go ahead and prepare to ask for a password
450 in case we're creating a new user. 'dn' will be 'new'
451 in this case. It is set to the correct value later. */
452 if ($this->dn == "new"){
453 $set_pass= 1;
454 } else {
455 $set_pass= 0;
456 }
458 /* Save user data to ldap */
459 if($this->usertab->save() == 1){
460 gosa_log ("User object '".$this->dn."' saving failed.");
461 return;
462 }
463 gosa_log ("User object '".$this->dn."' has been saved");
465 /* User has been saved successfully, remove lock from LDAP. */
466 if ($this->dn != "new"){
467 del_lock ($this->dn);
468 }
470 /* In case of new users, ask for a password, skip this for templates */
471 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
472 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
473 }
475 unset ($this->usertab);
476 $this->usertab= NULL;
477 unset ($_SESSION['objectinfo']);
478 } else {
479 /* Ok. There seem to be errors regarding to the tab data,
480 show message and continue as usual. */
481 show_errors($message);
482 }
483 }
486 /********************
487 We want to create a new user, so fetch all available user templates
488 ********************/
490 /* Generate template list */
491 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
493 $this->templates= array();
494 $ldap= $this->config->get_ldap_link();
496 /* Create list of templates */
497 foreach ($this->config->departments as $key => $value){
499 /* Get acls from different ou's */
500 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
501 $acl= get_module_permission($acl, "user", get_people_ou().$value);
503 /* If creation of a new user is allowed, append this template */
504 if (chkacl($acl, "create") == ""){
506 /* Search all templates from the current dn */
507 $ldap->cd (get_people_ou().$value);
508 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
510 /* Append */
511 if ($ldap->count() != 0){
512 while ($attrs= $ldap->fetch()){
513 $this->templates[$ldap->getDN()]=
514 $attrs['uid'][0]." - ".@LDAP::fix($key);
515 }
516 $this->templates['none']= _("none");
517 }
518 }
519 }
521 /* Sort templates */
522 natcasesort ($this->templates);
523 reset ($this->templates);
524 }
527 /********************
528 Create a new user,template, user from template
529 ********************/
531 /* New user/template request */
532 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
533 /* By default we set 'dn' to 'new', all relevant plugins will
534 react on this. */
535 $this->dn= "new";
536 if (isset($this->config->current['IDGEN'])){
537 $this->got_uid= false;
538 } else {
539 $this->got_uid= true;
540 }
542 /* Create new usertab object */
543 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
544 $this->usertab->set_acl(array(':all'));
545 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
547 /* Take care about templates */
548 if ($s_action=="new_tpl"){
549 $this->is_template= TRUE;
550 $this->usertab->set_template_mode ();
551 } else {
552 $this->is_template= FALSE;
553 }
555 /* Use template if there are any of them */
556 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
557 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
558 $smarty->assign("$attr", $this->$attr);
559 }
560 if ($s_action=="create_user_from_tpl"){
561 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
562 } else {
563 $smarty->assign("template", "none");
564 }
565 $smarty->assign("edit_uid", "");
566 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
567 }
568 }
570 /********************
571 Template selected continue edit
572 ********************/
574 /* Continue template editing */
575 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
576 $this->sn = $_POST['sn'];
577 $this->givenName = $_POST['givenName'];
579 /* Check for requred values */
580 $message= array();
581 if ($this->sn == "") {
582 $message[]= _("The required field 'Name' is not set.");
583 }
584 if ($this->givenName == "") {
585 $message[]= _("The required field 'Given name' is not set.");
586 }
588 /* Check if dn is used */
589 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
590 $ldap= $this->config->get_ldap_link();
591 $ldap->cd ($dn);
592 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
593 if ($ldap->count () != 0){
594 $message[]= _("A person with the choosen name is already used in this tree.");
595 }
597 /* Show error message / continue editing */
598 if (count($message) > 0){
599 show_errors ($message);
600 } else {
601 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
602 if (isset($this->config->current['IDGEN']) &&
603 $this->config->current['IDGEN'] != ""){
604 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
605 if (count($uids)){
606 $smarty->assign("edit_uid", "false");
607 $smarty->assign("uids", $uids);
608 $this->uid= current($uids);
609 }
610 } else {
611 $smarty->assign("edit_uid", "");
612 $this->uid= "";
613 }
614 $this->got_uid= true;
615 }
617 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
618 $smarty->assign("$attr", $this->$attr);
619 }
620 if (isset($_POST['template'])){
621 $smarty->assign("template", $_POST['template']);
622 }
623 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
624 }
627 /********************
628 No template selected continue edit
629 ********************/
631 /* No template. Ok. Lets fill data into the normal user dialog */
632 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
633 foreach(array("sn", "givenName", "uid") as $attr){
634 if (isset($_POST[$attr])){
635 $this->usertab->by_object['user']->$attr= $_POST[$attr];
636 }
637 }
638 }
641 /********************
642 Template selected continue edit
643 ********************/
645 /* Finish template preamble */
646 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
648 /* Might not be filled if IDGEN is unset */
649 $this->sn = $_POST['sn'];
650 $this->givenName = $_POST['givenName'];
652 /* Move user supplied data to sub plugins */
653 $this->uid = $_POST['uid'];
654 $this->usertab->uid = $this->uid;
655 $this->usertab->sn = $this->sn;
656 $this->usertab->givenName = $this->givenName;
657 $template_dn = $_POST['template'];
658 $this->usertab->adapt_from_template($template_dn);
659 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
660 $this->usertab->by_object['user']->base= $template_base;
662 /* Set up the users ACL's for this 'dn' */
663 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
664 $this->usertab->set_acl($acl);
665 }
668 /********************
669 If no template was selected set base
670 ********************/
672 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
673 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
674 }
677 /********************
678 Display subdialog
679 ********************/
681 /* Show tab dialog if object is present */
682 if(isset($this->usertab->config)){
683 $display= $this->usertab->execute();
685 /* Don't show buttons if tab dialog requests this */
686 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
687 $display.= "<p style=\"text-align:right\">\n";
688 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
689 $display.= " \n";
690 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
691 $display.= "</p>";
692 }
693 return ($display);
694 }
696 /* Return rendered main page */
697 /* Display dialog with system list */
698 $this->DivListUsers->parent = $this;
699 $this->DivListUsers->execute();
701 /* Add departments if subsearch is disabled */
702 if(!$this->DivListUsers->SubSearch){
703 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
704 }
705 $this->reload();
706 $this->DivListUsers->setEntries($this->list);
707 return($this->DivListUsers->Draw());
708 }
711 function reload()
712 {
713 /* Set base for all searches */
714 $base= $this->DivListUsers->selectedBase;
715 $this->list =array();
717 /* Get filter configuration */
718 $Regex = $this->DivListUsers->Regex;
719 $SubSearch = $this->DivListUsers->SubSearch;
720 $ShowTemplates = $this->DivListUsers->ShowTemplates;
721 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
722 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
723 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
724 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
725 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
727 /* Setup filter depending on selection */
728 $filter="";
729 if ($this->config->current['SAMBAVERSION'] == 3){
730 $samba= "sambaSamAccount";
731 } else {
732 $samba= "sambaAccount";
733 }
735 if ($ShowFunctionalUsers){
736 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
737 "(objectClass=gosaMailAccount)(objectClass=$samba)".
738 "(objectClass=gosaProxyAccount))))";
739 }
740 if ($ShowUnixUsers){
741 $filter.= "(objectClass=posixAccount)";
742 }
743 if ($ShowMailUsers){
744 $filter.= "(objectClass=gosaMailAccount)";
745 }
746 if ($ShowSambaUsers){
747 $filter.= "(objectClass=$samba)";
748 }
749 if ($ShowProxyUsers){
750 $filter.= "(objectClass=gosaProxyAccount)";
751 }
752 if ($ShowTemplates){
753 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
754 } else {
755 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
756 }
757 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
759 /* Generate userlist */
760 $ldap= $this->config->get_ldap_link(TRUE);
761 if ($SubSearch){
762 $ListTemp = get_list($filter, $this->ui->subtreeACL, $base,
763 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
764 } else {
765 $base= get_people_ou().$base;
766 $ListTemp = get_list($filter, $this->ui->subtreeACL, $base,
767 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
768 }
769 $SortTemp = array();
770 $List = array();
771 foreach($ListTemp as $Key => $Entry){
773 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
774 * Else winstations will be listed too, if you use the subtree flag.
775 */
776 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
777 continue;
778 }else{
780 // Generate caption for rows
781 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
782 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
783 } else {
784 $display= "[".$Entry["uid"][0]."]";
785 }
787 $display = strtolower($display);
788 $List[$display] = $Entry;
789 $SortTemp[$display] = $display;
790 }
791 }
792 natcasesort($SortTemp);
793 reset($SortTemp);
795 $this->list = array();
796 foreach($SortTemp as $Key){
797 $this->list[] = $List[$Key];
798 }
799 }
801 function remove_lock()
802 {
803 /* Remove user lock if a DN is marked as "currently edited" */
804 if (isset($this->usertab->dn)){
805 del_lock ($this->usertab->dn);
806 }
807 }
810 /* Perform copy & paste requests
811 If copy&paste is in progress this returns a dialog to fix required attributes
812 */
813 function copyPasteHandling($s_action,$s_entry)
814 {
815 /* Only perform copy/paste if it is enabled */
816 if($this->CopyPasteHandler){
818 /* Prepare current object to be pasted */
819 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
821 $this->CopyPasteHandler->save_object();
822 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
824 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
825 us to solve all attribute mismatches for this object.
826 If nothing is returned, copy & paste was succesfully or aborted */
827 if(($ret= $this->CopyPasteHandler->execute())){
828 return ($ret);
829 }
831 /* Use the last dn to search for it's ID in the newly generated list. */
832 $dn= $this->CopyPasteHandler->lastdn;
834 /* Get new user list */
835 $this->reload();
836 foreach($this->list as $id => $entry){
837 if($entry['dn'] == $dn){
838 $s_entry= $id;
839 break;
840 }
841 }
843 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
844 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
845 $this->CPPasswordChange = $s_entry;
846 }
847 }
849 /* Copy selected object
850 Create a new empty object and the current selected object.
851 Send both to copy&paste class*/
852 if($s_action == "copy"){
853 $this->CopyPasteHandler->Clear();
854 $dn= $this->list[trim($s_entry)]['dn'];
855 $acl= get_permissions ($dn, $this->ui->subtreeACL);
856 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
857 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
858 $obj-> set_acl($acl);
859 $objNew-> set_acl($acl);
860 $this->CopyPasteHandler->Copy($obj,$objNew);
861 }
863 /* Cut selected object.
864 Open user object and send it to the copy & paste handler */
865 if($s_action == "cut"){
866 $this->CopyPasteHandler->Clear();
867 $dn= $this->list[trim($s_entry)]['dn'];
868 $acl= get_permissions ($dn, $this->ui->subtreeACL);
869 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
870 $obj->set_acl($acl);
871 $this->CopyPasteHandler->Cut($obj);
872 }
873 }
874 }
876 function save_object()
877 {
878 /* Handle divlist filter && department selection*/
879 if(!is_object($this->usertab)){
880 $this->DivListUsers->save_object();
881 }
882 }
884 /* A set of disabled and therefore overloaded functions. They are
885 not needed in this class. */
886 function remove_from_parent() { }
887 function check() { }
888 function save() { }
889 function adapt_from_template($dn) { }
890 function password_change_needed() { }
891 function show_header($button_text, $text, $disabled= FALSE) { }
893 } /* ... class userManagement */
894 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
895 ?>