commit | author | age
|
48e9c1
|
1 |
<?php |
T |
2 |
/** |
|
3 |
* New user identity |
|
4 |
* |
|
5 |
* Populates a new user's default identity from LDAP on their first visit. |
|
6 |
* |
|
7 |
* This plugin requires that a working public_ldap directory be configured. |
|
8 |
* |
|
9 |
* @version @package_version@ |
|
10 |
* @author Kris Steinhoff |
|
11 |
* |
|
12 |
* Example configuration: |
|
13 |
* |
|
14 |
* // The id of the address book to use to automatically set a new |
|
15 |
* // user's full name in their new identity. (This should be an |
|
16 |
* // string, which refers to the $rcmail_config['ldap_public'] array.) |
|
17 |
* $rcmail_config['new_user_identity_addressbook'] = 'People'; |
|
18 |
* |
|
19 |
* // When automatically setting a new users's full name in their |
|
20 |
* // new identity, match the user's login name against this field. |
|
21 |
* $rcmail_config['new_user_identity_match'] = 'uid'; |
|
22 |
* |
|
23 |
* // Use this field (from fieldmap configuration) to fill alias col of |
|
24 |
* // the new user record. |
|
25 |
* $rcmail_config['new_user_identity_alias'] = 'alias'; |
|
26 |
*/ |
|
27 |
class new_user_identity extends rcube_plugin |
|
28 |
{ |
|
29 |
public $task = 'login'; |
|
30 |
|
|
31 |
private $ldap; |
|
32 |
|
|
33 |
function init() |
|
34 |
{ |
|
35 |
$this->add_hook('user_create', array($this, 'lookup_user_name')); |
|
36 |
} |
|
37 |
|
|
38 |
function lookup_user_name($args) |
|
39 |
{ |
|
40 |
$rcmail = rcmail::get_instance(); |
|
41 |
|
|
42 |
if ($this->init_ldap($args['host'])) { |
|
43 |
$results = $this->ldap->search('*', $args['user'], TRUE); |
|
44 |
if (count($results->records) == 1) { |
|
45 |
$args['user_name'] = $results->records[0]['name']; |
|
46 |
if (!$args['user_email'] && strpos($results->records[0]['email'], '@')) { |
|
47 |
$args['user_email'] = rcube_idn_to_ascii($results->records[0]['email']); |
|
48 |
} |
|
49 |
if (($alias_col = $rcmail->config->get('new_user_identity_alias')) && $results->records[0][$alias_col]) { |
|
50 |
$args['alias'] = $results->records[0][$alias_col]; |
|
51 |
} |
|
52 |
} |
|
53 |
} |
|
54 |
return $args; |
|
55 |
} |
|
56 |
|
|
57 |
private function init_ldap($host) |
|
58 |
{ |
|
59 |
if ($this->ldap) |
|
60 |
return $this->ldap->ready; |
|
61 |
|
|
62 |
$rcmail = rcmail::get_instance(); |
|
63 |
|
|
64 |
$addressbook = $rcmail->config->get('new_user_identity_addressbook'); |
|
65 |
$ldap_config = (array)$rcmail->config->get('ldap_public'); |
|
66 |
$match = $rcmail->config->get('new_user_identity_match'); |
|
67 |
|
|
68 |
if (empty($addressbook) || empty($match) || empty($ldap_config[$addressbook])) { |
|
69 |
return false; |
|
70 |
} |
|
71 |
|
|
72 |
$this->ldap = new new_user_identity_ldap_backend( |
|
73 |
$ldap_config[$addressbook], |
|
74 |
$rcmail->config->get('ldap_debug'), |
|
75 |
$rcmail->config->mail_domain($host), |
|
76 |
$match); |
|
77 |
|
|
78 |
return $this->ldap->ready; |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
class new_user_identity_ldap_backend extends rcube_ldap |
|
83 |
{ |
|
84 |
function __construct($p, $debug, $mail_domain, $search) |
|
85 |
{ |
|
86 |
parent::__construct($p, $debug, $mail_domain); |
|
87 |
$this->prop['search_fields'] = (array)$search; |
|
88 |
} |
|
89 |
} |