Skip to content

Commit

Permalink
🐛 N°8115 - Unattended Install: unable to connect to MySQL with TLS (#694
Browse files Browse the repository at this point in the history
)

🐛 Support TLS connections to MySQL in unattended-install process
  • Loading branch information
tomrss authored Jan 31, 2025
1 parent 8e0e01a commit ab92957
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions setup/unattended-install/unattended-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function PrintUsageAndExit()
$sDBPwd = $aDBXmlSettings['pwd'];
$sDBName = $aDBXmlSettings['name'];
$sDBPrefix = $aDBXmlSettings['prefix'];
$bDBTlsEnabled = $aDBXmlSettings['db_tls_enabled'];
$sDBTlsCa = $aDBXmlSettings['db_tls_ca'];

if ($sMode == 'install')
{
Expand Down Expand Up @@ -219,13 +221,10 @@ function PrintUsageAndExit()
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";
Expand All @@ -236,6 +235,10 @@ function PrintUsageAndExit()
echo "The database '$sDBName' does not seem to exist. Nothing to cleanup.\n";
}
}
catch (MySQLException $e)
{
die($e->getMessage()."\nExiting");
}
}
}
else
Expand Down Expand Up @@ -312,9 +315,9 @@ function PrintUsageAndExit()
}
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)
Expand Down Expand Up @@ -357,6 +360,10 @@ function PrintUsageAndExit()
}
}
}
catch (MySQLException $e)
{
// Continue anyway
}
}
}
else
Expand Down

0 comments on commit ab92957

Please sign in to comment.