ent 9154 SSL MySQL console connection

This commit is contained in:
edu.corral 2022-09-14 14:19:47 +02:00
parent 3a1ec66bfb
commit 544f337181
4 changed files with 336 additions and 293 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* General setup. * General setup.
* *
@ -513,8 +514,8 @@ echo '<form id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godm
echo '<fieldset>'; echo '<fieldset>';
echo '<legend>'.__('General options').'</legend>'; echo '<legend>'.__('General options').'</legend>';
html_print_input_hidden('update_config', 1); html_print_input_hidden('update_config', 1);
html_print_table($table); html_print_table($table);
$encryption = [ $encryption = [
'ssl' => 'SSL', 'ssl' => 'SSL',
@ -528,56 +529,56 @@ echo '</fieldset>';
echo '<fieldset>'; echo '<fieldset>';
echo '<legend>'.__('Mail configuration').'</legend>'; echo '<legend>'.__('Mail configuration').'</legend>';
$table_mail_conf->data[0][0] = ui_print_warning_message( $table_mail_conf->data[0][0] = ui_print_warning_message(
__( __(
'Please notice that some providers like Gmail or Office365 need to setup/enable manually external connections using SMTP and you need to use STARTTLS on port 587. 'Please notice that some providers like Gmail or Office365 need to setup/enable manually external connections using SMTP and you need to use STARTTLS on port 587.
If you have manual settings in your pandora_server.conf, please note these settings will ignore this console setup.' If you have manual settings in your pandora_server.conf, please note these settings will ignore this console setup.'
) )
); );
$table_mail_conf->data[1][0] = __('From address'); $table_mail_conf->data[1][0] = __('From address');
$table_mail_conf->data[1][1] = html_print_input_text( $table_mail_conf->data[1][1] = html_print_input_text(
'email_from_dir', 'email_from_dir',
$config['email_from_dir'], $config['email_from_dir'],
'', '',
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[2][0] = __('From name'); $table_mail_conf->data[2][0] = __('From name');
$table_mail_conf->data[2][1] = html_print_input_text( $table_mail_conf->data[2][1] = html_print_input_text(
'email_from_name', 'email_from_name',
$config['email_from_name'], $config['email_from_name'],
'', '',
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[3][0] = __('SMTP Server'); $table_mail_conf->data[3][0] = __('SMTP Server');
$table_mail_conf->data[3][1] = html_print_input_text( $table_mail_conf->data[3][1] = html_print_input_text(
'email_smtpServer', 'email_smtpServer',
$config['email_smtpServer'], $config['email_smtpServer'],
'', '',
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[4][0] = __('SMTP Port'); $table_mail_conf->data[4][0] = __('SMTP Port');
$table_mail_conf->data[4][1] = html_print_input_text( $table_mail_conf->data[4][1] = html_print_input_text(
'email_smtpPort', 'email_smtpPort',
$config['email_smtpPort'], $config['email_smtpPort'],
'', '',
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[5][0] = __('Encryption'); $table_mail_conf->data[5][0] = __('Encryption');
$table_mail_conf->data[5][1] = html_print_select( $table_mail_conf->data[5][1] = html_print_select(
$encryption, $encryption,
'email_encryption', 'email_encryption',
$config['email_encryption'], $config['email_encryption'],
@ -585,20 +586,20 @@ echo '<legend>'.__('Mail configuration').'</legend>';
__('none'), __('none'),
0, 0,
true true
); );
$table_mail_conf->data[6][0] = __('Email user'); $table_mail_conf->data[6][0] = __('Email user');
$table_mail_conf->data[6][1] = html_print_input_text( $table_mail_conf->data[6][1] = html_print_input_text(
'email_username', 'email_username',
$config['email_username'], $config['email_username'],
'', '',
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[7][0] = __('Email password'); $table_mail_conf->data[7][0] = __('Email password');
$table_mail_conf->data[7][1] = html_print_input_password( $table_mail_conf->data[7][1] = html_print_input_password(
'email_password', 'email_password',
io_output_password( io_output_password(
$config['email_password'] $config['email_password']
@ -607,48 +608,48 @@ echo '<legend>'.__('Mail configuration').'</legend>';
30, 30,
100, 100,
true true
); );
$table_mail_conf->data[7][1] .= ui_print_reveal_password( $table_mail_conf->data[7][1] .= ui_print_reveal_password(
'email_password', 'email_password',
true true
); );
$uniqid = uniqid(); $uniqid = uniqid();
$table_mail_conf->data[8][0] = html_print_button( $table_mail_conf->data[8][0] = html_print_button(
__('Email test'), __('Email test'),
'email_test_dialog', 'email_test_dialog',
false, false,
"show_email_test('".$uniqid."');", "show_email_test('".$uniqid."');",
'class="sub next"', 'class="sub next"',
true true
); );
print_email_test_modal_window($uniqid); print_email_test_modal_window($uniqid);
html_print_input_hidden('update_config', 1); html_print_input_hidden('update_config', 1);
html_print_table($table_mail_conf); html_print_table($table_mail_conf);
echo '</fieldset>'; echo '</fieldset>';
echo '<fieldset>'; echo '<fieldset>';
echo '<div class="action-buttons" style="width: '.$table->width.'">'; echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"');
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
/** /**
* Print the modal window for the summary of each alerts group * Print the modal window for the summary of each alerts group
* *
* @param string $id Id. * @param string $id Id.
* *
* @return void * @return void
*/ */
function print_email_test_modal_window($id) function print_email_test_modal_window($id)
{ {
// Email config table. // Email config table.
$table_mail_test = new stdClass(); $table_mail_test = new stdClass();
$table_mail_test->width = '100%'; $table_mail_test->width = '100%';
@ -679,12 +680,12 @@ echo '<legend>'.__('Mail configuration').'</legend>';
$table_mail_test->data[1][1] = '&nbsp&nbsp<span id="email_test_sent_message" class="invisible"><b>Email sent</b></span><span id="email_test_failure_message" class=invisible"><b>Email could not be sent</b></span>'; $table_mail_test->data[1][1] = '&nbsp&nbsp<span id="email_test_sent_message" class="invisible"><b>Email sent</b></span><span id="email_test_failure_message" class=invisible"><b>Email could not be sent</b></span>';
echo '<div id="email_test_'.$id.'" title="'.__('Check mail configuration').'" class="invisible">'.html_print_table($table_mail_test, true).'</div>'; echo '<div id="email_test_'.$id.'" title="'.__('Check mail configuration').'" class="invisible">'.html_print_table($table_mail_test, true).'</div>';
} }
?> ?>
<script type="text/javascript"> <script type="text/javascript">
function show_timezone () { function show_timezone() {
zone = $("#zone").val(); zone = $("#zone").val();
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -693,19 +694,19 @@ function show_timezone () {
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
$("#timezone").empty(); $("#timezone").empty();
jQuery.each (data, function (id, value) { jQuery.each(data, function(id, value) {
timezone = value; timezone = value;
$("select[name='timezone']").append($("<option>").val(timezone).html(timezone)); $("select[name='timezone']").append($("<option>").val(timezone).html(timezone));
}); });
} }
}); });
} }
function show_email_test(id) { function show_email_test(id) {
$('#email_test_sent_message').hide(); $('#email_test_sent_message').hide();
$('#email_test_failure_message').hide(); $('#email_test_failure_message').hide();
$("#email_test_"+id).dialog({ $("#email_test_" + id).dialog({
resizable: true, resizable: true,
draggable: true, draggable: true,
modal: true, modal: true,
@ -715,27 +716,27 @@ function show_email_test(id) {
background: "black" background: "black"
} }
}); });
} }
function perform_email_test () { function perform_email_test() {
$('#email_test_sent_message').hide(); $('#email_test_sent_message').hide();
$('#email_test_failure_message').hide(); $('#email_test_failure_message').hide();
var test_address = $('#text-email_test_address').val(); var test_address = $('#text-email_test_address').val();
params = { params = {
email_smtpServer : $('#text-email_smtpServer').val(), email_smtpServer: $('#text-email_smtpServer').val(),
email_smtpPort : $('#text-email_smtpPort').val(), email_smtpPort: $('#text-email_smtpPort').val(),
email_username : $('#text-email_username').val(), email_username: $('#text-email_username').val(),
email_password : $('#password-email_password').val(), email_password: $('#password-email_password').val(),
email_encryption : $( "#email_encryption option:selected" ).val(), email_encryption: $("#email_encryption option:selected").val(),
email_from_dir : $('#text-email_from_dir').val(), email_from_dir: $('#text-email_from_dir').val(),
email_from_name : $('#text-email_from_name').val() email_from_name: $('#text-email_from_name').val()
}; };
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
data : { data: {
page: "godmode/setup/setup_general", page: "godmode/setup/setup_general",
test_address: test_address, test_address: test_address,
params: params params: params
@ -755,14 +756,14 @@ function perform_email_test () {
$('#email_test_sent_message').hide(); $('#email_test_sent_message').hide();
}, },
}); });
} }
$(document).ready (function () { $(document).ready(function() {
$("#zone").attr("hidden", true); $("#zone").attr("hidden", true);
$("#timezone").attr("hidden", true); $("#timezone").attr("hidden", true);
$("#change_timezone").click(function () { $("#change_timezone").click(function() {
$("#zone").attr("hidden", false); $("#zone").attr("hidden", false);
$("#timezone").attr("hidden", false); $("#timezone").attr("hidden", false);
}); });
@ -771,49 +772,58 @@ $(document).ready (function () {
$('#ssl-path-tr').show(); $('#ssl-path-tr').show();
} }
$("input[name=use_cert]").change(function () { if ($("input[name=mysql_use_cert]").is(':checked')) {
if( $(this).is(":checked") ) $('#mysql-ssl-path-tr').show();
}
$("input[name=use_cert]").change(function() {
if ($(this).is(":checked"))
$('#ssl-path-tr').show(); $('#ssl-path-tr').show();
else else
$('#ssl-path-tr').hide(); $('#ssl-path-tr').hide();
}); });
$("input[name=https]").change(function (){
if($("input[name=https]").prop('checked')) { $("input[name=mysql_use_cert]").change(function() {
if ($(this).is(":checked"))
$('#mysql-ssl-path-tr').show();
else
$('#mysql-ssl-path-tr').hide();
});
$("input[name=https]").change(function() {
if ($("input[name=https]").prop('checked')) {
$("#dialog").dialog({ $("#dialog").dialog({
modal: true, modal: true,
width: 500, width: 500,
buttons:[ buttons: [{
{
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-next', class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-next',
text: "<?php echo __('OK'); ?>", text: "<?php echo __('OK'); ?>",
click: function(){ click: function() {
$(this).dialog("close"); $(this).dialog("close");
} }
} }]
]
}); });
} }
}) })
$("input[name=force_public_url]").change(function (){ $("input[name=force_public_url]").change(function() {
if($("input[name=force_public_url]").prop('checked')) { if ($("input[name=force_public_url]").prop('checked')) {
$("#force_public_url_dialog").dialog({ $("#force_public_url_dialog").dialog({
modal: true, modal: true,
width: 500, width: 500,
buttons: [ buttons: [{
{
class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-next', class: 'ui-widget ui-state-default ui-corner-all ui-button-text-only sub upd submit-next',
text: "<?php echo __('OK'); ?>", text: "<?php echo __('OK'); ?>",
click: function(){ click: function() {
$(this).dialog("close"); $(this).dialog("close");
} }
} }]
]
}); });
} }
}) })
$('input#button-email_test').click(perform_email_test); $('input#button-email_test').click(perform_email_test);
}); });
</script> </script>

View File

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

View File

@ -31,7 +31,9 @@ function mysql_connect_db(
$user=null, $user=null,
$pass=null, $pass=null,
$port=null, $port=null,
$charset=null $charset=null,
$ssl=null,
$verify=null
) { ) {
global $config; global $config;
@ -55,6 +57,14 @@ function mysql_connect_db(
$port = $config['dbport']; $port = $config['dbport'];
} }
if ($ssl === null && (bool) $config['dbssl'] === true) {
$ssl = $config['dbsslcafile'];
}
if ($verify === null && (bool) $config['sslverifyservercert'] === true) {
$verify = 'ignore verify';
}
// Check if mysqli is available // Check if mysqli is available
if (!isset($config['mysqli'])) { if (!isset($config['mysqli'])) {
$config['mysqli'] = extension_loaded(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 // 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 you want persistent connections change it to mysql_pconnect().
if ($config['mysqli']) { if ($config['mysqli']) {
if (empty($ssl)) {
$connect_id = mysqli_connect($host, $user, $pass, $db, $port); $connect_id = mysqli_connect($host, $user, $pass, $db, $port);
if (mysqli_connect_errno() > 0) { if (mysqli_connect_errno() > 0) {
include 'general/mysqlerr.php'; include 'general/mysqlerr.php';
@ -76,9 +87,25 @@ function mysql_connect_db(
} }
mysqli_select_db($connect_id, $db); mysqli_select_db($connect_id, $db);
} else {
$connect_id = mysqli_init();
mysqli_ssl_set($connect_id, null, null, $ssl, null, null);
if ($verify === null) {
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 { } else {
$connect_id = @mysql_connect($host.':'.$port, $user, $pass, true); $connect_id = @mysql_connect($host.':'.$port, $user, $pass, true);
if (! $connect_id) { if (!$connect_id) {
return false; return false;
} }
@ -117,7 +144,7 @@ function mysql_db_get_all_rows_sql($sql, $search_history_db=false, $cache=true,
$history = false; $history = false;
// Connect to the history DB // Connect to the history DB
if (! isset($config['history_db_connection']) || $config['history_db_connection'] === false) { if (!isset($config['history_db_connection']) || $config['history_db_connection'] === false) {
$config['history_db_connection'] = db_connect($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false); $config['history_db_connection'] = db_connect($config['history_db_host'], $config['history_db_name'], $config['history_db_user'], io_output_password($config['history_db_pass']), $config['history_db_port'], false);
} }
@ -142,13 +169,13 @@ function mysql_db_get_all_rows_sql($sql, $search_history_db=false, $cache=true,
} }
// Append result to the history DB data // Append result to the history DB data
if (! empty($return)) { if (!empty($return)) {
foreach ($return as $row) { foreach ($return as $row) {
array_push($history, $row); array_push($history, $row);
} }
} }
if (! empty($history)) { if (!empty($history)) {
return $history; return $history;
} }
@ -240,7 +267,7 @@ function mysql_db_get_row($table, $field_search, $condition, $fields=false, $cac
} else { } else {
if (is_array($fields)) { if (is_array($fields)) {
$fields = implode(',', $fields); $fields = implode(',', $fields);
} else if (! is_string($fields)) { } else if (!is_string($fields)) {
return false; return false;
} }
} }
@ -403,7 +430,7 @@ function mysql_db_process_sql($sql, $rettype='affected_rows', $dbconnection='',
$cache = $config['dbcache']; $cache = $config['dbcache'];
} }
if ($cache && ! empty($sql_cache[$sql_cache['id']][$sql])) { if ($cache && !empty($sql_cache[$sql_cache['id']][$sql])) {
$retval = $sql_cache[$sql_cache['id']][$sql]; $retval = $sql_cache[$sql_cache['id']][$sql];
$sql_cache['saved'][$sql_cache['id']]++; $sql_cache['saved'][$sql_cache['id']]++;
db_add_database_debug_trace($sql); db_add_database_debug_trace($sql);
@ -518,7 +545,7 @@ function mysql_db_process_sql($sql, $rettype='affected_rows', $dbconnection='',
} }
} }
if (! empty($retval)) { if (!empty($retval)) {
return $retval; return $retval;
} }
@ -594,7 +621,7 @@ function mysql_encapsule_fields_with_same_name_to_instructions($field)
*/ */
function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false) function mysql_db_get_value_filter($field, $table, $filter, $where_join='AND', $search_history_db=false)
{ {
if (! is_array($filter) || empty($filter)) { if (!is_array($filter) || empty($filter)) {
return false; return false;
} }
@ -693,7 +720,7 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
{ {
$fields = []; $fields = [];
if (! is_array($values)) { if (!is_array($values)) {
return ''; return '';
} }
@ -863,7 +890,7 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
$i++; $i++;
} }
return (! empty($query) ? $prefix : '').$query.$group.$order.$limit.$offset; return (!empty($query) ? $prefix : '').$query.$group.$order.$limit.$offset;
} }
@ -945,7 +972,7 @@ function mysql_db_get_row_filter($table, $filter, $fields=false, $where_join='AN
} else { } else {
if (is_array($fields)) { if (is_array($fields)) {
$fields = implode(',', $fields); $fields = implode(',', $fields);
} else if (! is_string($fields)) { } else if (!is_string($fields)) {
return false; return false;
} }
} }
@ -995,7 +1022,7 @@ function mysql_db_get_all_rows_filter($table, $filter=[], $fields=false, $where_
$fields = '*'; $fields = '*';
} else if (is_array($fields)) { } else if (is_array($fields)) {
$fields = implode(',', $fields); $fields = implode(',', $fields);
} else if (! is_string($fields)) { } else if (!is_string($fields)) {
return false; return false;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Main configuration of Pandora FMS * Main configuration of Pandora FMS
* *
@ -30,6 +31,7 @@
require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/functions.php'; require_once __DIR__.'/functions.php';
enterprise_include_once('include/functions_config.php'); enterprise_include_once('include/functions_config.php');
use PandoraFMS\Core\DBMaintainer; use PandoraFMS\Core\DBMaintainer;
use PandoraFMS\Core\Config; use PandoraFMS\Core\Config;
@ -146,7 +148,7 @@ function config_update_config()
return false; return false;
} }
if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) { if (!check_acl($config['id_user'], 0, 'PM') && !is_user_admin($config['id_user'])) {
$config['error_config_update_config'] = []; $config['error_config_update_config'] = [];
$config['error_config_update_config']['correct'] = false; $config['error_config_update_config']['correct'] = false;
$config['error_config_update_config']['message'] = __('Failed updated: User is not admin.'); $config['error_config_update_config']['message'] = __('Failed updated: User is not admin.');
@ -3399,7 +3401,6 @@ function config_check()
$supervisor = new ConsoleSupervisor(false); $supervisor = new ConsoleSupervisor(false);
$supervisor->runBasic(); $supervisor->runBasic();
} }
} }
@ -3424,7 +3425,6 @@ function get_um_url()
} }
return $url; return $url;
} }