diff --git a/pandora_console/images/widgets/inventory.png b/pandora_console/images/widgets/inventory.png new file mode 100644 index 0000000000..9d3b198b7c Binary files /dev/null and b/pandora_console/images/widgets/inventory.png differ diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 14712eee27..8c61d38b70 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -412,6 +412,10 @@ class Widget $className .= '\WuxWidget'; break; + case 'inventory': + $className .= '\InventoryWidget'; + break; + case 'os_quick_report': $className .= '\OsQuickReportWidget'; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/inventory.php b/pandora_console/include/lib/Dashboard/Widgets/inventory.php new file mode 100644 index 0000000000..ba9d75a1c0 --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/inventory.php @@ -0,0 +1,1337 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Inventory'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'inventory'; + } + + // Must be configured before using. + $this->configurationRequired = false; + if (empty($this->values['inventoryModuleId']) === true) { + $this->configurationRequired = true; + } + + $this->overflow_scrollbars = false; + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + if (isset($decoder['agentId']) === true) { + $values['agentId'] = $decoder['agentId']; + } + + if (isset($decoder['agentAlias']) === true) { + $values['agentAlias'] = $decoder['agentAlias']; + } + + if (isset($decoder['metaconsoleId']) === true) { + $values['metaconsoleId'] = $decoder['metaconsoleId']; + } + + if (isset($decoder['inventoryModuleId']) === true) { + $values['inventoryModuleId'] = $decoder['inventoryModuleId']; + } + + if (isset($decoder['freeSearch']) === true) { + $values['freeSearch'] = $decoder['freeSearch']; + } + + if (isset($decoder['orderByAgent']) === true) { + $values['orderByAgent'] = $decoder['orderByAgent']; + } + + if (isset($decoder['idGroup']) === true) { + $values['idGroup'] = $decoder['idGroup']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Agent. + /*$inputs[] = [ + 'label' => __('Agent'), + 'arguments' => [ + 'type' => 'autocomplete_agent', + 'name' => 'agentAlias', + 'id_agent_hidden' => $values['agentId'], + 'name_agent_hidden' => 'agentId', + 'server_id_hidden' => $values['metaconsoleId'], + 'name_server_hidden' => 'metaconsoleId', + 'return' => true, + 'module_input' => true, + 'module_name' => 'moduleId', + 'module_none' => false, + 'size' => 0, + ], + ]; + + // Module. + $inputs[] = [ + 'label' => __('Module'), + 'arguments' => [ + 'type' => 'autocomplete_module', + 'name' => 'moduleId', + 'selected' => $values['moduleId'], + 'return' => true, + 'sort' => false, + 'agent_id' => $values['agentId'], + 'metaconsole_id' => $values['metaconsoleId'], + 'style' => 'width: inherit;', + 'nothing' => __('None'), + 'nothing_value' => 0, + ], + ]; + + // Agent/module/description free search. + $inputs[] = [ + 'label' => __('Free search'), + 'arguments' => [ + 'name' => 'label', + 'type' => 'text', + 'value' => '', + 'return' => true, + 'size' => 0, + ], + ]; + + // Enable/disable order by agent. + $inputs[] = [ + 'label' => __('Recursion'), + 'arguments' => [ + 'wrapper' => 'div', + 'name' => 'group_recursion', + 'type' => 'switch', + 'value' => $values['group_recursion'], + 'return' => true, + ], + ]; + + if ($is_metaconsole === true) { + // Node select. + $nodes = []; + foreach ($nodes_connection as $row) { + $nodes[$row['id']] = $row['server_name']; + } + + $inputs[] = html_print_label_input_block( + __('Server'), + html_print_select( + $nodes, + 'id_server', + $id_server, + $filteringFunction, + __('All'), + 0, + true, + false, + true, + '', + false, + 'width:100%;' + ) + ); + } + + // Group select. + $inputs[] = html_print_label_input_block( + __('Group'), + html_print_select_groups( + $config['id_user'], + $access, + true, + 'id_group', + $inventory_id_group, + $filteringFunction, + '', + '1', + true, + false, + true, + '', + false + ) + );*/ + + // Format Data. + $inputs[] = [ + 'label' => __('Order by agent'), + 'arguments' => [ + 'name' => 'order_by_agent', + 'type' => 'switch', + 'value' => $values['orderByAgent'], + ], + ]; + + $inputs[] = [ + 'label' => __('Free search'), + 'arguments' => [ + 'name' => 'free_search', + 'type' => 'text', + 'class' => 'w100p', + 'input_class' => 'flex-row', + 'value' => $values['freeSearch'], + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('Group'), + 'arguments' => [ + 'type' => 'select_groups', + 'privilege' => 'AR', + 'name' => 'id_group', + 'selected' => $values['idGroup'], + 'nothing_value' => __('All'), + 'return' => true, + 'multiple' => false, + ], + ]; + + $inputs[] = [ + 'label' => __('Agent'), + 'arguments' => [ + 'type' => 'autocomplete_agent', + 'name' => 'agentAlias', + 'id_agent_hidden' => $values['agentId'], + 'name_agent_hidden' => 'agentId', + 'server_id_hidden' => $values['metaconsoleId'], + 'name_server_hidden' => 'metaconsoleId', + 'return' => true, + 'module_input' => true, + 'module_name' => 'moduleId', + 'module_none' => false, + 'size' => 0, + ], + ]; + + $fields = []; + + array_unshift($fields, __('All')); + $inputs[] = [ + 'label' => __('Module'), + 'arguments' => [ + 'name' => 'module_inventory', + 'id' => 'module_inventory', + 'input_class' => 'flex-row', + 'type' => 'select', + 'selected' => $values['inventoryModuleId'], + 'nothing' => __('Basic info'), + 'nothing_value' => 'basic', + 'fields' => $fields, + 'class' => '', + 'return' => true, + 'sort' => true, + ], + ]; + + // Agent select. + if ($is_metaconsole === false) { + $agents = []; + $sql = 'SELECT id_agente, nombre FROM tagente'; + if ($inventory_id_group > 0) { + $sql .= ' WHERE id_grupo = '.$inventory_id_group; + } else { + $user_groups = implode(',', array_keys(users_get_groups($config['id_user']))); + + // Avoid errors if there are no groups. + if (empty($user_groups) === true) { + $user_groups = '"0"'; + } + + $sql .= ' WHERE id_grupo IN ('.$user_groups.')'; + } + + $result = db_get_all_rows_sql($sql); + if ($result) { + foreach ($result as $row) { + $agents[$row['id_agente']] = $row['nombre']; + } + } + } + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['agentId'] = (int) \get_parameter('agentId', 0); + $values['metaconsoleId'] = (int) \get_parameter('metaconsoleId', 0); + $values['inventoryModuleId'] = \get_parameter('module_inventory', 'basic'); + $values['agentAlias'] = \get_parameter('agentAlias', ''); + $values['freeSearch'] = (string) \get_parameter('free_search', ''); + $values['orderByAgent'] = \get_parameter('order_by_agent', 0); + $values['idGroup'] = \get_parameter('id_group', 0); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $inventory_id_agent = $this->values['agentId']; + $inventory_agent = $this->values['agentAlias']; + + if (strlen($inventory_agent) === 0) { + $inventory_id_agent = -1; + $inventory_agent = __('All'); + } else if ($inventory_agent == __('All')) { + $inventory_id_agent = 0; + } + + $inventory_module = $this->values['inventoryModuleId']; + + $inventory_id_group = (int) $this->values['idGroup']; + $inventory_search_string = (string) $this->values['freeSearch']; + $order_by_agent = (bool) $this->values['orderByAgent']; + + $pagination_url_parameters = [ + 'inventory_id_agent' => $inventory_id_agent, + 'inventory_agent' => $inventory_agent, + 'inventory_id_group' => $inventory_id_group, + ]; + + $noFilterSelected = false; + + // Get variables. + if (is_metaconsole() === true) { + + $nodes_connection = metaconsole_get_connections(); + $id_server = (int) $this->values['metaconsoleId']; + + $pagination_url_parameters['id_server'] = $id_server; + + if ($inventory_id_agent > 0) { + $inventory_id_server = (int) get_parameter('id_server_agent', -1); + $pagination_url_parameters['inventory_id_server'] = $inventory_id_server; + + if ($inventory_id_server !== -1) { + $id_server = $inventory_id_server; + $pagination_url_parameters['id_server'] = $id_server; + } + } + + // No filter selected. + $noFilterSelected = $inventory_id_agent === -1 && $inventory_id_group === 0 && $id_server === 0; + + $nodo_image_url = $config['homeurl'].'/images/node.png'; + if ($id_server > 0) { + $connection = metaconsole_get_connection_by_id($id_server); + $agents_node = metaconsole_get_agents_servers($connection['server_name'], $inventory_id_group); + $node = metaconsole_get_servers($id_server); + $nodos = []; + + if (metaconsole_connect($connection) !== NOERR) { + ui_print_error_message( + __('There was a problem connecting with the node') + ); + } + + $sql = 'SELECT DISTINCT name as indexname, name + FROM tmodule_inventory, tagent_module_inventory + WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory'; + if ($inventory_id_agent > 0) { + $sql .= ' AND id_agente = '.$inventory_id_agent; + $agents_node = [$inventory_id_agent => $inventory_id_agent]; + } + + $result_module = db_get_all_rows_sql($sql); + // Get the data. + $rows_meta = inventory_get_datatable( + array_keys($agents_node), + $inventory_module, + 0, + $inventory_search_string, + false, + false, + $order_by_agent, + $server, + $pagination_url_parameters + ); + + $data_tmp['server_name'] = $connection['server_name']; + $data_tmp['dbhost'] = $connection['dbhost']; + $data_tmp['server_uid'] = $connection['server_uid']; + $data_tmp['data'] = $rows_meta; + + $nodos[$connection['id']] = $data_tmp; + if ($result_data !== ERR_NODATA) { + $inventory_data .= $result_data; + } + + // Restore db connection. + metaconsole_restore_db(); + } else { + $result_module = []; + $nodos = []; + foreach ($nodes_connection as $key => $server) { + $agents_node = metaconsole_get_agents_servers($server['server_name'], $inventory_id_group); + $connection = metaconsole_get_connection($server['server_name']); + if (metaconsole_connect($connection) !== NOERR) { + continue; + } + + $sql = 'SELECT DISTINCT name as indexname, name + FROM tmodule_inventory, tagent_module_inventory + WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory'; + if ($inventory_id_agent > 0) { + $sql .= ' AND id_agente = '.$inventory_id_agent; + $agents_node = [$inventory_id_agent => $inventory_id_agent]; + } + + $result = db_get_all_rows_sql($sql); + if ($result !== false) { + $result_module = array_merge($result_module, $result); + // Get the data. + $rows_meta = inventory_get_datatable( + array_keys($agents_node), + $inventory_module, + 0, + $inventory_search_string, + false, + false, + $order_by_agent, + $server, + $pagination_url_parameters + ); + + $data_tmp['server_name'] = $server['server_name']; + $data_tmp['dbhost'] = $server['dbhost']; + $data_tmp['server_uid'] = $server['server_uid']; + $data_tmp['data'] = $rows_meta; + $nodos[$server['id']] = $data_tmp; + if ($result_data !== ERR_NODATA) { + $inventory_data .= $result_data; + } + } + + // Restore db connection. + metaconsole_restore_db(); + } + } + + $fields = []; + foreach ($result_module as $row) { + $id = array_shift($row); + $value = array_shift($row); + $fields[$id] = $value; + } + } + + // Agent select. + if (is_metaconsole() === false) { + $agents = []; + $sql = 'SELECT id_agente, nombre FROM tagente'; + if ($inventory_id_group > 0) { + $sql .= ' WHERE id_grupo = '.$inventory_id_group; + } else { + $user_groups = implode(',', array_keys(users_get_groups($config['id_user']))); + + // Avoid errors if there are no groups. + if (empty($user_groups) === true) { + $user_groups = '"0"'; + } + + $sql .= ' WHERE id_grupo IN ('.$user_groups.')'; + } + + $result = db_get_all_rows_sql($sql); + if ($result) { + foreach ($result as $row) { + $agents[$row['id_agente']] = $row['nombre']; + } + } + } + + $filteringFunction = ''; + if ($inventory_module !== 'basic') { + if (is_metaconsole() === true) { + 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 $key => $row) { + $columns = explode(';', io_safe_output($row['data_format'])); + array_push($columns, 'Timestamp'); + $data = []; + $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' => 'fti', + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'zeroRecords' => __('No inventory found'), + 'emptyTable' => __('No inventory found'), + 'return' => true, + 'default_pagination' => 10, + 'no_sortable_columns' => [-1], + 'csv' => 0, + + ] + ); + + $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, + false, + $id_table + ); + } + + $agents .= ui_toggle( + $modules, + $agent_rows['agent'], + '', + '', + true, + true, + '', + 'white-box-content w100p', + 'box-shadow white_table_graph w100p', + ); + } + + $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_key => $module_rows) { + $agent = ''; + $data = []; + foreach ($module_rows as $row) { + $columns = explode(';', io_safe_output($row['data_format'])); + array_push($columns, 'Timestamp'); + + $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' => 'fti', + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'zeroRecords' => __('No inventory found'), + 'emptyTable' => __('No inventory found'), + 'return' => true, + 'default_pagination' => 10, + 'no_sortable_columns' => [-1], + 'csv' => 0, + ] + ); + + $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, + false, + $id_table + ); + + + $agents .= ui_toggle( + $agent, + $module_key, + '', + '', + true, + true, + '', + 'white-box-content w100p', + 'box-shadow white_table_graph w100p', + ); + } + + $node_name = $nodo['server_name']; + if ($count[$nodo['server_name']] > 1) { + $node_name .= ' ('.$nodo['dbhost'].')'; + } + + ui_toggle( + $agents, + ''.$node_name.'', + '', + '', + false, + false + ); + } + } + } else { + // Single agent selected. + if ($inventory_id_agent > 0 && isset($agents[$inventory_id_agent]) === true) { + $agents = [$inventory_id_agent => $agents[$inventory_id_agent]]; + } + + $agents_ids = array_keys($agents); + if (count($agents_ids) > 0) { + $rows = inventory_get_datatable( + $agents_ids, + $inventory_module, + 0, + $inventory_search_string, + false, + false, + $order_by_agent + ); + } + + if (count($agents_ids) === 0 || (int) $rows === ERR_NODATA) { + ui_print_info_message( + [ + 'no_close' => true, + 'message' => __('No data found.'), + ] + ); + return; + } + + echo "
'; + ?> + + $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_'.$key_row.'_'.$row['id_module_inventory'].'_'.$row['id_agente']; + + $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' => 'fti', + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'zeroRecords' => __('No inventory found'), + 'emptyTable' => __('No inventory found'), + 'return' => true, + 'default_pagination' => 10, + 'no_sortable_columns' => [-1], + 'csv' => 0, + ] + ); + + $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, + false, + $id_table + ); + } + + ui_toggle( + $modules, + $agent_rows['agent'], + '', + '', + false, + false + ); + } + } else { + $count_rows = count($rows); + foreach ($rows as $module_rows) { + $agent = ''; + $data = []; + + foreach ($module_rows as $row) { + $columns = explode(';', io_safe_output($row['data_format'])); + array_push($columns, 'Timestamp'); + array_push($columns, 'Agent'); + + // Exclude results don't match filter. + if ($inventory_search_string && preg_match('/'.io_safe_output($inventory_search_string).'/', ($row['data'])) == 0) { + continue; + } + + $data_tmp = []; + if ($row['data'] !== '') { + $values_explode = explode(';', io_safe_output($row['data'])); + + foreach ($values_explode as $key => $value) { + $data_tmp[$columns[$key]] = $value; + } + + $data_tmp['Timestamp'] = $row['timestamp']; + $data_tmp['Agent'] = $row['name_agent']; + array_push($data, $data_tmp); + } + + + $id_table = 'id_'.$row['id_module_inventory']; + } + + if ($count_rows > 1) { + $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' => 'fti', + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'zeroRecords' => __('No inventory found'), + 'emptyTable' => __('No inventory found'), + 'return' => true, + 'no_sortable_columns' => [], + 'mini_search' => true, + 'mini_pagination' => true, + 'csv' => 0, + ] + ); + + ui_toggle( + $table, + array_shift($module_rows)['name'], + '', + '', + false, + false + ); + } else { + 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, + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'zeroRecords' => __('No inventory found'), + 'emptyTable' => __('No inventory found'), + 'print_pagination_search_csv' => true, + 'csv' => 0, + ] + ); + + html_print_action_buttons( + '', + ['type' => 'form_action'] + ); + } + } + } + } + } else { + $id_agente = $inventory_id_agent; + $agentes = []; + $data = []; + $class = 'info_table'; + $style = 'width: 100%; font-size: 100px !important;'; + $ordering = true; + $searching = false; + + $columns = [ + 'alias', + 'ip', + 'secondoaryIp', + 'group', + 'secondaryGroups', + 'description', + 'os', + 'interval', + 'lastContact', + 'lastStatusChange', + 'customFields', + 'valuesCustomFields', + ]; + + $columns_names = [ + __('Alias'), + __('IP'), + __('Secondary IP'), + __('Group'), + __('Secondary groups'), + __('Description'), + __('OS'), + __('Interval'), + __('Last contact'), + __('Last status change'), + __('Custom fields'), + __('Values Custom Fields'), + ]; + + ui_print_datatable( + [ + 'id' => 'basic_info', + 'class' => $class, + 'style' => $style, + 'columns' => $columns, + 'column_names' => $columns_names, + 'ordering' => $ordering, + 'searching' => $searching, + 'order' => [ + 'field' => $columns[0], + 'direction' => 'asc', + ], + 'ajax_url' => 'operation/inventory/inventory', + 'ajax_data' => [ + 'get_data_basic_info' => 1, + 'id_agent' => $id_agente, + 'id_group' => $inventory_id_group, + ], + 'zeroRecords' => __('Agent info not found'), + 'emptyTable' => __('Agent info not found'), + 'return' => false, + 'csv' => 0, + ] + ); + echo ''; + + html_print_action_buttons( + '', + ['type' => 'form_action'] + ); + } + + ui_require_jquery_file('pandora.controls'); + ui_require_jquery_file('ajaxqueue'); + ui_require_jquery_file('bgiframe'); + } + + + /** + * Aux javascript to be run after form load. + * + * @return string + */ + public function getFormJS(): string + { + $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false); + $selectbox_id = 'module_inventory'; + + return ' + $(document).ready(function() { + if ($("#hidden-agentId").val() < 1) { + $("#text-agentAlias").val("'.__('All').'"); + } + getInventoryModules(); + + let clickedOnDynamicElement = false; + + $("[id^=\'ui-id-\']").on("click", function() { + clickedOnDynamicElement = true; + getInventoryModules(); + }); + + $("#text-agentAlias").on("keyup", function(event) { + console.log("keyup"); + console.log($("#text-agentAlias").val()); + if (!clickedOnDynamicElement || $("#text-agentAlias").val() === "") { + getInventoryModules(); + } else { + clickedOnDynamicElement = false; + } + }); + + $("#text-agentAlias").focus(function() { + $("#hidden-agentId").val("0"); + }); + }); + + function getInventoryModules() { + console.log("CALLED0"); + const clickedId = $(this).attr(\'id\'); + + $("#'.$selectbox_id.'").empty(); + + if ($("#hidden-agentId").val() > 0 || $("#text-agentAlias").val() === "'.__('All').'") { + console.log("CALLED1"); + $("#module_inventory").enable(); + var inputs = []; + var metaconsoleID = $("#hidden-metaconsoleId").val(); + if (isNaN(metaconsoleID) === true) { + metaconsoleID = 0; + } + inputs.push("id_agent=" + $("#hidden-agentId").val()); + inputs.push("get_agent_inventory_modules=1"); + inputs.push("id_node=" + metaconsoleID); + inputs.push("page=operation/agentes/ver_agente"); + + jQuery.ajax({ + data: inputs.join("&"), + type: "POST", + url: action="'.$javascript_ajax_page.'", + dataType: "json", + success: function (data) { + if (data) { + $("#'.$selectbox_id.'").append($("")); + $("#'.$selectbox_id.'").append($("")); + jQuery.each (data, function(id, value) { + console.log("qewqwe", value); + $("#'.$selectbox_id.'").append($("")); + }); + $("#'.$selectbox_id.'").val("'.$this->values['inventoryModuleId'].'"); + + } + } + }); + } else { + console.log("CALLED2"); + $("#module_inventory").disable(); + } + + return false; + } + '; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Inventory'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'inventory'; + } + + + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 330, + ]; + + return $size; + } + + +} diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 9bda55e947..a6d2dcccd8 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -68,6 +68,7 @@ if (is_ajax()) { $id_group = (int) get_parameter('id_group'); $pendingdelete = (bool) get_parameter('pendingdelete'); $get_node_agent = (bool) get_parameter('get_node_agent', false); + $get_agent_inventory_modules = (bool) get_parameter('get_agent_inventory_modules', false); $refresh_contact = get_parameter('refresh_contact', 0); @@ -1327,6 +1328,86 @@ if (is_ajax()) { } } + if ($get_agent_inventory_modules) { + $inventory_id_agent = get_parameter('id_agent'); + $id_node = (int) get_parameter('id_node'); + + $sql = 'SELECT `name` + FROM tmodule_inventory, tagent_module_inventory + WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory'; + + if ($inventory_id_agent > 0) { + $sql .= ' AND id_agente = '.$inventory_id_agent; + } + + $fields = []; + + // Get results from all nodes if id_node equals to 0. + if ($id_node === 0 && is_metaconsole() === true) { + $result = []; + $nodes_connection = metaconsole_get_connections(); + + foreach ($nodes_connection as $key => $server) { + $id_node = $server['id']; + + try { + if (is_metaconsole() === true) { + $node = new Node($id_node); + $node->connect(); + } + + $node_result = db_get_all_rows_sql($sql); + + if ($node_result === false) { + continue; + } + + $result = array_merge( + $result, + $node_result + ); + + if (is_metaconsole() === true) { + $node->disconnect(); + } + } catch (Exception $e) { + if ($node !== null) { + $node->disconnect(); + } + + return; + } + } + } else { + try { + if (is_metaconsole() === true) { + $node = new Node($id_node); + $node->connect(); + } + + $result = db_get_all_rows_sql($sql); + + if (is_metaconsole() === true) { + $node->disconnect(); + } + } catch (Exception $e) { + if ($node !== null) { + $node->disconnect(); + } + + return; + } + } + + if ($result === false) { + $result = []; + } + + echo json_encode($result); + + return; + } + return; }