diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index dcc0b252ac..61ec06a93b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,18 @@ +2012-04-26 Miguel de Dios + + * operation/agentes/exportdata.php, + operation/events/events_list.php: cleaned source code style. + + * include/functions_events.php, + include/functions_network_components.php, + include/functions_api.php: fixed some things, the function + "events_validate_event" when can't update as validate any event + return false, into the file "functions_network_components" added + $config['homedir'] for situations where include in a other path that + index. And show error when make a bad validate event. + + MERGED FROM 4.0.2 + 2012-04-26 Juan Manuel Ramon * include/styles/pandora_forms.css diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6585397a99..c590b29ea3 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14,6 +14,8 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; + //Set character encoding to UTF-8 - fixes a lot of multibyte character headaches require_once('functions_agents.php'); @@ -4410,7 +4412,7 @@ function set_validate_events($id_event, $trash1, $other, $return_type, $user_in_ returnData('string', array('type' => 'string', 'data' => 'Correct validation')); } else { - returnError('error_validate_event', 'Error in validation operation.'); + returnError('Error in validation operation.'); } } @@ -4530,25 +4532,25 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d $sql_post .= " AND id_alert_am = ".$id_alert_am; if ($id_event != -1) - $sql_post .= " AND id_evento = ".$id_event; + $sql_post .= " AND id_evento = " . $id_event; if ($id_user_ack != "0") - $sql_post .= " AND id_usuario = '".$id_user_ack."'"; + $sql_post .= " AND id_usuario = '" . $id_user_ack . "'"; if ($utimestamp_upper != 0) - $sql_post .= " AND utimestamp >= ".$utimestamp_upper; + $sql_post .= " AND utimestamp >= " . $utimestamp_upper; if ($utimestamp_bottom != 0) - $sql_post .= " AND utimestamp <= ".$utimestamp_bottom; + $sql_post .= " AND utimestamp <= " . $utimestamp_bottom; if ($event_view_hr > 0) { $unixtime = get_system_time () - ($event_view_hr * 3600); //Put hours in seconds - $sql_post .= " AND (utimestamp > ".$unixtime . " OR estado = 2)"; + $sql_post .= " AND (utimestamp > " . $unixtime . " OR estado = 2)"; } //Search by tag if ($tag != "") { - $sql_post .= " AND tags LIKE '%".io_safe_input($tag)."%'"; + $sql_post .= " AND tags LIKE '%" . io_safe_input($tag) . "%'"; } if ($group_rep == 0) { @@ -4557,12 +4559,12 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d if ($filter['total']) { $sql = "SELECT COUNT(*) FROM tevento - WHERE 1=1 ".$sql_post; + WHERE 1=1 " . $sql_post; } else if ($filter['more_criticity']) { $sql = "SELECT criticity FROM tevento - WHERE 1=1 ".$sql_post." ORDER BY criticity DESC LIMIT 1"; + WHERE 1=1 " . $sql_post . " ORDER BY criticity DESC LIMIT 1"; } else { $sql = "SELECT *, @@ -4570,7 +4572,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon FROM tevento - WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination; + WHERE 1=1 " . $sql_post . " ORDER BY utimestamp DESC LIMIT " . $offset . "," . $pagination; } break; case "postgresql": @@ -4580,7 +4582,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon FROM tevento - WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset; + WHERE 1=1 " . $sql_post . " ORDER BY utimestamp DESC LIMIT " . $pagination . " OFFSET " . $offset; break; case "oracle": //TODO TOTAL @@ -4652,7 +4654,7 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d } //html_debug_print($filter, true); $result = db_get_all_rows_sql ($sql); - //html_debug_print($sql); + //html_debug_print($sql, true); if (($result !== false) && (!$filter['total']) && (!$filter['more_criticity'])) { //Add the description and image diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index d5cf37c17a..ab3c4afdec 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -166,10 +166,10 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new } $id_event = array_unique($id_event); } - + db_process_sql_begin (); - switch($new_status) { + switch ($new_status) { case 1: $new_status_string = __('Validated'); break; @@ -183,9 +183,10 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new $comment = str_replace(array("\r\n", "\r", "\n"), '
', $comment); - if($comment != '') { + if ($comment != '') { $commentbox = '
'.$comment.'
'; - }else { + } + else { $commentbox = ''; } @@ -196,7 +197,7 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new $comment = '-- '.$new_status_string.' '.__('by').' '.$config['id_user'].' '.'['.date ($config["date_format"]).'] --
'.$commentbox; $fullevent = events_get_event($event); - if($fullevent['user_comment'] != ''){ + if ($fullevent['user_comment'] != '') { $comment .= '
'.$fullevent['user_comment']; } @@ -209,11 +210,13 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new 'id_usuario' => $config['id_user'], 'user_comment' => $comment); - $ret = db_process_sql_update('tevento', $values, array('id_evento' => $event), 'AND', false); - if ($ret === false) { - process_sql_rollback (); + $ret = db_process_sql_update('tevento', $values, + array('id_evento' => $event), 'AND', false); + + if (($ret === false) || ($ret === 0)) { + db_process_sql_rollback (); return false; - } + } } /* @@ -222,6 +225,7 @@ function events_validate_event ($id_event, $similars = true, $comment = '', $new } */ db_process_sql_commit (); + return true; } diff --git a/pandora_console/include/functions_network_components.php b/pandora_console/include/functions_network_components.php index 56e2aee7fd..2d99076265 100644 --- a/pandora_console/include/functions_network_components.php +++ b/pandora_console/include/functions_network_components.php @@ -18,12 +18,14 @@ * @subpackage Network components */ +global $config; + /** * Include modules functions */ -include_once ($config['homedir'].'/include/functions_modules.php'); -include_once ($config['homedir'].'/include/functions_agents.php'); -include_once ($config['homedir'].'/include/functions_users.php'); +include_once ($config['homedir'] . 'include/functions_modules.php'); +include_once ($config['homedir'] . 'include/functions_agents.php'); +include_once ($config['homedir'] . 'include/functions_users.php'); /** * Get a list of network components. @@ -43,7 +45,7 @@ include_once ($config['homedir'].'/include/functions_users.php'); */ function network_components_get_network_components ($id_module, $filter = false, $fields = false) { global $config; - + if (! is_array ($filter)) $filter = array (); if (! empty ($id_module)) @@ -55,18 +57,17 @@ function network_components_get_network_components ($id_module, $filter = false, $components = db_get_all_rows_filter ('tnetwork_component', $filter, $fields); break; - case "oracle": + case "oracle": if (count ($fields) > 1) { $fields = implode(',',$fields); - } + } if (isset($filter['offset'])) { $components = oracle_recode_query ('SELECT ' . $fields . ' FROM tnetwork_component', $filter, 'AND', false); if ($components != false) { - for ($i=0; $i < count($components); $i++) { - unset($components[$i]['rnum']); + unset($components[$i]['rnum']); } - } + } } else { $components = db_get_all_rows_filter ('tnetwork_component', @@ -76,6 +77,7 @@ function network_components_get_network_components ($id_module, $filter = false, } if ($components === false) return array (); + return $components; } @@ -235,14 +237,15 @@ function network_components_get_network_component ($id_network_component, $filte */ function network_components_create_network_component ($name, $type, $id_group, $values = false) { global $config; - + switch ($config['dbtype']) { case "oracle": if (empty($values['tcp_rcv'])) $values['tcp_rcv'] = " "; - return; + return; + break; } - + if (empty ($name)) return false; if (empty ($type)) @@ -374,31 +377,31 @@ function network_components_duplicate_network_component ($id_local_component) { return false; $name = __('Copy of').' '.$network['name']; - - $networkCopy['description'] = $network['description']; - $networkCopy['max'] = $network['max']; - $networkCopy['min'] = $network['min']; - $networkCopy['module_interval'] = $network['module_interval']; - $networkCopy['tcp_port'] = $network['tcp_port']; - $networkCopy['tcp_send'] = $network['tcp_send']; - $networkCopy['tcp_rcv'] = $network['tcp_rcv']; - $networkCopy['snmp_community'] = $network['snmp_community']; - $networkCopy['snmp_oid'] = $network['snmp_oid']; - $networkCopy['id_module_group'] = $network['id_module_group']; - $networkCopy['id_modulo'] = $network['id_modulo']; - $networkCopy['id_plugin'] = $network['id_plugin']; - $networkCopy['plugin_user'] = $network['plugin_user']; - $networkCopy['plugin_pass'] = $network['plugin_pass']; - $networkCopy['plugin_parameter'] = $network['plugin_parameter']; - $networkCopy['max_timeout'] = $network['max_timeout']; - $networkCopy['history_data'] = $network['history_data']; - $networkCopy['min_warning'] = $network['min_warning']; - $networkCopy['max_warning'] = $network['max_warning']; - $networkCopy['str_warning'] = $network['str_warning']; - $networkCopy['min_critical'] = $network['min_critical']; - $networkCopy['max_critical'] = $network['max_critical']; - $networkCopy['str_critical'] = $network['str_critical']; - $networkCopy['min_ff_event'] = $network['min_ff_event']; + + $networkCopy['description'] = $network['description']; + $networkCopy['max'] = $network['max']; + $networkCopy['min'] = $network['min']; + $networkCopy['module_interval'] = $network['module_interval']; + $networkCopy['tcp_port'] = $network['tcp_port']; + $networkCopy['tcp_send'] = $network['tcp_send']; + $networkCopy['tcp_rcv'] = $network['tcp_rcv']; + $networkCopy['snmp_community'] = $network['snmp_community']; + $networkCopy['snmp_oid'] = $network['snmp_oid']; + $networkCopy['id_module_group'] = $network['id_module_group']; + $networkCopy['id_modulo'] = $network['id_modulo']; + $networkCopy['id_plugin'] = $network['id_plugin']; + $networkCopy['plugin_user'] = $network['plugin_user']; + $networkCopy['plugin_pass'] = $network['plugin_pass']; + $networkCopy['plugin_parameter'] = $network['plugin_parameter']; + $networkCopy['max_timeout'] = $network['max_timeout']; + $networkCopy['history_data'] = $network['history_data']; + $networkCopy['min_warning'] = $network['min_warning']; + $networkCopy['max_warning'] = $network['max_warning']; + $networkCopy['str_warning'] = $network['str_warning']; + $networkCopy['min_critical'] = $network['min_critical']; + $networkCopy['max_critical'] = $network['max_critical']; + $networkCopy['str_critical'] = $network['str_critical']; + $networkCopy['min_ff_event'] = $network['min_ff_event']; return network_components_create_network_component ($name, $network['type'], $network['id_group'], $networkCopy); } diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index 1ad2c4fb9e..7a53065a19 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -462,7 +462,6 @@ $(document).ready (function () { } $("select#export_type").trigger('change'); - }); $("select#export_type").change (function () { @@ -479,7 +478,7 @@ $("select#export_type").change (function () { case 'data': f.action = "index.php?sec=reporting&sec2=operation/agentes/exportdata"; break; - } + } }); function submit_group() { @@ -487,6 +486,5 @@ function submit_group() { f.action = "index.php?sec=reporting&sec2=operation/agentes/exportdata"; f.form.submit(); } - /* ]]> */ diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 682b6167d7..8817bbf593 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -127,7 +127,7 @@ $tag = get_parameter("tag", ""); if ($id_agent == -2) { $text_agent = (string) get_parameter("text_agent", __("All")); - + switch ($text_agent) { case __('All'): @@ -176,7 +176,7 @@ else { // Skip system messages if user is not PM if (!check_acl ($config["id_user"], 0, "PM")) { - $sql_post .= " AND id_grupo != 0"; + $sql_post .= " AND id_grupo != 0"; } switch($status) { @@ -455,7 +455,7 @@ else { case "mysql": db_process_sql ('SET group_concat_max_len = 9999999'); $sql = "SELECT *, MAX(id_evento) AS id_evento, GROUP_CONCAT(DISTINCT user_comment SEPARATOR '') AS user_comment, - MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep + MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep FROM tevento WHERE 1=1 ".$sql_post." GROUP BY evento, id_agentmodule @@ -463,7 +463,7 @@ else { break; case "postgresql": $sql = "SELECT *, MAX(id_evento) AS id_evento, array_to_string(array_agg(DISTINCT user_comment), '') AS user_comment, - MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep + MIN(estado) AS min_estado, MAX(estado) AS max_estado, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep FROM tevento WHERE 1=1 ".$sql_post." GROUP BY evento, id_agentmodule, id_evento, id_agente, id_usuario, id_grupo, estado, timestamp, utimestamp, event_type, id_alert_am, criticity, user_comment, tags, source, id_extra @@ -499,7 +499,7 @@ if (($config['dbtype'] == 'oracle') && ($result !== false)) { for ($i=0; $i < count($result); $i++) { unset($result[$i]['rnum']); } -} +} if ($group_rep == 0) { $sql = "SELECT COUNT(id_evento) FROM tevento WHERE 1=1 ".$sql_post; @@ -909,14 +909,14 @@ foreach ($result as $event) { $string .= ''; $string .= '' . __('Event name') . ''; $string .= io_safe_output($event["evento"]); - $string .= ''; + $string .= ''; $string .= ''; $string .= '' . __('Severity') . ''; $string .= html_print_image ($img_sev, true, - array ("class" => "image_status", - "width" => 12, - "height" => 12, - "title" => get_priority_name ($event["criticity"]))); + array ("class" => "image_status", + "width" => 12, + "height" => 12, + "title" => get_priority_name ($event["criticity"]))); $string .= ' '.get_priority_name ($event["criticity"]); $string .= ''; $string .= ''; @@ -934,7 +934,7 @@ foreach ($result as $event) { } else { $string .= date ($config["date_format"], strtotime($event["timestamp"])); - } + } $string .= ''; $odd = 'rowOdd'; @@ -966,9 +966,10 @@ foreach ($result as $event) { $string .= ''; $string .= $module_group; $string .= ''; - + $odd = ($odd == '')? 'rowOdd' : ''; - } else { + } + else { $string .= ''; $string .= '' . __('Agent module') . ''; $string .= '- ' . __('Empty') . ' -'; @@ -995,17 +996,17 @@ foreach ($result as $event) { $string .= html_print_image ("images/bell_pause.png", true, array ("title" => __('Go to data overview'))); } - + $sql = 'SELECT name FROM talert_templates WHERE id IN (SELECT id_alert_template FROM talert_template_modules WHERE id = ' . $event["id_alert_am"] . ');'; - + $templateName = db_get_sql($sql); - + $string .= $templateName; - + $string .= ''; $odd = ($odd == '')? 'rowOdd' : ''; @@ -1114,15 +1115,14 @@ if (!empty ($table->data)) { echo '
'; echo ""; - + html_print_table ($table); - + echo '
'; if (check_acl ($config["id_user"], 0, "IW") == 1) { html_print_submit_button (__('Update'), 'validate_btn', false, 'class="sub ok"'); } if (check_acl ($config["id_user"], 0,"IM") == 1) { - html_print_button(__('Delete'), 'delete_button', false, 'submit_delete();', 'class="sub delete"'); ?>