mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 08:57:03 +03:00
Merge DomainAdminInterface into DomainInterface
This commit is contained in:
parent
3251611c6d
commit
398c77eb35
5 changed files with 66 additions and 96 deletions
|
|
@ -238,7 +238,7 @@ class Actions
|
||||||
$mResult = new Providers\Login\DefaultLogin();
|
$mResult = new Providers\Login\DefaultLogin();
|
||||||
break;
|
break;
|
||||||
case 'domain':
|
case 'domain':
|
||||||
// Providers\Domain\DomainAdminInterface
|
// Providers\Domain\DomainInterface
|
||||||
$mResult = new Providers\Domain\DefaultDomain(APP_PRIVATE_DATA . 'domains', $this->Cacher());
|
$mResult = new Providers\Domain\DefaultDomain(APP_PRIVATE_DATA . 'domains', $this->Cacher());
|
||||||
break;
|
break;
|
||||||
case 'filters':
|
case 'filters':
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,11 @@ class Domain extends AbstractProvider
|
||||||
*/
|
*/
|
||||||
private $oPlugins;
|
private $oPlugins;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $bAdmin;
|
|
||||||
|
|
||||||
public function __construct(Domain\DomainInterface $oDriver,
|
public function __construct(Domain\DomainInterface $oDriver,
|
||||||
\RainLoop\Plugins\Manager $oPlugins)
|
\RainLoop\Plugins\Manager $oPlugins)
|
||||||
{
|
{
|
||||||
$this->oDriver = $oDriver;
|
$this->oDriver = $oDriver;
|
||||||
$this->oPlugins = $oPlugins;
|
$this->oPlugins = $oPlugins;
|
||||||
$this->bAdmin = $this->oDriver instanceof Domain\DomainAdminInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function IsAdmin() : bool
|
|
||||||
{
|
|
||||||
return $this->bAdmin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true, bool $bCheckAliases = true) : ?\RainLoop\Model\Domain
|
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true, bool $bCheckAliases = true) : ?\RainLoop\Model\Domain
|
||||||
|
|
@ -45,7 +34,7 @@ class Domain extends AbstractProvider
|
||||||
|
|
||||||
public function Save(\RainLoop\Model\Domain $oDomain) : bool
|
public function Save(\RainLoop\Model\Domain $oDomain) : bool
|
||||||
{
|
{
|
||||||
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
|
return $this->oDriver->Save($oDomain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SaveAlias(string $sName, string $sAlias) : bool
|
public function SaveAlias(string $sName, string $sAlias) : bool
|
||||||
|
|
@ -55,80 +44,77 @@ class Domain extends AbstractProvider
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->bAdmin ? $this->oDriver->SaveAlias($sName, $sAlias) : false;
|
return $this->oDriver->SaveAlias($sName, $sAlias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Delete(string $sName) : bool
|
public function Delete(string $sName) : bool
|
||||||
{
|
{
|
||||||
return $this->bAdmin ? $this->oDriver->Delete($sName) : false;
|
return $this->oDriver->Delete($sName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Disable(string $sName, bool $bDisabled) : bool
|
public function Disable(string $sName, bool $bDisabled) : bool
|
||||||
{
|
{
|
||||||
return $this->bAdmin ? $this->oDriver->Disable($sName, $bDisabled) : false;
|
return $this->oDriver->Disable($sName, $bDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetList(bool $bIncludeAliases = true) : array
|
public function GetList(bool $bIncludeAliases = true) : array
|
||||||
{
|
{
|
||||||
return $this->bAdmin ? $this->oDriver->GetList($bIncludeAliases) : array();
|
return $this->oDriver->GetList($bIncludeAliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, string $sNameForTest = null) : ?\RainLoop\Model\Domain
|
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, string $sNameForTest = null) : ?\RainLoop\Model\Domain
|
||||||
{
|
{
|
||||||
$oDomain = null;
|
$oDomain = null;
|
||||||
|
|
||||||
if ($this->bAdmin)
|
$sName = (string) $oActions->GetActionParam('Name', '');
|
||||||
|
|
||||||
|
if (\strlen($sName) && $sNameForTest && !\str_contains($sName, '*'))
|
||||||
{
|
{
|
||||||
$sName = (string) $oActions->GetActionParam('Name', '');
|
$sNameForTest = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (\strlen($sName) && $sNameForTest && !\str_contains($sName, '*'))
|
if (\strlen($sName) || $sNameForTest)
|
||||||
|
{
|
||||||
|
$bCreate = !empty($oActions->GetActionParam('Create', 0));
|
||||||
|
$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');
|
||||||
|
$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');
|
||||||
|
$bOutSetSender = '1' === (string) $oActions->GetActionParam('OutSetSender', '0');
|
||||||
|
$bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
|
||||||
|
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
|
||||||
|
|
||||||
|
$oDomain = $sNameForTest ? null : $this->Load($sName);
|
||||||
|
if ($oDomain instanceof \RainLoop\Model\Domain)
|
||||||
{
|
{
|
||||||
$sNameForTest = null;
|
if ($bCreate)
|
||||||
|
{
|
||||||
|
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oDomain = new \RainLoop\Model\Domain($sNameForTest ?: $sName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\strlen($sName) || $sNameForTest)
|
$sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost);
|
||||||
{
|
$sSieveHost = \MailSo\Base\Utils::IdnToAscii($sSieveHost);
|
||||||
$bCreate = !empty($oActions->GetActionParam('Create', 0));
|
$sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost);
|
||||||
$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');
|
|
||||||
$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');
|
|
||||||
$bOutSetSender = '1' === (string) $oActions->GetActionParam('OutSetSender', '0');
|
|
||||||
$bOutUsePhpMail = '1' === (string) $oActions->GetActionParam('OutUsePhpMail', '0');
|
|
||||||
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
|
|
||||||
|
|
||||||
$oDomain = $sNameForTest ? null : $this->Load($sName);
|
$oDomain->SetConfig(
|
||||||
if ($oDomain instanceof \RainLoop\Model\Domain)
|
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
||||||
{
|
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
||||||
if ($bCreate)
|
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutSetSender, $bOutUsePhpMail,
|
||||||
{
|
$sWhiteList);
|
||||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$oDomain = new \RainLoop\Model\Domain($sNameForTest ?: $sName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sIncHost = \MailSo\Base\Utils::IdnToAscii($sIncHost);
|
|
||||||
$sSieveHost = \MailSo\Base\Utils::IdnToAscii($sSieveHost);
|
|
||||||
$sOutHost = \MailSo\Base\Utils::IdnToAscii($sOutHost);
|
|
||||||
|
|
||||||
$oDomain->SetConfig(
|
|
||||||
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
|
|
||||||
$bUseSieve, $sSieveHost, $iSievePort, $iSieveSecure,
|
|
||||||
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $bOutSetSender, $bOutUsePhpMail,
|
|
||||||
$sWhiteList);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $oDomain;
|
return $oDomain;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace RainLoop\Providers\Domain;
|
namespace RainLoop\Providers\Domain;
|
||||||
|
|
||||||
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
class DefaultDomain implements DomainInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
|
@ -22,25 +22,17 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
|
||||||
|
|
||||||
public function codeFileName(string $sName, bool $bBack = false) : string
|
public function codeFileName(string $sName, bool $bBack = false) : string
|
||||||
{
|
{
|
||||||
if ($bBack && 'default' === $sName)
|
if ($bBack && 'default' === $sName) {
|
||||||
{
|
|
||||||
return '*';
|
return '*';
|
||||||
}
|
}
|
||||||
else if (!$bBack && '*' === $sName)
|
|
||||||
{
|
if (!$bBack && '*' === $sName) {
|
||||||
return 'default';
|
return 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bBack)
|
return $bBack
|
||||||
{
|
? \str_replace('_wildcard_', '*', \MailSo\Base\Utils::IdnToUtf8($sName, true))
|
||||||
$sName = \MailSo\Base\Utils::IdnToUtf8($sName, true);
|
: \str_replace('*', '_wildcard_', \MailSo\Base\Utils::IdnToAscii($sName, true));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sName = \MailSo\Base\Utils::IdnToAscii($sName, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function wildcardDomainsCacheKey() : string
|
private function wildcardDomainsCacheKey() : string
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\Domain;
|
|
||||||
|
|
||||||
interface DomainAdminInterface extends DomainInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public function Disable(string $sName, bool $bDisable) : bool;
|
|
||||||
|
|
||||||
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true) : ?\RainLoop\Model\Domain;
|
|
||||||
|
|
||||||
public function Save(\RainLoop\Model\Domain $oDomain) : bool;
|
|
||||||
|
|
||||||
public function Delete(string $sName) : bool;
|
|
||||||
|
|
||||||
public function GetList(bool $bIncludeAliases = true) : array;
|
|
||||||
}
|
|
||||||
|
|
@ -4,4 +4,13 @@ namespace RainLoop\Providers\Domain;
|
||||||
|
|
||||||
interface DomainInterface
|
interface DomainInterface
|
||||||
{
|
{
|
||||||
}
|
public function Disable(string $sName, bool $bDisable) : bool;
|
||||||
|
|
||||||
|
public function Load(string $sName, bool $bFindWithWildCard = false, bool $bCheckDisabled = true) : ?\RainLoop\Model\Domain;
|
||||||
|
|
||||||
|
public function Save(\RainLoop\Model\Domain $oDomain) : bool;
|
||||||
|
|
||||||
|
public function Delete(string $sName) : bool;
|
||||||
|
|
||||||
|
public function GetList(bool $bIncludeAliases = true) : array;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue