From afe99a4587584f6c6cf899f0110bc1c9aad65a86 Mon Sep 17 00:00:00 2001 From: Esteban Sanchez Date: Tue, 20 Jan 2009 16:43:49 +0000 Subject: [PATCH] 2009-01-20 Esteban Sanchez * ChangeLog: Fixed tabs. Removed some conflict markups and a bit of style here and there. * index.php, godmode/setup/setup.php, include/styles/menu.css, operation/agentes/estado_agente.php, operation/agentes/estado_monitores.php, operation/agentes/estado_ultimopaquete.php, include/functions.php: Tab and spaces style correction. * godmode/reporting/map_builder.php: Use generic database functions for the insert. Now a node can represent a whole agent, changing to bad if any module has failed. * include/config_process.php: Use generic databse functions for inserts. Fixed an error when inserting loginhash_pwd token. Make the token a bit more complicated by multiplying two numbers. * include/functions_visual_map.php: Add support to agent nodes that will turn to bad icon when any module fails. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1363 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 22 ++++++ .../godmode/reporting/map_builder.php | 27 +++---- pandora_console/godmode/setup/setup.php | 2 +- pandora_console/include/config_process.php | 70 +++++++++++-------- pandora_console/include/functions.php | 20 +++--- .../include/functions_visual_map.php | 44 +++++++----- pandora_console/include/styles/menu.css | 2 +- pandora_console/index.php | 22 +++--- .../operation/agentes/estado_agente.php | 13 ++-- .../operation/agentes/estado_monitores.php | 12 ++-- .../agentes/estado_ultimopaquete.php | 38 +++++----- 11 files changed, 156 insertions(+), 116 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a8b4b0c4d8..98f0948747 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,25 @@ +2009-01-20 Esteban Sanchez + + * ChangeLog: Fixed tabs. Removed some conflict markups and a bit of + style here and there. + + * index.php, godmode/setup/setup.php, include/styles/menu.css, + operation/agentes/estado_agente.php, + operation/agentes/estado_monitores.php, + operation/agentes/estado_ultimopaquete.php, + include/functions.php: Tab and spaces style correction. + + * godmode/reporting/map_builder.php: Use generic database functions + for the insert. Now a node can represent a whole agent, changing to + bad if any module has failed. + + * include/config_process.php: Use generic databse functions for + inserts. Fixed an error when inserting loginhash_pwd token. Make the + token a bit more complicated by multiplying two numbers. + + * include/functions_visual_map.php: Add support to agent nodes that + will turn to bad icon when any module fails. + 2009-01-20 Esteban Sanchez * include/javascript/jquery.js: Downgraded to 1.2. It was causing some diff --git a/pandora_console/godmode/reporting/map_builder.php b/pandora_console/godmode/reporting/map_builder.php index 9c847478f8..d828dfa24b 100644 --- a/pandora_console/godmode/reporting/map_builder.php +++ b/pandora_console/godmode/reporting/map_builder.php @@ -147,18 +147,19 @@ if ($create_layout_data) { $layout_data_width = (int) get_parameter ("width"); $layout_data_height = (int) get_parameter ("height"); - $sql = sprintf ('INSERT INTO tlayout_data (id_layout, label, id_layout_linked, - label_color, image, type, id_agente_modulo, parent_item, period, no_link_color, - width, height) - VALUES (%d, "%s", %d, "%s", "%s", %d, %d, %d, %d, 1, %d, %d)', - $id_layout, $layout_data_label, - $layout_data_map_linked, - $layout_data_label_color, - $layout_data_image, $layout_data_type, - $layout_data_id_agent_module, - $layout_data_parent_item, $layout_data_period * 3600, - $layout_data_width, $layout_data_height); - $result = process_sql ($sql, 'insert_id'); + $values = array ('id_layout' => $id_layout, + 'label' => $layout_data_label, + 'id_layout_linked' => $layout_data_map_linked, + 'label_color' => $layout_data_label_color, + 'image' => $layout_data_image, + 'type' => $layout_data_type, + 'id_agente_modulo' => $layout_data_id_agent_module, + 'parent_item' => $layout_data_parent_item, + 'period' => $layout_data_period * 3600, + 'no_link_color' => 1, + 'width' => $layout_data_width, + 'height' => $layout_data_height); + $result = process_sql_insert ('tlayout_data', $values); if ($result !== false) { echo '

'.__('Created successfully').'

'; @@ -446,7 +447,7 @@ function agent_changed (event, id_agent, selected) { }, function (data) { $('#form_layout_data_editor #module').empty (); - $('#form_layout_data_editor #module').append ($('').html ("--").attr ("value", 0)); + $('#form_layout_data_editor #module').append ($('').html ("").attr ("value", 0)); jQuery.each (data, function (i, val) { s = html_entity_decode (val['nombre']); $('#form_layout_data_editor #module').append ($('').html (s).attr ("value", val['id_agente_modulo'])); diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 62dc69da33..d6abc9e4c5 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -75,7 +75,7 @@ if ($update_settings) { process_sql ("UPDATE tconfig SET VALUE='".$config["prominent_time"]."' WHERE token = 'prominent_time'"); process_sql ("UPDATE tconfig SET VALUE='".$config["timesource"]."' WHERE token = 'timesource'"); process_sql ("UPDATE tconfig SET VALUE='".$config["event_view_hr"]."' WHERE token = 'event_view_hr'"); - process_sql ("UPDATE tconfig SET VALUE='".$config["loginhash_pwd"]."' WHERE token = 'loginhash_pwd'"); + process_sql ("UPDATE tconfig SET VALUE='".$config["loginhash_pwd"]."' WHERE token = 'loginhash_pwd'"); } echo "

".__('Setup')." > "; diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 16c86e0d9f..4a554e342d 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -17,20 +17,20 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //Pandora Version -$build_version = "PC090115"; -$pandora_version = "v2.1-dev"; +$build_version = 'PC090120'; +$pandora_version = 'v2.1-dev'; // This is directory where placed "/attachment" directory, to upload files stores. // This MUST be writtable by http server user, and should be in pandora root. // By default, Pandora adds /attachment to this, so by default is the pandora console home dir -$config["attachment_store"] = $config["homedir"]."/attachment"; +$config['attachment_store'] = $config['homedir'].'/attachment'; // Default font used for graphics (a Free TrueType font included with Pandora FMS) -$config["fontpath"] = $config["homedir"]."/reporting/FreeSans.ttf"; +$config['fontpath'] = $config['homedir'].'/reporting/FreeSans.ttf'; // Style (pandora by default) -$config["style"] = "pandora"; +$config['style'] = 'pandora'; // Read remaining config tokens from DB if (! mysql_connect ($config["dbhost"], $config["dbuser"], $config["dbpass"])) { @@ -58,7 +58,7 @@ mysql_select_db ($config["dbname"]); require_once ('functions_db.php'); $configs = get_db_all_rows_in_table ('tconfig'); -if (sizeof ($configs) == 0) { +if (empty ($configs)) { exit ('Pandora FMS Error
@@ -76,18 +76,19 @@ if (sizeof ($configs) == 0) {
'); } +/* Compatibility fix */ foreach ($configs as $c) { switch ($c["token"]) { case "language_code": - $config["language"] = $c["value"]; + $config['language'] = $c['value']; break; default: - $config[$c["token"]] = $c["value"]; + $config[$c['token']] = $c['value']; } } -if ($config["language"] == 'ast_es') { +if ($config['language'] == 'ast_es') { $help_code = 'ast'; } else { $help_code = substr ($config["language"], 0, 2); @@ -112,47 +113,54 @@ if (file_exists ('./include/languages/'.$config["language"].'.mo')) { $l10n->load_tables(); } -if (!isset ($config['date_format'])) { - $config['date_format'] = 'F j, Y, g:i a'; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('date_format', '".$config['date_format']."')"); -} - -if (!isset($config["event_view_hr"])){ - $config["event_view_hr"] = 8; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('event_view_hr', ".$config["event_view_hr"].")"); -} - -if (!isset($config["loginhash_pwd"])){ - $config["loginhash_pwd"] = rand(0,1000)."pandorahash"; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('loginhash_pwd', ".$config["loginhash_pwd"].")"); -} - if (isset ($config['homeurl']) && $config['homeurl'][0] != '/') { $config['homeurl'] = '/'.$config['homeurl']; } +if (!isset ($config['date_format'])) { + $config['date_format'] = 'F j, Y, g:i a'; + process_sql_insert ('tconfig', array ('token' => 'date_format', + 'value' => $config['date_format'])); +} + +if (! isset ($config['event_view_hr'])) { + $config['event_view_hr'] = 8; + process_sql_insert ('tconfig', array ('token' => 'event_view_hr', + 'value' => $config['event_view_hr'])); +} + +if (! isset ($config['loginhash_pwd'])) { + $config['loginhash_pwd'] = rand (0, 1000) * rand (0, 1000)."pandorahash"; + process_sql_insert ('tconfig', array ('token' => 'loginhash_pwd', + 'value' => $config["loginhash_pwd"])); +} -// If first time, make the trap2agent disable in DB if (!isset($config["trap2agent"])){ $config["trap2agent"] = 0; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('trap2agent', 0)"); + process_sql_insert ('tconfig', array ('token' => 'trap2agent', + 'value' => $config['trap2agent'])); } if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) { // Default period (in secs) for auto SLA calculation (for monitors) $config["sla_period"] = 604800; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('sla_period',604800)"); + process_sql_insert ('tconfig', array ('token' => 'sla_period', + 'value' => $config['sla_period'])); } if (!isset ($config["prominent_time"])) { - // Prominent time tells us what to show prominently when a timestamp is displayed. The comparation (... days ago) or the timestamp (full date) + // Prominent time tells us what to show prominently when a timestamp is + // displayed. The comparation (... days ago) or the timestamp (full date) $config["prominent_time"] = "comparation"; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('prominent_time','comparation')"); + process_sql_insert ('tconfig', array ('token' => 'prominent_time', + 'value' => $config['prominent_time'])); } if (!isset ($config["timesource"])) { - // Prominent time tells us what to show prominently when a timestamp is displayed. The comparation (... days ago) or the timestamp (full date) + // Prominent time tells us what to show prominently when a timestamp is + // displayed. The comparation (... days ago) or the timestamp (full date) $config["timesource"] = "system"; - process_sql ("INSERT INTO tconfig (token,value) VALUES ('timesource','system')"); + process_sql_insert ('tconfig', array ('token' => 'timesource', + 'value' => $config['timesource'])); } ?> diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ab9beeaf64..ba1a56452e 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -423,12 +423,12 @@ function format_numeric ($number, $decimals = 1) { * @return string A string with the number and the multiplier */ function format_for_graph ($number , $decimals = 1, $dec_point = ".", $thousands_sep = ",") { - $shorts = array("","K","M","G","T","P"); - $pos = 0; - while ($number>=1000) { //as long as the number can be divided by 1000 - $pos++; //Position in array starting with 0 - $number = $number/1000; - } + $shorts = array ("","K","M","G","T","P"); + $pos = 0; + while ($number >= 1000) { //as long as the number can be divided by 1000 + $pos++; //Position in array starting with 0 + $number = $number / 1000; + } return format_numeric ($number, $decimals). $shorts[$pos]; //This will actually do the rounding and the decimals } @@ -990,8 +990,8 @@ if (!function_exists ("mb_strtoupper")) { */ function unsafe_string ($string) { - if (get_magic_quotes_gpc () == 1) - $string = stripslashes ($string); + if (get_magic_quotes_gpc ()) + return stripslashes ($string); return $string; } @@ -1003,7 +1003,7 @@ function unsafe_string ($string) { function safe_sql_string ($string) { if (get_magic_quotes_gpc () == 0) - $string = mysql_escape_string ($string); - return $string; + return $string; + return mysql_escape_string ($string); } ?> diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 8b36643234..4ba0fb64ae 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -34,25 +34,37 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = $lines = array (); if ($layout_datas !== false) { - foreach ($layout_datas as $layout_data) { // Linked to other layout ?? - Only if not module defined - if (($layout_data['id_layout_linked'] != 0) && ($layout_data['id_agente_modulo'] == 0)) { + if ($layout_data['id_layout_linked'] != 0) { $status = return_status_layout ($layout_data['id_layout_linked']); } else { $id_agent = get_db_value ("id_agente", "tagente_estado", "id_agente_modulo", $layout_data['id_agente_modulo']); - $id_agent_module_parent = get_db_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); - // Item value - $status = return_status_agent_module ($layout_data['id_agente_modulo']); - if ($layout_data['no_link_color'] == 1) - $status_parent = -1; - else - $status_parent = return_status_agent_module ($id_agent_module_parent); + if ($layout_data['id_agente_modulo'] != 0) { + $id_agent_module_parent = get_db_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); + // Item value + $status = return_status_agent_module ($layout_data['id_agente_modulo']); + if ($layout_data['no_link_color'] == 1) + $status_parent = -1; + else + $status_parent = return_status_agent_module ($id_agent_module_parent); + } else { + $interval = get_agent_interval ($id_agent); + $sql = sprintf ('SELECT COUNT(*) + FROM tagente_estado, tagente_modulo + WHERE tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo + AND tagente_modulo.disabled = 0 + AND tagente_modulo.id_agente = %d + AND (utimestamp >= UNIX_TIMESTAMP() - module_interval * 2 + OR (module_interval = 0 + AND utimestamp >= UNIX_TIMESTAMP() - %d))', + $id_agent, $interval * 2); + $status = get_db_sql ($sql); + } } - + // STATIC IMAGE (type = 0) if ($layout_data['type'] == 0) { - // Link image //index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=1 if ($status == 0) // Bad monitor @@ -61,7 +73,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = $z_index = 3; else $z_index = 1; // Print BAD over good - + // Draw image echo '
'; if ($show_links) { @@ -76,7 +88,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = echo ''; else echo ''; + title="'.$layout_data['label'].'">'; } else { if ($layout_data['width'] != "" && $layout_data['width'] != 0) echo ''; } echo ""; - + // Draw label - echo "
"; + echo "
"; echo $layout_data['label']; echo "
"; } @@ -116,7 +128,7 @@ function print_pandora_visual_map ($id_layout, $show_links = true, $draw_lines = $line['color'] = $layout_data['label_color']; array_push ($lines, $line); } - + // Get parent relationship - Create line data if ($layout_data["parent_item"] != "" && $layout_data["parent_item"] != 0) { $line['id'] = $layout_data['id']; diff --git a/pandora_console/include/styles/menu.css b/pandora_console/include/styles/menu.css index 0cbf3c0d5f..b0be0491b3 100644 --- a/pandora_console/include/styles/menu.css +++ b/pandora_console/include/styles/menu.css @@ -49,7 +49,7 @@ } /* a selected ul has a height set in the style tag */ .menu.int ul.selected { - height: inherit; + height: inherit; } /* Force the hovered ul to be 28px unless the ul is selected */ diff --git a/pandora_console/index.php b/pandora_console/index.php index cd79bda6c1..c87489f972 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -46,8 +46,8 @@ if ($develop_bypass != 1) { } // Check perms for config.php if ((substr (sprintf ('%o', fileperms('include/config.php')), -4) != "0600") && - (substr (sprintf ('%o', fileperms('include/config.php')), -4) != "0660") && - (substr (sprintf ('%o', fileperms('include/config.php')), -4) != "0640")) { + (substr (sprintf ('%o', fileperms('include/config.php')), -4) != "0660") && + (substr (sprintf ('%o', fileperms('include/config.php')), -4) != "0640")) { include "general/error_perms.php"; exit; } @@ -144,19 +144,19 @@ $sec = safe_url_extraclean ($sec); // Hash login process if (! isset ($_SESSION['id_usuario']) && isset ($_GET["loginhash"])) { - $loginhash_data = get_parameter("loginhash_data", ""); - $loginhash_user = get_parameter("loginhash_user", ""); - - if ($loginhash_data == md5($loginhash_user.$config["loginhash_pwd"])) { + $loginhash_data = get_parameter("loginhash_data", ""); + $loginhash_user = get_parameter("loginhash_user", ""); + + if ($loginhash_data == md5($loginhash_user.$config["loginhash_pwd"])) { update_user_contact ($loginhash_user); logon_db ($loginhash_user, $REMOTE_ADDR); $_SESSION['id_usuario'] = $loginhash_user; $config["id_user"] = $loginhash_user; - } else { - require_once ('general/login_page.php'); - audit_db ("system", $REMOTE_ADDR, "Logon Failed (loginhash", ""); - exit; - } + } else { + require_once ('general/login_page.php'); + audit_db ("system", $REMOTE_ADDR, "Logon Failed (loginhash", ""); + exit; + } } // Login process diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 47e8ac6c74..a6c639fabb 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -218,13 +218,13 @@ if ($agents !== false) { $agent_down = 1; if ($async == 0) $monitor_down++; - } else{ + } else { if ($module["estado"] == 2) - $monitor_warning ++; + $monitor_warning++; elseif ($module["estado"]== 1) - $monitor_critical ++; + $monitor_critical++; else - $monitor_normal ++; + $monitor_normal++; } } // Color change for each line (1.2 beta2) @@ -248,7 +248,7 @@ if ($agents !== false) { echo $nombre_agente; echo ""; - // Show SO icon :) + // Show SO icon echo ""; print_os_icon ($id_os, false); echo ""; @@ -285,8 +285,7 @@ if ($agents !== false) { if ($numero_modulos > 0){ if ($agent_down > 0) { echo ''; - } - elseif ($monitor_critical > 0){ + } elseif ($monitor_critical > 0){ echo ''; } elseif ($monitor_warning > 0) { echo ''; diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 65a5567f03..7fad6bf05b 100644 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -80,13 +80,11 @@ foreach ($modules as $module) { $data[4] = ''; - } else { - $data[4] .= substr(salida_limpia($module["datos"]),0,42) . '">'; - } - - + if (is_numeric($module["datos"])) { + $data[4] .= format_for_graph($module["datos"]). '">'; + } else { + $data[4] .= substr(salida_limpia($module["datos"]),0,42) . '">'; + } if ($module["module_interval"] > 0) { $data[5] = $module["module_interval"]; diff --git a/pandora_console/operation/agentes/estado_ultimopaquete.php b/pandora_console/operation/agentes/estado_ultimopaquete.php index 20c449ac26..2138b99553 100644 --- a/pandora_console/operation/agentes/estado_ultimopaquete.php +++ b/pandora_console/operation/agentes/estado_ultimopaquete.php @@ -123,44 +123,44 @@ if (mysql_num_rows ($result3)) { $real_interval = $intervalo_agente; } - if (($row3["id_tipo_modulo"] != 3) + if (($row3["id_tipo_modulo"] != 3) AND ($row3["id_tipo_modulo"] != 10) AND ($row3["id_tipo_modulo"] != 17) AND ($row3["id_tipo_modulo"] != 23)){ - echo ""; - echo salida_limpia(substr($row3["descripcion"],0,32)); + echo ""; + echo salida_limpia(substr($row3["descripcion"],0,32)); if (strlen($row3["descripcion"]) > 32){ echo "..."; } - echo ""; - } + echo ""; + } if (($row3["id_tipo_modulo"] == 100) OR ($row3['history_data'] == 0)) { - echo ""; + echo ""; echo substr(salida_limpia($row3["datos"]),0,12); - } else { - // String uses colspan2 and different graphtype - if (($row3["id_tipo_modulo"] == 3) + } else { + // String uses colspan2 and different graphtype + if (($row3["id_tipo_modulo"] == 3) OR ($row3["id_tipo_modulo"] == 10) OR ($row3["id_tipo_modulo"] == 17) OR ($row3["id_tipo_modulo"] == 23)){ $graph_type = "string"; - echo ""; - } - elseif (($row3["id_tipo_modulo"] == 2) + echo ""; + } + elseif (($row3["id_tipo_modulo"] == 2) OR ($row3["id_tipo_modulo"] == 6) OR ($row3["id_tipo_modulo"] == 21) OR ($row3["id_tipo_modulo"] == 18) OR ($row3["id_tipo_modulo"] == 9)) { $graph_type = "boolean"; - echo ""; - } + echo ""; + } else { $graph_type = "sparse"; echo ""; - } + } - // Kind of data - if (is_numeric($row3["datos"])) { + // Kind of data + if (is_numeric($row3["datos"])) { echo format_for_graph($row3["datos"] ); } else echo substr(salida_limpia($row3["datos"]),0,42); @@ -214,8 +214,8 @@ if (mysql_num_rows ($result3)) { } } echo ""; - } - echo ''; + } + echo ''; } else { echo "
".__('This agent doesn\'t have any module')."
";