pandorafms/pandora_console/godmode/massive/massive_edit_modules.php

307 lines
11 KiB
PHP
Raw Normal View History

<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org 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 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.
// Load global vars
check_login ();
2009-04-02 Sancho Lerena <slerena@artica.es> * pandoradb.sql: Final DB changes proposed for closing this month the DB scheme. tagente-> new server_name field to assign server (old fields will be removed). talert_templates has two new types (warning, critical). tevento has "user_comment" new field. Tserver has three new fields, server_type (so some old fields will be deleted), threads and queued_modules this last two are for statistical options. Tusuario add language type to override global language. * update_manager/main.php: Minor changes for correct ACL usage. Non PM users could see in what revision it the system, but only that. * pandoradb_migrate_v2.x_to_v3.0.sql: Updated script for new DB changes. * general/noaccess.php: Added footer and ending div. Page was very ugly when showing noaccess errors, nobody see it ???. * godmode/menu.php: A LOT of ACL fixes on several options. * godmode/agentes/agent_manager.php: Fixed a crazy floating icon. * godmode/agentes/manage_config_remote.php: A LOT of changes, rewriting stuff, because was not working. This also adds a lot of ACL checks. * godmode/agentes/massive_config.php, massive*: ACL changes. * godmode/agentes/modificar_agente.php: Fixed ACL problems. * godmode/agentes/module_manager_editor.php: Fixed bad module categories for some types (data, plugin and prediction). * godmode/alerts/alert_list.php: Fixed ACL problem. * godmode/reporting/graph_builder.php: Added ACl restriction for non-viewable agents for current user. Seems to be a problem with data with more than 2 sources. * godmode/reporting/map_builder.php: ACL checks improved. * godmode/reporting/reporting_builder.php: ACL checks added (was missing), some code ported from 2.1, other is new. New fields shown in list. * include/functions.php: Fixed the annoying bug of "bad counters" in function human_time_description_raw(). Function used,format_numeric() should not be used never to calculate nothing, only to print formatted strings. * include/functions_db.php: Added function user_access_to_agent() to know if a given user has access to a given agent. * include/functioins_report.php: get_report() should let admin to watch any report. Fixed. * agentes/alerts_status.php: Fixed ACL problem for view alert. * operation/incidents/incident.php: Bad call for pagination() was giving problems to pagination call. Somebody changes pagination() interface and make this broken. Please if you change any interface, be sure that is compatible with old code or make a post in the list about this ! * godmode/users/user_edit.php: Additional ACL check to do not let anybody to watch non accesible users. Even for see the username or description. * reporting/pchart_graph.php:Progress bar shown text in white when > 60%. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1594 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-02 21:16:59 +02:00
if (! give_acl ($config['id_user'], 0, "PM")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation",
2009-04-02 Sancho Lerena <slerena@artica.es> * pandoradb.sql: Final DB changes proposed for closing this month the DB scheme. tagente-> new server_name field to assign server (old fields will be removed). talert_templates has two new types (warning, critical). tevento has "user_comment" new field. Tserver has three new fields, server_type (so some old fields will be deleted), threads and queued_modules this last two are for statistical options. Tusuario add language type to override global language. * update_manager/main.php: Minor changes for correct ACL usage. Non PM users could see in what revision it the system, but only that. * pandoradb_migrate_v2.x_to_v3.0.sql: Updated script for new DB changes. * general/noaccess.php: Added footer and ending div. Page was very ugly when showing noaccess errors, nobody see it ???. * godmode/menu.php: A LOT of ACL fixes on several options. * godmode/agentes/agent_manager.php: Fixed a crazy floating icon. * godmode/agentes/manage_config_remote.php: A LOT of changes, rewriting stuff, because was not working. This also adds a lot of ACL checks. * godmode/agentes/massive_config.php, massive*: ACL changes. * godmode/agentes/modificar_agente.php: Fixed ACL problems. * godmode/agentes/module_manager_editor.php: Fixed bad module categories for some types (data, plugin and prediction). * godmode/alerts/alert_list.php: Fixed ACL problem. * godmode/reporting/graph_builder.php: Added ACl restriction for non-viewable agents for current user. Seems to be a problem with data with more than 2 sources. * godmode/reporting/map_builder.php: ACL checks improved. * godmode/reporting/reporting_builder.php: ACL checks added (was missing), some code ported from 2.1, other is new. New fields shown in list. * include/functions.php: Fixed the annoying bug of "bad counters" in function human_time_description_raw(). Function used,format_numeric() should not be used never to calculate nothing, only to print formatted strings. * include/functions_db.php: Added function user_access_to_agent() to know if a given user has access to a given agent. * include/functioins_report.php: get_report() should let admin to watch any report. Fixed. * agentes/alerts_status.php: Fixed ACL problem for view alert. * operation/incidents/incident.php: Bad call for pagination() was giving problems to pagination call. Somebody changes pagination() interface and make this broken. Please if you change any interface, be sure that is compatible with old code or make a post in the list about this ! * godmode/users/user_edit.php: Additional ACL check to do not let anybody to watch non accesible users. Even for see the username or description. * reporting/pchart_graph.php:Progress bar shown text in white when > 60%. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1594 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2009-04-02 21:16:59 +02:00
"Trying to access massive module update");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_modules.php');
function process_manage_edit ($module_name, $group_select = null, $agents_select = null) {
if (is_int ($module_name) && $module_name <= 0) {
echo '<h3 class="error">'.__('No modules selected').'</h3>';
return false;
}
if (($group_select === null) || ($group_select == 0))
$agents = array_keys (get_group_agents (array_keys (get_user_groups ()), false, "none"));
else {
if (($agents_select === null) || ($agents_select == 0)) {
$agents = array_keys (get_group_agents ($group_select, false, "none"));
}
else {
$agents = $agents_select;
}
}
/* List of fields which can be updated */
$fields = array ('min_warning', 'max_warning', 'min_critical', 'max_critical', 'min_ff_event','module_interval',
'disabled','post_process','snmp_community','min','max','id_module_group', 'plugin_user', 'plugin_pass', 'id_export', 'history_data');
$values = array ();
foreach ($fields as $field) {
$value = get_parameter ($field);
if ($value != '')
$values[$field] = $value;
}
if (strlen(get_parameter('history_data')) > 0) {
$values['history_data'] = get_parameter('history_data');
}
$modules = get_db_all_rows_filter ('tagente_modulo',
array ('id_agente' => $agents,
'nombre' => $module_name),
array ('id_agente_modulo'));
process_sql_begin ();
if ($modules === false)
return false;
foreach ($modules as $module) {
$result = update_agent_module ($module['id_agente_modulo'], $values, true);
if ($result === false) {
process_sql_rollback ();
return false;
}
}
process_sql_commit ();
return true;
}
$module_type = (int) get_parameter ('module_type');
$module_name = (string) get_parameter ('module_name');
$idGroupMassive = (int) get_parameter('id_group_massive');
$idAgentMassive = (int) get_parameter('id_agent_massive');
$group_select = get_parameter('groups_select');
$agents_select = get_parameter('agents_select');
$update = (bool) get_parameter_post ('update');
if ($update) {
$result = process_manage_edit ($module_name, $group_select, $agents_select);
print_result_message ($result,
__('Successfully updated'),
__('Could not be updated'));
}
$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->rowstyle = array ();
$table->size = array ();
$table->size[0] = '15%';
$table->size[1] = '35%'; /* Fixed using javascript */
$table->size[2] = '15%';
$table->size[3] = '35%';
if (! $module_type) {
$table->rowstyle['edit1'] = 'display: none';
$table->rowstyle['edit2'] = 'display: none';
$table->rowstyle['edit3'] = 'display: none';
$table->rowstyle['edit4'] = 'display: none';
$table->rowstyle['edit5'] = 'display: none';
$table->rowstyle['edit6'] = 'display: none';
$table->rowstyle['edit7'] = 'display: none';
}
$agents = get_group_agents (array_keys (get_user_groups ()), false, "none");
$module_types = get_db_all_rows_filter ('tagente_modulo,ttipo_modulo',
array ('tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo',
'id_agente' => array_keys ($agents),
'disabled' => 0,
'order' => 'ttipo_modulo.nombre'),
array ('DISTINCT(id_tipo)',
'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description'));
if ($module_types === false)
$module_types = array ();
$types = '';
foreach ($module_types as $type) {
$types[$type['id_tipo']] = $type['description'];
}
$table->data = array ();
$table->data[0][0] = __('Module type');
$table->data[0][0] .= '<span id="module_loading" class="invisible">';
$table->data[0][0] .= '<img src="images/spinner.png" />';
$table->data[0][0] .= '</span>';
$table->data[0][1] = print_select ($types,
'module_type', $module_type, false, __('Select'), 0, true, false, false);
$modules = array ();
if ($module_type != '') {
$filter = array ('id_tipo_modulo' => $module_type);
}
else {
$filter = false;
}
$names = get_agent_modules (array_keys ($agents),
'DISTINCT(nombre)', $filter, false);
foreach ($names as $name) {
$modules[$name['nombre']] = $name['nombre'];
}
$table->data[0][2] = __('Module name');
$table->data[0][3] = print_select ($modules, 'module_name',
$module_name, false, __('Select'), 0, true, false, false);
$table->rowstyle[1] = 'vertical-align: top;';
$table->data[1][0] = __('Agent group');
$table->data[1][1] = print_select (get_all_groups(true), 'groups_select',
$idGroupMassive, false, __('All'), 0, true, false, false);
$table->data[1][2] = __('Agents');
$table->data[1][3] = print_select ($agents, 'agents_select[]',
$idAgentMassive, false, __('All'), 0, true, true, false);
$table->data['edit1'][0] = __('Warning status');
$table->data['edit1'][1] = '<em>'.__('Min.').'</em>';
$table->data['edit1'][1] .= print_input_text ('min_warning', '', '', 5, 15, true);
$table->data['edit1'][1] .= '<br /><em>'.__('Max.').'</em>';
$table->data['edit1'][1] .= print_input_text ('max_warning', '', '', 5, 15, true);
$table->data['edit1'][2] = __('Critical status');
$table->data['edit1'][3] = '<em>'.__('Min.').'</em>';
$table->data['edit1'][3] .= print_input_text ('min_critical', '', '', 5, 15, true);
$table->data['edit1'][3] .= '<br /><em>'.__('Max.').'</em>';
$table->data['edit1'][3] .= print_input_text ('max_critical', '', '', 5, 15, true);
$table->data['edit2'][0] = __('Interval');
$table->data['edit2'][1] = print_input_text ('module_interval', '', '', 5, 15, true);
$table->data['edit2'][2] = __('Disabled');
//$table->data['edit2'][3] = print_checkbox ("disabled", 1, '', true);
$table->data['edit2'][3] = print_select(array('' => '', '1' => __('Yes'), '0' => __('No')),'disabled','','','', '', true);
$table->data['edit3'][0] = __('Post process');
$table->data['edit3'][1] = print_input_text ('post_process', '', '', 10, 15, true);
$table->data['edit3'][2] = __('SMNP community');
$table->data['edit3'][3] = print_input_text ('snmp_community', '', '', 10, 15, true);
$table->data['edit4'][0] = __('Value');
$table->data['edit4'][1] = '<em>'.__('Min.').'</em>';
$table->data['edit4'][1] .= print_input_text ('min', '', '', 5, 15, true);
$table->data['edit4'][1] .= '<br /><em>'.__('Max.').'</em>';
$table->data['edit4'][1] .= print_input_text ('max', '', '', 5, 15, true);
$table->data['edit4'][2] = __('Module group');
$table->data['edit4'][3] = print_select (get_modulegroups(),
'id_module_group', '', '', __('Select'), 0, true, false, false);
$table->data['edit5'][0] = __('Username');
$table->data['edit5'][1] = print_input_text ('plugin_user', '', '', 15, 60, true);
$table->data['edit5'][2] = __('Password');
$table->data['edit5'][3] = print_input_password ('plugin_pass', '', '', 15, 60, true);
$table->data['edit6'][0] = __('Export target');
$table->data['edit6'][1] = print_select_from_sql ('SELECT id, name FROM tserver_export ORDER BY name',
'id_export', '', '',__('None'),'0', true, false, false);
/* FF stands for Flip-flop */
$table->data['edit7'][0] = __('FF threshold').' '.print_help_icon ('ff_threshold', true);
$table->data['edit7'][1] = print_input_text ('min_ff_event', '', '', 5, 15, true);
$table->data['edit7'][2] = __('Historical data');
$table->data['edit7'][3] = print_select(array('' => '', '1' => __('Yes'), '0' => __('No')),'history_data','','','', '', true);
echo '<form method="post" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=edit_modules" id="form_edit" 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 ('update', 1);
print_submit_button (__('Update'), 'go', false, 'class="sub upd"');
echo '</div>';
echo '</form>';
echo '<h3 class="error invisible" id="message"> </h3>';
require_jquery_file ('pandora.controls');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
$("#module_type").change (function () {
if (this.value == '0') {
filter = '';
}
else {
filter = "id_tipo_modulo="+this.value;
}
$("#module_loading").show ();
$("tr#delete_table-edit1, tr#delete_table-edit2").hide ();
$("#module_name").attr ("disabled", "disabled")
$("#module_name option[value!=0]").remove ();
jQuery.post ("ajax.php",
{"page" : "operation/massive/ver_agente",
"get_agent_modules_json" : 1,
"filter" : filter,
"fields" : "DISTINCT(nombre)",
"indexed" : 0
},
function (data, status) {
jQuery.each (data, function (id, value) {
option = $("<option></option>").attr ("value", value["nombre"]).html (value["nombre"]);
$("#module_name").append (option);
});
$("#module_loading").hide ();
$("#module_name").removeAttr ("disabled");
},
"json"
);
});
$("#module_name").change (function () {
if (this.value <= 0) {
// $("td#delete_table-0-1").css ("width", "85%");
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7").hide ();
return;
}
$("td#delete_table-0-1, td#delete_table-edit1-1, td#delete_table-edit2-1").css ("width", "35%");
$("#form_edit input[type=text]").attr ("value", "");
$("#form_edit input[type=checkbox]").removeAttr ("checked");
$("tr#delete_table-edit1, tr#delete_table-edit2, tr#delete_table-edit3, tr#delete_table-edit4, tr#delete_table-edit5, tr#delete_table-edit6, tr#delete_table-edit7").show ();
});
$("#groups_select").change (
function () {
jQuery.post ("ajax.php",
{"page" : "operation/massive/ver_agente",
"get_agents_group_json" : 1,
"id_group" : this.value,
},
function (data, status) {
$("#agents_select").html('');
option = $("<option></option>").attr ("value", 0).html ("<?php echo __('All'); ?>").attr ("selected", "selected");
$("#agents_select").append (option);
jQuery.each (data, function (id, value) {
option = $("<option></option>").attr ("value", value["id_agente"]).html (value["nombre"]);
$("#agents_select").append (option);
});
},
"json"
);
}
);
});
/* ]]> */
</script>