mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 17:07:03 +03:00
vpopmail-change-password fixes
This commit is contained in:
parent
9b8258ad91
commit
f15f25a635
3 changed files with 300 additions and 301 deletions
|
|
@ -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,43 +163,42 @@ 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
|
||||||
{
|
{
|
||||||
$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(
|
$sCryptPass = isset($aColCrypt[0][$this->mColumn]) ? $aColCrypt[0][$this->mColumn] : '';
|
||||||
$email_parts[0],
|
if (0 < \strlen($sCryptPass) && \crypt($sPrevPassword, $sCryptPass) === $sCryptPass)
|
||||||
$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)*/)
|
|
||||||
{
|
{
|
||||||
|
$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=?');
|
||||||
$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=?');
|
$oUpdate->execute(array(
|
||||||
$update->execute(array(
|
|
||||||
$sNewPassword,
|
$sNewPassword,
|
||||||
$email_parts[0],
|
$sLoginPart,
|
||||||
$email_parts[1]
|
$sDomainPart
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$bResult = true;
|
$bResult = true;
|
||||||
if ($this->oLogger)
|
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.');
|
$this->oLogger->Write('Something went wrong. Either current password is incorrect, or new password does not match criteria.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (\Exception $oException)
|
catch (\Exception $oException)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.0
|
1.1
|
||||||
|
|
|
||||||
|
|
@ -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')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue