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
class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
@ -144,8 +145,8 @@ class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword
*/
public function PasswordChangePossibility($oAccount)
{
return $oAccount && $oAccount->Domain() &&
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
return 0 === \count($this->aDomains) || ($oAccount && \in_array(\strtolower(
\MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email)), $this->aDomains));
}
/**
@ -162,43 +163,42 @@ class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword
$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;
$dsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
$options = array(
$sDsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
$aOptions = array(
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
$sLoginPart = \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email());
$sDomainPart = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
try
{
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options);
$oConn = new PDO($sDsn, $this->mUser, $this->mPass, $aOptions);
$select = $conn->prepare("SELECT $this->mColumn FROM $this->mTable WHERE pw_name=? AND pw_domain=? LIMIT 1");
$oSelect = $oConn->prepare('SELECT '.$this->mColumn.' FROM '.$this->mTable.' WHERE pw_name=? AND pw_domain=? LIMIT 1');
$oSelect->execute(array($sLoginPart, $sDomainPart));
$email_parts = explode("@", $oAccount->Email());
$aColCrypt = $oSelect->fetchAll(PDO::FETCH_ASSOC);
$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)*/)
$sCryptPass = isset($aColCrypt[0][$this->mColumn]) ? $aColCrypt[0][$this->mColumn] : '';
if (0 < \strlen($sCryptPass) && \crypt($sPrevPassword, $sCryptPass) === $sCryptPass)
{
$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(
$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(
$sNewPassword,
$email_parts[0],
$email_parts[1]
$sLoginPart,
$sDomainPart
));
$bResult = true;
if ($this->oLogger)
{
@ -213,7 +213,6 @@ class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
}
}
}
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')
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
->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')
->SetDefaultValue('localhost'),
\RainLoop\Plugins\Property::NewInstance('mUser')->SetLabel('MySQL User')