From 57f5db749af2221917bf07ec933754a472f1d52e Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Jul 2012 09:59:03 +0000 Subject: [PATCH] 2012-07-24 Miguel de Dios * operation/messages/message_edit.php, operation/reporting/reporting_xml.php, operation/reporting/graph_viewer.php, operation/agentes/exportdata.php, operation/agentes/group_view.php, operation/agentes/status_monitor.php, godmode/agentes/configurar_agente.php, include/functions_agents.php: cleaned source code style. * godmode/agentes/module_manager.php: fixed the messages for to delete multiple modules. Fixes: #3543532 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6807 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 15 +++ .../godmode/agentes/configurar_agente.php | 2 +- .../godmode/agentes/module_manager.php | 96 ++++++++++++------- pandora_console/include/functions_agents.php | 2 - .../operation/agentes/exportdata.php | 44 +++++---- .../operation/agentes/group_view.php | 52 +++++----- .../operation/agentes/status_monitor.php | 38 ++++---- .../operation/messages/message_edit.php | 7 +- .../operation/reporting/graph_viewer.php | 27 +++--- .../operation/reporting/reporting_xml.php | 8 +- 10 files changed, 169 insertions(+), 122 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index bc5d4ec110..366c2c7edb 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,18 @@ +2012-07-24 Miguel de Dios + + * operation/messages/message_edit.php, + operation/reporting/reporting_xml.php, + operation/reporting/graph_viewer.php, + operation/agentes/exportdata.php, operation/agentes/group_view.php, + operation/agentes/status_monitor.php, + godmode/agentes/configurar_agente.php, include/functions_agents.php: + cleaned source code style. + + * godmode/agentes/module_manager.php: fixed the messages for to + delete multiple modules. + + Fixes: #3543532 + 2012-07-24 Miguel de Dios * godmode/setup/file_manager.php, godmode/setup/news.php, diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c08e1e21e6..ebd234d142 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -977,7 +977,7 @@ if ($delete_module) { // DELETE agent module ! $result = db_process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $id_borrar_modulo)); if ($result === false) $error++; - + if (alerts_delete_alert_agent_module($id_borrar_modulo) === false) $error++; diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 79e1e31525..11f90e2f90 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -31,7 +31,8 @@ $search_string = io_safe_output(urldecode(trim(get_parameter ("search_string", " echo '
'; echo ''; echo ""; echo "
"; -echo __('Search').' '.html_print_input_text ('search_string', $search_string, '', 15, 255, true); +echo __('Search') . ' ' . + html_print_input_text ('search_string', $search_string, '', 15, 255, true); echo ""; html_print_submit_button (__('Filter'), 'filter', false, 'class="sub search"'); @@ -92,13 +93,14 @@ echo "
"; if (! isset ($id_agente)) return; - + $multiple_delete = (bool) get_parameter('multiple_delete'); if ($multiple_delete) { $id_agent_modules_delete = (array)get_parameter('id_delete'); + $count_correct_delete_modules = 0; foreach($id_agent_modules_delete as $id_agent_module_del) { $id_grupo = (int) agents_get_agent_group($id_agente); @@ -112,7 +114,7 @@ if ($multiple_delete) { if ($id_agent_module_del < 1) { db_pandora_audit("HACK Attempt", "Expected variable from form is not correct"); - die ("Nice try buddy"); + die (__("Nice try buddy")); exit; } @@ -130,14 +132,14 @@ if ($multiple_delete) { if (db_process_sql("UPDATE tagente_modulo SET nombre = 'pendingdelete', disabled = 1, delete_pending = 1 WHERE id_agente_modulo = ".$id_agent_module_del, "affected_rows", '', true, $status, false) === false) $error++; - + switch ($config["dbtype"]) { case "mysql": - case "postgresql": + case "postgresql": $result = db_process_sql_delete('tagente_estado', array('id_agente_modulo' => $id_agent_module_del)); if ($result === false) $error++; - + $result = db_process_sql_delete('tagente_datos_inc', array('id_agente_modulo' => $id_agent_module_del)); if ($result === false) $error++; @@ -150,8 +152,7 @@ if ($multiple_delete) { if ($result === false) $error++; break; - - } + } // Trick to detect if we are deleting a synthetic module (avg or arithmetic) // If result is empty then module doesn't have this type of submodules @@ -177,22 +178,38 @@ if ($multiple_delete) { $update_orders = false; $result = enterprise_hook('modules_delete_synthetic_operations', array($id_target_module, $id_agent_module_del, $update_orders)); if ($result === false) - $error++; + $error++; $count_components++; $last_target_module = $id_target_module; } } - } - + } + //Check for errors if ($error != 0) { db_process_sql_rollback (); - ui_print_error_message (__('There was a problem deleting the module')); } else { db_process_sql_commit (); - ui_print_success_message (__('Module deleted succesfully')); + $count_correct_delete_modules++; + } + } + + $count_modules_to_delete = count($id_agent_modules_delete); + if ($count_correct_delete_modules == 0) { + ui_print_error_message( + sprintf(__('There was a problem deleting %s modules, none deleted.'), + $count_modules_to_delete)); + } + else { + if ($count_correct_delete_modules == $count_modules_to_delete) { + ui_print_success_message (__('All Modules deleted succesfully')); + } + else { + ui_print_error_message( + sprintf(__('There was a problem only deleted %s modules of %s total.'), + count_correct_delete_modules, $count_modules_to_delete)); } } } @@ -224,7 +241,7 @@ switch ($sortField) { $selectNameUp = $selected; switch ($config["dbtype"]) { case "mysql": - case "postgresql": + case "postgresql": $order[] = array('field' => 'tagente_modulo.nombre', 'order' => 'ASC'); break; case "oracle": @@ -242,7 +259,7 @@ switch ($sortField) { case "oracle": $order[] = array('field' => 'dbms_lob.substr(tagente_modulo.nombre,4000,1)', 'order' => 'DESC'); break; - } + } break; } break; @@ -305,13 +322,13 @@ switch ($sortField) { // TODO: CLEAN extra_sql $extra_sql = ''; - + // Build the order sql -if(!empty($order)) { +if (!empty($order)) { $order_sql = ' ORDER BY '; } $first = true; -foreach($order as $ord) { +foreach ($order as $ord) { if($first) { $first = false; } @@ -326,12 +343,13 @@ foreach($order as $ord) { $limit = (int) $config["block_size"]; $offset = (int) get_parameter ('offset'); -$params = implode(',', array ('id_agente_modulo', 'id_tipo_modulo', 'descripcion', 'nombre', - 'max', 'min', 'module_interval', 'id_modulo', 'id_module_group', - 'disabled','max_warning', 'min_warning', 'str_warning', - 'max_critical', 'min_critical', 'str_critical')); - -$where = sprintf("delete_pending = 0 AND id_agente = %s", $id_agente); +$params = implode(',', array ('id_agente_modulo', 'id_tipo_modulo', + 'descripcion', 'nombre', 'max', 'min', 'module_interval', + 'id_modulo', 'id_module_group', 'disabled','max_warning', + 'min_warning', 'str_warning', 'max_critical', 'min_critical', + 'str_critical')); + +$where = sprintf("delete_pending = 0 AND id_agente = %s", $id_agente); $search_string_entities = io_safe_input($search_string); @@ -344,26 +362,32 @@ switch ($config["dbtype"]) { if(!isset($limit_sql)) { $limit_sql = " LIMIT $offset, $limit "; } - $sql = sprintf("SELECT %s FROM tagente_modulo WHERE %s (%s %s) %s %s", - $params, $basic_where, $extra_sql, $where, $order_sql, $limit_sql); - + $sql = sprintf("SELECT %s + FROM tagente_modulo + WHERE %s (%s %s) %s %s", + $params, $basic_where, $extra_sql, $where, $order_sql, $limit_sql); + $modules = db_get_all_rows_sql($sql); break; case "oracle": $set = array(); $set['limit'] = $limit; - $set['offset'] = $offset; - $sql = sprintf("SELECT %s FROM tagente_modulo WHERE %s (%s %s) %s", - $params, $basic_where, $extra_sql, $where, $order_sql); + $set['offset'] = $offset; + $sql = sprintf("SELECT %s + FROM tagente_modulo + WHERE %s (%s %s) %s", + $params, $basic_where, $extra_sql, $where, $order_sql); $modules = oracle_recode_query ($sql, $set, 'AND', false); break; } - -$sql_total_modules = sprintf("SELECT count(*) FROM tagente_modulo WHERE %s (%s %s)", $basic_where, $extra_sql, $where); + +$sql_total_modules = sprintf("SELECT count(*) + FROM tagente_modulo + WHERE %s (%s %s)", $basic_where, $extra_sql, $where); $total_modules = db_get_value_sql($sql_total_modules); -$total_modules = isset ($total_modules) ? $total_modules : 0; +$total_modules = isset ($total_modules) ? $total_modules : 0; if ($modules === false) { echo "
".__('No available data to show')."
"; @@ -421,11 +445,11 @@ foreach($tempRows as $row) { foreach ($modules as $module) { $is_extra = enterprise_hook('policies_is_module_extra_policy', array($module["id_agente_modulo"])); - + if($is_extra === ENTERPRISE_NOT_HOOK) { $is_extra = false; } - + if (! check_acl ($config["id_user"], $group, "AW", $id_agente) && !$is_extra) { continue; } @@ -571,4 +595,4 @@ html_print_input_hidden ('multiple_delete', 1); html_print_submit_button (__('Delete'), 'multiple_delete', false, 'class="sub delete"'); echo ''; echo '
' -?> +?> \ No newline at end of file diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 9c55118db5..9bb211a993 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1702,7 +1702,6 @@ function agents_get_status($id_agent = 0, $noACLs = false) { else { return AGENT_MODULE_STATUS_NORMAL; } - } /** @@ -1948,7 +1947,6 @@ function agents_monitor_unknown ($id_agent, $filter="") { } // Get ok monitors by using the status code in modules. - function agents_monitor_ok ($id_agent, $filter="") { if ($filter) { diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php index b621e14a3b..e412f2144c 100644 --- a/pandora_console/operation/agentes/exportdata.php +++ b/pandora_console/operation/agentes/exportdata.php @@ -304,37 +304,39 @@ if (empty($export_btn)) { //Agent selector $table->data[1][0] = ''.__('Source agent').''; - + if ($group > 0) { $filter['id_grupo'] = (array) $group; - } else { + } + else { $filter['id_grupo'] = array_keys ($groups); } - + $agents = array (); $rows = agents_get_agents ($filter, false, 'AR'); if ($rows == null) $rows = array(); foreach ($rows as $row) { $agents[$row['id_agente']] = $row['nombre']; } - + //Src code of lightning image with skins $src_code = html_print_image ('images/lightning.png', true, false, true); - + $table->data[1][1] = html_print_input_text_extended ('agent', agents_get_name ($agent), 'text-agent', '', 40, 100, false, '', array('style' => "background: url($src_code) no-repeat right;"), true) . ' ' . __("Type at least two characters to search") . ''; - + //Module selector $table->data[2][0] = ''.__('Modules').''; $table->data[2][0] .= ui_print_help_tip(__("No modules of type string. You can not calculate their average"),true); - + if ($agent > 0) { $modules = agents_get_modules ($agent); - } else { + } + else { $modules = array (); } - + if(!empty($modules)) { //remove modules of type string because you cant calculate their average. $i = 0; foreach ($modules as $key=>$module) { @@ -351,40 +353,40 @@ if (empty($export_btn)) { $i++; } } - + $disabled_export_button = false; if (empty($modules)) { $disabled_export_button = true; } - + $table->data[2][1] = html_print_select ($modules, "module_arr[]", array_keys ($modules), '', '', 0, true, true, true, 'w155', false); - + //Start date selector $table->data[3][0] = ''.__('Begin date').''; - + $table->data[3][1] = html_print_input_text ('start_date', date ("Y-m-d", get_system_time () - 86400), false, 10, 10, true); $table->data[3][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-start_date'),this);")); $table->data[3][1] .= html_print_input_text ('start_time', date ("H:i", get_system_time () - 86400), false, 10, 5, true); - + //End date selector $table->data[4][0] = ''.__('End date').''; $table->data[4][1] = html_print_input_text ('end_date', date ("Y-m-d", get_system_time ()), false, 10, 10, true); $table->data[4][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-end_date'),this);")); $table->data[4][1] .= html_print_input_text ('end_time', date ("H:i", get_system_time ()), false, 10, 5, true); - + //Export type $table->data[5][0] = ''.__('Export type').''; - + $export_types = array (); $export_types["data"] = __('Data table'); $export_types["csv"] = __('CSV'); $export_types["excel"] = __('MS Excel'); $export_types["avg"] = __('Average per hour/day'); - + $table->data[5][1] = html_print_select ($export_types, "export_type", $export_type, '', '', 0, true, false, true, 'w130', false); - + html_print_table ($table); - + // Submit button echo '
'; html_print_button (__('Export'), 'export_btn', $disabled_export_button, 'change_action()', 'class="sub wand"'); @@ -483,7 +485,7 @@ $(document).ready (function () { function change_action() { type = $("#export_type").val(); var f = document.forms.export_form; - + switch (type) { case 'csv': f.action = "operation/agentes/exportdata.csv.php"; @@ -505,4 +507,4 @@ function submit_group() { f.form.submit(); } /* ]]> */ - + \ No newline at end of file diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php index c1c8443d47..02f41cd090 100644 --- a/pandora_console/operation/agentes/group_view.php +++ b/pandora_console/operation/agentes/group_view.php @@ -66,7 +66,8 @@ foreach($groups_full as $group) { if ($config["realtimestats"] == 0){ $updated_time = __('Last update'). " : ". ui_print_timestamp (db_get_sql ("SELECT min(utimestamp) FROM tgroup_stat"), true); -} else { +} +else { $updated_time = __("Updated at realtime"); } @@ -81,32 +82,31 @@ $counter = 1; $agents = agents_get_group_agents(array_keys($groups)); if (count($agents) > 0) { - -echo ''; - -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; -echo ""; - -$printed_groups = array(); - -// For each valid group for this user, take data from agent and modules -foreach ($groups as $id_group => $group) { - groups_get_group_row($id_group, $groups, $group, $printed_groups); + echo '
".__("Group").""; -echo "".__("Agents")."".__("Agent unknown")."".__("Unknown")."".__("Not Init")."".__("Normal")."".__("Warning")."".__("Critical")."".__("Alert fired")."
'; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + $printed_groups = array(); + + // For each valid group for this user, take data from agent and modules + foreach ($groups as $id_group => $group) { + groups_get_group_row($id_group, $groups, $group, $printed_groups); + } + + echo "
".__("Group").""; + echo "".__("Agents")."".__("Agent unknown")."".__("Unknown")."".__("Not Init")."".__("Normal")."".__("Warning")."".__("Critical")."".__("Alert fired")."
"; } - -echo ""; - -} else { - echo "
".__('There are no defined agents')."
"; +else { + echo "
" . __('There are no defined agents') . + "
"; } ?> diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index f0ba2a786a..78ef2cd4dc 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -328,9 +328,9 @@ switch ($sortField) { // Begin Build SQL sentences $sql = " FROM tagente, tagente_modulo, tagente_estado WHERE $sql_extra (tagente.id_agente = tagente_modulo.id_agente - AND tagente_modulo.disabled = 0 - AND tagente.disabled = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo"; + AND tagente_modulo.disabled = 0 + AND tagente.disabled = 0 + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo"; // Agent group selector if ($ag_group > 0 && check_acl ($config["id_user"], $ag_group, "AR")) { @@ -453,7 +453,7 @@ switch ($config["dbtype"]) { tagente_modulo.max_critical, tagente_modulo.str_critical, tagente_modulo.extended_info, - tagente_estado.utimestamp AS utimestamp".$sql; + tagente_estado.utimestamp AS utimestamp" . $sql; $sql = oracle_recode_query ($sql, $set); break; } @@ -469,7 +469,7 @@ if ($result === false) { if (($config['dbtype'] == 'oracle') && ($result !== false)) { for ($i=0; $i < count($result); $i++) { - unset($result[$i]['rnum']); + unset($result[$i]['rnum']); } } @@ -568,7 +568,7 @@ foreach ($result as $row) { $title = __('(Unlinked) ') . $policyInfo['name_policy']; } } - + $data[0] = '' . html_print_image($img,true, array('title' => $title)) . ''; @@ -625,18 +625,18 @@ foreach ($result as $row) { $handle = "stat".$nombre_tipo_modulo."_".$row["id_agente_modulo"]; $url = 'include/procesos.php?agente='.$row["id_agente_modulo"]; $win_handle=dechex(crc32($row["id_agente_modulo"].$row["module_name"])); - + $link ="winopeng('operation/agentes/stat_win.php?type=$graph_type&period=86400&id=".$row["id_agente_modulo"]."&label=".base64_encode($row["module_name"])."&refresh=600','day_".$win_handle."')"; - + $data[6] = '' . html_print_image("images/chart_curve.png", true, array("border" => '0', "alt" => "")) . ''; $data[6] .= " " . html_print_image('images/binary.png', true, array("style" => '0', "alt" => '')) . ""; } - + $data[7] = ui_print_module_warn_value($row['max_warning'], $row['min_warning'], $row['str_warning'], $row['max_critical'], $row['min_critical'], $row['str_critical']); - + if (is_numeric($row["datos"])){ $salida = format_numeric($row["datos"]); - + // Show units ONLY in numeric data types if (isset($row["unit"])){ $salida .= " " . ''. io_safe_output($row["unit"]) . ''; @@ -659,9 +659,9 @@ foreach ($result as $row) { title='". $module_value ."' style='white-space: nowrap;'>" . '' . $sub_string . ' ' . "" . html_print_image("images/rosette.png", true) . "" . ""; - } + } } - + $data[8] = $salida; if ($row["module_interval"] > 0) @@ -671,7 +671,8 @@ foreach ($result as $row) { if ($row['estado'] == 3){ $option = array ("html_attr" => 'class="redb"'); - } else { + } + else { $option = array (); } $data[9] = ui_print_timestamp ($row["utimestamp"], true, $option); @@ -680,8 +681,11 @@ foreach ($result as $row) { } if (!empty ($table->data)) { html_print_table ($table); -} else { - echo '
'.__('This group doesn\'t have any monitor').'
'; +} +else { + echo '
' . + __('This group doesn\'t have any monitor') . + '
'; } ?> + \ No newline at end of file diff --git a/pandora_console/operation/messages/message_edit.php b/pandora_console/operation/messages/message_edit.php index 0a94cc63c4..8084b3f755 100644 --- a/pandora_console/operation/messages/message_edit.php +++ b/pandora_console/operation/messages/message_edit.php @@ -156,7 +156,8 @@ $table->data[0][0] = __('Sender'); if (!empty($own_info['fullname'])) { $table->data[0][1] = $own_info['fullname']; -} else { +} +else { $table->data[0][1] = $config['id_user']; } @@ -170,9 +171,9 @@ foreach ($users_full as $user_id => $user_info) { if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM")) $return_all_groups = true; -else +else $return_all_groups = false; - + $groups = users_get_groups ($config["id_user"], "AR"); //Get a list of all groups $table->data[1][1] = html_print_select ($users, "dst_user", $dst_user, '', __('Select user'), false, true, false, '', false); diff --git a/pandora_console/operation/reporting/graph_viewer.php b/pandora_console/operation/reporting/graph_viewer.php index a94da052fd..1e5948a8e9 100644 --- a/pandora_console/operation/reporting/graph_viewer.php +++ b/pandora_console/operation/reporting/graph_viewer.php @@ -158,7 +158,7 @@ if ($view_graph) { $stackeds[2] = __('Line'); $stackeds[3] = __('Stacked line'); html_print_select ($stackeds, 'stacked', $stacked , '', '', -1, false, false); - + echo ""; echo ""; $zooms = array(); @@ -167,21 +167,21 @@ if ($view_graph) { $zooms[2] = __('Zoom x2'); $zooms[3] = __('Zoom x3'); html_print_select ($zooms, 'zoom', $zoom , '', '', 0); - + echo ""; echo ""; - echo ""; + echo ""; echo ""; echo ""; echo ""; - echo ""; + echo ""; /* We must add javascript here. Otherwise, the date picker won't - work if the date is not correct because php is returning. */ - + work if the date is not correct because php is returning. */ + ui_require_jquery_file ('timeentry'); ?> - + '.__('Invalid date selected').''; + echo '

' . __('Invalid date selected') . + '

'; return; } return; @@ -226,8 +227,8 @@ if (! empty ($graphs)) { array_push ($table->data, $data); } html_print_table ($table); -} else { +} +else { echo "
".__('There are no defined reportings')."
"; } - -?> +?> \ No newline at end of file diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 31ec8e2633..01ef9547a8 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -22,13 +22,15 @@ function xml_array ($array) { if (is_int ($name)) { echo ""; $name = "object"; - } else { + } + else { echo "<".$name.">"; } if (is_array ($value)) { xml_array ($value); - } else { + } + else { echo $value; } @@ -46,7 +48,7 @@ if (isset ($_GET["direct"])) { Although it's not recommended, you can put your login and password in a GET request (append &nick=&password=). - + You SHOULD put it in a POST but some programs might not be able to handle it without extensive re-programming Either way, you should have a read-only user for getting reports