reset-map fixed

Former-commit-id: b89cf24a88f5e190cae0d2e55a55a8d988d94458
This commit is contained in:
fbsanchez 2019-03-22 18:27:12 +01:00
parent 091e2db13a
commit face622e9e
3 changed files with 62 additions and 46 deletions

View File

@ -753,9 +753,25 @@ class NetworkMap
// Empty map returns no data. // Empty map returns no data.
$nodes = []; $nodes = [];
} else { } else {
if ($this->mapOptions['map_filter']['dont_show_subgroups'] == 'true') {
// Show only current selected group.
$filter['id_grupo'] = $this->idGroup;
} else {
// Show current group and children.
$childrens = groups_get_childrens($this->idGroup, null, true);
if (!empty($childrens)) {
$childrens = array_keys($childrens);
$filter['id_grupo'] = $childrens;
$filter['id_grupo'][] = $this->idGroup;
} else {
$filter['id_grupo'] = $this->idGroup;
}
}
// Group map. // Group map.
$nodes = agents_get_agents( $nodes = agents_get_agents(
['id_grupo' => $this->idGroup], $filter,
['*'], ['*'],
'AR', 'AR',
[ [
@ -764,14 +780,18 @@ class NetworkMap
] ]
); );
// Remap ids. if (is_array($nodes)) {
$nodes = array_reduce( // Remap ids.
$nodes, $nodes = array_reduce(
function ($carry, $item) { $nodes,
$carry[$item['id_agente']] = $item; function ($carry, $item) {
return $carry; $carry[$item['id_agente']] = $item;
} return $carry;
); }
);
} else {
$nodes = [];
}
} }
return $nodes; return $nodes;

View File

@ -434,15 +434,15 @@ function agents_get_agents(
$filter_nogroup = $filter; $filter_nogroup = $filter;
// Get user groups // Get user groups
$groups = array_keys(users_get_groups($config['id_user'], $access, false)); $groups = array_keys(users_get_groups($config['id_user'], $access, true));
// If no group specified, get all user groups // If no group specified, get all user groups
if (empty($filter['id_grupo'])) { if (isset($filter['id_grupo']) === false) {
$all_groups = true; $all_groups = true;
$filter['id_grupo'] = $groups; $filter['id_grupo'] = $groups;
} else if (! is_array($filter['id_grupo'])) { } else if (! is_array($filter['id_grupo'])) {
$all_groups = false; $all_groups = false;
// If group is specified but not allowed, return false // If group is specified but not allowed, return false.
if (! in_array($filter['id_grupo'], $groups)) { if (! in_array($filter['id_grupo'], $groups)) {
return false; return false;
} }
@ -466,11 +466,6 @@ function agents_get_agents(
$filter['id_group'] = $filter['id_grupo']; $filter['id_group'] = $filter['id_grupo'];
if (in_array(0, $filter['id_grupo'])) {
unset($filter['id_grupo']);
unset($filter['id_group']);
}
if (!is_array($fields)) { if (!is_array($fields)) {
$fields = []; $fields = [];
$fields[0] = 'id_agente'; $fields[0] = 'id_agente';
@ -578,6 +573,7 @@ function agents_get_agents(
} }
$sql = sprintf('%s %s', $sql, $limit_sql); $sql = sprintf('%s %s', $sql, $limit_sql);
if ($return) { if ($return) {
return $sql; return $sql;
} else { } else {

View File

@ -2551,28 +2551,29 @@ function proceed_to_restart_map() {
text: ok_button, text: ok_button,
click: function() { click: function() {
$(this).dialog("close"); $(this).dialog("close");
var new_elements = []; var data = {
new_elements[0] = $("#text-name").val(); params: {
new_elements[1] = $("#id_group").val(); name: $("#text-name").val(),
new_elements[2] = $("#text-node_radius").val(); id_group: $("#id_group").val(),
new_elements[3] = $("#textarea_description").val(); node_radius: $("#text-node_radius").val(),
new_elements[4] = $("input[name=source]:checked").val(); description: $("#textarea_description").val(),
if (new_elements[4] == "group") { source: $("input[name=source]:checked").val(),
new_elements[5] = $("#checkbox-dont_show_subgroups").is(":checked"); dont_show_subgroups: $("#checkbox-dont_show_subgroups").is(
} else if (new_elements[4] == "recon_task") { ":checked"
new_elements[5] = $("#recon_task_id").val(); ),
} else { recon_task_id: $("#recon_task_id").val(),
new_elements[5] = $("#text-ip_mask").val(); ip_mask: $("#text-ip_mask").val(),
} generation_method: $("#method").val(),
new_elements[6] = $("#method").val(); pos_x: $("#text-pos_x").val(),
new_elements[7] = $("#text-pos_x").val(); pos_y: $("#text-pos_y").val(),
new_elements[8] = $("#text-pos_y").val(); scale_z: $("#text-scale_z").val(),
new_elements[9] = $("#text-scale_z").val(); node_sep: $("#text-node_sep").val(),
new_elements[10] = $("#text-node_sep").val(); mindist: $("#text-mindist").val(),
new_elements[11] = $("#text-mindist").val(); rank_sep: $("#text-rank_sep").val(),
new_elements[12] = $("#text-rank_sep").val(); kval: $("#text-kval").val()
new_elements[13] = $("#text-kval").val(); }
reset_map_from_form(new_elements); };
reset_map_from_form(data);
} }
}, },
{ {
@ -2601,17 +2602,16 @@ function proceed_to_restart_map() {
} }
function reset_map_from_form(new_elements) { function reset_map_from_form(new_elements) {
var params = []; var data = new_elements;
params.push("reset_map=1"); data.map_id = networkmap_id;
params.push("map_id=" + networkmap_id); data.reset_map = 1;
params.push("elems[]=" + new_elements); data.page = "enterprise/operation/agentes/pandora_networkmap.view";
params.push("page=enterprise/operation/agentes/pandora_networkmap.view");
jQuery.ajax({ jQuery.ajax({
data: params.join("&"), data: data,
dataType: "json", dataType: "json",
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
success: function(data) { success: function(d) {
window.location = window.location =
"index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" + "index.php?sec=network&sec2=operation/agentes/pandora_networkmap&tab=view&id_networkmap=" +
networkmap_id; networkmap_id;