mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +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,229 +1,228 @@
|
||||||
<?php
|
<?php
|
||||||
class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
|
||||||
{
|
class ChangePasswordVpopmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||||
/**
|
{
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mHost = 'localhost';
|
*/
|
||||||
|
private $mHost = 'localhost';
|
||||||
/**
|
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mUser = '';
|
*/
|
||||||
|
private $mUser = '';
|
||||||
/**
|
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mPass = '';
|
*/
|
||||||
|
private $mPass = '';
|
||||||
/**
|
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mDatabase = '';
|
*/
|
||||||
|
private $mDatabase = '';
|
||||||
/**
|
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mTable = '';
|
*/
|
||||||
|
private $mTable = '';
|
||||||
/**
|
|
||||||
* @var string
|
/**
|
||||||
*/
|
* @var string
|
||||||
private $mColumn = '';
|
*/
|
||||||
|
private $mColumn = '';
|
||||||
/**
|
|
||||||
* @var \MailSo\Log\Logger
|
/**
|
||||||
*/
|
* @var \MailSo\Log\Logger
|
||||||
private $oLogger = null;
|
*/
|
||||||
|
private $oLogger = null;
|
||||||
/**
|
|
||||||
* @var array
|
/**
|
||||||
*/
|
* @var array
|
||||||
private $aDomains = array();
|
*/
|
||||||
|
private $aDomains = array();
|
||||||
/**
|
|
||||||
* @param string $mHost
|
/**
|
||||||
*
|
* @param string $mHost
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmHost($mHost)
|
*/
|
||||||
{
|
public function SetmHost($mHost)
|
||||||
$this->mHost = $mHost;
|
{
|
||||||
return $this;
|
$this->mHost = $mHost;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param string $mUser
|
/**
|
||||||
*
|
* @param string $mUser
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmUser($mUser)
|
*/
|
||||||
{
|
public function SetmUser($mUser)
|
||||||
$this->mUser = $mUser;
|
{
|
||||||
return $this;
|
$this->mUser = $mUser;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param string $mPass
|
/**
|
||||||
*
|
* @param string $mPass
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmPass($mPass)
|
*/
|
||||||
{
|
public function SetmPass($mPass)
|
||||||
$this->mPass = $mPass;
|
{
|
||||||
return $this;
|
$this->mPass = $mPass;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param string $mDatabase
|
/**
|
||||||
*
|
* @param string $mDatabase
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmDatabase($mDatabase)
|
*/
|
||||||
{
|
public function SetmDatabase($mDatabase)
|
||||||
$this->mDatabase = $mDatabase;
|
{
|
||||||
return $this;
|
$this->mDatabase = $mDatabase;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param string $mTable
|
/**
|
||||||
*
|
* @param string $mTable
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmTable($mTable)
|
*/
|
||||||
{
|
public function SetmTable($mTable)
|
||||||
$this->mTable = $mTable;
|
{
|
||||||
return $this;
|
$this->mTable = $mTable;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param string $mColumn
|
/**
|
||||||
*
|
* @param string $mColumn
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetmColumn($mColumn)
|
*/
|
||||||
{
|
public function SetmColumn($mColumn)
|
||||||
$this->mColumn = $mColumn;
|
{
|
||||||
return $this;
|
$this->mColumn = $mColumn;
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param \MailSo\Log\Logger $oLogger
|
/**
|
||||||
*
|
* @param \MailSo\Log\Logger $oLogger
|
||||||
* @return \ChangePasswordVpopmailDriver
|
*
|
||||||
*/
|
* @return \ChangePasswordVpopmailDriver
|
||||||
public function SetLogger($oLogger)
|
*/
|
||||||
{
|
public function SetLogger($oLogger)
|
||||||
if ($oLogger instanceof \MailSo\Log\Logger)
|
{
|
||||||
{
|
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||||
$this->oLogger = $oLogger;
|
{
|
||||||
}
|
$this->oLogger = $oLogger;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param array $aDomains
|
/**
|
||||||
*
|
* @param array $aDomains
|
||||||
* @return bool
|
*
|
||||||
*/
|
* @return bool
|
||||||
public function SetAllowedDomains($aDomains)
|
*/
|
||||||
{
|
public function SetAllowedDomains($aDomains)
|
||||||
if (\is_array($aDomains) && 0 < \count($aDomains))
|
{
|
||||||
{
|
if (\is_array($aDomains) && 0 < \count($aDomains))
|
||||||
$this->aDomains = $aDomains;
|
{
|
||||||
}
|
$this->aDomains = $aDomains;
|
||||||
|
}
|
||||||
return $this;
|
|
||||||
}
|
return $this;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param \RainLoop\Account $oAccount
|
/**
|
||||||
*
|
* @param \RainLoop\Account $oAccount
|
||||||
* @return bool
|
*
|
||||||
*/
|
* @return bool
|
||||||
public function PasswordChangePossibility($oAccount)
|
*/
|
||||||
{
|
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));
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param \RainLoop\Account $oAccount
|
/**
|
||||||
* @param string $sPrevPassword
|
* @param \RainLoop\Account $oAccount
|
||||||
* @param string $sNewPassword
|
* @param string $sPrevPassword
|
||||||
*
|
* @param string $sNewPassword
|
||||||
* @return bool
|
*
|
||||||
*/
|
* @return bool
|
||||||
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
|
*/
|
||||||
{
|
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
|
||||||
if ($this->oLogger)
|
{
|
||||||
{
|
if ($this->oLogger)
|
||||||
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
|
{
|
||||||
}
|
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
|
||||||
|
}
|
||||||
$bResult = false;
|
|
||||||
|
if (empty($this->mHost) || empty($this->mDatabase) || empty($this->mColumn) || empty($this->mTable))
|
||||||
$dsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
|
{
|
||||||
$options = array(
|
return false;
|
||||||
PDO::ATTR_EMULATE_PREPARES => false,
|
}
|
||||||
PDO::ATTR_PERSISTENT => true,
|
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
$bResult = false;
|
||||||
);
|
|
||||||
|
$sDsn = 'mysql:host='.$this->mHost.';dbname='.$this->mDatabase.';charset=utf8';
|
||||||
try
|
$aOptions = array(
|
||||||
{
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
$conn = new PDO($dsn,$this->mUser,$this->mPass,$options);
|
PDO::ATTR_PERSISTENT => true,
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
||||||
$select = $conn->prepare("SELECT $this->mColumn FROM $this->mTable WHERE pw_name=? AND pw_domain=? LIMIT 1");
|
);
|
||||||
|
|
||||||
$email_parts = explode("@", $oAccount->Email());
|
$sLoginPart = \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email());
|
||||||
|
$sDomainPart = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
|
||||||
$select->execute(array(
|
|
||||||
$email_parts[0],
|
try
|
||||||
$email_parts[1]
|
{
|
||||||
));
|
$oConn = new PDO($sDsn, $this->mUser, $this->mPass, $aOptions);
|
||||||
|
|
||||||
$colCrypt = $select->fetchAll(PDO::FETCH_ASSOC);
|
$oSelect = $oConn->prepare('SELECT '.$this->mColumn.' FROM '.$this->mTable.' WHERE pw_name=? AND pw_domain=? LIMIT 1');
|
||||||
$sCryptPass = $colCrypt[0][$this->mColumn];
|
$oSelect->execute(array($sLoginPart, $sDomainPart));
|
||||||
|
|
||||||
if (0 < strlen($sCryptPass) && crypt($sPrevPassword, $sCryptPass) === $sCryptPass /*&& 7 < mb_strlen($sNewPassword) && 20 > mb_strlen($sNewPassword) && !preg_match('/[^A-Za-z0-9]+/', $sNewPassword)*/)
|
$aColCrypt = $oSelect->fetchAll(PDO::FETCH_ASSOC);
|
||||||
{
|
|
||||||
|
$sCryptPass = isset($aColCrypt[0][$this->mColumn]) ? $aColCrypt[0][$this->mColumn] : '';
|
||||||
$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=?');
|
if (0 < \strlen($sCryptPass) && \crypt($sPrevPassword, $sCryptPass) === $sCryptPass)
|
||||||
$update->execute(array(
|
{
|
||||||
$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=?');
|
||||||
$email_parts[0],
|
$oUpdate->execute(array(
|
||||||
$email_parts[1]
|
$sNewPassword,
|
||||||
));
|
$sLoginPart,
|
||||||
|
$sDomainPart
|
||||||
|
));
|
||||||
|
|
||||||
$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)
|
{
|
||||||
{
|
$bResult = false;
|
||||||
$bResult = false;
|
if ($this->oLogger)
|
||||||
if ($this->oLogger)
|
{
|
||||||
{
|
$this->oLogger->WriteException($oException);
|
||||||
$this->oLogger->WriteException($oException);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return $bResult;
|
||||||
return $bResult;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.0
|
1.1
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,71 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ChangePasswordVpopmailPlugin extends \RainLoop\Plugins\AbstractPlugin
|
class ChangePasswordVpopmailPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
{
|
{
|
||||||
public function Init()
|
public function Init()
|
||||||
{
|
{
|
||||||
$this->addHook('main.fabrica', 'MainFabrica');
|
$this->addHook('main.fabrica', 'MainFabrica');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sName
|
* @param string $sName
|
||||||
* @param mixed $oProvider
|
* @param mixed $oProvider
|
||||||
*/
|
*/
|
||||||
public function MainFabrica($sName, &$oProvider)
|
public function MainFabrica($sName, &$oProvider)
|
||||||
{
|
{
|
||||||
switch ($sName)
|
switch ($sName)
|
||||||
{
|
{
|
||||||
case 'change-password':
|
case 'change-password':
|
||||||
|
|
||||||
include_once __DIR__.'/ChangePasswordVpopmailDriver.php';
|
include_once __DIR__.'/ChangePasswordVpopmailDriver.php';
|
||||||
|
|
||||||
$oProvider = new ChangePasswordVpopmailDriver();
|
$oProvider = new ChangePasswordVpopmailDriver();
|
||||||
|
|
||||||
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
|
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
|
||||||
$this->Config()->Get('plugin', 'domains', ''))));
|
$this->Config()->Get('plugin', 'domains', ''))));
|
||||||
|
|
||||||
if (0 < \strlen($sDomains))
|
if (0 < \strlen($sDomains))
|
||||||
{
|
{
|
||||||
$aDomains = \explode(' ', $sDomains);
|
$aDomains = \explode(' ', $sDomains);
|
||||||
$oProvider->SetAllowedDomains($aDomains);
|
$oProvider->SetAllowedDomains($aDomains);
|
||||||
}
|
}
|
||||||
|
|
||||||
$oProvider
|
$oProvider
|
||||||
->SetLogger($this->Manager()->Actions()->Logger())
|
->SetLogger($this->Manager()->Actions()->Logger())
|
||||||
->SetmHost($this->Config()->Get('plugin', 'mHost', ''))
|
->SetmHost($this->Config()->Get('plugin', 'mHost', ''))
|
||||||
->SetmUser($this->Config()->Get('plugin', 'mUser', ''))
|
->SetmUser($this->Config()->Get('plugin', 'mUser', ''))
|
||||||
->SetmPass($this->Config()->Get('plugin', 'mPass', ''))
|
->SetmPass($this->Config()->Get('plugin', 'mPass', ''))
|
||||||
->SetmDatabase($this->Config()->Get('plugin', 'mDatabase', ''))
|
->SetmDatabase($this->Config()->Get('plugin', 'mDatabase', ''))
|
||||||
->SetmTable($this->Config()->Get('plugin', 'mTable', ''))
|
->SetmTable($this->Config()->Get('plugin', 'mTable', ''))
|
||||||
->SetmColumn($this->Config()->Get('plugin', 'mColumn', ''))
|
->SetmColumn($this->Config()->Get('plugin', 'mColumn', ''))
|
||||||
;
|
;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function configMapping()
|
public function configMapping()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
\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')
|
||||||
->SetDefaultValue('vpopmail'),
|
->SetDefaultValue('vpopmail'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('mPass')->SetLabel('MySQL Password')
|
\RainLoop\Plugins\Property::NewInstance('mPass')->SetLabel('MySQL Password')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
|
||||||
\RainLoop\Plugins\Property::NewInstance('mDatabase')->SetLabel('MySQL Database')
|
\RainLoop\Plugins\Property::NewInstance('mDatabase')->SetLabel('MySQL Database')
|
||||||
->SetDefaultValue('vpopmail'),
|
->SetDefaultValue('vpopmail'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('mTable')->SetLabel('MySQL Table')
|
\RainLoop\Plugins\Property::NewInstance('mTable')->SetLabel('MySQL Table')
|
||||||
->SetDefaultValue('vpopmail'),
|
->SetDefaultValue('vpopmail'),
|
||||||
\RainLoop\Plugins\Property::NewInstance('mColumn')->SetLabel('MySQL Column')
|
\RainLoop\Plugins\Property::NewInstance('mColumn')->SetLabel('MySQL Column')
|
||||||
->SetDefaultValue('pw_passwd')
|
->SetDefaultValue('pw_passwd')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue