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 !== false) { foreach ($result as $row) { $agents[$row['id_agente']] = $row['nombre']; } } $agents_select = $agents; if (strlen($inventory_agent) == 0) { $inventory_id_agent = -1; $inventory_agent = __('All'); } else if ($inventory_agent == __('All')) { $inventory_id_agent = 0; } else { $sql = 'SELECT id_agente FROM tagente WHERE nombre LIKE "'.$inventory_agent.'"'; $result = db_get_all_rows_sql($sql); $inventory_id_agent = $result[0]['id_agente']; } // 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) { $inventory_data = inventory_get_data( $agents_ids, $inventory_module, $utimestamp, $inventory_search_string, $export, false, $order_by_agent ); if ((int) $inventory_data === ERR_NODATA) { $inventory_data = ''; } } return; } return; } global $config; check_login(); $is_metaconsole = is_metaconsole(); if ($is_metaconsole === true) { open_meta_frame(); } if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'], 0, 'AW')) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, 'Trying to access Inventory' ); include 'general/noaccess.php'; return; } require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_inventory.php'; // Header. ui_print_standard_header( __('Inventory'), 'images/op_inventory.png', false, '', false, [], [ [ 'link' => '', 'label' => __('Monitoring'), ], ] ); $inventory_id_agent = (int) get_parameter('agent_id', -1); $inventory_agent = (string) get_parameter('agent', ''); if (strlen($inventory_agent) == 0) { $inventory_id_agent = -1; $inventory_agent = __('All'); } else if ($inventory_agent == __('All')) { $inventory_id_agent = 0; } $inventory_module = get_parameter('module_inventory_general_view'); $inventory_id_group = (int) get_parameter('id_group'); $inventory_search_string = (string) get_parameter('search_string'); $order_by_agent = (bool) get_parameter('order_by_agent'); $export = (string) get_parameter('export'); $utimestamp = (int) get_parameter('utimestamp'); $submit_filter = (bool) get_parameter('submit_filter'); $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) get_parameter('id_server', 0); $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; } if ($is_metaconsole === true) { 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); 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; } $result_module = db_get_all_rows_sql($sql); if ($submit_filter === true) { $inventory_data .= inventory_get_data( array_keys($agents_node), $inventory_module, $utimestamp, $inventory_search_string, $export, false, $order_by_agent, $node, $pagination_url_parameters ); } // Restore db connection. metaconsole_restore_db(); } else { $result_module = []; 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; } $result = db_get_all_rows_sql($sql); if ($result !== false) { $result_module = array_merge($result_module, $result); if ($submit_filter === true) { // Get the data. $result_data = inventory_get_data( array_keys($agents_node), $inventory_module, $utimestamp, $inventory_search_string, $export, false, $order_by_agent, $server, $pagination_url_parameters ); 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_a = (bool) check_acl($config['id_user'], 0, 'AR'); $agent_w = (bool) check_acl($config['id_user'], 0, 'AW'); $access = ($agent_a === true) ? 'AR' : (($agent_w === true) ? 'AW' : 'AR'); if (is_metaconsole() === true) { $filteringFunction = 'active_inventory_submit()'; ui_print_info_message(['no_close' => true, 'message' => __('You must select at least one filter.'), 'force_class' => 'select_one_filter']); ?> '; $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; $table->size = []; $table->size[0] = '120px'; $table->cellpadding = 0; $table->cellspacing = 0; $table->data = []; $table->rowspan[0][4] = 2; if ($is_metaconsole === true) { // Node select. $nodes = []; foreach ($nodes_connection as $row) { $nodes[$row['id']] = $row['server_name']; } $table->data[-1][0] = ''.__('Server').''; $table->data[-1][1] = html_print_select($nodes, 'id_server', $id_server, $filteringFunction, __('All'), 0, true, false, true, '', false, 'min-width: 250px; max-width: 300px;'); } // Group select. $table->data[0][0] = ''.__('Group').''; $table->data[0][1] = '