From ab929571c7e8ce8ccaa6fefe6e3c29b2844700c9 Mon Sep 17 00:00:00 2001 From: Tommaso Rossi Date: Fri, 31 Jan 2025 14:45:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20N=C2=B08115=20-=20Unattended=20I?= =?UTF-8?q?nstall:=20unable=20to=20connect=20to=20MySQL=20with=20TLS=20(#6?= =?UTF-8?q?94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 Support TLS connections to MySQL in unattended-install process --- .../unattended-install/unattended-install.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/setup/unattended-install/unattended-install.php b/setup/unattended-install/unattended-install.php index cde9ff084..4151318ad 100644 --- a/setup/unattended-install/unattended-install.php +++ b/setup/unattended-install/unattended-install.php @@ -143,6 +143,8 @@ $sDBUser = $aDBXmlSettings['user']; $sDBPwd = $aDBXmlSettings['pwd']; $sDBName = $aDBXmlSettings['name']; $sDBPrefix = $aDBXmlSettings['prefix']; +$bDBTlsEnabled = $aDBXmlSettings['db_tls_enabled']; +$sDBTlsCa = $aDBXmlSettings['db_tls_ca']; if ($sMode == 'install') { @@ -219,13 +221,10 @@ if ($sMode == 'install') die("Cleanup not implemented for a partial database (prefix= '$sDBPrefix')\nExiting."); } - $oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd); - if ($oMysqli->connect_errno) - { - die("Cannot connect to the MySQL server (".$oMysqli->connect_errno . ") ".$oMysqli->connect_error."\nExiting"); - } - else + try { + $oMysqli = CMDBSource::GetMysqliInstance($sDBServer, $sDBUser, $sDBPwd, null, $bDBTlsEnabled, $sDBTlsCa, true); + if ($oMysqli->select_db($sDBName)) { echo "Deleting database '$sDBName'\n"; @@ -236,6 +235,10 @@ if ($sMode == 'install') echo "The database '$sDBName' does not seem to exist. Nothing to cleanup.\n"; } } + catch (MySQLException $e) + { + die($e->getMessage()."\nExiting"); + } } } else @@ -312,9 +315,9 @@ if ($bInstall) } else { - $oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd); - if (!$oMysqli->connect_errno) + try { + $oMysqli = CMDBSource::GetMysqliInstance($sDBServer, $sDBUser, $sDBPwd, null, $bDBTlsEnabled, $sDBTlsCa, true); if ($oMysqli->select_db($sDBName)) { // Check the presence of a table to record information about the MTP (from the Designer) @@ -357,6 +360,10 @@ if ($bInstall) } } } + catch (MySQLException $e) + { + // Continue anyway + } } } else