From 22f151bc6da6f6c9f0260cfc6f41c6acb01a60ad Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 28 Apr 2021 17:01:50 +0200 Subject: [PATCH 01/20] fixed bug in users search --- .../operation/search_users.getdata.php | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/pandora_console/operation/search_users.getdata.php b/pandora_console/operation/search_users.getdata.php index 99ca08ee68..9ba7ee24af 100644 --- a/pandora_console/operation/search_users.getdata.php +++ b/pandora_console/operation/search_users.getdata.php @@ -221,7 +221,18 @@ if ($searchUsers) { // Check ACLs $users_id = []; foreach ($users as $key => $user) { - if (!check_acl($config['id_user'], users_get_groups($user['id_user']), 'UM') && $config['id_user'] != $user['id_user']) { + $user_can_manage_all = users_can_manage_group_all('UM'); + + $user_groups = users_get_groups( + $user['id_user'], + 'AR', + $user_can_manage_all + ); + + // Get group IDs. + $user_groups = array_keys($user_groups); + + if (!check_acl_one_of_groups($config['id_user'], $user_groups, 'UM') && $config['id_user'] != $user['id_user']) { unset($users[$key]); } else { $users_id[] = $user['id_user']; @@ -229,33 +240,9 @@ if ($searchUsers) { } if ($only_count) { + $totalUsers = count($users); unset($users); } - - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $sql = "SELECT COUNT(id_user) AS count FROM tusuario - WHERE id_user LIKE '%".$stringSearchSQL."%' OR - fullname LIKE '%".$stringSearchSQL."%' OR - firstname LIKE '%".$stringSearchSQL."%' OR - lastname LIKE '%".$stringSearchSQL."%' OR - middlename LIKE '%".$stringSearchSQL."%' OR - email LIKE '%".$stringSearchSQL."%'"; - break; - - case 'oracle': - $sql = "SELECT COUNT(id_user) AS count FROM tusuario - WHERE upper(id_user) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(fullname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(firstname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(lastname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(middlename) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(email LIKE) '%".strtolower($stringSearchSQL)."%'"; - break; - } - - $totalUsers = db_get_value_sql($sql); } else { $totalUsers = 0; } From 1c1e25e71261830a6429b8b33132d65fed0e6e30 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 14 May 2021 14:54:09 +0200 Subject: [PATCH 02/20] Added new item type in reports --- .../reporting_builder.item_editor.php | 155 ++++++++++++++++++ .../include/functions_reporting.php | 13 ++ .../include/functions_reporting_html.php | 63 ++++++- pandora_console/include/functions_reports.php | 5 + 4 files changed, 235 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ed52b23aad..c7dd995dbe 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3020,6 +3020,144 @@ $class = 'databox filters'; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5223,6 +5361,12 @@ function chooseType() { $("#row_users").hide(); $("#row_profiles_group").hide(); $("#row_select_by_group").hide(); + $("#row_os").hide(); + $("#row_custom_field").hide(); + $("#row_agent_status").hide(); + $("#row_agent_version").hide(); + $("#row_agent_remote_conf").hide(); + $("#row_module_free_search").hide(); // SLA list default state. @@ -5764,6 +5908,17 @@ function chooseType() { break; + case 'agents_inventory': + $("#row_group").show(); + $("#row_os").show(); + $("#row_custom_field").show(); + $("#row_status").show(); + $("#row_agent_version").show(); + $("#row_agent_remote_conf").show(); + $("#row_module_free_search").show(); + + break; + case 'inventory': $("#row_description").show(); $("#row_group").show(); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index e82bac98ce..93aa30d878 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -734,6 +734,13 @@ function reporting_make_reporting_data( ); break; + case 'agents_inventory': + $report['contents'][] = reporting_agents_inventory( + $report, + $content + ); + break; + case 'inventory': $report['contents'][] = reporting_inventory( $report, @@ -2256,6 +2263,12 @@ function reporting_event_report_module( } +function reporting_agents_inventory($report, $content) +{ + hd($content); +} + + function reporting_inventory_changes($report, $content, $type) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index de800f09d3..211d8b193d 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -247,7 +247,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) } $table->colspan['description_row']['description'] = 3; - + hd($item['type']); switch ($item['type']) { case 'availability': default: @@ -377,6 +377,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) reporting_html_agent_module($table, $item); break; + case 'agents_inventory': + reporting_html_agents_inventory($table, $item); + break; + case 'inventory': reporting_html_inventory($table, $item); break; @@ -1425,6 +1429,63 @@ function reporting_html_event_report_module($table, $item, $pdf=0) } +/** + * Print in html agents inventory + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param boolean $pdf Print pdf true or false. + * + * @return html + */ +function reporting_html_agents_inventory($table, $item, $pdf=0) +{ + hd('agents inventory'); + hd($item); + + global $config; + + if (empty($item['data']) === false) { + $table_data = new stdClass(); + $table_data->width = '100%'; + $table_data->headstyle = []; + $table_data->headstyle[0] = 'text-align: left;'; + $table_data->style = []; + $table_data->style[0] = 'text-align: left;'; + $table_data->head = [ + __('Name'), + __('Date'), + __('Data'), + __('Status'), + ]; + + $table_data->data = []; + $table_data->data[1][0] = $item['data']['agent_name']; + $table_data->data[1][0] .= ' / '; + $table_data->data[1][0] .= $item['data']['module_name']; + + $table_data->data[1][1] = date( + 'Y-m-d H:i:s', + $item['data']['utimestamp'] + ); + } + + if ($pdf === 0) { + $table->colspan['last_value']['cell'] = 3; + $table->cellstyle['last_value']['cell'] = 'text-align: center;'; + $table->data['last_value']['cell'] = html_print_table( + $table_data, + true + ); + } else { + return html_print_table( + $table_data, + true + ); + } +} + + /** * Print in html inventory changes reports * diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index fbf647d392..71fa925ba5 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -848,6 +848,11 @@ function reports_get_report_types($template=false, $not_editor=false) 'name' => __('Group event report'), ]; + $types['agents_inventory'] = [ + 'optgroup' => __('Inventory'), + 'name' => __('Agents inventory'), + ]; + if ($config['enterprise_installed']) { $types['inventory'] = [ 'optgroup' => __('Inventory'), From 7abe6d544668ae0dc0640bcba0d28ed8c62eca0f Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 27 May 2021 11:22:01 +0200 Subject: [PATCH 03/20] created new report item --- .../reporting_builder.item_editor.php | 116 ++++++++++++-- .../godmode/reporting/reporting_builder.php | 24 +++ pandora_console/include/ajax/module.php | 2 +- .../include/functions_reporting.php | 124 ++++++++++++++- .../include/functions_reporting_html.php | 143 ++++++++++++++---- 5 files changed, 360 insertions(+), 49 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index c7dd995dbe..16db89b622 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -62,6 +62,20 @@ $show_sort_options = []; $show_sort_options[1] = __('Ascending'); $show_sort_options[2] = __('Descending'); +// Agents inventory display options. +$agents_inventory_display_options = []; +$agents_inventory_display_options['alias'] = __('Alias'); +$agents_inventory_display_options['direccion'] = __('IP'); +$agents_inventory_display_options['id_os'] = __('OS'); +$agents_inventory_display_options['id_grupo'] = __('Group'); +$agents_inventory_display_options['secondary_groups'] = __('Secondary groups'); +$agents_inventory_display_options['comentarios'] = __('Description'); +$agents_inventory_display_options['url_address'] = __('URL'); +$agents_inventory_display_options['custom_fields'] = __('Custom fields'); +$agents_inventory_display_options['estado'] = __('Status'); +$agents_inventory_display_options['agent_version'] = __('Version'); +$agents_inventory_display_options['remote'] = __('Remote configuration'); + enterprise_include('/godmode/reporting/reporting_builder.item_editor.php'); require_once $config['homedir'].'/include/functions_agents.php'; if (enterprise_include_once('include/functions_metaconsole.php')) { @@ -725,6 +739,26 @@ switch ($action) { $idAgentModule = $module; break; + case 'agents_inventory': + + + + $description = $item['description']; + $es = json_decode($item['external_source'], true); + // hd($es); + $date = $es['date']; + $selected_agent_group_filter = $es['agent_group_filter']; + $selected_agents_inventory_display_options = $es['agents_inventory_display_options']; + $selected_agent_os_filter = $es['agent_os_filter']; + $selected_agent_custom_field_filter = $es['agent_custom_field_filter']; + $selected_agent_status_filter = $es['agent_status_filter']; + $selected_agent_module_search_filter = $es['agent_module_search_filter']; + $selected_agent_version_filter = $es['agent_version_filter']; + + $idAgent = $es['id_agents']; + $idAgentModule = $inventory_modules; + break; + case 'inventory': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -3020,18 +3054,64 @@ $class = 'databox filters'; + + + + + + + + + + + + + + + + + + @@ -3082,8 +3162,8 @@ $class = 'databox filters'; html_print_select( $fields, - 'users_groups[]', - [], + 'agent_status_filter', + $selected_agent_status_filter, '', false, '', @@ -3101,14 +3181,14 @@ $class = 'databox filters'; $value) { + if (array_search('secondary_groups', $es_agents_inventory_display_options) !== false) { + $sql_agent_sec_group = sprintf( + 'SELECT id_group + FROM tagent_secondary_group + WHERE id_agent = %d', + $value['id_agente'] + ); + + $agent_secondary_groups = []; + $agent_secondary_groups = db_get_all_rows_sql($sql_agent_sec_group); + + $agents[$key]['secondary_groups'] = $agent_secondary_groups; + } + + if (array_search('custom_fields', $es_agents_inventory_display_options) !== false) { + $sql_agent_custom_fields = sprintf( + 'SELECT tacd.description, tacf.name + FROM tagent_custom_data tacd INNER JOIN tagent_custom_fields tacf + ON tacd.id_field = tacf.id_field + WHERE tacd.description != "" AND tacd.id_agent = %d', + $value['id_agente'] + ); + + $agent_custom_fields = []; + $agent_custom_fields = db_get_all_rows_sql($sql_agent_custom_fields); + + $agents[$key]['custom_fields'] = $agent_custom_fields; + } + } + + foreach ($agents as $key => $value) { + foreach ($value as $agent_val_key => $agent_val) { + // Exclude from data to be displayed in report those fields that were not selected to be displayed by user. + if (array_search($agent_val_key, $es_agents_inventory_display_options) === false) { + unset($agents[$key][$agent_val_key]); + } + } + } + + $return['data'] = $agents; + + return reporting_check_structure_content($return); } @@ -2286,7 +2406,7 @@ function reporting_inventory_changes($report, $content, $type) metaconsole_connect($server); } - $es = json_decode($content['external_source'], true); + $es = json_decode($content['external_source'], true); $id_agent = $es['id_agents']; $module_name = $es['inventory_modules']; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 211d8b193d..ceba581f11 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -247,7 +247,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) } $table->colspan['description_row']['description'] = 3; - hd($item['type']); + switch ($item['type']) { case 'availability': default: @@ -1440,46 +1440,129 @@ function reporting_html_event_report_module($table, $item, $pdf=0) */ function reporting_html_agents_inventory($table, $item, $pdf=0) { - hd('agents inventory'); - hd($item); - global $config; - if (empty($item['data']) === false) { - $table_data = new stdClass(); - $table_data->width = '100%'; - $table_data->headstyle = []; - $table_data->headstyle[0] = 'text-align: left;'; - $table_data->style = []; - $table_data->style[0] = 'text-align: left;'; - $table_data->head = [ - __('Name'), - __('Date'), - __('Data'), - __('Status'), - ]; + $table1 = new stdClass(); + $table1->width = '100%'; - $table_data->data = []; - $table_data->data[1][0] = $item['data']['agent_name']; - $table_data->data[1][0] .= ' / '; - $table_data->data[1][0] .= $item['data']['module_name']; + $table1->style[0] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->class = 'databox data'; + $table1->cellpadding = 1; + $table1->cellspacing = 1; + $table1->styleTable = 'overflow: wrap; table-layout: fixed;'; - $table_data->data[1][1] = date( - 'Y-m-d H:i:s', - $item['data']['utimestamp'] - ); + $table1->style[0] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[1] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[2] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[3] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[4] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[5] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[6] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[7] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[8] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[9] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[10] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[11] = 'text-align: left;vertical-align: top; min-width: 100px'; + + $table1->head = []; + + foreach ($item['data'][0] as $field_key => $field_value) { + switch ($field_key) { + case 'alias': + $table1->head[] = __('Alias'); + break; + + case 'direccion': + $table1->head[] = __('IP Address'); + break; + + case 'id_os': + $table1->head[] = __('OS'); + break; + + case 'id_grupo': + $table1->head[] = __('Group'); + break; + + case 'comentarios': + $table1->head[] = __('Description'); + break; + + case 'secondary_groups': + $table1->head[] = __('Sec. groups'); + break; + + case 'url_address': + $table1->head[] = __('URL'); + break; + + case 'custom_fields': + $table1->head[] = __('Custom fields'); + break; + + case 'estado': + $table1->head[] = __('Status'); + break; + + case 'agent_version': + $table1->head[] = __('Version'); + break; + + case 'remote': + $table1->head[] = __('Remote conf.'); + break; + } + } + + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->headstyle[3] = 'text-align: left'; + $table1->headstyle[4] = 'text-align: left'; + $table1->headstyle[5] = 'text-align: left'; + $table1->headstyle[6] = 'text-align: left'; + $table1->headstyle[7] = 'text-align: left'; + $table1->headstyle[8] = 'text-align: left'; + $table1->headstyle[9] = 'text-align: left'; + $table1->headstyle[10] = 'text-align: left'; + $table1->headstyle[11] = 'text-align: left'; + + $table1->data = []; + + foreach ($item['data'] as $data) { + $row = []; + + foreach ($data as $data_field_key => $data_field_value) { + $column_value = $data_field_value; + + if ($data_field_key === 'id_os') { + $column_value = get_os_name((int) $data_field_value); + } else if ($data_field_key === 'estado') { + $column_value = ui_print_module_status((int) $data_field_value, true); + } else if ($data_field_key === 'id_grupo') { + $column_value = ui_print_group_icon((int) $data_field_value, true); + } + + $row[] = $column_value; + } + + $table1->data[] = $row; + + if ($pdf !== 0) { + $table1->data[] = '
'; + } } if ($pdf === 0) { - $table->colspan['last_value']['cell'] = 3; - $table->cellstyle['last_value']['cell'] = 'text-align: center;'; - $table->data['last_value']['cell'] = html_print_table( - $table_data, + $table->colspan['permissions']['cell'] = 3; + $table->cellstyle['permissions']['cell'] = 'text-align: center;'; + $table->data['permissions']['cell'] = html_print_table( + $table1, true ); } else { return html_print_table( - $table_data, + $table1, true ); } From 3362106afe28b32d71d5c9d03c179a46f8da2e7b Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 31 May 2021 13:13:25 +0200 Subject: [PATCH 04/20] added agents inventory report item --- .../reporting_builder.item_editor.php | 10 ++++----- .../godmode/reporting/reporting_builder.php | 2 ++ .../include/functions_reporting.php | 22 ++++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 16db89b622..aa8c68175e 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -740,12 +740,9 @@ switch ($action) { break; case 'agents_inventory': - - - $description = $item['description']; $es = json_decode($item['external_source'], true); - // hd($es); + $date = $es['date']; $selected_agent_group_filter = $es['agent_group_filter']; $selected_agents_inventory_display_options = $es['agents_inventory_display_options']; @@ -754,6 +751,7 @@ switch ($action) { $selected_agent_status_filter = $es['agent_status_filter']; $selected_agent_module_search_filter = $es['agent_module_search_filter']; $selected_agent_version_filter = $es['agent_version_filter']; + $selected_agent_remote = $es['agent_remote_conf']; $idAgent = $es['id_agents']; $idAgentModule = $inventory_modules; @@ -3201,7 +3199,7 @@ $class = 'databox filters'; ?> - + - + diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 0e7d4c2705..6a2c9b9d34 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2108,6 +2108,7 @@ switch ($action) { $es['agent_version_filter'] = get_parameter('agent_version_filter'); $es['agent_module_search_filter'] = get_parameter('agent_module_search_filter'); $es['agent_group_filter'] = get_parameter('agent_group_filter'); + $es['agent_remote_conf'] = get_parameter('agent_remote_conf'); $values['external_source'] = json_encode($es); break; @@ -2745,6 +2746,7 @@ switch ($action) { $es['agent_version_filter'] = get_parameter('agent_version_filter'); $es['agent_module_search_filter'] = get_parameter('agent_module_search_filter'); $es['agent_group_filter'] = get_parameter('agent_group_filter'); + $es['agent_remote_conf'] = get_parameter('agent_remote_conf'); $values['external_source'] = json_encode($es); break; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index d4965815b0..76c9986fb4 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2284,26 +2284,27 @@ function reporting_agents_inventory($report, $content) $es_agent_module_search_filter = $external_source['agent_module_search_filter']; $es_agent_group_filter = $external_source['agent_group_filter']; $es_users_groups = $external_source['users_groups']; - + $es_agent_remote_conf = $external_source['agent_remote_conf']; + hd($es_agent_group_filter); $search_sql = ''; - if ($es_custom_fields != 0) { + if ($es_custom_fields != '') { $search_sql .= ' AND id_os = '.$es_custom_fields; } - if ($es_os_filter != 0) { + if ($es_os_filter != '') { $search_sql .= ' AND id_os = '.$es_os_filter; } - if ($es_agent_status_filter != 0) { + if ($es_agent_status_filter != '') { $search_sql .= ' AND tae.estado = '.$es_agent_status_filter; } - if ($es_agent_version_filter != 0) { - $search_sql .= ' AND tagente.agent_version = '.$es_agent_version_filter; + if ($es_agent_version_filter != '') { + $search_sql .= ' AND tagente.agent_version = "'.$es_agent_version_filter.'"'; } - if ($es_agent_module_search_filter != 0) { + if ($es_agent_module_search_filter != '') { $search_sql .= ' AND tam.nombre = '.$es_agent_module_search_filter; } @@ -2311,8 +2312,13 @@ function reporting_agents_inventory($report, $content) $search_sql .= ' AND tagente.id_grupo = '.$es_agent_group_filter; } - $user_groups_to_sql = implode(',', array_keys(users_get_groups())); + hd($es_agent_remote); + if ($es_agent_remote_conf != '') { + $search_sql .= ' AND tagente.remote = '.$es_agent_remote_conf; + } + $user_groups_to_sql = implode(',', array_keys(users_get_groups())); + hd($search_sql); $sql = sprintf( 'SELECT DISTINCT(tagente.id_agente) AS id_agente, tagente.id_os, From 9cbe6a2924932c4a015e7bc54e0680317e183d3b Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 1 Jun 2021 09:43:55 +0200 Subject: [PATCH 05/20] created new report item --- .../reporting_builder.item_editor.php | 2 +- .../include/functions_reporting.php | 108 ++++++++++-------- .../include/functions_reporting_html.php | 24 ++++ 3 files changed, 88 insertions(+), 46 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index aa8c68175e..099d398691 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3199,7 +3199,7 @@ $class = 'databox filters'; ?> - + $value) { - if (array_search('secondary_groups', $es_agents_inventory_display_options) !== false) { - $sql_agent_sec_group = sprintf( - 'SELECT id_group - FROM tagent_secondary_group - WHERE id_agent = %d', - $value['id_agente'] - ); - - $agent_secondary_groups = []; - $agent_secondary_groups = db_get_all_rows_sql($sql_agent_sec_group); - - $agents[$key]['secondary_groups'] = $agent_secondary_groups; - } - - if (array_search('custom_fields', $es_agents_inventory_display_options) !== false) { - $sql_agent_custom_fields = sprintf( - 'SELECT tacd.description, tacf.name - FROM tagent_custom_data tacd INNER JOIN tagent_custom_fields tacf - ON tacd.id_field = tacf.id_field - WHERE tacd.description != "" AND tacd.id_agent = %d', - $value['id_agente'] - ); - - $agent_custom_fields = []; - $agent_custom_fields = db_get_all_rows_sql($sql_agent_custom_fields); - - $agents[$key]['custom_fields'] = $agent_custom_fields; - } + if (is_metaconsole()) { + $servers_ids = array_column(metaconsole_get_servers(), 'id'); + } else { + $servers_ids = [0]; } - foreach ($agents as $key => $value) { - foreach ($value as $agent_val_key => $agent_val) { - // Exclude from data to be displayed in report those fields that were not selected to be displayed by user. - if (array_search($agent_val_key, $es_agents_inventory_display_options) === false) { - unset($agents[$key][$agent_val_key]); + $return['data'] = []; + + foreach ($servers_ids as $server_id) { + if (is_metaconsole()) { + $server = metaconsole_get_connection_by_id($server_id); + metaconsole_connect($server); + } + + $agents = db_get_all_rows_sql($sql); + + foreach ($agents as $key => $value) { + if (array_search('secondary_groups', $es_agents_inventory_display_options) !== false) { + $sql_agent_sec_group = sprintf( + 'SELECT id_group + FROM tagent_secondary_group + WHERE id_agent = %d', + $value['id_agente'] + ); + + $agent_secondary_groups = []; + $agent_secondary_groups = db_get_all_rows_sql($sql_agent_sec_group); + + $agents[$key]['secondary_groups'] = $agent_secondary_groups; + } + + if (array_search('custom_fields', $es_agents_inventory_display_options) !== false) { + $sql_agent_custom_fields = sprintf( + 'SELECT tacd.description, tacf.name + FROM tagent_custom_data tacd INNER JOIN tagent_custom_fields tacf + ON tacd.id_field = tacf.id_field + WHERE tacd.description != "" AND tacd.id_agent = %d', + $value['id_agente'] + ); + + $agent_custom_fields = []; + $agent_custom_fields = db_get_all_rows_sql($sql_agent_custom_fields); + + $agents[$key]['custom_fields'] = $agent_custom_fields; } } - } - $return['data'] = $agents; + foreach ($agents as $key => $value) { + foreach ($value as $agent_val_key => $agent_val) { + // Exclude from data to be displayed in report those fields that were not selected to be displayed by user. + if (array_search($agent_val_key, $es_agents_inventory_display_options) === false) { + unset($agents[$key][$agent_val_key]); + } + } + } + + $return['data'] = array_merge($return['data'], $agents); + + if (is_metaconsole()) { + metaconsole_restore_db(); + } + } return reporting_check_structure_content($return); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index ceba581f11..925adecf50 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1541,6 +1541,26 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) $column_value = ui_print_module_status((int) $data_field_value, true); } else if ($data_field_key === 'id_grupo') { $column_value = ui_print_group_icon((int) $data_field_value, true); + } else if ($data_field_key === 'custom_fields') { + $custom_fields_value = []; + + if (is_array($data_field_value)) { + foreach ($data_field_value as $value) { + $custom_fields_value[] = $value['name'].': '.$value['description']; + } + } + + $column_value = implode(' / ', $custom_fields_value); + } else if ($data_field_key === 'secondary_groups') { + $custom_fields_value = []; + + if (is_array($data_field_value)) { + foreach ($data_field_value as $value) { + $custom_fields_value[] = ui_print_group_icon((int) $value['id_group'], true); + } + } + + $column_value = implode(' / ', $custom_fields_value); } $row[] = $column_value; @@ -1553,6 +1573,8 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) } } + hd('======', true); + hd($pdf, true); if ($pdf === 0) { $table->colspan['permissions']['cell'] = 3; $table->cellstyle['permissions']['cell'] = 'text-align: center;'; @@ -5903,6 +5925,8 @@ function reporting_html_permissions($table, $item, $pdf=0) } } + // hd("lllllp", true); + // hd($pdf, true); if ($pdf === 0) { $table->colspan['permissions']['cell'] = 3; $table->cellstyle['permissions']['cell'] = 'text-align: center;'; From 59834088bf7925f69d9c9cd28d6c9a6ce95c4864 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 1 Jun 2021 18:04:01 +0200 Subject: [PATCH 06/20] created agents inventory report item --- .../reporting_builder.item_editor.php | 35 +++++++++++++++++++ .../godmode/reporting/reporting_builder.php | 2 ++ .../include/functions_reporting.php | 14 +++++++- .../include/functions_reporting_html.php | 4 --- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 099d398691..271b440fdf 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -744,6 +744,7 @@ switch ($action) { $es = json_decode($item['external_source'], true); $date = $es['date']; + $selected_agent_server_filter = $es['agent_server_filter']; $selected_agent_group_filter = $es['agent_group_filter']; $selected_agents_inventory_display_options = $es['agents_inventory_display_options']; $selected_agent_os_filter = $es['agent_os_filter']; @@ -3078,6 +3079,38 @@ $class = 'databox filters'; + $server) { + $server_fields[$key] = $server['server_name']; + } + + $server_filter_markup = ' + + '.__('Server').''.html_print_select( + $server_fields, + 'agent_server_filter', + $selected_agent_server_filter, + '', + false, + '', + true, + false, + false, + '', + false, + 'min-width: 180px' + ).''; + + if (is_metaconsole()) { + echo $server_filter_markup; + } + ?> + colspan['permissions']['cell'] = 3; $table->cellstyle['permissions']['cell'] = 'text-align: center;'; @@ -5925,8 +5923,6 @@ function reporting_html_permissions($table, $item, $pdf=0) } } - // hd("lllllp", true); - // hd($pdf, true); if ($pdf === 0) { $table->colspan['permissions']['cell'] = 3; $table->cellstyle['permissions']['cell'] = 'text-align: center;'; From 8492a7d1c9a1b1339979fa4c05b7b0084d71e5c5 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 1 Jun 2021 18:05:45 +0200 Subject: [PATCH 07/20] created agents inventory report item --- pandora_console/include/ajax/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 1960b288af..1734c2094a 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1166,7 +1166,7 @@ if (check_login()) { $last_status_change_text = 'Time elapsed since last status change: '; $last_status_change_text .= !empty($module['last_status_change']) ? human_time_comparation($module['last_status_change']) : __('N/A'); - hd($title); + $data[5] = ui_print_status_image($status, htmlspecialchars($title), true, false, false, false, $last_status_change_text); if (!$show_context_help_first_time) { $show_context_help_first_time = true; From 24990b26f3bd1baf8b6f5428d25d18b4cc54d3a6 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 2 Jun 2021 09:06:39 +0200 Subject: [PATCH 08/20] minor fix for pdfs --- pandora_console/include/functions_reporting_html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a8b30e0b82..d0272447c3 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1538,7 +1538,7 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) if ($data_field_key === 'id_os') { $column_value = get_os_name((int) $data_field_value); } else if ($data_field_key === 'estado') { - $column_value = ui_print_module_status((int) $data_field_value, true); + $column_value = ($pdf === 0) ? ui_print_module_status((int) $data_field_value, true) : modules_get_modules_status((int) $data_field_value); } else if ($data_field_key === 'id_grupo') { $column_value = ui_print_group_icon((int) $data_field_value, true); } else if ($data_field_key === 'custom_fields') { From 9513386ff7c52c7665b9253704612f499d91e34d Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 2 Jun 2021 12:47:55 +0200 Subject: [PATCH 09/20] prevent nonadmin users from viewing admin users in pandora search --- pandora_console/operation/search_users.getdata.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/operation/search_users.getdata.php b/pandora_console/operation/search_users.getdata.php index 9ba7ee24af..76cf7792ea 100644 --- a/pandora_console/operation/search_users.getdata.php +++ b/pandora_console/operation/search_users.getdata.php @@ -232,7 +232,12 @@ if ($searchUsers) { // Get group IDs. $user_groups = array_keys($user_groups); - if (!check_acl_one_of_groups($config['id_user'], $user_groups, 'UM') && $config['id_user'] != $user['id_user']) { + if (check_acl_one_of_groups($config['id_user'], $user_groups, 'UM') === false + && $config['id_user'] != $user['id_user'] + || (users_is_admin($config['id_user']) === false + && users_is_admin($user['id_user']) === true) + || $config['id_user'] === $user['id_user'] + ) { unset($users[$key]); } else { $users_id[] = $user['id_user']; From 84905a6579ac56ceec92895f2109db678effd4f4 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 2 Jun 2021 18:39:33 +0200 Subject: [PATCH 10/20] minor fixes in report item --- .../reporting_builder.item_editor.php | 12 +++++----- .../include/functions_reporting.php | 22 +++++++++---------- .../include/functions_reporting_html.php | 11 ++++++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 271b440fdf..3d5b1d91d5 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3141,11 +3141,13 @@ $class = 'databox filters'; @@ -3193,13 +3195,13 @@ $class = 'databox filters'; html_print_select( $fields, - 'agent_status_filter', + 'agent_status_filter[]', $selected_agent_status_filter, '', false, '', false, - false, + true, false, '', false, diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 88b55367bf..ffbd08eec3 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2298,11 +2298,7 @@ function reporting_agents_inventory($report, $content) } if ($es_os_filter != '') { - $search_sql .= ' AND id_os = '.$es_os_filter; - } - - if ($es_agent_status_filter != '') { - $search_sql .= ' AND tae.estado = '.$es_agent_status_filter; + $search_sql .= ' AND id_os IN ('.implode(',', $es_os_filter).')'; } if ($es_agent_version_filter != '') { @@ -2327,7 +2323,6 @@ function reporting_agents_inventory($report, $content) 'SELECT DISTINCT(tagente.id_agente) AS id_agente, tagente.id_os, tagente.direccion, - tae.estado, tagente.agent_version, tagente.alias, tagente.id_grupo, @@ -2338,12 +2333,6 @@ function reporting_agents_inventory($report, $content) ON tagente.id_agente = tasg.id_agent INNER JOIN tagente_modulo tam ON tam.id_agente = tagente.id_agente - INNER JOIN ( - SELECT * - FROM (SELECT id_agente, estado FROM tagente_estado ORDER BY `utimestamp` DESC) tagente_estado - GROUP BY `id_agente` - ) tae - ON tae.id_agente = tagente.id_agente WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s)) %s', $user_groups_to_sql, @@ -2403,6 +2392,15 @@ function reporting_agents_inventory($report, $content) $agents[$key]['custom_fields'] = $agent_custom_fields; } + + if (array_search('estado', $es_agents_inventory_display_options) !== false) { + if (in_array(agents_get_status($value['id_agente']), $es_agent_status_filter)) { + $agents[$key]['estado'] = agents_get_status($value['id_agente']); + } else { + // Agent does not match status filter. + unset($agents[$key]); + } + } } foreach ($agents as $key => $value) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index d0272447c3..dfdf56825a 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1535,12 +1535,19 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) foreach ($data as $data_field_key => $data_field_value) { $column_value = $data_field_value; + $show_link = $pdf === 0 ? true : false; + + // Necessary transformations of data prior to represent it. if ($data_field_key === 'id_os') { $column_value = get_os_name((int) $data_field_value); + } else if ($data_field_key === 'remote' && $pdf === 0) { + $column_value = ((int) $data_field_value === 1) ? __('Yes') : __('No'); + } else if ($data_field_key === 'url_address' && $pdf === 0) { + $column_value = ui_print_truncate_text($data_field_value, 10); } else if ($data_field_key === 'estado') { $column_value = ($pdf === 0) ? ui_print_module_status((int) $data_field_value, true) : modules_get_modules_status((int) $data_field_value); } else if ($data_field_key === 'id_grupo') { - $column_value = ui_print_group_icon((int) $data_field_value, true); + $column_value = ui_print_group_icon((int) $data_field_value, true, 'groups_small', '', $show_link); } else if ($data_field_key === 'custom_fields') { $custom_fields_value = []; @@ -1556,7 +1563,7 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) if (is_array($data_field_value)) { foreach ($data_field_value as $value) { - $custom_fields_value[] = ui_print_group_icon((int) $value['id_group'], true); + $custom_fields_value[] = ui_print_group_icon((int) $value['id_group'], true, 'groups_small', '', $show_link); } } From 36eb084824d8e115e27e07397f4a03b5e52d7659 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 2 Jun 2021 19:02:25 +0200 Subject: [PATCH 11/20] minor fixes --- .../godmode/reporting/reporting_builder.item_editor.php | 6 +++--- pandora_console/include/functions_reporting.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 3d5b1d91d5..b77188a023 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3144,7 +3144,7 @@ $class = 'databox filters'; 'agent_os_filter[]', $selected_agent_os_filter, '', - 'All', + __('All'), '0', false, true @@ -3198,8 +3198,8 @@ $class = 'databox filters'; 'agent_status_filter[]', $selected_agent_status_filter, '', - false, - '', + __('All'), + '-1', false, true, false, diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ffbd08eec3..65daf41679 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2297,7 +2297,7 @@ function reporting_agents_inventory($report, $content) $search_sql .= ' AND id_os = '.$es_custom_fields; } - if ($es_os_filter != '') { + if (in_array('0', $es_os_filter) === false) { $search_sql .= ' AND id_os IN ('.implode(',', $es_os_filter).')'; } @@ -2394,7 +2394,7 @@ function reporting_agents_inventory($report, $content) } if (array_search('estado', $es_agents_inventory_display_options) !== false) { - if (in_array(agents_get_status($value['id_agente']), $es_agent_status_filter)) { + if (in_array('-1', $es_agent_status_filter) === true || in_array(agents_get_status($value['id_agente']), $es_agent_status_filter)) { $agents[$key]['estado'] = agents_get_status($value['id_agente']); } else { // Agent does not match status filter. From b8c6922902ae76dd3e458c2904b4d73c04aab4e9 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 3 Jun 2021 12:04:25 +0200 Subject: [PATCH 12/20] minor fixes in report item --- .../reporting_builder.item_editor.php | 10 +++++++++- .../include/functions_reporting.php | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b77188a023..bffe894931 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3139,6 +3139,10 @@ $class = 'databox filters'; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 65daf41679..a2ace0502a 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2310,7 +2310,7 @@ function reporting_agents_inventory($report, $content) } if ($es_agent_group_filter != 0) { - $search_sql .= ' AND tagente.id_grupo = '.$es_agent_group_filter; + $search_sql .= ' AND (tagente.id_grupo = '.$es_agent_group_filter.' OR tasg.id_group = '.$es_agent_group_filter.')'; } if ($es_agent_remote_conf != 0) { @@ -2331,7 +2331,7 @@ function reporting_agents_inventory($report, $content) tagente.remote FROM tagente LEFT JOIN tagent_secondary_group tasg ON tagente.id_agente = tasg.id_agent - INNER JOIN tagente_modulo tam + LEFT JOIN tagente_modulo tam ON tam.id_agente = tagente.id_agente WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s)) %s', @@ -2346,7 +2346,7 @@ function reporting_agents_inventory($report, $content) $servers_ids = [0]; } - $return['data'] = []; + $return_data = []; foreach ($servers_ids as $server_id) { if (is_metaconsole()) { @@ -2412,13 +2412,23 @@ function reporting_agents_inventory($report, $content) } } - $return['data'] = array_merge($return['data'], $agents); + $return_data[$server_id] = $agents; if (is_metaconsole()) { metaconsole_restore_db(); } } + $all_data = []; + + foreach ($return_data as $server_agents) { + foreach ($server_agents as $agent) { + $all_data[] = $agent; + } + } + + $return['data'] = $all_data; + return reporting_check_structure_content($return); } From fb5ecaeef412b89277c5d102164fc35c13f127d5 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 3 Jun 2021 13:49:10 +0200 Subject: [PATCH 13/20] minor fixes in report item --- pandora_console/include/functions_reporting.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a2ace0502a..73bd978dc9 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2394,11 +2394,19 @@ function reporting_agents_inventory($report, $content) } if (array_search('estado', $es_agents_inventory_display_options) !== false) { - if (in_array('-1', $es_agent_status_filter) === true || in_array(agents_get_status($value['id_agente']), $es_agent_status_filter)) { - $agents[$key]['estado'] = agents_get_status($value['id_agente']); + if (in_array(6, $es_agent_status_filter)) { + if (agents_get_status($value['id_agente']) === 0) { + unset($agents[$key]); + } else { + $agents[$key]['estado'] = agents_get_status($value['id_agente']); + } } else { - // Agent does not match status filter. - unset($agents[$key]); + if (in_array('-1', $es_agent_status_filter) === true || in_array(agents_get_status($value['id_agente']), $es_agent_status_filter)) { + $agents[$key]['estado'] = agents_get_status($value['id_agente']); + } else { + // Agent does not match status filter. + unset($agents[$key]); + } } } } From 08c945d91d39873082c0f056aa22ee382c18c2bb Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 3 Jun 2021 15:37:11 +0200 Subject: [PATCH 14/20] Fixed missed buttons, improve code and added go back button when create-update --- .../godmode/reporting/graph_builder.main.php | 47 ++++++++++------ .../godmode/reporting/graph_builder.php | 22 ++++---- .../operation/reporting/graph_viewer.php | 55 ++++++++++++++----- 3 files changed, 82 insertions(+), 42 deletions(-) diff --git a/pandora_console/godmode/reporting/graph_builder.main.php b/pandora_console/godmode/reporting/graph_builder.main.php index 23cfc010c8..3b77ed932f 100644 --- a/pandora_console/godmode/reporting/graph_builder.main.php +++ b/pandora_console/godmode/reporting/graph_builder.main.php @@ -73,7 +73,7 @@ if (! check_acl($config['id_user'], 0, 'RW') exit; } -if ($edit_graph) { +if ($edit_graph === true) { $graphInTgraph = db_get_row_sql( 'SELECT * FROM tgraph WHERE id_graph = '.$id_graph ); @@ -113,18 +113,18 @@ if ($edit_graph) { // ----------------------- // CREATE/EDIT GRAPH FORM // ----------------------- -$url = 'index.php?sec=reporting&sec2=godmode/reporting/graph_builder'; -if ($edit_graph) { - $output = "
"; +$url = 'index.php?sec=reporting&sec2=godmode/reporting/graph_builder&edit_graph=1'; +if ($edit_graph === true) { + $output = ""; } else { - $output = ""; + $output = ""; } $output .= ""; $output .= ''; $output .= "'; $output .= "'; $output .= "
".__('Name').'