2013-01-18 10:56:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation for version 2.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2019-01-30 16:18:44 +01:00
|
|
|
if (check_acl($id_user, 0, 'ER')) {
|
|
|
|
$groups = users_get_groups($id_user, 'ER');
|
|
|
|
} else if (check_acl($id_user, 0, 'EW')) {
|
|
|
|
$groups = users_get_groups($id_user, 'EW');
|
|
|
|
} else if (check_acl($id_user, 0, 'EM')) {
|
|
|
|
$groups = users_get_groups($id_user, 'EM');
|
|
|
|
}
|
2016-09-08 16:06:12 +02:00
|
|
|
|
2013-01-18 10:56:46 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$propagate = db_get_value('propagate', 'tgrupo', 'id_grupo', $id_group);
|
2014-11-18 11:27:04 +01:00
|
|
|
|
2014-11-18 15:18:00 +01:00
|
|
|
if ($id_group > 0) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$filter_resume['groups'] = $id_group;
|
|
|
|
if ($propagate) {
|
|
|
|
$childrens_ids = [$id_group];
|
|
|
|
|
|
|
|
$childrens = groups_get_childrens($id_group, null, true);
|
|
|
|
|
|
|
|
if (!empty($childrens)) {
|
|
|
|
foreach ($childrens as $child) {
|
|
|
|
$childrens_ids[] = (int) $child['id_grupo'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$childrens_ids = [];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$childrens_ids = array_keys($groups);
|
2014-11-18 11:27:04 +01:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
// Group selection
|
|
|
|
if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
|
|
|
if ($propagate) {
|
|
|
|
$childrens_str = implode(',', $childrens_ids);
|
|
|
|
$sql_post = " AND (id_grupo IN ($childrens_str) OR id_group IN ($childrens_str))";
|
|
|
|
} else {
|
|
|
|
// If a group is selected and it's in the groups allowed
|
|
|
|
$sql_post = " AND (id_grupo = $id_group OR id_group = $id_group)";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$sql_post = sprintf(
|
|
|
|
' AND (id_grupo IN (%s) OR id_group IN (%s)) ',
|
|
|
|
implode(',', array_keys($groups)),
|
|
|
|
implode(',', array_keys($groups))
|
|
|
|
);
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip system messages if user is not PM
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!check_acl($id_user, 0, 'PM')) {
|
|
|
|
$sql_post .= ' AND id_grupo != 0';
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ($status) {
|
2019-01-30 16:18:44 +01:00
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
$filter_resume['status'] = $status;
|
|
|
|
$sql_post .= ' AND estado = '.$status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
$filter_resume['status'] = $status;
|
|
|
|
$sql_post .= ' AND (estado = 0 OR estado = 2)';
|
|
|
|
break;
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:59:17 +02:00
|
|
|
|
|
|
|
$events_wi_cdata = db_get_all_rows_sql('SELECT id_evento,custom_data from tevento WHERE custom_data != ""');
|
|
|
|
$count_events = 0;
|
|
|
|
$events_wi_cdata_id = 'OR id_evento IN (';
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($events_wi_cdata === false) {
|
|
|
|
$events_wi_cdata = [];
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:59:17 +02:00
|
|
|
foreach ($events_wi_cdata as $key => $value) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$needle = base64_decode($value['custom_data']);
|
|
|
|
if (($needle != '') && ($search != '')) {
|
|
|
|
if (strpos(strtolower($needle), strtolower($search)) != false) {
|
|
|
|
$events_wi_cdata_id .= $value['id_evento'];
|
|
|
|
$count_events++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value !== end($events_wi_cdata) && $count_events > 0) {
|
|
|
|
$events_wi_cdata_id .= ',';
|
|
|
|
$events_wi_cdata_id = str_replace(',,', ',', $events_wi_cdata_id);
|
|
|
|
}
|
2017-05-18 14:59:17 +02:00
|
|
|
}
|
2017-06-07 17:55:53 +02:00
|
|
|
|
2017-05-18 14:59:17 +02:00
|
|
|
$events_wi_cdata_id .= ')';
|
|
|
|
|
2017-06-07 17:55:53 +02:00
|
|
|
$events_wi_cdata_id = str_replace(',)', ')', $events_wi_cdata_id);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($count_events == 0) {
|
|
|
|
$events_wi_cdata_id = '';
|
2017-05-18 14:59:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($search != '') {
|
|
|
|
$filter_resume['free_search'] = $search;
|
|
|
|
$sql_post .= " AND (evento LIKE '%".$search."%' OR id_evento LIKE '%$search%' ".$events_wi_cdata_id.')';
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($event_type != '') {
|
|
|
|
$filter_resume['event_type'] = $event_type;
|
|
|
|
// If normal, warning, could be several (going_up_warning, going_down_warning... too complex
|
|
|
|
// for the user so for him is presented only "warning, critical and normal"
|
|
|
|
if ($event_type == 'warning' || $event_type == 'critical' || $event_type == 'normal') {
|
|
|
|
$sql_post .= " AND event_type LIKE '%$event_type%' ";
|
|
|
|
} else if ($event_type == 'not_normal') {
|
|
|
|
$sql_post .= " AND (event_type LIKE '%warning%' OR event_type LIKE '%critical%' OR event_type LIKE '%unknown%') ";
|
|
|
|
} else if ($event_type != 'all') {
|
|
|
|
$sql_post .= " AND event_type = '".$event_type."'";
|
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($severity != -1) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$filter_resume['severity'] = $severity;
|
|
|
|
switch ($severity) {
|
|
|
|
case EVENT_CRIT_WARNING_OR_CRITICAL:
|
|
|
|
$sql_post .= '
|
|
|
|
AND (criticity = '.EVENT_CRIT_WARNING.' OR
|
|
|
|
criticity = '.EVENT_CRIT_CRITICAL.')';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_CRIT_OR_NORMAL:
|
|
|
|
$sql_post .= '
|
|
|
|
AND (criticity = '.EVENT_CRIT_NORMAL.' OR
|
|
|
|
criticity = '.EVENT_CRIT_CRITICAL.')';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVENT_CRIT_NOT_NORMAL:
|
|
|
|
$sql_post .= ' AND criticity != '.EVENT_CRIT_NORMAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$sql_post .= " AND criticity = $severity";
|
|
|
|
break;
|
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
2018-08-31 16:25:12 +02:00
|
|
|
if ($id_extra != '') {
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_post .= " AND id_extra LIKE '%$id_extra%'";
|
2018-08-31 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($user_comment != '') {
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_post .= " AND user_comment LIKE '%$user_comment%'";
|
2018-08-31 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($source != '') {
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_post .= " AND source LIKE '%$source%'";
|
2018-08-31 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
2013-01-18 10:56:46 +01:00
|
|
|
// In metaconsole mode the agent search is performed by name
|
2013-03-20 Miguel de Dios <miguel.dedios@artica.es>
* mobile/operation/events.php, mobile/include/ui.class.php,
mobile/index.php: added first version of events section.
* include/functions_incidents.php, include/functions_users.php,
include/functions.php, include/functions_groups.php,
include/functions_events.php, include/functions_html.php,
operation/events/events.build_table.php,
operation/events/events.build_query.php,
operation/events/events_list.php: some changes for interact with
mobile version.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7872 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-20 13:29:33 +01:00
|
|
|
if ($meta) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$text_agent = get_parameter('text_agent', '');
|
|
|
|
$id_agent = get_parameter('id_agent', 0);
|
|
|
|
if ($id_agent) {
|
|
|
|
$sql_post .= ' AND agent_name IN (SELECT nombre FROM tmetaconsole_agent WHERE
|
|
|
|
id_tagente ='.$id_agent." AND alias LIKE '".io_safe_input($text_agent)."')";
|
|
|
|
$filter_resume['agent'] = $text_agent;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch ($id_agent) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
// Agent doesnt exist. No results will returned
|
|
|
|
$sql_post .= ' AND 1 = 0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$filter_resume['agent'] = $id_agent;
|
|
|
|
$sql_post .= ' AND id_agente = '.$id_agent;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-27 19:09:07 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 15:00:06 +02:00
|
|
|
|
|
|
|
|
2014-09-01 15:23:45 +02:00
|
|
|
if ($meta) {
|
2019-01-30 16:18:44 +01:00
|
|
|
// There is another filter.
|
|
|
|
} else {
|
|
|
|
if (!empty($text_module)) {
|
|
|
|
$filter_resume['module'] = $text_module;
|
|
|
|
$sql_post .= " AND id_agentmodule IN (
|
2014-09-01 15:23:45 +02:00
|
|
|
SELECT id_agente_modulo
|
|
|
|
FROM tagente_modulo
|
2015-05-22 11:14:40 +02:00
|
|
|
WHERE nombre = '$text_module'
|
|
|
|
)";
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($id_user_ack != '0') {
|
|
|
|
$filter_resume['user_ack'] = $id_user_ack;
|
|
|
|
$sql_post .= " AND id_usuario = '".$id_user_ack."'";
|
2017-02-28 15:41:03 +01:00
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
|
2014-10-09 13:50:05 +02:00
|
|
|
if (!isset($date_from)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$date_from = '';
|
2014-10-09 13:50:05 +02:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2014-10-09 13:50:05 +02:00
|
|
|
if (!isset($date_to)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$date_to = '';
|
2014-10-09 13:50:05 +02:00
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
|
2014-05-20 16:40:43 +02:00
|
|
|
if (($date_from == '') && ($date_to == '')) {
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($event_view_hr > 0) {
|
|
|
|
$filter_resume['hours_max'] = $event_view_hr;
|
|
|
|
$unixtime = (get_system_time() - ($event_view_hr * SECONDS_1HOUR));
|
|
|
|
$sql_post .= ' AND (utimestamp > '.$unixtime.')';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Some of this values will have the user's timezone,
|
|
|
|
// so we need to reverse it to the system's timezone
|
|
|
|
// before using it into the db
|
|
|
|
$fixed_offset = get_fixed_offset();
|
|
|
|
|
|
|
|
if (!empty($date_from)) {
|
|
|
|
if (empty($time_from)) {
|
|
|
|
$time_from = '00:00:00';
|
|
|
|
}
|
|
|
|
|
|
|
|
$utimestamp_from = (strtotime($date_from.' '.$time_from) - $fixed_offset);
|
|
|
|
$filter_resume['time_from'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_from);
|
|
|
|
$sql_post .= ' AND (utimestamp >= '.$utimestamp_from.')';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($date_to)) {
|
|
|
|
if (empty($time_to)) {
|
|
|
|
$time_to = '23:59:59';
|
|
|
|
}
|
|
|
|
|
|
|
|
$utimestamp_to = (strtotime($date_to.' '.$time_to) - $fixed_offset);
|
|
|
|
$filter_resume['time_to'] = date(DATE_FORMAT.' '.TIME_FORMAT, $utimestamp_to);
|
|
|
|
$sql_post .= ' AND (utimestamp <= '.$utimestamp_to.')';
|
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// Search by tag
|
2013-01-18 10:56:46 +01:00
|
|
|
if (!empty($tag_with)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!users_is_admin()) {
|
|
|
|
$user_tags = array_flip(tags_get_tags_for_module_search());
|
|
|
|
if ($user_tags != null) {
|
|
|
|
foreach ($tag_with as $id_tag) {
|
|
|
|
if (!array_search($id_tag, $user_tags)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= ' AND ( ';
|
|
|
|
$first = true;
|
|
|
|
$filter_resume['tag_inc'] = $tag_with;
|
|
|
|
foreach ($tag_with as $id_tag) {
|
|
|
|
if ($first) {
|
|
|
|
$sql_post .= ' ( ';
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
$sql_post .= ' AND ( ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= "tags LIKE '".tags_get_name($id_tag)."'";
|
|
|
|
$sql_post .= ' OR ';
|
|
|
|
$sql_post .= "tags LIKE '".tags_get_name($id_tag).",%'";
|
|
|
|
$sql_post .= ' OR ';
|
|
|
|
$sql_post .= "tags LIKE '%,".tags_get_name($id_tag)."'";
|
|
|
|
$sql_post .= ' OR ';
|
|
|
|
$sql_post .= "tags LIKE '%,".tags_get_name($id_tag).",%'";
|
|
|
|
$sql_post .= ' ) ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= ' ) ';
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2013-01-18 10:56:46 +01:00
|
|
|
if (!empty($tag_without)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_post .= ' AND ( ';
|
|
|
|
$first = true;
|
|
|
|
$filter_resume['tag_no_inc'] = $tag_without;
|
|
|
|
foreach ($tag_without as $id_tag) {
|
|
|
|
if ($first) {
|
|
|
|
$first = false;
|
|
|
|
} else {
|
|
|
|
$sql_post .= ' AND ';
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= "tags NOT LIKE '%".tags_get_name($id_tag)."%'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= ' ) ';
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter/Only alerts
|
|
|
|
if (isset($filter_only_alert)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($filter_only_alert == 0) {
|
|
|
|
$filter_resume['alerts'] = $filter_only_alert;
|
|
|
|
$sql_post .= " AND event_type NOT LIKE '%alert%'";
|
|
|
|
} else if ($filter_only_alert == 1) {
|
|
|
|
$filter_resume['alerts'] = $filter_only_alert;
|
|
|
|
$sql_post .= " AND event_type LIKE '%alert%'";
|
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tags ACLS
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($id_group > 0 && in_array($id_group, array_keys($groups))) {
|
|
|
|
$group_array = (array) $id_group;
|
|
|
|
} else {
|
|
|
|
$group_array = array_keys($groups);
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
if (check_acl($id_user, 0, 'ER')) {
|
|
|
|
$tags_acls_condition = tags_get_acl_tags(
|
|
|
|
$id_user,
|
|
|
|
$group_array,
|
|
|
|
'ER',
|
|
|
|
'event_condition',
|
|
|
|
'AND',
|
|
|
|
'',
|
|
|
|
$meta,
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
|
|
|
} else if (check_acl($id_user, 0, 'EW')) {
|
|
|
|
$tags_acls_condition = tags_get_acl_tags(
|
|
|
|
$id_user,
|
|
|
|
$group_array,
|
|
|
|
'EW',
|
|
|
|
'event_condition',
|
|
|
|
'AND',
|
|
|
|
'',
|
|
|
|
$meta,
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
|
|
|
} else if (check_acl($id_user, 0, 'EM')) {
|
|
|
|
$tags_acls_condition = tags_get_acl_tags(
|
|
|
|
$id_user,
|
|
|
|
$group_array,
|
|
|
|
'EM',
|
|
|
|
'event_condition',
|
|
|
|
'AND',
|
|
|
|
'',
|
|
|
|
$meta,
|
|
|
|
[],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)"
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|
2018-10-05 09:40:08 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (($tags_acls_condition != ERR_WRONG_PARAMETERS) && ($tags_acls_condition != ERR_ACL) && ($tags_acls_condition != -110000)) {
|
|
|
|
$sql_post .= $tags_acls_condition;
|
2014-08-25 11:02:45 +02:00
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
|
|
|
|
// Metaconsole fitlers
|
2013-03-20 Miguel de Dios <miguel.dedios@artica.es>
* mobile/operation/events.php, mobile/include/ui.class.php,
mobile/index.php: added first version of events section.
* include/functions_incidents.php, include/functions_users.php,
include/functions.php, include/functions_groups.php,
include/functions_events.php, include/functions_html.php,
operation/events/events.build_table.php,
operation/events/events.build_query.php,
operation/events/events_list.php: some changes for interact with
mobile version.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7872 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2013-03-20 13:29:33 +01:00
|
|
|
if ($meta) {
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($server_id) {
|
|
|
|
$filter_resume['server'] = $server_id;
|
|
|
|
$sql_post .= ' AND server_id = '.$server_id;
|
|
|
|
} else {
|
|
|
|
$enabled_nodes = db_get_all_rows_sql(
|
|
|
|
'
|
2015-06-30 16:48:32 +02:00
|
|
|
SELECT id
|
|
|
|
FROM tmetaconsole_setup
|
2019-01-30 16:18:44 +01:00
|
|
|
WHERE disabled = 0'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (empty($enabled_nodes)) {
|
|
|
|
$sql_post .= ' AND 1 = 0';
|
|
|
|
} else {
|
|
|
|
if ($strict_user == 1) {
|
|
|
|
$enabled_nodes_id = [];
|
|
|
|
} else {
|
|
|
|
$enabled_nodes_id = [0];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($enabled_nodes as $en) {
|
|
|
|
$enabled_nodes_id[] = $en['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_post .= ' AND server_id IN ('.implode(',', $enabled_nodes_id).')';
|
|
|
|
}
|
|
|
|
}
|
2013-01-18 10:56:46 +01:00
|
|
|
}
|