50009650714d8e5935f91e27039fe4f8669e1bb3
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 "ftpusers" => "checked",
52 "faxusers" => "checked",
53 "functionalusers" => "checked",
54 "depselect" => $base,
55 "regex" => "*");
56 register_global("userfilter", $userfilter);
57 }
58 }
60 function execute()
61 {
62 $smarty= get_smarty();
63 $userfilter= get_global("userfilter");
65 /* Save filter data if we are in the headpage */
66 if (!isset($this->usertab)){
67 foreach( array("depselect", "regex") as $type){
68 if (isset($_POST[$type])){
69 $userfilter[$type]= $_POST[$type];
70 }
71 }
72 if (isset($_POST['depselect'])){
73 foreach( array("functionalusers", "unixusers", "mailusers",
74 "sambausers", "proxyusers", "ftpusers",
75 "faxusers", "templates", "subsearch") as $type){
77 if (isset($_POST[$type])) {
78 $userfilter[$type]= "checked";
79 } else {
80 $userfilter[$type]= "";
81 }
82 }
83 }
84 if (isset($_GET['search'])){
85 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
86 if ($s == "**"){
87 $s= "*";
88 }
89 $userfilter['regex']= $s;
90 }
91 register_global("userfilter", $userfilter);
92 }
94 /* React on user interaction here */
95 if ($_SERVER["REQUEST_METHOD"] == "POST"){
97 /* User wants to edit data? */
98 if ( (isset($_POST['select_user']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['userlist']) && $_POST['userlist'] != ""){
100 /* Get 'dn' from posted 'uid', must be unique */
101 $this->dn= trim($_POST['userlist']);
103 /* Check locking, save current plugin in 'back_plugin', so
104 the dialog knows where to return. */
105 if (($user= get_lock($this->dn)) != ""){
106 return(gen_locked_message ($user, $this->dn));
107 }
109 /* Lock the current entry, so everyone will get the
110 above dialog */
111 add_lock ($this->dn, $this->ui->dn);
113 /* Set up the users ACL's for this 'dn' */
114 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
116 /* Register usertab to trigger edit dialog */
117 $this->usertab= new usertabs($this->config,
118 $this->config->data['TABS']['USERTABS'], $this->dn);
119 $this->usertab->set_acl($acl);
121 $_SESSION['objectinfo']= $this->dn;
122 }
123 }
125 /* Reset requested? */
126 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
127 if (isset($this->usertab)){
128 del_lock ($this->usertab->dn);
129 unset ($this->usertab);
130 }
131 $this->usertab= NULL;
132 $this->lognames= array();;
133 $this->sn= "";
134 $this->givenName= "";
135 $this->uid= "";
136 unset ($_SESSION['objectinfo']);
137 }
139 /* Password change requested */
140 if (isset($_POST['setpass_user']) && isset($_POST['userlist'])){
142 /* Get 'dn' from posted 'uid' */
143 $this->dn= trim($_POST['userlist']);
145 /* Load permissions for selected 'dn' and check if
146 we're allowed to remove this 'dn' */
147 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
148 $acl= get_module_permission($acl, "user", $this->dn);
149 if (chkacl($acl, "password") == ""){
151 /* User is allowed to change passwords, save 'dn' and 'acl' for next
152 dialog. */
153 $this->acl= $acl;
154 $_SESSION['objectinfo']= $this->dn;
155 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
157 } else {
158 /* User is not allowed. Show message and cancel. */
159 print_red (_("You are not allowed to set this users password!"));
160 }
161 }
163 /* Perform password change */
164 if (isset($_POST['password_finish'])){
166 /* For security reasons, check if user is allowed to set password again */
167 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
169 /* Check input and feed errors into 'message' */
170 $message= array();
172 /* Sanity checks... */
173 if ($_POST['new_password'] != $_POST['repeated_password']){
175 /* Matching passwords in new and repeated? */
176 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
177 } else {
179 /* Empty password is not permitted by default. */
180 if ($_POST['new_password'] == ""){
181 $message[]= _("The password you've entered as 'New password' is empty.");
182 }
183 }
185 /* Errors, or change password? */
186 if (count($message) != 0){
188 /* Show error message and continue editing */
189 show_errors ($message);
190 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
191 }
193 /* Set password, perform required steps */
194 if ($this->usertab){
195 if ($this->usertab->password_change_needed()){
196 $obj= $this->usertab->by_object['user'];
197 change_password ($this->usertab->dn, $_POST['new_password'],
198 0, $obj->pw_storage);
199 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
200 unset($this->usertab);
201 $this->usertab= NULL;
202 }
203 } else {
204 change_password ($this->dn, $_POST['new_password']);
205 gosa_log ("Password for '".$this->dn."' has been changed");
206 }
207 } else {
209 /* Missing permissions, show message */
210 print_red (_("You are not allowed to set this users password!"));
211 }
213 /* Clean session, delete lock */
214 del_lock ($this->dn);
215 $this->reload();
216 unset ($this->usertab);
217 $this->usertab= NULL;
218 $this->lognames= array();;
219 $this->sn= "";
220 $this->givenName= "";
221 $this->uid= "";
222 unset ($_SESSION['objectinfo']);
223 }
226 /* Remove user was requested */
227 if (isset($_POST['delete_user']) && isset($_POST['userlist'])){
229 /* Get 'dn' from posted 'uid' */
230 $this->dn= trim($_POST['userlist']);
232 /* Load permissions for selected 'dn' and check if
233 we're allowed to remove this 'dn' */
234 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
235 $this->acl= get_module_permission($acl, "user", $this->dn);
236 if (chkacl($this->acl, "delete") == ""){
238 /* Check locking, save current plugin in 'back_plugin', so
239 the dialog knows where to return. */
240 if (($user= get_lock($this->dn)) != ""){
241 return(gen_locked_message ($user, $this->dn));
242 }
244 /* Lock the current entry, so nobody will edit it during deletion */
245 add_lock ($this->dn, $this->ui->dn);
246 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
247 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
248 } else {
250 /* Obviously the user isn't allowed to delete. Show message and
251 clean session. */
252 print_red (_("You are not allowed to delete this user!"));
253 }
254 }
258 /* Confirmation for deletion has been passed. User should be deleted. */
259 if (isset($_POST['delete_user_confirm'])){
261 /* Some nice guy may send this as POST, so we've to check
262 for the permissions again. */
263 if (chkacl($this->acl, "delete") == ""){
265 /* Delete request is permitted, perform LDAP action */
266 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
267 $this->dn);
268 $this->usertab->set_acl(array($this->acl));
269 $this->usertab->delete ();
270 gosa_log ("User object '".$this->dn."' has been removed");
271 unset ($this->usertab);
272 $this->usertab= NULL;
274 /* User list has changed, reload it. */
275 $this->reload ();
276 } else {
278 /* Normally this shouldn't be reached, send some extra
279 logs to notify the administrator */
280 print_red (_("You are not allowed to delete this user!"));
282 if(isset($this->ui->uid)){
283 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
284 }
285 }
287 /* Remove lock file after successfull deletion */
288 del_lock ($this->dn);
289 }
292 /* Delete user canceled? */
293 if (isset($_POST['delete_cancel'])){
294 del_lock ($this->dn);
295 }
298 /* Finish user edit is triggered by the tabulator dialog, so
299 the user wants to save edited data. Check and save at this
300 point. */
301 if (isset($_POST['edit_finish'])){
303 /* Check tabs, will feed message array */
304 $this->usertab->last= $this->usertab->current;
305 $this->usertab->save_object();
306 $message= $this->usertab->check();
308 /* Save, or display error message? */
309 if (count($message) == 0){
311 /* No errors. Go ahead and prepare to ask for a password
312 in case we're creating a new user. 'dn' will be 'new'
313 in this case. It is set to the correct value later. */
314 if ($this->dn == "new"){
315 $set_pass= 1;
316 } else {
317 $set_pass= 0;
318 }
320 /* Save user data to ldap */
321 if($this->usertab->save() == 1){
322 gosa_log ("User object '".$this->dn."' saving failed.");
323 return;
324 }
325 gosa_log ("User object '".$this->dn."' has been saved");
327 /* User has been saved successfully, remove lock from
328 LDAP. */
329 if ($this->dn != "new"){
330 del_lock ($this->dn);
331 }
333 /* In case of new users, ask for a password */
334 if (($set_pass || $this->usertab->password_change_needed()) &&
335 !$this->is_template){
337 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
338 }
340 /* There's no page reload so we have to read new users at
341 this point. */
342 $this->reload ();
343 unset ($this->usertab);
344 $this->usertab= NULL;
345 unset ($_SESSION['objectinfo']);
347 } else {
348 /* Ok. There seem to be errors regarding to the tab data,
349 show message and continue as usual. */
350 show_errors($message);
351 }
352 }
354 /* Generate template list */
355 if (isset($_POST['new_user'])){
356 $this->templates= array();
357 $ldap= $this->config->get_ldap_link();
358 foreach ($this->config->departments as $key => $value){
359 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
360 $acl= get_module_permission($acl, "user", get_people_ou().$value);
361 if (chkacl($acl, "create") == ""){
362 $ldap->cd (get_people_ou().$value);
363 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
365 if ($ldap->count() != 0){
366 while ($attrs= $ldap->fetch()){
367 $this->templates[$ldap->getDN()]=
368 $attrs['uid'][0]." - $key";
369 }
370 $this->templates['none']= _("none");
371 }
372 }
373 }
374 natcasesort ($this->templates);
375 reset ($this->templates);
376 }
378 /* New user/template request */
379 if (isset($_POST['new_user']) || isset($_POST['new_template'])){
381 /* By default we set 'dn' to 'new', all relevant plugins will
382 react on this. */
383 $this->dn= "new";
384 if (isset($this->config->current['IDGEN'])){
385 $this->got_uid= false;
386 } else {
387 $this->got_uid= true;
388 }
390 /* Create new usertab object */
391 $this->usertab= new usertabs($this->config,
392 $this->config->data['TABS']['USERTABS'], $this->dn);
393 $this->usertab->set_acl(array(':all'));
395 /* Take care about templates */
396 if (isset($_POST['new_template'])){
397 $this->is_template= TRUE;
398 $this->usertab->set_template_mode ();
399 } else {
400 $this->is_template= FALSE;
401 }
403 /* Use template if there are any of them */
404 if (count($this->templates) && !isset($_POST['new_template'])){
405 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
406 $smarty->assign("$attr", $this->$attr);
407 }
408 if (isset($_POST['template'])){
409 $smarty->assign("template", $_POST['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", "ftpusers",
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=PureFTPdUser)(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['ftpusers'] == "checked"){
592 $filter.= "(objectClass=PureFTPdUser)";
593 }
594 if ($userfilter['faxusers'] == "checked"){
595 $filter.= "(objectClass=goFaxAccount)";
596 }
598 if ($userfilter['templates'] == "checked"){
599 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
600 } else {
601 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
602 }
603 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
605 /* Generate userlist */
606 $ldap= $this->config->get_ldap_link(TRUE);
607 if ($userfilter['subsearch'] == "checked"){
608 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
609 } else {
610 $base= get_people_ou().$base;
611 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
612 }
614 $this->userlist= array();
616 foreach ($this->list as $value){
617 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
618 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
619 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
620 continue;
621 }
622 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
623 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
624 $value["givenName"][0].
625 " [".$value["uid"][0]."]";
626 } else {
627 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
628 }
629 }
630 }
631 natcasesort ($this->userlist);
632 reset ($this->userlist);
633 }
635 function remove_from_parent()
636 {
637 }
640 /* Check values */
641 function check()
642 {
643 }
646 /* Save to LDAP */
647 function save()
648 {
649 }
651 function adapt_from_template($dn)
652 {
653 }
655 function password_change_needed()
656 {
657 }
659 function show_header($button_text, $text, $disabled= FALSE)
660 {
661 }
663 function remove_lock()
664 {
665 if (isset($this->usertab->dn)){
666 del_lock ($this->usertab->dn);
667 }
668 }
670 }
672 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
673 ?>