2008-04-23 22:51:37 +02:00
|
|
|
<?php
|
2019-06-20 13:33:37 +02:00
|
|
|
/**
|
|
|
|
* Event RSS exporter.
|
|
|
|
*
|
|
|
|
* @category Event RSS export
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2019-06-20 13:33:37 +02:00
|
|
|
* 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.
|
2021-03-15 10:07:36 +01:00
|
|
|
ini_set('display_errors', 0);
|
2009-06-08 20:17:33 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once '../../include/config.php';
|
|
|
|
require_once '../../include/functions.php';
|
|
|
|
require_once '../../include/functions_db.php';
|
|
|
|
require_once '../../include/functions_api.php';
|
|
|
|
require_once '../../include/functions_agents.php';
|
|
|
|
require_once '../../include/functions_users.php';
|
|
|
|
require_once '../../include/functions_tags.php';
|
|
|
|
require_once '../../include/functions_groups.php';
|
2010-07-02 14:21:39 +02:00
|
|
|
|
2010-01-25 20:47:38 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
/**
|
|
|
|
* Generates an xml entry.
|
|
|
|
*
|
|
|
|
* @param string $key Key.
|
|
|
|
* @param string $value Value.
|
|
|
|
*
|
|
|
|
* @return string XML entry.
|
|
|
|
*/
|
|
|
|
function xml_entry($key, $value)
|
|
|
|
{
|
|
|
|
$output = '<'.xml_entities($key).'>';
|
|
|
|
$output .= '<![CDATA['.io_safe_output($value).']]>';
|
|
|
|
$output .= '</'.xml_entities($key).'>';
|
|
|
|
return $output."\n";
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Escape entities for XML.
|
|
|
|
*
|
|
|
|
* @param string $str String.
|
|
|
|
*
|
|
|
|
* @return string Escaped string.
|
|
|
|
*/
|
|
|
|
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;
|
2010-09-27 13:24:43 +02:00
|
|
|
}
|
2012-09-19 Miguel de Dios <miguel.dedios@artica.es>
* extensions/resource_registration.php, extensions/system_info.php,
extensions/update_manager/lib/libupdate_manager.php,
godmode/agentes/modificar_agente.php,
godmode/alerts/alert_actions.php,
godmode/alerts/alert_list.list.php,
godmode/massive/massive_add_profiles.php,
godmode/massive/massive_edit_modules.php,
godmode/servers/manage_recontask.php,
godmode/setup/setup_visuals.php, include/functions_api.php,
include/functions_graph.php, include/functions_messages.php,
include/graphs/functions_flot.php,
include/graphs/flot/pandora.flot.js, operation/tree.php,
operation/agentes/status_events.php,
operation/agentes/ver_agente.php, operation/events/events_list.php,
operation/events/events_marquee.php,
operation/events/events_rss.php: cleaned source code style.
* godmode/reporting/reporting_builder.item_editor.php,
include/functions_ui.php, include/ajax/agent.php: continue to change
to the new function "ui_print_agent_autocomplete_input" to make more
easy (and standar) the autocomplete agent input.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6988 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-09-19 16:45:59 +02:00
|
|
|
|
2010-09-01 15:34:15 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
/**
|
|
|
|
* 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));
|
2010-09-01 15:34:15 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
return ($k2 * 256 + $k1);
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2010-09-01 15:34:15 +02:00
|
|
|
}
|
2010-01-25 20:47:38 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2019-01-30 16:18:44 +01:00
|
|
|
function rss_error_handler($errno, $errstr, $errfile, $errline, $error_human_description=null)
|
|
|
|
{
|
|
|
|
$url = ui_get_full_url(false);
|
|
|
|
$selfurl = ui_get_full_url('?'.$_SERVER['QUERY_STRING'], false, true);
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// ' Fixes certain highlighters freaking out on the PHP closing tag.
|
|
|
|
$rss_feed = rss_header(0);
|
2019-01-30 16:18:44 +01:00
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '<item>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '<guid>'.$url.'/index.php?sec=eventos&sec2=operation/events/events</guid>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '<title>Error creating feed</title>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
|
|
|
|
if (empty($error_human_description)) {
|
|
|
|
$rss_feed .= '<description>There was an error creating the feed: '.$errno.' - '.$errstr.' in '.$errfile.' on line '.$errline.'</description>';
|
|
|
|
} else {
|
|
|
|
$rss_feed .= '<description>'.xml_entities(io_safe_input($error_human_description)).'</description>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '<link>'.$url.'/index.php?sec=eventos&sec2=operation/events/events</link>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '</item>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '</channel>';
|
|
|
|
$rss_feed .= "\n";
|
|
|
|
$rss_feed .= '</rss>';
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
echo $rss_feed;
|
2009-03-05 18:40:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 10:56:46 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// Errors output as RSS.
|
2019-01-30 16:18:44 +01:00
|
|
|
set_error_handler('rss_error_handler', E_ERROR);
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// Send header before starting to output.
|
|
|
|
header('Content-Type: application/xml; charset=UTF-8');
|
2013-01-18 10:56:46 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$ipOrigin = $_SERVER['REMOTE_ADDR'];
|
2010-07-02 14:21:39 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// 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.')
|
|
|
|
);
|
2010-09-27 13:24:43 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
exit;
|
|
|
|
}
|
2012-07-10 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added more constants into the constants
block of time conversion to seconds.
* godmode/alerts/alert_commands.php, godmode/setup/performance.php,
include/help/en/help_date_format.php, include/functions_netflow.php,
include/functions_tags.php, include/graphs/functions_pchart.php,
include/functions_modules.php, extensions/agents_modules.php,
extensions/update_manager.php, extensions/resource_exportation.php,
extensions/module_groups.php,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/system_info.php, operation/events/events_rss.php,
operation/events/export_csv.php, mobile/operation/events/events.php,
mobile/include/system.class.php: used the new constants time instead
the magic numbers, and cleaned source code style.
git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6762 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2012-07-10 15:31:34 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// Check user credentials.
|
|
|
|
$user = get_parameter('user');
|
|
|
|
$hashup = get_parameter('hashup');
|
2010-09-27 13:24:43 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$pss = get_user_info($user);
|
|
|
|
$hashup2 = md5($user.$pss['password']);
|
2008-04-23 22:51:37 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
if ($hashup != $hashup2) {
|
|
|
|
rss_error_handler(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
__('The URL of your feed has bad hash.')
|
|
|
|
);
|
2009-03-05 18:40:40 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
exit;
|
2009-03-05 18:40:40 +01:00
|
|
|
}
|
2008-04-23 22:51:37 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$reset_session = false;
|
|
|
|
if (empty($config['id_user'])) {
|
|
|
|
$config['id_user'] = $user;
|
|
|
|
$reset_session = true;
|
2008-09-03 17:47:09 +02:00
|
|
|
}
|
2008-04-23 22:51:37 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$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',
|
2023-01-17 10:14:22 +01:00
|
|
|
'ta.alias as agent_name',
|
2019-06-20 13:33:37 +02:00
|
|
|
'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.']');
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// Dump events.
|
|
|
|
$limit = get_parameter('limit', 20);
|
|
|
|
$offset = get_parameter('offset', 0);
|
|
|
|
$events = events_get_all(
|
|
|
|
$fields,
|
|
|
|
$filter,
|
|
|
|
$offset,
|
|
|
|
$limit,
|
|
|
|
'desc',
|
|
|
|
'timestamp',
|
|
|
|
$filter['history']
|
|
|
|
);
|
2014-10-09 19:43:03 +02:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$last_timestamp = 0;
|
|
|
|
if (is_array($events)) {
|
|
|
|
$last_timestamp = $events[0]['utimestamp'];
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
// Dump headers.
|
|
|
|
$rss = rss_header($last_timestamp);
|
|
|
|
$url = ui_get_full_url(false);
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
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']);
|
|
|
|
}
|
|
|
|
|
2023-01-17 10:10:59 +01:00
|
|
|
$rss .= xml_entry('author', $row['agent_name']);
|
2019-06-20 13:33:37 +02:00
|
|
|
$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>';
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
2019-06-20 13:33:37 +02:00
|
|
|
} 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";
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
$rss .= "</channel>\n</rss>\n";
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
echo $rss;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo rss_error_handler(200, 'Controlled error', '', '', $e->getMessage());
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
|
2019-06-20 13:33:37 +02:00
|
|
|
if ($reset_session) {
|
|
|
|
unset($config['id_user']);
|
2014-10-09 19:43:03 +02:00
|
|
|
}
|