mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
[ldap-contacts-suggestions] Use LDAP URI for connecting
ldap_connect(<host>, <port>) is deprecated and ldap_connect(<uri>) is more expressive (for example, by allowing the use of SSL to be mandatory using a ldaps:// URL).
This commit is contained in:
parent
1841688b5f
commit
8e9cef4f78
2 changed files with 11 additions and 21 deletions
|
|
@ -5,12 +5,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $sHostName = '127.0.0.1';
|
private $sLdapUri = 'ldap://127.0.0.1:389';
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $iHostPort = 389;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var bool
|
||||||
|
|
@ -63,8 +58,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
||||||
private $sAllowedEmails = '';
|
private $sAllowedEmails = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sHostName
|
* @param string $sLdapUri
|
||||||
* @param int $iHostPort
|
|
||||||
* @param bool $bUseStartTLS
|
* @param bool $bUseStartTLS
|
||||||
* @param string $sBindDn
|
* @param string $sBindDn
|
||||||
* @param string $sBindPassword
|
* @param string $sBindPassword
|
||||||
|
|
@ -76,10 +70,9 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
||||||
*
|
*
|
||||||
* @return \LdapContactsSuggestions
|
* @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->sLdapUri = $sLdapUri;
|
||||||
$this->iHostPort = $iHostPort;
|
|
||||||
$this->bUseStartTLS = $bUseStartTLS;
|
$this->bUseStartTLS = $bUseStartTLS;
|
||||||
if (0 < \strlen($sBindDn))
|
if (0 < \strlen($sBindDn))
|
||||||
{
|
{
|
||||||
|
|
@ -193,7 +186,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
|
||||||
$sSearchEscaped = $this->escape($sQuery);
|
$sSearchEscaped = $this->escape($sQuery);
|
||||||
|
|
||||||
$aResult = array();
|
$aResult = array();
|
||||||
$oCon = @\ldap_connect($this->sHostName, $this->iHostPort);
|
$oCon = @\ldap_connect($this->sLdapUri);
|
||||||
if ($oCon)
|
if ($oCon)
|
||||||
{
|
{
|
||||||
$this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
|
$this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,7 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$mResult = array();
|
$mResult = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$sHostName = \trim($this->Config()->Get('plugin', 'hostname', ''));
|
$sLdapUri = \trim($this->Config()->Get('plugin', 'ldap_uri', ''));
|
||||||
$iHostPort = (int) $this->Config()->Get('plugin', 'port', 389);
|
|
||||||
$bUseStartTLS = (bool) $this->Config()->Get('plugin', 'use_start_tls', True);
|
$bUseStartTLS = (bool) $this->Config()->Get('plugin', 'use_start_tls', True);
|
||||||
$sBindDn = \trim($this->Config()->Get('plugin', 'bind_dn', ''));
|
$sBindDn = \trim($this->Config()->Get('plugin', 'bind_dn', ''));
|
||||||
$sBindPassword = \trim($this->Config()->Get('plugin', 'bind_password', ''));
|
$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', ''));
|
$sEmailField = \trim($this->Config()->Get('plugin', 'mail_field', ''));
|
||||||
$sAllowedEmails = \trim($this->Config()->Get('plugin', 'allowed_emails', ''));
|
$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';
|
include_once __DIR__.'/LdapContactsSuggestions.php';
|
||||||
|
|
||||||
$oProvider = new LdapContactsSuggestions();
|
$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;
|
$mResult[] = $oProvider;
|
||||||
}
|
}
|
||||||
|
|
@ -73,11 +72,9 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
protected function configMapping() : array
|
protected function configMapping() : array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
\RainLoop\Plugins\Property::NewInstance('hostname')->SetLabel('LDAP hostname')
|
\RainLoop\Plugins\Property::NewInstance('ldap_uri')->SetLabel('LDAP URI')
|
||||||
->SetDefaultValue('127.0.0.1'),
|
->SetDescription('LDAP server URI(s), space separated')
|
||||||
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('LDAP port')
|
->SetDefaultValue('ldap://127.0.0.1:389'),
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
|
||||||
->SetDefaultValue(389),
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('use_start_tls')->SetLabel('Use StartTLS')
|
\RainLoop\Plugins\Property::NewInstance('use_start_tls')->SetLabel('Use StartTLS')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(True),
|
->SetDefaultValue(True),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue