support for autoconfiguration

Former-commit-id: 034ed513ed9cf7efbe22720b61e8ff431ebbbc84
This commit is contained in:
fbsanchez 2019-02-18 14:00:55 +01:00
parent 5816320eff
commit 46af41a2cc
3 changed files with 103 additions and 170 deletions

View File

@ -109,6 +109,7 @@ class HostDevices extends Wizard
]
);
$this->printGoBackButton();
return;
}
@ -202,6 +203,7 @@ class HostDevices extends Wizard
$server_id = get_parameter('id_recon_server', '');
$network = get_parameter('network', '');
$id_group = get_parameter('id_group', '');
$interval = get_parameter('interval', 0);
if (isset($task_id) === true) {
// We're updating this task.
@ -265,6 +267,7 @@ class HostDevices extends Wizard
$this->task['subnet'] = $network;
$this->task['id_recon_server'] = $server_id;
$this->task['id_group'] = $id_group;
$this->task['interval_sweep'] = $interval;
if (isset($this->task['id_rt']) === false) {
// Create.
@ -343,42 +346,6 @@ class HostDevices extends Wizard
$this->task['snmp_security_level'] = $snmp_security_level;
$this->task['auth_strings'] = $auth_strings;
// Update.
$res = db_process_sql_update(
'trecon_task',
$this->task,
['id_rt' => $this->task['id_rt']]
);
return true;
}
if ($this->page == 3) {
// Interval and schedules.
// By default manual if not defined.
$id_rt = get_parameter('task', -1);
$task = db_get_row(
'trecon_task',
'id_rt',
$id_rt
);
if ($task !== false) {
$this->task = $task;
} else {
$this->msg = __('Failed to find network scan task.');
return false;
}
$interval = get_parameter('interval', 0);
$id_os = get_parameter('id_os', 0);
$recon_ports = get_parameter('recon_ports', '');
$this->task['id_os'] = $id_os;
$this->task['interval_sweep'] = $interval;
$this->task['recon_ports'] = $recon_ports;
if ($this->task['disabled'] == 2) {
// Wizard finished.
$this->task['disabled'] = 0;
@ -394,7 +361,7 @@ class HostDevices extends Wizard
return true;
}
if ($this->page == 4) {
if ($this->page == 3) {
// Wizard ended. Load data and return control to Discovery.
$id_rt = get_parameter('task', -1);
@ -472,7 +439,7 @@ class HostDevices extends Wizard
// Check ACL. If user is not able to manage target task,
// redirect him to main page.
if (users_is_admin() || check_acl(
if (users_is_admin() !== true && check_acl(
$config['id_usuario'],
$this->task['id_group'],
'PM'
@ -485,7 +452,7 @@ class HostDevices extends Wizard
return null;
}
if (isset($this->page)
if (isset($this->page) === true
&& $this->page != 0
&& isset($this->task['id_rt']) === false
) {
@ -526,7 +493,7 @@ class HostDevices extends Wizard
// -------------------------------.
// Page 0. wizard starts HERE.
// -------------------------------.
if (!isset($this->page) || $this->page == 0) {
if (isset($this->page) === true || $this->page == 0) {
if (isset($this->page) === false
|| $this->page == 0
) {
@ -614,6 +581,44 @@ class HostDevices extends Wizard
],
];
// Interval and schedules.
$interv_manual = 0;
if ((int) $this->task['interval_sweep'] == 0) {
$interv_manual = 1;
}
// Schedule.
$form['inputs'][] = [
'label' => '<b>'.__('Interval').'</b>'.ui_print_help_tip(
__('Manual interval means that it will be executed only On-demand'),
true
),
'arguments' => [
'type' => 'select',
'selected' => $interv_manual,
'fields' => [
0 => __('Defined'),
1 => __('Manual'),
],
'name' => 'interval_manual_defined',
'return' => true,
],
'extra' => '<span id="interval_manual_container">'.html_print_extended_select_for_time(
'interval',
$this->task['interval_sweep'],
'',
'',
'0',
false,
true,
false,
false
).ui_print_help_tip(
__('The minimum recomended interval for Recon Task is 5 minutes'),
true
).'</span>',
];
$str = __('Next');
if (isset($this->task['id_rt']) === true) {
@ -641,6 +646,21 @@ class HostDevices extends Wizard
'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url,
];
$form['js'] = '
$("select#interval_manual_defined").change(function() {
if ($("#interval_manual_defined").val() == 1) {
$("#interval_manual_container").hide();
$("#text-interval_text").val(0);
$("#hidden-interval").val(0);
}
else {
$("#interval_manual_container").show();
$("#text-interval_text").val(10);
$("#hidden-interval").val(600);
$("#interval_units").val(60);
}
}).change();';
// XXX: Could be improved validating inputs before continue (JS)
// Print NetScan page 0.
$this->printForm($form);
@ -679,17 +699,38 @@ class HostDevices extends Wizard
$form['inputs'][] = [
'label' => __('Module template'),
'arguments' => [
'name' => 'id_network_profile',
'type' => 'select_from_sql',
'sql' => 'SELECT id_np, name
'name' => 'id_network_profile',
'type' => 'select_from_sql',
'sql' => 'SELECT id_np, name
FROM tnetwork_profile
ORDER BY name',
'return' => true,
'selected' => $this->task['id_network_profile'],
'return' => true,
'selected' => $this->task['id_network_profile'],
'nothing_value' => 0,
'nothing' => __('None'),
],
];
if (enterprise_installed() === true) {
// Input: Enable auto configuration.
$form['inputs'][] = [
'label' => __('Apply autoconfiguration rules').ui_print_help_tip(
__(
'System is able to auto configure detected host & devices by applying your defined configuration rules.'
),
true
),
'arguments' => [
'name' => 'autoconfiguration_enabled',
'type' => 'switch',
'return' => true,
'value' => (isset($this->task['autoconfiguration_enabled'])) ? $this->task['autoconfiguration_enabled'] : 0,
],
];
}
// Feature configuration.
// Input: SNMP enabled.
$form['inputs'][] = [
@ -879,7 +920,12 @@ class HostDevices extends Wizard
'hidden' => 1,
'block_content' => [
[
'label' => __('WMI Auth. strings'),
'label' => '<b>'.__('WMI Auth. strings').'</b>'.ui_print_help_tip(
__(
'Auth strings must be defined as user%pass, comma separated as many you need.'
),
true
),
'arguments' => [
'name' => 'auth_strings',
'type' => 'text',
@ -950,7 +996,7 @@ class HostDevices extends Wizard
$form['inputs'][] = [
'arguments' => [
'name' => 'submit',
'label' => __('Next'),
'label' => __('Finish'),
'type' => 'submit',
'attributes' => 'class="sub next"',
'return' => true,
@ -1017,129 +1063,6 @@ $(function() {
}
if ($this->page == 2) {
// Interval and schedules.
$interv_manual = 0;
if ((int) $this->task['interval_sweep'] == 0) {
$interv_manual = 1;
}
// Filter: OS.
$form['inputs'][] = [
'label' => '<b>'.__('Filter by OS').'</b>',
'arguments' => [
'type' => 'select_from_sql',
'sql' => 'SELECT id_os, name
FROM tconfig_os
ORDER BY name',
'name' => 'id_os',
'return' => 'true',
'nothing' => __('Any'),
'selected' => $this->task['id_os'],
],
];
// Filter: Ports.
$form['inputs'][] = [
'label' => '<b>'.__('Filter by ports').'</b>'.ui_print_help_tip(
__('Ports defined like: 80 or 80,443,512 or even 0-1024 (Like Nmap command line format). If dont want to do a sweep using portscan, left it in blank'),
true
),
'arguments' => [
'type' => 'text',
'name' => 'recon_ports',
'return' => 'true',
'recon_ports' => $this->task['recon_ports'],
],
];
// Schedule.
$form['inputs'][] = [
'label' => '<b>'.__('Interval').'</b>'.ui_print_help_tip(
__('Manual interval means that it will be executed only On-demand'),
true
),
'arguments' => [
'type' => 'select',
'selected' => $interv_manual,
'fields' => [
0 => __('Defined'),
1 => __('Manual'),
],
'name' => 'interval_manual_defined',
'return' => true,
],
'extra' => '<span id="interval_manual_container">'.html_print_extended_select_for_time(
'interval',
$this->task['interval_sweep'],
'',
'',
'0',
false,
true,
false,
false
).ui_print_help_tip(
__('The minimum recomended interval for Recon Task is 5 minutes'),
true
).'</span>',
];
// Hidden, id_rt.
$form['inputs'][] = [
'arguments' => [
'name' => 'task',
'value' => $this->task['id_rt'],
'type' => 'hidden',
'return' => true,
],
];
// Hidden, page.
$form['inputs'][] = [
'arguments' => [
'name' => 'page',
'value' => ($this->page + 1),
'type' => 'hidden',
'return' => true,
],
];
// Submit button.
$form['inputs'][] = [
'arguments' => [
'name' => 'submit',
'label' => __('Next'),
'type' => 'submit',
'attributes' => 'class="sub next"',
'return' => true,
],
];
$form['form'] = [
'method' => 'POST',
'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'],
];
$form['js'] = '
$("select#interval_manual_defined").change(function() {
if ($("#interval_manual_defined").val() == 1) {
$("#interval_manual_container").hide();
$("#text-interval_text").val(0);
$("#hidden-interval").val(0);
}
else {
$("#interval_manual_container").show();
$("#text-interval_text").val(10);
$("#hidden-interval").val(600);
$("#interval_units").val(60);
}
}).change();';
$this->printForm($form);
return null;
}
if ($this->page == 3) {
if ($this->task['id_rt']) {
// 0 - Is OK.
$this->result = 0;

View File

@ -190,6 +190,7 @@ sub data_consumer ($$) {
vlan_cache_enabled => $task->{'vlan_enabled'},
wmi_enabled => $task->{'wmi_enabled'},
auth_strings_array => \@auth_strings,
autoconfigure_agent => $task->{'autoconfiguration_enabled'}
%{$pa_config}
);
@ -445,6 +446,14 @@ sub PandoraFMS::Recon::Base::create_agent($$) {
$location->{'longitude'}, $location->{'latitude'}
);
return undef unless defined ($agent_id) and ($agent_id > 0);
# Autoconfigure agent
if (defined($self->{'autoconfiguration_enabled'}) && $self->{'autoconfiguration_enabled'} == 1) {
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'}, $host_name, $agent_id, $agent_data, $self->{'dbh'}]);
}
pandora_event($self->{'pa_config'}, "[RECON] New " . safe_output($self->get_device_type($device)) . " found (" . join(',', safe_output($self->get_addresses($device))) . ").", $self->{'group_id'}, $agent_id, 2, 0, 0, 'recon_host_detected', 0, $self->{'dbh'});
$agent_learning = 1;

View File

@ -166,6 +166,7 @@ sub new {
snmp_timeout => 2,
snmp_version => 1,
subnets => [],
autoconfiguration_enabled => 0,
@_,
};