Hi *,
I am in the process of deploying Roundcube (0.9.5) and so far everything works fine, including the import of the addressbook of our legacy Squirremail webmailer and the initial creation of the user via the new_user_identity plugin using our LDAP server.
Now I only need a way to overwrite/set/force the identity of the user from the LDAP server on every login of a user.
identities_level is set to 4 (one read-only identity) and populated correctly on the first login, but users do things like marrying or moving to different departments which changes their name and/or mail-address.
This change needs to be reflected automatically inside roundcube without the need (or possibility) for the user to edit the identity himself.
In Squirrelmail I was able to hack the retrieveuserdata plugin, which is run on every login and overwrite the identity prefs with the current values for a user from LDAP.
For Roundcube I have looked at the provided plugin hooks, but I am currently a bit lost on how to proceed. The user_create hook is obviously only invoked on the first login, so cannot be used for later changes.
The user2mail hook looks promising but I was unable to find (and understand) an example on how to use it (I am a Perl guy, PHP is like a 4th language for me ;)).
Maybe I overlooked the obvious simple solution, please gently nudge me in the right direction.
Grüße, Sven.
Sven Hartge sven@svenhartge.de wrote:
I am in the process of deploying Roundcube (0.9.5) and so far everything works fine, including the import of the addressbook of our legacy Squirremail webmailer and the initial creation of the user via the new_user_identity plugin using our LDAP server.
Now I only need a way to overwrite/set/force the identity of the user from the LDAP server on every login of a user.
For Roundcube I have looked at the provided plugin hooks, but I am currently a bit lost on how to proceed. The user_create hook is obviously only invoked on the first login, so cannot be used for later changes.
The user2mail hook looks promising but I was unable to find (and understand) an example on how to use it (I am a Perl guy, PHP is like a 4th language for me ;)).
OK. After implementing a very simple test-plugin, which just hooks user2email and sets $args['email'] to a fixed value, I discoverd that user2email is only called during create() from rcube_user.php. Reading the changelog this was made during the outsourcing of the virtuser_* functions into their own separate plugins.
I have not found any other hook in 0.9.5 where I might overwrite the identity of already existing users.
Is this correct? What am I missing? Do I need to try the 1.0-git version? I'd like to avoid to deploy a devel-version to a production system.
Grüße, Sven.
Sven Hartge wrote:
Sven Hartge sven@svenhartge.de wrote:
I am in the process of deploying Roundcube (0.9.5) and so far everything works fine, including the import of the addressbook of our legacy Squirremail webmailer and the initial creation of the user via the new_user_identity plugin using our LDAP server.
Now I only need a way to overwrite/set/force the identity of the user from the LDAP server on every login of a user.
For Roundcube I have looked at the provided plugin hooks, but I am currently a bit lost on how to proceed. The user_create hook is obviously only invoked on the first login, so cannot be used for later changes.
The user2mail hook looks promising but I was unable to find (and understand) an example on how to use it (I am a Perl guy, PHP is like a 4th language for me ;)).
OK. After implementing a very simple test-plugin, which just hooks user2email and sets $args['email'] to a fixed value, I discoverd that user2email is only called during create() from rcube_user.php. Reading the changelog this was made during the outsourcing of the virtuser_* functions into their own separate plugins.
All the hooks you listed so far are only called once then the user logs in for the first time.
I have not found any other hook in 0.9.5 where I might overwrite the identity of already existing users.
I suggest to use the 'login_after' hook to verify/update a user's identities on login. That hook is also available in 0.9.5 so don't worry about that.
So in 'login_after' for example, you have access to the user object with its identities like this:
$user = rcmail::get_instance()->user; foreach ($user->list_identities() as $identity) { // check and update here }
~Thomas
Thomas Bruederli thomas@roundcube.net wrote:
Sven Hartge wrote:
Sven Hartge sven@svenhartge.de wrote:
Now I only need a way to overwrite/set/force the identity of the user from the LDAP server on every login of a user.
OK. After implementing a very simple test-plugin, which just hooks user2email and sets $args['email'] to a fixed value, I discoverd that user2email is only called during create() from rcube_user.php. Reading the changelog this was made during the outsourcing of the virtuser_* functions into their own separate plugins.
All the hooks you listed so far are only called once then the user logs in for the first time.
Well, they were the most obvious ones to me at the time I looked.
I suggest to use the 'login_after' hook to verify/update a user's identities on login. That hook is also available in 0.9.5 so don't worry about that.
So in 'login_after' for example, you have access to the user object with its identities like this:
$user = rcmail::get_instance()->user; foreach ($user->list_identities() as $identity) { // check and update here }
Aha! I did look at login_after, but just at the possible return values. I did not comprehend that I am able to access the user object and change it accordingly. (Which is purely my fault, it is clearly stated on the wiki page.)
Thanks Thomas, this helps me out a great deal. Back to the $editor!
BTW: What is the preferred method of writing some information into a log file to aid debugging? I guess it is as simple as write_log("log_name","log content").
Grüße, Sven.
Sven Hartge wrote:
BTW: What is the preferred method of writing some information into a log file to aid debugging? I guess it is as simple as write_log("log_name","log content").
The very simplest way is to use console($arg1, $arg, ...); which will dump all argument variables to <roundcube-dir>/logs/console. write_log() will of course also work but it only takes one string argument as content to log.
~Thomas
Thomas Bruederli thomas@roundcube.net wrote:
I suggest to use the 'login_after' hook to verify/update a user's identities on login. That hook is also available in 0.9.5 so don't worry about that.
So in 'login_after' for example, you have access to the user object with its identities like this:
$user = rcmail::get_instance()->user; foreach ($user->list_identities() as $identity) { // check and update here }
Thank you again. After gathering info on the available methods for the user object from rcube_user.php I was able to come up with the following solution:
function updateuser($args)
{
$rcmail = rcmail::get_instance();
$user = $rcmail->user;
$identity = $user->get_identity();
$username = $user->get_username();
if ($this->init_ldap()) {
$results = $this->ldap->search('*', $username, true);
if (count($results->records) == 1) {
$identity['name'] = is_array($results->records[0]['name']) ? $results->records[0]['name'][0] : $results->records[0]['name'];
$identity['email'] = is_array($results->records[0]['email']) ? $results->records[0]['email'][0] : $results->records[0]['email'];
}
}
$user->update_identity($identity['identity_id'],$identity);
}
The LDAP functions have been ripped from the new_user_identity plugin (thanks Kris Steinhoff) and are identical, I just changed the config-string to "update_user_addressbook" and "update_user_match".
Maybe this functionality can be incorporated into the new_user_identity plugin and make it configurable if the admin wants further automatic updates to the identity of a user after the initial creation.
Grüße, Sven.