From fcdc478bacf19584234dcea17fdbb3bb636de41a Mon Sep 17 00:00:00 2001
From: esanchezm <noreply@pandorafms.org>
Date: Mon, 12 Jan 2009 15:09:10 +0000
Subject: [PATCH] 2009-01-12  Esteban Sanchez  <estebans@artica.es>

        * include/functions_alerts.php: Removed debug output. Show no SQL
        error on delete_alert_* functions.

        * index.php: Added missing jQuery script.

        * godmode/alerts/alert_templates.php: Added a missing br. Show "empty"
        string if no value was set.

        * godmode/alerts/alert_commands.php: Added a check to avoid internal
        commands removal.

        * pandoradb.sql: Removed talerta table.

        * pandoradb_data.sql: Data from talerta moved to talert_commands.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1332 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                      | 17 +++++++++++++++++
 .../godmode/alerts/alert_commands.php          |  7 ++++---
 .../godmode/alerts/alert_templates.php         |  6 +++++-
 pandora_console/include/functions_alerts.php   | 18 +++++++++++++-----
 pandora_console/index.php                      |  1 +
 pandora_console/pandoradb.sql                  |  8 --------
 pandora_console/pandoradb_data.sql             | 18 +++++++++---------
 7 files changed, 49 insertions(+), 26 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 180ec27b49..26a1130a9f 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,20 @@
+2009-01-12  Esteban Sanchez  <estebans@artica.es>
+
+	* include/functions_alerts.php: Removed debug output. Show no SQL
+	error on delete_alert_* functions.
+
+	* index.php: Added missing jQuery script.
+
+	* godmode/alerts/alert_templates.php: Added a missing br. Show "empty"
+	string if no value was set.
+
+	* godmode/alerts/alert_commands.php: Added a check to avoid internal
+	commands removal.
+
+	* pandoradb.sql: Removed talerta table.
+
+	* pandoradb_data.sql: Data from talerta moved to talert_commands.
+
 2009-01-12  Esteban Sanchez  <estebans@artica.es>
 
 	* godmode/agentes/alert_manager.php: Complete rewritten of the alert
diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php
index f5edfa115d..aafa44e2db 100644
--- a/pandora_console/godmode/alerts/alert_commands.php
+++ b/pandora_console/godmode/alerts/alert_commands.php
@@ -77,12 +77,13 @@ if ($update_command) {
 
 if ($delete_command) {
 	$id = get_parameter ('id');
-	// Commands below 4 are special and cannot be deleted
-	if ($id < 4) {
+	
+	// Internal commands cannot be deleted
+	if (get_alert_command_internal ($id)) {
 		audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
 			"Trying to access Alert Management");
 		require ("general/noaccess.php");
-		exit;
+		return;
 	}
 	
 	$result = delete_alert_command ($id);
diff --git a/pandora_console/godmode/alerts/alert_templates.php b/pandora_console/godmode/alerts/alert_templates.php
index 4a234b1b3d..b51f9de1e5 100644
--- a/pandora_console/godmode/alerts/alert_templates.php
+++ b/pandora_console/godmode/alerts/alert_templates.php
@@ -47,7 +47,11 @@ if (defined ('AJAX')) {
 		case 'equal':
 		case 'not_equal':
 			echo '<strong>'.__('Value').':</strong> ';
-			echo '<code>'.$template['value'].'</code>';
+			if (empty ($template['value']))
+				echo '<em>'.__('Empty').'</em>';
+			else
+				echo '<code>'.$template['value'].'</code>';
+			echo '<br />';
 			
 			break;
 		case 'max':
diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php
index 1d728aea75..beb838de17 100644
--- a/pandora_console/include/functions_alerts.php
+++ b/pandora_console/include/functions_alerts.php
@@ -47,7 +47,7 @@ function create_alert_command ($name, $command, $values = false) {
 	return process_sql ($sql, 'insert_id');
 }
 
-function update_alert_command ($id_alert_command, $name, $command, $description = '') {
+function update_alert_command ($id_alert_command, $name, $command, $description = '', $values = false) {
 	$id_alert_command = safe_int ($id_alert_command, 1);
 	if (empty ($id_alert_command))
 		return false;
@@ -71,7 +71,7 @@ function delete_alert_command ($id_alert_command) {
 	
 	$sql = sprintf ('DELETE FROM talert_commands WHERE id = %d',
 		$id_alert_command);
-	return process_sql ($sql);
+	return @process_sql ($sql);
 }
 
 function get_alert_command ($id_alert_command) {
@@ -98,6 +98,14 @@ function get_alert_command_command ($id_alert_command) {
 	return get_db_value ('command', 'talert_commands', 'id', $id_alert_command);
 }
 
+function get_alert_command_internal ($id_alert_command) {
+	$id_alert_command = safe_int ($id_alert_command, 1);
+	if (empty ($id_alert_command))
+		return false;
+	
+	return (bool) get_db_value ('internal', 'talert_commands', 'id', $id_alert_command);
+}
+
 function get_alert_command_description ($id_alert_command) {
 	$id_alert_command = safe_int ($id_alert_command, 1);
 	if (empty ($id_alert_command))
@@ -173,7 +181,7 @@ function delete_alert_action ($id_alert_action) {
 	
 	$sql = sprintf ('DELETE FROM talert_actions WHERE id = %d',
 		$id_alert_action);
-	return process_sql ($sql);
+	return @process_sql ($sql);
 }
 
 function get_alert_actions ($only_names = true) {
@@ -371,7 +379,7 @@ function update_alert_template ($id_alert_template, $values = false) {
 		SET %s
 		WHERE id = %d',
 		format_array_to_update_sql ($values), $id_alert_template);
-	echo $sql;
+	
 	return process_sql ($sql) !== false;
 }
 
@@ -382,7 +390,7 @@ function delete_alert_template ($id_alert_template) {
 	
 	$sql = sprintf ('DELETE FROM talert_templates WHERE id = %d',
 		$id_alert_template);
-	return process_sql ($sql);
+	return @process_sql ($sql);
 }
 
 function get_alert_templates ($only_names = true) {
diff --git a/pandora_console/index.php b/pandora_console/index.php
index f0d315e86f..fbb2d6440d 100644
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -118,6 +118,7 @@ echo '<title>Pandora FMS - '.__('the Flexible Monitoring System').'</title>
 <link rel="icon" href="images/pandora.ico" type="image/ico" />
 <link rel="stylesheet" href="include/styles/'.$config["style"].'.css" type="text/css" />
 <script type="text/javascript" src="include/javascript/wz_jsgraphics.js"></script>
+<script type="text/javascript" src="include/javascript/jquery.js"></script>
 <script type="text/javascript" src="include/javascript/pandora.js"></script>';
 
 enterprise_hook ('load_html_header');
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index 66e1bfb034..2ae9b3d07f 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -284,14 +284,6 @@ CREATE TABLE IF NOT EXISTS `talert_template_module_actions` (
     ON DELETE RESTRICT ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-CREATE TABLE  IF NOT EXISTS `talerta` (
-  `id` int(10) unsigned NOT NULL auto_increment,
-  `id_alert_module` int(10) unsigned NOT NULL,
-  `id_alert_template` int(10) unsigned NOT NULL,
-  `id_alert_action` int(10) unsigned NOT NULL,
-  PRIMARY KEY  (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
 CREATE TABLE  IF NOT EXISTS `tcompound_alert` (
   `id` int(10) unsigned NOT NULL auto_increment,
   `id_aam` int(10) unsigned NOT NULL default '0',
diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql
index b91cb3b72f..cf9a6ca052 100644
--- a/pandora_console/pandoradb_data.sql
+++ b/pandora_console/pandoradb_data.sql
@@ -26,16 +26,16 @@
 -- Dumping data for table `talerta`
 --
 
-INSERT INTO `talerta` VALUES (1,'Compound only', 'Internal type', 'This alert will not be executed individually');
-INSERT INTO `talerta` VALUES (2,'eMail','Internal type', 'This alert send an email using internal Pandora FMS Server SMTP capabilities (defined in each server, using:\r\n_field1_ as destination email address, and\r\n_field2_ as subject for message. \r\n_field3_ as text of message.');
-INSERT INTO `talerta` VALUES (3,'Internal Audit','Internal type','This alert save alert in Pandora interal audit system. Fields are static and only _field1_ is used.');
-INSERT INTO `talerta` VALUES (4,'Pandora FMS Event','Internal type','This alert create an special event into Pandora FMS event manager.');
+INSERT INTO `talert_commands` VALUES (1,'Compound only', 'Internal type', 'This alert will not be executed individually', 1);
+INSERT INTO `talert_commands` VALUES (2,'eMail','Internal type', 'This alert send an email using internal Pandora FMS Server SMTP capabilities (defined in each server, using:\r\n_field1_ as destination email address, and\r\n_field2_ as subject for message. \r\n_field3_ as text of message.', 1);
+INSERT INTO `talert_commands` VALUES (3,'Internal Audit','Internal type','This alert save alert in Pandora interal audit system. Fields are static and only _field1_ is used.', 1);
+INSERT INTO `talert_commands` VALUES (4,'Pandora FMS Event','Internal type','This alert create an special event into Pandora FMS event manager.', 1);
 
-INSERT INTO `talerta` VALUES (5,'Pandora FMS Alertlog','echo _timestamp_ pandora _agent_ _data_ _field1_ _field2_ >> /var/log/pandora/pandora_alert.log','This is a default alert to write alerts in a standard ASCII  plaintext log file in /var/log/pandora/pandora_alert.log\r\n');
-INSERT INTO `talerta` VALUES (6,'SNMP Trap','/usr/bin/snmptrap -v 1 -c trap_public 192.168.0.4 1.1.1.1.1.1.1.1 _agent_ _field1_','Send a SNMPTRAP to 192.168.0.4. Please review config and adapt to your needs, this is only a sample, not functional itself.');
-INSERT INTO `talerta` VALUES (7,'Syslog','logger -p daemon.alert Pandora Alert _agent_ _data_ _field1_ _field2_','Uses field1 and field2 to generate Syslog alert in facility daemon with "alert" level.');
-INSERT INTO `talerta` VALUES (8,'Sound Alert','/usr/bin/play /usr/share/sounds/alarm.wav','');
-INSERT INTO `talerta` VALUES (9,'Jabber Alert','echo _field3_ | sendxmpp -r _field1_ --chatroom _field2_','Send jabber alert to chat room in a predefined server (configure first .sendxmpprc file). Uses field3 as text message, field1 as useralias for source message, and field2 for chatroom name');
+INSERT INTO `talert_commands` VALUES (5,'Pandora FMS Alertlog','echo _timestamp_ pandora _agent_ _data_ _field1_ _field2_ >> /var/log/pandora/pandora_alert.log','This is a default alert to write alerts in a standard ASCII  plaintext log file in /var/log/pandora/pandora_alert.log\r\n', 0);
+INSERT INTO `talert_commands` VALUES (6,'SNMP Trap','/usr/bin/snmptrap -v 1 -c trap_public 192.168.0.4 1.1.1.1.1.1.1.1 _agent_ _field1_','Send a SNMPTRAP to 192.168.0.4. Please review config and adapt to your needs, this is only a sample, not functional itself.', 0);
+INSERT INTO `talert_commands` VALUES (7,'Syslog','logger -p daemon.alert Pandora Alert _agent_ _data_ _field1_ _field2_','Uses field1 and field2 to generate Syslog alert in facility daemon with "alert" level.', 0);
+INSERT INTO `talert_commands` VALUES (8,'Sound Alert','/usr/bin/play /usr/share/sounds/alarm.wav','', 0);
+INSERT INTO `talert_commands` VALUES (9,'Jabber Alert','echo _field3_ | sendxmpp -r _field1_ --chatroom _field2_','Send jabber alert to chat room in a predefined server (configure first .sendxmpprc file). Uses field3 as text message, field1 as useralias for source message, and field2 for chatroom name');
 
 
 --