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