Merge branch 'ent-4238-eventos-csv-e-historico' into 'develop'

Ent 4238 eventos csv e historico

See merge request artica/pandorafms!2515
This commit is contained in:
Daniel Rodriguez 2019-06-25 18:33:49 +02:00
commit 61e07abf3a
14 changed files with 1254 additions and 609 deletions

View File

@ -1,5 +1,7 @@
START TRANSACTION; START TRANSACTION;
ALTER TABLE `tmetaconsole_agent` ADD INDEX `id_tagente_idx` (`id_tagente`);
DELETE FROM `ttipo_modulo` WHERE `nombre` LIKE 'log4x'; DELETE FROM `ttipo_modulo` WHERE `nombre` LIKE 'log4x';

View File

@ -113,6 +113,8 @@ $fields_available['instructions'] = __('Instructions');
$fields_available['server_name'] = __('Server Name'); $fields_available['server_name'] = __('Server Name');
$fields_available['data'] = __('Data'); $fields_available['data'] = __('Data');
$fields_available['module_status'] = __('Module Status'); $fields_available['module_status'] = __('Module Status');
$fields_available['mini_severity'] = __('Severity mini');
// Remove fields already selected. // Remove fields already selected.
foreach ($fields_available as $key => $available) { foreach ($fields_available as $key => $available) {

View File

@ -50,17 +50,10 @@ if (check_acl($config['id_user'], 0, 'PM')) {
'text' => '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=responses&amp;pure='.$config['pure'].'">'.html_print_image('images/event_responses.png', true, ['title' => __('Event responses')]).'</a>', 'text' => '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=responses&amp;pure='.$config['pure'].'">'.html_print_image('images/event_responses.png', true, ['title' => __('Event responses')]).'</a>',
]; ];
if (!is_metaconsole()) {
$buttons['fields'] = [ $buttons['fields'] = [
'active' => false, 'active' => false,
'text' => '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=fields&amp;pure='.$config['pure'].'">'.html_print_image('images/custom_columns.png', true, ['title' => __('Custom fields')]).'</a>', 'text' => '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=fields&amp;pure='.$config['pure'].'">'.html_print_image('images/custom_columns.png', true, ['title' => __('Custom fields')]).'</a>',
]; ];
} else {
$buttons['fields'] = [
'active' => false,
'text' => '<a href="index.php?sec=eventos&sec2=event/custom_events&amp;section=fields&amp;pure='.$config['pure'].'">'.html_print_image('images/custom_columns.png', true, ['title' => __('Custom fields')]).'</a>',
];
}
} }
switch ($section) { switch ($section) {

View File

@ -75,13 +75,73 @@ $graphic_event_group = (bool) get_parameter('graphic_event_group');
$get_table_response_command = (bool) get_parameter('get_table_response_command'); $get_table_response_command = (bool) get_parameter('get_table_response_command');
$save_filter_modal = get_parameter('save_filter_modal', 0); $save_filter_modal = get_parameter('save_filter_modal', 0);
$load_filter_modal = get_parameter('load_filter_modal', 0); $load_filter_modal = get_parameter('load_filter_modal', 0);
$save_filter = get_parameter('save_filter', 0);
$get_filter_values = get_parameter('get_filter_values', 0); $get_filter_values = get_parameter('get_filter_values', 0);
$update_event_filter = get_parameter('update_event_filter', 0); $update_event_filter = get_parameter('update_event_filter', 0);
$save_event_filter = get_parameter('save_event_filter', 0); $save_event_filter = get_parameter('save_event_filter', 0);
$in_process_event = get_parameter('in_process_event', 0); $in_process_event = get_parameter('in_process_event', 0);
$validate_event = get_parameter('validate_event', 0); $validate_event = get_parameter('validate_event', 0);
$delete_event = get_parameter('delete_event', 0); $delete_event = get_parameter('delete_event', 0);
$get_event_filters = get_parameter('get_event_filters', 0);
$get_comments = get_parameter('get_comments', 0);
if ($get_comments) {
$event = get_parameter('event', false);
$filter = get_parameter('filter', false);
if ($event === false) {
return __('Failed to retrieve comments');
}
if ($filter['group_rep'] == 1) {
$events = events_get_all(
['te.*'],
// Filter.
$filter,
// Offset.
null,
// Limit.
null,
// Order.
null,
// Sort_field.
null,
// History.
$filter['history'],
// Return_sql.
false,
// Having.
sprintf(
' HAVING max_id_evento = %d',
$event['id_evento']
)
);
if ($events !== false) {
$event = $events[0];
}
} else {
$events = events_get_event(
$event['id_evento'],
false,
$meta,
$history
);
if ($events !== false) {
$event = $events[0];
}
}
echo events_page_comments($event, true);
return;
}
if ($get_event_filters) {
$event_filter = events_get_event_filter_select();
echo io_json_mb_encode($event_filter);
return;
}
// Delete event (filtered or not). // Delete event (filtered or not).
if ($delete_event) { if ($delete_event) {
@ -267,6 +327,17 @@ if ($get_filter_values) {
$event_filter = events_get_event_filter($id_filter); $event_filter = events_get_event_filter($id_filter);
if ($event_filter === false) {
$event_filter = [
'status' => EVENT_NO_VALIDATED,
'event_view_hr' => $config['event_view_hr'],
'group_rep' => 1,
'tag_with' => [],
'tag_without' => [],
'history' => false,
];
}
$event_filter['search'] = io_safe_output($event_filter['search']); $event_filter['search'] = io_safe_output($event_filter['search']);
$event_filter['id_name'] = io_safe_output($event_filter['id_name']); $event_filter['id_name'] = io_safe_output($event_filter['id_name']);
$event_filter['tag_with'] = base64_encode( $event_filter['tag_with'] = base64_encode(
@ -590,7 +661,7 @@ function save_new_filter() {
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{ {
"page" : "operation/events/events_list", "page" : "include/ajax/events",
"save_event_filter" : 1, "save_event_filter" : 1,
"id_name" : $("#text-id_name").val(), "id_name" : $("#text-id_name").val(),
"id_group" : $("select#id_group").val(), "id_group" : $("select#id_group").val(),
@ -659,7 +730,7 @@ function save_update_filter() {
var name_filter_update = $("#overwrite_filter option[value='"+id_filter_update+"']").text(); var name_filter_update = $("#overwrite_filter option[value='"+id_filter_update+"']").text();
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{"page" : "operation/events/events_list", {"page" : "include/ajax/events",
"update_event_filter" : 1, "update_event_filter" : 1,
"id" : $("#overwrite_filter").val(), "id" : $("#overwrite_filter").val(),
"id_group" : $("select#id_group").val(), "id_group" : $("select#id_group").val(),
@ -712,7 +783,7 @@ function save_update_filter() {
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('none')."'"; ?> ).attr ("value", 0)); $('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('none')."'"; ?> ).attr ("value", 0));
// Reload filters select // Reload filters select
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>", jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{"page" : "operation/events/events_list", {"page" : "include/ajax/events",
"get_event_filters" : 1 "get_event_filters" : 1
}, },
function (data) { function (data) {
@ -1040,6 +1111,7 @@ if ($get_extended_event) {
global $config; global $config;
$event = get_parameter('event', false); $event = get_parameter('event', false);
$filter = get_parameter('filter', false);
if ($event === false) { if ($event === false) {
return; return;
@ -1079,28 +1151,36 @@ if ($get_extended_event) {
} }
// Check ACLs. // Check ACLs.
$access = false;
if (is_user_admin($config['id_user'])) { if (is_user_admin($config['id_user'])) {
// Do nothing if you're admin, you get full access. // Do nothing if you're admin, you get full access.
$__ignored_line = 0; $access = true;
} else if ($config['id_user'] == $event['owner_user']) { } else if ($config['id_user'] == $event['owner_user']) {
// Do nothing if you're the owner user, you get access. // Do nothing if you're the owner user, you get access.
$__ignored_line = 0; $access = true;
} else if ($event['id_grupo'] == 0) { } else if ($event['id_grupo'] == 0) {
// If the event has access to all groups, you get access. // If the event has access to all groups, you get access.
$__ignored_line = 0; $access = true;
} else { } else {
// Get your groups. // Get your groups.
$groups = users_get_groups($config['id_user'], 'ER'); $groups = users_get_groups($config['id_user'], 'ER');
if (in_array($event['id_grupo'], array_keys($groups))) { if (in_array($event['id_grupo'], array_keys($groups))) {
// If event group is among the groups of the user, you get access. // If event group is among the groups of the user, you get access.
$__ignored_line = 0; $access = true;
} else { } else if ($event['id_agente']
&& agents_check_access_agent($event['id_agente'], 'ER')
) {
// Secondary group, indirect access.
$access = true;
}
}
if (!$access) {
// If all the access types fail, abort. // If all the access types fail, abort.
echo 'Access denied'; echo 'Access denied';
return false; return false;
} }
}
// Print group_rep in a hidden field to recover it from javascript. // Print group_rep in a hidden field to recover it from javascript.
html_print_input_hidden('group_rep', (int) $group_rep); html_print_input_hidden('group_rep', (int) $group_rep);
@ -1227,7 +1307,7 @@ if ($get_extended_event) {
$general = events_page_general($event); $general = events_page_general($event);
$comments = events_page_comments($event); $comments = '<div id="extended_event_comments_page" class="extended_event_pages"></div>';
$notifications = '<div id="notification_comment_error" style="display:none">'.ui_print_error_message(__('Error adding comment'), '', true).'</div>'; $notifications = '<div id="notification_comment_error" style="display:none">'.ui_print_error_message(__('Error adding comment'), '', true).'</div>';
$notifications .= '<div id="notification_comment_success" style="display:none">'.ui_print_success_message(__('Comment added successfully'), '', true).'</div>'; $notifications .= '<div id="notification_comment_success" style="display:none">'.ui_print_success_message(__('Comment added successfully'), '', true).'</div>';
@ -1238,6 +1318,18 @@ if ($get_extended_event) {
$loading = '<div id="response_loading" style="display:none">'.html_print_image('images/spinner.gif', true).'</div>'; $loading = '<div id="response_loading" style="display:none">'.html_print_image('images/spinner.gif', true).'</div>';
$i = 0;
$tab['general'] = $i++;
$tab['details'] = $i++;
if (!empty($related)) {
$tab['related'] = $i++;
}
$tab['custom_fields'] = $i++;
$tab['comments'] = $i++;
$tab['responses'] = $i++;
$tab['custom_data'] = $i++;
$out = '<div id="tabs">'.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'</div>'; $out = '<div id="tabs">'.$tabs.$notifications.$loading.$general.$details.$related.$custom_fields.$comments.$responses.$custom_data.html_print_input_hidden('id_event', $event['id_evento']).'</div>';
$js = '<script> $js = '<script>
@ -1249,31 +1341,31 @@ if ($get_extended_event) {
// Load the required tab. // Load the required tab.
switch ($dialog_page) { switch ($dialog_page) {
case 'general': case 'general':
$js .= '$tabs.tabs( "option", "active", 0);'; $js .= '$tabs.tabs( "option", "active", '.$tab['general'].');';
break; break;
case 'details': case 'details':
$js .= '$tabs.tabs( "option", "active", 1);'; $js .= '$tabs.tabs( "option", "active", '.$tab['details'].');';
break; break;
case 'related': case 'related':
$js .= '$tabs.tabs( "option", "active", 2);'; $js .= '$tabs.tabs( "option", "active", '.$tab['related'].');';
break; break;
case 'custom_fields': case 'custom_fields':
$js .= '$tabs.tabs( "option", "active", 3);'; $js .= '$tabs.tabs( "option", "active", '.$tab['custom_fields'].');';
break; break;
case 'comments': case 'comments':
$js .= '$tabs.tabs( "option", "active", 4);'; $js .= '$tabs.tabs( "option", "active", '.$tab['comments'].');';
break; break;
case 'responses': case 'responses':
$js .= '$tabs.tabs( "option", "active", 5);'; $js .= '$tabs.tabs( "option", "active", '.$tab['responses'].');';
break; break;
case 'custom_data': case 'custom_data':
$js .= '$tabs.tabs( "option", "active", 6);'; $js .= '$tabs.tabs( "option", "active", '.$tab['custom_data'].');';
break; break;
default: default:
@ -1283,6 +1375,24 @@ if ($get_extended_event) {
$js .= '});'; $js .= '});';
$js .= '
$("#link_comments").click(function (){
$.post ({
url : "ajax.php",
data : {
page: "include/ajax/events",
get_comments: 1,
event: '.json_encode($event).',
filter: '.json_encode($filter).'
},
dataType : "html",
success: function (data) {
$("#extended_event_comments_page").empty();
$("#extended_event_comments_page").html(data);
}
});
});';
if (events_has_extended_info($event['id_evento']) === true) { if (events_has_extended_info($event['id_evento']) === true) {
$js .= ' $js .= '
$("#link_related").click(function (){ $("#link_related").click(function (){

View File

@ -146,7 +146,7 @@ define('COL_NOTINIT', '#4a83f3');
define('COL_UNKNOWN', '#B2B2B2'); define('COL_UNKNOWN', '#B2B2B2');
define('COL_DOWNTIME', '#976DB1'); define('COL_DOWNTIME', '#976DB1');
define('COL_IGNORED', '#DDD'); define('COL_IGNORED', '#DDD');
define('COL_ALERTFIRED', '#FFA631'); define('COL_ALERTFIRED', '#F36201');
define('COL_MINOR', '#B2B2B2'); define('COL_MINOR', '#B2B2B2');
define('COL_MAJOR', '#C97A4A'); define('COL_MAJOR', '#C97A4A');
define('COL_INFORMATIONAL', '#E4E4E4'); define('COL_INFORMATIONAL', '#E4E4E4');

View File

@ -34,6 +34,143 @@ enterprise_include_once('meta/include/functions_agents_meta.php');
enterprise_include_once('meta/include/functions_modules_meta.php'); enterprise_include_once('meta/include/functions_modules_meta.php');
/**
* Translates a numeric value module_status into descriptive text.
*
* @param integer $status Module status.
*
* @return string Descriptive text.
*/
function events_translate_module_status($status)
{
switch ($status) {
case AGENT_MODULE_STATUS_NORMAL:
return __('NORMAL');
case AGENT_MODULE_STATUS_CRITICAL_BAD:
return __('CRITICAL');
case AGENT_MODULE_STATUS_NO_DATA:
return __('NOT INIT');
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
case AGENT_MODULE_STATUS_NORMAL_ALERT:
case AGENT_MODULE_STATUS_WARNING_ALERT:
return __('ALERT');
case AGENT_MODULE_STATUS_WARNING:
return __('WARNING');
default:
return __('UNKNOWN');
}
}
/**
* Translates a numeric value event_type into descriptive text.
*
* @param integer $event_type Event type.
*
* @return string Descriptive text.
*/
function events_translate_event_type($event_type)
{
// Event type prepared.
switch ($event_type) {
case EVENTS_ALERT_FIRED:
case EVENTS_ALERT_RECOVERED:
case EVENTS_ALERT_CEASED:
case EVENTS_ALERT_MANUAL_VALIDATION:
return __('ALERT');
case EVENTS_RECON_HOST_DETECTED:
case EVENTS_SYSTEM:
case EVENTS_ERROR:
case EVENTS_NEW_AGENT:
case EVENTS_CONFIGURATION_CHANGE:
return __('SYSTEM');
case EVENTS_GOING_UP_WARNING:
case EVENTS_GOING_DOWN_WARNING:
return __('WARNING');
case EVENTS_GOING_DOWN_NORMAL:
case EVENTS_GOING_UP_NORMAL:
return __('NORMAL');
case EVENTS_GOING_DOWN_CRITICAL:
case EVENTS_GOING_UP_CRITICAL:
return __('CRITICAL');
case EVENTS_UNKNOWN:
case EVENTS_GOING_UNKNOWN:
default:
return __('UNKNOWN');
}
}
/**
* Translates a numeric value event_status into descriptive text.
*
* @param integer $status Event status.
*
* @return string Descriptive text.
*/
function events_translate_event_status($status)
{
switch ($status) {
case EVENT_STATUS_NEW:
default:
return __('NEW');
case EVENT_STATUS_INPROCESS:
return __('IN PROCESS');
case EVENT_STATUS_VALIDATED:
return __('VALIDATED');
}
}
/**
* Translates a numeric value criticity into descriptive text.
*
* @param integer $criticity Event criticity.
*
* @return string Descriptive text.
*/
function events_translate_event_criticity($criticity)
{
switch ($criticity) {
case EVENT_CRIT_CRITICAL:
return __('CRITICAL');
case EVENT_CRIT_MAINTENANCE:
return __('MAINTENANCE');
case EVENT_CRIT_INFORMATIONAL:
return __('INFORMATIONAL');
case EVENT_CRIT_MAJOR:
return __('MAJOR');
case EVENT_CRIT_MINOR:
return __('MINOR');
case EVENT_CRIT_NORMAL:
return __('NORMAL');
case EVENT_CRIT_WARNING:
return __('WARNING');
default:
return __('UNKNOWN');
}
}
/** /**
* Return all header string for each event field. * Return all header string for each event field.
* *
@ -151,6 +288,9 @@ function events_get_column_name($field)
case 'options': case 'options':
return __('Options'); return __('Options');
case 'mini_severity':
return 'S';
default: default:
return __($field); return __($field);
} }
@ -641,32 +781,35 @@ function events_get_all(
} }
} }
if (isset($filter['id_group_filter']) && $filter['id_group_filter'] > 0) { $groups = $filter['id_group_filter'];
if (isset($groups) && $groups > 0) {
$propagate = db_get_value( $propagate = db_get_value(
'propagate', 'propagate',
'tgrupo', 'tgrupo',
'id_grupo', 'id_grupo',
$filter['id_group_filter'] $groups
); );
if (!$propagate) { if (!$propagate) {
$sql_filters[] = sprintf( $sql_filters[] = sprintf(
' AND te.id_grupo = %d ', ' AND (te.id_grupo = %d OR tasg.id_group = %d)',
$filter['id_group_filter'] $groups
); );
} else { } else {
$groups = [ $filter['id_group_filter'] ]; $children = groups_get_children($groups);
$childrens = groups_get_childrens($id_group, null, true); $_groups = [ $groups ];
if (!empty($childrens)) { if (!empty($children)) {
foreach ($childrens as $child) { foreach ($children as $child) {
$groups[] = (int) $child['id_grupo']; $_groups[] = (int) $child['id_grupo'];
} }
} }
$filter['id_group_filter'] = $groups; $groups = $_groups;
$sql_filters[] = sprintf( $sql_filters[] = sprintf(
' AND id_group IN (%s) ', ' AND (te.id_grupo IN (%s) OR tasg.id_group IN (%s))',
join(',', $filter['id_group_filter']) join(',', $groups),
join(',', $groups)
); );
} }
} }
@ -702,8 +845,6 @@ function events_get_all(
} }
} }
$sg_active = enterprise_hook('agents_is_using_secondary_groups');
if (!$user_is_admin) { if (!$user_is_admin) {
$ER_groups = users_get_groups($config['id_user'], 'ER', false); $ER_groups = users_get_groups($config['id_user'], 'ER', false);
$EM_groups = users_get_groups($config['id_user'], 'EM', false, true); $EM_groups = users_get_groups($config['id_user'], 'EM', false, true);
@ -713,7 +854,8 @@ function events_get_all(
if (!$user_is_admin && !users_can_manage_group_all('ER')) { if (!$user_is_admin && !users_can_manage_group_all('ER')) {
// Get groups where user have ER grants. // Get groups where user have ER grants.
$sql_filters[] = sprintf( $sql_filters[] = sprintf(
' AND te.id_grupo IN ( %s )', ' AND (te.id_grupo IN ( %s ) OR tasg.id_group IN (%s))',
join(', ', array_keys($ER_groups)),
join(', ', array_keys($ER_groups)) join(', ', array_keys($ER_groups))
); );
} }
@ -912,7 +1054,9 @@ function events_get_all(
// Force_group_and_tag. // Force_group_and_tag.
true, true,
// Table tag for id_grupo. // Table tag for id_grupo.
'te.' 'te.',
// Alt table tag for id_grupo.
'tasg.'
); );
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
} else if (check_acl($config['id_user'], 0, 'EW')) { } else if (check_acl($config['id_user'], 0, 'EW')) {
@ -936,7 +1080,9 @@ function events_get_all(
// Force_group_and_tag. // Force_group_and_tag.
true, true,
// Table tag for id_grupo. // Table tag for id_grupo.
'te.' 'te.',
// Alt table tag for id_grupo.
'tasg.'
); );
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
} else if (check_acl($config['id_user'], 0, 'EM')) { } else if (check_acl($config['id_user'], 0, 'EM')) {
@ -960,7 +1106,9 @@ function events_get_all(
// Force_group_and_tag. // Force_group_and_tag.
true, true,
// Table tag for id_grupo. // Table tag for id_grupo.
'te.' 'te.',
// Alt table tag for id_grupo.
'tasg.'
); );
// FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)". // FORCE CHECK SQL "(TAG = tag1 AND id_grupo = 1)".
} }
@ -1036,12 +1184,37 @@ function events_get_all(
$tgrupo_join = 'LEFT'; $tgrupo_join = 'LEFT';
$tgrupo_join_filters = []; $tgrupo_join_filters = [];
if (isset($filter['id_group_filter']) && $filter['id_group_filter'] > 0) { if (isset($groups)
&& (is_array($groups)
|| $groups > 0)
) {
$tgrupo_join = 'INNER'; $tgrupo_join = 'INNER';
if (is_array($groups)) {
$tgrupo_join_filters[] = sprintf( $tgrupo_join_filters[] = sprintf(
' AND tg.id_grupo = %s', ' AND (tg.id_grupo IN (%s) OR tasg.id_group IN (%s))',
$filter['id_group_filter'] join(', ', $groups),
join(', ', $groups)
); );
} else {
$tgrupo_join_filters[] = sprintf(
' AND (tg.id_grupo = %s OR tasg.id_group = %s)',
$groups,
$groups
);
}
}
$server_join = '';
if (is_metaconsole()) {
$server_join = ' LEFT JOIN tmetaconsole_setup ts
ON ts.id = te.server_id';
if (!empty($filter['server_id'])) {
$server_join = sprintf(
' LEFT JOIN tmetaconsole_setup ts
ON ts.id = te.server_id AND ts.id= %d',
$filter['server_id']
);
}
} }
// Secondary groups. // Secondary groups.
@ -1076,6 +1249,7 @@ function events_get_all(
%s JOIN tgrupo tg %s JOIN tgrupo tg
ON te.id_grupo = tg.id_grupo ON te.id_grupo = tg.id_grupo
%s %s
%s
WHERE 1=1 WHERE 1=1
%s %s
%s %s
@ -1094,6 +1268,7 @@ function events_get_all(
join(' ', $agent_join_filters), join(' ', $agent_join_filters),
$tgrupo_join, $tgrupo_join,
join(' ', $tgrupo_join_filters), join(' ', $tgrupo_join_filters),
$server_join,
join(' ', $sql_filters), join(' ', $sql_filters),
$group_by, $group_by,
$order_by, $order_by,
@ -4363,7 +4538,7 @@ function events_page_general($event)
* *
* @return string HTML. * @return string HTML.
*/ */
function events_page_comments($event) function events_page_comments($event, $ajax=false)
{ {
// Comments. // Comments.
global $config; global $config;
@ -4372,7 +4547,7 @@ function events_page_comments($event)
$comments = $event['user_comment']; $comments = $event['user_comment'];
if (isset($event['comments'])) { if (isset($event['comments'])) {
$comments = $event['comments']; $comments = explode('<br>', $event['comments']);
} }
$table_comments = new stdClass; $table_comments = new stdClass;
@ -4383,25 +4558,26 @@ function events_page_comments($event)
$comments = str_replace(["\n", '&#x0a;'], '<br>', $comments); $comments = str_replace(["\n", '&#x0a;'], '<br>', $comments);
if (is_array($comments)) {
foreach ($comments as $comm) {
if (empty($comm)) {
continue;
}
$comments_array[] = json_decode(io_safe_output($comm), true);
}
} else {
// If comments are not stored in json, the format is old. // If comments are not stored in json, the format is old.
$comments_array = json_decode(io_safe_output($comments), true); $comments_array = json_decode(io_safe_output($comments), true);
if (!empty($comments) && json_last_error() != JSON_ERROR_NONE) {
$comments_array = [
[
'comment' => 'Error retrieving comments',
'action' => 'Internal message',
'id_user' => 'SYSTEM',
'utimestamp' => time(),
],
];
} }
foreach ($comments_array as $comm) {
// Show the comments more recent first. // Show the comments more recent first.
if (is_array($comments_array)) { if (is_array($comm)) {
$comments_array = array_reverse($comments_array); $comm = array_reverse($comm);
} }
if (empty($comments_array)) { if (empty($comm)) {
$comments_format = 'old'; $comments_format = 'old';
} else { } else {
$comments_format = 'new'; $comments_format = 'new';
@ -4409,7 +4585,7 @@ function events_page_comments($event)
switch ($comments_format) { switch ($comments_format) {
case 'new': case 'new':
if (empty($comments_array)) { if (empty($comm)) {
$table_comments->style[0] = 'text-align:center;'; $table_comments->style[0] = 'text-align:center;';
$table_comments->colspan[0][0] = 2; $table_comments->colspan[0][0] = 2;
$data = []; $data = [];
@ -4417,10 +4593,10 @@ function events_page_comments($event)
$table_comments->data[] = $data; $table_comments->data[] = $data;
} }
if (isset($comments_array) === true if (isset($comm) === true
&& is_array($comments_array) === true && is_array($comm) === true
) { ) {
foreach ($comments_array as $c) { foreach ($comm as $c) {
$data[0] = '<b>'.$c['action'].' by '.$c['id_user'].'</b>'; $data[0] = '<b>'.$c['action'].' by '.$c['id_user'].'</b>';
$data[0] .= '<br><br><i>'.date($config['date_format'], $c['utimestamp']).'</i>'; $data[0] .= '<br><br><i>'.date($config['date_format'], $c['utimestamp']).'</i>';
$data[1] = $c['comment']; $data[1] = $c['comment'];
@ -4430,13 +4606,13 @@ function events_page_comments($event)
break; break;
case 'old': case 'old':
$comments_array = explode('<br>', $comments); $comm = explode('<br>', $comments);
// Split comments and put in table. // Split comments and put in table.
$col = 0; $col = 0;
$data = []; $data = [];
foreach ($comments_array as $c) { foreach ($comm as $c) {
switch ($col) { switch ($col) {
case 0: case 0:
$row_text = preg_replace('/\s*--\s*/', '', $c); $row_text = preg_replace('/\s*--\s*/', '', $c);
@ -4465,7 +4641,7 @@ function events_page_comments($event)
} }
} }
if (count($comments_array) == 1 && $comments_array[0] == '') { if (count($comm) == 1 && $comm[0] == '') {
$table_comments->style[0] = 'text-align:center;'; $table_comments->style[0] = 'text-align:center;';
$table_comments->colspan[0][0] = 2; $table_comments->colspan[0][0] = 2;
$data = []; $data = [];
@ -4478,6 +4654,7 @@ function events_page_comments($event)
// Ignore. // Ignore.
break; break;
} }
}
if (((tags_checks_event_acl( if (((tags_checks_event_acl(
$config['id_user'], $config['id_user'],
@ -4519,9 +4696,11 @@ function events_page_comments($event)
); );
} }
$comments = '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>'; if ($ajax) {
return $comments_form.html_print_table($table_comments, true);
}
return $comments; return '<div id="extended_event_comments_page" class="extended_event_pages">'.$comments_form.html_print_table($table_comments, true).'</div>';
} }
@ -6449,10 +6628,6 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep=
*/ */
function events_get_secondary_groups_left_join($table) function events_get_secondary_groups_left_join($table)
{ {
if (users_is_admin()) {
return '';
}
if ($table == 'tevento') { if ($table == 'tevento') {
return 'LEFT JOIN tagent_secondary_group tasg ON te.id_agente = tasg.id_agent'; return 'LEFT JOIN tagent_secondary_group tasg ON te.id_agente = tasg.id_agent';
} }

View File

@ -298,6 +298,52 @@ function groups_get_childrens_ids($parent, $groups=null)
/** /**
* Return a array of id_group of children of given parent.
*
* @param integer $parent The id_grupo parent to search its children.
* @param array $ignorePropagate Ignore propagate.
*/
function groups_get_children($parent, $ignorePropagate=false)
{
static $groups;
if (empty($groups)) {
$groups = db_get_all_rows_in_table('tgrupo');
$groups = array_reduce(
$groups,
function ($carry, $item) {
$carry[$item['id_grupo']] = $item;
return $carry;
}
);
}
$return = [];
foreach ($groups as $key => $g) {
if ($g['id_grupo'] == 0) {
continue;
}
if ($ignorePropagate || $parent == 0 || $groups[$parent]['propagate']) {
if ($g['parent'] == $parent) {
$return += [$g['id_grupo'] => $g];
if ($g['propagate'] || $ignorePropagate) {
$return += groups_get_children(
$g['id_grupo'],
$ignorePropagate
);
}
}
}
}
return $return;
}
/**
* XXX: This is not working. Expects 'propagate' on CHILD not on PARENT!!!
*
* Return a array of id_group of childrens (to branches down) * Return a array of id_group of childrens (to branches down)
* *
* @param integer $parent The id_group parent to search the childrens. * @param integer $parent The id_group parent to search the childrens.

View File

@ -745,7 +745,8 @@ function tags_get_acl_tags(
$meta=false, $meta=false,
$childrens_ids=[], $childrens_ids=[],
$force_group_and_tag=false, $force_group_and_tag=false,
$id_grupo_table_pretag='' $id_grupo_table_pretag='',
$alt_id_grupo_table_pretag=''
) { ) {
global $config; global $config;
@ -820,7 +821,8 @@ function tags_get_acl_tags(
$meta, $meta,
$force_group_and_tag, $force_group_and_tag,
false, false,
$id_grupo_table_pretag $id_grupo_table_pretag,
$alt_id_grupo_table_pretag
); );
if (!empty($condition)) { if (!empty($condition)) {
@ -917,7 +919,8 @@ function tags_get_acl_tags_event_condition(
$meta=false, $meta=false,
$force_group_and_tag=false, $force_group_and_tag=false,
$force_equal=false, $force_equal=false,
$id_grupo_table_pretag='' $id_grupo_table_pretag='',
$alt_id_grupo_table_pretag=''
) { ) {
global $config; global $config;
$condition = []; $condition = [];
@ -935,7 +938,7 @@ function tags_get_acl_tags_event_condition(
// Group condition (The module belongs to an agent of the group X) // Group condition (The module belongs to an agent of the group X)
// $group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));. // $group_condition = sprintf('id_grupo IN (%s)', implode(',', array_values(groups_get_id_recursive($group_id, true))));.
$group_condition = '('.$id_grupo_table_pretag.'id_grupo = '.$group_id.' OR id_group = '.$group_id.')'; $group_condition = '('.$id_grupo_table_pretag.'id_grupo = '.$group_id.' OR '.$alt_id_grupo_table_pretag.'id_group = '.$group_id.')';
// Tags condition (The module has at least one of the restricted tags). // Tags condition (The module has at least one of the restricted tags).
$tags_condition = ''; $tags_condition = '';
@ -971,7 +974,7 @@ function tags_get_acl_tags_event_condition(
} }
$in_group = implode(',', $without_tags); $in_group = implode(',', $without_tags);
$condition .= sprintf('('.$id_grupo_table_pretag.'id_grupo IN (%s) OR id_group IN (%s))', $in_group, $in_group); $condition .= sprintf('('.$id_grupo_table_pretag.'id_grupo IN (%s) OR '.$alt_id_grupo_table_pretag.'id_group IN (%s))', $in_group, $in_group);
} }
$condition = !empty($condition) ? "($condition)" : ''; $condition = !empty($condition) ? "($condition)" : '';

View File

@ -2942,15 +2942,15 @@ function ui_print_datatable(array $parameters)
} }
if (!isset($parameters['order']['field'])) { if (!isset($parameters['order']['field'])) {
$order = 1; $order = 0;
} else { } else {
$order = array_search( $order = array_search(
$parameters['order']['field'], $parameters['order']['field'],
$parameters['columns'] $parameters['columns']
); );
if (empty($order)) { if ($order === false) {
$order = 1; $order = 0;
} }
} }

View File

@ -231,7 +231,6 @@ function get_response(response_id) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: false, async: false,
timeout: 10000,
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
response = data; response = data;
@ -255,7 +254,6 @@ function get_response_params(response_id) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: false, async: false,
timeout: 10000,
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
response_params = data; response_params = data;
@ -279,7 +277,6 @@ function get_response_description(response_id) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: false, async: false,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
response_description = data; response_description = data;
@ -305,7 +302,6 @@ function get_event_name(event_id, meta, history) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: false, async: false,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
name = data; name = data;
@ -349,7 +345,6 @@ function get_response_target(
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: false, async: false,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
target = data; target = data;
@ -394,7 +389,6 @@ function perform_response(target, response_id) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true, async: true,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
var out = data.replace(/[\n|\r]/g, "<br>"); var out = data.replace(/[\n|\r]/g, "<br>");
@ -424,7 +418,6 @@ function perform_response_massive(target, response_id, out_iterator) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true, async: true,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
var out = data.replace(/[\n|\r]/g, "<br>"); var out = data.replace(/[\n|\r]/g, "<br>");
@ -460,7 +453,6 @@ function event_change_status(event_ids) {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true, async: true,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
$("#button-status_button").removeAttr("disabled"); $("#button-status_button").removeAttr("disabled");
@ -499,7 +491,6 @@ function event_change_owner() {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true, async: true,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
$("#button-owner_button").removeAttr("disabled"); $("#button-owner_button").removeAttr("disabled");
@ -553,13 +544,11 @@ function event_comment() {
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
async: true, async: true,
timeout: 10000,
dataType: "html", dataType: "html",
success: function(data) { success: function(data) {
$("#button-comment_button").removeAttr("disabled"); $("#button-comment_button").removeAttr("disabled");
$("#response_loading").show(); $("#response_loading").hide();
dt_events.draw(false); $("#link_comments").click();
show_event_dialog(current_event, "comments", data);
} }
}); });
@ -681,7 +670,6 @@ function update_event(table, id_evento, type, event_rep, row) {
// Update events matching current filters and id_evento selected. // Update events matching current filters and id_evento selected.
$.ajax({ $.ajax({
async: true, async: true,
timeout: 10000,
type: "POST", type: "POST",
url: $("#hidden-ajax_file").val(), url: $("#hidden-ajax_file").val(),
data: { data: {
@ -700,7 +688,7 @@ function update_event(table, id_evento, type, event_rep, row) {
var diff_s = diff_g / 1000; var diff_s = diff_g / 1000;
if (processed >= $(".chk_val:checked").length) { if (processed >= $(".chk_val:checked").length) {
// If operation takes less than 2 seconds, redraw. // If operation takes less than 2 seconds, redraw.
if (diff_s < 2) { if (diff_s < 2 || $(".chk_val:checked").length > 1) {
redraw = true; redraw = true;
} }
if (redraw) { if (redraw) {
@ -722,6 +710,7 @@ function validate_event(table, id_evento, event_rep, row) {
var button = document.getElementById("val-" + id_evento); var button = document.getElementById("val-" + id_evento);
if (!button) { if (!button) {
// Button does not exist. Ignore. // Button does not exist. Ignore.
processed += 1;
return; return;
} }
@ -734,6 +723,7 @@ function in_process_event(table, id_evento, event_rep, row) {
var button = document.getElementById("proc-" + id_evento); var button = document.getElementById("proc-" + id_evento);
if (!button) { if (!button) {
// Button does not exist. Ignore. // Button does not exist. Ignore.
processed += 1;
return; return;
} }
@ -752,6 +742,7 @@ function delete_event(table, id_evento, event_rep, row) {
var button = document.getElementById("del-" + id_evento); var button = document.getElementById("del-" + id_evento);
if (!button) { if (!button) {
// Button does not exist. Ignore. // Button does not exist. Ignore.
processed += 1;
return; return;
} }

View File

@ -1,7 +1,6 @@
<?php <?php
/** /**
* Extension to manage a list of gateways and the node address where they should * Event list.
* point to.
* *
* @category Events * @category Events
* @package Pandora FMS * @package Pandora FMS
@ -45,9 +44,13 @@ require_once $config['homedir'].'/include/functions_ui.php';
// Check access. // Check access.
check_login(); check_login();
if (! check_acl($config['id_user'], 0, 'ER') $event_a = check_acl($config['id_user'], 0, 'ER');
&& ! check_acl($config['id_user'], 0, 'EW') $event_w = check_acl($config['id_user'], 0, 'EW');
&& ! check_acl($config['id_user'], 0, 'EM') $event_m = check_acl($config['id_user'], 0, 'EM');
if (! $event_a
&& ! $event_w
&& ! $event_m
) { ) {
db_pandora_audit( db_pandora_audit(
'ACL Violation', 'ACL Violation',
@ -62,9 +65,6 @@ if (! check_acl($config['id_user'], 0, 'ER')
} }
$event_a = check_acl($config['id_user'], 0, 'ER');
$event_w = check_acl($config['id_user'], 0, 'EW');
$event_m = check_acl($config['id_user'], 0, 'EM');
$access = ($event_a == true) ? 'ER' : (($event_w == true) ? 'EW' : (($event_m == true) ? 'EM' : 'ER')); $access = ($event_a == true) ? 'ER' : (($event_w == true) ? 'EW' : (($event_m == true) ? 'EM' : 'ER'));
@ -88,32 +88,118 @@ if (is_metaconsole()) {
ui_require_javascript_file('pandora_events'); ui_require_javascript_file('pandora_events');
// Get requests. // Get requests.
$id_group = get_parameter('filter[id_group]'); $default_filter = [
$event_type = get_parameter('filter[event_type]'); 'status' => EVENT_NO_VALIDATED,
$severity = get_parameter('filter[severity]'); 'event_view_hr' => $config['event_view_hr'],
$status = get_parameter('filter[status]', EVENT_NO_VALIDATED); 'group_rep' => 1,
$search = get_parameter('filter[search]'); 'tag_with' => [],
$text_agent = get_parameter('filter[text_agent]'); 'tag_without' => [],
$id_agent = get_parameter('filter[id_agent]'); 'history' => false,
$id_agent_module = get_parameter('filter[id_agent_module]'); ];
$pagination = get_parameter('filter[pagination]');
$event_view_hr = get_parameter('filter[event_view_hr]', $config['event_view_hr']); $fb64 = get_parameter('fb64', null);
$id_user_ack = get_parameter('filter[id_user_ack]'); if (isset($fb64)) {
$group_rep = get_parameter('filter[group_rep]', 1); $filter = json_decode(base64_decode($fb64), true);
$tag_with = get_parameter('filter[tag_with]', []); } else {
$tag_without = get_parameter('filter[tag_without]', []); $filter = get_parameter(
$filter_only_alert = get_parameter('filter[filter_only_alert]'); 'filter',
$id_group_filter = get_parameter('filter[id_group_filter]'); $default_filter
$date_from = get_parameter('filter[date_from]'); );
$date_to = get_parameter('filter[date_to]'); }
$source = get_parameter('filter[source]');
$id_extra = get_parameter('filter[id_extra]'); $id_group = get_parameter(
$user_comment = get_parameter('filter[user_comment]'); 'filter[id_group]',
$filter['id_group']
);
$event_type = get_parameter(
'filter[event_type]',
$filter['event_type']
);
$severity = get_parameter(
'filter[severity]',
$filter['severity']
);
$status = get_parameter(
'filter[status]',
$filter['status']
);
$search = get_parameter(
'filter[search]',
$filter['search']
);
$text_agent = get_parameter(
'filter[text_agent]',
$filter['text_agent']
);
$id_agent = get_parameter(
'filter[id_agent]',
$filter['id_agent']
);
$id_agent_module = get_parameter(
'filter[id_agent_module]',
$filter['id_agent_module']
);
$pagination = get_parameter(
'filter[pagination]',
$filter['pagination']
);
$event_view_hr = get_parameter(
'filter[event_view_hr]',
$filter['event_view_hr']
);
$id_user_ack = get_parameter(
'filter[id_user_ack]',
$filter['id_user_ack']
);
$group_rep = get_parameter(
'filter[group_rep]',
$filter['group_rep']
);
$tag_with = get_parameter(
'filter[tag_with]',
$filter['tag_with']
);
$tag_without = get_parameter(
'filter[tag_without]',
$filter['tag_without']
);
$filter_only_alert = get_parameter(
'filter[filter_only_alert]',
$filter['filter_only_alert']
);
$id_group_filter = get_parameter(
'filter[id_group_filter]',
$filter['id_group_filter']
);
$date_from = get_parameter(
'filter[date_from]',
$filter['date_from']
);
$date_to = get_parameter(
'filter[date_to]',
$filter['date_to']
);
$source = get_parameter(
'filter[source]',
$filter['source']
);
$id_extra = get_parameter(
'filter[id_extra]',
$filter['id_extra']
);
$user_comment = get_parameter(
'filter[user_comment]',
$filter['user_comment']
);
$history = get_parameter(
'history',
$filter['history']
);
$section = get_parameter('section', false);
// Ajax responses. // Ajax responses.
if (is_ajax()) { if (is_ajax()) {
$get_events = get_parameter('get_events', 0); $get_events = get_parameter('get_events', 0);
$filter = get_parameter('filter', []);
// Datatables offset, limit. // Datatables offset, limit.
$start = get_parameter('start', 0); $start = get_parameter('start', 0);
$length = get_parameter('length', $config['block_size']); $length = get_parameter('length', $config['block_size']);
@ -123,6 +209,10 @@ if (is_ajax()) {
ob_start(); ob_start();
$order = get_datatable_order(true); $order = get_datatable_order(true);
if (is_array($order) && $order['field'] == 'mini_severity') {
$order['field'] = 'te.criticity';
}
$fields = [ $fields = [
'te.id_evento', 'te.id_evento',
'te.id_agente', 'te.id_agente',
@ -151,11 +241,17 @@ if (is_ajax()) {
'tg.nombre as group_name', 'tg.nombre as group_name',
]; ];
if (!is_metaconsole()) { if (!is_metaconsole()) {
$fields[] = 'am.nombre as id_agentmodule'; $fields[] = 'am.nombre as module_name';
$fields[] = 'am.id_agente_modulo as id_agentmodule';
$fields[] = 'ta.server_name as server_name';
} else {
$fields[] = 'ts.server_name as server_name';
} }
$events = events_get_all( $events = events_get_all(
// Fields.
$fields, $fields,
// Filter.
$filter, $filter,
// Offset. // Offset.
$start, $start,
@ -164,7 +260,9 @@ if (is_ajax()) {
// Order. // Order.
$order['direction'], $order['direction'],
// Sort field. // Sort field.
$order['field'] $order['field'],
// History.
$history
); );
$count = events_get_all( $count = events_get_all(
'count', 'count',
@ -181,6 +279,11 @@ if (is_ajax()) {
function ($carry, $item) { function ($carry, $item) {
$tmp = (object) $item; $tmp = (object) $item;
$tmp->evento = io_safe_output($tmp->evento); $tmp->evento = io_safe_output($tmp->evento);
if ($tmp->module_name) {
$tmp->module_name = io_safe_output($tmp->module_name);
}
$tmp->agent_name = io_safe_output($tmp->agent_name);
$tmp->ack_utimestamp = ui_print_timestamp( $tmp->ack_utimestamp = ui_print_timestamp(
$tmp->ack_utimestamp, $tmp->ack_utimestamp,
true true
@ -191,6 +294,9 @@ if (is_ajax()) {
); );
$tmp->data = format_numeric($tmp->data, 1); $tmp->data = format_numeric($tmp->data, 1);
$tmp->b64 = base64_encode(json_encode($tmp));
$carry[] = $tmp; $carry[] = $tmp;
return $carry; return $carry;
} }
@ -487,34 +593,34 @@ if ($pure) {
// Fullscreen. // Fullscreen.
$fullscreen['active'] = false; $fullscreen['active'] = false;
$fullscreen['text'] = '<a href="'.$url.'&amp;pure=1">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen')]).'</a>'; $fullscreen['text'] = '<a class="events_link" href="'.$url.'&amp;pure=1&">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen')]).'</a>';
// Event list. // Event list.
$list['active'] = false; $list['active'] = false;
$list['text'] = '<a href="index.php?sec=eventos&sec2=operation/events/events&amp;pure='.$config['pure'].'">'.html_print_image('images/events_list.png', true, ['title' => __('Event list')]).'</a>'; $list['text'] = '<a class="events_link" href="index.php?sec=eventos&sec2=operation/events/events&amp;pure='.$config['pure'].'&">'.html_print_image('images/events_list.png', true, ['title' => __('Event list')]).'</a>';
// History event list. // History event list.
$history_list['active'] = false; $history_list['active'] = false;
$history_list['text'] = '<a href="index.php?sec=eventos&sec2=operation/events/events&amp;pure='.$config['pure'].'&amp;section=history&amp;history=1">'.html_print_image('images/books.png', true, ['title' => __('History event list')]).'</a>'; $history_list['text'] = '<a class="events_link" href="index.php?sec=eventos&sec2=operation/events/events&amp;pure='.$config['pure'].'&amp;section=history&amp;history=1&">'.html_print_image('images/books.png', true, ['title' => __('History event list')]).'</a>';
// RSS. // RSS.
$rss['active'] = false; $rss['active'] = false;
$rss['text'] = '<a href="operation/events/events_rss.php?user='.$config['id_user'].'&hashup='.$hashup.'&'.$params.'">'.html_print_image('images/rss.png', true, ['title' => __('RSS Events')]).'</a>'; $rss['text'] = '<a class="events_link" href="operation/events/events_rss.php?user='.$config['id_user'].'&hashup='.$hashup.'&">'.html_print_image('images/rss.png', true, ['title' => __('RSS Events')]).'</a>';
// Marquee. // Marquee.
$marquee['active'] = false; $marquee['active'] = false;
$marquee['text'] = '<a href="operation/events/events_marquee.php">'.html_print_image('images/heart.png', true, ['title' => __('Marquee display')]).'</a>'; $marquee['text'] = '<a class="events_link" href="operation/events/events_marquee.php?">'.html_print_image('images/heart.png', true, ['title' => __('Marquee display')]).'</a>';
// CSV. // CSV.
$csv['active'] = false; $csv['active'] = false;
$csv['text'] = '<a href="operation/events/export_csv.php?'.$params.'">'.html_print_image('images/csv_mc.png', true, ['title' => __('Export to CSV file')]).'</a>'; $csv['text'] = '<a class="events_link" href="operation/events/export_csv.php?'.$filter_b64.'">'.html_print_image('images/csv_mc.png', true, ['title' => __('Export to CSV file')]).'</a>';
// Sound events. // Sound events.
$sound_event['active'] = false; $sound_event['active'] = false;
$sound_event['text'] = '<a href="javascript: openSoundEventWindow();">'.html_print_image('images/sound.png', true, ['title' => __('Sound events')]).'</a>'; $sound_event['text'] = '<a href="javascript: openSoundEventWindow();">'.html_print_image('images/sound.png', true, ['title' => __('Sound events')]).'</a>';
// If the user has administrator permission display manage tab. // If the user has administrator permission display manage tab.
if (check_acl($config['id_user'], 0, 'EW') || check_acl($config['id_user'], 0, 'EM')) { if ($event_w || $event_m) {
// Manage events. // Manage events.
$manage_events['active'] = false; $manage_events['active'] = false;
$manage_events['text'] = '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=filter&amp;pure='.$config['pure'].'">'.html_print_image('images/setup.png', true, ['title' => __('Manage events')]).'</a>'; $manage_events['text'] = '<a href="index.php?sec=eventos&sec2=godmode/events/events&amp;section=filter&amp;pure='.$config['pure'].'">'.html_print_image('images/setup.png', true, ['title' => __('Manage events')]).'</a>';
@ -791,12 +897,14 @@ $buttons[] = [
'onclick' => '', 'onclick' => '',
]; ];
if ($event_w || $event_m) {
$buttons[] = [ $buttons[] = [
'id' => 'save-filter', 'id' => 'save-filter',
'class' => 'float-left margin-right-2 sub wand', 'class' => 'float-left margin-right-2 sub wand',
'text' => __('Save filter'), 'text' => __('Save filter'),
'onclick' => '', 'onclick' => '',
]; ];
}
/* /*
* Advanced filter. * Advanced filter.
@ -1067,6 +1175,10 @@ try {
'text' => 'evento', 'text' => 'evento',
'class' => 'mw120px', 'class' => 'mw120px',
], ],
[
'text' => 'mini_severity',
'class' => 'no-padding',
],
'id_evento', 'id_evento',
// 'id_agente', // 'id_agente',
// 'id_usuario', // 'id_usuario',
@ -1112,6 +1224,12 @@ try {
$fields = $default_fields; $fields = $default_fields;
} }
if (in_array('mini_severity', $fields) > 0) {
$fields[array_search('mini_severity', $fields)] = [
'text' => 'mini_severity',
'class' => 'no-padding-imp',
];
}
$evento_id = array_search('evento', $fields); $evento_id = array_search('evento', $fields);
if ($evento_id !== false) { if ($evento_id !== false) {
@ -1219,6 +1337,7 @@ try {
$active_filters_div .= '</div>'; $active_filters_div .= '</div>';
$table_id = 'events'; $table_id = 'events';
$form_id = 'events_form';
// Print datatable. // Print datatable.
ui_print_datatable( ui_print_datatable(
@ -1227,9 +1346,12 @@ try {
'class' => 'info_table events', 'class' => 'info_table events',
'style' => 'width: 100%;', 'style' => 'width: 100%;',
'ajax_url' => 'operation/events/events', 'ajax_url' => 'operation/events/events',
'ajax_data' => ['get_events' => 1], 'ajax_data' => [
'get_events' => 1,
'history' => (int) $history,
],
'form' => [ 'form' => [
'id' => 'events_form', 'id' => $form_id,
'class' => 'flex-row', 'class' => 'flex-row',
'html' => $filter, 'html' => $filter,
'inputs' => [], 'inputs' => [],
@ -1280,20 +1402,22 @@ try {
$sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'"; $sql_event_resp = "SELECT id, name FROM tevent_response WHERE type LIKE 'command'";
$event_responses = db_get_all_rows_sql($sql_event_resp); $event_responses = db_get_all_rows_sql($sql_event_resp);
if (check_acl($config['id_user'], 0, 'EW') == 1 && !$readonly) { if ($config['event_replication'] != 1) {
if ($event_w && !$readonly) {
$array_events_actions['in_progress_selected'] = __('In progress selected'); $array_events_actions['in_progress_selected'] = __('In progress selected');
$array_events_actions['validate_selected'] = __('Validate selected'); $array_events_actions['validate_selected'] = __('Validate selected');
} }
if (check_acl($config['id_user'], 0, 'EM') == 1 && !$readonly) { if ($event_m == 1 && !$readonly) {
$array_events_actions['delete_selected'] = __('Delete selected'); $array_events_actions['delete_selected'] = __('Delete selected');
} }
}
foreach ($event_responses as $val) { foreach ($event_responses as $val) {
$array_events_actions[$val['id']] = $val['name']; $array_events_actions[$val['id']] = $val['name'];
} }
if ($config['event_replication'] != 1) {
echo '<div class="multi-response-buttons">'; echo '<div class="multi-response-buttons">';
echo '<form method="post" id="form_event_response">'; echo '<form method="post" id="form_event_response">';
echo '<input type="hidden" id="max_execution_event_response" value="'.$config['max_execution_event_response'].'" />'; echo '<input type="hidden" id="max_execution_event_response" value="'.$config['max_execution_event_response'].'" />';
@ -1312,7 +1436,7 @@ if ($config['event_replication'] != 1) {
'Please, select an event' 'Please, select an event'
).'</span>'; ).'</span>';
echo '</div>'; echo '</div>';
}
// Close viewer. // Close viewer.
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
@ -1477,16 +1601,17 @@ function process_datatables_item(item) {
output += '</div>'; output += '</div>';
// Add event severity to end of text. // Add event severity to end of text.
evn = '<div class="event flex-row h100p nowrap">'; evn = '<a href="javascript:" onclick="show_event_dialog(\'';
evn += '<div><a href="javascript:" onclick="show_event_dialog(\''; evn += item.b64+'\','+$("#group_rep").val()+');">';
evn += btoa(JSON.stringify(item))+'\','+$("#group_rep").val()+');">';
// Grouped events. // Grouped events.
if(item.event_rep && item.event_rep > 1) { if(item.event_rep && item.event_rep > 1) {
evn += '('+item.event_rep+') '; evn += '('+item.event_rep+') ';
} }
evn += item.evento+'</a></div>'; evn += item.evento+'</a>';
evn += output;
evn += '</div>' item.mini_severity = '<div class="event flex-row h100p nowrap">';
item.mini_severity += output;
item.mini_severity += '</div>';
criticity = '<div class="criticity" style="background: '; criticity = '<div class="criticity" style="background: ';
criticity += color + '">' + text + "</div>"; criticity += color + '">' + text + "</div>";
@ -1517,7 +1642,7 @@ function process_datatables_item(item) {
case "<?php echo EVENTS_GOING_UP_WARNING; ?>": case "<?php echo EVENTS_GOING_UP_WARNING; ?>":
case "<?php echo EVENTS_GOING_DOWN_WARNING; ?>": case "<?php echo EVENTS_GOING_DOWN_WARNING; ?>":
$tex = "<?php echo __('WARNING'); ?>"; text = "<?php echo __('WARNING'); ?>";
color = "<?php echo COL_WARNING; ?>"; color = "<?php echo COL_WARNING; ?>";
break; break;
@ -1580,42 +1705,10 @@ function process_datatables_item(item) {
module_status = '<div class="criticity" style="background: '; module_status = '<div class="criticity" style="background: ';
module_status += color + '">' + text + "</div>"; module_status += color + '">' + text + "</div>";
/* Agent name link */
if (item.id_agente > 0) {
item.agent_name = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>' +item.id_agente+'">' + item.agent_name + '</a>';
} else {
item.agent_name = '';
}
/* Agent ID link */
if (item.id_agente > 0) {
<?php
if (in_array('agent_name', $fields)) {
?>
item.id_agente = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>'+item.id_agente+'">' + item.id_agente + '</a>';
<?php
} else {
?>
item.id_agente = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>'+item.id_agente+'">' + item.agent_name + '</a>';
<?php
}
?>
} else {
item.id_agente = '';
}
/* Group name */
if (item.id_grupo == "0") {
item.id_grupo = "<?php echo __('All'); ?>";
} else {
item.id_grupo = item.group_name;
}
/* Options */ /* Options */
// Show more. // Show more.
item.options = '<a href="javascript:" onclick="show_event_dialog(\''; item.options = '<a href="javascript:" onclick="show_event_dialog(\'';
item.options += btoa(JSON.stringify(item))+'\','+$("#group_rep").val(); item.options += item.b64+'\','+$("#group_rep").val();
item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>'; item.options += ')" ><?php echo html_print_image('images/eye.png', true, ['title' => __('Show more')]); ?></a>';
<?php <?php
@ -1658,6 +1751,9 @@ function process_datatables_item(item) {
item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete event')]); ?></a>'; item.options += '<?php echo html_print_image('images/cross.png', true, ['title' => __('Delete event')]); ?></a>';
} }
} }
<?php
}
?>
// Multi select. // Multi select.
item.m = '<input name="checkbox-multi[]" type="checkbox" value="'; item.m = '<input name="checkbox-multi[]" type="checkbox" value="';
@ -1668,27 +1764,49 @@ function process_datatables_item(item) {
item.m += ' event_rep="0" '; item.m += ' event_rep="0" ';
} }
item.m += 'class="candeleted chk_val">'; item.m += 'class="candeleted chk_val">';
<?php
}
?>
/* Status */ /* Status */
img = '<?php echo html_print_image('images/star.png', true, ['title' => __('Unknown'), 'class' => 'forced-title']); ?>'; img = '<?php echo html_print_image('images/star.png', true, ['title' => __('Unknown'), 'class' => 'forced-title']); ?>';
switch (item.estado) { switch (item.estado) {
case "0": case "<?php echo EVENT_STATUS_NEW; ?>":
img = '<?php echo html_print_image('images/star.png', true, ['title' => __('New event'), 'class' => 'forced-title']); ?>'; img = '<?php echo html_print_image('images/star.png', true, ['title' => __('New event'), 'class' => 'forced-title']); ?>';
break; break;
case "1": case "<?php echo EVENT_STATUS_VALIDATED; ?>":
img = '<?php echo html_print_image('images/tick.png', true, [ 'title' => __('Event validated'), 'class' => 'forced-title']); ?>'; img = '<?php echo html_print_image('images/tick.png', true, [ 'title' => __('Event validated'), 'class' => 'forced-title']); ?>';
break; break;
case "2": case "<?php echo EVENT_STATUS_INPROCESS; ?>":
img = '<?php echo html_print_image('images/hourglass.png', true, [ 'title' => __('Event in process'), 'class' => 'forced-title']); ?>'; img = '<?php echo html_print_image('images/hourglass.png', true, [ 'title' => __('Event in process'), 'class' => 'forced-title']); ?>';
break; break;
} }
/* Update column content now to avoid json poisoning. */ /* Update column content now to avoid json poisoning. */
/* Agent name link */
if (item.id_agente > 0) {
item.agent_name = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>' +item.id_agente+'">' + item.agent_name + '</a>';
} else {
item.agent_name = '';
}
/* Agent ID link */
if (item.id_agente > 0) {
<?php
if (in_array('agent_name', $fields)) {
?>
item.id_agente = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>'+item.id_agente+'">' + item.id_agente + '</a>';
<?php
} else {
?>
item.id_agente = '<a href="<?php echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='); ?>'+item.id_agente+'">' + item.agent_name + '</a>';
<?php
}
?>
} else {
item.id_agente = '';
}
item.estado = '<div>'; item.estado = '<div>';
item.estado += img; item.estado += img;
item.estado += '</div>'; item.estado += '</div>';
@ -1708,6 +1826,15 @@ function process_datatables_item(item) {
// Add event severity format to itself. // Add event severity format to itself.
item.evento = evn; item.evento = evn;
/* Group name */
if (item.id_grupo == "0") {
item.id_grupo = "<?php echo __('All'); ?>";
} else {
item.id_grupo = item.group_name;
}
/* Module name */
item.id_agentmodule = item.module_name;
} }
/* Datatables auxiliary functions ends */ /* Datatables auxiliary functions ends */
@ -1957,6 +2084,23 @@ function reorder_tags_inputs() {
} }
/* Tag management ends */ /* Tag management ends */
$(document).ready( function() { $(document).ready( function() {
/* Filter to a href */
$('.events_link').on('click', function(e) {
e.preventDefault();
inputs = $("#<?php echo $form_id; ?> :input");
values = {};
inputs.each(function() {
values[this.name] = $(this).val();
})
values['history'] = "<?php echo (int) $history; ?>";
var url = e.currentTarget.href;
url += 'fb64=' + btoa(JSON.stringify(values));
document.location = url;
});
/* Multi select handler */ /* Multi select handler */
$('#checkbox-all_validate_box').on('change', function() { $('#checkbox-all_validate_box').on('change', function() {

View File

@ -1,18 +1,37 @@
<?php <?php
/**
* Event RSS exporter.
*
* @category Event RSS export
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 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.
* ============================================================================
*/
// Load global vars.
global $config;
// Don't display other errors, messes up XML.
ini_set('display_errors', E_ALL);
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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.
ini_set('display_errors', 0);
// Don't display other errors, messes up XML
require_once '../../include/config.php'; require_once '../../include/config.php';
require_once '../../include/functions.php'; require_once '../../include/functions.php';
require_once '../../include/functions_db.php'; require_once '../../include/functions_db.php';
@ -22,65 +41,115 @@ require_once '../../include/functions_users.php';
require_once '../../include/functions_tags.php'; require_once '../../include/functions_tags.php';
require_once '../../include/functions_groups.php'; require_once '../../include/functions_groups.php';
$ipOrigin = $_SERVER['REMOTE_ADDR'];
// Uncoment this to activate ACL on RSS Events /**
if (!isInACL($ipOrigin)) { * Generates an xml entry.
rss_error_handler( *
null, * @param string $key Key.
null, * @param string $value Value.
null, *
null, * @return string XML entry.
__('Your IP is not into the IP list with API access.') */
); function xml_entry($key, $value)
{
exit; $output = '<'.xml_entities($key).'>';
$output .= '<![CDATA['.io_safe_output($value).']]>';
$output .= '</'.xml_entities($key).'>';
return $output."\n";
} }
// Check user credentials
$user = get_parameter('user');
$hashup = get_parameter('hashup');
$pss = get_user_info($user); /**
$hashup2 = md5($user.$pss['password']); * Escape entities for XML.
*
if ($hashup != $hashup2) { * @param string $str String.
rss_error_handler( *
null, * @return string Escaped string.
null, */
null, function xml_entities($str)
null, {
__('The URL of your feed has bad hash.') if (!is_string($str)) {
); return '';
exit;
} }
header('Content-Type: application/xml; charset=UTF-8'); if (preg_match_all('/(&[^;]+;)/', $str, $matches) != 0) {
// Send header before starting to output $matches = $matches[0];
foreach ($matches as $entity) {
$char = html_entity_decode($entity, (ENT_COMPAT | ENT_HTML401), 'UTF-8');
$html_entity_numeric = '&#'.uniord($char).';';
$str = str_replace($entity, $html_entity_numeric, $str);
}
}
return $str;
}
/**
* Undocumented function.
*
* @param string $u U.
*
* @return integer Ord.
*/
function uniord($u)
{
$k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));
return ($k2 * 256 + $k1);
}
/**
* Generate RSS header.
*
* @param integer $lastbuild Date, last build.
*
* @return string RSS header.
*/
function rss_header($lastbuild=0)
{
$selfurl = ui_get_full_url('?'.$_SERVER['QUERY_STRING'], false, true);
// ' <?php ' -- Fixes highlighters thinking that the closing tag is PHP
$rss_feed = '<?xml version="1.0" encoding="utf-8" ?>'."\n";
$rss_feed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
$rss_feed .= '<channel>'."\n";
$rss_feed .= '<title>'.io_safe_output(get_product_name()).' Events Feed</title>'."\n";
$rss_feed .= '<description>Latest events on '.get_product_name().'</description>'."\n";
$rss_feed .= '<lastBuildDate>'.date(DATE_RFC822, $lastbuild).'</lastBuildDate>'."\n";
// Last build date is the last event - that way readers won't mark it as having new posts.
$rss_feed .= '<link>'.$url.'</link>'."\n";
// Link back to the main Pandora page.
$rss_feed .= '<atom:link href="'.xml_entities(io_safe_input($selfurl)).'" rel="self" type="application/rss+xml" />'."\n";
return $rss_feed;
}
/**
* RSS error handler.
*
* @param string $errno Errno.
* @param string $errstr Errstr.
* @param string $errfile Errfile.
* @param string $errline Errline.
* @param string $error_human_description Error_human_description.
*
* @return void
*/
function rss_error_handler($errno, $errstr, $errfile, $errline, $error_human_description=null) function rss_error_handler($errno, $errstr, $errfile, $errline, $error_human_description=null)
{ {
$url = ui_get_full_url(false); $url = ui_get_full_url(false);
$selfurl = ui_get_full_url('?'.$_SERVER['QUERY_STRING'], false, true); $selfurl = ui_get_full_url('?'.$_SERVER['QUERY_STRING'], false, true);
$rss_feed = '<?xml version="1.0" encoding="utf-8" ?>'; // ' Fixes certain highlighters freaking out on the PHP closing tag.
// ' Fixes certain highlighters freaking out on the PHP closing tag $rss_feed = rss_header(0);
$rss_feed .= "\n";
$rss_feed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$rss_feed .= "\n";
$rss_feed .= '<channel>';
$rss_feed .= "\n";
$rss_feed .= '<title>'.get_product_name().' RSS Feed</title>';
$rss_feed .= "\n";
$rss_feed .= '<description>Latest events on '.get_product_name().'</description>';
$rss_feed .= "\n";
$rss_feed .= '<lastBuildDate>'.date(DATE_RFC822, 0).'</lastBuildDate>';
$rss_feed .= "\n";
$rss_feed .= '<link>'.$url.'</link>';
// Link back to the main Pandora page
$rss_feed .= "\n";
$rss_feed .= '<atom:link href="'.xml_entities(io_safe_input($selfurl)).'" rel="self" type="application/rss+xml" />';
// Alternative for Atom feeds. It's the same.
$rss_feed .= "\n"; $rss_feed .= "\n";
$rss_feed .= '<item>'; $rss_feed .= '<item>';
$rss_feed .= "\n"; $rss_feed .= "\n";
@ -104,169 +173,206 @@ function rss_error_handler($errno, $errstr, $errfile, $errline, $error_human_des
$rss_feed .= "\n"; $rss_feed .= "\n";
$rss_feed .= '</rss>'; $rss_feed .= '</rss>';
exit($rss_feed);
// Exit by displaying the feed
}
set_error_handler('rss_error_handler', E_ERROR);
// Errors output as RSS
$id_group = get_parameter('id_group', 0);
// group
$event_type = get_parameter('event_type', '');
// 0 all
$severity = (int) get_parameter('severity', -1);
// -1 all
$status = (int) get_parameter('status', 0);
// -1 all, 0 only red, 1 only green
$id_agent = (int) get_parameter('id_agent', -1);
$id_event = (int) get_parameter('id_event', -1);
// This will allow to select only 1 event (eg. RSS)
$event_view_hr = (int) get_parameter('event_view_hr', 0);
$id_user_ack = get_parameter('id_user_ack', 0);
$search = io_safe_output(preg_replace('/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', rawurldecode(get_parameter('search'))));
$text_agent = (string) get_parameter('text_agent', __('All'));
$tag_with_json = base64_decode(get_parameter('tag_with', ''));
$tag_with_json_clean = io_safe_output($tag_with_json);
$tag_with_base64 = base64_encode($tag_with_json_clean);
$tag_with = json_decode($tag_with_json_clean, true);
if (empty($tag_with)) {
$tag_with = [];
}
$tag_with = array_diff($tag_with, [0 => 0]);
$tag_without_json = base64_decode(get_parameter('tag_without', ''));
$tag_without_json_clean = io_safe_output($tag_without_json);
$tag_without_base64 = base64_encode($tag_without_json_clean);
$tag_without = json_decode($tag_without_json_clean, true);
if (empty($tag_without)) {
$tag_without = [];
}
$tag_without = array_diff($tag_without, [0 => 0]);
$filter_only_alert = (int) get_parameter('filter_only_alert', -1);
//
// Build the condition of the events query
$sql_post = '';
$meta = false;
$id_user = $user;
require 'events.build_query.php';
// Now $sql_post have all the where condition
//
$sql = 'SELECT *
FROM tevento te LEFT JOIN tagent_secondary_group tasg
ON te.id_grupo = tasg.id_group
WHERE 1=1 '.$sql_post.'
ORDER BY utimestamp DESC';
$result = db_get_all_rows_sql($sql);
$url = ui_get_full_url(false);
$selfurl = ui_get_full_url('?'.$_SERVER['QUERY_STRING'], false, true);
if (empty($result)) {
$lastbuild = 0;
// Last build in 1970
} else {
$lastbuild = (int) $result[0]['utimestamp'];
}
$rss_feed = '<?xml version="1.0" encoding="utf-8" ?>'."\n";
// ' <?php ' -- Fixes highlighters thinking that the closing tag is PHP
$rss_feed .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
$rss_feed .= '<channel>'."\n";
$rss_feed .= '<title>'.get_product_name().' RSS Feed</title>'."\n";
$rss_feed .= '<description>Latest events on '.get_product_name().'</description>'."\n";
$rss_feed .= '<lastBuildDate>'.date(DATE_RFC822, $lastbuild).'</lastBuildDate>'."\n";
// Last build date is the last event - that way readers won't mark it as having new posts
$rss_feed .= '<link>'.$url.'</link>'."\n";
// Link back to the main Pandora page
$rss_feed .= '<atom:link href="'.xml_entities(io_safe_input($selfurl)).'" rel="self" type="application/rss+xml" />'."\n";
;
// Alternative for Atom feeds. It's the same.
if (empty($result)) {
$result = [];
$rss_feed .= '<item><guid>'.xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events')).'</guid><title>No results</title>';
$rss_feed .= '<description>There are no results. Click on the link to see all Pending events</description>';
$rss_feed .= '<link>'.xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events')).'</link></item>'."\n";
}
foreach ($result as $row) {
if (!check_acl($user, $row['id_grupo'], 'ER')) {
continue;
}
if ($row['event_type'] == 'system') {
$agent_name = __('System');
} else if ($row['id_agente'] > 0) {
// Agent name
$agent_name = agents_get_alias($row['id_agente']);
} else {
$agent_name = __('Alert').__('SNMP');
}
// This is mandatory
$rss_feed .= '<item><guid>';
$rss_feed .= xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events&id_event='.$row['id_evento']));
$rss_feed .= '</guid><title>';
$rss_feed .= xml_entities($agent_name);
$rss_feed .= '</title><description>';
$rss_feed .= xml_entities($row['evento']);
if ($row['estado'] == 1) {
$rss_feed .= xml_entities(io_safe_input('<br /><br />'.'Validated by '.$row['id_usuario']));
}
$rss_feed .= '</description><link>';
$rss_feed .= xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events&id_event='.$row['id_evento']));
$rss_feed .= '</link>';
// The rest is optional
$rss_feed .= '<pubDate>'.date(DATE_RFC822, $row['utimestamp']).'</pubDate>';
// This is mandatory again
$rss_feed .= '</item>'."\n";
}
$rss_feed .= "</channel>\n</rss>\n";
echo $rss_feed; echo $rss_feed;
function xml_entities($str)
{
if (!is_string($str)) {
return '';
}
if (preg_match_all('/(&[^;]+;)/', $str, $matches) != 0) {
$matches = $matches[0];
foreach ($matches as $entity) {
$char = html_entity_decode($entity, (ENT_COMPAT | ENT_HTML401), 'UTF-8');
$html_entity_numeric = '&#'.uniord($char).';';
$str = str_replace($entity, $html_entity_numeric, $str);
}
}
return $str;
} }
function uniord($u) // Errors output as RSS.
{ set_error_handler('rss_error_handler', E_ERROR);
$k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
$k1 = ord(substr($k, 0, 1));
$k2 = ord(substr($k, 1, 1));
return ($k2 * 256 + $k1); // Send header before starting to output.
header('Content-Type: application/xml; charset=UTF-8');
$ipOrigin = $_SERVER['REMOTE_ADDR'];
// Uncoment this to activate ACL on RSS Events.
if (!isInACL($ipOrigin)) {
rss_error_handler(
null,
null,
null,
null,
__('Your IP is not into the IP list with API access.')
);
exit;
}
// Check user credentials.
$user = get_parameter('user');
$hashup = get_parameter('hashup');
$pss = get_user_info($user);
$hashup2 = md5($user.$pss['password']);
if ($hashup != $hashup2) {
rss_error_handler(
null,
null,
null,
null,
__('The URL of your feed has bad hash.')
);
exit;
}
$reset_session = false;
if (empty($config['id_user'])) {
$config['id_user'] = $user;
$reset_session = true;
}
$column_names = [
'id_evento',
'evento',
'timestamp',
'estado',
'event_type',
'utimestamp',
'id_agente',
'agent_name',
'id_usuario',
'id_grupo',
'id_agentmodule',
'id_alert_am',
'criticity',
'user_comment',
'tags',
'source',
'id_extra',
'critical_instructions',
'warning_instructions',
'unknown_instructions',
'owner_user',
'ack_utimestamp',
'custom_data',
'data',
'module_status',
];
$fields = [
'te.id_evento',
'te.evento',
'te.timestamp',
'te.estado',
'te.event_type',
'te.utimestamp',
'te.id_agente',
'ta.alias as agent_name',
'te.id_usuario',
'te.id_grupo',
'te.id_agentmodule',
'am.nombre as module_name',
'te.id_alert_am',
'te.criticity',
'te.user_comment',
'te.tags',
'te.source',
'te.id_extra',
'te.critical_instructions',
'te.warning_instructions',
'te.unknown_instructions',
'te.owner_user',
'te.ack_utimestamp',
'te.custom_data',
'te.data',
'te.module_status',
'tg.nombre as group_name',
];
try {
$fb64 = get_parameter('fb64', null);
$plain_filter = base64_decode($fb64);
$filter = json_decode($plain_filter, true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new Exception('Invalid filter. ['.$plain_filter.']');
}
// Dump events.
$limit = get_parameter('limit', 20);
$offset = get_parameter('offset', 0);
$events = events_get_all(
$fields,
$filter,
$offset,
$limit,
'desc',
'timestamp',
$filter['history']
);
$last_timestamp = 0;
if (is_array($events)) {
$last_timestamp = $events[0]['utimestamp'];
}
// Dump headers.
$rss = rss_header($last_timestamp);
$url = ui_get_full_url(false);
if (is_array($events)) {
foreach ($events as $row) {
$rss .= '<item>';
$rss .= xml_entry('title', $row['evento']);
if (!empty($row['id_agente'])) {
$rss .= xml_entry('link', $url.'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$row['id_agente']);
}
$rss .= xml_entry('comments', $row['']);
$rss .= xml_entry('pubDate', $row['timestamp']);
$rss .= xml_entry('category', $row['source']);
foreach ($column_names as $val) {
$key = $val;
if ($val == 'id_grupo') {
$key = 'group_name';
} else if ($val == 'id_agentmodule') {
$key = 'module_name';
}
switch ($key) {
case 'module_status':
$value = events_translate_module_status(
$row[$key]
);
break;
case 'event_type':
$value = events_translate_event_type(
$row[$key]
);
break;
case 'criticity':
$value = events_translate_event_criticity(
$row[$key]
);
break;
default:
$value = $row[$key];
break;
}
$rss .= xml_entry($key, $value);
}
$rss .= '</item>';
}
} else {
$rss .= '<item><guid>'.xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events')).'</guid><title>No results</title>';
$rss .= '<description>There are no results. Click on the link to see all Pending events</description>';
$rss .= '<link>'.xml_entities(io_safe_input($url.'/index.php?sec=eventos&sec2=operation/events/events')).'</link></item>'."\n";
}
$rss .= "</channel>\n</rss>\n";
echo $rss;
} catch (Exception $e) {
echo rss_error_handler(200, 'Controlled error', '', '', $e->getMessage());
}
if ($reset_session) {
unset($config['id_user']);
} }

View File

@ -1,18 +1,34 @@
<?php <?php
/**
* Event CSV exporter.
*
* @category Event CSV export
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 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.
* ============================================================================
*/
// Load global vars.
global $config;
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 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.
// Don't start a session before this import.
// The session is configured and started inside the config process.
require_once '../../include/config.php'; require_once '../../include/config.php';
require_once '../../include/auth/mysql.php'; require_once '../../include/auth/mysql.php';
require_once '../../include/functions.php'; require_once '../../include/functions.php';
@ -23,134 +39,165 @@ require_once '../../include/functions_groups.php';
$config['id_user'] = $_SESSION['id_usuario']; $config['id_user'] = $_SESSION['id_usuario'];
if (! check_acl($config['id_user'], 0, 'ER') && ! check_acl($config['id_user'], 0, 'EW') && ! check_acl($config['id_user'], 0, 'EM')) { if (! check_acl($config['id_user'], 0, 'ER')
&& ! check_acl($config['id_user'], 0, 'EW')
&& ! check_acl($config['id_user'], 0, 'EM')
) {
exit; exit;
} }
global $config; // Loading l10n tables, because of being invoked not through index.php.
// loading l10n tables, because of being invoked not through index.php.
$l10n = null; $l10n = null;
if (file_exists($config['homedir'].'/include/languages/'.$user_language.'.mo')) { if (file_exists($config['homedir'].'/include/languages/'.$user_language.'.mo')) {
$l10n = new gettext_reader(new CachedFileReader($config['homedir'].'/include/languages/'.$user_language.'.mo')); $cfr = new CachedFileReader(
$config['homedir'].'/include/languages/'.$user_language.'.mo'
);
$l10n = new gettext_reader($cfr);
$l10n->load_tables(); $l10n->load_tables();
} }
$offset = (int) get_parameter('offset'); $column_names = [
$id_group = (int) get_parameter('id_group'); 'id_evento',
// group 'evento',
$event_type = (string) get_parameter('event_type', 'all'); 'timestamp',
// 0 all 'estado',
$severity = (int) get_parameter('severity', -1); 'event_type',
// -1 all 'utimestamp',
$status = (int) get_parameter('status', -1); 'id_agente',
// -1 all, 0 only red, 1 only green 'agent_name',
$id_agent = (int) get_parameter('id_agent', -1); 'id_usuario',
'id_grupo',
'id_agentmodule',
'id_alert_am',
'criticity',
'user_comment',
'tags',
'source',
'id_extra',
'critical_instructions',
'warning_instructions',
'unknown_instructions',
'owner_user',
'ack_utimestamp',
'custom_data',
'data',
'module_status',
];
$id_event = (int) get_parameter('id_event', -1); $fields = [
$event_view_hr = (int) get_parameter('event_view_hr', $config['event_view_hr']); 'te.id_evento',
$id_user_ack = get_parameter('id_user_ack', 0); 'te.evento',
$search = io_safe_output(preg_replace('/&([A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', rawurldecode(get_parameter('search')))); 'te.timestamp',
$text_agent = (string) get_parameter('text_agent', __('All')); 'te.estado',
'te.event_type',
$tag_with_json = base64_decode(get_parameter('tag_with', '')); 'te.utimestamp',
$tag_with_json_clean = io_safe_output($tag_with_json); 'te.id_agente',
$tag_with_base64 = base64_encode($tag_with_json_clean); 'ta.alias as agent_name',
$tag_with = json_decode($tag_with_json_clean, true); 'te.id_usuario',
if (empty($tag_with)) { 'te.id_grupo',
$tag_with = []; 'te.id_agentmodule',
} 'am.nombre as module_name',
'te.id_alert_am',
$tag_with = array_diff($tag_with, [0 => 0]); 'te.criticity',
'te.user_comment',
$tag_without_json = base64_decode(get_parameter('tag_without', '')); 'te.tags',
$tag_without_json_clean = io_safe_output($tag_without_json); 'te.source',
$tag_without_base64 = base64_encode($tag_without_json_clean); 'te.id_extra',
$tag_without = json_decode($tag_without_json_clean, true); 'te.critical_instructions',
if (empty($tag_without)) { 'te.warning_instructions',
$tag_without = []; 'te.unknown_instructions',
} 'te.owner_user',
'te.ack_utimestamp',
$tag_without = array_diff($tag_without, [0 => 0]); 'te.custom_data',
'te.data',
$filter_only_alert = (int) get_parameter('filter_only_alert', -1); 'te.module_status',
'tg.nombre as group_name',
// ];
// Build the condition of the events query
$sql_post = '';
$meta = false;
$id_user = $config['id_user'];
require 'events.build_query.php';
// Now $sql_post have all the where condition
//
switch ($config['dbtype']) {
case 'mysql':
case 'postgresql':
case 'oracle':
$sql = 'SELECT *
FROM tevento te
LEFT JOIN tagent_secondary_group tasg
ON te.id_grupo = tasg.id_group
WHERE 1=1 '.$sql_post.'
ORDER BY utimestamp DESC';
break;
}
$now = date('Y-m-d'); $now = date('Y-m-d');
// Show contentype header // Download header.
header('Content-type: text/txt'); header('Content-type: text/txt');
header('Content-Disposition: attachment; filename="pandora_export_event'.$now.'.csv"'); header('Content-Disposition: attachment; filename="pandora_export_event'.$now.'.csv"');
echo 'timestamp'; try {
echo $config['csv_divider']; $fb64 = get_parameter('fb64', null);
echo 'agent'; $plain_filter = base64_decode($fb64);
echo $config['csv_divider']; $filter = json_decode($plain_filter, true);
echo 'group'; if (json_last_error() != JSON_ERROR_NONE) {
echo $config['csv_divider']; throw new Exception('Invalid filter. ['.$plain_filter.']');
echo 'event'; }
echo $config['csv_divider'];
echo 'status'; $names = events_get_column_names($column_names);
echo $config['csv_divider'];
echo 'user'; // Dump headers.
echo $config['csv_divider']; foreach ($names as $n) {
echo 'event_type'; echo io_safe_output($n).$config['csv_divider'];
echo $config['csv_divider']; }
echo 'severity';
echo $config['csv_divider']; echo chr(13);
echo 'id';
echo chr(13); // Dump events.
$events_per_step = 1000;
$new = true; $step = 0;
while ($event = db_get_all_row_by_steps_sql($new, $result, $sql)) { while (1) {
$new = false; $events = events_get_all(
$alias = db_get_value('alias', 'tagente', 'id_agente', $event['id_agente']); $fields,
if ((!check_acl($config['id_user'], $event['id_grupo'], 'ER') $filter,
&& !check_acl($config['id_user'], $event['id_grupo'], 'EW') && !check_acl($config['id_user'], $event['id_grupo'], 'EM') ) (($step++) * $events_per_step),
|| (!check_acl($config['id_user'], 0, 'PM') && $event['event_type'] == 'system') $events_per_step,
) { 'desc',
continue; 'timestamp',
$filter['history']
);
if ($events === false) {
break;
}
foreach ($events as $row) {
foreach ($column_names as $val) {
$key = $val;
if ($val == 'id_grupo') {
$key = 'group_name';
} else if ($val == 'id_agentmodule') {
$key = 'module_name';
}
switch ($key) {
case 'module_status':
echo events_translate_module_status(
$row[$key]
);
break;
case 'event_type':
echo events_translate_event_type(
$row[$key]
);
break;
case 'criticity':
echo events_translate_event_criticity(
$row[$key]
);
break;
default:
echo io_safe_output($row[$key]);
break;
} }
echo date($config['date_format'], $event['utimestamp']);
echo $config['csv_divider']; echo $config['csv_divider'];
echo io_safe_output($alias); }
echo $config['csv_divider'];
echo io_safe_output(groups_get_name($event['id_grupo']));
echo $config['csv_divider'];
echo io_safe_output($event['evento']);
echo $config['csv_divider'];
echo io_safe_output($event['estado']);
echo $config['csv_divider'];
echo io_safe_output($event['id_usuario']);
echo $config['csv_divider'];
echo io_safe_output($event['event_type']);
echo $config['csv_divider'];
echo $event['criticity'];
echo $config['csv_divider'];
echo $event['id_evento'];
echo chr(13); echo chr(13);
} }
}
} catch (Exception $e) {
echo 'ERROR'.chr(13);
echo $e->getMessage();
exit;
}
exit;

View File

@ -373,10 +373,36 @@ if (check_acl($config['id_user'], 0, 'ER')
$pss = get_user_info($config['id_user']); $pss = get_user_info($config['id_user']);
$hashup = md5($config['id_user'].$pss['password']); $hashup = md5($config['id_user'].$pss['password']);
$user_filter = db_get_row_sql(
sprintf(
'SELECT f.id_filter, f.id_name
FROM tevent_filter f
INNER JOIN tusuario u
ON u.default_event_filter=f.id_filter
WHERE u.id_user = "%s" ',
$config['id_user']
)
);
if ($user_filter !== false) {
$filter = events_get_event_filter($user_filter['id_filter']);
} else {
// Default.
$filter = [
'status' => EVENT_NO_VALIDATED,
'event_view_hr' => $config['event_view_hr'],
'group_rep' => 1,
'tag_with' => [],
'tag_without' => [],
'history' => false,
];
}
$fb64 = base64_encode(json_encode($filter));
// RSS. // RSS.
$sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&search=&event_type=&severity=-1&status=3&id_group=0&refr=0&id_agent=0&pagination=20&group_rep=1&event_view_hr=8&id_user_ack=0&tag_with=&tag_without=&filter_only_alert-1&offset=0&toogle_filter=no&filter_id=0&id_name=&id_group=0&history=0&section=list&open_filter=0&pure=']['text'] = __('RSS'); $sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&fb64='.$fb64]['text'] = __('RSS');
$sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&search=&event_type=&severity=-1&status=3&id_group=0&refr=0&id_agent=0&pagination=20&group_rep=1&event_view_hr=8&id_user_ack=0&tag_with=&tag_without=&filter_only_alert-1&offset=0&toogle_filter=no&filter_id=0&id_name=&id_group=0&history=0&section=list&open_filter=0&pure=']['id'] = 'RSS'; $sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&fb64='.$fb64]['id'] = 'RSS';
$sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&search=&event_type=&severity=-1&status=3&id_group=0&refr=0&id_agent=0&pagination=20&group_rep=1&event_view_hr=8&id_user_ack=0&tag_with=&tag_without=&filter_only_alert-1&offset=0&toogle_filter=no&filter_id=0&id_name=&id_group=0&history=0&section=list&open_filter=0&pure=']['type'] = 'direct'; $sub['operation/events/events_rss.php?user='.$config['id_user'].'&amp;hashup='.$hashup.'&fb64='.$fb64]['type'] = 'direct';
// Marquee. // Marquee.
$sub['operation/events/events_marquee.php']['text'] = __('Marquee'); $sub['operation/events/events_marquee.php']['text'] = __('Marquee');