2009-03-30 Esteban Sanchez <estebans@artica.es>

* include/functions_ui.php: Added print_message(),
	print_error_message() and print_success_message().

	* godmode/users/configure_user.php,
	operation/users/user_edit.php,
	godmode/reporting/map_builder_wizard.php: Use print_error_message() or
	print_success_message() when there was no other option.

	* godmode/modules/manage_network_templates.php: Fixed CSV export
	notice errors. Style corrections.

	* godmode/modules/manage_network_templates_form.php: Style
	corrections.

	* include/functions_network_profiles.php: Added to repository. Network
	profiles function API.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1577 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-03-30 09:27:04 +00:00
parent 413619dba5
commit 3c4fba1e47
8 changed files with 196 additions and 78 deletions

View File

@ -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 "<h2>".__('Module management')." &gt; ".__('Module template management')."</h2>";
@ -114,8 +126,11 @@ foreach ($result as $row) {
$data = array ();
$data[0] = '<a href="index.php?sec=gmodules&amp;sec2=godmode/modules/manage_network_templates_form&amp;id_np='.$row["id_np"].'">'.safe_input ($row["name"]).'</a>';
$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 '</form>';
} else {
echo '<div class="nf" style="width:90%">'.__('There are no defined network profiles').'</div>';
echo '<div class="nf" style="width:'.$table->width.'">'.__('There are no defined network profiles').'</div>';
}
unset ($table);
echo '<form method="post" action="index.php?sec=gmodules&amp;sec2=godmode/modules/manage_network_templates_form&amp;id_np=-1">';
echo '<div style="width:90%; text-align:right;">';
echo '<form method="post" action="index.php?sec=gmodules&amp;sec2=godmode/modules/manage_network_templates_form">';
echo '<div style="width: '.$table->width.'" class="action-buttons">';
print_submit_button (__('Create'), "crt", '', 'class="sub next"');
echo '</div></form>';

View File

@ -101,9 +101,9 @@ if (isset ($_GET["create"]) || isset ($_GET["update"])) {
echo "<h2>".__('Module management')." &gt; ".__('Module template management')."</h2>";
if ($id_np < 1) {
echo '<form name="new_temp" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&create=1">';
echo '<form name="new_temp" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&create=1">';
} else {
echo '<form name="mod_temp" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&update='.$id_np.'">';
echo '<form name="mod_temp" method="post" action="index.php?sec=gmodules&sec2=godmode/modules/manage_network_templates_form&id_np='.$id_np.'&update='.$id_np.'">';
}
echo '<table width="550" cellpadding="4" cellspacing="4" class="databox_color">';
@ -226,8 +226,8 @@ if ($id_np > 0) {
}
?>
<script language="JavaScript" type="text/javascript">
<!--
<script type="text/javascript">
/* <![CDATA[ */
function CheckAll() {
for (var i = 0; i < document.component_delete.elements.length; i++) {
@ -236,5 +236,5 @@ function CheckAll() {
e.checked = !e.checked;
}
}
-->
/* ]]> */
</script>

View File

@ -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 '<h3><a href="index.php?sec=greporting&sec2=godmode/reporting/map_builder&id_layout='.$id_layout.'">'.__('Map builder').'</a></h3>';
}
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 '<h2>'.__('Visual map wizard').' - '.$layout["name"].'</h2>';

View File

@ -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,

View File

@ -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

View File

@ -0,0 +1,60 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// 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 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
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/**
* Get a custom user report.
*
* @param int Report id to get.
* @param array Extra filter.
* @param array Fields to get.
*
* @return Report with the given id. False if not available or readable.
*/
function get_network_profile ($id_network_profile, $filter = false, $fields = false) {
global $config;
$id_network_profile = safe_int ($id_network_profile);
if (empty ($id_network_profile))
return false;
if (! is_array ($filter))
$filter = array ();
$filter['id_np'] = $id_network_profile;
return @get_db_row_filter ('tnetwork_profile', $filter, $fields);
}
/**
* Deletes a network_profile.
*
* @param int Network profile id to be deleted.
*
* @return bool True if deleted, false otherwise.
*/
function delete_network_profile ($id_network_profile) {
$id_network_profile = safe_int ($id_network_profile);
if (empty ($id_network_profile))
return false;
$profile = get_network_profile ($id_network_profile);
if ($profile === false)
return false;
return @process_sql_delete ('tnetwork_profile',
array ('id_np' => $id_network_profile));
}
?>

View File

@ -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.'</'.$tag.'>';
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.'</'.$tag.'>';
} else {
$output = '<'.$tag.' class="suc" '.$attributes.'>'.$good.'</'.$tag.'>';
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
*/

View File

@ -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);