mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
bulk operation edit agents add secundary groups pandora_enterprise#2152
This commit is contained in:
parent
867dbc7d5c
commit
a359fd6828
@ -188,7 +188,7 @@ if ($disk_conf_delete) {
|
|||||||
@unlink($filename['conf']);
|
@unlink($filename['conf']);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '<form autocomplete="new-password" name="conf_agent" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente">';
|
echo '<form autocomplete="new-password" name="conf_agent" id="form_agent" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente">';
|
||||||
|
|
||||||
// Custom ID.
|
// Custom ID.
|
||||||
$custom_id_div = '<div class="label_select">';
|
$custom_id_div = '<div class="label_select">';
|
||||||
@ -449,123 +449,14 @@ if (!$new_agent && $alias != '') {
|
|||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
if (enterprise_installed()) {
|
if (enterprise_installed()) {
|
||||||
$secondary_groups_selected = enterprise_hook('agents_get_secondary_groups', [$id_agente]);
|
$adv_secondary_groups_label = '<div class="label_select">';
|
||||||
$adv_secondary_groups_label = '<div class="label_select"><p class="input_label">'.__('Secondary groups').'</p></div>';
|
$adv_secondary_groups_label .= '<p class="input_label">';
|
||||||
$adv_secondary_groups_left = html_print_select_groups(
|
$adv_secondary_groups_label .= __('Secondary groups');
|
||||||
// Id_user.
|
$adv_secondary_groups_label .= '</p>';
|
||||||
// Use the current user to select the groups.
|
$adv_secondary_groups_label .= '</div>';
|
||||||
false,
|
$select_agent_secondary = html_print_select_agent_secondary(
|
||||||
// Privilege.
|
$agent,
|
||||||
// ACL permission.
|
$id_agente
|
||||||
'AR',
|
|
||||||
// ReturnAllGroup.
|
|
||||||
// Not all group.
|
|
||||||
false,
|
|
||||||
// Name.
|
|
||||||
// HTML id.
|
|
||||||
'secondary_groups',
|
|
||||||
// Selected.
|
|
||||||
// No select any by default.
|
|
||||||
'',
|
|
||||||
// Script.
|
|
||||||
// Javascript onChange code.
|
|
||||||
'',
|
|
||||||
// Nothing.
|
|
||||||
// Do not user no selected value.
|
|
||||||
false,
|
|
||||||
// Nothing_value.
|
|
||||||
// Do not use no selected value.
|
|
||||||
0,
|
|
||||||
// Return.
|
|
||||||
// Return HTML (not echo).
|
|
||||||
true,
|
|
||||||
// Multiple.
|
|
||||||
// Multiple selection.
|
|
||||||
true,
|
|
||||||
// Sort.
|
|
||||||
// Sorting by default.
|
|
||||||
true,
|
|
||||||
// Class.
|
|
||||||
// CSS classnames (default).
|
|
||||||
'',
|
|
||||||
// Disabled.
|
|
||||||
// Not disabled (default).
|
|
||||||
false,
|
|
||||||
// Style.
|
|
||||||
// Inline styles (default).
|
|
||||||
'min-width:170px;',
|
|
||||||
// Option_style.
|
|
||||||
// Option style select (default).
|
|
||||||
false,
|
|
||||||
// Id_group.
|
|
||||||
// Do not truncate the users tree (default).
|
|
||||||
false,
|
|
||||||
// Keys_field.
|
|
||||||
// Key to get as value (default).
|
|
||||||
'id_grupo',
|
|
||||||
// Strict_user.
|
|
||||||
// Not strict user (default).
|
|
||||||
false,
|
|
||||||
// Delete_groups.
|
|
||||||
// Do not show the primary group in this selection.
|
|
||||||
array_merge(
|
|
||||||
(empty($secondary_groups_selected['plain']) === false) ? $secondary_groups_selected['plain'] : [],
|
|
||||||
[$agent['id_grupo']]
|
|
||||||
)
|
|
||||||
// Include_groups.
|
|
||||||
// Size.
|
|
||||||
// Simple_multiple_options.
|
|
||||||
);
|
|
||||||
|
|
||||||
$adv_secondary_groups_arrows = html_print_input_image(
|
|
||||||
'add_secondary',
|
|
||||||
'images/darrowright_green.png',
|
|
||||||
1,
|
|
||||||
'',
|
|
||||||
true,
|
|
||||||
[
|
|
||||||
'id' => 'right_autorefreshlist',
|
|
||||||
'title' => __('Add secondary groups'),
|
|
||||||
'onclick' => 'agent_manager_add_secondary_groups(event, '.$id_agente.');',
|
|
||||||
]
|
|
||||||
).html_print_input_image(
|
|
||||||
'remove_secondary',
|
|
||||||
'images/darrowleft_green.png',
|
|
||||||
1,
|
|
||||||
'',
|
|
||||||
true,
|
|
||||||
[
|
|
||||||
'id' => 'left_autorefreshlist',
|
|
||||||
'title' => __('Remove secondary groups'),
|
|
||||||
'onclick' => 'agent_manager_remove_secondary_groups(event, '.$id_agente.');',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$adv_secondary_groups_right .= html_print_select(
|
|
||||||
// Values.
|
|
||||||
$secondary_groups_selected['for_select'],
|
|
||||||
// HTML id.
|
|
||||||
'secondary_groups_selected',
|
|
||||||
// Selected.
|
|
||||||
'',
|
|
||||||
// Javascript onChange code.
|
|
||||||
'',
|
|
||||||
// Nothing selected.
|
|
||||||
false,
|
|
||||||
// Nothing selected.
|
|
||||||
0,
|
|
||||||
// Return HTML (not echo).
|
|
||||||
true,
|
|
||||||
// Multiple selection.
|
|
||||||
true,
|
|
||||||
// Sort.
|
|
||||||
true,
|
|
||||||
// Class.
|
|
||||||
'',
|
|
||||||
// Disabled.
|
|
||||||
false,
|
|
||||||
// Style.
|
|
||||||
'min-width:170px;'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Safe operation mode.
|
// Safe operation mode.
|
||||||
@ -821,19 +712,15 @@ if (enterprise_installed()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// General display distribution.
|
// General display distribution.
|
||||||
$table_adv_options = $advanced_div.$adv_secondary_groups_label.'
|
$table_adv_options = $advanced_div;
|
||||||
<div class="sg_source">
|
$table_adv_options .= $adv_secondary_groups_label;
|
||||||
'.$adv_secondary_groups_left.'
|
$table_adv_options .= $select_agent_secondary;
|
||||||
</div>
|
$table_adv_options .= '</div>';
|
||||||
<div class="secondary_group_arrows">
|
|
||||||
'.$adv_secondary_groups_arrows.'
|
$table_adv_options .= '<div class="agent_av_opt_right" >';
|
||||||
</div>
|
$table_adv_options .= $table_adv_parent;
|
||||||
<div class="sg_target">
|
$table_adv_options .= $table_adv_module_mode;
|
||||||
'.$adv_secondary_groups_right.'
|
$table_adv_options .= $table_adv_cascade;
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="agent_av_opt_right" >
|
|
||||||
'.$table_adv_parent.$table_adv_module_mode.$table_adv_cascade;
|
|
||||||
|
|
||||||
if ($new_agent) {
|
if ($new_agent) {
|
||||||
// If agent is new, show custom id as old style format.
|
// If agent is new, show custom id as old style format.
|
||||||
@ -1110,133 +997,6 @@ ui_require_jquery_file('bgiframe');
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function agent_manager_add_secondary_groups (event, id_agent) {
|
|
||||||
event.preventDefault();
|
|
||||||
var primary_value = $("#grupo").val()
|
|
||||||
// The selected primary value cannot be selected like secondary
|
|
||||||
if ($("#secondary_groups option:selected[value=" + primary_value + "]").length > 0) {
|
|
||||||
alert("<?php echo __('Primary group cannot be secondary too.'); ?>")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// On agent creation PHP will update the secondary groups table (not via AJAX)
|
|
||||||
if (id_agent == 0) {
|
|
||||||
agent_manager_add_secondary_groups_ui();
|
|
||||||
agent_manager_update_hidden_input_secondary();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selected_items = new Array();
|
|
||||||
$("#secondary_groups option:selected").each(function(){
|
|
||||||
selected_items.push($(this).val())
|
|
||||||
})
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
page: "godmode/agentes/agent_manager",
|
|
||||||
id_agent: id_agent,
|
|
||||||
groups: selected_items,
|
|
||||||
add_secondary_groups: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make the AJAX call to update the secondary groups
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "ajax.php",
|
|
||||||
dataType: "html",
|
|
||||||
data: data,
|
|
||||||
success: function (data) {
|
|
||||||
if (data == 1) {
|
|
||||||
agent_manager_add_secondary_groups_ui();
|
|
||||||
} else {
|
|
||||||
console.error("Error in AJAX call to add secondary groups")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
console.error("Fatal error in AJAX call to add secondary groups")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function agent_manager_remove_secondary_groups (event, id_agent) {
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
// On agent creation PHP will update the secondary groups table (not via AJAX)
|
|
||||||
if (id_agent == 0) {
|
|
||||||
agent_manager_remove_secondary_groups_ui();
|
|
||||||
agent_manager_update_hidden_input_secondary();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selected_items = new Array();
|
|
||||||
$("#secondary_groups_selected option:selected").each(function(){
|
|
||||||
selected_items.push($(this).val())
|
|
||||||
})
|
|
||||||
|
|
||||||
var data = {
|
|
||||||
page: "godmode/agentes/agent_manager",
|
|
||||||
id_agent: id_agent,
|
|
||||||
groups: selected_items,
|
|
||||||
remove_secondary_groups: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make the AJAX call to update the secondary groups
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "ajax.php",
|
|
||||||
dataType: "html",
|
|
||||||
data: data,
|
|
||||||
success: function (data) {
|
|
||||||
if (data == 1) {
|
|
||||||
agent_manager_remove_secondary_groups_ui();
|
|
||||||
} else {
|
|
||||||
console.error("Error in AJAX call to add secondary groups")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function (data) {
|
|
||||||
console.error("Fatal error in AJAX call to add secondary groups")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move from left input to right input
|
|
||||||
function agent_manager_add_secondary_groups_ui () {
|
|
||||||
$("#secondary_groups_selected option[value=0]").remove()
|
|
||||||
$("#secondary_groups option:selected").each(function() {
|
|
||||||
$(this).remove().appendTo("#secondary_groups_selected")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move from right input to left input
|
|
||||||
function agent_manager_remove_secondary_groups_ui () {
|
|
||||||
// Remove the groups selected if success
|
|
||||||
$("#secondary_groups_selected option:selected").each(function(){
|
|
||||||
$(this).remove().appendTo("#secondary_groups")
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add none if empty select
|
|
||||||
if ($("#secondary_groups_selected option").length == 0) {
|
|
||||||
$("#secondary_groups_selected").append($('<option>',{
|
|
||||||
value: 0,
|
|
||||||
text: "<?php echo __('None'); ?>"
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function agent_manager_update_hidden_input_secondary () {
|
|
||||||
var groups = [];
|
|
||||||
if(!$('form[name="conf_agent"] #secondary_hidden').length) {
|
|
||||||
$('form[name="conf_agent"]').append(
|
|
||||||
'<input name="secondary_hidden" type="hidden" id="secondary_hidden">'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
var groups = new Array();
|
|
||||||
$("#secondary_groups_selected option").each(function() {
|
|
||||||
groups.push($(this).val())
|
|
||||||
})
|
|
||||||
|
|
||||||
$("#secondary_hidden").val(groups.join(','));
|
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready (function() {
|
$(document).ready (function() {
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||||
*
|
*
|
||||||
* ============================================================================
|
* ============================================================================
|
||||||
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
|
||||||
* Please see http://pandorafms.org for full contribution list
|
* Please see http://pandorafms.org for full contribution list
|
||||||
* This program is free software; you can redistribute it and/or
|
* 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 General Public License
|
||||||
@ -140,6 +140,9 @@ if ($update_agents) {
|
|||||||
$values['safe_mode_module'] = '0';
|
$values['safe_mode_module'] = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$secondary_groups_added = (string) get_parameter('secondary_hidden_added', '');
|
||||||
|
$secondary_groups_removed = (string) get_parameter('secondary_hidden_removed', '');
|
||||||
|
|
||||||
$fields = db_get_all_fields_in_table('tagent_custom_fields');
|
$fields = db_get_all_fields_in_table('tagent_custom_fields');
|
||||||
|
|
||||||
if ($fields === false) {
|
if ($fields === false) {
|
||||||
@ -378,15 +381,40 @@ if ($update_agents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create or Remove the secondary groups.
|
||||||
|
if (empty($secondary_groups_added) === false
|
||||||
|
|| empty($secondary_groups_removed) === false
|
||||||
|
) {
|
||||||
|
$result = enterprise_hook(
|
||||||
|
'agents_update_secondary_groups',
|
||||||
|
[
|
||||||
|
$id_agent,
|
||||||
|
explode(',', $secondary_groups_added),
|
||||||
|
explode(',', $secondary_groups_removed),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$n_edited += (int) $result;
|
$n_edited += (int) $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
db_pandora_audit('Massive management', 'Update agent '.$id_agent, false, false, json_encode($info));
|
db_pandora_audit(
|
||||||
|
'Massive management',
|
||||||
|
'Update agent '.$id_agent,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
json_encode($info)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (isset($id_agent)) {
|
if (isset($id_agent) === true) {
|
||||||
db_pandora_audit('Massive management', 'Try to update agent '.$id_agent, false, false, json_encode($info));
|
db_pandora_audit(
|
||||||
|
'Massive management',
|
||||||
|
'Try to update agent '.$id_agent,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
json_encode($info)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,7 +609,16 @@ $table->data[0][1] .= '<b>'.__('Cascade protection').'</b>'.html_print_select(
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$table->data[0][1] .= ' '.__('Module').' '.html_print_select($modules, 'cascade_protection_module', $cascade_protection_module, '', '', 0, true);
|
$table->data[0][1] .= ' '.__('Module').' ';
|
||||||
|
$table->data[0][1] .= html_print_select(
|
||||||
|
$modules,
|
||||||
|
'cascade_protection_module',
|
||||||
|
$cascade_protection_module,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
0,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
$table->data[1][0] = __('Group');
|
$table->data[1][0] = __('Group');
|
||||||
$table->data[1][1] = '<div class="w290px inline">';
|
$table->data[1][1] = '<div class="w290px inline">';
|
||||||
@ -605,7 +642,17 @@ $table->data[1][1] .= '</div>';
|
|||||||
|
|
||||||
$table->data[2][0] = __('Interval');
|
$table->data[2][0] = __('Interval');
|
||||||
|
|
||||||
$table->data[2][1] = html_print_extended_select_for_time('interval', 0, '', __('No change'), '0', 10, true, 'width: 150px', false);
|
$table->data[2][1] = html_print_extended_select_for_time(
|
||||||
|
'interval',
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
__('No change'),
|
||||||
|
'0',
|
||||||
|
10,
|
||||||
|
true,
|
||||||
|
'width: 150px',
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
$table->data[3][0] = __('OS');
|
$table->data[3][0] = __('OS');
|
||||||
$table->data[3][1] = html_print_select_from_sql(
|
$table->data[3][1] = html_print_select_from_sql(
|
||||||
@ -649,7 +696,14 @@ $table->data[4][1] = html_print_select(
|
|||||||
|
|
||||||
// Description.
|
// Description.
|
||||||
$table->data[5][0] = __('Description');
|
$table->data[5][0] = __('Description');
|
||||||
$table->data[5][1] = html_print_input_text('description', $description, '', 45, 255, true);
|
$table->data[5][1] = html_print_input_text(
|
||||||
|
'description',
|
||||||
|
$description,
|
||||||
|
'',
|
||||||
|
45,
|
||||||
|
255,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
html_print_table($table);
|
html_print_table($table);
|
||||||
unset($table);
|
unset($table);
|
||||||
@ -682,18 +736,117 @@ $table->data = [];
|
|||||||
$table->data[0][0] = __('Custom ID');
|
$table->data[0][0] = __('Custom ID');
|
||||||
$table->data[0][1] = html_print_input_text('custom_id', $custom_id, '', 16, 255, true);
|
$table->data[0][1] = html_print_input_text('custom_id', $custom_id, '', 16, 255, true);
|
||||||
|
|
||||||
|
// Secondary Groups.
|
||||||
|
if (enterprise_installed() === true) {
|
||||||
|
$table->data['secondary_groups_added'][0] = __('Secondary groups added');
|
||||||
|
$table->data['secondary_groups_added'][1] = html_print_select_agent_secondary(
|
||||||
|
$agent,
|
||||||
|
$id_agente,
|
||||||
|
[
|
||||||
|
'container' => true,
|
||||||
|
'id_form' => 'form_agent',
|
||||||
|
'extra_id' => '_added',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$table->data['seconsary_groups_removed'][0] = __('Secondary groups remove');
|
||||||
|
$table->data['seconsary_groups_removed'][1] = html_print_select_agent_secondary(
|
||||||
|
$agent,
|
||||||
|
$id_agente,
|
||||||
|
[
|
||||||
|
'container' => true,
|
||||||
|
'id_form' => 'form_agent',
|
||||||
|
'extra_id' => '_removed',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Learn mode / Normal mode.
|
// Learn mode / Normal mode.
|
||||||
$table->data[1][0] = __('Module definition');
|
$table->data[1][0] = __('Module definition');
|
||||||
$table->data[1][1] = __('No change').' '.html_print_radio_button_extended('mode', -1, '', $mode, false, '', 'class="mrgn_right_40px"', true);
|
$table->data[1][1] = __('No change').' ';
|
||||||
$table->data[1][1] .= __('Learning mode').' '.html_print_radio_button_extended('mode', 1, '', $mode, false, '', 'class="mrgn_right_40px"', true);
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
$table->data[1][1] .= __('Normal mode').' '.html_print_radio_button_extended('mode', 0, '', $mode, false, '', 'class="mrgn_right_40px"', true);
|
'mode',
|
||||||
$table->data[1][1] .= __('Autodisable mode').' '.html_print_radio_button_extended('mode', 2, '', $mode, false, '', 'class="mrgn_right_40px"', true);
|
-1,
|
||||||
|
'',
|
||||||
|
$mode,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$table->data[1][1] .= __('Learning mode').' ';
|
||||||
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
|
'mode',
|
||||||
|
1,
|
||||||
|
'',
|
||||||
|
$mode,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$table->data[1][1] .= __('Normal mode').' ';
|
||||||
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
|
'mode',
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
$mode,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$table->data[1][1] .= __('Autodisable mode').' ';
|
||||||
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
|
'mode',
|
||||||
|
2,
|
||||||
|
'',
|
||||||
|
$mode,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// Status (Disabled / Enabled).
|
// Status (Disabled / Enabled).
|
||||||
$table->data[2][0] = __('Status');
|
$table->data[2][0] = __('Status');
|
||||||
$table->data[2][1] = __('No change').' '.html_print_radio_button_extended('disabled', -1, '', $disabled, false, '', 'class="mrgn_right_40px"', true);
|
$table->data[2][1] = __('No change').' ';
|
||||||
$table->data[2][1] .= __('Disabled').' '.ui_print_help_tip(__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'), true).' '.html_print_radio_button_extended('disabled', 1, '', $disabled, false, '', 'class="mrgn_right_40px"', true);
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
$table->data[2][1] .= __('Active').' '.html_print_radio_button_extended('disabled', 0, '', $disabled, false, '', 'class="mrgn_right_40px"', true);
|
'disabled',
|
||||||
|
-1,
|
||||||
|
'',
|
||||||
|
$disabled,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$table->data[2][1] .= __('Disabled').' ';
|
||||||
|
$table->data[1][1] .= ui_print_help_tip(
|
||||||
|
__('If the remote configuration is enabled, it will also go into standby mode when disabling it.'),
|
||||||
|
true
|
||||||
|
).' ';
|
||||||
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
|
'disabled',
|
||||||
|
1,
|
||||||
|
'',
|
||||||
|
$disabled,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$table->data[2][1] .= __('Active').' ';
|
||||||
|
$table->data[1][1] .= html_print_radio_button_extended(
|
||||||
|
'disabled',
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
$disabled,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
'class="mrgn_right_40px"',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// Remote configuration.
|
// Remote configuration.
|
||||||
$table->data[3][0] = __('Remote configuration');
|
$table->data[3][0] = __('Remote configuration');
|
||||||
@ -868,7 +1021,6 @@ attachActionButton('update_agents', 'update', $table->width);
|
|||||||
echo '</div></form>';
|
echo '</div></form>';
|
||||||
|
|
||||||
ui_require_jquery_file('form');
|
ui_require_jquery_file('form');
|
||||||
|
|
||||||
ui_require_jquery_file('pandora.controls');
|
ui_require_jquery_file('pandora.controls');
|
||||||
ui_require_jquery_file('ajaxqueue');
|
ui_require_jquery_file('ajaxqueue');
|
||||||
ui_require_jquery_file('bgiframe');
|
ui_require_jquery_file('bgiframe');
|
||||||
|
@ -5619,3 +5619,185 @@ function html_print_select_search(
|
|||||||
echo $output;
|
echo $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print html select for agents secondary.
|
||||||
|
*
|
||||||
|
* @param integer $agent Agent.
|
||||||
|
* @param integer $id_agente Id Agent.
|
||||||
|
* @param array $options Array options.
|
||||||
|
*
|
||||||
|
* @return string Html output.
|
||||||
|
*/
|
||||||
|
function html_print_select_agent_secondary($agent, $id_agente, $options=[])
|
||||||
|
{
|
||||||
|
ui_require_css_file('agent_manager');
|
||||||
|
ui_require_javascript_file('pandora_agents');
|
||||||
|
|
||||||
|
if (empty($options) === '' || isset($options['id_form']) === false) {
|
||||||
|
$options['id_form'] = 'form_agent';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($options) === '' || isset($options['id_form']) === false) {
|
||||||
|
$options['extra_id'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$secondary_groups_selected = enterprise_hook(
|
||||||
|
'agents_get_secondary_groups',
|
||||||
|
[$id_agente]
|
||||||
|
);
|
||||||
|
|
||||||
|
$adv_secondary_groups_left = html_print_select_groups(
|
||||||
|
// Id_user.
|
||||||
|
// Use the current user to select the groups.
|
||||||
|
false,
|
||||||
|
// Privilege.
|
||||||
|
// ACL permission.
|
||||||
|
'AR',
|
||||||
|
// ReturnAllGroup.
|
||||||
|
// Not all group.
|
||||||
|
false,
|
||||||
|
// Name.
|
||||||
|
// HTML id.
|
||||||
|
'secondary_groups'.$options['extra_id'],
|
||||||
|
// Selected.
|
||||||
|
// No select any by default.
|
||||||
|
'',
|
||||||
|
// Script.
|
||||||
|
// Javascript onChange code.
|
||||||
|
'',
|
||||||
|
// Nothing.
|
||||||
|
// Do not user no selected value.
|
||||||
|
false,
|
||||||
|
// Nothing_value.
|
||||||
|
// Do not use no selected value.
|
||||||
|
0,
|
||||||
|
// Return.
|
||||||
|
// Return HTML (not echo).
|
||||||
|
true,
|
||||||
|
// Multiple.
|
||||||
|
// Multiple selection.
|
||||||
|
true,
|
||||||
|
// Sort.
|
||||||
|
// Sorting by default.
|
||||||
|
true,
|
||||||
|
// Class.
|
||||||
|
// CSS classnames (default).
|
||||||
|
'',
|
||||||
|
// Disabled.
|
||||||
|
// Not disabled (default).
|
||||||
|
false,
|
||||||
|
// Style.
|
||||||
|
// Inline styles (default).
|
||||||
|
'min-width:170px;',
|
||||||
|
// Option_style.
|
||||||
|
// Option style select (default).
|
||||||
|
false,
|
||||||
|
// Id_group.
|
||||||
|
// Do not truncate the users tree (default).
|
||||||
|
false,
|
||||||
|
// Keys_field.
|
||||||
|
// Key to get as value (default).
|
||||||
|
'id_grupo',
|
||||||
|
// Strict_user.
|
||||||
|
// Not strict user (default).
|
||||||
|
false,
|
||||||
|
// Delete_groups.
|
||||||
|
// Do not show the primary group in this selection.
|
||||||
|
array_merge(
|
||||||
|
(empty($secondary_groups_selected['plain']) === false) ? $secondary_groups_selected['plain'] : [],
|
||||||
|
[$agent['id_grupo']]
|
||||||
|
)
|
||||||
|
// Include_groups.
|
||||||
|
// Size.
|
||||||
|
// Simple_multiple_options.
|
||||||
|
);
|
||||||
|
|
||||||
|
$dictionary = base64_encode(
|
||||||
|
json_encode(
|
||||||
|
[
|
||||||
|
'primary_group' => __('Primary group cannot be secondary too.'),
|
||||||
|
'strNone' => __('None'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$adv_secondary_groups_arrows = html_print_input_image(
|
||||||
|
'add_secondary',
|
||||||
|
'images/darrowright_green.png',
|
||||||
|
1,
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
[
|
||||||
|
'id' => 'right_autorefreshlist'.$options['extra_id'],
|
||||||
|
'title' => __('Add secondary groups'),
|
||||||
|
'onclick' => 'agent_manager_add_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$adv_secondary_groups_arrows .= html_print_input_image(
|
||||||
|
'remove_secondary',
|
||||||
|
'images/darrowleft_green.png',
|
||||||
|
1,
|
||||||
|
'',
|
||||||
|
true,
|
||||||
|
[
|
||||||
|
'id' => 'left_autorefreshlist'.$options['extra_id'],
|
||||||
|
'title' => __('Remove secondary groups'),
|
||||||
|
'onclick' => 'agent_manager_remove_secondary_groups(event, '.$id_agente.',\''.$options['extra_id'].'\', \''.$options['id_form'].'\', \''.$dictionary.'\');',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$adv_secondary_groups_right .= html_print_select(
|
||||||
|
// Values.
|
||||||
|
$secondary_groups_selected['for_select'],
|
||||||
|
// HTML id.
|
||||||
|
'secondary_groups_selected'.$options['extra_id'],
|
||||||
|
// Selected.
|
||||||
|
'',
|
||||||
|
// Javascript onChange code.
|
||||||
|
'',
|
||||||
|
// Nothing selected.
|
||||||
|
false,
|
||||||
|
// Nothing selected.
|
||||||
|
0,
|
||||||
|
// Return HTML (not echo).
|
||||||
|
true,
|
||||||
|
// Multiple selection.
|
||||||
|
true,
|
||||||
|
// Sort.
|
||||||
|
true,
|
||||||
|
// Class.
|
||||||
|
'',
|
||||||
|
// Disabled.
|
||||||
|
false,
|
||||||
|
// Style.
|
||||||
|
'min-width:170px;'
|
||||||
|
);
|
||||||
|
|
||||||
|
$output = '';
|
||||||
|
if (isset($options['container']) === true
|
||||||
|
&& $options['container'] === true
|
||||||
|
) {
|
||||||
|
$output = '<div class="secondary_groups_list">';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output .= '<div class="sg_source">';
|
||||||
|
$output .= $adv_secondary_groups_left;
|
||||||
|
$output .= '</div>';
|
||||||
|
$output .= '<div class="secondary_group_arrows">';
|
||||||
|
$output .= $adv_secondary_groups_arrows;
|
||||||
|
$output .= '</div>';
|
||||||
|
$output .= '<div class="sg_target">';
|
||||||
|
$output .= $adv_secondary_groups_right;
|
||||||
|
$output .= '</div>';
|
||||||
|
|
||||||
|
if (isset($options['container']) === true
|
||||||
|
&& $options['container'] === true
|
||||||
|
) {
|
||||||
|
$output .= '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
169
pandora_console/include/javascript/pandora_agents.js
Normal file
169
pandora_console/include/javascript/pandora_agents.js
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/* globals $ */
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function agent_manager_add_secondary_groups(
|
||||||
|
event,
|
||||||
|
id_agent,
|
||||||
|
extra_id,
|
||||||
|
id_form,
|
||||||
|
dictionary
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
var primary_value = $("#grupo").val();
|
||||||
|
dictionary = JSON.parse(atob(dictionary));
|
||||||
|
// The selected primary value cannot be selected like secondary.
|
||||||
|
if (
|
||||||
|
$(
|
||||||
|
"#secondary_groups" +
|
||||||
|
extra_id +
|
||||||
|
" option:selected[value=" +
|
||||||
|
primary_value +
|
||||||
|
"]"
|
||||||
|
).length > 0
|
||||||
|
) {
|
||||||
|
alert(dictionary.primary_group);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On agent creation PHP will update the secondary groups table (not via AJAX).
|
||||||
|
if (id_agent == 0) {
|
||||||
|
agent_manager_add_secondary_groups_ui(extra_id);
|
||||||
|
agent_manager_update_hidden_input_secondary(id_form, extra_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected_items = new Array();
|
||||||
|
$("#secondary_groups" + extra_id + " option:selected").each(function() {
|
||||||
|
selected_items.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
page: "godmode/agentes/agent_manager",
|
||||||
|
id_agent: id_agent,
|
||||||
|
groups: selected_items,
|
||||||
|
add_secondary_groups: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make the AJAX call to update the secondary groups.
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "ajax.php",
|
||||||
|
dataType: "html",
|
||||||
|
data: data,
|
||||||
|
success: function(data) {
|
||||||
|
if (data == 1) {
|
||||||
|
agent_manager_add_secondary_groups_ui(extra_id);
|
||||||
|
} else {
|
||||||
|
console.error("Error in AJAX call to add secondary groups");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error(
|
||||||
|
"Fatal error in AJAX call to add secondary groups: " + data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function agent_manager_remove_secondary_groups(
|
||||||
|
event,
|
||||||
|
id_agent,
|
||||||
|
extra_id,
|
||||||
|
id_form,
|
||||||
|
dictionary
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
dictionary = JSON.parse(atob(dictionary));
|
||||||
|
// On agent creation PHP will update the secondary groups table (not via AJAX).
|
||||||
|
if (id_agent == 0) {
|
||||||
|
agent_manager_remove_secondary_groups_ui(dictionary.strNone, extra_id);
|
||||||
|
agent_manager_update_hidden_input_secondary(id_form, extra_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected_items = new Array();
|
||||||
|
$("#secondary_groups_selected" + extra_id + " option:selected").each(
|
||||||
|
function() {
|
||||||
|
selected_items.push($(this).val());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
page: "godmode/agentes/agent_manager",
|
||||||
|
id_agent: id_agent,
|
||||||
|
groups: selected_items,
|
||||||
|
remove_secondary_groups: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make the AJAX call to update the secondary groups.
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "ajax.php",
|
||||||
|
dataType: "html",
|
||||||
|
data: data,
|
||||||
|
success: function(data) {
|
||||||
|
if (data == 1) {
|
||||||
|
agent_manager_remove_secondary_groups_ui(dictionary.strNone, extra_id);
|
||||||
|
} else {
|
||||||
|
console.error("Error in AJAX call to add secondary groups");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
console.error(
|
||||||
|
"Fatal error in AJAX call to add secondary groups: " + data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move from left input to right input.
|
||||||
|
function agent_manager_add_secondary_groups_ui(extra_id) {
|
||||||
|
$("#secondary_groups_selected" + extra_id + " option[value=0]").remove();
|
||||||
|
$("#secondary_groups" + extra_id + " option:selected").each(function() {
|
||||||
|
$(this)
|
||||||
|
.remove()
|
||||||
|
.appendTo("#secondary_groups_selected" + extra_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move from right input to left input.
|
||||||
|
function agent_manager_remove_secondary_groups_ui(strNone, extra_id) {
|
||||||
|
// Remove the groups selected if success.
|
||||||
|
$("#secondary_groups_selected" + extra_id + " option:selected").each(
|
||||||
|
function() {
|
||||||
|
$(this)
|
||||||
|
.remove()
|
||||||
|
.appendTo("#secondary_groups" + extra_id);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add none if empty select.
|
||||||
|
if ($("#secondary_groups_selected" + extra_id + " option").length == 0) {
|
||||||
|
$("#secondary_groups_selected" + extra_id).append(
|
||||||
|
$("<option>", {
|
||||||
|
value: 0,
|
||||||
|
text: strNone
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function agent_manager_update_hidden_input_secondary(id_form, extra_id) {
|
||||||
|
var groups = [];
|
||||||
|
if (!$("#" + id_form + " #secondary_hidden" + extra_id).length) {
|
||||||
|
$("#" + id_form).append(
|
||||||
|
'<input name="secondary_hidden' +
|
||||||
|
extra_id +
|
||||||
|
'" type="hidden" id="secondary_hidden' +
|
||||||
|
extra_id +
|
||||||
|
'">'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#secondary_groups_selected" + extra_id + " option").each(function() {
|
||||||
|
groups.push($(this).val());
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#secondary_hidden" + extra_id).val(groups.join(","));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user