2009-02-19 Esteban Sanchez <estebans@artica.es>

* include/functions_ui.php: Added require_css_file(),
	require_javascript_file() and require_jquery_file() to add CSS,
	javascript and jQuery files to the header easily without changing
	config object. A path parameter is addded to allow the use on
	enterprise code.

	* include/functions_db.php: Added
	get_db_value_filter(), get_db_all_rows_filter() and
	process_sql_delete(). Fixed delete_agent() style and use these
	functions. Added process_page_head() from functions_ui.php and changed
	a bit the config javascript object part.

	* include/functions_custom_graphs.php: Get results indexed by id on
	get_user_custom_graphs().

	* include/functions.php: Moved process_page_head to functions_ui.php.
	
	* godmode/agentes/manage_delete.php: New interface to perform massive
	agents deletion.

	* godmode/menu.php: Added new option to massive agents deletion.

	* general/main_menu.php, godmode/agentes/manage_config.php,
	godmode/agentes/module_manager_editor.php,
	godmode/agentes/planned_downtime.php,
	godmode/alerts/alert_compounds.php, godmode/alerts/alert_list.php,
	godmode/alerts/configure_alert_compound.php,
	godmode/alerts/configure_alert_template.php,
	godmode/reporting/map_builder.php, operation/agentes/networkmap.php,
	operation/reporting/reporting_viewer.php,
	operation/visual_console/render_view.php: Use new functions in include
	CSS and javascript files.

	* index.php: Bit of style when printing the header so the HTML can be
	readed easily in a editor.

	* include/javascript/pandora.js: Added a variable to determine the
	enterprise directory.

	* include/styles/pandora.css: Added style for manage_delete.php



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1467 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-02-19 16:10:04 +00:00
parent 611c3f60a9
commit f22fa04934
23 changed files with 620 additions and 227 deletions

View File

@ -1,3 +1,46 @@
2009-02-19 Esteban Sanchez <estebans@artica.es>
* include/functions_ui.php: Added require_css_file(),
require_javascript_file() and require_jquery_file() to add CSS,
javascript and jQuery files to the header easily without changing
config object. A path parameter is addded to allow the use on
enterprise code.
* include/functions_db.php: Added
get_db_value_filter(), get_db_all_rows_filter() and
process_sql_delete(). Fixed delete_agent() style and use these
functions. Added process_page_head() from functions_ui.php and changed
a bit the config javascript object part.
* include/functions_custom_graphs.php: Get results indexed by id on
get_user_custom_graphs().
* include/functions.php: Moved process_page_head to functions_ui.php.
* godmode/agentes/manage_delete.php: New interface to perform massive
agents deletion.
* godmode/menu.php: Added new option to massive agents deletion.
* general/main_menu.php, godmode/agentes/manage_config.php,
godmode/agentes/module_manager_editor.php,
godmode/agentes/planned_downtime.php,
godmode/alerts/alert_compounds.php, godmode/alerts/alert_list.php,
godmode/alerts/configure_alert_compound.php,
godmode/alerts/configure_alert_template.php,
godmode/reporting/map_builder.php, operation/agentes/networkmap.php,
operation/reporting/reporting_viewer.php,
operation/visual_console/render_view.php: Use new functions in include
CSS and javascript files.
* index.php: Bit of style when printing the header so the HTML can be
readed easily in a editor.
* include/javascript/pandora.js: Added a variable to determine the
enterprise directory.
* include/styles/pandora.css: Added style for manage_delete.php
2009-02-18 Esteban Sanchez <estebans@artica.es>
* godmode/agentes/alert_manager.php: Removed from repository. Agent

View File

@ -95,7 +95,7 @@ echo '<a class="white_bold" href="index.php?sec=eventos&amp;sec2=operation/event
// Styled text
echo '</td><td width="20%"><div id="head_r"><span id="logo_text1">Pandora</span> <span id="logo_text2">FMS</span></div></td></tr></table>';
$config['jquery'][] = 'countdown';
require_jquery_file ('countdown');
?>
<script language="javascript" type="text/javascript">

View File

@ -135,7 +135,7 @@ unset ($menu);
require ("links_menu.php");
$config['jquery'][] = 'cookie';
require_jquery_file ('cookie');
?>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */

View File

@ -223,7 +223,7 @@ echo '<legend><span>'.__('To agent(s)').'</span></legend>';
print_table ($table);
echo '</fieldset>';
echo '<div class="action-buttons" style="width: 90%">';
echo '<div class="action-buttons" style="width: '.$table->width.'">';
print_input_hidden ('do_operation', 1);
print_submit_button (__('Go'), 'go', false, 'class="sub next"');
echo '</div>';
@ -231,8 +231,8 @@ echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
$config['jquery'][] = 'form';
$config['jquery'][] = 'pandora.controls';
require_jquery_file ('form');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">

View File

@ -0,0 +1,121 @@
<?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 General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributepd 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.
// Load global vars
check_login ();
if (! give_acl ($config['id_user'], 0, "LM")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Agent Config Management Admin section");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_agents.php');
require_once ('include/functions_alerts.php');
require_once ('include/functions_modules.php');
echo '<h2>'.__('Massive agent deletion').'</h2>';
function process_manage_delete ($id_agents) {
if (empty ($id_agents)) {
echo '<h3 class="error">'.__('No agents selected').'</h3>';
return false;
}
$id_agents = (array) $id_agents;
$copy_modules = (bool) get_parameter ('copy_modules');
$copy_alerts = (bool) get_parameter ('copy_alerts');
process_sql ('SET AUTOCOMMIT = 0');
process_sql ('START TRANSACTION');
$error = false;
foreach ($id_agents as $id_agent) {
$success = delete_agent ($id_agent);
if (! $success)
break;
}
if (! $success) {
echo '<h3 class="error">'.__('There was an error deleting the agent, the operation has been cancelled').'</h3>';
echo '<h4>'.__('Could not delete agent').' '.get_agent_name ($id_agent).'</h4>';
process_sql ('ROLLBACK');
} else {
echo '<h3 class="suc">'.__('Successfully deleted').'</h3>';
process_sql ('COMMIT');
}
process_sql ('SET AUTOCOMMIT = 1');
}
$id_group = (int) get_parameter ('id_group');
$id_agents = (array) get_parameter ('id_agents');
$delete = (bool) get_parameter_post ('delete');
if ($delete) {
process_manage_delete ($id_agents);
}
$groups = get_user_groups ();
$table->id = 'delete_table';
$table->width = '95%';
$table->data = array ();
$table->style = array ();
$table->style[0] = 'font-weight: bold; vertical-align:top';
$table->style[2] = 'font-weight: bold';
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '85%';
$table->data = array ();
$table->data[0][0] = __('Group');
$table->data[0][1] = print_select ($groups, 'id_group', $id_group,
false, '', '', true);
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
$table->data[1][0] .= '<img src="images/spinner.gif" />';
$table->data[1][0] .= '</span>';
$table->data[1][1] = print_select (get_group_agents ($id_group, false, "none"),
'id_agents[]', 0, false, '', '', true, true);
echo '<form method="post" onsubmit="if (! confirm(\''.__('Are you sure').'\')) return false;">';
print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'" onsubmit="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
print_input_hidden ('delete', 1);
print_submit_button (__('Delete'), 'go', false, 'class="sub delete"');
echo '</div>';
echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
require_jquery_file ('form');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
$(document).ready (function () {
$("#id_group").pandoraSelectGroup ({
agentSelectId: "id_agents\\[\\]"
});
});
</script>

View File

@ -220,8 +220,9 @@ if ($id_agent_module) {
}
echo '</div>';
echo '</form>';
$config['jquery'][] = 'ui';
$config['jquery'][] = 'form';
require_jquery_file ('ui');
require_jquery_file ('form');
?>
<script language="javascript">

View File

@ -310,10 +310,10 @@ if ($create_downtime || $update_downtime) {
echo '</div>';
}
$config['css'][] = 'datepicker';
$config['jquery'][] = 'ui.core';
$config['jquery'][] = 'ui.datepicker';
$config['jquery'][] = 'timeentry';
require_css_file ('datepicker');
require_jquery_file ('ui.core');
require_jquery_file ('ui.datepicker');
require_jquery_file ('timeentry');
?>
<script language="javascript" type="text/javascript">

View File

@ -187,7 +187,7 @@ print_input_hidden ('new_compound', 1);
echo '</form>';
echo '</div>';
$config['jquery'][] = 'pandora.controls';
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">

View File

@ -394,10 +394,9 @@ print_submit_button (__('Add'), 'add_action', false, 'class="sub next"');
echo '</div>';
echo '</form>';
$config['css'][] = 'cluetip';
$config['jquery'][] = 'cluetip';
$config['jquery'][] = 'pandora.controls';
require_css_file ('cluetip');
require_jquery_file ('cluetip');
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
/* <![CDATA[ */

View File

@ -590,13 +590,13 @@ if ($step == 1) {
print_select (get_alert_compound_operations (), 'operations');
echo '</div>';
}
$config['jquery'][] = 'form';
$config['jquery'][] = 'tablesorter';
$config['jquery'][] = 'tablesorter.pager';
$config['jquery'][] = 'ui.core';
$config['jquery'][] = 'timeentry';
$config['css'][] = 'timeentry';
require_css_file ('timeentry');
require_jquery_file ('form');
require_jquery_file ('tablesorter');
require_jquery_file ('tablesorter.pager');
require_jquery_file ('ui.core');
require_jquery_file ('timeentry');
?>
<script type="text/javascript" src="include/javascript/pandora_alerts.js"></script>

View File

@ -502,11 +502,9 @@ if ($step >= LAST_STEP) {
echo '</div>';
echo '</form>';
$config['jquery'][] = 'ui.core';
$config['jquery'][] = 'timeentry';
$config['jquery'][] = 'ui.core';
$config['js'][] = 'pandora_alerts';
require_jquery_file ('ui.core');
require_jquery_file ('timeentry');
require_javascript_file ('pandora_alerts');
?>
<script type="text/javascript">
/* <![CDATA[ */

View File

@ -34,6 +34,8 @@ if (give_acl ($config['id_user'], 0, "AW")) {
$sub["godmode/agentes/manage_config_remote"]["text"] = __('Duplicate config');
$sub["godmode/agentes/manage_delete"]["text"] = __('Massive delete');
if (give_acl ($config["id_user"], 0, "PM")) {
$sub["godmode/groups/group_list"]["text"] = __('Manage groups');
}

View File

@ -433,12 +433,13 @@ if (! $edit_layout && ! $id_layout) {
}
}
$config['css'][] = 'color-picker';
$config['jquery'][] = 'ui.core';
$config['jquery'][] = 'ui.draggable';
$config['jquery'][] = 'ui.droppable';
$config['jquery'][] = 'colorpicker';
$config['js'][] = 'pandora_visual_console';
require_css_file ('color-picker');
require_jquery_file ('ui.core');
require_jquery_file ('ui.draggable');
require_jquery_file ('ui.droppable');
require_jquery_file ('colorpicker');
require_javascript_file ('pandora_visual_console');
?>
<script language="javascript" type="text/javascript">
function agent_changed (event, id_agent, selected) {

View File

@ -1004,137 +1004,4 @@ function safe_sql_string ($string) {
return $string;
return mysql_escape_string ($string);
}
/**
* Callback function to add stuff to the head. This allows us to add scripts to the header after the fact as well as extensive validation
* DO NOT CALL print_f, echo, ob_start, ob_flush, ob_end functions here.
*
* To add jquery scripts just put them in include/javascript and then add them to the $config['jquery'] array (eg. $config['jquery'][] = ui.datepicker)
* To add javascript scripts just put them in include/javascript and then add them to the $config['js'] array
* To add css just put them in include/styles and then add them to the $config['css'] array
*
* @param string Callback will fill this with the current buffer.
* @param bitfield Callback will fill this with a bitfield (see ob_start)
*
* @return string String to return to the browser
*/
function process_page_head ($string, $bitfield) {
global $config;
$output = '';
if ($config["refr"] > 0) {
// Agent selection filters and refresh
$query = 'http' . (isset ($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': '') . '://' . $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != 80 && (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE && $_SERVER['SERVER_PORT'] != 443)) {
$query .= ":" . $_SERVER['SERVER_PORT'];
}
$query .= $_SERVER['SCRIPT_NAME'];
if (sizeof ($_REQUEST))
//Some (old) browsers don't like the ?&key=var
$query .= '?1=1';
//We don't clean these variables up as they're only being passed along
foreach ($_GET as $key => $value) {
/* Avoid the 1=1 */
if ($key == 1)
continue;
$query .= '&amp;'.$key.'='.$value;
}
foreach ($_POST as $key => $value) {
$query .= '&amp;'.$key.'='.$value;
}
$output .= '<meta http-equiv="refresh" content="'.$config["refr"].'; URL='.$query.'" />';
}
$output .= '<title>Pandora FMS - '.__('the Flexible Monitoring System').'</title>
<meta http-equiv="expires" content="0" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="author" content="Sancho Lerena" />
<meta name="copyright" content="This is GPL software. Created by Sancho Lerena and others" />
<meta name="keywords" content="pandora, monitoring, system, GPL, software" />
<meta name="robots" content="index, follow" />
<link rel="icon" href="images/pandora.ico" type="image/ico" />
<link rel="stylesheet" href="include/styles/'.$config["style"].'.css" type="text/css" />
<!--[if gte IE 6]>
<link rel="stylesheet" href="include/styles/ie.css" type="text/css"/>
<![endif]-->
<script type="text/javascript" src="include/javascript/pandora.js"></script>
<script type="text/javascript" src="include/javascript/jquery.js"></script>
<script type="text/javascript" src="include/javascript/jquery.pandora.js"></script>
<script type="text/javascript" src="include/languages/time_'.$config['language'].'.js"></script>
<script type="text/javascript" src="include/languages/date_'.$config['language'].'.js"></script>
<script type="text/javascript" src="include/languages/countdown_'.$config['language'].'.js"></script>';
if (!empty ($config['css'])) {
$loaded = array ('', $config["style"], 'ie'); //We can't load empty and we loaded current style and ie
foreach ($config['css'] as $style) {
if (in_array ($style, $loaded)) {
continue;
}
array_push ($loaded, $style);
$output .= '<link rel="stylesheet" href="include/styles/'.$style.'.css" type="text/css" />'."\n";
}
}
if (!empty ($config['js'])) {
//Load other javascript
$loaded = array ('', 'pandora', 'date_'.$config['language'], 'time_'.$config['language'], 'countdown_'.$config['language']); //We can't load empty and we loaded wz_jsgraphics and pandora
foreach ($config['js'] as $javascript) {
if (in_array ($javascript, $loaded)) {
continue;
}
array_push ($loaded, $javascript);
$output .= '<script type="text/javascript" src="include/javascript/'.$javascript.'.js"></script>'."\n";
}
}
if (!empty ($config['jquery'])) {
//Load jQuery
$loaded = array ('', 'pandora'); //We automagically load pandora and jquery
//Then add each script as necessary
foreach ($config['jquery'] as $script) {
if (in_array ($script, $loaded)) {
continue;
}
array_push ($loaded, $script);
$output .= '<script type="text/javascript" src="include/javascript/jquery.'.$script.'.js"></script>';
}
}
$output .= $string;
return $output;
}
/**
* Callback function to add stuff to the body
*
* @param string Callback will fill this with the current buffer.
* @param bitfield Callback will fill this with a bitfield (see ob_start)
*
* @return string String to return to the browser
*/
function process_page_body ($string, $bitfield) {
global $config;
// Show custom background
if ($config["pure"] == 0) {
$output = '<body style="background-color:#555555;">';
} else {
$output = '<body>'; //Don't enforce a white background color. Let user style sheet do that
}
$output .= $string;
$output .= '</body>';
return $output;
}
?>

View File

@ -45,7 +45,7 @@ function get_user_custom_graphs ($id_user = 0, $only_names = false) {
if ($only_names) {
$graphs[$graph['id_graph']] = $graph['name'];
} else {
array_push ($graphs, $graph);
$graphs[$graph['id_graph']] = $graph;
}
}

View File

@ -1454,6 +1454,50 @@ function get_db_value ($field, $table, $field_search = 1, $condition = 1) {
return $result[0][$field];
}
/**
* Get the first value of the first row of a table in the database from an
* array with filter conditions.
*
* Example:
<code>
get_db_value_filter ('name', 'talert_templates',
array ('value' => 2, 'type' => 'equal'));
// Equivalent to:
// SELECT name FROM talert_templates WHERE value = 2 AND type = 'equal' LIMIT 1
get_db_value_filter ('description', 'talert_templates',
array ('name' => 'My alert', 'type' => 'regex'), 'OR');
// Equivalent to:
// SELECT description FROM talert_templates WHERE name = 'My alert' OR type = 'equal' LIMIT 1
</code>
*
* @param string Field name to get
* @param string Table to retrieve the data
* @param array Conditions to filter the element. See format_array_to_where_clause_sql()
* for the format
* @param string Join operator for the elements in the filter.
*
* @return mixed Value of first column of the first row. False if there were no row.
*/
function get_db_value_filter ($field, $table, $filter, $join = 'AND') {
if (! is_array ($filter) || empty ($filter))
return false;
/* Avoid limit and offset if given */
unset ($filter['limit']);
unset ($filter['offset']);
$sql = sprintf ("SELECT %s FROM %s WHERE %s LIMIT 1",
$field, $table,
format_array_to_where_clause_sql ($filter, $join));
$result = get_db_all_rows_sql ($sql);
if ($result === false)
return false;
return $result[0][$field];
}
/**
* Get the first row of an SQL database query.
*
@ -1533,6 +1577,22 @@ function get_db_all_rows_sql ($sql) {
return false;
}
function get_db_all_rows_filter ($table, $filter, $fields = false) {
if (empty ($fields)) {
$fields = '*';
} else {
if (is_array ($fields))
$fields = implode (',', $fields);
else if (! is_string ($fields))
return false;
}
$sql = sprintf ('SELECT %s FROM %s WHERE %s',
$fields, $table, format_array_to_where_clause_sql ($filter));
return get_db_all_rows_sql ($sql);
}
/**
* Error handler function when an SQL error is triggered.
*
@ -1722,7 +1782,7 @@ function format_array_to_update_sql ($values) {
$values['name'] = "Name";
$values['description'] = "Long description";
$values['limit'] = $config['block_size']; // Assume it's 20
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_sql ($values);
$sql = 'SELECT * FROM table WHERE '.format_array_to_where_clause_sql ($values);
echo $sql;
</code>
* Will return:
@ -1780,7 +1840,7 @@ function format_array_to_where_clause_sql ($values, $join = 'AND') {
}
if ($i < $max) {
$query .= $join;
$query .= ' '.$join.' ';
}
$i++;
}
@ -2267,52 +2327,62 @@ function server_status ($id_server) {
* @return bool False if error, true if success.
*/
function delete_agent ($id_agents) {
//Init vars
$errors = 0;
global $config;
$error = false;
//Subfunciton for less typing
/**
* @ignore
*/
function temp_sql_delete ($table, $row, $value) {
global $errors; //Globalize the errors variable
$sql = sprintf ("DELETE FROM %s WHERE %s = %s", $table, $row, $value);
$result = process_sql ($sql);
if ($result === false)
$errors++;
global $error; //Globalize the errors variable
$result = process_sql_delete ($table, $row.' = '.$value);
if ($result === false) {
$error = true;
echo $table, $row.' = '.$value;
}
}
//Convert single values to an array
if (!is_array ($id_agents)) {
$id_agents[0] = (int) $id_agents;
}
if (! is_array ($id_agents))
$id_agents = (array) $id_agents;
//Start transaction
process_sql ("SET AUTOCOMMIT = 0;");
$trerr = process_sql ("START TRANSACTION;");
if ($trerr === false) {
echo "Error starting transaction";
if ($trerr === false)
return false;
}
foreach ($id_agents as $id_agent) {
$id_agent = (int) $id_agent; //Cast as integer
$agent_name = get_agent_name ($id_agent);
if ($id_agent < 1)
continue; //If an agent is not an integer or invalid, don't process it
continue;
/* Check for deletion permissions */
$id_group = get_agent_group ($id_agent);
if (! give_acl ($config['id_user'], $id_group, "AW")) {
process_sql ("ROLLBACK;");
process_sql ("SET AUTOCOMMIT = 1;");
return false;
}
//A variable where we store that long subquery thing for
//modules
$tmodbase = "ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = ".$id_agent.")";
$where_modules = "ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = ".$id_agent.")";
//IP address
$sql = sprintf ("SELECT id_ag FROM taddress_agent, taddress WHERE taddress_agent.id_a = taddress.id_a AND id_agent = %d", $id_agent);
$result = get_db_all_rows_sql ($sql);
$sql = sprintf ("SELECT id_ag FROM taddress_agent, taddress
WHERE taddress_agent.id_a = taddress.id_a
AND id_agent = %d",
$id_agent);
$addresses = get_db_all_rows_sql ($sql);
if ($result)
foreach ($result as $row) {
temp_sql_delete ("taddress_agent", "id_ag", $row["id_ag"]);
if ($addresses === false)
$addresses = array ();
foreach ($addresses as $address) {
temp_sql_delete ("taddress_agent", "id_ag", $address["id_ag"]);
}
// We cannot delete tagente_datos and tagente_datos_string here
@ -2321,53 +2391,58 @@ function delete_agent ($id_agents) {
// daily maintance process, all data for that modules are deleted
//Alert
/* TODO: Compound alert */
//temp_sql_delete ("tcompound_alert", "id_aam", "ANY(SELECT id_aam FROM talerta_agente_modulo WHERE id_agent = ".$id_agent.")");
temp_sql_delete ("talert_template_modules", "id_agent_module", $tmodbase);
temp_sql_delete ("talert_compound", "id_agent", $id_agent);
temp_sql_delete ("talert_template_modules", "id_agent_module", $where_modules);
//Events (up/down monitors)
temp_sql_delete ("tevento", "id_agente", $id_agent);
//Graphs, layouts & reports
temp_sql_delete ("tgraph_source", "id_agent_module", $tmodbase);
temp_sql_delete ("tlayout_data", "id_agente_modulo", $tmodbase);
temp_sql_delete ("treport_content", "id_agent_module", $tmodbase);
temp_sql_delete ("tgraph_source", "id_agent_module", $where_modules);
temp_sql_delete ("tlayout_data", "id_agente_modulo", $where_modules);
temp_sql_delete ("treport_content", "id_agent_module", $where_modules);
//Planned Downtime
temp_sql_delete ("tplanned_downtime_agents", "id_agent", $id_agent);
//The status of the module
temp_sql_delete ("tagente_estado", "id_agente_modulo", $tmodbase);
temp_sql_delete ("tagente_estado", "id_agente_modulo", $where_modules);
//The actual modules, don't put anything based on
//tagente_modulo after this
temp_sql_delete ("tagente_modulo", "id_agente", $id_agent);
process_sql ('UPDATE tagente_modulo SET delete_pending = 1, disabled = 1 WHERE id_agente = '. $id_agent);
process_sql_update ('tagente_modulo',
array ('delete_pending' => 1, 'disabled' => 1),
'id_agente = '. $id_agent);
//Access entries
temp_sql_delete ("tagent_access", "id_agent", $id_agent);
//tagente_datos_inc
temp_sql_delete ("tagente_datos_inc", "id_agente_modulo", $tmodbase);
temp_sql_delete ("tagente_datos_inc", "id_agente_modulo", $where_modules);
// Delete remote configuration
if (isset ($config["remote_config"])) {
$agent_md5 = md5 (get_agent_name ($id_agent), FALSE);
if (file_exists ($config["remote_config"]."/".$agent_md5.".md5")) {
// Agent remote configuration editor
$file_name = $config["remote_config"]."/".$agent_md5.".conf";
@unlink ($file_name);
$file_name = $config["remote_config"]."/".$agent_md5.".md5";
@unlink ($file_name);
}
}
//And at long last, the agent
temp_sql_delete ("tagente", "id_agente", $id_agent);
// Delete remote configuration
$agent_md5 = md5($agent_name, FALSE);
if (isset($config["remote_config"]))
if (file_exists($config["remote_config"] . "/" . $agent_md5 . ".md5")) {
// Agent remote configuration editor
$file_name = $config["remote_config"] . "/" . $agent_md5 . ".conf";
unlink ($file_name);
$file_name = $config["remote_config"] . "/" . $agent_md5 . ".md5";
unlink ($file_name);
}
/* Break the loop on error */
if ($error)
break;
}
if ($errors > 0) {
if ($error) {
process_sql ("ROLLBACK;");
process_sql ("SET AUTOCOMMIT = 1;");
return false;
@ -2581,7 +2656,7 @@ function process_sql_insert ($table, $values) {
}
/**
* Inserts strings into database
* Updates a database record.
*
* All values should be cleaned before passing. Quoting isn't necessary.
* Examples:
@ -2642,4 +2717,52 @@ function process_sql_update ($table, $values, $where = false, $where_join = 'AND
return process_sql ($query);
}
/**
* Delete database records.
*
* All values should be cleaned before passing. Quoting isn't necessary.
* Examples:
*
* <code>
process_sql_delete ('table', array ('id' => 1));
// DELETE FROM table WHERE id = 1
process_sql_delete ('table', array ('id' => 1, 'name' => 'example'));
// DELETE FROM table WHERE id = 1 AND name = 'example'
process_sql_delete ('table', array ('id' => 1, 'name' => 'example'), 'OR');
// DELETE FROM table WHERE id = 1 OR name = 'example'
process_sql_delete ('table', 'id in (1, 2, 3) OR id > 10');
// DELETE FROM table WHERE id in (1, 2, 3) OR id > 10
* <code>
*
* @param string Table to insert into
* @param array An associative array of values to update
* @param mixed An associative array of field and value matches. Will be joined
* with operator specified by $where_join. A custom string can also be provided.
* If nothing is provided, the update will affect all rows.
* @param string When a $where parameter is given, this will work as the glue
* between the fields. "AND" operator will be use by default. Other values might
* be "OR", "AND NOT", "XOR"
*
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
*/
function process_sql_delete ($table, $where, $where_join = 'AND') {
if (empty ($where))
/* Should avoid any mistake that lead to deleting all data */
return false;
$query = sprintf ("DELETE FROM `%s` WHERE ", $table);
if ($where) {
if (is_string ($where)) {
/* FIXME: Should we clean the string for sanity?
Who cares if this is deleting data... */
$query .= $where;
} else if (is_array ($where)) {
$query .= format_array_to_where_clause_sql ($where);
}
}
return process_sql ($query);
}
?>

View File

@ -413,4 +413,238 @@ function print_help_icon ($help_id, $return = false) {
return $output;
}
/**
* Add a CSS file to the HTML head tag.
*
* To make a CSS file available just put it in include/styles. The
* file name should be like "name.css". The "name" would be the value
* needed to pass to this function.
* @param string Script name to add without the "jquery." prefix and the ".js"
* suffix. Example:
<code>
require_css_file ('pandora');
// Would include include/styles/pandora.js
</code>
*
* @return bool True if the file was added. False if the file doesn't exist.
*/
function require_css_file ($name, $path = 'include/styles/') {
global $config;
$filename = $path.$name.'.css';
if (! isset ($config['css']))
$config['css'] = array ();
if (isset ($config['css'][$name]))
return true;
if (! file_exists ($filename) && ! file_exists ($config['homedir'].'/'.$filename))
return false;
$config['css'][$name] = $filename;
return true;
}
/**
* Add a javascript file to the HTML head tag.
*
* To make a javascript file available just put it in include/javascript. The
* file name should be like "name.js". The "name" would be the value
* needed to pass to this function.
* @param string Script name to add without the "jquery." prefix and the ".js"
* suffix. Example:
<code>
require_javascript_file ('pandora');
// Would include include/javascript/pandora.js
</code>
*
* @return bool True if the file was added. False if the file doesn't exist.
*/
function require_javascript_file ($name, $path = 'include/javascript/') {
global $config;
$filename = $path.$name.'.js';
if (! isset ($config['js']))
$config['js'] = array ();
if (isset ($config['js'][$name]))
return true;
/* We checks two paths because it may fails on enterprise */
if (! file_exists ($filename) && ! file_exists ($config['homedir'].'/'.$filename))
return false;
$config['js'][$name] = $filename;
return true;
}
/**
* Add a jQuery file to the HTML head tag.
*
* To make a jQuery script available just put it in include/javascript. The
* file name should be like "jquery.name.js". The "name" would be the value
* needed to pass to this function. Notice that this function does not manage
* jQuery denpendencies.
* @param string Script name to add without the "jquery." prefix and the ".js"
* suffix. Example:
<code>
require_jquery_file ('form');
// Would include include/javascript/jquery.form.js
</code>
*
* @return bool True if the file was added. False if the file doesn't exist.
*/
function require_jquery_file ($name, $path = 'include/javascript/') {
global $config;
$filename = $path.'jquery.'.$name.'.js';
if (! isset ($config['jquery']))
$config['jquery'] = array ();
if (isset ($config['jquery'][$name]))
return true;
/* We checks two paths because it may fails on enterprise */
if (! file_exists ($filename) && ! file_exists ($config['homedir'].'/'.$filename))
return false;
$config['jquery'][$name] = $filename;
return true;
}
/**
* Callback function to add stuff to the head. This allows us to add scripts
* to the header after the fact as well as extensive validation.
*
* DO NOT CALL print_f, echo, ob_start, ob_flush, ob_end functions here.
*
* To add css just put them in include/styles and then add them to the
* $config['css'] array
*
* @param string Callback will fill this with the current buffer.
* @param bitfield Callback will fill this with a bitfield (see ob_start)
*
* @return string String to return to the browser
*/
function process_page_head ($string, $bitfield) {
global $config;
$output = '';
if ($config["refr"] > 0) {
// Agent selection filters and refresh
$query = 'http' . (isset ($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? 's': '') . '://' . $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != 80 && (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE && $_SERVER['SERVER_PORT'] != 443)) {
$query .= ":" . $_SERVER['SERVER_PORT'];
}
$query .= $_SERVER['SCRIPT_NAME'];
if (sizeof ($_REQUEST))
//Some (old) browsers don't like the ?&key=var
$query .= '?1=1';
//We don't clean these variables up as they're only being passed along
foreach ($_GET as $key => $value) {
/* Avoid the 1=1 */
if ($key == 1)
continue;
$query .= '&amp;'.$key.'='.$value;
}
foreach ($_POST as $key => $value) {
$query .= '&amp;'.$key.'='.$value;
}
$output .= '<meta http-equiv="refresh" content="'.$config["refr"].'; URL='.$query.'" />';
}
$output .= "\n\t";
$output .= '<title>Pandora FMS - '.__('the Flexible Monitoring System').'</title>
<meta http-equiv="expires" content="0" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="author" content="Sancho Lerena" />
<meta name="copyright" content="This is GPL software. Created by Sancho Lerena and others" />
<meta name="keywords" content="pandora, monitoring, system, GPL, software" />
<meta name="robots" content="index, follow" />
<link rel="icon" href="images/pandora.ico" type="image/ico" />
<link rel="stylesheet" href="include/styles/'.$config["style"].'.css" type="text/css" />
<!--[if gte IE 6]>
<link rel="stylesheet" href="include/styles/ie.css" type="text/css"/>
<![endif]-->
<script type="text/javascript" src="include/javascript/pandora.js"></script>
<script type="text/javascript" src="include/javascript/jquery.js"></script>
<script type="text/javascript" src="include/javascript/jquery.pandora.js"></script>
<script type="text/javascript" src="include/languages/time_'.$config['language'].'.js"></script>
<script type="text/javascript" src="include/languages/date_'.$config['language'].'.js"></script>
<script type="text/javascript" src="include/languages/countdown_'.$config['language'].'.js"></script>'."\n\t";
if (!empty ($config['css'])) {
//We can't load empty and we loaded current style and ie
$loaded = array ('', $config["style"], 'ie');
foreach ($config['css'] as $name => $filename) {
if (in_array ($name, $loaded))
continue;
array_push ($loaded, $name);
$output .= '<link rel="stylesheet" href="'.$filename.'" type="text/css" />'."\n\t";
}
}
if (!empty ($config['js'])) {
//Load other javascript
//We can't load empty and we loaded wz_jsgraphics and pandora
$loaded = array ('', 'pandora', 'date_'.$config['language'],
'time_'.$config['language'], 'countdown_'.$config['language']);
foreach ($config['js'] as $name => $filename) {
if (in_array ($name, $loaded))
continue;
array_push ($loaded, $name);
$output .= '<script type="text/javascript" src="'.$filename.'"></script>'."\n\t";
}
}
if (!empty ($config['jquery'])) {
//Load jQuery
$loaded = array ('', 'pandora');
//Then add each script as necessary
foreach ($config['jquery'] as $name => $filename) {
if (in_array ($name, $loaded))
continue;
array_push ($loaded, $name);
$output .= '<script type="text/javascript" src="'.$filename.'"></script>'."\n\t";
}
}
$output .= $string;
return $output;
}
/**
* Callback function to add stuff to the body
*
* @param string Callback will fill this with the current buffer.
* @param bitfield Callback will fill this with a bitfield (see ob_start)
*
* @return string String to return to the browser
*/
function process_page_body ($string, $bitfield) {
global $config;
// Show custom background
if ($config["pure"] == 0) {
$output = '<body style="background-color:#555555;">';
} else {
$output = '<body>'; //Don't enforce a white background color. Let user style sheet do that
}
$output .= $string;
$output .= '</body>';
return $output;
}
?>

View File

@ -1,3 +1,5 @@
var ENTERPRISE_DIR = 'enterprise';
/* Function to hide/unhide a specific Div id */
function toggleDiv (divid){
if (document.getElementById(divid).style.display == 'none') {

View File

@ -761,7 +761,8 @@ table#source_table select,
table#destiny_table select,
table#target_table select,
table#filter_compound_table select,
table#filter_compound_table #text-search {
table#filter_compound_table #text-search,
table#delete_table select {
width: 100%;
}
table#simple select#network_component_group,

View File

@ -98,7 +98,9 @@ if (!empty ($config["https"]) && empty ($_SERVER['HTTPS'])) {
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>';
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
echo '<head>';
//This starts the page head. In the call back function, things from $page['head'] array will be processed into the head
ob_start ('process_page_head');
// Pure mode (without menu, header and footer).
@ -108,10 +110,9 @@ $config["pure"] = (bool) get_parameter ("pure");
$config["refr"] = (int) get_parameter ("refr");
enterprise_include ('index.php');
enterprise_hook ('load_html_header');
//This tag is included in the buffer passed to process_page_head so technically it can be stripped
echo '</head>';
echo '</head>'."\n";
ob_start ('process_page_body');
@ -247,4 +248,4 @@ if ($config["pure"] == 0) {
echo '</div>'; //container div
while (@ob_end_flush ());
echo '</html>';
?>
?>

View File

@ -387,8 +387,8 @@ if ($result !== false) {
return;
}
$config['css'][] = 'cluetip';
$config['jquery'][] = 'cluetip';
require_css_file ('cluetip');
require_jquery_file ('cluetip');
?>
<script language="javascript" type="text/javascript">
/* <![CDATA[ */

View File

@ -83,10 +83,10 @@ echo '</div>';
/* We must add javascript here. Otherwise, the date picker won't
work if the date is not correct because php is returning. */
$config['css'][] = 'datepicker';
$config['jquery'][] = 'ui.core';
$config['jquery'][] = 'ui.datepicker';
$config['jquery'][] = 'ui.timeentry';
require_css_file ('datepicker');
require_jquery_file ('ui.core');
require_jquery_file ('ui.datepicker');
require_jquery_file ('ui.timeentry');
?>
<script language="javascript" type="text/javascript">

View File

@ -101,8 +101,8 @@ print_table ($table);
echo '</form>';
if ($config["pure"] && $refr != 0) {
$config['jquery'][] = 'countdown';
$config['css'][] = 'countdown';
require_jquery_file ('countdown');
require_css_file ('countdown');
}
$config['js'][] = 'pandora_visual_console';
?>