vpopmail-change-password fixes

This commit is contained in:
RainLoop Team 2015-05-20 16:09:50 +04:00
parent 9b8258ad91
commit f15f25a635
3 changed files with 300 additions and 301 deletions

View file

@ -1,4 +1,5 @@
<?php <?php
class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{ {
/** /**
@ -144,8 +145,8 @@ class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword
*/ */
public function PasswordChangePossibility($oAccount) public function PasswordChangePossibility($oAccount)
{ {
return $oAccount && $oAccount->Domain() && return 0 === \count($this->aDomains) || ($oAccount && \in_array(\strtolower(
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains); \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email)), $this->aDomains));
} }
/** /**
@ -162,58 +163,56 @@ class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword
$this->oLogger->Write('Try to change password for '.$oAccount->Email()); $this->oLogger->Write('Try to change password for '.$oAccount->Email());
} }
if (empty($this->mHost) || empty($this->mDatabase) || empty($this->mColumn) || empty($this->mTable))
{
return false;
}
$bResult = false; $bResult = false;
$dsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8'; $sDsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
$options = array( $aOptions = array(
PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_PERSISTENT => true, PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
); );
$sLoginPart = \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email());
$sDomainPart = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
try try
{
$oConn = new PDO($sDsn, $this->mUser, $this->mPass, $aOptions);
$oSelect = $oConn->prepare('SELECT '.$this->mColumn.' FROM '.$this->mTable.' WHERE pw_name=? AND pw_domain=? LIMIT 1');
$oSelect->execute(array($sLoginPart, $sDomainPart));
$aColCrypt = $oSelect->fetchAll(PDO::FETCH_ASSOC);
$sCryptPass = isset($aColCrypt[0][$this->mColumn]) ? $aColCrypt[0][$this->mColumn] : '';
if (0 < \strlen($sCryptPass) && \crypt($sPrevPassword, $sCryptPass) === $sCryptPass)
{ {
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options); $oUpdate = $oConn->prepare('UPDATE '.$this->mTable.' SET '.$this->mColumn.'=ENCRYPT(?,concat("$1$",right(md5(rand()), 8 ),"$")), pw_clear_passwd=\'\' WHERE pw_name=? AND pw_domain=?');
$oUpdate->execute(array(
$select = $conn->prepare("SELECT $this->mColumn FROM $this->mTable WHERE pw_name=? AND pw_domain=? LIMIT 1"); $sNewPassword,
$sLoginPart,
$email_parts = explode("@", $oAccount->Email()); $sDomainPart
$select->execute(array(
$email_parts[0],
$email_parts[1]
)); ));
$colCrypt = $select->fetchAll(PDO::FETCH_ASSOC);
$sCryptPass = $colCrypt[0][$this->mColumn];
if (0 < strlen($sCryptPass) && crypt($sPrevPassword, $sCryptPass) === $sCryptPass /*&& 7 < mb_strlen($sNewPassword) && 20 > mb_strlen($sNewPassword) && !preg_match('/[^A-Za-z0-9]+/', $sNewPassword)*/)
{
$update = $conn->prepare('UPDATE '.$this->mTable.' SET '.$this->mColumn.'=ENCRYPT(?,concat("$1$",right(md5(rand()), 8 ),"$")), pw_clear_passwd=\'\' WHERE pw_name=? AND pw_domain=?');
$update->execute(array(
$sNewPassword,
$email_parts[0],
$email_parts[1]
));
$bResult = true; $bResult = true;
if ($this->oLogger) if ($this->oLogger)
{ {
$this->oLogger->Write('Success! Password changed.'); $this->oLogger->Write('Success! Password changed.');
} }
} }
else else
{ {
$bResult = false; $bResult = false;
if ($this->oLogger) if ($this->oLogger)
{ {
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.'); $this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
} }
} }
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {

View file

@ -1 +1 @@
1.0 1.1

View file

@ -53,7 +53,7 @@ class ChangePasswordVpopmailPlugin extends \RainLoop\Plugins\AbstractPlugin
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains') \RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT) ->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->SetDescription('Allowed domains, space as delimiter') ->SetDescription('Allowed domains, space as delimiter')
->SetDefaultValue('* gmail.com yahoo.com dusal.net'), ->SetDefaultValue('gmail.com yahoo.com'),
\RainLoop\Plugins\Property::NewInstance('mHost')->SetLabel('MySQL Host') \RainLoop\Plugins\Property::NewInstance('mHost')->SetLabel('MySQL Host')
->SetDefaultValue('localhost'), ->SetDefaultValue('localhost'),
\RainLoop\Plugins\Property::NewInstance('mUser')->SetLabel('MySQL User') \RainLoop\Plugins\Property::NewInstance('mUser')->SetLabel('MySQL User')