diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 30ef84d85..e59c1e612 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -636,7 +636,7 @@ class Actions $aResult['determineUserLanguage'] = (bool)$oConfig->Get('login', 'determine_user_language', true); $aResult['determineUserDomain'] = (bool)$oConfig->Get('login', 'determine_user_domain', false); - $aResult['supportedPdoDrivers'] = \RainLoop\Common\PdoAbstract::getAvailableDrivers(); + $aResult['supportedPdoDrivers'] = \RainLoop\Pdo\Base::getAvailableDrivers(); $aResult['contactsEnable'] = (bool)$oConfig->Get('contacts', 'enable', false); $aResult['contactsSync'] = (bool)$oConfig->Get('contacts', 'allow_sync', false); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php index 6a86c1bcc..5b8cef13d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php @@ -344,7 +344,7 @@ class ActionsAdmin extends Actions $aResult['determineUserLanguage'] = (bool)$oConfig->Get('login', 'determine_user_language', true); $aResult['determineUserDomain'] = (bool)$oConfig->Get('login', 'determine_user_domain', false); - $aResult['supportedPdoDrivers'] = \RainLoop\Common\PdoAbstract::getAvailableDrivers(); + $aResult['supportedPdoDrivers'] = \RainLoop\Pdo\Base::getAvailableDrivers(); $aResult['contactsEnable'] = (bool)$oConfig->Get('contacts', 'enable', false); $aResult['contactsSync'] = (bool)$oConfig->Get('contacts', 'allow_sync', false); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Base.php similarity index 91% rename from snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php rename to snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Base.php index 677490a8d..5d1974849 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Base.php @@ -1,8 +1,8 @@ getPdoAccessData(); + $oSettings = $this->getPdoSettings(); - if (!\in_array($sType, static::getAvailableDrivers())) { + if (!\in_array($oSettings->driver, static::getAvailableDrivers())) { throw new \Exception('Unknown PDO SQL connection type'); } - if (empty($sDsn)) { + if (empty($oSettings->dsn)) { throw new \Exception('Empty PDO DSN configuration'); } - $this->sDbType = $sType; + $this->sDbType = $oSettings->driver; $options = []; - if ('mysql' === $sType) { - if ($sSslCa) { - $options[\PDO::MYSQL_ATTR_SSL_CA] = $sSslCa; + if ('mysql' === $oSettings->driver) { + if ($oSettings->sslCa) { + $options[\PDO::MYSQL_ATTR_SSL_CA] = $oSettings->sslCa; } - $options[\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = !empty($bSslVerify); - if ($sSslCiphers) { - $options[\PDO::MYSQL_ATTR_SSL_CIPHER] = $sSslCiphers; + $options[\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $oSettings->sslVerify; + if ($oSettings->sslCiphers) { + $options[\PDO::MYSQL_ATTR_SSL_CIPHER] = $oSettings->sslCiphers; } /* $options[\PDO::MYSQL_ATTR_SSL_CAPATH] = ''; @@ -78,15 +77,15 @@ abstract class PdoAbstract */ } - $oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword, $options); + $oPdo = new \PDO($oSettings->dsn, $oSettings->user, $oSettings->password, $options); $sPdoType = $oPdo->getAttribute(\PDO::ATTR_DRIVER_NAME); $oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); // $bCaseFunc = false; - if ('mysql' === $sType && 'mysql' === $sPdoType) { + if ('mysql' === $oSettings->driver && 'mysql' === $sPdoType) { $oPdo->exec('SET NAMES utf8mb4 COLLATE utf8mb4_general_ci'); } -// else if ('sqlite' === $sType && 'sqlite' === $sPdoType && $this->bSqliteCollate) { +// else if ('sqlite' === $oSettings->driver && 'sqlite' === $sPdoType && $this->bSqliteCollate) { // if (\method_exists($oPdo, 'sqliteCreateCollation')) { // $oPdo->sqliteCreateCollation('SQLITE_NOCASE_UTF8', array($this, 'sqliteNoCaseCollationHelper')); // $bCaseFunc = true; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Settings.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Settings.php new file mode 100644 index 000000000..ecddde9f6 --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Pdo/Settings.php @@ -0,0 +1,20 @@ +Get('contacts', 'type', 'sqlite')); - if ('sqlite' === $sDsnType) { - $sUser = $sPassword = ''; + $oSettings = new \RainLoop\Pdo\Settings; + $oSettings->driver = static::validPdoType($oConfig->Get('contacts', 'type', 'sqlite')); + if ('sqlite' === $oSettings->driver) { $sDsn = 'sqlite:' . APP_PRIVATE_DATA . 'AddressBook.sqlite'; /* // TODO: use local db? @@ -60,20 +48,18 @@ class PdoAddressBook */ } else { $sDsn = \trim($oConfig->Get('contacts', 'pdo_dsn', '')); - $sUser = \trim($oConfig->Get('contacts', 'pdo_user', '')); - $sPassword = (string)$oConfig->Get('contacts', 'pdo_password', ''); - $sDsn = $sDsnType . ':' . \preg_replace('/^[a-z]+:/', '', $sDsn); - if ('mysql' === $sDsnType) { - $this->sSslCa = \trim($oConfig->Get('contacts', 'mysql_ssl_ca', '')); - $this->bSslVerify = !!$oConfig->Get('contacts', 'mysql_ssl_verify', true); - $this->sSslCiphers = \trim($oConfig->Get('contacts', 'mysql_ssl_ciphers', '')); + $oSettings->user = \trim($oConfig->Get('contacts', 'pdo_user', '')); + $oSettings->password = (string)$oConfig->Get('contacts', 'pdo_password', ''); + $sDsn = $oSettings->driver . ':' . \preg_replace('/^[a-z]+:/', '', $sDsn); + if ('mysql' === $oSettings->driver) { + $oSettings->sslCa = \trim($oConfig->Get('contacts', 'mysql_ssl_ca', '')); + $oSettings->sslVerify = !!$oConfig->Get('contacts', 'mysql_ssl_verify', true); + $oSettings->sslCiphers = \trim($oConfig->Get('contacts', 'mysql_ssl_ciphers', '')); } } - $this->sDsn = $sDsn; - $this->sUser = $sUser; - $this->sPassword = $sPassword; - $this->sDsnType = $sDsnType; + $oSettings->dsn = $sDsn; + $this->settings = $oSettings; $this->bExplain = false; // debug } @@ -87,7 +73,7 @@ class PdoAddressBook public function IsSupported() : bool { $aDrivers = static::getAvailableDrivers(); - return \is_array($aDrivers) && \in_array($this->sDsnType, $aDrivers); + return \is_array($aDrivers) && \in_array($this->settings->driver, $aDrivers); } public function SetEmail(string $sEmail) : bool @@ -1075,7 +1061,7 @@ class PdoAddressBook $sResult = ''; try { $this->SyncDatabase(); - if (0 >= $this->getVersion($this->sDsnType.'-ab-version')) { + if (0 >= $this->getVersion($this->settings->driver.'-ab-version')) { $sResult = 'Unknown database error'; } } @@ -1222,10 +1208,10 @@ SQLITEINITIAL; } $mCache = false; - switch ($this->sDsnType) { + switch ($this->settings->driver) { case 'mysql': - $mCache = $this->dataBaseUpgrade($this->sDsnType.'-ab-version', array( - 1 => $this->getInitialTablesArray($this->sDsnType), + $mCache = $this->dataBaseUpgrade($this->settings->driver.'-ab-version', array( + 1 => $this->getInitialTablesArray($this->settings->driver), 2 => array( 'ALTER TABLE rainloop_ab_properties ADD prop_value_lower MEDIUMTEXT NOT NULL AFTER prop_value_custom;' ), @@ -1242,8 +1228,8 @@ SQLITEINITIAL; )); break; case 'pgsql': - $mCache = $this->dataBaseUpgrade($this->sDsnType.'-ab-version', array( - 1 => $this->getInitialTablesArray($this->sDsnType), + $mCache = $this->dataBaseUpgrade($this->settings->driver.'-ab-version', array( + 1 => $this->getInitialTablesArray($this->settings->driver), 2 => array( 'ALTER TABLE rainloop_ab_properties ADD prop_value_lower text NOT NULL DEFAULT \'\';' ), @@ -1252,8 +1238,8 @@ SQLITEINITIAL; )); break; case 'sqlite': - $mCache = $this->dataBaseUpgrade($this->sDsnType.'-ab-version', array( - 1 => $this->getInitialTablesArray($this->sDsnType), + $mCache = $this->dataBaseUpgrade($this->settings->driver.'-ab-version', array( + 1 => $this->getInitialTablesArray($this->settings->driver), 2 => array( 'ALTER TABLE rainloop_ab_properties ADD prop_value_lower text NOT NULL DEFAULT \'\';' ), @@ -1305,17 +1291,15 @@ SQLITEINITIAL; (string) \mb_strtolower($sSearch)).'%'; } - protected function getPdoAccessData() : array + protected function getPdoSettings() : \RainLoop\Pdo\Settings { - $sSslCa = $this->sSslCa; + $sSslCa = $this->settings->sslCa; if ($sSslCa && !\is_file($sSslCa)) { $sFile = \APP_PRIVATE_DATA . 'configs/contacts_mysql_ssl_ca.pem'; // $sSslCa = (\is_file($sFile) || \file_put_contents($sFile, $sSslCa)) ? $sFile : ''; - $sSslCa = \file_put_contents($sFile, $sSslCa) ? $sFile : ''; + $this->settings->sslCa = \file_put_contents($sFile, $sSslCa) ? $sFile : ''; } - return array($this->sDsnType, $this->sDsn, $this->sUser, $this->sPassword, - $sSslCa, $this->bSslVerify, $this->sSslCiphers - ); + return $this->settings; } protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int