Updated tags optimization
This commit is contained in:
parent
f3eae5e111
commit
e8621e54e5
|
@ -30,28 +30,19 @@ if (is_ajax()) {
|
|||
require_once ('include/functions_tags.php');
|
||||
|
||||
$limit = (int) get_parameter("limit", 5);
|
||||
// TODO revision tag
|
||||
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
|
||||
$filter = "estado<>1 $tags_condition";
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
case "postgresql":
|
||||
$sql = sprintf ("SELECT id_agente, evento, utimestamp
|
||||
FROM tevento
|
||||
WHERE %s
|
||||
ORDER BY utimestamp DESC LIMIT %d",
|
||||
$filter, $limit);
|
||||
break;
|
||||
case "oracle":
|
||||
$sql = sprintf ("SELECT *
|
||||
FROM tevento
|
||||
WHERE %s
|
||||
AND rownum <= %d
|
||||
ORDER BY utimestamp DESC",
|
||||
$filter, $limit);
|
||||
break;
|
||||
}
|
||||
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
|
||||
|
||||
$filter = "estado <> 1 $tags_condition";
|
||||
|
||||
$sql = sprintf ("SELECT id_agente, evento, utimestamp
|
||||
FROM tevento
|
||||
LEFT JOIN tagent_secondary_group
|
||||
ON tevento.id_agente = tagent_secondary_group.id_agent
|
||||
WHERE %s
|
||||
ORDER BY utimestamp DESC LIMIT %d",
|
||||
$filter, $limit);
|
||||
|
||||
$result = db_get_all_rows_sql ($sql);
|
||||
|
||||
$events = array();
|
||||
|
|
|
@ -455,8 +455,6 @@ $search_string_entities = io_safe_input($search_string);
|
|||
$basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities);
|
||||
|
||||
// Tags acl
|
||||
$tags_join = "";
|
||||
$tags_condition = "";
|
||||
$agent_tags = tags_get_user_applied_agent_tags($id_agente);
|
||||
if ($agent_tags !== true) {
|
||||
$where_tags = " AND ttag_module.id_tag IN (" . implode(',', $agent_tags) . ")";
|
||||
|
|
|
@ -555,7 +555,7 @@ if ($table_events) {
|
|||
|
||||
// Fix: for tag functionality groups have to be all user_groups (propagate ACL funct!)
|
||||
$groups = users_get_groups($config["id_user"]);
|
||||
// TODO revision tag
|
||||
|
||||
$tags_condition = tags_get_acl_tags($config['id_user'],
|
||||
array_keys($groups), 'ER', 'event_condition', 'AND');
|
||||
echo '<div id="div_all_events_24h">';
|
||||
|
|
|
@ -1810,24 +1810,6 @@ function get_group_alerts($id_group, $filter = '', $options = false,
|
|||
FROM tagente_modulo WHERE delete_pending = 0';
|
||||
}
|
||||
|
||||
if ($strict_user) {
|
||||
$groups = users_get_groups($config["id_user"]);
|
||||
|
||||
if ($idGroup !== 0) {
|
||||
// TODO revision tag
|
||||
$where_tags = tags_get_acl_tags($config['id_user'], $idGroup, 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
|
||||
} else {
|
||||
$where_tags = tags_get_acl_tags($config['id_user'], array_keys($groups), 'AR', 'module_condition', 'AND', 'tagente_modulo', true, array(), true);
|
||||
}
|
||||
|
||||
// If there are any errors add imposible condition
|
||||
if (in_array($where_tags, array(ERR_WRONG_PARAMETERS, ERR_ACL))) {
|
||||
$subQuery .= ' AND 1 = 0';
|
||||
}
|
||||
else {
|
||||
$subQuery .= $where_tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($allModules)
|
||||
|
|
|
@ -3554,7 +3554,6 @@ function events_sql_events_grouped_agents($id_agent, $server_id = -1,
|
|||
else {
|
||||
$group_array = array_keys($groups);
|
||||
}
|
||||
// TODO revision tag
|
||||
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
|
||||
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
||||
|
||||
|
@ -3600,6 +3599,8 @@ function events_list_events_grouped_agents($sql) {
|
|||
$table = events_get_events_table(is_metaconsole(), $history);
|
||||
|
||||
$sql = "select * from $table
|
||||
LEFT JOIN tagent_secondary_group
|
||||
ON tagent_secondary_group.id_agent = tevento.id_agente
|
||||
WHERE $sql";
|
||||
|
||||
$result = db_get_all_rows_sql ($sql);
|
||||
|
|
|
@ -988,7 +988,6 @@ function tags_get_user_tags($id_user = false, $access = 'AR', $return_tag_any =
|
|||
}
|
||||
|
||||
// Get the tags of the required access flag for each group
|
||||
// TODO revision tag
|
||||
$tags = tags_get_acl_tags($id_user, 0, $access, 'data');
|
||||
// If there are wrong parameters or fail ACL check, return false
|
||||
if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) {
|
||||
|
@ -1076,8 +1075,7 @@ function tags_get_tags_for_module_search($id_user = false, $access = 'AR') {
|
|||
//--------------------------------------------------------------
|
||||
return false;
|
||||
}
|
||||
// Get the tags of the required access flag for each group
|
||||
// TODO revision tag
|
||||
// Get the tags of the required access flag for each group
|
||||
$tags = tags_get_acl_tags($id_user, 0, $access, 'data');
|
||||
// If there are wrong parameters or fail ACL check, return false
|
||||
if ($tags_user === ERR_WRONG_PARAMETERS || $tags_user === ERR_ACL) {
|
||||
|
@ -1161,7 +1159,7 @@ function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_
|
|||
$id_group[] = $parent['id_grupo'];
|
||||
}
|
||||
}
|
||||
// TODO revision tag
|
||||
|
||||
$acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
|
||||
|
||||
// If there are wrong parameters or fail ACL check, return false
|
||||
|
@ -1261,106 +1259,6 @@ function tags_check_acl($id_user, $id_group, $access, $tags = array(), $flag_id_
|
|||
return false;
|
||||
}
|
||||
|
||||
function tags_check_acl_event($id_user, $id_group, $access, $tags = array(),$p = false) {
|
||||
global $config;
|
||||
|
||||
if($id_user === false) {
|
||||
$id_user = $config['id_user'];
|
||||
}
|
||||
// TODO revision tag
|
||||
$acls = tags_get_acl_tags($id_user, $id_group, $access, 'data');
|
||||
|
||||
// If there are wrong parameters or fail ACL check, return false
|
||||
if($acls === ERR_WRONG_PARAMETERS || $acls === ERR_ACL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there are not tags restrictions or tags passed, check the group access
|
||||
if (empty($acls) || empty($tags)) {
|
||||
if (!is_array($id_group))
|
||||
$group_id_array = array($id_group);
|
||||
|
||||
foreach ($id_group as $group) {
|
||||
if (check_acl($id_user, $group, $access))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
# Fix: If user profile has more than one group, due to ACL propagation then id_group can be an array
|
||||
if (is_array($id_group)) {
|
||||
|
||||
foreach ($id_group as $group) {
|
||||
if ($group > 0) {
|
||||
if (isset($acls[$group])) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = tags_get_id($tag);
|
||||
if (in_array($tag, $acls[$group])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//return false;
|
||||
$return = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($acls as $acl_tags) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = tags_get_id($tag);
|
||||
if (in_array($tag, $acl_tags)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
if ($id_group > 0) {
|
||||
if (isset($acls[$id_group])) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = tags_get_id($tag);
|
||||
|
||||
if (in_array($tag, $acls[$id_group])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//return false;
|
||||
$return = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($acls as $acl_tags) {
|
||||
foreach ($tags as $tag) {
|
||||
$tag = tags_get_id($tag);
|
||||
if (in_array($tag, $acl_tags)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//return false;
|
||||
$return = false;
|
||||
|
||||
if ($return == false) {
|
||||
$parent = db_get_value('parent','tgrupo','id_grupo',$id_group);
|
||||
|
||||
if ($parent !== 0) {
|
||||
$propagate = db_get_value('propagate','tgrupo','id_grupo',$parent);
|
||||
if ($propagate == 1) {
|
||||
$acl_parent = tags_check_acl_event($id_user, $parent, $access, $tags,$p);
|
||||
return $acl_parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This function checks event ACLs */
|
||||
function tags_checks_event_acl($id_user, $id_group, $access, $tags = array(), $childrens_ids = array()) {
|
||||
global $config;
|
||||
|
|
|
@ -540,7 +540,6 @@ function show_events_group_agent (id_insert, id_agent, server_id) {
|
|||
data: parameter,
|
||||
dataType: 'html',
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
$("#"+id_insert).html(data);
|
||||
$("#"+id_insert).toggle();
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ if (!empty($network_interfaces)) {
|
|||
else {
|
||||
$group_array = $user_groups_ids;
|
||||
}
|
||||
// TODO revision tag
|
||||
|
||||
$acl_tags = tags_get_acl_tags($config['id_user'], $group_array, 'ER',
|
||||
'event_condition', 'AND', '', true, array(), true);
|
||||
|
||||
|
|
|
@ -178,7 +178,6 @@ echo '<td style="vertical-align: top; width: 75%; padding-top: 0px;" id="rightco
|
|||
// ---------------------------------------------------------------------
|
||||
|
||||
if (check_acl($config['id_user'],0,'ER')) {
|
||||
// TODO event tag revision
|
||||
$tags_condition = tags_get_acl_tags(false,0,'ER','event_condition');
|
||||
$event_filter = "estado<>1";
|
||||
if (!empty($tags_condition)) {
|
||||
|
|
|
@ -310,7 +310,7 @@ if ($id_group > 0 && in_array ($id_group, array_keys ($groups))) {
|
|||
else {
|
||||
$group_array = array_keys($groups);
|
||||
}
|
||||
// TODO revision tag
|
||||
|
||||
if (check_acl ($id_user, 0, "ER"))
|
||||
$tags_acls_condition = tags_get_acl_tags($id_user, $group_array, 'ER',
|
||||
'event_condition', 'AND', '', $meta, array(), true); //FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
||||
|
|
Loading…
Reference in New Issue