2022-11-16 01:29:01 +08:00
< ? php
use RainLoop\Enumerations\Capa ;
use RainLoop\Enumerations\PluginPropertyType ;
use RainLoop\Plugins\AbstractPlugin ;
use RainLoop\Plugins\Property ;
2022-11-30 18:54:55 +08:00
use RainLoop\Model\MainAccount ;
2022-11-16 01:29:01 +08:00
use RainLoop\Actions ;
class LdapMailAccountsPlugin extends AbstractPlugin
{
const
NAME = 'LDAP Mail Accounts' ,
2022-12-09 00:15:46 +08:00
VERSION = '1.1' ,
2022-11-16 01:29:01 +08:00
AUTHOR = 'cm-schl' ,
URL = 'https://github.com/cm-sch' ,
2022-12-09 00:15:46 +08:00
RELEASE = '2022-12-08' ,
REQUIRED = '2.23.0' ,
2022-11-16 01:29:01 +08:00
CATEGORY = 'Accounts' ,
2022-11-25 18:41:31 +08:00
DESCRIPTION = 'Add additional mail accounts the SnappyMail user has access to by a LDAP query. Basing on the work of FWest98 (https://github.com/FWest98).' ;
2022-11-16 01:29:01 +08:00
public function __construct ()
{
include_once __DIR__ . '/LdapMailAccounts.php' ;
2022-11-29 23:51:54 +08:00
include_once __DIR__ . '/LdapMailAccountsConfig.php' ;
include_once __DIR__ . '/LdapMailAccountsException.php' ;
2022-11-16 01:29:01 +08:00
parent :: __construct ();
}
public function Init () : void
{
2022-11-29 23:28:59 +08:00
$this -> addHook ( " login.success " , 'AddAdditionalLdapMailAccounts' );
2022-11-16 01:29:01 +08:00
}
2022-11-25 17:42:14 +08:00
// Function gets called by RainLoop/Actions/User.php
2022-11-29 23:28:59 +08:00
/**
* Add additional mail accounts to the webinterface of the user by looking up the ldap directory
2022-11-30 18:54:55 +08:00
*
2022-11-30 18:59:54 +08:00
* @ param MainAccount $oAccount
2022-11-29 23:28:59 +08:00
*/
2022-11-30 18:59:54 +08:00
public function AddAdditionalLdapMailAccounts ( MainAccount $oAccount )
2022-11-16 01:29:01 +08:00
{
2022-11-30 18:59:54 +08:00
// Set up config
$config = LdapMailAccountsConfig :: MakeConfig ( $this -> Config ());
2022-11-16 01:29:01 +08:00
2022-11-30 18:59:54 +08:00
$oldapMailAccounts = new LdapMailAccounts ( $config , $this -> Manager () -> Actions () -> Logger ());
2022-11-16 01:29:01 +08:00
2022-11-30 18:59:54 +08:00
$oldapMailAccounts -> AddLdapMailAccounts ( $oAccount );
2022-11-16 01:29:01 +08:00
}
2022-11-29 23:28:59 +08:00
/**
* Defines the content of the plugin configuration page inside the Admin Panel of SnappyMail
*/
2022-11-16 01:29:01 +08:00
protected function configMapping () : array
{
return [
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_SERVER )
2022-11-16 01:29:01 +08:00
-> SetLabel ( " LDAP Server URL " )
-> SetPlaceholder ( " ldap://server:port " )
-> SetType ( PluginPropertyType :: STRING ),
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_PROTOCOL_VERSION )
2022-11-16 01:29:01 +08:00
-> SetLabel ( " LDAP Protocol Version " )
-> SetType ( PluginPropertyType :: SELECTION )
-> SetDefaultValue ([ 2 , 3 ]),
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_BIND_USER )
2022-11-25 18:41:31 +08:00
-> SetLabel ( " LDAP Username " )
2022-11-25 17:42:14 +08:00
-> SetDescription ( " The user to use for binding to the LDAP server. Should be a DN or RDN. Leave empty for anonymous bind. " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING ),
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_BIND_PASSWORD )
2022-11-25 18:41:31 +08:00
-> SetLabel ( " LDAP Password " )
2022-11-25 17:42:14 +08:00
-> SetDescription ( " Leave empty for anonymous bind. " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: PASSWORD ),
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_OBJECTCLASS )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " Object class " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-25 18:41:31 +08:00
-> SetDescription ( " The object class to use when searching for additional mail accounts of the logged in SnappyMail user " )
2022-11-16 01:29:01 +08:00
-> SetDefaultValue ( " user " ),
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_BASE )
2022-11-25 18:41:31 +08:00
-> SetLabel ( " Base DN " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-25 18:41:31 +08:00
-> SetDescription ( " The base DN to search in for additional mail accounts of the logged in SnappyMail user " ),
2022-11-16 01:29:01 +08:00
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_FIELD_SEARCH )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " Search field " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-25 18:41:31 +08:00
-> SetDescription ( " The name of the ldap attribute that has to contain the here defined 'LDAP search string'. " )
2022-11-30 18:54:55 +08:00
-> SetDefaultValue ( " member " ),
2022-11-16 01:29:01 +08:00
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_SEARCH_STRING )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " LDAP search string " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-25 17:42:14 +08:00
-> SetDescription ( " The search string used to find ldap objects of mail accounts the user has access to.
\nPossible placeholers : \n #USERNAME# - replaced with the username of the actual SnappyMail user
2022-11-25 18:41:31 +08:00
\n #BASE_DN# - replaced with the value inside the field 'User base DN'.")
2022-11-30 18:54:55 +08:00
-> SetDefaultValue ( " uid=#USERNAME# " ),
2022-11-16 01:29:01 +08:00
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_FIELD_USERNAME )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " Username field of additional account " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-30 18:54:55 +08:00
-> SetDescription ( " The field containing the username of the found additional mail account.
2022-11-25 18:41:31 +08:00
\nThis username gets used by SnappyMail to login to the additional mail account .
\nIf this field contains an email address , only the local - part before the @ is used . " )
2022-11-25 17:42:14 +08:00
-> SetDefaultValue ( " uid " ),
2022-11-16 01:29:01 +08:00
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_FIELD_MAIL_DOMAIN )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " Domain name field of additional account " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-30 18:54:55 +08:00
-> SetDescription ( " The field containing the domain name of the found additional mail account.
2022-11-25 18:41:31 +08:00
\nThis domain gets looked up by SnappyMail to choose the right connection parameters at logging in to the additional mail account .
\nIf this field contains an email address , only the domain - part after the @ is used . " )
2022-11-30 18:54:55 +08:00
-> SetDefaultValue ( " mail " ),
2022-11-16 01:29:01 +08:00
2022-11-29 23:51:54 +08:00
Property :: NewInstance ( LdapMailAccountsConfig :: CONFIG_FIELD_NAME )
2022-11-25 17:42:14 +08:00
-> SetLabel ( " Additional account name field " )
2022-11-16 01:29:01 +08:00
-> SetType ( PluginPropertyType :: STRING )
2022-11-25 17:42:14 +08:00
-> SetDescription ( " The field containing the default sender name of the found additional mail account. " )
-> SetDefaultValue ( " displayName " )
2022-11-16 01:29:01 +08:00
];
}
}