From e6d02b75404fb732fa5f417499a51e9eeb3a97b0 Mon Sep 17 00:00:00 2001 From: Aldrioth Date: Mon, 1 Aug 2011 16:52:26 +0000 Subject: [PATCH] 2011-08-01 Tomas Palacios * godmode/massive: fixed a bug regarding warnings, SQL errors and undefined variables in massive alert ops. * godmode/snmpconsole/snmp_alert.php godmode/users/profile_list.php: fixed a bug regarding creation of snmp alerts and profiles with no info at all. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4659 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- .../massive/massive_add_action_alerts.php | 2 +- .../godmode/massive/massive_add_alerts.php | 2 +- .../massive/massive_delete_action_alerts.php | 2 +- .../godmode/massive/massive_delete_alerts.php | 2 +- .../massive/massive_enable_disable_alerts.php | 4 +- .../godmode/snmpconsole/snmp_alert.php | 31 ++++--- .../godmode/users/profile_list.php | 81 +++++++++++-------- 7 files changed, 73 insertions(+), 51 deletions(-) diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 561796122f..5aa19a4b26 100644 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -66,7 +66,7 @@ $id_alert_compounds = (array) get_parameter ('id_alert_compounds'); $add = (bool) get_parameter_post ('add'); if ($add) { - if(empty($id_agents)) + if(empty($id_agents) || $id_agents[0] == 0) ui_print_result_message (false, '', __('Could not be added').". ".__('No agents selected')); else { $action = (int) get_parameter ('action'); diff --git a/pandora_console/godmode/massive/massive_add_alerts.php b/pandora_console/godmode/massive/massive_add_alerts.php index 1377a07162..acd9b0f55f 100644 --- a/pandora_console/godmode/massive/massive_add_alerts.php +++ b/pandora_console/godmode/massive/massive_add_alerts.php @@ -44,7 +44,7 @@ if (is_ajax ()) { } function process_manage_add ($id_alert_template, $id_agents, $module_names) { - if (empty ($id_agents)) { + if (empty ($id_agents) || $id_agents[0] == 0) { echo '

'.__('No agents selected').'

'; return false; } diff --git a/pandora_console/godmode/massive/massive_delete_action_alerts.php b/pandora_console/godmode/massive/massive_delete_action_alerts.php index 69bf1b05bc..c0921becd0 100644 --- a/pandora_console/godmode/massive/massive_delete_action_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_action_alerts.php @@ -65,7 +65,7 @@ $id_alert_compounds = (array) get_parameter ('id_alert_compounds'); $delete = (bool) get_parameter_post ('delete'); if ($delete) { - if(empty($id_agents)) + if(empty($id_agents) || $id_agents[0] == 0) ui_print_result_message (false, '', __('Could not be deleted').". ".__('No agents selected')); else { $action = (int) get_parameter ('action'); diff --git a/pandora_console/godmode/massive/massive_delete_alerts.php b/pandora_console/godmode/massive/massive_delete_alerts.php index d0f55b839c..9dc2f14f98 100644 --- a/pandora_console/godmode/massive/massive_delete_alerts.php +++ b/pandora_console/godmode/massive/massive_delete_alerts.php @@ -51,7 +51,7 @@ function process_manage_delete ($id_alert_template, $id_agents, $module_names) { return false; } - if (empty ($id_agents)) { + if (empty ($id_agents) || $id_agents[0] == 0) { echo '

'.__('No agents selected').'

'; return false; } diff --git a/pandora_console/godmode/massive/massive_enable_disable_alerts.php b/pandora_console/godmode/massive/massive_enable_disable_alerts.php index a521498a76..3a9ae40dbc 100644 --- a/pandora_console/godmode/massive/massive_enable_disable_alerts.php +++ b/pandora_console/godmode/massive/massive_enable_disable_alerts.php @@ -93,9 +93,9 @@ switch($action) { ui_print_result_message ($result, __('Successfully disabled'), __('Could not be disabled')); - $info = 'Alert: ' . json_encode($id_disabled_alerts); + $info = 'Alert: ' . json_encode($id_enabled_alerts); if ($result) { - db_pandora_audit("Masive management", "Disaable alert", false, false, $info); + db_pandora_audit("Masive management", "Disable alert", false, false, $info); } else { db_pandora_audit("Masive management", "Fail try to Disable alert", false, false, $info); diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 1ba4cdce86..3fbad6f9de 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -65,9 +65,14 @@ if (isset ($_GET["update_alert"]) && $_GET["update_alert"] == "-1") { 'max_alerts' => $max_alerts, 'min_alerts' => $min_alerts, 'priority' => $priority); - $result = db_process_sql_insert('talert_snmp', $values); + if (!$source_ip || !$oid) { + $result = ''; + } + else { + $result = db_process_sql_insert('talert_snmp', $values); + } - if ($result === false) { + if (!$result) { echo '

'.__('There was a problem creating the alert').'

'; } else { @@ -75,15 +80,21 @@ if (isset ($_GET["update_alert"]) && $_GET["update_alert"] == "-1") { } } else { - $sql = sprintf ("UPDATE talert_snmp SET - priority = %d, id_alert = %d, al_field1 = '%s', al_field2 = '%s', al_field3 = '%s', description = '%s', agent = '%s', custom_oid = '%s', - oid = '%s', time_threshold = %d, max_alerts = %d, min_alerts = %d WHERE id_as = %d", - $priority, $alert_type, $al_field1, $al_field2, $al_field3, $description, $source_ip, $custom_value, - $oid, $time_threshold, $max_alerts, $min_alerts, $id_as); - - $result = db_process_sql ($sql); - if ($result === false) { + if (!$source_ip || !$oid) { + $result = ''; + } + else { + $sql = sprintf ("UPDATE talert_snmp SET + priority = %d, id_alert = %d, al_field1 = '%s', al_field2 = '%s', al_field3 = '%s', description = '%s', agent = '%s', custom_oid = '%s', + oid = '%s', time_threshold = %d, max_alerts = %d, min_alerts = %d WHERE id_as = %d", + $priority, $alert_type, $al_field1, $al_field2, $al_field3, $description, $source_ip, $custom_value, + $oid, $time_threshold, $max_alerts, $min_alerts, $id_as); + + $result = db_process_sql ($sql); + } + + if (!$result) { echo '

'.__('There was a problem updating the alert').'

'; } else { echo '

'.__('Successfully updated').'

'; diff --git a/pandora_console/godmode/users/profile_list.php b/pandora_console/godmode/users/profile_list.php index b3df77c14d..6019989e32 100644 --- a/pandora_console/godmode/users/profile_list.php +++ b/pandora_console/godmode/users/profile_list.php @@ -89,30 +89,35 @@ if ($update_profile) { $alert_management = (bool) get_parameter ("alert_management"); $pandora_management = (bool) get_parameter ("pandora_management"); - $sql = sprintf ('UPDATE tperfil SET - name = "%s", incident_view = %d, incident_edit = %d, - incident_management = %d, agent_view = %d, agent_edit = %d, - alert_edit = %d, user_management = %d, db_management = %d, - alert_management = %d, pandora_management = %d WHERE id_perfil = %d', - $name, $incident_view, $incident_edit, $incident_management, - $agent_view, $agent_edit, $alert_edit, $user_management, - $db_management, $alert_management, $pandora_management, - $id_profile); - $ret = db_process_sql ($sql); - if ($ret !== false) { - $info = 'Name: ' . $name . ' Incident view: ' . $incident_view . - ' Incident edit: ' . $incident_edit . ' Incident management: ' . $incident_management . - ' Agent view: ' . $agent_view . ' Agent edit: ' . $agent_edit . - ' Alert edit: ' . $alert_edit . ' User management: ' . $user_management . - ' DB management: ' . $db_management . ' Alert management: ' . $alert_management . - ' Pandora Management: ' . $pandora_management; - db_pandora_audit("User management", - "Update profile ". $name, false, false, $info); - - echo '

'.__('Successfully updated').'

'; + if ($name) { + $sql = sprintf ('UPDATE tperfil SET + name = "%s", incident_view = %d, incident_edit = %d, + incident_management = %d, agent_view = %d, agent_edit = %d, + alert_edit = %d, user_management = %d, db_management = %d, + alert_management = %d, pandora_management = %d WHERE id_perfil = %d', + $name, $incident_view, $incident_edit, $incident_management, + $agent_view, $agent_edit, $alert_edit, $user_management, + $db_management, $alert_management, $pandora_management, + $id_profile); + $ret = db_process_sql ($sql); + if ($ret !== false) { + $info = 'Name: ' . $name . ' Incident view: ' . $incident_view . + ' Incident edit: ' . $incident_edit . ' Incident management: ' . $incident_management . + ' Agent view: ' . $agent_view . ' Agent edit: ' . $agent_edit . + ' Alert edit: ' . $alert_edit . ' User management: ' . $user_management . + ' DB management: ' . $db_management . ' Alert management: ' . $alert_management . + ' Pandora Management: ' . $pandora_management; + db_pandora_audit("User management", + "Update profile ". $name, false, false, $info); + + echo '

'.__('Successfully updated').'

'; + } + else { + echo '

'; + } } else { - echo '

'; + echo '

'; } $id_profile = 0; } @@ -143,22 +148,28 @@ if ($create_profile) { 'db_management' => $db_management, 'alert_management' => $alert_management, 'pandora_management' => $pandora_management); - $ret = db_process_sql_insert('tperfil', $values); + + if ($name) { + $ret = db_process_sql_insert('tperfil', $values); - if ($ret !== false) { - echo '

'.__('Successfully created').'

'; - - $info = 'Name: ' . $name . ' Incident view: ' . $incident_view . - ' Incident edit: ' . $incident_edit . ' Incident management: ' . $incident_management . - ' Agent view: ' . $agent_view . ' Agent edit: ' . $agent_edit . - ' Alert edit: ' . $alert_edit . ' User management: ' . $user_management . - ' DB management: ' . $db_management . ' Alert management: ' . $alert_management . - ' Pandora Management: ' . $pandora_management; - db_pandora_audit("User management", - "Created profile ". $name, false, false, $info); + if ($ret !== false) { + echo '

'.__('Successfully created').'

'; + + $info = 'Name: ' . $name . ' Incident view: ' . $incident_view . + ' Incident edit: ' . $incident_edit . ' Incident management: ' . $incident_management . + ' Agent view: ' . $agent_view . ' Agent edit: ' . $agent_edit . + ' Alert edit: ' . $alert_edit . ' User management: ' . $user_management . + ' DB management: ' . $db_management . ' Alert management: ' . $alert_management . + ' Pandora Management: ' . $pandora_management; + db_pandora_audit("User management", + "Created profile ". $name, false, false, $info); + } + else { + echo '

'.__('There was a problem creating this profile').'

'; + } } else { - echo '

'.__('There was a problem creating this profile').'

'; + echo '

'; } $id_profile = 0; }