2015-09-08 05:15:39 +08:00
< ? php
class LdapContactsSuggestionsPlugin extends \RainLoop\Plugins\AbstractPlugin
{
2021-02-10 16:50:20 +08:00
const
NAME = 'Contacts suggestions (LDAP)' ,
2022-05-05 22:26:23 +08:00
VERSION = '2.9' ,
2022-05-12 05:14:12 +08:00
RELEASE = '2022-05-05' ,
2022-05-19 04:53:20 +08:00
CATEGORY = 'Contacts' ,
2022-05-05 22:26:23 +08:00
DESCRIPTION = 'Get contacts suggestions from LDAP.' ,
REQUIRED = '2.9.1' ;
2021-02-10 16:50:20 +08:00
2020-08-31 00:04:54 +08:00
public function Init () : void
2015-09-08 05:15:39 +08:00
{
$this -> addHook ( 'main.fabrica' , 'MainFabrica' );
}
/**
* @ return string
*/
2020-08-31 00:04:54 +08:00
public function Supported () : string
2015-09-08 05:15:39 +08:00
{
if ( ! \function_exists ( 'ldap_connect' ))
{
2021-08-28 05:49:03 +08:00
return 'The LDAP PHP extension must be installed to use this extension' ;
2015-09-08 05:15:39 +08:00
}
return '' ;
}
/**
* @ param string $sName
* @ param mixed $mResult
*/
public function MainFabrica ( $sName , & $mResult )
{
switch ( $sName )
{
case 'suggestions' :
if ( ! \is_array ( $mResult ))
{
$mResult = array ();
}
2021-08-22 18:17:05 +08:00
$sLdapUri = \trim ( $this -> Config () -> Get ( 'plugin' , 'ldap_uri' , '' ));
2021-08-22 16:48:33 +08:00
$bUseStartTLS = ( bool ) $this -> Config () -> Get ( 'plugin' , 'use_start_tls' , True );
2021-08-22 18:01:43 +08:00
$sBindDn = \trim ( $this -> Config () -> Get ( 'plugin' , 'bind_dn' , '' ));
$sBindPassword = \trim ( $this -> Config () -> Get ( 'plugin' , 'bind_password' , '' ));
$sBaseDn = \trim ( $this -> Config () -> Get ( 'plugin' , 'base_dn' , '' ));
2021-08-22 19:32:20 +08:00
$sObjectClasses = \trim ( $this -> Config () -> Get ( 'plugin' , 'object_classes' , '' ));
2021-08-22 19:10:40 +08:00
$sUidAttributes = \trim ( $this -> Config () -> Get ( 'plugin' , 'uid_attributes' , '' ));
$sNameAttributes = \trim ( $this -> Config () -> Get ( 'plugin' , 'name_attributes' , '' ));
$sEmailAttributes = \trim ( $this -> Config () -> Get ( 'plugin' , 'mail_attributes' , '' ));
2021-08-22 06:42:38 +08:00
$sAllowedEmails = \trim ( $this -> Config () -> Get ( 'plugin' , 'allowed_emails' , '' ));
2015-09-08 05:15:39 +08:00
2021-08-22 19:32:20 +08:00
if ( 0 < \strlen ( $sLdapUri ) && 0 < \strlen ( $sBaseDn ) && 0 < \strlen ( $sObjectClasses ) && 0 < \strlen ( $sEmailAttributes ))
2015-09-08 05:15:39 +08:00
{
include_once __DIR__ . '/LdapContactsSuggestions.php' ;
$oProvider = new LdapContactsSuggestions ();
2021-08-22 19:32:20 +08:00
$oProvider -> SetConfig ( $sLdapUri , $bUseStartTLS , $sBindDn , $sBindPassword , $sBaseDn , $sObjectClasses , $sUidAttributes , $sNameAttributes , $sEmailAttributes , $sAllowedEmails );
2015-09-08 05:15:39 +08:00
$mResult [] = $oProvider ;
}
break ;
}
}
/**
* @ return array
*/
2020-08-31 00:04:54 +08:00
protected function configMapping () : array
2015-09-08 05:15:39 +08:00
{
return array (
2021-08-22 18:17:05 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'ldap_uri' ) -> SetLabel ( 'LDAP URI' )
-> SetDescription ( 'LDAP server URI(s), space separated' )
2021-08-23 16:14:42 +08:00
-> SetDefaultValue ( 'ldap://localhost:389' ),
2021-08-22 16:48:33 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'use_start_tls' ) -> SetLabel ( 'Use StartTLS' )
-> SetType ( \RainLoop\Enumerations\PluginPropertyType :: BOOL )
-> SetDefaultValue ( True ),
2021-08-22 18:01:43 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'bind_dn' ) -> SetLabel ( 'Bind DN' )
2021-08-22 17:48:21 +08:00
-> SetDescription ( 'DN to bind (login) with. If left blank, anonymous bind will be tried and the password will be ignored' )
2015-09-08 05:15:39 +08:00
-> SetDefaultValue ( '' ),
2021-08-22 18:01:43 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'bind_password' ) -> SetLabel ( 'Bind password' )
2015-09-08 05:15:39 +08:00
-> SetType ( \RainLoop\Enumerations\PluginPropertyType :: PASSWORD )
-> SetDefaultValue ( '' ),
2021-08-22 18:01:43 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'base_dn' ) -> SetLabel ( 'Search base DN' )
2021-08-22 17:48:21 +08:00
-> 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}' )
2021-08-22 18:54:02 +08:00
-> SetDefaultValue ( 'ou=People,dc=example,dc=com' ),
2021-08-22 19:32:20 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'object_classes' ) -> SetLabel ( 'objectClasses to use' )
-> SetDescription ( 'LDAP objectClasses to search for, comma separated list' )
2015-09-08 05:15:39 +08:00
-> SetDefaultValue ( 'inetOrgPerson' ),
2021-08-22 19:10:40 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'uid_attributes' ) -> SetLabel ( 'uid attributes' )
2021-08-22 17:48:21 +08:00
-> SetDescription ( 'LDAP attributes for userids, comma separated list in order of preference' )
2018-06-07 06:02:43 +08:00
-> SetDefaultValue ( 'uid' ),
2021-08-22 19:10:40 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'name_attributes' ) -> SetLabel ( 'Name attributes' )
2021-08-22 17:48:21 +08:00
-> SetDescription ( 'LDAP attributes for user names, comma separated list in order of preference' )
2021-08-22 18:54:02 +08:00
-> SetDefaultValue ( 'displayName,cn,givenName,sn' ),
2021-08-22 19:10:40 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'mail_attributes' ) -> SetLabel ( 'Mail attributes' )
2021-08-22 17:48:21 +08:00
-> SetDescription ( 'LDAP attributes for user email addresses, comma separated list in order of preference' )
2021-08-22 18:54:02 +08:00
-> SetDefaultValue ( 'mailAddress,mail,mailAlternateAddress,mailAlias' ),
2015-09-08 05:15:39 +08:00
\RainLoop\Plugins\Property :: NewInstance ( 'allowed_emails' ) -> SetLabel ( 'Allowed emails' )
2021-08-22 17:48:21 +08:00
-> SetDescription ( 'Email addresses of users which should be allowed to do LDAP lookups, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net' )
2015-09-08 05:15:39 +08:00
-> SetDefaultValue ( '*' )
);
}
2018-11-30 20:54:28 +08:00
}