Added more plugin hooks

Added proxy auth plugin example (dev)
This commit is contained in:
RainLoop Team 2014-10-16 19:57:47 +04:00
parent 819ba4a2ef
commit 9c43105e95
8 changed files with 432 additions and 123 deletions

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1 @@
1.0

View file

@ -0,0 +1,41 @@
<?php
class ProxyauthLoginExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('event.login-post-login-provide', 'EventLoginPostLoginProvide');
}
/**
* @param \RainLoop\Account $oAccount
*/
public function EventLoginPostLoginProvide(&$oAccount)
{
if ($oAccount instanceof \RainLoop\Account)
{
// Verify logic
$bValid = isValidAccount($oAccount->Login(), $oAccount->Password());
/**
* $oAccount->Email(); // Email (It is not a IMAP login)
* $oAccount->Login(); // IMAP login
* $oAccount->Password(); // IMAP password
* $oAccount->DomainIncHost(); // IMAP host
*
* @see \RainLoo\Account for more
*/
if ($bValid) // if verify failed
{
// throw a Auth Error Exception
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
}
else // Or setup your proxyauth admin account credentials
{
$oAccount->SetProxyAuthUser('admin@domain.com');
$oAccount->SetProxyAuthPassword('secret-admin-password');
}
}
}
}

View file

@ -19,6 +19,16 @@ class Account
*/ */
private $sPassword; private $sPassword;
/**
* @var string
*/
private $sProxyAuthUser;
/**
* @var string
*/
private $sProxyAuthPassword;
/** /**
* @var string * @var string
*/ */
@ -40,16 +50,21 @@ class Account
* @param string $sPassword * @param string $sPassword
* @param \RainLoop\Domain $oDomain * @param \RainLoop\Domain $oDomain
* @param string $sSignMeToken = '' * @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
* *
* @return void * @return void
*/ */
protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain, $sSignMeToken = '') protected function __construct($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{ {
$this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true); $this->sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail, true);
$this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin); $this->sLogin = \MailSo\Base\Utils::IdnToAscii($sLogin);
$this->sPassword = $sPassword; $this->sPassword = $sPassword;
$this->oDomain = $oDomain; $this->oDomain = $oDomain;
$this->sSignMeToken = $sSignMeToken; $this->sSignMeToken = $sSignMeToken;
$this->sProxyAuthUser = $sProxyAuthUser;
$this->sProxyAuthPassword = $sProxyAuthPassword;
} }
/** /**
@ -58,12 +73,15 @@ class Account
* @param string $sPassword * @param string $sPassword
* @param \RainLoop\Domain $oDomain * @param \RainLoop\Domain $oDomain
* @param string $sSignMeToken = '' * @param string $sSignMeToken = ''
* @param string $sProxyAuthUser = ''
* @param string $sProxyAuthPassword = ''
* *
* @return \RainLoop\Account * @return \RainLoop\Account
*/ */
public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain, $sSignMeToken = '') public static function NewInstance($sEmail, $sLogin, $sPassword, \RainLoop\Domain $oDomain,
$sSignMeToken = '', $sProxyAuthUser = '', $sProxyAuthPassword = '')
{ {
return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken); return new self($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken, $sProxyAuthUser, $sProxyAuthPassword);
} }
/** /**
@ -81,6 +99,22 @@ class Account
{ {
return $this->sParentEmail; return $this->sParentEmail;
} }
/**
* @return string
*/
public function ProxyAuthUser()
{
return $this->sProxyAuthUser;
}
/**
* @return string
*/
public function ProxyAuthPassword()
{
return $this->sProxyAuthPassword;
}
/** /**
* @return string * @return string
@ -104,6 +138,14 @@ class Account
return $sLogin; return $sLogin;
} }
/**
* @return string
*/
public function IncPassword()
{
return $this->sPassword;
}
/** /**
* @return string * @return string
*/ */
@ -131,7 +173,7 @@ class Account
*/ */
public function Password() public function Password()
{ {
return $this->sPassword; return $this->IncPassword();
} }
/** /**
@ -163,8 +205,8 @@ class Account
*/ */
public function Hash() public function Hash()
{ {
return md5(APP_SALT.$this->Email().APP_SALT.$this->oDomain->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email())). return md5(APP_SALT.$this->Email().APP_SALT.$this->DomainIncHost().
APP_SALT.$this->oDomain->IncPort().APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT); APP_SALT.$this->DomainIncPort().APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT);
} }
/** /**
@ -187,20 +229,229 @@ class Account
$this->sParentEmail = \MailSo\Base\Utils::IdnToAscii($sParentEmail, true); $this->sParentEmail = \MailSo\Base\Utils::IdnToAscii($sParentEmail, true);
} }
/**
* @param string $sProxyAuthUser
*
* @return void
*/
public function SetProxyAuthUser($sProxyAuthUser)
{
return $this->sProxyAuthUser = $sProxyAuthUser;
}
/**
* @param string $sProxyAuthPassword
*
* @return void
*/
public function SetProxyAuthPassword($sProxyAuthPassword)
{
return $this->sProxyAuthPassword = $sProxyAuthPassword;
}
/**
* @return string
*/
public function DomainIncHost()
{
return $this->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email()));
}
/**
* @return int
*/
public function DomainIncPort()
{
return $this->Domain()->IncPort();
}
/**
* @return int
*/
public function DomainIncSecure()
{
return $this->Domain()->IncSecure();
}
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function DomainIncVerifySsl($bGlobalVerify = null)
{
return $this->Domain()->IncVerifySsl($bGlobalVerify);
}
/**
* @return string
*/
public function DomainOutHost()
{
return $this->Domain()->OutHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email()));
}
/**
* @return int
*/
public function DomainOutPort()
{
return $this->Domain()->OutPort();
}
/**
* @return int
*/
public function DomainOutSecure()
{
return $this->Domain()->OutSecure();
}
/**
* @return bool
*/
public function DomainOutAuth()
{
return $this->Domain()->OutAuth();
}
/**
* @param bool|null $bGlobalVerify = null
*
* @return bool
*/
public function DomainOutVerifySsl($bGlobalVerify = null)
{
return $this->Domain()->OutVerifySsl($bGlobalVerify);
}
/** /**
* @return string * @return string
*/ */
public function GetAuthToken() public function GetAuthToken()
{ {
return \RainLoop\Utils::EncodeKeyValues(array( return \RainLoop\Utils::EncodeKeyValues(array(
'token', 'token', // 0
$this->sEmail, $this->sEmail, // 1
$this->sLogin, $this->sLogin, // 2
$this->sPassword, $this->sPassword, // 3
\RainLoop\Utils::Fingerprint(), \RainLoop\Utils::Fingerprint(), // 4
$this->sSignMeToken, $this->sSignMeToken, // 5
$this->sParentEmail, $this->sParentEmail, // 6
\RainLoop\Utils::GetShortToken() \RainLoop\Utils::GetShortToken(), // 7
$this->sProxyAuthUser, // 8
$this->sProxyAuthPassword // 9
)); ));
} }
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Mail\MailClient $oMailClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function IncConnectAndLoginHelper($oPlugins, $oMailClient, $oConfig)
{
$bLogin = false;
$aImapCredentials = array(
'UseConnect' => true,
'UseAuth' => true,
'Host' => $this->DomainIncHost(),
'Port' => $this->DomainIncPort(),
'Secure' => $this->DomainIncSecure(),
'Login' => $this->IncLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => $this->DomainIncVerifySsl(!!$oConfig->Get('ssl', 'verify_certificate')),
'UseAuthPlainIfSupported' => !!$oConfig->Get('labs', 'use_imap_auth_plain')
);
$oPlugins->RunHook('filter.imap-credentials', array($this, &$aImapCredentials));
$oPlugins->RunHook('event.imap-pre-connect', array($this, $aImapCredentials['UseConnect'], $aImapCredentials));
if ($aImapCredentials['UseConnect'])
{
$oMailClient
->Connect($aImapCredentials['Host'], $aImapCredentials['Port'],
$aImapCredentials['Secure'], $aImapCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.imap-pre-login', array($this, $aImapCredentials['UseAuth'], $aImapCredentials));
if ($aImapCredentials['UseAuth'])
{
if (0 < \strlen($aImapCredentials['ProxyAuthUser']) &&
0 < \strlen($aImapCredentials['ProxyAuthPassword']))
{
$oMailClient
->Login($aImapCredentials['ProxyAuthUser'], $aImapCredentials['ProxyAuthPassword'],
$aImapCredentials['Login'], $aImapCredentials['UseAuthPlainIfSupported']);
}
else
{
$oMailClient->Login($aImapCredentials['Login'], $aImapCredentials['Password'], '',
$aImapCredentials['UseAuthPlainIfSupported']);
}
$bLogin = true;
}
$oPlugins->RunHook('event.imap-post-login', array($this, $aImapCredentials['UseAuth'], $bLogin, $aImapCredentials));
return $bLogin;
}
/**
* @param \RainLoop\Plugins\Manager $oPlugins
* @param \MailSo\Smtp\SmtpClient $oSmtpClient
* @param \RainLoop\Application $oConfig
*
* @return bool
*/
public function OutConnectAndLoginHelper($oPlugins, $oSmtpClient, $oConfig)
{
$bLogin = false;
$aSmtpCredentials = array(
'UseConnect' => true,
'UseAuth' => $this->DomainOutAuth(),
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $this->DomainOutHost(),
'Port' => $this->DomainOutPort(),
'Secure' => $this->DomainOutSecure(),
'Login' => $this->OutLogin(),
'Password' => $this->Password(),
'ProxyAuthUser' => $this->ProxyAuthUser(),
'ProxyAuthPassword' => $this->ProxyAuthPassword(),
'VerifySsl' => $this->DomainOutVerifySsl(!!$oConfig->Get('ssl', 'verify_certificate'))
);
$oPlugins->RunHook('filter.smtp-credentials', array($this, &$aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
if ($aSmtpCredentials['UseConnect'])
{
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'],
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure'], $aSmtpCredentials['VerifySsl']);
}
$oPlugins->RunHook('event.smtp-post-connect', array($this, $aSmtpCredentials['UseConnect'], $aSmtpCredentials));
$oPlugins->RunHook('event.smtp-pre-login', array($this, $aSmtpCredentials['UseAuth'], $aSmtpCredentials));
if ($aSmtpCredentials['UseAuth'])
{
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
$bLogin = true;
}
$oPlugins->RunHook('event.smtp-post-login', array($this, $aSmtpCredentials['UseAuth'], $bLogin, $aSmtpCredentials));
return $bLogin;
}
} }

View file

@ -621,7 +621,7 @@ class Actions
if (null === $this->oDomainProvider) if (null === $this->oDomainProvider)
{ {
$this->oDomainProvider = new \RainLoop\Providers\Domain( $this->oDomainProvider = new \RainLoop\Providers\Domain(
$this->fabrica('domain')); $this->fabrica('domain'), $this->Plugins());
} }
return $this->oDomainProvider; return $this->oDomainProvider;
@ -833,23 +833,41 @@ class Actions
* @param string $sEmail * @param string $sEmail
* @param string $sLogin * @param string $sLogin
* @param string $sPassword * @param string $sPassword
* @param bool $sSignMeToken = '' * @param string $sSignMeToken = ''
* @param bool $bThrowProvideException = false
* *
* @return \RainLoop\Account|null * @return \RainLoop\Account|null
*/ */
public function LoginProvide($sEmail, $sLogin, $sPassword, $sSignMeToken = '') public function LoginProvide($sEmail, $sLogin, $sPassword, $sSignMeToken = '', $bThrowProvideException = false)
{ {
$oResult = null; $oAccount = null;
if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword)) if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword))
{ {
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true); $oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true);
if ($oDomain instanceof \RainLoop\Domain && $oDomain->ValidateWhiteList($sEmail, $sLogin)) if ($oDomain instanceof \RainLoop\Domain)
{ {
$oResult = \RainLoop\Account::NewInstance($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken); if ($oDomain->ValidateWhiteList($sEmail, $sLogin))
{
$oAccount = \RainLoop\Account::NewInstance($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken);
$this->Plugins()->RunHook('filter.acount', array(&$oAccount));
if ($bThrowProvideException && !($oAccount instanceof \RainLoop\Account))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
}
}
else if ($bThrowProvideException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
}
}
else if ($bThrowProvideException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
} }
} }
return $oResult; return $oAccount;
} }
/** /**
@ -866,36 +884,30 @@ class Actions
if (!empty($sToken)) if (!empty($sToken))
{ {
$aAccountHash = \RainLoop\Utils::DecodeKeyValues($sToken); $aAccountHash = \RainLoop\Utils::DecodeKeyValues($sToken);
if (!empty($aAccountHash[0]) && 'token' === $aAccountHash[0] && 8 === \count($aAccountHash) && if (!empty($aAccountHash[0]) && 'token' === $aAccountHash[0] && // simple token validation
// !empty($aAccountHash[4]) && \RainLoop\Utils::Fingerprint() === $aAccountHash[4] && 8 <= \count($aAccountHash) && // length checking
!empty($aAccountHash[7]) && (!$bValidateShortToken || \RainLoop\Utils::GetShortToken() === $aAccountHash[7]) !empty($aAccountHash[7]) && // does short token exist
(!$bValidateShortToken || \RainLoop\Utils::GetShortToken() === $aAccountHash[7]) // check short token if needed
) )
{ {
$oAccount = $this->LoginProvide($aAccountHash[1], $aAccountHash[2], $aAccountHash[3], $oAccount = $this->LoginProvide($aAccountHash[1], $aAccountHash[2], $aAccountHash[3],
empty($aAccountHash[5]) ? '' : $aAccountHash[5]); empty($aAccountHash[5]) ? '' : $aAccountHash[5], $bThrowExceptionOnFalse);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
if (!empty($aAccountHash[8]) && !empty($aAccountHash[9])) // init proxy user/password
{
$oAccount->SetProxyAuthUser($aAccountHash[8]);
$oAccount->SetProxyAuthUser($aAccountHash[89]);
}
$this->Logger()->AddSecret($oAccount->Password()); $this->Logger()->AddSecret($oAccount->Password());
$this->Logger()->AddSecret($oAccount->ProxyAuthPassword());
$oAccount->SetParentEmail($aAccountHash[6]); $oAccount->SetParentEmail($aAccountHash[6]);
$oResult = $oAccount; $oResult = $oAccount;
} }
else
{
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($aAccountHash[1]), true);
if ($bThrowExceptionOnFalse)
{
if (!($oDomain instanceof \RainLoop\Domain))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
}
else if (!$oDomain->ValidateWhiteList($aAccountHash[1], $aAccountHash[2]))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
}
}
}
} }
else if ($bThrowExceptionOnFalse) else if ($bThrowExceptionOnFalse)
{ {
@ -1361,7 +1373,7 @@ class Actions
/** /**
* @param \RainLoop\Account $oAccount * @param \RainLoop\Account $oAccount
*/ */
public function AuthProcess($oAccount) public function AuthToken($oAccount)
{ {
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
@ -1385,12 +1397,7 @@ class Actions
{ {
try try
{ {
$this->MailClient() $oAccount->IncConnectAndLoginHelper($this->Plugins(), $this->MailClient(), $this->Config());
->Connect($oAccount->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
$oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure(),
$oAccount->Domain()->IncVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate')))
->Login($oAccount->IncLogin(), $oAccount->Password())
;
} }
catch (\RainLoop\Exceptions\ClientException $oException) catch (\RainLoop\Exceptions\ClientException $oException)
{ {
@ -1481,6 +1488,8 @@ class Actions
if (false === \strpos($sEmail, '@') || 0 === \strlen($sPassword)) if (false === \strpos($sEmail, '@') || 0 === \strlen($sPassword))
{ {
$this->loginErrorDelay();
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidInputArgument); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidInputArgument);
} }
@ -1491,28 +1500,33 @@ class Actions
$this->Logger()->AddSecret($sPassword); $this->Logger()->AddSecret($sPassword);
$oAccount = $this->LoginProvide($sEmail, $sLogin, $sPassword, $sSignMeToken); $this->Plugins()->RunHook('event.login-pre-login-provide', array());
if (!($oAccount instanceof \RainLoop\Account))
try
{ {
$this->loginErrorDelay(); $oAccount = $this->LoginProvide($sEmail, $sLogin, $sPassword, $sSignMeToken, true);
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true); if (!($oAccount instanceof \RainLoop\Account))
if (!($oDomain instanceof \RainLoop\Domain))
{ {
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
} }
else if (!$oDomain->ValidateWhiteList($sEmail, $sLogin))
{ $this->Plugins()->RunHook('event.login-post-login-provide', array(&$oAccount));
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
} if (!($oAccount instanceof \RainLoop\Account))
else
{ {
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
} }
} }
catch (\Exception $oException)
{
$this->loginErrorDelay();
throw $oException;
}
// Two factor auth // Two factor auth
if ($oAccount && $this->TwoFactorAuthProvider()->IsActive()) if ($this->TwoFactorAuthProvider()->IsActive())
{ {
$aData = $this->getTwoFactorInfo($oAccount->ParentEmailHelper()); $aData = $this->getTwoFactorInfo($oAccount->ParentEmailHelper());
if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable']) if ($aData && isset($aData['IsSet'], $aData['Enable']) && !empty($aData['Secret']) && $aData['IsSet'] && $aData['Enable'])
@ -1526,6 +1540,7 @@ class Actions
if (empty($sAdditionalCode)) if (empty($sAdditionalCode))
{ {
$this->Logger()->Write('TFA: Required Code for '.$oAccount->ParentEmailHelper().' account.'); $this->Logger()->Write('TFA: Required Code for '.$oAccount->ParentEmailHelper().' account.');
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountTwoFactorAuthRequired); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountTwoFactorAuthRequired);
} }
else else
@ -1553,6 +1568,7 @@ class Actions
if (!$bGood && !$this->TwoFactorAuthProvider()->VerifyCode($aData['Secret'], $sAdditionalCode)) if (!$bGood && !$this->TwoFactorAuthProvider()->VerifyCode($aData['Secret'], $sAdditionalCode))
{ {
$this->loginErrorDelay(); $this->loginErrorDelay();
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountTwoFactorAuthError); throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountTwoFactorAuthError);
} }
} }
@ -1567,6 +1583,7 @@ class Actions
catch (\Exception $oException) catch (\Exception $oException)
{ {
$this->loginErrorDelay(); $this->loginErrorDelay();
throw $oException; throw $oException;
} }
@ -1701,7 +1718,7 @@ class Actions
} }
} }
$this->AuthProcess($oAccount); $this->AuthToken($oAccount);
if ($oAccount && 0 < \strlen($sLanguage)) if ($oAccount && 0 < \strlen($sLanguage))
{ {
@ -1983,7 +2000,7 @@ class Actions
$oAccountToChange = $this->GetAccountFromCustomToken($aAccounts[$sParentEmail], false, false); $oAccountToChange = $this->GetAccountFromCustomToken($aAccounts[$sParentEmail], false, false);
if ($oAccountToChange) if ($oAccountToChange)
{ {
$this->AuthProcess($oAccountToChange); $this->AuthToken($oAccountToChange);
} }
} }
@ -4688,62 +4705,34 @@ class Actions
$oFrom = $oMessage->GetFrom(); $oFrom = $oMessage->GetFrom();
$sFrom = $oFrom instanceof \MailSo\Mime\Email ? $oFrom->GetEmail() : ''; $sFrom = $oFrom instanceof \MailSo\Mime\Email ? $oFrom->GetEmail() : '';
$sFrom = empty($sFrom) ? $oAccount->Email() : $sFrom;
$aSmtpCredentials = array( $aHiddenRcpt = array();
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(), $this->Plugins()->RunHook('filter.smtp-from', array($oAccount, $oMessage, &$sFrom));
'Host' => $oAccount->Domain()->OutHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
'Port' => $oAccount->Domain()->OutPort(),
'Secure' => $oAccount->Domain()->OutSecure(),
'UseAuth' => $oAccount->Domain()->OutAuth(),
'From' => empty($sFrom) ? $oAccount->Email() : $sFrom,
'Login' => $oAccount->OutLogin(),
'Password' => $oAccount->Password(),
'VerifySsl' => $oAccount->Domain()->OutVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate')),
'HiddenRcpt' => array()
);
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials)); if ($bAddHiddenRcpt)
if (!$bAddHiddenRcpt)
{ {
$aSmtpCredentials['HiddenRcpt'] = array(); $this->Plugins()->RunHook('filter.smtp-hidden-rcpt', array($oAccount, $oMessage, &$aHiddenRcpt));
} }
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = $bHookLogoutAndDisconnect = false; $bLoggined = $oAccount->OutConnectAndLoginHelper($this->Plugins(), $oSmtpClient, $this->Config());
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
&$oSmtpClient, $oMessage, &$oRcpt,
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData, &$bHookLogoutAndDisconnect));
if (!$bHookConnect) if ($oSmtpClient->IsConnected())
{ {
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'], if (!empty($sFrom))
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure'], $aSmtpCredentials['VerifySsl']);
}
if (!$bHookAuth)
{
if ($aSmtpCredentials['UseAuth'])
{ {
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']); $oSmtpClient->MailFrom($sFrom);
} }
}
if (!$bHookFrom)
{
$oSmtpClient->MailFrom($aSmtpCredentials['From']);
}
if (!$bHookTo)
{
$aRcpt =& $oRcpt->GetAsArray(); $aRcpt =& $oRcpt->GetAsArray();
foreach ($aRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($aRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
{ {
$oSmtpClient->Rcpt($oEmail->GetEmail()); $oSmtpClient->Rcpt($oEmail->GetEmail());
} }
if (isset($aSmtpCredentials['HiddenRcpt']) && is_array($aSmtpCredentials['HiddenRcpt'])) if ($bAddHiddenRcpt && \is_array($aHiddenRcpt) && 0 < \count($aHiddenRcpt))
{ {
foreach ($aSmtpCredentials['HiddenRcpt'] as $sEmail) foreach ($aHiddenRcpt as $sEmail)
{ {
if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail)) if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail))
{ {
@ -4751,16 +4740,15 @@ class Actions
} }
} }
} }
}
if (!$bHookData)
{
$oSmtpClient->DataWithStream($rMessageStream); $oSmtpClient->DataWithStream($rMessageStream);
}
if (!$bHookLogoutAndDisconnect) if ($bLoggined)
{ {
$oSmtpClient->LogoutAndDisconnect(); $oSmtpClient->Logout();
}
$oSmtpClient->Disconnect();
} }
} }
catch (\MailSo\Net\Exceptions\ConnectionException $oException) catch (\MailSo\Net\Exceptions\ConnectionException $oException)
@ -6672,12 +6660,7 @@ class Actions
try try
{ {
$this->MailClient() $oAccount->IncConnectAndLoginHelper($this->Plugins(), $this->MailClient(), $this->Config());
->Connect($oAccount->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
$oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure(),
$oAccount->Domain()->IncVerifySsl(!!$this->Config()->Get('ssl', 'verify_certificate')))
->Login($oAccount->IncLogin(), $oAccount->Password(), !!$this->Config()->Get('labs', 'use_imap_auth_plain'))
;
} }
catch (\MailSo\Net\Exceptions\ConnectionException $oException) catch (\MailSo\Net\Exceptions\ConnectionException $oException)
{ {

View file

@ -9,6 +9,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider
*/ */
private $oDriver; private $oDriver;
/**
* @var \RainLoop\Plugins\Manager
*/
private $oPlugins;
/** /**
* @var bool * @var bool
*/ */
@ -19,9 +24,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider
* *
* @return void * @return void
*/ */
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver) public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver,
\RainLoop\Plugins\Manager $oPlugins)
{ {
$this->oDriver = $oDriver; $this->oDriver = $oDriver;
$this->oPlugins = $oPlugins;
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface; $this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface;
} }
@ -42,7 +49,13 @@ class Domain extends \RainLoop\Providers\AbstractProvider
*/ */
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true) public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true)
{ {
return $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled); $oDomain = $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled);
if ($oDomain instanceof \RainLoop\Domain)
{
$this->oPlugins->RunHook('filter.domain', array(&$oDomain));
}
return $oDomain;
} }
/** /**

View file

@ -805,7 +805,7 @@ class ServiceActions
try try
{ {
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword); $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$bLogout = !($oAccount instanceof \RainLoop\Account); $bLogout = !($oAccount instanceof \RainLoop\Account);
} }
@ -843,7 +843,7 @@ class ServiceActions
try try
{ {
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword); $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$bLogout = !($oAccount instanceof \RainLoop\Account); $bLogout = !($oAccount instanceof \RainLoop\Account);
} }
catch (\Exception $oException) catch (\Exception $oException)
@ -878,7 +878,7 @@ class ServiceActions
try try
{ {
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword); $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$bLogout = !($oAccount instanceof \RainLoop\Account); $bLogout = !($oAccount instanceof \RainLoop\Account);
} }
catch (\Exception $oException) catch (\Exception $oException)
@ -994,7 +994,7 @@ class ServiceActions
if ($oAccountToLogin) if ($oAccountToLogin)
{ {
$this->oActions->AuthProcess($oAccountToLogin); $this->oActions->AuthToken($oAccountToLogin);
} }
} }
@ -1042,7 +1042,7 @@ class ServiceActions
{ {
$this->oActions->CheckMailConnection($oAccount); $this->oActions->CheckMailConnection($oAccount);
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$sAuthAccountHash = $this->oActions->GetSpecAuthToken(); $sAuthAccountHash = $this->oActions->GetSpecAuthToken();
} }

View file

@ -348,7 +348,7 @@ class Social
$oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']); $oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$iErrorCode = 0; $iErrorCode = 0;
} }
@ -495,7 +495,7 @@ class Social
$oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']); $oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$iErrorCode = 0; $iErrorCode = 0;
} }
@ -671,7 +671,7 @@ class Social
$oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']); $oAccount = $this->oActions->LoginProcess($aUserData['Email'], $aUserData['Password']);
if ($oAccount instanceof \RainLoop\Account) if ($oAccount instanceof \RainLoop\Account)
{ {
$this->oActions->AuthProcess($oAccount); $this->oActions->AuthToken($oAccount);
$iErrorCode = 0; $iErrorCode = 0;
} }