Admin panel forms improvement

Domain system  improvement
This commit is contained in:
RainLoop Team 2014-04-26 03:41:47 +04:00
parent 79721f60df
commit de0648a392
17 changed files with 265 additions and 179 deletions

View file

@ -203,11 +203,12 @@ AdminAjaxRemoteStorage.prototype.createOrUpdateDomain = function (fCallback,
});
};
AdminAjaxRemoteStorage.prototype.testConnectionForDomain = function (fCallback,
AdminAjaxRemoteStorage.prototype.testConnectionForDomain = function (fCallback, sName,
sIncHost, iIncPort, sIncSecure,
sOutHost, iOutPort, sOutSecure, bOutAuth)
{
this.defaultRequest(fCallback, 'AdminDomainTest', {
'Name': sName,
'IncHost': sIncHost,
'IncPort': iIncPort,
'IncSecure': sIncSecure,

View file

@ -26,6 +26,14 @@ function AdminDataStorage()
this.licenseError = ko.observable('');
this.licenseTrigger = ko.observable(false);
this.adminManLoading = ko.computed(function () {
return '000' !== [this.domainsLoading() ? '1' : '0', this.pluginsLoading() ? '1' : '0', this.packagesLoading() ? '1' : '0'].join('');
}, this);
this.adminManLoadingVisibility = ko.computed(function () {
return this.adminManLoading() ? 'visible' : 'hidden';
}, this).extend({'rateLimit': 300});
}
_.extend(AdminDataStorage.prototype, AbstractData.prototype);

View file

@ -11,6 +11,8 @@ function AdminPaneViewModel()
this.adminDomain = ko.observable(RL.settingsGet('AdminDomain'));
this.version = ko.observable(RL.settingsGet('Version'));
this.adminManLoadingVisibility = RL.data().adminManLoadingVisibility;
Knoin.constructorEnd(this);
}

View file

@ -35,20 +35,6 @@ function PopupsDomainViewModel()
this.smtpAuth = ko.observable(true);
this.whiteList = ko.observable('');
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.smtpServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
{
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
}
}, this);
this.headerText = ko.computed(function () {
var sName = this.name();
return this.edit() ? 'Edit Domain "' + sName + '"' :
@ -98,6 +84,7 @@ function PopupsDomainViewModel()
this.testing(true);
RL.remote().testConnectionForDomain(
_.bind(this.onTestConnectionResponse, this),
this.name(),
this.imapServer(),
this.imapPort(),
this.imapSecure(),
@ -112,6 +99,67 @@ function PopupsDomainViewModel()
this.whiteListPage(!this.whiteListPage());
});
// smart form improvements
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.smtpServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
{
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
}
}, this);
this.imapSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.imapPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (993 === iPort)
{
this.imapPort(143);
}
break;
case '1':
if (143 === iPort)
{
this.imapPort(993);
}
break;
}
}, this);
this.smtpSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.smtpPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (465 === iPort || 587 === iPort)
{
this.smtpPort(25);
}
break;
case '1':
if (25 === iPort || 587 === iPort)
{
this.smtpPort(465);
}
break;
case '2':
if (25 === iPort || 465 === iPort)
{
this.smtpPort(587);
}
break;
}
}, this);
Knoin.constructorEnd(this);
}

View file

@ -166,8 +166,9 @@ class Account
*/
public function Hash()
{
return md5(APP_SALT.$this->Email().APP_SALT.$this->oDomain->IncHost().APP_SALT.$this->oDomain->IncPort().
APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT);
return md5(APP_SALT.$this->Email().APP_SALT.$this->oDomain->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($this->Email())).
APP_SALT.$this->oDomain->IncPort().APP_SALT.$this->Password().APP_SALT.'0'.APP_SALT.$this->ParentEmail().APP_SALT);
}
/**

View file

@ -231,10 +231,8 @@ class Actions
$oResult = new \RainLoop\Providers\Login\DefaultLogin();
break;
case 'domain':
// \RainLoop\Providers\Domain\DomainSimpleInterface
// \RainLoop\Providers\Domain\DomainAdminInterface
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains',
$this->Cacher());
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains', $this->Cacher());
break;
case 'address-book':
// \RainLoop\Providers\AddressBook\AddressBookInterface
@ -849,7 +847,7 @@ class Actions
if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword))
{
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true);
if ($oDomain instanceof \RainLoop\Domain && !$oDomain->Disabled() && $oDomain->ValidateWhiteList($sEmail, $sLogin))
if ($oDomain instanceof \RainLoop\Domain && $oDomain->ValidateWhiteList($sEmail, $sLogin))
{
$oResult = \RainLoop\Account::NewInstance($sEmail, $sLogin, $sPassword, $oDomain, $sSignMeToken);
}
@ -892,7 +890,7 @@ class Actions
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($aAccountHash[1]), true);
if ($bThrowExceptionOnFalse)
{
if (!($oDomain instanceof \RainLoop\Domain) || $oDomain->Disabled())
if (!($oDomain instanceof \RainLoop\Domain))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
}
@ -1374,7 +1372,7 @@ class Actions
$this->loginErrorDelay();
$oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true);
if (!($oDomain instanceof \RainLoop\Domain) || $oDomain->Disabled())
if (!($oDomain instanceof \RainLoop\Domain))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
}
@ -1439,7 +1437,8 @@ class Actions
try
{
$this->MailClient()
->Connect($oAccount->Domain()->IncHost(), $oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure())
->Connect($oAccount->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
$oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure())
->Login($oAccount->IncLogin(), $oAccount->Password())
;
}
@ -2458,9 +2457,9 @@ class Actions
$oImapClient = \MailSo\Imap\ImapClient::NewInstance()->SetLogger($this->Logger());
$oImapClient->SetTimeOuts(5);
$iTime = microtime(true);
$oImapClient->Connect($oDomain->IncHost(), $oDomain->IncPort(), $oDomain->IncSecure());
$iImapTime = microtime(true) - $iTime;
$iTime = \microtime(true);
$oImapClient->Connect($oDomain->IncHost($oDomain->Name()), $oDomain->IncPort(), $oDomain->IncSecure());
$iImapTime = \microtime(true) - $iTime;
$oImapClient->Disconnect();
$bImapResult = true;
}
@ -2474,9 +2473,9 @@ class Actions
$oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance()->SetLogger($this->Logger());
$oSmtpClient->SetTimeOuts(5);
$iTime = microtime(true);
$oSmtpClient->Connect($oDomain->OutHost(), $oDomain->OutPort(), '127.0.0.1', $oDomain->OutSecure());
$iSmtpTime = microtime(true) - $iTime;
$iTime = \microtime(true);
$oSmtpClient->Connect($oDomain->OutHost($oDomain->Name()), $oDomain->OutPort(), '127.0.0.1', $oDomain->OutSecure());
$iSmtpTime = \microtime(true) - $iTime;
$oSmtpClient->Disconnect();
$bSmtpResult = true;
}
@ -4249,7 +4248,7 @@ class Actions
$aSmtpCredentials = array(
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $oAccount->Domain()->OutHost(),
'Host' => $oAccount->Domain()->OutHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
'Port' => $oAccount->Domain()->OutPort(),
'Secure' => $oAccount->Domain()->OutSecure(),
'UseAuth' => $oAccount->Domain()->OutAuth(),
@ -6160,7 +6159,8 @@ class Actions
try
{
$this->MailClient()
->Connect($oAccount->Domain()->IncHost(), $oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure())
->Connect($oAccount->Domain()->IncHost(\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email())),
$oAccount->Domain()->IncPort(), $oAccount->Domain()->IncSecure())
->Login($oAccount->IncLogin(), $oAccount->Password(), !!$this->Config()->Get('labs', 'use_imap_auth_plain'))
;
}

View file

@ -63,11 +63,6 @@ class Domain
*/
private $sWhiteList;
/**
* @var bool
*/
private $bDisabled;
/**
* @param string $sName
* @param string $sIncHost
@ -95,7 +90,6 @@ class Domain
$this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth;
$this->sWhiteList = \trim($sWhiteList);
$this->bDisabled = false;
}
/**
@ -125,6 +119,7 @@ class Domain
}
/**
* @param string $sName
* @param array $aDomain
*
* @return \RainLoop\Domain|null
@ -171,14 +166,6 @@ class Domain
return str_replace('"', '\\"', $sStr);
}
/**
* @param bool0 $bDisabled
*/
public function SetDisabled($bDisabled)
{
$this->bDisabled = (bool) $bDisabled;
}
public function Normalize()
{
$this->sIncHost = \trim($this->sIncHost);
@ -299,11 +286,13 @@ class Domain
}
/**
* @param string $sRealDomainName = ''
*
* @return string
*/
public function IncHost()
public function IncHost($sRealDomainName = '')
{
return $this->sIncHost;
return 0 < \strlen($sRealDomainName) ? \str_replace('{domain:name}', $sRealDomainName, $this->sIncHost) : $this->sIncHost;
}
/**
@ -331,11 +320,12 @@ class Domain
}
/**
* @param string $sRealDomainName = ''
* @return string
*/
public function OutHost()
public function OutHost($sRealDomainName = '')
{
return $this->sOutHost;
return 0 < \strlen($sRealDomainName) ? \str_replace('{domain:name}', $sRealDomainName, $this->sOutHost) : $this->sOutHost;
}
/**
@ -378,14 +368,6 @@ class Domain
return $this->sWhiteList;
}
/**
* @return bool
*/
public function Disabled()
{
return $this->bDisabled;
}
/**
* @param string $sEmail
* @param string $sLogin = ''

View file

@ -35,13 +35,13 @@ class Domain extends \RainLoop\Providers\AbstractProvider
/**
* @param string $sName
* @param bool $bDefaultOnNull = false
* @param bool $bFindWithWildCard = false
*
* @return \RainLoop\Domain|null
*/
public function Load($sName, $bDefaultOnNull = false)
public function Load($sName, $bFindWithWildCard = false)
{
return $this->oDriver->Load($sName, $bDefaultOnNull);
return $this->oDriver->Load($sName, $bFindWithWildCard);
}
/**
@ -122,6 +122,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
$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);

View file

@ -141,15 +141,22 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
public function Load($sName, $bFindWithWildCard = false)
{
$mResult = null;
$sDisabled = '';
$sFoundedValue = '';
$sName = \strtolower($sName);
$sRealFileName = $this->codeFileName($sName);
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini'))
if (\file_exists($this->sDomainPath.'/disabled'))
{
$aDomain = @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini');
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
}
if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini') &&
(0 === \strlen($sDisabled) || false === \strpos(\strtolower(','.$sDisabled.','), \strtolower(','.$sName.','))))
{
$aDomain = @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini');
// fix misspellings (#119)
if (\is_array($aDomain))
{
@ -184,20 +191,10 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface
{
if (\RainLoop\Plugins\Helper::ValidateWildcardValues($sName, $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
if ($mResult instanceof \RainLoop\Domain)
{
if (\file_exists($this->sDomainPath.'/disabled'))
{
$sDisabled = @\file_get_contents($this->sDomainPath.'/disabled');
if (false !== $sDisabled && 0 < \strlen($sDisabled))
{
$sDisabledName = 0 < \strlen($sFoundedValue) ? $sFoundedValue : $sName;
$mResult->SetDisabled(false !== \strpos(strtolower(','.$sDisabled.','), \strtolower(','.$sDisabledName.',')));
if (0 === \strlen($sDisabled) || false === \strpos(\strtolower(','.$sDisabled.','), \strtolower(','.$sFoundedValue.',')))
{
$mResult = $this->Load($sFoundedValue, false);
}
}
}
}

View file

@ -1,49 +1,50 @@
<?php
namespace RainLoop\Providers\Domain;
interface DomainAdminInterface extends DomainInterface
{
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable);
/**
* @param string $sName
*
* @return \RainLoop\Domain | null
*/
public function Load($sName);
/**
* @param \RainLoop\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain);
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName);
/**
* @param int $iOffset
* @param int $iLimit = 20
*
* @return array
*/
public function GetList($iOffset, $iLimit = 20);
/**
* @return int
*/
public function Count();
<?php
namespace RainLoop\Providers\Domain;
interface DomainAdminInterface extends DomainInterface
{
/**
* @param string $sName
* @param bool $bDisable
*
* @return bool
*/
public function Disable($sName, $bDisable);
/**
* @param string $sName
* @param bool $bFindWithWildCard = false
*
* @return \RainLoop\Domain | null
*/
public function Load($sName, $bFindWithWildCard = false);
/**
* @param \RainLoop\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain);
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName);
/**
* @param int $iOffset
* @param int $iLimit = 20
*
* @return array
*/
public function GetList($iOffset, $iLimit = 20);
/**
* @return int
*/
public function Count();
}

View file

@ -1,13 +0,0 @@
<?php
namespace RainLoop\Providers\Domain;
interface DomainSimpleInterface extends DomainInterface
{
/**
* @param string $sName
*
* @return \RainLoop\Domain | null
*/
public function Load($sName);
}

View file

@ -2,6 +2,8 @@
<div class="b-toolbar g-ui-user-select-none">
<div class="btn-toolbar">
<h4 class="pull-left">
<i class="icon-spinner animated" style="margin-top: 2px" data-bind="style: {'visibility': adminManLoadingVisibility }"></i>
&nbsp;&nbsp;
Admin Panel
&nbsp;&nbsp;
(<span data-bind="text: adminDomain"></span>&nbsp;&ndash;&nbsp;<span data-bind="text: version"></span>)

View file

@ -3,21 +3,20 @@
Domains
</div>
<div>
<blockquote>
<p class="muted">
List of domains webmail is allowed to access.
</p>
</blockquote>
<a class="btn" data-bind="click: createDomain">
<i class="icon-plus"></i>
&nbsp;&nbsp;
Add Domain
</a>
<div class="process-place" data-bind="style: {'visibility': visibility }">
<i class="icon-spinner animated"></i>
&nbsp;&nbsp;
loading...
</div>
<br />
<br />
<blockquote>
<p class="muted">
List of domains webmail is allowed to access.
<br />
Click on the name to configure the domain.
</p>
</blockquote>
<table class="table table-hover b-admin-domains-list-table" data-bind="i18nUpdate: domains">
<colgroup>
<col />

View file

@ -4,23 +4,17 @@
Cannot access the repository at the moment.
</div>
<!--
<div class="alert" data-bind="visible: !packagesMainUpdatable() && !packagesLoading()">
Unable to update RainLoop Webmail source!
</div>
-->
<div class="alert" data-bind="visible: '' !== packagesError()">
<button type="button" class="close" data-bind="click: function () { packagesError('') }">&times;</button>
<span data-bind="text: packagesError"></span>
</div>
<div class="process-place" data-bind="style: {'visibility': visibility }">
<!-- <div class="process-place" data-bind="style: {'visibility': visibility }">
<i class="icon-spinner animated"></i>
&nbsp;&nbsp;
loading...
</div>
-->
<div data-bind="visible: 0 < packagesAvailableForUpdate().length">
<div class="legend">
Available for Update (<span data-bind="text: packagesAvailableForUpdate().length"></span>)

View file

@ -7,16 +7,16 @@
</div>
</div>
<div class="process-place" data-bind="style: {'visibility': visibility }">
<!-- <div class="process-place" data-bind="style: {'visibility': visibility }">
<i class="icon-spinner animated"></i>
&nbsp;&nbsp;
loading...
</div>
</div>-->
<div class="legend">
Plugins
</div>
<div>
<label data-bind="click: function () { enabledPlugins(!enabledPlugins()); }">
<i data-bind="css: enabledPlugins() ? 'icon-checkbox-checked' : 'icon-checkbox-unchecked'"></i>

View file

@ -4938,20 +4938,6 @@ function PopupsDomainViewModel()
this.smtpAuth = ko.observable(true);
this.whiteList = ko.observable('');
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.smtpServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
{
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
}
}, this);
this.headerText = ko.computed(function () {
var sName = this.name();
return this.edit() ? 'Edit Domain "' + sName + '"' :
@ -5001,6 +4987,7 @@ function PopupsDomainViewModel()
this.testing(true);
RL.remote().testConnectionForDomain(
_.bind(this.onTestConnectionResponse, this),
this.name(),
this.imapServer(),
this.imapPort(),
this.imapSecure(),
@ -5015,6 +5002,67 @@ function PopupsDomainViewModel()
this.whiteListPage(!this.whiteListPage());
});
// smart form improvements
this.imapServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.name() && '' === this.imapServer())
{
this.imapServer(this.name().replace(/[.]?[*][.]?/g, ''));
}
}, this);
this.smtpServerFocus.subscribe(function (bValue) {
if (bValue && '' !== this.imapServer() && '' === this.smtpServer())
{
this.smtpServer(this.imapServer().replace(/imap/ig, 'smtp'));
}
}, this);
this.imapSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.imapPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (993 === iPort)
{
this.imapPort(143);
}
break;
case '1':
if (143 === iPort)
{
this.imapPort(993);
}
break;
}
}, this);
this.smtpSecure.subscribe(function (sValue) {
var iPort = Utils.pInt(this.smtpPort());
sValue = Utils.pString(sValue);
switch (sValue)
{
case '0':
if (465 === iPort || 587 === iPort)
{
this.smtpPort(25);
}
break;
case '1':
if (25 === iPort || 587 === iPort)
{
this.smtpPort(465);
}
break;
case '2':
if (25 === iPort || 465 === iPort)
{
this.smtpPort(587);
}
break;
}
}, this);
Knoin.constructorEnd(this);
}
@ -5660,6 +5708,8 @@ function AdminPaneViewModel()
this.adminDomain = ko.observable(RL.settingsGet('AdminDomain'));
this.version = ko.observable(RL.settingsGet('Version'));
this.adminManLoadingVisibility = RL.data().adminManLoadingVisibility;
Knoin.constructorEnd(this);
}
@ -6809,6 +6859,14 @@ function AdminDataStorage()
this.licenseError = ko.observable('');
this.licenseTrigger = ko.observable(false);
this.adminManLoading = ko.computed(function () {
return '000' !== [this.domainsLoading() ? '1' : '0', this.pluginsLoading() ? '1' : '0', this.packagesLoading() ? '1' : '0'].join('');
}, this);
this.adminManLoadingVisibility = ko.computed(function () {
return this.adminManLoading() ? 'visible' : 'hidden';
}, this).extend({'rateLimit': 300});
}
_.extend(AdminDataStorage.prototype, AbstractData.prototype);
@ -7294,11 +7352,12 @@ AdminAjaxRemoteStorage.prototype.createOrUpdateDomain = function (fCallback,
});
};
AdminAjaxRemoteStorage.prototype.testConnectionForDomain = function (fCallback,
AdminAjaxRemoteStorage.prototype.testConnectionForDomain = function (fCallback, sName,
sIncHost, iIncPort, sIncSecure,
sOutHost, iOutPort, sOutSecure, bOutAuth)
{
this.defaultRequest(fCallback, 'AdminDomainTest', {
'Name': sName,
'IncHost': sIncHost,
'IncPort': iIncPort,
'IncSecure': sIncSecure,

File diff suppressed because one or more lines are too long