3dfc051e60fc6b04a8d3f176ac2d1a98871c562d
1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Users";
26 var $plDescription= "This does something";
28 /* Dialog attributes */
29 var $usertab= NULL;
30 var $userlist= array();
31 var $ui= NULL;
32 var $acl= "";
33 var $templates= array();
34 var $got_uid= false;
36 function userManagement ($config, $ui)
37 {
38 /* Save configuration for internal use */
39 $this->config= $config;
40 $this->ui= $ui;
42 /* Get global filter config */
43 if (!is_global("userfilter")){
44 $base= get_base_from_people($ui->dn);
45 $userfilter= array( "mailusers" => "checked",
46 "unixusers" => "checked",
47 "templates" => "",
48 "subsearch" => "",
49 "proxyusers" => "checked",
50 "sambausers" => "checked",
51 "faxusers" => "checked",
52 "functionalusers" => "checked",
53 "depselect" => $base,
54 "regex" => "*");
55 register_global("userfilter", $userfilter);
56 }
57 }
59 function execute()
60 {
61 $smarty= get_smarty();
62 $userfilter= get_global("userfilter");
64 /* Save filter data if we are in the headpage */
65 if (!isset($this->usertab)){
66 foreach( array("depselect", "regex") as $type){
67 if (isset($_POST[$type])){
68 $userfilter[$type]= $_POST[$type];
69 }
70 }
71 if (isset($_POST['depselect'])){
72 foreach( array("functionalusers", "unixusers", "mailusers",
73 "sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
75 if (isset($_POST[$type])) {
76 $userfilter[$type]= "checked";
77 } else {
78 $userfilter[$type]= "";
79 }
80 }
81 }
82 if (isset($_GET['search'])){
83 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
84 if ($s == "**"){
85 $s= "*";
86 }
87 $userfilter['regex']= $s;
88 }
89 register_global("userfilter", $userfilter);
90 }
92 /* React on user interaction here */
93 if ($_SERVER["REQUEST_METHOD"] == "POST"){
95 /* User wants to edit data? */
96 if ( (isset($_POST['select_user']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['userlist']) && $_POST['userlist'] != ""){
98 /* Get 'dn' from posted 'uid', must be unique */
99 $this->dn= trim($_POST['userlist']);
101 /* Check locking, save current plugin in 'back_plugin', so
102 the dialog knows where to return. */
103 if (($user= get_lock($this->dn)) != ""){
104 return(gen_locked_message ($user, $this->dn));
105 }
107 /* Lock the current entry, so everyone will get the
108 above dialog */
109 add_lock ($this->dn, $this->ui->dn);
111 /* Set up the users ACL's for this 'dn' */
112 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
114 /* Register usertab to trigger edit dialog */
115 $this->usertab= new usertabs($this->config,
116 $this->config->data['TABS']['USERTABS'], $this->dn);
117 $this->usertab->set_acl($acl);
119 $_SESSION['objectinfo']= $this->dn;
120 }
121 }
123 /* Reset requested? */
124 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
125 if (isset($this->usertab)){
126 del_lock ($this->usertab->dn);
127 unset ($this->usertab);
128 }
129 $this->usertab= NULL;
130 $this->lognames= array();;
131 $this->sn= "";
132 $this->givenName= "";
133 $this->uid= "";
134 unset ($_SESSION['objectinfo']);
135 }
137 /* Password change requested */
138 if (isset($_POST['setpass_user']) && isset($_POST['userlist'])){
140 /* Get 'dn' from posted 'uid' */
141 $this->dn= trim($_POST['userlist']);
143 /* Load permissions for selected 'dn' and check if
144 we're allowed to remove this 'dn' */
145 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
146 $acl= get_module_permission($acl, "user", $this->dn);
147 if (chkacl($acl, "password") == ""){
149 /* User is allowed to change passwords, save 'dn' and 'acl' for next
150 dialog. */
151 $this->acl= $acl;
152 $_SESSION['objectinfo']= $this->dn;
153 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
155 } else {
156 /* User is not allowed. Show message and cancel. */
157 print_red (_("You are not allowed to set this users password!"));
158 }
159 }
161 /* Perform password change */
162 if (isset($_POST['password_finish'])){
164 /* For security reasons, check if user is allowed to set password again */
165 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
167 /* Check input and feed errors into 'message' */
168 $message= array();
170 /* Sanity checks... */
171 if ($_POST['new_password'] != $_POST['repeated_password']){
173 /* Matching passwords in new and repeated? */
174 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
175 } else {
177 /* Empty password is not permitted by default. */
178 if ($_POST['new_password'] == ""){
179 $message[]= _("The password you've entered as 'New password' is empty.");
180 }
181 }
183 /* Errors, or change password? */
184 if (count($message) != 0){
186 /* Show error message and continue editing */
187 show_errors ($message);
188 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
189 }
191 /* Set password, perform required steps */
192 if ($this->usertab){
193 if ($this->usertab->password_change_needed()){
194 $obj= $this->usertab->by_object['user'];
195 change_password ($this->usertab->dn, $_POST['new_password'],
196 0, $obj->pw_storage);
197 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
198 unset($this->usertab);
199 $this->usertab= NULL;
200 }
201 } else {
202 change_password ($this->dn, $_POST['new_password']);
203 gosa_log ("Password for '".$this->dn."' has been changed");
204 }
205 } else {
207 /* Missing permissions, show message */
208 print_red (_("You are not allowed to set this users password!"));
209 }
211 /* Clean session, delete lock */
212 del_lock ($this->dn);
213 $this->reload();
214 unset ($this->usertab);
215 $this->usertab= NULL;
216 $this->lognames= array();;
217 $this->sn= "";
218 $this->givenName= "";
219 $this->uid= "";
220 unset ($_SESSION['objectinfo']);
221 }
224 /* Remove user was requested */
225 if (isset($_POST['delete_user']) && isset($_POST['userlist'])){
227 /* Get 'dn' from posted 'uid' */
228 $this->dn= trim($_POST['userlist']);
230 /* Load permissions for selected 'dn' and check if
231 we're allowed to remove this 'dn' */
232 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
233 $this->acl= get_module_permission($acl, "user", $this->dn);
234 if (chkacl($this->acl, "delete") == ""){
236 /* Check locking, save current plugin in 'back_plugin', so
237 the dialog knows where to return. */
238 if (($user= get_lock($this->dn)) != ""){
239 return(gen_locked_message ($user, $this->dn));
240 }
242 /* Lock the current entry, so nobody will edit it during deletion */
243 add_lock ($this->dn, $this->ui->dn);
244 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
245 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
246 } else {
248 /* Obviously the user isn't allowed to delete. Show message and
249 clean session. */
250 print_red (_("You are not allowed to delete this user!"));
251 }
252 }
256 /* Confirmation for deletion has been passed. User should be deleted. */
257 if (isset($_POST['delete_user_confirm'])){
259 /* Some nice guy may send this as POST, so we've to check
260 for the permissions again. */
261 if (chkacl($this->acl, "delete") == ""){
263 /* Delete request is permitted, perform LDAP action */
264 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
265 $this->dn);
266 $this->usertab->set_acl(array($this->acl));
267 $this->usertab->delete ();
268 gosa_log ("User object '".$this->dn."' has been removed");
269 unset ($this->usertab);
270 $this->usertab= NULL;
272 /* User list has changed, reload it. */
273 $this->reload ();
274 } else {
276 /* Normally this shouldn't be reached, send some extra
277 logs to notify the administrator */
278 print_red (_("You are not allowed to delete this user!"));
280 if(isset($this->ui->uid)){
281 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
282 }
283 }
285 /* Remove lock file after successfull deletion */
286 del_lock ($this->dn);
287 }
290 /* Delete user canceled? */
291 if (isset($_POST['delete_cancel'])){
292 del_lock ($this->dn);
293 }
296 /* Finish user edit is triggered by the tabulator dialog, so
297 the user wants to save edited data. Check and save at this
298 point. */
299 if (isset($_POST['edit_finish'])){
301 /* Check tabs, will feed message array */
302 $this->usertab->last= $this->usertab->current;
303 $this->usertab->save_object();
304 $message= $this->usertab->check();
306 /* Save, or display error message? */
307 if (count($message) == 0){
309 /* No errors. Go ahead and prepare to ask for a password
310 in case we're creating a new user. 'dn' will be 'new'
311 in this case. It is set to the correct value later. */
312 if ($this->dn == "new"){
313 $set_pass= 1;
314 } else {
315 $set_pass= 0;
316 }
318 /* Save user data to ldap */
319 if($this->usertab->save() == 1){
320 gosa_log ("User object '".$this->dn."' saving failed.");
321 return;
322 }
323 gosa_log ("User object '".$this->dn."' has been saved");
325 /* User has been saved successfully, remove lock from
326 LDAP. */
327 if ($this->dn != "new"){
328 del_lock ($this->dn);
329 }
331 /* In case of new users, ask for a password */
332 if (($set_pass || $this->usertab->password_change_needed()) &&
333 !$this->is_template){
335 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
336 }
338 /* There's no page reload so we have to read new users at
339 this point. */
340 $this->reload ();
341 unset ($this->usertab);
342 $this->usertab= NULL;
343 unset ($_SESSION['objectinfo']);
345 } else {
346 /* Ok. There seem to be errors regarding to the tab data,
347 show message and continue as usual. */
348 show_errors($message);
349 }
350 }
352 /* Generate template list */
353 if (isset($_POST['new_user'])){
354 $this->templates= array();
355 $ldap= $this->config->get_ldap_link();
356 foreach ($this->config->departments as $key => $value){
357 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
358 $acl= get_module_permission($acl, "user", get_people_ou().$value);
359 if (chkacl($acl, "create") == ""){
360 $ldap->cd (get_people_ou().$value);
361 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
363 if ($ldap->count() != 0){
364 while ($attrs= $ldap->fetch()){
365 $this->templates[$ldap->getDN()]=
366 $attrs['uid'][0]." - $key";
367 }
368 $this->templates['none']= _("none");
369 }
370 }
371 }
372 natcasesort ($this->templates);
373 reset ($this->templates);
374 }
376 /* New user/template request */
377 if (isset($_POST['new_user']) || isset($_POST['new_template'])){
379 /* By default we set 'dn' to 'new', all relevant plugins will
380 react on this. */
381 $this->dn= "new";
382 if (isset($this->config->current['IDGEN'])){
383 $this->got_uid= false;
384 } else {
385 $this->got_uid= true;
386 }
388 /* Create new usertab object */
389 $this->usertab= new usertabs($this->config,
390 $this->config->data['TABS']['USERTABS'], $this->dn);
391 $this->usertab->set_acl(array(':all'));
393 /* Take care about templates */
394 if (isset($_POST['new_template'])){
395 $this->is_template= TRUE;
396 $this->usertab->set_template_mode ();
397 } else {
398 $this->is_template= FALSE;
399 }
401 /* Use template if there are any of them */
402 if (count($this->templates) && !isset($_POST['new_template'])){
403 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
404 $smarty->assign("$attr", $this->$attr);
405 }
406 if (isset($_POST['template'])){
407 $smarty->assign("template", $_POST['template']);
408 } else {
409 $smarty->assign("template", "");
410 }
411 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
412 }
414 }
416 /* Continue template editing */
417 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
418 $this->sn= $_POST['sn'];
419 $this->givenName= $_POST['givenName'];
421 /* Check for requred values */
422 $message= array();
423 if ($this->sn == "") {
424 $message[]= _("The required field 'Name' is not set.");
425 }
426 if ($this->givenName == "") {
427 $message[]= _("The required field 'Given name' is not set.");
428 }
430 /* Check if dn is used */
431 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
432 $ldap= $this->config->get_ldap_link();
433 $ldap->cd ($dn);
434 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
435 if ($ldap->count () != 0){
436 $message[]= _("A person with the choosen name is already used in this tree.");
437 }
439 /* Show error message / continue editing */
440 if (count($message) > 0){
441 show_errors ($message);
442 } else {
443 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
444 if (isset($this->config->current['IDGEN']) &&
445 $this->config->current['IDGEN'] != ""){
446 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
447 if (count($uids)){
448 $smarty->assign("edit_uid", "false");
449 $smarty->assign("uids", $uids);
450 $this->uid= current($uids);
451 }
452 } else {
453 $this->uid= "";
454 }
455 $this->got_uid= true;
456 }
458 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
459 $smarty->assign("$attr", $this->$attr);
460 }
461 if (isset($_POST['template'])){
462 $smarty->assign("template", $_POST['template']);
463 }
464 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
465 }
467 /* No template. Ok. Lets fill data into the normal user dialog */
468 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
469 foreach(array("sn", "givenName", "uid") as $attr){
470 if (isset($_POST[$attr])){
471 $this->usertab->by_object['user']->$attr= $_POST[$attr];
472 }
473 }
474 }
476 /* Finish template preamble */
477 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
479 /* Might not be filled if IDGEN is unset */
480 $this->sn= $_POST['sn'];
481 $this->givenName= $_POST['givenName'];
483 /* Move user supplied data to sub plugins */
484 $this->uid= $_POST['uid'];
485 $this->usertab->uid= $this->uid;
486 $this->usertab->sn= $this->sn;
487 $this->usertab->givenName= $this->givenName;
488 $template_dn= $_POST['template'];
489 $this->usertab->adapt_from_template($template_dn);
490 $template_base= preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
491 $this->usertab->by_object['user']->base= $template_base;
493 /* Set up the users ACL's for this 'dn' */
494 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
495 $this->usertab->set_acl($acl);
496 }
498 /* Show tab dialog if object is present */
499 if ($this->usertab){
500 $display= $this->usertab->execute();
502 /* Don't show buttons if tab dialog requests this */
503 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
504 $display.= "<p style=\"text-align:right\">\n";
505 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
506 $display.= " \n";
507 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
508 $display.= "</p>";
509 }
510 return ($display);
511 }
513 $smarty= get_smarty();
515 /* Check sorting variable */
516 if (!isset($this->usertab) &&
517 !isset($_POST['new_user']) &&
518 !isset($_POST['new_template']) &&
519 !isset($_POST['delete_user']) &&
520 !isset($_POST['setpass_user']) &&
521 !isset($_POST['select_user'])){
522 $this->reload();
523 }
525 /* Check for exeeded sizelimit */
526 if (($message= check_sizelimit()) != ""){
527 return($message);
528 }
530 /* Show main page */
531 $smarty->assign("userlist", $this->userlist);
532 $smarty->assign("search_image", get_template_path('images/search.png'));
533 $smarty->assign("tree_image", get_template_path('images/tree.png'));
534 $smarty->assign("infoimage", get_template_path('images/info.png'));
535 $smarty->assign("launchimage", get_template_path('images/launch.png'));
536 $smarty->assign("deplist", $this->config->idepartments);
537 foreach( array("depselect", "regex", "functionalusers", "unixusers",
538 "mailusers", "sambausers", "proxyusers",
539 "faxusers", "templates", "subsearch") as $type){
541 $smarty->assign("$type", $userfilter[$type]);
542 }
544 /* Extend if we are not using javascript */
545 $smarty->assign("apply", apply_filter());
546 $smarty->assign("alphabet", generate_alphabet());
547 $smarty->assign("hint", print_sizelimit_warning());
549 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
550 }
553 function reload()
554 {
555 /* Get config */
556 $userfilter= get_global('userfilter');
558 /* Set base for all searches */
559 $base= $userfilter['depselect'];
561 /* Regex filter? */
562 if ($userfilter['regex'] != ""){
563 $regex= $userfilter['regex'];
564 } else {
565 $regex= "*";
566 }
568 /* Set filter depending on selection */
569 if ($this->config->current['SAMBAVERSION'] == 3){
570 $samba= "sambaSamAccount";
571 } else {
572 $samba= "sambaAccount";
573 }
575 $filter="";
576 if ($userfilter['functionalusers'] == "checked"){
577 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
578 }
579 if ($userfilter['unixusers'] == "checked"){
580 $filter.= "(objectClass=posixAccount)";
581 }
582 if ($userfilter['mailusers'] == "checked"){
583 $filter.= "(objectClass=gosaMailAccount)";
584 }
585 if ($userfilter['sambausers'] == "checked"){
586 $filter.= "(objectClass=$samba)";
587 }
588 if ($userfilter['proxyusers'] == "checked"){
589 $filter.= "(objectClass=gosaProxyAccount)";
590 }
591 if ($userfilter['faxusers'] == "checked"){
592 $filter.= "(objectClass=goFaxAccount)";
593 }
595 if ($userfilter['templates'] == "checked"){
596 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
597 } else {
598 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
599 }
600 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
602 /* Generate userlist */
603 $ldap= $this->config->get_ldap_link(TRUE);
604 if ($userfilter['subsearch'] == "checked"){
605 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
606 } else {
607 $base= get_people_ou().$base;
608 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
609 }
611 $this->userlist= array();
613 foreach ($this->list as $value){
614 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
615 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
616 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
617 continue;
618 }
619 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
620 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
621 $value["givenName"][0].
622 " [".$value["uid"][0]."]";
623 } else {
624 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
625 }
626 }
627 }
628 natcasesort ($this->userlist);
629 reset ($this->userlist);
630 }
632 function remove_from_parent()
633 {
634 }
637 /* Check values */
638 function check()
639 {
640 }
643 /* Save to LDAP */
644 function save()
645 {
646 }
648 function adapt_from_template($dn)
649 {
650 }
652 function password_change_needed()
653 {
654 }
656 function show_header($button_text, $text, $disabled= FALSE)
657 {
658 }
660 function remove_lock()
661 {
662 if (isset($this->usertab->dn)){
663 del_lock ($this->usertab->dn);
664 }
665 }
667 }
669 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
670 ?>