Merge branch 'ent-10118-creacion-de-mapas-de-red' into 'develop'

Ent 10118 creacion de mapas de red

See merge request artica/pandorafms!5531
This commit is contained in:
Diego Muñoz-Reja 2023-02-15 12:55:43 +00:00
commit 472ffdf443
7 changed files with 129 additions and 45 deletions

View File

@ -2,6 +2,8 @@ START TRANSACTION;
ALTER TABLE `tserver` ADD COLUMN `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0; ALTER TABLE `tserver` ADD COLUMN `server_keepalive_utimestamp` BIGINT NOT NULL DEFAULT 0;
ALTER TABLE `tmap` MODIFY COLUMN `id_group` TEXT NOT NULL default '';
CREATE TABLE IF NOT EXISTS `tmonitor_filter` ( CREATE TABLE IF NOT EXISTS `tmonitor_filter` (
`id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id_filter` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_name` VARCHAR(600) NOT NULL, `id_name` VARCHAR(600) NOT NULL,

View File

@ -782,7 +782,9 @@ class NetworkMap
if ($this->network) { if ($this->network) {
// Network map, based on direct network. // Network map, based on direct network.
$nodes = networkmap_get_nodes_from_ip_mask( $nodes = networkmap_get_nodes_from_ip_mask(
$this->network $this->network,
false,
'
'
); );
} else if ($this->mapOptions['map_filter']['empty_map']) { } else if ($this->mapOptions['map_filter']['empty_map']) {
// Empty map returns no data. // Empty map returns no data.
@ -792,17 +794,22 @@ class NetworkMap
|| $this->mapOptions['map_filter']['dont_show_subgroups'] == 1 || $this->mapOptions['map_filter']['dont_show_subgroups'] == 1
) { ) {
// Show only current selected group. // Show only current selected group.
$filter['id_grupo'] = $this->idGroup; $filter['id_grupo'] = explode(',', $this->idGroup);
} else { } else {
// Show current group and children. // Show current group and children.
$childrens = groups_get_children($this->idGroup, null, true); foreach (explode(',', $this->idGroup) as $key => $group) {
$childrens = groups_get_children($group, null, true);
if (!empty($childrens)) { if (!empty($childrens)) {
$childrens = array_keys($childrens); $childrens = array_keys($childrens);
$filter['id_grupo'] = $childrens; if (empty($filter['id_grupo']) === false) {
$filter['id_grupo'][] = $this->idGroup; $filter['id_grupo'] = array_merge($filter['id_grupo'], $childrens);
} else { } else {
$filter['id_grupo'] = $this->idGroup; $filter['id_grupo'] = $childrens;
}
} else {
$filter['id_grupo'][] = $group;
}
} }
} }

View File

@ -1356,9 +1356,10 @@ function networkmap_get_types($strict_user=false)
*/ */
function networkmap_get_nodes_from_ip_mask( function networkmap_get_nodes_from_ip_mask(
$ip_mask, $ip_mask,
$return_ids_only=false $return_ids_only=false,
$separator=',',
) { ) {
$list_ip_masks = explode(',', $ip_mask); $list_ip_masks = explode($separator, $ip_mask);
if (empty($list_ip_masks) === true) { if (empty($list_ip_masks) === true) {
return []; return [];

View File

@ -273,6 +273,25 @@ if (!empty($result)) {
if ($not_found) { if ($not_found) {
ui_print_error_message(__('Not found networkmap.')); ui_print_error_message(__('Not found networkmap.'));
} else { } else {
if ($disabled_source === false) {
echo '<div id="map_loading" style="width: 98%;height: 1000px; background-color: rgba(245, 245, 245, .3);position: absolute;display: flex;justify-content: center;align-items: center;flex-direction: column-reverse;">';
echo html_print_image('images/spinner.gif', true, 'width: 50px;height: 50px;');
echo '<div>'.__('Creating map...').'</div>';
echo '</div>';
$info1 = __('To create a network map that visually recreates link-level (L2) relationships, you must first discover these relationships with Discovery Server. Network maps only reflect relationships that have already been discovered.');
$separator = '<br>';
$info2 = __('Discovery Server discovers relationships between interfaces (L2) through SNMP and relationships between hosts (L3) through route discovery.');
$info3 = __('You can also create these relationships manually by editing nodes or re-passing a discovery task after adding new information (for example by adding new SNMP communities).');
$info4 = __('See our documentation for more information.');
ui_print_info_message(
[
'no_close' => false,
'message' => $info1.$separator.$info2.$separator.$info3.$separator.$info4,
],
'style="width: 98%;"'
);
}
$table = new stdClass(); $table = new stdClass();
$table->id = 'form_editor'; $table->id = 'form_editor';
@ -337,7 +356,14 @@ if ($not_found) {
); );
$table->data[3][0] = __('Description'); $table->data[3][0] = __('Description');
$table->data[3][1] = html_print_textarea('description', 7, 25, $description, '', true); $table->data[3][1] = html_print_input_text(
'description',
$description,
'',
100,
100,
true
);
$table->data[4][0] = __('Position X'); $table->data[4][0] = __('Position X');
$table->data[4][1] = html_print_input_text('pos_x', $offset_x, '', 2, 10, true); $table->data[4][1] = html_print_input_text('pos_x', $offset_x, '', 2, 10, true);
@ -352,7 +378,23 @@ if ($not_found) {
$table->data[6][1] = html_print_input_text('scale_z', $scale_z, '', 2, 10, true).ui_print_help_tip(__('Introduce zoom level. 1 = Highest resolution. Figures may include decimals'), true); $table->data[6][1] = html_print_input_text('scale_z', $scale_z, '', 2, 10, true).ui_print_help_tip(__('Introduce zoom level. 1 = Highest resolution. Figures may include decimals'), true);
$table->data['source'][0] = __('Source'); $table->data['source'][0] = __('Source');
$table->data['source'][1] = html_print_radio_button('source', 'group', __('Group'), $source, true, $disabled_source).html_print_radio_button('source', 'recon_task', __('Discovery task'), $source, true, $disabled_source).html_print_radio_button('source', 'ip_mask', __('CIDR IP mask'), $source, true, $disabled_source); $table->data['source'][1] = html_print_select(
[
'group' => __('Group'),
'recon_task' => __('Discovery task'),
'ip_mask' => __('CIDR IP mask'),
],
'source',
$source,
'',
'',
0,
true,
false,
false,
'',
$disabled_source
);
$table->data['source_data_recon_task'][0] = __('Source from recon task'); $table->data['source_data_recon_task'][0] = __('Source from recon task');
$table->data['source_data_recon_task'][0] .= ui_print_help_tip( $table->data['source_data_recon_task'][0] .= ui_print_help_tip(
@ -378,18 +420,28 @@ if ($not_found) {
); );
$table->data['source_data_ip_mask'][0] = __('Source from CIDR IP mask'); $table->data['source_data_ip_mask'][0] = __('Source from CIDR IP mask');
$table->data['source_data_ip_mask'][1] = html_print_input_text('ip_mask', $ip_mask, '', 20, 255, true, $disabled_source); $table->data['source_data_ip_mask'][1] = html_print_textarea(
'ip_mask',
3,
5,
$ip_mask,
'style="width: 238px"',
true,
'',
$disabled_source
);
$table->data['source_data_group'][0] = __('Source group'); $table->data['source_data_group'][0] = __('Source group');
$table->data['source_data_group'][1] = '<div class="w250px">'.html_print_select_groups( $table->data['source_data_group'][1] = '<div class="w250px">'.html_print_select_groups(
$config['id_user'], $config['id_user'],
'AR', 'AR',
true, true,
'id_group', 'id_group[]',
$id_group, explode(',', $id_group),
'', '',
'', '',
'', '',
true,
true true
).'</div>'; ).'</div>';
$table->data['source_data_group'][1] .= html_print_image( $table->data['source_data_group'][1] .= html_print_image(
@ -498,8 +550,9 @@ if ($not_found) {
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$("input[name='source']").on('change', function() { $("#map_loading").hide();
var source = $("input[name='source']:checked").val(); $("#source").change(function() {
const source = $(this).val();
if (source == 'recon_task') { if (source == 'recon_task') {
$("#form_editor-source_data_ip_mask") $("#form_editor-source_data_ip_mask")
@ -510,7 +563,6 @@ $(document).ready(function() {
.css('display', 'none'); .css('display', 'none');
$("#form_editor-source_data_recon_task") $("#form_editor-source_data_recon_task")
.css('display', ''); .css('display', '');
} }
else if (source == 'ip_mask') { else if (source == 'ip_mask') {
$("#form_editor-source_data_ip_mask") $("#form_editor-source_data_ip_mask")
@ -599,16 +651,14 @@ $(document).ready(function() {
} }
}); });
$("input[name='source']").trigger("change"); $("#source").trigger("change");
$("#method").trigger("change"); $("#method").trigger("change");
// Control if id_group has changed. // Control if id_group has changed.
var id_group_old = $("#id_group").val(); var id_group_old = $("#id_group").val();
var id_group_changed = false; var id_group_changed = false;
$("#id_group").on('change',{id_group_old: id_group_old}, function () { $("#id_group").on('change',{id_group_old: id_group_old}, function () {
var id_group_new = $("#id_group").val(); var id_group_new = $("#id_group").val();
if((id_group_old != id_group_new) && (update_networkmap == 1 )) { if((id_group_old != id_group_new) && (update_networkmap == 1 )) {
id_group_changed = true; id_group_changed = true;
@ -625,7 +675,7 @@ $(document).ready(function() {
update_networkmap = $("input[name='update_networkmap']").val(); update_networkmap = $("input[name='update_networkmap']").val();
$( "#submit-crt" ).click(function( event ) { $( "#submit-crt" ).click(function( event ) {
$("#map_loading").show();
if(update_networkmap == 1 && id_group_changed === true) { if(update_networkmap == 1 && id_group_changed === true) {
confirmDialog({ confirmDialog({
title: '<?php echo __('Are you sure?'); ?>', title: '<?php echo __('Are you sure?'); ?>',
@ -643,7 +693,6 @@ $(document).ready(function() {
}) })
event.preventDefault(); event.preventDefault();
} }
}); });
$("#refresh_time_units").trigger("change"); $("#refresh_time_units").trigger("change");

View File

@ -182,7 +182,7 @@ if ($save_empty_networkmap === true) {
$values = []; $values = [];
$values['name'] = $name; $values['name'] = $name;
$values['id_group'] = $id_group; $values['id_group'] = implode(',', $id_group);
$values['generation_method'] = 4; $values['generation_method'] = 4;
@ -237,7 +237,7 @@ if ($new_networkmap || $save_networkmap) {
} }
if ($save_networkmap) { if ($save_networkmap) {
$id_group = (int) get_parameter('id_group', 0); $id_group = get_parameter('id_group', 0);
$id_group_map = (int) get_parameter('id_group_map', 0); $id_group_map = (int) get_parameter('id_group_map', 0);
@ -292,7 +292,7 @@ if ($new_networkmap || $save_networkmap) {
$values = []; $values = [];
$values['name'] = $name; $values['name'] = $name;
$values['id_group'] = $id_group; $values['id_group'] = implode(',', $id_group);
$values['source_period'] = 60; $values['source_period'] = 60;
$values['width'] = $width; $values['width'] = $width;
$values['height'] = $height; $values['height'] = $height;
@ -333,7 +333,7 @@ if ($new_networkmap || $save_networkmap) {
if ($source == 'group') { if ($source == 'group') {
$values['source'] = 0; $values['source'] = 0;
$values['source_data'] = $id_group; $values['source_data'] = implode(',', $id_group);
} else if ($source == 'recon_task') { } else if ($source == 'recon_task') {
$values['source'] = 1; $values['source'] = 1;
$values['source_data'] = $recon_task_id; $values['source_data'] = $recon_task_id;
@ -444,7 +444,7 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
} }
if ($update_networkmap) { if ($update_networkmap) {
$id_group = (int) get_parameter('id_group', 0); $id_group = get_parameter('id_group', 0);
// Get id of old group source to check changes. // Get id of old group source to check changes.
$id_group_old = db_get_value('id_group', 'tmap', 'id', $id); $id_group_old = db_get_value('id_group', 'tmap', 'id', $id);
@ -480,7 +480,7 @@ else if ($update_networkmap || $copy_networkmap || $delete) {
$values = []; $values = [];
$values['name'] = $name; $values['name'] = $name;
$values['id_group'] = $id_group; $values['id_group'] = implode(',', $id_group);
$values['id_group_map'] = $id_group_map; $values['id_group_map'] = $id_group_map;
$description = get_parameter('description', ''); $description = get_parameter('description', '');

View File

@ -171,7 +171,23 @@ if (is_ajax() === true) {
$table->data[6][1] = html_print_input_text('scale_z', $map_filter['z_dash'], '', 2, 10, true).ui_print_help_tip(__('Introduce zoom level. 1 = Highest resolution. Figures may include decimals'), true); $table->data[6][1] = html_print_input_text('scale_z', $map_filter['z_dash'], '', 2, 10, true).ui_print_help_tip(__('Introduce zoom level. 1 = Highest resolution. Figures may include decimals'), true);
$table->data['source'][0] = __('Source'); $table->data['source'][0] = __('Source');
$table->data['source'][1] = html_print_radio_button('source', 'group', __('Group'), $source, true).html_print_radio_button('source', 'recon_task', __('Discovery task'), $source, true).html_print_radio_button('source', 'ip_mask', __('CIDR IP mask'), $source, true); $table->data['source'][1] = html_print_select(
[
'group' => __('Group'),
'recon_task' => __('Discovery task'),
'ip_mask' => __('CIDR IP mask'),
],
'source',
$source,
'',
'',
0,
true,
false,
false,
'',
$disabled_source
);
if (! check_acl($config['id_user'], 0, 'PM')) { if (! check_acl($config['id_user'], 0, 'PM')) {
$sql = sprintf( $sql = sprintf(
@ -221,7 +237,16 @@ if (is_ajax() === true) {
); );
$table->data['source_data_ip_mask'][0] = __('Source from CIDR IP mask'); $table->data['source_data_ip_mask'][0] = __('Source from CIDR IP mask');
$table->data['source_data_ip_mask'][1] = html_print_input_text('ip_mask', $map_info['source_data'], '', 20, 255, true); $table->data['source_data_ip_mask'][1] = html_print_textarea(
'ip_mask',
3,
5,
$map_info['source_data'],
'',
true,
'',
$disabled_source
);
$dont_show_subgroups = 0; $dont_show_subgroups = 0;
if (isset($map_filter['dont_show_subgroups'])) { if (isset($map_filter['dont_show_subgroups'])) {
@ -296,8 +321,8 @@ if (is_ajax() === true) {
$map_form .= html_print_table($table, true); $map_form .= html_print_table($table, true);
$map_form .= '<script> $map_form .= '<script>
$("input[name=\'source\']").on(\'change\', function() { $("#source").change(function() {
var source = $("input[name=\'source\']:checked").val(); const source = $(this).val();
if (source == \'recon_task\') { if (source == \'recon_task\') {
$("#form_editor-source_data_ip_mask") $("#form_editor-source_data_ip_mask")
@ -389,7 +414,7 @@ if (is_ajax() === true) {
} }
}); });
$("input[name=\'source\']").trigger("change"); $("#source").trigger("change");
$("#method").trigger("change"); $("#method").trigger("change");
</script>'; </script>';

View File

@ -2323,7 +2323,7 @@ CREATE TABLE IF NOT EXISTS `tsessions_php` (
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmap` ( CREATE TABLE IF NOT EXISTS `tmap` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`id_group` INT UNSIGNED NOT NULL DEFAULT 0, `id_group` TEXT NOT NULL DEFAULT '',
`id_user` VARCHAR(255) NOT NULL DEFAULT '', `id_user` VARCHAR(255) NOT NULL DEFAULT '',
`type` INT UNSIGNED NOT NULL DEFAULT 0, `type` INT UNSIGNED NOT NULL DEFAULT 0,
`subtype` INT UNSIGNED NOT NULL DEFAULT 0, `subtype` INT UNSIGNED NOT NULL DEFAULT 0,