🐛 N°8115 - Unattended Install: unable to connect to MySQL with TLS (#694)

🐛 Support TLS connections to MySQL in unattended-install process
This commit is contained in:
Tommaso Rossi
2025-01-31 14:45:52 +01:00
committed by GitHub
parent 8e0e01ad40
commit ab929571c7

View File

@@ -143,6 +143,8 @@ $sDBUser = $aDBXmlSettings['user'];
$sDBPwd = $aDBXmlSettings['pwd']; $sDBPwd = $aDBXmlSettings['pwd'];
$sDBName = $aDBXmlSettings['name']; $sDBName = $aDBXmlSettings['name'];
$sDBPrefix = $aDBXmlSettings['prefix']; $sDBPrefix = $aDBXmlSettings['prefix'];
$bDBTlsEnabled = $aDBXmlSettings['db_tls_enabled'];
$sDBTlsCa = $aDBXmlSettings['db_tls_ca'];
if ($sMode == 'install') if ($sMode == 'install')
{ {
@@ -219,13 +221,10 @@ if ($sMode == 'install')
die("Cleanup not implemented for a partial database (prefix= '$sDBPrefix')\nExiting."); die("Cleanup not implemented for a partial database (prefix= '$sDBPrefix')\nExiting.");
} }
$oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd); try
if ($oMysqli->connect_errno)
{
die("Cannot connect to the MySQL server (".$oMysqli->connect_errno . ") ".$oMysqli->connect_error."\nExiting");
}
else
{ {
$oMysqli = CMDBSource::GetMysqliInstance($sDBServer, $sDBUser, $sDBPwd, null, $bDBTlsEnabled, $sDBTlsCa, true);
if ($oMysqli->select_db($sDBName)) if ($oMysqli->select_db($sDBName))
{ {
echo "Deleting database '$sDBName'\n"; 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"; echo "The database '$sDBName' does not seem to exist. Nothing to cleanup.\n";
} }
} }
catch (MySQLException $e)
{
die($e->getMessage()."\nExiting");
}
} }
} }
else else
@@ -312,9 +315,9 @@ if ($bInstall)
} }
else else
{ {
$oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd); try
if (!$oMysqli->connect_errno)
{ {
$oMysqli = CMDBSource::GetMysqliInstance($sDBServer, $sDBUser, $sDBPwd, null, $bDBTlsEnabled, $sDBTlsCa, true);
if ($oMysqli->select_db($sDBName)) if ($oMysqli->select_db($sDBName))
{ {
// Check the presence of a table to record information about the MTP (from the Designer) // 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 else