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/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index 14a29c4bb2..9ee95f78cc 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', ''); @@ -102,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/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 633fbfe19f..8dcf6d9a1e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -92,27 +92,24 @@ class HostDevices extends Wizard $mode = get_parameter('mode', null); if ($mode === null) { - $this->setBreadcrum(['Host&devices']); + $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'), + ], + ] + ); + $this->printGoBackButton(); return; } @@ -120,8 +117,8 @@ class HostDevices extends Wizard if ($mode == 'importcsv') { $this->setBreadcrum( [ - 'Host&devices', - 'Import CSV', + '
Host & devices
', + '
Import CSV
', ] ); $this->printHeader(); @@ -135,10 +132,20 @@ class HostDevices extends Wizard // Do not paint breadcrum in last page. Redirected. $this->setBreadcrum( [ - 'Host&devices', - 'Net scan', + '
Host & devices
', + '
Net scan definition
', ] ); + if ($this->page == 1) { + $this->setBreadcrum( + [ + '
Host & devices
', + '
Net scan definition
', + '
Net scan features
', + ] + ); + } + $this->printHeader(); } @@ -206,6 +213,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. @@ -269,6 +277,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. @@ -306,6 +315,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'); @@ -330,6 +342,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; @@ -347,42 +360,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; @@ -398,7 +375,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); @@ -443,9 +420,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( @@ -477,11 +451,22 @@ class HostDevices extends Wizard ], ]; + // Check ACL. If user is not able to manage target task, + // redirect him to main page. + if (users_is_admin() !== true && 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; } - if (isset($this->page) + if (isset($this->page) === true && $this->page != 0 && isset($this->task['id_rt']) === false ) { @@ -522,7 +507,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 ) { @@ -610,6 +595,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) { @@ -637,6 +660,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); @@ -675,17 +713,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'][] = [ @@ -875,7 +934,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', @@ -946,7 +1010,7 @@ class HostDevices extends Wizard $form['inputs'][] = [ 'arguments' => [ 'name' => 'submit', - 'label' => __('Next'), + 'label' => __('Finish'), 'type' => 'submit', 'attributes' => 'class="sub next"', 'return' => true, @@ -958,6 +1022,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 { @@ -1012,129 +1077,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_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 288a32fc47..3afd31d332 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -124,7 +124,7 @@ class Wizard */ public function printBreadcrum() { - return '

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

'; + return '

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

'; } @@ -518,7 +518,8 @@ class Wizard * * @return void Print the full list. */ - public static function printBigButtonsList($list_data) { + public static function printBigButtonsList($list_data) + { echo ''; 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 @@ - - - + + 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 diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index f633866f65..3fb907ab06 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -356,42 +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_sql = 'INNER JOIN tnotification_source ns - ON tm.id_source = ns.id - AND ns.enabled = 1'; + $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 + 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" AND ng.id_group=0)) - ) t - %s', + AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) + ) t + WHERE %s %s', + $source_select, $source_sql, $user, $user, $user, - $read + $read, + $source_extra ); return (int) db_get_sql($sql); @@ -478,7 +495,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. @@ -496,7 +517,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..26dcc248c5 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'], @@ -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; 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; +} 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 = []; 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); 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; 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 7b6fa7c0ea..527dbe5054 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,6 +192,8 @@ sub data_consumer ($$) { vlan_cache_enabled => $task->{'vlan_enabled'}, wmi_enabled => $task->{'wmi_enabled'}, auth_strings_array => \@auth_strings, + autoconfiguration_enabled => $task->{'autoconfiguration_enabled'}, + main_event_id => $main_event, %{$pa_config} ); @@ -445,7 +449,23 @@ sub PandoraFMS::Recon::Base::create_agent($$) { $location->{'longitude'}, $location->{'latitude'} ); return undef unless defined ($agent_id) and ($agent_id > 0); - 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'}); + + # 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'}, 1]); + } + + 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." + ); + + } + $agent_learning = 1; # Create network profile modules for the agent 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, @_, };