From 27da41c7dabc362652b832bd895d7f5dcbca27dc Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 Feb 2019 14:39:01 +0100 Subject: [PATCH 01/50] WIP Host&devices Former-commit-id: cc18e55a30f72c606bb5b5736a5fa771987e0a45 --- pandora_console/godmode/menu.php | 7 + pandora_console/godmode/servers/discovery.php | 67 ++ .../godmode/wizards/HostDevices.class.php | 835 ++++++++++++++++++ .../godmode/wizards/Wizard.interface.php | 16 + .../godmode/wizards/hostDevices.png | Bin 0 -> 5251 bytes pandora_console/godmode/wizards/index.php | 7 + 6 files changed, 932 insertions(+) create mode 100755 pandora_console/godmode/servers/discovery.php create mode 100755 pandora_console/godmode/wizards/HostDevices.class.php create mode 100755 pandora_console/godmode/wizards/Wizard.interface.php create mode 100755 pandora_console/godmode/wizards/hostDevices.png create mode 100755 pandora_console/godmode/wizards/index.php diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 69ec49cfce..7722463c65 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -200,11 +200,18 @@ if (check_acl($config['id_user'], 0, 'AW') || check_acl($config['id_user'], 0, ' $menu_godmode['gservers']['id'] = 'god-servers'; $sub = []; + if (check_acl($config['id_user'], 0, 'PM')) { + $sub['godmode/servers/discovery']['text'] = __('Discover'); + $sub['godmode/servers/discovery']['id'] = 'Discover'; + } + if (check_acl($config['id_user'], 0, 'AW')) { $sub['godmode/servers/modificar_server']['text'] = __('Manage servers'); $sub['godmode/servers/modificar_server']['id'] = 'Manage servers'; } + + // This subtabs are only for Pandora Admin if (check_acl($config['id_user'], 0, 'PM')) { enterprise_hook('ha_cluster'); diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php new file mode 100755 index 0000000000..557b7bf5b3 --- /dev/null +++ b/pandora_console/godmode/servers/discovery.php @@ -0,0 +1,67 @@ +run(); + // TODO: Here we'll controlle if return is a valid recon task id. + exit(); +} + +if ($classname_selected === null) { + // Load classes and print selector. + echo ''; $output .= ''; $output .= $js; + if ($return === false) { + echo $output; + } + return $output; } From 8acb658266ac79153027f01c62647c325c52099e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 14 Feb 2019 13:27:49 +0100 Subject: [PATCH 08/50] WIP: H&D Former-commit-id: 7e74f1330b7e5cfdab3757ec62523942a1b4fe9f --- pandora_console/godmode/servers/discovery.php | 1 - .../godmode/wizards/HostDevices.class.php | 182 ++++++++++++++++-- .../godmode/wizards/Wizard.main.php | 81 +++++++- pandora_console/include/styles/wizard.css | 11 ++ 4 files changed, 254 insertions(+), 21 deletions(-) create mode 100644 pandora_console/include/styles/wizard.css diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index e02d62783e..39c31b9465 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -52,7 +52,6 @@ if ($classname_selected !== null) { $wiz = new $classname_selected($page); $wiz->run(); // TODO: Here we'll controlle if return is a valid recon task id. - exit(); } if ($classname_selected === null) { diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 2b12530453..421ea07484 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -1,6 +1,7 @@ page) === false - || $this->page == 0 - ) { - $form = []; + if (isset($this->page) && $this->page == 1) { + // Parse page 0 responses. + $this->parseNetScan(); + } - // Input task name. - // Input Discovery Server. - // Input Network. - // Input interval. - // Input group. - $form['inputs'] = [ - [ - 'label' => __('Task name'), + if (!isset($this->page) || $this->page == 0) { + // Interval. + $interv_manual = 0; + if ((int) $interval == 0) { + $interv_manual = 1; + } + + if (isset($this->page) === false + || $this->page == 0 + ) { + $form = []; + + // Input task name. + $form['inputs'][] = [ + 'label' => ''.__('Task name').'', + 'arguments' => [ + 'name' => 'taskname', + 'value' => '', + 'type' => 'text', + 'size' => 25, + ], + ]; + + // Input Discovery Server. + $form['inputs'][] = [ + 'label' => ''.__('Discovery server').''.ui_print_help_tip( + __('You must select a Discovery Server to run the Task, otherwise the Recon Task will never run'), + true + ), + 'arguments' => [ + 'type' => 'select_from_sql', + 'sql' => sprintf( + 'SELECT id_server, name + FROM tserver + WHERE server_type = %d + ORDER BY name', + SERVER_TYPE_DISCOVERY + ), + 'name' => 'id_recon_server', + 'selected' => 0, + 'return' => true, + ], + ]; + + // Input Network. + $form['inputs'][] = [ + + 'label' => ''.__('Network').''.ui_print_help_tip( + __('You can specify several networks, separated by commas, for example: 192.168.50.0/24,192.168.60.0/24'), + true + ), 'arguments' => [ 'name' => 'name', 'value' => '', 'type' => 'text', 'size' => 25, ], - ], - ]; + ]; - $this->printForm($form); + // Input interval. + $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', + $interval, + '', + '', + '0', + false, + true, + false, + false + ).ui_print_help_tip( + __('The minimum recomended interval for Recon Task is 5 minutes'), + true + ).'', + ]; + + // Input Group. + $form['inputs'][] = [ + 'label' => ''.__('Group').'', + 'arguments' => [ + 'name' => 'id_group', + 'privilege' => 'PM', + 'type' => 'select_groups', + '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' => '#', + ]; + + $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();'; + + // Print NetScan page 0. + $this->printForm($form); + } + } + + if ($this->page == 1) { + // Page 1. + echo 'page 1!'; } if ($this->page == 100) { diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 743d82dd11..e8722ea8e8 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -45,6 +45,7 @@ class Wizard */ public function run() { + ui_require_css_file('wizard'); } @@ -214,6 +215,77 @@ class Wizard ((isset($data['options']) === true) ? $data['options'] : false) ); + case 'select': + return html_print_select( + $data['fields'], + $data['name'], + ((isset($data['selected']) === true) ? $data['selected'] : ''), + ((isset($data['script']) === true) ? $data['script'] : ''), + ((isset($data['nothing']) === true) ? $data['nothing'] : ''), + ((isset($data['nothing_value']) === true) ? $data['nothing_value'] : 0), + ((isset($data['return']) === true) ? $data['return'] : false), + ((isset($data['multiple']) === true) ? $data['multiple'] : false), + ((isset($data['sort']) === true) ? $data['sort'] : true), + ((isset($data['class']) === true) ? $data['class'] : ''), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['style']) === true) ? $data['style'] : false), + ((isset($data['option_style']) === true) ? $data['option_style'] : false), + ((isset($data['size']) === true) ? $data['size'] : false), + ((isset($data['modal']) === true) ? $data['modal'] : false), + ((isset($data['message']) === true) ? $data['message'] : ''), + ((isset($data['select_all']) === true) ? $data['select_all'] : false) + ); + + case 'select_from_sql': + return html_print_select_from_sql( + $data['sql'], + $data['name'], + ((isset($data['selected']) === true) ? $data['selected'] : ''), + ((isset($data['script']) === true) ? $data['script'] : ''), + ((isset($data['nothing']) === true) ? $data['nothing'] : ''), + ((isset($data['nothing_value']) === true) ? $data['nothing_value'] : '0'), + ((isset($data['return']) === true) ? $data['return'] : false), + ((isset($data['multiple']) === true) ? $data['multiple'] : false), + ((isset($data['sort']) === true) ? $data['sort'] : true), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['style']) === true) ? $data['style'] : false), + ((isset($data['size']) === true) ? $data['size'] : false), + ((isset($data['trucate_size']) === true) ? $data['trucate_size'] : GENERIC_SIZE_TEXT) + ); + + case 'select_groups': + return html_print_select_groups( + ((isset($data['id_user']) === true) ? $data['id_user'] : false), + ((isset($data['privilege']) === true) ? $data['privilege'] : 'AR'), + ((isset($data['returnAllGroup']) === true) ? $data['returnAllGroup'] : true), + $data['name'], + ((isset($data['selected']) === true) ? $data['selected'] : ''), + ((isset($data['script']) === true) ? $data['script'] : ''), + ((isset($data['nothing']) === true) ? $data['nothing'] : ''), + ((isset($data['nothing_value']) === true) ? $data['nothing_value'] : 0), + ((isset($data['return']) === true) ? $data['return'] : false), + ((isset($data['multiple']) === true) ? $data['multiple'] : false), + ((isset($data['sort']) === true) ? $data['sort'] : true), + ((isset($data['class']) === true) ? $data['class'] : ''), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['style']) === true) ? $data['style'] : false), + ((isset($data['option_style']) === true) ? $data['option_style'] : false), + ((isset($data['id_group']) === true) ? $data['id_group'] : false), + ((isset($data['keys_field']) === true) ? $data['keys_field'] : 'id_grupo'), + ((isset($data['strict_user']) === true) ? $data['strict_user'] : false), + ((isset($data['delete_groups']) === true) ? $data['delete_groups'] : false), + ((isset($data['include_groups']) === true) ? $data['include_groups'] : false) + ); + + case 'submit': + return html_print_submit_button( + ((isset($data['label']) === true) ? $data['label'] : 'OK'), + ((isset($data['name']) === true) ? $data['name'] : ''), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['attributes']) === true) ? $data['attributes'] : ''), + ((isset($data['return']) === true) ? $data['return'] : false) + ); + default: // Ignore. break; @@ -239,16 +311,19 @@ class Wizard $output = '
'; - $ouput .= '
    '; + $output .= '
      '; foreach ($inputs as $input) { $output .= '
    • '; - $output .= $this->printInput($input['arguments']).'
    • '; + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + $output .= ''; } $output .= '
    '; $output .= ''; - $output .= $js; + $output .= ''; if ($return === false) { echo $output; diff --git a/pandora_console/include/styles/wizard.css b/pandora_console/include/styles/wizard.css new file mode 100644 index 0000000000..26f4ac0385 --- /dev/null +++ b/pandora_console/include/styles/wizard.css @@ -0,0 +1,11 @@ +ul.wizard { +} + +ul.wizard li { + padding: 10px; +} + +ul.wizard li > label { + width: 250px; + display: inline-block; +} From 0d7ea0d056030ffd5d2300a23ab6c122f72133d5 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 14 Feb 2019 16:56:03 +0100 Subject: [PATCH 09/50] Added CSV report and copy a lot of not revisted code Former-commit-id: 005362b157450862501963770df3fd0419bc573a --- .../godmode/wizards/HostDevices.class.php | 200 ++++++++++++++++-- .../godmode/wizards/Wizard.main.php | 2 +- 2 files changed, 189 insertions(+), 13 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 421ea07484..8a6a14f892 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -8,6 +8,10 @@ require_once $config['homedir'].'/include/functions_users.php'; */ class HostDevices extends Wizard { + // CSV constants. + const HDW_CSV_NOT_DATA = 0; + const HDW_CSV_DUPLICATED = 0; + const HDW_CSV_GROUP_EXISTS = 0; /** * Undocumented variable @@ -114,11 +118,10 @@ class HostDevices extends Wizard if ($mode === null) { $this->setBreadcrum(['Host&devices']); $this->printHeader(); - if (extensions_is_enabled_extension('csv_import')) { - echo 'Importar csv'; - } + echo 'Importar csv'; echo 'Escanear red'; + return; } @@ -126,7 +129,7 @@ class HostDevices extends Wizard $this->setBreadcrum( [ 'Host&devices', - 'Import CSV', + 'Import CSV', ] ); $this->printHeader(); @@ -178,8 +181,7 @@ class HostDevices extends Wizard { global $config; - if (!check_acl($config['id_user'], 0, 'AW') - ) { + if (!check_acl($config['id_user'], 0, 'AW')) { db_pandora_audit( 'ACL Violation', 'Trying to access db status' @@ -188,17 +190,133 @@ class HostDevices extends Wizard return; } - if (!extensions_is_enabled_extension('csv_import')) { - ui_print_error_message( + if (!isset($this->page) || $this->page == 0) { + $this->printForm( [ - 'message' => __('Extension CSV Import is not enabled.'), - 'no_close' => true, + 'form' => [ + 'action' => '#', + 'method' => 'POST', + 'enctype' => 'multipart/form-data', + ], + 'inputs' => [ + [ + 'arguments' => [ + 'type' => 'hidden', + 'name' => 'import_file', + 'value' => 1, + 'return' => true, + ], + ], + [ + 'label' => __('Upload file'), + 'arguments' => [ + 'type' => 'file', + 'name' => 'file', + 'return' => true, + ], + ], + [ + 'label' => __('Server'), + 'arguments' => [ + 'type' => 'select', + 'fields' => servers_get_names(), + 'name' => 'server', + 'return' => true, + ], + ], + [ + 'label' => __('Separator'), + 'arguments' => [ + 'type' => 'select', + 'fields' => [ + ',' => ',', + ';' => ';', + ':' => ':', + '.' => '.', + '#' => '#', + ], + 'name' => 'separator', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'page', + 'value' => 1, + 'type' => 'hidden', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go'), + 'type' => 'submit', + 'attributes' => 'class="sub next"', + 'return' => true, + ], + ], + ], ] ); - return; } - include_once $config['homedir'].'/enterprise/extensions/csv_import/main.php'; + if (isset($this->page) && $this->page == 1) { + $server = get_parameter('server'); + $separator = get_parameter('separator'); + + if (isset($_FILES['file'])) { + $file_status_code = get_file_upload_status('file'); + $file_status = translate_file_upload_status($file_status_code); + + if ($file_status === true) { + $error_message = []; + $line = -1; + $file = fopen($_FILES['file']['tmp_name'], 'r'); + if (! empty($file)) { + while (($data = fgetcsv($file, 1000, $separator)) !== false) { + $result = $this->processCsvData($data, $server); + $line++; + if ($result === HDW_CSV_NOT_DATA || $result === HDW_CSV_DUPLICATED || $result === HDW_CSV_GROUP_EXISTS) { + if ($result === HDW_CSV_NOT_DATA) { + $error_message[] = __('No data or wrong separator in line ').$line.'
    '; + } else if ($result === HDW_CSV_DUPLICATED) { + $error_message[] = __('Agent ').io_safe_input($data[0]).__(' duplicated').'
    '; + } else { + $error_message[] = __("Id group %s in line %s doesn't exist in %s", $data[4], $line, get_product_name()).'
    '; + } + + continue; + } + + ui_print_result_message( + $result !== false, + __('Created agent %s', $result['agent_name']), + __('Could not create agent %s', $result['agent_name']) + ); + } + } + + fclose($file); + + if (empty($error_message)) { + ui_print_success_message(__('File processed')); + } else { + foreach ($error_message as $msg) { + ui_print_error_message($msg); + } + } + } else { + ui_print_error_message($file_status); + } + + @unlink($_FILES['file']['tmp_name']); + } else { + ui_print_error_message(__('No input file detected')); + } + + echo $this->breadcrum[0]; + } } @@ -405,4 +523,62 @@ class HostDevices extends Wizard } + /** + * Process the csv of agent. + * + * @param array $data Data of agent. + * @param string $server Name of server. + * + * @return array with data porcessed. + */ + private static function processCsvData($data, $server='') + { + if (empty($data) || count($data) < 5) { + return HDW_CSV_NOT_DATA; + } + + $data['network_components'] = array_slice($data, 6); + $data['agent_name'] = io_safe_input($data[0]); + $data['alias'] = io_safe_input($data[0]); + $data['ip_address'] = $data[1]; + $data['id_os'] = $data[2]; + $data['interval'] = $data[3]; + $data['id_group'] = $data[4]; + $data['comentarios'] = io_safe_input($data[5]); + + $exists = (bool) agents_get_agent_id($data['agent_name']); + if ($exists) { + return HDW_CSV_DUPLICATED; + } + + $group_exists_in_pandora = (bool) groups_get_group_by_id($data['id_group']); + if (!$group_exists_in_pandora) { + return HDW_CSV_GROUP_EXISTS; + } + + $data['id_agent'] = agents_create_agent( + $data['agent_name'], + $data['id_group'], + $data['interval'], + $data['ip_address'], + [ + 'id_os' => $data['id_os'], + 'server_name' => $server, + 'modo' => 1, + 'alias' => $data['alias'], + 'comentarios' => $data['comentarios'], + ] + ); + + foreach ($data['network_components'] as $id_network_component) { + network_components_create_module_from_network_component( + (int) $id_network_component, + $data['id_agent'] + ); + } + + return $data; + } + + } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index e8722ea8e8..3298a2e0e7 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -308,7 +308,7 @@ class Wizard $inputs = $data['inputs']; $js = $data['js']; - $output = '
    '; $output .= '
      '; From 7df9d4f78b09cd35157457f2177e7e526ec871f6 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 14 Feb 2019 17:14:01 +0100 Subject: [PATCH 10/50] WIP: H&D merge Former-commit-id: d53f7d5abed5cfc8d45e6a42bfd52089ff463ff3 --- .../godmode/wizards/HostDevices.class.php | 295 ++++++++++++++++-- .../godmode/wizards/Wizard.main.php | 74 ++++- pandora_console/include/functions_html.php | 1 + pandora_console/include/styles/wizard.css | 6 +- 4 files changed, 344 insertions(+), 32 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 8a6a14f892..e6117afa4a 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -27,13 +27,6 @@ class HostDevices extends Wizard */ public $result; - /** - * Undocumented variable - * - * @var [type] - */ - public $id; - /** * Undocumented variable * @@ -69,6 +62,13 @@ class HostDevices extends Wizard */ public $page; + /** + * Stores all needed parameters to create a recon task. + * + * @var array + */ + public $task; + /** * Undocumented function. @@ -88,7 +88,7 @@ class HostDevices extends Wizard ) { $this->setBreadcrum([]); - $this->id = null; + $this->task = []; $this->msg = $msg; $this->icon = $icon; $this->label = $label; @@ -488,21 +488,7 @@ class HostDevices extends Wizard 'action' => '#', ]; - $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); } @@ -510,7 +496,268 @@ class HostDevices extends Wizard if ($this->page == 1) { // Page 1. - echo 'page 1!'; + $form = []; + // 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, + ], + ]; + + $form['inputs'][] = [ + 'extra' => '

      Please, configure task '.io_safe_output($this->task['name']).'

      ', + ]; + + // Input: Module template. + $form['inputs'][] = [ + 'label' => __('Module template'), + 'arguments' => [ + 'name' => 'id_network_profile', + 'type' => 'select_from_sql', + 'sql' => 'SELECT id_np, name + FROM tnetwork_profile + ORDER BY name', + 'return' => true, + + ], + ]; + + // Feature configuration. + // Input: Module template. + $form['inputs'][] = [ + 'label' => __('SNMP enabled'), + 'arguments' => [ + 'name' => 'snmp_enabled', + 'type' => 'switch', + 'return' => true, + 'onclick' => "\$('#snmp_extra').toggle();", + + ], + ]; + + // SNMP CONFIGURATION. + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_extra', + 'block_content' => [ + 'label' => __('SNMP version'), + 'arguments' => [ + 'name' => 'auth_strings', + 'fields' => [ + '1' => 'v. 1', + '2c' => 'v. 2c', + '3' => 'v. 3', + ], + 'type' => 'select', + 'script' => "\$('#snmp_options_v'+this.value).toggle()", + 'return' => true, + ], + ], + ]; + + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_v1', + 'block_content' => [ + 'label' => __('Community'), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + + ], + ], + ]; + + // Input: WMI enabled. + $form['inputs'][] = [ + 'label' => __('WMI enabled'), + 'arguments' => [ + 'name' => 'wmi_enabled', + 'type' => 'switch', + 'return' => true, + 'onclick' => "\$('#wmi_extra').toggle();", + + ], + ]; + + // WMI CONFIGURATION. + $form['inputs'][] = [ + 'label' => __('WMI Auth. strings'), + 'hidden' => 1, + 'id' => 'wmi_extra', + 'arguments' => [ + 'name' => 'auth_strings', + 'type' => 'text', + 'return' => true, + + ], + ]; + + // Input: Module template. + $form['inputs'][] = [ + 'label' => __('OS detection'), + 'arguments' => [ + 'name' => 'os_detect', + 'type' => 'switch', + 'return' => true, + + ], + ]; + + // Input: Name resolution. + $form['inputs'][] = [ + 'label' => __('Name resolution'), + 'arguments' => [ + 'name' => 'resolve_names', + 'type' => 'switch', + 'return' => true, + ], + ]; + + // Input: Parent detection. + $form['inputs'][] = [ + 'label' => __('Parent detection'), + 'arguments' => [ + 'name' => 'parent_detection', + 'type' => 'switch', + 'return' => true, + ], + ]; + + // Input: VLAN enabled. + $form['inputs'][] = [ + 'label' => __('VLAN enabled'), + 'arguments' => [ + 'name' => 'os_detect', + 'type' => 'switch', + '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->printForm($form); + } + + if ($this->page == 2) { + // Interval and schedules. + $interv_manual = 0; + if ((int) $interval == 0) { + $interv_manual = 1; + } + + $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', + $interval, + '', + '', + '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' => '#', + ]; + + $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); } if ($this->page == 100) { diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 3298a2e0e7..c164b287b7 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -95,7 +95,7 @@ class Wizard * * @return string HTML code for desired input. */ - public function printInput(array $data) + public function printInput($data) { if (is_array($data) === false) { return ''; @@ -286,6 +286,20 @@ class Wizard ((isset($data['return']) === true) ? $data['return'] : false) ); + case 'checkbox': + return html_print_checkbox( + $data['name'], + $data['value'], + ((isset($data['checked']) === true) ? $data['checked'] : false), + ((isset($data['return']) === true) ? $data['return'] : false), + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['script']) === true) ? $data['script'] : ''), + ((isset($data['disabled_hidden']) === true) ? $data['disabled_hidden'] : false) + ); + + case 'switch': + return html_print_switch($data); + default: // Ignore. break; @@ -295,10 +309,60 @@ class Wizard } + /** + * Print a block of inputs. + * + * @param array $input Definition of target block to be printed. + * @param boolean $return Return as string or direct output. + * + * @return string HTML content. + */ + public function printBlock(array $input, bool $return=false) + { + $output = ''; + if ($input['hidden'] == 1) { + $class = ' class="hidden"'; + } else { + $class = ''; + } + + if (is_array($input['block_content']) === true) { + // Print independent block of inputs. + $output .= '
    • '; + $output .= '
        '; + foreach ($input['block_content'] as $input) { + $output .= $this->printBlock($input, $return); + } + + $output .= '
    • '; + } else { + if ($input['arguments']['type'] != 'hidden') { + $output .= '
    • '; + $output .= ''; + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + $output .= '
    • '; + } else { + $output .= $this->printInput($input['arguments']); + // Allow dynamic content. + $output .= $input['extra']; + } + } + + if ($return === false) { + echo $output; + } + + return $output; + } + + /** * Print a form. * - * @param array $data Definition of target form to be printed. + * @param array $data Definition of target form to be printed. + * @param boolean $return Return as string or direct output. * * @return string HTML code. */ @@ -314,11 +378,7 @@ class Wizard $output .= '
        '; foreach ($inputs as $input) { - $output .= '
      • '; - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - $output .= '
      • '; + $output .= $this->printBlock($input, true); } $output .= '
      '; diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 8985655745..ca23d3b029 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3016,6 +3016,7 @@ function html_print_switch($attributes=[]) 'id', 'class', 'name', + 'onclick', ]; foreach ($valid_attrs as $va) { if (!isset($attributes[$va])) { diff --git a/pandora_console/include/styles/wizard.css b/pandora_console/include/styles/wizard.css index 26f4ac0385..fdaf5afa4b 100644 --- a/pandora_console/include/styles/wizard.css +++ b/pandora_console/include/styles/wizard.css @@ -5,7 +5,11 @@ ul.wizard li { padding: 10px; } -ul.wizard li > label { +ul.wizard li > label:not(.p-switch) { width: 250px; display: inline-block; } + +.hidden { + display: none; +} From 39958741763fb23de8f75fca6e7d675312461fa2 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 14 Feb 2019 17:19:20 +0100 Subject: [PATCH 11/50] WIP: H&D: merge Former-commit-id: c1e04b80a49fb0a9870676dc8f59732cd595fbc0 --- .../godmode/wizards/HostDevices.class.php | 249 +++- pandora_console/install.php | 1090 ----------------- 2 files changed, 192 insertions(+), 1147 deletions(-) delete mode 100644 pandora_console/install.php diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index e6117afa4a..23250995db 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -327,6 +327,93 @@ class HostDevices extends Wizard */ public function parseNetScan() { + if ($this->page == 0) { + // Error. Must not be here. + return true; + } + + // Validate response from page 0. No, not a bug, we're always 1 page + // from 'validation' page. + if ($this->page == 1) { + $taskname = get_parameter('taskname', ''); + $comment = get_parameter('comment', ''); + $server_id = get_parameter('id_recon_server', ''); + $network = get_parameter('name', ''); + $id_group = get_parameter('id_group', ''); + + if ($taskname == '') { + $this->msg = __('You must provide a task name.'); + return false; + } + + if ($server_id == '') { + $this->msg = __('You must select a Discovery Server.'); + return false; + } + + if ($network == '') { + // XXX: Could be improved validating provided network. + $this->msg = __('You must provide a valid network.'); + return false; + } + + if ($id_group == '') { + $this->msg = __('You must select a valid group.'); + return false; + } + + // Assign fields. + $this->task['name'] = $taskname; + $this->task['description'] = $comment; + $this->task['subnet'] = $network; + $this->task['id_recon_server'] = $server_id; + // Disabled 2 Implies wizard non finished. + $this->task['disabled'] = 2; + + $this->task['id_rt'] = 5; + + if (!isset($this->task['id_rt'])) { + // Create. + $this->task['id_rt'] = db_process_sql_insert( + 'trecon_task', + $this->task + ); + } else { + // Update. + db_process_sql_update( + 'trecon_task', + $this->task, + ['id_rt' => $this->task['id_rt']] + ); + } + + return true; + } + + // Validate response from page 1. + if ($this->page == 2) { + $id_rt = get_parameter('task', -1); + + $this->task = db_get_row( + 'trecon_task', + 'id_rt', + $id_rt + ); + + hd($this->task); + + return false; + } + + if ($this->page == 3) { + // Interval and schedules. + // By default manual if not defined. + $interval = get_parameter('interval', 0); + + $this->task['interval_sweep'] = $interval; + return false; + } + return false; } @@ -355,18 +442,83 @@ class HostDevices extends Wizard $user_groups = users_get_groups(false, 'AW', true, false, null, 'id_grupo'); $user_groups = array_keys($user_groups); - if (isset($this->page) && $this->page == 1) { - // Parse page 0 responses. - $this->parseNetScan(); + if ($this->parseNetScan() === false) { + // Error. + ui_print_error_message( + $this->msg + ); + + $form = [ + 'form' => [ + 'method' => 'POST', + 'action' => '#', + ], + 'inputs' => [ + [ + 'arguments' => [ + 'type' => 'hidden', + 'name' => 'page', + 'value' => ($this->page - 1), + ], + ], + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go back'), + 'type' => 'submit', + 'attributes' => 'class="sub cancel"', + 'return' => true, + ], + ], + ], + ]; + + $this->printForm($form); + return null; } - if (!isset($this->page) || $this->page == 0) { - // Interval. - $interv_manual = 0; - if ((int) $interval == 0) { - $interv_manual = 1; - } + if (isset($this->page) + && $this->page != 0 + && isset($this->task['id_rt']) === false + ) { + // Error. + ui_print_error_message( + __('Internal error, please re-run this wizard.') + ); + $form = [ + 'form' => [ + 'method' => 'POST', + 'action' => '#', + ], + 'inputs' => [ + [ + 'arguments' => [ + 'type' => 'hidden', + 'name' => 'page', + 'value' => 0, + ], + ], + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go back'), + 'type' => 'submit', + 'attributes' => 'class="sub cancel"', + 'return' => true, + ], + ], + ], + ]; + + $this->printForm($form); + return null; + } + + // -------------------------------. + // Page 0. wizard starts HERE. + // -------------------------------. + if (!isset($this->page) || $this->page == 0) { if (isset($this->page) === false || $this->page == 0 ) { @@ -383,6 +535,17 @@ class HostDevices extends Wizard ], ]; + // Input task name. + $form['inputs'][] = [ + 'label' => ''.__('Comment').'', + 'arguments' => [ + 'name' => 'comment', + 'value' => '', + 'type' => 'text', + 'size' => 25, + ], + ]; + // Input Discovery Server. $form['inputs'][] = [ 'label' => ''.__('Discovery server').''.ui_print_help_tip( @@ -419,38 +582,6 @@ class HostDevices extends Wizard ], ]; - // Input interval. - $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', - $interval, - '', - '', - '0', - false, - true, - false, - false - ).ui_print_help_tip( - __('The minimum recomended interval for Recon Task is 5 minutes'), - true - ).'', - ]; - // Input Group. $form['inputs'][] = [ 'label' => ''.__('Group').'', @@ -553,17 +684,19 @@ class HostDevices extends Wizard 'hidden' => 1, 'block_id' => 'snmp_extra', 'block_content' => [ - 'label' => __('SNMP version'), - 'arguments' => [ - 'name' => 'auth_strings', - 'fields' => [ - '1' => 'v. 1', - '2c' => 'v. 2c', - '3' => 'v. 3', + [ + 'label' => __('SNMP version'), + 'arguments' => [ + 'name' => 'auth_strings', + 'fields' => [ + '1' => 'v. 1', + '2c' => 'v. 2c', + '3' => 'v. 3', + ], + 'type' => 'select', + 'script' => "\$('#snmp_options_v'+this.value).toggle()", + 'return' => true, ], - 'type' => 'select', - 'script' => "\$('#snmp_options_v'+this.value).toggle()", - 'return' => true, ], ], ]; @@ -572,13 +705,15 @@ class HostDevices extends Wizard 'hidden' => 1, 'block_id' => 'snmp_options_v1', 'block_content' => [ - 'label' => __('Community'), - 'arguments' => [ - 'name' => 'community', - 'type' => 'text', - 'size' => 25, - 'return' => true, + [ + 'label' => __('Community'), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + ], ], ], ]; diff --git a/pandora_console/install.php b/pandora_console/install.php deleted file mode 100644 index 69e11b10bd..0000000000 --- a/pandora_console/install.php +++ /dev/null @@ -1,1090 +0,0 @@ - - - - - Pandora FMS - Installation Wizard - - - - - - - - - - - - - - - -
      - -
      - - - -'; - echo " $label "; - echo ''; - if (!extension_loaded($ext)) { - echo ""; - return 1; - } else { - echo ""; - return 0; - } - - echo ''; -} - -function check_include($ext, $label) -{ - echo ''; - echo " $label "; - echo ''; - if (!include $ext) { - echo ""; - return 1; - } else { - echo ""; - return 0; - } - - echo ''; -} - - -function check_exists($file, $label) -{ - echo ''; - echo " $label "; - echo ''; - if (!file_exists($file)) { - echo " "; - return 1; - } else { - echo " "; - return 0; - } - - echo ''; -} - - -function check_generic($ok, $label) -{ - echo ""; - if ($ok == 0) { - echo " "; - echo ''; - echo " $label "; - echo ''; - echo ''; - return 1; - } else { - echo " "; - echo ''; - echo " $label "; - echo ''; - echo ''; - return 0; - } -} - - -function check_writable($fullpath, $label) -{ - echo ""; - if (file_exists($fullpath)) { - if (is_writable($fullpath)) { - echo " "; - echo ''; - echo " $label "; - echo ''; - echo ''; - return 0; - } else { - echo " "; - echo ''; - echo " $label "; - echo ''; - echo ''; - return 1; - } - } else { - echo " "; - echo ''; - echo " $label "; - echo ''; - echo ''; - return 1; - } -} - - -function check_variable($var, $value, $label, $mode) -{ - echo ''; - echo " $label "; - echo ''; - if ($mode == 1) { - if ($var >= $value) { - echo " "; - return 0; - } else { - echo " "; - return 1; - } - } else if ($var == $value) { - echo " "; - return 0; - } else { - echo " "; - return 1; - } - - echo ''; -} - - -function parse_mysql_dump($url) -{ - if (file_exists($url)) { - $file_content = file($url); - $query = ''; - foreach ($file_content as $sql_line) { - if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { - $query .= $sql_line; - if (preg_match("/;[\040]*\$/", $sql_line)) { - if (!$result = mysql_query($query)) { - echo mysql_error(); - // Uncomment for debug - echo "
      $query
      "; - return 0; - } - - $query = ''; - } - } - } - - return 1; - } else { - return 0; - } -} - - -function parse_mysqli_dump($connection, $url) -{ - if (file_exists($url)) { - $file_content = file($url); - $query = ''; - foreach ($file_content as $sql_line) { - if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { - $query .= $sql_line; - if (preg_match("/;[\040]*\$/", $sql_line)) { - if (!$result = mysqli_query($connection, $query)) { - echo mysqli_error(); - // Uncomment for debug - echo "
      $query
      "; - return 0; - } - - $query = ''; - } - } - } - - return 1; - } else { - return 0; - } -} - - -function random_name($size) -{ - $temp = ''; - for ($a = 0; $a < $size; $a++) { - $temp = $temp.chr(rand(122, 97)); - } - - return $temp; -} - - -function print_logo_status($step, $step_total) -{ - global $banner; - - $header = " -
      -
      -
      - $banner -
      -
      "; - $header .= " -
      - Install step $step of $step_total -
      "; - - return $header; -} - - -// -// This function adjusts path settings in pandora db for FreeBSD. -// -// All packages and configuration files except operating system's base files -// are installed under /usr/local in FreeBSD. So, path settings in pandora db -// for some programs should be changed from the Linux default. -// -function adjust_paths_for_freebsd($engine, $connection=false) -{ - $adjust_sql = [ - "update trecon_script set script = REPLACE(script,'/usr/share','/usr/local/share');", - "update tconfig set value = REPLACE(value,'/usr/bin','/usr/local/bin') where token='netflow_daemon' OR token='netflow_nfdump' OR token='netflow_nfexpire';", - "update talert_commands set command = REPLACE(command,'/usr/bin','/usr/local/bin');", - "update talert_commands set command = REPLACE(command,'/usr/share', '/usr/local/share');", - "update tplugin set execute = REPLACE(execute,'/usr/share','/usr/local/share');", - "update tevent_response set target = REPLACE(target,'/usr/share','/usr/local/share');", - "insert into tconfig (token, value) VALUES ('graphviz_bin_dir', '/usr/local/bin');", - ]; - - for ($i = 0; $i < count($adjust_sql); $i++) { - switch ($engine) { - case 'mysql': - $result = mysql_query($adjust_sql[$i]); - break; - - case 'mysqli': - $result = mysqli_query($connection, $adjust_sql[$i]); - break; - - case 'oracle': - // Delete the last semicolon from current query - $query = substr($adjust_sql[$i], 0, (strlen($adjust_sql[$i]) - 1)); - $sql = oci_parse($connection, $query); - $result = oci_execute($sql); - break; - - case 'pgsql': - pg_send_query($connection, $adjust_sql[$i]); - $result = pg_get_result($connection); - break; - } - - if (!$result) { - return 0; - } - } - - return 1; -} - - -function install_step1() -{ - global $banner; - - echo " -
      -
      - ".print_logo_status(1, 6)." -
      -

      Welcome to Pandora FMS installation Wizard

      -

      This wizard helps you to quick install Pandora FMS console and main database in your system.

      -

      In four steps, this installer will check all dependencies and will create your configuration, ready to use.

      -

      For more information, please refer to documentation.
      - Pandora FMS Development Team

      - "; - if (file_exists('include/config.php')) { - echo "
      Warning: You already have a config.php file. - Configuration and database would be overwritten if you continued.
      "; - } - - echo '
      '; - echo ''; - $writable = check_writable('include', 'Checking if ./include is writable'); - if (file_exists('include/config.php')) { - $writable += check_writable('include/config.php', 'Checking if include/config.php is writable'); - } - - echo '
      '; - - echo "
      Warning: This installer will overwrite and destroy - your existing Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database.
      -
      "; - - echo "
      Upgrade: - If you want to upgrade from Pandora FMS 4.x to 5.0 version, please use the migration tool inside /extras directory in this setup. -
      "; - - echo '
      '; - - if ($writable == 0) { - echo "
      "; - echo ""; - echo '
      '; - } else { - echo "
      ERROR:You need to setup permissions to be able to write in ./include directory
      "; - } - - echo '
      '; - - echo "
      "; - echo " -
      -
      - Pandora FMS is an OpenSource Software project registered at - SourceForge -
      -
      "; -} - - -function install_step1_licence() -{ - echo " -
      -
      - ".print_logo_status(2, 6)." -
      -

      GPL2 Licence terms agreement

      -

      Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms.. -

      For more information, please refer to our website at http://pandorafms.org and contact us if you have any kind of question about the usage of Pandora FMS

      -

      If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

      - "; - - if (!file_exists('COPYING')) { - echo "
      Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; - echo '
      '; - } else { - echo ""; - echo "'; - echo '

      '; - echo "

      "; - } - - echo '
      '; - - echo "
      -
      -
      - Pandora FMS is an OpenSource Software project registered at - SourceForge -
      -
      "; -} - - -function install_step2() -{ - echo " -
      -
      - ".print_logo_status(3, 6)." -
      "; - echo '

      Checking software dependencies

      '; - echo ''; - $res = 0; - $res += check_variable(phpversion(), '5.2', 'PHP version >= 5.2', 1); - $res += check_extension('gd', 'PHP GD extension'); - $res += check_extension('ldap', 'PHP LDAP extension'); - $res += check_extension('snmp', 'PHP SNMP extension'); - $res += check_extension('session', 'PHP session extension'); - $res += check_extension('gettext', 'PHP gettext extension'); - $res += check_extension('mbstring', 'PHP Multibyte String'); - $res += check_extension('zip', 'PHP Zip'); - $res += check_extension('zlib', 'PHP Zlib extension'); - $res += check_extension('json', 'PHP json extension'); - $res += check_extension('curl', 'CURL (Client URL Library)'); - $res += check_extension('filter', 'PHP filter extension'); - $res += check_extension('calendar', 'PHP calendar extension'); - if (PHP_OS == 'FreeBSD') { - $res += check_exists('/usr/local/bin/twopi', 'Graphviz Binary'); - } else if (PHP_OS == 'NetBSD') { - $res += check_exists('/usr/pkg/bin/twopi', 'Graphviz Binary'); - } else if (substr(PHP_OS, 0, 3) == 'WIN') { - $res += check_exists("..\\..\\..\\Graphviz\\bin\\twopi.exe", 'Graphviz Binary'); - } else { - $res += check_exists('/usr/bin/twopi', 'Graphviz Binary'); - } - - echo ''; - check_extension('mysql', 'PHP MySQL extension'); - check_extension('mysqli', 'PHP MySQL(mysqli) extension'); - echo '
      '; - echo "DB Engines"; - echo ''; - echo '
      '; - - if ($res > 0) { - echo " -
      You have some incomplete - dependencies. Please correct them or this installer - will not be able to finish your installation. -
      -
      - Remember, if you install any PHP module to comply - with these dependences, you need to restart - your HTTP/Apache server after it to use the new - modules. -
      -
      - Ignore it. -
      "; - } else { - echo "
      "; - echo " - "; - echo '
      '; - } - - echo '
      '; - echo "
      "; - echo " -
      -
      -
      -
      - Pandora FMS is an OpenSource Software project registered at - SourceForge -
      - "; -} - - -function install_step3() -{ - $options = ''; - if (extension_loaded('mysql')) { - $options .= ""; - } - - if (extension_loaded('mysqli')) { - $options .= ""; - } - - $error = false; - if (empty($options)) { - $error = true; - } - - echo " -
      -
      - ".print_logo_status(4, 6)." -
      -

      Environment and database setup

      -

      - This wizard will create your Pandora FMS database, - and populate it with all the data needed to run for the first time. -

      -

      - You need a privileged user to create database schema, this is usually root user. - Information about root user will not be used or stored anymore. -

      -

      - You can also deploy the scheme into an existing Database. - In this case you need a privileged Database user and password of that instance. -

      -

      - Now, please, complete all details to configure your database and environment setup. -

      -
      - Warning: This installer will overwrite and destroy your existing - Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database. -

      -
      "; - - if (extension_loaded('oci8')) { - echo "
      For Oracle installation an existing Database with a privileged user is needed.
      "; - } - - if (!$error) { - echo ""; - } - - echo ""; - echo '"; - - // the field dbgrant is only shown when the DB host is different from 127.0.0.1 or localhost - echo " - - "; - - echo " "; - - echo ""; - echo '
      '; - echo 'DB Engine
      '; - - if ($error) { - echo " -
      - Warning: You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies. -
      "; - } else { - echo "'; - - echo '
      '; - echo ' Installation in
      '; - echo "'; - } - - echo "
      DB User with privileges
      - - -
      DB Password for this user
      - - -
      DB Hostname
      - - -
      DB Name (pandora by default)
      - - -
      Drop Database if exists
      - -
      Full path to HTTP publication directory
      - For example /var/www/pandora_console/ -
      - - -
      '; - echo "URL path to Pandora FMS Console
      - For example '/pandora_console' -
      - -
      - "; - - if (!$error) { - echo "
      "; - echo " - "; - echo '
      '; - ?> - - '; - - echo ''; - - echo "
      "; - echo "
      -
      - Pandora FMS is an OpenSource Software project registered at - SourceForge -
      -
      "; -} - - -function install_step4() -{ - $pandora_config = 'include/config.php'; - - if ((! isset($_POST['user'])) || (! isset($_POST['dbname'])) || (! isset($_POST['host'])) - || (! isset($_POST['pass'])) || (!isset($_POST['engine'])) || (! isset($_POST['db_action'])) - ) { - $dbpassword = ''; - $dbuser = ''; - $dbhost = ''; - $dbname = ''; - $engine = ''; - $dbaction = ''; - $dbgrant = ''; - } else { - $engine = $_POST['engine']; - $dbpassword = $_POST['pass']; - $dbuser = $_POST['user']; - $dbhost = $_POST['host']; - $dbaction = $_POST['db_action']; - if (isset($_POST['dbgrant']) && $_POST['dbgrant'] != '') { - $dbgrant = $_POST['dbgrant']; - } else { - $dbgrant = $_SERVER['SERVER_ADDR']; - } - - if (isset($_POST['drop'])) { - $dbdrop = $_POST['drop']; - } else { - $dbdrop = 0; - } - - $dbname = $_POST['dbname']; - if (isset($_POST['url'])) { - $url = $_POST['url']; - } else { - $url = 'http://localhost'; - } - - if (isset($_POST['path'])) { - $path = $_POST['path']; - $path = str_replace('\\', '/', $path); - // Windows compatibility - } else { - $path = '/var/www'; - } - } - - $everything_ok = 0; - $step1 = 0; - $step2 = 0; - $step3 = 0; - $step4 = 0; - $step5 = 0; - $step6 = 0; - $step7 = 0; - - echo " -
      -
      - ".print_logo_status(5, 6)." -
      -

      Creating database and default configuration file

      - "; - switch ($engine) { - case 'mysql': - if (! mysql_connect($dbhost, $dbuser, $dbpassword)) { - check_generic(0, 'Connection with Database'); - } else { - check_generic(1, 'Connection with Database'); - - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1) { - mysql_query("DROP DATABASE IF EXISTS `$dbname`"); - } - - // Create schema - if ($dbaction == 'db_new' || $dbdrop == 1) { - $step1 = mysql_query("CREATE DATABASE `$dbname`"); - check_generic($step1, "Creating database '$dbname'"); - } else { - $step1 = 1; - } - - if ($step1 == 1) { - $step2 = mysql_select_db($dbname); - check_generic($step2, "Opening database '$dbname'"); - - $step3 = parse_mysql_dump('pandoradb.sql'); - check_generic($step3, 'Creating schema'); - - $step4 = parse_mysql_dump('pandoradb_data.sql'); - check_generic($step4, 'Populating database'); - if (PHP_OS == 'FreeBSD') { - $step_freebsd = adjust_paths_for_freebsd($engine); - check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); - } - - $random_password = random_name(8); - $host = $dbhost; - // set default granted origin to the origin of the queries - if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { - $host = $dbgrant; - // if the granted origin is different from local machine, set the valid origin - } - - $step5 = mysql_query( - "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host - IDENTIFIED BY '".$random_password."'" - ); - mysql_query('FLUSH PRIVILEGES'); - check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
      Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
      "); - - $step6 = is_writable('include'); - check_generic($step6, "Write permissions to save config file in './include'"); - - $cfgin = fopen('include/config.inc.php', 'r'); - $cfgout = fopen($pandora_config, 'w'); - $config_contents = fread($cfgin, filesize('include/config.inc.php')); - $dbtype = 'mysql'; - $config_new = ''; - $step7 = fputs($cfgout, $config_new); - $step7 = ($step7 + fputs($cfgout, $config_contents)); - if ($step7 > 0) { - $step7 = 1; - } - - fclose($cfgin); - fclose($cfgout); - chmod($pandora_config, 0600); - check_generic($step7, "Created new config file at '".$pandora_config."'"); - } - } - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - break; - - case 'mysqli': - $connection = mysqli_connect($dbhost, $dbuser, $dbpassword); - if (mysqli_connect_error() > 0) { - check_generic(0, 'Connection with Database'); - } else { - check_generic(1, 'Connection with Database'); - - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1) { - mysqli_query($connection, "DROP DATABASE IF EXISTS `$dbname`"); - } - - // Create schema - if ($dbaction == 'db_new' || $dbdrop == 1) { - $step1 = mysqli_query($connection, "CREATE DATABASE `$dbname`"); - check_generic($step1, "Creating database '$dbname'"); - } else { - $step1 = 1; - } - - if ($step1 == 1) { - $step2 = mysqli_select_db($connection, $dbname); - check_generic($step2, "Opening database '$dbname'"); - - $step3 = parse_mysqli_dump($connection, 'pandoradb.sql'); - check_generic($step3, 'Creating schema'); - - $step4 = parse_mysqli_dump($connection, 'pandoradb_data.sql'); - check_generic($step4, 'Populating database'); - if (PHP_OS == 'FreeBSD') { - $step_freebsd = adjust_paths_for_freebsd($engine, $connection); - check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); - } - - $random_password = random_name(8); - $host = $dbhost; - // set default granted origin to the origin of the queries - if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { - $host = $dbgrant; - // if the granted origin is different from local machine, set the valid origin - } - - $step5 = mysqli_query( - $connection, - "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host - IDENTIFIED BY '".$random_password."'" - ); - mysqli_query($connection, 'FLUSH PRIVILEGES'); - check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
      Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
      "); - - $step6 = is_writable('include'); - check_generic($step6, "Write permissions to save config file in './include'"); - - $cfgin = fopen('include/config.inc.php', 'r'); - $cfgout = fopen($pandora_config, 'w'); - $config_contents = fread($cfgin, filesize('include/config.inc.php')); - $dbtype = 'mysql'; - $config_new = ''; - $step7 = fputs($cfgout, $config_new); - $step7 = ($step7 + fputs($cfgout, $config_contents)); - if ($step7 > 0) { - $step7 = 1; - } - - fclose($cfgin); - fclose($cfgout); - chmod($pandora_config, 0600); - check_generic($step7, "Created new config file at '".$pandora_config."'"); - } - } - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - break; - } - - echo '
      '; - - if ($everything_ok == 1) { - echo "
      "; - echo " - "; - echo '
      '; - } else { - $info = "
      There were some problems. - Installation was not completed. -

      Please correct failures before trying again. - All database "; - if ($engine == 'oracle') { - $info .= 'objects '; - } else { - $info .= 'schemes '; - } - - $info .= 'created in this step have been dropped.

      -
      '; - echo $info; - - switch ($engine) { - case 'mysql': - if (mysql_error() != '') { - echo "
      ERROR: ".mysql_error().'.
      '; - } - - if ($step1 == 1) { - mysql_query("DROP DATABASE $dbname"); - } - break; - - case 'mysqli': - if (mysqli_error($connection) != '') { - echo "
      ERROR: ".mysqli_error($connection).'.
      '; - } - - if ($step1 == 1) { - mysqli_query($connection, "DROP DATABASE $dbname"); - } - break; - } - - echo '
      '; - } - - echo '
      '; - echo "
      "; - echo " -
      -
      - Pandora FMS is an Open Source Software project registered at - SourceForge -
      -
      "; -} - - -function install_step5() -{ - echo " -
      -
      - ".print_logo_status(6, 6)." -
      -

      Installation complete

      -

      For security, you now must manually delete this installer - ('install.php') file before trying to access to your Pandora FMS console. -

      You should also install Pandora FMS Servers before trying to monitor anything; - please read documentation on how to install it.

      -

      Default user is 'admin' with password 'pandora', - please change it both as soon as possible.

      -

      Don't forget to check http://pandorafms.com - for updates. -

      Select if you want to rename 'install.php'.

      -
      - - -
      -


      . -

      -
      "; - - echo "
      -
      - Pandora FMS is an OpenSource Software project registered at - SourceForge -
      -
      "; -} From 2059614ba231115ffa46e388301b28f68b90253f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 14 Feb 2019 17:20:00 +0100 Subject: [PATCH 12/50] missed install... Former-commit-id: a2e1bc42354612afde7e1a28845348f41eab7509 --- pandora_console/install.php | 1106 +++++++++++++++++++++++++++++++++++ 1 file changed, 1106 insertions(+) create mode 100644 pandora_console/install.php diff --git a/pandora_console/install.php b/pandora_console/install.php new file mode 100644 index 0000000000..2a190ff74e --- /dev/null +++ b/pandora_console/install.php @@ -0,0 +1,1106 @@ + + + + + Pandora FMS - Installation Wizard + + + + + + + + + + + + + + + +
      + +
      + + + +'; + echo " $label "; + echo ''; + if (!extension_loaded($ext)) { + echo ""; + return 1; + } else { + echo ""; + return 0; + } + + echo ''; +} + +function check_include($ext, $label) +{ + echo ''; + echo " $label "; + echo ''; + if (!include $ext) { + echo ""; + return 1; + } else { + echo ""; + return 0; + } + + echo ''; +} + + +function check_exists($file, $label) +{ + echo ''; + echo " $label "; + echo ''; + if (!file_exists($file)) { + echo " "; + return 1; + } else { + echo " "; + return 0; + } + + echo ''; +} + + +function check_generic($ok, $label) +{ + echo ""; + if ($ok == 0) { + echo " "; + echo ''; + echo " $label "; + echo ''; + echo ''; + return 1; + } else { + echo " "; + echo ''; + echo " $label "; + echo ''; + echo ''; + return 0; + } +} + + +function check_writable($fullpath, $label) +{ + echo ""; + if (file_exists($fullpath)) { + if (is_writable($fullpath)) { + echo " "; + echo ''; + echo " $label "; + echo ''; + echo ''; + return 0; + } else { + echo " "; + echo ''; + echo " $label "; + echo ''; + echo ''; + return 1; + } + } else { + echo " "; + echo ''; + echo " $label "; + echo ''; + echo ''; + return 1; + } +} + + +function check_variable($var, $value, $label, $mode) +{ + echo ''; + echo " $label "; + echo ''; + if ($mode == 1) { + if ($var >= $value) { + echo " "; + return 0; + } else { + echo " "; + return 1; + } + } else if ($var == $value) { + echo " "; + return 0; + } else { + echo " "; + return 1; + } + + echo ''; +} + + +function parse_mysql_dump($url) +{ + if (file_exists($url)) { + $file_content = file($url); + $query = ''; + foreach ($file_content as $sql_line) { + if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { + $query .= $sql_line; + if (preg_match("/;[\040]*\$/", $sql_line)) { + if (!$result = mysql_query($query)) { + echo mysql_error(); + // Uncomment for debug + echo "
      $query
      "; + return 0; + } + + $query = ''; + } + } + } + + return 1; + } else { + return 0; + } +} + + +function parse_mysqli_dump($connection, $url) +{ + if (file_exists($url)) { + $file_content = file($url); + $query = ''; + foreach ($file_content as $sql_line) { + if (trim($sql_line) != '' && strpos($sql_line, '-- ') === false) { + $query .= $sql_line; + if (preg_match("/;[\040]*\$/", $sql_line)) { + if (!$result = mysqli_query($connection, $query)) { + echo mysqli_error(); + // Uncomment for debug + echo "
      $query
      "; + return 0; + } + + $query = ''; + } + } + } + + return 1; + } else { + return 0; + } +} + + +function random_name($size) +{ + $temp = ''; + for ($a = 0; $a < $size; $a++) { + $temp = $temp.chr(rand(122, 97)); + } + + return $temp; +} + + +function print_logo_status($step, $step_total) +{ + global $banner; + + $header = " +
      +
      +
      + $banner +
      +
      "; + $header .= " +
      + Install step $step of $step_total +
      "; + + return $header; +} + + +// +// This function adjusts path settings in pandora db for FreeBSD. +// +// All packages and configuration files except operating system's base files +// are installed under /usr/local in FreeBSD. So, path settings in pandora db +// for some programs should be changed from the Linux default. +// +function adjust_paths_for_freebsd($engine, $connection=false) +{ + $adjust_sql = [ + "update trecon_script set script = REPLACE(script,'/usr/share','/usr/local/share');", + "update tconfig set value = REPLACE(value,'/usr/bin','/usr/local/bin') where token='netflow_daemon' OR token='netflow_nfdump' OR token='netflow_nfexpire';", + "update talert_commands set command = REPLACE(command,'/usr/bin','/usr/local/bin');", + "update talert_commands set command = REPLACE(command,'/usr/share', '/usr/local/share');", + "update tplugin set execute = REPLACE(execute,'/usr/share','/usr/local/share');", + "update tevent_response set target = REPLACE(target,'/usr/share','/usr/local/share');", + "insert into tconfig (token, value) VALUES ('graphviz_bin_dir', '/usr/local/bin');", + ]; + + for ($i = 0; $i < count($adjust_sql); $i++) { + switch ($engine) { + case 'mysql': + $result = mysql_query($adjust_sql[$i]); + break; + + case 'mysqli': + $result = mysqli_query($connection, $adjust_sql[$i]); + break; + + case 'oracle': + // Delete the last semicolon from current query + $query = substr($adjust_sql[$i], 0, (strlen($adjust_sql[$i]) - 1)); + $sql = oci_parse($connection, $query); + $result = oci_execute($sql); + break; + + case 'pgsql': + pg_send_query($connection, $adjust_sql[$i]); + $result = pg_get_result($connection); + break; + } + + if (!$result) { + return 0; + } + } + + return 1; +} + + +function install_step1() +{ + global $banner; + + echo " +
      +
      + ".print_logo_status(1, 6)." +
      +

      Welcome to Pandora FMS installation Wizard

      +

      This wizard helps you to quick install Pandora FMS console and main database in your system.

      +

      In four steps, this installer will check all dependencies and will create your configuration, ready to use.

      +

      For more information, please refer to documentation.
      + Pandora FMS Development Team

      + "; + if (file_exists('include/config.php')) { + echo "
      Warning: You already have a config.php file. + Configuration and database would be overwritten if you continued.
      "; + } + + echo '
      '; + echo ''; + $writable = check_writable('include', 'Checking if ./include is writable'); + if (file_exists('include/config.php')) { + $writable += check_writable('include/config.php', 'Checking if include/config.php is writable'); + } + + echo '
      '; + + echo "
      Warning: This installer will overwrite and destroy + your existing Pandora FMS configuration and Database. Before continue, + please be sure that you have no valuable Pandora FMS data in your Database.
      +
      "; + + echo "
      Upgrade: + If you want to upgrade from Pandora FMS 4.x to 5.0 version, please use the migration tool inside /extras directory in this setup. +
      "; + + echo '
      '; + + if ($writable == 0) { + echo "
      "; + echo ""; + echo '
      '; + } else { + echo "
      ERROR:You need to setup permissions to be able to write in ./include directory
      "; + } + + echo '
      '; + + echo "
      "; + echo " +
      +
      + Pandora FMS is an OpenSource Software project registered at + SourceForge +
      +
      "; +} + + +function install_step1_licence() +{ + echo " +
      +
      + ".print_logo_status(2, 6)." +
      +

      GPL2 Licence terms agreement

      +

      Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms.. +

      For more information, please refer to our website at http://pandorafms.org and contact us if you have any kind of question about the usage of Pandora FMS

      +

      If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

      + "; + + if (!file_exists('COPYING')) { + echo "
      Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; + echo '
      '; + } else { + echo "
      "; + echo "'; + echo '

      '; + echo "

      "; + } + + echo '
      '; + + echo "
      +
      +
      + Pandora FMS is an OpenSource Software project registered at + SourceForge +
      +
      "; +} + + +function install_step2() +{ + echo " +
      +
      + ".print_logo_status(3, 6)." +
      "; + echo '

      Checking software dependencies

      '; + echo ''; + $res = 0; + $res += check_variable(phpversion(), '5.2', 'PHP version >= 5.2', 1); + $res += check_extension('gd', 'PHP GD extension'); + $res += check_extension('ldap', 'PHP LDAP extension'); + $res += check_extension('snmp', 'PHP SNMP extension'); + $res += check_extension('session', 'PHP session extension'); + $res += check_extension('gettext', 'PHP gettext extension'); + $res += check_extension('mbstring', 'PHP Multibyte String'); + $res += check_extension('zip', 'PHP Zip'); + $res += check_extension('zlib', 'PHP Zlib extension'); + $res += check_extension('json', 'PHP json extension'); + $res += check_extension('curl', 'CURL (Client URL Library)'); + $res += check_extension('filter', 'PHP filter extension'); + $res += check_extension('calendar', 'PHP calendar extension'); + if (PHP_OS == 'FreeBSD') { + $res += check_exists('/usr/local/bin/twopi', 'Graphviz Binary'); + } else if (PHP_OS == 'NetBSD') { + $res += check_exists('/usr/pkg/bin/twopi', 'Graphviz Binary'); + } else if (substr(PHP_OS, 0, 3) == 'WIN') { + $res += check_exists("..\\..\\..\\Graphviz\\bin\\twopi.exe", 'Graphviz Binary'); + } else { + $res += check_exists('/usr/bin/twopi', 'Graphviz Binary'); + } + + echo ''; + check_extension('mysql', 'PHP MySQL extension'); + check_extension('mysqli', 'PHP MySQL(mysqli) extension'); + echo '
      '; + echo "DB Engines"; + echo ''; + echo '
      '; + + if ($res > 0) { + echo " +
      You have some incomplete + dependencies. Please correct them or this installer + will not be able to finish your installation. +
      +
      + Remember, if you install any PHP module to comply + with these dependences, you need to restart + your HTTP/Apache server after it to use the new + modules. +
      +
      + Ignore it. +
      "; + } else { + echo "
      "; + echo " + "; + echo '
      '; + } + + echo '
      '; + echo "
      "; + echo " +
      +
      +
      +
      + Pandora FMS is an OpenSource Software project registered at + SourceForge +
      + "; +} + + +function install_step3() +{ + $options = ''; + if (extension_loaded('mysql')) { + $options .= ""; + } + + if (extension_loaded('mysqli')) { + $options .= ""; + } + + $error = false; + if (empty($options)) { + $error = true; + } + + echo " +
      +
      + ".print_logo_status(4, 6)." +
      +

      Environment and database setup

      +

      + This wizard will create your Pandora FMS database, + and populate it with all the data needed to run for the first time. +

      +

      + You need a privileged user to create database schema, this is usually root user. + Information about root user will not be used or stored anymore. +

      +

      + You can also deploy the scheme into an existing Database. + In this case you need a privileged Database user and password of that instance. +

      +

      + Now, please, complete all details to configure your database and environment setup. +

      +
      + Warning: This installer will overwrite and destroy your existing + Pandora FMS configuration and Database. Before continue, + please be sure that you have no valuable Pandora FMS data in your Database. +

      +
      "; + + if (extension_loaded('oci8')) { + echo "
      For Oracle installation an existing Database with a privileged user is needed.
      "; + } + + if (!$error) { + echo ""; + } + + echo ""; + echo '"; + + // the field dbgrant is only shown when the DB host is different from 127.0.0.1 or localhost + echo " + + "; + + echo " "; + + echo ""; + echo '
      '; + echo 'DB Engine
      '; + + if ($error) { + echo " +
      + Warning: You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies. +
      "; + } else { + echo "'; + + echo '
      '; + echo ' Installation in
      '; + echo "'; + } + + echo "
      DB User with privileges
      + + +
      DB Password for this user
      + + +
      DB Hostname
      + + +
      DB Name (pandora by default)
      + + +
      Drop Database if exists
      + +
      Full path to HTTP publication directory
      + For example /var/www/pandora_console/ +
      + + +
      '; + echo "URL path to Pandora FMS Console
      + For example '/pandora_console' +
      + +
      + "; + + if (!$error) { + echo "
      "; + echo " + "; + echo '
      '; + ?> + + '; + + echo ''; + + echo "
      "; + echo "
      +
      + Pandora FMS is an OpenSource Software project registered at + SourceForge +
      +
      "; +} + + +function install_step4() +{ + $pandora_config = 'include/config.php'; + + if ((! isset($_POST['user'])) || (! isset($_POST['dbname'])) || (! isset($_POST['host'])) + || (! isset($_POST['pass'])) || (!isset($_POST['engine'])) || (! isset($_POST['db_action'])) + ) { + $dbpassword = ''; + $dbuser = ''; + $dbhost = ''; + $dbname = ''; + $engine = ''; + $dbaction = ''; + $dbgrant = ''; + } else { + $engine = $_POST['engine']; + $dbpassword = $_POST['pass']; + $dbuser = $_POST['user']; + $dbhost = $_POST['host']; + $dbaction = $_POST['db_action']; + if (isset($_POST['dbgrant']) && $_POST['dbgrant'] != '') { + $dbgrant = $_POST['dbgrant']; + } else { + $dbgrant = $_SERVER['SERVER_ADDR']; + } + + if (isset($_POST['drop'])) { + $dbdrop = $_POST['drop']; + } else { + $dbdrop = 0; + } + + $dbname = $_POST['dbname']; + if (isset($_POST['url'])) { + $url = $_POST['url']; + } else { + $url = 'http://localhost'; + } + + if (isset($_POST['path'])) { + $path = $_POST['path']; + $path = str_replace('\\', '/', $path); + // Windows compatibility + } else { + $path = '/var/www'; + } + } + + $everything_ok = 0; + $step1 = 0; + $step2 = 0; + $step3 = 0; + $step4 = 0; + $step5 = 0; + $step6 = 0; + $step7 = 0; + + echo " +
      +
      + ".print_logo_status(5, 6)." +
      +

      Creating database and default configuration file

      + "; + switch ($engine) { + case 'mysql': + if (! mysql_connect($dbhost, $dbuser, $dbpassword)) { + check_generic(0, 'Connection with Database'); + } else { + check_generic(1, 'Connection with Database'); + + // Drop database if needed and don't want to install over an existing DB + if ($dbdrop == 1) { + mysql_query("DROP DATABASE IF EXISTS `$dbname`"); + } + + // Create schema + if ($dbaction == 'db_new' || $dbdrop == 1) { + $step1 = mysql_query("CREATE DATABASE `$dbname`"); + check_generic($step1, "Creating database '$dbname'"); + } else { + $step1 = 1; + } + + if ($step1 == 1) { + $step2 = mysql_select_db($dbname); + check_generic($step2, "Opening database '$dbname'"); + + $step3 = parse_mysql_dump('pandoradb.sql'); + check_generic($step3, 'Creating schema'); + + $step4 = parse_mysql_dump('pandoradb_data.sql'); + check_generic($step4, 'Populating database'); + if (PHP_OS == 'FreeBSD') { + $step_freebsd = adjust_paths_for_freebsd($engine); + check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); + } + + $random_password = random_name(8); + $host = $dbhost; + // set default granted origin to the origin of the queries + if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { + $host = $dbgrant; + // if the granted origin is different from local machine, set the valid origin + } + + $step5 = mysql_query( + "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host + IDENTIFIED BY '".$random_password."'" + ); + mysql_query('FLUSH PRIVILEGES'); + check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
      Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
      "); + + $step6 = is_writable('include'); + check_generic($step6, "Write permissions to save config file in './include'"); + + $cfgin = fopen('include/config.inc.php', 'r'); + $cfgout = fopen($pandora_config, 'w'); + $config_contents = fread($cfgin, filesize('include/config.inc.php')); + $dbtype = 'mysql'; + $config_new = ''; + $step7 = fputs($cfgout, $config_new); + $step7 = ($step7 + fputs($cfgout, $config_contents)); + if ($step7 > 0) { + $step7 = 1; + } + + fclose($cfgin); + fclose($cfgout); + chmod($pandora_config, 0600); + check_generic($step7, "Created new config file at '".$pandora_config."'"); + } + } + + if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { + $everything_ok = 1; + } + break; + + case 'mysqli': + $connection = mysqli_connect($dbhost, $dbuser, $dbpassword); + if (mysqli_connect_error() > 0) { + check_generic(0, 'Connection with Database'); + } else { + check_generic(1, 'Connection with Database'); + + // Drop database if needed and don't want to install over an existing DB + if ($dbdrop == 1) { + mysqli_query($connection, "DROP DATABASE IF EXISTS `$dbname`"); + } + + // Create schema + if ($dbaction == 'db_new' || $dbdrop == 1) { + $step1 = mysqli_query($connection, "CREATE DATABASE `$dbname`"); + check_generic($step1, "Creating database '$dbname'"); + } else { + $step1 = 1; + } + + if ($step1 == 1) { + $step2 = mysqli_select_db($connection, $dbname); + check_generic($step2, "Opening database '$dbname'"); + + $step3 = parse_mysqli_dump($connection, 'pandoradb.sql'); + check_generic($step3, 'Creating schema'); + + $step4 = parse_mysqli_dump($connection, 'pandoradb_data.sql'); + check_generic($step4, 'Populating database'); + if (PHP_OS == 'FreeBSD') { + $step_freebsd = adjust_paths_for_freebsd($engine, $connection); + check_generic($step_freebsd, 'Adjusting paths in database for FreeBSD'); + } + + $random_password = random_name(8); + $host = $dbhost; + // set default granted origin to the origin of the queries + if (($dbhost != 'localhost') && ($dbhost != '127.0.0.1')) { + $host = $dbgrant; + // if the granted origin is different from local machine, set the valid origin + } + + $step5 = mysqli_query( + $connection, + "GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host + IDENTIFIED BY '".$random_password."'" + ); + mysqli_query($connection, 'FLUSH PRIVILEGES'); + check_generic($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
      Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
      "); + + $step6 = is_writable('include'); + check_generic($step6, "Write permissions to save config file in './include'"); + + $cfgin = fopen('include/config.inc.php', 'r'); + $cfgout = fopen($pandora_config, 'w'); + $config_contents = fread($cfgin, filesize('include/config.inc.php')); + $dbtype = 'mysql'; + $config_new = ''; + $step7 = fputs($cfgout, $config_new); + $step7 = ($step7 + fputs($cfgout, $config_contents)); + if ($step7 > 0) { + $step7 = 1; + } + + fclose($cfgin); + fclose($cfgout); + chmod($pandora_config, 0600); + check_generic($step7, "Created new config file at '".$pandora_config."'"); + } + } + + if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { + $everything_ok = 1; + } + break; + } + + echo '
      '; + + if ($everything_ok == 1) { + echo "
      "; + echo " + "; + echo '
      '; + } else { + $info = "
      There were some problems. + Installation was not completed. +

      Please correct failures before trying again. + All database "; + if ($engine == 'oracle') { + $info .= 'objects '; + } else { + $info .= 'schemes '; + } + + $info .= 'created in this step have been dropped.

      +
      '; + echo $info; + + switch ($engine) { + case 'mysql': + if (mysql_error() != '') { + echo "
      ERROR: ".mysql_error().'.
      '; + } + + if ($step1 == 1) { + mysql_query("DROP DATABASE $dbname"); + } + break; + + case 'mysqli': + if (mysqli_error($connection) != '') { + echo "
      ERROR: ".mysqli_error($connection).'.
      '; + } + + if ($step1 == 1) { + mysqli_query($connection, "DROP DATABASE $dbname"); + } + break; + } + + echo '
      '; + } + + echo '
      '; + echo "
      "; + echo " +
      +
      + Pandora FMS is an Open Source Software project registered at + SourceForge +
      +
      "; +} + + +function install_step5() +{ + echo " +
      +
      + ".print_logo_status(6, 6)." +
      +

      Installation complete

      +

      For security, you now must manually delete this installer + ('install.php') file before trying to access to your Pandora FMS console. +

      You should also install Pandora FMS Servers before trying to monitor anything; + please read documentation on how to install it.

      +

      Default user is 'admin' with password 'pandora', + please change it both as soon as possible.

      +

      Don't forget to check http://pandorafms.com + for updates. +

      Select if you want to rename 'install.php'.

      +
      + + +
      +


      . +

      +
      "; + + echo "
      +
      + Pandora FMS is an OpenSource Software project registered at + SourceForge +
      +
      "; +} From 96fccc578c2349207482b4daf1a25e411f04c8b7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 14 Feb 2019 17:56:10 +0100 Subject: [PATCH 13/50] WIP: H&D Former-commit-id: 82a6c84a2c896a08f420a89dc3fe6cd79d8ff3bb --- .../godmode/wizards/HostDevices.class.php | 298 +++++------------- .../godmode/wizards/Wizard.main.php | 7 + 2 files changed, 83 insertions(+), 222 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 23250995db..758f8e653b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -1,7 +1,34 @@ setBreadcrum( - [ - 'Host&devices', - 'Import CSV', - ] - ); - $this->printHeader(); - return $this->runCSV(); + if (enterprise_installed()) { + if ($mode == 'importcsv') { + $this->setBreadcrum( + [ + 'Host&devices', + 'Import CSV', + ] + ); + $this->printHeader(); + $csv_importer = new CSVImportAgents($this->page, $this->breadcrum); + return $csv_importer->runCSV(); + } } if ($mode == 'netscan') { @@ -172,154 +195,6 @@ class HostDevices extends Wizard // Extra methods. - /** - * Undocumented function - * - * @return void - */ - public function runCSV() - { - global $config; - - if (!check_acl($config['id_user'], 0, 'AW')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access db status' - ); - include 'general/noaccess.php'; - return; - } - - if (!isset($this->page) || $this->page == 0) { - $this->printForm( - [ - 'form' => [ - 'action' => '#', - 'method' => 'POST', - 'enctype' => 'multipart/form-data', - ], - 'inputs' => [ - [ - 'arguments' => [ - 'type' => 'hidden', - 'name' => 'import_file', - 'value' => 1, - 'return' => true, - ], - ], - [ - 'label' => __('Upload file'), - 'arguments' => [ - 'type' => 'file', - 'name' => 'file', - 'return' => true, - ], - ], - [ - 'label' => __('Server'), - 'arguments' => [ - 'type' => 'select', - 'fields' => servers_get_names(), - 'name' => 'server', - 'return' => true, - ], - ], - [ - 'label' => __('Separator'), - 'arguments' => [ - 'type' => 'select', - 'fields' => [ - ',' => ',', - ';' => ';', - ':' => ':', - '.' => '.', - '#' => '#', - ], - 'name' => 'separator', - 'return' => true, - ], - ], - [ - 'arguments' => [ - 'name' => 'page', - 'value' => 1, - 'type' => 'hidden', - 'return' => true, - ], - ], - [ - 'arguments' => [ - 'name' => 'submit', - 'label' => __('Go'), - 'type' => 'submit', - 'attributes' => 'class="sub next"', - 'return' => true, - ], - ], - ], - ] - ); - } - - if (isset($this->page) && $this->page == 1) { - $server = get_parameter('server'); - $separator = get_parameter('separator'); - - if (isset($_FILES['file'])) { - $file_status_code = get_file_upload_status('file'); - $file_status = translate_file_upload_status($file_status_code); - - if ($file_status === true) { - $error_message = []; - $line = -1; - $file = fopen($_FILES['file']['tmp_name'], 'r'); - if (! empty($file)) { - while (($data = fgetcsv($file, 1000, $separator)) !== false) { - $result = $this->processCsvData($data, $server); - $line++; - if ($result === HDW_CSV_NOT_DATA || $result === HDW_CSV_DUPLICATED || $result === HDW_CSV_GROUP_EXISTS) { - if ($result === HDW_CSV_NOT_DATA) { - $error_message[] = __('No data or wrong separator in line ').$line.'
      '; - } else if ($result === HDW_CSV_DUPLICATED) { - $error_message[] = __('Agent ').io_safe_input($data[0]).__(' duplicated').'
      '; - } else { - $error_message[] = __("Id group %s in line %s doesn't exist in %s", $data[4], $line, get_product_name()).'
      '; - } - - continue; - } - - ui_print_result_message( - $result !== false, - __('Created agent %s', $result['agent_name']), - __('Could not create agent %s', $result['agent_name']) - ); - } - } - - fclose($file); - - if (empty($error_message)) { - ui_print_success_message(__('File processed')); - } else { - foreach ($error_message as $msg) { - ui_print_error_message($msg); - } - } - } else { - ui_print_error_message($file_status); - } - - @unlink($_FILES['file']['tmp_name']); - } else { - ui_print_error_message(__('No input file detected')); - } - - echo $this->breadcrum[0]; - } - } - - /** * Retrieves and validates information given by user in NetScan wizard. * @@ -701,6 +576,7 @@ class HostDevices extends Wizard ], ]; + // SNMP Options pack v1. $form['inputs'][] = [ 'hidden' => 1, 'block_id' => 'snmp_options_v1', @@ -718,6 +594,42 @@ class HostDevices extends Wizard ], ]; + // SNMP Options pack v2c. + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_v2c', + 'block_content' => [ + [ + 'label' => __('Community'), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + + ], + ], + ], + ]; + + // SNMP Options pack v3. + $form['inputs'][] = [ + 'hidden' => 1, + 'block_id' => 'snmp_options_v3', + 'block_content' => [ + [ + 'label' => __(''), + 'arguments' => [ + 'name' => 'community', + 'type' => 'text', + 'size' => 25, + 'return' => true, + + ], + ], + ], + ]; + // Input: WMI enabled. $form['inputs'][] = [ 'label' => __('WMI enabled'), @@ -905,62 +817,4 @@ $("select#interval_manual_defined").change(function() { } - /** - * Process the csv of agent. - * - * @param array $data Data of agent. - * @param string $server Name of server. - * - * @return array with data porcessed. - */ - private static function processCsvData($data, $server='') - { - if (empty($data) || count($data) < 5) { - return HDW_CSV_NOT_DATA; - } - - $data['network_components'] = array_slice($data, 6); - $data['agent_name'] = io_safe_input($data[0]); - $data['alias'] = io_safe_input($data[0]); - $data['ip_address'] = $data[1]; - $data['id_os'] = $data[2]; - $data['interval'] = $data[3]; - $data['id_group'] = $data[4]; - $data['comentarios'] = io_safe_input($data[5]); - - $exists = (bool) agents_get_agent_id($data['agent_name']); - if ($exists) { - return HDW_CSV_DUPLICATED; - } - - $group_exists_in_pandora = (bool) groups_get_group_by_id($data['id_group']); - if (!$group_exists_in_pandora) { - return HDW_CSV_GROUP_EXISTS; - } - - $data['id_agent'] = agents_create_agent( - $data['agent_name'], - $data['id_group'], - $data['interval'], - $data['ip_address'], - [ - 'id_os' => $data['id_os'], - 'server_name' => $server, - 'modo' => 1, - 'alias' => $data['alias'], - 'comentarios' => $data['comentarios'], - ] - ); - - foreach ($data['network_components'] as $id_network_component) { - network_components_create_module_from_network_component( - (int) $id_network_component, - $data['id_agent'] - ); - } - - return $data; - } - - } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index c164b287b7..1a70bae362 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -13,6 +13,13 @@ class Wizard */ public $breadcrum; + /** + * Undocumented variable + * + * @var [type] + */ + public $page; + /** * Setter for breadcrum From f777c59a8374025b1c2d3950c4b0df9ad6500df7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 10:00:23 +0100 Subject: [PATCH 14/50] WIP: H&D skel files css wiz&discov Former-commit-id: e57758a9e77b19868262557d9e11a0ff7b38f02c --- pandora_console/godmode/servers/discovery.php | 2 ++ pandora_console/include/styles/discovery.css | 3 +++ pandora_console/include/styles/wizard.css | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 pandora_console/include/styles/discovery.css diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 39c31b9465..25619fbc7a 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -13,6 +13,8 @@ if (! check_acl($config['id_user'], 0, 'AW')) { exit; } +ui_require_css_file('discovery'); + ui_print_page_header(__('Discover'), 'wizards/hostDevices.png', false, '', true); diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css new file mode 100644 index 0000000000..62be6c7c98 --- /dev/null +++ b/pandora_console/include/styles/discovery.css @@ -0,0 +1,3 @@ +/* + * Discovery css global + */ diff --git a/pandora_console/include/styles/wizard.css b/pandora_console/include/styles/wizard.css index fdaf5afa4b..912f5d5a4f 100644 --- a/pandora_console/include/styles/wizard.css +++ b/pandora_console/include/styles/wizard.css @@ -1,3 +1,7 @@ +/* + * Discovery > Wizard css global style + */ + ul.wizard { } From efdc17b801579c1f69d095ea8e251f61f5c43522 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 13:08:44 +0100 Subject: [PATCH 15/50] WIP: H&D Former-commit-id: 605aa350c6d8d9bcebadbb941bba2a6fc399cb7c --- pandora_console/godmode/servers/discovery.php | 3 +- .../godmode/wizards/HostDevices.class.php | 417 +++++++++++++++--- pandora_console/include/functions.php | 20 + 3 files changed, 374 insertions(+), 66 deletions(-) diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 25619fbc7a..70da2939e7 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -52,8 +52,9 @@ $classname_selected = get_wiz_class($wiz_in_use); // Else: class not found pseudo exception. if ($classname_selected !== null) { $wiz = new $classname_selected($page); - $wiz->run(); + $result = $wiz->run(); // TODO: Here we'll controlle if return is a valid recon task id. + hd($result); } if ($classname_selected === null) { diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 758f8e653b..7e2772d6e1 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -102,7 +102,7 @@ class HostDevices extends Wizard */ public function __construct( int $page=0, - string $msg='hola', + string $msg='Default message. Not set.', string $icon='hostDevices.png', string $label='Host & Devices' ) { @@ -203,19 +203,68 @@ class HostDevices extends Wizard public function parseNetScan() { if ($this->page == 0) { - // Error. Must not be here. + // Check if we're updating a task. + $task_id = get_parameter('task', null); + + if (isset($task_id) === true) { + // We're updating this task. + $task = db_get_row( + 'trecon_task', + 'id_rt', + $task_id + ); + + if ($task !== false) { + $this->task = $task; + } + } + return true; } // Validate response from page 0. No, not a bug, we're always 1 page // from 'validation' page. if ($this->page == 1) { + $task_id = get_parameter('task', null); $taskname = get_parameter('taskname', ''); $comment = get_parameter('comment', ''); $server_id = get_parameter('id_recon_server', ''); - $network = get_parameter('name', ''); + $network = get_parameter('network', ''); $id_group = get_parameter('id_group', ''); + if (isset($task_id) === true) { + // We're updating this task. + $task = db_get_row( + 'trecon_task', + 'id_rt', + $task_id + ); + + if ($task !== false) { + $this->task = $task; + } + } else if (isset($taskname) === true + && isset($network) === true + ) { + // Avoid double creation. + $task = db_get_row_filter( + 'trecon_task', + [ + 'name' => $taskname, + 'subnet' => $network, + ] + ); + + if ($task !== false) { + $this->task = $task; + } + } + + if (isset($this->task['id_rt']) === false) { + // Disabled 2 Implies wizard non finished. + $this->task['disabled'] = 2; + } + if ($taskname == '') { $this->msg = __('You must provide a task name.'); return false; @@ -242,12 +291,9 @@ class HostDevices extends Wizard $this->task['description'] = $comment; $this->task['subnet'] = $network; $this->task['id_recon_server'] = $server_id; - // Disabled 2 Implies wizard non finished. - $this->task['disabled'] = 2; + $this->task['id_group'] = $id_group; - $this->task['id_rt'] = 5; - - if (!isset($this->task['id_rt'])) { + if (isset($this->task['id_rt']) === false) { // Create. $this->task['id_rt'] = db_process_sql_insert( 'trecon_task', @@ -269,24 +315,121 @@ class HostDevices extends Wizard if ($this->page == 2) { $id_rt = get_parameter('task', -1); - $this->task = db_get_row( + $task = db_get_row( 'trecon_task', 'id_rt', $id_rt ); - hd($this->task); + if ($task !== false) { + $this->task = $task; + } else { + $this->msg = __('Failed to find network scan task.'); + return false; + } - return false; + $id_network_profile = get_parameter('id_network_profile', null); + $snmp_enabled = get_parameter_switch('snmp_enabled'); + $os_detect = get_parameter_switch('os_detect'); + $parent_detection = get_parameter_switch('parent_detection'); + $parent_recursion = get_parameter_switch('parent_recursion'); + $vlan_enabled = get_parameter_switch('vlan_enabled'); + $snmp_version = get_parameter('snmp_version', null); + $community = get_parameter('community', null); + $snmp_context = get_parameter('snmp_context', null); + $snmp_auth_user = get_parameter('snmp_auth_user', null); + $snmp_auth_pass = get_parameter('snmp_auth_pass', null); + $snmp_privacy_method = get_parameter('snmp_privacy_method', null); + $snmp_privacy_pass = get_parameter('snmp_privacy_pass', null); + $snmp_auth_method = get_parameter('snmp_auth_method', null); + $snmp_security_level = get_parameter('snmp_security_level', null); + $auth_strings = get_parameter('auth_strings', null); + + if ($snmp_version == 3) { + $this->task['snmp_community'] = $snmp_context; + } else { + $this->task['snmp_community'] = $community; + } + + $this->task['id_network_profile'] = $id_network_profile; + $this->task['snmp_enabled'] = $snmp_enabled; + $this->task['os_detect'] = $os_detect; + $this->task['parent_detection'] = $parent_detection; + $this->task['parent_recursion'] = $parent_recursion; + $this->task['vlan_enabled'] = $vlan_enabled; + $this->task['snmp_version'] = $snmp_version; + $this->task['snmp_auth_user'] = $snmp_auth_user; + $this->task['snmp_auth_pass'] = $snmp_auth_pass; + $this->task['snmp_privacy_method'] = $snmp_privacy_method; + $this->task['snmp_privacy_pass'] = $snmp_privacy_pass; + $this->task['snmp_auth_method'] = $snmp_auth_method; + $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. - $interval = get_parameter('interval', 0); + $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); $this->task['interval_sweep'] = $interval; - return false; + + if ($this->task['disabled'] == 2) { + // Wizard finished. + $this->task['disabled'] = 0; + } + + // Update. + $res = db_process_sql_update( + 'trecon_task', + $this->task, + ['id_rt' => $this->task['id_rt']] + ); + + return true; + } + + if ($this->page == 4) { + // Wizard ended. Load data and return control to Discovery. + $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; + } + + return true; } return false; @@ -326,14 +469,14 @@ class HostDevices extends Wizard $form = [ 'form' => [ 'method' => 'POST', - 'action' => '#', + 'action' => $this->url.'&mode=netscan&page='.($this->page - 1).'&task='.$this->task['id_rt'], ], 'inputs' => [ [ 'arguments' => [ 'type' => 'hidden', - 'name' => 'page', - 'value' => ($this->page - 1), + 'name' => 'task', + 'value' => $this->task['id_rt'], ], ], [ @@ -364,7 +507,7 @@ class HostDevices extends Wizard $form = [ 'form' => [ 'method' => 'POST', - 'action' => '#', + 'action' => $this->url.'&mode=netscan&page=0', ], 'inputs' => [ [ @@ -404,18 +547,29 @@ class HostDevices extends Wizard 'label' => ''.__('Task name').'', 'arguments' => [ 'name' => 'taskname', - 'value' => '', + 'value' => $this->task['name'], 'type' => 'text', 'size' => 25, ], ]; + if (isset($this->task['id_rt']) === true) { + // Propagate id. + $form['inputs'][] = [ + 'arguments' => [ + 'name' => 'task', + 'value' => $this->task['id_rt'], + 'type' => 'hidden', + ], + ]; + } + // Input task name. $form['inputs'][] = [ 'label' => ''.__('Comment').'', 'arguments' => [ 'name' => 'comment', - 'value' => '', + 'value' => $this->task['description'], 'type' => 'text', 'size' => 25, ], @@ -437,7 +591,7 @@ class HostDevices extends Wizard SERVER_TYPE_DISCOVERY ), 'name' => 'id_recon_server', - 'selected' => 0, + 'selected' => $this->task['id_recon_server'], 'return' => true, ], ]; @@ -450,8 +604,8 @@ class HostDevices extends Wizard true ), 'arguments' => [ - 'name' => 'name', - 'value' => '', + 'name' => 'network', + 'value' => $this->task['subnet'], 'type' => 'text', 'size' => 25, ], @@ -464,25 +618,22 @@ class HostDevices extends Wizard 'name' => 'id_group', 'privilege' => 'PM', 'type' => 'select_groups', + 'selected' => $this->task['id_group'], 'return' => true, ], ]; - // Hidden, page. - $form['inputs'][] = [ - 'arguments' => [ - 'name' => 'page', - 'value' => ($this->page + 1), - 'type' => 'hidden', - 'return' => true, - ], - ]; + $str = __('Next'); + + if (isset($this->task['id_rt']) === true) { + $str = __('Update and continue'); + } // Submit button. $form['inputs'][] = [ 'arguments' => [ 'name' => 'submit', - 'label' => __('Next'), + 'label' => $str, 'type' => 'submit', 'attributes' => 'class="sub next"', 'return' => true, @@ -491,7 +642,7 @@ class HostDevices extends Wizard $form['form'] = [ 'method' => 'POST', - 'action' => '#', + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1), ]; // XXX: Could be improved validating inputs before continue (JS) @@ -549,27 +700,28 @@ class HostDevices extends Wizard 'name' => 'snmp_enabled', 'type' => 'switch', 'return' => true, - 'onclick' => "\$('#snmp_extra').toggle();", + 'value' => 1, + 'onclick' => 'extraSNMP();', ], ]; // SNMP CONFIGURATION. $form['inputs'][] = [ - 'hidden' => 1, + 'hidden' => 0, 'block_id' => 'snmp_extra', 'block_content' => [ [ 'label' => __('SNMP version'), 'arguments' => [ - 'name' => 'auth_strings', + 'name' => 'snmp_version', 'fields' => [ '1' => 'v. 1', '2c' => 'v. 2c', '3' => 'v. 3', ], 'type' => 'select', - 'script' => "\$('#snmp_options_v'+this.value).toggle()", + 'script' => 'SNMPExtraShow(this.value)', 'return' => true, ], ], @@ -579,28 +731,15 @@ class HostDevices extends Wizard // SNMP Options pack v1. $form['inputs'][] = [ 'hidden' => 1, - 'block_id' => 'snmp_options_v1', + 'block_id' => 'snmp_options_basic', 'block_content' => [ [ - 'label' => __('Community'), - 'arguments' => [ - 'name' => 'community', - 'type' => 'text', - 'size' => 25, - 'return' => true, - - ], - ], - ], - ]; - - // SNMP Options pack v2c. - $form['inputs'][] = [ - 'hidden' => 1, - 'block_id' => 'snmp_options_v2c', - 'block_content' => [ - [ - 'label' => __('Community'), + 'label' => ''.__('SNMP Default community').''.ui_print_help_tip( + __( + 'You can specify several values, separated by commas, for example: public,mysecret,1234' + ), + true + ), 'arguments' => [ 'name' => 'community', 'type' => 'text', @@ -618,15 +757,99 @@ class HostDevices extends Wizard 'block_id' => 'snmp_options_v3', 'block_content' => [ [ - 'label' => __(''), + 'label' => ''.__('Context').'', 'arguments' => [ - 'name' => 'community', + 'name' => 'snmp_context', 'type' => 'text', - 'size' => 25, + 'size' => 15, 'return' => true, ], ], + [ + 'label' => ''.__('Auth user').'', + 'arguments' => [ + 'name' => 'snmp_auth_user', + 'type' => 'text', + 'size' => 15, + 'return' => true, + + ], + ], + [ + 'label' => ''.__('Auth password').''.ui_print_help_tip( + __( + 'The pass length must be eight character minimum.' + ), + true + ), + 'arguments' => [ + 'name' => 'snmp_auth_pass', + 'type' => 'password', + 'size' => 15, + 'return' => true, + + ], + ], + [ + 'label' => ''.__('Privacy method').'', + 'arguments' => [ + 'name' => 'snmp_privacy_method', + 'type' => 'select', + 'fields' => [ + 'DES' => __('DES'), + 'AES' => __('AES'), + ], + 'size' => 15, + 'return' => true, + + ], + ], + [ + 'label' => ''.__('Privacy pass').''.ui_print_help_tip( + __( + 'The pass length must be eight character minimum.' + ), + true + ), + 'arguments' => [ + 'name' => 'snmp_privacy_pass', + 'type' => 'password', + 'size' => 15, + 'return' => true, + + ], + ], + [ + 'label' => ''.__('Auth method').'', + 'arguments' => [ + 'name' => 'snmp_auth_method', + 'type' => 'select', + 'fields' => [ + 'MD5' => __('MD5'), + 'SHA' => __('SHA'), + ], + 'size' => 15, + 'return' => true, + + ], + ], + [ + 'label' => ''.__('Security level').'', + 'arguments' => [ + 'name' => 'snmp_security_level', + 'type' => 'select', + 'fields' => [ + 'noAuthNoPriv' => __('Not auth and not privacy method'), + 'authNoPriv' => __('Auth and not privacy method'), + 'authPriv' => __('Auth and privacy method'), + ], + 'size' => 15, + 'return' => true, + + ], + ], + ], ]; @@ -662,6 +885,7 @@ class HostDevices extends Wizard 'name' => 'os_detect', 'type' => 'switch', 'return' => true, + 'value' => 1, ], ]; @@ -683,6 +907,18 @@ class HostDevices extends Wizard 'name' => 'parent_detection', 'type' => 'switch', 'return' => true, + 'value' => 1, + ], + ]; + + // Input: Parent recursion. + $form['inputs'][] = [ + 'label' => __('Parent recursion'), + 'arguments' => [ + 'name' => 'parent_recursion', + 'type' => 'switch', + 'return' => true, + 'value' => 1, ], ]; @@ -690,9 +926,10 @@ class HostDevices extends Wizard $form['inputs'][] = [ 'label' => __('VLAN enabled'), 'arguments' => [ - 'name' => 'os_detect', + 'name' => 'vlan_enabled', 'type' => 'switch', 'return' => true, + 'value' => 1, ], ]; @@ -707,9 +944,49 @@ class HostDevices extends Wizard ], ]; + $form['js'] = ' +function SNMPExtraShow(target) { + $("#snmp_options_basic").hide(); + $("#snmp_options_v3").hide(); + if (target == 3) { + $("#snmp_options_v3").show(); + } else { + $("#snmp_options_basic").show(); + } + +} + +function extraSNMP() { + if (document.getElementsByName("snmp_enabled")[0].checked) { + SNMPExtraShow($("#snmp_version").val()); + $("#snmp_extra").show(); + } else { + // Hide unusable sections + $("#snmp_extra").hide(); + $("#snmp_options_basic").hide(); + $("#snmp_options_v3").hide(); + + // Disable snmp dependant checks + if (document.getElementsByName("parent_recursion")[0].checked) + $("input[name=parent_recursion]").click(); + + if (document.getElementsByName("parent_detection")[0].checked) + $("input[name=parent_detection]").click(); + + if (document.getElementsByName("vlan_enabled")[0].checked) + $("input[name=vlan_enabled]").click(); + + } +} + +$(function() { + SNMPExtraShow($("#snmp_version").val()) +}); + '; + $form['form'] = [ 'method' => 'POST', - 'action' => '#', + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'], ]; $this->printForm($form); @@ -786,7 +1063,7 @@ class HostDevices extends Wizard $form['form'] = [ 'method' => 'POST', - 'action' => '#', + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).'&task='.$this->task['id_rt'], ]; $form['js'] = ' @@ -807,10 +1084,20 @@ $("select#interval_manual_defined").change(function() { $this->printForm($form); } - if ($this->page == 100) { + if ($this->page == 3) { + if ($this->task['id_rt']) { + // 0 - Is OK. + $this->result = 0; + $this->msg = __('Task configured.'); + } else { + // 1 - Is NOT OK. + $this->result = 1; + $this->msg = __('Wizard failed. Cannot configure task.'); + } + return [ 'result' => $this->result, - 'id' => $this->id, + 'id' => $this->task['id_rt'], 'msg' => $this->msg, ]; } diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 6f13388fc0..58120c4616 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -852,6 +852,26 @@ function get_parameter_checkbox($name, $default='') } +/** + * Transforms a swicth data (on - non present) to a int value. + * + * @param string $name Variable, switch name. + * @param string $default Default value. + * + * @return integer Value, 1 on, 0 off. + */ +function get_parameter_switch($name, $default='') +{ + $data = get_parameter($name, 0); + + if ($data == 'on') { + return 1; + } + + return 0; +} + + function get_cookie($name, $default='') { if (isset($_COOKIE[$name])) { From ec672d6bfbb7a0c133d372e772d4fd5ed4df34c1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 13:57:33 +0100 Subject: [PATCH 16/50] H&D network scan Former-commit-id: dcd22994d6addf69ab5d68a6724d12e26e994d15 --- pandora_console/godmode/servers/discovery.php | 14 +- .../godmode/wizards/HostDevices.class.php | 135 ++++++++++++------ 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 70da2939e7..2afbbb0f24 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -53,8 +53,18 @@ $classname_selected = get_wiz_class($wiz_in_use); if ($classname_selected !== null) { $wiz = new $classname_selected($page); $result = $wiz->run(); - // TODO: Here we'll controlle if return is a valid recon task id. - hd($result); + if (is_array($result) === true) { + if ($result['result'] === 0) { + // Success. + ui_print_success_message($result['msg']); + // TODO: Show task progress before redirect to main discovery menu. + } else { + // Failed. + ui_print_error_message($result['msg']); + } + + $classname_selected = null; + } } if ($classname_selected === null) { diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 7e2772d6e1..f31d16618b 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -160,13 +160,17 @@ class HostDevices extends Wizard } if ($mode == 'netscan') { - $this->setBreadcrum( - [ - 'Host&devices', - 'Net scan', - ] - ); - $this->printHeader(); + if ($this->page != 3) { + // Do not paint breadcrum in last page. Redirected. + $this->setBreadcrum( + [ + 'Host&devices', + 'Net scan', + ] + ); + $this->printHeader(); + } + return $this->runNetScan(); } @@ -258,6 +262,9 @@ class HostDevices extends Wizard if ($task !== false) { $this->task = $task; } + + $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); + return false; } if (isset($this->task['id_rt']) === false) { @@ -334,6 +341,8 @@ class HostDevices extends Wizard $parent_detection = get_parameter_switch('parent_detection'); $parent_recursion = get_parameter_switch('parent_recursion'); $vlan_enabled = get_parameter_switch('vlan_enabled'); + $wmi_enabled = get_parameter_switch('wmi_enabled'); + $resolve_names = get_parameter_switch('resolve_names'); $snmp_version = get_parameter('snmp_version', null); $community = get_parameter('community', null); $snmp_context = get_parameter('snmp_context', null); @@ -357,6 +366,8 @@ class HostDevices extends Wizard $this->task['parent_detection'] = $parent_detection; $this->task['parent_recursion'] = $parent_recursion; $this->task['vlan_enabled'] = $vlan_enabled; + $this->task['wmi_enabled'] = $wmi_enabled; + $this->task['resolve_names'] = $resolve_names; $this->task['snmp_version'] = $snmp_version; $this->task['snmp_auth_user'] = $snmp_auth_user; $this->task['snmp_auth_pass'] = $snmp_auth_pass; @@ -640,9 +651,14 @@ class HostDevices extends Wizard ], ]; + $task_url = ''; + if (isset($this->task['id_rt'])) { + $task_url = '&task='.$this->task['id_rt']; + } + $form['form'] = [ 'method' => 'POST', - 'action' => $this->url.'&mode=netscan&page='.($this->page + 1), + 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url, ]; // XXX: Could be improved validating inputs before continue (JS) @@ -682,12 +698,13 @@ 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, + 'return' => true, + 'selected' => $this->task['id_network_profile'], ], ]; @@ -700,7 +717,7 @@ class HostDevices extends Wizard 'name' => 'snmp_enabled', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['snmp_enabled'])) ? $this->task['snmp_enabled'] : 1, 'onclick' => 'extraSNMP();', ], @@ -714,15 +731,16 @@ class HostDevices extends Wizard [ 'label' => __('SNMP version'), 'arguments' => [ - 'name' => 'snmp_version', - 'fields' => [ + 'name' => 'snmp_version', + 'fields' => [ '1' => 'v. 1', '2c' => 'v. 2c', '3' => 'v. 3', ], - 'type' => 'select', - 'script' => 'SNMPExtraShow(this.value)', - 'return' => true, + 'type' => 'select', + 'script' => 'SNMPExtraShow(this.value)', + 'selected' => $this->task['snmp_version'], + 'return' => true, ], ], ], @@ -743,6 +761,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'community', 'type' => 'text', + 'value' => $this->task['snmp_community'], 'size' => 25, 'return' => true, @@ -761,6 +780,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_context', 'type' => 'text', + 'value' => $this->task['snmp_community'], 'size' => 15, 'return' => true, @@ -771,6 +791,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_auth_user', 'type' => 'text', + 'value' => $this->task['snmp_auth_user'], 'size' => 15, 'return' => true, @@ -786,6 +807,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_auth_pass', 'type' => 'password', + 'value' => $this->task['snmp_auth_pass'], 'size' => 15, 'return' => true, @@ -794,14 +816,15 @@ class HostDevices extends Wizard [ 'label' => ''.__('Privacy method').'', 'arguments' => [ - 'name' => 'snmp_privacy_method', - 'type' => 'select', - 'fields' => [ + 'name' => 'snmp_privacy_method', + 'type' => 'select', + 'fields' => [ 'DES' => __('DES'), 'AES' => __('AES'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_privacy_method'], + 'size' => 15, + 'return' => true, ], ], @@ -815,6 +838,7 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'snmp_privacy_pass', 'type' => 'password', + 'value' => $this->task['snmp_privacy_pass'], 'size' => 15, 'return' => true, @@ -823,29 +847,31 @@ class HostDevices extends Wizard [ 'label' => ''.__('Auth method').'', 'arguments' => [ - 'name' => 'snmp_auth_method', - 'type' => 'select', - 'fields' => [ + 'name' => 'snmp_auth_method', + 'type' => 'select', + 'fields' => [ 'MD5' => __('MD5'), 'SHA' => __('SHA'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_auth_method'], + 'size' => 15, + 'return' => true, ], ], [ 'label' => ''.__('Security level').'', 'arguments' => [ - 'name' => 'snmp_security_level', - 'type' => 'select', - 'fields' => [ + 'name' => 'snmp_security_level', + 'type' => 'select', + 'fields' => [ 'noAuthNoPriv' => __('Not auth and not privacy method'), 'authNoPriv' => __('Auth and not privacy method'), 'authPriv' => __('Auth and privacy method'), ], - 'size' => 15, - 'return' => true, + 'selected' => $this->task['snmp_security_level'], + 'size' => 15, + 'return' => true, ], ], @@ -859,22 +885,27 @@ class HostDevices extends Wizard 'arguments' => [ 'name' => 'wmi_enabled', 'type' => 'switch', + 'value' => (isset($this->task['wmi_enabled'])) ? $this->task['wmi_enabled'] : 0, 'return' => true, - 'onclick' => "\$('#wmi_extra').toggle();", + 'onclick' => 'toggleWMI();', ], ]; // WMI CONFIGURATION. $form['inputs'][] = [ - 'label' => __('WMI Auth. strings'), - 'hidden' => 1, - 'id' => 'wmi_extra', - 'arguments' => [ - 'name' => 'auth_strings', - 'type' => 'text', - 'return' => true, - + 'block_id' => 'wmi_extra', + 'hidden' => 1, + 'block_content' => [ + [ + 'label' => __('WMI Auth. strings'), + 'arguments' => [ + 'name' => 'auth_strings', + 'type' => 'text', + 'value' => $this->task['auth_strings'], + 'return' => true, + ], + ], ], ]; @@ -885,7 +916,7 @@ class HostDevices extends Wizard 'name' => 'os_detect', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['os_detect'])) ? $this->task['os_detect'] : 1, ], ]; @@ -897,6 +928,7 @@ class HostDevices extends Wizard 'name' => 'resolve_names', 'type' => 'switch', 'return' => true, + 'value' => (isset($this->task['resolve_names'])) ? $this->task['resolve_names'] : 0, ], ]; @@ -907,7 +939,7 @@ class HostDevices extends Wizard 'name' => 'parent_detection', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['parent_detection'])) ? $this->task['parent_detection'] : 1, ], ]; @@ -918,7 +950,7 @@ class HostDevices extends Wizard 'name' => 'parent_recursion', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['parent_recursion'])) ? $this->task['parent_recursion'] : 1, ], ]; @@ -929,7 +961,7 @@ class HostDevices extends Wizard 'name' => 'vlan_enabled', 'type' => 'switch', 'return' => true, - 'value' => 1, + 'value' => (isset($this->task['vlan_enabled'])) ? $this->task['vlan_enabled'] : 1, ], ]; @@ -979,8 +1011,16 @@ function extraSNMP() { } } +function toggleWMI() { + if (document.getElementsByName("wmi_enabled")[0].checked) + $("#wmi_extra").show(); + else + $("#wmi_extra").hide(); +} + $(function() { - SNMPExtraShow($("#snmp_version").val()) + SNMPExtraShow($("#snmp_version").val()); + toggleWMI(); }); '; @@ -1082,6 +1122,7 @@ $("select#interval_manual_defined").change(function() { }).change();'; $this->printForm($form); + return null; } if ($this->page == 3) { From 32d34cd09b9ff6fbfed2e6d9a77d3aaf7232a3b0 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 15 Feb 2019 14:02:32 +0100 Subject: [PATCH 17/50] Changed styles in host and devices Former-commit-id: 743f203466e8e3745a33837054e5bc4faa69337c --- pandora_console/godmode/servers/discovery.php | 9 +++--- .../godmode/wizards/HostDevices.class.php | 21 +++++++++++-- pandora_console/images/wizard/csv_image.svg | 4 +++ pandora_console/include/styles/discovery.css | 30 +++++++++++++++++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 pandora_console/images/wizard/csv_image.svg diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 70da2939e7..39cc86675c 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -15,7 +15,7 @@ if (! check_acl($config['id_user'], 0, 'AW')) { ui_require_css_file('discovery'); -ui_print_page_header(__('Discover'), 'wizards/hostDevices.png', false, '', true); +ui_print_page_header(__('Discover'), '', false, '', true); /** @@ -64,13 +64,12 @@ if ($classname_selected === null) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); $wiz_data = $obj->load(); - - hd($wiz_data); ?> +
    • - <?php echo $classname; ?> -
      + <?php echo $classname; ?> +
    • diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 7e2772d6e1..157657d237 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -138,9 +138,24 @@ class HostDevices extends Wizard if ($mode === null) { $this->setBreadcrum(['Host&devices']); $this->printHeader(); - - echo 'Importar csv'; - echo 'Escanear red'; + echo '
      '; + echo '
      '; + echo '
      '; + echo 'importcsv'; + echo '
      '; + echo '
      '; + echo ''.__('Import CSV').''; + echo '
      '; + echo '
      '; + echo '
      '; + echo '
      '; + echo 'importcsv'; + echo '
      '; + echo '
      '; + echo ''.__('Escanear red').''; + echo '
      '; + echo '
      '; + echo '
      '; return; } diff --git a/pandora_console/images/wizard/csv_image.svg b/pandora_console/images/wizard/csv_image.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/csv_image.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 62be6c7c98..5f2cc45b68 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -1,3 +1,33 @@ /* * Discovery css global */ + +#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; +} +#text_wizard { + font-weight: bolder; + text-decoration: none; + font-size: 24px; +} From e397353f71b2cb60bab75a65ad788cb5d91f814f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 14:03:16 +0100 Subject: [PATCH 18/50] minor fix get_parameter_switch Former-commit-id: c8e430e1cbd789a99058217e7dffb4098aab821a --- pandora_console/include/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 58120c4616..e1861e70a3 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -862,9 +862,11 @@ function get_parameter_checkbox($name, $default='') */ function get_parameter_switch($name, $default='') { - $data = get_parameter($name, 0); + $data = get_parameter($name, null); - if ($data == 'on') { + if ($data === null) { + return 0; + } else if ($data == 'on') { return 1; } From c62c01c4a0cc26759b1dcc68dbc69720b96a8ea0 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 14:14:56 +0100 Subject: [PATCH 19/50] H&D minor fix - visual Former-commit-id: 57d1e3c62192d9568bfa4db11658e31a8d811a3a --- .../godmode/wizards/HostDevices.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index c7eddc84f4..adbc13180e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -740,7 +740,7 @@ class HostDevices extends Wizard // SNMP CONFIGURATION. $form['inputs'][] = [ - 'hidden' => 0, + 'hidden' => 1, 'block_id' => 'snmp_extra', 'block_content' => [ [ @@ -995,10 +995,12 @@ class HostDevices extends Wizard function SNMPExtraShow(target) { $("#snmp_options_basic").hide(); $("#snmp_options_v3").hide(); - if (target == 3) { - $("#snmp_options_v3").show(); - } else { - $("#snmp_options_basic").show(); + if (document.getElementsByName("snmp_enabled")[0].checked) { + if (target == 3) { + $("#snmp_options_v3").show(); + } else { + $("#snmp_options_basic").show(); + } } } From 45fd528e3880bea244a350425fbb4003013e0c7f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:02:55 +0100 Subject: [PATCH 20/50] minor fixes H&D Former-commit-id: c3236b91b4b6a0f37af2d4da4955c711dd4ace43 --- pandora_console/godmode/wizards/HostDevices.class.php | 5 ++--- pandora_server/lib/PandoraFMS/Recon/Base.pm | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index adbc13180e..12fcaaa39e 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -276,10 +276,9 @@ class HostDevices extends Wizard if ($task !== false) { $this->task = $task; + $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); + return false; } - - $this->msg = __('This network scan task has been already defined. Please edit it or create a new one.'); - return false; } if (isset($this->task['id_rt']) === false) { diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 8d24ebf311..116bcd75e6 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1500,6 +1500,9 @@ sub snmp_get_command { my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; if ($self->{'snmp_version'} eq "3") { + if ($self->{'community'}) { # Context + $command .= " -N $self->{'community} "; + } $command .= " -l$self->{'snmp_security_level'} "; if ($self->{'snmp_security_level'} ne "noAuthNoPriv") { $command .= " -u$self->{'snmp_auth_user'} -a$self->{'snmp_auth_method'} -A$self->{'snmp_auth_pass'} "; From 7a1b66755deea0a35d5f3ba83fb455726b54db93 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:06:28 +0100 Subject: [PATCH 21/50] minor fixes H&D Former-commit-id: a4ffc2e761dc0a4d06209fb1c448bc17d5d45022 --- pandora_server/lib/PandoraFMS/Recon/Base.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 116bcd75e6..e819b06476 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1501,7 +1501,7 @@ sub snmp_get_command { my $command = "snmpwalk -M/dev/null -r$self->{'snmp_checks'} -t$self->{'snmp_timeout'} -v$self->{'snmp_version'} -On -Oe "; if ($self->{'snmp_version'} eq "3") { if ($self->{'community'}) { # Context - $command .= " -N $self->{'community} "; + $command .= " -N $self->{'community'} "; } $command .= " -l$self->{'snmp_security_level'} "; if ($self->{'snmp_security_level'} ne "noAuthNoPriv") { From 0f375d6a766e5118f999c9337b8368c4d1abedd5 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 16:37:48 +0100 Subject: [PATCH 22/50] H&D minor fix group cannot be All Former-commit-id: 2feb42ce06bd379bbb3804a30fab744a4b01b1e1 --- .../godmode/wizards/HostDevices.class.php | 54 +++++++++++++++---- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 12fcaaa39e..f619d2d706 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -420,7 +420,12 @@ class HostDevices extends Wizard } $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. @@ -640,11 +645,12 @@ class HostDevices extends Wizard $form['inputs'][] = [ 'label' => ''.__('Group').'', 'arguments' => [ - 'name' => 'id_group', - 'privilege' => 'PM', - 'type' => 'select_groups', - 'selected' => $this->task['id_group'], - 'return' => true, + 'name' => 'id_group', + 'returnAllGroup' => false, + 'privilege' => 'PM', + 'type' => 'select_groups', + 'selected' => $this->task['id_group'], + 'return' => true, ], ]; @@ -724,7 +730,7 @@ class HostDevices extends Wizard ]; // Feature configuration. - // Input: Module template. + // Input: SNMP enabled. $form['inputs'][] = [ 'label' => __('SNMP enabled'), 'arguments' => [ @@ -923,7 +929,7 @@ class HostDevices extends Wizard ], ]; - // Input: Module template. + // Input: Enforce os detection. $form['inputs'][] = [ 'label' => __('OS detection'), 'arguments' => [ @@ -1051,10 +1057,40 @@ $(function() { if ($this->page == 2) { // Interval and schedules. $interv_manual = 0; - if ((int) $interval == 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'), @@ -1072,7 +1108,7 @@ $(function() { ], 'extra' => ''.html_print_extended_select_for_time( 'interval', - $interval, + $this->task['interval_sweep'], '', '', '0', From 5093094d7d20bc4e1e1b6fc5f3b9e75ce98ed32b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:05:59 +0100 Subject: [PATCH 23/50] H&D tasklist and some visual changes Former-commit-id: d9130ec520b0c23a9cf42ce62aae6c3d2432649b --- pandora_console/godmode/servers/discovery.php | 15 +- .../wizards/DiscoveryTaskList.class.php | 297 ++++++++++++++++++ .../godmode/wizards/HostDevices.class.php | 59 +--- .../godmode/wizards/Wizard.main.php | 70 ++++- pandora_console/images/wizard/hostdevices.svg | 4 + pandora_console/images/wizard/tasklist.svg | 4 + pandora_console/include/styles/discovery.css | 37 +++ 7 files changed, 430 insertions(+), 56 deletions(-) create mode 100644 pandora_console/godmode/wizards/DiscoveryTaskList.class.php create mode 100644 pandora_console/images/wizard/hostdevices.svg create mode 100644 pandora_console/images/wizard/tasklist.svg diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 456bf05c01..024eb39e30 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -30,6 +30,9 @@ function get_wiz_class($str) case 'hd': return 'HostDevices'; + case 'tasklist': + return 'DiscoveryTaskList'; + default: // Ignore. return null; @@ -37,6 +40,10 @@ function get_wiz_class($str) } +/* + * CLASS LOADER. + */ + // Dynamic class loader. $classes = glob($config['homedir'].'/godmode/wizards/*.class.php'); foreach ($classes as $classpath) { @@ -76,10 +83,12 @@ if ($classname_selected === null) { $wiz_data = $obj->load(); ?> -
    • +
    • - <?php echo $classname; ?> -
      +
      + +
      +
    • diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php new file mode 100644 index 0000000000..0ad4af9683 --- /dev/null +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -0,0 +1,297 @@ +setBreadcrum([]); + + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->label = __($label); + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' + ); + + return $this; + } + + + /** + * Implements run method. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + // Load styles. + parent::run(); + return $this->showList(); + } + + + /** + * Implements load method. + * + * @return mixed Skeleton for button. + */ + public function load() + { + return [ + 'icon' => $this->icon, + 'label' => $this->label, + 'url' => $this->url, + + ]; + + } + + + /** + * Show complete list of running tasks. + * + * @return boolean Success or not. + */ + public function showList() + { + global $config; + + check_login(); + + if (! check_acl($config['id_user'], 0, 'PM')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + // Get all recon servers + $servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3'); + if ($servers === false) { + $servers = []; + ui_print_error_message(__('Discovery Server is disabled')); + return; + } else { + $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); + if ($recon_task === false) { + ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); + include_once $config['homedir'].'/general/firts_task/recon_view.php'; + return; + } else { + include_once $config['homedir'].'/include/functions_graph.php'; + include_once $config['homedir'].'/include/functions_servers.php'; + include_once $config['homedir'].'/include/functions_network_profiles.php'; + + $modules_server = 0; + $total_modules = 0; + $total_modules_data = 0; + + // -------------------------------- + // FORCE A RECON TASK + // -------------------------------- + if (check_acl($config['id_user'], 0, 'PM')) { + if (isset($_GET['force'])) { + $id = (int) get_parameter_get('force', 0); + servers_force_recon_task($id); + } + } + + foreach ($servers as $serverItem) { + $id_server = $serverItem['id_server']; + $server_name = servers_get_name($id_server); + $recon_tasks = db_get_all_rows_field_filter('trecon_task', 'id_recon_server', $id_server); + + // Show network tasks for Recon Server + if ($recon_tasks === false) { + $recon_tasks = []; + } + + $table = new StdClass(); + $table->cellpadding = 4; + $table->cellspacing = 4; + $table->width = '100%'; + $table->class = 'databox data'; + $table->head = []; + $table->data = []; + $table->align = []; + $table->headstyle = []; + for ($i = 0; $i < 9; $i++) { + $table->headstyle[$i] = 'text-align: left;'; + } + + $table->head[0] = __('Force'); + $table->align[0] = 'left'; + + $table->head[1] = __('Task name'); + $table->align[1] = 'left'; + + $table->head[2] = __('Interval'); + $table->align[2] = 'left'; + + $table->head[3] = __('Network'); + $table->align[3] = 'left'; + + $table->head[4] = __('Status'); + $table->align[4] = 'left'; + + $table->head[5] = __('Template'); + $table->align[5] = 'left'; + + $table->head[6] = __('Progress'); + $table->align[6] = 'left'; + + $table->head[7] = __('Updated at'); + $table->align[7] = 'left'; + + $table->head[8] = __('Edit'); + $table->align[8] = 'left'; + + foreach ($recon_tasks as $task) { + $data = []; + + if ($task['disabled'] == 0) { + $data[0] = ''; + $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); + $data[0] .= ''; + } else { + $data[0] = ''; + } + + $data[1] = ''.$task['name'].''; + + $data[2] = human_time_description_raw($task['interval_sweep']); + + if ($task['id_recon_script'] == 0) { + $data[3] = $task['subnet']; + } else { + $data[3] = '-'; + } + + if ($task['status'] <= 0) { + $data[4] = __('Done'); + } else { + $data[4] = __('Pending'); + } + + if ($task['id_recon_script'] == 0) { + // Network recon task + $data[5] = html_print_image('images/network.png', true, ['title' => __('Network recon task')]).'  '; + $data[5] .= network_profiles_get_name($task['id_network_profile']); + } else { + // APP recon task + $data[5] = html_print_image('images/plugin.png', true).'  '; + $data[5] .= db_get_sql(sprintf('SELECT name FROM trecon_script WHERE id_recon_script = %d', $task['id_recon_script'])); + } + + if ($task['status'] <= 0 || $task['status'] > 100) { + $data[6] = '-'; + } else { + $data[6] = progress_bar($task['status'], 100, 20, __('Progress').':'.$task['status'].'%', 1); + } + + $data[7] = ui_print_timestamp($task['utimestamp'], true); + + if (check_acl($config['id_user'], $task['id_group'], 'PM')) { + $data[8] = ''.html_print_image( + 'images/wrench_orange.png', + true + ).''; + } else { + $data[8] = ''; + } + + array_push($table->data, $data); + } + + if (empty($table->data)) { + echo '
      '.__('Server').' '.$server_name.' '.__('has no recon tasks assigned').'
      '; + } else { + html_print_table($table); + } + + unset($table); + } + } + } + + $form = [ + 'form' => [ + 'method' => 'POST', + 'action' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + ], + 'inputs' => [ + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go back'), + 'type' => 'submit', + 'attributes' => 'class="sub cancel"', + 'return' => true, + ], + ], + ], + ]; + + $this->printForm($form); + + return true; + } + + +} diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index f619d2d706..633fbfe19f 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -31,56 +31,12 @@ require_once $config['homedir'].'/include/functions_users.php'; enterprise_include('include/class/CSVImportAgents.class.php'); /** - * Undocumented class + * Wizard section Host&devices. + * Provides classic recon task creation. + * In enterprise environments, provides also CSV agent import features. */ class HostDevices extends Wizard { - // CSV constants. - const HDW_CSV_NOT_DATA = 0; - const HDW_CSV_DUPLICATED = 0; - const HDW_CSV_GROUP_EXISTS = 0; - - /** - * Undocumented variable - * - * @var array - */ - public $values = []; - - /** - * Undocumented variable - * - * @var [type] - */ - public $result; - - /** - * Undocumented variable - * - * @var [type] - */ - public $msg; - - /** - * Undocumented variable - * - * @var [type] - */ - public $icon; - - /** - * Undocumented variable - * - * @var [type] - */ - public $label; - - /** - * Undocumented variable - * - * @var [type] - */ - public $url; /** * Stores all needed parameters to create a recon task. @@ -91,7 +47,7 @@ class HostDevices extends Wizard /** - * Undocumented function. + * Constructor. * * @param integer $page Start page, by default 0. * @param string $msg Mensajito. @@ -103,7 +59,7 @@ class HostDevices extends Wizard public function __construct( int $page=0, string $msg='Default message. Not set.', - string $icon='hostDevices.png', + string $icon='images/wizard/hostdevices.svg', string $label='Host & Devices' ) { $this->setBreadcrum([]); @@ -122,9 +78,9 @@ class HostDevices extends Wizard /** - * Undocumented function + * Run wizard manager. * - * @return void + * @return mixed Returns null if wizard is ongoing. Result if done. */ public function run() { @@ -684,6 +640,7 @@ class HostDevices extends Wizard // XXX: Could be improved validating inputs before continue (JS) // Print NetScan page 0. $this->printForm($form); + $this->printGoBackButton(); } } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 1a70bae362..ecc253ad04 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -20,6 +20,41 @@ class Wizard */ public $page; + /** + * Target icon to be shown in discovery wizard list. + * + * @var string + */ + public $icon; + + /** + * Target label to be shown in discovery wizard list. + * + * @var string + */ + public $label; + + /** + * This wizard's url. + * + * @var string + */ + public $url; + + /** + * Result of wizard execution (0 - ok, 1 - not ok). + * + * @var integer + */ + public $result; + + /** + * Message to be delivered to user. + * + * @var string + */ + public $msg; + /** * Setter for breadcrum @@ -285,13 +320,13 @@ class Wizard ); case 'submit': - return html_print_submit_button( + return '
      '.html_print_submit_button( ((isset($data['label']) === true) ? $data['label'] : 'OK'), ((isset($data['name']) === true) ? $data['name'] : ''), ((isset($data['disabled']) === true) ? $data['disabled'] : false), ((isset($data['attributes']) === true) ? $data['attributes'] : ''), ((isset($data['return']) === true) ? $data['return'] : false) - ); + ).'
      '; case 'checkbox': return html_print_checkbox( @@ -316,6 +351,37 @@ class Wizard } + /** + * Prints a go back button redirecting to main page. + * + * @return void + */ + public function printGoBackButton() + { + $form = [ + 'form' => [ + 'method' => 'POST', + 'action' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + ], + 'inputs' => [ + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => __('Go back'), + 'type' => 'submit', + 'attributes' => 'class="sub cancel"', + 'return' => true, + ], + ], + ], + ]; + + $this->printForm($form); + } + + /** * Print a block of inputs. * diff --git a/pandora_console/images/wizard/hostdevices.svg b/pandora_console/images/wizard/hostdevices.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/hostdevices.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/images/wizard/tasklist.svg b/pandora_console/images/wizard/tasklist.svg new file mode 100644 index 0000000000..1e82511472 --- /dev/null +++ b/pandora_console/images/wizard/tasklist.svg @@ -0,0 +1,4 @@ + + + + diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 5f2cc45b68..df393fdf3e 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -2,6 +2,43 @@ * Discovery css global */ +li.discovery { + display: inline-block; + float: left; + width: 250px; + height: 120px; + margin: 15px; +} + +li.discovery > a { + text-decoration: none; +} + +li.discovery > a:hover { + color: #000; +} + +li.discovery img { + height: 90px; +} + +li.discovery > a label { + cursor: pointer; +} + +div.data_container { + width: 100%; + height: 100%; + text-align: center; + border: 1px solid #ddd; + padding-top: 30px; + padding-bottom: 30px; +} + +div.data_container:hover { + box-shadow: 2px 2px 10px #ddd; +} + #contenedor_principal { height: auto; position: relative; From a5ad61f340ac851ca5dc5226132a29e50c1c2ed7 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:35:35 +0100 Subject: [PATCH 24/50] discovery delete task Former-commit-id: 8809067053aa6bebfa61498afb2108aea352f3d7 --- .../wizards/DiscoveryTaskList.class.php | 73 ++++++++++++++++--- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 0ad4af9683..5488b675b9 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -76,6 +76,13 @@ class DiscoveryTaskList extends Wizard { // Load styles. parent::run(); + + $delete = (bool) get_parameter('delete', false); + + if ($delete) { + return $this->deleteTask(); + } + return $this->showList(); } @@ -97,6 +104,41 @@ class DiscoveryTaskList extends Wizard } + /** + * Delete a recon task. + * + * @return void + */ + public function deleteTask() + { + global $config; + + if (! check_acl($config['id_user'], 0, 'PM')) { + db_pandora_audit( + 'ACL Violation', + 'Trying to access recon task viewer' + ); + include 'general/noaccess.php'; + return; + } + + $task = get_parameter('task', null); + + if ($task !== null) { + db_process_sql_delete( + 'trecon_task', + ['id_rt' => $task] + ); + } + + return [ + 'result' => 0, + 'msg' => __('Task successfully deleted'), + 'id' => false, + ]; + } + + /** * Show complete list of running tasks. * @@ -114,21 +156,21 @@ class DiscoveryTaskList extends Wizard 'Trying to access recon task viewer' ); include 'general/noaccess.php'; - return; + return false; } - // Get all recon servers + // Get all recon servers. $servers = db_get_all_rows_sql('SELECT * FROM tserver WHERE server_type = 3'); if ($servers === false) { $servers = []; ui_print_error_message(__('Discovery Server is disabled')); - return; + return false; } else { $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); if ($recon_task === false) { ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); include_once $config['homedir'].'/general/firts_task/recon_view.php'; - return; + return false; } else { include_once $config['homedir'].'/include/functions_graph.php'; include_once $config['homedir'].'/include/functions_servers.php'; @@ -145,6 +187,11 @@ class DiscoveryTaskList extends Wizard if (isset($_GET['force'])) { $id = (int) get_parameter_get('force', 0); servers_force_recon_task($id); + header( + 'Location: '.ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' + ) + ); } } @@ -153,7 +200,7 @@ class DiscoveryTaskList extends Wizard $server_name = servers_get_name($id_server); $recon_tasks = db_get_all_rows_field_filter('trecon_task', 'id_recon_server', $id_server); - // Show network tasks for Recon Server + // Show network tasks for Recon Server. if ($recon_tasks === false) { $recon_tasks = []; } @@ -195,14 +242,16 @@ class DiscoveryTaskList extends Wizard $table->head[7] = __('Updated at'); $table->align[7] = 'left'; - $table->head[8] = __('Edit'); + $table->head[8] = __('Operations'); $table->align[8] = 'left'; foreach ($recon_tasks as $task) { $data = []; if ($task['disabled'] == 0) { - $data[0] = ''; + $data[0] = ''; $data[0] .= html_print_image('images/target.png', true, ['title' => __('Force')]); $data[0] .= ''; } else { @@ -226,11 +275,11 @@ class DiscoveryTaskList extends Wizard } if ($task['id_recon_script'] == 0) { - // Network recon task + // Network recon task. $data[5] = html_print_image('images/network.png', true, ['title' => __('Network recon task')]).'  '; $data[5] .= network_profiles_get_name($task['id_network_profile']); } else { - // APP recon task + // APP recon task. $data[5] = html_print_image('images/plugin.png', true).'  '; $data[5] .= db_get_sql(sprintf('SELECT name FROM trecon_script WHERE id_recon_script = %d', $task['id_recon_script'])); } @@ -250,6 +299,12 @@ class DiscoveryTaskList extends Wizard 'images/wrench_orange.png', true ).''; + $data[8] .= ''.html_print_image( + 'images/cross.png', + true + ).''; } else { $data[8] = ''; } From 912f0baace3b3917fdf76dd7703078901f86de48 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:42:44 +0100 Subject: [PATCH 25/50] Discovery Tasks first tasks and some minor fixes Former-commit-id: 4a37dc99f1b1a95217e9be207526d750133a14a6 --- pandora_console/general/firts_task/recon_view.php | 10 +++++----- .../godmode/wizards/DiscoveryTaskList.class.php | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pandora_console/general/firts_task/recon_view.php b/pandora_console/general/firts_task/recon_view.php index 1d81c13e98..2377ce7c20 100755 --- a/pandora_console/general/firts_task/recon_view.php +++ b/pandora_console/general/firts_task/recon_view.php @@ -15,17 +15,17 @@ global $config; check_login(); ui_require_css_file('firts_task'); ?> - true, 'message' => __('There are no recon task defined yet.') ]); ?> + true, 'message' => __('There are no discovery tasks defined yet.') ]); ?>
      __('Discovery server')]); ?>
      -

      +

      ICMP (pings), SNMP (detecting the topology of networks and their interfaces), and other customized @@ -33,8 +33,8 @@ ui_require_css_file('firts_task'); ); ?>

      -
      - + +

      diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 5488b675b9..d0c5da17fb 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -168,7 +168,6 @@ class DiscoveryTaskList extends Wizard } else { $recon_task = db_get_all_rows_sql('SELECT * FROM trecon_task'); if ($recon_task === false) { - ui_print_page_header(__('Recon View'), 'images/op_recon.png', false, '', false); include_once $config['homedir'].'/general/firts_task/recon_view.php'; return false; } else { From c49c8bc0b5d84ab2b61c05ee629fe15764d27a76 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 15 Feb 2019 18:44:59 +0100 Subject: [PATCH 26/50] discovery minor style changes Former-commit-id: ea572c9d797214cbfc6f1b9ff2025f0c4819b4ed --- pandora_console/include/styles/discovery.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index df393fdf3e..930dbd047d 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -30,7 +30,6 @@ div.data_container { width: 100%; height: 100%; text-align: center; - border: 1px solid #ddd; padding-top: 30px; padding-bottom: 30px; } @@ -39,6 +38,9 @@ div.data_container:hover { box-shadow: 2px 2px 10px #ddd; } +/* + * TODO: This may be at hostdevices.css + */ #contenedor_principal { height: auto; position: relative; From a9caebbbf41f4dfcc6a38e7fc2a7e5093caf7f78 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 18 Feb 2019 10:24:19 +0100 Subject: [PATCH 27/50] Put the list into a function Former-commit-id: 11e4d0faa3512e46582530f48bab2cfa1031e89f --- pandora_console/godmode/servers/discovery.php | 18 ++------- .../godmode/wizards/Wizard.main.php | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 024eb39e30..97b9b8a884 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -76,24 +76,12 @@ if ($classname_selected !== null) { if ($classname_selected === null) { // Load classes and print selector. - echo '
        '; + $wiz_data = []; foreach ($classes as $classpath) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); - $wiz_data = $obj->load(); - ?> - -
      • - -
        - -
        -
        -
        -
      • - - load(); } - echo '
      '; + Wizard::printBigButtonsList($wiz_data); } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index ecc253ad04..709e601fa5 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -467,4 +467,44 @@ class Wizard } + /** + * Print a big button element (huge image, big text and link). + * + * @param array $data Element data (link, image...). + * + * @return void Only prints the element. + */ + public static function printBigButtonElement($data) + { + if (isset($data['url']) === false) { + $data['url'] = '#'; + } + + ?> +
    • + +
      + +
      +
      +
      +
    • + '; + array_map('self::printBigButtonElement', $list_data); + echo '
    '; + } } From 29206eb3bbd2b9bd10e0dc9570cf1dabde797923 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 18 Feb 2019 11:42:55 +0100 Subject: [PATCH 28/50] 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 29/50] 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 30/50] 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 31/50] 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 32/50] 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 33/50] 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 34/50] 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 35/50] 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 36/50] 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 37/50] 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 38/50] 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 39/50] 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 40/50] 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'})) { From 85371424eed81f5a37b4a8187bb34937fb97485e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Feb 2019 11:13:07 +0100 Subject: [PATCH 41/50] Minor fixes and status check Former-commit-id: 47a7e75579927c0ac109f303b77ebcc273334581 --- .../include/class/ConsoleSupervisor.php | 56 ++++++++++++++++++- pandora_console/include/functions_config.php | 5 ++ pandora_console/include/styles/pandora.css | 9 ++- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 60b5b6083c..88dbf0f11f 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -501,6 +501,7 @@ class ConsoleSupervisor case 'NOTIF.UPDATEMANAGER.OPENSETUP': case 'NOTIF.UPDATEMANAGER.UPDATE': case 'NOTIF.UPDATEMANAGER.MINOR': + case 'NOTIF.CRON.CONFIGURED': default: // NOTIF.SERVER.STATUS. // NOTIF.SERVER.STATUS.ID_SERVER. @@ -1379,7 +1380,10 @@ class ConsoleSupervisor [ 'type' => 'NOTIF.PANDORADB', 'title' => __('Database maintance problem'), - 'message' => __('Your database is not maintained correctly. It seems that more than 48hrs have passed without proper maintenance. Please review documents of %s on how to perform this maintenance process (DB Tool) and enable it as soon as possible.', get_product_name()), + 'message' => __( + 'Your database is not maintained correctly. It seems that more than 48hrs have passed without proper maintenance. Please review documents of %s on how to perform this maintenance process (DB Tool) and enable it as soon as possible.', + io_safe_output(get_product_name()) + ), 'url' => ui_get_full_url( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ), @@ -2081,4 +2085,54 @@ class ConsoleSupervisor } + /** + * Check if CRON utility has been configured. + * + * @return void + */ + public function checkCronRunning() + { + global $config; + + // Check if DiscoveryCronTasks is running. Warn user if not. + if ($config['cron_last_run'] == 0 + || (get_system_time() - $config['cron_last_run']) > 3600 + ) { + $message_conf_cron = __('DiscoveryConsoleTasks is not running properly'); + if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { + $message_conf_cron .= __('Discovery relies on a proper setup of cron, the time-based scheduling service'); + $message_conf_cron .= ' '.__('Please, add the following line to your crontab file:'); + $message_conf_cron .= '
    * * * * * <user> wget -q -O - --no-check-certificate ';
    +                $message_conf_cron .= str_replace(
    +                    ENTERPRISE_DIR.'/meta/',
    +                    '',
    +                    ui_get_full_url(false)
    +                );
    +                $message_conf_cron .= ENTERPRISE_DIR.'/'.EXTENSIONS_DIR;
    +                $message_conf_cron .= '/cron/cron.php >> ';
    +                $message_conf_cron .= $config['homedir'].'/pandora_console.log
    '; + } + + if (isset($config['cron_last_run']) === true) { + $message_conf_cron .= __('Last execution').': '; + $message_conf_cron .= date('Y/m/d H:i:s', $config['cron_last_run']); + } + + $this->notify( + [ + 'type' => 'NOTIF.CRON.CONFIGURED', + 'title' => __('DiscoveryConsoleTasks is not configured.'), + 'message' => __($message_conf_cron), + 'url' => ui_get_full_url( + 'index.php?extension_in_menu=gservers&sec=extensions&sec2=enterprise/extensions/cron' + ), + ] + ); + } else { + $this->cleanNotifications('NOTIF.CRON.CONFIGURED'); + } + + } + + } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index d55eda62e5..8875f7ade9 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -2676,6 +2676,11 @@ function config_check() if (license_free()) { $supervisor = new ConsoleSupervisor(false); $supervisor->run(); + } else if ($config['cron_last_run'] == 0 + || (get_system_time() - $config['cron_last_run']) > 3600 + ) { + $supervisor = new ConsoleSupervisor(false); + $supervisor->checkCronRunning(); } } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index f3fdca5874..03fb56489a 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -4305,6 +4305,7 @@ div#dialog_messages table th:last-child { position: absolute; width: 400px; margin-top: -5px; + border-radius: 5px; } #notification-wrapper::before { content: ""; @@ -4338,12 +4339,15 @@ div#dialog_messages table th:last-child { background: whitesmoke; height: 100px; margin: 7px; - border: #cccccc solid 1px; + border: #e4e4e4 solid 1px; display: flex; flex-flow: row nowrap; align-items: center; padding: 5px; } +.notification-item:hover { + border: #ccc solid 1px; +} .notification-item > * { padding-left: 15px; pointer-events: none; @@ -4357,6 +4361,9 @@ div#dialog_messages table th:last-child { width: 87%; display: flex; flex-flow: column nowrap; + overflow: hidden; + max-height: 83px; + line-height: 1.4em; } .notification-item img { max-width: 100%; From 8c09b945c776688d2f91b1429b13a582d8c0ed9b Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Feb 2019 11:14:48 +0100 Subject: [PATCH 42/50] minor fix changed customer check Former-commit-id: f2659c9e7780dcddaa9528b1aa13a4d61026c154 --- pandora_console/include/functions_config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 8875f7ade9..2a301affd9 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -2673,7 +2673,7 @@ function config_check() include_once __DIR__.'/class/ConsoleSupervisor.php'; // Enterprise customers launch supervisor using discovery task. - if (license_free()) { + if (enterprise_installed() === false) { $supervisor = new ConsoleSupervisor(false); $supervisor->run(); } else if ($config['cron_last_run'] == 0 From ea70c0846c82281607016e69d369e62dc8275bdc Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 19 Feb 2019 16:34:11 +0100 Subject: [PATCH 43/50] Added href in wizard Former-commit-id: 9b6b9e66d14257163f14bc904d5b13c6de9f9912 --- .../godmode/wizards/HostDevices.class.php | 18 +++++++++--------- pandora_console/include/styles/discovery.css | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 8dcf6d9a1e..f7a9b22e21 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(['']); + $this->setBreadcrum(['
        Host & devices
    ']); $this->printHeader(); $this->printBigButtonsList( [ @@ -117,8 +117,8 @@ class HostDevices extends Wizard if ($mode == 'importcsv') { $this->setBreadcrum( [ - '', - '', + '
        Host & devices
    ', + '
          Import CSV
    ', ] ); $this->printHeader(); @@ -128,20 +128,20 @@ class HostDevices extends Wizard } if ($mode == 'netscan') { - if ($this->page != 3) { + if ($this->page != 2) { // Do not paint breadcrum in last page. Redirected. $this->setBreadcrum( [ - '', - '', + '
        Host & devices
    ', + '
        Net scan definition
    ', ] ); if ($this->page == 1) { $this->setBreadcrum( [ - '', - '', - '', + '
        Host & devices
    ', + '
        Net scan definition
    ', + '
        Net scan features
    ', ] ); } diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index ad85fd606c..7c5933aba9 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -61,8 +61,7 @@ div.data_container:hover { display: inline-block; position: relative; background: #82b92e; - width: 15%; - padding: 1%; + padding: 14px; margin-left: 20px; margin-bottom: 10px; } From fa3f548cdd35b607e1605d7ee5c6107449258404 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 19 Feb 2019 20:27:05 +0100 Subject: [PATCH 44/50] Several changes for Wiz.App support Former-commit-id: 7c86d2e601771686a69d3f1b846638a427a25d6e --- .../wizards/DiscoveryTaskList.class.php | 27 ++++++++++- .../godmode/wizards/Wizard.main.php | 46 +++++++++++++++++++ .../include/class/ConsoleSupervisor.php | 3 +- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index d0c5da17fb..e135c80672 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -292,8 +292,13 @@ class DiscoveryTaskList extends Wizard $data[7] = ui_print_timestamp($task['utimestamp'], true); if (check_acl($config['id_user'], $task['id_group'], 'PM')) { + // Check if is a H&D, Cloud or Application. $data[8] = ''.html_print_image( 'images/wrench_orange.png', true @@ -348,4 +353,24 @@ class DiscoveryTaskList extends Wizard } + /** + * Return target url sub-string to edit target task. + * + * @param array $task With all data. + * + * @return string + */ + public function getTargetWiz($task) + { + // TODO: Do not use description. Use recon_script ID instead. + switch ($task['description']) { + case 'Discovery.Application.VMware': + return 'wiz=app&mode=vmware'; + + default: + return 'wiz=hd&mode=netscan'; + } + } + + } diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 2f58bea91e..31e494a737 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -80,6 +80,52 @@ class Wizard } + /** + * Setter for label + * + * @param string $str Label. + * + * @return void + */ + public function setLabel(string $str) + { + $this->label = $str; + } + + + /** + * Getter for label + * + * @return array Breadcrum. + */ + public function getLabel() + { + return $this->label; + } + + + /** + * Builder for breadcrum + * + * @param array $urls Array of urls to be stored in breadcrum. + * + * @return void + */ + public function prepareBreadcrum(array $urls) + { + $bc = []; + $i = 0; + foreach ($urls as $url) { + $bc[$i] = ''; + $bc[$i] .= '
    '.$url['label'].'
    '; + $bc[$i++] .= '
    '; + } + + $this->setBreadcrum($bc); + + } + + /** * To be overwritten. * diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 88dbf0f11f..fa40994962 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -2101,7 +2101,7 @@ class ConsoleSupervisor $message_conf_cron = __('DiscoveryConsoleTasks is not running properly'); if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { $message_conf_cron .= __('Discovery relies on a proper setup of cron, the time-based scheduling service'); - $message_conf_cron .= ' '.__('Please, add the following line to your crontab file:'); + $message_conf_cron .= '. '.__('Please, add the following line to your crontab file:'); $message_conf_cron .= '
    * * * * * <user> wget -q -O - --no-check-certificate ';
                     $message_conf_cron .= str_replace(
                         ENTERPRISE_DIR.'/meta/',
    @@ -2116,6 +2116,7 @@ class ConsoleSupervisor
                 if (isset($config['cron_last_run']) === true) {
                     $message_conf_cron .= __('Last execution').': ';
                     $message_conf_cron .= date('Y/m/d H:i:s', $config['cron_last_run']);
    +                $message_conf_cron .= __('Please check process is no locked.');
                 }
     
                 $this->notify(
    
    From 3d2ae475431b63b87bd42bec933af670a86ce1b0 Mon Sep 17 00:00:00 2001
    From: manuel 
    Date: Wed, 20 Feb 2019 08:41:15 +0100
    Subject: [PATCH 45/50] Added prepareBreadcrum function
    
    Former-commit-id: caf781a20bdd16bed7347bf755e2bf0da6ae7e99
    ---
     .../godmode/wizards/HostDevices.class.php     | 74 ++++++++++++++++---
     1 file changed, 63 insertions(+), 11 deletions(-)
    
    diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php
    index f7a9b22e21..83f5d21b4c 100755
    --- a/pandora_console/godmode/wizards/HostDevices.class.php
    +++ b/pandora_console/godmode/wizards/HostDevices.class.php
    @@ -92,7 +92,15 @@ class HostDevices extends Wizard
             $mode = get_parameter('mode', null);
     
             if ($mode === null) {
    -            $this->setBreadcrum(['
        Host & devices
    ']); + $this->prepareBreadcrum( + [ + [ + 'link' => $this->url.'&wiz=hd', + 'label' => __('    Host & devices'), + ], + ] + ); + $this->printHeader(); $this->printBigButtonsList( [ @@ -115,10 +123,16 @@ class HostDevices extends Wizard if (enterprise_installed()) { if ($mode == 'importcsv') { - $this->setBreadcrum( + $this->prepareBreadcrum( [ - '
        Host & devices
    ', - '
          Import CSV
    ', + [ + 'link' => $this->url.'&wiz=hd', + 'label' => __('    Host & devices'), + ], + [ + 'link' => $this->url.'&wiz=hd&mode=importcsv', + 'label' => __('      Import CSV'), + ], ] ); $this->printHeader(); @@ -130,18 +144,34 @@ class HostDevices extends Wizard if ($mode == 'netscan') { if ($this->page != 2) { // Do not paint breadcrum in last page. Redirected. - $this->setBreadcrum( + $this->prepareBreadcrum( [ - '
        Host & devices
    ', - '
        Net scan definition
    ', + [ + 'link' => $this->url.'&wiz=hd', + 'label' => __('    Host & devices'), + ], + [ + 'link' => $this->url.'&wiz=hd&mode=netscan', + 'label' => __('      Net scan definition'), + ], ] ); + if ($this->page == 1) { - $this->setBreadcrum( + $this->prepareBreadcrum( [ - '
        Host & devices
    ', - '
        Net scan definition
    ', - '
        Net scan features
    ', + [ + 'link' => $this->url.'&wiz=hd', + 'label' => __('    Host & devices'), + ], + [ + 'link' => $this->url.'&wiz=hd&mode=netscan', + 'label' => __('      Net scan definition'), + ], + [ + 'link' => $this->url.'&wiz=hd&mode=netscan&page=1', + 'label' => __('      Net scan features'), + ], ] ); } @@ -1096,4 +1126,26 @@ $(function() { } + /** + * Builder for breadcrum + * + * @param array $urls Array of urls to be stored in breadcrum. + * + * @return void + */ + public function prepareBreadcrum(array $urls) + { + $bc = []; + $i = 0; + foreach ($urls as $url) { + $bc[$i] = ''; + $bc[$i] .= '
    '.$url['label'].'
    '; + $bc[$i++] .= '
    '; + } + + $this->setBreadcrum($bc); + + } + + } From e9d97e8010d1eb73a43d487e6503e78a725ce70d Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Feb 2019 10:53:54 +0100 Subject: [PATCH 46/50] Wiz. Added option url to printGoBackButton Former-commit-id: 31c9c56da3475f9b1510904ad7237f993c0a6ccf --- pandora_console/godmode/wizards/Wizard.main.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 31e494a737..ebee7c9c03 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -402,13 +402,17 @@ class Wizard * * @return void */ - public function printGoBackButton() + public function printGoBackButton($url) { + if (isset($url) === false) { + $url = 'index.php?sec=gservers&sec2=godmode/servers/discovery'; + } + $form = [ 'form' => [ 'method' => 'POST', 'action' => ui_get_full_url( - 'index.php?sec=gservers&sec2=godmode/servers/discovery' + $url ), ], 'inputs' => [ From 65db8482c1645191f16b1d730b7b4ed75ef2dd80 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Feb 2019 10:58:56 +0100 Subject: [PATCH 47/50] Wiz. Added option url to printGoBackButton Former-commit-id: fd0c76ce5efef9902cbda2817b13e59e6672c972 --- pandora_console/godmode/wizards/Wizard.main.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index ebee7c9c03..d2ee440a67 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -405,15 +405,15 @@ class Wizard public function printGoBackButton($url) { if (isset($url) === false) { - $url = 'index.php?sec=gservers&sec2=godmode/servers/discovery'; + $url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ); } $form = [ 'form' => [ 'method' => 'POST', - 'action' => ui_get_full_url( - $url - ), + 'action' => $url, ], 'inputs' => [ [ From a63e497497e60fc5ed91872832a88de1a043bb1c Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Feb 2019 11:11:26 +0100 Subject: [PATCH 48/50] Wiz. Added textarea input Former-commit-id: 319ab37377e6649c1cd6c6adea1e956e934f2e23 --- pandora_console/godmode/wizards/Wizard.main.php | 11 +++++++++++ pandora_console/include/styles/wizard.css | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index d2ee440a67..21731a4bf8 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -388,6 +388,17 @@ class Wizard case 'switch': return html_print_switch($data); + case 'textarea': + return html_print_textarea( + $data['name'], + $data['rows'], + $data['columns'], + ((isset($data['value']) === true) ? $data['value'] : ''), + ((isset($data['attributes']) === true) ? $data['attributes'] : ''), + ((isset($data['return']) === true) ? $data['return'] : false), + ((isset($data['class']) === true) ? $data['class'] : '') + ); + default: // Ignore. break; diff --git a/pandora_console/include/styles/wizard.css b/pandora_console/include/styles/wizard.css index 912f5d5a4f..869ea85f2c 100644 --- a/pandora_console/include/styles/wizard.css +++ b/pandora_console/include/styles/wizard.css @@ -10,6 +10,12 @@ ul.wizard li { } ul.wizard li > label:not(.p-switch) { + width: 250px; + vertical-align: top; + display: inline-block; +} + +ul.wizard li > textarea { width: 250px; display: inline-block; } From f19bdf956e800c31ceaf12790ae0e1e4da502d02 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Feb 2019 12:32:12 +0100 Subject: [PATCH 49/50] Wiz. minor fix default value url in goback button Former-commit-id: 434b2acb09290f11c8804024adb8834b86eeda73 --- pandora_console/godmode/wizards/Wizard.main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 21731a4bf8..65a526cc58 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -413,7 +413,7 @@ class Wizard * * @return void */ - public function printGoBackButton($url) + public function printGoBackButton($url=null) { if (isset($url) === false) { $url = ui_get_full_url( From 4834561e873d6117197ef697eaa7c683f30a2359 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Feb 2019 14:38:00 +0100 Subject: [PATCH 50/50] Wiz. minor fixes Former-commit-id: b3963bf5994a8f9829922e0a1b0be3a20fc54fba --- .../godmode/wizards/HostDevices.class.php | 12 ++++- .../godmode/wizards/Wizard.main.php | 44 ++++++++++++++++++- pandora_console/include/styles/discovery.css | 10 ++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 83f5d21b4c..b5f635eb40 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -690,6 +690,14 @@ class HostDevices extends Wizard 'action' => $this->url.'&mode=netscan&page='.($this->page + 1).$task_url, ]; + // Default. + $interval = 600; + $unit = 60; + if (isset($this->task['interval_sweep']) === true) { + $interval = $this->task['interval_sweep']; + $unit = $this->getTimeUnit($interval); + } + $form['js'] = ' $("select#interval_manual_defined").change(function() { if ($("#interval_manual_defined").val() == 1) { @@ -700,8 +708,8 @@ $("select#interval_manual_defined").change(function() { else { $("#interval_manual_container").show(); $("#text-interval_text").val(10); - $("#hidden-interval").val(600); - $("#interval_units").val(60); + $("#hidden-interval").val('.$interval.'); + $("#interval_units").val('.$unit.'); } }).change();'; diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 65a526cc58..638228c365 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -104,6 +104,40 @@ class Wizard } + /** + * Return units associated to target interval (in seconds). + * + * @param integer $interval Target interval. + * + * @return integer Unit. + */ + public function getTimeUnit($interval) + { + $units = [ + 1, + 60, + 3600, + 86400, + 604800, + 2592000, + 31104000, + ]; + + $size = count($units); + for ($i = 0; $i < $size; $i++) { + if ($interval < $units[$i]) { + if (($i - 1) < 0) { + return 1; + } + + return $units[($i - 1)]; + } + } + + return $units[-1]; + } + + /** * Builder for breadcrum * @@ -116,9 +150,15 @@ class Wizard $bc = []; $i = 0; foreach ($urls as $url) { + if ($url['selected'] == 1) { + $class = 'selected'; + } else { + $class = ''; + } + $bc[$i] = ''; - $bc[$i] .= '
    '.$url['label'].'
    '; - $bc[$i++] .= '
    '; + $bc[$i] .= '
    '.$url['label']; + $bc[$i++] .= '
    '; } $this->setBreadcrum($bc); diff --git a/pandora_console/include/styles/discovery.css b/pandora_console/include/styles/discovery.css index 7c5933aba9..aebb0a3d0d 100644 --- a/pandora_console/include/styles/discovery.css +++ b/pandora_console/include/styles/discovery.css @@ -60,7 +60,7 @@ div.data_container:hover { .arrow_box { display: inline-block; position: relative; - background: #82b92e; + background: #ccc; padding: 14px; margin-left: 20px; margin-bottom: 10px; @@ -75,6 +75,9 @@ div.data_container:hover { position: absolute; pointer-events: none; } +.arrow_box.selected { + background: #82b92e; +} .arrow_box:after { left: 0%; @@ -84,7 +87,10 @@ div.data_container:hover { } .arrow_box:before { left: 100%; - border-left-color: #82b92e; + border-left-color: #ccc; border-width: 20px; margin-top: -20px; } +.arrow_box.selected:before { + border-left-color: #82b92e; +}