diff --git a/plugins/postfixadmin-change-password/ChangePasswordPostfixAdminDriver.php b/plugins/postfixadmin-change-password/ChangePasswordPostfixAdminDriver.php index 7c72af236b..fd2284b8b1 100755 --- a/plugins/postfixadmin-change-password/ChangePasswordPostfixAdminDriver.php +++ b/plugins/postfixadmin-change-password/ChangePasswordPostfixAdminDriver.php @@ -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 @@ public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNe { 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 @@ private function cryptPassword($sPassword, $oPdo) 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 @@ private function cryptPassword($sPassword, $oPdo) $sResult = $aFetchResult[0]['encpass']; } } - break; + }else{ + throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CouldNotSaveNewPassword); + } + break; } return $sResult; diff --git a/plugins/postfixadmin-change-password/VERSION b/plugins/postfixadmin-change-password/VERSION index ea710abb95..7e32cd5698 100644 --- a/plugins/postfixadmin-change-password/VERSION +++ b/plugins/postfixadmin-change-password/VERSION @@ -1 +1 @@ -1.2 \ No newline at end of file +1.3 diff --git a/plugins/postfixadmin-change-password/index.php b/plugins/postfixadmin-change-password/index.php index 3e1223d4b7..ef2f5eee18 100755 --- a/plugins/postfixadmin-change-password/index.php +++ b/plugins/postfixadmin-change-password/index.php @@ -14,13 +14,13 @@ public function Supported() { 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 @@ public function MainFabrica($sName, &$oProvider) $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 @@ public function MainFabrica($sName, &$oProvider) 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')