bulk operations agents in meta #8290

This commit is contained in:
Daniel Barbero Martin 2022-01-20 16:52:14 +01:00
parent 42d1ccbc13
commit 87bfd08bb9
2 changed files with 497 additions and 403 deletions

View File

@ -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
@ -29,7 +29,7 @@
// Begin. // Begin.
check_login(); check_login();
if (! check_acl($config['id_user'], 0, 'AW')) { if ((bool) check_acl($config['id_user'], 0, 'AW') === false) {
db_pandora_audit( db_pandora_audit(
'ACL Violation', 'ACL Violation',
'Trying to access massive agent deletion section' 'Trying to access massive agent deletion section'
@ -38,10 +38,11 @@ if (! check_acl($config['id_user'], 0, 'AW')) {
return; return;
} }
require_once 'include/functions_agents.php'; require_once $config['homedir'].'/include/functions_agents.php';
require_once 'include/functions_alerts.php'; require_once $config['homedir'].'/include/functions_alerts.php';
require_once 'include/functions_modules.php'; require_once $config['homedir'].'/include/functions_modules.php';
require_once 'include/functions_users.php'; require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_massive_operations.php';
function process_manage_delete($id_agents) function process_manage_delete($id_agents)
@ -99,19 +100,50 @@ $recursion = get_parameter('recursion');
$delete = (bool) get_parameter_post('delete'); $delete = (bool) get_parameter_post('delete');
if ($delete) { if ($delete === true) {
$result = process_manage_delete($id_agents); $result = process_manage_delete($id_agents);
$info = '{"Agent":"'.implode(',', $id_agents).'"}'; $info = '{"Agent":"'.implode(',', $id_agents).'"}';
if ($result) { if ($result === true) {
db_pandora_audit('Massive management', 'Delete agent ', false, false, $info); db_pandora_audit(
'Massive management',
'Delete agent ',
false,
false,
$info
);
} else { } else {
db_pandora_audit('Massive management', 'Fail try to delete agent', false, false, $info); db_pandora_audit(
'Massive management',
'Fail try to delete agent',
false,
false,
$info
);
} }
} }
$groups = users_get_groups();
if (is_metaconsole() === false && is_management_allowed() === false) {
if (\is_metaconsole() === false) {
$url_link = '<a target="_blank" href="'.ui_get_meta_url($url).'">';
$url_link .= __('metaconsole');
$url_link .= '</a>';
} else {
$url_link = __('any node');
}
\ui_print_warning_message(
__(
'This node is configured with centralized mode. All alert calendar information is read only. Go to %s to manage it.',
$url_link
)
);
}
// $groups = users_get_groups();
$table = new stdClass;
$table->id = 'delete_table'; $table->id = 'delete_table';
$table->class = 'databox filters'; $table->class = 'databox filters';
$table->width = '100%'; $table->width = '100%';
@ -177,31 +209,75 @@ $table->data[1][3] = html_print_select(
__('All'), __('All'),
2, 2,
true, true,
false,
true,
'', '',
'', false,
'',
'',
'width:30%;' 'width:30%;'
); );
$table->data[2][0] = __('Agents'); if (is_metaconsole() === true) {
$table->data[2][0] .= '<span id="agent_loading" class="invisible">'; $servers = metaconsole_get_servers();
$table->data[2][0] .= html_print_image('images/spinner.png', true); $server_fields = [];
$table->data[2][0] .= '</span>'; foreach ($servers as $key => $server) {
$table->data[2][1] = html_print_select( $server_fields[$key] = $server['server_name'];
agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)), false, 'none'), }
$table->data[2][2] = __('Node');
$table->data[2][3] = html_print_select(
$server_fields,
'node',
0,
'',
__('All'),
0,
true
);
}
$table->data[3][0] = __('Agents');
$table->data[3][0] .= '<span id="agent_loading" class="invisible">';
$table->data[3][0] .= html_print_image('images/spinner.png', true);
$table->data[3][0] .= '</span>';
$table->data[3][1] = html_print_select(
agents_get_agents_selected(
array_keys(users_get_groups($config['id_user'], 'AW', false))
),
'id_agents[]', 'id_agents[]',
0, 0,
false, false,
'', '',
'', '',
true, true,
true,
true,
'',
false,
'min-width: 500px; max-width: 500px; max-height: 100px',
false,
false,
false,
'',
false,
false,
false,
false,
true,
true,
true true
); );
echo '<form method="post" id="form_agents" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_agents">'; $url = 'index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_agents';
if (is_metaconsole() === true) {
$ulr = 'index.php?sec=advanced&sec2=advanced/massive_operations&tab=massive_agents&pure=0&option=delete_agents';
}
echo '<form method="post" id="form_agents" action="'.$url.'">';
html_print_table($table); html_print_table($table);
if (is_management_allowed() === true) {
if (is_metaconsole() === true || is_management_allowed() === true) {
attachActionButton('delete', 'delete', $table->width); attachActionButton('delete', 'delete', $table->width);
} }
@ -215,22 +291,16 @@ ui_require_jquery_file('pandora.controls');
<script type="text/javascript"> <script type="text/javascript">
$(document).ready (function () { $(document).ready (function () {
var recursion; var recursion;
$("#checkbox-recursion").click(function () { $("#checkbox-recursion").click(function () {
recursion = this.checked ? 1 : 0; recursion = this.checked ? 1 : 0;
$("#id_group").trigger("change"); $("#id_group").trigger("change");
}); });
var disabled; var disabled;
$("#disabled").click(function () { $("#disabled").click(function () {
disabled = this.value;
disabled = this.value; $("#id_group").trigger("change");
$("#id_group").trigger("change");
}); });
$("#id_group").pandoraSelectGroupAgent ({ $("#id_group").pandoraSelectGroupAgent ({
@ -253,7 +323,6 @@ ui_require_jquery_file('pandora.controls');
disabled = 2; disabled = 2;
$("#id_group").trigger("change"); //$("#id_group").trigger("change");
}); });
</script> </script>

View File

@ -1,371 +1,396 @@
/* globals jQuery, js_html_entity_decode */
(function($) { (function($) {
var dummyFunc = function () { var dummyFunc = function() {
return true; return true;
}; };
var _pandoraSelectGroupAgent = function (disabled) { var _pandoraSelectGroupAgent = function(disabled) {
var that = this; var that = this;
this.defaults = { this.defaults = {
agentSelect: "select#id_agent", agentSelect: "select#id_agent",
status_agents: -1, status_agents: -1,
recursion: 0, recursion: 0,
filter_agents_json: "", filter_agents_json: "",
loading: "#agent_loading", loading: "#agent_loading",
callbackBefore: dummyFunc, callbackBefore: dummyFunc,
callbackPre: dummyFunc, callbackPre: dummyFunc,
callbackPost: dummyFunc, callbackPost: dummyFunc,
callbackAfter: dummyFunc, callbackAfter: dummyFunc,
debug: false, debug: false,
disabled: disabled || false, disabled: disabled || false,
privilege: "", privilege: "",
}; serialized: false,
serialized_separator: ""
};
/* public methods */ /* public methods */
this.construct = function (settings) { this.construct = function(settings) {
return this.each (function() { return this.each(function() {
this.config = {}; this.config = {};
this.config = $.extend (this.config, that.defaults, settings); this.config = $.extend(this.config, that.defaults, settings);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change(function() {
var $select = $(config.agentSelect).disable (); var $select = $(config.agentSelect).disable();
$(config.loading).show (); $(config.loading).show();
$("option[value!=0]", $select).remove (); $("option[value!=0]", $select).remove();
if (! config.callbackBefore (this)) if (!config.callbackBefore(this)) return;
return;
if (typeof config.recursion === "function") { var recursion_value;
// Perform this for those cases where recursion parameter is obtained through a function that returns a variable that is set in the lexical environment where this constructor is called. if (typeof config.recursion === "function") {
var recursion_value = config.recursion(); // Perform this for those cases where recursion parameter
// is obtained through a function that returns a variable
// that is set in the lexical environment
// where this constructor is called.
recursion_value = config.recursion();
if (typeof recursion_value === "boolean") { if (typeof recursion_value === "boolean") {
recursion_value = recursion_value ? 1 : 0; recursion_value = recursion_value ? 1 : 0;
} }
} else { } else {
var recursion_value = config.recursion; recursion_value = config.recursion;
} }
var opts = { var opts = {
"page" : "godmode/groups/group_list", page: "godmode/groups/group_list",
"get_group_agents" : 1, get_group_agents: 1,
"id_group" : this.value, id_group: this.value,
"recursion" : recursion_value, recursion: recursion_value,
"filter_agents_json" : config.filter_agents_json, filter_agents_json: config.filter_agents_json,
"disabled" : (typeof config.disabled === "function") disabled:
? (config.disabled()) typeof config.disabled === "function"
: (config.disabled), ? config.disabled()
"status_agents" : config.status_agents, : config.disabled,
"add_alert_bulk_op" : config.add_alert_bulk_op, status_agents: config.status_agents,
"privilege" : config.privilege, add_alert_bulk_op: config.add_alert_bulk_op,
// Add a key prefix to avoid auto sorting in js object conversion privilege: config.privilege,
"keys_prefix" : "_" // Add a key prefix to avoid auto sorting in js object conversion
}; keys_prefix: "_"
if(opts['disabled'] == 1 || opts['disabled'] == 0){ };
jQuery.post ("ajax.php", if (opts["disabled"] == 1 || opts["disabled"] == 0) {
opts, jQuery.post(
function (data, status) { "ajax.php",
jQuery.each (data, function (id, value) { opts,
// Remove keys_prefix from the index function(data) {
id = id.substring(1); jQuery.each(data, function(id, value) {
if (id !== 'keycount') { // Remove keys_prefix from the index.
config.callbackPre (); id = id.substring(1);
option = $("<option></option>") if (id !== "keycount") {
.attr ("value", id) config.callbackPre();
.html (value); var option = $("<option></option>")
config.callbackPost (id, value, option); .attr("value", id)
$(config.agentSelect).append (option); .html(value);
} config.callbackPost(id, value, option);
}); $(config.agentSelect).append(option);
$(config.loading).hide (); }
$select.enable (); });
config.callbackAfter (); $(config.loading).hide();
}, $select.enable();
"json" config.callbackAfter();
); },
} "json"
else{ );
opts['disabled'] = 0; } else {
jQuery.post ("ajax.php", opts["disabled"] = 0;
opts, jQuery.post(
function (data, status) { "ajax.php",
jQuery.each (data, function (id, value) { opts,
// Remove keys_prefix from the index function(data) {
id = id.substring(1); jQuery.each(data, function(id, value) {
if (id !== 'keycount') { // Remove keys_prefix from the index
config.callbackPre (); id = id.substring(1);
option = $("<option></option>") if (id !== "keycount") {
.attr ("value", id) config.callbackPre();
.html (value); var option = $("<option></option>")
config.callbackPost (id, value, option); .attr("value", id)
$(config.agentSelect).append (option); .html(value);
} config.callbackPost(id, value, option);
}); $(config.agentSelect).append(option);
$(config.loading).hide (); }
$select.enable (); });
config.callbackAfter (); $(config.loading).hide();
}, $select.enable();
"json" config.callbackAfter();
); },
opts['disabled'] = 1; "json"
jQuery.post ("ajax.php", );
opts, opts["disabled"] = 1;
function (data, status) { jQuery.post(
jQuery.each (data, function (id, value) { "ajax.php",
// Remove keys_prefix from the index opts,
id = id.substring(1); function(data) {
if (id !== 'keycount') { jQuery.each(data, function(id, value) {
config.callbackPre (); // Remove keys_prefix from the index
option = $("<option></option>") id = id.substring(1);
.attr ("value", id) if (id !== "keycount") {
.html (value); config.callbackPre();
config.callbackPost (id, value, option); var option = $("<option></option>")
$(config.agentSelect).append (option); .attr("value", id)
} .html(value);
}); config.callbackPost(id, value, option);
$(config.loading).hide (); $(config.agentSelect).append(option);
$select.enable (); }
config.callbackAfter (); });
}, $(config.loading).hide();
"json" $select.enable();
); config.callbackAfter();
},
"json"
);
}
});
});
};
};
} $.extend({
pandoraSelectGroupAgent: new _pandoraSelectGroupAgent(),
pandoraSelectGroupAgentDisabled: new _pandoraSelectGroupAgent(true)
});
$.extend({
pandoraSelectAgentModule: new (function() {
this.defaults = {
moduleSelect: "select#id_agent_module",
loading: "#module_loading",
callbackBefore: dummyFunc,
callbackPre: dummyFunc,
callbackPost: dummyFunc,
callbackAfter: dummyFunc,
moduleFilter: {
disabled: 0,
deletePending: 0
},
debug: false
};
/* public methods */
this.construct = function(settings) {
return this.each(function() {
this.config = {};
}); this.config = $.extend(
}); this.config,
}; $.pandoraSelectAgentModule.defaults,
}; settings
);
$.extend ({ var config = this.config;
pandoraSelectGroupAgent: new _pandoraSelectGroupAgent(), $(this).change(function() {
pandoraSelectGroupAgentDisabled: new _pandoraSelectGroupAgent(true), var $select = $(config.moduleSelect).disable();
}); $(config.loading).show();
$("option[value!=0]", $select).remove();
if (!config.callbackBefore(this)) return;
$.extend ({ jQuery.post(
pandoraSelectAgentModule: new function() { "ajax.php",
this.defaults = { {
moduleSelect: "select#id_agent_module", page: "operation/agentes/ver_agente",
loading: "#module_loading", get_agent_modules_json: 1,
callbackBefore: dummyFunc, id_agent: this.value,
callbackPre: dummyFunc, disabled: config.moduleFilter.disabled,
callbackPost: dummyFunc, delete_pending: config.moduleFilter.deletePending
callbackAfter: dummyFunc, },
moduleFilter: { function(data) {
disabled: 0, jQuery.each(data, function(i, value) {
deletePending: 0 config.callbackPre();
}, // Get the selected item from hidden field
debug: false var selected = $(
}; "#hidden-" + config.moduleSelect.attr("id") + "_selected"
).val();
var option;
if (selected == i) {
option = $("<option></option>")
.prop("selected", true)
.attr("value", value["id_agente_modulo"])
.html(js_html_entity_decode(value["nombre"]));
} else {
option = $("<option></option>")
.attr("value", value["id_agente_modulo"])
.html(js_html_entity_decode(value["nombre"]));
}
config.callbackPost(i, value, option);
$(config.moduleSelect).append(option);
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
});
});
};
})()
});
/* public methods */ $.extend({
this.construct = function (settings) { pandoraSelectAgentAlert: new (function() {
return this.each (function() { this.defaults = {
this.config = {}; alertSelect: "select#id_agent_module",
loading: "#alert_loading",
callbackBefore: dummyFunc,
callbackPre: dummyFunc,
callbackPost: dummyFunc,
callbackAfter: dummyFunc,
debug: false
};
this.config = $.extend (this.config, $.pandoraSelectAgentModule.defaults, settings); /* public methods */
this.construct = function(settings) {
return this.each(function() {
this.config = {};
var config = this.config; this.config = $.extend(
$(this).change (function () { this.config,
var $select = $(config.moduleSelect).disable (); $.pandoraSelectAgentAlert.defaults,
$(config.loading).show (); settings
$("option[value!=0]", $select).remove (); );
if (! config.callbackBefore (this))
return;
jQuery.post ('ajax.php', var config = this.config;
{
"page": "operation/agentes/ver_agente",
"get_agent_modules_json": 1,
"id_agent": this.value,
"disabled": config.moduleFilter.disabled,
"delete_pending": config.moduleFilter.deletePending
},
function (data) {
jQuery.each (data, function (i, value) {
config.callbackPre ();
// Get the selected item from hidden field
selected = $('#hidden-'+config.moduleSelect.attr('id')+'_selected').val();
if (selected == i) {
option = $("<option></option>")
.prop ("selected", true)
.attr ("value", value['id_agente_modulo'])
.html (js_html_entity_decode (value['nombre']));
}
else {
option = $("<option></option>")
.attr ("value", value['id_agente_modulo'])
.html (js_html_entity_decode (value['nombre']));
}
config.callbackPost (i, value, option);
$(config.moduleSelect).append (option);
});
$(config.loading).hide ();
$select.enable ();
config.callbackAfter ();
},
"json"
);
});
});
}; $(this).change(function() {
} var $select = $(config.alertSelect).disable();
}); $(config.loading).show();
$("option[value!=0]", $select).remove();
if (!config.callbackBefore(this)) return;
$.extend ({ jQuery.post(
pandoraSelectAgentAlert: new function() { "ajax.php",
this.defaults = { {
alertSelect: "select#id_agent_module", page: "include/ajax/alert_list.ajax",
loading: "#alert_loading", get_agent_alerts_simple: 1,
callbackBefore: dummyFunc, id_agent: this.value
callbackPre: dummyFunc, },
callbackPost: dummyFunc, function(data) {
callbackAfter: dummyFunc, jQuery.each(data, function(i, value) {
debug: false config.callbackPre();
}; var option = $("<option></option>")
.attr("value", value["id"])
.html(js_html_entity_decode(value["template"]["name"]))
.append(
" (" + js_html_entity_decode(value["module_name"]) + ")"
);
config.callbackPost(i, value, option);
$(config.alertSelect).append(option);
});
$(config.loading).hide();
$select.enable();
config.callbackAfter();
},
"json"
);
});
});
};
})()
});
/* public methods */ $.extend({
this.construct = function (settings) { pandoraSelectOS: new (function() {
return this.each (function() { this.defaults = {
this.config = {}; alertSelect: "select#id_os",
spanPreview: "#os_preview",
debug: false
};
this.config = $.extend (this.config, $.pandoraSelectAgentAlert.defaults, settings); /* public methods */
this.construct = function(settings) {
return this.each(function() {
this.config = {};
this.config = $.extend(
this.config,
$.pandoraSelectOS.defaults,
settings
);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change(function() {
var $select = $(config.alertSelect).disable (); var id_os = this.value;
$(config.loading).show ();
$("option[value!=0]", $select).remove ();
if (! config.callbackBefore (this))
return;
jQuery.post ('ajax.php', var home_url;
{"page": "include/ajax/alert_list.ajax", if (typeof settings == "undefined") home_url = "./";
"get_agent_alerts_simple": 1, else home_url = settings.home_url;
"id_agent": this.value
},
function (data) {
jQuery.each (data, function (i, value) {
config.callbackPre ();
option = $("<option></option>")
.attr ("value", value['id'])
.html (js_html_entity_decode (value['template']['name']))
.append (" ("+js_html_entity_decode (value['module_name'])+")");
config.callbackPost (i, value, option);
$(config.alertSelect).append (option);
});
$(config.loading).hide ();
$select.enable ();
config.callbackAfter ();
},
"json"
);
});
});
};
}
});
$.extend ({ $(config.spanPreview).fadeOut("fast", function() {
pandoraSelectOS: new function() { $("img", config.spanPreview).remove();
this.defaults = { jQuery.post(
alertSelect: "select#id_os", home_url + "ajax.php",
spanPreview: "#os_preview", { page: "godmode/setup/setup", get_os_icon: 1, id_os: id_os },
debug: false function(data) {
}; $(config.spanPreview)
.append(data)
.fadeIn("fast");
},
"html"
);
});
});
});
};
})()
});
/* public methods */ $.extend({
this.construct = function (settings) { pandoraSelectGroupIcon: new (function() {
return this.each (function() { this.defaults = {
this.config = {}; alertSelect: "select#id_group",
this.config = $.extend (this.config, $.pandoraSelectOS.defaults, settings); spanPreview: "#group_preview",
debug: false
};
var config = this.config; /* public methods */
this.construct = function(settings) {
return this.each(function() {
this.config = {};
this.config = $.extend(
this.config,
$.pandoraSelectGroupIcon.defaults,
settings
);
$(this).change (function () { var config = this.config;
var id_os = this.value;
var home_url; $(this).change(function() {
if (typeof(settings) == 'undefined') var id_group = this.value;
home_url = './';
else
home_url = settings.home_url;
$(config.spanPreview).fadeOut ('fast', function () { $(config.spanPreview).fadeOut("fast", function() {
$("img", config.spanPreview).remove (); $("img", config.spanPreview).remove();
jQuery.post (home_url + 'ajax.php', jQuery.post(
{"page": "godmode/setup/setup", "ajax.php",
"get_os_icon": 1, {
"id_os": id_os page: "godmode/groups/group_list",
}, get_group_json: 1,
function (data) { id_group: id_group
$(config.spanPreview) },
.append (data) function(data) {
.fadeIn ('fast'); var img = $("<img />").attr(
}, "src",
"html" "images/groups_small/" + data["icon"] + ".png"
); );
}); $(config.spanPreview)
.append(img)
.fadeIn("fast");
},
"json"
);
});
});
});
};
})()
});
}); $.fn.extend({
}); pandoraSelectGroupAgent: $.pandoraSelectGroupAgent.construct,
}; pandoraSelectGroupAgentDisabled:
} $.pandoraSelectGroupAgentDisabled.construct,
}); pandoraSelectAgentModule: $.pandoraSelectAgentModule.construct,
pandoraSelectAgentAlert: $.pandoraSelectAgentAlert.construct,
$.extend ({ pandoraSelectOS: $.pandoraSelectOS.construct,
pandoraSelectGroupIcon: new function() { pandoraSelectGroupIcon: $.pandoraSelectGroupIcon.construct
this.defaults = { });
alertSelect: "select#id_group", })(jQuery);
spanPreview: "#group_preview",
debug: false
};
/* public methods */
this.construct = function (settings) {
return this.each (function() {
this.config = {};
this.config = $.extend (this.config, $.pandoraSelectGroupIcon.defaults, settings);
var config = this.config;
$(this).change (function () {
var id_group = this.value;
$(config.spanPreview).fadeOut ('fast', function () {
$("img", config.spanPreview).remove ();
jQuery.post ('ajax.php',
{"page": "godmode/groups/group_list",
"get_group_json": 1,
"id_group": id_group
},
function (data) {
img = $("<img />").attr ("src", "images/groups_small/"+data["icon"]+".png");
$(config.spanPreview)
.append (img)
.fadeIn ('fast');
},
"json"
);
});
});
});
};
}
});
$.fn.extend({
pandoraSelectGroupAgent: $.pandoraSelectGroupAgent.construct,
pandoraSelectGroupAgentDisabled: $.pandoraSelectGroupAgentDisabled.construct,
pandoraSelectAgentModule: $.pandoraSelectAgentModule.construct,
pandoraSelectAgentAlert: $.pandoraSelectAgentAlert.construct,
pandoraSelectOS: $.pandoraSelectOS.construct,
pandoraSelectGroupIcon: $.pandoraSelectGroupIcon.construct
});
}) (jQuery);