mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 01:05:39 +02:00
Merge branch 'ent-5575-wizard-de-modulos-y-recon-by-steps' of brutus.artica.es:artica/pandorafms into ent-5575-wizard-de-modulos-y-recon-by-steps
This commit is contained in:
commit
85765099ea
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
enterprise_include_once('include/functions_license.php');
|
||||||
|
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
check_login();
|
check_login();
|
||||||
|
@ -1250,6 +1250,12 @@ class DiscoveryTaskList extends HTML
|
|||||||
echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), true); simTree_tree.clickNode($(this));});">';
|
echo '<button onclick="$(\'.sim-tree li a\').each(function(){simTree_tree.doCheck($(this), true); simTree_tree.clickNode($(this));});">';
|
||||||
echo __('deselect all');
|
echo __('deselect all');
|
||||||
echo '</button>';
|
echo '</button>';
|
||||||
|
echo '<button onclick="$(\'.sim-tree-spread.sim-icon-r\').click();">';
|
||||||
|
echo __('expand all');
|
||||||
|
echo '</button>';
|
||||||
|
echo '<button onclick="$(\'.sim-tree-spread.sim-icon-d\').click();">';
|
||||||
|
echo __('collapse all');
|
||||||
|
echo '</button>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|
||||||
@ -1279,12 +1285,18 @@ class DiscoveryTaskList extends HTML
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ids = [];
|
$ids = [];
|
||||||
|
$n_agents = 0;
|
||||||
$selection = io_safe_output(get_parameter('tree-data-tree', ''));
|
$selection = io_safe_output(get_parameter('tree-data-tree', ''));
|
||||||
if (empty($selection) === false) {
|
if (empty($selection) === false) {
|
||||||
$selection = json_decode($selection, true);
|
$selection = json_decode($selection, true);
|
||||||
$ids = array_reduce(
|
$ids = array_reduce(
|
||||||
$selection,
|
$selection,
|
||||||
function ($carry, $item) {
|
function ($carry, $item) use (&$n_agents) {
|
||||||
|
if (explode('-', $item['id'])[1] === null) {
|
||||||
|
// String is agent-module.
|
||||||
|
$n_agents++;
|
||||||
|
}
|
||||||
|
|
||||||
$carry[] = $item['id'];
|
$carry[] = $item['id'];
|
||||||
return $carry;
|
return $carry;
|
||||||
}
|
}
|
||||||
@ -1296,6 +1308,24 @@ class DiscoveryTaskList extends HTML
|
|||||||
['id_rt' => $id_task]
|
['id_rt' => $id_task]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// License precheck.
|
||||||
|
$license = enterprise_hook('license_get_info');
|
||||||
|
|
||||||
|
if (is_array($license) === true
|
||||||
|
&& $n_agents > ($license['limit'] - $license['count'])
|
||||||
|
) {
|
||||||
|
$limit = ($license['limit'] - $license['count']);
|
||||||
|
echo json_encode(
|
||||||
|
[
|
||||||
|
'error' => __(
|
||||||
|
'Your selection exceeds the agents available on your license. Limit %d',
|
||||||
|
$limit
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$summary = [];
|
$summary = [];
|
||||||
if (is_array($ids)) {
|
if (is_array($ids)) {
|
||||||
foreach ($task_data as $row) {
|
foreach ($task_data as $row) {
|
||||||
|
@ -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)) {
|
||||||
|
$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'][] = [
|
$form['inputs'][] = [
|
||||||
'label' => __('Review results').ui_print_help_tip(
|
'label' => __('Review results').ui_print_help_tip(
|
||||||
__(
|
__(
|
||||||
@ -957,7 +987,8 @@ class HostDevices extends Wizard
|
|||||||
'name' => 'review_results',
|
'name' => 'review_results',
|
||||||
'type' => 'switch',
|
'type' => 'switch',
|
||||||
'return' => true,
|
'return' => true,
|
||||||
'value' => ($this->task['review_mode'] == DISCOVERY_STANDARD) ? 0 : 1,
|
'value' => ($this->task['review_mode'] == DISCOVERY_STANDARD) ? (($limited) ? 1 : 0) : 1,
|
||||||
|
'disabled' => $limited,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -270,6 +270,8 @@ our @EXPORT = qw(
|
|||||||
pandora_delete_custom_graph
|
pandora_delete_custom_graph
|
||||||
pandora_edit_custom_graph
|
pandora_edit_custom_graph
|
||||||
notification_set_targets
|
notification_set_targets
|
||||||
|
notification_get_users
|
||||||
|
notification_get_groups
|
||||||
);
|
);
|
||||||
|
|
||||||
# Some global variables
|
# Some global variables
|
||||||
@ -6254,6 +6256,55 @@ sub notification_set_targets {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
=head2 C<< notification_get_users (I<$dbh>, I<$source>) >>
|
||||||
|
Get targets for given sources
|
||||||
|
=cut
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
sub notification_get_users {
|
||||||
|
my ($dbh, $source) = @_;
|
||||||
|
|
||||||
|
my @results = get_db_rows(
|
||||||
|
$dbh,
|
||||||
|
'SELECT id_user
|
||||||
|
FROM tnotification_source_user nsu
|
||||||
|
INNER JOIN tnotification_source ns ON nsu.id_source=ns.id
|
||||||
|
WHERE ns.description = ?
|
||||||
|
',
|
||||||
|
safe_input($source)
|
||||||
|
);
|
||||||
|
|
||||||
|
@results = map { $_->{'id_user'} } @results;
|
||||||
|
return @results;
|
||||||
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
=head2 C<< notification_get_groups (I<$dbh>, I<$source>) >>
|
||||||
|
Get targets for given sources
|
||||||
|
=cut
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
sub notification_get_groups {
|
||||||
|
my ($dbh, $source) = @_;
|
||||||
|
|
||||||
|
my @results = get_db_rows(
|
||||||
|
$dbh,
|
||||||
|
'SELECT id_group
|
||||||
|
FROM tnotification_source_group nsg
|
||||||
|
INNER JOIN tnotification_source ns ON nsg.id_source=ns.id
|
||||||
|
WHERE ns.description = ?
|
||||||
|
',
|
||||||
|
safe_input($source)
|
||||||
|
);
|
||||||
|
|
||||||
|
@results = map { $_->{'id_group'} } @results;
|
||||||
|
return @results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
@ -206,17 +206,26 @@ sub data_consumer ($$) {
|
|||||||
@auth_strings = split(/,/, safe_output($task->{'auth_strings'}));
|
@auth_strings = split(/,/, safe_output($task->{'auth_strings'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
my $main_event = pandora_event($pa_config, "[Discovery] Execution summary",$task->{'id_group'}, 0, 0, 0, 0, 'system', 0, $dbh);
|
my $main_event = pandora_event($pa_config,
|
||||||
|
"[Discovery] Execution summary",
|
||||||
|
$task->{'id_group'}, 0, 0, 0, 0, 'system', 0, $dbh
|
||||||
|
);
|
||||||
|
|
||||||
my %cnf_extra;
|
my %cnf_extra;
|
||||||
|
|
||||||
my $r = enterprise_hook('discovery_generate_extra_cnf',[$pa_config, $dbh, $task, \%cnf_extra]);
|
my $r = enterprise_hook(
|
||||||
|
'discovery_generate_extra_cnf',
|
||||||
|
[
|
||||||
|
$pa_config,
|
||||||
|
$dbh, $task,
|
||||||
|
\%cnf_extra
|
||||||
|
]
|
||||||
|
);
|
||||||
if (defined($r) && $r eq 'ERR') {
|
if (defined($r) && $r eq 'ERR') {
|
||||||
# Could not generate extra cnf, skip this task.
|
# Could not generate extra cnf, skip this task.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($task->{'type'} == DISCOVERY_APP_SAP) {
|
if ($task->{'type'} == DISCOVERY_APP_SAP) {
|
||||||
# SAP TASK, retrieve license.
|
# SAP TASK, retrieve license.
|
||||||
$task->{'sap_license'} = pandora_get_config_value(
|
$task->{'sap_license'} = pandora_get_config_value(
|
||||||
@ -907,23 +916,21 @@ sub PandoraFMS::Recon::Base::get_credentials {
|
|||||||
################################################################################
|
################################################################################
|
||||||
# Create agents and modules reported by Recon::Base.
|
# Create agents and modules reported by Recon::Base.
|
||||||
################################################################################
|
################################################################################
|
||||||
sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
sub PandoraFMS::Recon::Base::report_scanned_agents($;$) {
|
||||||
my ($self) = @_;
|
my ($self,$force) = @_;
|
||||||
|
|
||||||
my $force_creation = 0;
|
my $force_creation = $force;
|
||||||
|
$force_creation = 0 unless (is_enabled($force));
|
||||||
if (defined($self->{'task_data'}{'review_mode'})
|
|
||||||
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_STANDARD
|
|
||||||
) {
|
|
||||||
$force_creation = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Creation
|
# Creation
|
||||||
#
|
#
|
||||||
if(defined($self->{'task_data'}{'review_mode'})
|
|
||||||
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_RESULTS
|
if($force_creation == 1
|
||||||
|
|| (defined($self->{'task_data'}{'review_mode'})
|
||||||
|
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_RESULTS)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
# Load cache.
|
# Load cache.
|
||||||
my @rows = get_db_rows(
|
my @rows = get_db_rows(
|
||||||
$self->{'dbh'},
|
$self->{'dbh'},
|
||||||
@ -999,10 +1006,11 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
$agent_id = get_db_value(
|
$agent_id = get_db_value(
|
||||||
$self->{'dbh'},
|
$self->{'dbh'},
|
||||||
'SELECT id_agente FROM tagente WHERE nombre = ?',
|
'SELECT id_agente FROM tagente WHERE nombre = ?',
|
||||||
safe_input($data->{'agent'}->{'name'})
|
safe_input($data->{'agent'}{'nombre'})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!defined($agent_id) || $agent_id <= 0) {
|
if (!defined($agent_id) || $agent_id <= 0) {
|
||||||
|
# Agent creation.
|
||||||
$agent_id = pandora_create_agent(
|
$agent_id = pandora_create_agent(
|
||||||
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'},
|
$self->{'pa_config'}, $self->{'servername'}, $data->{'agent'}{'nombre'},
|
||||||
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id,
|
$data->{'agent'}{'direccion'}, $self->{'task_data'}{'group_id'}, $parent_id,
|
||||||
@ -1011,6 +1019,43 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
$data->{'agent'}{'timezone_offset'}
|
$data->{'agent'}{'timezone_offset'}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Agent autoconfiguration.
|
||||||
|
if (is_enabled($self->{'autoconfiguration_enabled'})) {
|
||||||
|
my $agent_data = PandoraFMS::DB::get_db_single_row(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'SELECT * FROM tagente WHERE id_agente = ?',
|
||||||
|
$agent_id
|
||||||
|
);
|
||||||
|
|
||||||
|
# Update agent configuration once, after create agent.
|
||||||
|
enterprise_hook(
|
||||||
|
'autoconfigure_agent',
|
||||||
|
[
|
||||||
|
$self->{'pa_config'},
|
||||||
|
$data->{'agent'}{'direccion'},
|
||||||
|
$agent_id,
|
||||||
|
$agent_data,
|
||||||
|
$self->{'dbh'},
|
||||||
|
1
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined($self->{'main_event_id'})) {
|
||||||
|
my $addresses_str = join(
|
||||||
|
',',
|
||||||
|
$self->get_addresses(safe_output($data->{'agent'}{'nombre'}))
|
||||||
|
);
|
||||||
|
|
||||||
|
pandora_extended_event(
|
||||||
|
$self->{'pa_config'}, $self->{'dbh'},
|
||||||
|
$self->{'main_event_id'},"[Discovery] New "
|
||||||
|
. $self->get_device_type(safe_output($data->{'agent'}{'nombre'}))
|
||||||
|
. " found " . $data->{'agent'}{'nombre'} . " (" . $addresses_str
|
||||||
|
. ") Agent $agent_id."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$agent_learning = 1;
|
$agent_learning = 1;
|
||||||
} else {
|
} else {
|
||||||
# Read from effective agent_id.
|
# Read from effective agent_id.
|
||||||
@ -1044,17 +1089,13 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
|
|
||||||
$self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5);
|
$self->call('message', "[$agent_id] Module: ".$module->{'name'}, 5);
|
||||||
|
|
||||||
my $agentmodule_id = $module->{'agentmodule_id'};
|
my $agentmodule_id = get_db_value(
|
||||||
|
|
||||||
if (defined($agentmodule_id) && $agentmodule_id > 0) {
|
|
||||||
$agentmodule_id = get_db_value(
|
|
||||||
$self->{'dbh'},
|
$self->{'dbh'},
|
||||||
'SELECT id_agente_modulo FROM tagente_modulo
|
'SELECT id_agente_modulo FROM tagente_modulo
|
||||||
WHERE id_agente_modulo = ? AND nombre = ?',
|
WHERE id_agente = ? AND nombre = ?',
|
||||||
$agentmodule_id,
|
$agent_id,
|
||||||
safe_input($module->{'name'})
|
safe_input($module->{'name'})
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_enabled($agentmodule_id)) {
|
if (!is_enabled($agentmodule_id)) {
|
||||||
# Create.
|
# Create.
|
||||||
@ -1261,6 +1302,46 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(defined($self->{'task_data'}{'review_mode'})
|
||||||
|
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_REVIEW
|
||||||
|
) {
|
||||||
|
# Notify.
|
||||||
|
my $notification = {};
|
||||||
|
$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 = ?',
|
||||||
|
safe_input('System status')
|
||||||
|
);
|
||||||
|
|
||||||
|
# Create message
|
||||||
|
my $notification_id = db_process_insert(
|
||||||
|
$self->{'dbh'},
|
||||||
|
'id_mensaje',
|
||||||
|
'tmensajes',
|
||||||
|
$notification
|
||||||
|
);
|
||||||
|
|
||||||
|
if (is_enabled($notification_id)) {
|
||||||
|
my @users = notification_get_users($self->{'dbh'}, 'System status');
|
||||||
|
my @groups = notification_get_groups($self->{'dbh'}, 'System status');
|
||||||
|
|
||||||
|
notification_set_targets(
|
||||||
|
$self->{'pa_config'}, $self->{'dbh'},
|
||||||
|
$notification_id, \@users, \@groups
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$self->call('message', "Completed", 5);
|
$self->call('message', "Completed", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,7 +683,11 @@ sub get_device_type($$) {
|
|||||||
my ($self, $device) = @_;
|
my ($self, $device) = @_;
|
||||||
|
|
||||||
if (defined($self->{'visited_devices'}->{$device})) {
|
if (defined($self->{'visited_devices'}->{$device})) {
|
||||||
|
if (defined($self->{'visited_devices'}->{$device}->{'type'})) {
|
||||||
return $self->{'visited_devices'}->{$device}->{'type'};
|
return $self->{'visited_devices'}->{$device}->{'type'};
|
||||||
|
} else {
|
||||||
|
$self->{'visited_devices'}->{$device}->{'type'} = 'host';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assume 'host' by default.
|
# Assume 'host' by default.
|
||||||
@ -1931,7 +1935,14 @@ sub scan($) {
|
|||||||
$self->call('message', "[6/6] Processing results.", 3);
|
$self->call('message', "[6/6] Processing results.", 3);
|
||||||
$self->{'step'} = STEP_PROCESSING;
|
$self->{'step'} = STEP_PROCESSING;
|
||||||
# Send agent information to Database (Discovery) or XML (satellite.).
|
# Send agent information to Database (Discovery) or XML (satellite.).
|
||||||
$self->call('report_scanned_agents', $self->{'agents_found'});
|
$self->call('report_scanned_agents');
|
||||||
|
|
||||||
|
if(defined($self->{'task_data'}{'review_mode'})
|
||||||
|
&& $self->{'task_data'}{'review_mode'} == DISCOVERY_STANDARD
|
||||||
|
) {
|
||||||
|
# Send agent information to Database (Discovery) or XML (satellite.).
|
||||||
|
$self->call('report_scanned_agents', 1);
|
||||||
|
}
|
||||||
|
|
||||||
# Done!
|
# Done!
|
||||||
$self->{'step'} = '';
|
$self->{'step'} = '';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user