2014-05-08 Alejandro Gallardo <alejandro.gallardo@artica.es>
* pandora_console/extensions/matrix_events/ajax.php, pandora_console/extensions/matrix_events.php: Added files. New extension to see the latest events like if you were the operator of the Nebuchadnezzar. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9896 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
fb33ea796c
commit
490537ee91
|
@ -1,3 +1,10 @@
|
|||
2014-05-08 Alejandro Gallardo <alejandro.gallardo@artica.es>
|
||||
|
||||
* pandora_console/extensions/matrix_events/ajax.php,
|
||||
pandora_console/extensions/matrix_events.php: Added
|
||||
files. New extension to see the latest events like if
|
||||
you were the operator of the Nebuchadnezzar.
|
||||
|
||||
2014-05-08 Vanessa Gil <vanessa.gil@artica.es>
|
||||
|
||||
* godmode/servers/plugin.php: Removed 'max. retries'.
|
||||
|
|
|
@ -0,0 +1,265 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
function load_matrix_console() {
|
||||
global $config;
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "ER")) {
|
||||
db_pandora_audit("ACL Violation", "Trying to access event viewer");
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
$pure = (bool) get_parameter('pure');
|
||||
|
||||
if (! $pure) {
|
||||
$title_menu = __("Matrix events");
|
||||
$fullscreen['text'] = '<a href="index.php?extension_in_menu=eventos&sec=extensions&sec2=extensions/matrix_events&pure=1">'
|
||||
. html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode')))
|
||||
. "</a>";
|
||||
$onheader = array('fullscreen' => $fullscreen);
|
||||
ui_print_page_header ($title_menu, "images/op_monitoring.png", false, "", false, $onheader);
|
||||
}
|
||||
|
||||
echo "<canvas id=\"matrix-terminal\" style=\"display:block;\"></canvas>";
|
||||
|
||||
?>
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
var terminal = {
|
||||
element : "",
|
||||
context : null,
|
||||
fontSize : 14,
|
||||
timers : {
|
||||
rain : null,
|
||||
event : null,
|
||||
events : null
|
||||
},
|
||||
stopRain : function () {
|
||||
if (this.timers.rain) {
|
||||
clearInterval(this.timers.rain);
|
||||
}
|
||||
},
|
||||
stopEvent : function () {
|
||||
if (this.timers.event) {
|
||||
clearInterval(this.timers.event);
|
||||
}
|
||||
},
|
||||
clear : function () {
|
||||
this.stopRain();
|
||||
this.stopEvent();
|
||||
if (this.context) {
|
||||
this.context.fillStyle = "rgba(0, 0, 0, 1.0)";
|
||||
this.context.fillRect(0, 0, width, height);
|
||||
}
|
||||
},
|
||||
print : function () {
|
||||
|
||||
this.stopRain();
|
||||
|
||||
var letters = "田由甲申甴电甶アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン<>*01ACREJWH{V";
|
||||
|
||||
// Converting the string into an array of single characters
|
||||
letters = letters.split("");
|
||||
|
||||
var width = this.element.width;
|
||||
var height = this.element.height;
|
||||
var context = this.context;
|
||||
|
||||
var font_size = this.fontSize;
|
||||
// Number of columns for the rain
|
||||
var columns = Math.round(width / font_size);
|
||||
// Number of rows for the rain
|
||||
var rows = Math.round(height / font_size);
|
||||
// An array of drops - one per column
|
||||
var drops = [];
|
||||
// x below is the x coordinate
|
||||
// 1 = y co-ordinate of the drop(same for every drop initially)
|
||||
for (var x = 0; x < columns; x++) {
|
||||
drops[x] = -1;
|
||||
}
|
||||
|
||||
// Drawing the characters
|
||||
function draw() {
|
||||
// Black BG for the canvas
|
||||
// Translucent BG to show trail
|
||||
context.fillStyle = "rgba(0, 0, 0, 0.05)";
|
||||
context.fillRect(0, 0, width, height);
|
||||
|
||||
context.fillStyle = "#0F0"; // Green text
|
||||
context.font = font_size + "px arial";
|
||||
// Looping over drops
|
||||
for (var i = 0; i < drops.length; i++) {
|
||||
if (drops[i] == -1) {
|
||||
if (Math.random() > 0.975) {
|
||||
drops[i] = 1;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// A random character to print
|
||||
var letter = letters[Math.floor(Math.random() * letters.length)];
|
||||
//x = i * font_size, y = value of drops[i] * font_size
|
||||
context.fillText(letter, i * font_size, drops[i] * font_size);
|
||||
|
||||
// Sending the drop back to the top randomly after it has crossed the screen
|
||||
// Adding a randomness to the reset to make the drops scattered on the Y axis
|
||||
if (drops[i] * font_size > height && Math.random() > 0.975) {
|
||||
drops[i] = 0;
|
||||
}
|
||||
//incrementing Y coordinate
|
||||
drops[i]++;
|
||||
}
|
||||
|
||||
}
|
||||
this.timers.rain = setInterval(draw, 33);
|
||||
},
|
||||
showEvent : function (message) {
|
||||
|
||||
this.stopEvent();
|
||||
|
||||
var context = this.context;
|
||||
var font_size = this.fontSize;
|
||||
var width = this.element.width;
|
||||
var height = this.element.height;
|
||||
var columns = Math.round(width / font_size);
|
||||
var rows = Math.round(height / font_size);
|
||||
var middleColumn = Math.floor(rows / 2);
|
||||
|
||||
while (message.length < columns) {
|
||||
message = " " + message + " ";
|
||||
}
|
||||
|
||||
// Converting the string into an array of single characters
|
||||
var letters = message.split("");
|
||||
var positions = [];
|
||||
// x below is the x coordinate
|
||||
// 1 = y co-ordinate of the drop(same for every drop initially)
|
||||
for (var i = 0; i < letters.length; i++) {
|
||||
positions[i] = -1;
|
||||
}
|
||||
function drawMessage() {
|
||||
// Looping over drops
|
||||
for (var i = 0; i < letters.length; i++) {
|
||||
if (positions[i] < 0) {
|
||||
if (Math.random() > 0.9) {
|
||||
positions[i] = 1;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else if (positions[i] < middleColumn) {
|
||||
context.fillStyle = "#0F0";
|
||||
context.fillText(letters[i], i * font_size, positions[i] * font_size);
|
||||
//incrementing Y coordinate
|
||||
positions[i]++;
|
||||
} else if (positions[i] > middleColumn) {
|
||||
context.fillStyle = "#0F0";
|
||||
context.fillText(letters[i], i * font_size, positions[i] * font_size);
|
||||
//incrementing Y coordinate
|
||||
// Adding a randomness to the reset to make the drops scattered on the Y axis
|
||||
if (positions[i] * font_size > terminal.height) {
|
||||
positions[i] = -1;
|
||||
}
|
||||
//incrementing Y coordinate
|
||||
positions[i]++;
|
||||
} else {
|
||||
context.fillStyle = "rgba(255, 255, 255, 1.0)";
|
||||
context.fillText(letters[i], i * font_size, positions[i] * font_size);
|
||||
|
||||
function moveLetter(array, index) {
|
||||
setTimeout(function() {
|
||||
if (array[index] == middleColumn) {
|
||||
array[index]++;
|
||||
}
|
||||
}, 15000);
|
||||
}
|
||||
moveLetter(positions, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.timers.event = setInterval(drawMessage, 100);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready (function () {
|
||||
|
||||
var pure = <?php echo json_encode($pure); ?>;
|
||||
|
||||
terminal.element = document.getElementById("matrix-terminal");
|
||||
if (pure) {
|
||||
terminal.fontSize = terminal.fontSize + 2;
|
||||
terminal.element.height = window.innerHeight;
|
||||
terminal.element.width = window.innerWidth;
|
||||
|
||||
$("#matrix-terminal").click(function() {
|
||||
document.location.search = "?extension_in_menu=eventos&sec=extensions&sec2=extensions/matrix_events";
|
||||
});
|
||||
$("#main_pure").css("margin", 0)
|
||||
} else {
|
||||
terminal.element.height = $("#main").innerHeight();
|
||||
terminal.element.width = $("#main").innerWidth();
|
||||
|
||||
$("#matrix-terminal").dblclick(function() {
|
||||
document.location.search = "?extension_in_menu=eventos&sec=extensions&sec2=extensions/matrix_events&pure=1";
|
||||
});
|
||||
}
|
||||
terminal.context = terminal.element.getContext("2d");
|
||||
|
||||
terminal.print();
|
||||
showLastEvents();
|
||||
});
|
||||
|
||||
// Shows the last 5 events via ajax
|
||||
function showLastEvents () {
|
||||
|
||||
if (terminal.timers.events) {
|
||||
clearInterval(terminal.timers.events);
|
||||
}
|
||||
|
||||
$.ajax ({
|
||||
url : "ajax.php",
|
||||
data : {
|
||||
page: "<?php echo EXTENSIONS_DIR; ?>/matrix_events/ajax",
|
||||
get_last_events: 1
|
||||
},
|
||||
type : 'POST',
|
||||
dataType : 'json',
|
||||
success: function (data) {
|
||||
events = data;
|
||||
|
||||
if (events.length > 0) {
|
||||
event = events.shift();
|
||||
terminal.showEvent(event.agent + " - " + event.text + " - " + event.date);
|
||||
}
|
||||
var showEventsInterval = function () {
|
||||
if (events.length > 0) {
|
||||
event = events.shift();
|
||||
terminal.showEvent(event.agent + " - " + event.text + " - " + event.date);
|
||||
} else {
|
||||
showLastEvents();
|
||||
}
|
||||
}
|
||||
terminal.timers.events = setInterval(showEventsInterval, 20000);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
extensions_add_operation_menu_option("Matrix", 'eventos', '', "v1r1");
|
||||
extensions_add_main_function('load_matrix_console');
|
||||
?>
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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; 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.
|
||||
|
||||
global $config;
|
||||
|
||||
if (is_ajax()) {
|
||||
|
||||
if (! check_acl ($config["id_user"], 0, "ER")) {
|
||||
db_pandora_audit("ACL Violation", "Trying to access event viewer");
|
||||
return;
|
||||
}
|
||||
|
||||
$get_last_events = (bool) get_parameter("get_last_events");
|
||||
if ($get_last_events) {
|
||||
|
||||
require_once ('include/functions_io.php');
|
||||
require_once ('include/functions_tags.php');
|
||||
|
||||
$limit = (int) get_parameter("limit", 5);
|
||||
|
||||
$tags_condition = tags_get_acl_tags($config['id_user'], 0, 'ER', 'event_condition', 'AND');
|
||||
$filter = "estado<>1 $tags_condition";
|
||||
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
case "postgresql":
|
||||
$sql = sprintf ("SELECT id_agente, evento, utimestamp
|
||||
FROM tevento
|
||||
WHERE %s
|
||||
ORDER BY utimestamp DESC LIMIT %d",
|
||||
$filter, $limit);
|
||||
break;
|
||||
case "oracle":
|
||||
$sql = sprintf ("SELECT *
|
||||
FROM tevento
|
||||
WHERE %s
|
||||
AND rownum <= %d
|
||||
ORDER BY utimestamp DESC",
|
||||
$filter, $limit);
|
||||
break;
|
||||
}
|
||||
$result = db_get_all_rows_sql ($sql);
|
||||
|
||||
$events = array();
|
||||
if (! empty($result)) {
|
||||
foreach ($result as $key => $value) {
|
||||
$event = array();
|
||||
$event['agent'] = (empty($value['id_agente'])) ? "System" : agents_get_name($value['id_agente']);
|
||||
$event['text'] = io_safe_output($value['evento']);
|
||||
$event['date'] = date(io_safe_output($config['date_format']), $value['utimestamp']);
|
||||
$events[] = $event;
|
||||
}
|
||||
} else {
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
echo json_encode($events);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue