mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Add alias support (domains)
This commit is contained in:
parent
a1d829c697
commit
28a125426a
26 changed files with 1014 additions and 92 deletions
|
|
@ -4082,25 +4082,14 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
$iOffset = (int) $this->GetActionParam('Offset', 0);
|
||||
$iLimit = (int) $this->GetActionParam('Limit', 20);
|
||||
$sSearch = (string) $this->GetActionParam('Search', '');
|
||||
$bIncludeAliases = '1' === (string) $this->GetActionParam('IncludeAliases', '1');
|
||||
|
||||
$iOffset = 0;
|
||||
$sSearch = '';
|
||||
$iLimit = $this->Config()->Get('labs', 'domain_list_limit', 99);
|
||||
|
||||
$sSearch = \trim($sSearch);
|
||||
|
||||
if ($iOffset < 0)
|
||||
{
|
||||
$iOffset = 0;
|
||||
}
|
||||
|
||||
if ($iLimit < 20)
|
||||
{
|
||||
$iLimit = 20;
|
||||
}
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__,
|
||||
$this->DomainProvider()->GetList($iOffset, $iLimit, $sSearch));
|
||||
$this->DomainProvider()->GetList($iOffset, $iLimit, $sSearch, $bIncludeAliases));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -4140,6 +4129,19 @@ NewThemeLink IncludeCss LoadingDescriptionEsc TemplatesLink LangLink IncludeBack
|
|||
$oDomain instanceof \RainLoop\Model\Domain ? $this->DomainProvider()->Save($oDomain) : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function DoAdminDomainAliasSave()
|
||||
{
|
||||
$this->IsAdminLoggined();
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, $this->DomainProvider()->SaveAlias(
|
||||
(string) $this->GetActionParam('Name', ''),
|
||||
(string) $this->GetActionParam('Alias', '')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -93,6 +93,11 @@ class Domain
|
|||
*/
|
||||
private $sWhiteList;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sAliasName;
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sIncHost
|
||||
|
|
@ -138,6 +143,7 @@ class Domain
|
|||
$this->bSieveAllowRaw = false;
|
||||
|
||||
$this->sWhiteList = \trim($sWhiteList);
|
||||
$this->sAliasName = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -510,6 +516,25 @@ class Domain
|
|||
return $this->sWhiteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function AliasName()
|
||||
{
|
||||
return $this->sAliasName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAliasName
|
||||
* @return self
|
||||
*/
|
||||
public function SetAliasName($sAliasName)
|
||||
{
|
||||
$this->sAliasName = $sAliasName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sLogin = ''
|
||||
|
|
@ -558,7 +583,8 @@ class Domain
|
|||
'OutShortLogin' => $this->OutShortLogin(),
|
||||
'OutAuth' => $this->OutAuth(),
|
||||
'OutUsePhpMail' => $this->OutUsePhpMail(),
|
||||
'WhiteList' => $this->WhiteList()
|
||||
'WhiteList' => $this->WhiteList(),
|
||||
'AliasName' => $this->AliasName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,12 +44,13 @@ class Domain extends \RainLoop\Providers\AbstractProvider
|
|||
* @param string $sName
|
||||
* @param bool $bFindWithWildCard = false
|
||||
* @param bool $bCheckDisabled = true
|
||||
* @param bool $bCheckAliases = true
|
||||
*
|
||||
* @return \RainLoop\Model\Domain|null
|
||||
*/
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true)
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
|
||||
{
|
||||
$oDomain = $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled);
|
||||
$oDomain = $this->oDriver->Load($sName, $bFindWithWildCard, $bCheckDisabled, $bCheckAliases);
|
||||
if ($oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
$this->oPlugins->RunHook('filter.domain', array(&$oDomain));
|
||||
|
|
@ -68,6 +69,22 @@ class Domain extends \RainLoop\Providers\AbstractProvider
|
|||
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sAlias
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SaveAlias($sName, $sAlias)
|
||||
{
|
||||
if ($this->Load($sName, false, false))
|
||||
{
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
||||
}
|
||||
|
||||
return $this->bAdmin ? $this->oDriver->SaveAlias($sName, $sAlias) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
|
|
@ -93,12 +110,25 @@ class Domain extends \RainLoop\Providers\AbstractProvider
|
|||
* @param int $iOffset = 0
|
||||
* @param int $iLimit = 20
|
||||
* @param string $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '')
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
return $this->bAdmin ? $this->oDriver->GetList($iOffset, $iLimit, $sSearch) : array();
|
||||
$sSearch = \trim($sSearch);
|
||||
|
||||
if ($iOffset < 0)
|
||||
{
|
||||
$iOffset = 0;
|
||||
}
|
||||
|
||||
if ($iLimit < 20)
|
||||
{
|
||||
$iLimit = 20;
|
||||
}
|
||||
|
||||
return $this->bAdmin ? $this->oDriver->GetList($iOffset, $iLimit, $sSearch, $bIncludeAliases) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,6 +214,79 @@ class Domain extends \RainLoop\Providers\AbstractProvider
|
|||
return $oDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Actions $oActions
|
||||
* @param string $sNameForTest = ''
|
||||
*
|
||||
* @return \RainLoop\Model\Domain | null
|
||||
*/
|
||||
public function CreateNewAliasFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
|
||||
{
|
||||
$oDomain = null;
|
||||
|
||||
if ($this->bAdmin)
|
||||
{
|
||||
$bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
|
||||
$sName = (string) $oActions->GetActionParam('Name', '');
|
||||
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
|
||||
$iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
|
||||
$iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$bIncShortLogin = '1' === (string) $oActions->GetActionParam('IncShortLogin', '0');
|
||||
$bUseSieve = '1' === (string) $oActions->GetActionParam('UseSieve', '0');
|
||||
$bSieveAllowRaw = '1' === (string) $oActions->GetActionParam('SieveAllowRaw', '0');
|
||||
$sSieveHost = (string) $oActions->GetActionParam('SieveHost', '');
|
||||
$iSievePort = (int) $oActions->GetActionParam('SievePort', 4190);
|
||||
$iSieveSecure = (int) $oActions->GetActionParam('SieveSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$sOutHost = (string) $oActions->GetActionParam('OutHost', '');
|
||||
$iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
|
||||
$iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
|
||||
$bOutShortLogin = '1' === (string) $oActions->GetActionParam('OutShortLogin', '0');
|
||||
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
|
||||
$bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
|
||||
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
|
||||
|
||||
if (0 < \strlen($sName) && 0 < strlen($sNameForTest) && false === \strpos($sName, '*'))
|
||||
{
|
||||
$sNameForTest = '';
|
||||
}
|
||||
|
||||
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
|
||||
{
|
||||
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
|
||||
if ($oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
if ($bCreate)
|
||||
{
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oDomain->UpdateInstance(
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oDomain = \RainLoop\Model\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
|
||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutUsePhpMail,
|
||||
$sWhiteList);
|
||||
}
|
||||
}
|
||||
|
||||
if ($oDomain)
|
||||
{
|
||||
$oDomain->SetSieveAllowRaw($bSieveAllowRaw);
|
||||
}
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -55,44 +55,6 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bDisable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Disable($sName, $bDisable)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
|
||||
$sFile = '';
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aNames = \explode(',', $sFile);
|
||||
if ($bDisable)
|
||||
{
|
||||
\array_push($aNames, $sName);
|
||||
$aResult = $aNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($aNames as $sItem)
|
||||
{
|
||||
if ($sName !== $sItem)
|
||||
{
|
||||
$aResult[] = $sItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -146,10 +108,11 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
* @param string $sName
|
||||
* @param bool $bFindWithWildCard = false
|
||||
* @param bool $bCheckDisabled = true
|
||||
* @param bool $bCheckAliases = true
|
||||
*
|
||||
* @return \RainLoop\Model\Domain|null
|
||||
*/
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true)
|
||||
public function Load($sName, $bFindWithWildCard = false, $bCheckDisabled = true, $bCheckAliases = true)
|
||||
{
|
||||
$mResult = null;
|
||||
|
||||
|
|
@ -167,6 +130,17 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$aDomain = \RainLoop\Utils::CustomParseIniFile($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
// if ($bCheckAliases && !empty($aDomain['alias']))
|
||||
// {
|
||||
// $oDomain = $this->Load($aDomain['alias'], false, false, false);
|
||||
// if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
// {
|
||||
// $oDomain->SetAliasName($sName);
|
||||
// }
|
||||
//
|
||||
// return $oDomain;
|
||||
// }
|
||||
|
||||
// fix misspellings (#119)
|
||||
if (\is_array($aDomain))
|
||||
{
|
||||
|
|
@ -194,6 +168,21 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
|
||||
$mResult = \RainLoop\Model\Domain::NewInstanceFromDomainConfigArray($sName, $aDomain);
|
||||
}
|
||||
else if ($bCheckAliases && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias') &&
|
||||
(!$bCheckDisabled || 0 === \strlen($sDisabled) || false === \strpos(','.$sDisabled.',', ','.\MailSo\Base\Utils::IdnToAscii($sName, true).',')))
|
||||
{
|
||||
$sAlias = \trim(\file_get_contents($this->sDomainPath.'/'.$sRealFileName.'.alias'));
|
||||
if (!empty($sAlias))
|
||||
{
|
||||
$oDomain = $this->Load($sAlias, false, false, false);
|
||||
if ($oDomain && $oDomain instanceof \RainLoop\Model\Domain)
|
||||
{
|
||||
$oDomain->SetAliasName($sName);
|
||||
}
|
||||
|
||||
return $oDomain;
|
||||
}
|
||||
}
|
||||
else if ($bFindWithWildCard)
|
||||
{
|
||||
$sNames = $this->getWildcardDomainsLine();
|
||||
|
|
@ -231,6 +220,63 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param string $sAlias
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function SaveAlias($sName, $sAlias)
|
||||
{
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if ($this->oCacher)
|
||||
{
|
||||
$this->oCacher->Delete($this->wildcardDomainsCacheKey());
|
||||
}
|
||||
|
||||
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.alias', $sAlias);
|
||||
return \is_int($mResult) && 0 < $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param bool $bDisable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function Disable($sName, $bDisable)
|
||||
{
|
||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
||||
|
||||
$sFile = '';
|
||||
if (\file_exists($this->sDomainPath.'/disabled'))
|
||||
{
|
||||
$sFile = @\file_get_contents($this->sDomainPath.'/disabled');
|
||||
}
|
||||
|
||||
$aResult = array();
|
||||
$aNames = \explode(',', $sFile);
|
||||
if ($bDisable)
|
||||
{
|
||||
\array_push($aNames, $sName);
|
||||
$aResult = $aNames;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($aNames as $sItem)
|
||||
{
|
||||
if ($sName !== $sItem)
|
||||
{
|
||||
$aResult[] = $sItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = \array_unique($aResult);
|
||||
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
|
|
@ -241,9 +287,16 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
$bResult = true;
|
||||
$sRealFileName = $this->codeFileName($sName);
|
||||
|
||||
if (0 < \strlen($sName) && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
if (0 < \strlen($sName))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
|
||||
}
|
||||
else if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.alias'))
|
||||
{
|
||||
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.alias');
|
||||
}
|
||||
}
|
||||
|
||||
if ($bResult)
|
||||
|
|
@ -260,36 +313,51 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $iOffset
|
||||
* @param int $iOffset = 0
|
||||
* @param int $iLimit = 20
|
||||
* @param int $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset, $iLimit = 20)
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
$aResult = array();
|
||||
$aWildCards = array();
|
||||
$aList = \glob($this->sDomainPath.'/*.ini');
|
||||
$aAliases = array();
|
||||
|
||||
$aList = \glob($this->sDomainPath.'/*.{ini,alias}', GLOB_BRACE);
|
||||
|
||||
foreach ($aList as $sFile)
|
||||
{
|
||||
$sName = \substr(\basename($sFile), 0, -4);
|
||||
$sName = \basename($sFile);
|
||||
$bAlias = '.alias' === \substr($sName, -6);
|
||||
|
||||
$sName = \preg_replace('/\.(ini|alias)$/', '', $sName);
|
||||
$sName = $this->codeFileName($sName, true);
|
||||
|
||||
if (false === \strpos($sName, '*'))
|
||||
if ($bAlias)
|
||||
{
|
||||
$aResult[] = $sName;
|
||||
if ($bIncludeAliases)
|
||||
{
|
||||
$aAliases[] = $sName;
|
||||
}
|
||||
}
|
||||
else if (false !== \strpos($sName, '*'))
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aWildCards[] = $sName;
|
||||
$aResult[] = $sName;
|
||||
}
|
||||
}
|
||||
|
||||
\sort($aResult, SORT_STRING);
|
||||
\sort($aAliases, SORT_STRING);
|
||||
\rsort($aWildCards, SORT_STRING);
|
||||
|
||||
$aResult = \array_merge($aResult, $aWildCards);
|
||||
$aResult = \array_merge($aResult, $aAliases, $aWildCards);
|
||||
|
||||
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
|
||||
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
|
||||
|
|
@ -314,7 +382,10 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
$aReturn = array();
|
||||
foreach ($aResult as $sName)
|
||||
{
|
||||
$aReturn[$sName] = !\in_array($sName, $aDisabledNames);
|
||||
$aReturn[$sName] = array(
|
||||
!\in_array($sName, $aDisabledNames),
|
||||
\in_array($sName, $aAliases)
|
||||
);
|
||||
}
|
||||
|
||||
return $aReturn;
|
||||
|
|
@ -322,11 +393,12 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
|||
|
||||
/**
|
||||
* @param string $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count()
|
||||
public function Count($sSearch = '', $bIncludeAliases = true)
|
||||
{
|
||||
return \count($this->GetList(0, 999));
|
||||
return \count($this->GetList(0, 999, $sSearch, $bIncludeAliases));
|
||||
}
|
||||
}
|
||||
|
|
@ -37,15 +37,20 @@ interface DomainAdminInterface extends DomainInterface
|
|||
public function Delete($sName);
|
||||
|
||||
/**
|
||||
* @param int $iOffset
|
||||
* @param int $iOffset = 0
|
||||
* @param int $iLimit = 20
|
||||
* @param int $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetList($iOffset, $iLimit = 20);
|
||||
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '', $bIncludeAliases = true);
|
||||
|
||||
/**
|
||||
* @param string $sSearch = ''
|
||||
* @param bool $bIncludeAliases = true
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function Count();
|
||||
public function Count($sSearch = '', $bIncludeAliases = true);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue