Rename plugin as it does not depend on virtuser_query and update config strings
This commit is contained in:
parent
23fcd9cb96
commit
53b951a3b6
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "arisuongaku/virtuser_identity_autoupdate",
|
"name": "arisuongaku/identity_db",
|
||||||
"type": "roundcube-plugin",
|
"type": "roundcube-plugin",
|
||||||
"description": "Updates user's identities on login based on aliases from virtuser_query. Update rules are configurable.",
|
"description": "Updates user's identities on login based on a database query. Some update rules are configurable.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
$conf = $config['virtuser_identity_autoupdate'] = array();
|
$conf = array();
|
||||||
|
|
||||||
// Enables (true) or disables (false) the plugin
|
// Enables (true) or disables (false) the plugin
|
||||||
$conf['update_on_login'] = true;
|
$conf['update_on_login'] = true;
|
||||||
|
|
||||||
// Remove identities for which the email address is unknown for this user
|
// Remove identities for which the email address is unknown for this user
|
||||||
$conf['remove_unknown_alias_identities'] = true;
|
$conf['remove_unknown_identities'] = true;
|
||||||
|
|
||||||
// Connection to the database which holds user aliases information
|
// Connection to the database which holds user aliases information
|
||||||
$conf['dsn'] = '';
|
$conf['dsn'] = '';
|
||||||
|
|
||||||
// Query all aliases for a given user. '%u' will be replaced with the username.
|
// Query all aliases for a given user. '%u' will be replaced with the username.
|
||||||
// Example : SELECT aliases.email FROM aliases LEFT JOIN users ON aliases.user_id=users.id WHERE users.name="%u"
|
// Example : SELECT aliases.email FROM aliases LEFT JOIN users ON aliases.user_id=users.id WHERE users.name="%u"
|
||||||
$conf['user_aliases_query'] = '';
|
$conf['identities_query'] = '';
|
||||||
|
|
||||||
|
// Finally register to the global config
|
||||||
|
$config['identity_db'] = $conf;
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Virtuser Identity Auto Update
|
* Identity DB
|
||||||
*
|
*
|
||||||
* Updates user's identities on each login
|
* Updates user's identities on each login from a database request
|
||||||
*
|
*
|
||||||
* This plugin requires virtuser_query to work.
|
|
||||||
*
|
|
||||||
* @author Alice Gaudon
|
* @author Alice Gaudon
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
class virtuser_identities_autoupdate extends rcube_plugin
|
class identity_db extends rcube_plugin
|
||||||
{
|
{
|
||||||
private $rc;
|
private $rc;
|
||||||
private $config;
|
private $config;
|
||||||
@ -19,7 +17,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
|
|||||||
{
|
{
|
||||||
$this->rc = rcmail::get_instance();
|
$this->rc = rcmail::get_instance();
|
||||||
$this->load_config();
|
$this->load_config();
|
||||||
$this->config = $this->rc->config->get('virtuser_identity_autoupdate');
|
$this->config = $this->rc->config->get('identity_db');
|
||||||
|
|
||||||
$this->add_hook('login_after', array($this, 'login_after'));
|
$this->add_hook('login_after', array($this, 'login_after'));
|
||||||
}
|
}
|
||||||
@ -36,7 +34,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
|
|||||||
$target_identities = $this->fetch_aliases($user->data['username']);
|
$target_identities = $this->fetch_aliases($user->data['username']);
|
||||||
|
|
||||||
// If enabled, remove unknown identities
|
// If enabled, remove unknown identities
|
||||||
if ($this->config['remove_unknown_alias_identities']) {
|
if ($this->config['remove_unknown_identities']) {
|
||||||
foreach ($current_identities as $existing_identity) {
|
foreach ($current_identities as $existing_identity) {
|
||||||
if (!in_array($existing_identity['email'], $target_identities)) {
|
if (!in_array($existing_identity['email'], $target_identities)) {
|
||||||
// Remove
|
// Remove
|
||||||
@ -76,7 +74,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (!$hook_result['abort'] && $hook_result['record']['email']) {
|
if (!$hook_result['abort'] && $hook_result['record']['email']) {
|
||||||
$insert_result = $user->insert_identity($hook_result['record']);
|
$user->insert_identity($hook_result['record']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +86,7 @@ class virtuser_identities_autoupdate extends rcube_plugin
|
|||||||
|
|
||||||
$dbh = $this->get_dbh();
|
$dbh = $this->get_dbh();
|
||||||
|
|
||||||
$result = $dbh->query(preg_replace('/%u/', $dbh->escape($username), $this->config['user_aliases_query']));
|
$result = $dbh->query(preg_replace('/%u/', $dbh->escape($username), $this->config['identities_query']));
|
||||||
|
|
||||||
while ($row = $dbh->fetch_array($result)) {
|
while ($row = $dbh->fetch_array($result)) {
|
||||||
array_push($aliases, $row[0]);
|
array_push($aliases, $row[0]);
|
Loading…
Reference in New Issue
Block a user