3970c7727e89d75441678e68bca8d0e2026908a0
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;
35 var $departments=array();
37 var $CopyPasteHandler ;
38 var $enableCopyPaste = false;
40 function userManagement ($config, $ui)
41 {
42 /* Save configuration for internal use */
43 $this->config= $config;
44 $this->ui= $ui;
46 /* Copy & Paste handler */
47 if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){
48 $this->enableCopyPaste = true;
49 }
50 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
52 /* Get global filter config */
53 if (!isset($_SESSION["userfilter"])){
54 $base= get_base_from_people($ui->dn);
55 $userfilter= array( "mailusers" => "checked",
56 "unixusers" => "checked",
57 "templates" => "",
58 "subsearch" => "",
59 "proxyusers" => "checked",
60 "sambausers" => "checked",
61 "faxusers" => "checked",
62 "functionalusers" => "checked",
63 "depselect" => $base,
64 "regex" => "*");
65 $_SESSION["userfilter"] = $userfilter;
66 }
67 }
69 function execute()
70 {
71 /* Call parent execute */
72 plugin::execute();
74 /* LOCK MESSAGE Vars */
75 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
78 $smarty = get_smarty(); // Smarty instance
79 $userfilter = get_global("userfilter"); // contains Filter Settings
80 $s_action = ""; // Contains the action to proceed
81 $s_entry = ""; // The value for s_action
82 $base_back = ""; // The Link for Backbutton
84 /* Start for New List Managment */
85 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
86 $s_action="open";
87 $s_entry = base64_decode($_GET['dep_id']);
88 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
89 }
91 /* Test Posts */
92 foreach($_POST as $key => $val){
93 // Post for delete
94 if(preg_match("/user_del.*/",$key)){
95 $s_action = "del";
96 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
97 // Post for edit
98 }elseif(preg_match("/user_edit_.*/",$key)){
99 $s_action="edit";
100 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
101 // Post for new
102 }elseif(preg_match("/dep_back.*/i",$key)){
103 $s_action="back";
104 }elseif(preg_match("/user_new.*/",$key)){
105 $s_action="new";
106 }elseif(preg_match("/dep_home.*/i",$key)){
107 $s_action="home";
108 }elseif(preg_match("/user_tplnew.*/i",$key)){
109 $s_action="new_tpl";
110 }elseif(preg_match("/user_chgpw.*/i",$key)){
111 $s_action="change_pw";
112 $s_entry = preg_replace("/user_chgpw_/i","",$key);
113 }elseif(preg_match("/dep_root.*/i",$key)){
114 $s_action="root";
115 }elseif(preg_match("/userfrom_tpl.*/i",$key)){
116 $s_action="create_user_from_tpl";
117 $s_entry = preg_replace("/userfrom_tpl_/i","",$key);
118 }elseif(preg_match("/^editPaste.*/i",$key)){
119 $s_action="editPaste";
120 }elseif(preg_match("/^copy_.*/",$key)){
121 $s_action="copy";
122 $s_entry = preg_replace("/^copy_/i","",$key);
123 }elseif(preg_match("/^cut_.*/",$key)){
124 $s_action="cut";
125 $s_entry = preg_replace("/^cut_/i","",$key);
126 }
127 }
129 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
130 $s_action = "edit";
131 $s_entry = $_GET['id'];
132 }
134 $s_entry = preg_replace("/_.$/","",$s_entry);
136 if(preg_match("/.*-.*/",$s_entry)){
137 $s_tab = preg_replace("/^.*-/i","",$s_entry);
138 $s_entry = preg_replace("/-.*$/i","",$s_entry);
139 }else{
140 $s_tab = "user";
141 };
143 /* Department changed? */
144 if(isset($_POST['depselect']) && $_POST['depselect']){
145 $userfilter['depselect']= $_POST['depselect'];
146 }
148 /* Homebutton is posted */
149 if($s_action=="home"){
150 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
151 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
152 }
154 if($s_action=="root"){
155 $userfilter['depselect']=($this->config->current['BASE']);
156 }
159 /* If Backbutton is Posted */
160 if($s_action=="back"){
161 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
162 $base_back = convert_department_dn($base_back);
164 if(isset($this->config->departments[trim($base_back)])){
165 $userfilter['depselect']= $this->config->departments[trim($base_back)];
166 }else{
167 $userfilter['depselect']= $this->config->departments["/"];
168 }
169 }
172 /* Only perform copy / paste if it is enabled
173 */
174 if($this->enableCopyPaste){
176 /* Paste copied/cutted object in here
177 */
178 if(($s_action == "editPaste") || ($this->CopyPasteHandler->stillOpen())){
179 $this->CopyPasteHandler->save_object();
180 $this->CopyPasteHandler->SetVar("base",$userfilter['depselect']);
181 $ret = $this->CopyPasteHandler->execute(false);
182 if($ret) return($ret);
183 $this->reload();
184 $s_action = "change_pw";
185 $dn = $this->CopyPasteHandler->lastdn;
187 foreach($this->list as $id => $entry){
188 if($entry['dn'] == $dn){
189 $s_entry = $id;
190 }
191 }
192 $s_action = "change_pw";
193 }
196 /* Copy current object to CopyHandler
197 */
198 if($s_action == "copy"){
199 $this->CopyPasteHandler->Clear();
201 $dn = $this->list[trim($s_entry)]['dn'];
202 $acl = get_permissions ($dn, $this->ui->subtreeACL);
204 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
205 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
207 $obj->set_acl($acl);
208 $objNew->set_acl($acl);
210 foreach($obj->by_object as $name => $tab){
211 foreach(array("photoData","jpegPhoto","is_account") as $attr){
212 if(isset($obj->by_object[$name]->$attr)){
213 $objNew->by_object[$name]->$attr = $obj->by_object[$name]->$attr;
214 }
215 }
216 }
217 $this->CopyPasteHandler->Copy($obj,$objNew);
218 }
221 /* Copy current object to CopyHandler
222 */
223 if($s_action == "cut"){
224 $this->CopyPasteHandler->Clear();
225 $dn = $this->list[trim($s_entry)]['dn'];
226 $acl= get_permissions ($dn, $this->ui->subtreeACL);
228 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
229 $obj->set_acl($acl);
231 $this->CopyPasteHandler->Cut($obj);
232 }
233 }
235 /* End for new List Managment */
237 /* Save filter data if we are in the headpage */
238 if (!isset($this->usertab)){
239 if (isset($_POST['regexit'])){
240 $userfilter["regex"]= $_POST['regexit'];
241 }
242 }
243 if(isset($_POST['regexit'])){
244 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
245 if (isset($_POST[$type])) {
246 $userfilter[$type]= "checked";
247 } else {
248 $userfilter[$type]= "";
249 }
250 }
251 }
252 if (isset($_GET['search'])){
253 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
254 if ($s == "**"){
255 $s= "*";
256 }
257 $userfilter['regex']= $s;
258 }
259 register_global("userfilter", $userfilter);
262 /* React on user interaction here */
263 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
265 /* User wants to edit data? */
267 /* Check for config to ensure that there is currently no user open */
268 if (($s_action=="edit") && (!isset($this->usertab->config))){
270 /* Get 'dn' from posted 'uid', must be unique */
272 $this->dn= $this->list[trim($s_entry)]['dn'];
274 /* Check locking, save current plugin in 'back_plugin', so
275 the dialog knows where to return. */
276 if (($user= get_lock($this->dn)) != ""){
277 return(gen_locked_message ($user, $this->dn));
278 }
280 /* Lock the current entry, so everyone will get the
281 above dialog */
282 add_lock ($this->dn, $this->ui->dn);
284 /* Set up the users ACL's for this 'dn' */
285 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
287 /* Register usertab to trigger edit dialog */
288 $this->usertab= new usertabs($this->config,
289 $this->config->data['TABS']['USERTABS'], $this->dn);
290 // $_POST[$s_tab]=$s_tab;
292 // This would be better
293 $this->usertab->current = $s_tab;
294 $this->usertab->set_acl($acl);
296 $_SESSION['objectinfo']= $this->dn;
297 }
298 }
300 /* Reset requested? */
301 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
302 if (isset($this->usertab)){
303 del_lock ($this->usertab->dn);
304 unset ($this->usertab);
305 }
306 $this->usertab= NULL;
307 $this->lognames= array();;
308 $this->sn= "";
309 $this->givenName= "";
310 $this->uid= "";
311 unset ($_SESSION['objectinfo']);
312 }
314 /* Password change requested */
315 if ($s_action=="change_pw"){
317 /* Get 'dn' from posted 'uid' */
318 $this->dn= $this->list[trim($s_entry)]['dn'];
320 /* Load permissions for selected 'dn' and check if
321 we're allowed to remove this 'dn' */
322 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
323 $acl= get_module_permission($acl, "user", $this->dn);
324 if (chkacl($acl, "password") == ""){
326 /* User is allowed to change passwords, save 'dn' and 'acl' for next
327 dialog. */
328 $this->acl= $acl;
329 $_SESSION['objectinfo']= $this->dn;
330 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
332 } else {
333 /* User is not allowed. Show message and cancel. */
334 print_red (_("You are not allowed to set this users password!"));
335 }
336 }
338 /* Perform password change */
339 if (isset($_POST['password_finish'])){
341 /* For security reasons, check if user is allowed to set password again */
342 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
344 /* Check input and feed errors into 'message' */
345 $message= array();
347 /* Sanity checks... */
348 if ($_POST['new_password'] != $_POST['repeated_password']){
350 /* Matching passwords in new and repeated? */
351 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
352 } else {
354 /* Empty password is not permitted by default. */
355 if ($_POST['new_password'] == ""){
356 $message[]= _("The password you've entered as 'New password' is empty.");
357 }
358 }
360 /* Errors, or change password? */
361 if (count($message) != 0){
363 /* Show error message and continue editing */
364 show_errors ($message);
365 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
366 }
368 $config= $this->config;
369 $ldap_ui= $this->config->get_ldap_link();
370 if(isset($this->usertab->dn)){
371 $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
372 }else{
373 $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
374 }
375 if((is_array($user))&&(isset($user['uid']))){
376 $username= $user['uid'][0];
377 }
379 /* Set password, perform required steps */
380 if ($this->usertab){
381 if ($this->usertab->password_change_needed()){
382 $obj= $this->usertab->by_object['user'];
383 change_password ($this->usertab->dn, $_POST['new_password'],
384 0, $obj->pw_storage);
385 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
386 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
387 }
389 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
390 unset($this->usertab);
391 $this->usertab= NULL;
392 }
393 } else {
394 change_password ($this->dn, $_POST['new_password']);
395 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
396 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
397 }
399 gosa_log ("Password for '".$this->dn."' has been changed");
400 }
401 } else {
403 /* Missing permissions, show message */
404 print_red (_("You are not allowed to set this users password!"));
405 }
407 /* Clean session, delete lock */
408 del_lock ($this->dn);
409 $this->reload();
410 unset ($this->usertab);
411 $this->usertab= NULL;
412 $this->lognames= array();;
413 $this->sn= "";
414 $this->givenName= "";
415 $this->uid= "";
416 unset ($_SESSION['objectinfo']);
417 }
420 /* Remove user was requested */
421 if ($s_action=="del"){
423 /* Get 'dn' from posted 'uid' */
424 $this->dn= $this->list[trim($s_entry)]['dn'];
426 /* Load permissions for selected 'dn' and check if
427 we're allowed to remove this 'dn' */
428 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
429 $this->acl= get_module_permission($acl, "user", $this->dn);
430 if (chkacl($this->acl, "delete") == ""){
432 /* Check locking, save current plugin in 'back_plugin', so
433 the dialog knows where to return. */
434 if (($user= get_lock($this->dn)) != ""){
435 return(gen_locked_message ($user, $this->dn));
436 }
438 /* Lock the current entry, so nobody will edit it during deletion */
439 add_lock ($this->dn, $this->ui->dn);
440 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), LDAP::fix($this->dn)));
441 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
442 } else {
444 /* Obviously the user isn't allowed to delete. Show message and
445 clean session. */
446 print_red (_("You are not allowed to delete this user!"));
447 }
448 }
452 /* Confirmation for deletion has been passed. User should be deleted. */
453 if (isset($_POST['delete_user_confirm'])){
455 /* Some nice guy may send this as POST, so we've to check
456 for the permissions again. */
457 if (chkacl($this->acl, "delete") == ""){
459 /* Delete request is permitted, perform LDAP action */
460 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
461 $this->dn);
462 $this->usertab->set_acl(array($this->acl));
463 $this->usertab->delete ();
464 gosa_log ("User object '".$this->dn."' has been removed");
465 unset ($this->usertab);
466 $this->usertab= NULL;
468 /* User list has changed, reload it. */
469 $this->reload ();
470 } else {
472 /* Normally this shouldn't be reached, send some extra
473 logs to notify the administrator */
474 print_red (_("You are not allowed to delete this user!"));
476 if(isset($this->ui->uid)){
477 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
478 }
479 }
481 /* Remove lock file after successfull deletion */
482 del_lock ($this->dn);
483 }
486 /* Delete user canceled? */
487 if (isset($_POST['delete_cancel'])){
488 del_lock ($this->dn);
489 }
492 /* Finish user edit is triggered by the tabulator dialog, so
493 the user wants to save edited data. Check and save at this
494 point. */
495 if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){
497 /* Check tabs, will feed message array */
498 $this->usertab->last= $this->usertab->current;
499 $this->usertab->save_object();
500 $message= $this->usertab->check();
502 /* Save, or display error message? */
503 if (count($message) == 0){
505 /* No errors. Go ahead and prepare to ask for a password
506 in case we're creating a new user. 'dn' will be 'new'
507 in this case. It is set to the correct value later. */
508 if ($this->dn == "new"){
509 $set_pass= 1;
510 } else {
511 $set_pass= 0;
512 }
514 /* Save user data to ldap */
515 if($this->usertab->save() == 1){
516 gosa_log ("User object '".$this->dn."' saving failed.");
517 return;
518 }
519 gosa_log ("User object '".$this->dn."' has been saved");
521 /* User has been saved successfully, remove lock from
522 LDAP. */
523 if ($this->dn != "new"){
524 del_lock ($this->dn);
525 }
527 /* In case of new users, ask for a password */
528 if (($set_pass || $this->usertab->password_change_needed()) &&
529 !$this->is_template){
531 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
532 }
534 /* There's no page reload so we have to read new users at
535 this point. */
536 $this->reload ();
537 unset ($this->usertab);
538 $this->usertab= NULL;
539 unset ($_SESSION['objectinfo']);
541 } else {
542 /* Ok. There seem to be errors regarding to the tab data,
543 show message and continue as usual. */
544 show_errors($message);
545 }
546 }
548 /* Generate template list */
549 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
551 $this->templates= array();
553 $ldap= $this->config->get_ldap_link();
555 /* Create list of tempaltes */
556 foreach ($this->config->departments as $key => $value){
558 /* Get acls from different ou's */
559 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
560 $acl= get_module_permission($acl, "user", get_people_ou().$value);
562 /* If creation of a new user is allowed, append this template */
563 if (chkacl($acl, "create") == ""){
565 /* Search all templates from the current dn */
566 $ldap->cd (get_people_ou().$value);
567 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
569 /* Append */
570 if ($ldap->count() != 0){
571 while ($attrs= $ldap->fetch()){
572 $this->templates[$ldap->getDN()]=
573 $attrs['uid'][0]." - $key";
574 }
575 $this->templates['none']= _("none");
576 }
577 }
578 }
580 /* Sort templates */
581 natcasesort ($this->templates);
582 reset ($this->templates);
583 }
585 /* New user/template request */
586 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
587 /* By default we set 'dn' to 'new', all relevant plugins will
588 react on this. */
589 $this->dn= "new";
590 if (isset($this->config->current['IDGEN'])){
591 $this->got_uid= false;
592 } else {
593 $this->got_uid= true;
594 }
596 /* Create new usertab object */
597 $this->usertab= new usertabs($this->config,
598 $this->config->data['TABS']['USERTABS'], $this->dn);
599 $this->usertab->set_acl(array(':all'));
600 $this->usertab->by_object['user']->base= $userfilter['depselect'];
602 /* Take care about templates */
603 if ($s_action=="new_tpl"){
604 $this->is_template= TRUE;
605 $this->usertab->set_template_mode ();
606 } else {
607 $this->is_template= FALSE;
608 }
610 /* Use template if there are any of them */
612 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
613 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
614 $smarty->assign("$attr", $this->$attr);
615 }
616 if ($s_action=="create_user_from_tpl"){
617 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
618 } else {
619 $smarty->assign("template", "none");
620 }
621 $smarty->assign("edit_uid", "");
622 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
623 }
624 }
626 /* Continue template editing */
627 if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
628 $this->sn= $_POST['sn'];
629 $this->givenName= $_POST['givenName'];
631 /* Check for requred values */
632 $message= array();
633 if ($this->sn == "") {
634 $message[]= _("The required field 'Name' is not set.");
635 }
636 if ($this->givenName == "") {
637 $message[]= _("The required field 'Given name' is not set.");
638 }
640 /* Check if dn is used */
641 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
642 $ldap= $this->config->get_ldap_link();
643 $ldap->cd ($dn);
644 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
645 if ($ldap->count () != 0){
646 $message[]= _("A person with the choosen name is already used in this tree.");
647 }
649 /* Show error message / continue editing */
650 if (count($message) > 0){
651 show_errors ($message);
652 } else {
653 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
654 if (isset($this->config->current['IDGEN']) &&
655 $this->config->current['IDGEN'] != ""){
656 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
657 if (count($uids)){
658 $smarty->assign("edit_uid", "false");
659 $smarty->assign("uids", $uids);
660 $this->uid= current($uids);
661 }
662 } else {
663 $smarty->assign("edit_uid", "");
664 $this->uid= "";
665 }
666 $this->got_uid= true;
667 }
669 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
670 $smarty->assign("$attr", $this->$attr);
671 }
672 if (isset($_POST['template'])){
673 $smarty->assign("template", $_POST['template']);
674 }
675 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
676 }
678 /* No template. Ok. Lets fill data into the normal user dialog */
679 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
680 foreach(array("sn", "givenName", "uid") as $attr){
681 if (isset($_POST[$attr])){
682 $this->usertab->by_object['user']->$attr= $_POST[$attr];
683 }
684 }
685 }
687 /* Finish template preamble */
688 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
690 /* Might not be filled if IDGEN is unset */
691 $this->sn = $_POST['sn'];
692 $this->givenName = $_POST['givenName'];
694 /* Move user supplied data to sub plugins */
695 $this->uid = $_POST['uid'];
696 $this->usertab->uid = $this->uid;
697 $this->usertab->sn = $this->sn;
698 $this->usertab->givenName = $this->givenName;
699 $template_dn = $_POST['template'];
700 $this->usertab->adapt_from_template($template_dn);
701 $template_base = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
702 $this->usertab->by_object['user']->base= $template_base;
704 /* Set up the users ACL's for this 'dn' */
705 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
706 $this->usertab->set_acl($acl);
707 }
709 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
710 $this->usertab->by_object['user']->base= $userfilter['depselect'];
711 }
713 /* Show tab dialog if object is present */
714 if(isset($this->usertab->config)){
715 $display= $this->usertab->execute();
717 /* Don't show buttons if tab dialog requests this */
718 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
719 $display.= "<p style=\"text-align:right\">\n";
720 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
721 $display.= " \n";
722 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
723 $display.= "</p>";
724 }
725 return ($display);
726 }
728 $smarty= get_smarty();
730 /* Check sorting variable */
731 if (!isset($this->usertab) &&
732 !isset($_POST['new_user']) &&
733 !isset($_POST['new_template']) &&
734 !isset($_POST['delete_user']) &&
735 !isset($_POST['setpass_user']) &&
736 !isset($_POST['select_user'])){
737 $this->reload();
738 }
740 /* Check for exeeded sizelimit */
741 if (($message= check_sizelimit()) != ""){
742 return($message);
743 }
745 /* Prepare departments */
746 $options= "";
747 foreach ($this->config->idepartments as $key => $value){
748 if ($userfilter['depselect'] == $key){
749 $options.= "<option selected value='$key'>$value</option>";
750 } else {
751 $options.= "<option value='$key'>$value</option>";
752 }
753 }
756 /* Create paste icon
757 */
758 if($this->enableCopyPaste){
759 $Copy_Paste = " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ";
760 if($this->CopyPasteHandler->isCurrentObjectPastAble()){
761 if($this->CopyPasteHandler->isCurrentCutted()){
762 $img = "images/cutpaste.png";
763 }else{
764 $img = "images/copypaste.png";
765 }
766 $Copy_Paste .= "<input type='image' name='editPaste' class='center'
767 src='".$img."' alt='"._("Paste")."' title='".$this->CopyPasteHandler->GetCurrentDn()."'> ";
768 }else{
769 $Copy_Paste .= "<img class='center' src='images/cant_editpaste.png' alt='"._("Can't paste")."'> ";
770 }
771 }else{
772 $Copy_Paste ="";
773 }
776 /* NEW LIST MANAGMENT */
777 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
778 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
779 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
780 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
781 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
782 " <input class='center' type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
783 " <input class='center' type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
784 $Copy_Paste.
785 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
786 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
787 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
788 "</div>";
793 if($this->enableCopyPaste){
794 $action = "<input class='center' type='image'
795 src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
796 $action.= "<input class='center' type='image'
797 src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
798 $action.= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
799 name='user_edit_%KEY%' title='"._("Edit user")."'>";
800 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
801 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
802 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
803 name='user_del_%KEY%' title='"._("Delete user")."'>";
804 }else{
805 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'
806 name='user_edit_%KEY%' title='"._("Edit user")."'>";
807 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."'
808 name='user_chgpw_%KEY%' title='"._("Change password")."'>";
809 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'
810 name='user_del_%KEY%' title='"._("Delete user")."'>";
811 }
815 $divlist = new divlist("userstab");
816 $divlist->SetHeader(array(
817 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
818 array("string" => _("Username")." / "._("Department"), "attach" => "style=''"),
819 array("string" => _("Properties"), "attach" => "style='width:152px;'"),
820 array("string" => _("Actions"), "attach" => "style='width:90px;border-right:0px;text-align:right;'")));
823 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
824 $divlist->SetEntriesPerPage(0);
826 // Defining Links
827 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
829 /* Insert departments in divlist*/
830 foreach($this->departments as $key=> $val){
832 if(!isset($this->config->departments[trim($key)])){
833 $this->config->departments[trim($key)]="";
834 }
836 $non_empty="";
837 $keys= str_replace("/","\/",$key);
838 foreach($this->config->departments as $keyd=>$vald ){
839 if(preg_match("/".$keys."\/.*/",$keyd)){
840 $non_empty="full";
841 }
842 }
844 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
845 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
846 $field3 = array("string" => " ", "attach" => "style='width:152px;'");
847 $field4 = array("string" => " ", "attach" => "style='width:90px;border-right:0px;text-align:right;'");
850 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
851 }
853 /* Pictures for Extensions */
854 $usrimg ="<input class='center' type='image' src='images/penguin.png' alt='"._("GOsa")."'
855 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
856 $posiximg = "<input class='center' type='image' src='images/select_user.png' alt='"._("Posix")."'
857 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
858 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
859 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
860 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
861 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
862 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
863 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
864 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
865 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
866 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
867 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
868 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
869 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
872 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
874 // User and Template Images
875 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
876 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
877 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
879 // Defines Arrays to save User and Templates
880 $tpls = array();
881 $users= array();
883 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
884 * Read Sip Table for specified account (for each user with phoneAccount).
885 * Check the attributes ip port and regseconds.
886 * If regseconds is set and >0 , the phone is logged in.
887 * Else the phone is currently not logged.
888 * If we can't read any Data from the DB or there is no goFon DB specified
889 * show old style without status icons.
890 */
891 $r_db =false;
892 $r_con =false;
893 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
894 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
895 // Connect to DB server
897 /*
898 If you want to disable the status pictures, just comment out the next line
899 */
900 $r_con = false;
901 $r_db = false;
902 if(is_callable("mysql_pconnect")){
903 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
904 // Check if we are connected correctly
905 if($r_con){
906 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
907 }
908 }
909 }
911 // Test Every Entry and generate divlist Array
912 foreach($this->list as $key => $val){
913 $connected = ""; // This string represents timestamp or offline status
914 $ip_port = ""; // String that will represent ip : port of the connected phone
915 if((in_array("goFonAccount" ,$val['objectClass']))){
917 /* Set defaults */
918 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
919 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
920 $fonac = preg_replace("/%title%/", "", $fonac);
922 /* Database connection is ok ?*/
923 if(($r_db)&&(is_callable("mysql_query"))){
924 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
925 $mysql_entry = @mysql_fetch_row($res);
926 if(is_array($mysql_entry)){
927 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
928 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
929 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
930 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
931 $fonac = preg_replace("/%title%/", $connected, $fonac);
932 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
933 }
934 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
935 $connected = " | "._("Offline");
936 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
937 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
938 $fonac = preg_replace("/%title%/", $connected, $fonac);
939 }
940 }
941 }
942 }else{
943 $fonac=$empty;
944 }
948 // Specify Pics for Extensions
949 if(in_array("posixAccount" ,$val['objectClass'])){
950 $posix = preg_replace("/%KEY%/", "$key", $posiximg);
951 }else{
952 $posix=$empty;
953 }
955 if(in_array("gotoEnvironment" ,$val['objectClass'])){
956 $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
957 }else{
958 $enviro =$empty;
959 }
961 if(in_array("gosaMailAccount" ,$val['objectClass'])){
962 $maila = preg_replace("/%KEY%/", "$key", $mailimg);
963 }else{
964 $maila=$empty;
965 }
967 if(in_array("goFaxAccount" ,$val['objectClass'])){
968 $faxac = preg_replace("/%KEY%/", "$key", $faximg);
969 }else{
970 $faxac=$empty;
971 }
973 if(in_array("sambaSamAccount" ,$val['objectClass'])){
974 $samba = preg_replace("/%KEY%/", "$key", $sambaimg);
975 }else{
976 $samba=$empty;
977 }
979 if(in_array("gosaUserTemplate",$val['objectClass'])){
980 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
981 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
982 }else{
983 $s_img_create_from_template = "";
984 $tpl=$userimg;
985 }
987 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
989 // Generate caption for rows
990 if (isset($val["sn"]) && isset($val["givenName"])){
991 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
992 } else {
993 $display= "[".$val["uid"][0]."]";
994 }
996 /* Create each field */
997 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
998 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".$val['dn']."'");
999 $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$s_img_create_from_template, "attach" => "style='width:152px;'");
1000 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='width:90px;border-right:0px;text-align:right;'");
1002 $add = array($field1,$field2,$field3,$field4);
1004 // Template or User
1005 if(in_array("gosaUserTemplate",$val['objectClass'])){
1006 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
1007 }else{
1008 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
1009 }
1010 }
1012 // Sort Entries
1013 ksort($users);
1014 ksort($tpls);
1016 // Append Templates
1017 foreach($tpls as $key => $val){
1018 $divlist->AddEntry( $val, array(""));
1019 }
1020 // Append Users
1021 foreach($users as $key => $val){
1022 $divlist->AddEntry( $val, array(""));
1023 }
1024 /* Show main page */
1025 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
1026 $smarty->assign("userlist", $divlist->DrawList());
1027 $smarty->assign("userlisthead", $listhead);
1029 /* END NEW LIST MANAGMENT
1030 */
1031 $smarty->assign("search_image", get_template_path('images/search.png'));
1032 $smarty->assign("tree_image", get_template_path('images/tree.png'));
1033 $smarty->assign("infoimage", get_template_path('images/info.png'));
1034 $smarty->assign("launchimage", get_template_path('images/launch.png'));
1035 $smarty->assign("deplist", $this->config->idepartments);
1036 foreach( array("depselect", "functionalusers", "unixusers",
1037 "mailusers", "sambausers", "proxyusers",
1038 "faxusers", "templates", "subsearch") as $type){
1040 $smarty->assign("$type", $userfilter[$type]);
1041 }
1043 $smarty->assign("regex", $userfilter["regex"]);
1044 /* Extend if we are not using javascript */
1045 $smarty->assign("apply", apply_filter());
1046 $smarty->assign("alphabet", generate_alphabet());
1047 $smarty->assign("hint", print_sizelimit_warning());
1049 if((is_callable("mysql_close"))&&($r_con)){
1050 @mysql_close($r_con);
1051 }
1052 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
1053 }
1056 function reload()
1057 {
1058 /* Get config */
1059 $userfilter= get_global('userfilter');
1061 /* Set base for all searches */
1062 $base= $userfilter['depselect'];
1064 /* Regex filter? */
1065 if ($userfilter['regex'] != ""){
1066 $regex= $userfilter['regex'];
1067 } else {
1068 $regex= "*";
1069 }
1071 /* Set filter depending on selection */
1072 if ($this->config->current['SAMBAVERSION'] == 3){
1073 $samba= "sambaSamAccount";
1074 } else {
1075 $samba= "sambaAccount";
1076 }
1079 /* Sometimes not all users were displayed in the users list.
1080 The problem was, that we search for an objectClass
1081 which isn't used in every ldap-schema configuration.
1082 Here we remove this class, if there is no result returned from
1083 our test search.
1084 */
1085 $ldap = $this->config->get_ldap_link();
1086 $ldap->cd($this->config->current['BASE']);
1088 $ldap->search("(objectClass=goFaxAccount)",array("cn","uid"));
1089 if($ldap->fetch()){
1090 $useFaxInFilter = true;
1091 $FaxFilter = "(objectClass=goFaxAccount)";
1092 } else {
1093 $useFaxInFilter = false;
1094 $FaxFilter = "";
1095 }
1098 $filter="";
1099 if ($userfilter['functionalusers'] == "checked"){
1100 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)".$FaxFilter."(objectClass=gosaProxyAccount))))";
1101 }
1102 if ($userfilter['unixusers'] == "checked"){
1103 $filter.= "(objectClass=posixAccount)";
1104 }
1105 if ($userfilter['mailusers'] == "checked"){
1106 $filter.= "(objectClass=gosaMailAccount)";
1107 }
1108 if ($userfilter['sambausers'] == "checked"){
1109 $filter.= "(objectClass=$samba)";
1110 }
1111 if ($userfilter['proxyusers'] == "checked"){
1112 $filter.= "(objectClass=gosaProxyAccount)";
1113 }
1114 if (($userfilter['faxusers'] == "checked") && ($useFaxInFilter)){
1115 $filter.= "(objectClass=goFaxAccount)";
1116 }
1117 if ($userfilter['templates'] == "checked"){
1118 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
1119 } else {
1120 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
1121 }
1122 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
1124 /* Generate userlist */
1125 $ldap= $this->config->get_ldap_link(TRUE);
1126 if ($userfilter['subsearch'] == "checked"){
1127 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
1128 } else {
1129 $base= get_people_ou().$base;
1130 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
1131 }
1134 /* NEW LIST MANAGMENT
1135 * We also need to search for the departments
1136 * So we are able to navigate like in konquerer
1137 */
1139 /* Create base to search in */
1141 $peopleOU = get_people_ou();
1142 if(empty($peopleOU)) {
1143 $base2 = $base;
1144 }else{
1145 $base2 = preg_replace("/".$peopleOU."/i","",$base);
1146 }
1148 /* Get all departments within this subtree */
1149 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1150 TRUE, $base2, array("ou", "description"), TRUE);
1152 $this->departments= array();
1154 /* Create array with results */
1155 $tmp = array();
1156 foreach ($res3 as $value){
1157 $tmp[strtolower($value['dn']).$value['dn']]=$value;
1158 }
1160 /* Sort array */
1161 ksort($tmp);
1163 /* Create result array */
1164 foreach($tmp as $value){
1165 if(isset($value['description'][0])){
1166 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1167 }else{
1168 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);
1169 }
1170 }
1171 /* END NEW LIST MANAGMENT
1172 */
1175 $this->userlist= array();
1177 foreach ($this->list as $value){
1178 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1179 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1180 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1181 continue;
1182 }
1183 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1184 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1185 $value["givenName"][0].
1186 " [".$value["uid"][0]."]";
1187 } else {
1188 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1189 }
1190 }
1191 }
1193 natcasesort ($this->userlist);
1194 reset ($this->userlist);
1195 }
1197 function remove_from_parent()
1198 {
1199 }
1202 /* Check values */
1203 function check()
1204 {
1205 }
1208 /* Save to LDAP */
1209 function save()
1210 {
1211 }
1213 function adapt_from_template($dn)
1214 {
1215 }
1217 function password_change_needed()
1218 {
1219 }
1221 function show_header($button_text, $text, $disabled= FALSE)
1222 {
1223 }
1225 function remove_lock()
1226 {
1227 if (isset($this->usertab->dn)){
1228 del_lock ($this->usertab->dn);
1229 }
1230 }
1232 }
1234 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1235 ?>