6e30cb359b6eba8ca39fd618913674b327bcff35
1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class userManagement extends plugin
24 {
25 /* Plugin definitions */
26 var $plHeadline= "Users";
27 var $plDescription= "Manage users";
29 /* Dialog attributes */
30 var $usertab = NULL;
31 var $ui = NULL;
32 var $templates = array();
33 var $got_uid = false;
34 var $CopyPasteHandler = NULL;
35 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
36 var $DivListUsers;
38 var $pwd_change_queue = array();
40 var $start_pasting_copied_objects = FALSE;
41 var $current_action ="";
42 var $msg_dialog= NULL;
44 function userManagement(&$config, $ui)
45 {
46 /* Save configuration for internal use */
47 $this->config= &$config;
48 $this->ui= &$ui;
50 /* Copy & Paste handler */
51 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
52 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
53 }
55 /* Creat dialog object */
56 $this->DivListUsers = new divListUsers($this->config,$this);
58 }
61 function execute()
62 {
63 /* Call parent execute */
64 plugin::execute();
66 /* LOCK MESSAGE Vars */
67 session::set('LOCK_VARS_TO_USE',array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/","/^multiple_edit/","/menu_action/"));
69 $smarty = get_smarty(); // Smarty instance
70 $s_action = ""; // Contains the action to be taken
71 $s_entry = ""; // The value for s_action
73 /* Edit entry button pressed? */
74 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
75 $s_action= "edit";
76 $s_entry= validate($_GET['id']);
77 }
79 /* Test relevant POST values */
80 foreach($_POST as $key => $val){
82 /* Get every possible POST combination and set s_action/s_entry accordingly */
83 foreach(array("del" => "user_del",
84 "edit" => "user_edit",
85 "new" => "user_new",
86 "new_tpl" => "user_tplnew",
87 "del_multiple" => "^remove_multiple_users",
88 "create_user_from_tpl" => "userfrom_tpl",
89 "change_pw" => "user_chgpw",
90 "editPaste" => "editPaste",
91 "copy_multiple" => "multiple_copy_users",
92 "multiple_edit" => "multiple_edit",
93 "cut_multiple" => "multiple_cut_users",
94 "multiple_password_change" => "multiple_password_change",
95 "copy" => "^copy",
96 "toggle_lock_status" => "toggle_lock_status",
97 "cut" => "^cut") as $act => $name){
99 if (preg_match("/".$name.".*/", $key)){
100 $s_action= $act;
101 $s_entry= preg_replace("/".$name."_/i", "", $key);
102 break;
103 }
104 }
106 } /* ...Test POST */
108 /* Remove coordinate prefix from POST, required by some browsers */
109 $s_entry= preg_replace("/_.$/", "", $s_entry);
111 /* Seperate possibly encoded tab and entry, default to tab "user" */
112 if(preg_match("/.*-.*/", $s_entry)){
113 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
114 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
115 }else{
116 $s_tab= "user";
117 }
119 if(!$this->config->search($s_tab, 'class',array('tabs'))){
120 $s_tab = "user";
121 }
123 if (isset($_POST['menu_action'])){
125 /* handle C&P from layers menu */
126 if(preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
127 $s_action = "copy_multiple";
128 }
129 if(preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
130 $s_action = "cut_multiple";
131 }
132 if(preg_match("/^editPaste/",$_POST['menu_action'])){
133 $s_action = "editPaste";
134 }
136 /* Create options */
137 if($_POST['menu_action'] == "user_new"){
138 $s_action = "new";
139 }
140 if($_POST['menu_action'] == "user_tplnew"){
141 $s_action = "new_tpl";
142 }
143 if($_POST['menu_action'] == "multiple_edit"){
144 $s_action = "multiple_edit";
145 }
147 /* handle remove from layers menu */
148 if(preg_match("/^multiple_password_change/",$_POST['menu_action'])){
149 $s_action = "multiple_password_change";
150 }
152 /* handle remove from layers menu */
153 if(preg_match("/^remove_multiple/",$_POST['menu_action'])){
154 $s_action = "del_multiple";
155 }
156 if(preg_match("/^templatize_multiple/",$_POST['menu_action'])){
157 $s_action = "templatize_multiple";
158 }
160 if(preg_match("/^event/",$_POST['menu_action'])){
161 $s_action = $_POST['menu_action'];
162 }
163 }
165 /* Use template */
166 if(isset($_POST['templatize_continue'])){
167 $s_action = "templatize_continue";
168 }
171 /********************
172 Create notification event
173 ********************/
175 if(preg_match("/^event_/",$s_action) && class_available("DaemonEvent")){
176 $ids = $this->list_get_selected_items();
177 $uids = array();
178 foreach($ids as $id){
179 $uids[] = $this->list[$id]['uid'][0];
180 }
181 if(count($uids)){
182 $events = DaemonEvent::get_event_types(USER_EVENT);
183 $event = preg_replace("/^event_/","",$s_action);
184 if(isset($events['BY_CLASS'][$event])){
185 $type = $events['BY_CLASS'][$event];
186 $this->usertab = new $type['CLASS_NAME']($this->config);
187 $this->usertab->add_users($uids);
188 $this->usertab->set_type(TRIGGERED_EVENT);
189 }
190 }
191 }
193 /* Abort event dialog */
194 if(isset($_POST['abort_event_dialog'])){
195 $this->usertab = FALSE;
196 }
198 /* Save event */
199 if(isset($_POST['save_event_dialog'])){
200 $this->usertab->save_object();
201 $msgs = $this->usertab->check();
202 if(count($msgs)){
203 msg_dialog::displayChecks($msgs);
204 }else{
206 $o_queue = new gosaSupportDaemon();
207 $o_queue->append($this->usertab);
208 if($o_queue->is_error()){
209 msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
210 }else{
211 $this->usertab = FALSE;
212 }
213 }
214 }
216 /* Display event */
217 if($this->usertab instanceof DaemonEvent){
218 $this->usertab->save_object();
219 return($this->usertab->execute());
220 }
223 /********************
224 Copy & Paste
225 ********************/
227 /* Display the copy & paste dialog, if it is currently open */
228 if($this->CPPasswordChange == ""){
229 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
230 if($ret){
231 return($ret);
232 }
233 }
236 /********************
237 Change password confirmed
238 ********************/
240 /* Perform password change */
241 if (isset($_POST['password_finish'])){
243 /* For security reasons, check if user is allowed to set password again */
244 $dn = $this->dn;
245 $acl = $this->ui->get_permissions($dn, "users/password");
246 $cacl= $this->ui->get_permissions($dn, "users/user");
248 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
250 /* Check input and feed errors into 'message' */
251 $message= array();
253 /* Sanity checks... */
254 if ($_POST['new_password'] != $_POST['repeated_password']){
256 /* Matching passwords in new and repeated? */
257 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
258 } else {
260 /* Empty password is not permitted by default. */
261 if ($_POST['new_password'] == ""){
262 msgPool::required(_("New password"));
263 }
264 }
266 /* Errors, or password change? */
267 if (count($message) != 0){
269 /* Show error message and continue editing */
270 msg_dialog::displayChecks($message);
271 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
272 }
274 $config= $this->config;
275 $ldap_ui= $this->config->get_ldap_link();
276 if(isset($this->usertab->dn)){
277 $ldap_ui->cat($this->usertab->dn,array("uid"));
278 $user = $ldap_ui->fetch();
279 }else{
280 $ldap_ui->cat($this->dn,array("uid"));
281 $user = $ldap_ui->fetch();
282 }
283 if((is_array($user))&&(isset($user['uid']))){
284 $username= $user['uid'][0];
285 }
287 /* Set password, perform required steps */
288 if ($this->usertab){
289 if ($this->usertab->password_change_needed()){
290 $obj= $this->usertab->by_object['user'];
291 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
292 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
293 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
294 }
295 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
296 unset($this->usertab);
297 $this->usertab= NULL;
298 }
299 } else {
300 change_password ($this->dn, $_POST['new_password']);
301 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
302 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
303 }
304 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
305 }
306 } else {
308 /* Missing permissions, show message */
309 msg_dialog::display(_("Password change"),_("You have no permission to change this users password!"),WARNING_DIALOG);
310 }
311 /* Clean session, delete lock */
312 del_lock ($this->dn);
313 unset ($this->usertab);
314 $this->usertab= NULL;
315 $this->lognames= array();;
316 $this->sn= "";
317 $this->givenName= "";
318 $this->uid= "";
319 session::un_set('objectinfo');
320 }
323 /********************
324 Change multiple passwords requested
325 ********************/
327 if($s_action == "multiple_password_change"){
328 $this->pwd_change_queue = $this->list_get_selected_items();
329 }
332 /********************
333 Change password requested
334 ********************/
336 /* Password change requested */
337 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
339 /* Get users whose passwords should be changed. */
340 if(count($this->pwd_change_queue)){
341 $s_entry= array_pop($this->pwd_change_queue);
342 }
344 if(!empty($this->CPPasswordChange)){
345 $s_entry = $this->CPPasswordChange;
346 $this->CPPasswordChange = "";
347 }
349 /* Get 'dn' from posted 'uid' */
350 $this->dn= $this->list[trim($s_entry)]['dn'];
352 /* Load permissions for selected 'dn' and check if
353 we're allowed to remove this 'dn' */
354 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
356 /* User is allowed to change passwords, save 'dn' and 'acl' for next
357 dialog. */
358 session::set('objectinfo',$this->dn);
359 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
362 } else {
363 /* User is not allowed. Show message and cancel. */
364 msg_dialog::display(_("Password change"),_("You have no permission to change this users password!"),WARNING_DIALOG);
365 }
366 }
370 /********************
371 Edit existing entry
372 ********************/
374 /* User wants to edit data? */
375 if (($s_action=="edit") && (!isset($this->usertab->config))){
377 /* Get 'dn' from posted 'uid', must be unique */
378 $this->dn= $this->list[trim($s_entry)]['dn'];
380 /* Check locking, save current plugin in 'back_plugin', so
381 the dialog knows where to return. */
382 if (($user= get_lock($this->dn)) != ""){
383 return(gen_locked_message ($user, $this->dn));
384 }
386 /* Lock the current entry, so everyone will get the
387 above dialog */
388 add_lock ($this->dn, $this->ui->dn);
390 /* Register usertab to trigger edit dialog */
391 $this->usertab= new usertabs($this->config,
392 $this->config->data['TABS']['USERTABS'], $this->dn);
394 /* Switch tab, if it was requested by the user */
395 $this->usertab->current = $s_tab;
397 /* Set ACL and move DN to the headline */
398 $this->usertab->set_acl_base($this->dn);
399 session::set('objectinfo',$this->dn);
400 }
403 /********************
404 Edit multiple entries
405 ********************/
407 /* User wants to edit data? */
408 if ($s_action == "multiple_edit" && !isset($this->usertab->config)){
410 $this->dn = array();
411 foreach($this->list_get_selected_items() as $id){
412 $this->dn[] = $this->list[$id]['dn'];;
413 }
414 $tmp = new multi_plug($this->config,"usertabs",$this->config->data['TABS']['USERTABS'],
415 $this->dn,$this->DivListUsers->selectedBase,"user");
416 if ($tmp->entries_locked()){
417 return($tmp->display_lock_message());
418 }
419 $tmp->lock_entries($this->ui->dn);
420 if($tmp->multiple_available()){
421 $this->usertab = $tmp;
422 $this->usertab->set_active_tab($s_tab);
423 session::set('objectinfo',$this->usertab->get_object_info());
424 }
425 }
428 /********************
429 Edit canceled
430 ********************/
432 /* Reset all relevant data, if we get a _cancel request */
433 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
434 if (isset($this->usertab)){
435 del_lock ($this->usertab->dn);
436 unset ($this->usertab);
437 }
438 $this->usertab= NULL;
439 $this->lognames= array();;
440 $this->sn= "";
441 $this->givenName= "";
442 $this->uid= "";
443 session::un_set('objectinfo');
444 }
447 /********************
448 We want to create a new user, so fetch all available user templates
449 ********************/
451 /* Generate template list */
452 if ($s_action == "new" || $s_action == "create_user_from_tpl" || $s_action == "templatize_multiple"){
454 $this->templates= array();
455 $ldap= $this->config->get_ldap_link();
457 /* Create list of templates */
458 foreach ($this->config->departments as $key => $value){
460 /* Get acls from different ou's */
461 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
463 /* If creation of a new user is allowed, append this template */
464 if (preg_match("/c/",$acl)){
466 /* Search all templates from the current dn */
467 $ldap->cd (get_people_ou().$value);
468 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
470 /* Append */
471 if ($ldap->count() != 0){
472 while ($attrs= $ldap->fetch()){
473 $this->templates[$ldap->getDN()]=
474 $attrs['uid'][0]." - ".@LDAP::fix($key);
475 }
476 if ($s_action != "templatize_multiple"){
477 $this->templates['none']= _("none");
478 }
479 }
480 }
481 }
483 /* Sort templates */
484 natcasesort ($this->templates);
485 reset ($this->templates);
486 }
489 /********************
490 Apply template to multiple entries requested, display confirm dialog
491 ********************/
493 if ($s_action=="templatize_multiple"){
494 $ids = $this->list_get_selected_items();
495 $this->dns = array();
496 if(count($ids)){
498 foreach($ids as $id){
499 $dn = $this->list[$id]['dn'];
500 if (($user= get_lock($dn)) != ""){
501 return(gen_locked_message ($user, $dn));
502 }
503 $this->dns[$id] = $dn;
504 }
505 }
507 $smarty->assign("templates", $this->templates);
509 return($smarty->fetch(get_template_path('templatize.tpl', TRUE)));
510 }
512 /* Perform templatizing after the button has been pressed */
513 if ($s_action == "templatize_continue"){
515 $acl = $this->ui->get_permissions($_POST['template'], "users/user");
517 /* Template readable? */
518 if (preg_match('/r/', $acl)){
519 $template_dn= $_POST['template'];
521 foreach ($this->dns as $dn){
522 $acl = $this->ui->get_permissions($_POST['template'], "users/user");
523 if (preg_match('/w/', $acl)){
524 $usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
525 $usertab->adapt_from_template($template_dn, array("sn", "givenName", "uid"));
526 $usertab->save();
527 unset ($usertab);
528 $usertab= NULL;
529 } else {
530 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to modify object '%s'!"), $dn), ERROR_DIALOG);
531 }
532 }
533 } else {
534 msg_dialog::display(_("Permission error"), _("You have no permission to use this template!"), ERROR_DIALOG);
535 }
537 }
540 /********************
541 Delete MULTIPLE entries requested, display confirm dialog
542 ********************/
544 if ($s_action=="del_multiple"){
545 $ids = $this->list_get_selected_items();
546 $this->dns = array();
547 if(count($ids)){
549 foreach($ids as $id){
550 $dn = $this->list[$id]['dn'];
551 if (($user= get_lock($dn)) != ""){
552 return(gen_locked_message ($user, $dn));
553 }
554 $this->dns[$id] = $dn;
555 }
557 $dns_names = array();
558 foreach($this->dns as $dn){
559 $dns_names[] = @LDAP::fix($dn);
560 }
562 /* Lock the current entry, so nobody will edit it during deletion */
563 $info = sprintf(msgPool::deleteInfo($dns_names,_("user")));
564 $this->msg_dialog = new msg_dialog(_("Delete users"),$info,CONFIRM_DIALOG);
565 $this->current_action = $s_action;
566 }
567 }
570 /********************
571 Delete MULTIPLE entries confirmed
572 ********************/
574 /* Confirmation for deletion has been passed. Users should be deleted. */
575 if ($this->current_action == "del_multiple" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
577 $this->current_action = "";
579 /* Remove user by user and check acls before removeing them */
580 foreach($this->dns as $key => $dn){
582 $acl = $this->ui->get_permissions($dn, "users/user");
583 if (preg_match('/d/', $acl)){
585 /* Delete request is permitted, perform LDAP action */
586 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
587 $this->usertab->set_acl_base();
588 $this->usertab->delete ();
589 unset ($this->usertab);
590 $this->usertab= NULL;
591 } else {
592 msg_dialog::display(_("Warning"),msgPool::permDelete($dn),WARNING_DIALOG);
593 if(isset($this->ui->uid)){
594 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
595 }
596 }
597 /* Remove lock file after successfull deletion */
598 del_lock ($dn);
599 unset($this->dns[$key]);
600 }
601 }
604 /********************
605 Delete MULTIPLE entries Canceled
606 ********************/
608 /* Remove lock */
609 if(isset($_POST['delete_multiple_user_cancel'])){
610 foreach($this->dns as $key => $dn){
611 del_lock ($dn);
612 unset($this->dns[$key]);
613 }
614 }
617 /********************
618 Toggle lock status for user
619 ********************/
621 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
623 /* Get entry check current status */
624 $val = $this->list[$s_entry];
625 $pwd = $val['userPassword'][0];
627 if(!preg_match("/^\{[^\}]/",$pwd)){
628 trigger_error("Can not deactivate user which is using clear password encryption.");
629 }else{
631 $locked = false;
632 if(preg_match("/^[^\}]*+\}!/",$pwd)){
633 $locked = true;
634 }
636 /* Create ldap array to update status */
637 $attrs = array("userPassword" => $pwd);
638 if($locked){
639 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
640 }else{
641 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
642 }
644 /* Write new status back to ldap */
645 $ldap = $this->config->get_ldap_link();
646 $ldap->cd($val['dn']);
647 $ldap->modify($attrs);
648 if (!$ldap->success()){
649 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $val['dn'], 0, get_class()));
650 }
651 }
652 }
655 /********************
656 Delete entry requested, display confirm dialog
657 ********************/
659 /* Remove user was requested */
660 if ($s_action=="del"){
662 /* Get 'dn' from posted 'uid' */
663 $this->dn= $this->list[trim($s_entry)]['dn'];
665 /* Load permissions for selected 'dn' and check if
666 we're allowed to remove this 'dn' */
668 /* Check locking, save current plugin in 'back_plugin', so
669 the dialog knows where to return. */
670 if (($user= get_lock($this->dn)) != ""){
671 return(gen_locked_message ($user, $this->dn));
672 }
674 $this->msg_dialog = new msg_dialog( _("Delete user"),msgPool::deleteInfo(@LDAP::fix($this->dn),_("user")),CONFIRM_DIALOG);
675 $this->current_action = $s_action;
676 }
679 /********************
680 Delete entry confirmed
681 ********************/
683 /* Confirmation for deletion has been passed. User should be deleted. */
684 if ($this->current_action == "del" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
686 $this->current_action = "";
688 /* Some nice guy may send this as POST, so we've to check
689 for the permissions again. */
691 $acl = $this->ui->get_permissions($this->dn, "users/user");
693 if (preg_match('/d/', $acl)){
695 /* Delete request is permitted, perform LDAP action */
696 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
697 $this->usertab->set_acl_base();
698 $this->usertab->delete ();
699 unset ($this->usertab);
700 $this->usertab= NULL;
701 msg_dialog::display(_("Information"),_("User successfully removed."),INFO_DIALOG);
702 } else {
704 /* Normally this shouldn't be reached, send some extra
705 logs to notify the administrator */
706 msg_dialog::display(_("Warning"),msgPool::permDelete(),WARNING_DIALOG);
708 if(isset($this->ui->uid)){
709 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
710 }
711 }
713 /* Remove lock file after successfull deletion */
714 del_lock ($this->dn);
715 }
718 /********************
719 Delete entry Canceled
720 ********************/
722 /* Delete user canceled? */
723 if (isset($_POST['delete_cancel'])){
724 del_lock ($this->dn);
725 }
728 /********************
729 Edit entry finished (Save)
730 ********************/
732 /* Finish user edit is triggered by the tabulator dialog, so
733 the user wants to save edited data. Check and save at this
734 point. */
735 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
737 /* Check tabs, will feed message array */
738 $this->usertab->last= $this->usertab->current;
739 $this->usertab->save_object();
740 $message= $this->usertab->check();
742 /* Save, or display error message? */
743 if (count($message) == 0){
745 /* No errors. Go ahead and prepare to ask for a password
746 in case we're creating a new user. 'dn' will be 'new'
747 in this case. It is set to the correct value later. */
748 if ($this->dn == "new"){
749 $set_pass= 1;
750 } else {
751 $set_pass= 0;
752 }
754 /* Save user data to ldap */
755 if($this->usertab->save() == 1){
756 return;
757 }
759 if (!isset($_POST['edit_apply'])){
760 /* User has been saved successfully, remove lock from LDAP. */
761 if ($this->dn != "new"){
762 del_lock ($this->dn);
763 }
765 /* In case of new users, ask for a password, skip this for templates */
766 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
767 $this->dn = $this->usertab->dn;
768 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
769 }
771 unset ($this->usertab);
772 $this->usertab= NULL;
773 session::un_set('objectinfo');
774 }
775 } else {
776 /* Ok. There seem to be errors regarding to the tab data,
777 show message and continue as usual. */
778 msg_dialog::displayChecks($message);
779 }
780 }
784 /********************
785 Create a new user,template, user from template
786 ********************/
788 /* Check selected options for template */
789 if (isset($_POST['template_continue'])){
790 $message = array();
791 if(!isset($_POST['template']) || (empty($_POST['template']))){
792 $message[]= msgPool::invalid(_("Template"));
793 }
794 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
795 $message[]= msgPool::required(_("Name"));
796 }
797 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
798 $message[]= msgPool::required(_("Given name"));
799 }
801 /* Show error message / continue editing */
802 if (count($message) > 0){
803 msg_dialog::displayChecks($message);
805 foreach(array("sn", "givenName", "uid", "template") as $attr){
806 if(isset($_POST[$attr])){
807 $smarty->assign("$attr", $_POST[$attr]);
808 }else{
809 $smarty->assign("$attr", "");
810 }
811 }
812 $smarty->assign("templates",$this->templates);
813 $smarty->assign("got_uid",$this->got_uid);
814 $smarty->assign("edit_uid",false);
815 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
817 }
818 }
820 /* New user/template request */
821 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
822 /* By default we set 'dn' to 'new', all relevant plugins will
823 react on this. */
824 $this->dn= "new";
826 if (isset($this->config->current['IDGEN'])){
827 $this->got_uid= false;
828 } else {
829 $this->got_uid= true;
830 }
832 /* Create new usertab object */
833 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
834 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
835 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
837 /* Take care about templates */
838 if ($s_action=="new_tpl"){
839 $this->is_template= TRUE;
840 $this->usertab->set_template_mode ();
841 } else {
842 $this->is_template= FALSE;
843 }
845 /* Use template if there are any of them */
846 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
847 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
848 $smarty->assign("$attr", $this->$attr);
849 }
850 if ($s_action=="create_user_from_tpl"){
851 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
852 } else {
853 $smarty->assign("template", "none");
854 }
855 $smarty->assign("edit_uid", "");
856 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
857 }
858 }
860 /********************
861 Template selected continue edit
862 ********************/
864 /* Continue template editing */
865 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
867 $this->sn = $_POST['sn'];
868 $this->givenName = $_POST['givenName'];
870 /* Check for requred values */
871 $message= array();
872 if ($this->sn == "") {
873 $message[]= msgPool::required(_("Name"));
874 }
875 if ($this->givenName == "") {
876 $message[]= msgPool::required(_("Given name"));
877 }
879 /* Check if dn is used */
880 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
881 $ldap= $this->config->get_ldap_link();
882 $ldap->cd ($dn);
883 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
884 if ($ldap->count () != 0){
885 msgPool::duplicated(_("Name"));
886 }
888 /* Show error message / continue editing */
889 if (count($message) > 0){
890 msg_dialog::displayChecks($message);
891 } else {
892 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
893 if (isset($this->config->current['IDGEN']) &&
894 $this->config->current['IDGEN'] != ""){
895 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
896 if (count($uids)){
897 $smarty->assign("edit_uid", "false");
898 $smarty->assign("uids", $uids);
899 $this->uid= current($uids);
900 }
901 } else {
902 $smarty->assign("edit_uid", "");
903 $this->uid= "";
904 }
905 $this->got_uid= true;
906 }
908 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
909 $smarty->assign("$attr", $this->$attr);
910 }
911 if (isset($_POST['template'])){
912 $smarty->assign("template", $_POST['template']);
913 }
914 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
915 }
917 /********************
918 No template selected continue edit
919 ********************/
921 /* No template. Ok. Lets fill data into the normal user dialog */
922 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
923 foreach(array("sn", "givenName", "uid") as $attr){
924 if (isset($_POST[$attr])){
925 $this->usertab->by_object['user']->$attr= $_POST[$attr];
926 }
927 }
928 }
931 /********************
932 Template selected continue edit
933 ********************/
935 /* Finish template preamble */
936 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
938 /* Might not be filled if IDGEN is unset */
939 $this->sn = $_POST['sn'];
940 $this->givenName = $_POST['givenName'];
942 /* Move user supplied data to sub plugins */
943 $this->uid = $_POST['uid'];
944 $this->usertab->uid = $this->uid;
945 $this->usertab->sn = $this->sn;
946 $this->usertab->givenName = $this->givenName;
947 $template_dn = $_POST['template'];
948 $this->usertab->adapt_from_template($template_dn);
949 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
950 $this->usertab->by_object['user']->base= $template_base;
951 }
954 /********************
955 If no template was selected set base
956 ********************/
958 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
959 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
960 }
963 /********************
964 Display subdialog
965 ********************/
967 /* Show tab dialog if object is present */
968 if(isset($this->usertab->config)){
970 $display= $this->usertab->execute();
972 /* Don't show buttons if tab dialog requests this */
974 $dia = FALSE;
975 if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){
976 $dia = $this->usertab->by_object[$this->usertab->current]->dialog;
977 }
979 if(!is_object($dia) && $dia != TRUE){
980 $display.= "<p style=\"text-align:right\">\n";
981 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
982 $display.= " \n";
983 if ($this->dn != "new"){
984 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
985 $display.= " \n";
986 }
987 $display.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
988 $display.= "</p>";
989 }
990 return ($display);
991 }
993 /* Check if there is a snapshot dialog open */
994 $base = $this->DivListUsers->selectedBase;
995 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
996 return($str);
997 }
999 /* Return rendered main page */
1000 /* Display dialog with system list */
1001 $this->DivListUsers->parent = $this;
1002 $this->DivListUsers->execute();
1004 /* Add departments if subsearch is disabled */
1005 if(!$this->DivListUsers->SubSearch){
1006 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
1007 }
1008 $this->reload();
1009 $this->DivListUsers->setEntries($this->list);
1010 return($this->DivListUsers->Draw());
1011 }
1014 /* Return departments, that will be included within snapshot detection */
1015 function get_used_snapshot_bases()
1016 {
1017 return(array(get_people_ou().$this->DivListUsers->selectedBase));
1018 }
1021 function reload()
1022 {
1023 /* Set base for all searches */
1024 $base= $this->DivListUsers->selectedBase;
1025 $this->list =array();
1027 /* Get filter configuration */
1028 $Regex = $this->DivListUsers->Regex;
1029 $SubSearch = $this->DivListUsers->SubSearch;
1030 $ShowTemplates = $this->DivListUsers->ShowTemplates;
1031 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
1032 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
1033 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
1034 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
1035 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
1037 /* Setup filter depending on selection */
1038 $filter="";
1039 if ($this->config->current['SAMBAVERSION'] == 3){
1040 $samba= "sambaSamAccount";
1041 } else {
1042 $samba= "sambaAccount";
1043 }
1045 if ($ShowFunctionalUsers){
1046 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
1047 "(objectClass=gosaMailAccount)(objectClass=$samba)".
1048 "(objectClass=gosaProxyAccount))))";
1049 }
1050 if ($ShowUnixUsers){
1051 $filter.= "(objectClass=posixAccount)";
1052 }
1053 if ($ShowMailUsers){
1054 $filter.= "(objectClass=gosaMailAccount)";
1055 }
1056 if ($ShowSambaUsers){
1057 $filter.= "(objectClass=$samba)";
1058 }
1059 if ($ShowProxyUsers){
1060 $filter.= "(objectClass=gosaProxyAccount)";
1061 }
1062 if ($ShowTemplates){
1063 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
1064 } else {
1065 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
1066 }
1067 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
1069 /* Generate userlist */
1070 $ldap= $this->config->get_ldap_link(TRUE);
1072 if ($SubSearch){
1073 $ListTemp = get_sub_list($filter, "users", get_people_ou(),$base,
1074 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
1075 } else {
1076 $base= get_people_ou().$base;
1077 $ListTemp = get_sub_list($filter, "users", get_people_ou(),$base,
1078 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
1079 }
1080 $SortTemp = array();
1081 $List = array();
1082 foreach($ListTemp as $Key => $Entry){
1084 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
1085 * Else winstations will be listed too, if you use the subtree flag.
1086 */
1087 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
1088 continue;
1089 }else{
1091 // Generate caption for rows
1092 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
1093 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
1094 } else {
1095 $display= "[".$Entry["uid"][0]."]";
1096 }
1098 $display = strtolower($display);
1099 $List[$display] = $Entry;
1100 $SortTemp[$display] = $display;
1101 }
1102 }
1103 natcasesort($SortTemp);
1104 reset($SortTemp);
1106 $this->list = array();
1107 foreach($SortTemp as $Key){
1108 $this->list[] = $List[$Key];
1109 }
1110 }
1112 function remove_lock()
1113 {
1114 /* Remove user lock if a DN is marked as "currently edited" */
1115 if (isset($this->usertab->dn)){
1116 del_lock ($this->usertab->dn);
1117 }
1118 }
1121 function copyPasteHandling_from_queue($s_action,$s_entry)
1122 {
1123 /* Check if Copy & Paste is disabled */
1124 if(!is_object($this->CopyPasteHandler)){
1125 return("");
1126 }
1128 /* Add a single entry to queue */
1129 if($s_action == "cut" || $s_action == "copy"){
1130 /* Cleanup object queue */
1131 $this->CopyPasteHandler->cleanup_queue();
1132 $dn = $this->list[$s_entry]['dn'];
1133 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
1134 }
1136 /* Add entries to queue */
1137 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1139 /* Cleanup object queue */
1140 $this->CopyPasteHandler->cleanup_queue();
1142 /* Add new entries to CP queue */
1143 foreach($this->list_get_selected_items() as $id){
1144 $dn = $this->list[$id]['dn'];
1146 if($s_action == "copy_multiple"){
1147 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
1148 }
1149 if($s_action == "cut_multiple"){
1150 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
1151 }
1152 }
1153 }
1155 /* Start pasting entries */
1156 if($s_action == "editPaste"){
1157 $this->start_pasting_copied_objects = TRUE;
1158 }
1160 /* Return C&P dialog */
1161 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1163 /* Get dialog */
1164 $data = $this->CopyPasteHandler->execute();
1165 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
1167 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
1168 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
1169 $s_entry = $this->CopyPasteHandler->last_entry();
1170 $this->reload();
1171 foreach($this->list as $key => $entry){
1172 if($entry['dn'] == $s_entry){
1173 $this->CPPasswordChange = $key;
1174 }
1175 }
1176 }
1178 /* Return dialog data */
1179 if(!empty($data) && $this->CPPasswordChange == ""){
1180 return($data);
1181 }
1182 }
1184 /* Automatically disable status for pasting */
1185 if(!$this->CopyPasteHandler->entries_queued()){
1186 $this->start_pasting_copied_objects = FALSE;
1187 }
1188 return("");
1189 }
1192 function save_object()
1193 {
1194 /* Handle divlist filter && department selection*/
1195 if(!is_object($this->usertab)){
1196 $this->DivListUsers->save_object();
1197 }
1198 if(is_object($this->CopyPasteHandler)){
1199 $this->CopyPasteHandler->save_object();
1200 }
1201 }
1204 function list_get_selected_items()
1205 {
1206 $ids = array();
1207 foreach($_POST as $name => $value){
1208 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1209 $id = preg_replace("/^item_selected_/","",$name);
1210 $ids[$id] = $id;
1211 }
1212 }
1213 return($ids);
1214 }
1217 /* A set of disabled and therefore overloaded functions. They are
1218 not needed in this class. */
1219 function remove_from_parent() { }
1220 function check() { }
1221 function save() { }
1222 function adapt_from_template($dn, $skip= array()) { }
1223 function password_change_needed() { }
1225 } /* ... class userManagement */
1226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1227 ?>