From 6dc775649dee49ec6b018f5c46da8f04b7181dce Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 14 Mar 2022 15:29:40 +0100 Subject: [PATCH 1/6] Fix dashboard events responses --- pandora_console/include/ajax/events.php | 14 +++++++------- .../include/lib/Dashboard/Widgets/events_list.php | 1 + pandora_console/include/styles/pandora.css | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index e8a0d5831a..8446748cd4 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1578,14 +1578,14 @@ if ($get_extended_event) { $comments = '
'; - $notifications = ''; - $notifications .= ''; - $notifications .= ''; - $notifications .= ''; - $notifications .= ''; - $notifications .= ''; + $notifications = '
'.ui_print_error_message(__('Error adding comment'), '', true).'
'; + $notifications .= '
'.ui_print_success_message(__('Comment added successfully'), '', true).'
'; + $notifications .= '
'.ui_print_error_message(__('Error changing event status'), '', true).'
'; + $notifications .= '
'.ui_print_success_message(__('Event status changed successfully'), '', true).'
'; + $notifications .= '
'.ui_print_error_message(__('Error changing event owner'), '', true).'
'; + $notifications .= '
'.ui_print_success_message(__('Event owner changed successfully'), '', true).'
'; - $loading = ''; + $loading = '
'.html_print_image('images/spinner.gif', true).'
'; $i = 0; $tab['general'] = $i++; diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index 602533e73a..ebd4dfb09f 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -502,6 +502,7 @@ class EventsListWidget extends Widget \ui_require_css_file('events', 'include/styles/', true); \ui_require_css_file('tables', 'include/styles/', true); + \ui_require_javascript_file('pandora_events', 'include/javascript/', true); $this->values['groupId'] = explode(',', $this->values['groupId'][0]); $this->values['tagsId'] = explode(',', $this->values['tagsId'][0]); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index b6a7a72d93..74e6594f97 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -875,6 +875,9 @@ select:-internal-list-box { .invisible_important { display: none !important; } +.invisible_events { + display: none; +} .visible { display: block; From ba6a56b9fc63a9710b39af1992493899b7e440e9 Mon Sep 17 00:00:00 2001 From: Luis Date: Mon, 21 Mar 2022 18:15:58 +0100 Subject: [PATCH 2/6] WIP: event dashboard responses --- pandora_console/include/ajax/events.php | 8 ++++-- pandora_console/include/functions_events.php | 2 ++ .../include/javascript/pandora_dashboards.js | 25 ++++++++++++++++++- .../include/javascript/pandora_events.js | 9 ++++++- .../lib/Dashboard/Widgets/events_list.php | 13 ++++++---- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 8446748cd4..988c458a1c 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1269,10 +1269,14 @@ if ($change_status) { ); if ($return !== false) { + $event_st = events_display_status($new_status); + echo json_encode( [ - 'status' => 'status_ok', - 'user' => db_get_value( + 'status_title' => $event_st['title'], + 'status_img' => html_print_image($event_st['img'], true, false, true), + 'status' => 'status_ok', + 'user' => db_get_value( 'fullname', 'tusuario', 'id_user', diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 26f41a2589..1861134e3f 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -5008,6 +5008,8 @@ function events_page_general($event) $event_st = events_display_status($event['estado']); $data = []; + + $table_general->rowid[7] = 'general_status'; $data[0] = __('Status'); $data[1] = $event_st['title']; $data[2] = html_print_image($event_st['img'], true); diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index aacf542cbb..104073ef84 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -651,7 +651,7 @@ function initialiceLayout(data) { url: data.url, data: { page: data.page, - method: "drawWidget", + method: "drawCell", dashboardId: data.dashboardId, cellId: cellId, newWidth: newWidth, @@ -1329,6 +1329,29 @@ function dashboardShowEventDialog(settings) { close: function() { //$("#refrcounter").countdown("resume"); //$("div.vc-countdown").countdown("resume"); + debugger; + $.ajax({ + method: "post", + url: settings.ajaxUrl, + data: { + page: "operation/dashboard/dashboard", + method: "drawWidget", + dashboardId: settings.dashboardId, + cellId: settings.cellId, + widgetId: settings.widgetId, + redraw: 1 + }, + success: function(dataWidget) { + // Widget empty and reload. + $("#widget-" + settings.cellId + " .content-widget").empty(); + $("#widget-" + settings.cellId + " .content-widget").append( + dataWidget + ); + }, + error: function(error) { + console.error(error); + } + }); }, overlay: { opacity: 0.5, diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 357e22318c..6826eb3eed 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -504,7 +504,7 @@ function event_change_status(event_ids) { if ($("#notification_status_error").length) { $("#notification_status_error").hide(); } - + debugger; if (data.status == "status_ok") { if (typeof dt_events !== "undefined") { dt_events.draw(false); @@ -519,6 +519,13 @@ function event_change_status(event_ids) { "N/A" ); } + + $("#general_status") + .find(".general_status") + .text(data.status_title); + $("#general_status") + .find("img") + .attr("src", data.status_img); } else { $("#notification_status_error").show(); } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index ebd4dfb09f..c3b01a177e 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -718,16 +718,19 @@ class EventsListWidget extends Widget $settings = json_encode( [ - 'event' => $event, - 'page' => 'include/ajax/events', - 'cellId' => $this->cellId, - 'ajaxUrl' => \ui_get_full_url( + 'event' => $event, + 'page' => 'include/ajax/events', + 'cellId' => $this->cellId, + 'ajaxUrl' => \ui_get_full_url( 'ajax.php', false, false, false ), - 'result' => false, + 'result' => false, + 'dashboardId' => $this->dashboardId, + 'widgetId' => $this->widgetId, + 'cellId' => $this->cellId, ] ); From 174f6dce511ce3753f3554d1baeecd872d2871a6 Mon Sep 17 00:00:00 2001 From: Calvo Date: Tue, 22 Mar 2022 18:02:53 +0100 Subject: [PATCH 3/6] Fix dashboard event list, Removed missing debugger in code --- pandora_console/include/ajax/events.php | 2 ++ pandora_console/include/functions_events.php | 2 +- .../javascript/multiselect_filtered.js | 1 - .../include/javascript/pandora_dashboards.js | 29 +++++++++++++++++-- .../include/javascript/pandora_events.js | 2 +- .../lib/Dashboard/Widgets/events_list.php | 6 ++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 988c458a1c..45b159dae5 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1588,6 +1588,8 @@ if ($get_extended_event) { $notifications .= '
'.ui_print_success_message(__('Event status changed successfully'), '', true).'
'; $notifications .= '
'.ui_print_error_message(__('Error changing event owner'), '', true).'
'; $notifications .= '
'.ui_print_success_message(__('Event owner changed successfully'), '', true).'
'; + $notifications .= '
'.ui_print_error_message(__('Error deleting event'), '', true).'
'; + $loading = '
'.html_print_image('images/spinner.gif', true).'
'; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 1861134e3f..879c36c38e 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -3752,7 +3752,7 @@ function events_page_responses($event, $childrens_ids=[]) $data = []; $data[0] = __('Delete event'); $data[1] = ''; - $data[2] = '
'; + $data[2] = ''; $data[2] .= html_print_button( __('Delete event'), 'delete_button', diff --git a/pandora_console/include/javascript/multiselect_filtered.js b/pandora_console/include/javascript/multiselect_filtered.js index 74f24f5a0a..dcaee528b0 100644 --- a/pandora_console/include/javascript/multiselect_filtered.js +++ b/pandora_console/include/javascript/multiselect_filtered.js @@ -232,7 +232,6 @@ function fmModuleChange(uniqId, isMeta) { selection: showCommonModules }, function(data) { - debugger; $("#filtered-module-modules-" + uniqId).html(""); if (data) { jQuery.each(data, function(id, value) { diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 104073ef84..a0f8f0a5d5 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -651,7 +651,7 @@ function initialiceLayout(data) { url: data.url, data: { page: data.page, - method: "drawCell", + method: "drawWidget", dashboardId: data.dashboardId, cellId: cellId, newWidth: newWidth, @@ -1326,10 +1326,35 @@ function dashboardShowEventDialog(settings) { resizable: true, draggable: true, modal: true, + create: function() { + $("#button-delete_button").removeAttr("onclick"); + $("#button-delete_button").click(function() { + var confirm_message = $("#hidden-delete_confirm_message").val(); + if (confirm(confirm_message) == false) { + return false; + } + $.ajax({ + method: "post", + url: settings.ajaxUrl, + data: { + page: "include/ajax/events", + delete_event: 1, + id_evento: settings.event.id_evento, + filter: [] + }, + success: function() { + $("#notification_delete_error").show(); + $("#event_details_window").dialog("close"); + }, + error: function(error) { + console.error(error); + } + }); + }); + }, close: function() { //$("#refrcounter").countdown("resume"); //$("div.vc-countdown").countdown("resume"); - debugger; $.ajax({ method: "post", url: settings.ajaxUrl, diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 6826eb3eed..86107bb03d 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -504,7 +504,7 @@ function event_change_status(event_ids) { if ($("#notification_status_error").length) { $("#notification_status_error").hide(); } - debugger; + if (data.status == "status_ok") { if (typeof dt_events !== "undefined") { dt_events.draw(false); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index c3b01a177e..21336e7419 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -669,6 +669,12 @@ class EventsListWidget extends Widget true ); + $output .= \html_print_input_hidden( + 'delete_confirm_message', + __('Are you sure?'), + true + ); + $table = new \StdClass; $table->class = 'widget_groups_status databox'; $table->cellspacing = '1'; From 6ed885118852db58092aa59de4b0d297708142f3 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 24 Mar 2022 18:52:06 +0100 Subject: [PATCH 4/6] Fix event list widget actions on dashboard --- pandora_console/include/ajax/events.php | 73 +++++++++++++++++-- pandora_console/include/functions_events.php | 14 ++-- .../include/javascript/pandora_dashboards.js | 4 +- .../include/javascript/pandora_events.js | 4 + .../lib/Dashboard/Widgets/events_list.php | 7 ++ 5 files changed, 88 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 45b159dae5..e74006d406 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -26,6 +26,8 @@ * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Node; + // Begin. global $config; @@ -86,6 +88,7 @@ $get_event_filters = get_parameter('get_event_filters', 0); $get_comments = (bool) get_parameter('get_comments', false); $get_events_fired = (bool) get_parameter('get_events_fired'); $get_id_source_event = get_parameter('get_id_source_event'); +$node_id = (int) get_parameter('node_id', 0); if ($get_comments === true) { $event = get_parameter('event', false); $filter = get_parameter('filter', false); @@ -195,7 +198,23 @@ if ($delete_event) { return; } - $r = events_delete($id_evento, $filter); + if ($node_id > 0) { + try { + $node = new Node($node_id); + $node->connect(); + $r = events_delete($id_evento, $filter, false, true); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + $success = false; + echo 'owner_error'; + } finally { + $node->disconnect(); + } + } else { + $r = events_delete($id_evento, $filter); + } + if ($r === false) { echo 'Failed'; } else { @@ -1261,12 +1280,32 @@ if ($change_status) { $event_ids = get_parameter('event_ids'); $new_status = get_parameter('new_status'); - $return = events_change_status( - explode(',', $event_ids), - $new_status, - $meta, - $history - ); + if ($node_id > 0) { + try { + $node = new Node($node_id); + $node->connect(); + $return = events_change_status( + explode(',', $event_ids), + $new_status, + $meta, + $history + ); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + $success = false; + echo 'owner_error'; + } finally { + $node->disconnect(); + } + } else { + $return = events_change_status( + explode(',', $event_ids), + $new_status, + $meta, + $history + ); + } if ($return !== false) { $event_st = events_display_status($new_status); @@ -1310,7 +1349,22 @@ if ($change_owner) { $new_owner = ''; } - $return = events_change_owner($event_id, $new_owner, true, $meta, $history); + if ($node_id > 0) { + try { + $node = new Node($node_id); + $node->connect(); + $return = events_change_owner($event_id, $new_owner, true, $meta, $history); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + $success = false; + echo 'owner_error'; + } finally { + $node->disconnect(); + } + } else { + $return = events_change_owner($event_id, $new_owner, true, $meta, $history); + } if ($return) { echo 'owner_ok'; @@ -1415,6 +1469,9 @@ if ($get_extended_event) { // Print group_rep in a hidden field to recover it from javascript. html_print_input_hidden('group_rep', (int) $group_rep); + if ($node_id > 0) { + html_print_input_hidden('node_id', (int) $node_id); + } if ($event === false) { return; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 879c36c38e..10a77f9d5c 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -352,13 +352,14 @@ function events_get_column_names($fields, $table_alias=false) /** * Validates all events matching target filter. * - * @param integer $id_evento Master event. - * @param array $filter Optional. Filter options. - * @param boolean $history Apply on historical table. + * @param integer $id_evento Master event. + * @param array $filter Optional. Filter options. + * @param boolean $history Apply on historical table. + * @param boolean $force_node Force node table. * * @return integer Events validated or false if error. */ -function events_delete($id_evento, $filter=null, $history=false) +function events_delete($id_evento, $filter=null, $history=false, $force_node=false) { if (!isset($id_evento) || $id_evento <= 0) { return false; @@ -368,7 +369,10 @@ function events_delete($id_evento, $filter=null, $history=false) $filter = ['group_rep' => 0]; } - $table = events_get_events_table(is_metaconsole(), $history); + $table = events_get_events_table( + ($force_node === false) ? is_metaconsole() : false, + $history + ); switch ($filter['group_rep']) { case '0': diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index a0f8f0a5d5..928896ef90 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -1313,7 +1313,8 @@ function dashboardShowEventDialog(settings) { dialog_page: "", meta: 0, history: 0, - filter: [] + filter: [], + node_id: settings.node_id }, dataType: "html", success: function(data) { @@ -1339,6 +1340,7 @@ function dashboardShowEventDialog(settings) { data: { page: "include/ajax/events", delete_event: 1, + node_id: settings.node_id, id_evento: settings.event.id_evento, filter: [] }, diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 86107bb03d..eda55136f5 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -476,6 +476,7 @@ function event_change_status(event_ids) { var new_status = $("#estado").val(); var meta = $("#hidden-meta").val(); var history = $("#hidden-history").val(); + var node_id = $("#hidden-node_id").val(); $("#button-status_button").attr("disabled", "disabled"); $("#response_loading").show(); @@ -487,6 +488,7 @@ function event_change_status(event_ids) { event_ids: event_ids, new_status: new_status, meta: meta, + node_id: node_id, history: history }, type: "POST", @@ -540,6 +542,7 @@ function event_change_owner() { var new_owner = $("#id_owner").val(); var meta = $("#hidden-meta").val(); var history = $("#hidden-history").val(); + var node_id = $("#hidden-node_id").val(); $("#button-owner_button").attr("disabled", "disabled"); $("#response_loading").show(); @@ -551,6 +554,7 @@ function event_change_owner() { event_id: event_id, new_owner: new_owner, meta: meta, + node_id: node_id, history: history }, type: "POST", diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index 21336e7419..e0c1bfe3cf 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -669,6 +669,12 @@ class EventsListWidget extends Widget true ); + $output .= \html_print_input_hidden( + 'meta', + is_metaconsole(), + true + ); + $output .= \html_print_input_hidden( 'delete_confirm_message', __('Are you sure?'), @@ -737,6 +743,7 @@ class EventsListWidget extends Widget 'dashboardId' => $this->dashboardId, 'widgetId' => $this->widgetId, 'cellId' => $this->cellId, + 'node_id' => $this->nodeId, ] ); From 5e6bdaeb1592f8b108980757ecf6f376a9f092d2 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 25 Mar 2022 14:05:38 +0100 Subject: [PATCH 5/6] Fix events dashboard user owner entities --- pandora_console/include/ajax/events.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index e74006d406..04bb68a2a8 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1380,9 +1380,11 @@ if ($change_owner) { if ($get_extended_event) { global $config; - $event = get_parameter('event', false); + $event = io_safe_output(get_parameter('event', false)); $filter = get_parameter('filter', false); + $event = io_safe_output($event); + if ($event === false) { return; } From 4109d9485351aecc4b189c7e86478c835e075180 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 25 Mar 2022 14:07:44 +0100 Subject: [PATCH 6/6] Fix events dashboard user owner entities --- pandora_console/include/ajax/events.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 04bb68a2a8..8daf7bb786 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1383,8 +1383,6 @@ if ($get_extended_event) { $event = io_safe_output(get_parameter('event', false)); $filter = get_parameter('filter', false); - $event = io_safe_output($event); - if ($event === false) { return; }