From bd16fa49d9f1ad4761fe078f41d915ad1e41949d Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 5 Oct 2017 16:28:32 -0300 Subject: [PATCH] Fix: Missing LDAP reconnect setting --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 ++ packages/rocketchat-ldap/server/ldap.js | 14 +++----------- packages/rocketchat-ldap/server/settings.js | 1 + packages/rocketchat-ldap/server/sync.js | 15 +++++++++------ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 28d6c77be58a..5d1824191a0c 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1028,6 +1028,8 @@ "LDAP_Merge_Existing_Users_Description": "*Caution!* When importing an user from LDAP and an user with same username already exists the LDAP info and password will be set into the existing user.", "LDAP_Port": "Port", "LDAP_Port_Description": "Port to access LDAP. eg: `389` or `636` for LDAPS", + "LDAP_Reconnect": "Reconnect", + "LDAP_Reconnect_Description": "Try to reconnect automatically when connection is interrupted by some reason while executing operations", "LDAP_Reject_Unauthorized": "Reject Unauthorized", "LDAP_Reject_Unauthorized_Description": "Disable this option to allow certificates that can not be verified. Usually Self Signed Certificates will require this option disabled to work", "LDAP_Sync_User_Avatar": "Sync User Avatar", diff --git a/packages/rocketchat-ldap/server/ldap.js b/packages/rocketchat-ldap/server/ldap.js index 0311151979ce..48f64f485919 100644 --- a/packages/rocketchat-ldap/server/ldap.js +++ b/packages/rocketchat-ldap/server/ldap.js @@ -20,6 +20,7 @@ export default class LDAP { this.options = { host: RocketChat.settings.get('LDAP_Host'), port: RocketChat.settings.get('LDAP_Port'), + Reconnect: RocketChat.settings.get('LDAP_Reconnect'), timeout: RocketChat.settings.get('LDAP_Timeout'), connect_timeout: RocketChat.settings.get('LDAP_Connect_Timeout'), idle_timeout: RocketChat.settings.get('LDAP_Idle_Timeout'), @@ -68,7 +69,7 @@ export default class LDAP { timeout: this.options.timeout, connectTimeout: this.options.connect_timeout, idleTimeout: this.options.idle_timeout, - reconnect: true + reconnect: this.options.Reconnect }; const tlsOptions = { @@ -363,22 +364,13 @@ export default class LDAP { logger.search.debug('Page'); // Force LDAP idle to wait the record processing this.client._updateIdle(true); - page(null, entries, {end: false, next: () => { + page(null, entries, {end: !next, next: () => { // Reset idle timer this.client._updateIdle(); next && next(); }}); entries = []; }); - - res.on('end', () => { - logger.search.info('Search result count', entries.length); - page(null, [], {end: true, next: () => { - // Reset idle timer - this.client._updateIdle(); - }}); - // logger.search.debug('Search result', JSON.stringify(jsonEntries, null, 2)); - }); }); } diff --git a/packages/rocketchat-ldap/server/settings.js b/packages/rocketchat-ldap/server/settings.js index 054c6fdda56d..a1d0d1091122 100644 --- a/packages/rocketchat-ldap/server/settings.js +++ b/packages/rocketchat-ldap/server/settings.js @@ -25,6 +25,7 @@ RocketChat.settings.addGroup('LDAP', function() { this.add('LDAP_Login_Fallback', true, { type: 'boolean', enableQuery }); this.add('LDAP_Host', '', { type: 'string', enableQuery }); this.add('LDAP_Port', '389', { type: 'string', enableQuery }); + this.add('LDAP_Reconnect', false, { type: 'boolean', enableQuery }); this.add('LDAP_Encryption', 'plain', { type: 'select', values: [ { key: 'plain', i18nLabel: 'No_Encryption' }, { key: 'tls', i18nLabel: 'StartTLS' }, { key: 'ssl', i18nLabel: 'SSL/LDAPS' } ], enableQuery }); this.add('LDAP_CA_Cert', '', { type: 'string', multiline: true, enableQuery: enableTLSQuery }); this.add('LDAP_Reject_Unauthorized', true, { type: 'boolean', enableQuery: enableTLSQuery }); diff --git a/packages/rocketchat-ldap/server/sync.js b/packages/rocketchat-ldap/server/sync.js index 7041725558ae..3741ab803370 100644 --- a/packages/rocketchat-ldap/server/sync.js +++ b/packages/rocketchat-ldap/server/sync.js @@ -235,7 +235,7 @@ export function importNewUsers(ldap) { } let count = 0; - ldap.searchUsersSync('*', Meteor.bindEnvironment((error, ldapUsers, {next} = {}) => { + ldap.searchUsersSync('*', Meteor.bindEnvironment((error, ldapUsers, {next, end} = {}) => { if (error) { throw error; } @@ -275,14 +275,17 @@ export function importNewUsers(ldap) { } } - if (count % 1000 === 0) { - logger.info('Imported:', count); + if (count % 100 === 0) { + logger.info('Import running. Users imported until now:', count); } }); - next && next(); - })); - logger.info('Imported:', count); + if (end) { + logger.info('Import finished. Users imported:', count); + } + + next(count); + })); } function sync() {