';
@@ -508,12 +541,732 @@ if ($is_metaconsole === false) {
}
true, 'message' => __('No data found.') ]);
+ if ($inventory_module !== 'basic') {
+ if ($order_by_agent === true) {
+ foreach ($rows as $agent_rows) {
+ foreach ($agent_rows['row'] as $row) {
+ $data = [];
+
+ $columns = explode(';', io_safe_output($row['data_format']));
+ array_push($columns, 'Timestamp');
+
+ $data_rows = explode(PHP_EOL, $row['data']);
+ foreach ($data_rows as $data_row) {
+ // Exclude results don't match filter.
+ if ($inventory_search_string && preg_match('/'.io_safe_output($inventory_search_string).'/', ($data_row)) == 0) {
+ continue;
+ }
+
+ $column_data = explode(';', io_safe_output($data_row));
+
+ if ($column_data[0] !== '') {
+ $row_tmp = [];
+ foreach ($column_data as $key => $value) {
+ $row_tmp[$columns[$key]] = $value;
+ }
+
+ $row_tmp['Timestamp'] = $row['timestamp'];
+ array_push($data, (object) $row_tmp);
+ }
+ }
+
+ $id_table = 'id_'.$row['id_module_inventory'];
+
+ $table = ui_print_datatable(
+ [
+ 'id' => $id_table,
+ 'class' => 'info_table w100p',
+ 'style' => 'width: 100%',
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'no_sortable_columns' => [],
+ 'data_element' => $data,
+ 'searching' => true,
+ 'dom_elements' => 'lftipB',
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('No inventory found'),
+ 'emptyTable' => __('No inventory found'),
+ 'return' => true,
+ 'default_pagination' => 10,
+ 'no_sortable_columns' => [-1],
+ ]
+ );
+
+ $modules .= ui_toggle(
+ $table,
+ ''.$row['name'].'',
+ '',
+ '',
+ true,
+ true,
+ '',
+ 'white-box-content w100p',
+ 'box-shadow white_table_graph w100p',
+ 'images/arrow_down_green.png',
+ 'images/arrow_right_green.png',
+ false,
+ false,
+ false,
+ '',
+ '',
+ null,
+ null,
+ $id_table
+ );
+ }
+
+ ui_toggle(
+ $modules,
+ $agent_rows['agent'],
+ '',
+ '',
+ false,
+ false
+ );
+ }
+ } else {
+ foreach ($rows as $module_rows) {
+ $agent = '';
+ foreach ($module_rows as $row) {
+ $columns = explode(';', io_safe_output($row['data_format']));
+ array_push($columns, 'Timestamp');
+ $data = [];
+
+ $data_explode = explode(PHP_EOL, $row['data']);
+ foreach ($data_explode as $values) {
+ // Exclude results don't match filter.
+ if ($inventory_search_string && preg_match('/'.io_safe_output($inventory_search_string).'/', ($values)) == 0) {
+ continue;
+ }
+
+ $data_tmp = [];
+ if ($values !== '') {
+ $values_explode = explode(';', io_safe_output($values));
+
+ foreach ($values_explode as $key => $value) {
+ $data_tmp[$columns[$key]] = $value;
+ }
+
+ $data_tmp['Timestamp'] = $row['timestamp'];
+ array_push($data, $data_tmp);
+ }
+ }
+
+
+ $id_table = 'id_'.$row['id_module_inventory'];
+
+ $table = ui_print_datatable(
+ [
+ 'id' => $id_table,
+ 'class' => 'info_table w100p',
+ 'style' => 'width: 100%',
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'no_sortable_columns' => [],
+ 'data_element' => $data,
+ 'searching' => true,
+ 'dom_elements' => 'lftipB',
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('No inventory found'),
+ 'emptyTable' => __('No inventory found'),
+ 'return' => true,
+ 'default_pagination' => 10,
+ 'no_sortable_columns' => [-1],
+ ]
+ );
+
+ $agent .= ui_toggle(
+ $table,
+ ''.$row['name_agent'].'',
+ '',
+ '',
+ true,
+ true,
+ '',
+ 'white-box-content w100p',
+ 'box-shadow white_table_graph w100p',
+ 'images/arrow_down_green.png',
+ 'images/arrow_right_green.png',
+ false,
+ false,
+ false,
+ '',
+ '',
+ null,
+ null,
+ $id_table
+ );
+ }
+
+ ui_toggle(
+ $agent,
+ $module_rows[0]['name'],
+ '',
+ '',
+ false,
+ false
+ );
+ }
+ }
} else {
- echo $inventory_data;
+ $id_agente = $inventory_id_agent;
+ $agentes = [];
+ $data = [];
+ $class = 'info_table w100p';
+ $style = 'width: 100%';
+ $ordering = false;
+ $searching = false;
+ $dom = 't';
+ $columns = [
+ __('Alias'),
+ __('IP'),
+ __("IP's Secondary"),
+ __('Group'),
+ __('Secondary groups'),
+ __('Description'),
+ __('OS'),
+ __('Interval'),
+ __('Last contact'),
+ __('Last status change'),
+ __('Custom fields'),
+ __('Values Custom Fields'),
+ ];
+ if ((int) $id_agente === 0) {
+ $class = 'databox info_table w100p';
+ $style = 'width: 99%';
+ $ordering = true;
+ $searching = true;
+ $dom = 'lftipB';
+ $agentes = db_get_all_rows_sql('SELECT id_agente FROM tagente');
+ } else {
+ array_push($agentes, $id_agente);
+ }
+
+ foreach ($agentes as $id) {
+ if ((int) $id_agente === 0) {
+ $id = $id['id_agente'];
+ }
+
+ $agent = db_get_row('tagente', 'id_agente', $id);
+
+ $ip = ''.__('N/A').'';
+ if (empty($agent['direccion']) === false) {
+ $ip = $agent['direccion'];
+ }
+
+
+ $secondary_ips = '';
+ foreach (agents_get_addresses($id) as $ip) {
+ if ($ip !== $agent['direccion']) {
+ $secondary_ips .= ''.$ip.'';
+ }
+ }
+
+ $group = groups_get_name($agent['id_grupo']);
+ $secondary_groups = enterprise_hook('agents_get_secondary_groups', [$id]);
+
+ if (empty($secondary_groups['for_select']) === true) {
+ $sec_group_data = ''.__('N/A').'';
+ } else {
+ $sec_group = [];
+ foreach ($secondary_groups['for_select'] as $name) {
+ $sec_group[] = $name;
+ }
+
+ $sec_group_data = implode(', ', $sec_group);
+ }
+
+ $os = ui_print_os_icon($agent['id_os'], false, true).' ';
+ $os .= io_safe_output(get_os_name($agent['id_os'])).' '.io_safe_output($agent['os_version']);
+ $interval = human_time_description_raw($agent['intervalo'], false, 'large');
+ $last_contact = ui_print_timestamp($agent['ultimo_contacto'], true);
+ // $last_contact .= ' / '.date_w_fixed_tz($agent['ultimo_contacto_remoto']);
+ $last_status_change_agent = agents_get_last_status_change($agent['id_agente']);
+ $time_elapsed = !empty($last_status_change_agent) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').'';
+
+ $sql_fields = 'SELECT tcf.name, tcd.description, tcf.is_password_type
+ FROM tagent_custom_fields tcf
+ INNER JOIN tagent_custom_data tcd ON tcd.id_field=tcf.id_field
+ WHERE tcd.id_agent='.$id.' AND tcd.description!=""';
+ $field_result = db_get_all_rows_sql($sql_fields);
+
+ $custom_fields_names = '';
+ $custom_fields_values = '';
+ foreach ($field_result as $field) {
+ $field_name = str_replace(' ', ' ', io_safe_output($field['name']));
+ $custom_fields_names .= ''.$field_name.'';
+
+ $description = $field['description'];
+ $password_length = strlen(io_safe_output($field['description']));
+ $asterisks = '';
+
+ if ((int) $field['is_password_type'] === 1) {
+ for ($i = 0; $i < $password_length; $i++) {
+ $asterisks .= '●';
+ }
+
+ $description = $asterisks;
+ }
+
+ $custom_fields_values .= ''.$description.'';
+ }
+
+ $data_tmp = [
+ __('Alias') => $agent['alias'],
+ __('IP') => $ip,
+ __("IP's Secondary") => $secondary_ips,
+ __('Group') => $group,
+ __('Secondary groups') => $sec_group_data,
+ __('Description') => $agent['comentarios'],
+ __('OS') => $os,
+ __('Interval') => $interval,
+ __('Last contact') => $last_contact,
+ __('Last status change') => $time_elapsed,
+ __('Custom fields') => $custom_fields_names,
+ __('Values Custom Fields') => $custom_fields_values,
+ ];
+
+ array_push($data, $data_tmp);
+ }
+
+ $table = ui_print_datatable(
+ [
+ 'id' => 'basic_info',
+ 'class' => $class,
+ 'style' => $style,
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'ordering' => $ordering,
+ 'data_element' => $data,
+ 'searching' => $searching,
+ 'dom_elements' => $dom,
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('Agent info not found'),
+ 'emptyTable' => __('Agent info not found'),
+ 'default_pagination' => 10,
+ 'return' => true,
+ ]
+ );
+ if ((int) $id_agente === 0) {
+ echo $table;
+ } else {
+ echo ' '.$table.' ';
+ }
+ }
+
+ // Metaconsole.
+} else {
+ if ($inventory_module !== 'basic') {
+ if ($order_by_agent === true) {
+ $count_nodos_tmp = [];
+ foreach ($nodos as $count_value) {
+ array_push($count_nodos_tmp, $count_value['server_name']);
+ }
+
+ $count = array_count_values($count_nodos_tmp);
+
+ foreach ($nodos as $nodo) {
+ $agents = '';
+ foreach ($nodo['data'] as $agent_rows) {
+ $modules = '';
+ foreach ($agent_rows['row'] as $row) {
+ $data = [];
+
+ $columns = explode(';', io_safe_output($row['data_format']));
+ array_push($columns, 'Timestamp');
+
+ $data_rows = explode(PHP_EOL, $row['data']);
+ foreach ($data_rows as $data_row) {
+ // Exclude results don't match filter.
+ if ($inventory_search_string && preg_match('/'.io_safe_output($inventory_search_string).'/', ($data_row)) == 0) {
+ continue;
+ }
+
+ $column_data = explode(';', io_safe_output($data_row));
+
+ if ($column_data[0] !== '') {
+ $row_tmp = [];
+ foreach ($column_data as $key => $value) {
+ $row_tmp[$columns[$key]] = $value;
+ }
+
+ $row_tmp['Timestamp'] = $row['timestamp'];
+ array_push($data, (object) $row_tmp);
+ }
+ }
+
+ $id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
+
+ $table = ui_print_datatable(
+ [
+ 'id' => $id_table,
+ 'class' => 'info_table w100p',
+ 'style' => 'width: 100%',
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'no_sortable_columns' => [],
+ 'data_element' => $data,
+ 'searching' => true,
+ 'dom_elements' => 'lftipB',
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('No inventory found'),
+ 'emptyTable' => __('No inventory found'),
+ 'return' => true,
+ 'default_pagination' => 10,
+ 'no_sortable_columns' => [-1],
+ ]
+ );
+
+ $modules .= ui_toggle(
+ $table,
+ ''.$row['name'].'',
+ '',
+ '',
+ true,
+ true,
+ '',
+ 'white-box-content w100p',
+ 'box-shadow white_table_graph w100p',
+ 'images/arrow_down_green.png',
+ 'images/arrow_right_green.png',
+ false,
+ false,
+ false,
+ '',
+ '',
+ null,
+ null,
+ $id_table
+ );
+ }
+
+ $agents .= ui_toggle(
+ $modules,
+ $agent_rows['agent'],
+ '',
+ '',
+ true,
+ true
+ );
+ }
+
+ $node_name = $nodo['server_name'];
+ if ($count[$nodo['server_name']] > 1) {
+ $node_name .= ' ('.$nodo['dbhost'].')';
+ }
+
+ ui_toggle(
+ $agents,
+ ''.$node_name.'',
+ '',
+ '',
+ false,
+ false
+ );
+ }
+ } else {
+ $count_nodos_tmp = [];
+ foreach ($nodos as $count_value) {
+ array_push($count_nodos_tmp, $count_value['server_name']);
+ }
+
+ $count = array_count_values($count_nodos_tmp);
+
+ foreach ($nodos as $nodo_key => $nodo) {
+ $agents = '';
+ foreach ($nodo['data'] as $module_rows) {
+ $agent = '';
+ foreach ($module_rows as $row) {
+ $columns = explode(';', io_safe_output($row['data_format']));
+ array_push($columns, 'Timestamp');
+ $data = [];
+
+ $data_explode = explode(PHP_EOL, $row['data']);
+ foreach ($data_explode as $values) {
+ // Exclude results don't match filter.
+ if ($inventory_search_string && preg_match('/'.io_safe_output($inventory_search_string).'/', ($values)) == 0) {
+ continue;
+ }
+
+ $data_tmp = [];
+ if ($values !== '') {
+ $values_explode = explode(';', io_safe_output($values));
+
+ foreach ($values_explode as $key => $value) {
+ $data_tmp[$columns[$key]] = $value;
+ }
+
+ $data_tmp['Timestamp'] = $row['timestamp'];
+ array_push($data, $data_tmp);
+ }
+ }
+
+
+ $id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
+
+ $table = ui_print_datatable(
+ [
+ 'id' => $id_table,
+ 'class' => 'info_table w100p',
+ 'style' => 'width: 100%',
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'no_sortable_columns' => [],
+ 'data_element' => $data,
+ 'searching' => true,
+ 'dom_elements' => 'lftipB',
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('No inventory found'),
+ 'emptyTable' => __('No inventory found'),
+ 'return' => true,
+ 'default_pagination' => 10,
+ 'no_sortable_columns' => [-1],
+ ]
+ );
+
+ $agent .= ui_toggle(
+ $table,
+ ''.$row['name_agent'].'',
+ '',
+ '',
+ true,
+ true,
+ '',
+ 'white-box-content w100p',
+ 'box-shadow white_table_graph w100p',
+ 'images/arrow_down_green.png',
+ 'images/arrow_right_green.png',
+ false,
+ false,
+ false,
+ '',
+ '',
+ null,
+ null,
+ $id_table
+ );
+ }
+
+ $agents .= ui_toggle(
+ $agent,
+ $module_rows[0]['name'],
+ '',
+ '',
+ true,
+ true
+ );
+ }
+
+ $node_name = $nodo['server_name'];
+ if ($count[$nodo['server_name']] > 1) {
+ $node_name .= ' ('.$nodo['dbhost'].')';
+ }
+
+ ui_toggle(
+ $agents,
+ ''.$node_name.'',
+ '',
+ '',
+ false,
+ false
+ );
+ }
+ }
+ } else {
+ $id_agente = $inventory_id_agent;
+ $agentes = [];
+ $data = [];
+ $class = 'info_table w100p';
+ $style = 'width: 100%';
+ $ordering = false;
+ $searching = false;
+ $dom = 't';
+ $columns = [
+ __('Alias'),
+ __('IP'),
+ __("IP's Secondary"),
+ __('Group'),
+ __('Secondary groups'),
+ __('Description'),
+ __('OS'),
+ __('Interval'),
+ __('Last contact'),
+ __('Last status change'),
+ __('Custom fields'),
+ __('Values Custom Fields'),
+ ];
+
+ if ($id_server === 0) {
+ $servers_ids = array_column(metaconsole_get_servers(), 'id');
+ } else {
+ $servers_ids = [$id_server];
+ }
+
+ foreach ($servers_ids as $server_id) {
+ if (is_metaconsole()) {
+ $server = metaconsole_get_connection_by_id($server_id);
+
+ if ((int) $es_agent_server_filter !== 0
+ && (int) $es_agent_server_filter !== (int) $server_id
+ ) {
+ continue;
+ }
+
+ metaconsole_connect($server);
+ }
+
+ if ((int) $id_agente === 0) {
+ $class = 'databox info_table w100p';
+ $style = 'width: 99%';
+ $ordering = true;
+ $searching = true;
+ $dom = 'lftipB';
+ $sql_agentes = 'SELECT t.id_agente
+ FROM tagente t
+ LEFT JOIN tgrupo tg ON tg.id_grupo = t.id_grupo
+ WHERE (t.alias LIKE "%'.$inventory_search_string.'%")
+ OR (t.comentarios LIKE "%'.$inventory_search_string.'%")
+ OR (t.direccion LIKE "%'.$inventory_search_string.'%")
+ OR (t.os_version LIKE "%'.$inventory_search_string.'%")
+ OR (tg.nombre LIKE "%'.$inventory_search_string.'%")';
+ $agentes = db_get_all_rows_sql($sql_agentes);
+ } else {
+ array_push($agentes, $id_agente);
+ }
+
+ foreach ($agentes as $id) {
+ if ((int) $id_agente === 0) {
+ $id = $id['id_agente'];
+ }
+
+ $agent = db_get_row('tagente', 'id_agente', $id);
+
+ $ip = ''.__('N/A').'';
+ if (empty($agent['direccion']) === false) {
+ $ip = $agent['direccion'];
+ }
+
+
+ $secondary_ips = '';
+ foreach (agents_get_addresses($id) as $ip) {
+ if ($ip !== $agent['direccion']) {
+ $secondary_ips .= ''.$ip.'';
+ }
+ }
+
+ $group = groups_get_name($agent['id_grupo']);
+ $secondary_groups = enterprise_hook('agents_get_secondary_groups', [$id]);
+
+ if (empty($secondary_groups['for_select']) === true) {
+ $sec_group_data = ''.__('N/A').'';
+ } else {
+ $sec_group = [];
+ foreach ($secondary_groups['for_select'] as $name) {
+ $sec_group[] = $name;
+ }
+
+ $sec_group_data = implode(', ', $sec_group);
+ }
+
+ $os = ui_print_os_icon($agent['id_os'], false, true).' ';
+ $os .= io_safe_output(get_os_name($agent['id_os'])).' '.io_safe_output($agent['os_version']);
+ $interval = human_time_description_raw($agent['intervalo'], false, 'large');
+ $last_contact = ui_print_timestamp($agent['ultimo_contacto'], true);
+ // $last_contact .= ' / '.date_w_fixed_tz($agent['ultimo_contacto_remoto']);
+ $last_status_change_agent = agents_get_last_status_change($agent['id_agente']);
+ $time_elapsed = !empty($last_status_change_agent) ? human_time_comparation($last_status_change_agent) : ''.__('N/A').'';
+
+ $sql_fields = 'SELECT tcf.name, tcd.description, tcf.is_password_type
+ FROM tagent_custom_fields tcf
+ INNER JOIN tagent_custom_data tcd ON tcd.id_field=tcf.id_field
+ WHERE tcd.id_agent='.$id.' AND tcd.description!=""';
+ $field_result = db_get_all_rows_sql($sql_fields);
+
+ $custom_fields_names = '';
+ $custom_fields_values = '';
+ foreach ($field_result as $field) {
+ $field_name = str_replace(' ', ' ', io_safe_output($field['name']));
+ $custom_fields_names .= ''.$field_name.'';
+
+ $description = $field['description'];
+ $password_length = strlen(io_safe_output($field['description']));
+ $asterisks = '';
+
+ if ((int) $field['is_password_type'] === 1) {
+ for ($i = 0; $i < $password_length; $i++) {
+ $asterisks .= '●';
+ }
+
+ $description = $asterisks;
+ }
+
+ $custom_fields_values .= ''.$description.'';
+ }
+
+ $data_tmp = [
+ __('Alias') => $agent['alias'],
+ __('IP') => $ip,
+ __("IP's Secondary") => $secondary_ips,
+ __('Group') => $group,
+ __('Secondary groups') => $sec_group_data,
+ __('Description') => $agent['comentarios'],
+ __('OS') => $os,
+ __('Interval') => $interval,
+ __('Last contact') => $last_contact,
+ __('Last status change') => $time_elapsed,
+ __('Custom fields') => $custom_fields_names,
+ __('Values Custom Fields') => $custom_fields_values,
+ ];
+
+ array_push($data, $data_tmp);
+ }
+
+ if (is_metaconsole()) {
+ metaconsole_restore_db();
+ }
+ }
+
+ $table = ui_print_datatable(
+ [
+ 'id' => 'basic_info',
+ 'class' => $class,
+ 'style' => $style,
+ 'columns' => $columns,
+ 'column_names' => $columns,
+ 'ordering' => $ordering,
+ 'data_element' => $data,
+ 'searching' => $searching,
+ 'dom_elements' => $dom,
+ 'order' => [
+ 'field' => $columns[0],
+ 'direction' => 'asc',
+ ],
+ 'zeroRecords' => __('Agent info not found'),
+ 'emptyTable' => __('Agent info not found'),
+ 'default_pagination' => 10,
+ 'return' => true,
+ ]
+ );
+ if ((int) $id_agente === 0) {
+ echo $table;
+ } else {
+ echo ''.$table.' ';
+ }
}
close_meta_frame();
@@ -539,6 +1292,27 @@ ui_require_jquery_file('bgiframe');
$("#id_group").blur (function () {
$(this).css ("width", "180px");
});
+
+ // Reduce margins between table and pagination.
+ $('.dataTables_paginate.paging_simple_numbers').css('margin-top', 10);
+ $('.dataTables_paginate.paging_simple_numbers').css('margin-bottom', 10);
+
+ // Change chevron for node icon.
+ let toggle = document.querySelectorAll('.toggle-inventory-nodo');
+ let src = '';
+
+ toggle.forEach(img => {
+ img.parentElement.parentElement.style = 'cursor: pointer; border: 0';
+ img.parentElement.previousElementSibling.src = src;
+ });
+
+ toggle.forEach(divParent => {
+ let div = divParent.parentElement.parentElement;
+ $(div).click(function (e) {
+ div.style = 'cursor: pointer; border: 0';
+ div.firstChild.src = src;
+ });
+ });
});
/* ]]> */
|