$id_agent, 'nombre' => $values['safe_mode_module'], ] ); } } // CONF FILE DELETION if (isset($values['delete_conf'])) { unset($values['delete_conf']); $n_deleted = 0; foreach ($id_agents as $id_agent) { $agent_md5 = md5(agents_get_name($id_agent)); @unlink( $config['remote_config'].'/md5/'.$agent_md5.'.md5' ); $result = @unlink( $config['remote_config'].'/conf/'.$agent_md5.'.conf' ); $n_deleted += (int) $result; } if ($n_deleted > 0) { db_pandora_audit('Massive management', 'Delete conf file '.$id_agent); } else { db_pandora_audit('Massive management', 'Try to delete conf file '.$id_agent); } ui_print_result_message( $n_deleted > 0, __('Configuration files deleted successfully').'('.$n_deleted.')', __('Configuration files cannot be deleted') ); } if (empty($values) && empty($fields)) { $id_agents = []; } $n_edited = 0; $result = false; foreach ($id_agents as $id_agent) { $old_interval_value = db_get_value_filter('intervalo', 'tagente', ['id_agente' => $id_agent]); if (!empty($values)) { $group_old = false; $disabled_old = false; if ($values['id_grupo'] || isset($values['disabled'])) { $values_old = db_get_row_filter('tagente', ['id_agente' => $id_agent], ['id_grupo', 'disabled']); if ($values_old['id_grupo']) { $group_old = $values_old['id_grupo']; } if (isset($values['disabled'])) { $disabled_old = $values_old['disabled']; } } // Get the id_agent_module for this agent to update the 'safe_operation_mode' field. if (isset($values['safe_mode_module']) && ($values['safe_mode_module'] != '0')) { $values['safe_mode_module'] = $id_module_safe[$id_agent]; } $result = db_process_sql_update( 'tagente', $values, ['id_agente' => $id_agent] ); if ($result && $config['metaconsole_agent_cache'] == 1) { $server_name['server_name'] = db_get_sql('SELECT server_name FROM tagente WHERE id_agente ='.$id_agent); // Force an update of the agent cache. $result_metaconsole = agent_update_from_cache($id_agent, $values, $server_name); } // Update the configuration files. if ($result && ($old_interval_value != $values['intervalo']) && !empty($values['intervalo'])) { enterprise_hook( 'config_agents_update_config_token', [ $id_agent, 'interval', $values['intervalo'], ] ); } if ($disabled_old !== false && $disabled_old != $values['disabled']) { enterprise_hook( 'config_agents_update_config_token', [ $id_agent, 'standby', $values['disabled'], ] ); // Validate alerts for disabled agents. if ($values['disabled'] == 1) { alerts_validate_alert_agent($id_agent); } } if ($group_old || $result) { if ($group_old && $group_old != null) { $tpolicy_group_old = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups WHERE id_group = '.$group_old ); } else { $tpolicy_group_old = db_get_all_rows_sql('SELECT id_policy FROM tpolicy_groups'); } if ($tpolicy_group_old) { foreach ($tpolicy_group_old as $key => $value) { $tpolicy_agents_old = db_get_sql( 'SELECT * FROM tpolicy_agents WHERE id_policy = '.$value['id_policy'].' AND id_agent = '.$id_agent ); if ($tpolicy_agents_old) { $result2 = db_process_sql_update( 'tpolicy_agents', ['pending_delete' => 1], [ 'id_agent' => $id_agent, 'id_policy' => $value['id_policy'], ] ); } } } if ($values['id_grupo'] && $values['id_grupo'] != null) { $tpolicy_group_new = db_get_all_rows_sql( 'SELECT id_policy FROM tpolicy_groups WHERE id_group = '.$values['id_grupo'] ); } else { $tpolicy_group_new = db_get_all_rows_sql('SELECT id_policy FROM tpolicy_groups'); } if ($tpolicy_group_new) { foreach ($tpolicy_group_new as $key => $value) { $tpolicy_agents_new = db_get_sql( 'SELECT * FROM tpolicy_agents WHERE id_policy = '.$value['id_policy'].' AND id_agent ='.$id_agent ); if (!$tpolicy_agents_new) { db_process_sql_insert( 'tpolicy_agents', [ 'id_policy' => $value['id_policy'], 'id_agent' => $id_agent, ] ); } else { $result3 = db_process_sql_update( 'tpolicy_agents', ['pending_delete' => 0], [ 'id_agent' => $id_agent, 'id_policy' => $value['id_policy'], ] ); } } } } } $info = []; // Update Custom Fields foreach ($fields as $field) { $info[$field['id_field']] = $field['name']; $value = get_parameter('customvalue_'.$field['id_field']); if (empty($value) === false) { $key = $field['id_field']; $old_value = db_get_all_rows_filter( 'tagent_custom_data', [ 'id_agent' => $id_agent, 'id_field' => $key, ] ); if ($old_value === false) { // Create custom field if not exist $result = db_process_sql_insert( 'tagent_custom_data', [ 'id_field' => $key, 'id_agent' => $id_agent, 'description' => $value, ] ); } else { if ($old_value[0]['description'] !== $value) { $result = db_process_sql_update( 'tagent_custom_data', ['description' => $value], [ 'id_field' => $key, 'id_agent' => $id_agent, ] ); } } } } $n_edited += (int) $result; } if ($result !== false) { db_pandora_audit('Massive management', 'Update agent '.$id_agent, false, false, json_encode($info)); } else { if (isset($id_agent)) { db_pandora_audit('Massive management', 'Try to update agent '.$id_agent, false, false, json_encode($info)); } } ui_print_result_message( $result !== false, __('Agents updated successfully (%d)', $n_edited), __('Agents cannot be updated (maybe there was no field to update)') ); } $id_group = 0; $groups = users_get_groups(); $table = new StdClass(); $table->id = 'delete_table'; $table->class = 'databox filters'; $table->width = '100%'; $table->data = []; $table->style = []; $table->style[0] = 'font-weight: bold;'; $table->style[2] = 'font-weight: bold'; $table->size = []; $table->size[0] = '15%'; $table->size[1] = '35%'; $table->size[2] = '15%'; $table->size[3] = '35%'; $table->data = []; $table->data[0][0] = __('Group'); $table->data[0][1] = html_print_select_groups( false, 'AW', true, 'id_group', $id_group, false, '', '', true ); $table->data[0][2] = __('Group recursion'); $table->data[0][3] = html_print_checkbox( 'recursion2', 1, $recursion, true, false ); $status_list = []; $status_list[AGENT_STATUS_NORMAL] = __('Normal'); $status_list[AGENT_STATUS_WARNING] = __('Warning'); $status_list[AGENT_STATUS_CRITICAL] = __('Critical'); $status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); $status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); $status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); $table->data[1][0] = __('Status'); $table->data[1][1] = html_print_select( $status_list, 'status_agents', 'selected', '', __('All'), AGENT_STATUS_ALL, true ); $table->data[1][2] = __('Show agents'); $table->data[1][3] = html_print_select( [ 0 => 'Only enabled', 1 => 'Only disabled', ], 'disabled', 2, '', __('All'), 2, true, '', '', '', '', 'width:30%;' ); $table->data[2][0] = __('Agents'); $table->data[2][0] .= ''; $enabled_agents = agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)), ['disabled' => 0], 'none'); $all_agents = (agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)), ['disabled' => 1], 'none') + $enabled_agents); $table->data[2][1] = html_print_select( $all_agents, 'id_agents[]', 0, false, '', '', true, true ); echo '
'; html_print_table($table); $nombre_agente = ''; $direccion_agente = ''; $id_agente = 0; $id_parent = 0; $cascade_protection = 0; $group = 0; $interval = ''; $id_os = 0; $server_name = 0; $description = ''; echo ''; ui_toggle(html_print_table($table, true), __('Advanced options')); unset($table); $table = new StdClass(); $table->width = '100%'; $table->class = 'databox filters'; $table->head = []; $table->style = []; $table->style[0] = 'font-weight: bold; width: 150px;'; $table->data = []; $table->size[0] = '15%'; $table->size[1] = '35%'; $table->size[2] = '15%'; $table->size[3] = '35%'; $fields = db_get_all_fields_in_table('tagent_custom_fields'); if ($fields === false) { $fields = []; } foreach ($fields as $field) { $data[0] = ''.$field['name'].''; $combo = []; $combo = $field['combo_values']; $combo = explode(',', $combo); $combo_values = []; foreach ($combo as $value) { $combo_values[$value] = $value; } $custom_value = db_get_value_filter('description', 'tagent_custom_data', ['id_field' => $field['id_field'], 'id_agent' => $id_agente]); if ($custom_value === false) { $custom_value = ''; } if ($field['is_password_type']) { $data[1] = html_print_input_text_extended( 'customvalue_'.$field['id_field'], $custom_value, 'customvalue_'.$field['id_field'], '', 30, 100, $view_mode, '', '', true, true ); } else { $data[1] = html_print_textarea('customvalue_'.$field['id_field'], 2, 65, $custom_value, 'class="mrgn_right_30px"', true); } if ($field['combo_values'] !== '') { $data[1] = html_print_input( [ 'type' => 'select_search', 'fields' => $combo_values, 'name' => 'customvalue_'.$field['id_field'], 'selected' => $custom_value, 'nothing' => __('No change'), 'nothing_value' => '', 'return' => true, 'sort' => false, ] ); }; array_push($table->data, $data); } if (!empty($fields)) { ui_toggle(html_print_table($table, true), __('Custom fields')); } echo ''; html_print_input_hidden('id_agente', $id_agente); attachActionButton('update_agents', 'update', $table->width); // Shown and hide div. echo '
'; ui_require_jquery_file('form'); ui_require_jquery_file('pandora.controls'); ui_require_jquery_file('ajaxqueue'); ui_require_jquery_file('bgiframe'); ?>