[ldap-contacts-suggestions] Rename some variables

Rename some variables to use common LDAP terminology and to make their
purpose clearer.
This commit is contained in:
David Härdeman 2021-08-22 12:01:43 +02:00
parent a53d7383db
commit 1841688b5f
2 changed files with 24 additions and 24 deletions

View file

@ -20,17 +20,17 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
/** /**
* @var string * @var string
*/ */
private $sAccessDn = null; private $sBindDn = null;
/** /**
* @var string * @var string
*/ */
private $sAccessPassword = null; private $sBindPassword = null;
/** /**
* @var string * @var string
*/ */
private $sUsersDn = ''; private $sBaseDn = '';
/** /**
* @var string * @var string
@ -66,9 +66,9 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
* @param string $sHostName * @param string $sHostName
* @param int $iHostPort * @param int $iHostPort
* @param bool $bUseStartTLS * @param bool $bUseStartTLS
* @param string $sAccessDn * @param string $sBindDn
* @param string $sAccessPassword * @param string $sBindPassword
* @param string $sUsersDn * @param string $sBaseDn
* @param string $sObjectClass * @param string $sObjectClass
* @param string $sNameField * @param string $sNameField
* @param string $sEmailField * @param string $sEmailField
@ -76,17 +76,17 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
* *
* @return \LdapContactsSuggestions * @return \LdapContactsSuggestions
*/ */
public function SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sAccessDn, $sAccessPassword, $sUsersDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails) public function SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails)
{ {
$this->sHostName = $sHostName; $this->sHostName = $sHostName;
$this->iHostPort = $iHostPort; $this->iHostPort = $iHostPort;
$this->bUseStartTLS = $bUseStartTLS; $this->bUseStartTLS = $bUseStartTLS;
if (0 < \strlen($sAccessDn)) if (0 < \strlen($sBindDn))
{ {
$this->sAccessDn = $sAccessDn; $this->sBindDn = $sBindDn;
$this->sAccessPassword = $sAccessPassword; $this->sBindPassword = $sBindPassword;
} }
$this->sUsersDn = $sUsersDn; $this->sBaseDn = $sBaseDn;
$this->sObjectClass = $sObjectClass; $this->sObjectClass = $sObjectClass;
$this->sUidField = $sUidField; $this->sUidField = $sUidField;
$this->sNameField = $sNameField; $this->sNameField = $sNameField;
@ -206,9 +206,9 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
return $aResult; return $aResult;
} }
if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword)) if (!@\ldap_bind($oCon, $this->sBindDn, $this->sBindPassword))
{ {
if (is_null($this->sAccessDn)) if (is_null($this->sBindDn))
{ {
$this->logLdapError($oCon, 'ldap_bind (anonymous)'); $this->logLdapError($oCon, 'ldap_bind (anonymous)');
} }
@ -221,7 +221,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
} }
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email()); $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
$sSearchDn = \strtr($this->sUsersDn, array( $sBaseDn = \strtr($this->sBaseDn, array(
'{domain}' => $sDomain, '{domain}' => $sDomain,
'{domain:dc}' => 'dc='.\strtr($sDomain, array('.' => ',dc=')), '{domain:dc}' => 'dc='.\strtr($sDomain, array('.' => ',dc=')),
'{email}' => $oAccount->Email(), '{email}' => $oAccount->Email(),
@ -258,8 +258,8 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
$sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : ''); $sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : '');
$sFilter .= ')'; $sFilter .= ')';
$this->oLogger->Write('ldap_search: start: '.$sSearchDn.' / '.$sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_search: start: '.$sBaseDn.' / '.$sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
$oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30); $oS = @\ldap_search($oCon, $sBaseDn, $sFilter, $aItems, 0, 30, 30);
if ($oS) if ($oS)
{ {
$aEntries = @\ldap_get_entries($oCon, $oS); $aEntries = @\ldap_get_entries($oCon, $oS);

View file

@ -44,21 +44,21 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
$sHostName = \trim($this->Config()->Get('plugin', 'hostname', '')); $sHostName = \trim($this->Config()->Get('plugin', 'hostname', ''));
$iHostPort = (int) $this->Config()->Get('plugin', 'port', 389); $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);
$sAccessDn = \trim($this->Config()->Get('plugin', 'access_dn', '')); $sBindDn = \trim($this->Config()->Get('plugin', 'bind_dn', ''));
$sAccessPassword = \trim($this->Config()->Get('plugin', 'access_password', '')); $sBindPassword = \trim($this->Config()->Get('plugin', 'bind_password', ''));
$sUsersDn = \trim($this->Config()->Get('plugin', 'users_dn_format', '')); $sBaseDn = \trim($this->Config()->Get('plugin', 'base_dn', ''));
$sObjectClass = \trim($this->Config()->Get('plugin', 'object_class', '')); $sObjectClass = \trim($this->Config()->Get('plugin', 'object_class', ''));
$sUidField = \trim($this->Config()->Get('plugin', 'uid_field', '')); $sUidField = \trim($this->Config()->Get('plugin', 'uid_field', ''));
$sNameField = \trim($this->Config()->Get('plugin', 'name_field', '')); $sNameField = \trim($this->Config()->Get('plugin', 'name_field', ''));
$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($sUsersDn) && 0 < \strlen($sObjectClass) && 0 < \strlen($sEmailField)) if (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, $sAccessDn, $sAccessPassword, $sUsersDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails); $oProvider->SetConfig($sHostName, $iHostPort, $bUseStartTLS, $sBindDn, $sBindPassword, $sBaseDn, $sObjectClass, $sUidField, $sNameField, $sEmailField, $sAllowedEmails);
$mResult[] = $oProvider; $mResult[] = $oProvider;
} }
@ -81,13 +81,13 @@ class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
\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),
\RainLoop\Plugins\Property::NewInstance('access_dn')->SetLabel('Bind DN') \RainLoop\Plugins\Property::NewInstance('bind_dn')->SetLabel('Bind DN')
->SetDescription('DN to bind (login) with. If left blank, anonymous bind will be tried and the password will be ignored') ->SetDescription('DN to bind (login) with. If left blank, anonymous bind will be tried and the password will be ignored')
->SetDefaultValue(''), ->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('access_password')->SetLabel('Bind password') \RainLoop\Plugins\Property::NewInstance('bind_password')->SetLabel('Bind password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD) ->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''), ->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('users_dn_format')->SetLabel('Search base DN') \RainLoop\Plugins\Property::NewInstance('base_dn')->SetLabel('Search base DN')
->SetDescription('DN to use as the search base. Supported tokens: {domain}, {domain:dc}, {email}, {email:user}, {email:domain}, {login}, {imap:login}, {imap:host}, {imap:port}') ->SetDescription('DN to use as the search base. Supported tokens: {domain}, {domain:dc}, {email}, {email:user}, {email:domain}, {login}, {imap:login}, {imap:host}, {imap:port}')
->SetDefaultValue('ou=People,dc=domain,dc=com'), ->SetDefaultValue('ou=People,dc=domain,dc=com'),
\RainLoop\Plugins\Property::NewInstance('object_class')->SetLabel('objectClass value') \RainLoop\Plugins\Property::NewInstance('object_class')->SetLabel('objectClass value')