From 5feb11c547e2eb54a939c9c6a028a2542dd2fefd Mon Sep 17 00:00:00 2001 From: Daniel Cebrian <daniel.cebrian@pandorafms.com> Date: Wed, 31 Jan 2024 16:34:25 +0100 Subject: [PATCH] 9992 added email test dialog in metaconsole --- .../godmode/setup/setup_general.php | 112 ------------------ pandora_console/include/functions_html.php | 49 ++++++++ pandora_console/include/javascript/pandora.js | 57 +++++++++ 3 files changed, 106 insertions(+), 112 deletions(-) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 46a91e27c6..3366fcc6f8 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -960,60 +960,6 @@ echo '<legend>'.__('Mail configuration').'</legend>'; ); echo '</form>'; - - - /** - * Print the modal window for the summary of each alerts group - * - * @param string $id Id. - * - * @return void - */ - function print_email_test_modal_window($id) - { - // Email config table. - $table_mail_test = new stdClass(); - $table_mail_test->width = '100%'; - $table_mail_test->class = 'filter-table-adv'; - $table_mail_test->data = []; - - $table_mail_test->data[0][] = html_print_label_input_block( - __('Address'), - html_print_input_text( - 'email_test_address', - '', - '', - 35, - 100, - true - ) - ); - - $table_mail_test->data[1][] = '  <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->colspan[2][0] = 2; - $submitButton = html_print_div( - [ - 'class' => 'action-buttons-right-forced', - 'content' => html_print_button( - __('Send'), - 'email_test', - false, - '', - [ - 'icon' => 'cog', - 'mode' => 'mini', - ], - true - ), - ], - true - ); - - echo '<div id="email_test_'.$id.'" title="'.__('Check mail configuration').'" class="invisible">'.html_print_table($table_mail_test, true).$submitButton.'</div>'; - } - - ?> <script type="text/javascript"> function show_timezone () { @@ -1033,62 +979,6 @@ function show_timezone () { }); } -function show_email_test(id) { - $('#email_test_sent_message').hide(); - $('#email_test_failure_message').hide(); - - $("#email_test_"+id).dialog({ - resizable: true, - draggable: true, - modal: true, - width: 450, - overlay: { - opacity: 0.5, - background: "black" - } - }); -} - -function perform_email_test () { - $('#email_test_sent_message').hide(); - $('#email_test_failure_message').hide(); - - var test_address = $('#text-email_test_address').val(); - params = { - email_smtpServer : $('#text-email_smtpServer').val(), - email_smtpPort : $('#text-email_smtpPort').val(), - email_username : $('#text-email_username').val(), - email_password : $('#password-email_password').val(), - email_encryption : $( "#email_encryption option:selected" ).val(), - email_from_dir : $('#text-email_from_dir').val(), - email_from_name : $('#text-email_from_name').val() - }; - - $.ajax({ - type: "POST", - url: "ajax.php", - data : { - page: "godmode/setup/setup_general", - test_address: test_address, - params: params - }, - dataType: "json", - success: function(data) { - if (parseInt(data) === 1) { - $('#email_test_sent_message').show(); - $('#email_test_failure_message').hide(); - } else { - $('#email_test_failure_message').show(); - $('#email_test_sent_message').hide(); - } - }, - error: function() { - $('#email_test_failure_message').show(); - $('#email_test_sent_message').hide(); - }, - }); -} - $(document).ready (function () { $("#zone").attr("hidden", true); @@ -1146,8 +1036,6 @@ $(document).ready (function () { } }) - $('#button-email_test').click(perform_email_test); - $("#right_iblacklist").click (function () { jQuery.each($("select[name='inventory_changes_blacklist_out[]'] option:selected"), function (key, value) { imodule_name = $(value).html(); diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 580802fc94..3a4ca01ebb 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -7691,3 +7691,52 @@ function html_print_wizard_diagnosis( echo $output; } } + + +/** + * Print the modal window for the summary of each alerts group + * + * @param string $id Id. + * + * @return void + */ +function print_email_test_modal_window($id) +{ + // Email config table. + $table_mail_test = new stdClass(); + $table_mail_test->width = '100%'; + $table_mail_test->class = 'filter-table-adv'; + $table_mail_test->data = []; + $table_mail_test->data[0][] = html_print_label_input_block( + __('Address'), + html_print_input_text( + 'email_test_address', + '', + '', + 35, + 100, + true + ) + ); + $table_mail_test->data[1][] = '  <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->colspan[2][0] = 2; + $submitButton = html_print_div( + [ + 'class' => 'action-buttons-right-forced', + 'content' => html_print_button( + __('Send'), + 'email_test', + false, + 'perform_email_test()', + [ + 'icon' => 'cog', + 'mode' => 'mini', + ], + true + ), + ], + true + ); + + echo '<div id="email_test_'.$id.'" title="'.__('Check mail configuration').'" class="invisible">'.html_print_table($table_mail_test, true).$submitButton.'</div>'; +} diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 8d7bf3a1b2..2c39e69288 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2621,3 +2621,60 @@ function christmas_click(flagEasternEgg) { }, 120000); } } + +function perform_email_test() { + $("#email_test_sent_message").hide(); + $("#email_test_failure_message").hide(); + + var test_address = $("#text-email_test_address").val(); + var params = { + email_smtpServer: $("#text-email_smtpServer").val(), + email_smtpPort: $("#text-email_smtpPort").val(), + email_username: $("#text-email_username").val(), + email_password: $("#password-email_password").val(), + email_encryption: $("#email_encryption option:selected").val(), + email_from_dir: $("#text-email_from_dir").val(), + email_from_name: $("#text-email_from_name").val() + }; + + $.ajax({ + type: "POST", + url: "ajax.php", + data: { + page: "godmode/setup/setup_general", + test_address: test_address, + params: params + }, + dataType: "json", + success: function(data) { + if (parseInt(data) === 1) { + $("#email_test_sent_message").show(); + $("#email_test_failure_message").hide(); + } else { + console.log($("#email_test_failure_message")); + $("#email_test_failure_message").show(); + $("#email_test_sent_message").hide(); + } + }, + error: function() { + $("#email_test_failure_message").show(); + $("#email_test_sent_message").hide(); + } + }); +} + +function show_email_test(id) { + $("#email_test_sent_message").hide(); + $("#email_test_failure_message").hide(); + + $("#email_test_" + id).dialog({ + resizable: true, + draggable: true, + modal: true, + width: 450, + overlay: { + opacity: 0.5, + background: "black" + } + }); +}