Some changes, multibox fixes for metaconsole

This commit is contained in:
fbsanchez 2021-06-23 14:24:16 +02:00
parent de03486134
commit be09c1c64d
3 changed files with 55 additions and 16 deletions

View File

@ -1441,7 +1441,7 @@ function html_print_select_multiple_modules_filtered(array $data):string
// Force_serialized. // Force_serialized.
false, false,
// Meta_fields. // Meta_fields.
$data['mMetaFields'] ($data['mMetaFields'] ?? is_metaconsole())
); );
if ((empty($agents)) === true || $agents == -1) { if ((empty($agents)) === true || $agents == -1) {

View File

@ -133,6 +133,7 @@ div.target {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 100%; width: 100%;
box-sizing: border-box;
} }
div.target.flex { div.target.flex {
border: 2px dashed #ddd; border: 2px dashed #ddd;

View File

@ -275,20 +275,38 @@ if (is_ajax()) {
} }
} else { } else {
// All modules. // All modules.
$modules = array_reduce( $return = [];
$modules[$tserver], $nodes = [];
function ($carry, $item) use ($tserver) { foreach ($agents as $tserver => $id_agents) {
$t = []; try {
foreach ($item as $k => $v) { $nodes[$tserver] = new Node($tserver);
$t[$k] = $v; } catch (Exception $e) {
} hd($e);
}
$t['id_node'] = $tserver; $return = array_reduce(
$carry[] = $t; $modules[$tserver],
return $carry; function ($carry, $item) use ($tserver, $nodes) {
}, $t = [];
[] foreach ($item as $k => $v) {
); $t[$k] = $v;
}
$t['id_node'] = $tserver;
if ($nodes[$tserver] !== null) {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' » '.$t['nombre']
);
}
$carry[] = $t;
return $carry;
},
$return
);
}
$modules = $return;
} }
echo json_encode($modules); echo json_encode($modules);
@ -301,12 +319,27 @@ if (is_ajax()) {
$modules = (array) get_parameter('modules', []); $modules = (array) get_parameter('modules', []);
$existing_modules = []; $existing_modules = [];
$avoid_duplicates = [];
foreach ($modules as $def) { foreach ($modules as $def) {
$data = explode('|', $def); $data = explode('|', $def);
if (is_metaconsole() === true) { if (is_metaconsole() === true) {
$id_node = (int) $data[0]; $id_node = (int) $data[0];
$id_agent = (int) $data[1]; $id_agent = db_get_value(
$module_name = $data[2]; 'id_tagente',
'tmetaconsole_agent',
'id_agente',
(int) $data[1]
);
if ($id_agent === false) {
continue;
}
$mod = explode(' » ', $data[2]);
$module_name = $mod[1];
if (empty($module_name) === true) {
$module_name = $data[2];
}
} else { } else {
$id_agent = $data[0]; $id_agent = $data[0];
$module_name = $data[1]; $module_name = $data[1];
@ -337,6 +370,11 @@ if (is_ajax()) {
$text .= $module->agent()->alias().' » '.$module->nombre(); $text .= $module->agent()->alias().' » '.$module->nombre();
$id .= $module->id_agente_modulo(); $id .= $module->id_agente_modulo();
if ($avoid_duplicates[$id] === 1) {
continue;
}
$avoid_duplicates[$id] = 1;
$existing_modules[] = [ $existing_modules[] = [
'id' => $id, 'id' => $id,
'text' => io_safe_output($text), 'text' => io_safe_output($text),