From a40c04aa49eb1c40cb52b9e192e51ac336189224 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 27 Apr 2023 09:08:24 +0200 Subject: [PATCH 01/71] #10660 Update the function to create the warp journal table for check the variable config prominent time and prints the timestamp according this --- .../include/ajax/update_manager.php | 70 ++++++++++++++++--- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/ajax/update_manager.php b/pandora_console/include/ajax/update_manager.php index 4e6eefdfd3..175a4a3522 100644 --- a/pandora_console/include/ajax/update_manager.php +++ b/pandora_console/include/ajax/update_manager.php @@ -129,19 +129,67 @@ if ($method === 'draw') { $count = db_get_value('count(*)', '('.$sql.') t'); if ($data) { - $data = array_reduce( - $data, - function ($carry, $item) { - // Transforms array of arrays $data into an array - // of objects, making a post-process of certain fields. - $tmp = (object) $item; + if ($config['prominent_time'] === 'timestamp') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = human_time_comparation($tmp->utimestamp); + $tmp->utimestamp = ''.modules_format_timestamp($tmp->utimestamp).''; - $tmp->utimestamp = human_time_comparation($tmp->utimestamp); + $carry[] = $tmp; + return $carry; + } + ); + } else if ($config['prominent_time'] === 'comparation') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; - $carry[] = $tmp; - return $carry; - } - ); + $carry[] = $tmp; + return $carry; + } + ); + } else if ($config['prominent_time'] === 'compact') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp, 'tiny').''; + + $carry[] = $tmp; + return $carry; + } + ); + } else { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; + + $carry[] = $tmp; + return $carry; + } + ); + } } // Datatables format: RecordsTotal && recordsfiltered. From fdc13256cd776b52b3127496e7b00a5cfd4102ef Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 27 Apr 2023 16:05:37 +0200 Subject: [PATCH 02/71] #9478 create edit delete alerts from meta --- .../godmode/alerts/alert_list.builder.php | 38 ++- pandora_console/godmode/alerts/alert_list.php | 74 ++++++ .../include/ajax/alert_list.ajax.php | 31 ++- pandora_console/include/functions_ui.php | 68 +++++- .../operation/agentes/alerts_status.php | 225 +++++++++++------- .../operation/agentes/estado_agente.php | 18 ++ .../operation/agentes/ver_agente.php | 5 + 7 files changed, 362 insertions(+), 97 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index af380c396c..9e42cd5a44 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -40,29 +40,47 @@ $table->size = []; $table->style[0] = 'width: 50%'; $table->style[1] = 'width: 50%'; -// Add an agent selector -if (! $id_agente) { +if (is_metaconsole() === true) { $params = []; $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_agent'; $params['selectbox_id'] = 'id_agent_module'; $params['javascript_is_function_select'] = true; - $params['metaconsole_enabled'] = false; + $params['metaconsole_enabled'] = true; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; + $params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax'; + $table->data[0][0] = html_print_label_input_block( __('Agent'), - ui_print_agent_autocomplete_input($params) + '
'.ui_print_agent_autocomplete_input($params).'
' ); +} else { + // Add an agent selector. + if (! $id_agente) { + $params = []; + $params['return'] = true; + $params['show_helptip'] = true; + $params['input_name'] = 'id_agent'; + $params['selectbox_id'] = 'id_agent_module'; + $params['javascript_is_function_select'] = true; + $params['metaconsole_enabled'] = false; + $params['use_hidden_input_idagent'] = true; + $params['print_hidden_input_idagent'] = true; + $table->data[0][0] = html_print_label_input_block( + __('Agent'), + ui_print_agent_autocomplete_input($params) + ); + } + + if ($id_agente) { + $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); + } } $modules = []; -if ($id_agente) { - $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); -} - $table->data[0][1] = html_print_label_input_block( __('Module'), html_print_select( @@ -319,7 +337,8 @@ $(document).ready (function () { jQuery.post ( + "ajax.php", {"page" : "operation/agentes/estado_agente", "get_agent_module_last_value" : 1, - "id_agent_module" : this.value + "id_agent_module" : this.value, + "server_name" : $('#text-id_agent').val(), }, function (data, status) { if (data === false) { @@ -338,5 +357,4 @@ $(document).ready (function () { ); }); }); -/* ]]> */ diff --git a/pandora_console/godmode/alerts/alert_list.php b/pandora_console/godmode/alerts/alert_list.php index ce42dd1675..9abe728e5e 100644 --- a/pandora_console/godmode/alerts/alert_list.php +++ b/pandora_console/godmode/alerts/alert_list.php @@ -99,6 +99,19 @@ if ($update_alert) { } if ($create_alert) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_alert_template = (int) get_parameter('template'); $id_agent_module = (int) get_parameter('id_agent_module'); @@ -203,9 +216,28 @@ if ($create_alert) { } } } + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($delete_alert) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_alert_agent_module = (int) get_parameter('id_alert'); $temp = db_get_row('talert_template_modules', 'id', $id_alert_agent_module); @@ -241,6 +273,11 @@ if ($delete_alert) { '', true ); + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($add_action) { @@ -283,6 +320,19 @@ if ($add_action) { } if ($update_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $alert_id = (int) get_parameter('alert_id'); $id_action = (int) get_parameter('action_select_ajax-'.$alert_id); $id_module_action = (int) get_parameter('id_module_action_ajax'); @@ -321,9 +371,28 @@ if ($update_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($delete_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_action = (int) get_parameter('id_action'); $id_alert = (int) get_parameter('id_alert'); @@ -348,6 +417,11 @@ if ($delete_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } } if ($enable_alert) { diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 7d9e372d7e..3c66cf1df9 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -406,6 +406,19 @@ if ($get_actions_module) { } if ($show_update_action_menu) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + if (! check_acl($config['id_user'], 0, 'LW')) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, @@ -436,7 +449,12 @@ if ($show_update_action_menu) { $id_action ); - $data .= '
'; + if (is_metaconsole()) { + $data .= ''; + } else { + $data .= ''; + } + $data .= ''; $data .= html_print_input_hidden( 'update_action', @@ -453,6 +471,11 @@ if ($show_update_action_menu) { $id_action, true ); + $data .= html_print_input_hidden( + 'id_agent', + $server_name, + true + ); if (! $id_agente) { $data .= ''; $data .= '
'; @@ -571,6 +594,11 @@ if ($show_update_action_menu) { true ); $data .= ''; + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } + echo $data; return; } @@ -933,6 +961,7 @@ if ($get_agent_alerts_datatable === true) { $tmp->last_fired = $row[7]; $tmp->status = $row[8]; $tmp->validate = $row[9]; + $tmp->actions = $row[10]; } else { // Open. $tmp->standby = $row[0]; diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 4dcf94edf1..62999b53b3 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1139,6 +1139,7 @@ function ui_format_alert_row( 'last_fired' => 7, 'status' => 8, 'validate' => 9, + 'actions' => 10, ]; } else { $index = [ @@ -1458,6 +1459,69 @@ function ui_format_alert_row( } $data[$index['status']] = ui_print_status_image($status, $title, true); + $data[$index['status']] .= '