mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 17:25:26 +02:00
[Tags performance] Events improvements
This commit is contained in:
parent
debf8db577
commit
9a47d5325e
@ -818,8 +818,9 @@ function agents_get_group_agents (
|
|||||||
$filter = array();
|
$filter = array();
|
||||||
|
|
||||||
if (!$noACL) {
|
if (!$noACL) {
|
||||||
$id_group = 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)) {
|
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 array ();
|
return array ();
|
||||||
@ -1054,7 +1055,8 @@ function agents_get_modules ($id_agent = null, $details = false,
|
|||||||
if (empty($userGroups)) {
|
if (empty($userGroups)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$id_userGroups = $id_groups = array_keys($userGroups);
|
$id_groups = array_keys($userGroups);
|
||||||
|
$id_groups_sql = implode(',', $id_groups);
|
||||||
|
|
||||||
// =================================================================
|
// =================================================================
|
||||||
// When there is not a agent id. Get a agents of groups that the
|
// When there is not a agent id. Get a agents of groups that the
|
||||||
@ -1085,48 +1087,24 @@ function agents_get_modules ($id_agent = null, $details = false,
|
|||||||
$id_agent = safe_int ($id_agent, 1);
|
$id_agent = safe_int ($id_agent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = "(
|
$where = "1 = 1 ";
|
||||||
1 = (
|
// Groups ACL only when user is not empty
|
||||||
SELECT is_admin
|
if (!users_can_manage_group_all("AR")) {
|
||||||
FROM tusuario
|
$where = "(
|
||||||
WHERE id_user = '" . $config['id_user'] . "'
|
tagente.id_grupo IN ($id_groups_sql) OR tasg.id_group IN ($id_groups_sql)
|
||||||
)
|
|
||||||
OR
|
|
||||||
tagente_modulo.id_agente IN (
|
|
||||||
SELECT id_agente
|
|
||||||
FROM tagente tas LEFT JOIN tagent_secondary_group tasgs
|
|
||||||
ON tas.id_agente = tasgs.id_agent
|
|
||||||
WHERE (tas.id_grupo IN (
|
|
||||||
" . implode(',', $id_userGroups) . "
|
|
||||||
) OR
|
|
||||||
tasgs.id_group IN (
|
|
||||||
" . implode(',', $id_userGroups) . "
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
OR 0 IN (
|
|
||||||
SELECT id_grupo
|
|
||||||
FROM tusuario_perfil
|
|
||||||
WHERE id_usuario = '" . $config['id_user'] . "'
|
|
||||||
AND id_perfil IN (
|
|
||||||
SELECT id_perfil
|
|
||||||
FROM tperfil WHERE agent_view = 1
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
if (! empty ($id_agent)) {
|
|
||||||
$where .= sprintf (' AND id_agente IN (%s)', implode (",", (array) $id_agent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$where .= ' AND delete_pending = 0 ';
|
if (! empty ($id_agent)) {
|
||||||
|
$id_agent_sql = implode (",", (array)$id_agent);
|
||||||
|
$where .= " AND tagente.id_agente IN ($id_agent_sql) ";
|
||||||
|
}
|
||||||
|
|
||||||
if (! empty ($filter)) {
|
if (! empty ($filter)) {
|
||||||
$where .= ' AND ';
|
$where .= ' AND ';
|
||||||
if (is_array ($filter)) {
|
if (is_array ($filter)) {
|
||||||
$fields = array ();
|
$fields = array ();
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
// Code for filters as array of arrays
|
// Code for filters as array of arrays
|
||||||
// for example:
|
// for example:
|
||||||
@ -1151,7 +1129,6 @@ function agents_get_modules ($id_agent = null, $details = false,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
|
||||||
foreach ($list_filter as $item) {
|
foreach ($list_filter as $item) {
|
||||||
$field = $item['field'];
|
$field = $item['field'];
|
||||||
$value = $item['value'];
|
$value = $item['value'];
|
||||||
@ -1165,62 +1142,23 @@ function agents_get_modules ($id_agent = null, $details = false,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($value[0] == '%') {
|
if ($value[0] == '%') {
|
||||||
switch ($config['dbtype']) {
|
array_push ($fields,
|
||||||
case "mysql":
|
$field . ' LIKE "' . $value . '"');
|
||||||
case "postgresql":
|
|
||||||
array_push ($fields,
|
|
||||||
$field . ' LIKE "' . $value . '"');
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
array_push ($fields,
|
|
||||||
$field . ' LIKE \'' . $value . '\'');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ($operatorDistin) {
|
else if ($operatorDistin) {
|
||||||
array_push($fields, $field.' <> ' . substr($value, 2));
|
array_push($fields, $field.' <> ' . substr($value, 2));
|
||||||
}
|
}
|
||||||
else if (substr($value, -1) == '%') {
|
else if (substr($value, -1) == '%') {
|
||||||
switch ($config['dbtype']) {
|
array_push ($fields, $field.' LIKE "'.$value.'"');
|
||||||
case "mysql":
|
|
||||||
case "postgresql":
|
|
||||||
array_push ($fields, $field.' LIKE "'.$value.'"');
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
array_push ($fields, $field.' LIKE \''.$value.'\'');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//else if (strstr($value, '666=666', true) == '') {
|
|
||||||
else if (strncmp($value, '666=666', 7) == 0) {
|
else if (strncmp($value, '666=666', 7) == 0) {
|
||||||
switch ($config['dbtype']) {
|
array_push ($fields, ' '.$value);
|
||||||
case "mysql":
|
|
||||||
case "postgresql":
|
|
||||||
array_push ($fields, ' '.$value);
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
array_push ($fields, ' '.$value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (preg_match('/\bin\b/i',$field)) {
|
else if (preg_match('/\bin\b/i',$field)) {
|
||||||
array_push ($fields, $field.' '.$value);
|
array_push ($fields, $field.' '.$value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch ($config["dbtype"]) {
|
array_push ($fields, 'tagente_modulo.' . $field.' = "'.$value.'"');
|
||||||
case "mysql":
|
|
||||||
array_push ($fields, $field.' = "'.$value.'"');
|
|
||||||
break;
|
|
||||||
case "postgresql":
|
|
||||||
array_push ($fields, $field.' = \''.$value.'\'');
|
|
||||||
break;
|
|
||||||
case "oracle":
|
|
||||||
if (is_int ($value) || is_float ($value) || is_double ($value))
|
|
||||||
array_push ($fields, $field.' = '.$value.'');
|
|
||||||
else
|
|
||||||
array_push ($fields, $field.' = \''.$value.'\'');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$where .= implode (' AND ', $fields);
|
$where .= implode (' AND ', $fields);
|
||||||
@ -1231,36 +1169,41 @@ function agents_get_modules ($id_agent = null, $details = false,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty ($details)) {
|
if (empty ($details)) {
|
||||||
$details = "nombre";
|
$details = "tagente_modulo.nombre";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
$details = (array)$details;
|
||||||
$details = io_safe_input ($details);
|
$details = io_safe_input ($details);
|
||||||
|
$details = array_map(function ($a) { return 'tagente_modulo.' . $a;}, $details);
|
||||||
}
|
}
|
||||||
|
|
||||||
//$where .= " AND id_policy_module = 0 ";
|
$sql_tags_join = "";
|
||||||
|
|
||||||
if (tags_has_user_acl_tags($config['id_user'])){
|
if (tags_has_user_acl_tags($config['id_user'])){
|
||||||
// TODO revision tag
|
|
||||||
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
|
$where_tags = tags_get_acl_tags($config['id_user'], $id_groups, 'AR',
|
||||||
'module_condition', 'AND', 'tagente_modulo', false, array(),
|
'module_condition', 'AND', 'tagente_modulo', false, array(),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
$where .= "\n\n" . $where_tags;
|
$where .= "\n\n" . $where_tags;
|
||||||
|
$sql_tags_join = "INNER JOIN ttag_module
|
||||||
|
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = sprintf ('SELECT %s%s
|
$sql = sprintf ('SELECT %s%s
|
||||||
FROM tagente_modulo
|
FROM tagente_modulo
|
||||||
WHERE
|
%s
|
||||||
%s
|
INNER JOIN tagente
|
||||||
ORDER BY nombre',
|
ON tagente.id_agente = tagente_modulo.id_agente
|
||||||
($details != '*' && $indexed) ? 'id_agente_modulo,' : '',
|
LEFT JOIN tagent_secondary_group tasg
|
||||||
|
ON tagente.id_agente = tasg.id_agent
|
||||||
|
WHERE tagente_modulo.delete_pending = 0
|
||||||
|
AND %s
|
||||||
|
GROUP BY tagente_modulo.id_agente_modulo
|
||||||
|
ORDER BY tagente_modulo.nombre',
|
||||||
|
($details != 'tagente_modulo.*' && $indexed) ? 'tagente_modulo.id_agente_modulo,' : '',
|
||||||
io_safe_output(implode (",", (array) $details)),
|
io_safe_output(implode (",", (array) $details)),
|
||||||
|
$sql_tags_join,
|
||||||
$where);
|
$where);
|
||||||
|
|
||||||
|
|
||||||
$result = db_get_all_rows_sql ($sql);
|
$result = db_get_all_rows_sql ($sql);
|
||||||
|
|
||||||
|
|
||||||
if (empty ($result)) {
|
if (empty ($result)) {
|
||||||
return array ();
|
return array ();
|
||||||
}
|
}
|
||||||
@ -2589,74 +2532,66 @@ function agents_get_agent_custom_field ($agent_id, $custom_field_name) {
|
|||||||
return db_get_value_sql($sql);
|
return db_get_value_sql($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
function select_modules_for_agent_group($id_group, $id_agents,
|
function select_modules_for_agent_group(
|
||||||
$selection, $return = true) {
|
$id_group, $id_agents, $selection, $return = true
|
||||||
|
) {
|
||||||
|
global $config;
|
||||||
$agents = implode(",", $id_agents);
|
$agents = implode(",", $id_agents);
|
||||||
|
|
||||||
|
$filter_agent_group = "";
|
||||||
$filter_group = "";
|
$filter_group = "";
|
||||||
$filter_agent = "";
|
$filter_agent = "";
|
||||||
|
$selection_filter = "";
|
||||||
|
$sql_conditions_tags = "";
|
||||||
|
$sql_tags_inner = "";
|
||||||
|
|
||||||
|
$groups = array_keys(users_get_groups(false, "AR", false));
|
||||||
|
|
||||||
if ($id_group != 0) {
|
if ($id_group != 0) {
|
||||||
$filter_group = " AND id_module_group = ". $id_group;
|
$filter_group = " AND tagente_modulo.id_module_group = ". $id_group;
|
||||||
}
|
}
|
||||||
if ($agents != null) {
|
if ($agents != null) {
|
||||||
$filter_agent = " AND id_agente IN (" . $agents . ")";
|
$filter_agent = " AND tagente.id_agente IN (" . $agents . ")";
|
||||||
|
}
|
||||||
|
if (!users_can_manage_group_all("AR")) {
|
||||||
|
$group_string = implode(',', $groups);
|
||||||
|
$filter_agent_group = " AND (
|
||||||
|
tagente.id_grupo IN ($group_string)
|
||||||
|
OR tasg.id_group IN ($group_string)
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
if (!$selection && $agents != null) {
|
||||||
|
$number_agents = count($id_agents);
|
||||||
|
$selection_filter = "HAVING COUNT(tagente_modulo.id_agente_modulo) = $number_agents";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($selection == 1 || (count($id_agents) == 1)) {
|
if (tags_has_user_acl_tags(false)){
|
||||||
$modules = db_get_all_rows_sql("SELECT DISTINCT nombre, id_agente_modulo
|
$sql_conditions_tags = tags_get_acl_tags(
|
||||||
FROM tagente_modulo
|
$config['id_user'], $groups, 'AR',
|
||||||
WHERE 1 = 1" . $filter_agent . $filter_group);
|
'module_condition', 'AND', 'tagente_modulo', true, array(),
|
||||||
|
false);
|
||||||
if (empty($modules)) $modules = array();
|
$sql_tags_inner = "INNER JOIN ttag_module
|
||||||
|
ON ttag_module.id_agente_modulo = tagente_modulo.id_agente_modulo";
|
||||||
$found = array();
|
|
||||||
foreach ($modules as $i=>$row) {
|
|
||||||
$check = $row['nombre'];
|
|
||||||
if (@$found[$check]++) {
|
|
||||||
unset($modules[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$modules = db_get_all_rows_sql("SELECT nombre, id_agente_modulo
|
|
||||||
FROM tagente_modulo
|
|
||||||
WHERE 1 = 1" . $filter_agent . $filter_group);
|
|
||||||
|
|
||||||
if (empty($modules)) $modules = array();
|
$sql = "SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre
|
||||||
|
FROM tagente_modulo
|
||||||
|
$sql_tags_inner
|
||||||
|
INNER JOIN tagente
|
||||||
|
ON tagente.id_agente = tagente_modulo.id_agente
|
||||||
|
LEFT JOIN tagent_secondary_group tasg
|
||||||
|
ON tagente.id_agente = tasg.id_agent
|
||||||
|
WHERE tagente.disabled = 0
|
||||||
|
AND tagente_modulo.disabled = 0
|
||||||
|
$filter_agent_group
|
||||||
|
$filter_group
|
||||||
|
$filter_agent
|
||||||
|
$sql_conditions_tags
|
||||||
|
GROUP BY tagente_modulo.nombre
|
||||||
|
$selection_filter";
|
||||||
|
|
||||||
foreach ($modules as $m) {
|
$modules = db_get_all_rows_sql($sql);
|
||||||
$is_in_all_agents = true;
|
if ($modules === false) $modules = array();
|
||||||
$module_name = $m['nombre'];
|
|
||||||
foreach ($id_agents as $a) {
|
|
||||||
$module_in_agent = db_get_value_filter('id_agente_modulo',
|
|
||||||
'tagente_modulo', array('id_agente' => $a, 'nombre' => $module_name));
|
|
||||||
if (!$module_in_agent) {
|
|
||||||
$is_in_all_agents = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($is_in_all_agents) {
|
|
||||||
$modules_to_report[] = $m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$modules = $modules_to_report;
|
|
||||||
|
|
||||||
$found = array();
|
|
||||||
if (is_array($modules) || is_object($modules)){
|
|
||||||
foreach ($modules as $i=>$row) {
|
|
||||||
$check = $row['nombre'];
|
|
||||||
if (@$found[$check]++) {
|
|
||||||
unset($modules[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_array($modules) || is_object($modules)){
|
|
||||||
foreach ($modules as $k => $v) {
|
|
||||||
$modules[$k] = io_safe_output($v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($return == false){
|
if($return == false){
|
||||||
foreach ($modules as $value) {
|
foreach ($modules as $value) {
|
||||||
|
@ -690,7 +690,7 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR',
|
|||||||
case 'module_condition':
|
case 'module_condition':
|
||||||
// Return the condition of the tags for tagente_modulo table
|
// Return the condition of the tags for tagente_modulo table
|
||||||
|
|
||||||
$condition = tags_get_acl_tags_module_condition_old($acltags,
|
$condition = tags_get_acl_tags_module_condition($acltags,
|
||||||
$query_table);
|
$query_table);
|
||||||
if (!empty($condition)) {
|
if (!empty($condition)) {
|
||||||
return " $query_prefix " . $condition;
|
return " $query_prefix " . $condition;
|
||||||
@ -698,7 +698,6 @@ function tags_get_acl_tags($id_user, $id_group, $access = 'AR',
|
|||||||
break;
|
break;
|
||||||
case 'event_condition':
|
case 'event_condition':
|
||||||
// Return the condition of the tags for tevento table
|
// Return the condition of the tags for tevento table
|
||||||
// TODO event tag revision
|
|
||||||
$condition = tags_get_acl_tags_event_condition($acltags, $meta, $force_group_and_tag);
|
$condition = tags_get_acl_tags_event_condition($acltags, $meta, $force_group_and_tag);
|
||||||
|
|
||||||
if (!empty($condition)) {
|
if (!empty($condition)) {
|
||||||
@ -868,16 +867,20 @@ function tags_get_acl_tags_event_condition($acltags, $meta = false, $force_group
|
|||||||
$tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
|
$tags_condition = $group_condition . " AND (" . implode(" OR ", $tags_condition_array) . ")";
|
||||||
$condition[] = "($tags_condition)\n";
|
$condition[] = "($tags_condition)\n";
|
||||||
}
|
}
|
||||||
if (empty($condition)) {
|
if (!empty($condition)) {
|
||||||
return " 1=1 ";
|
$condition = implode(' OR ', $condition);
|
||||||
}
|
}
|
||||||
$condition = implode(' OR ', $condition);
|
|
||||||
|
|
||||||
if (!empty($without_tags)) {
|
if (!empty($without_tags)) {
|
||||||
$condition .= ' OR ';
|
if (!empty($condition)) {
|
||||||
|
$condition .= ' OR ';
|
||||||
|
}
|
||||||
$in_group = implode(",",$without_tags);
|
$in_group = implode(",",$without_tags);
|
||||||
$condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
|
$condition .= sprintf('(id_grupo IN (%s) OR id_group IN (%s))',$in_group,$in_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$condition = !empty($condition) ? "($condition)" : '';
|
||||||
|
|
||||||
return $condition;
|
return $condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -899,11 +902,10 @@ function tags_has_user_acl_tags($id_user = false) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = sprintf("SELECT count(*)
|
$query = "SELECT count(*)
|
||||||
FROM tusuario_perfil, tperfil
|
FROM tusuario_perfil
|
||||||
WHERE tperfil.id_perfil = tusuario_perfil.id_perfil AND
|
WHERE tusuario_perfil.id_usuario = '$id_user'
|
||||||
tusuario_perfil.id_usuario = '%s' AND tags != ''",
|
AND tags != '' AND tags !='0'";
|
||||||
$id_user);
|
|
||||||
|
|
||||||
$user_tags = db_get_value_sql($query);
|
$user_tags = db_get_value_sql($query);
|
||||||
|
|
||||||
|
@ -177,16 +177,15 @@ echo '<td style="vertical-align: top; width: 75%; padding-top: 0px;" id="rightco
|
|||||||
// Last events information
|
// Last events information
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
$acltags = tags_get_user_groups_and_tags ($config['id_user'], 'ER', $user_strict);
|
if (check_acl($config['id_user'],0,'ER')) {
|
||||||
|
|
||||||
if (!empty($acltags)) {
|
|
||||||
// TODO event tag revision
|
// TODO event tag revision
|
||||||
$tags_condition = tags_get_acl_tags_event_condition($acltags, false, $user_strict);
|
$tags_condition = tags_get_acl_tags(false,0,'ER','event_condition');
|
||||||
|
$event_filter = "estado<>1";
|
||||||
if (!empty($tags_condition)) {
|
if (!empty($tags_condition)) {
|
||||||
$events = events_print_event_table ("estado<>1 AND ($tags_condition)", 10, "100%",true,false,true);
|
$event_filter .= " AND ($tags_condition)";
|
||||||
ui_toggle($events, __('Latest events'),false,false);
|
|
||||||
}
|
}
|
||||||
|
$events = events_print_event_table ($event_filter, 10, "100%",true,false,true);
|
||||||
|
ui_toggle($events, __('Latest events'),false,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user