diff --git a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php index f30973227..288122fde 100644 --- a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php +++ b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php @@ -5,12 +5,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges /** * @var string */ - private $sHostName = '127.0.0.1'; - - /** - * @var int - */ - private $iHostPort = 389; + private $sLdapUri = 'ldap://127.0.0.1:389'; /** * @var bool @@ -63,8 +58,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges private $sAllowedEmails = ''; /** - * @param string $sHostName - * @param int $iHostPort + * @param string $sLdapUri * @param bool $bUseStartTLS * @param string $sBindDn * @param string $sBindPassword @@ -76,10 +70,9 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges * * @return \LdapContactsSuggestions */ - public function SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails) + public function SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails) { - $this->sHostName = $sHostName; - $this->iHostPort = $iHostPort; + $this->sLdapUri = $sLdapUri; $this->bUseStartTLS = $bUseStartTLS; if (0 < \strlen($sBindDn)) { @@ -193,7 +186,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges $sSearchEscaped = $this->escape($sQuery); $aResult = array(); - $oCon = @\ldap_connect($this->sHostName, $this->iHostPort); + $oCon = @\ldap_connect($this->sLdapUri); if ($oCon) { $this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP'); diff --git a/plugins/ldap-contacts-suggestions/index.php b/plugins/ldap-contacts-suggestions/index.php index 8efa7e498..217d2971f 100644 --- a/plugins/ldap-contacts-suggestions/index.php +++ b/plugins/ldap-contacts-suggestions/index.php @@ -41,8 +41,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin $mResult = array(); } - $sHostName = \trim($this->Config()->Get('plugin', 'hostname', '')); - $iHostPort = (int) $this->Config()->Get('plugin', 'port', 389); + $sLdapUri = \trim($this->Config()->Get('plugin', 'ldap_uri', '')); $bUseStartTLS = (bool) $this->Config()->Get('plugin', 'use_start_tls', True); $sBindDn = \trim($this->Config()->Get('plugin', 'bind_dn', '')); $sBindPassword = \trim($this->Config()->Get('plugin', 'bind_password', '')); @@ -53,12 +52,12 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin $sEmailField = \trim($this->Config()->Get('plugin', 'mail_field', '')); $sAllowedEmails = \trim($this->Config()->Get('plugin', 'allowed_emails', '')); - if (0 < \strlen($sBaseDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField)) + if (0 < \strlen($sLdapUri) && 0 < \strlen($sBaseDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField)) { include_once __DIR__.'/LdapContactsSuggestions.php'; $oProvider = new LdapContactsSuggestions(); - $oProvider->SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails); + $oProvider->SetConfig($sLdapUri, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails); $mResult[] = $oProvider; } @@ -73,11 +72,9 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin protected function configMapping() : array { return array( - \RainLoop\Plugins\Property::NewInstance('hostname')->SetLabel('LDAP hostname') - ->SetDefaultValue('127.0.0.1'), - \RainLoop\Plugins\Property::NewInstance('port')->SetLabel('LDAP port') - ->SetType(\RainLoop\Enumerations\PluginPropertyType::INT) - ->SetDefaultValue(389), + \RainLoop\Plugins\Property::NewInstance('ldap_uri')->SetLabel('LDAP URI') + ->SetDescription('LDAP server URI(s), space separated') + ->SetDefaultValue('ldap://127.0.0.1:389'), \RainLoop\Plugins\Property::NewInstance('use_start_tls')->SetLabel('Use StartTLS') ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetDefaultValue(True),