From 2521b32f1365363dcc0bd7ed8ab589cf481559fd Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Mon, 8 Feb 2021 16:33:54 +0100 Subject: [PATCH 1/3] WIP: Backup upload --- .../massive/massive_add_action_alerts.php | 3 +- .../godmode/massive/massive_edit_modules.php | 3 +- .../godmode/massive/massive_operations.php | 18 ++++--- pandora_console/include/functions_ui.php | 52 +++++++++++++++++++ pandora_console/include/styles/pandora.css | 13 +++++ 5 files changed, 80 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 4107c193ec..7bfbbee09f 100755 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -259,6 +259,7 @@ echo ''; echo ''; +ui_require_javascript_file('massive_operations'); ui_require_jquery_file('form'); ui_require_jquery_file('pandora.controls'); ?> @@ -276,7 +277,7 @@ $(document).ready (function () { get_parameters_count + post_parameters_count; if (count_parameters > limit_parameters_massive) { - alert(""); + showMassiveOperationMessage(); return false; } }); diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 07a3d94174..a097b460ca 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -1185,6 +1185,7 @@ $table->data['edit1'][1] = ''; // Hack to translate text "none" in PHP to javascript echo ''; echo ''; + ui_require_javascript_file('massive_operations'); ui_require_jquery_file('pandora.controls'); if ($selection_mode == 'modules') { @@ -1213,7 +1214,7 @@ $(document).ready (function () { get_parameters_count + post_parameters_count; if (count_parameters > limit_parameters_massive) { - alert(""); + showMassiveOperationMessage(''); return false; } }); diff --git a/pandora_console/godmode/massive/massive_operations.php b/pandora_console/godmode/massive/massive_operations.php index 8aa329508b..b82d4dcda9 100755 --- a/pandora_console/godmode/massive/massive_operations.php +++ b/pandora_console/godmode/massive/massive_operations.php @@ -316,11 +316,15 @@ $submit_template_enabled = get_parameter('id_alert_template_enabled'); $submit_template_not_standby = get_parameter('id_alert_template_not_standby'); $submit_template_standby = get_parameter('id_alert_template_standby'); $submit_add = get_parameter('crtbutton'); - -echo '
'; -echo html_print_image('images/wait.gif', true, ['border' => '0']).'
'; -echo ''.__('Please wait...').''; -echo '
'; +// Waiting spinner. +ui_print_spinner(__('Loading')); +// Modal for show messages. +html_print_div( + [ + 'id' => 'massive_modal', + 'content' => '', + ] +); ?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index d3005d5639..fcf9adce0d 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -6273,3 +6273,55 @@ function ui_print_reveal_password(string $name, bool $return=false) echo $output; } + + +/** + * Generate a spinner box for waiting times + * + * @param string $text Text for show in spinner. English Loading for default. + * @param boolean $return If true, return the string with the formed element. + * + * @return string + */ +function ui_print_spinner(string $text='Loading', bool $return=false) +{ + $output = ''; + + $output .= '
'; + + $output .= html_print_div( + [ + 'id' => 'loading_spinner', + 'class' => 'white_box invisible', + 'content' => ''.$text.'...'.html_print_image( + 'images/spinner.gif', + true, + [ + 'border' => '0', + 'width' => '25px', + 'heigth' => '25px', + ] + ), + ], + true + ); + + $output .= '
'; + + $output .= ' + + '; + + if ($return === true) { + return $output; + } else { + echo $output; + } +} diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 9a1ce23dca..c2cb379ea4 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -792,6 +792,7 @@ p.center { cursor: help; } +/* Legacy spinner */ #loading { position: fixed; width: 200px; @@ -802,6 +803,18 @@ p.center { padding: 20px; } +/* New standard spinner */ +#loading_spinner { + position: fixed; + margin-left: 30%; + text-align: center; + top: 50%; + background-color: #fff; + border: 2px solid #82b92e; + box-shadow: 2px 2px 2px #9dbba1; + padding: 20px; +} + .tactical_set legend { text-align: left; color: #3f3f3f; From e727f7c276a63d515f1fc89c040b4e732056d17b Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 12 Feb 2021 11:28:13 +0100 Subject: [PATCH 2/3] Added modals and fixed some bugs --- .../massive/massive_add_action_alerts.php | 67 ++++++------- .../godmode/massive/massive_add_alerts.php | 14 ++- .../godmode/massive/massive_add_profiles.php | 48 +++++---- .../godmode/massive/massive_copy_modules.php | 60 +++++++----- .../massive/massive_delete_action_alerts.php | 45 ++++++--- .../godmode/massive/massive_delete_agents.php | 64 ++++++------ .../godmode/massive/massive_delete_alerts.php | 49 ++++++---- .../massive/massive_delete_modules.php | 71 +++++++------- .../massive/massive_delete_profiles.php | 48 +++++---- .../godmode/massive/massive_edit_agents.php | 85 +++++++++------- .../godmode/massive/massive_edit_modules.php | 93 +++++++++--------- .../godmode/massive/massive_edit_plugins.php | 44 ++++++--- .../massive/massive_enable_disable_alerts.php | 39 +++++--- .../godmode/massive/massive_operations.php | 84 ++++++++++------ .../massive/massive_standby_alerts.php | 43 +++++--- .../include/functions_massive_operations.php | 97 +++++++++++++++++++ pandora_console/include/functions_ui.php | 3 +- .../include/javascript/massive_operations.js | 93 ++++++++++++++++++ pandora_console/include/styles/pandora.css | 1 + 19 files changed, 690 insertions(+), 358 deletions(-) create mode 100644 pandora_console/include/functions_massive_operations.php create mode 100644 pandora_console/include/javascript/massive_operations.js diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 7bfbbee09f..f9a02c8545 100755 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -1,17 +1,32 @@ data[1][0] .= ''; $table->data[1][1] = html_print_select([], 'id_agents[]', 0, false, __('Any'), '', true, true); $table->data[2][0] = __('Alert templates'); -$table->data[2][0] .= ''; $table->data[2][1] = html_print_select([], 'id_alert_templates[]', '', '', '', '', true, true, true, '', $alert_templates == 0); $table->data[2][2] = __('When select agents'); $table->data[2][2] .= '
'; @@ -251,10 +263,8 @@ $agents_with_templates_json = json_encode($agents_with_templates_json); echo ""; -echo '
'; -html_print_input_hidden('add', 1); -html_print_submit_button(__('Add'), 'go', false, 'class="sub add"'); -echo '
'; +attachActionButton('add', 'create', $table->width); + echo ''; echo ''; @@ -265,23 +275,8 @@ ui_require_jquery_file('pandora.controls'); ?> - - "+value+""; }); $("#id_alert_templates").append (options); - $("#template_loading").hide (); + hideSpinner(); $select_template.enable (); }, "json" diff --git a/pandora_console/include/functions_massive_operations.php b/pandora_console/include/functions_massive_operations.php new file mode 100644 index 0000000000..389d87ddcc --- /dev/null +++ b/pandora_console/include/functions_massive_operations.php @@ -0,0 +1,97 @@ + 'action-buttons', + 'style' => sprintf('width: %s', $tableWidth), + 'content' => html_print_input_hidden( + $action, + 1 + ).html_print_button( + __($caption), + 'go', + false, + '', + sprintf('class="sub %s"', $class), + true + ), + ], + $return + ); +} diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index fcf9adce0d..8cb234db8e 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -6277,8 +6277,9 @@ function ui_print_reveal_password(string $name, bool $return=false) /** * Generate a spinner box for waiting times + * TIP: It's made for Massive Operations, but it migth used in entire project. * - * @param string $text Text for show in spinner. English Loading for default. + * @param string $text Text for show in spinner. English term Loading for default. * @param boolean $return If true, return the string with the formed element. * * @return string diff --git a/pandora_console/include/javascript/massive_operations.js b/pandora_console/include/javascript/massive_operations.js new file mode 100644 index 0000000000..dd1c8acd13 --- /dev/null +++ b/pandora_console/include/javascript/massive_operations.js @@ -0,0 +1,93 @@ +/** global $ */ +function massiveOperationValidation(contents, totalCount, limit, thisForm) { + var output = false; + + // If the amount of changes exceed the limit, the operation stops. + if (totalCount > limit) { + // Set the content. + $("#massive_modal") + .empty() + .html(contents.html); + // Set the title. + $("#massive_modal").prop("title", contents.title); + // Build the dialog for show the mesage. + $("#massive_modal").dialog({ + resizable: true, + draggable: true, + modal: true, + width: 800, + buttons: [ + { + text: "OK", + click: function() { + hideSpinner(); + $(this).dialog("close"); + return false; + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + } + }); + + return false; + } else { + confirmDialog({ + title: contents.title, + message: contents.question, + ok: contents.ok, + cancel: contents.cancel, + onAccept: function() { + showSpinner(); + output = true; + $("#" + thisForm).submit(); + }, + onDeny: function() { + hideSpinner(); + return false; + } + }); + } + + return output; +} + +/* +function showMassiveOperationMessage(message) { + $("#massive_modal") + .empty() + .html(message); + + $("#massive_modal").prop("title", "Massive operations"); + + $("#massive_modal").dialog({ + resizable: true, + draggable: true, + modal: true, + width: 800, + buttons: [ + { + text: "OK", + click: function() { + $(this).dialog("close"); + hideSpinner(); + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + } + }); +} +*/ diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index c2cb379ea4..79e5572823 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -813,6 +813,7 @@ p.center { border: 2px solid #82b92e; box-shadow: 2px 2px 2px #9dbba1; padding: 20px; + z-index: 100; } .tactical_set legend { From 6ee5b9c3e9c43b1a54856cf3d8f4c637a146513a Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 4 Mar 2021 11:33:21 +0100 Subject: [PATCH 3/3] Fix issues --- .../godmode/massive/massive_edit_plugins.php | 35 ++-------- .../include/javascript/massive_operations.js | 65 ++++++++++--------- 2 files changed, 39 insertions(+), 61 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_plugins.php b/pandora_console/godmode/massive/massive_edit_plugins.php index 1b721ac1a5..bcbed6238d 100644 --- a/pandora_console/godmode/massive/massive_edit_plugins.php +++ b/pandora_console/godmode/massive/massive_edit_plugins.php @@ -417,35 +417,6 @@ echo ''; canSubmit = val; $submitButton.prop('disabled', !val); } - - var showSpinner = function () { - var $loadingSpinner = $pluginsSelect.siblings('img#loading_spinner'); - - if ($loadingSpinner.length > 0) { - // Display inline instead using the show function - // cause its absolute positioning. - $loadingSpinner.css('display', 'inline'); - return; - } - - $loadingSpinner = $(''); - - $loadingSpinner - .prop('id', 'loading_spinner') - .css('padding-left', '5px') - .css('position', 'absolute') - .css('top', $pluginsSelect.position().top + 'px') - .prop('src', "images/spinner.gif"); - - $pluginsSelect.parent().append($loadingSpinner); - } - - var hideSpinner = function () { - var $loadingSpinner = $pluginsSelect.siblings('img#loading_spinner'); - - if ($loadingSpinner.length > 0) - $loadingSpinner.hide(); - } var clearModulePluginMacrosValues = function () { $('input.plugin-macro') @@ -876,6 +847,7 @@ echo ''; } var errorHandler = function (error) { + hideSpinner(); console.log(": " + error.message); // alert(": " + err.message); @@ -939,7 +911,10 @@ echo ''; $agentModulesRow.show(); } else { - alert(""); + var contents = {}; + contents.html = ''; + contents.title = ''; + showMassiveModal(contents); // Abort the another call if (typeof pluginXHR !== 'undefined') { diff --git a/pandora_console/include/javascript/massive_operations.js b/pandora_console/include/javascript/massive_operations.js index dd1c8acd13..2335c2a305 100644 --- a/pandora_console/include/javascript/massive_operations.js +++ b/pandora_console/include/javascript/massive_operations.js @@ -4,37 +4,7 @@ function massiveOperationValidation(contents, totalCount, limit, thisForm) { // If the amount of changes exceed the limit, the operation stops. if (totalCount > limit) { - // Set the content. - $("#massive_modal") - .empty() - .html(contents.html); - // Set the title. - $("#massive_modal").prop("title", contents.title); - // Build the dialog for show the mesage. - $("#massive_modal").dialog({ - resizable: true, - draggable: true, - modal: true, - width: 800, - buttons: [ - { - text: "OK", - click: function() { - hideSpinner(); - $(this).dialog("close"); - return false; - } - } - ], - overlay: { - opacity: 0.5, - background: "black" - }, - closeOnEscape: false, - open: function(event, ui) { - $(".ui-dialog-titlebar-close").hide(); - } - }); + showMassiveModal(contents); return false; } else { @@ -58,6 +28,39 @@ function massiveOperationValidation(contents, totalCount, limit, thisForm) { return output; } +function showMassiveModal(contents) { + $("#massive_modal") + .empty() + .html(contents.html); + // Set the title. + $("#massive_modal").prop("title", contents.title); + // Build the dialog for show the mesage. + $("#massive_modal").dialog({ + resizable: true, + draggable: true, + modal: true, + width: 800, + buttons: [ + { + text: "OK", + click: function() { + hideSpinner(); + $(this).dialog("close"); + return false; + } + } + ], + overlay: { + opacity: 0.5, + background: "black" + }, + closeOnEscape: false, + open: function(event, ui) { + $(".ui-dialog-titlebar-close").hide(); + } + }); +} + /* function showMassiveOperationMessage(message) { $("#massive_modal")