diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 430ca9d6a1..8c4f5db14b 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -949,11 +949,11 @@ function agents_get_group_agents( $filter = []; - // check available groups for target user only if asking for 'All' group + // Check available groups for target user only if asking for 'All' group. if (!$noACL && $id_group == 0) { - $id_group = $id_group == 0 ? array_keys(users_get_groups(false, 'AR', false)) : groups_safe_acl($config['id_user'], $id_group, 'AR'); + $id_group = ($id_group == 0) ? array_keys(users_get_groups(false, 'AR', false)) : groups_safe_acl($config['id_user'], $id_group, 'AR'); if (empty($id_group)) { - // An empty array means the user doesn't have access + // An empty array means the user doesn't have access. return []; } } @@ -970,7 +970,7 @@ function agents_get_group_agents( $id_group = groups_get_id_recursive($id_group, true); } - // check available groups for target user only if asking for 'All' group + // Check available groups for target user only if asking for 'All' group. if (!$noACL && $id_group == 0) { $id_group = array_keys( users_get_groups(false, 'AR', true, false, (array) $id_group) @@ -978,7 +978,7 @@ function agents_get_group_agents( } } - // Search for primary and secondary groups + // Search for primary and secondary groups. if (!empty($id_group)) { $filter[] = '('.db_format_array_where_clause_sql( [ @@ -990,7 +990,7 @@ function agents_get_group_agents( } if ($search === true) { - // No added search. Show both disabled and non-disabled + // No added search. Show both disabled and non-disabled. } else if (is_array($search)) { if (!$search['all_agents']) { $filter['disabled'] = 0; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 84d18e2743..701042448f 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2257,7 +2257,7 @@ function html_print_checkbox_extended($name, $value, $checked, $disabled, $scrip if ($id == '') { $output .= ' id="checkbox-'.$id_aux.'"'; } else { - $output .= ' '.$id.'"'; + $output .= ' id='.$id; } if ($script != '') { diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index a9a9a076bd..5578b9182f 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -1,17 +1,32 @@ $v) { @@ -139,7 +164,7 @@ if (is_ajax()) { $id_agents = get_parameter('id_agents'); $selection = get_parameter('selection'); - // No filter by module group + // No filter by module group. $modules = select_modules_for_agent_group(0, $id_agents, $selection, false, true); echo json_encode($modules); return; @@ -314,28 +339,28 @@ if (is_ajax()) { } if (!empty($module_name)) { - $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%$module_name%'"; + $filter .= " AND t1.nombre COLLATE utf8_general_ci LIKE '%".$module_name."%'"; } - // Status selector + // Status selector. if ($status_modulo == AGENT_MODULE_STATUS_NORMAL) { - // Normal + // Normal. $sql_conditions .= ' estado = 0 AND utimestamp > 0 ) OR (t1.id_tipo_modulo IN(21,22,23,100)) '; } else if ($status_modulo == AGENT_MODULE_STATUS_CRITICAL_BAD) { - // Critical + // Critical. $sql_conditions .= ' estado = 1 AND utimestamp > 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_WARNING) { - // Warning + // Warning. $sql_conditions .= ' estado = 2 AND utimestamp > 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_NOT_NORMAL) { - // Not normal + // Not normal. $sql_conditions .= ' estado <> 0)'; } else if ($status_modulo == AGENT_MODULE_STATUS_UNKNOWN) { - // Unknown + // Unknown. $sql_conditions .= ' estado = 3 AND utimestamp <> 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_NOT_INIT) { - // Not init + // Not init. $sql_conditions .= ' utimestamp = 0 ) AND t1.id_tipo_modulo NOT IN (21,22,23,100)'; } @@ -415,7 +440,7 @@ if (is_ajax()) { foreach ($array_reduced as $server_name => $id_agents) { // Metaconsole db connection - // $server_name can be the server id (ugly hack, I know) + // $server_name can be the server id (ugly hack, I know). if (is_numeric($server_name)) { $connection = metaconsole_get_connection_by_id($server_name); } else { @@ -426,7 +451,7 @@ if (is_ajax()) { continue; } - // Get agent's modules + // Get agent's modules. $sql = sprintf( 'SELECT t1.id_agente, t1.id_agente_modulo, t1.nombre FROM tagente_modulo t1 %s @@ -454,7 +479,7 @@ if (is_ajax()) { $modules_aux = []; foreach ($modules as $key => $module) { - // Don't change this order, is used in the serialization + // Don't change this order, is used in the serialization. $module_data = [ 'id_module' => $module['id_agente_modulo'], 'id_agent' => $module['id_agente'], @@ -469,7 +494,7 @@ if (is_ajax()) { $modules = $modules_aux; - // Build the next array using the common values + // Build the next array using the common values. if (!empty($last_modules_set)) { $modules = array_intersect_key($modules, $last_modules_set); @@ -483,7 +508,7 @@ if (is_ajax()) { $last_modules_set = $modules; - // Restore db connection + // Restore db connection. metaconsole_restore_db(); } @@ -493,7 +518,6 @@ if (is_ajax()) { $module_data_processed = array_map( function ($item) { - // data: -> id_module | id_agent | server_name; return implode('|', $item); }, $module_data @@ -603,16 +627,16 @@ if (is_ajax()) { if ($get_agent_modules_json) { $id_agent = (int) get_parameter('id_agent'); - // Use -1 as not received + // Use -1 as not received. $disabled = (int) get_parameter('disabled', -1); $delete_pending = (int) get_parameter('delete_pending', -1); - // Use 0 as not received + // Use 0 as not received. $id_tipo_modulo = (int) get_parameter('id_tipo_modulo', 0); $status_modulo = (int) get_parameter('status_module', -1); $tags = (array) get_parameter('tags', []); - // Filter + // Filter. $filter = []; if ($disabled !== -1) { $filter['disabled'] = $disabled; @@ -630,30 +654,34 @@ if (is_ajax()) { $filter = false; } - $get_only_string_modules = get_parameter('get_only_string_modules', false); + $get_only_string_modules = get_parameter( + 'get_only_string_modules', + false + ); + if ($get_only_string_modules) { $filter['tagente_modulo.id_tipo_modulo IN'] = '(17,23,3,10,33)'; } - // Status selector + // Status selector. if ($status_modulo == AGENT_MODULE_STATUS_NORMAL) { - // Normal - $sql_conditions .= ' estado = 0 AND utimestamp > 0 ) + // Normal. + $sql_conditions .= ' estado = 0 AND utimestamp > 0 ) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,100)) '; } else if ($status_modulo == AGENT_MODULE_STATUS_CRITICAL_BAD) { - // Critical + // Critical. $sql_conditions .= ' estado = 1 AND utimestamp > 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_WARNING) { - // Warning + // Warning. $sql_conditions .= ' estado = 2 AND utimestamp > 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_NOT_NORMAL) { - // Not normal + // Not normal. $sql_conditions .= ' estado <> 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_UNKNOWN) { - // Unknown + // Unknown. $sql_conditions .= ' estado = 3 AND utimestamp <> 0 )'; } else if ($status_modulo == AGENT_MODULE_STATUS_NOT_INIT) { - // Not init + // Not init. $sql_conditions .= ' utimestamp = 0 ) AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,100)'; } @@ -666,7 +694,7 @@ if (is_ajax()) { $get_id_and_name = (bool) get_parameter('get_id_and_name'); $get_distinct_name = (bool) get_parameter('get_distinct_name'); - // Fields + // Fields. $fields = '*'; if ($get_id_and_name) { $fields = [ @@ -683,7 +711,8 @@ if (is_ajax()) { $agentName = (string) get_parameter('agent_name', null); $server_name = (string) get_parameter('server_name', null); $server_id = (int) get_parameter('server_id', 0); - // This will force to get local modules although metaconsole is active, by default get all modules from all nodes + // This will force to get local modules although metaconsole is active, + // by default get all modules from all nodes. $force_local_modules = (int) get_parameter('force_local_modules', 0); if ($agentName != null) { @@ -706,7 +735,7 @@ if (is_ajax()) { } if (metaconsole_load_external_db($connection) == NOERR) { - // Get all agents if no agent was given + // Get all agents if no agent was given. if ($id_agent == 0) { $id_agent = array_keys( agents_get_group_agents( @@ -720,11 +749,11 @@ if (is_ajax()) { $agent_modules = agents_get_modules($id_agent, $fields, $filter, $indexed, true, $force_tags); } - // Restore db connection + // Restore db connection. metaconsole_restore_db(); } } else { - // Get all agents if no agent was given + // Get all agents if no agent was given. if ($id_agent == 0) { $id_agent = array_keys( agents_get_group_agents( @@ -768,7 +797,7 @@ if (is_ajax()) { $id_agent = (int) get_parameter('id_agent'); $metaconsole = (bool) get_parameter('metaconsole', false); $id_server = (int) get_parameter('id_server', 0); - // Metaconsole + // Metaconsole. $server = null; if ($metaconsole) { $filter = []; @@ -805,7 +834,7 @@ if (is_ajax()) { echo ''.__('Last remote contact').': '.human_time_comparation($agent['ultimo_contacto_remoto']).'
'; if (!$metaconsole) { - // Fix : Only show agents with module with tags of user profile + // Fix : Only show agents with module with tags of user profile. $_user_tags = tags_get_user_tags($config['id_user'], 'RR'); $_sql_post = ''; @@ -842,10 +871,10 @@ if (is_ajax()) { if ($bad_modules === false) { $size_bad_modules = 0; } else { - $size_bad_modules = sizeof($bad_modules); + $size_bad_modules = count($bad_modules); } - // Modules down + // Modules down. if ($size_bad_modules > 0) { echo ''.__('Monitors down').': '.$size_bad_modules.' / '.$total_modules; echo ''; } - // Alerts (if present) + // Alerts (if present). $sql = sprintf( 'SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente @@ -940,8 +969,8 @@ if (is_ajax()) { if ($module['id_tipo_modulo'] == 18) { echo ''.__('Address').': '; - // Get the IP/IPs from the module description - // Always the IP is the last part of the description (after the last space) + // Get the IP/IPs from the module description Always the IP + // is the last part of the description (after the last space). $ips = explode(' ', $module['descripcion']); $ips = $ips[(count($ips) - 1)]; @@ -951,7 +980,7 @@ if (is_ajax()) { } else { echo ''; @@ -1036,7 +1065,7 @@ $agent_a = check_acl($config['id_user'], 0, 'AR'); $agent_w = check_acl($config['id_user'], 0, 'AW'); $access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR'); $agent = db_get_row('tagente', 'id_agente', $id_agente); -// get group for this id_agente +// Get group for this id_agente. $id_grupo = $agent['id_grupo']; $is_extra = enterprise_hook('policies_is_agent_extra_policy', [$id_agente]); @@ -1056,7 +1085,7 @@ if (! check_acl_one_of_groups($config['id_user'], $all_groups, 'AR') && ! check_ return; } -// Check for Network FLAG change request +// Check for Network FLAG change request. $flag = get_parameter('flag', ''); if ($flag !== '') { if ($flag == 1 && check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { @@ -1070,7 +1099,7 @@ if ($flag !== '') { } } -// Check for Network FLAG change request +// Check for Network FLAG change request. $flag_agent = get_parameter('flag_agent', ''); if ($flag_agent !== '') { if ($flag_agent == 1 && check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) { @@ -1085,10 +1114,10 @@ if ($agent['icon_path']) { } -// -------------Code for the tabs in the header of agent page----------- +// Code for the tabs in the header of agent page. $tab = get_parameter('tab', 'main'); -// Manage tab +// Manage tab. $managetab = []; if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') || $is_extra) { @@ -1104,7 +1133,7 @@ if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') || $is_extra) } -// Main tab +// Main tab. $maintab['text'] = ''.html_print_image('images/agent_mc.png', true, ['title' => __('Main')]).''; if ($tab == 'main') { @@ -1115,7 +1144,7 @@ if ($tab == 'main') { -// Alert tab +// Alert tab. $alerttab['text'] = ''.html_print_image('images/op_alerts.png', true, ['title' => __('Alerts')]).''; if ($tab == 'alert') { @@ -1124,27 +1153,27 @@ if ($tab == 'alert') { $alerttab['active'] = false; } -// Inventory +// Inventory. $inventorytab = enterprise_hook('inventory_tab'); if ($inventorytab == -1) { $inventorytab = ''; } -// Collection +// Collection. $collectiontab = enterprise_hook('collection_tab'); if ($collectiontab == -1) { $collectiontab = ''; } -// Policy +// Policy. $policyTab = enterprise_hook('policy_tab'); if ($policyTab == -1) { $policyTab = ''; } -// WUX Console +// WUX Console. $modules_wux = enterprise_hook('get_wux_modules', [$id_agente]); if ($modules_wux) { $wux_console_tab = enterprise_hook('wux_console_tab'); @@ -1161,7 +1190,7 @@ if ($url_route_analyzer) { } } -// GIS tab +// GIS tab. $gistab = []; if ($config['activate_gis']) { $gistab['text'] = ''.html_print_image('images/op_gis.png', true, [ 'title' => __('GIS data')]).''; @@ -1174,7 +1203,7 @@ if ($config['activate_gis']) { } -// Incident tab +// Incident tab. $total_incidents = agents_get_count_incidents($id_agente); if ($total_incidents > 0) { $incidenttab['text'] = ''.html_print_image('images/book_edit.png', true, ['title' => __('Incidents')]).''; @@ -1187,7 +1216,7 @@ if ($total_incidents > 0) { } -// Url address tab +// Url address tab. if ($agent['url_address'] != '') { $urladdresstab['text'] = ''.html_print_image('images/link.png', true, ['title' => __('Url address')]).''; } @@ -1199,7 +1228,7 @@ if ($tab == 'url_address') { } -// Custom fields tab +// Custom fields tab. $custom_fields['text'] = ''.html_print_image('images/custom_field.png', true, ['title' => __('Custom fields')]).''; if ($tab == 'custom_fields') { $custom_fields['active'] = true; @@ -1208,7 +1237,7 @@ if ($tab == 'custom_fields') { } -// Graphs tab +// Graphs tab. $graphs['text'] = ''.html_print_image('images/chart.png', true, ['title' => __('Graphs')]).''; if ($tab == 'graphs') { $graphs['active'] = true; @@ -1217,7 +1246,7 @@ if ($tab == 'graphs') { } -// Log viewer tab +// Log viewer tab. if (enterprise_installed() && $config['log_collector']) { $is_windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'; $agent_has_logs = (bool) db_get_value('id_agent', 'tagent_module_log', 'id_agent', $id_agente); @@ -1229,7 +1258,7 @@ if (enterprise_installed() && $config['log_collector']) { } } -// eHorus tab +// EHorus tab. if ($config['ehorus_enabled'] && !empty($config['ehorus_custom_field']) && (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') || is_user_admin($config['id_user'])) ) { @@ -1238,7 +1267,7 @@ if ($config['ehorus_enabled'] && !empty($config['ehorus_custom_field']) $tab_url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=ehorus&id_agente='.$id_agente; $ehorus_tab['text'] = ''.html_print_image('images/ehorus/ehorus.png', true, [ 'title' => __('eHorus')]).''; - // Hidden subtab layer + // Hidden subtab layer. $ehorus_tab['sub_menu'] = '