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] = '
'; $table->data[0][1] .= html_print_select_groups( $config['id_user'], $access, true, 'id_group', $inventory_id_group, $filteringFunction, '', '1', true, false, true, '', false ); $table->data[0][1] .= '
'; // Module selected. $table->data[0][2] = ''.__('Module').''; if ($is_metaconsole === true) { $table->data[0][3] = html_print_select($fields, 'module_inventory_general_view', $inventory_module, $filteringFunction, __('All'), 0, true, false, true, '', false, 'min-width: 194px; max-width: 200px;'); } else { $sql = 'SELECT 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; } $table->data[0][3] = html_print_select_from_sql($sql, 'module_inventory_general_view', $inventory_module, '', __('All'), 'all', true, false, false); } // Button of submit. $table->data[0][4] = html_print_submit_button(__('Search'), 'submit_filter', $noFilterSelected, "class='sub search'", 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']; } } } $table->data[1][0] = ''.__('Agent').''; $params = []; $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'agent'; $params['value'] = $inventory_agent; $params['selectbox_id'] = 'module_inventory_general_view'; $params['javascript_is_function_select'] = true; $params['javascript_function_action_after_select'] = 'this.form.submit'; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; $params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent'; $params['hidden_input_idagent_name'] = 'agent_id'; $params['hidden_input_idagent_value'] = $inventory_id_agent; if ($is_metaconsole === true) { $params['print_input_id_server'] = true; $params['input_id_server_id'] = 'hidden-autocomplete_id_server'; $params['input_id_server_name'] = 'id_server_agent'; $params['input_id_server_value'] = $inventory_id_server; $params['metaconsole_enabled'] = true; } $table->data[1][1] = ui_print_agent_autocomplete_input($params); // String search_string. $table->data[1][2] = ''.__('Search').''; $table->data[1][3] = html_print_input_text('search_string', $inventory_search_string, '', 25, 0, true, false, false, '', '', $filteringFunction, 'off', false, $filteringFunction); // Date filter. In Metaconsole has not reason for show. if (is_metaconsole() === false) { $table->data[2][0] = ''.__('Date').''; $dates = inventory_get_dates($inventory_module, $inventory_agent, $inventory_id_group); $table->data[2][1] = html_print_select($dates, 'utimestamp', $utimestamp, '', __('Last'), 0, true); } // Order by agent filter. $table->data[2][2] = ''.__('Order by agent').''; $table->data[2][3] = html_print_checkbox('order_by_agent', 1, $order_by_agent, true, false, ''); html_print_table($table); echo ''; // No agent selected or no search performed. if ($inventory_id_agent < 0 || $submit_filter === false) { echo ' '; return; } if ($is_metaconsole === false) { // 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, '', $pagination_url_parameters ); } if (count($agents_ids) === 0 || (int) $inventory_data === ERR_NODATA) { ui_print_info_message(['no_close' => true, 'message' => __('No data found.') ]); echo ' '; return; } echo "
"; echo "".__('Export this list to CSV').''.html_print_image('images/csv.png', true, ['title' => __('Export this list to CSV')]).''; echo '
'; echo "'; ?> true, 'message' => __('No data found.') ]); } else { echo $inventory_data; } close_meta_frame(); } ui_require_jquery_file('pandora.controls'); ui_require_jquery_file('ajaxqueue'); ui_require_jquery_file('bgiframe'); ?>