diff --git a/pandora_console/godmode/modules/manage_network_templates.php b/pandora_console/godmode/modules/manage_network_templates.php index 7a52fc4f4e..e4fc621dfd 100644 --- a/pandora_console/godmode/modules/manage_network_templates.php +++ b/pandora_console/godmode/modules/manage_network_templates.php @@ -26,35 +26,42 @@ if (! give_acl ($config['id_user'], 0, "PM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access Network Profile Management"); require ("general/noaccess.php"); - exit; + return; } - -if (isset ($_POST["delete_profile"])) { // if delete - $id_np = (int) get_parameter_post ("delete_profile", 0); - $sql = sprintf ("DELETE FROM tnetwork_profile WHERE id_np = %d", $id_np); - $result = process_sql ($sql); + +require_once ('include/functions_network_profiles.php'); + +$delete_profile = (bool) get_parameter ('delete_profile'); +$export_profile = (bool) get_parameter ('export_profile'); + +if ($delete_profile) { // if delete + $id = (int) get_parameter_post ('delete_profile'); + + $result = delete_network_profile ($id); print_result_message ($result, __('Template successfully deleted'), __('Error deleting template')); } -if (isset ($_POST["export_profile"])) { - $id_np = (int) get_parameter_post ("export_profile", 0); - $profile_info = get_db_row ("tnetwork_profile", "id_np", $id_np); +if ($export_profile) { + $id = (int) get_parameter_post ("export_profile"); + $profile_info = get_network_profile ($id); if (empty ($profile_info)) { - print_result_message (false, '', __('This template does not exist')); + print_error_message (__('This template does not exist')); return; - } + } //It's important to keep the structure and order in the same way for backwards compatibility. $sql = sprintf ("SELECT components.name, components.description, components.type, components.max, components.min, components.module_interval, - components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, - components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, - components.max_timeout, components.history_data, components.min_warning, components.max_warning, components.min_critical, - components.max_critical, components.min_ff_event, comp_group.name AS group_name - FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group - WHERE tpc.id_nc = components.id_nc AND components.id_group = comp_group.id_sg AND tpc.id_np = %d", $id_np); + components.tcp_port, components.tcp_send, components.tcp_rcv, components.snmp_community, components.snmp_oid, + components.id_module_group, components.id_modulo, components.plugin_user, components.plugin_pass, components.plugin_parameter, + components.max_timeout, components.history_data, components.min_warning, components.max_warning, components.min_critical, + components.max_critical, components.min_ff_event, comp_group.name AS group_name + FROM `tnetwork_component` AS components, tnetwork_profile_component AS tpc, tnetwork_component_group AS comp_group + WHERE tpc.id_nc = components.id_nc + AND components.id_group = comp_group.id_sg + AND tpc.id_np = %d", $id); $components = get_db_all_rows_sql ($sql); @@ -68,19 +75,22 @@ if (isset ($_POST["export_profile"])) { $row_names[] = $row_name; } } - while (@ob_end_clean()); //Clean up output buffering //Send headers to tell the browser we're sending a file - header("Content-type: application/octet-stream"); - header("Content-Disposition: attachment; filename=".preg_replace ('/\s/', '_', $profile_info["name"]).".csv"); - header("Pragma: no-cache"); - header("Expires: 0"); + header ("Content-type: application/octet-stream"); + header ("Content-Disposition: attachment; filename=".preg_replace ('/\s/', '_', $profile_info["name"]).".csv"); + header ("Pragma: no-cache"); + header ("Expires: 0"); + + //Clean up output buffering + while (@ob_end_clean ()); //Then print the first line (row names) echo '"'.implode ('","', $row_names).'"'; echo "\n"; //Then print the rest of the data. Encapsulate in quotes in case we have comma's in any of the descriptions + foreach ($components as $row) { foreach ($inv_names as $bad_key) { unset ($row[$bad_key]); @@ -88,7 +98,9 @@ if (isset ($_POST["export_profile"])) { echo '"'.implode ('","', $row).'"'; echo "\n"; } - exit; //We're done here. The original page will still be there. + + //We're done here. The original page will still be there + exit; } echo "

".__('Module management')." > ".__('Module template management')."

"; @@ -114,8 +126,11 @@ foreach ($result as $row) { $data = array (); $data[0] = ''.safe_input ($row["name"]).''; $data[1] = safe_input ($row["description"]); - $data[2] = print_input_image ("delete_profile", "images/cross.png", $row["id_np"],'', true, array ('onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', 'border' => 0)); - $data[2] .= print_input_image ("export_profile", "images/lightning_go.png", $row["id_np"], '', true, array ('border' => 0)); + $data[2] = print_input_image ("delete_profile", "images/cross.png", + $row["id_np"],'', true, + array ('onclick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;')); + $data[2] .= print_input_image ("export_profile", "images/lightning_go.png", + $row["id_np"], '', true); array_push ($table->data, $data); } @@ -125,12 +140,11 @@ if (!empty ($table->data)) { print_table ($table); echo ''; } else { - echo '
'.__('There are no defined network profiles').'
'; + echo '
'.__('There are no defined network profiles').'
'; } -unset ($table); -echo '
'; -echo '
'; +echo ''; +echo '
'; print_submit_button (__('Create'), "crt", '', 'class="sub next"'); echo '
'; diff --git a/pandora_console/godmode/modules/manage_network_templates_form.php b/pandora_console/godmode/modules/manage_network_templates_form.php index 21ee504e88..846b0b453c 100644 --- a/pandora_console/godmode/modules/manage_network_templates_form.php +++ b/pandora_console/godmode/modules/manage_network_templates_form.php @@ -101,9 +101,9 @@ if (isset ($_GET["create"]) || isset ($_GET["update"])) { echo "

".__('Module management')." > ".__('Module template management')."

"; if ($id_np < 1) { - echo '
'; + echo ''; } else { - echo ''; + echo ''; } echo ''; @@ -226,8 +226,8 @@ if ($id_np > 0) { } ?> - diff --git a/pandora_console/godmode/reporting/map_builder_wizard.php b/pandora_console/godmode/reporting/map_builder_wizard.php index 06f19d8e00..1c5e7b1d48 100644 --- a/pandora_console/godmode/reporting/map_builder_wizard.php +++ b/pandora_console/godmode/reporting/map_builder_wizard.php @@ -30,7 +30,7 @@ $layout_id = (int) get_parameter ('id_layout'); $layout = get_db_row ('tlayout', 'id', $layout_id); if (empty ($layout)) { - print_result_message (false, '', __('No layout with this id found')); + print_error_message (__('No layout with this id found')); return; } @@ -44,7 +44,7 @@ if (! give_acl ($config['id_user'], $layout_group, "AW")) { function process_wizard_add ($id_agents, $image, $id_layout, $range, $width = 0, $height = 0) { if (empty ($id_agents)) { - print_result_message (false, '', __('No agents selected')); + print_error_message (__('No agents selected')); return false; } @@ -74,13 +74,13 @@ function process_wizard_add ($id_agents, $image, $id_layout, $range, $width = 0, $pos_x = $pos_x + $range; } - print_result_message (true, __('Agent successfully added to layout'), ''); + print_success_message (__('Agent successfully added to layout')); echo '

'.__('Map builder').'

'; } function process_wizard_add_modules ($id_modules, $image, $id_layout, $range, $width = 0, $height = 0) { if (empty ($id_modules)) { - print_result_message (false, '', __('No modules selected')); + print_error_message (__('No modules selected')); return false; } @@ -114,7 +114,7 @@ function process_wizard_add_modules ($id_modules, $image, $id_layout, $range, $w $pos_x = $pos_x + $range; } - print_result_message (true, __('Modules successfully added to layout'), ''); + print_success_message (__('Modules successfully added to layout')); } echo '

'.__('Visual map wizard').' - '.$layout["name"].'

'; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 13890b2f0a..82c0255c8d 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -28,7 +28,7 @@ if (! give_acl ($config['id_user'], 0, "UM")) { audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation", "Trying to access User Management"); require ("general/noaccess.php"); - exit; + return; } if ($config['user_can_update_info']) { @@ -57,8 +57,7 @@ if ($new_user && $config['admin_can_add_user']) { if ($create_user) { if (! $config['admin_can_add_user']) { - print_result_message (false, '', - __('The current authentication scheme doesn\'t support creating users from Pandora FMS')); + print_error_message (__('The current authentication scheme doesn\'t support creating users from Pandora FMS')); return; } @@ -75,13 +74,13 @@ if ($create_user) { $is_admin = (bool) get_parameter ('is_admin', 0); if ($password_new == '') { - print_result_message (false, '', __('Passwords cannot be empty')); + print_error_message (__('Passwords cannot be empty')); $user_info = $values; $password_new = ''; $password_confirm = ''; $new_user = true; } elseif ($password_new != $password_confirm) { - print_result_message (false, '', __('Passwords didn\'t match')); + print_error_message (__('Passwords didn\'t match')); $user_info = $values; $password_new = ''; $password_confirm = ''; @@ -121,8 +120,7 @@ if ($update_user) { __('User info successfully updated'), __('Error updating user info (no change?)')); } else { - print_result_message (false, '', - __('Passwords does not match')); + print_error_message (__('Passwords does not match')); } } else { print_result_message ($res1, diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 678dee0ca1..70e8675f65 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -2,12 +2,14 @@ // Pandora FMS - the Flexible Monitoring System // ============================================ +// Copyright (c) 2009 Artica Soluciones Tecnologicas, http://www.artica.es // Copyright (c) 2009 Evi Vanoost, vanooste@rcbi.rochester.edu // Please see http://pandora.sourceforge.net for full contribution list // This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License +// modify it under the terms of the GNU Lesser General Public License (LGPL) // as published by the Free Software Foundation for version 2. +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/pandora_console/include/functions_network_profiles.php b/pandora_console/include/functions_network_profiles.php new file mode 100644 index 0000000000..acbe48343f --- /dev/null +++ b/pandora_console/include/functions_network_profiles.php @@ -0,0 +1,60 @@ + $id_network_profile)); +} + +?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 4e46b2eb24..0c863dcdac 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -18,18 +18,68 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. /** - * Evaluates a result using empty() and then prints an error or success message + * Prints a generic message between tags. * - * @param mixed $result the results to evaluate. 0, NULL, false, '' or - * array() is bad, the rest is good - * @param string $good the string to be displayed if the result was good - * @param string $bad the string to be displayed if the result was bad - * @param string $attributes any other attributes to be set for the h3 - * @param bool $return whether to output the string or return it - * @param string $tag what tag to use (you could specify something else than + * @param string The message string to be displayed + * @param string the class to user + * @param string Any other attributes to be set for the tag. + * @param bool Whether to output the string or return it + * @param string What tag to use (you could specify something else than * h3 like div or h2) * - * @return string XHTML code if return parameter is true. + * @return string HTML code if return parameter is true. + */ +function print_message ($message, $class = '', $attributes = '', $return = false, $tag = 'h3') { + $output = '<'.$tag.(empty ($class) ? '' : ' class="'.$class.'" ').$attributes.'>'.$message.''; + + if ($return) + return $output; + echo $output; +} + +/** + * Prints an error message. + * + * @param string The error message to be displayed + * @param string Any other attributes to be set for the tag. + * @param bool Whether to output the string or return it + * @param string What tag to use (you could specify something else than + * h3 like div or h2) + * + * @return string HTML code if return parameter is true. + */ +function print_error_message ($message, $attributes = '', $return = false, $tag = 'h3') { + return print_message ($message, 'error', $attributes, $return, $tag); +} + +/** + * Prints an operation success message. + * + * @param string The message to be displayed + * @param string Any other attributes to be set for the tag. + * @param bool Whether to output the string or return it + * @param string What tag to use (you could specify something else than + * h3 like div or h2) + * + * @return string HTML code if return parameter is true. + */ +function print_success_message ($message, $attributes = '', $return = false, $tag = 'h3') { + return print_message ($message, 'suc', $attributes, $return, $tag); +} + +/** + * Evaluates a result using empty() and then prints an error or success message + * + * @param mixed The results to evaluate. 0, NULL, false, '' or + * array() is bad, the rest is good + * @param string The string to be displayed if the result was good + * @param string The string to be displayed if the result was bad + * @param string Any other attributes to be set for the h3 + * @param bool Whether to output the string or return it + * @param string What tag to use (you could specify something else than + * h3 like div or h2) + * + * @return string HTML code if return parameter is true. */ function print_result_message ($result, $good = '', $bad = '', $attributes = '', $return = false, $tag = 'h3') { if ($good == '' || $good === false) @@ -39,15 +89,9 @@ function print_result_message ($result, $good = '', $bad = '', $attributes = '', $bad = __('Error processing request'); if (empty ($result)) { - $output = '<'.$tag.' class="error" '.$attributes.'>'.$bad.''; - } else { - $output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.''; + return print_error_message ($bad, $attributes, $return, $tag); } - - if ($return) - return $output; - - echo $output; + return print_success_message ($good, $attributes, $return, $tag); } /** @@ -55,9 +99,9 @@ function print_result_message ($result, $good = '', $bad = '', $attributes = '', * with as title the correctly formatted full timestamp and a time comparation * in the tag * - * @param int $unixtime: Any type of timestamp really, but we prefer unixtime - * @param bool $return whether to output the string or return it - * @param array $option: An array with different options for this function + * @param int Any type of timestamp really, but we prefer unixtime + * @param bool Whether to output the string or return it + * @param array An array with different options for this function * Key html_attr: which html attributes to add (defaults to none) * Key tag: Which html tag to use (defaults to span) * Key prominent: Overrides user preference and display "comparation" or "timestamp" @@ -130,8 +174,8 @@ function print_timestamp ($unixtime, $return = false, $option = array ()) { /** * Prints a username with real name, link to the user_edit page etc. * - * @param string $username The username to render - * @param bool $return Whether to return or print + * @param string The username to render + * @param bool Whether to return or print * * @return string HTML code if return parameter is true. */ @@ -147,9 +191,9 @@ function print_username ($username, $return = false) { /** * Print group icon within a link * - * @param string $id_group Group id - * @param bool $return Whether to return or print - * @param string $path What path to use (relative to images/). Defaults to groups_small + * @param int Group id + * @param bool Whether to return or print + * @param string What path to use (relative to images/). Defaults to groups_small * * @return string HTML code if return parameter is true. */ @@ -201,9 +245,9 @@ function print_os_icon ($id_os, $name = true, $return = false) { /** * Prints an agent name with the correct link * - * @param int $id_agent Agent id - * @param bool $return Whether to return the string or echo it too - * @param int $cutoff After how much characters to cut off the inside of the + * @param int Agent id + * @param bool Whether to return the string or echo it too + * @param int After how much characters to cut off the inside of the * link. The full agent name will remain in the roll-over * * @return string HTML with agent name and link @@ -397,8 +441,8 @@ function print_alert_template_example ($id_alert_template, $return = false, $pri /** * Prints a help tip icon. * - * @param string $help_id Id of the help article - * @param bool $return Whether to return or output the result + * @param string Id of the help article + * @param bool Whether to return or output the result * * @return string The help tip */ diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index 091a51891a..50eeb7170d 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -50,7 +50,7 @@ if (isset ($_GET["modified"]) && !$view_mode) { __('Password successfully updated'), __('Error updating passwords: %s', $config['auth_error'])); } elseif ($password_new !== "-") { - print_result_message (false, '', __('Passwords didn\'t match or other problem encountered while updating passwords')); + print_error_message (__('Passwords didn\'t match or other problem encountered while updating passwords')); } $return = update_user ($id, $upd_info);