Experimental support for wildcards in the domain name.

This commit is contained in:
RainLoop Team 2014-02-08 03:28:11 +04:00
parent ab07d102f9
commit 93e09effba
5 changed files with 276 additions and 253 deletions

View file

@ -22,6 +22,8 @@ function PopupsDomainViewModel()
this.smtpServerFocus = ko.observable(false); this.smtpServerFocus = ko.observable(false);
this.name = ko.observable(''); this.name = ko.observable('');
this.name.focused = ko.observable(false);
this.imapServer = ko.observable(''); this.imapServer = ko.observable('');
this.imapPort = ko.observable(Consts.Values.ImapDefaulPort); this.imapPort = ko.observable(Consts.Values.ImapDefaulPort);
this.imapSecure = ko.observable(Enums.ServerSecure.None); this.imapSecure = ko.observable(Enums.ServerSecure.None);
@ -36,7 +38,7 @@ function PopupsDomainViewModel()
this.imapServerFocus.subscribe(function (bValue) { this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer()) if (bValue && '' !== this.name() && '' === this.imapServer())
{ {
this.imapServer(this.name()); this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
} }
}, this); }, this);
@ -186,6 +188,14 @@ PopupsDomainViewModel.prototype.onShow = function (oDomain)
} }
}; };
PopupsDomainViewModel.prototype.onFocus = function ()
{
if ('' === this.name())
{
this.name.focused(true);
}
};
PopupsDomainViewModel.prototype.onBuild = function () PopupsDomainViewModel.prototype.onBuild = function ()
{ {
var self = this; var self = this;
@ -208,6 +218,8 @@ PopupsDomainViewModel.prototype.clearForm = function ()
this.savingError(''); this.savingError('');
this.name(''); this.name('');
this.name.focused(false);
this.imapServer(''); this.imapServer('');
this.imapPort(Consts.Values.ImapDefaulPort); this.imapPort(Consts.Values.ImapDefaulPort);
this.imapSecure(Enums.ServerSecure.None); this.imapSecure(Enums.ServerSecure.None);

View file

@ -1,247 +1,246 @@
<?php <?php
namespace RainLoop\Providers\Domain; namespace RainLoop\Providers\Domain;
class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{ {
/** /**
* @var string * @var string
*/ */
protected $sDomainPath; protected $sDomainPath;
/** /**
* @param string $sDomainPath * @param string $sDomainPath
* *
* @return void * @return void
*/ */
public function __construct($sDomainPath) public function __construct($sDomainPath)
{ {
$this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/'); $this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/');
} }
/** /**
* @param string $sName * @param string $sName
* @param bool $bBack = false * @param bool $bBack = false
* *
* @return string * @return string
*/ */
public function codeFileName($sName, $bBack = false) public function codeFileName($sName, $bBack = false)
{ {
if ($bBack && 'default' === $sName) if ($bBack && 'default' === $sName)
{ {
return '*'; return '*';
} }
else if (!$bBack && '*' === $sName) else if (!$bBack && '*' === $sName)
{ {
return 'default'; return 'default';
} }
$sName = \strtolower($sName); $sName = \strtolower($sName);
return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName); return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName);
} }
/** /**
* @param string $sName * @param string $sName
* @param bool $bDisable * @param bool $bDisable
* *
* @return bool * @return bool
*/ */
public function Disable($sName, $bDisable) public function Disable($sName, $bDisable)
{ {
$sFile = ''; $sFile = '';
if (\file_exists($this->sDomainPath.'/disabled')) if (\file_exists($this->sDomainPath.'/disabled'))
{ {
$sFile = @\file_get_contents($this->sDomainPath.'/disabled'); $sFile = @\file_get_contents($this->sDomainPath.'/disabled');
} }
$aResult = array(); $aResult = array();
$aNames = \explode(',', $sFile); $aNames = \explode(',', $sFile);
if ($bDisable) if ($bDisable)
{ {
\array_push($aNames, $sName); \array_push($aNames, $sName);
$aResult = $aNames; $aResult = $aNames;
} }
else else
{ {
foreach ($aNames as $sItem) foreach ($aNames as $sItem)
{ {
if ($sName !== $sItem) if ($sName !== $sItem)
{ {
$aResult[] = $sItem; $aResult[] = $sItem;
} }
} }
} }
$aResult = \array_unique($aResult); $aResult = \array_unique($aResult);
return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', ')); return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', '));
} }
/** /**
* @param string $sName * @param string $sName
* @param bool $bFindWithWildCard = false * @param bool $bFindWithWildCard = false
* *
* @return \RainLoop\Domain | null * @return \RainLoop\Domain | null
*/ */
public function Load($sName, $bFindWithWildCard = false) public function Load($sName, $bFindWithWildCard = false)
{ {
$mResult = null; $mResult = null;
$sName = \strtolower($sName);
$sRealFileName = $this->codeFileName($sName); $sName = \strtolower($sName);
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini')) $sRealFileName = $this->codeFileName($sName);
{
$mResult = \RainLoop\Domain::NewInstanceFromDomainConfigArray( if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
$sName, @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini')); {
$mResult = \RainLoop\Domain::NewInstanceFromDomainConfigArray(
if ($mResult instanceof \RainLoop\Domain) $sName, @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini'));
{ }
if (\file_exists($this->sDomainPath.'/disabled')) else if ($bFindWithWildCard)
{ {
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled'); $sNames = '';
if (false !== $sDisabled && 0 < \strlen($sDisabled)) $aNames = array();
{
$mResult->SetDisabled(false !== \strpos(strtolower(','.$sDisabled.','), \strtolower(','.$sName.','))); $aList = \glob($this->sDomainPath.'/*.ini');
} foreach ($aList as $sFile)
} {
} $sName = \strtolower(\substr(\basename($sFile), 0, -4));
} if ('default' === $sName || false !== strpos($sName, '_wildcard_'))
else if ($bFindWithWildCard) {
{ $aNames[] = $this->codeFileName($sName, true);
// TODO }
// $sNames = ''; }
// $aNames = array();
// if (0 < \count($aNames))
// $aList = \glob($this->sDomainPath.'/*.ini'); {
// foreach ($aList as $sFile) \rsort($aNames, SORT_STRING);
// { $sNames = \implode(' ', $aNames);
// $sName = \strtolower(\substr(\basename($sFile), 0, -4)); }
// if ('default' === $sName || false !== strpos($sName, '_wildcard_'))
// { if (0 < \strlen($sNames))
// $aNames[] = $this->codeFileName($sName, true); {
// } $sFoundedValue = '';
// } if (\RainLoop\Plugins\Helper::ValidateWildcardValues($sName, $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
// {
// if (0 < \count($aNames)) $mResult = $this->Load($sFoundedValue, false);
// { }
// \rsort($sNames, SORT_STRING); }
// $sNames = \implode(' ', $aNames); }
// }
// if ($mResult instanceof \RainLoop\Domain)
// if (0 < \strlen($sNames)) {
// { if (\file_exists($this->sDomainPath.'/disabled'))
// $sFoundedValue = ''; {
// if (\RainLoop\Plugins\Helper::ValidateWildcardValues($sName, $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue)) $sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
// { if (false !== $sDisabled && 0 < \strlen($sDisabled))
// $mResult = $this->Load($sFoundedValue, false); {
// } $mResult->SetDisabled(false !== \strpos(strtolower(','.$sDisabled.','), \strtolower(','.$sName.',')));
// } }
}
$mResult = $this->Load('default', false); }
}
return $mResult;
return $mResult; }
}
/**
/** * @param \RainLoop\Domain $oDomain
* @param \RainLoop\Domain $oDomain *
* * @return bool
* @return bool */
*/ public function Save(\RainLoop\Domain $oDomain)
public function Save(\RainLoop\Domain $oDomain) {
{ $sName = \strtolower($oDomain->Name());
$sName = \strtolower($oDomain->Name()); $sRealFileName = $this->codeFileName($sName);
$sRealFileName = $this->codeFileName($sName);
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString());
$mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString()); return \is_int($mResult) && 0 < $mResult;
return \is_int($mResult) && 0 < $mResult; }
}
/**
/** * @param string $sName
* @param string $sName *
* * @return bool
* @return bool */
*/ public function Delete($sName)
public function Delete($sName) {
{ $bResult = true;
$bResult = true; $sName = \strtolower($sName);
$sName = \strtolower($sName); $sRealFileName = $this->codeFileName($sName);
$sRealFileName = $this->codeFileName($sName);
if (0 < \strlen($sName) && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
if (0 < \strlen($sName) && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini')) {
{ $bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini');
$bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini'); }
}
if ($bResult)
if ($bResult) {
{ $this->Disable($sName, false);
$this->Disable($sName, false); }
}
return $bResult;
return $bResult; }
}
/**
/** * @param int $iOffset
* @param int $iOffset * @param int $iLimit = 20
* @param int $iLimit = 20 *
* * @return array
* @return array */
*/ public function GetList($iOffset, $iLimit = 20)
public function GetList($iOffset, $iLimit = 20) {
{ $aResult = array();
$aResult = array(); $aWildCards = array();
$aWildCards = array(); $aList = \glob($this->sDomainPath.'/*.ini');
$aList = \glob($this->sDomainPath.'/*.ini');
foreach ($aList as $sFile)
foreach ($aList as $sFile) {
{ $sName = \strtolower(\substr(\basename($sFile), 0, -4));
$sName = \strtolower(\substr(\basename($sFile), 0, -4)); $sName = $this->codeFileName($sName, true);
$sName = $this->codeFileName($sName, true); if (false === \strpos($sName, '*'))
if (false === \strpos($sName, '*')) {
{ $aResult[] = $sName;
$aResult[] = $sName; }
} else
else {
{ $aWildCards[] = $sName;
$aWildCards[] = $sName; }
} }
}
\sort($aResult, SORT_STRING);
\sort($aResult, SORT_STRING); \rsort($aWildCards, SORT_STRING);
\rsort($aWildCards, SORT_STRING);
$aResult = \array_merge($aResult, $aWildCards);
$aResult = \array_merge($aResult, $aWildCards);
$iOffset = (0 > $iOffset) ? 0 : $iOffset;
$iOffset = (0 > $iOffset) ? 0 : $iOffset; $iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aResult = \array_slice($aResult, $iOffset, $iLimit);
$aDisabledNames = array();
$aDisabledNames = array(); if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled'))
if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled')) {
{ $sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled'); if (false !== $sDisabled && 0 < strlen($sDisabled))
if (false !== $sDisabled && 0 < strlen($sDisabled)) {
{ $aDisabledNames = \explode(',', strtolower($sDisabled));
$aDisabledNames = \explode(',', strtolower($sDisabled)); $aDisabledNames = \array_unique($aDisabledNames);
$aDisabledNames = \array_unique($aDisabledNames); }
} }
}
$aReturn = array();
$aReturn = array(); foreach ($aResult as $sName)
foreach ($aResult as $sName) {
{ $aReturn[$sName] = !\in_array(\strtolower($sName), $aDisabledNames);
$aReturn[$sName] = !\in_array(\strtolower($sName), $aDisabledNames); }
}
return $aReturn;
return $aReturn; }
}
/**
/** * @param string $sSearch = ''
* @param string $sSearch = '' *
* * @return int
* @return int */
*/ public function Count()
public function Count() {
{ return \count($this->GetList(0, 999));
return \count($this->GetList(0, 999)); }
}
} }

View file

@ -8,9 +8,9 @@
<form class="form-horizontal domain-form" action="#/" onsubmit="return false;"> <form class="form-horizontal domain-form" action="#/" onsubmit="return false;">
<div class="row" data-bind="visible: !edit()"> <div class="row" data-bind="visible: !edit()">
<div class="span8"> <div class="span8">
Name Name <span style="color: #aaa">(wildcard supported)</span>
<br /> <br />
<input type="text" data-bind="value: name, valueUpdate: 'afterkeydown'" /> <input type="text" data-bind="value: name, hasfocus: name.focused, valueUpdate: 'afterkeydown'" />
<span class="error-desc" data-bind="text: savingError"></span> <span class="error-desc" data-bind="text: savingError"></span>
</div> </div>
</div> </div>
@ -87,7 +87,7 @@
List of users webmail is allowed to access. List of users webmail is allowed to access.
Use a space as delimiter. Use a space as delimiter.
</div> </div>
<textarea class="input-xxlarge" style="width: 600px" rows="8" data-bind="value: whiteList"></textarea> <textarea class="input-xxlarge" style="width: 600px" rows="8" data-bind="value: whiteList" tabindex="-1"></textarea>
</div> </div>
</div> </div>
</form> </form>

View file

@ -4498,6 +4498,8 @@ function PopupsDomainViewModel()
this.smtpServerFocus = ko.observable(false); this.smtpServerFocus = ko.observable(false);
this.name = ko.observable(''); this.name = ko.observable('');
this.name.focused = ko.observable(false);
this.imapServer = ko.observable(''); this.imapServer = ko.observable('');
this.imapPort = ko.observable(Consts.Values.ImapDefaulPort); this.imapPort = ko.observable(Consts.Values.ImapDefaulPort);
this.imapSecure = ko.observable(Enums.ServerSecure.None); this.imapSecure = ko.observable(Enums.ServerSecure.None);
@ -4512,7 +4514,7 @@ function PopupsDomainViewModel()
this.imapServerFocus.subscribe(function (bValue) { this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer()) if (bValue && '' !== this.name() && '' === this.imapServer())
{ {
this.imapServer(this.name()); this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
} }
}, this); }, this);
@ -4662,6 +4664,14 @@ PopupsDomainViewModel.prototype.onShow = function (oDomain)
} }
}; };
PopupsDomainViewModel.prototype.onFocus = function ()
{
if ('' === this.name())
{
this.name.focused(true);
}
};
PopupsDomainViewModel.prototype.onBuild = function () PopupsDomainViewModel.prototype.onBuild = function ()
{ {
var self = this; var self = this;
@ -4684,6 +4694,8 @@ PopupsDomainViewModel.prototype.clearForm = function ()
this.savingError(''); this.savingError('');
this.name(''); this.name('');
this.name.focused(false);
this.imapServer(''); this.imapServer('');
this.imapPort(Consts.Values.ImapDefaulPort); this.imapPort(Consts.Values.ImapDefaulPort);
this.imapSecure(Enums.ServerSecure.None); this.imapSecure(Enums.ServerSecure.None);

File diff suppressed because one or more lines are too long