2010-05-31 11:22:15 +02:00
|
|
|
<?php
|
2019-02-25 13:02:39 +01:00
|
|
|
/**
|
|
|
|
* Extension to manage a list of gateways and the node address where they should
|
|
|
|
* point to.
|
|
|
|
*
|
|
|
|
* @category Extensions
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Community
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2019-02-25 13:02:39 +01:00
|
|
|
* 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.
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
check_login();
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (! check_acl($config['id_user'], 0, 'AW')) {
|
|
|
|
db_pandora_audit(
|
|
|
|
'ACL Violation',
|
|
|
|
'Trying to access massive alert deletion'
|
|
|
|
);
|
|
|
|
include 'general/noaccess.php';
|
|
|
|
return;
|
2010-05-31 11:22:15 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
require_once 'include/functions_agents.php';
|
|
|
|
require_once 'include/functions_alerts.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_modules.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_users.php';
|
|
|
|
|
|
|
|
if (is_ajax()) {
|
|
|
|
$get_agents = (bool) get_parameter('get_agents');
|
|
|
|
$recursion = (bool) get_parameter('recursion', false);
|
|
|
|
|
|
|
|
if ($get_agents) {
|
|
|
|
$id_group = (int) get_parameter('id_group', 0);
|
2019-02-25 13:02:39 +01:00
|
|
|
// Is is possible add keys prefix to avoid auto
|
|
|
|
// sorting in js object conversion.
|
2019-01-30 16:18:44 +01:00
|
|
|
$keys_prefix = (string) get_parameter('keys_prefix', '');
|
|
|
|
|
|
|
|
if ($id_group == 0) {
|
|
|
|
$agents = agents_get_group_agents(
|
|
|
|
array_keys(
|
|
|
|
users_get_groups(
|
|
|
|
$config['id_user'],
|
|
|
|
'AW',
|
|
|
|
true,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
$recursion
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$agents = agents_get_group_agents(
|
|
|
|
$id_group,
|
|
|
|
false,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
$recursion
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-25 13:02:39 +01:00
|
|
|
// Add keys prefix.
|
2019-01-30 16:18:44 +01:00
|
|
|
if ($keys_prefix !== '') {
|
|
|
|
foreach ($agents as $k => $v) {
|
|
|
|
$agents[$keys_prefix.$k] = $v;
|
|
|
|
unset($agents[$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($agents);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2010-05-31 11:22:15 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
|
|
|
|
function process_manage_add($id_alert_template, $id_agents, $module_names)
|
|
|
|
{
|
|
|
|
if (empty($id_agents) || $id_agents[0] == 0) {
|
|
|
|
ui_print_error_message(__('No agents selected'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($id_alert_template)) {
|
|
|
|
ui_print_error_message(__('No alert selected'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-11 14:35:32 +02:00
|
|
|
$modules_id = [];
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
foreach ($module_names as $module) {
|
|
|
|
foreach ($id_agents as $id_agent) {
|
2020-09-11 14:35:32 +02:00
|
|
|
if ($module == '0') {
|
|
|
|
// Get all modules of agent.
|
|
|
|
$agent_modules = db_get_all_rows_filter(
|
|
|
|
'tagente_modulo',
|
|
|
|
['id_agente' => $id_agent],
|
|
|
|
'id_agente_modulo'
|
|
|
|
);
|
|
|
|
|
|
|
|
$agent_modules_id = array_map(
|
|
|
|
function ($field) {
|
|
|
|
return $field['id_agente_modulo'];
|
|
|
|
},
|
|
|
|
$agent_modules
|
|
|
|
);
|
|
|
|
|
|
|
|
$modules_id = array_merge($modules_id, $agent_modules_id);
|
|
|
|
} else {
|
|
|
|
$module_id = modules_get_agentmodule_id($module, $id_agent);
|
|
|
|
$modules_id[] = $module_id['id_agente_modulo'];
|
|
|
|
}
|
2019-01-30 16:18:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$conttotal = 0;
|
|
|
|
$contsuccess = 0;
|
|
|
|
foreach ($modules_id as $module) {
|
|
|
|
$success = alerts_create_alert_agent_module($module, $id_alert_template);
|
|
|
|
|
|
|
|
if ($success) {
|
|
|
|
$contsuccess ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$conttotal ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($contsuccess > 0) {
|
|
|
|
db_pandora_audit('Massive management', 'Add alert', false, false, 'Alert template: '.$id_alert_template.' Modules: '.json_encode($modules_id));
|
|
|
|
} else {
|
|
|
|
db_pandora_audit('Massive management', 'Fail try to add alert', false, false, 'Alert template: '.$id_alert_template.' Modules: '.json_encode($modules_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_print_result_message(
|
|
|
|
$contsuccess > 0,
|
|
|
|
__('Successfully added').'('.$contsuccess.'/'.$conttotal.')',
|
|
|
|
__('Could not be added')
|
|
|
|
);
|
|
|
|
|
2010-05-31 11:22:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$id_group = (int) get_parameter('id_group', -1);
|
|
|
|
$id_agents = get_parameter('id_agents');
|
|
|
|
$module_names = get_parameter('module');
|
|
|
|
$id_alert_template = (int) get_parameter('id_alert_template');
|
|
|
|
$recursion = get_parameter('recursion');
|
|
|
|
|
|
|
|
$add = (bool) get_parameter_post('add');
|
2010-05-31 11:22:15 +02:00
|
|
|
|
|
|
|
if ($add) {
|
2019-01-30 16:18:44 +01:00
|
|
|
process_manage_add($id_alert_template, $id_agents, $module_names);
|
2010-05-31 11:22:15 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$groups = users_get_groups();
|
2014-05-30 13:01:22 +02:00
|
|
|
$own_info = get_user_info($config['id_user']);
|
2019-01-30 16:18:44 +01:00
|
|
|
if (!$own_info['is_admin'] && !check_acl($config['id_user'], 0, 'AW')) {
|
|
|
|
$return_all_group = false;
|
|
|
|
} else {
|
|
|
|
$return_all_group = true;
|
|
|
|
}
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2019-02-25 13:02:39 +01:00
|
|
|
$table = new stdClass();
|
2010-10-08 13:16:57 +02:00
|
|
|
$table->id = 'add_table';
|
2015-06-15 15:50:28 +02:00
|
|
|
$table->class = 'databox filters';
|
|
|
|
$table->width = '100%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data = [];
|
|
|
|
$table->style = [];
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->style[0] = 'font-weight: bold; vertical-align:top';
|
2010-10-08 13:16:57 +02:00
|
|
|
$table->style[2] = 'font-weight: bold; vertical-align:top';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->size = [];
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->size[0] = '15%';
|
2017-03-09 16:09:50 +01:00
|
|
|
$table->size[1] = '25%';
|
2010-10-08 13:16:57 +02:00
|
|
|
$table->size[2] = '15%';
|
2017-03-09 16:09:50 +01:00
|
|
|
$table->size[3] = '30%';
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data = [];
|
|
|
|
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->data[0][0] = __('Group');
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data[0][1] = html_print_select_groups(
|
|
|
|
false,
|
|
|
|
'AW',
|
|
|
|
$return_all_group,
|
|
|
|
'id_group',
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
'Select',
|
|
|
|
-1,
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'width:180px;'
|
|
|
|
);
|
2011-08-29 08:16:04 +02:00
|
|
|
$table->data[0][2] = __('Group recursion');
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data[0][3] = html_print_checkbox('recursion', 1, $recursion, true, false, '', true);
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2010-10-08 13:16:57 +02:00
|
|
|
$table->data[1][0] = __('Agents');
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->data[1][0] .= '<span id="agent_loading" class="invisible">';
|
2011-04-27 15:43:31 +02:00
|
|
|
$table->data[1][0] .= html_print_image('images/spinner.png', true);
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->data[1][0] .= '</span>';
|
2019-01-30 16:18:44 +01:00
|
|
|
$agents_alerts = alerts_get_agents_with_alert_template(
|
|
|
|
$id_alert_template,
|
|
|
|
$id_group,
|
|
|
|
false,
|
|
|
|
[
|
|
|
|
'tagente.nombre',
|
|
|
|
'tagente.id_agente',
|
|
|
|
]
|
|
|
|
);
|
2014-05-30 13:01:22 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$agents = agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)));
|
|
|
|
$table->data[1][1] = html_print_select(
|
|
|
|
$agents,
|
|
|
|
'id_agents[]',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'width:180px;'
|
|
|
|
);
|
2012-04-10 13:28:36 +02:00
|
|
|
$table->data[1][2] = __('When select agents');
|
|
|
|
$table->data[1][2] .= '<br>';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data[1][2] .= html_print_select(
|
|
|
|
[
|
|
|
|
'common' => __('Show common modules'),
|
|
|
|
'all' => __('Show all modules'),
|
|
|
|
],
|
|
|
|
'modules_selection_mode',
|
|
|
|
'common',
|
|
|
|
false,
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
true
|
|
|
|
);
|
|
|
|
$table->data[1][3] = html_print_select([], 'module[]', '', false, '', '', true, true, false, '', false, 'width:180px;');
|
2010-10-08 13:16:57 +02:00
|
|
|
|
2021-06-04 09:01:16 +02:00
|
|
|
$usr_groups = users_get_groups($config['id_user'], 'LW', true);
|
|
|
|
$filter_groups = '';
|
|
|
|
$filter_groups = implode(',', array_keys($usr_groups));
|
|
|
|
$templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']);
|
2010-05-31 11:22:15 +02:00
|
|
|
$table->data[2][0] = __('Alert template');
|
2019-01-30 16:18:44 +01:00
|
|
|
$table->data[2][1] = html_print_select(
|
|
|
|
index_array($templates, 'id', 'name'),
|
|
|
|
'id_alert_template',
|
|
|
|
$id_alert_template,
|
|
|
|
false,
|
|
|
|
__('Select'),
|
|
|
|
0,
|
|
|
|
true
|
|
|
|
);
|
2010-10-08 13:16:57 +02:00
|
|
|
$table->data[2][2] = '';
|
|
|
|
$table->data[2][3] = '';
|
|
|
|
|
2011-11-10 20:19:38 +01:00
|
|
|
echo '<form method="post" id="form_alerts" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=add_alerts">';
|
2019-01-30 16:18:44 +01:00
|
|
|
html_print_table($table);
|
2010-05-31 11:22:15 +02:00
|
|
|
|
2021-02-12 11:28:13 +01:00
|
|
|
attachActionButton('add', 'add', $table->width);
|
|
|
|
|
2010-05-31 11:22:15 +02:00
|
|
|
echo '</form>';
|
|
|
|
|
2019-02-25 13:02:39 +01:00
|
|
|
// TODO: Change to iu_print_error system.
|
2010-05-31 11:22:15 +02:00
|
|
|
echo '<h3 class="error invisible" id="message"> </h3>';
|
|
|
|
|
2019-02-25 13:02:39 +01:00
|
|
|
// Hack to translate text "none" in PHP to javascript.
|
2021-03-11 15:40:23 +01:00
|
|
|
echo '<span id ="none_text" class="invisible">'.__('None').'</span>';
|
2010-10-08 13:16:57 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
ui_require_jquery_file('form');
|
|
|
|
ui_require_jquery_file('pandora.controls');
|
2010-05-31 11:22:15 +02:00
|
|
|
?>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
/* <![CDATA[ */
|
2015-02-04 11:18:34 +01:00
|
|
|
var limit_parameters_massive = <?php echo $config['limit_parameters_massive']; ?>;
|
|
|
|
|
2010-05-31 11:22:15 +02:00
|
|
|
$(document).ready (function () {
|
2021-02-12 11:28:13 +01:00
|
|
|
/* $("#form_alerts").submit(function() {
|
2019-01-30 16:18:44 +01:00
|
|
|
var get_parameters_count = window.location.href.slice(
|
|
|
|
window.location.href.indexOf('?') + 1).split('&').length;
|
|
|
|
var post_parameters_count = $("#form_alerts").serializeArray().length;
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
var count_parameters =
|
|
|
|
get_parameters_count + post_parameters_count;
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (count_parameters > limit_parameters_massive) {
|
|
|
|
alert("<?php echo __('Unsucessful sending the data, please contact with your administrator or make with less elements.'); ?>");
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-12 11:28:13 +01:00
|
|
|
}); */
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#checkbox-recursion").click(function () {
|
|
|
|
$("#id_group").trigger("change");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_agents").change(agent_changed_by_multiple_agents);
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_group").change (function () {
|
|
|
|
var $select = $("#id_agents").enable ();
|
2021-02-12 11:28:13 +01:00
|
|
|
showSpinner();
|
2019-01-30 16:18:44 +01:00
|
|
|
$("option", $select).remove ();
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
jQuery.post ("ajax.php",
|
|
|
|
{"page" : "godmode/massive/massive_add_alerts",
|
|
|
|
"get_agents" : 1,
|
|
|
|
"id_group" : this.value,
|
|
|
|
"recursion" : $("#checkbox-recursion").is(":checked") ? 1 : 0,
|
2019-02-25 13:02:39 +01:00
|
|
|
// Add a key prefix to avoid auto sorting in js object conversion.
|
2019-01-30 16:18:44 +01:00
|
|
|
"keys_prefix" : "_"
|
|
|
|
},
|
|
|
|
function (data, status) {
|
|
|
|
options = "";
|
|
|
|
jQuery.each (data, function (id, value) {
|
2019-02-25 13:02:39 +01:00
|
|
|
// Remove keys_prefix from the index.
|
2019-01-30 16:18:44 +01:00
|
|
|
id = id.substring(1);
|
|
|
|
options += "<option value=\""+id+"\">"+value+"</option>";
|
|
|
|
});
|
|
|
|
$("#id_agents").append (options);
|
2021-02-12 11:28:13 +01:00
|
|
|
hideSpinner();
|
2019-01-30 16:18:44 +01:00
|
|
|
$select.enable ();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_group").value = "0";
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_group").click (
|
|
|
|
function () {
|
|
|
|
$(this).css ("width", "auto");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_group").blur (function () {
|
|
|
|
$(this).css ("width", "180px");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_agents").click (
|
|
|
|
function () {
|
|
|
|
$(this).css ("width", "auto");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#id_agents").blur (function () {
|
|
|
|
$(this).css ("width", "180px");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#module").click (
|
|
|
|
function () {
|
|
|
|
$(this).css ("width", "auto");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#module").blur (function () {
|
|
|
|
$(this).css ("width", "180px");
|
|
|
|
});
|
2019-02-25 13:02:39 +01:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$("#modules_selection_mode").change (function() {
|
|
|
|
$("#id_agents").trigger('change');
|
|
|
|
});
|
2010-05-31 11:22:15 +02:00
|
|
|
});
|
|
|
|
/* ]]> */
|
|
|
|
</script>
|