Merge pull request #1584 from mwohlert/ChangePasswordPostfix-PostgresSQL

Add PostgreSQL to postfixadmin-change-password Plugin
This commit is contained in:
RainLoop Team 2018-02-21 02:08:17 +03:00 committed by GitHub
commit 11989a4c28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 15 deletions

View file

@ -2,6 +2,11 @@
class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sEngine = 'MySQL';
/**
* @var string
*/
@ -57,6 +62,17 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
*/
private $oLogger = null;
/**
* @param string $sEngine
*
* @return \ChangePasswordPostfixAdminDriver
*/
public function SetEngine($sEngine)
{
$this->sEngine = $sEngine;
return $this;
}
/**
* @param string $sHost
*
@ -215,7 +231,19 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
{
try
{
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
$sDsn = '';
switch($this->sEngine){
case 'MySQL':
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
break;
case 'PostgreSQL':
$sDsn = 'pgsql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
break;
default:
$sDsn = 'mysql:host='.$this->sHost.';port='.$this->iPort.';dbname='.$this->sDatabase;
break;
}
$oPdo = new \PDO($sDsn, $this->sUser, $this->sPassword);
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
@ -289,7 +317,8 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
break;
case 'mysql_encrypt':
$oStmt = $oPdo->prepare('SELECT ENCRYPT(?) AS encpass');
if($this->sEngine == 'MySQL'){
$oStmt = $oPdo->prepare('SELECT ENCRYPT(?) AS encpass');
if ($oStmt->execute(array($sPassword)))
{
$aFetchResult = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
@ -298,7 +327,10 @@ class ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePass
$sResult = $aFetchResult[0]['encpass'];
}
}
break;
}else{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword);
}
break;
}
return $sResult;

View file

@ -1 +1 @@
1.2
1.3

View file

@ -14,13 +14,13 @@ class PostfixadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
{
if (!extension_loaded('pdo') || !class_exists('PDO'))
{
return 'The PHP extension PDO (mysql) must be installed to use this plugin';
return 'The PHP extension PDO must be installed to use this plugin';
}
$aDrivers = \PDO::getAvailableDrivers();
if (!is_array($aDrivers) || !in_array('mysql', $aDrivers))
if (!is_array($aDrivers) || (!in_array('mysql', $aDrivers) && !in_array('pgsql', $aDrivers)))
{
return 'The PHP extension PDO (mysql) must be installed to use this plugin';
return 'The PHP extension PDO (mysql or pgsql) must be installed to use this plugin';
}
return '';
@ -41,6 +41,7 @@ class PostfixadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
$oProvider = new ChangePasswordPostfixAdminDriver();
$oProvider
->SetEngine($this->Config()->Get('plugin', 'engine',''))
->SetHost($this->Config()->Get('plugin', 'host', ''))
->SetPort((int) $this->Config()->Get('plugin', 'port', 3306))
->SetDatabase($this->Config()->Get('plugin', 'database', ''))
@ -64,22 +65,26 @@ class PostfixadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('MySQL Host')
\RainLoop\Plugins\Property::NewInstance('engine')->SetLabel('Engine')
->SetType(\RainLoop\Enumerations\PluginPropertyType::SELECTION)
->SetDefaultValue(array('MySQL', 'PostgreSQL'))
->SetDescription('Database Engine'),
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('Host')
->SetDefaultValue('127.0.0.1'),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('MySQL Port')
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(3306),
\RainLoop\Plugins\Property::NewInstance('database')->SetLabel('MySQL Database')
\RainLoop\Plugins\Property::NewInstance('database')->SetLabel('Database')
->SetDefaultValue('postfixadmin'),
\RainLoop\Plugins\Property::NewInstance('table')->SetLabel('MySQL table')
\RainLoop\Plugins\Property::NewInstance('table')->SetLabel('table')
->SetDefaultValue('mailbox'),
\RainLoop\Plugins\Property::NewInstance('usercol')->SetLabel('MySQL username column')
\RainLoop\Plugins\Property::NewInstance('usercol')->SetLabel('username column')
->SetDefaultValue('username'),
\RainLoop\Plugins\Property::NewInstance('passcol')->SetLabel('MySQL password column')
\RainLoop\Plugins\Property::NewInstance('passcol')->SetLabel('password column')
->SetDefaultValue('password'),
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('MySQL User')
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('User')
->SetDefaultValue('postfixadmin'),
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('MySQL Password')
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('Password')
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('encrypt')->SetLabel('Encrypt')