From 67678017a82660c450e194cc5bdedc4fbc418863 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Wed, 24 Sep 2014 02:02:20 +0400 Subject: [PATCH] "cpanel-change-password" plugin improvements --- .../CpanelChangePasswordDriver.php | 52 ++++++++++++++----- plugins/cpanel-change-password/VERSION | 2 +- plugins/cpanel-change-password/index.php | 4 +- .../libraries/RainLoop/Plugins/Manager.php | 4 +- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/plugins/cpanel-change-password/CpanelChangePasswordDriver.php b/plugins/cpanel-change-password/CpanelChangePasswordDriver.php index 715727a3c..a94e61504 100644 --- a/plugins/cpanel-change-password/CpanelChangePasswordDriver.php +++ b/plugins/cpanel-change-password/CpanelChangePasswordDriver.php @@ -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; } diff --git a/plugins/cpanel-change-password/VERSION b/plugins/cpanel-change-password/VERSION index ea710abb9..a58941b07 100644 --- a/plugins/cpanel-change-password/VERSION +++ b/plugins/cpanel-change-password/VERSION @@ -1 +1 @@ -1.2 \ No newline at end of file +1.3 \ No newline at end of file diff --git a/plugins/cpanel-change-password/index.php b/plugins/cpanel-change-password/index.php index 666e0bdd1..5f2602bdb 100644 --- a/plugins/cpanel-change-password/index.php +++ b/plugins/cpanel-change-password/index.php @@ -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', '')))); } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php index 544d4781b..00182d6cc 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php @@ -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); } } }