Change password plugins fixes

Small fixes
This commit is contained in:
RainLoop Team 2014-08-31 00:04:11 +04:00
parent 4cc1a0b0b7
commit c7108a74e0
13 changed files with 339 additions and 378 deletions

View file

@ -131,7 +131,7 @@ html.rgba.textshadow {
}
.tooltip-inner {
max-width: 400px;
max-width: 380px;
text-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
padding: 5px 10px;
border-radius: 2px;

View file

@ -1,51 +1,47 @@
<?php
class ChangePasswordExampleDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var array
*/
private $aDomains = array();
/**
* @param array $aDomains
*
* @return bool
*/
public function SetAllowedDomains($aDomains)
{
if (\is_array($aDomains) && 0 < \count($aDomains))
{
$this->aDomains = $aDomains;
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
$bResult = false;
// TODO
return $bResult;
}
<?php
class ChangePasswordExampleDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sAllowedEmails = '';
/**
* @param string $sAllowedEmails
*
* @return \ChangePasswordExampleDriver
*/
public function SetAllowedEmails($sAllowedEmails)
{
$this->sAllowedEmails = $sAllowedEmails;
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Email() &&
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
$bResult = false;
// TODO
return $bResult;
}
}

View file

@ -1 +1 @@
1.0
1.1

View file

@ -1,49 +1,41 @@
<?php
class ChangePasswordExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
include_once __DIR__.'/ChangePasswordExampleDriver.php';
$oProvider = new ChangePasswordExampleDriver();
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
$this->Config()->Get('plugin', 'domains', ''))));
if (0 < \strlen($sDomains))
{
$aDomains = \explode(' ', $sDomains);
$oProvider->SetAllowedDomains($aDomains);
}
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('domain1.com domain2.com')
);
}
<?php
class ChangePasswordExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
include_once __DIR__.'/ChangePasswordExampleDriver.php';
$oProvider = new ChangePasswordExampleDriver();
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
->SetDefaultValue('*')
);
}
}

View file

@ -1,159 +1,155 @@
<?php
class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sHost = '';
/**
* @var int
*/
private $iPost = 2087;
/**
* @var string
*/
private $sUser = '';
/**
* @var string
*/
private $sPassword = '';
/**
* @var array
*/
private $aDomains = array();
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sHost
* @param int $iPost
* @param bool $sSsl
* @param string $sUser
* @param string $sPassword
*
* @return \CpanleChangePasswordDriver
*/
public function SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword)
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->sSsl = $sSsl;
$this->sUser = $sUser;
$this->sPassword = $sPassword;
return $this;
}
/**
* @param array $aDomains
*
* @return \CpanleChangePasswordDriver
*/
public function SetAllowedDomains($aDomains)
{
if (\is_array($aDomains) && 0 < \count($aDomains))
{
$this->aDomains = $aDomains;
}
return $this;
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \CpanleChangePasswordDriver
*/
public function SetLogger($oLogger)
{
if ($oLogger instanceof \MailSo\Log\Logger)
{
$this->oLogger = $oLogger;
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
if ($this->oLogger)
{
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
}
include_once __DIR__.'/xmlapi.php';
$bResult = false;
if (!empty($this->sHost) && 0 < $this->iPost &&
0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) &&
$oAccount && \class_exists('xmlapi'))
{
try
{
$oXmlApi = new \xmlapi($this->sHost);
$oXmlApi->set_port($this->iPost);
$oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
$oXmlApi->set_debug(false);
$oXmlApi->set_output('json');
$oXmlApi->set_http_client('curl');
$oXmlApi->password_auth($this->sUser, $this->sPassword);
$sEmail = $oAccount->Email();
$aArgs = array(
'email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail),
'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail),
'password' => $sNewPassword
);
$sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
if ($sResult)
{
$aResult = @\json_decode($sResult, true);
$bResult = isset($aResult['cpanelresult']['data'][0]['result']) &&
!!$aResult['cpanelresult']['data'][0]['result'];
}
if (!$bResult && $this->oLogger)
{
$this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::ERROR);
}
}
catch (\Exception $oException)
{
if ($this->oLogger)
{
$this->oLogger->WriteException($oException);
}
}
}
return $bResult;
}
<?php
class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sHost = '';
/**
* @var int
*/
private $iPost = 2087;
/**
* @var string
*/
private $sUser = '';
/**
* @var string
*/
private $sPassword = '';
/**
* @var string
*/
private $sAllowedEmails = '';
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sHost
* @param int $iPost
* @param bool $sSsl
* @param string $sUser
* @param string $sPassword
*
* @return \CpanelChangePasswordDriver
*/
public function SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword)
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->sSsl = $sSsl;
$this->sUser = $sUser;
$this->sPassword = $sPassword;
return $this;
}
/**
* @param string $sAllowedEmails
*
* @return \CpanelChangePasswordDriver
*/
public function SetAllowedEmails($sAllowedEmails)
{
$this->sAllowedEmails = $sAllowedEmails;
return $this;
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \CpanelChangePasswordDriver
*/
public function SetLogger($oLogger)
{
if ($oLogger instanceof \MailSo\Log\Logger)
{
$this->oLogger = $oLogger;
}
return $this;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return bool
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Email() &&
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
if ($this->oLogger)
{
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
}
include_once __DIR__.'/xmlapi.php';
$bResult = false;
if (!empty($this->sHost) && 0 < $this->iPost &&
0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) &&
$oAccount && \class_exists('xmlapi'))
{
try
{
$oXmlApi = new \xmlapi($this->sHost);
$oXmlApi->set_port($this->iPost);
$oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
$oXmlApi->set_debug(false);
$oXmlApi->set_output('json');
$oXmlApi->set_http_client('curl');
$oXmlApi->password_auth($this->sUser, $this->sPassword);
$sEmail = $oAccount->Email();
$aArgs = array(
'email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail),
'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail),
'password' => $sNewPassword
);
$sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
if ($sResult)
{
$aResult = @\json_decode($sResult, true);
$bResult = isset($aResult['cpanelresult']['data'][0]['result']) &&
!!$aResult['cpanelresult']['data'][0]['result'];
}
if (!$bResult && $this->oLogger)
{
$this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::ERROR);
}
}
catch (\Exception $oException)
{
if ($this->oLogger)
{
$this->oLogger->WriteException($oException);
}
}
}
return $bResult;
}
}

View file

@ -1 +1 @@
1.1
1.2

View file

@ -1,73 +1,65 @@
<?php
class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
$sHost = \trim($this->Config()->Get('plugin', 'host', ''));
$iPost = (int) $this->Config()->Get('plugin', 'port', 2087);
$sUser = (string) $this->Config()->Get('plugin', 'user', '');
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
$sSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
{
include_once __DIR__.'/CpanelChangePasswordDriver.php';
$oProvider = new CpanelChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword);
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
$this->Config()->Get('plugin', 'domains', ''))));
if (0 < \strlen($sDomains))
{
$aDomains = \explode(' ', $sDomains);
$oProvider->SetAllowedDomains($aDomains);
}
}
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('cPanel Host')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('cPanel Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(2087),
\RainLoop\Plugins\Property::NewInstance('ssl')->SetLabel('Use SSL')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('cPanel User')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('cPanel Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('domain1.com domain2.com')
);
}
<?php
class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
{
public function Init()
{
$this->addHook('main.fabrica', 'MainFabrica');
}
/**
* @param string $sName
* @param mixed $oProvider
*/
public function MainFabrica($sName, &$oProvider)
{
switch ($sName)
{
case 'change-password':
$sHost = \trim($this->Config()->Get('plugin', 'host', ''));
$iPost = (int) $this->Config()->Get('plugin', 'port', 2087);
$sUser = (string) $this->Config()->Get('plugin', 'user', '');
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
$sSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
{
include_once __DIR__.'/CpanelChangePasswordDriver.php';
$oProvider = new CpanelChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword);
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
}
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('cPanel Host')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('cPanel Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(2087),
\RainLoop\Plugins\Property::NewInstance('ssl')->SetLabel('Use SSL')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('cPanel User')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('cPanel Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
->SetDefaultValue('*')
);
}
}

View file

@ -11,22 +11,22 @@ class HmailserverChangePasswordDriver implements \RainLoop\Providers\ChangePassw
* @var string
*/
private $sPassword = '';
/**
* @var array
* @var string
*/
private $aDomains = array();
private $sAllowedEmails = '';
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sLogin
* @param string $sPassword
*
* @return \CpanleChangePasswordDriver
* @return \HmailserverChangePasswordDriver
*/
public function SetConfig($sLogin, $sPassword)
{
@ -37,24 +37,20 @@ class HmailserverChangePasswordDriver implements \RainLoop\Providers\ChangePassw
}
/**
* @param array $aDomains
* @param string $sAllowedEmails
*
* @return \CpanleChangePasswordDriver
* @return \HmailserverChangePasswordDriver
*/
public function SetAllowedDomains($aDomains)
public function SetAllowedEmails($sAllowedEmails)
{
if (\is_array($aDomains) && 0 < \count($aDomains))
{
$this->aDomains = $aDomains;
}
$this->sAllowedEmails = $sAllowedEmails;
return $this;
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \CpanleChangePasswordDriver
* @return \HmailserverChangePasswordDriver
*/
public function SetLogger($oLogger)
{
@ -73,8 +69,8 @@ class HmailserverChangePasswordDriver implements \RainLoop\Providers\ChangePassw
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
return $oAccount && $oAccount->Email() &&
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
}
/**

View file

@ -1 +1 @@
1.1
1.2

View file

@ -40,15 +40,7 @@ class HmailserverChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
$oProvider = new HmailserverChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sLogin, $sPassword);
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
$this->Config()->Get('plugin', 'domains', ''))));
if (0 < \strlen($sDomains))
{
$aDomains = \explode(' ', $sDomains);
$oProvider->SetAllowedDomains($aDomains);
}
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
}
break;
@ -66,10 +58,10 @@ class HmailserverChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('HmailServer Admin Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
\RainLoop\Plugins\Property::NewInstance('allowed_emails')->SetLabel('Allowed emails')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('domain1.com domain2.com')
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
->SetDefaultValue('*')
);
}
}

View file

@ -82,7 +82,7 @@ abstract class NetClient
$this->bUnreadBuffer = false;
$this->bRunningCallback = false;
$this->oLogger = null;
$this->__AUTOLOGOUT__ = true;
$this->sResponseBuffer = '';
@ -238,11 +238,6 @@ abstract class NetClient
{
@\stream_set_timeout($this->rConnect, $this->iSocketTimeOut);
}
if (\MailSo\Base\Utils::FunctionExistsAndEnabled('stream_set_blocking'))
{
@\stream_set_blocking($this->rConnect, 1);
}
}
}
@ -339,7 +334,7 @@ abstract class NetClient
{
$bFake = false;
}
if ($bFake)
{
$sFakeRaw .= "\r\n";
@ -413,6 +408,8 @@ abstract class NetClient
}
else
{
// $this->writeLog('Stream Meta: '.
// \print_r($aSocketStatus, true), \MailSo\Log\Enumerations\Type::ERROR);
$this->writeLogException(
new Exceptions\SocketReadException(),
\MailSo\Log\Enumerations\Type::ERROR, true);

View file

@ -637,7 +637,7 @@
filter: Alpha(Opacity=30);
}
/*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */
/* =============================================================================
@ -1150,7 +1150,7 @@ table {
border-spacing: 0;
border-collapse: collapse;
}
@charset "UTF-8";
@font-face {
@ -1522,7 +1522,7 @@ table {
.icon-resize-out:before {
content: "\e06d";
}
/** initial setup **/
.nano {
/*
@ -1638,7 +1638,7 @@ table {
.nano > .pane2.active > .slider2 {
background-color: rgba(0, 0, 0, 0.4);
}
/* Magnific Popup CSS */
.mfp-bg {
position: fixed;
@ -2094,7 +2094,7 @@ img.mfp-img {
padding-top: 0;
}
/* overlay at start */
.mfp-fade.mfp-bg {
@ -2135,7 +2135,7 @@ img.mfp-img {
-ms-transform: translateX(50px);
transform: translateX(50px);
}
.simple-pace {
pointer-events: none;
@ -2210,7 +2210,7 @@ img.mfp-img {
transform: translate(-32px, 0);
transform: translate(-32px, 0);
}
}
}
.inputosaurus-container {
display: inline-block;
margin: 0 5px 0 0;
@ -2275,7 +2275,7 @@ img.mfp-img {
.inputosaurus-input-hidden {
display: none;
}
.flag-wrapper {
display: inline-block;
width: 24px;
@ -2397,7 +2397,7 @@ img.mfp-img {
.flag.flag-zh-hk {
background-position: -208px -22px;
}
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
.clearfix {
*zoom: 1;
@ -6295,7 +6295,7 @@ html.rgba.textshadow .btn.btn-primary {
}
.tooltip .tooltip-inner {
padding: 5px 10px;
max-width: 400px;
max-width: 380px;
border-radius: 2px;
text-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

File diff suppressed because one or more lines are too long