mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 06:58:27 +03:00
Merge pull request #727 from cm-schl/master
Plugin to add additional accounts by ldap
This commit is contained in:
commit
e92910d4a0
5 changed files with 610 additions and 0 deletions
410
plugins/ldap-mail-accounts/LdapMailAccounts.php
Normal file
410
plugins/ldap-mail-accounts/LdapMailAccounts.php
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
<?php
|
||||
|
||||
use RainLoop\Enumerations\Capa;
|
||||
use MailSo\Log\Logger;
|
||||
use RainLoop\Actions;
|
||||
use RainLoop\Model\Account;
|
||||
|
||||
class LdapMailAccounts
|
||||
{
|
||||
/** @var resource */
|
||||
private $ldap;
|
||||
|
||||
/** @var bool */
|
||||
private $ldapAvailable = true;
|
||||
/** @var bool */
|
||||
private $ldapConnected = false;
|
||||
/** @var bool */
|
||||
private $ldapBound = false;
|
||||
|
||||
/** @var LdapMailAccountsConfig */
|
||||
private $config;
|
||||
|
||||
/** @var Logger */
|
||||
private $logger;
|
||||
|
||||
private const LOG_KEY = "LDAP MAIL ACCOUNTS PLUGIN";
|
||||
|
||||
/**
|
||||
* LdapMailAccount constructor.
|
||||
*
|
||||
* @param LdapMailAccountsConfig $config LdapMailAccountsConfig object containing the admin configuration for this plugin
|
||||
* @param Logger $logger Used to write to the logfile
|
||||
*/
|
||||
public function __construct(LdapMailAccountsConfig $config, Logger $logger)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
|
||||
// Check if LDAP is available
|
||||
if (!extension_loaded('ldap') || !function_exists('ldap_connect')) {
|
||||
$this->ldapAvailable = false;
|
||||
$logger->Write("The LDAP extension is not available!", \LOG_WARNING, self::LOG_KEY);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->Connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* Add additional mail accounts to the given primary account by looking up the ldap directory
|
||||
*
|
||||
* The ldap lookup has to be configured in the plugin configuration of the extension (in the SnappyMail Admin Panel)
|
||||
*
|
||||
* @param Account $oAccount
|
||||
* @return bool true if additional accounts have been added or no additional accounts where found in . false if an error occured
|
||||
*/
|
||||
public function AddLdapMailAccounts(Account $oAccount): bool
|
||||
{
|
||||
try {
|
||||
$this->EnsureBound();
|
||||
} catch (LdapMailAccountsException $e) {
|
||||
return false; // exceptions are only thrown from the handleerror function that does logging already
|
||||
}
|
||||
|
||||
// Try to get account information. Login() returns the username of the user
|
||||
// and removes the domainname if this was configured inside the domain config.
|
||||
$username = @ldap_escape($oAccount->Login(), "", LDAP_ESCAPE_FILTER);
|
||||
|
||||
$searchString = $this->config->search_string;
|
||||
|
||||
// Replace placeholders inside the ldap search string with actual values
|
||||
$searchString = str_replace("#USERNAME#", $username, $searchString);
|
||||
$searchString = str_replace("#BASE_DN#", $this->config->base, $searchString);
|
||||
|
||||
$this->logger->Write("ldap search string after replacement of placeholders: $searchString", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
try {
|
||||
$mailAddressResults = $this->FindLdapResults(
|
||||
$this->config->field_search,
|
||||
$searchString,
|
||||
$this->config->base,
|
||||
$this->config->objectclass,
|
||||
$this->config->field_name,
|
||||
$this->config->field_username,
|
||||
$this->config->field_domain
|
||||
);
|
||||
}
|
||||
catch (LdapMailAccountsException $e) {
|
||||
return false; // exceptions are only thrown from the handleerror function that does logging already
|
||||
}
|
||||
if (count($mailAddressResults) < 1) {
|
||||
$this->logger->Write("Could not find user $username", \LOG_NOTICE, self::LOG_KEY);
|
||||
return false;
|
||||
} else if (count($mailAddressResults) == 1) {
|
||||
$this->logger->Write("Found only one match for user $username, no additional mail adresses found", \LOG_NOTICE, self::LOG_KEY);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Basing on https://github.com/the-djmaze/snappymail/issues/616
|
||||
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
|
||||
//Check if SnappyMail is configured to allow additional accounts
|
||||
if (!$oActions->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
|
||||
return $oActions->FalseResponse(__FUNCTION__);
|
||||
}
|
||||
|
||||
$aAccounts = $oActions->GetAccounts($oAccount);
|
||||
|
||||
//Search for accounts with suffix " (LDAP)" at the end of the name that where created by this plugin and initially remove them from the
|
||||
//account array. This only removes the visibility but does not delete the config done by the user. So if a user looses access to a
|
||||
//mailbox the user will not see the account anymore but the configuration can be restored when the user regains access to it
|
||||
foreach($aAccounts as $key => $aAccount)
|
||||
{
|
||||
if (preg_match("/\s\(LDAP\)$/", $aAccount['name']))
|
||||
{
|
||||
unset($aAccounts[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($mailAddressResults as $mailAddressResult)
|
||||
{
|
||||
$sUsername = $mailAddressResult->username;
|
||||
$sDomain = $mailAddressResult->domain;
|
||||
$sName = $mailAddressResult->name;
|
||||
|
||||
//Check if the domain of the found mail address is in the list of configured domains
|
||||
if ($oActions->DomainProvider()->Load($sDomain, true))
|
||||
{
|
||||
//only execute if the found account isn't already in the list of additional accounts
|
||||
//and if the found account is different from the main account
|
||||
if (!isset($aAccounts["$sUsername@$sDomain"]) && $oAccount->Email() !== "$sUsername@$sDomain")
|
||||
{
|
||||
//Try to login the user with the same password as the primary account has
|
||||
//if this fails the user will see the new mail addresses but will be asked for the correct password
|
||||
$sPass = $oAccount->Password();
|
||||
|
||||
$oNewAccount = RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials($oActions, "$sUsername@$sDomain", $sUsername, $sPass);
|
||||
|
||||
$aAccounts["$sUsername@$sDomain"] = $oNewAccount->asTokenArray($oAccount);
|
||||
}
|
||||
|
||||
//Always inject/update the found mailbox names into the array (also if the mailbox already existed)
|
||||
if (isset($aAccounts["$sUsername@$sDomain"]))
|
||||
{
|
||||
$aAccounts["$sUsername@$sDomain"]['name'] = $sName . " (LDAP)";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->logger->Write("Domain $sDomain is not part of configured domains in SnappyMail Admin Panel - mail address $sUsername@$sDomain will not be added.", \LOG_NOTICE, self::LOG_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
if ($aAccounts)
|
||||
{
|
||||
$oActions->SetAccounts($oAccount, $aAccounts);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a connection to the LDAP was possible
|
||||
*
|
||||
* @throws LdapMailAccountsException
|
||||
*
|
||||
* */
|
||||
private function EnsureConnected(): void
|
||||
{
|
||||
if ($this->ldapConnected) return;
|
||||
|
||||
$res = $this->Connect();
|
||||
if (!$res)
|
||||
$this->HandleLdapError("Connect");
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the LDAP using the server address and protocol version defined inside the configuration of the plugin
|
||||
*/
|
||||
private function Connect(): bool
|
||||
{
|
||||
// Set up connection
|
||||
$ldap = @ldap_connect($this->config->server);
|
||||
if ($ldap === false) {
|
||||
$this->ldapAvailable = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set protocol version
|
||||
$option = @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, $this->config->protocol);
|
||||
if (!$option) {
|
||||
$this->ldapAvailable = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->ldap = $ldap;
|
||||
$this->ldapConnected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the plugin has been authenticated at the LDAP
|
||||
*
|
||||
* @throws LdapMailAccountsException
|
||||
*
|
||||
* */
|
||||
private function EnsureBound(): void
|
||||
{
|
||||
if ($this->ldapBound) return;
|
||||
$this->EnsureConnected();
|
||||
|
||||
$res = $this->Bind();
|
||||
if (!$res)
|
||||
$this->HandleLdapError("Bind");
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates the plugin at the LDAP using the username and password defined inside the configuration of the plugin
|
||||
*
|
||||
* @return bool true if authentication was successful
|
||||
*/
|
||||
private function Bind(): bool
|
||||
{
|
||||
// Bind to LDAP here
|
||||
$bindResult = @ldap_bind($this->ldap, $this->config->bind_user, $this->config->bind_password);
|
||||
if (!$bindResult) {
|
||||
$this->ldapAvailable = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->ldapBound = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles and logs an eventual LDAP error
|
||||
*
|
||||
* @param string $op
|
||||
* @throws LdapMailAccountsException
|
||||
*/
|
||||
private function HandleLdapError(string $op = ""): void
|
||||
{
|
||||
// Obtain LDAP error and write logs
|
||||
$errorNo = @ldap_errno($this->ldap);
|
||||
$errorMsg = @ldap_error($this->ldap);
|
||||
|
||||
$message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})";
|
||||
$this->logger->Write($message, \LOG_ERR, self::LOG_KEY);
|
||||
throw new LdapMailAccountsException($message, $errorNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the LDAP for additional mail accounts
|
||||
*
|
||||
* The search for additional mail accounts is done by a ldap search using the defined fields inside the configuration of the plugin (SnappyMail Admin Panel)
|
||||
*
|
||||
* @param string $searchField
|
||||
* @param string $searchString
|
||||
* @param string $searchBase
|
||||
* @param string $objectClass
|
||||
* @param string $nameField
|
||||
* @param string $usernameField
|
||||
* @param string $domainField
|
||||
* @return LdapMailAccountResult[]
|
||||
* @throws LdapMailAccountsException
|
||||
*/
|
||||
private function FindLdapResults(
|
||||
string $searchField,
|
||||
string $searchString,
|
||||
string $searchBase,
|
||||
string $objectClass,
|
||||
string $nameField,
|
||||
string $usernameField,
|
||||
string $domainField): array
|
||||
{
|
||||
$this->EnsureBound();
|
||||
$nameField = strtolower($nameField);
|
||||
$usernameField = strtolower($usernameField);
|
||||
$domainField = strtolower($domainField);
|
||||
|
||||
$filter = "(&(objectclass=$objectClass)($searchField=$searchString))";
|
||||
$this->logger->Write("Used ldap filter to search for additional mail accounts: $filter", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
$ldapResult = @ldap_search($this->ldap, $searchBase, $filter, ['dn', $usernameField, $nameField, $domainField]);
|
||||
if (!$ldapResult) {
|
||||
$this->HandleLdapError("Fetch $objectClass");
|
||||
return [];
|
||||
}
|
||||
|
||||
$entries = @ldap_get_entries($this->ldap, $ldapResult);
|
||||
if (!$entries) {
|
||||
$this->HandleLdapError("Fetch $objectClass");
|
||||
return [];
|
||||
}
|
||||
|
||||
// Save the found ldap entries into a LdapMailAccountResult object and return them
|
||||
$results = [];
|
||||
for ($i = 0; $i < $entries["count"]; $i++) {
|
||||
$entry = $entries[$i];
|
||||
|
||||
$result = new LdapMailAccountResult();
|
||||
$result->dn = $entry["dn"];
|
||||
$result->name = $this->LdapGetAttribute($entry, $nameField, true, true);
|
||||
|
||||
$result->username = $this->LdapGetAttribute($entry, $usernameField, true, true);
|
||||
$result->username = $this->RemoveEventualDomainPart($result->username);
|
||||
|
||||
$result->domain = $this->LdapGetAttribute($entry, $domainField, true, true);
|
||||
$result->domain = $this->RemoveEventualLocalPart($result->domain);
|
||||
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an eventually found domain-part of an email address
|
||||
*
|
||||
* If the input string contains an '@' character the function returns the local-part before the '@'\
|
||||
* If no '@' character can be found the input string is returned.
|
||||
*
|
||||
* @param string $sInput
|
||||
* @return string
|
||||
*/
|
||||
public static function RemoveEventualDomainPart(string $sInput) : string
|
||||
{
|
||||
// Copy of \MailSo\Base\Utils::GetAccountNameFromEmail to make sure that also after eventual future
|
||||
// updates the input string gets returned when no '@' is found (GetDomainFromEmail already doesn't do this)
|
||||
$sResult = '';
|
||||
if (\strlen($sInput))
|
||||
{
|
||||
$iPos = \strrpos($sInput, '@');
|
||||
$sResult = (false === $iPos) ? $sInput : \substr($sInput, 0, $iPos);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an eventually found local-part of an email address
|
||||
*
|
||||
* If the input string contains an '@' character the function returns the domain-part behind the '@'\
|
||||
* If no '@' character can be found the input string is returned.
|
||||
*
|
||||
* @param string $sInput
|
||||
* @return string
|
||||
*/
|
||||
public static function RemoveEventualLocalPart(string $sInput) : string
|
||||
{
|
||||
$sResult = '';
|
||||
if (\strlen($sInput))
|
||||
{
|
||||
$iPos = \strrpos($sInput, '@');
|
||||
$sResult = (false === $iPos) ? $sInput : \substr($sInput, $iPos + 1);
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets LDAP attributes out of the input array
|
||||
*
|
||||
* @param array $entry Array containing the result of a ldap search
|
||||
* @param string $attribute The name of the attribute to return
|
||||
* @param bool $single If true the function checks if exact one value for this attribute is inside the input array. If false an array is returned. Default true.
|
||||
* @param bool $required If true the attribute has to exist inside the input array. Default false.
|
||||
* @return string|string[]
|
||||
*/
|
||||
private function LdapGetAttribute(array $entry, string $attribute, bool $single = true, bool $required = false)
|
||||
{
|
||||
if (!isset($entry[$attribute])) {
|
||||
if ($required)
|
||||
$this->logger->Write("Attribute $attribute not found on object {$entry['dn']} while required", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
return $single ? "" : [];
|
||||
}
|
||||
|
||||
if ($single) {
|
||||
if ($entry[$attribute]["count"] > 1)
|
||||
$this->logger->Write("Attribute $attribute is multivalues while only a single value is expected", \LOG_NOTICE, self::LOG_KEY);
|
||||
|
||||
return $entry[$attribute][0];
|
||||
}
|
||||
|
||||
$result = $entry[$attribute];
|
||||
unset($result["count"]);
|
||||
return array_values($result);
|
||||
}
|
||||
}
|
||||
|
||||
class LdapMailAccountResult
|
||||
{
|
||||
/** @var string */
|
||||
public $dn;
|
||||
|
||||
/** @var string */
|
||||
public $name;
|
||||
|
||||
/** @var string */
|
||||
public $username;
|
||||
|
||||
/** @var string */
|
||||
public $domain;
|
||||
}
|
||||
51
plugins/ldap-mail-accounts/LdapMailAccountsConfig.php
Normal file
51
plugins/ldap-mail-accounts/LdapMailAccountsConfig.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
|
||||
use RainLoop\Config\Plugin;
|
||||
|
||||
class LdapMailAccountsConfig
|
||||
{
|
||||
public const CONFIG_SERVER = "server";
|
||||
public const CONFIG_PROTOCOL_VERSION = "server_version";
|
||||
|
||||
public const CONFIG_BIND_USER = "bind_user";
|
||||
public const CONFIG_BIND_PASSWORD = "bind_password";
|
||||
|
||||
public const CONFIG_BASE = "base";
|
||||
public const CONFIG_OBJECTCLASS = "objectclass";
|
||||
public const CONFIG_FIELD_NAME = "field_name";
|
||||
public const CONFIG_FIELD_SEARCH = "field_search";
|
||||
public const CONFIG_FIELD_USERNAME = "field_username";
|
||||
public const CONFIG_SEARCH_STRING = "search_string";
|
||||
public const CONFIG_FIELD_MAIL_DOMAIN = "field_domain";
|
||||
|
||||
public $server;
|
||||
public $protocol;
|
||||
public $bind_user;
|
||||
public $bind_password;
|
||||
public $base;
|
||||
public $objectclass;
|
||||
public $field_name;
|
||||
public $field_search;
|
||||
public $field_username;
|
||||
public $search_string;
|
||||
public $field_domain;
|
||||
|
||||
public static function MakeConfig(Plugin $config): LdapMailAccountsConfig
|
||||
{
|
||||
$ldap = new self();
|
||||
$ldap->server = trim($config->Get("plugin", self::CONFIG_SERVER));
|
||||
$ldap->protocol = (int)trim($config->Get("plugin", self::CONFIG_PROTOCOL_VERSION, 3));
|
||||
$ldap->bind_user = trim($config->Get("plugin", self::CONFIG_BIND_USER));
|
||||
$ldap->bind_password = trim($config->Get("plugin", self::CONFIG_BIND_PASSWORD));
|
||||
$ldap->base = trim($config->Get("plugin", self::CONFIG_BASE));
|
||||
$ldap->objectclass = trim($config->Get("plugin", self::CONFIG_OBJECTCLASS));
|
||||
$ldap->field_name = trim($config->Get("plugin", self::CONFIG_FIELD_NAME));
|
||||
$ldap->field_search = trim($config->Get("plugin", self::CONFIG_FIELD_SEARCH));
|
||||
$ldap->field_username = trim($config->Get("plugin", self::CONFIG_FIELD_USERNAME));
|
||||
$ldap->search_string = trim($config->Get("plugin", self::CONFIG_SEARCH_STRING));
|
||||
$ldap->field_domain = trim($config->Get("plugin", self::CONFIG_FIELD_MAIL_DOMAIN));
|
||||
|
||||
return $ldap;
|
||||
}
|
||||
}
|
||||
5
plugins/ldap-mail-accounts/LdapMailAccountsException.php
Normal file
5
plugins/ldap-mail-accounts/LdapMailAccountsException.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
class LdapMailAccountsException extends \RainLoop\Exceptions\ClientException
|
||||
{
|
||||
}
|
||||
17
plugins/ldap-mail-accounts/README.md
Normal file
17
plugins/ldap-mail-accounts/README.md
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
## LDAP Mail Accounts Plugin for SnappyMail
|
||||
|
||||
### Description
|
||||
This plugin can be used to add additional mail accounts to SnappyMail when a user logs in successfully. The list of additional accounts is retrieved by a ldap query that can be configured inside the plugin settings.\
|
||||
On a successful login the username of the SnappyMail user is passed to the plugin and will be searched in the ldap. If additional mail accounts are found, the username and domain-part of those will be used to add the new mail account. The plugin tries to log in the user with the same password used to login to SnappyMail - if this fails SnappyMail asks the user to insert his credentials.
|
||||
|
||||
### Configuration
|
||||
- Install and activate the plugin using the SnappyMail Admin Panel -> menu Extensions.
|
||||
- Click on the gear symbol beside the plugin to open the configration dialog.
|
||||
- Insert the connection data to access your LDAP. Leave username and password empty for an anonymous login.
|
||||
- The fields `Object class`, `Base DN`, `Search field` and `LDAP search string` are used to put together a ldap search filter which will return the additional mail accounts of a user:\
|
||||
`(&(objectclass=<YOUR OBJECT CLASS>)(<YOUR SEARCH FIELD>=<YOUR SEARCH STRING>))`.\
|
||||
This filter will be executed on the `Base DN` you have defined. `LDAP search string` can contain the placeholders `#USERNAME#` (will be replaced with the username the user logged in to Snappymail) and `#BASE_DN#` (will be replaced with the value you inserted into the field `Base DN` inside the plugin settings). This will allow you to create more complex search strings like `uid=#USERNAME#`.
|
||||
- `Username field of additional account`, `Domain name field of additional account` and `Additional account name field` are used to define the ldap attributes to read when the ldap search was successful. For example insert `mail` into the `Username field of additional account` and the `Domain name field of additional account` to use the [local-part](https://en.wikipedia.org/wiki/Email_address#Local-part) of the mail address as username and the [domain-part](https://en.wikipedia.org/wiki/Email_address#Domain) as domain for the additional account.\
|
||||
`Username field of additional account` and `Domain name field of additional account` before use get checked by the plugin if they contain a mail address and if true only the local-part or domain-part is returned. If no `@` is found the content of the found ldap attribute is returned without modification. This can be usefull if your user should login with something different than the mail address (a username that is diffrent from the local-part of the mail address).
|
||||
|
||||
**Important:** keep in mind, that SnappyMail normally needs a mail address as username. In some special circumstances (login with an ldap username, not a mail address) this can mean that you have to configure the plugin to put together a 'fake' mail address like `<LDAP-USERNAME>@<YOUR-DOMAIN>`.
|
||||
127
plugins/ldap-mail-accounts/index.php
Normal file
127
plugins/ldap-mail-accounts/index.php
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
use RainLoop\Enumerations\Capa;
|
||||
use RainLoop\Enumerations\PluginPropertyType;
|
||||
use RainLoop\Plugins\AbstractPlugin;
|
||||
use RainLoop\Plugins\Property;
|
||||
use RainLoop\Model\Account;
|
||||
use RainLoop\Actions;
|
||||
|
||||
|
||||
class LdapMailAccountsPlugin extends AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'LDAP Mail Accounts',
|
||||
VERSION = '1.0',
|
||||
AUTHOR = 'cm-schl',
|
||||
URL = 'https://github.com/cm-sch',
|
||||
RELEASE = '2022-11-25',
|
||||
REQUIRED = '2.20.0',
|
||||
CATEGORY = 'Accounts',
|
||||
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).';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
include_once __DIR__ . '/LdapMailAccounts.php';
|
||||
include_once __DIR__ . '/LdapMailAccountsConfig.php';
|
||||
include_once __DIR__ . '/LdapMailAccountsException.php';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function Init(): void
|
||||
{
|
||||
$this->addHook("login.success", 'AddAdditionalLdapMailAccounts');
|
||||
}
|
||||
|
||||
// Function gets called by RainLoop/Actions/User.php
|
||||
/**
|
||||
* Add additional mail accounts to the webinterface of the user by looking up the ldap directory
|
||||
*
|
||||
* @param Account $oAccount
|
||||
*/
|
||||
public function AddAdditionalLdapMailAccounts(Account $oAccount)
|
||||
{
|
||||
// Set up config
|
||||
$config = LdapMailAccountsConfig::MakeConfig($this->Config());
|
||||
|
||||
$oldapMailAccounts = new LdapMailAccounts($config, $this->Manager()->Actions()->Logger());
|
||||
|
||||
$oldapMailAccounts->AddLdapMailAccounts($oAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the content of the plugin configuration page inside the Admin Panel of SnappyMail
|
||||
*/
|
||||
protected function configMapping(): array
|
||||
{
|
||||
return [
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_SERVER)
|
||||
->SetLabel("LDAP Server URL")
|
||||
->SetPlaceholder("ldap://server:port")
|
||||
->SetType(PluginPropertyType::STRING),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_PROTOCOL_VERSION)
|
||||
->SetLabel("LDAP Protocol Version")
|
||||
->SetType(PluginPropertyType::SELECTION)
|
||||
->SetDefaultValue([2, 3]),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_BIND_USER)
|
||||
->SetLabel("LDAP Username")
|
||||
->SetDescription("The user to use for binding to the LDAP server. Should be a DN or RDN. Leave empty for anonymous bind.")
|
||||
->SetType(PluginPropertyType::STRING),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_BIND_PASSWORD)
|
||||
->SetLabel("LDAP Password")
|
||||
->SetDescription("Leave empty for anonymous bind.")
|
||||
->SetType(PluginPropertyType::PASSWORD),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_OBJECTCLASS)
|
||||
->SetLabel("Object class")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The object class to use when searching for additional mail accounts of the logged in SnappyMail user")
|
||||
->SetDefaultValue("user"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_BASE)
|
||||
->SetLabel("Base DN")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The base DN to search in for additional mail accounts of the logged in SnappyMail user"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_SEARCH)
|
||||
->SetLabel("Search field")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The name of the ldap attribute that has to contain the here defined 'LDAP search string'.")
|
||||
->SetDefaultValue("member"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_SEARCH_STRING)
|
||||
->SetLabel("LDAP search string")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->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
|
||||
\n#BASE_DN# - replaced with the value inside the field 'User base DN'.")
|
||||
->SetDefaultValue("uid=#USERNAME#"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_USERNAME)
|
||||
->SetLabel("Username field of additional account")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The field containing the username of the found additional mail account.
|
||||
\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.")
|
||||
->SetDefaultValue("uid"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_MAIL_DOMAIN)
|
||||
->SetLabel("Domain name field of additional account")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The field containing the domain name of the found additional mail account.
|
||||
\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.")
|
||||
->SetDefaultValue("mail"),
|
||||
|
||||
Property::NewInstance(LdapMailAccountsConfig::CONFIG_FIELD_NAME)
|
||||
->SetLabel("Additional account name field")
|
||||
->SetType(PluginPropertyType::STRING)
|
||||
->SetDescription("The field containing the default sender name of the found additional mail account.")
|
||||
->SetDefaultValue("displayName")
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue