"cpanel-change-password" plugin improvements

This commit is contained in:
RainLoop Team 2014-09-24 02:02:20 +04:00
parent d8dc6ee5ec
commit 67678017a8
4 changed files with 45 additions and 17 deletions

View file

@ -12,6 +12,11 @@ class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\C
*/
private $iPost = 2087;
/**
* @var bool
*/
private $bSsl = true;
/**
* @var string
*/
@ -35,17 +40,17 @@ class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\C
/**
* @param string $sHost
* @param int $iPost
* @param bool $sSsl
* @param bool $bSsl
* @param string $sUser
* @param string $sPassword
*
* @return \CpanelChangePasswordDriver
*/
public function SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword)
public function SetConfig($sHost, $iPost, $bSsl, $sUser, $sPassword)
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->sSsl = $sSsl;
$this->bSsl = !!$bSsl;
$this->sUser = $sUser;
$this->sPassword = $sPassword;
@ -103,32 +108,48 @@ class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\C
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
}
include_once __DIR__.'/xmlapi.php';
if (!\class_exists('xmlapi'))
{
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'))
{
$sEmail = $oAccount->Email();
$sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
$sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
$sHost = $this->sHost;
$sHost = \str_replace('{user:domain}', $sEmailDomain, $sHost);
$sUser = $this->sUser;
$sUser = \str_replace('{user:email}', $sEmail, $sUser);
$sUser = \str_replace('{user:login}', $sEmailUser, $sUser);
$sPassword = $this->sPassword;
$sPassword = \str_replace('{user:password}', $oAccount->Password(), $sPassword);
try
{
$oXmlApi = new \xmlapi($this->sHost);
$oXmlApi = new \xmlapi($sHost);
$oXmlApi->set_port($this->iPost);
$oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
$oXmlApi->set_protocol($this->bSsl ? 'https' : 'http');
$oXmlApi->set_debug(false);
$oXmlApi->set_output('json');
// $oXmlApi->set_http_client('fopen');
$oXmlApi->set_http_client('curl');
$oXmlApi->password_auth($this->sUser, $this->sPassword);
$sEmail = $oAccount->Email();
$oXmlApi->password_auth($sUser, $sPassword);
$aArgs = array(
'email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail),
'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail),
'email' => $sEmailUser,
'domain' => $sEmailDomain,
'password' => $sNewPassword
);
$sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
$sResult = $oXmlApi->api2_query($sUser, 'Email', 'passwdpop', $aArgs);
if ($sResult)
{
$aResult = @\json_decode($sResult, true);
@ -149,6 +170,13 @@ class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\C
}
}
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('CPANEL: Incorrent configuration data', \MailSo\Log\Enumerations\Type::ERROR);
}
}
return $bResult;
}

View file

@ -1 +1 @@
1.2
1.3

View file

@ -21,7 +21,7 @@ class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
$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);
$bSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
{
@ -29,7 +29,7 @@ class CpanelChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
$oProvider = new CpanelChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword);
$oProvider->SetConfig($sHost, $iPost, $bSsl, $sUser, $sPassword);
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
}

View file

@ -591,11 +591,11 @@ class Manager
{
foreach ($this->aProcessTemplate[$sName] as $sPlace => $aAddHtml)
{
if (is_array($aAddHtml) && 0 < count($aAddHtml))
if (\is_array($aAddHtml) && 0 < \count($aAddHtml))
{
foreach ($aAddHtml as $sAddHtml)
{
$sHtml = str_replace('{{INCLUDE/'.$sPlace.'/PLACE}}', $sAddHtml.'{{INCLUDE/'.$sPlace.'/PLACE}}', $sHtml);
$sHtml = \str_replace('{{INCLUDE/'.$sPlace.'/PLACE}}', $sAddHtml.'{{INCLUDE/'.$sPlace.'/PLACE}}', $sHtml);
}
}
}