From 0784bcb8d74214448e3908e8c05a8c6be38ef457 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 10 Jan 2013 23:30:26 +0100
Subject: introduce configPrefix to allow settings for multiple LDAP servers
---
apps/user_ldap/ajax/testConfiguration.php | 4 +--
apps/user_ldap/appinfo/app.php | 2 +-
apps/user_ldap/lib/connection.php | 58 ++++++++++++++++---------------
3 files changed, 33 insertions(+), 31 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php
index a82f7e4c17b..fd72485268f 100644
--- a/apps/user_ldap/ajax/testConfiguration.php
+++ b/apps/user_ldap/ajax/testConfiguration.php
@@ -4,7 +4,7 @@
* ownCloud - user_ldap
*
* @author Arthur Schiwon
- * @copyright 2012 Arthur Schiwon blizzz@owncloud.com
+ * @copyright 2012, 2013 Arthur Schiwon blizzz@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -26,7 +26,7 @@ OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
-$connection = new \OCA\user_ldap\lib\Connection(null);
+$connection = new \OCA\user_ldap\lib\Connection('', null);
if($connection->setConfiguration($_POST)) {
//Configuration is okay
if($connection->bind()) {
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index ce3079da0ba..9e72e388e67 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -23,7 +23,7 @@
OCP\App::registerAdmin('user_ldap', 'settings');
-$connector = new OCA\user_ldap\lib\Connection('user_ldap');
+$connector = new OCA\user_ldap\lib\Connection('', 'user_ldap');
$userBackend = new OCA\user_ldap\USER_LDAP();
$userBackend->setConnector($connector);
$groupBackend = new OCA\user_ldap\GROUP_LDAP();
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 7046cbbfc78..21b2d7560c9 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -4,7 +4,7 @@
* ownCloud – LDAP Access
*
* @author Arthur Schiwon
- * @copyright 2012 Arthur Schiwon blizzz@owncloud.com
+ * @copyright 2012, 2013 Arthur Schiwon blizzz@owncloud.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -25,6 +25,7 @@ namespace OCA\user_ldap\lib;
class Connection {
private $ldapConnectionRes = null;
+ private $configPrefix;
private $configID;
private $configured = false;
@@ -59,7 +60,8 @@ class Connection {
'hasPagedResultSupport' => false,
);
- public function __construct($configID = 'user_ldap') {
+ public function __construct($configPrefix = '', $configID = 'user_ldap') {
+ $this->configPrefix = $configPrefix;
$this->configID = $configID;
$this->cache = \OC_Cache::getGlobalCache();
$this->config['hasPagedResultSupport'] = (function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response'));
@@ -89,7 +91,7 @@ class Connection {
\OCP\Util::writeLog('user_ldap', 'Set config ldapUuidAttribute to '.$value, \OCP\Util::DEBUG);
$this->config[$name] = $value;
if(!empty($this->configID)) {
- \OCP\Config::setAppValue($this->configID, 'ldap_uuid_attribute', $value);
+ \OCP\Config::setAppValue($this->configID, $this->configPrefix.'ldap_uuid_attribute', $value);
}
$changed = true;
}
@@ -126,7 +128,7 @@ class Connection {
}
private function getCacheKey($key) {
- $prefix = 'LDAP-'.$this->configID.'-';
+ $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
if(is_null($key)) {
return $prefix;
}
@@ -183,30 +185,30 @@ class Connection {
\OCP\Util::writeLog('user_ldap', 'Checking conf state: isConfigured? '.print_r($this->configured, true).' isForce? '.print_r($force, true).' configID? '.print_r($this->configID, true), \OCP\Util::DEBUG);
if((!$this->configured || $force) && !is_null($this->configID)) {
\OCP\Util::writeLog('user_ldap', 'Reading the configuration', \OCP\Util::DEBUG);
- $this->config['ldapHost'] = \OCP\Config::getAppValue($this->configID, 'ldap_host', '');
- $this->config['ldapPort'] = \OCP\Config::getAppValue($this->configID, 'ldap_port', 389);
- $this->config['ldapAgentName'] = \OCP\Config::getAppValue($this->configID, 'ldap_dn', '');
- $this->config['ldapAgentPassword'] = base64_decode(\OCP\Config::getAppValue($this->configID, 'ldap_agent_password', ''));
- $this->config['ldapBase'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, 'ldap_base', ''));
- $this->config['ldapBaseUsers'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, 'ldap_base_users', $this->config['ldapBase']));
- $this->config['ldapBaseGroups'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, 'ldap_base_groups', $this->config['ldapBase']));
- $this->config['ldapTLS'] = \OCP\Config::getAppValue($this->configID, 'ldap_tls', 0);
- $this->config['ldapNoCase'] = \OCP\Config::getAppValue($this->configID, 'ldap_nocase', 0);
- $this->config['turnOffCertCheck'] = \OCP\Config::getAppValue($this->configID, 'ldap_turn_off_cert_check', 0);
- $this->config['ldapUserDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, 'ldap_display_name', 'uid'), 'UTF-8');
- $this->config['ldapUserFilter'] = \OCP\Config::getAppValue($this->configID, 'ldap_userlist_filter', 'objectClass=person');
- $this->config['ldapGroupFilter'] = \OCP\Config::getAppValue($this->configID, 'ldap_group_filter', '(objectClass=posixGroup)');
- $this->config['ldapLoginFilter'] = \OCP\Config::getAppValue($this->configID, 'ldap_login_filter', '(uid=%uid)');
- $this->config['ldapGroupDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, 'ldap_group_display_name', 'uid'), 'UTF-8');
- $this->config['ldapQuotaAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_quota_attr', '');
- $this->config['ldapQuotaDefault'] = \OCP\Config::getAppValue($this->configID, 'ldap_quota_def', '');
- $this->config['ldapEmailAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_email_attr', '');
- $this->config['ldapGroupMemberAssocAttr'] = \OCP\Config::getAppValue($this->configID, 'ldap_group_member_assoc_attribute', 'uniqueMember');
+ $this->config['ldapHost'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_host', '');
+ $this->config['ldapPort'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_port', 389);
+ $this->config['ldapAgentName'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_dn', '');
+ $this->config['ldapAgentPassword'] = base64_decode(\OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_agent_password', ''));
+ $this->config['ldapBase'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base', ''));
+ $this->config['ldapBaseUsers'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_users', $this->config['ldapBase']));
+ $this->config['ldapBaseGroups'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_groups', $this->config['ldapBase']));
+ $this->config['ldapTLS'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_tls', 0);
+ $this->config['ldapNoCase'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_nocase', 0);
+ $this->config['turnOffCertCheck'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_turn_off_cert_check', 0);
+ $this->config['ldapUserDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, '$this->configPrefix.ldap_display_name', 'uid'), 'UTF-8');
+ $this->config['ldapUserFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_userlist_filter', 'objectClass=person');
+ $this->config['ldapGroupFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_group_filter', '(objectClass=posixGroup)');
+ $this->config['ldapLoginFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_login_filter', '(uid=%uid)');
+ $this->config['ldapGroupDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_group_display_name', 'uid'), 'UTF-8');
+ $this->config['ldapQuotaAttribute'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_quota_attr', '');
+ $this->config['ldapQuotaDefault'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_quota_def', '');
+ $this->config['ldapEmailAttribute'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_email_attr', '');
+ $this->config['ldapGroupMemberAssocAttr'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_group_member_assoc_attribute', 'uniqueMember');
$this->config['ldapIgnoreNamingRules'] = \OCP\Config::getSystemValue('ldapIgnoreNamingRules', false);
- $this->config['ldapCacheTTL'] = \OCP\Config::getAppValue($this->configID, 'ldap_cache_ttl', 10*60);
- $this->config['ldapUuidAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_uuid_attribute', 'auto');
- $this->config['ldapOverrideUuidAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_override_uuid_attribute', 0);
- $this->config['homeFolderNamingRule'] = \OCP\Config::getAppValue($this->configID, 'home_folder_naming_rule', 'opt:username');
+ $this->config['ldapCacheTTL'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_cache_ttl', 10*60);
+ $this->config['ldapUuidAttribute'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_uuid_attribute', 'auto');
+ $this->config['ldapOverrideUuidAttribute'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_override_uuid_attribute', 0);
+ $this->config['homeFolderNamingRule'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'home_folder_naming_rule', 'opt:username');
$this->configured = $this->validateConfiguration();
}
@@ -264,7 +266,7 @@ class Connection {
\OCP\Util::writeLog('user_ldap', 'No group filter is specified, LDAP group feature will not be used.', \OCP\Util::INFO);
}
if(!in_array($this->config['ldapUuidAttribute'], array('auto', 'entryuuid', 'nsuniqueid', 'objectguid')) && (!is_null($this->configID))) {
- \OCP\Config::setAppValue($this->configID, 'ldap_uuid_attribute', 'auto');
+ \OCP\Config::setAppValue($this->configID, $this->configPrefix.'ldap_uuid_attribute', 'auto');
\OCP\Util::writeLog('user_ldap', 'Illegal value for the UUID Attribute, reset to autodetect.', \OCP\Util::INFO);
}
--
cgit v1.2.3
From fab5817f67a9e9dde245d522838fee3b928fcbd8 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 10 Jan 2013 23:34:24 +0100
Subject: documentation for the Connection constructor
---
apps/user_ldap/lib/connection.php | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 21b2d7560c9..803ac34f597 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -60,6 +60,11 @@ class Connection {
'hasPagedResultSupport' => false,
);
+ /**
+ * @brief Constructor
+ * @param $configPrefix a string with the prefix for the configkey column (appconfig table)
+ * @param $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
+ */
public function __construct($configPrefix = '', $configID = 'user_ldap') {
$this->configPrefix = $configPrefix;
$this->configID = $configID;
--
cgit v1.2.3
From 09c54722a877352713d8cefdb6a0a92860633898 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Fri, 11 Jan 2013 18:13:22 +0100
Subject: add LDAP User and Group proxies to suppoer multiple servers
---
apps/user_ldap/group_proxy.php | 178 +++++++++++++++++++++++++++++++++++++++++
apps/user_ldap/lib/proxy.php | 104 ++++++++++++++++++++++++
apps/user_ldap/user_proxy.php | 159 ++++++++++++++++++++++++++++++++++++
3 files changed, 441 insertions(+)
create mode 100644 apps/user_ldap/group_proxy.php
create mode 100644 apps/user_ldap/lib/proxy.php
create mode 100644 apps/user_ldap/user_proxy.php
(limited to 'apps')
diff --git a/apps/user_ldap/group_proxy.php b/apps/user_ldap/group_proxy.php
new file mode 100644
index 00000000000..5aa1aef0e0e
--- /dev/null
+++ b/apps/user_ldap/group_proxy.php
@@ -0,0 +1,178 @@
+.
+ *
+ */
+
+namespace OCA\user_ldap;
+
+class Group_Proxy extends lib\Proxy implements \OCP\GroupInterface {
+ private $backends = array();
+ private $refBackend = null;
+
+ /**
+ * @brief Constructor
+ * @param $serverConfigPrefixes array containing the config Prefixes
+ */
+ public function __construct($serverConfigPrefixes) {
+ parent::__construct();
+ foreach($serverConfigPrefixes as $configPrefix) {
+ $this->backends[$configPrefix] = new \OCA\user_ldap\GROUP_LDAP();
+ $connector = $this->getConnector($configPrefix);
+ $this->backends[$configPrefix]->setConnector($connector);
+ if(is_null($this->refBackend)) {
+ $this->refBackend = &$this->backends[$configPrefix];
+ }
+ }
+ }
+
+ /**
+ * @brief Tries the backends one after the other until a positive result is returned from the specified method
+ * @param $gid string, the gid connected to the request
+ * @param $method string, the method of the group backend that shall be called
+ * @param $parameters an array of parameters to be passed
+ * @return mixed, the result of the method or false
+ */
+ protected function walkBackends($gid, $method, $parameters) {
+ $cacheKey = $this->getGroupCacheKey($gid);
+ foreach($this->backends as $configPrefix => $backend) {
+ if($result = call_user_func_array(array($backend, $method), $parameters)) {
+ $this->writeToCache($cacheKey, $configPrefix);
+ return $result;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @brief Asks the backend connected to the server that supposely takes care of the gid from the request.
+ * @param $gid string, the gid connected to the request
+ * @param $method string, the method of the group backend that shall be called
+ * @param $parameters an array of parameters to be passed
+ * @return mixed, the result of the method or false
+ */
+ protected function callOnLastSeenOn($gid, $method, $parameters) {
+ $cacheKey = $this->getGroupCacheKey($gid);;
+ $prefix = $this->getFromCache($cacheKey);
+ //in case the uid has been found in the past, try this stored connection first
+ if(!is_null($prefix)) {
+ if(isset($this->backends[$prefix])) {
+ $result = call_user_func_array(array($this->backends[$prefix], $method), $parameters);
+ if(!$result) {
+ //not found here, reset cache to null
+ $this->writeToCache($cacheKey, null);
+ }
+ return $result;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @brief is user in group?
+ * @param $uid uid of the user
+ * @param $gid gid of the group
+ * @returns true/false
+ *
+ * Checks whether the user is member of a group or not.
+ */
+ public function inGroup($uid, $gid) {
+ return $this->handleRequest($gid, 'inGroup', array($uid, $gid));
+ }
+
+ /**
+ * @brief Get all groups a user belongs to
+ * @param $uid Name of the user
+ * @returns array with group names
+ *
+ * This function fetches all groups a user belongs to. It does not check
+ * if the user exists at all.
+ */
+ public function getUserGroups($uid) {
+ $groups = array();
+
+ foreach($this->backends as $backend) {
+ $backendGroups = $backend->getUserGroups($uid);
+ if (is_array($backendGroups)) {
+ $groups = array_merge($groups, $backendGroups);
+ }
+ }
+
+ return $groups;
+ }
+
+ /**
+ * @brief get a list of all users in a group
+ * @returns array with user ids
+ */
+ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $users = array();
+
+ foreach($this->backends as $backend) {
+ $backendUsers = $backend->usersInGroup($gid, $search, $limit, $offset);
+ if (is_array($backendUsers)) {
+ $users = array_merge($users, $backendUsers);
+ }
+ }
+
+ return $users;
+ }
+
+ /**
+ * @brief get a list of all groups
+ * @returns array with group names
+ *
+ * Returns a list with all groups
+ */
+ public function getGroups($search = '', $limit = -1, $offset = 0) {
+ $groups = array();
+
+ foreach($this->backends as $backend) {
+ $backendGroups = $backend->getGroups($search, $limit, $offset);
+ if (is_array($backendGroups)) {
+ $groups = array_merge($groups, $backendGroups);
+ }
+ }
+
+ return $groups;
+ }
+
+ /**
+ * check if a group exists
+ * @param string $gid
+ * @return bool
+ */
+ public function groupExists($gid) {
+ return $this->handleRequest($gid, 'groupExists', array($gid));
+ }
+
+ /**
+ * @brief Check if backend implements actions
+ * @param $actions bitwise-or'ed actions
+ * @returns boolean
+ *
+ * Returns the supported actions as int to be
+ * compared with OC_USER_BACKEND_CREATE_USER etc.
+ */
+ public function implementsActions($actions) {
+ //it's the same across all our user backends obviously
+ return $this->refBackend->implementsActions($actions);
+ }
+}
\ No newline at end of file
diff --git a/apps/user_ldap/lib/proxy.php b/apps/user_ldap/lib/proxy.php
new file mode 100644
index 00000000000..c80e2163475
--- /dev/null
+++ b/apps/user_ldap/lib/proxy.php
@@ -0,0 +1,104 @@
+.
+ *
+ */
+
+namespace OCA\user_ldap\lib;
+
+abstract class Proxy {
+ static private $connectors = array();
+
+ public function __construct() {
+ $this->cache = \OC_Cache::getGlobalCache();
+ }
+
+ private function addConnector($configPrefix) {
+ self::$connectors[$configPrefix] = new \OCA\user_ldap\lib\Connection($configPrefix);
+ }
+
+ protected function getConnector($configPrefix) {
+ if(!isset(self::$connectors[$configPrefix])) {
+ $this->addConnector($configPrefix);
+ }
+ return self::$connectors[$configPrefix];
+ }
+
+ protected function getConnectors() {
+ return self::$connectors;
+ }
+
+ protected function getUserCacheKey($uid) {
+ return 'user-'.$uid.'-lastSeenOn';
+ }
+
+ protected function getGroupCacheKey($gid) {
+ return 'group-'.$gid.'-lastSeenOn';
+ }
+
+ abstract protected function callOnLastSeenOn($id, $method, $parameters);
+ abstract protected function walkBackends($id, $method, $parameters);
+
+ /**
+ * @brief Takes care of the request to the User backend
+ * @param $uid string, the uid connected to the request
+ * @param $method string, the method of the user backend that shall be called
+ * @param $parameters an array of parameters to be passed
+ * @return mixed, the result of the specified method
+ */
+ protected function handleRequest($id, $method, $parameters) {
+ if(!$result = $this->callOnLastSeenOn($id, $method, $parameters)) {
+ $result = $this->walkBackends($id, $method, $parameters);
+ }
+ return $result;
+ }
+
+ private function getCacheKey($key) {
+ $prefix = 'LDAP-Proxy-';
+ if(is_null($key)) {
+ return $prefix;
+ }
+ return $prefix.md5($key);
+ }
+
+ public function getFromCache($key) {
+ if(!$this->isCached($key)) {
+ return null;
+ }
+ $key = $this->getCacheKey($key);
+
+ return unserialize(base64_decode($this->cache->get($key)));
+ }
+
+ public function isCached($key) {
+ $key = $this->getCacheKey($key);
+ return $this->cache->hasKey($key);
+ }
+
+ public function writeToCache($key, $value) {
+ $key = $this->getCacheKey($key);
+ $value = base64_encode(serialize($value));
+ $this->cache->set($key, $value, '2592000');
+ }
+
+ public function clearCache() {
+ $this->cache->clear($this->getCacheKey(null));
+ }
+}
\ No newline at end of file
diff --git a/apps/user_ldap/user_proxy.php b/apps/user_ldap/user_proxy.php
new file mode 100644
index 00000000000..47f901ddb51
--- /dev/null
+++ b/apps/user_ldap/user_proxy.php
@@ -0,0 +1,159 @@
+.
+ *
+ */
+
+namespace OCA\user_ldap;
+
+class User_Proxy extends lib\Proxy implements \OCP\UserInterface {
+ private $backends = array();
+ private $refBackend = null;
+
+ /**
+ * @brief Constructor
+ * @param $serverConfigPrefixes array containing the config Prefixes
+ */
+ public function __construct($serverConfigPrefixes) {
+ parent::__construct();
+ foreach($serverConfigPrefixes as $configPrefix) {
+ $this->backends[$configPrefix] = new \OCA\user_ldap\USER_LDAP();
+ $connector = $this->getConnector($configPrefix);
+ $this->backends[$configPrefix]->setConnector($connector);
+ if(is_null($this->refBackend)) {
+ $this->refBackend = &$this->backends[$configPrefix];
+ }
+ }
+ }
+
+ /**
+ * @brief Tries the backends one after the other until a positive result is returned from the specified method
+ * @param $uid string, the uid connected to the request
+ * @param $method string, the method of the user backend that shall be called
+ * @param $parameters an array of parameters to be passed
+ * @return mixed, the result of the method or false
+ */
+ protected function walkBackends($uid, $method, $parameters) {
+ $cacheKey = $this->getUserCacheKey($uid);
+ foreach($this->backends as $configPrefix => $backend) {
+ if($result = call_user_func_array(array($backend, $method), $parameters)) {
+ $this->writeToCache($cacheKey, $configPrefix);
+ return $result;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @brief Asks the backend connected to the server that supposely takes care of the uid from the request.
+ * @param $uid string, the uid connected to the request
+ * @param $method string, the method of the user backend that shall be called
+ * @param $parameters an array of parameters to be passed
+ * @return mixed, the result of the method or false
+ */
+ protected function callOnLastSeenOn($uid, $method, $parameters) {
+ $cacheKey = $this->getUserCacheKey($uid);
+ $prefix = $this->getFromCache($cacheKey);
+ //in case the uid has been found in the past, try this stored connection first
+ if(!is_null($prefix)) {
+ if(isset($this->backends[$prefix])) {
+ $result = call_user_func_array(array($this->backends[$prefix], $method), $parameters);
+ if(!$result) {
+ //not found here, reset cache to null
+ $this->writeToCache($cacheKey, null);
+ }
+ return $result;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @brief Check if backend implements actions
+ * @param $actions bitwise-or'ed actions
+ * @returns boolean
+ *
+ * Returns the supported actions as int to be
+ * compared with OC_USER_BACKEND_CREATE_USER etc.
+ */
+ public function implementsActions($actions) {
+ //it's the same across all our user backends obviously
+ return $this->refBackend->implementsActions($actions);
+ }
+
+ /**
+ * @brief Get a list of all users
+ * @returns array with all uids
+ *
+ * Get a list of all users.
+ */
+ public function getUsers($search = '', $limit = 10, $offset = 0) {
+ //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends
+ $users = array();
+ foreach($this->backends as $backend) {
+ $backendUsers = $backend->getUsers($search, $limit, $offset);
+ if (is_array($backendUsers)) {
+ $users = array_merge($users, $backendUsers);
+ }
+ }
+ return $users;
+ }
+
+ /**
+ * @brief check if a user exists
+ * @param string $uid the username
+ * @return boolean
+ */
+ public function userExists($uid) {
+ return $this->handleRequest($uid, 'userExists', array($uid));
+ }
+
+ /**
+ * @brief Check if the password is correct
+ * @param $uid The username
+ * @param $password The password
+ * @returns true/false
+ *
+ * Check if the password is correct without logging in the user
+ */
+ public function checkPassword($uid, $password) {
+ return $this->handleRequest($uid, 'checkPassword', array($uid, $password));
+ }
+
+ /**
+ * @brief get the user's home directory
+ * @param string $uid the username
+ * @return boolean
+ */
+ public function getHome($uid) {
+ return $this->handleRequest($uid, 'getHome', array($uid));
+ }
+
+ /**
+ * @brief delete a user
+ * @param $uid The username of the user to delete
+ * @returns true/false
+ *
+ * Deletes a user
+ */
+ public function deleteUser($uid) {
+ return false;
+ }
+}
\ No newline at end of file
--
cgit v1.2.3
From ad1113c2cb06f1c35102c50e24d803fa1bd2d367 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 16 Jan 2013 14:56:57 +0100
Subject: LDAP: fix parameter passed not as expected
---
apps/user_ldap/lib/access.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 422e43fc003..27c74446976 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -912,7 +912,7 @@ abstract class Access {
$reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
//a bit recursive, $offset of 0 is the exit
\OCP\Util::writeLog('user_ldap', 'Looking for cookie L/O '.$limit.'/'.$reOffset, \OCP\Util::INFO);
- $this->search($filter, $base, $attr, $limit, $reOffset, true);
+ $this->search($filter, array($base), $attr, $limit, $reOffset, true);
$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
//TODO: remember this, probably does not change in the next request...
--
cgit v1.2.3
From 4699f36e4406a50e3b44a2b69b3ecc37a93c321c Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 16 Jan 2013 14:58:49 +0100
Subject: LDAP: fix read configuration, remove unnecessary debug output
---
apps/user_ldap/lib/connection.php | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 803ac34f597..1dc1d1510ab 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -70,7 +70,6 @@ class Connection {
$this->configID = $configID;
$this->cache = \OC_Cache::getGlobalCache();
$this->config['hasPagedResultSupport'] = (function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response'));
- \OCP\Util::writeLog('user_ldap', 'PHP supports paged results? '.print_r($this->config['hasPagedResultSupport'], true), \OCP\Util::INFO);
}
public function __destruct() {
@@ -187,20 +186,20 @@ class Connection {
* Caches the general LDAP configuration.
*/
private function readConfiguration($force = false) {
- \OCP\Util::writeLog('user_ldap', 'Checking conf state: isConfigured? '.print_r($this->configured, true).' isForce? '.print_r($force, true).' configID? '.print_r($this->configID, true), \OCP\Util::DEBUG);
if((!$this->configured || $force) && !is_null($this->configID)) {
- \OCP\Util::writeLog('user_ldap', 'Reading the configuration', \OCP\Util::DEBUG);
$this->config['ldapHost'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_host', '');
$this->config['ldapPort'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_port', 389);
$this->config['ldapAgentName'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_dn', '');
$this->config['ldapAgentPassword'] = base64_decode(\OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_agent_password', ''));
- $this->config['ldapBase'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base', ''));
- $this->config['ldapBaseUsers'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_users', $this->config['ldapBase']));
- $this->config['ldapBaseGroups'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_groups', $this->config['ldapBase']));
+ $rawLdapBase = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base', '');
+ $this->config['ldapBase'] = preg_split('/\r\n|\r|\n/', $rawLdapBase);
+ $this->config['ldapBaseUsers'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_users', $rawLdapBase));
+ $this->config['ldapBaseGroups'] = preg_split('/\r\n|\r|\n/', \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base_groups', $rawLdapBase));
+ unset($rawLdapBase);
$this->config['ldapTLS'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_tls', 0);
$this->config['ldapNoCase'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_nocase', 0);
$this->config['turnOffCertCheck'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_turn_off_cert_check', 0);
- $this->config['ldapUserDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, '$this->configPrefix.ldap_display_name', 'uid'), 'UTF-8');
+ $this->config['ldapUserDisplayName'] = mb_strtolower(\OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_display_name', 'uid'), 'UTF-8');
$this->config['ldapUserFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_userlist_filter', 'objectClass=person');
$this->config['ldapGroupFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_group_filter', '(objectClass=posixGroup)');
$this->config['ldapLoginFilter'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_login_filter', '(uid=%uid)');
--
cgit v1.2.3
From 6063ce9c8d3f32a7c9d53a0aa77d2cbfa0798f7b Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 16 Jan 2013 14:59:41 +0100
Subject: LDAP: enable support for multiple LDAP/AD servers
---
apps/user_ldap/appinfo/app.php | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index 9e72e388e67..69860ba1432 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -23,11 +23,27 @@
OCP\App::registerAdmin('user_ldap', 'settings');
-$connector = new OCA\user_ldap\lib\Connection('', 'user_ldap');
-$userBackend = new OCA\user_ldap\USER_LDAP();
-$userBackend->setConnector($connector);
-$groupBackend = new OCA\user_ldap\GROUP_LDAP();
-$groupBackend->setConnector($connector);
+$query = \OCP\DB::prepare('
+ SELECT DISTINCT `configkey`
+ FROM `*PREFIX*appconfig`
+ WHERE `configkey` LIKE ?
+');
+$serverConnections = $query->execute(array('%ldap_login_filter'))->fetchAll();
+if(count($serverConnections) == 1) {
+ $prefix = substr($serverConnections[0]['configkey'], 0, strlen($serverConnections[0]['configkey'])- strlen('ldap_login_filter'));
+ $connector = new OCA\user_ldap\lib\Connection($prefix);
+ $userBackend = new OCA\user_ldap\USER_LDAP();
+ $userBackend->setConnector($connector);
+ $groupBackend = new OCA\user_ldap\GROUP_LDAP();
+ $groupBackend->setConnector($connector);
+} else {
+ $prefixes = array();
+ foreach($serverConnections as $serverConnection) {
+ $prefixes[] = substr($serverConnection['configkey'], 0, strlen($serverConnection['configkey'])- strlen('ldap_login_filter'));
+ }
+ $userBackend = new OCA\user_ldap\User_Proxy($prefixes);
+ $groupBackend = new OCA\user_ldap\Group_Proxy($prefixes);
+}
// register user backend
OC_User::useBackend($userBackend);
--
cgit v1.2.3
From 3d56cf3a5b29e0c75f98646eafd22ee8cb7749dc Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 17 Jan 2013 13:31:14 +0100
Subject: LDAP: add support for backup/replica servers
---
apps/user_ldap/lib/connection.php | 40 ++++++++++++++++++++++++++++-------
apps/user_ldap/settings.php | 2 +-
apps/user_ldap/templates/settings.php | 3 +++
3 files changed, 36 insertions(+), 9 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 1dc1d1510ab..a22246c7091 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -36,6 +36,8 @@ class Connection {
protected $config = array(
'ldapHost' => null,
'ldapPort' => null,
+ 'ldapBackupHost' => null,
+ 'ldapBackupPort' => null,
'ldapBase' => null,
'ldapBaseUsers' => null,
'ldapBaseGroups' => null,
@@ -56,6 +58,7 @@ class Connection {
'ldapCacheTTL' => null,
'ldapUuidAttribute' => null,
'ldapOverrideUuidAttribute' => null,
+ 'ldapOverrideMainServer' => false,
'homeFolderNamingRule' => null,
'hasPagedResultSupport' => false,
);
@@ -188,7 +191,10 @@ class Connection {
private function readConfiguration($force = false) {
if((!$this->configured || $force) && !is_null($this->configID)) {
$this->config['ldapHost'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_host', '');
+ $this->config['ldapBackupHost'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_backup_host', '');
$this->config['ldapPort'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_port', 389);
+ $this->config['ldapBackupPort'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_backup_port', $this->config['ldapPort']);
+ $this->config['ldapOverrideMainServer']= \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_override_main_server', false);
$this->config['ldapAgentName'] = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_dn', '');
$this->config['ldapAgentPassword'] = base64_decode(\OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_agent_password', ''));
$rawLdapBase = \OCP\Config::getAppValue($this->configID, $this->configPrefix.'ldap_base', '');
@@ -229,7 +235,7 @@ class Connection {
return false;
}
- $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
+ $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldapOverrideMainServer' => 'ldap_override_main_server', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule');
@@ -342,16 +348,34 @@ class Connection {
\OCP\Util::writeLog('user_ldap', 'Could not turn off SSL certificate validation.', \OCP\Util::WARN);
}
}
- $this->ldapConnectionRes = ldap_connect($this->config['ldapHost'], $this->config['ldapPort']);
- if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
- if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
- if($this->config['ldapTLS']) {
- ldap_start_tls($this->ldapConnectionRes);
+ if(!$this->config['ldapOverrideMainServer'] && !$this->getFromCache('overrideMainServer')) {
+ $this->doConnect($this->config['ldapHost'], $this->config['ldapPort']);
+ $bindStatus = $this->bind();
+ }
+
+ $error = null;
+ //if LDAP server is not reachable, try the Backup (Replica!) Server
+ if((!$bindStatus && ($error = ldap_errno($this->ldapConnectionRes)) == -1)
+ || $this->config['ldapOverrideMainServer']
+ || $this->getFromCache('overrideMainServer')) {
+ $this->doConnect($this->config['ldapBackupHost'], $this->config['ldapBackupPort']);
+ $bindStatus = $this->bind();
+ if($bindStatus && $error == -1) {
+ $this->writeToCache('overrideMainServer', true);
}
- }
}
+ return $bindStatus;
+ }
+ }
- return $this->bind();
+ private function doConnect($host, $port) {
+ $this->ldapConnectionRes = ldap_connect($host, $port);
+ if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
+ if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
+ if($this->config['ldapTLS']) {
+ ldap_start_tls($this->ldapConnectionRes);
+ }
+ }
}
}
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index 58ec8e7f7a4..e49f37da2de 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -23,7 +23,7 @@
OC_Util::checkAdminUser();
-$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_agent_password', 'ldap_base', 'ldap_base_users', 'ldap_base_groups', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_group_filter', 'ldap_display_name', 'ldap_group_display_name', 'ldap_tls', 'ldap_turn_off_cert_check', 'ldap_nocase', 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr', 'ldap_group_member_assoc_attribute', 'ldap_cache_ttl', 'home_folder_naming_rule');
+$params = array('ldap_host', 'ldap_port', 'ldap_backup_host', 'ldap_backup_port', 'ldap_override_main_server', 'ldap_dn', 'ldap_agent_password', 'ldap_base', 'ldap_base_users', 'ldap_base_groups', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_group_filter', 'ldap_display_name', 'ldap_group_display_name', 'ldap_tls', 'ldap_turn_off_cert_check', 'ldap_nocase', 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr', 'ldap_group_member_assoc_attribute', 'ldap_cache_ttl', 'home_folder_naming_rule');
OCP\Util::addscript('user_ldap', 'settings');
OCP\Util::addstyle('user_ldap', 'settings');
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index b24c6e2f025..030fbff4aac 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -22,6 +22,9 @@
-
-
-
-
-
t('use %%uid placeholder, e.g. "uid=%%uid"');?>
-
t('without any placeholder, e.g. "objectClass=person".');?>
-
t('without any placeholder, e.g. "objectClass=posixGroup".');?>
+
+
+
+
+
t('use %%uid placeholder, e.g. "uid=%%uid"');?>
+
t('without any placeholder, e.g. "objectClass=person".');?>
+
t('without any placeholder, e.g. "objectClass=posixGroup".');?>
-
-
-
-
title="t('When switched on, ownCloud will only connect to the replica server.');?>" />
-
-
-
-
title="t('Do not use it for SSL connections, it will fail.');?>" />
-
>
-
> t('Not recommended, use for testing only.');?>
-
-
-
-
-
-
-
+
+
+
+
data-default="" title="t('When switched on, ownCloud will only connect to the replica server.');?>" />
+
+
+
+
data-default="" title="t('Do not use it for SSL connections, it will fail.');?>" />
+
>
+
> t('Not recommended, use for testing only.');?>
+
+
+
+
+
+
+
t('Help');?>
--
cgit v1.2.3
From 229a25f41a5cf1b9eeac8cccedaa7196975328b4 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Fri, 18 Jan 2013 13:53:26 +0100
Subject: fix mixed key and value
---
apps/user_ldap/lib/connection.php | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index b6ed500cb15..926691c2d91 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -264,7 +264,7 @@ class Connection {
return false;
}
- $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldapOverrideMainServer' => 'ldap_override_main_server', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
+ $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule');
@@ -287,6 +287,14 @@ class Connection {
return $this->configured;
}
+ /**
+ * @brief get the current LDAP configuration
+ * @return array
+ */
+ public function getConfiguration() {
+ return $this->config;
+ }
+
/**
* @brief Validates the user specified configuration
* @returns true if configuration seems OK, false otherwise
--
cgit v1.2.3
From 6d84aa93d3ddf4f7d3c8599cba17bb02fd6df9e9 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Sun, 20 Jan 2013 18:02:44 +0100
Subject: Ajaxifiy Settings Save
---
apps/user_ldap/ajax/setConfiguration.php | 33 +++++++++++++++++++++
apps/user_ldap/js/settings.js | 14 +++++++++
apps/user_ldap/lib/connection.php | 51 +++++++++++++++++++++++++++++---
apps/user_ldap/templates/settings.php | 2 +-
4 files changed, 95 insertions(+), 5 deletions(-)
create mode 100644 apps/user_ldap/ajax/setConfiguration.php
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/setConfiguration.php b/apps/user_ldap/ajax/setConfiguration.php
new file mode 100644
index 00000000000..206487c7e0a
--- /dev/null
+++ b/apps/user_ldap/ajax/setConfiguration.php
@@ -0,0 +1,33 @@
+.
+ *
+ */
+
+// Check user and app status
+OCP\JSON::checkAdminUser();
+OCP\JSON::checkAppEnabled('user_ldap');
+OCP\JSON::callCheck();
+
+$prefix = $_POST['ldap_serverconfig_chooser'];
+$connection = new \OCA\user_ldap\lib\Connection($prefix);
+$connection->setConfiguration($_POST);
+$connection->saveConfiguration();
+OCP\JSON::success();
\ No newline at end of file
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 0b8f141dfa2..a07d140cf86 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -22,6 +22,20 @@ $(document).ready(function() {
);
});
+ $('#ldap_submit').click(function(event) {
+ event.preventDefault();
+ $.post(
+ OC.filePath('user_ldap','ajax','setConfiguration.php'),
+ $('#ldap').serialize(),
+ function (result) {
+ if (result.status == 'success') {
+ $('#notification').text(t('user_ldap', 'LDAP Configuration Saved'));
+ $('#notification').fadeIn();
+ }
+ }
+ );
+ });
+
$('#ldap_serverconfig_chooser').change(function(event) {
value = $('#ldap_serverconfig_chooser option:selected:first').attr('value');
if(value == 'NEW') {
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 926691c2d91..ebc46bf3b94 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -195,6 +195,12 @@ class Connection {
$defaults[$varname]);
}
+ private function setValue($varname, $value) {
+ \OCP\Config::setAppValue($this->configID,
+ $this->configPrefix.$varname,
+ $value);
+ }
+
/**
* Caches the general LDAP configuration.
*/
@@ -205,7 +211,7 @@ class Connection {
$this->config['ldapHost'] = $this->$v('ldap_host');
$this->config['ldapBackupHost'] = $this->$v('ldap_backup_host');
$this->config['ldapPort'] = $this->$v('ldap_port');
- $this->config['ldapBackupPort'] = $this->$v('ldapPort');
+ $this->config['ldapBackupPort'] = $this->$v('ldap_backup_port');
$this->config['ldapOverrideMainServer']
= $this->$v('ldap_override_main_server');
$this->config['ldapAgentName'] = $this->$v('ldap_dn');
@@ -253,6 +259,13 @@ class Connection {
}
}
+ private function getConfigTranslationArray() {
+ static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
+
+ 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'turn_off_cert_check' => 'turnOffCertCheck');
+ return $array;
+ }
+
/**
* @brief set LDAP configuration with values delivered by an array, not read from configuration
* @param $config array that holds the config parameters in an associated array
@@ -264,9 +277,7 @@ class Connection {
return false;
}
- $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
-
- 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule');
+ $params = $this->getConfigTranslationArray();
foreach($config as $parameter => $value) {
if(isset($this->config[$parameter])) {
@@ -287,11 +298,42 @@ class Connection {
return $this->configured;
}
+ public function saveConfiguration() {
+ $trans = array_flip($this->getConfigTranslationArray());
+ foreach($this->config as $key => $value) {
+ \OCP\Util::writeLog('user_ldap', 'LDAP: storing key '.$key.' value '.$value, \OCP\Util::DEBUG);
+ switch ($key) {
+ case 'ldap_agent_password':
+ $value = base64_encode($value);
+ break;
+ case 'home_folder_naming_rule':
+ $value = empty($value) ? 'opt:username' : 'attr:'.$value;
+ break;
+ case 'ldapIgnoreNamingRules':
+ case 'ldapOverrideUuidAttribute':
+ case 'hasPagedResultSupport':
+ continue;
+ default:
+ if(is_null($value)) {
+ $value = 0;
+ }
+ }
+
+ $this->setValue($trans[$key], $value);
+ }
+ }
+
/**
* @brief get the current LDAP configuration
* @return array
*/
public function getConfiguration() {
+ $trans = $this->getConfigTranslationArray();
+ $config = array();
+ foreach($trans as $classKey => $dbKey) {
+ $config[$dbKey] = $this->config[$classKey];
+ }
+
return $this->config;
}
@@ -394,6 +436,7 @@ class Connection {
'ldap_uuid_attribute' => 'auto',
'ldap_override_uuid_attribute' => 0,
'home_folder_naming_rule' => '',
+ 'ldap_turn_off_cert_check' => 0,
);
}
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 90a46a1733a..6b95f8660eb 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -44,7 +44,7 @@
- t('Help');?>
+ t('Help');?>
--
cgit v1.2.3
From 0c3466325b858013acf799fa1cd65acaad48d723 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Sun, 20 Jan 2013 18:27:39 +0100
Subject: fix continue in switch, add another key to skip
---
apps/user_ldap/lib/connection.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index ebc46bf3b94..bf36db82232 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -311,8 +311,9 @@ class Connection {
break;
case 'ldapIgnoreNamingRules':
case 'ldapOverrideUuidAttribute':
+ case 'ldapUuidAttribute':
case 'hasPagedResultSupport':
- continue;
+ continue 2;
default:
if(is_null($value)) {
$value = 0;
--
cgit v1.2.3
From 10876aba896be188be2883dbc059b93fea96bbf5 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Sun, 20 Jan 2013 18:30:14 +0100
Subject: fix more config keys for save settings handling
---
apps/user_ldap/lib/connection.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index bf36db82232..7d9f82cf83d 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -303,10 +303,10 @@ class Connection {
foreach($this->config as $key => $value) {
\OCP\Util::writeLog('user_ldap', 'LDAP: storing key '.$key.' value '.$value, \OCP\Util::DEBUG);
switch ($key) {
- case 'ldap_agent_password':
+ case 'ldapAgentPassword':
$value = base64_encode($value);
break;
- case 'home_folder_naming_rule':
+ case 'homeFolderNamingRule':
$value = empty($value) ? 'opt:username' : 'attr:'.$value;
break;
case 'ldapIgnoreNamingRules':
--
cgit v1.2.3
From 83d9e1e2f083b176e3bff9d3851211b3bc9cb560 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 23 Jan 2013 23:40:21 +0100
Subject: make sure that Configuration is read when getConfiguration is called.
And give back the appropriate result.
---
apps/user_ldap/lib/connection.php | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 7d9f82cf83d..39ff530dc43 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -51,6 +51,7 @@ class Connection {
'ldapUserFilter' => null,
'ldapGroupFilter' => null,
'ldapGroupDisplayName' => null,
+ 'ldapGroupMemberAssocAttr' => null,
'ldapLoginFilter' => null,
'ldapQuotaAttribute' => null,
'ldapQuotaDefault' => null,
@@ -262,7 +263,7 @@ class Connection {
private function getConfigTranslationArray() {
static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
- 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'turn_off_cert_check' => 'turnOffCertCheck');
+ 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck');
return $array;
}
@@ -329,13 +330,22 @@ class Connection {
* @return array
*/
public function getConfiguration() {
+ $this->readConfiguration();
$trans = $this->getConfigTranslationArray();
$config = array();
- foreach($trans as $classKey => $dbKey) {
- $config[$dbKey] = $this->config[$classKey];
+ foreach($trans as $dbKey => $classKey) {
+ if($classKey == 'homeFolderNamingRule') {
+ if(strpos($this->config[$classKey], 'opt') === 0) {
+ $config[$dbKey] = '';
+ } else {
+ $config[$dbKey] = substr($this->config[$dbKey], 5);
+ }
+ continue;
+ }
+ $config[$dbKey] = $this->config[$classKey];
}
- return $this->config;
+ return $config;
}
/**
--
cgit v1.2.3
From 06c284f6cc6256b22f645d2d35f966c0bc98f4df Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 23 Jan 2013 23:41:35 +0100
Subject: LDAP settings: read configuration when another server config is
chosen
---
apps/user_ldap/ajax/getConfiguration.php | 31 ++++++++++++++++++++++++++
apps/user_ldap/js/settings.js | 37 +++++++++++++++++++++++++++++---
2 files changed, 65 insertions(+), 3 deletions(-)
create mode 100644 apps/user_ldap/ajax/getConfiguration.php
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/getConfiguration.php b/apps/user_ldap/ajax/getConfiguration.php
new file mode 100644
index 00000000000..dfae68d2dc9
--- /dev/null
+++ b/apps/user_ldap/ajax/getConfiguration.php
@@ -0,0 +1,31 @@
+.
+ *
+ */
+
+// Check user and app status
+OCP\JSON::checkAdminUser();
+OCP\JSON::checkAppEnabled('user_ldap');
+OCP\JSON::callCheck();
+
+$prefix = $_POST['ldap_serverconfig_chooser'];
+$connection = new \OCA\user_ldap\lib\Connection($prefix);
+OCP\JSON::success(array('configuration' => $connection->getConfiguration()));
\ No newline at end of file
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index a07d140cf86..66876cadaf7 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -49,6 +49,9 @@ $(document).ready(function() {
function(keep) {
if(!keep) {
$('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() {
+ if($(this).attr('id') == 'ldap_serverconfig_chooser') {
+ return;
+ }
$(this).val($(this).attr('data-default'));
});
$('#ldap').find('input[type=checkbox]').each(function() {
@@ -61,8 +64,8 @@ $(document).ready(function() {
}
}
);
- $('#ldap_serverconfig_chooser option:selected:first').removeAttr('selected');
- var html = '';
+ $('#ldap_serverconfig_chooser option:selected').removeAttr('selected');
+ var html = '';
$('#ldap_serverconfig_chooser option:last').before(html);
} else {
OC.dialogs.alert(
@@ -73,7 +76,35 @@ $(document).ready(function() {
}
);
} else {
- alert(value);
+ $.post(
+ OC.filePath('user_ldap','ajax','getConfiguration.php'),
+ $('#ldap_serverconfig_chooser').serialize(),
+ function (result) {
+ if(result.status == 'success') {
+ $.each(result.configuration, function(configkey, configvalue) {
+ elementID = '#'+configkey;
+
+ //deal with Checkboxes
+ if($(elementID).is('input[type=checkbox]')) {
+ if(configvalue == 1) {
+ $(elementID).attr('checked', 'checked');
+ } else {
+ $(elementID).removeAttr('checked');
+ }
+ return;
+ }
+
+ //On Textareas, Multi-Line Settings come as array
+ if($(elementID).is('textarea') && $.isArray(configvalue)) {
+ configvalue = configvalue.join("\n");
+ }
+
+ // assign the value
+ $('#'+configkey).val(configvalue);
+ });
+ }
+ }
+ );
}
});
});
\ No newline at end of file
--
cgit v1.2.3
From b979bf6f1cc2c3b9cf6d7a004edb5cbf9299e08b Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 23 Jan 2013 23:46:55 +0100
Subject: LDAP: fix default
---
apps/user_ldap/lib/connection.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 39ff530dc43..61b84fb10a1 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -446,7 +446,7 @@ class Connection {
'ldap_cache_ttl' => 600,
'ldap_uuid_attribute' => 'auto',
'ldap_override_uuid_attribute' => 0,
- 'home_folder_naming_rule' => '',
+ 'home_folder_naming_rule' => 'opt:username',
'ldap_turn_off_cert_check' => 0,
);
}
--
cgit v1.2.3
From 96949fc9dd5c50818a8f8bda75a9beb731ac91ae Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 12:42:28 +0100
Subject: LDAP: consolidate config prefix determination, autofill combo box in
settings
---
apps/user_ldap/appinfo/app.php | 20 +++++---------------
apps/user_ldap/settings.php | 11 ++++++++++-
apps/user_ldap/templates/settings.php | 1 -
3 files changed, 15 insertions(+), 17 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index 69860ba1432..79cfab58796 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -23,26 +23,16 @@
OCP\App::registerAdmin('user_ldap', 'settings');
-$query = \OCP\DB::prepare('
- SELECT DISTINCT `configkey`
- FROM `*PREFIX*appconfig`
- WHERE `configkey` LIKE ?
-');
-$serverConnections = $query->execute(array('%ldap_login_filter'))->fetchAll();
-if(count($serverConnections) == 1) {
- $prefix = substr($serverConnections[0]['configkey'], 0, strlen($serverConnections[0]['configkey'])- strlen('ldap_login_filter'));
- $connector = new OCA\user_ldap\lib\Connection($prefix);
+$configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
+if(count($configPrefixes) == 1) {
+ $connector = new OCA\user_ldap\lib\Connection($configPrefixes[0]);
$userBackend = new OCA\user_ldap\USER_LDAP();
$userBackend->setConnector($connector);
$groupBackend = new OCA\user_ldap\GROUP_LDAP();
$groupBackend->setConnector($connector);
} else {
- $prefixes = array();
- foreach($serverConnections as $serverConnection) {
- $prefixes[] = substr($serverConnection['configkey'], 0, strlen($serverConnection['configkey'])- strlen('ldap_login_filter'));
- }
- $userBackend = new OCA\user_ldap\User_Proxy($prefixes);
- $groupBackend = new OCA\user_ldap\Group_Proxy($prefixes);
+ $userBackend = new OCA\user_ldap\User_Proxy($configPrefixes);
+ $groupBackend = new OCA\user_ldap\Group_Proxy($configPrefixes);
}
// register user backend
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index f3f0826739f..57d370601cf 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -86,7 +86,16 @@ $tmpl->assign('ldap_cache_ttl', OCP\Config::getAppValue('user_ldap', 'ldap_cache
$hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username');
$hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:'));
$tmpl->assign('home_folder_naming_rule', $hfnr, '');
-$tmpl->assign('serverConfigurationOptions', '', false);
+
+$prefixes = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
+$scoHtml = '';
+$i = 1;
+$sel = ' selected';
+foreach($prefixes as $prefix) {
+ $scoHtml .= '';
+ $sel = '';
+}
+$tmpl->assign('serverConfigurationOptions', $scoHtml, false);
// assign default values
if(!isset($ldap)) {
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 6b95f8660eb..20297c02d39 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -13,7 +13,6 @@
?>
--
cgit v1.2.3
From 319dcd45e1cecb9de98d8bb24a3a71cb0eee6a8a Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 12:44:30 +0100
Subject: LDAP: Clear cache on saving settings
---
apps/user_ldap/lib/connection.php | 1 +
1 file changed, 1 insertion(+)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 61b84fb10a1..70311ba5c73 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -323,6 +323,7 @@ class Connection {
$this->setValue($trans[$key], $value);
}
+ $this->clearCache();
}
/**
--
cgit v1.2.3
From b084ed6a428470d44a98b70a5fc22341edb4165a Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 12:46:10 +0100
Subject: LDAP: clean up, save configuration is now handled by Ajax
---
apps/user_ldap/settings.php | 31 -------------------------------
1 file changed, 31 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index 57d370601cf..a6e8bd5512b 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -38,37 +38,6 @@ $params = array('ldap_host', 'ldap_port', 'ldap_backup_host',
OCP\Util::addscript('user_ldap', 'settings');
OCP\Util::addstyle('user_ldap', 'settings');
-if($_POST) {
- $clearCache = false;
- foreach($params as $param) {
- if(isset($_POST[$param])) {
- $clearCache = true;
- if('ldap_agent_password' == $param) {
- OCP\Config::setAppValue('user_ldap', $param, base64_encode($_POST[$param]));
- } elseif('home_folder_naming_rule' == $param) {
- $value = empty($_POST[$param]) ? 'opt:username' : 'attr:'.$_POST[$param];
- OCP\Config::setAppValue('user_ldap', $param, $value);
- } else {
- OCP\Config::setAppValue('user_ldap', $param, $_POST[$param]);
- }
- }
- elseif('ldap_tls' == $param) {
- // unchecked checkboxes are not included in the post paramters
- OCP\Config::setAppValue('user_ldap', $param, 0);
- }
- elseif('ldap_nocase' == $param) {
- OCP\Config::setAppValue('user_ldap', $param, 0);
- }
- elseif('ldap_turn_off_cert_check' == $param) {
- OCP\Config::setAppValue('user_ldap', $param, 0);
- }
- }
- if($clearCache) {
- $ldap = new \OCA\user_ldap\lib\Connection();
- $ldap->clearCache();
- }
-}
-
// fill template
$tmpl = new OCP\Template('user_ldap', 'settings');
foreach($params as $param) {
--
cgit v1.2.3
From b2ea78c00d203d7a70952dc7dab095cbeafb0b95 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 13:00:40 +0100
Subject: LDAP: improve and cleanup settings JS
---
apps/user_ldap/js/settings.js | 95 ++++++++++++++++++++++++-------------------
1 file changed, 53 insertions(+), 42 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 66876cadaf7..c3484da5ac6 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -1,6 +1,57 @@
+var LdapConfiguration = {
+ refreshConfig: function() {
+ $.post(
+ OC.filePath('user_ldap','ajax','getConfiguration.php'),
+ $('#ldap_serverconfig_chooser').serialize(),
+ function (result) {
+ if(result.status == 'success') {
+ $.each(result.configuration, function(configkey, configvalue) {
+ elementID = '#'+configkey;
+
+ //deal with Checkboxes
+ if($(elementID).is('input[type=checkbox]')) {
+ if(configvalue == 1) {
+ $(elementID).attr('checked', 'checked');
+ } else {
+ $(elementID).removeAttr('checked');
+ }
+ return;
+ }
+
+ //On Textareas, Multi-Line Settings come as array
+ if($(elementID).is('textarea') && $.isArray(configvalue)) {
+ configvalue = configvalue.join("\n");
+ }
+
+ // assign the value
+ $('#'+configkey).val(configvalue);
+ });
+ }
+ }
+ );
+ },
+
+ resetDefaults: function() {
+ $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() {
+ if($(this).attr('id') == 'ldap_serverconfig_chooser') {
+ return;
+ }
+ $(this).val($(this).attr('data-default'));
+ });
+ $('#ldap').find('input[type=checkbox]').each(function() {
+ if($(this).attr('data-default') == 1) {
+ $(this).attr('checked', 'checked');
+ } else {
+ $(this).removeAttr('checked');
+ }
+ });
+ }
+}
+
$(document).ready(function() {
$('#ldapSettings').tabs();
$('#ldap_action_test_connection').button();
+ LdapConfiguration.refreshConfig();
$('#ldap_action_test_connection').click(function(event){
event.preventDefault();
$.post(
@@ -48,19 +99,7 @@ $(document).ready(function() {
'Keep settings?',
function(keep) {
if(!keep) {
- $('#ldap').find('input[type=text], input[type=number], input[type=password], textarea, select').each(function() {
- if($(this).attr('id') == 'ldap_serverconfig_chooser') {
- return;
- }
- $(this).val($(this).attr('data-default'));
- });
- $('#ldap').find('input[type=checkbox]').each(function() {
- if($(this).attr('data-default') == 1) {
- $(this).attr('checked', 'checked');
- } else {
- $(this).removeAttr('checked');
- }
- });
+ LdapConfiguration.resetDefaults();
}
}
);
@@ -76,35 +115,7 @@ $(document).ready(function() {
}
);
} else {
- $.post(
- OC.filePath('user_ldap','ajax','getConfiguration.php'),
- $('#ldap_serverconfig_chooser').serialize(),
- function (result) {
- if(result.status == 'success') {
- $.each(result.configuration, function(configkey, configvalue) {
- elementID = '#'+configkey;
-
- //deal with Checkboxes
- if($(elementID).is('input[type=checkbox]')) {
- if(configvalue == 1) {
- $(elementID).attr('checked', 'checked');
- } else {
- $(elementID).removeAttr('checked');
- }
- return;
- }
-
- //On Textareas, Multi-Line Settings come as array
- if($(elementID).is('textarea') && $.isArray(configvalue)) {
- configvalue = configvalue.join("\n");
- }
-
- // assign the value
- $('#'+configkey).val(configvalue);
- });
- }
- }
- );
+ LdapConfiguration.refreshConfig();
}
});
});
\ No newline at end of file
--
cgit v1.2.3
From fccfdb2a52de89532cbf3417082455e14b7eaf8b Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 13:01:20 +0100
Subject: LPAP: cleanup settings.php, it's already ajaxified
---
apps/user_ldap/settings.php | 15 ---------------
1 file changed, 15 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index a6e8bd5512b..5b679683f27 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -40,21 +40,6 @@ OCP\Util::addstyle('user_ldap', 'settings');
// fill template
$tmpl = new OCP\Template('user_ldap', 'settings');
-foreach($params as $param) {
- $value = OCP\Config::getAppValue('user_ldap', $param, '');
- $tmpl->assign($param, $value);
-}
-
-// settings with default values
-$tmpl->assign('ldap_port', OCP\Config::getAppValue('user_ldap', 'ldap_port', '389'));
-$tmpl->assign('ldap_display_name', OCP\Config::getAppValue('user_ldap', 'ldap_display_name', 'uid'));
-$tmpl->assign('ldap_group_display_name', OCP\Config::getAppValue('user_ldap', 'ldap_group_display_name', 'cn'));
-$tmpl->assign('ldap_group_member_assoc_attribute', OCP\Config::getAppValue('user_ldap', 'ldap_group_member_assoc_attribute', 'uniqueMember'));
-$tmpl->assign('ldap_agent_password', base64_decode(OCP\Config::getAppValue('user_ldap', 'ldap_agent_password')));
-$tmpl->assign('ldap_cache_ttl', OCP\Config::getAppValue('user_ldap', 'ldap_cache_ttl', '600'));
-$hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username');
-$hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:'));
-$tmpl->assign('home_folder_naming_rule', $hfnr, '');
$prefixes = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
$scoHtml = '';
--
cgit v1.2.3
From 3bf38c7a8469d1a1eac579378fc6336db86d0218 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 13:01:43 +0100
Subject: LDAP: add missing new LDAP Helper
---
apps/user_ldap/lib/helper.php | 66 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 apps/user_ldap/lib/helper.php
(limited to 'apps')
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
new file mode 100644
index 00000000000..1751f57f503
--- /dev/null
+++ b/apps/user_ldap/lib/helper.php
@@ -0,0 +1,66 @@
+.
+ *
+ */
+
+namespace OCA\user_ldap\lib;
+
+class Helper {
+
+ /**
+ * @brief returns prefixes for each saved LDAP/AD server configuration.
+ * @return array with a list of the available prefixes
+ *
+ * Configuration prefixes are used to set up configurations for n LDAP or
+ * AD servers. Since configuration is stored in the database, table
+ * appconfig under appid user_ldap, the common identifiers in column
+ * 'configkey' have a prefix. The prefix for the very first server
+ * configuration is empty.
+ * Configkey Examples:
+ * Server 1: ldap_login_filtter
+ * Server 2: s1_ldap_login_filter
+ * Server 3: s2_ldap_login_filter
+ *
+ * The prefix needs to be passed to the constructor of Connection class,
+ * except the default (first) server shall be connected to.
+ *
+ */
+ static public function getServerConfigurationPrefixes() {
+ $referenceConfigkey = 'ldap_login_filter';
+
+ $query = \OCP\DB::prepare('
+ SELECT DISTINCT `configkey`
+ FROM `*PREFIX*appconfig`
+ WHERE `configkey` LIKE ?
+ ');
+
+ $serverConfigs = $query->execute(array('%'.$referenceConfigkey))->fetchAll();
+ $prefixes = array();
+
+ foreach($serverConfigs as $serverConfig) {
+ $len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey);
+ $prefixes[] = substr($serverConfig['configkey'], 0, $len);
+ }
+
+ return $prefixes;
+ }
+}
+
--
cgit v1.2.3
From 5b9e181198a61f5c123f5e8d5acec4c30cc8908a Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 14:11:53 +0100
Subject: LDAP: implement deleteConfiguration feature
---
apps/user_ldap/js/settings.js | 33 ++++++++++++++++++++++++
apps/user_ldap/lib/helper.php | 47 +++++++++++++++++++++++++++--------
apps/user_ldap/templates/settings.php | 4 ++-
3 files changed, 73 insertions(+), 11 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index c3484da5ac6..49bbc60d81c 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -45,12 +45,32 @@ var LdapConfiguration = {
$(this).removeAttr('checked');
}
});
+ },
+
+ deleteConfiguration: function() {
+ $.post(
+ OC.filePath('user_ldap','ajax','deleteConfiguration.php'),
+ $('#ldap_serverconfig_chooser').serialize(),
+ function (result) {
+ if(result.status == 'success') {
+ $('#ldap_serverconfig_chooser option:selected').remove();
+ $('#ldap_serverconfig_chooser option:first').select();
+ LdapConfiguration.refreshConfig();
+ } else {
+ OC.dialogs.alert(
+ result.message,
+ 'Deletion failed'
+ );
+ }
+ }
+ );
}
}
$(document).ready(function() {
$('#ldapSettings').tabs();
$('#ldap_action_test_connection').button();
+ $('#ldap_action_delete_configuration').button();
LdapConfiguration.refreshConfig();
$('#ldap_action_test_connection').click(function(event){
event.preventDefault();
@@ -73,6 +93,19 @@ $(document).ready(function() {
);
});
+ $('#ldap_action_delete_configuration').click(function(event) {
+ event.preventDefault();
+ OC.dialogs.confirm(
+ 'Do you really want to delete the current Server Configuration?',
+ 'Confirm Deletion',
+ function(deleteConfiguration) {
+ if(deleteConfiguration) {
+ LdapConfiguration.deleteConfiguration();
+ }
+ }
+ );
+ });
+
$('#ldap_submit').click(function(event) {
event.preventDefault();
$.post(
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 1751f57f503..5f6e2a1d037 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -24,13 +24,13 @@
namespace OCA\user_ldap\lib;
class Helper {
-
+
/**
* @brief returns prefixes for each saved LDAP/AD server configuration.
* @return array with a list of the available prefixes
- *
+ *
* Configuration prefixes are used to set up configurations for n LDAP or
- * AD servers. Since configuration is stored in the database, table
+ * AD servers. Since configuration is stored in the database, table
* appconfig under appid user_ldap, the common identifiers in column
* 'configkey' have a prefix. The prefix for the very first server
* configuration is empty.
@@ -38,29 +38,56 @@ class Helper {
* Server 1: ldap_login_filtter
* Server 2: s1_ldap_login_filter
* Server 3: s2_ldap_login_filter
- *
- * The prefix needs to be passed to the constructor of Connection class,
+ *
+ * The prefix needs to be passed to the constructor of Connection class,
* except the default (first) server shall be connected to.
- *
+ *
*/
static public function getServerConfigurationPrefixes() {
$referenceConfigkey = 'ldap_login_filter';
-
+
$query = \OCP\DB::prepare('
SELECT DISTINCT `configkey`
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
');
-
+
$serverConfigs = $query->execute(array('%'.$referenceConfigkey))->fetchAll();
$prefixes = array();
-
+
foreach($serverConfigs as $serverConfig) {
$len = strlen($serverConfig['configkey']) - strlen($referenceConfigkey);
$prefixes[] = substr($serverConfig['configkey'], 0, $len);
}
-
+
return $prefixes;
}
+
+ static public function deleteServerConfiguration($prefix) {
+ //just to be on the safe side
+ \OCP\User::checkAdminUser();
+
+ if(!in_array($prefix, self::getServerConfigurationPrefixes())) {
+ return false;
+ }
+
+ $query = \OCP\DB::prepare('
+ DELETE
+ FROM `*PREFIX*appconfig`
+ WHERE `configkey` LIKE ?
+ AND appid = "user_ldap"
+ ');
+ $res = $query->execute(array($prefix.'%'));
+
+ if(\OCP\DB::isError($res)) {
+ return false;
+ }
+
+ if($res->numRows() == 0) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 20297c02d39..513c59653e6 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -15,7 +15,9 @@
+
+
+
--
cgit v1.2.3
From 6bc72569666ac5fc8063a4b6233fb25a8ec94060 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 14:12:12 +0100
Subject: LDAP: forgotten file for deleteConfig feature
---
apps/user_ldap/ajax/deleteConfiguration.php | 34 +++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 apps/user_ldap/ajax/deleteConfiguration.php
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
new file mode 100644
index 00000000000..78f88dc942d
--- /dev/null
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -0,0 +1,34 @@
+.
+ *
+ */
+
+// Check user and app status
+OCP\JSON::checkAdminUser();
+OCP\JSON::checkAppEnabled('user_ldap');
+OCP\JSON::callCheck();
+
+$prefix = $_POST['ldap_serverconfig_chooser'];
+if(\OCA\user_ldap\lib\Helper::deleteServerConfiguration($prefix)){
+ OCP\JSON::success();
+} else {
+ OCP\JSON::error('Failed to delete the server configuration');
+}
\ No newline at end of file
--
cgit v1.2.3
From 2749a14171ee7ce32085cc2d0edbfcd5490d2ca3 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 22:39:05 +0100
Subject: LDAP: make it possible to enable/disable server configurations
---
apps/user_ldap/appinfo/app.php | 10 ++++++----
apps/user_ldap/appinfo/update.php | 14 +++++++++++---
apps/user_ldap/appinfo/version | 2 +-
apps/user_ldap/lib/connection.php | 25 +++++++++++++++++++++++--
apps/user_ldap/lib/helper.php | 14 ++++++++++----
apps/user_ldap/templates/settings.php | 1 +
6 files changed, 52 insertions(+), 14 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php
index 79cfab58796..dec87684c9e 100644
--- a/apps/user_ldap/appinfo/app.php
+++ b/apps/user_ldap/appinfo/app.php
@@ -23,7 +23,7 @@
OCP\App::registerAdmin('user_ldap', 'settings');
-$configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
+$configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes(true);
if(count($configPrefixes) == 1) {
$connector = new OCA\user_ldap\lib\Connection($configPrefixes[0]);
$userBackend = new OCA\user_ldap\USER_LDAP();
@@ -35,9 +35,11 @@ if(count($configPrefixes) == 1) {
$groupBackend = new OCA\user_ldap\Group_Proxy($configPrefixes);
}
-// register user backend
-OC_User::useBackend($userBackend);
-OC_Group::useBackend($groupBackend);
+if(count($configPrefixes) > 0) {
+ // register user backend
+ OC_User::useBackend($userBackend);
+ OC_Group::useBackend($groupBackend);
+}
// add settings page to navigation
$entry = array(
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php
index 9b54ba18b6c..11e19289918 100644
--- a/apps/user_ldap/appinfo/update.php
+++ b/apps/user_ldap/appinfo/update.php
@@ -22,12 +22,10 @@ if($state == 'unset') {
OCP\Config::setSystemValue('ldapIgnoreNamingRules', false);
}
-// ### SUPPORTED upgrade path starts here ###
-
//from version 0.2 to 0.3 (0.2.0.x dev version)
$objects = array('user', 'group');
-$connector = new \OCA\user_ldap\lib\Connection('user_ldap');
+$connector = new \OCA\user_ldap\lib\Connection();
$userBE = new \OCA\user_ldap\USER_LDAP();
$userBE->setConnector($connector);
$groupBE = new \OCA\user_ldap\GROUP_LDAP();
@@ -80,3 +78,13 @@ function escapeDN($dn) {
return $dn;
}
+
+
+// SUPPORTED UPGRADE FROM Version 0.3 (ownCloud 4.5) to 0.4 (ownCloud 5)
+
+if(!isset($connector)) {
+ $connector = new \OCA\user_ldap\lib\Connection();
+}
+//it is required, that connections do habe ldap_configuration_active setting stored in the database
+$connector->getConfiguration();
+$connector->saveConfiguration();
\ No newline at end of file
diff --git a/apps/user_ldap/appinfo/version b/apps/user_ldap/appinfo/version
index b1a5f4781d1..705e30728e0 100644
--- a/apps/user_ldap/appinfo/version
+++ b/apps/user_ldap/appinfo/version
@@ -1 +1 @@
-0.3.0.1
\ No newline at end of file
+0.3.9.0
\ No newline at end of file
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 70311ba5c73..124ebe7aab2 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -60,6 +60,7 @@ class Connection {
'ldapUuidAttribute' => null,
'ldapOverrideUuidAttribute' => null,
'ldapOverrideMainServer' => false,
+ 'ldapConfigurationActive' => false,
'homeFolderNamingRule' => null,
'hasPagedResultSupport' => false,
);
@@ -174,7 +175,8 @@ class Connection {
if(!$this->configured) {
$this->readConfiguration();
}
- if(!$this->config['ldapCacheTTL']) {
+ if(!$this->config['ldapCacheTTL']
+ || !$this->config['ldapConfigurationActive']) {
return null;
}
$key = $this->getCacheKey($key);
@@ -255,6 +257,8 @@ class Connection {
= $this->$v('ldap_override_uuid_attribute');
$this->config['homeFolderNamingRule']
= $this->$v('home_folder_naming_rule');
+ $this->config['ldapConfigurationActive']
+ = $this->$v('ldap_configuration_active');
$this->configured = $this->validateConfiguration();
}
@@ -263,7 +267,7 @@ class Connection {
private function getConfigTranslationArray() {
static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
- 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck');
+ 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck', 'ldap_configuration_active' => 'ldapConfigurationActive');
return $array;
}
@@ -310,6 +314,13 @@ class Connection {
case 'homeFolderNamingRule':
$value = empty($value) ? 'opt:username' : 'attr:'.$value;
break;
+ case 'ldapBase':
+ case 'ldapBaseUsers':
+ case 'ldapBaseGroups':
+ if(is_array($value)){
+ $value = implode("\n", $value);
+ }
+ break;
case 'ldapIgnoreNamingRules':
case 'ldapOverrideUuidAttribute':
case 'ldapUuidAttribute':
@@ -342,6 +353,9 @@ class Connection {
$config[$dbKey] = substr($this->config[$dbKey], 5);
}
continue;
+ } else if(strpos($classKey, 'ldapBase') !== false) {
+ $config[$dbKey] = implode("\n", $this->config[$classKey]);
+ continue;
}
$config[$dbKey] = $this->config[$classKey];
}
@@ -449,6 +463,7 @@ class Connection {
'ldap_override_uuid_attribute' => 0,
'home_folder_naming_rule' => 'opt:username',
'ldap_turn_off_cert_check' => 0,
+ 'ldap_configuration_active' => 1,
);
}
@@ -456,6 +471,9 @@ class Connection {
* Connects and Binds to LDAP
*/
private function establishConnection() {
+ if(!$this->config['ldapConfigurationActive']) {
+ return null;
+ }
static $phpLDAPinstalled = true;
if(!$phpLDAPinstalled) {
return false;
@@ -519,6 +537,9 @@ class Connection {
* Binds to LDAP
*/
public function bind() {
+ if(!$this->config['ldapConfigurationActive']) {
+ return false;
+ }
$ldapLogin = @ldap_bind($this->getConnectionResource(), $this->config['ldapAgentName'], $this->config['ldapAgentPassword']);
if(!$ldapLogin) {
\OCP\Util::writeLog('user_ldap', 'Bind failed: ' . ldap_errno($this->ldapConnectionRes) . ': ' . ldap_error($this->ldapConnectionRes), \OCP\Util::ERROR);
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 5f6e2a1d037..03a65a65b1c 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -27,6 +27,8 @@ class Helper {
/**
* @brief returns prefixes for each saved LDAP/AD server configuration.
+ * @param bool optional, whether only active configuration shall be
+ * retrieved, defaults to false
* @return array with a list of the available prefixes
*
* Configuration prefixes are used to set up configurations for n LDAP or
@@ -43,14 +45,18 @@ class Helper {
* except the default (first) server shall be connected to.
*
*/
- static public function getServerConfigurationPrefixes() {
- $referenceConfigkey = 'ldap_login_filter';
+ static public function getServerConfigurationPrefixes($activeConfigurations = false) {
+ $referenceConfigkey = 'ldap_configuration_active';
- $query = \OCP\DB::prepare('
+ $query = '
SELECT DISTINCT `configkey`
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
- ');
+ ';
+ if($activeConfigurations) {
+ $query .= ' AND `configvalue` = 1';
+ }
+ $query = \OCP\DB::prepare($query);
$serverConfigs = $query->execute(array('%'.$referenceConfigkey))->fetchAll();
$prefixes = array();
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 513c59653e6..e7b9e18dbe0 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -27,6 +27,7 @@
t('without any placeholder, e.g. "objectClass=posixGroup".');?>
+
data-default="" title="t('When unchecked, this configuration will be skipped.');?>" />
--
cgit v1.2.3
From 3e99f12120dde810e3976b270666751b52c98959 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 24 Jan 2013 22:47:25 +0100
Subject: LDAP: make settings strings in JS translatable
---
apps/user_ldap/js/settings.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 49bbc60d81c..7d0a85248f3 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -59,7 +59,7 @@ var LdapConfiguration = {
} else {
OC.dialogs.alert(
result.message,
- 'Deletion failed'
+ t('user_ldap', 'Deletion failed')
);
}
}
@@ -81,12 +81,12 @@ $(document).ready(function() {
if (result.status == 'success') {
OC.dialogs.alert(
result.message,
- 'Connection test succeeded'
+ t('user_ldap', 'Connection test succeeded')
);
} else {
OC.dialogs.alert(
result.message,
- 'Connection test failed'
+ t('user_ldap', 'Connection test failed')
);
}
}
@@ -96,8 +96,8 @@ $(document).ready(function() {
$('#ldap_action_delete_configuration').click(function(event) {
event.preventDefault();
OC.dialogs.confirm(
- 'Do you really want to delete the current Server Configuration?',
- 'Confirm Deletion',
+ t('user_ldap', 'Do you really want to delete the current Server Configuration?'),
+ t('user_ldap', 'Confirm Deletion'),
function(deleteConfiguration) {
if(deleteConfiguration) {
LdapConfiguration.deleteConfiguration();
@@ -128,8 +128,8 @@ $(document).ready(function() {
function (result) {
if(result.status == 'success') {
OC.dialogs.confirm(
- 'Take over settings from recent server configuration?',
- 'Keep settings?',
+ t('user_ldap', 'Take over settings from recent server configuration?'),
+ t('user_ldap', 'Keep settings?'),
function(keep) {
if(!keep) {
LdapConfiguration.resetDefaults();
@@ -142,7 +142,7 @@ $(document).ready(function() {
} else {
OC.dialogs.alert(
result.message,
- 'Cannot add server configuration'
+ t('user_ldap', 'Cannot add server configuration')
);
}
}
--
cgit v1.2.3
From a8ac4bdf79b65239c6aeef4e6d0d642bedefc9c3 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 02:30:24 +0100
Subject: LDAP: Always preset configuration prefix when no configuratin is
stored or all remaining ones are deleted
---
apps/user_ldap/js/settings.js | 60 ++++++++++++++++++++++++++-----------------
apps/user_ldap/settings.php | 3 +++
2 files changed, 39 insertions(+), 24 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index 7d0a85248f3..d1b1b715a57 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -1,5 +1,9 @@
var LdapConfiguration = {
refreshConfig: function() {
+ if($('#ldap_serverconfig_chooser option').length < 2) {
+ LdapConfiguration.addConfiguration(true);
+ return;
+ }
$.post(
OC.filePath('user_ldap','ajax','getConfiguration.php'),
$('#ldap_serverconfig_chooser').serialize(),
@@ -64,6 +68,37 @@ var LdapConfiguration = {
}
}
);
+ },
+
+ addConfiguration: function(doNotAsk) {
+ $.post(
+ OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'),
+ function (result) {
+ if(result.status == 'success') {
+ if(doNotAsk) {
+ LdapConfiguration.resetDefaults();
+ } else {
+ OC.dialogs.confirm(
+ t('user_ldap', 'Take over settings from recent server configuration?'),
+ t('user_ldap', 'Keep settings?'),
+ function(keep) {
+ if(!keep) {
+ LdapConfiguration.resetDefaults();
+ }
+ }
+ );
+ }
+ $('#ldap_serverconfig_chooser option:selected').removeAttr('selected');
+ var html = '';
+ $('#ldap_serverconfig_chooser option:last').before(html);
+ } else {
+ OC.dialogs.alert(
+ result.message,
+ t('user_ldap', 'Cannot add server configuration')
+ );
+ }
+ }
+ );
}
}
@@ -123,30 +158,7 @@ $(document).ready(function() {
$('#ldap_serverconfig_chooser').change(function(event) {
value = $('#ldap_serverconfig_chooser option:selected:first').attr('value');
if(value == 'NEW') {
- $.post(
- OC.filePath('user_ldap','ajax','getNewServerConfigPrefix.php'),
- function (result) {
- if(result.status == 'success') {
- OC.dialogs.confirm(
- t('user_ldap', 'Take over settings from recent server configuration?'),
- t('user_ldap', 'Keep settings?'),
- function(keep) {
- if(!keep) {
- LdapConfiguration.resetDefaults();
- }
- }
- );
- $('#ldap_serverconfig_chooser option:selected').removeAttr('selected');
- var html = '';
- $('#ldap_serverconfig_chooser option:last').before(html);
- } else {
- OC.dialogs.alert(
- result.message,
- t('user_ldap', 'Cannot add server configuration')
- );
- }
- }
- );
+ LdapConfiguration.addConfiguration(false);
} else {
LdapConfiguration.refreshConfig();
}
diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php
index 5b679683f27..d5d2f648b38 100644
--- a/apps/user_ldap/settings.php
+++ b/apps/user_ldap/settings.php
@@ -49,6 +49,9 @@ foreach($prefixes as $prefix) {
$scoHtml .= '';
$sel = '';
}
+if(count($prefixes) == 0) {
+ $scoHtml .= '';
+}
$tmpl->assign('serverConfigurationOptions', $scoHtml, false);
// assign default values
--
cgit v1.2.3
From 9f7d7802762000f9dd033f922c9ba2d3b0f3fa79 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 02:31:14 +0100
Subject: LDAP: use consolidated method for determining config prefix
---
apps/user_ldap/ajax/getNewServerConfigPrefix.php | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/getNewServerConfigPrefix.php b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
index 1a5f78cf214..17e78f87072 100644
--- a/apps/user_ldap/ajax/getNewServerConfigPrefix.php
+++ b/apps/user_ldap/ajax/getNewServerConfigPrefix.php
@@ -26,12 +26,7 @@ OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
-$query = \OCP\DB::prepare('
- SELECT DISTINCT `configkey`
- FROM `*PREFIX*appconfig`
- WHERE `configkey` LIKE ?
-');
-$serverConnections = $query->execute(array('%ldap_login_filter'))->fetchAll();
+$serverConnections = \OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes();
sort($serverConnections);
$lk = array_pop($serverConnections);
$ln = intval(str_replace('s', '', $lk));
--
cgit v1.2.3
From a5575220376afc5a2b47784368183983aec432ef Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 02:39:11 +0100
Subject: LDAP: send back error message properly
---
apps/user_ldap/ajax/deleteConfiguration.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
index 78f88dc942d..e91e75bbba3 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -30,5 +30,5 @@ $prefix = $_POST['ldap_serverconfig_chooser'];
if(\OCA\user_ldap\lib\Helper::deleteServerConfiguration($prefix)){
OCP\JSON::success();
} else {
- OCP\JSON::error('Failed to delete the server configuration');
+ OCP\JSON::error(array('message' => 'Failed to delete the server configuration'));
}
\ No newline at end of file
--
cgit v1.2.3
From 19867b1d0881d0ee427f889e2fb7ec72caf73090 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 02:39:44 +0100
Subject: LDAP: make sure app meta data is not deleted from database when
deleting configuration with empty prefix
---
apps/user_ldap/lib/helper.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 03a65a65b1c..263d95f898f 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -81,7 +81,8 @@ class Helper {
DELETE
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
- AND appid = "user_ldap"
+ AND `appid` = "user_ldap"
+ AND `configkey` NOT IN ("enabled", "installed_version", "types", "bgjUpdateGroupsLastRun")
');
$res = $query->execute(array($prefix.'%'));
--
cgit v1.2.3
From 14bc6f8c6c87bbb16529d2e52208ddab9c56fde6 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 03:34:51 +0100
Subject: LDAP: working visual feedback on save. Save button will be
highlighted green or red.
---
apps/user_ldap/js/settings.js | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index d1b1b715a57..166761bc1ff 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -104,6 +104,7 @@ var LdapConfiguration = {
$(document).ready(function() {
$('#ldapSettings').tabs();
+ $('#ldap_submit').button();
$('#ldap_action_test_connection').button();
$('#ldap_action_delete_configuration').button();
LdapConfiguration.refreshConfig();
@@ -147,9 +148,18 @@ $(document).ready(function() {
OC.filePath('user_ldap','ajax','setConfiguration.php'),
$('#ldap').serialize(),
function (result) {
+ bgcolor = $('#ldap_submit').css('background');
if (result.status == 'success') {
- $('#notification').text(t('user_ldap', 'LDAP Configuration Saved'));
- $('#notification').fadeIn();
+ //the dealing with colors is a but ugly, but the jQuery version in use has issues with rgba colors
+ $('#ldap_submit').css('background', '#fff');
+ $('#ldap_submit').effect('highlight', {'color':'#A8FA87'}, 5000, function() {
+ $('#ldap_submit').css('background', bgcolor);
+ });
+ } else {
+ $('#ldap_submit').css('background', '#fff');
+ $('#ldap_submit').effect('highlight', {'color':'#E97'}, 5000, function() {
+ $('#ldap_submit').css('background', bgcolor);
+ });
}
}
);
--
cgit v1.2.3
From e8db1e884e2792476de1ea2b33804c9665526b7d Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 03:44:11 +0100
Subject: LDAP: some inline documentation
---
apps/user_ldap/lib/connection.php | 7 +++++++
apps/user_ldap/lib/helper.php | 5 +++++
2 files changed, 12 insertions(+)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 124ebe7aab2..2d34013c9d8 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -264,6 +264,9 @@ class Connection {
}
}
+ /**
+ * @return returns an array that maps internal variable names to database fields
+ */
private function getConfigTranslationArray() {
static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
@@ -303,6 +306,10 @@ class Connection {
return $this->configured;
}
+ /**
+ * @brief saves the current Configuration in the database
+ingle parameters
+ */
public function saveConfiguration() {
$trans = array_flip($this->getConfigTranslationArray());
foreach($this->config as $key => $value) {
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 263d95f898f..3c4b98af1a4 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -69,6 +69,11 @@ class Helper {
return $prefixes;
}
+ /**
+ * @brief deletes a given saved LDAP/AD server configuration.
+ * @param string the configuration prefix of the config to delete
+ * @return bool true on success, false otherweise
+ */
static public function deleteServerConfiguration($prefix) {
//just to be on the safe side
\OCP\User::checkAdminUser();
--
cgit v1.2.3
From 8f388d9df4aad381ed8774971ea1e3ae1c9dcf33 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Wed, 30 Jan 2013 13:48:59 +0100
Subject: LDAP: update link to online documentation
---
apps/user_ldap/templates/settings.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index e7b9e18dbe0..ad8e58e1c2d 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -46,7 +46,7 @@
- t('Help');?>
+ t('Help');?>
--
cgit v1.2.3
From b3b0544e17b172da1ae3760fe5b4e4f90c20b47a Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 01:46:34 +0100
Subject: LDAP: make it possible to define attributes that should be considered
on searches
---
apps/user_ldap/group_ldap.php | 10 ++++-----
apps/user_ldap/lib/access.php | 44 +++++++++++++++++++++++++++++++++++++++
apps/user_ldap/lib/connection.php | 23 ++++++++++++++++++--
apps/user_ldap/user_ldap.php | 3 +--
4 files changed, 70 insertions(+), 10 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php
index 63437310088..02ceecaea0b 100644
--- a/apps/user_ldap/group_ldap.php
+++ b/apps/user_ldap/group_ldap.php
@@ -171,7 +171,6 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
return array();
}
- $search = empty($search) ? '*' : '*'.$search.'*';
$groupUsers = array();
$isMemberUid = (strtolower($this->connection->ldapGroupMemberAssocAttr) == 'memberuid');
foreach($members as $member) {
@@ -179,7 +178,7 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
//we got uids, need to get their DNs to 'tranlsate' them to usernames
$filter = $this->combineFilterWithAnd(array(
\OCP\Util::mb_str_replace('%uid', $member, $this->connection>ldapLoginFilter, 'UTF-8'),
- $this->connection->ldapUserDisplayName.'='.$search
+ $this->getFilterPartForUserSearch($search)
));
$ldap_users = $this->fetchListOfUsers($filter, 'dn');
if(count($ldap_users) < 1) {
@@ -188,8 +187,8 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
$groupUsers[] = $this->dn2username($ldap_users[0]);
} else {
//we got DNs, check if we need to filter by search or we can give back all of them
- if($search != '*') {
- if(!$this->readAttribute($member, $this->connection->ldapUserDisplayName, $this->connection->ldapUserDisplayName.'='.$search)) {
+ if(!empty($search)) {
+ if(!$this->readAttribute($member, $this->connection->ldapUserDisplayName, $this->getFilterPartForUserSearch($search))) {
continue;
}
}
@@ -230,10 +229,9 @@ class GROUP_LDAP extends lib\Access implements \OCP\GroupInterface {
if($limit <= 0) {
$limit = null;
}
- $search = empty($search) ? '*' : '*'.$search.'*';
$filter = $this->combineFilterWithAnd(array(
$this->connection->ldapGroupFilter,
- $this->connection->ldapGroupDisplayName.'='.$search
+ $this->getFilterPartForGroupSearch($search)
));
\OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG);
$ldap_groups = $this->fetchListOfGroups($filter, array($this->connection->ldapGroupDisplayName, 'dn'), $limit, $offset);
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 27c74446976..68cbe4a5e75 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -719,6 +719,50 @@ abstract class Access {
return $combinedFilter;
}
+ /**
+ * @brief creates a filter part for to perfrom search for users
+ * @param string $search the search term
+ * @return string the final filter part to use in LDAP searches
+ */
+ public function getFilterPartForUserSearch($search) {
+ return $this->getFilterPartForSearch($search, $this->connection->ldapAttributesForUserSearch, $this->connection->ldapUserDisplayName);
+ }
+
+ /**
+ * @brief creates a filter part for to perfrom search for groups
+ * @param string $search the search term
+ * @return string the final filter part to use in LDAP searches
+ */
+ public function getFilterPartForGroupSearch($search) {
+ return $this->getFilterPartForSearch($search, $this->connection->ldapAttributesForGroupSearch, $this->connection->ldapGroupDisplayName);
+ }
+
+ /**
+ * @brief creates a filter part for searches
+ * @param string $search the search term
+ * @param string $fallbackAttribute a fallback attribute in case the user
+ * did not define search attributes. Typically the display name attribute.
+ * @returns string the final filter part to use in LDAP searches
+ */
+ private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
+ $filter = array();
+ $search = empty($search) ? '*' : '*'.$search.'*';
+ if(!is_array($searchAttributes) || count($searchAttributes) == 0) {
+ if(empty($fallbackAttribute)) {
+ return '';
+ }
+ $filter[] = $fallbackAttribute . '=' . $search;
+ } else {
+ foreach($searchAttributes as $attribute) {
+ $filter[] = $attribute . '=' . $search;
+ }
+ }
+ if(count($filter) == 1) {
+ return '('.$filter[0].')';
+ }
+ return $this->combineFilterWithOr($filter);
+ }
+
public function areCredentialsValid($name, $password) {
$name = $this->DNasBaseParameter($name);
$testConnection = clone $this->connection;
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 2d34013c9d8..9044b395d4e 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -61,6 +61,8 @@ class Connection {
'ldapOverrideUuidAttribute' => null,
'ldapOverrideMainServer' => false,
'ldapConfigurationActive' => false,
+ 'ldapAttributesForUserSearch' => null,
+ 'ldapAttributesForGroupSearch' => null,
'homeFolderNamingRule' => null,
'hasPagedResultSupport' => false,
);
@@ -259,6 +261,10 @@ class Connection {
= $this->$v('home_folder_naming_rule');
$this->config['ldapConfigurationActive']
= $this->$v('ldap_configuration_active');
+ $this->config['ldapAttributesForUserSearch']
+ = preg_split('/\r\n|\r|\n/', $this->$v('ldap_attributes_for_user_search'));
+ $this->config['ldapAttributesForGroupSearch']
+ = preg_split('/\r\n|\r|\n/', $this->$v('ldap_attributes_for_group_search'));
$this->configured = $this->validateConfiguration();
}
@@ -270,7 +276,7 @@ class Connection {
private function getConfigTranslationArray() {
static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName',
- 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck', 'ldap_configuration_active' => 'ldapConfigurationActive');
+ 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck', 'ldap_configuration_active' => 'ldapConfigurationActive', 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch');
return $array;
}
@@ -324,6 +330,8 @@ ingle parameters
case 'ldapBase':
case 'ldapBaseUsers':
case 'ldapBaseGroups':
+ case 'ldapAttributesForUserSearch':
+ case 'ldapAttributesForGroupSearch':
if(is_array($value)){
$value = implode("\n", $value);
}
@@ -360,7 +368,8 @@ ingle parameters
$config[$dbKey] = substr($this->config[$dbKey], 5);
}
continue;
- } else if(strpos($classKey, 'ldapBase') !== false) {
+ } else if((strpos($classKey, 'ldapBase') !== false)
+ || (strpos($classKey, 'ldapAttributes') !== false)) {
$config[$dbKey] = implode("\n", $this->config[$classKey]);
continue;
}
@@ -395,6 +404,14 @@ ingle parameters
//force default
$this->config['ldapBackupPort'] = $this->config['ldapPort'];
}
+ foreach(array('ldapAttributesForUserSearch', 'ldapAttributesForGroupSearch') as $key) {
+ if(is_array($this->config[$key])
+ && count($this->config[$key]) == 1
+ && empty($this->config[$key][0])) {
+ $this->config[$key] = array();
+ }
+ }
+
//second step: critical checks. If left empty or filled wrong, set as unconfigured and give a warning.
@@ -471,6 +488,8 @@ ingle parameters
'home_folder_naming_rule' => 'opt:username',
'ldap_turn_off_cert_check' => 0,
'ldap_configuration_active' => 1,
+ 'ldap_attributes_for_user_search' => '',
+ 'ldap_attributes_for_group_search' => '',
);
}
diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php
index 6591d1d5fee..cb11ae39099 100644
--- a/apps/user_ldap/user_ldap.php
+++ b/apps/user_ldap/user_ldap.php
@@ -116,10 +116,9 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface {
if($limit <= 0) {
$limit = null;
}
- $search = empty($search) ? '*' : '*'.$search.'*';
$filter = $this->combineFilterWithAnd(array(
$this->connection->ldapUserFilter,
- $this->connection->ldapUserDisplayName.'='.$search
+ $this->getFilterPartForUserSearch($search)
));
\OCP\Util::writeLog('user_ldap', 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, \OCP\Util::DEBUG);
--
cgit v1.2.3
From b5ed8b2751408fd6ce02046aef294d267cd15021 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 01:46:54 +0100
Subject: LDAP: fix wrong index
---
apps/user_ldap/lib/connection.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 9044b395d4e..c5af73857a0 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -365,7 +365,7 @@ ingle parameters
if(strpos($this->config[$classKey], 'opt') === 0) {
$config[$dbKey] = '';
} else {
- $config[$dbKey] = substr($this->config[$dbKey], 5);
+ $config[$dbKey] = substr($this->config[$classKey], 5);
}
continue;
} else if((strpos($classKey, 'ldapBase') !== false)
--
cgit v1.2.3
From 0b98dc30b286bb9960fc1e47d4363e7973b01cd0 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 01:56:16 +0100
Subject: LDAP: remove unnecessary placeholders, fixes PHP warnings
---
apps/user_ldap/templates/settings.php | 46 +++++++++++++++++------------------
1 file changed, 23 insertions(+), 23 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index ad8e58e1c2d..af983039d6e 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -18,33 +18,33 @@
-
-
-
-
-
t('use %%uid placeholder, e.g. "uid=%%uid"');?>
-
t('without any placeholder, e.g. "objectClass=person".');?>
-
t('without any placeholder, e.g. "objectClass=posixGroup".');?>
+
+
+
+
+
t('use %%uid placeholder, e.g. "uid=%%uid"');?>
+
t('without any placeholder, e.g. "objectClass=person".');?>
+
t('without any placeholder, e.g. "objectClass=posixGroup".');?>
-
data-default="" title="t('When unchecked, this configuration will be skipped.');?>" />
-
-
-
-
data-default="" title="t('When switched on, ownCloud will only connect to the replica server.');?>" />
-
-
+
+
+
+
+
+
+
-
data-default="" title="t('Do not use it for SSL connections, it will fail.');?>" />
+
>
-
> t('Not recommended, use for testing only.');?>
-
-
-
-
-
-
-
+
t('Not recommended, use for testing only.');?>
+
+
+
+
+
+
+
t('Help');?>
--
cgit v1.2.3
From 1a854454d67f39794b24cc00bfbaadf8a921b7a0 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 02:00:29 +0100
Subject: LDAP: avoid attempts to save null as configvalue
---
apps/user_ldap/lib/connection.php | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index c5af73857a0..8ddc106d0b9 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -341,10 +341,9 @@ ingle parameters
case 'ldapUuidAttribute':
case 'hasPagedResultSupport':
continue 2;
- default:
- if(is_null($value)) {
- $value = 0;
- }
+ }
+ if(is_null($value)) {
+ $value = '';
}
$this->setValue($trans[$key], $value);
--
cgit v1.2.3
From 2f11d7fe126dcf0615cbb4c2d04b5c2f51813104 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 02:10:13 +0100
Subject: LDAP: adjust settings interface for custom search attributes
---
apps/user_ldap/templates/settings.php | 2 ++
1 file changed, 2 insertions(+)
(limited to 'apps')
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index af983039d6e..e6fa91cc85f 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -33,7 +33,9 @@
+
+
>
--
cgit v1.2.3
From a17a7f5cdbd6db27207e066d6e6baa147ba717aa Mon Sep 17 00:00:00 2001
From: Thomas Mueller
Date: Thu, 31 Jan 2013 17:43:24 +0100
Subject: adding l10n support to user_ldap
---
apps/user_ldap/ajax/deleteConfiguration.php | 3 ++-
apps/user_ldap/ajax/testConfiguration.php | 8 +++++---
2 files changed, 7 insertions(+), 4 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/ajax/deleteConfiguration.php b/apps/user_ldap/ajax/deleteConfiguration.php
index e91e75bbba3..b7d633a049d 100644
--- a/apps/user_ldap/ajax/deleteConfiguration.php
+++ b/apps/user_ldap/ajax/deleteConfiguration.php
@@ -30,5 +30,6 @@ $prefix = $_POST['ldap_serverconfig_chooser'];
if(\OCA\user_ldap\lib\Helper::deleteServerConfiguration($prefix)){
OCP\JSON::success();
} else {
- OCP\JSON::error(array('message' => 'Failed to delete the server configuration'));
+ $l=OC_L10N::get('user_ldap');
+ OCP\JSON::error(array('message' => $l->t('Failed to delete the server configuration')));
}
\ No newline at end of file
diff --git a/apps/user_ldap/ajax/testConfiguration.php b/apps/user_ldap/ajax/testConfiguration.php
index fd72485268f..f8038e31469 100644
--- a/apps/user_ldap/ajax/testConfiguration.php
+++ b/apps/user_ldap/ajax/testConfiguration.php
@@ -26,14 +26,16 @@ OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
+$l=OC_L10N::get('user_ldap');
+
$connection = new \OCA\user_ldap\lib\Connection('', null);
if($connection->setConfiguration($_POST)) {
//Configuration is okay
if($connection->bind()) {
- OCP\JSON::success(array('message' => 'The configuration is valid and the connection could be established!'));
+ OCP\JSON::success(array('message' => $l->t('The configuration is valid and the connection could be established!')));
} else {
- OCP\JSON::error(array('message' => 'The configuration is valid, but the Bind failed. Please check the server settings and credentials.'));
+ OCP\JSON::error(array('message' => $l->t('The configuration is valid, but the Bind failed. Please check the server settings and credentials.')));
}
} else {
- OCP\JSON::error(array('message' => 'The configuration is invalid. Please look in the ownCloud log for further details.'));
+ OCP\JSON::error(array('message' => $l->t('The configuration is invalid. Please look in the ownCloud log for further details.')));
}
--
cgit v1.2.3
From 7f2d7cdbe1b822721ecb3b696937835f36564f39 Mon Sep 17 00:00:00 2001
From: Thomas Mueller
Date: Thu, 31 Jan 2013 17:44:25 +0100
Subject: spell check
---
apps/user_ldap/appinfo/update.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php
index 11e19289918..f9681e38e68 100644
--- a/apps/user_ldap/appinfo/update.php
+++ b/apps/user_ldap/appinfo/update.php
@@ -5,7 +5,7 @@
//ATTENTION
//Upgrade from ownCloud 3 (LDAP backend 0.1) to ownCloud 4.5 (LDAP backend 0.3) is not supported!!
//You must do upgrade to ownCloud 4.0 first!
-//The upgrade stuff in the section from 0.1 to 0.2 is just to minimize the bad efffects.
+//The upgrade stuff in the section from 0.1 to 0.2 is just to minimize the bad effects.
//settings
$pw = OCP\Config::getAppValue('user_ldap', 'ldap_password');
@@ -85,6 +85,6 @@ function escapeDN($dn) {
if(!isset($connector)) {
$connector = new \OCA\user_ldap\lib\Connection();
}
-//it is required, that connections do habe ldap_configuration_active setting stored in the database
+//it is required, that connections do have ldap_configuration_active setting stored in the database
$connector->getConfiguration();
$connector->saveConfiguration();
\ No newline at end of file
--
cgit v1.2.3
From 5862f3d140357bd2da91f0034dab0eeb2ae4a1a0 Mon Sep 17 00:00:00 2001
From: Thomas Mueller
Date: Thu, 31 Jan 2013 17:51:59 +0100
Subject: spell check
---
apps/user_ldap/lib/connection.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 8ddc106d0b9..7a9732b2ce5 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -97,7 +97,7 @@ class Connection {
public function __set($name, $value) {
$changed = false;
- //omly few options are writable
+ //only few options are writable
if($name == 'ldapUuidAttribute') {
\OCP\Util::writeLog('user_ldap', 'Set config ldapUuidAttribute to '.$value, \OCP\Util::DEBUG);
$this->config[$name] = $value;
@@ -455,8 +455,8 @@ ingle parameters
}
/**
- * @returns an associted array with the default values. Keys are correspond
- * to configvalue entries in the database table
+ * @returns an associative array with the default values. Keys are correspond
+ * to config-value entries in the database table
*/
public function getDefaults() {
return array(
--
cgit v1.2.3
From 19714151e218114cbff8439186adb94155344490 Mon Sep 17 00:00:00 2001
From: Thomas Mueller
Date: Thu, 31 Jan 2013 17:53:01 +0100
Subject: spell check
---
apps/user_ldap/lib/helper.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/helper.php b/apps/user_ldap/lib/helper.php
index 3c4b98af1a4..29ce998dae7 100644
--- a/apps/user_ldap/lib/helper.php
+++ b/apps/user_ldap/lib/helper.php
@@ -37,7 +37,7 @@ class Helper {
* 'configkey' have a prefix. The prefix for the very first server
* configuration is empty.
* Configkey Examples:
- * Server 1: ldap_login_filtter
+ * Server 1: ldap_login_filter
* Server 2: s1_ldap_login_filter
* Server 3: s2_ldap_login_filter
*
@@ -72,7 +72,7 @@ class Helper {
/**
* @brief deletes a given saved LDAP/AD server configuration.
* @param string the configuration prefix of the config to delete
- * @return bool true on success, false otherweise
+ * @return bool true on success, false otherwise
*/
static public function deleteServerConfiguration($prefix) {
//just to be on the safe side
--
cgit v1.2.3
From afacaf8bc2b4c0aca0130b961df2f0e12408e5bc Mon Sep 17 00:00:00 2001
From: Arthur Schiwon
Date: Thu, 31 Jan 2013 18:00:07 +0100
Subject: string fragment was added by accident and does not belong here
---
apps/user_ldap/lib/connection.php | 1 -
1 file changed, 1 deletion(-)
(limited to 'apps')
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 7a9732b2ce5..acc33e047c6 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -314,7 +314,6 @@ class Connection {
/**
* @brief saves the current Configuration in the database
-ingle parameters
*/
public function saveConfiguration() {
$trans = array_flip($this->getConfigTranslationArray());
--
cgit v1.2.3