From c556bf3ba8678112bc79bd12420bd0e547154d0a Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 30 Mar 2020 15:03:22 +0200 Subject: [PATCH] License validation --- .../godmode/wizards/HostDevices.class.php | 39 +++++++++++++++++-- .../lib/PandoraFMS/DiscoveryServer.pm | 6 ++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 727010cb8d..26333fbd49 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -946,6 +946,36 @@ class HostDevices extends Wizard ], ]; + // License precheck. + $license = enterprise_hook('license_get_info'); + $n_agents = 0; + foreach (explode(',', $this->task['subnet']) as $net) { + $mask = explode('/', $net, 2)[1]; + if (empty($mask) === true) { + $n_agents++; + } else { + $n_agents += pow(2, (32 - $mask)); + } + } + + $limited = false; + if (is_array($license) === true + && $n_agents > ($license['limit'] - $license['count']) + ) { + $limit = ($license['limit'] - $license['count']); + $limited = true; + } + + if ($limited === true) { + ui_print_warning_message( + __( + 'Configured networks could generate %d agents, your license only allows %d, \'review results\' is mandatory.', + $n_agents, + $limit + ) + ); + } + $form['inputs'][] = [ 'label' => __('Review results').ui_print_help_tip( __( @@ -954,10 +984,11 @@ class HostDevices extends Wizard true ), 'arguments' => [ - 'name' => 'review_results', - 'type' => 'switch', - 'return' => true, - 'value' => ($this->task['review_mode'] == DISCOVERY_STANDARD) ? 0 : 1, + 'name' => 'review_results', + 'type' => 'switch', + 'return' => true, + 'value' => ($this->task['review_mode'] == DISCOVERY_STANDARD) ? ($limited ? 1 : 0) : 1, + 'disabled' => $limited, ], ]; diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 26a5566ac0..2c3d9f1c9f 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -1308,11 +1308,15 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { ) { # Notify. my $notification = {}; - $notification->{'subject'} = safe_input('Review pending'); + $notification->{'subject'} = safe_input('Discovery task '); + $notification->{'subject'} .= $self->{'task_data'}{'name'}; + $notification->{'subject'} .= safe_input(' review pending'); + $notification->{'mensaje'} = safe_input( 'Discovery task (host&devices) \''.safe_output($self->{'task_data'}{'name'}) .'\' has been completed. Please review the results.' ); + $notification->{'id_source'} = get_db_value( $self->{'dbh'}, 'SELECT id FROM tnotification_source WHERE description = ?',