Merge branch 'ent-10008-Gestion-de-busquedas-en-la-vista-de-agentes-y-mejora-de-las-busquedas' into 'develop'

implemented agents view filter management

See merge request 
This commit is contained in:
Daniel Rodriguez 2023-03-02 17:21:13 +00:00
commit 0a16fbbecf
7 changed files with 1264 additions and 77 deletions

@ -1,6 +1,20 @@
-- Active: 1653046769261@@172.16.0.2@3306@pandora
START TRANSACTION;
CREATE TABLE IF NOT EXISTS `tagent_filter` (
`id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_name` VARCHAR(600) NOT NULL,
`id_group_filter` INT NOT NULL DEFAULT 0,
`group_id` INT NOT NULL DEFAULT 0,
`recursion` TEXT,
`status` INT NOT NULL DEFAULT -1,
`search` TEXT,
`id_os` INT NOT NULL DEFAULT 0,
`policies` TEXT,
`search_custom` TEXT,
`ag_custom_fields` TEXT,
PRIMARY KEY (`id_filter`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
CREATE TABLE `tevent_sound` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` TEXT NULL,

@ -31,6 +31,15 @@ $get_agents_interfaces = (bool) get_parameter('get_agents_interfaces');
$id_agents = get_parameter('id_agents', []);
$get_agents_group = (bool) get_parameter('get_agents_group', false);
$force_local = (bool) get_parameter('force_local', false);
// Agent detail filter.
$load_filter_modal = get_parameter('load_filter_modal', 0);
$save_filter_modal = get_parameter('save_filter_modal', 0);
$get_agent_filters = get_parameter('get_agent_filters', 0);
$save_agent_filter = get_parameter('save_agent_filter', 0);
$update_agent_filter = get_parameter('update_agent_filter', 0);
$delete_agent_filter = get_parameter('delete_agent_filter', 0);
if (https_is_running()) {
header('Content-type: application/json');
}
@ -345,4 +354,656 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
return;
}
// Saves an event filter.
if ($save_agent_filter) {
$values = [];
$values['id_name'] = get_parameter('id_name');
$values['group_id'] = get_parameter('group_id');
$values['recursion'] = get_parameter('recursion');
$values['status'] = get_parameter('status');
$values['search'] = get_parameter('search');
$values['id_os'] = get_parameter('id_os');
$values['policies'] = json_encode(get_parameter('policies'));
$values['search_custom'] = get_parameter('search_custom');
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
$values['id_group_filter'] = get_parameter('id_group_filter');
$exists = (bool) db_get_value_filter(
'id_filter',
'tagent_filter',
$values
);
if ($exists === true) {
echo 'duplicate';
} else {
$result = db_process_sql_insert('tagent_filter', $values);
if ($result === false) {
echo 'error';
} else {
echo $result;
}
}
}
if ($update_agent_filter) {
$values = [];
$id = get_parameter('id');
$values['group_id'] = get_parameter('group_id');
$values['recursion'] = get_parameter('recursion');
$values['status'] = get_parameter('status');
$values['search'] = get_parameter('search');
$values['id_os'] = get_parameter('id_os');
$values['policies'] = json_encode(get_parameter('policies'));
$values['search_custom'] = get_parameter('search_custom');
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
$result = db_process_sql_update(
'tagent_filter',
$values,
['id_filter' => $id]
);
if ($result === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($delete_agent_filter) {
$id = get_parameter('id');
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'DELETE
FROM tagent_filter
WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_process_sql($sql);
if ($agent_filters === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($get_agent_filters) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all('AR'),
true
);
$sql = 'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_get_all_rows_sql($sql);
$result = [];
if ($agent_filters !== false) {
foreach ($agent_filters as $agent_filter) {
$result[$agent_filter['id_filter']] = $agent_filter['id_name'];
}
}
echo io_json_mb_encode($result);
}
if ((int) $load_filter_modal === 1) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all('AR'),
true
);
$sql = 'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_get_all_rows_sql($sql);
$filters = [];
foreach ($agent_filters as $agent_filter) {
$filters[$agent_filter['id_filter']] = $agent_filter['id_name'];
}
echo '<div id="load-filter-select" class="load-filter-modal">';
echo '<form method="post" id="form_load_filter" action="index.php?sec=view&sec2=operation/agentes/estado_agente&pure=">';
$table = new StdClass;
$table->id = 'load_filter_form';
$table->width = '100%';
$table->cellspacing = 4;
$table->cellpadding = 4;
$table->class = 'databox';
if (is_metaconsole()) {
$table->cellspacing = 0;
$table->cellpadding = 0;
$table->class = 'databox filters';
}
$table->styleTable = 'font-weight: bold; color: #555; text-align:left;';
$filter_id_width = '200px';
if (is_metaconsole()) {
$filter_id_width = '150px';
}
$data = [];
$table->rowid[3] = 'update_filter_row1';
$data[0] = __('Load filter').$jump;
$data[0] .= html_print_select(
$filters,
'filter_id',
$current,
'',
__('None'),
0,
true,
false,
true,
'',
false,
'margin-left:5px; width:'.$filter_id_width.';'
);
$data[1] = html_print_submit_button(
__('Load filter'),
'load_filter',
false,
'class="sub upd"',
true
);
$data[1] .= html_print_input_hidden('load_filter', 1, true);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '</form>';
echo '</div>';
?>
<script type="text/javascript">
function show_filter() {
$("#load-filter-select").dialog({
resizable: true,
draggable: true,
modal: false,
closeOnEscape: true,
width: 450
});
}
$(document).ready(function() {
show_filter();
});
</script>
<?php
return;
}
if ($save_filter_modal) {
echo '<div id="save-filter-select">';
if (check_acl($config['id_user'], 0, 'AW')) {
echo '<div id="#info_box"></div>';
$table = new StdClass;
$table->id = 'save_filter_form';
$table->width = '100%';
$table->cellspacing = 4;
$table->cellpadding = 4;
$table->class = 'databox';
if (is_metaconsole() === true) {
$table->class = 'databox filters';
$table->cellspacing = 0;
$table->cellpadding = 0;
}
$table->styleTable = 'font-weight: bold; text-align:left;';
if (is_metaconsole() === true) {
$table->style[0] = 'width: 50%; width:50%;';
}
$data = [];
$table->rowid[0] = 'update_save_selector';
$data[0] = html_print_radio_button(
'filter_mode',
'new',
'',
true,
true
).__('New filter').'';
$data[1] = html_print_radio_button(
'filter_mode',
'update',
'',
false,
true
).__('Update/delete filter').'';
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[1] = 'save_filter_row1';
$data[0] = __('Filter name').$jump;
$data[0] .= html_print_input_text('id_name', '', '', 15, 255, true);
if (is_metaconsole() === true) {
$data[1] = __('Save in Group').$jump;
} else {
$data[1] = __('Filter group').$jump;
}
$user_groups_array = users_get_groups_for_select(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$data[1] .= html_print_select(
$user_groups_array,
'id_group_filter_dialog',
$id_group_filter,
'',
'',
0,
true,
false,
false,
'w130'
);
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[2] = 'save_filter_row2';
$table->data[] = $data;
$table->rowclass[] = '';
$data = [];
$table->rowid[3] = 'update_filter_row1';
$data[0] = __('Filter').$jump;
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_get_all_rows_sql($sql);
$_filters_update = [];
if ($agent_filters !== false) {
foreach ($agent_filters as $agent_filter) {
$_filters_update[$agent_filter['id_filter']] = $agent_filter['id_name'];
}
}
$data[0] .= html_print_select(
$_filters_update,
'overwrite_filter',
'',
'',
'',
0,
true
);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '<div id="update_delete_row"><br>';
echo html_print_submit_button(
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
echo html_print_submit_button(
__('Delete filter'),
'delete_filter',
false,
'class="sub delete float-right" onclick="save_delete_filter();"',
true
);
echo '</div>';
echo '<div><br>';
echo html_print_submit_button(
__('Save current filter'),
'save_filter',
false,
'class="sub upd float-right" onclick="save_new_filter();"',
true
);
echo '</div>';
} else {
include 'general/noaccess.php';
}
echo '</div>';
?>
<script type="text/javascript">
function show_save_filter() {
$('#save_filter_row1').show();
$('#save_filter_row2').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
// Filter save mode selector
$("[name='filter_mode']").click(function() {
if ($(this).val() == 'new') {
$('#save_filter_row1').show();
$('#save_filter_row2').show();
$('#submit-save_filter').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
}
else {
$('#save_filter_row1').hide();
$('#save_filter_row2').hide();
$('#update_filter_row1').show();
$('#submit-save_filter').hide();
$('#update_delete_row').show();
}
});
$("#save-filter-select").dialog({
resizable: true,
draggable: true,
modal: false,
closeOnEscape: true
});
}
function save_new_filter() {
// If the filter name is blank show error
if ($('#text-id_name').val() == '') {
$('#show_filter_error').html("<h3 class='error'><?php echo __('Filter name cannot be left blank'); ?></h3>");
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
return false;
}
var custom_fields_values = $('input[name^="ag_custom_fields"]').map(function() {
return this.value;
}).get();
var custom_fields_ids = $("input[name^='ag_custom_fields']").map(function() {
var name = $(this).attr("name");
var number = name.match(/\[(.*?)\]/)[1];
return number;
}).get();
var ag_custom_fields = custom_fields_ids.reduce(function(result, custom_fields_id, index) {
result[custom_fields_id] = custom_fields_values[index];
return result;
}, {});
var id_filter_save;
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"save_agent_filter" : 1,
"id_name": $("#text-id_name").val(),
"id" : $("#overwrite_filter").val(),
"group_id" : $("#group_id").val(),
"recursion" : $("#checkbox-recursion").is(':checked'),
"status" : $("#status").val(),
"search" : $("#text-search").val(),
"id_os" : $("#os").val(),
"policies" : $("#policies").val(),
"search_custom" : $("#text-search_custom").val(),
"ag_custom_fields": JSON.stringify(ag_custom_fields),
"id_group_filter": $("#id_group_filter_dialog").val(),
},
function (data) {
$("#info_box").hide();
if (data == 'error') {
$("#info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
else if (data == 'duplicate') {
$("#info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "duplicate_create_filter") {
return true;
}
else
return false;
}).show();
}
else {
id_filter_save = data;
$("#info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_create_filter") {
return true;
}
else
return false;
}).show();
}
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"get_agent_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
$('#filter_id').append($('<option></option>').html (s).attr("value", i));
});
},
"json"
);
// Close dialog.
$("#save-filter-select").dialog('close');
}
);
}
function save_update_filter() {
var id_filter_update = $("#overwrite_filter").val();
var name_filter_update = $("#overwrite_filter option[value='"+id_filter_update+"']").text();
var custom_fields_values = $('input[name^="ag_custom_fields"]').map(function() {
return this.value;
}).get();
var custom_fields_ids = $("input[name^='ag_custom_fields']").map(function() {
var name = $(this).attr("name");
var number = name.match(/\[(.*?)\]/)[1];
return number;
}).get();
var ag_custom_fields = custom_fields_ids.reduce(function(result, custom_fields_id, index) {
result[custom_fields_id] = custom_fields_values[index];
return result;
}, {});
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"update_agent_filter" : 1,
"id" : $("#overwrite_filter").val(),
"group_id" : $("#group_id").val(),
"recursion" : $("#checkbox-recursion").is(':checked'),
"status" : $("#status").val(),
"search" : $("#text-search").val(),
"id_os" : $("#os").val(),
"policies" : $("#policies").val(),
"search_custom" : $("#text-search_custom").val(),
"ag_custom_fields": JSON.stringify(ag_custom_fields),
},
function (data) {
$(".info_box").hide();
if (data == 'ok') {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_update_filter") {
return true;
}
else
return false;
}).show();
}
else {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
});
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"get_agent_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
if (i == id_filter_update) {
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
}
else {
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
}
});
},
"json"
);
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
// Update the info with the loaded filter
$("#hidden-id_name").val($('#text-id_name').val());
$('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update);
return false;
}
function save_delete_filter() {
var id_filter_update = $("#overwrite_filter").val();
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"delete_agent_filter" : 1,
"id" : $("#overwrite_filter").val(),
},
function (data) {
$(".info_box").hide();
if (data == 'ok') {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_update_filter") {
return true;
}
else
return false;
}).show();
}
else {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
});
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"get_agent_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
if (i == id_filter_update) {
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
}
else {
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
}
});
},
"json"
);
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
return false;
}
$(document).ready(function() {
show_save_filter();
});
</script>
<?php
return;
}
return;

@ -73,6 +73,7 @@ if (check_login()) {
$get_monitor_filters = get_parameter('get_monitor_filters', 0);
$save_monitor_filter = get_parameter('save_monitor_filter', 0);
$update_monitor_filter = get_parameter('update_monitor_filter', 0);
$delete_monitor_filter = get_parameter('delete_monitor_filter', 0);
if ($get_agent_modules_json_by_name === true) {
$agent_name = get_parameter('agent_name');
@ -1740,6 +1741,29 @@ if (check_login()) {
}
}
if ($delete_monitor_filter) {
$id = get_parameter('id');
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'DELETE
FROM tmonitor_filter
WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$monitor_filters = db_process_sql($sql);
if ($monitor_filters === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($get_monitor_filters) {
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
@ -1760,7 +1784,7 @@ if (check_login()) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
users_can_manage_group_all('AR'),
true
);
@ -1886,7 +1910,7 @@ if (check_login()) {
'',
false,
true
).__('Update filter').'';
).__('Update/delete filter').'';
$table->data[] = $data;
$table->rowclass[] = '';
@ -1904,7 +1928,7 @@ if (check_login()) {
$user_groups_array = users_get_groups_for_select(
$config['id_user'],
'AW',
users_can_manage_group_all(),
users_can_manage_group_all('AW'),
true
);
@ -1954,21 +1978,30 @@ if (check_login()) {
0,
true
);
$data[1] = html_print_submit_button(
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '<div>';
echo '<div id="update_delete_row"><br>';
echo html_print_submit_button(
__('Save filter'),
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
echo html_print_submit_button(
__('Delete filter'),
'delete_filter',
false,
'class="sub delete float-right" onclick="save_delete_filter();"',
true
);
echo '</div>';
echo '<div><br>';
echo html_print_submit_button(
__('Save current filter'),
'save_filter',
false,
'class="sub upd float-right" onclick="save_new_filter();"',
@ -1986,6 +2019,7 @@ if (check_login()) {
$('#save_filter_row1').show();
$('#save_filter_row2').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
// Filter save mode selector
$("[name='filter_mode']").click(function() {
if ($(this).val() == 'new') {
@ -1993,12 +2027,14 @@ if (check_login()) {
$('#save_filter_row2').show();
$('#submit-save_filter').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
}
else {
$('#save_filter_row1').hide();
$('#save_filter_row2').hide();
$('#update_filter_row1').show();
$('#submit-save_filter').hide();
$('#update_delete_row').show();
}
});
$("#save-filter-select").dialog({
@ -2189,6 +2225,69 @@ if (check_login()) {
$('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update);
return false;
}
function save_delete_filter() {
var id_filter_update = $("#overwrite_filter").val();
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/module",
"delete_monitor_filter" : 1,
"id" : $("#overwrite_filter").val(),
},
function (data) {
$(".info_box").hide();
if (data == 'ok') {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_update_filter") {
return true;
}
else
return false;
}).show();
}
else {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
});
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/module",
"get_monitor_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
if (i == id_filter_update) {
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
}
else {
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
}
});
},
"json"
);
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
return false;
}
$(document).ready(function() {
show_save_filter();

@ -519,6 +519,27 @@ function agents_get_agents(
$search_custom = '';
}
if (isset($filter['id_os'])) {
$id_os = $filter['id_os'];
unset($filter['id_os']);
} else {
$id_os = '';
}
if (isset($filter['policies'])) {
$policies = $filter['policies'];
unset($filter['policies']);
} else {
$policies = '';
}
if (isset($filter['other_condition'])) {
$other_condition = $filter['other_condition'];
unset($filter['other_condition']);
} else {
$other_condition = '';
}
if (isset($filter['offset'])) {
$offset = $filter['offset'];
unset($filter['offset']);
@ -692,25 +713,38 @@ function agents_get_agents(
$where_nogroup = '1 = 1';
}
$policy_join = '';
if ($policies !== '') {
$policy_join = 'INNER JOIN tpolicy_agents
ON tpolicy_agents.id_agent=tagente.id_agente';
}
if ($extra) {
$where = sprintf(
'(%s OR (%s)) AND (%s) AND (%s) %s AND %s',
'(%s OR (%s)) AND (%s) AND (%s) %s AND %s %s %s %s',
$sql_extra,
$where,
$where_nogroup,
$status_sql,
$search,
$disabled
$disabled,
$id_os,
$policies,
$other_condition
);
} else {
$where = sprintf(
'%s AND %s AND (%s) %s AND %s %s',
'%s AND %s AND (%s) %s AND %s %s %s %s %s',
$where,
$where_nogroup,
$status_sql,
$search,
$disabled,
$search_custom
$search_custom,
$id_os,
$policies,
$other_condition
);
}
@ -720,9 +754,11 @@ function agents_get_agents(
FROM `%s` tagente
LEFT JOIN tagent_secondary_group
ON tagent_secondary_group.id_agent=tagente.id_agente
%s
WHERE %s %s',
implode(',', $fields),
$table_name,
$policy_join,
$where,
$order
);

@ -36,6 +36,7 @@ require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_modules.php';
enterprise_include_once('include/functions_config_agents.php');
enterprise_include_once('include/functions_policies.php');
check_login();
@ -181,6 +182,9 @@ $offset = (int) get_parameter('offset', 0);
$refr = get_parameter('refr', 0);
$recursion = get_parameter('recursion', 0);
$status = (int) get_parameter('status', -1);
$os = (int) get_parameter('os', 0);
$policies = (array) get_parameter('policies', []);
$ag_custom_fields = (array) get_parameter('ag_custom_fields', []);
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
$agent_a = (bool) check_acl($config['id_user'], 0, 'AR');
@ -189,6 +193,52 @@ $access = ($agent_a === true) ? 'AR' : (($agent_w === true) ? 'AW' : 'AR');
$onheader = [];
$load_filter_id = (int) get_parameter('filter_id', 0);
if ($load_filter_id > 0) {
$user_groups_fl = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all('AR'),
true
);
$sql = sprintf(
'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_filter = %d AND id_group_filter IN (%s)',
$load_filter_id,
implode(',', array_keys($user_groups_fl))
);
$loaded_filter = db_get_row_sql($sql);
}
if ($loaded_filter['id_filter'] > 0) {
$query_filter['id_filter'] = $load_filter_id;
$filter = db_get_row_filter('tagent_filter', $query_filter, false);
if ($filter !== false) {
$group_id = (int) $filter['group_id'];
$recursion = $filter['recursion'];
$status = $filter['status'];
$search = $filter['search'];
$os = $filter['id_os'];
$policies = json_decode($filter['policies'], true);
$search_custom = $filter['search_custom'];
$ag_custom_fields = $filter['ag_custom_fields'];
}
if (is_array($ag_custom_fields) === false) {
$ag_custom_fields = json_decode(io_safe_output($ag_custom_fields), true);
}
if (is_array($policies) === false) {
$policies = json_decode(io_safe_output($policies), true);
}
}
if (check_acl($config['id_user'], 0, 'AW')) {
// Prepare the tab system to the future.
$tab = 'setup';
@ -247,22 +297,47 @@ if (isset($result_delete)) {
echo '<form method="post" action="?sec=view&sec2=operation/agentes/estado_agente&group_id='.$group_id.'">';
echo '<table cellpadding="4" cellspacing="4" class="databox filters bolder mrgn_btn_10px" width="100%">';
//echo '<table cellpadding="4" cellspacing="4" class="databox filters bolder mrgn_btn_10px" width="100%">';
echo '<tr><td class="nowrap w100px padding-right-2-imp">';
//echo '<tr><td class="nowrap w100px padding-right-2-imp">';
echo __('Group').'&nbsp;'.'&nbsp;'.'&nbsp;';
// Start Build Search Form.
//
$table = new StdClass();
$table->width = '100%';
$table->cellspacing = 0;
$table->cellpadding = 0;
$table->class = 'databox filters';
$table->style[0] = 'font-weight: bold;';
$table->style[1] = 'font-weight: bold;';
$table->style[2] = 'font-weight: bold;';
$table->style[3] = 'font-weight: bold;';
$table->style[4] = 'font-weight: bold;';
$table->data[0][0] = __('Group');
$table->data[0][0] .= '<div class="flex flex-row-vcenter w290px"><div class="w200px">';
$groups = users_get_groups(false, $access);
html_print_select_groups(false, $access, true, 'group_id', $group_id, 'this.form.submit()', '', '', false, false, true, '', false);
$table->data[0][0] .= html_print_select_groups(false, $access, true, 'group_id', $group_id, '', '', '', true, false, true, '', false);
echo '</td><td class="nowrap">'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;';
//$table->data[0][1] .= '&nbsp;&nbsp;';
echo __('Recursion').'&nbsp;'.'&nbsp;'.'&nbsp;';
html_print_checkbox('recursion', 1, $recursion, false, false, 'this.form.submit()');
$table->data[0][0] .= '<br>'.__('Recursion').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][0] .= html_print_input(
[
'type' => 'checkbox',
'name' => 'recursion',
'return' => true,
'checked' => $recursion,
'checked' => ($recursion === true || $recursion === 'true' || $recursion === '1') ? 'checked' : false,
'value' => 1,
]
);
echo '</td><td class="nowrap">';
//echo '</td><td class="nowrap">';
$fields = [];
$fields[AGENT_STATUS_NORMAL] = __('Normal');
@ -272,31 +347,125 @@ $fields[AGENT_STATUS_UNKNOWN] = __('Unknown');
$fields[AGENT_STATUS_NOT_NORMAL] = __('Not normal');
$fields[AGENT_STATUS_NOT_INIT] = __('Not init');
echo __('Status').'&nbsp;'.'&nbsp;'.'&nbsp;';
html_print_select($fields, 'status', $status, 'this.form.submit()', __('All'), AGENT_STATUS_ALL, false, false, true, '', false, 'width: 90px;');
$table->data[0][1] = __('Status').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][1] .= html_print_select($fields, 'status', $status, '', __('All'), AGENT_STATUS_ALL, true, false, true, '', false, 'width: 90px;');
echo '</td><td class="nowrap w100px">';
$table->data[0][2] = __('Search').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][2] .= html_print_input_text('search', $search, '', 15, 255, true);
echo __('Search').'&nbsp;'.'&nbsp;'.'&nbsp;';
html_print_input_text('search', $search, '', 15);
$table->data[1][0] = __('Operating System').'&nbsp;';
echo '</td><td class="nowrap w100px">';
$pre_fields = db_get_all_rows_sql(
'select distinct(tagente.id_os),tconfig_os.name from tagente,tconfig_os where tagente.id_os = tconfig_os.id_os'
);
$fields = [];
echo __('Search in custom fields').'&nbsp;'.'&nbsp;'.'&nbsp;';
html_print_input_text('search_custom', $search_custom, '', 15);
foreach ($pre_fields as $key => $value) {
$fields[$value['id_os']] = $value['name'];
}
echo '</td><td class="nowrap">';
$table->data[1][0] .= html_print_select($fields, 'os', $os, '', 'All', 0, true);
html_print_submit_button(
$table->data[1][1] = __('Policies').'&nbsp;';
$pre_fields = policies_get_policies(false, ['id', 'name']);
$fields = [];
foreach ($pre_fields as $value) {
$fields[$value['id']] = $value['name'];
}
$table->data[1][1] .= html_print_select($fields, 'policies[]', $policies, '', 'All', 0, true, true);
$table->data[1][2] = __('Search in custom fields').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[1][2] .= html_print_input_text('search_custom', $search_custom, '', 15, 255, true);
$custom_fields = db_get_all_fields_in_table('tagent_custom_fields');
if ($custom_fields === false) {
$custom_fields = [];
}
$div_custom_fields = '<div class="flex-row">';
foreach ($custom_fields as $custom_field) {
$custom_field_value = '';
if (empty($ag_custom_fields) === false) {
$custom_field_value = $ag_custom_fields[$custom_field['id_field']];
if (empty($custom_field_value) === true) {
$custom_field_value = '';
}
}
$div_custom_fields .= '<div class="div-col">';
$div_custom_fields .= '<div class="div-span">';
$div_custom_fields .= '<span >'.$custom_field['name'].'</span>';
$div_custom_fields .= '</div>';
$div_custom_fields .= '<div class="div-input">';
$div_custom_fields .= html_print_input_text(
'ag_custom_fields['.$custom_field['id_field'].']',
$custom_field_value,
'',
0,
300,
true,
false,
false,
'',
'div-input'
);
$div_custom_fields .= '</div></div>';
}
$table->colspan[2][0] = 7;
$table->cellstyle[2][0] = 'padding-left: 10px;';
$table->data[2][0] = ui_toggle(
$div_custom_fields,
__('Agent custom fields'),
'',
'',
true,
true,
'',
'white-box-content',
'white_table_graph'
);
$table->colspan[4][0] = 4;
$table->cellstyle[4][0] = 'padding-top: 0px;';
$table->data[4][0] = html_print_button(
__('Load filter'),
'load-filter',
false,
'',
'class="float-left margin-right-2 sub config"',
true
);
$table->cellstyle[4][0] .= 'padding-top: 0px;';
$table->data[4][0] .= html_print_button(
__('Manage filter'),
'save-filter',
false,
'',
'class="float-left margin-right-2 sub wand"',
true
);
$table->cellstyle[4][2] = 'padding-top: 0px;';
$table->data[4][2] = html_print_submit_button(
__('Search'),
'srcbutton',
'',
['class' => 'sub search']
['class' => 'sub search'],
true
);
echo '</td>';
html_print_table($table);
echo '</tr></table></form>';
'</form>';
if ($search != '') {
$filter = ['string' => '%'.$search.'%'];
@ -320,6 +489,8 @@ $selectDescriptionUp = false;
$selectDescriptionDown = false;
$selectLastContactUp = false;
$selectLastContactDown = false;
$selectLastStatusChangeUp = false;
$selectLastStatusChangeDown = false;
$order = null;
switch ($sortField) {
@ -479,6 +650,32 @@ switch ($sortField) {
}
break;
case 'last_status_change':
switch ($sort) {
case 'up':
$selectLastStatusChangeUp = $selected;
$order = [
'field' => 'last_status_change',
'field2' => 'alias',
'order' => 'ASC',
];
break;
case 'down':
$selectLastStatusChangeDown = $selected;
$order = [
'field' => 'last_status_change',
'field2' => 'alias',
'order' => 'DESC',
];
break;
default:
// Default.
break;
}
break;
case 'description':
switch ($sort) {
case 'up':
@ -518,6 +715,8 @@ switch ($sortField) {
$selectDescriptionDown = false;
$selectLastContactUp = false;
$selectLastContactDown = false;
$selectLastStatusChangeUp = false;
$selectLastStatusChangeDown = false;
$order = [
'field' => 'alias',
'field2' => 'alias',
@ -577,6 +776,24 @@ if (!empty($search_custom)) {
$search_sql_custom = '';
}
// Filter by agent custom fields.
$sql_conditions_custom_fields = '';
if (empty($ag_custom_fields) === false) {
$cf_filter = [];
foreach ($ag_custom_fields as $field_id => $value) {
if (empty($value) === false) {
$cf_filter[] = '(tagent_custom_data.id_field = '.$field_id.' AND tagent_custom_data.description LIKE \'%'.$value.'%\')';
}
}
if (empty($cf_filter) === false) {
$sql_conditions_custom_fields = ' AND tagente.id_agente IN (
SELECT tagent_custom_data.id_agent
FROM tagent_custom_data
WHERE '.implode(' AND ', $cf_filter).')';
}
}
// Show only selected groups.
if ($group_id > 0) {
$groups = [$group_id];
@ -589,23 +806,41 @@ if ($group_id > 0) {
$groups = array_keys($user_groups);
}
$all_policies = in_array(0, $policies ?? []);
$id_os_sql = '';
$policies_sql = '';
if ($os > 0) {
$id_os_sql = ' AND id_os = '.$os;
}
if ($all_policies === false && is_array($policies) && count($policies) > 0) {
$policies_sql = ' AND tpolicy_agents.id_policy IN ('.implode(',', $policies).')';
}
if ($strict_user) {
$count_filter = [
// 'order' => 'tagente.nombre ASC',
'order' => 'tagente.nombre ASC',
'disabled' => 0,
'status' => $status,
'search' => $search,
'order' => 'tagente.nombre ASC',
'disabled' => 0,
'status' => $status,
'search' => $search,
'id_os' => $id_os_sql,
'policies' => $policies_sql,
'other_condition' => $sql_conditions_custom_fields,
];
$filter = [
// 'order' => 'tagente.nombre ASC',
'order' => 'tagente.nombre ASC',
'disabled' => 0,
'status' => $status,
'search' => $search,
'offset' => (int) get_parameter('offset'),
'limit' => (int) $config['block_size'],
'order' => 'tagente.nombre ASC',
'disabled' => 0,
'status' => $status,
'search' => $search,
'offset' => (int) get_parameter('offset'),
'limit' => (int) $config['block_size'],
'id_os' => $id_os_sql,
'policies' => $policies_sql,
'other_condition' => $sql_conditions_custom_fields,
];
if ($group_id > 0) {
@ -644,28 +879,48 @@ if ($strict_user) {
$agents = tags_get_all_user_agents(false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
} else {
$count_filter = [
'disabled' => 0,
'id_grupo' => $groups,
'search' => $search_sql,
'search_custom' => $search_sql_custom,
'status' => $status,
'id_os' => $id_os_sql,
'policies' => $policies_sql,
'other_condition' => $sql_conditions_custom_fields,
];
$filter = [
'order' => 'nombre ASC',
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
'search_custom' => $search_sql_custom,
'search' => $search_sql,
'offset' => (int) get_parameter('offset'),
'limit' => (int) $config['block_size'],
'id_os' => $id_os_sql,
'policies' => $policies_sql,
'other_condition' => $sql_conditions_custom_fields,
];
$total_agents = agents_count_agents_filter(
[
'disabled' => 0,
'id_grupo' => $groups,
'search' => $search_sql,
'search_custom' => $search_sql_custom,
'status' => $status,
],
$count_filter,
$access
);
$query_order = $order;
if ($order['field'] === 'last_status_change') {
$query_order = [
'field' => 'alias',
'field2' => 'alias',
'order' => 'ASC',
];
}
$agents = agents_get_agents(
[
'order' => 'nombre '.' ASC',
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
'search_custom' => $search_sql_custom,
'search' => $search_sql,
'offset' => (int) get_parameter('offset'),
'limit' => (int) $config['block_size'],
],
$filter,
[
'id_agente',
'id_grupo',
@ -688,7 +943,7 @@ if ($strict_user) {
'agent_version',
],
$access,
$order
$query_order
);
}
@ -720,7 +975,8 @@ $url_up_group = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp
$url_down_group = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp;refr='.$refr.'&amp;offset='.$offset.'&amp;group_id='.$group_id.'&amp;recursion='.$recursion.'&amp;search='.$search.'&amp;status='.$status.'&amp;sort_field=group&amp;sort=down';
$url_up_last = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp;refr='.$refr.'&amp;offset='.$offset.'&amp;group_id='.$group_id.'&amp;recursion='.$recursion.'&amp;search='.$search.'&amp;status='.$status.'&amp;sort_field=last_contact&amp;sort=up';
$url_down_last = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp;refr='.$refr.'&amp;offset='.$offset.'&amp;group_id='.$group_id.'&amp;recursion='.$recursion.'&amp;search='.$search.'&amp;status='.$status.'&amp;sort_field=last_contact&amp;sort=down';
$url_up_last_status_change = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp;refr='.$refr.'&amp;offset='.$offset.'&amp;group_id='.$group_id.'&amp;recursion='.$recursion.'&amp;search='.$search.'&amp;status='.$status.'&amp;sort_field=last_status_change&amp;sort=up';
$url_down_last_status_change = 'index.php?sec=view&amp;sec2=operation/agentes/estado_agente&amp;refr='.$refr.'&amp;offset='.$offset.'&amp;group_id='.$group_id.'&amp;recursion='.$recursion.'&amp;search='.$search.'&amp;status='.$status.'&amp;sort_field=last_status_change&amp;sort=down';
// Prepare pagination.
ui_pagination(
@ -740,16 +996,16 @@ $table->head[0] = __('Agent').ui_get_sorting_arrows($url_up_agente, $url_down_ag
$table->size[0] = '12%';
$table->head[1] = __('Description').ui_get_sorting_arrows($url_up_description, $url_down_description, $selectDescriptionUp, $selectDescriptionDown);
$table->size[1] = '16%';
$table->size[1] = '14%';
$table->head[10] = __('Remote').ui_get_sorting_arrows($url_up_remote, $url_down_remote, $selectRemoteUp, $selectRemoteDown);
$table->size[10] = '9%';
$table->head[12] = __('Remote').ui_get_sorting_arrows($url_up_remote, $url_down_remote, $selectRemoteUp, $selectRemoteDown);
$table->size[12] = '9%';
$table->head[2] = __('OS').ui_get_sorting_arrows($url_up_os, $url_down_os, $selectOsUp, $selectOsDown);
$table->size[2] = '8%';
$table->head[3] = __('Interval').ui_get_sorting_arrows($url_up_interval, $url_down_interval, $selectIntervalUp, $selectIntervalDown);
$table->size[3] = '10%';
$table->size[3] = '8%';
$table->head[4] = __('Group').ui_get_sorting_arrows($url_up_group, $url_down_group, $selectGroupUp, $selectGroupDown);
$table->size[4] = '8%';
@ -767,7 +1023,13 @@ $table->head[8] = __('Alerts');
$table->size[8] = '4%';
$table->head[9] = __('Last contact').ui_get_sorting_arrows($url_up_last, $url_down_last, $selectLastContactUp, $selectLastContactDown);
$table->size[9] = '15%';
$table->size[9] = '8%';
$table->head[10] = __('Last status change').ui_get_sorting_arrows($url_up_last_status_change, $url_down_last_status_change, $selectLastStatusChangeUp, $selectLastStatusChangeDown);
$table->size[10] = '10%';
$table->head[11] = __('Agent events');
$table->size[11] = '4%';
$table->align = [];
@ -779,6 +1041,8 @@ $table->align[6] = 'left';
$table->align[7] = 'left';
$table->align[8] = 'left';
$table->align[9] = 'left';
$table->align[10] = 'left';
$table->align[11] = 'left';
$table->style = [];
@ -881,12 +1145,12 @@ foreach ($agents as $agent) {
$data[1] = '<span class="'.$custom_font_size.'">'.ui_print_truncate_text($agent['description'], 'description', false, true, true, '[&hellip;]').'</span>';
$data[10] = '';
$data[12] = '';
if (enterprise_installed()) {
enterprise_include_once('include/functions_config_agents.php');
if (enterprise_hook('config_agents_has_remote_configuration', [$agent['id_agente']])) {
$data[10] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=remote_configuration&id_agente='.$agent['id_agente'].'&disk_conf=1">'.html_print_image(
$data[12] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=remote_configuration&id_agente='.$agent['id_agente'].'&disk_conf=1">'.html_print_image(
'images/application_edit.png',
true,
[
@ -930,6 +1194,27 @@ foreach ($agents as $agent) {
$data[9] = agents_get_interval_status($agent);
$last_status_change_agent = agents_get_last_status_change($agent['id_agente']);
$time_elapsed = !empty($last_status_change_agent) ? human_time_comparation($last_status_change_agent) : '<em>'.__('N/A').'</em>';
$data[10] = $time_elapsed;
$agent_event_filter = [
'id_agent' => $agent['id_agente'],
'event_view_hr' => 48,
'status' => -1,
];
$fb64 = base64_encode(json_encode($agent_event_filter));
$data[11] = '<a href="index.php?sec=eventos&sec2=operation/events/events&fb64='.$fb64.'">'.html_print_image(
'images/lightning.png',
true,
[
'align' => 'middle',
'title' => __('Agent events'),
'class' => 'invert_filter',
]
).'</a>';
// This old code was returning "never" on agents without modules, BAD !!
// And does not print outdated agents in red. WRONG !!!!
// $data[7] = ui_print_timestamp ($agent_info["last_contact"], true);
@ -937,6 +1222,20 @@ foreach ($agents as $agent) {
}
if (!empty($table->data)) {
if ($order['field'] === 'last_status_change') {
$order_direction = $order['order'];
usort(
$table->data,
function ($a, $b) use ($order_direction) {
if ($order_direction === 'ASC') {
return strtotime($a[10]) > strtotime($b[10]);
} else {
return strtotime($a[10]) < strtotime($b[10]);
}
}
);
}
html_print_table($table);
ui_pagination(
@ -975,10 +1274,69 @@ if (!empty($table->data)) {
echo '</form>';
echo '</div>';
}
// Load filter div for dialog.
echo '<div id="load-modal-filter" style="display:none"></div>';
echo '<div id="save-modal-filter" style="display:none"></div>';
?>
<script type="text/javascript">
$(document).ready (function () {
var loading = 0;
/* Filter management */
$('#button-load-filter').click(function (event) {
if($('#load-filter-select').length) {
$('#load-filter-select').dialog();
} else {
if (loading == 0) {
loading = 1
$.ajax({
method: 'POST',
url: '<?php echo ui_get_full_url('ajax.php'); ?>',
data: {
page: 'include/ajax/agent',
load_filter_modal: 1
},
success: function (data) {
$('#load-modal-filter')
.empty()
.html(data);
loading = 0;
}
});
}
}
});
$('#button-save-filter').click(function (){
// event.preventDefault();
if($('#save-filter-select').length) {
$('#save-filter-select').dialog();
} else {
if (loading == 0) {
loading = 1
$.ajax({
method: 'POST',
url: '<?php echo ui_get_full_url('ajax.php'); ?>',
data: {
page: 'include/ajax/agent',
save_filter_modal: 1,
current_filter: $('#latest_filter_id').val()
},
success: function (data){
$('#save-modal-filter')
.empty()
.html(data);
loading = 0;
}
});
}
}
});
$("[class^='left']").mouseenter (function () {
$(".agent"+$(this)[0].className).css('visibility', '');
}).mouseleave(function () {

@ -227,7 +227,7 @@ if ($load_filter_id > 0) {
$user_groups_fl = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
users_can_manage_group_all('AR'),
true
);
@ -287,6 +287,8 @@ if ($loaded_filter['id_filter'] > 0) {
}
}
$all_groups = [];
// Agent group selector.
if (!$is_metaconsole) {
if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) {
@ -937,7 +939,7 @@ $table->data[4][0] = html_print_button(
$table->cellstyle[4][0] .= 'padding-top: 0px;';
$table->data[4][0] .= html_print_button(
__('Save filter'),
__('Manage filter'),
'save-filter',
false,
'',

@ -4181,6 +4181,23 @@ CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tagent_filter`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tagent_filter` (
`id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_name` VARCHAR(600) NOT NULL,
`id_group_filter` INT NOT NULL DEFAULT 0,
`group_id` INT NOT NULL DEFAULT 0,
`recursion` TEXT,
`status` INT NOT NULL DEFAULT -1,
`search` TEXT,
`id_os` INT NOT NULL DEFAULT 0,
`policies` TEXT,
`search_custom` TEXT,
`ag_custom_fields` TEXT,
PRIMARY KEY (`id_filter`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- Table `tevent_sound`
-- ---------------------------------------------------------------------
CREATE TABLE `tevent_sound` (
@ -4188,4 +4205,4 @@ CREATE TABLE `tevent_sound` (
`name` TEXT NULL,
`sound` TEXT NULL,
`active` TINYINT NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;