From 74634b8676cc13a240c73da0c0199a4cb5442564 Mon Sep 17 00:00:00 2001
From: slerena <slerena@gmail.com>
Date: Sun, 9 Dec 2012 22:31:29 +0000
Subject: [PATCH] 2012-12-09  Sancho Lerena <slerena@artica.es>

        Ported new feature (Command Snapshot) from 4.0.3 code.

        *  include/javascript/pandora.js: Added new javascript function
        to open a generic URL with custom width / height.

        * operation/agentes/snapshot_view.php: New feature for command
        snapshot rendering.

        * operation/agentes/datos_agente.php,
        operation/agentes/estado_monitores.php: Changes for new feature
        command snapshot monitoring.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7242 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  15 ++
 pandora_console/include/javascript/pandora.js |   8 +-
 .../operation/agentes/datos_agente.php        |  26 ++-
 .../operation/agentes/estado_monitores.php    |  31 ++-
 .../operation/agentes/snapshot_view.php       |  71 +++++++
 pandora_console/pandoradb.sql                 | 184 +++++++++---------
 6 files changed, 234 insertions(+), 101 deletions(-)
 create mode 100644 pandora_console/operation/agentes/snapshot_view.php

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 9d9d05c3b9..36ec418e4a 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,18 @@
+2012-12-09  Sancho Lerena <slerena@artica.es>
+
+	Ported new feature (Command Snapshot) from 4.0.3 code.
+
+        *  include/javascript/pandora.js: Added new javascript function
+        to open a generic URL with custom width / height.
+
+        * operation/agentes/snapshot_view.php: New feature for command
+        snapshot rendering.
+
+        * operation/agentes/datos_agente.php,
+        operation/agentes/estado_monitores.php: Changes for new feature
+        command snapshot monitoring.
+
+
 2012-12-07  Sergio Martin <sergio.martin@artica.es>
 
 	* include/functions_categories.php: Add categories
diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js
index 8d78dafaeb..28898fc7c5 100644
--- a/pandora_console/include/javascript/pandora.js
+++ b/pandora_console/include/javascript/pandora.js
@@ -13,7 +13,13 @@ function toggleDiv (divid){
 function winopeng (url, wid) {
 	open (url, wid,"width=650,height=410,status=no,toolbar=no,menubar=no,scrollbar=no");
 	// WARNING !! Internet Explorer DOESNT SUPPORT "-" CARACTERS IN WINDOW HANDLE VARIABLE
-	status =wid;
+	status = wid;
+}
+
+function winopeng_var (url, wid, width, height) {
+	open (url, wid,"width="+width+",height="+height+",status=no,toolbar=no,menubar=no,scrollbar=yes");
+        // WARNING !! Internet Explorer DOESNT SUPPORT "-" CARACTERS IN WINDOW HANDLE VARIABLE
+        status = wid;
 }
 
 function open_help (help_id) {
diff --git a/pandora_console/operation/agentes/datos_agente.php b/pandora_console/operation/agentes/datos_agente.php
index 93650a6fb7..f808b50d36 100644
--- a/pandora_console/operation/agentes/datos_agente.php
+++ b/pandora_console/operation/agentes/datos_agente.php
@@ -231,9 +231,31 @@ foreach($columns as $col => $attr) {
 
 foreach ($result as $row) {
 	$data = array ();
-	
+
 	foreach($columns as $col => $attr) {
-		$data[] = $attr[1] ($row[$attr[0]]);
+		if ($attr[1] != "modules_format_data")
+			$data[] = $attr[1] ($row[$attr[0]]);
+
+		// Its a single-data, multiline data (data snapshot) ?
+		elseif (preg_match ("/[\n]+/i", $row[$attr[0]])){
+
+			// Detect string data with \n and convert to <br>'s
+			$datos = preg_replace ('/\n/i','<br>',$row[$attr[0]]);
+			$datos = preg_replace ('/\s/i','&nbsp;',$datos);
+			
+			// Because this *SHIT* of print_table monster, I cannot format properly this cells
+			// so, eat this, motherfucker :))
+
+			$datos = "<span style='font-family: lucida console'>".$datos."</span>";
+	
+			// I dont why, but using index (value) method, data is automatically converted to html entities ¿?
+			$data[$attr[1]]=$datos;
+
+		} else {
+		// Just a string of alphanumerical data... just do print
+
+			$data[$attr[1]]=$row[$attr[0]];	
+		}
 	}
 	
 	array_push ($table->data, $data);
diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php
index 0759495c0e..10fce500f8 100644
--- a/pandora_console/operation/agentes/estado_monitores.php
+++ b/pandora_console/operation/agentes/estado_monitores.php
@@ -439,16 +439,35 @@ foreach ($modules as $module) {
 		}
 		else {
 			$module_value = io_safe_output($module["datos"]);
-			$sub_string = substr(io_safe_output($module["datos"]),0, 12);
+
+			// There are carriage returns here ?
+			// If carriage returns present... then is a "Snapshot" data (full command output)
+			if (preg_match ("/[\n]+/i", io_safe_output($module["datos"]))){
+
+		                $handle = "snapshot"."_".$module["id_agente_modulo"];
+                		$url = 'include/procesos.php?agente='.$module["id_agente_modulo"];
+		                $win_handle=dechex(crc32($handle));
+
+				$link ="winopeng_var('operation/agentes/snapshot_view.php?id=".$module["id_agente_modulo"]."&refr=".$module["current_interval"]."&label=".$module["nombre"]."','".$win_handle."', 700,480)"; 
+
+                        	$salida = '<a href="javascript:'.$link.'">' . html_print_image("images/default_list.png", true, array("border" => '0', "alt" => "", "title" => __("Snapshot view"))) . '</a> &nbsp;&nbsp;';
+
+
+                	//	$link ="winopeng('operation/agentes/snapshot_view.php?id=".$module["id_agente_modulo"]."',$win_handle)";
+		//		$salida = '<a href="javascript:'.$link.'">' . html_print_image("images/default_list.png", true, array("border" => '0', "alt" => "")) . '</a> &nbsp;&nbsp;';
 			
-			if ($module_value == $sub_string) {
-				$salida = $module_value;
-			}
-			else {
-				$salida = "<span id='value_module_" . $module["id_agente_modulo"] . "'
+			} else {	
+				$sub_string = substr(io_safe_output($module["datos"]),0, 12);
+			
+				if ($module_value == $sub_string) {
+					$salida = $module_value;
+				}
+				else {
+					$salida = "<span id='value_module_" . $module["id_agente_modulo"] . "'
 					title='".$module_value."' style='white-space: nowrap;'>" . 
 					'<span id="value_module_text_' . $module["id_agente_modulo"] . '">' . $sub_string . '</span> ' .
 					"<a href='javascript: toggle_full_value(" . $module["id_agente_modulo"] . ")'>" . html_print_image("images/rosette.png", true) . "" . "</span>";
+				}
 			}
 		}
 	}
diff --git a/pandora_console/operation/agentes/snapshot_view.php b/pandora_console/operation/agentes/snapshot_view.php
new file mode 100644
index 0000000000..48113443a9
--- /dev/null
+++ b/pandora_console/operation/agentes/snapshot_view.php
@@ -0,0 +1,71 @@
+<?php
+
+// 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.
+
+
+
+// Global & session management
+require_once ('../../include/config.php');
+require_once ('../../include/auth/mysql.php');
+
+if (! isset($_SESSION['id_usuario'])) {
+        session_start();
+        session_write_close();
+}
+
+require_once ($config['homedir'] . '/include/functions.php');
+require_once ($config['homedir'] . '/include/functions_db.php');
+require_once ($config['homedir'] . '/include/functions_ui.php');
+
+check_login ();
+
+$user_language = get_user_language ($config['id_user']);
+if (file_exists ('../../include/languages/'.$user_language.'.mo')) {
+        $l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo'));
+        $l10n->load_tables();
+}
+
+$id = get_parameter('id');
+$label = get_parameter ("label");
+
+// TODO - Put ACL here
+
+// Parsing the refresh before sending any header
+$refresh = (int) get_parameter ("refr", -1);
+if ($refresh > 0) {
+        $query = ui_get_url_refresh (false);
+        echo '<meta http-equiv="refresh" content="'.$refresh.'; URL='.$query.'" />';
+}
+?>
+
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>Pandora FMS Snapshot data view for module (<?php echo $label; ?>)</title>
+<body style='background:#000; color: #ccc;'>
+
+<?php
+
+$row = db_get_row_sql("SELECT * FROM tagente_estado WHERE id_agente_modulo = $id");
+
+echo "<h2>";
+echo __("Current data at");
+echo " ";
+echo $row["timestamp"];
+echo "</h2>";
+$datos = io_safe_output($row["datos"]);
+$datos = preg_replace ('/\n/i','<br>',$datos);
+$datos =  preg_replace ('/\s/i','&nbsp;',$datos);
+echo "<div style='padding: 10px; font-size: 14px; line-height: 16px; font-family: mono; text-align: left'>";
+echo $datos;
+echo "</div>";
+
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index 14cd7f0ab0..e64edd4783 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -24,9 +24,9 @@
 -- Priority : 3 - Warning (yellow)
 -- Priority : 4 - Critical (red)
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `taddress`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `taddress` (
 	`id_a` int(10) unsigned NOT NULL auto_increment,
 	`ip` varchar(60) NOT NULL default '',
@@ -35,9 +35,9 @@ CREATE TABLE IF NOT EXISTS `taddress` (
 	KEY `ip` (`ip`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `taddress_agent`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `taddress_agent` (
 	`id_ag` bigint(20) unsigned NOT NULL auto_increment,
 	`id_a` bigint(20) unsigned NOT NULL default '0',
@@ -45,9 +45,9 @@ CREATE TABLE IF NOT EXISTS `taddress_agent` (
 	PRIMARY KEY  (`id_ag`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tagente`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tagente` (
 	`id_agente` int(10) unsigned NOT NULL auto_increment,
 	`nombre` varchar(600) BINARY NOT NULL default '',
@@ -649,18 +649,18 @@ CREATE TABLE IF NOT EXISTS `tmensajes` (
 	PRIMARY KEY  (`id_mensaje`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tmodule_group`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tmodule_group` (
 	`id_mg` tinyint(4) unsigned NOT NULL auto_increment,
 	`name` varchar(150) NOT NULL default '',
 	PRIMARY KEY  (`id_mg`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnetwork_component`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnetwork_component` (
 	`id_nc` int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(80) NOT NULL,
@@ -710,9 +710,9 @@ CREATE TABLE IF NOT EXISTS `tnetwork_component` (
 	PRIMARY KEY  (`id_nc`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnetwork_component_group`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnetwork_component_group` (
 	`id_sg`  int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(200) NOT NULL default '',
@@ -720,9 +720,9 @@ CREATE TABLE IF NOT EXISTS `tnetwork_component_group` (
 	PRIMARY KEY  (`id_sg`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnetwork_profile`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnetwork_profile` (
 	`id_np`  int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(100) NOT NULL default '',
@@ -730,18 +730,18 @@ CREATE TABLE IF NOT EXISTS `tnetwork_profile` (
 	PRIMARY KEY  (`id_np`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnetwork_profile_component`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnetwork_profile_component` (
 	`id_nc` mediumint(8) unsigned NOT NULL default '0',
 	`id_np` mediumint(8) unsigned NOT NULL default '0',
 	KEY `id_np` (`id_np`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnota`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnota` (
 	`id_nota` bigint(6) unsigned zerofill NOT NULL auto_increment,
 	`id_incident` bigint(6) unsigned zerofill NOT NULL,
@@ -752,16 +752,16 @@ CREATE TABLE IF NOT EXISTS `tnota` (
 	KEY `id_incident` (`id_incident`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `torigen`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `torigen` (
 	`origen` varchar(100) NOT NULL default ''
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tperfil`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tperfil` (
 	`id_perfil` int(10) unsigned NOT NULL auto_increment,
 	`name` TEXT NOT NULL,
@@ -778,9 +778,9 @@ CREATE TABLE IF NOT EXISTS `tperfil` (
 	PRIMARY KEY  (`id_perfil`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `trecon_script`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `trecon_script` (
 	`id_recon_script` int(10) NOT NULL auto_increment,
 	`name` varchar(100) default '',
@@ -789,9 +789,9 @@ CREATE TABLE IF NOT EXISTS `trecon_script` (
 	PRIMARY KEY  (`id_recon_script`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `trecon_task`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `trecon_task` (
 	`id_rt` int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(100) NOT NULL default '',
@@ -821,9 +821,9 @@ CREATE TABLE IF NOT EXISTS `trecon_task` (
 	KEY `recon_task_daemon` (`id_recon_server`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tserver`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tserver` (
 	`id_server` int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(100) NOT NULL default '',
@@ -869,9 +869,9 @@ CREATE TABLE IF NOT EXISTS `tserver` (
 -- 9 web
 -- TODO: drop 2.x xxxx_server fields, unused since server_type exists.
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tsesion`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tsesion` (
 	`id_sesion` bigint(20) unsigned NOT NULL auto_increment,
 	`id_usuario` varchar(60) NOT NULL default '0',
@@ -885,9 +885,9 @@ CREATE TABLE IF NOT EXISTS `tsesion` (
 	KEY `idx_user` (`id_usuario`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `ttipo_modulo`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `ttipo_modulo` (
 	`id_tipo` smallint(5) unsigned NOT NULL auto_increment,
 	`nombre` varchar(100) NOT NULL default '',
@@ -897,9 +897,9 @@ CREATE TABLE IF NOT EXISTS `ttipo_modulo` (
 	PRIMARY KEY  (`id_tipo`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `ttrap`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `ttrap` (
 	`id_trap` bigint(20) unsigned NOT NULL auto_increment,
 	`source` varchar(50) NOT NULL default '',
@@ -922,9 +922,9 @@ CREATE TABLE IF NOT EXISTS `ttrap` (
 	INDEX status (`status`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tusuario`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tusuario` (
 	`id_user` varchar(60) NOT NULL default '0',
 	`fullname` varchar(255) NOT NULL,
@@ -958,9 +958,9 @@ CREATE TABLE IF NOT EXISTS `tusuario` (
 	UNIQUE KEY `id_user` (`id_user`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tusuario_perfil`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tusuario_perfil` (
 	`id_up` bigint(10) unsigned NOT NULL auto_increment,
 	`id_usuario` varchar(100) NOT NULL default '',
@@ -971,9 +971,9 @@ CREATE TABLE IF NOT EXISTS `tusuario_perfil` (
 	PRIMARY KEY  (`id_up`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnews`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnews` (
 	`id_news` INTEGER UNSIGNED NOT NULL  AUTO_INCREMENT,
 	`author` varchar(255)  NOT NULL DEFAULT '',
@@ -983,9 +983,9 @@ CREATE TABLE IF NOT EXISTS `tnews` (
 	PRIMARY KEY(`id_news`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgraph`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tgraph` (
 	`id_graph` INTEGER UNSIGNED NOT NULL  AUTO_INCREMENT,
 	`id_user` varchar(100) NOT NULL default '',
@@ -1002,9 +1002,9 @@ CREATE TABLE IF NOT EXISTS `tgraph` (
 	PRIMARY KEY(`id_graph`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgraph_source`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tgraph_source` (
 	`id_gs` INTEGER UNSIGNED NOT NULL  AUTO_INCREMENT,
 	`id_graph` int(11) NOT NULL default 0,
@@ -1013,9 +1013,9 @@ CREATE TABLE IF NOT EXISTS `tgraph_source` (
 	PRIMARY KEY(`id_gs`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `treport`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `treport` (
 	`id_report` INTEGER UNSIGNED NOT NULL  AUTO_INCREMENT,
 	`id_user` varchar(100) NOT NULL default '',
@@ -1034,9 +1034,9 @@ CREATE TABLE IF NOT EXISTS `treport` (
 	PRIMARY KEY(`id_report`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `treport_content`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `treport_content` (
 	`id_rc` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
 	`id_report` INTEGER UNSIGNED NOT NULL default 0,
@@ -1080,9 +1080,9 @@ CREATE TABLE IF NOT EXISTS `treport_content` (
 		ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `treport_content_sla_combined`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` (
 	`id` INTEGER UNSIGNED NOT NULL auto_increment,
 	`id_report_content` INTEGER UNSIGNED NOT NULL,
@@ -1096,9 +1096,9 @@ CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` (
 		ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `treport_content_item`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `treport_content_item` (
 	`id` INTEGER UNSIGNED NOT NULL auto_increment, 
 	`id_report_content` INTEGER UNSIGNED NOT NULL, 
@@ -1110,9 +1110,9 @@ CREATE TABLE IF NOT EXISTS `treport_content_item` (
 		ON UPDATE CASCADE ON DELETE CASCADE 
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `treport_custom_sql`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `treport_custom_sql` (
 	`id` INTEGER UNSIGNED NOT NULL auto_increment,
 	`name` varchar(150) NOT NULL default '',
@@ -1120,9 +1120,9 @@ CREATE TABLE IF NOT EXISTS `treport_custom_sql` (
 	PRIMARY KEY(`id`)
 ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tlayout`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tlayout` (
 	`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
 	`name` varchar(50)  NOT NULL,
@@ -1134,9 +1134,9 @@ CREATE TABLE IF NOT EXISTS `tlayout` (
 	PRIMARY KEY(`id`)
 )  ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tlayout_data`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tlayout_data` (
 	`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
 	`id_layout` INTEGER UNSIGNED NOT NULL default 0,
@@ -1158,9 +1158,9 @@ CREATE TABLE IF NOT EXISTS `tlayout_data` (
 	PRIMARY KEY(`id`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tplugin`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- The fields "net_dst_opt", "net_port_opt", "user_opt" and
 -- "pass_opt" are deprecated for the 5.1.
 CREATE TABLE IF NOT EXISTS `tplugin` (
@@ -1180,18 +1180,18 @@ CREATE TABLE IF NOT EXISTS `tplugin` (
 	PRIMARY KEY(`id`)
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8; 
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tmodule`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tmodule` (
 	`id_module` int(11) unsigned NOT NULL auto_increment,
 	`name` varchar(100) NOT NULL default '',
 	PRIMARY KEY (`id_module`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tserver_export`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tserver_export` (
 	`id` int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(100) NOT NULL default '',
@@ -1210,9 +1210,9 @@ CREATE TABLE IF NOT EXISTS `tserver_export` (
 	INDEX id_export_server (`id_export_server`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tserver_export_data`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- id_export_server is real pandora fms export server process that manages this server
 -- id is the "destination" server to export
 CREATE TABLE IF NOT EXISTS `tserver_export_data` (
@@ -1226,9 +1226,9 @@ CREATE TABLE IF NOT EXISTS `tserver_export_data` (
 	PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tplanned_downtime`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tplanned_downtime` (
 	`id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT,
 	`name` VARCHAR( 100 ) NOT NULL,
@@ -1255,9 +1255,9 @@ CREATE TABLE IF NOT EXISTS `tplanned_downtime` (
 	PRIMARY KEY (  `id` ) 
 ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tplanned_downtime_agents`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tplanned_downtime_agents` (
 	`id` int(20) unsigned NOT NULL auto_increment,
 	`id_agent` mediumint(8) unsigned NOT NULL default '0',
@@ -1268,9 +1268,9 @@ CREATE TABLE IF NOT EXISTS `tplanned_downtime_agents` (
 		ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tplanned_downtime_modules`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tplanned_downtime_modules` (
 	`id` int(20) unsigned NOT NULL auto_increment,
 	`id_agent` mediumint(8) unsigned NOT NULL default '0',
@@ -1282,9 +1282,9 @@ CREATE TABLE IF NOT EXISTS `tplanned_downtime_modules` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- GIS extension Tables
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgis_data_history`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE  TABLE IF NOT EXISTS `tgis_data_history` (
 	`id_tgis_data` INT NOT NULL AUTO_INCREMENT COMMENT 'key of the table' ,
 	`longitude` DOUBLE NOT NULL ,
@@ -1303,9 +1303,9 @@ ENGINE = InnoDB
 COMMENT = 'Table to store historical GIS information of the agents';
 
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgis_data_status`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE  TABLE IF NOT EXISTS `tgis_data_status` (
 	`tagente_id_agente` INT(10) UNSIGNED NOT NULL COMMENT 'Reference to the agent' ,
 	`current_longitude` DOUBLE NOT NULL COMMENT 'Last received longitude',
@@ -1329,9 +1329,9 @@ CREATE  TABLE IF NOT EXISTS `tgis_data_status` (
 ENGINE = InnoDB
 COMMENT = 'Table to store last GIS information of the agents';
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgis_map`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE  TABLE IF NOT EXISTS `tgis_map` (
 	`id_tgis_map` INT NOT NULL AUTO_INCREMENT COMMENT 'table identifier' ,
 	`map_name` VARCHAR(63) NOT NULL COMMENT 'Name of the map' ,
@@ -1438,9 +1438,9 @@ CREATE  TABLE IF NOT EXISTS `tgis_map_layer_has_tagente` (
 ENGINE = InnoDB
 COMMENT = 'Table to define wich agents are shown in a layer';
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tgroup_stat`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tgroup_stat` (
 	`id_group` int(10) unsigned NOT NULL default '0',
 	`modules` int(10) unsigned NOT NULL default '0',
@@ -1459,9 +1459,9 @@ CREATE TABLE IF NOT EXISTS `tgroup_stat` (
 COMMENT = 'Table to store global system stats per group' 
 DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tnetwork_map`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tnetwork_map` (
 	`id_networkmap` INT UNSIGNED NOT NULL AUTO_INCREMENT,
 	`id_user` VARCHAR(60)  NOT NULL,
@@ -1494,9 +1494,9 @@ CREATE TABLE IF NOT EXISTS `tnetwork_map` (
 	PRIMARY KEY  (`id_networkmap`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tsnmp_filter`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tsnmp_filter` (
 	`id_snmp_filter` int(10) unsigned NOT NULL auto_increment,
 	`description` varchar(255) default '',
@@ -1504,9 +1504,9 @@ CREATE TABLE IF NOT EXISTS `tsnmp_filter` (
 	PRIMARY KEY  (`id_snmp_filter`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tagent_custom_fields`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tagent_custom_fields` (
 	`id_field` int(10) unsigned NOT NULL auto_increment,
 	`name` varchar(45) NOT NULL default '',
@@ -1514,9 +1514,9 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_fields` (
 	PRIMARY KEY  (`id_field`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tagent_custom_data`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tagent_custom_data` (
 	`id_field` int(10) unsigned NOT NULL,
 	`id_agent` int(10) unsigned NOT NULL,
@@ -1528,9 +1528,9 @@ CREATE TABLE IF NOT EXISTS `tagent_custom_data` (
 	PRIMARY KEY  (`id_field`, `id_agent`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `ttag`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `ttag` ( 
 	`id_tag` integer(10) unsigned NOT NULL auto_increment, 
 	`name` varchar(100) NOT NULL default '', 
@@ -1661,9 +1661,9 @@ CREATE TABLE IF NOT EXISTS `tevent_response` (
 	PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 -- Table `tcategory`
-------------------------------------------------------------------------
+-- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tcategory` ( 
 	`id` int(10) unsigned NOT NULL auto_increment, 
 	`name` varchar(600) NOT NULL default '',