From 29206eb3bbd2b9bd10e0dc9570cf1dabde797923 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 18 Feb 2019 11:42:55 +0100 Subject: [PATCH 01/13] Added visual changes Former-commit-id: 33ac4873763e6b0e2cf3d2ad2b25492fe5b33583 --- .../godmode/wizards/HostDevices.class.php | 32 ++++++++----------- pandora_console/images/wizard/hostdevices.svg | 4 +-- pandora_console/images/wizard/tasklist.svg | 5 ++- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 633fbfe19f..54fdeb0716 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -94,24 +94,20 @@ class HostDevices extends Wizard if ($mode === null) { $this->setBreadcrum(['Host&devices']); $this->printHeader(); - echo '
'; - echo '
'; - echo '
'; - echo 'importcsv'; - echo '
'; - echo '
'; - echo ''.__('Import CSV').''; - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo 'importcsv'; - echo '
'; - echo '
'; - echo ''.__('Escanear red').''; - echo '
'; - echo '
'; - echo '
'; + $this->printBigButtonsList( + [ + [ + 'url' => $this->url.'&mode=importcsv', + 'icon' => 'images/wizard/csv_image.svg', + 'label' => __('Import CSV'), + ], + [ + 'url' => $this->url.'&mode=netscan', + 'icon' => 'images/wizard/csv_image.svg', + 'label' => __('Net Scan'), + ], + ] + ); return; } diff --git a/pandora_console/images/wizard/hostdevices.svg b/pandora_console/images/wizard/hostdevices.svg index 1e82511472..3add7ea833 100644 --- a/pandora_console/images/wizard/hostdevices.svg +++ b/pandora_console/images/wizard/hostdevices.svg @@ -1,4 +1,4 @@ - - + + diff --git a/pandora_console/images/wizard/tasklist.svg b/pandora_console/images/wizard/tasklist.svg index 1e82511472..bac9f75f6f 100644 --- a/pandora_console/images/wizard/tasklist.svg +++ b/pandora_console/images/wizard/tasklist.svg @@ -1,4 +1,3 @@ - - - + + From a1a429aa5275081ba230fb027f508641ef5be098 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 12:14:03 +0100 Subject: [PATCH 02/13] H&D minor fixes and acl checks Former-commit-id: cec9ec899e648ab6e76716333c8ee09ca875023a --- .../godmode/wizards/HostDevices.class.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 54fdeb0716..07f8e1ee7b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -439,9 +439,6 @@ class HostDevices extends Wizard return; } - $user_groups = users_get_groups(false, 'AW', true, false, null, 'id_grupo'); - $user_groups = array_keys($user_groups); - if ($this->parseNetScan() === false) { // Error. ui_print_error_message( @@ -473,6 +470,17 @@ 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( + $config['id_usuario'], + $this->task['id_group'], + 'PM' + ) !== true + ) { + $form['form']['action'] = $this->url.'&mode=netscan&page='.($this->page - 1); + } + $this->printForm($form); return null; } @@ -954,6 +962,7 @@ function SNMPExtraShow(target) { $("#snmp_options_basic").hide(); $("#snmp_options_v3").hide(); if (document.getElementsByName("snmp_enabled")[0].checked) { + $("#snmp_extra").show(); if (target == 3) { $("#snmp_options_v3").show(); } else { From 5816320effe68eb3ba1ccdeb7913439e712da461 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 14:00:38 +0100 Subject: [PATCH 03/13] new token. autoconfiguration_enabled. discovery tasks Former-commit-id: d19c86696b73335b6977d11d5ea683131780097e --- pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 1 + pandora_console/pandoradb.sql | 1 + 2 files changed, 2 insertions(+) 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 6140297ef8..c86c9bf7d6 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 @@ -1408,6 +1408,7 @@ ALTER TABLE trecon_task ADD `snmp_enabled` int(2) unsigned default '0'; ALTER TABLE trecon_task ADD `vlan_enabled` int(2) unsigned default '0'; ALTER TABLE trecon_task ADD `wmi_enabled` tinyint(1) unsigned DEFAULT '0'; ALTER TABLE trecon_task ADD `auth_strings` text; +ALTER TABLE trecon_task ADD `autoconfiguration_enabled` tinyint(1) unsigned default '0'; -- --------------------------------------------------------------------- -- Table `twidget` AND Table `twidget_dashboard` diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 4271269fd7..ae780a5470 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -784,6 +784,7 @@ CREATE TABLE IF NOT EXISTS `trecon_task` ( `snmp_security_level` varchar(25) NOT NULL default '', `wmi_enabled` tinyint(1) unsigned DEFAULT '0', `auth_strings` text, + `autoconfiguration_enabled` tinyint(1) unsigned default '0', PRIMARY KEY (`id_rt`), KEY `recon_task_daemon` (`id_recon_server`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 46af41a2cc3663e26258fb867a993c5ad058de7a Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 14:00:55 +0100 Subject: [PATCH 04/13] support for autoconfiguration Former-commit-id: 034ed513ed9cf7efbe22720b61e8ff431ebbbc84 --- .../godmode/wizards/HostDevices.class.php | 263 +++++++----------- .../lib/PandoraFMS/DiscoveryServer.pm | 9 + pandora_server/lib/PandoraFMS/Recon/Base.pm | 1 + 3 files changed, 103 insertions(+), 170 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 07f8e1ee7b..c537ae3c8d 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -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' => ''.__('Interval').''.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' => ''.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 + ).'', + ]; + $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' => ''.__('WMI Auth. strings').''.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' => ''.__('Filter by OS').'', - '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' => ''.__('Filter by ports').''.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' => ''.__('Interval').''.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' => ''.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 - ).'', - ]; - - // 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; diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 7b6fa7c0ea..b6423a8506 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -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; diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index e819b06476..ec3eb0d853 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -166,6 +166,7 @@ sub new { snmp_timeout => 2, snmp_version => 1, subnets => [], + autoconfiguration_enabled => 0, @_, }; From 34cf0bd837e3e1758a0cfc467de4be1827262ccf Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 14:01:17 +0100 Subject: [PATCH 05/13] minor fix acl check in notifications Former-commit-id: 3ee0004f0c8ab507ed2301b77117ca945fb4e826 --- pandora_console/godmode/setup/setup_notifications.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 14a29c4bb2..28c336aa92 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -32,12 +32,6 @@ require_once $config['homedir'].'/include/functions_notifications.php'; check_login(); -if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) { - db_pandora_audit('ACL Violation', 'Trying to access Setup Management'); - include 'general/noaccess.php'; - return; -} - // AJAX actions. $source = get_parameter('source', ''); $users = get_parameter('users', ''); From 7b2e0342c1c8a95e79bedd092d1737ef17dab92c Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 14:18:58 +0100 Subject: [PATCH 06/13] Fix. notification did not reach ALL target Former-commit-id: 237e5dac34bcbe50453e0b56f0964a9d74aa7c04 --- pandora_console/include/functions_messages.php | 4 ++-- pandora_console/include/functions_notifications.php | 2 +- pandora_console/operation/messages/message_edit.php | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index f633866f65..a67bcb56e1 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -384,7 +384,7 @@ function messages_get_count( AND up.id_grupo=ng.id_group ) ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null - AND (nu.id_user="%s" OR (up.id_usuario="%s" AND ng.id_group=0)) + AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) ) t %s', $source_sql, @@ -496,7 +496,7 @@ function messages_get_overview( ) ON tm.id_mensaje=ng.id_mensaje %s WHERE utimestamp_erased is null - AND (nu.id_user="%s" OR (up.id_usuario="%s" AND ng.id_group=0)) + AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) ) t %s %s diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 0e35b7ea37..23b1a90e70 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -145,7 +145,7 @@ function check_notification_readable(int $id_message) AND up.id_grupo=ng.id_group ) ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null - AND (nu.id_user="%s" OR (up.id_usuario="%s" AND ng.id_group=0))', + AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0)', $config['id_user'], $id_message, $config['id_user'], diff --git a/pandora_console/operation/messages/message_edit.php b/pandora_console/operation/messages/message_edit.php index 6c100d7c00..f116e6609d 100644 --- a/pandora_console/operation/messages/message_edit.php +++ b/pandora_console/operation/messages/message_edit.php @@ -106,7 +106,12 @@ if ($read_message) { $dst_name = $message['id_usuario_destino']; } - echo '

Conversation with '.$user_name.'

'; + if (isset($user_name) !== true || empty($user_name) === true) { + echo '

Notification

'; + } else { + echo '

Conversation with '.$user_name.'

'; + } + echo '

Subject: '.$message['subject'].'

'; $conversation = []; From 27602d8e49500cd7694f43c6be5b5775073dc61e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 15:14:24 +0100 Subject: [PATCH 07/13] Recovered notification editor for user Former-commit-id: a4fbf05912c974ab388cde9e9237022f2bcc3277 --- pandora_console/operation/users/user_edit.php | 49 ++----------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/pandora_console/operation/users/user_edit.php b/pandora_console/operation/users/user_edit.php index 1552f2f57c..0449902172 100644 --- a/pandora_console/operation/users/user_edit.php +++ b/pandora_console/operation/users/user_edit.php @@ -14,51 +14,8 @@ // Load global vars global $config; -check_login(); - -enterprise_hook('open_meta_frame'); - -require_once $config['homedir'].'/include/functions_profile.php'; -require_once $config['homedir'].'/include/functions_users.php'; -require_once $config['homedir'].'/include/functions_groups.php'; -require_once $config['homedir'].'/include/functions_visual_map.php'; - -$meta = false; -if (enterprise_installed() && defined('METACONSOLE')) { - $meta = true; -} - -$id = get_parameter_get('id', $config['id_user']); -// ID given as parameter -$status = get_parameter('status', -1); -// Flag to print action status message -$user_info = get_user_info($id); -$id = $user_info['id_user']; -// This is done in case there are problems with uppercase/lowercase (MySQL auth has that problem) -if ((!check_acl($config['id_user'], users_get_groups($id), 'UM')) - and ($id != $config['id_user']) -) { - db_pandora_audit('ACL Violation', 'Trying to view a user without privileges'); - include 'general/noaccess.php'; - exit; -} - -// If current user is editing himself or if the user has UM (User Management) rights on any groups the user is part of AND the authorization scheme allows for users/admins to update info -if (($config['id_user'] == $id || check_acl($config['id_user'], users_get_groups($id), 'UM')) && $config['user_can_update_info']) { - $view_mode = false; -} else { - $view_mode = true; -} - -// Header -if ($meta) { - user_meta_print_header(); - $url = 'index.php?sec=advanced&sec2=advanced/users_setup&tab=user_edit'; -} else { - ui_print_page_header(__('User detail editor'), 'images/op_workspace.png', false, '', false, ''); - $url = 'index.php?sec=workspace&sec2=operation/users/user_edit'; -} - +// Load the header +require $config['homedir'].'/operation/users/user_edit_header.php'; // Update user info if (isset($_GET['modified']) && !$view_mode) { @@ -535,7 +492,7 @@ $table->rowclass[] = ''; $table->rowstyle[] = ''; $table->data[] = $data; -echo '
'; +echo ''; html_print_table($table); From 37f6da9aa8df93525b87bd37968a30eb6f9a6dba Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 15:36:51 +0100 Subject: [PATCH 08/13] recovered. changes from 0b72571c7cb47056711365750f9035012ab88af6 [formerly f3a8cdd6923834443ed7223d1e6ad7776b861184] Former-commit-id: 591e002043d2bae2382c8a91c437057fd2b809c7 --- pandora_console/include/db/mysql.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index 49ffb2d101..66366c1289 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -706,6 +706,7 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa $i = 1; $max = count($values); foreach ($values as $field => $value) { + $negative = false; if (is_numeric($field)) { // User provide the exact operation to do $query .= $value; @@ -718,6 +719,11 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa continue; } + if ($field[0] == '!') { + $negative = true; + $field = substr($field, 1); + } + if ($field[0] != '`') { // If the field is as ., don't scape. if (strstr($field, '.') === false) { @@ -732,7 +738,8 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa } else if (is_float($value) || is_double($value)) { $query .= sprintf('%s = %f', $field, $value); } else if (is_array($value)) { - $query .= sprintf('%s IN ("%s")', $field, implode('", "', $value)); + $not = $negative ? ' NOT ' : ''; + $query .= sprintf('%s %sIN ("%s")', $field, $not, implode('", "', $value)); } else { if ($value === '') { // Search empty string From bb83f4ba4a316ff113d38d0d6b90108db2ebf9f1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 17:08:23 +0100 Subject: [PATCH 09/13] avoid to show notification if disabled by user Former-commit-id: d00b09c9e608c51223f7192ad85408976fac5baa --- .../godmode/setup/setup_notifications.php | 4 ++++ .../include/functions_messages.php | 19 +++++++++++++++---- .../include/functions_notifications.php | 8 +++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 28c336aa92..9ee95f78cc 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -96,6 +96,10 @@ if (get_parameter('check_new_notifications', 0)) { return; } + if (messages_get_count() == 0) { + return; + } + $messages = messages_get_overview( 'timestamp', 'ASC', diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index a67bcb56e1..9266733a68 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -365,9 +365,16 @@ function messages_get_count( if ($ignore_source === true) { $source_sql = ''; } else { - $source_sql = 'INNER JOIN tnotification_source ns - ON tm.id_source = ns.id - AND ns.enabled = 1'; + $source_sql = sprintf( + 'INNER JOIN tnotification_source ns + ON tm.id_source = ns.id + AND ns.enabled = 1 + INNER JOIN tnotification_source_user nsu + ON nsu.id_source=ns.id + AND nsu.enabled = 1 + AND nsu.id_user = "%s"', + $user + ); } $sql = sprintf( @@ -478,7 +485,11 @@ function messages_get_overview( if ($incl_source_info) { $source_fields = ', tns.*'; $source_join = 'INNER JOIN tnotification_source tns - ON tns.id=tm.id_source'; + ON tns.id=tm.id_source + INNER JOIN tnotification_source_user nsu + ON nsu.id_source=tns.id + AND nsu.enabled = 1 + OR tns.enabled = 1'; } // Using distinct because could be double assignment due group/user. diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 23b1a90e70..26dcc248c5 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -525,7 +525,7 @@ function notifications_build_user_enable_return($status, $enabled) function notifications_get_user_label_status($source, $user, $label) { // If not enabled, it cannot be modificable. - if (!$source['enabled'] || !$source[$label]) { + if (!$source['enabled']) { return notifications_build_user_enable_return(false, false); } @@ -551,7 +551,10 @@ function notifications_get_user_label_status($source, $user, $label) ); // No group found, return no permissions. $value = empty($common_groups) ? false : $source[$label]; - return notifications_build_user_enable_return($value, false); + return notifications_build_user_enable_return( + $value, + false + ); } @@ -570,7 +573,6 @@ function notifications_set_user_label_status($source, $user, $label, $value) $source_info = notifications_get_all_sources(['id' => $source]); if (!isset($source_info[0]) || !$source_info[0]['enabled'] - || !$source_info[0][$label] || !$source_info[0]['user_editable'] ) { return false; From af110f4820bbb0ac04ffe2262948c6b99b55bf49 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 18:13:22 +0100 Subject: [PATCH 10/13] minor fix notification direct assignment Former-commit-id: 59ffb2338377ac2c3270681e6905f5d853add16b --- .../include/functions_messages.php | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 9266733a68..3fb907ab06 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -356,49 +356,59 @@ function messages_get_count( if (!empty($incl_read)) { // Do not filter. - $read = ''; + $read = ' 1=1 '; } else { // Retrieve only unread messages. - $read = 'where t.read is null'; + $read = ' t.read is null'; } if ($ignore_source === true) { + $source_select = ''; $source_sql = ''; + $source_extra = ''; } else { + $source_select = ',IF(ns.user_editable,nsu.enabled,ns.enabled) as enabled'; + + // Row in tnotification_source_user could exist or not. $source_sql = sprintf( - 'INNER JOIN tnotification_source ns - ON tm.id_source = ns.id - AND ns.enabled = 1 - INNER JOIN tnotification_source_user nsu - ON nsu.id_source=ns.id - AND nsu.enabled = 1 - AND nsu.id_user = "%s"', + 'INNER JOIN ( + tnotification_source ns + LEFT JOIN tnotification_source_user nsu + ON ns.id=nsu.id_source + AND nsu.id_user="test") + ON tm.id_source=ns.id', $user ); + $source_extra = 'AND (t.enabled=1 OR t.enabled is null)'; } $sql = sprintf( - 'SELECT count(*) FROM ( - SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" - FROM tmensajes tm - %s - LEFT JOIN tnotification_user nu - ON tm.id_mensaje=nu.id_mensaje - AND nu.id_user="%s" - LEFT JOIN (tnotification_group ng - INNER JOIN tusuario_perfil up - ON ng.id_group=up.id_grupo - AND up.id_grupo=ng.id_group - ) ON tm.id_mensaje=ng.id_mensaje + 'SELECT count(*) as "n" FROM ( + SELECT + tm.*, + utimestamp_read > 0 as "read" + %s + FROM tmensajes tm + %s + LEFT JOIN tnotification_user nu + ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" + LEFT JOIN (tnotification_group ng + INNER JOIN tusuario_perfil up + ON ng.id_group=up.id_grupo + AND up.id_grupo=ng.id_group) + ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) - ) t - %s', + ) t + WHERE %s %s', + $source_select, $source_sql, $user, $user, $user, - $read + $read, + $source_extra ); return (int) db_get_sql($sql); From 7f0b676e0f03e91c6a51d5e5ce017f62f7f003fb Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 19:50:13 +0100 Subject: [PATCH 11/13] Discovery tasks. Extended events. Autoconfigure detected agents. Former-commit-id: da2282082606c970dbace453193eb0a7e4089731 --- .../godmode/wizards/HostDevices.class.php | 4 +++ pandora_server/lib/PandoraFMS/Core.pm | 32 ++++++++++++++++--- .../lib/PandoraFMS/DiscoveryServer.pm | 17 ++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index c537ae3c8d..bf4eb8f73d 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -305,6 +305,9 @@ class HostDevices extends Wizard } $id_network_profile = get_parameter('id_network_profile', null); + $autoconf_enabled = get_parameter_switch( + 'autoconfiguration_enabled' + ); $snmp_enabled = get_parameter_switch('snmp_enabled'); $os_detect = get_parameter_switch('os_detect'); $parent_detection = get_parameter_switch('parent_detection'); @@ -329,6 +332,7 @@ class HostDevices extends Wizard $this->task['snmp_community'] = $community; } + $this->task['autoconfiguration_enabled'] = $autoconf_enabled; $this->task['id_network_profile'] = $id_network_profile; $this->task['snmp_enabled'] = $snmp_enabled; $this->task['os_detect'] = $os_detect; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index ba9ddbeae8..84f16b5362 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -179,6 +179,7 @@ our @EXPORT = qw( pandora_evaluate_alert pandora_evaluate_snmp_alerts pandora_event + pandora_extended_event pandora_execute_alert pandora_execute_action pandora_exec_forced_alerts @@ -3270,11 +3271,11 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - db_do ($dbh, 'INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) + my $event_id = db_insert ($dbh, 'id_evento','INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, $module_data, $module_status); - + # Do not write to the event file - return if ($pa_config->{'event_file'} eq ''); + return $event_id if ($pa_config->{'event_file'} eq ''); # Add a header when the event file is created my $header = undef; @@ -3285,7 +3286,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { # Open the event file for writing if (! open (EVENT_FILE, '>>' . $pa_config->{'event_file'})) { logger($pa_config, "Error opening event file " . $pa_config->{'event_file'} . ": $!", 10); - return; + return $event_id; } # Resolve ids @@ -3308,6 +3309,29 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$$$) { print EVENT_FILE "$agent_name,".safe_output($group_name)."," . safe_output ($evento) . ",$timestamp,$event_status,$utimestamp,$event_type,".safe_output($module_name).",".safe_output($alert_name).",$severity,".safe_output($comment).",".safe_output($module_tags).",$source,$id_extra,$user_name,".safe_output($critical_instructions).",".safe_output($warning_instructions).",".safe_output($unknown_instructions).",$ack_utimestamp\n"; close (EVENT_FILE); + + return $event_id; +} + +########################################################################## +=head2 C<< pandora_extended_event (I<$pa_config>, I<$dbh>, I<$event_id>, I<$description>) >> + +Creates an extended event linked to an existing main event id. + +=cut +########################################################################## +sub pandora_extended_event($$$$) { + my ($pa_config, $dbh, $event_id, $description) = @_; + + return unless defined($event_id) && "$event_id" ne "" && $event_id > 0; + + return db_do( + $dbh, + 'INSERT INTO tevent_extended (id_evento, utimestamp, description) VALUES (?,?,?)', + $event_id, + time(), + safe_input($description) + ); } ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index b6423a8506..8911d353e3 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -163,6 +163,8 @@ sub data_consumer ($$) { @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 $recon = new PandoraFMS::Recon::Base( communities => \@communities, dbh => $dbh, @@ -190,7 +192,8 @@ sub data_consumer ($$) { vlan_cache_enabled => $task->{'vlan_enabled'}, wmi_enabled => $task->{'wmi_enabled'}, auth_strings_array => \@auth_strings, - autoconfigure_agent => $task->{'autoconfiguration_enabled'} + autoconfiguration_enabled => $task->{'autoconfiguration_enabled'}, + main_event_id => $main_event, %{$pa_config} ); @@ -451,10 +454,18 @@ sub PandoraFMS::Recon::Base::create_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'}]); + enterprise_hook('autoconfigure_agent', [$self->{'pa_config'}, $host_name, $agent_id, $agent_data, $self->{'dbh'}, $agent_id]); + } + + if (defined($self->{'main_event_id'})) { + my $addresses_str = join(',', safe_output($self->get_addresses($device))); + pandora_extended_event( + $self->{'pa_config'}, $self->{'dbh'}, $self->{'main_event_id'}, + "[Discovery] New " . safe_output($self->get_device_type($device)) . " found " . $host_name . " (" . $addresses_str . ") Agent $agent_id." + ); + } - 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; # Create network profile modules for the agent From 938408ada909387a37054cf4b57de43640663956 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 19 Feb 2019 08:58:30 +0100 Subject: [PATCH 12/13] Added wizard Former-commit-id: d47389f000b9295c21d9a56ed0138913d0045b76 --- .../godmode/wizards/HostDevices.class.php | 20 +++++-- .../godmode/wizards/Wizard.main.php | 7 ++- pandora_console/include/styles/discovery.css | 59 ++++++++++++------- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index c537ae3c8d..2dd29d923c 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -92,7 +92,7 @@ class HostDevices extends Wizard $mode = get_parameter('mode', null); if ($mode === null) { - $this->setBreadcrum(['Host&devices']); + $this->setBreadcrum(['']); $this->printHeader(); $this->printBigButtonsList( [ @@ -117,8 +117,8 @@ class HostDevices extends Wizard if ($mode == 'importcsv') { $this->setBreadcrum( [ - 'Host&devices', - 'Import CSV', + '', + '', ] ); $this->printHeader(); @@ -132,10 +132,20 @@ class HostDevices extends Wizard // Do not paint breadcrum in last page. Redirected. $this->setBreadcrum( [ - 'Host&devices', - 'Net scan', + '', + '', ] ); + if ($this->page == 1) { + $this->setBreadcrum( + [ + '', + '', + '', + ] + ); + } + $this->printHeader(); } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 709e601fa5..2f58bea91e 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -108,7 +108,7 @@ class Wizard */ public function printBreadcrum() { - return '

'.implode(' > ', $this->breadcrum).'

'; + return '

'.implode('', $this->breadcrum).'

'; } @@ -502,9 +502,12 @@ class Wizard * * @return void Print the full list. */ - public static function printBigButtonsList($list_data) { + public static function printBigButtonsList($list_data) + { echo '
    '; array_map('self::printBigButtonElement', $list_data); echo '
'; } + + } diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 930dbd047d..ad85fd606c 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -41,26 +41,6 @@ div.data_container:hover { /* * TODO: This may be at hostdevices.css */ -#contenedor_principal { - height: auto; - position: relative; - margin: auto; -} -#contenedor_imagen_texto { - width: 11%; - height: auto; - position: relative; - display: inline-block; - vertical-align: top; - overflow: hidden; - margin-right: 5%; -} -#imagen { - width: 15%; - height: auto; - position: relative; - display: inline; -} .texto { height: auto; text-align: center; @@ -70,3 +50,42 @@ div.data_container:hover { text-decoration: none; font-size: 24px; } +.text_color { + color: white; + margin-left: 25px; +} +.text_color:hover { + text-decoration: none; +} +.arrow_box { + display: inline-block; + position: relative; + background: #82b92e; + width: 15%; + padding: 1%; + margin-left: 20px; + margin-bottom: 10px; +} +.arrow_box:after, +.arrow_box:before { + top: 50%; + border: solid transparent; + content: " "; + height: 0; + width: 0; + position: absolute; + pointer-events: none; +} + +.arrow_box:after { + left: 0%; + border-left-color: white; + border-width: 20px; + margin-top: -20px; +} +.arrow_box:before { + left: 100%; + border-left-color: #82b92e; + border-width: 20px; + margin-top: -20px; +} From 906ba091e1135bae6ffa4b33faf5625730ed2e5b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Feb 2019 10:37:09 +0100 Subject: [PATCH 13/13] minor fixes/changes DiscoveryServer Former-commit-id: 8273727109628f99fc86c125c9b6f62a416c07f1 --- pandora_server/lib/PandoraFMS/DiscoveryServer.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index 8911d353e3..527dbe5054 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -454,7 +454,7 @@ sub PandoraFMS::Recon::Base::create_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'}, $agent_id]); + enterprise_hook('autoconfigure_agent', [$self->{'pa_config'}, $host_name, $agent_id, $agent_data, $self->{'dbh'}, 1]); } if (defined($self->{'main_event_id'})) {