Added strict ACL to agent detail view.

This commit is contained in:
Vanessa Gil 2015-01-26 13:50:58 +01:00
parent 2c985653fb
commit 2908f09b01
4 changed files with 159 additions and 52 deletions

View File

@ -1893,6 +1893,8 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
}
}
$list = array();
if ($list_groups == false) {
$list_groups = array();
}

View File

@ -7778,7 +7778,9 @@ function reporting_get_count_events_validated ($filter, $period = 0,
*
* @return string html formatted tiny stats of modules/alerts of an agent
*/
function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':') {
function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) {
global $config;
$out = '';
// Depend the type of object, the stats will refer agents, modules...
@ -7809,6 +7811,28 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $
break;
}
if ($strict_user && $type == 'agent') {
$acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user);
$filter['disabled'] = 0;
$id_agent = $counts_info['id_agente'];
$counts_info = array();
$counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL));
$counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING));
$counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD));
$counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT));
$counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN));
$counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count'];
$all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter);
$mod_clause = "(".implode(',', array_keys($all_agent_modules)).")";
$counts_info['fired_count'] = db_get_sql ("SELECT COUNT(times_fired)
FROM talert_template_modules
WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
}
// Store the counts in a data structure to print hidden divs with titles
$stats = array();

View File

@ -1850,8 +1850,33 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
}
}
$disabled_sql = '';
if (!empty($filter['disabled'])) {
$disabled_sql = " AND disabled = ".$filter['disabled'];
}
$order_by_condition = '';
if (!empty($filter['order'])) {
$order_by_condition = " ORDER BY ".$filter['order'];
} else {
$order_by_condition = " ORDER BY tagente.nombre ASC";
}
$limit_sql = '';
if (isset($filter['offset'])) {
$offset = $filter['offset'];
}
if (isset($filter['limit'])) {
$limit = $filter['limit'];
}
if (isset($offset) && isset($limit)) {
$limit_sql = " LIMIT $offset, $limit ";
}
if (!empty($filter['group_by'])) {
$group_by = " GROUP BY ".$filter['group_by'];
} else {
$group_by = " GROUP BY tagente.nombre";
}
$id_agent_search = '';
@ -1874,6 +1899,16 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
}
}
//~ $user_agents_sql = "SELECT ".$select_fields ."
//~ FROM tagente, tagente_modulo, ttag_module
//~ WHERE tagente.id_agente = tagente_modulo.id_agente
//~ AND tagente_modulo.id_agente_modulo = ttag_module.id_agente_modulo
//~ ". $tag_filter .
//~ $groups_clause . $search_sql . $void_agents .
//~ $status_sql .
//~ $group_by .
//~ " ORDER BY tagente.nombre ASC";
$user_agents_sql = "SELECT ".$select_fields ."
FROM tagente, tagente_modulo, ttag_module
WHERE tagente.id_agente = tagente_modulo.id_agente
@ -1881,10 +1916,11 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
". $tag_filter .
$groups_clause . $search_sql . $void_agents .
$status_sql .
$disabled_sql .
$group_by .
" ORDER BY tagente.nombre ASC";
$order_by_condition .
$limit_sql;
//return db_get_sql ($user_agents);
$user_agents = db_get_all_rows_sql($user_agents_sql);
if ($user_agents == false) {
@ -1904,7 +1940,7 @@ function tags_get_all_user_agents ($id_tag = false, $id_user = false, $groups_an
return $user_agents;
}
function tags_get_agent_modules ($id_agent, $groups_and_tags = array(), $fields = false, $filter = false, $return_all_fields = false) {
function tags_get_agent_modules ($id_agent, $groups_and_tags = array(), $fields = false, $filter = false, $return_all_fields = false, $get_filter_status = -1) {
global $config;
@ -1914,18 +1950,18 @@ function tags_get_agent_modules ($id_agent, $groups_and_tags = array(), $fields
if (!is_array ($fields)) {
$fields = array ();
$fields[0] = "id_agente_modulo";
$fields[1] = "nombre";
$fields[0] = "tagente_modulo.id_agente_modulo";
$fields[1] = "tagente_modulo.nombre";
}
$select_fields = implode(',',$fields);
if ($filter) {
$filter_sql = '';
if (isset($filter['disabled'])) {
$filter_sql .= " AND disabled = ".$filter['disabled'];
$filter_sql .= " AND tagente_modulo.disabled = ".$filter['disabled'];
}
if (isset($filter['nombre'])) {
$filter_sql .= ' AND nombre LIKE "' .$filter['nombre'].'"';
$filter_sql .= ' AND tagente_modulo.nombre LIKE "' .$filter['nombre'].'"';
}
}
@ -1935,16 +1971,28 @@ function tags_get_agent_modules ($id_agent, $groups_and_tags = array(), $fields
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if (isset($groups_and_tags[$agent_group]) && ($groups_and_tags[$agent_group] != '')) {
//~ $tag_filter = " AND ttag_module.id_tag IN (".$groups_and_tags[$agent_group].")";
$tag_filter = " AND id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (".$groups_and_tags[$agent_group]."))";
$tag_filter = " AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM ttag_module WHERE id_tag IN (".$groups_and_tags[$agent_group]."))";
}
}
$agent_modules_sql = "SELECT ".$select_fields ."
FROM tagente_modulo
WHERE id_agente=". $id_agent .
$tag_filter .
$filter_sql ."
ORDER BY nombre";
if ($get_filter_status != -1) {
$agent_modules_sql = "SELECT ".$select_fields ."
FROM tagente_modulo, tagente_estado
WHERE tagente_modulo.id_agente=". $id_agent .
" AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_estado.estado = ".$get_filter_status .
$tag_filter .
$filter_sql ."
ORDER BY nombre";
} else {
$agent_modules_sql = "SELECT ".$select_fields ."
FROM tagente_modulo
WHERE id_agente=". $id_agent .
$tag_filter .
$filter_sql ."
ORDER BY nombre";
}
$agent_modules = db_get_all_rows_sql($agent_modules_sql);

View File

@ -119,6 +119,8 @@ $refr = get_parameter('refr', 0);
$recursion = get_parameter('recursion', 0);
$status = (int) get_parameter ('status', -1);
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
$onheader = array();
if (check_acl ($config['id_user'], 0, "AW")) {
@ -139,8 +141,10 @@ if (check_acl ($config['id_user'], 0, "AW")) {
ui_print_page_header ( __("Agent detail"), "images/agent_mc.png", false, "agent_status", false, $onheader);
if (tags_has_user_acl_tags()) {
ui_print_tags_warning();
if (!$strict_user) {
if (tags_has_user_acl_tags()) {
ui_print_tags_warning();
}
}
// User is deleting agent
@ -342,43 +346,72 @@ else {
$groups = array_keys($user_groups);
}
$total_agents = 0;
$agents = false;
$total_agents = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $groups,
'search' => $search_sql,
'status' => $status),
array ('COUNT(*) as total'), 'AR', false);
$total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0;
if ($strict_user) {
$agents = agents_get_agents(array (
'order' => 'nombre ' . $order_collation . ' ASC',
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
'search' => $search_sql,
'offset' => (int) get_parameter ('offset'),
'limit' => (int) $config['block_size'] ),
$filter = array (
'order' => 'tagente.nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'status' => $status,
'search' => $search,
'offset' => (int) get_parameter ('offset'),
'limit' => (int) $config['block_size']);
if ($group_id > 0) {
$groups = array($group_id);
if ($recursion) {
$groups = groups_get_id_recursive($group_id, true);
}
$filter['id_group'] = implode(',', $groups);
}
$fields = array ('tagente.id_agente','tagente.id_grupo','tagente.id_os','tagente.ultimo_contacto','tagente.intervalo','tagente.comentarios description','tagente.quiet',
'tagente.normal_count','tagente.warning_count','tagente.critical_count','tagente.unknown_count','tagente.notinit_count','tagente.total_count','tagente.fired_count');
$acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user);
$agents = tags_get_all_user_agents (false, $config['id_user'], $acltags, $filter, $fields, false, $strict_user, true);
array ('id_agente',
'id_grupo',
'id_os',
'ultimo_contacto',
'intervalo',
'comentarios description',
'quiet',
'normal_count',
'warning_count',
'critical_count',
'unknown_count',
'notinit_count',
'total_count',
'fired_count'),
'AR',
$order);
$total_agents = count($agents);
} else {
$total_agents = 0;
$agents = false;
$total_agents = agents_get_agents(array (
'disabled' => 0,
'id_grupo' => $groups,
'search' => $search_sql,
'status' => $status),
array ('COUNT(*) as total'), 'AR', false);
$total_agents = isset ($total_agents[0]['total']) ? $total_agents[0]['total'] : 0;
$agents = agents_get_agents(array (
'order' => 'nombre ' . $order_collation . ' ASC',
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
'search' => $search_sql,
'offset' => (int) get_parameter ('offset'),
'limit' => (int) $config['block_size'] ),
array ('id_agente',
'id_grupo',
'id_os',
'ultimo_contacto',
'intervalo',
'comentarios description',
'quiet',
'normal_count',
'warning_count',
'critical_count',
'unknown_count',
'notinit_count',
'total_count',
'fired_count'),
'AR',
$order);
}
if (empty ($agents)) {
$agents = array ();
@ -472,7 +505,7 @@ foreach ($agents as $agent) {
$data[4] = ui_print_group_icon ($agent["id_grupo"], true);
$data[5] = reporting_tiny_stats($agent, true);
$data[5] = reporting_tiny_stats($agent, true, 'agent', ':', $strict_user);
$data[6] = $status_img;