3035d85141db10113f731c651b45193f8c1ec457
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 function userManagement ($config, $ui)
38 {
39 /* Save configuration for internal use */
40 $this->config= $config;
41 $this->ui= $ui;
43 /* Get global filter config */
44 if (!isset($_SESSION["userfilter"])){
45 $base= get_base_from_people($ui->dn);
46 $userfilter= array( "mailusers" => "checked",
47 "unixusers" => "checked",
48 "templates" => "",
49 "subsearch" => "",
50 "proxyusers" => "checked",
51 "sambausers" => "checked",
52 "faxusers" => "checked",
53 "functionalusers" => "checked",
54 "depselect" => $base,
55 "regex" => "*");
56 $_SESSION["userfilter"] = $userfilter;
57 }
58 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 $smarty = get_smarty(); // Smarty instance
66 $userfilter = get_global("userfilter"); // contains Filter Settings
67 $s_action = ""; // Contains the action to proceed
68 $s_entry = ""; // The value for s_action
69 $base_back = ""; // The Link for Backbutton
71 /* Start for New List Managment */
72 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
73 $s_action="open";
74 $s_entry = base64_decode($_GET['dep_id']);
75 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
76 }
78 /* Test Posts */
79 foreach($_POST as $key => $val){
80 // Post for delete
81 if(preg_match("/user_del.*/",$key)){
82 $s_action = "del";
83 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
84 // Post for edit
85 }elseif(preg_match("/user_edit_.*/",$key)){
86 $s_action="edit";
87 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
88 // Post for new
89 }elseif(preg_match("/dep_back.*/i",$key)){
90 $s_action="back";
91 }elseif(preg_match("/user_new.*/",$key)){
92 $s_action="new";
93 }elseif(preg_match("/dep_home.*/i",$key)){
94 $s_action="home";
95 }elseif(preg_match("/user_tplnew.*/i",$key)){
96 $s_action="new_tpl";
97 }elseif(preg_match("/user_chgpw.*/i",$key)){
98 $s_action="change_pw";
99 $s_entry = preg_replace("/user_chgpw_/i","",$key);
100 }elseif(preg_match("/dep_root.*/i",$key)){
101 $s_action="root";
102 }elseif(preg_match("/userfrom_tpl.*/i",$key)){
103 $s_action="create_user_from_tpl";
104 $s_entry = preg_replace("/userfrom_tpl_/i","",$key);
105 }
106 }
108 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
109 $s_action = "edit";
110 $s_entry = $_GET['id'];
111 }
113 $s_entry = preg_replace("/_.$/","",$s_entry);
115 if(preg_match("/.*-.*/",$s_entry)){
116 $s_tab = preg_replace("/^.*-/i","",$s_entry);
117 $s_entry = preg_replace("/-.*$/i","",$s_entry);
118 }else{
119 $s_tab = "user";
120 };
122 /* Department changed? */
123 if(isset($_POST['depselect']) && $_POST['depselect']){
124 $userfilter['depselect']= $_POST['depselect'];
125 }
127 /* Homebutton is posted */
128 if($s_action=="home"){
129 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
130 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
131 }
133 if($s_action=="root"){
134 $userfilter['depselect']=($this->config->current['BASE']);
135 }
138 /* If Backbutton is Posted */
139 if($s_action=="back"){
140 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
141 $base_back = convert_department_dn($base_back);
143 if(isset($this->config->departments[trim($base_back)])){
144 $userfilter['depselect']= $this->config->departments[trim($base_back)];
145 }else{
146 $userfilter['depselect']= $this->config->departments["/"];
147 }
148 }
150 /* End for new List Managment */
152 /* Save filter data if we are in the headpage */
153 if (!isset($this->usertab)){
154 if (isset($_POST['regexit'])){
155 $userfilter["regex"]= $_POST['regexit'];
156 }
157 }
158 if(isset($_POST['regexit'])){
159 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
160 if (isset($_POST[$type])) {
161 $userfilter[$type]= "checked";
162 } else {
163 $userfilter[$type]= "";
164 }
165 }
166 }
167 if (isset($_GET['search'])){
168 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
169 if ($s == "**"){
170 $s= "*";
171 }
172 $userfilter['regex']= $s;
173 }
174 register_global("userfilter", $userfilter);
177 /* React on user interaction here */
178 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
180 /* User wants to edit data? */
181 if ($s_action=="edit"){
183 /* Get 'dn' from posted 'uid', must be unique */
185 $this->dn= $this->list[trim($s_entry)]['dn'];
187 /* Check locking, save current plugin in 'back_plugin', so
188 the dialog knows where to return. */
189 if (($user= get_lock($this->dn)) != ""){
190 return(gen_locked_message ($user, $this->dn));
191 }
193 /* Lock the current entry, so everyone will get the
194 above dialog */
195 add_lock ($this->dn, $this->ui->dn);
197 /* Set up the users ACL's for this 'dn' */
198 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
200 /* Register usertab to trigger edit dialog */
201 $this->usertab= new usertabs($this->config,
202 $this->config->data['TABS']['USERTABS'], $this->dn);
203 // $_POST[$s_tab]=$s_tab;
205 // This would be better
206 $this->usertab->current = $s_tab;
207 $this->usertab->set_acl($acl);
209 $_SESSION['objectinfo']= $this->dn;
210 }
211 }
213 /* Reset requested? */
214 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
215 if (isset($this->usertab)){
216 del_lock ($this->usertab->dn);
217 unset ($this->usertab);
218 }
219 $this->usertab= NULL;
220 $this->lognames= array();;
221 $this->sn= "";
222 $this->givenName= "";
223 $this->uid= "";
224 unset ($_SESSION['objectinfo']);
225 }
227 /* Password change requested */
228 if ($s_action=="change_pw"){
230 /* Get 'dn' from posted 'uid' */
231 $this->dn= $this->list[trim($s_entry)]['dn'];
233 /* Load permissions for selected 'dn' and check if
234 we're allowed to remove this 'dn' */
235 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
236 $acl= get_module_permission($acl, "user", $this->dn);
237 if (chkacl($acl, "password") == ""){
239 /* User is allowed to change passwords, save 'dn' and 'acl' for next
240 dialog. */
241 $this->acl= $acl;
242 $_SESSION['objectinfo']= $this->dn;
243 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
245 } else {
246 /* User is not allowed. Show message and cancel. */
247 print_red (_("You are not allowed to set this users password!"));
248 }
249 }
251 /* Perform password change */
252 if (isset($_POST['password_finish'])){
254 /* For security reasons, check if user is allowed to set password again */
255 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
257 /* Check input and feed errors into 'message' */
258 $message= array();
260 /* Sanity checks... */
261 if ($_POST['new_password'] != $_POST['repeated_password']){
263 /* Matching passwords in new and repeated? */
264 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
265 } else {
267 /* Empty password is not permitted by default. */
268 if ($_POST['new_password'] == ""){
269 $message[]= _("The password you've entered as 'New password' is empty.");
270 }
271 }
273 /* Errors, or change password? */
274 if (count($message) != 0){
276 /* Show error message and continue editing */
277 show_errors ($message);
278 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
279 }
281 $config= $this->config;
282 $ldap_ui= $this->config->get_ldap_link();
283 if(isset($this->usertab->dn)){
284 $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
285 }else{
286 $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
287 }
288 if((is_array($user))&&(isset($user['uid']))){
289 $username= $user['uid'][0];
290 }
292 /* Set password, perform required steps */
293 if ($this->usertab){
294 if ($this->usertab->password_change_needed()){
295 $obj= $this->usertab->by_object['user'];
296 change_password ($this->usertab->dn, $_POST['new_password'],
297 0, $obj->pw_storage);
298 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
299 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
300 }
302 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
303 unset($this->usertab);
304 $this->usertab= NULL;
305 }
306 } else {
307 change_password ($this->dn, $_POST['new_password']);
308 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
309 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
310 }
312 gosa_log ("Password for '".$this->dn."' has been changed");
313 }
314 } else {
316 /* Missing permissions, show message */
317 print_red (_("You are not allowed to set this users password!"));
318 }
320 /* Clean session, delete lock */
321 del_lock ($this->dn);
322 $this->reload();
323 unset ($this->usertab);
324 $this->usertab= NULL;
325 $this->lognames= array();;
326 $this->sn= "";
327 $this->givenName= "";
328 $this->uid= "";
329 unset ($_SESSION['objectinfo']);
330 }
333 /* Remove user was requested */
334 if ($s_action=="del"){
336 /* Get 'dn' from posted 'uid' */
337 $this->dn= $this->list[trim($s_entry)]['dn'];
339 /* Load permissions for selected 'dn' and check if
340 we're allowed to remove this 'dn' */
341 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
342 $this->acl= get_module_permission($acl, "user", $this->dn);
343 if (chkacl($this->acl, "delete") == ""){
345 /* Check locking, save current plugin in 'back_plugin', so
346 the dialog knows where to return. */
347 if (($user= get_lock($this->dn)) != ""){
348 return(gen_locked_message ($user, $this->dn));
349 }
351 /* Lock the current entry, so nobody will edit it during deletion */
352 add_lock ($this->dn, $this->ui->dn);
353 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
354 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
355 } else {
357 /* Obviously the user isn't allowed to delete. Show message and
358 clean session. */
359 print_red (_("You are not allowed to delete this user!"));
360 }
361 }
365 /* Confirmation for deletion has been passed. User should be deleted. */
366 if (isset($_POST['delete_user_confirm'])){
368 /* Some nice guy may send this as POST, so we've to check
369 for the permissions again. */
370 if (chkacl($this->acl, "delete") == ""){
372 /* Delete request is permitted, perform LDAP action */
373 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
374 $this->dn);
375 $this->usertab->set_acl(array($this->acl));
376 $this->usertab->delete ();
377 gosa_log ("User object '".$this->dn."' has been removed");
378 unset ($this->usertab);
379 $this->usertab= NULL;
381 /* User list has changed, reload it. */
382 $this->reload ();
383 } else {
385 /* Normally this shouldn't be reached, send some extra
386 logs to notify the administrator */
387 print_red (_("You are not allowed to delete this user!"));
389 if(isset($this->ui->uid)){
390 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
391 }
392 }
394 /* Remove lock file after successfull deletion */
395 del_lock ($this->dn);
396 }
399 /* Delete user canceled? */
400 if (isset($_POST['delete_cancel'])){
401 del_lock ($this->dn);
402 }
405 /* Finish user edit is triggered by the tabulator dialog, so
406 the user wants to save edited data. Check and save at this
407 point. */
408 if (isset($_POST['edit_finish'])){
410 /* Check tabs, will feed message array */
411 $this->usertab->last= $this->usertab->current;
412 $this->usertab->save_object();
413 $message= $this->usertab->check();
415 /* Save, or display error message? */
416 if (count($message) == 0){
418 /* No errors. Go ahead and prepare to ask for a password
419 in case we're creating a new user. 'dn' will be 'new'
420 in this case. It is set to the correct value later. */
421 if ($this->dn == "new"){
422 $set_pass= 1;
423 } else {
424 $set_pass= 0;
425 }
427 /* Save user data to ldap */
428 if($this->usertab->save() == 1){
429 gosa_log ("User object '".$this->dn."' saving failed.");
430 return;
431 }
432 gosa_log ("User object '".$this->dn."' has been saved");
434 /* User has been saved successfully, remove lock from
435 LDAP. */
436 if ($this->dn != "new"){
437 del_lock ($this->dn);
438 }
440 /* In case of new users, ask for a password */
441 if (($set_pass || $this->usertab->password_change_needed()) &&
442 !$this->is_template){
444 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
445 }
447 /* There's no page reload so we have to read new users at
448 this point. */
449 $this->reload ();
450 unset ($this->usertab);
451 $this->usertab= NULL;
452 unset ($_SESSION['objectinfo']);
454 } else {
455 /* Ok. There seem to be errors regarding to the tab data,
456 show message and continue as usual. */
457 show_errors($message);
458 }
459 }
461 /* Generate template list */
462 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
464 $this->templates= array();
466 $ldap= $this->config->get_ldap_link();
468 /* Create list of tempaltes */
469 foreach ($this->config->departments as $key => $value){
471 /* Get acls from different ou's */
472 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
473 $acl= get_module_permission($acl, "user", get_people_ou().$value);
475 /* If creation of a new user is allowed, append this template */
476 if (chkacl($acl, "create") == ""){
478 /* Search all templates from the current dn */
479 $ldap->cd (get_people_ou().$value);
480 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
482 /* Append */
483 if ($ldap->count() != 0){
484 while ($attrs= $ldap->fetch()){
485 $this->templates[$ldap->getDN()]=
486 $attrs['uid'][0]." - $key";
487 }
488 $this->templates['none']= _("none");
489 }
490 }
491 }
493 /* Sort templates */
494 natcasesort ($this->templates);
495 reset ($this->templates);
496 }
498 /* New user/template request */
499 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
500 /* By default we set 'dn' to 'new', all relevant plugins will
501 react on this. */
502 $this->dn= "new";
503 if (isset($this->config->current['IDGEN'])){
504 $this->got_uid= false;
505 } else {
506 $this->got_uid= true;
507 }
509 /* Create new usertab object */
510 $this->usertab= new usertabs($this->config,
511 $this->config->data['TABS']['USERTABS'], $this->dn);
512 $this->usertab->set_acl(array(':all'));
513 $this->usertab->by_object['user']->base= $userfilter['depselect'];
515 /* Take care about templates */
516 if ($s_action=="new_tpl"){
517 $this->is_template= TRUE;
518 $this->usertab->set_template_mode ();
519 } else {
520 $this->is_template= FALSE;
521 }
523 /* Use template if there are any of them */
524 if ((count($this->templates) && !isset($_POST['new_template']))||($s_action=="create_user_from_tpl")){
525 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
526 $smarty->assign("$attr", $this->$attr);
527 }
528 if ($s_action=="create_user_from_tpl"){
529 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
530 } else {
531 $smarty->assign("template", "none");
532 }
533 $smarty->assign("edit_uid", "");
534 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
535 }
536 }
538 /* Continue template editing */
539 if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
540 $this->sn= $_POST['sn'];
541 $this->givenName= $_POST['givenName'];
543 /* Check for requred values */
544 $message= array();
545 if ($this->sn == "") {
546 $message[]= _("The required field 'Name' is not set.");
547 }
548 if ($this->givenName == "") {
549 $message[]= _("The required field 'Given name' is not set.");
550 }
552 /* Check if dn is used */
553 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
554 $ldap= $this->config->get_ldap_link();
555 $ldap->cd ($dn);
556 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
557 if ($ldap->count () != 0){
558 $message[]= _("A person with the choosen name is already used in this tree.");
559 }
561 /* Show error message / continue editing */
562 if (count($message) > 0){
563 show_errors ($message);
564 } else {
565 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
566 if (isset($this->config->current['IDGEN']) &&
567 $this->config->current['IDGEN'] != ""){
568 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
569 if (count($uids)){
570 $smarty->assign("edit_uid", "false");
571 $smarty->assign("uids", $uids);
572 $this->uid= current($uids);
573 }
574 } else {
575 $smarty->assign("edit_uid", "");
576 $this->uid= "";
577 }
578 $this->got_uid= true;
579 }
581 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
582 $smarty->assign("$attr", $this->$attr);
583 }
584 if (isset($_POST['template'])){
585 $smarty->assign("template", $_POST['template']);
586 }
587 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
588 }
590 /* No template. Ok. Lets fill data into the normal user dialog */
591 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
592 foreach(array("sn", "givenName", "uid") as $attr){
593 if (isset($_POST[$attr])){
594 $this->usertab->by_object['user']->$attr= $_POST[$attr];
595 }
596 }
597 }
599 /* Finish template preamble */
600 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
602 /* Might not be filled if IDGEN is unset */
603 $this->sn = $_POST['sn'];
604 $this->givenName = $_POST['givenName'];
606 /* Move user supplied data to sub plugins */
607 $this->uid = $_POST['uid'];
608 $this->usertab->uid = $this->uid;
609 $this->usertab->sn = $this->sn;
610 $this->usertab->givenName = $this->givenName;
611 $template_dn = $_POST['template'];
612 $this->usertab->adapt_from_template($template_dn);
613 $template_base = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
614 $this->usertab->by_object['user']->base= $template_base;
616 /* Set up the users ACL's for this 'dn' */
617 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
618 $this->usertab->set_acl($acl);
619 }
621 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
622 $this->usertab->by_object['user']->base= $userfilter['depselect'];
623 }
625 /* Show tab dialog if object is present */
626 if ($this->usertab){
627 $display= $this->usertab->execute();
629 /* Don't show buttons if tab dialog requests this */
630 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
631 $display.= "<p style=\"text-align:right\">\n";
632 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
633 $display.= " \n";
634 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
635 $display.= "</p>";
636 }
637 return ($display);
638 }
640 $smarty= get_smarty();
642 /* Check sorting variable */
643 if (!isset($this->usertab) &&
644 !isset($_POST['new_user']) &&
645 !isset($_POST['new_template']) &&
646 !isset($_POST['delete_user']) &&
647 !isset($_POST['setpass_user']) &&
648 !isset($_POST['select_user'])){
649 $this->reload();
650 }
652 /* Check for exeeded sizelimit */
653 if (($message= check_sizelimit()) != ""){
654 return($message);
655 }
657 /* Prepare departments */
658 $options= "";
659 foreach ($this->config->idepartments as $key => $value){
660 if ($userfilter['depselect'] == $key){
661 $options.= "<option selected value='$key'>$value</option>";
662 } else {
663 $options.= "<option value='$key'>$value</option>";
664 }
665 }
667 /* NEW LIST MANAGMENT */
668 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
669 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
670 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
671 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
672 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
673 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
674 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
675 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
676 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
677 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
678 "</div>";
680 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
681 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
682 $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
686 $divlist = new divlist("userstab");
687 $divlist->SetHeader(array(
688 array("string" => " "),
689 array("string" => _("Username")." / "._("Department")),
690 array("string" => _("Properties")),
691 array("string" => _("Actions"), "attach" => "style='border:none'" )));
694 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
695 $divlist->SetEntriesPerPage(0);
697 // Defining Links
698 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
700 /* Insert departments in divlist*/
701 foreach($this->departments as $key=> $val){
703 if(!isset($this->config->departments[trim($key)])){
704 $this->config->departments[trim($key)]="";
705 }
707 $non_empty="";
708 $keys= str_replace("/","\/",$key);
709 foreach($this->config->departments as $keyd=>$vald ){
710 if(preg_match("/".$keys."\/.*/",$keyd)){
711 $non_empty="full";
712 }
713 }
715 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:20px;text-align:center;'");
716 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
717 $field3 = array("string" => " ");
718 $field4 = array("string" => " ", "attach" => "style='width:48px;border:none'");
721 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
722 }
724 /* Pictures for Extensions */
725 $usrimg ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'
726 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
727 $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'
728 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
729 $eviroimg = "<input type='image' src='images/smallenv.png' alt='"._("Environment")."'
730 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
731 $mailimg = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'
732 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
733 $fonimg = "<input type='image' src='images/%image%' alt='"._("Phone")."'
734 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
735 $faximg = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'
736 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
737 $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'
738 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
739 $tplcreateuserimg = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
740 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
743 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
745 // User and Template Images
746 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
747 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
748 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
750 // Defines Arrays to save User and Templates
751 $tpls = array();
752 $users= array();
754 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
755 * Read Sip Table for specified account (for each user with phoneAccount).
756 * Check the attributes ip port and regseconds.
757 * If regseconds is set and >0 , the phone is logged in.
758 * Else the phone is currently not logged.
759 * If we can't read any Data from the DB or there is no goFon DB specified
760 * show old style without status icons.
761 */
762 $r_db =false;
763 $r_con =false;
764 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
765 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
766 // Connect to DB server
768 /*
769 If you want to disable the status pictures, just comment out the next line
770 */
771 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
772 // Check if we are connected correctly
773 if($r_con){
774 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
775 }
776 }
778 // Test Every Entry and generate divlist Array
779 foreach($this->list as $key => $val){
780 $connected = ""; // This string represents timestamp or offline status
781 $ip_port = ""; // String that will represent ip : port of the connected phone
782 if((in_array("goFonAccount" ,$val['objectClass']))){
784 /* Set defaults */
785 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
786 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
787 $fonac = preg_replace("/%title%/", "", $fonac);
789 /* Database connection is ok ?*/
790 if($r_db){
791 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
792 $mysql_entry = @mysql_fetch_row($res);
793 if(is_array($mysql_entry)){
794 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
795 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
796 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
797 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
798 $fonac = preg_replace("/%title%/", $connected, $fonac);
799 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
800 }
801 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
802 $connected = " | "._("Offline");
803 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
804 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
805 $fonac = preg_replace("/%title%/", $connected, $fonac);
806 }
807 }
808 }
809 }else{
810 $fonac=$empty;
811 }
815 // Specify Pics for Extensions
816 if(in_array("posixAccount" ,$val['objectClass'])){
817 $posix = preg_replace("/%KEY%/", "$key", $posiximg);
818 }else{
819 $posix=$empty;
820 }
822 if(in_array("gotoEnvironment" ,$val['objectClass'])){
823 $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
824 }else{
825 $enviro =$empty;
826 }
828 if(in_array("gosaMailAccount" ,$val['objectClass'])){
829 $maila = preg_replace("/%KEY%/", "$key", $mailimg);
830 }else{
831 $maila=$empty;
832 }
834 if(in_array("goFaxAccount" ,$val['objectClass'])){
835 $faxac = preg_replace("/%KEY%/", "$key", $faximg);
836 }else{
837 $faxac=$empty;
838 }
840 if(in_array("sambaSamAccount" ,$val['objectClass'])){
841 $samba = preg_replace("/%KEY%/", "$key", $sambaimg);
842 }else{
843 $samba=$empty;
844 }
846 if(in_array("gosaUserTemplate",$val['objectClass'])){
847 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
848 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
849 }else{
850 $s_img_create_from_template = "";
851 $tpl=$userimg;
852 }
854 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
856 // Generate caption for rows
857 if (isset($val["sn"]) && isset($val["givenName"])){
858 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
859 } else {
860 $display= "[".$val["uid"][0]."]";
861 }
863 /* Create each field */
864 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;text-align:center;'");
865 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
866 $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$s_img_create_from_template, "attach" => "style='width:136px;'");
867 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none;text-align:right;width:48px'");
869 $add = array($field1,$field2,$field3,$field4);
871 // Template or User
872 if(in_array("gosaUserTemplate",$val['objectClass'])){
873 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
874 }else{
875 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
876 }
877 }
879 // Sort Entries
880 ksort($users);
881 ksort($tpls);
883 // Append Templates
884 foreach($tpls as $key => $val){
885 $divlist->AddEntry( $val, array(""));
886 }
887 // Append Users
888 foreach($users as $key => $val){
889 $divlist->AddEntry( $val, array(""));
890 }
891 /* Show main page */
892 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
893 $smarty->assign("userlist", $divlist->DrawList());
894 $smarty->assign("userlisthead", $listhead);
896 /* END NEW LIST MANAGMENT
897 */
898 $smarty->assign("search_image", get_template_path('images/search.png'));
899 $smarty->assign("tree_image", get_template_path('images/tree.png'));
900 $smarty->assign("infoimage", get_template_path('images/info.png'));
901 $smarty->assign("launchimage", get_template_path('images/launch.png'));
902 $smarty->assign("deplist", $this->config->idepartments);
903 foreach( array("depselect", "functionalusers", "unixusers",
904 "mailusers", "sambausers", "proxyusers",
905 "faxusers", "templates", "subsearch") as $type){
907 $smarty->assign("$type", $userfilter[$type]);
908 }
910 $smarty->assign("regex", $userfilter["regex"]);
911 /* Extend if we are not using javascript */
912 $smarty->assign("apply", apply_filter());
913 $smarty->assign("alphabet", generate_alphabet());
914 $smarty->assign("hint", print_sizelimit_warning());
916 @mysql_close($r_con);
917 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
918 }
921 function reload()
922 {
923 /* Get config */
924 $userfilter= get_global('userfilter');
926 /* Set base for all searches */
927 $base= $userfilter['depselect'];
929 /* Regex filter? */
930 if ($userfilter['regex'] != ""){
931 $regex= $userfilter['regex'];
932 } else {
933 $regex= "*";
934 }
936 /* Set filter depending on selection */
937 if ($this->config->current['SAMBAVERSION'] == 3){
938 $samba= "sambaSamAccount";
939 } else {
940 $samba= "sambaAccount";
941 }
943 $filter="";
944 if ($userfilter['functionalusers'] == "checked"){
945 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
946 }
947 if ($userfilter['unixusers'] == "checked"){
948 $filter.= "(objectClass=posixAccount)";
949 }
950 if ($userfilter['mailusers'] == "checked"){
951 $filter.= "(objectClass=gosaMailAccount)";
952 }
953 if ($userfilter['sambausers'] == "checked"){
954 $filter.= "(objectClass=$samba)";
955 }
956 if ($userfilter['proxyusers'] == "checked"){
957 $filter.= "(objectClass=gosaProxyAccount)";
958 }
959 if ($userfilter['faxusers'] == "checked"){
960 $filter.= "(objectClass=goFaxAccount)";
961 }
963 if ($userfilter['templates'] == "checked"){
964 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
965 } else {
966 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
967 }
968 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
970 /* Generate userlist */
971 $ldap= $this->config->get_ldap_link(TRUE);
972 if ($userfilter['subsearch'] == "checked"){
973 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
974 } else {
975 $base= get_people_ou().$base;
976 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
977 }
981 /* NEW LIST MANAGMENT
982 * We also need to search for the departments
983 * So we are able to navigate like in konquerer
984 */
985 $base2 = preg_replace("/ou=people,/i","",$base);
987 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
988 TRUE, $base2, array("ou", "description"), TRUE);
990 $this->departments= array();
992 $tmp = array();
993 foreach ($res3 as $value){
994 $tmp[strtolower($value['dn']).$value['dn']]=$value;
995 }
996 ksort($tmp);
997 foreach($tmp as $value){
998 if($value["description"][0]!=".."){
999 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1000 }else{
1001 $this->departments[$value['dn']]=$value["description"][0];
1002 }
1003 }
1004 /* END NEW LIST MANAGMENT
1005 */
1008 $this->userlist= array();
1010 foreach ($this->list as $value){
1011 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1012 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1013 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1014 continue;
1015 }
1016 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1017 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1018 $value["givenName"][0].
1019 " [".$value["uid"][0]."]";
1020 } else {
1021 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1022 }
1023 }
1024 }
1026 natcasesort ($this->userlist);
1027 reset ($this->userlist);
1028 }
1030 function remove_from_parent()
1031 {
1032 }
1035 /* Check values */
1036 function check()
1037 {
1038 }
1041 /* Save to LDAP */
1042 function save()
1043 {
1044 }
1046 function adapt_from_template($dn)
1047 {
1048 }
1050 function password_change_needed()
1051 {
1052 }
1054 function show_header($button_text, $text, $disabled= FALSE)
1055 {
1056 }
1058 function remove_lock()
1059 {
1060 if (isset($this->usertab->dn)){
1061 del_lock ($this->usertab->dn);
1062 }
1063 }
1065 }
1067 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1068 ?>