From 762ad3106d56c0614d53c21401a6cd9440c3f514 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 7 Apr 2020 18:50:56 +0200 Subject: [PATCH] Improvements and fixes H&D with review --- pandora_console/extras/mr/37.sql | 2 +- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 2 +- .../wizards/DiscoveryTaskList.class.php | 50 ++++++++++++++----- .../godmode/wizards/HostDevices.class.php | 14 +++++- pandora_console/include/functions_html.php | 9 ++-- .../include/styles/hostdevices.css | 11 +++- pandora_console/include/styles/wizard.css | 2 +- pandora_console/pandoradb.sql | 2 +- .../lib/PandoraFMS/DiscoveryServer.pm | 23 +++++++-- pandora_server/lib/PandoraFMS/Recon/Base.pm | 15 ++++-- 10 files changed, 98 insertions(+), 32 deletions(-) diff --git a/pandora_console/extras/mr/37.sql b/pandora_console/extras/mr/37.sql index 3a392c8aed..8d29b06a53 100644 --- a/pandora_console/extras/mr/37.sql +++ b/pandora_console/extras/mr/37.sql @@ -12,7 +12,7 @@ CREATE TABLE `tdiscovery_tmp_agents` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_rt` int(10) unsigned NOT NULL, `label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - `data` text, + `data` MEDIUMTEXT, `review_date` datetime DEFAULT NULL, `created` datetime DEFAULT NULL, PRIMARY KEY (`id`), diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 3fade4831a..6dce97ee8a 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1698,7 +1698,7 @@ CREATE TABLE `tdiscovery_tmp_agents` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_rt` int(10) unsigned NOT NULL, `label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - `data` text, + `data` MEDIUMTEXT, `review_date` datetime DEFAULT NULL, `created` datetime DEFAULT NULL, PRIMARY KEY (`id`), diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 041053c2be..033395510c 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -523,6 +523,7 @@ class DiscoveryTaskList extends HTML $data[4] = '-'; } + $can_be_reviewed = false; if ($task['review_mode'] == DISCOVERY_STANDARD) { if ($task['status'] <= 0 && empty($task['summary']) === false @@ -539,6 +540,7 @@ class DiscoveryTaskList extends HTML if ($task['status'] <= 0 && empty($task['summary']) === false ) { + $can_be_reviewed = true; $data[5] = ''; $data[5] .= __('Review'); $data[5] .= ''; @@ -676,10 +678,22 @@ class DiscoveryTaskList extends HTML if (!$no_operations) { if ($task['disabled'] != 2) { - $data[9] = ''; + $data[9] = ''; + if ($can_be_reviewed) { + $data[9] .= ''; + $data[9] .= html_print_image( + 'images/expand.png', + true, + ['title' => __('Review results')] + ); + $data[9] .= ''; + } + + $data[9] .= ''; $data[9] .= html_print_image( 'images/eye.png', - true + true, + ['title' => __('View summary')] ); $data[9] .= ''; } @@ -693,7 +707,8 @@ class DiscoveryTaskList extends HTML $data[9] .= ''; $data[9] .= html_print_image( 'images/dynamic_network_icon.png', - true + true, + ['title' => __('View map')] ); $data[9] .= ''; } @@ -713,13 +728,15 @@ class DiscoveryTaskList extends HTML ) ).'">'.html_print_image( 'images/config.png', - true + true, + ['title' => __('Edit task')] ).''; $data[9] .= ''.html_print_image( 'images/cross.png', - true + true, + ['title' => __('Delete task')] ).''; } else { // Check if is a H&D, Cloud or Application or IPAM. @@ -731,13 +748,15 @@ class DiscoveryTaskList extends HTML ) ).'">'.html_print_image( 'images/config.png', - true + true, + ['title' => __('Edit task')] ).''; $data[9] .= ''.html_print_image( 'images/cross.png', - true + true, + ['title' => __('Delete task')] ).''; } } else { @@ -1214,7 +1233,6 @@ class DiscoveryTaskList extends HTML if (is_array($task_data)) { foreach ($task_data as $agent) { $data = json_decode(base64_decode($agent['data']), true); - if (is_array($data) === false) { continue; } @@ -1287,10 +1305,13 @@ class DiscoveryTaskList extends HTML ); } } + } - echo '
'; - echo $this->progressTaskSummary($task); - echo '
'; + echo '
'; + echo $this->progressTaskSummary($task); + echo '
'; + + if (count($simple_data) > 0) { echo '
'; echo ''; echo __('Please select devices to be monitored'); @@ -1309,7 +1330,6 @@ class DiscoveryTaskList extends HTML echo ''; echo '
'; echo ''; - echo '
'; echo '
'; echo parent::printTree( @@ -1317,6 +1337,12 @@ class DiscoveryTaskList extends HTML $simple_data ); echo '
'; + } else { + echo '
'; + echo ''; + echo __('No devices found in temporary resources, please re-launch.'); + echo ''; + echo '
'; } } diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 2737a959a1..9ed11dd29c 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -308,7 +308,18 @@ class HostDevices extends Wizard $interval = get_parameter('interval', 0); if ($network_csv_enabled) { - if ($_FILES['network_csv']['type'] != 'text/csv') { + if ($_FILES['network_csv']['type'] != 'text/csv' + && $_FILES['network_csv']['type'] != 'text/plain' + && $_FILES['network_csv']['type'] != 'application/octet-stream' + && $_FILES['network_csv']['type'] != 'application/vnd.ms-excel' + && $_FILES['network_csv']['type'] != 'text/x-csv' + && $_FILES['network_csv']['type'] != 'application/csv' + && $_FILES['network_csv']['type'] != 'application/x-csv' + && $_FILES['network_csv']['type'] != 'text/csv' + && $_FILES['network_csv']['type'] != 'text/comma-separated-values' + && $_FILES['network_csv']['type'] != 'text/x-comma-separated-values' + && $_FILES['network_csv']['type'] != 'text/tab-separated-values' + ) { $this->msg = __( 'Invalid mimetype for csv file: %s', $_FILES['network_csv']['type'] @@ -1057,6 +1068,7 @@ class HostDevices extends Wizard 'nothing_value' => 0, 'nothing' => __('None'), 'multiple' => true, + 'class' => 'select_multiple', ], ]; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 6ee12bea9d..0fdb98267d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -722,6 +722,7 @@ function html_print_select( * @param string $style The string of style. * @param mixed $size Max elements showed in select or default (size=10) * @param integer $truncante_size Truncate size of the element, by default is set to GENERIC_SIZE_TEXT constant + * @param integer $class Class to apply. * * @return string HTML code if return parameter is true. */ @@ -738,7 +739,8 @@ function html_print_select_from_sql( $disabled=false, $style=false, $size=false, - $trucate_size=GENERIC_SIZE_TEXT + $trucate_size=GENERIC_SIZE_TEXT, + $class='' ) { global $config; @@ -770,7 +772,7 @@ function html_print_select_from_sql( $return, $multiple, $sort, - '', + $class, $disabled, $style, '', @@ -3589,7 +3591,8 @@ function html_print_input($data, $wrapper='div', $input_only=false) ((isset($data['disabled']) === true) ? $data['disabled'] : false), ((isset($data['style']) === true) ? $data['style'] : false), ((isset($data['size']) === true) ? $data['size'] : false), - ((isset($data['trucate_size']) === true) ? $data['trucate_size'] : GENERIC_SIZE_TEXT) + ((isset($data['trucate_size']) === true) ? $data['trucate_size'] : GENERIC_SIZE_TEXT), + ((isset($data['class']) === true) ? $data['class'] : '') ); break; diff --git a/pandora_console/include/styles/hostdevices.css b/pandora_console/include/styles/hostdevices.css index ebd13988d5..e378e24d97 100644 --- a/pandora_console/include/styles/hostdevices.css +++ b/pandora_console/include/styles/hostdevices.css @@ -2,6 +2,13 @@ * TODO: This may be at hostdevices.css */ -#id_network_profile { - width: 300px; +select.select_multiple { + min-width: 500px; + width: 50%; + height: 250px; +} + +.indented select.select_multiple { + min-width: calc(500px - 1em); + width: calc(50% - 1em); } diff --git a/pandora_console/include/styles/wizard.css b/pandora_console/include/styles/wizard.css index 0609010dfb..7976971d74 100644 --- a/pandora_console/include/styles/wizard.css +++ b/pandora_console/include/styles/wizard.css @@ -32,7 +32,7 @@ ul.wizard li > textarea { } .wizard .indented { - margin-left: 2em; + margin-left: 1em; } .wizard .std_input { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index e32911bb53..83b842eee3 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -822,7 +822,7 @@ CREATE TABLE `tdiscovery_tmp_agents` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_rt` int(10) unsigned NOT NULL, `label` varchar(600) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', - `data` text, + `data` MEDIUMTEXT, `review_date` datetime DEFAULT NULL, `created` datetime DEFAULT NULL, PRIMARY KEY (`id`), diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index cee5efe451..73211f1aff 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -497,19 +497,32 @@ sub PandoraFMS::Recon::Base::test_module($$) { } elsif (($test->{'id_tipo_modulo'} >= 1 && $test->{'id_tipo_modulo'} <= 5) || ($test->{'id_tipo_modulo'} >= 21 && $test->{'id_tipo_modulo'} <= 23) - && is_enabled($test->{'id_plugin'}) ) { # Generic, plugins. (21-23 ASYNC) - # XXX TODO: Test plugins. - return 1; + if ($test->{'id_modulo'} == 6) { + # WMI commands. + $value = $self->call( + 'wmi_get_value', + $test->{'ip_target'}, + # WMI query. + $test->{'snmp_oid'}, + # Column + $test->{'tcp_port'} + ); + } elsif(is_enabled($test->{'id_plugin'})) { + # XXX TODO: Test plugins. How to identify arguments? and values? + # Disabled until we can ensure result. + return 0; + } } elsif ($test->{'id_tipo_modulo'} >= 34 && $test->{'id_tipo_modulo'} <= 37) { # Remote command. # XXX TODO: Test remote commands. - return 1; + # Disabled until we can ensure result. + return 0; + } elsif ($test->{'id_tipo_modulo'} >= 8 && $test->{'id_tipo_modulo'} <= 11) { # TCP - return 0 unless is_numeric($test->{'tcp_port'}) && $test->{'tcp_port'} > 0 && $test->{'tcp_port'} <= 65535; diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 9130fccb6a..21418c32e0 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -2175,7 +2175,7 @@ sub wmi_credentials_calculation { my ($self, $target) = @_; # Test empty credentials. - my @output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -N //$target "SELECT * FROM Win32_ComputerSystem" 2>&1`; + my @output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -N //$target "SELECT * FROM Win32_ComputerSystem" 2>$DEVNULL`; my $rs = $self->wmi_output_check($?, @output); if ($rs == WMI_OK) { @@ -2198,7 +2198,7 @@ sub wmi_credentials_calculation { my $auth = $cred->{'username'}.'%'.$cred->{'password'}; next if $auth eq '%'; - @output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -U $auth //$target "SELECT * FROM Win32_ComputerSystem" 2>&1`; + @output = `$self->{'timeout_cmd'}$self->{'wmi_client'} -U $auth //$target "SELECT * FROM Win32_ComputerSystem" 2>$DEVNULL`; my $rs = $self->wmi_output_check($?, @output); @@ -2288,11 +2288,13 @@ sub wmi_get { sub wmi_get_command { my ($self, $target, $auth, $query) = @_; + return () if is_empty($target); + my @output; if (defined($auth) && $auth ne '') { - @output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -U $auth //$target "$query" 2>&1`; + @output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -U $auth //$target "$query" 2>$DEVNULL`; }else { - @output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -N //$target "$query" 2>&1`; + @output = `$self->{'timeout_cmd'}"$self->{'wmi_client'}" -N //$target "$query" 2>$DEVNULL`; } my $rs = $self->wmi_output_check($?, @output); @@ -2301,9 +2303,12 @@ sub wmi_get_command { return @output; } + my $err = $self->{'last_wmi_error'}; + $err = 'Not OK, empty error' if is_empty($err); + $self->call( 'message', - "[".$target."] WMI error: ".$self->{'last_wmi_error'}, + "[".$target."] WMI error: ".$err, 10 );