H&D port filtering + control tasks cancellation while restarting server

This commit is contained in:
fbsanchez 2020-05-04 11:13:15 +02:00
parent 54a9ebd4ed
commit 4815dce8aa
4 changed files with 41 additions and 2 deletions

View File

@ -538,7 +538,14 @@ class DiscoveryTaskList extends HTML
}
$can_be_reviewed = false;
if ($task['review_mode'] == DISCOVERY_STANDARD) {
if (empty($task['summary']) === false
&& $task['summary'] == 'cancelled'
) {
$data[5] = __('Cancelled').ui_print_help_tip(
__('Server has been restarted while executing this task, please retry.'),
true
);
} else if ($task['review_mode'] == DISCOVERY_STANDARD) {
if ($task['status'] <= 0
&& empty($task['summary']) === false
) {

View File

@ -482,6 +482,7 @@ class HostDevices extends Wizard
$review_results = get_parameter_switch('review_results');
$review_limited = (bool) get_parameter('review_limited', 0);
$auto_monitor = get_parameter_switch('auto_monitor');
$recon_ports = get_parameter('recon_ports', null);
$autoconf_enabled = get_parameter_switch(
'autoconfiguration_enabled'
);
@ -533,6 +534,7 @@ class HostDevices extends Wizard
}
$this->task['auto_monitor'] = $auto_monitor;
$this->task['recon_ports'] = $recon_ports;
$this->task['snmp_enabled'] = $snmp_enabled;
$this->task['os_detect'] = $os_detect;
$this->task['parent_detection'] = $parent_detection;
@ -1038,6 +1040,21 @@ class HostDevices extends Wizard
],
];
$form['inputs'][] = [
'label' => __('Filter by opened ports').ui_print_help_tip(
__(
'Targets will be scanned if at least one of defined ports (comma separated) is open.'
),
true
),
'arguments' => [
'name' => 'recon_ports',
'type' => 'text',
'return' => true,
'value' => $this->task['recon_ports'],
],
];
$form['inputs'][] = [
'label' => __('Auto discover known hardware').ui_print_help_tip(
__(

View File

@ -105,7 +105,7 @@ sub new ($$$$$$) {
get_server_id ($dbh, $config->{'servername'}, DISCOVERYSERVER));
# Reset (but do not restart) manual recon tasks.
db_do ($dbh, 'UPDATE trecon_task SET status = -1 WHERE id_recon_server = ? AND status <> -1 AND interval_sweep = 0',
db_do ($dbh, 'UPDATE trecon_task SET status = -1, summary = "cancelled" WHERE id_recon_server = ? AND status <> -1 AND interval_sweep = 0',
get_server_id ($dbh, $config->{'servername'}, DISCOVERYSERVER));
# Call the constructor of the parent class
@ -250,6 +250,13 @@ sub data_consumer ($$) {
}
}
if (!is_empty($task->{'recon_ports'})) {
# Accept only valid symbols.
if ($task->{'recon_ports'} !~ /[\d\-\,\ ]+/) {
$task->{'recon_ports'} = '';
}
}
my $recon = new PandoraFMS::Recon::Base(
communities => \@communities,
dbh => $dbh,
@ -449,6 +456,9 @@ sub PandoraFMS::Recon::Base::guess_os($$) {
sub PandoraFMS::Recon::Base::tcp_scan ($$) {
my ($self, $host) = @_;
return if is_empty($host);
return if is_empty($self->{'recon_ports'});
my $r = `"$self->{pa_config}->{nmap}" -p$self->{recon_ports} $host`;
# Same as ""| grep open | wc -l" but multi-OS;

View File

@ -1549,6 +1549,11 @@ sub scan_subnet($) {
# Populate.
$self->call('update_progress', ceil($progress));
# Filter by port (if enabled).
if (!is_empty($self->{'recon_ports'})) {
next unless $self->call("tcp_scan", $addr) > 0;
}
# Enable/ disable capabilities.
$self->test_capabilities($addr);
}