Added switch to image content

(cherry picked from commit d0a83b50215c5a0ffa25a52f3ab825a9b93e9f77)
This commit is contained in:
fbsanchez 2016-10-14 11:27:54 +02:00
parent 8ed490e19e
commit 2513dea2b5
2 changed files with 117 additions and 104 deletions

View File

@ -2070,11 +2070,17 @@ function delete_dir($dir) {
return rmdir($dir); return rmdir($dir);
} }
/**
* Returns 1 if the data contains a codified image (base64)
*/
function is_image_data ($data) {
return (substr($data,0,10) == "data:image");
}
/** /**
* Returns 1 if this is Snapshot data, 0 otherwise * Returns 1 if this is Snapshot data, 0 otherwise
* Looks for two or more carriage returns. * Looks for two or more carriage returns.
*/ */
function is_snapshot_data ($data) { function is_snapshot_data ($data) {
// TODO IDEA: In the future, we can set a variable in setup // TODO IDEA: In the future, we can set a variable in setup
@ -2084,7 +2090,7 @@ function is_snapshot_data ($data) {
$temp = array(); $temp = array();
$count = preg_match_all ("/\n/", $data, $temp); $count = preg_match_all ("/\n/", $data, $temp);
if ($count > 2) if ( ($count > 2) || (is_image_data($data) )
return 1; return 1;
else else
return 0; return 0;

View File

@ -1,102 +1,109 @@
<?php <?php
// Pandora FMS - http://pandorafms.com // Pandora FMS - http://pandorafms.com
// ================================================== // ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas // Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list // Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License // modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2. // as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
if (! isset($_SESSION['id_usuario'])) { if (! isset($_SESSION['id_usuario'])) {
session_start(); session_start();
//session_write_close(); //session_write_close();
} }
require_once ('../../include/config.php'); require_once ('../../include/config.php');
require_once ($config['homedir'] . '/include/auth/mysql.php'); require_once ($config['homedir'] . '/include/auth/mysql.php');
require_once ($config['homedir'] . '/include/functions.php'); require_once ($config['homedir'] . '/include/functions.php');
require_once ($config['homedir'] . '/include/functions_db.php'); require_once ($config['homedir'] . '/include/functions_db.php');
require_once ($config['homedir'] . '/include/functions_reporting.php'); require_once ($config['homedir'] . '/include/functions_reporting.php');
require_once ($config['homedir'] . '/include/functions_graph.php'); require_once ($config['homedir'] . '/include/functions_graph.php');
require_once ($config['homedir'] . '/include/functions_modules.php'); require_once ($config['homedir'] . '/include/functions_modules.php');
require_once ($config['homedir'] . '/include/functions_agents.php'); require_once ($config['homedir'] . '/include/functions_agents.php');
require_once ($config['homedir'] . '/include/functions_tags.php'); require_once ($config['homedir'] . '/include/functions_tags.php');
check_login (); check_login ();
$user_language = get_user_language ($config['id_user']); $user_language = get_user_language ($config['id_user']);
if (file_exists ('../../include/languages/'.$user_language.'.mo')) { if (file_exists ('../../include/languages/'.$user_language.'.mo')) {
$l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo')); $l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo'));
$l10n->load_tables(); $l10n->load_tables();
} }
$id = get_parameter('id'); $id = get_parameter('id');
$label = get_parameter ("label"); $label = get_parameter ("label");
// TODO - Put ACL here // TODO - Put ACL here
?> ?>
<html> <html>
<head> <head>
<?php <?php
// Parsing the refresh before sending any header // Parsing the refresh before sending any header
$refresh = (int) get_parameter ("refr", -1); $refresh = (int) get_parameter ("refr", -1);
if ($refresh > 0) { if ($refresh > 0) {
$query = ui_get_url_refresh (false); $query = ui_get_url_refresh (false);
echo '<meta http-equiv="refresh" content="'.$refresh.'; URL='.$query.'" />'; echo '<meta http-equiv="refresh" content="'.$refresh.'; URL='.$query.'" />';
} }
?> ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pandora FMS Snapshot data view for module (<?php echo $label; ?>)</title> <title>Pandora FMS Snapshot data view for module (<?php echo $label; ?>)</title>
<script type='text/javascript' src='../../include/javascript/jquery-1.7.1.js'></script> <script type='text/javascript' src='../../include/javascript/jquery-1.7.1.js'></script>
</head> </head>
<body style='background:#000; color: #ccc;'> <body style='background:#000; color: #ccc;'>
<?php <?php
$row = db_get_row_sql("SELECT * $row = db_get_row_sql("SELECT *
FROM tagente_estado FROM tagente_estado
WHERE id_agente_modulo = $id"); WHERE id_agente_modulo = $id");
echo "<h2 id='title_snapshot_view'>"; echo "<h2 id='title_snapshot_view'>";
echo __("Current data at"); echo __("Current data at");
echo " "; echo " ";
echo $row["timestamp"]; echo $row["timestamp"];
echo "</h2>"; echo "</h2>";
$datos = io_safe_output($row["datos"]); $datos = io_safe_output($row["datos"]);
$datos = preg_replace ('/\n/i','<br>',$datos); if (is_image_data($datos)) {
$datos = preg_replace ('/\s/i','&nbsp;',$datos); echo '<img src="' . $datos . '" alt="image"/>';
echo "<div id='result_div' style='width: 100%; height: 100%; overflow: scroll; padding: 10px; font-size: 14px; line-height: 16px; font-family: mono,monospace; text-align: left'>"; }
echo $datos; else {
echo "</div>"; $datos = preg_replace ('/\n/i','<br>',$datos);
?> $datos = preg_replace ('/\s/i','&nbsp;',$datos);
<script type="text/javascript"> echo "<div id='result_div' style='width: 100%; height: 100%; overflow: scroll; padding: 10px; font-size: 14px; line-height: 16px; font-family: mono,monospace; text-align: left'>";
function getScrollbarWidth() { echo $datos;
var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div></div>'); echo "</div>";
$('body').append(div); ?>
var w1 = $('div', div).innerWidth(); <script type="text/javascript">
div.css('overflow-y', 'auto'); function getScrollbarWidth() {
var w2 = $('div', div).innerWidth(); var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div></div>');
$(div).remove(); $('body').append(div);
var w1 = $('div', div).innerWidth();
return (w1 - w2); div.css('overflow-y', 'auto');
} var w2 = $('div', div).innerWidth();
$(div).remove();
$(document).ready(function() {
width = $("#result_div").css("width"); return (w1 - w2);
width = width.replace("px", ""); }
width = parseInt(width);
$("#result_div").css("width", (width - getScrollbarWidth()) + "px"); $(document).ready(function() {
width = $("#result_div").css("width");
height = $("#result_div").css("height"); width = width.replace("px", "");
height = height.replace("px", ""); width = parseInt(width);
height = parseInt(height); $("#result_div").css("width", (width - getScrollbarWidth()) + "px");
$("#result_div").css("height", (height - getScrollbarWidth() - $("#title_snapshot_view").height() - 16) + "px");
}); height = $("#result_div").css("height");
</script> height = height.replace("px", "");
</body> height = parseInt(height);
</html> $("#result_div").css("height", (height - getScrollbarWidth() - $("#title_snapshot_view").height() - 16) + "px");
});
</script>
<?php
}
?>
</body>
</html>