mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
bulk operations agents in meta #8290
This commit is contained in:
parent
4e7afa7d0b
commit
7c2000c34d
@ -113,6 +113,9 @@ if (is_ajax() === true) {
|
|||||||
'|'
|
'|'
|
||||||
);
|
);
|
||||||
$force_serialized = (bool) get_parameter('force_serialized', false);
|
$force_serialized = (bool) get_parameter('force_serialized', false);
|
||||||
|
$nodes = (array) get_parameter('nodes', []);
|
||||||
|
|
||||||
|
hd($nodes, true);
|
||||||
|
|
||||||
if ((bool) check_acl($config['id_user'], $id_group, 'AR') === false) {
|
if ((bool) check_acl($config['id_user'], $id_group, 'AR') === false) {
|
||||||
db_pandora_audit(
|
db_pandora_audit(
|
||||||
@ -154,6 +157,10 @@ if (is_ajax() === true) {
|
|||||||
$filter[$_sql_post] = '1';
|
$filter[$_sql_post] = '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_metaconsole() === true && empty($nodes) === false) {
|
||||||
|
$filter['id_server'] = $nodes;
|
||||||
|
}
|
||||||
|
|
||||||
$id_groups_get_agents = $id_group;
|
$id_groups_get_agents = $id_group;
|
||||||
if ($id_group == 0 && $privilege != '') {
|
if ($id_group == 0 && $privilege != '') {
|
||||||
$groups = users_get_groups($config['id_user'], $privilege, false);
|
$groups = users_get_groups($config['id_user'], $privilege, false);
|
||||||
|
@ -45,24 +45,27 @@ require_once $config['homedir'].'/include/functions_users.php';
|
|||||||
require_once $config['homedir'].'/include/functions_massive_operations.php';
|
require_once $config['homedir'].'/include/functions_massive_operations.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk operations Delete.
|
||||||
|
*
|
||||||
|
* @param array $id_agents Agents to delete.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
function process_manage_delete($id_agents)
|
function process_manage_delete($id_agents)
|
||||||
{
|
{
|
||||||
if (empty($id_agents)) {
|
if (empty($id_agents) === true) {
|
||||||
ui_print_error_message(__('No agents selected'));
|
ui_print_error_message(__('No agents selected'));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id_agents = (array) $id_agents;
|
$id_agents = (array) $id_agents;
|
||||||
|
|
||||||
$copy_modules = (bool) get_parameter('copy_modules');
|
|
||||||
$copy_alerts = (bool) get_parameter('copy_alerts');
|
|
||||||
|
|
||||||
$error = false;
|
|
||||||
$count_deleted = 0;
|
$count_deleted = 0;
|
||||||
$agent_id_restore = 0;
|
$agent_id_restore = 0;
|
||||||
foreach ($id_agents as $id_agent) {
|
foreach ($id_agents as $id_agent) {
|
||||||
$success = agents_delete_agent($id_agent);
|
$success = agents_delete_agent($id_agent);
|
||||||
if (! $success) {
|
if (!$success) {
|
||||||
$agent_id_restore = $id_agent;
|
$agent_id_restore = $id_agent;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -70,7 +73,7 @@ function process_manage_delete($id_agents)
|
|||||||
$count_deleted++;
|
$count_deleted++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $success) {
|
if (!$success) {
|
||||||
ui_print_error_message(
|
ui_print_error_message(
|
||||||
sprintf(
|
sprintf(
|
||||||
__('There was an error deleting the agent, the operation has been cancelled Could not delete agent %s'),
|
__('There was an error deleting the agent, the operation has been cancelled Could not delete agent %s'),
|
||||||
@ -97,7 +100,6 @@ function process_manage_delete($id_agents)
|
|||||||
$id_group = (int) get_parameter('id_group');
|
$id_group = (int) get_parameter('id_group');
|
||||||
$id_agents = get_parameter('id_agents');
|
$id_agents = get_parameter('id_agents');
|
||||||
$recursion = get_parameter('recursion');
|
$recursion = get_parameter('recursion');
|
||||||
|
|
||||||
$delete = (bool) get_parameter_post('delete');
|
$delete = (bool) get_parameter_post('delete');
|
||||||
|
|
||||||
if ($delete === true) {
|
if ($delete === true) {
|
||||||
@ -135,14 +137,12 @@ if (is_metaconsole() === false && is_management_allowed() === false) {
|
|||||||
|
|
||||||
\ui_print_warning_message(
|
\ui_print_warning_message(
|
||||||
__(
|
__(
|
||||||
'This node is configured with centralized mode. All alert calendar information is read only. Go to %s to manage it.',
|
'This node is configured with centralized mode. Bulk operations is read only. Go to %s to manage it.',
|
||||||
$url_link
|
$url_link
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $groups = users_get_groups();
|
|
||||||
$table = new stdClass;
|
$table = new stdClass;
|
||||||
$table->id = 'delete_table';
|
$table->id = 'delete_table';
|
||||||
$table->class = 'databox filters';
|
$table->class = 'databox filters';
|
||||||
@ -226,24 +226,44 @@ if (is_metaconsole() === true) {
|
|||||||
$table->data[2][2] = __('Node');
|
$table->data[2][2] = __('Node');
|
||||||
$table->data[2][3] = html_print_select(
|
$table->data[2][3] = html_print_select(
|
||||||
$server_fields,
|
$server_fields,
|
||||||
'node',
|
'nodes[]',
|
||||||
0,
|
0,
|
||||||
|
false,
|
||||||
'',
|
'',
|
||||||
__('All'),
|
'',
|
||||||
0,
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
'min-width: 500px; max-width: 500px; max-height: 100px',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
'',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$table->data[3][0] = __('Agents');
|
$table->data[3][0] = __('Agents');
|
||||||
$table->data[3][0] .= '<span id="agent_loading" class="invisible">';
|
$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] .= html_print_image('images/spinner.png', true);
|
||||||
$table->data[3][0] .= '</span>';
|
$table->data[3][0] .= '</span>';
|
||||||
$table->data[3][1] = html_print_select(
|
$table->data[3][1] = html_print_select(
|
||||||
agents_get_agents_selected(
|
agents_get_group_agents(
|
||||||
array_keys(users_get_groups($config['id_user'], 'AW', false))
|
array_keys(users_get_groups($config['id_user'], 'AW', false)),
|
||||||
|
false,
|
||||||
|
'none',
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
is_metaconsole(),
|
||||||
|
'|'
|
||||||
),
|
),
|
||||||
'id_agents[]',
|
'id_agents[]',
|
||||||
0,
|
0,
|
||||||
@ -291,6 +311,10 @@ ui_require_jquery_file('pandora.controls');
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready (function () {
|
$(document).ready (function () {
|
||||||
|
// Check Metaconsole.
|
||||||
|
var metaconsole = '<?php echo (is_metaconsole() === true) ? 1 : 0; ?>';
|
||||||
|
|
||||||
|
// Listeners.
|
||||||
var recursion;
|
var recursion;
|
||||||
$("#checkbox-recursion").click(function () {
|
$("#checkbox-recursion").click(function () {
|
||||||
recursion = this.checked ? 1 : 0;
|
recursion = this.checked ? 1 : 0;
|
||||||
@ -298,12 +322,23 @@ ui_require_jquery_file('pandora.controls');
|
|||||||
});
|
});
|
||||||
|
|
||||||
var disabled;
|
var disabled;
|
||||||
$("#disabled").click(function () {
|
$("#disabled").change(function () {
|
||||||
disabled = this.value;
|
disabled = this.value;
|
||||||
$("#id_group").trigger("change");
|
$("#id_group").trigger("change");
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#id_group").pandoraSelectGroupAgent ({
|
var nodes;
|
||||||
|
$("#nodes").change(function () {
|
||||||
|
nodes = $("#nodes").val();
|
||||||
|
$("#id_group").trigger("change");
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#status_agents").change(function() {
|
||||||
|
$("#id_group").trigger("change");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Build data.
|
||||||
|
var data = {
|
||||||
status_agents: function () {
|
status_agents: function () {
|
||||||
return $("#status_agents").val();
|
return $("#status_agents").val();
|
||||||
},
|
},
|
||||||
@ -314,15 +349,18 @@ ui_require_jquery_file('pandora.controls');
|
|||||||
},
|
},
|
||||||
disabled: function() {
|
disabled: function() {
|
||||||
return disabled;
|
return disabled;
|
||||||
}
|
},
|
||||||
});
|
}
|
||||||
|
|
||||||
$("#status_agents").change(function() {
|
if (metaconsole == 1) {
|
||||||
$("#id_group").trigger("change");
|
data.serialized = true;
|
||||||
});
|
data.serialized_separator = '|';
|
||||||
|
data.nodes = function() {
|
||||||
|
return nodes;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
disabled = 2;
|
// Change agents.
|
||||||
|
$("#id_group").pandoraSelectGroupAgent(data);
|
||||||
//$("#id_group").trigger("change");
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -56,7 +56,7 @@ if (is_ajax()) {
|
|||||||
$name = agents_get_name($id_agent);
|
$name = agents_get_name($id_agent);
|
||||||
$agent_md5 = md5($name);
|
$agent_md5 = md5($name);
|
||||||
if (file_exists($config['remote_config'].'/md5/'.$agent_md5.'.md5')) {
|
if (file_exists($config['remote_config'].'/md5/'.$agent_md5.'.md5')) {
|
||||||
$cont ++;
|
$cont++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,12 +468,13 @@ $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');
|
$table->data[2][0] = __('Agents');
|
||||||
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
|
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
|
||||||
$table->data[2][0] .= html_print_image('images/spinner.png', true);
|
$table->data[2][0] .= html_print_image('images/spinner.png', true);
|
||||||
@ -942,12 +943,9 @@ $(document).ready (function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var disabled;
|
var disabled;
|
||||||
|
$("#disabled").change(function () {
|
||||||
$("#disabled").click(function () {
|
disabled = this.value;
|
||||||
|
$("#id_group").trigger("change");
|
||||||
disabled = this.value;
|
|
||||||
|
|
||||||
$("#id_group").trigger("change");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#id_agents').on('change', function() {
|
$('#id_agents').on('change', function() {
|
||||||
|
@ -1217,6 +1217,15 @@ function agents_get_group_agents(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((isset($search['disabled']) === true
|
||||||
|
&& $search['disabled'] === 2)
|
||||||
|
|| (isset($filter['disabled']) === true
|
||||||
|
&& $filter['disabled'] === 2)
|
||||||
|
) {
|
||||||
|
unset($search['disabled']);
|
||||||
|
unset($filter['disabled']);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($search['all_agents'])) {
|
if (isset($search['all_agents'])) {
|
||||||
unset($search['all_agents']);
|
unset($search['all_agents']);
|
||||||
}
|
}
|
||||||
@ -1309,17 +1318,20 @@ function agents_get_group_agents(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_metaconsole() && isset($search['id_server'])) {
|
if (is_metaconsole() === true
|
||||||
$filter['id_tmetaconsole_setup'] = $search['id_server'];
|
&& isset($search['id_server']) === true
|
||||||
|
&& empty($search['id_server']) === false
|
||||||
|
) {
|
||||||
|
$filter['ta.id_tmetaconsole_setup'] = $search['id_server'];
|
||||||
|
|
||||||
if ($filter['id_tmetaconsole_setup'] == 0) {
|
if ($filter['id_tmetaconsole_setup'] == 0) {
|
||||||
// All nodes.
|
// All nodes.
|
||||||
unset($filter['id_tmetaconsole_setup']);
|
unset($filter['id_tmetaconsole_setup']);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($search['id_server']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unset($search['id_server']);
|
||||||
|
|
||||||
if (!$add_alert_bulk_op) {
|
if (!$add_alert_bulk_op) {
|
||||||
// Add the rest of the filter from the search array.
|
// Add the rest of the filter from the search array.
|
||||||
foreach ($search as $key => $value) {
|
foreach ($search as $key => $value) {
|
||||||
@ -1332,7 +1344,7 @@ function agents_get_group_agents(
|
|||||||
|
|
||||||
$filter['order'] = 'alias';
|
$filter['order'] = 'alias';
|
||||||
|
|
||||||
if (is_metaconsole()) {
|
if (is_metaconsole() === true) {
|
||||||
$table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
|
$table_name = 'tmetaconsole_agent ta LEFT JOIN tmetaconsole_agent_secondary_group tasg ON ta.id_agente = tasg.id_agent';
|
||||||
|
|
||||||
if ($meta_fields === true) {
|
if ($meta_fields === true) {
|
||||||
@ -1357,6 +1369,10 @@ function agents_get_group_agents(
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hd($table_name, true);
|
||||||
|
hd($filter, true);
|
||||||
|
hd($fields, true);
|
||||||
|
|
||||||
$result = db_get_all_rows_filter($table_name, $filter, $fields);
|
$result = db_get_all_rows_filter($table_name, $filter, $fields);
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
disabled: disabled || false,
|
disabled: disabled || false,
|
||||||
privilege: "",
|
privilege: "",
|
||||||
serialized: false,
|
serialized: false,
|
||||||
serialized_separator: ""
|
serialized_separator: "",
|
||||||
|
nodes: []
|
||||||
};
|
};
|
||||||
|
|
||||||
/* public methods */
|
/* public methods */
|
||||||
@ -67,79 +68,39 @@
|
|||||||
add_alert_bulk_op: config.add_alert_bulk_op,
|
add_alert_bulk_op: config.add_alert_bulk_op,
|
||||||
privilege: config.privilege,
|
privilege: config.privilege,
|
||||||
// Add a key prefix to avoid auto sorting in js object conversion
|
// Add a key prefix to avoid auto sorting in js object conversion
|
||||||
keys_prefix: "_"
|
keys_prefix: "_",
|
||||||
|
serialized: config.serialized,
|
||||||
|
serialized_separator: config.serialized_separator,
|
||||||
|
nodes:
|
||||||
|
typeof config.nodes === "function"
|
||||||
|
? config.nodes()
|
||||||
|
: config.disabled
|
||||||
};
|
};
|
||||||
if (opts["disabled"] == 1 || opts["disabled"] == 0) {
|
|
||||||
jQuery.post(
|
console.log(opts);
|
||||||
"ajax.php",
|
|
||||||
opts,
|
jQuery.post(
|
||||||
function(data) {
|
"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);
|
||||||
var 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();
|
||||||
);
|
},
|
||||||
} else {
|
"json"
|
||||||
opts["disabled"] = 0;
|
);
|
||||||
jQuery.post(
|
|
||||||
"ajax.php",
|
|
||||||
opts,
|
|
||||||
function(data) {
|
|
||||||
jQuery.each(data, function(id, value) {
|
|
||||||
// Remove keys_prefix from the index
|
|
||||||
id = id.substring(1);
|
|
||||||
if (id !== "keycount") {
|
|
||||||
config.callbackPre();
|
|
||||||
var option = $("<option></option>")
|
|
||||||
.attr("value", id)
|
|
||||||
.html(value);
|
|
||||||
config.callbackPost(id, value, option);
|
|
||||||
$(config.agentSelect).append(option);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$(config.loading).hide();
|
|
||||||
$select.enable();
|
|
||||||
config.callbackAfter();
|
|
||||||
},
|
|
||||||
"json"
|
|
||||||
);
|
|
||||||
opts["disabled"] = 1;
|
|
||||||
jQuery.post(
|
|
||||||
"ajax.php",
|
|
||||||
opts,
|
|
||||||
function(data) {
|
|
||||||
jQuery.each(data, function(id, value) {
|
|
||||||
// Remove keys_prefix from the index
|
|
||||||
id = id.substring(1);
|
|
||||||
if (id !== "keycount") {
|
|
||||||
config.callbackPre();
|
|
||||||
var option = $("<option></option>")
|
|
||||||
.attr("value", id)
|
|
||||||
.html(value);
|
|
||||||
config.callbackPost(id, value, option);
|
|
||||||
$(config.agentSelect).append(option);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$(config.loading).hide();
|
|
||||||
$select.enable();
|
|
||||||
config.callbackAfter();
|
|
||||||
},
|
|
||||||
"json"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user