summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/acl/acl.js20
-rw-r--r--plugins/acl/acl.php84
-rw-r--r--plugins/acl/config.inc.php.dist7
3 files changed, 108 insertions, 3 deletions
diff --git a/plugins/acl/acl.js b/plugins/acl/acl.js
index 300fd7220..1ad25576c 100644
--- a/plugins/acl/acl.js
+++ b/plugins/acl/acl.js
@@ -1,14 +1,30 @@
/**
* ACL plugin script
*
- * @version 0.3
+ * @version 0.4
* @author Aleksander Machniak <alec@alec.pl>
*/
if (window.rcmail) {
rcmail.addEventListener('init', function() {
- if (rcmail.gui_objects.acltable)
+ if (rcmail.gui_objects.acltable) {
rcmail.acl_list_init();
+ // enable autocomplete on user input
+ if (rcmail.env.acl_users_source) {
+ rcmail.init_address_input_events($('#acluser'), 'plugin.acl-autocomplete');
+ // fix inserted value
+ rcmail.addEventListener('autocomplete_insert', function(e) {
+ if (e.field.id != 'acluser')
+ return;
+
+ var value = e.insert;
+ // get UID from the entry value
+ if (value.match(/\s*\(([^)]+)\)[, ]*$/))
+ value = RegExp.$1;
+ e.field.value = value;
+ });
+ }
+ }
rcmail.enable_command('acl-create', 'acl-save', 'acl-cancel', 'acl-mode-switch', true);
rcmail.enable_command('acl-delete', 'acl-edit', false);
diff --git a/plugins/acl/acl.php b/plugins/acl/acl.php
index 552b5032b..24dcc95d4 100644
--- a/plugins/acl/acl.php
+++ b/plugins/acl/acl.php
@@ -3,7 +3,7 @@
/**
* Folders Access Control Lists Management (RFC4314, RFC2086)
*
- * @version 0.3
+ * @version 0.4
* @author Aleksander Machniak <alec@alec.pl>
*
*
@@ -30,6 +30,7 @@ class acl extends rcube_plugin
private $rc;
private $supported = null;
private $mbox;
+ private $ldap;
private $specials = array('anyone', 'anonymous');
/**
@@ -45,6 +46,7 @@ class acl extends rcube_plugin
$this->add_hook('addressbook_form', array($this, 'folder_form'));
// Plugin actions
$this->register_action('plugin.acl', array($this, 'acl_actions'));
+ $this->register_action('plugin.acl-autocomplete', array($this, 'acl_autocomplete'));
}
/**
@@ -77,6 +79,45 @@ class acl extends rcube_plugin
}
/**
+ * Handler for user login autocomplete request
+ */
+ function acl_autocomplete()
+ {
+ $this->load_config();
+
+ $search = get_input_value('_search', RCUBE_INPUT_GPC, true);
+ $uid_field = $this->rc->config->get('acl_users_uid_field', 'uid');
+ $users = array();
+
+ if ($this->init_ldap()) {
+ $this->ldap->set_pagesize(15);
+ $result = $this->ldap->search('*', $search);
+
+ foreach ($result->records as $record) {
+ $user = $record[$uid_field];
+
+ if (is_array($user)) {
+ $user = array_filter($user);
+ $user = $user[0];
+ }
+
+ if ($user) {
+
+ if ($record['name'])
+ $user = $record['name'] . ' (' . $user . ')';
+
+ $users[] = $user;
+ }
+ }
+ }
+
+ sort($users, SORT_LOCALE_STRING);
+
+ $this->rc->output->command('ksearch_query_results', $users, $search);
+ $this->rc->output->send();
+ }
+
+ /**
* Handler for 'folder_form' hook
*
* @param array $args Hook arguments array (form data)
@@ -138,6 +179,7 @@ class acl extends rcube_plugin
// The 'Sharing' tab
$this->mbox = $mbox_imap;
+ $this->rc->output->set_env('acl_users_source', (bool) $this->rc->config->get('acl_users_source'));
$this->rc->output->set_env('mailbox', $mbox_imap);
$this->rc->output->add_handlers(array(
'acltable' => array($this, 'templ_table'),
@@ -573,4 +615,44 @@ class acl extends rcube_plugin
return $_SESSION['acl_username_realm'] = $domain;
}
+
+ /**
+ * Initializes autocomplete LDAP backend
+ */
+ private function init_ldap()
+ {
+ if ($this->ldap)
+ return $this->ldap->ready;
+
+ $ldap_config = (array) $this->rc->config->get('ldap_public');
+ $addressbook = $this->rc->config->get('acl_users_source');
+ $uid_field = $this->rc->config->get('acl_users_uid_field', 'uid');
+
+ if (empty($addressbook) || empty($uid_field) || empty($ldap_config[$addressbook])) {
+ return false;
+ }
+
+ // search also in UID field
+ $ldap_config[$addressbook]['search_fields'] = array_unique(
+ array_merge((array)$uid_field, (array)$ldap_config[$addressbook]['search_fields']));
+
+ // add UID field to fieldmap, so it will be returned in a record
+ if (isset($ldap_config[$addressbook]['fieldmap'])) {
+ if (empty($ldap_config[$addressbook]['fieldmap']['uid'])) {
+ $ldap_config[$addressbook]['fieldmap']['uid'] = $uid_field;
+ }
+ }
+ // ... no fieldmap, use the old method
+ else if (empty($ldap_config[$addressbook]['uid_field'])) {
+ $ldap_config[$addressbook]['uid_field'] = $uid_field;
+ }
+
+ // Initialize LDAP connection
+ $this->ldap = new rcube_ldap(
+ $ldap_config[$addressbook],
+ $this->rc->config->get('ldap_debug'),
+ $this->rc->config->mail_domain($_SESSION['imap_host']));
+
+ return $this->ldap->ready;
+ }
}
diff --git a/plugins/acl/config.inc.php.dist b/plugins/acl/config.inc.php.dist
index 4ced35861..a8a212d89 100644
--- a/plugins/acl/config.inc.php.dist
+++ b/plugins/acl/config.inc.php.dist
@@ -5,4 +5,11 @@
// In simple mode access rights are grouped into four groups: read, write, delete, full
$rcmail_config['acl_advanced_mode'] = false;
+// The ID of the LDAP addressbook that would be searched for existing user names.
+// (This should be a string, which refers to the $rcmail_config['ldap_public'] array.)
+$rcmail_config['acl_users_source'] = '';
+
+// The LDAP attribute which will be used as a user identifier
+$rcmail_config['acl_users_uid_field'] = 'uid';
+
?>