Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Jan 31, 2025
26 changes: 22 additions & 4 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,8 +221,16 @@ function PrintUsageAndExit()
die("Cleanup not implemented for a partial database (prefix= '$sDBPrefix')\nExiting.");
}

$oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd);
if ($oMysqli->connect_errno)
$oMysqli = new mysqli();
$iMySqlFlag = 0;
if ($bDBTlsEnabled)
{
$iMySqlFlag = (empty($sDBTlsCa))
? MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT
: MYSQLI_CLIENT_SSL;
$oMysqli->ssl_set($bDBTlsEnabled, null, $sDBTlsCa, null, null);
}
if (!$oMysqli->real_connect($sDBServer, $sDBUser, $sDBPwd, null, null, null, $iMySqlFlag))
{
die("Cannot connect to the MySQL server (".$oMysqli->connect_errno . ") ".$oMysqli->connect_error."\nExiting");
}
Expand Down Expand Up @@ -312,8 +322,16 @@ function PrintUsageAndExit()
}
else
{
$oMysqli = new mysqli($sDBServer, $sDBUser, $sDBPwd);
if (!$oMysqli->connect_errno)
$oMysqli = new mysqli();
$iMySqlFlag = 0;
if ($bDBTlsEnabled)
{
$iMySqlFlag = (empty($sDBTlsCa))
? MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT
: MYSQLI_CLIENT_SSL;
$oMysqli->ssl_set($bDBTlsEnabled, null, $sDBTlsCa, null, null);
}
if ($oMysqli->real_connect($sDBServer, $sDBUser, $sDBPwd, null, null, null, $iMySqlFlag))
{
if ($oMysqli->select_db($sDBName))
{
Expand Down