Merge branch 'ent-9154-ssl-mysql-parametros-consola-conexion-consola' into 'develop'

Ent 9154 ssl mysql parametros consola conexion consola

See merge request artica/pandorafms!5107
This commit is contained in:
Daniel Rodriguez 2022-09-16 08:55:49 +00:00
commit ca80be5867
3 changed files with 66 additions and 33 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* Configuraton sample file.
*
@ -38,6 +39,11 @@
* $config["homedir"]="/var/www/pandora_console/";
* $config["homeurl"]="/pandora_console/";
* $config["auth"]["scheme"] = "mysql";
*
* This is used to configure MySQL SSL console connection
* $config["dbssl"]=0;
* $config["dbsslcafile"]="/path/ca-cert.pem";
* $config["sslverifyservercert"]=1;
*/
// By default report any error but notices.

View File

@ -31,7 +31,9 @@ function mysql_connect_db(
$user=null,
$pass=null,
$port=null,
$charset=null
$charset=null,
$ssl=null,
$verify=null
) {
global $config;
@ -55,6 +57,14 @@ function mysql_connect_db(
$port = $config['dbport'];
}
if ($ssl === null && (bool) $config['dbssl'] === true) {
$ssl = $config['dbsslcafile'];
}
if ($verify === null && (bool) $config['sslverifyservercert'] === true) {
$verify = 'verified';
}
// Check if mysqli is available
if (!isset($config['mysqli'])) {
$config['mysqli'] = extension_loaded(mysqli);
@ -63,6 +73,7 @@ function mysql_connect_db(
// Non-persistent connection: This will help to avoid mysql errors like "has gone away" or locking problems
// If you want persistent connections change it to mysql_pconnect().
if ($config['mysqli']) {
if (empty($ssl)) {
$connect_id = mysqli_connect($host, $user, $pass, $db, $port);
if (mysqli_connect_errno() > 0) {
include 'general/mysqlerr.php';
@ -76,6 +87,22 @@ function mysql_connect_db(
}
mysqli_select_db($connect_id, $db);
} else {
$connect_id = mysqli_init();
mysqli_ssl_set($connect_id, null, null, $ssl, null, null);
if ($verify === 'verified') {
mysqli_real_connect($connect_id, $host, $user, $pass, $db, $port, null, MYSQLI_CLIENT_SSL);
} else {
mysqli_real_connect($connect_id, $host, $user, $pass, $db, $port, null, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
}
if (mysqli_connect_errno() > 0) {
include 'general/mysqlerr.php';
return false;
}
}
} else {
$connect_id = @mysql_connect($host.':'.$port, $user, $pass, true);
if (!$connect_id) {

View File

@ -1,4 +1,5 @@
<?php
/**
* Main configuration of Pandora FMS
*
@ -30,6 +31,7 @@
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/functions.php';
enterprise_include_once('include/functions_config.php');
use PandoraFMS\Core\DBMaintainer;
use PandoraFMS\Core\Config;
@ -3399,7 +3401,6 @@ function config_check()
$supervisor = new ConsoleSupervisor(false);
$supervisor->runBasic();
}
}
@ -3424,7 +3425,6 @@ function get_um_url()
}
return $url;
}