From 4394a8cf6ae5cc356fdcd75e2504e3cee8cb4222 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 22 Sep 2020 16:55:46 +0200 Subject: [PATCH 1/9] wip discovery.cloud.gcp --- pandora_console/include/class/CredentialStore.class.php | 2 +- pandora_console/include/constants.php | 4 +++- pandora_server/lib/PandoraFMS/Recon/Base.pm | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index adf9d6ed06..616c56d0cb 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -875,7 +875,7 @@ class CredentialStore extends Wizard 'AWS' => __('Aws'), 'AZURE' => __('Azure'), 'SAP' => __('SAP'), - // 'GOOGLE' => __('Google'), + 'GOOGLE' => __('Google'), ], 'selected' => (isset($values['product']) ? $values['product'] : 'CUSTOM'), 'disabled' => (bool) $values['product'], diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index d32dacb1fe..7d955973c0 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -618,7 +618,8 @@ define('DISCOVERY_CLOUD_AZURE_COMPUTE', 8); define('DISCOVERY_DEPLOY_AGENTS', 9); define('DISCOVERY_APP_SAP', 10); define('DISCOVERY_APP_DB2', 11); - +define('DISCOVERY_APP_MICROSOFT_SQL_SERVER', 12); +define('DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE', 13); // Force task build tmp results. define('DISCOVERY_REVIEW', 0); @@ -637,6 +638,7 @@ define('DISCOVERY_SCRIPT_IPMI_RECON', 4); // Discovery task descriptions. define('CLOUDWIZARD_AZURE_DESCRIPTION', 'Discovery.Cloud.Azure.Compute'); define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2'); +define('CLOUDWIZARD_GOOGLE_DESCRIPTION', 'Discovery.Cloud.GCP'); define('CLOUDWIZARD_VMWARE_DESCRIPTION', 'Discovery.App.VMware'); // Background options. diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index 1f6e13f2e6..aaf60eb581 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -38,9 +38,11 @@ use constant { DISCOVERY_CLOUD_AWS_EC2 => 6, DISCOVERY_CLOUD_AWS_RDS => 7, DISCOVERY_CLOUD_AZURE_COMPUTE => 8, + DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE => 13, DISCOVERY_DEPLOY_AGENTS => 9, DISCOVERY_APP_SAP => 10, DISCOVERY_APP_DB2 => 11, + DISCOVERY_APP_MICROSOFT_SQL_SERVER => 12, DISCOVERY_REVIEW => 0, DISCOVERY_STANDARD => 1, DISCOVERY_RESULTS => 2, From 9ce54213b65c4c7d3c89b05f4a416b70c7af3745 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 23 Sep 2020 14:07:23 +0200 Subject: [PATCH 2/9] WIP GCP --- .../include/class/CredentialStore.class.php | 134 ++++++++++++++---- pandora_console/include/functions_html.php | 13 +- .../include/javascript/pandora_ui.js | 26 ++-- .../include/styles/credential_store.css | 11 +- 4 files changed, 136 insertions(+), 48 deletions(-) diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index 616c56d0cb..c609947e4a 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -248,7 +248,12 @@ class CredentialStore extends Wizard ); } else { $groups = [ $filter['filter_id_group'] ]; - $childrens = groups_get_childrens($id_group, null, true); + $childrens = groups_get_childrens( + $filter['filter_id_group'], + null, + true + ); + if (!empty($childrens)) { foreach ($childrens as $child) { $groups[] = (int) $child['id_grupo']; @@ -385,6 +390,8 @@ class CredentialStore extends Wizard // Decrypt content. $key['username'] = io_output_password($key['username']); $key['password'] = io_output_password($key['password']); + $key['extra_1'] = io_output_password($key['extra_1']); + $key['extra_2'] = io_output_password($key['extra_2']); return $key; } @@ -425,6 +432,8 @@ class CredentialStore extends Wizard function ($carry, $item) { $item['username'] = io_output_password($item['username']); $item['password'] = io_output_password($item['password']); + $item['extra_1'] = io_output_password($item['extra_1']); + $item['extra_2'] = io_output_password($item['extra_2']); $carry[$item['identifier']] = $item['identifier']; return $carry; } @@ -561,13 +570,28 @@ class CredentialStore extends Wizard $extra_1 = get_parameter('extra_1', null); $extra_2 = get_parameter('extra_2', null); - if (empty($identifier)) { + if ($product === 'GOOGLE') { + $google_creds = json_decode(io_safe_output($extra_1)); + + if (json_last_error() !== JSON_ERROR_NONE) { + $this->ajaxMsg( + 'error', + __('Not a valid JSON: %s', json_last_error_msg()) + ); + exit; + } + + $username = $google_creds->client_email; + $password = $google_creds->private_key_id; + } + + if (empty($identifier) === true) { $error = __('Key identifier is required'); } else if ($id_group === null) { $error = __('You must select a group where store this key!'); - } else if (empty($product)) { + } else if (empty($product) === true) { $error = __('You must specify a product type'); - } else if (empty($username) && (empty($password))) { + } else if (empty($username) === true && (empty($password) === true)) { $error = __('You must specify a username and/or password'); } @@ -583,8 +607,8 @@ class CredentialStore extends Wizard 'product' => $product, 'username' => io_input_password($username), 'password' => io_input_password($password), - 'extra_1' => $extra_1, - 'extra_2' => $extra_2, + 'extra_1' => io_input_password($extra_1), + 'extra_2' => io_input_password($extra_2), ]; // Spaces are not allowed. @@ -887,6 +911,9 @@ class CredentialStore extends Wizard $pass_label = __('Password'); $extra_1_label = __('Extra'); $extra_2_label = __('Extra (2)'); + $extra1_type = 'text'; + $user = true; + $pass = true; $extra1 = true; $extra2 = true; @@ -907,7 +934,14 @@ class CredentialStore extends Wizard break; case 'GOOGLE': - // Need further investigation. + $extra_1_label = __('Auth JSON'); + $user = false; + $pass = false; + $extra1 = true; + $extra2 = false; + $extra1_type = 'textarea'; + break; + case 'CUSTOM': case 'SAP': $user_label = __('Account ID'); @@ -919,29 +953,33 @@ class CredentialStore extends Wizard break; } - $inputs[] = [ - 'label' => $user_label, - 'id' => 'div-username', - 'arguments' => [ - 'name' => 'username', - 'input_class' => 'flex-row', - 'type' => 'text', - 'value' => $values['username'], - 'return' => true, - ], - ]; + if ($user) { + $inputs[] = [ + 'label' => $user_label, + 'id' => 'div-username', + 'arguments' => [ + 'name' => 'username', + 'input_class' => 'flex-row', + 'type' => 'text', + 'value' => $values['username'], + 'return' => true, + ], + ]; + } - $inputs[] = [ - 'label' => $pass_label, - 'id' => 'div-password', - 'arguments' => [ - 'name' => 'password', - 'input_class' => 'flex-row', - 'type' => 'password', - 'value' => $values['password'], - 'return' => true, - ], - ]; + if ($pass) { + $inputs[] = [ + 'label' => $pass_label, + 'id' => 'div-password', + 'arguments' => [ + 'name' => 'password', + 'input_class' => 'flex-row', + 'type' => 'password', + 'value' => $values['password'], + 'return' => true, + ], + ]; + } if ($extra1) { $inputs[] = [ @@ -949,8 +987,9 @@ class CredentialStore extends Wizard 'id' => 'div-extra_1', 'arguments' => [ 'name' => 'extra_1', + 'id' => 'text-extra_1', 'input_class' => 'flex-row', - 'type' => 'text', + 'type' => $extra1_type, 'value' => $values['extra_1'], 'return' => true, ], @@ -1031,14 +1070,30 @@ class CredentialStore extends Wizard * Handles inputs visibility based on selected product. */ function calculate_inputs() { + if ($('#product :selected').val() != "GOOGLE") { + // Restore text-extra_1. + var val = $('#text-extra_1').val(); + if(typeof val == 'undefined') { + val = ''; + } + $('#text-extra_1').remove(); + $('#div-extra_1').append( + $('') + ); + } + if ($('#product :selected').val() == "CUSTOM") { $('#div-username label').text(''); $('#div-password label').text(''); + $('#div-username').show(); + $('#div-password').show(); $('#div-extra_1').hide(); $('#div-extra_2').hide(); } else if ($('#product :selected').val() == "AWS") { $('#div-username label').text(''); $('#div-password label').text(''); + $('#div-username').show(); + $('#div-password').show(); $('#div-extra_1').hide(); $('#div-extra_2').hide(); } else if ($('#product :selected').val() == "AZURE") { @@ -1046,13 +1101,32 @@ class CredentialStore extends Wizard $('#div-password label').text(''); $('#div-extra_1 label').text(''); $('#div-extra_2 label').text(''); + $('#div-username').show(); + $('#div-password').show(); $('#div-extra_1').show(); $('#div-extra_2').show(); } else if ($('#product :selected').val() == "SAP") { $('#div-username label').text(''); $('#div-password label').text(''); + $('#div-username').show(); + $('#div-password').show(); $('#div-extra_1').hide(); $('#div-extra_2').hide(); + } else if ($('#product :selected').val() == "GOOGLE") { + $('#div-username').hide(); + $('#div-password').hide(); + $('#div-extra_2').hide(); + $('#div-extra_1 label').text(''); + var val = $('#text-extra_1').val(); + if(typeof val == 'undefined') { + val = ''; + } + + $('#text-extra_1').remove(); + $('#div-extra_1').append( + $('') + ); + $('#div-extra_1').show(); } } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 6b66357652..44d88bdcc4 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2681,13 +2681,17 @@ function html_print_textarea( $attributes='', $return=false, $class='', - $disable=false + $disable=false, + $id=false ) { $disabled = ($disable) ? 'disabled' : ''; - $output = ''; - if ($return) { return $output; } @@ -4361,7 +4365,8 @@ function html_print_input($data, $wrapper='div', $input_only=false) ((isset($data['attributes']) === true) ? $data['attributes'] : ''), ((isset($data['return']) === true) ? $data['return'] : false), ((isset($data['class']) === true) ? $data['class'] : ''), - ((isset($data['disabled']) === true) ? $data['disabled'] : false) + ((isset($data['disabled']) === true) ? $data['disabled'] : false), + ((isset($data['id']) === true) ? $data['id'] : false) ); break; diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index 2445473591..efebf39e9f 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -249,22 +249,24 @@ function load_modal(settings) { }); } else { settings.form.forEach(function(element) { - $("#" + element + " :input").each(function() { - // TODO VALIDATE ALL INPUTS. - if (this.type == "file") { - if ($(this).prop("files")[0]) { - formdata.append(this.name, $(this).prop("files")[0]); - } - } else { - if ($(this).attr("type") == "checkbox") { - if (this.checked) { - formdata.append(this.name, "on"); + $("#" + element + " :input, #" + element + " textarea").each( + function() { + // TODO VALIDATE ALL INPUTS. + if (this.type == "file") { + if ($(this).prop("files")[0]) { + formdata.append(this.name, $(this).prop("files")[0]); } } else { - formdata.append(this.name, $(this).val()); + if ($(this).attr("type") == "checkbox") { + if (this.checked) { + formdata.append(this.name, "on"); + } + } else { + formdata.append(this.name, $(this).val()); + } } } - }); + ); }); } diff --git a/pandora_console/include/styles/credential_store.css b/pandora_console/include/styles/credential_store.css index 5707d90780..3f5ff8d23c 100644 --- a/pandora_console/include/styles/credential_store.css +++ b/pandora_console/include/styles/credential_store.css @@ -24,7 +24,7 @@ ul.wizard li { margin-right: 1em; } -form.modal ul.wizard li { +form#modal_form ul.wizard li { display: flex; flex-direction: row; width: 90%; @@ -32,7 +32,7 @@ form.modal ul.wizard li { justify-items: center; } -form.modal ul.wizard li * { +form#modal_form ul.wizard li * { flex: 1; } @@ -40,3 +40,10 @@ ul.wizard li.flex-indep { flex: 1; margin: 0; } + +form#modal_form ul.wizard li textarea { + font-size: 0.8em; + font-family: "Courier New", Courier, monospace; + flex: 1 1 400px; + max-width: 400px; +} From d292b06e9f6040d1c6b3fe81bb8cc30f594dec2f Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 24 Sep 2020 18:35:50 +0200 Subject: [PATCH 3/9] WIP GCP CE --- pandora_server/lib/PandoraFMS/Core.pm | 8 ++++++++ pandora_server/lib/PandoraFMS/Tools.pm | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3eff8e2384..1b9ac457ee 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -3319,6 +3319,14 @@ sub pandora_get_credential ($$$) { $pa_config, safe_output($key->{'password'}) ); + $key->{'extra_1'} = pandora_output_password( + $pa_config, + safe_output($key->{'extra_1'}) + ); + $key->{'extra_2'} = pandora_output_password( + $pa_config, + safe_output($key->{'extra_2'}) + ); return $key; } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 300e66e5a6..f28985b744 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -88,6 +88,10 @@ our @EXPORT = qw( DISCOVERY_CLOUD_AWS_RDS DISCOVERY_CLOUD_AZURE_COMPUTE DISCOVERY_DEPLOY_AGENTS + DISCOVERY_APP_SAP + DISCOVERY_APP_DB2 + DISCOVERY_APP_MICROSOFT_SQL_SERVER + DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE $DEVNULL $OS $OS_VERSION @@ -211,6 +215,10 @@ use constant DISCOVERY_CLOUD_AWS_EC2 => 6; use constant DISCOVERY_CLOUD_AWS_RDS => 7; use constant DISCOVERY_CLOUD_AZURE_COMPUTE => 8; use constant DISCOVERY_DEPLOY_AGENTS => 9; +use constant DISCOVERY_APP_SAP => 10; +use constant DISCOVERY_APP_DB2 => 11; +use constant DISCOVERY_APP_MICROSOFT_SQL_SERVER => 12; +use constant DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE => 13; # Set OS, OS version and /dev/null our $OS = $^O; From b2d819aa29e5ca013374656f17553911953b6572 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 25 Sep 2020 19:35:19 +0200 Subject: [PATCH 4/9] Minor fixes --- pandora_console/include/class/CredentialStore.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index c609947e4a..b8a29c16cc 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -605,10 +605,10 @@ class CredentialStore extends Wizard 'identifier' => $identifier, 'id_group' => $id_group, 'product' => $product, - 'username' => io_input_password($username), - 'password' => io_input_password($password), - 'extra_1' => io_input_password($extra_1), - 'extra_2' => io_input_password($extra_2), + 'username' => io_input_password(io_safe_output($username)), + 'password' => io_input_password(io_safe_output($password)), + 'extra_1' => io_input_password(io_safe_output($extra_1)), + 'extra_2' => io_input_password(io_safe_output($extra_2)), ]; // Spaces are not allowed. From 029a447e701cb74f6a19e6565941e8e645c83190 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 28 Sep 2020 13:55:26 +0200 Subject: [PATCH 5/9] gcp minor fixes --- pandora_console/godmode/wizards/DiscoveryTaskList.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 59a9fab84a..f1acf0c62a 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -1200,7 +1200,10 @@ class DiscoveryTaskList extends HTML $output = ''; // Header information. - if ((int) $task['status'] <= 0 && empty($summary)) { + if ((int) $task['status'] <= 0 + && empty($summary) + && $task['id_recon_script'] == 0 + ) { $output .= ui_print_info_message( __('This task has never executed'), '', From 34374159debe3bfd9a78548ebc33a6c90186c018 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 3 Dec 2020 18:00:20 +0100 Subject: [PATCH 6/9] gcp reviewed --- pandora_console/include/functions_html.php | 2 +- pandora_console/include/styles/pandora.css | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 2c1c08ab71..d3996bc7f8 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1772,7 +1772,7 @@ function html_print_extended_select_for_time( ob_start(); // Use the no_meta parameter because this image is only in the base console. - echo '
'; + echo '
'; html_print_select( $fields, $uniq_name.'_select', diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index bc743e9c77..9fe2db39c3 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -619,6 +619,13 @@ select:-internal-list-box { align-items: flex-end; } +.flex-row-start { + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: flex-start; +} + .flex-space-around { justify-content: space-around; } From d45a72f3558377dcf34ca4358c020c8041ab2274 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 4 Dec 2020 13:32:42 +0100 Subject: [PATCH 7/9] minor fix PM -> UM for cred access (managemnt) --- pandora_console/godmode/wizards/HostDevices.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/wizards/HostDevices.class.php b/pandora_console/godmode/wizards/HostDevices.class.php index 7abfe15d5d..35232650d5 100755 --- a/pandora_console/godmode/wizards/HostDevices.class.php +++ b/pandora_console/godmode/wizards/HostDevices.class.php @@ -1427,7 +1427,7 @@ class HostDevices extends Wizard include_once $config['homedir'].'/include/class/CredentialStore.class.php'; $available_keys = CredentialStore::getKeys('CUSTOM'); - if (check_acl($config['id_user'], 0, 'PM')) { + if (check_acl($config['id_user'], 0, 'UM')) { $link_to_cs = ''; From 839890025bb1d066c92d4c62cb79ac526db55506 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 4 Dec 2020 15:28:22 +0100 Subject: [PATCH 8/9] Added class per depth level snmp tree --- pandora_console/include/functions_snmp_browser.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 3f66c790ae..95956b422a 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -86,6 +86,7 @@ function snmp_browser_get_html_tree( $count = 0; $total = (count(array_keys($tree['__LEAVES__'])) - 1); $last_array[$depth] = $last; + $class = 'item_'.$depth; if ($depth > 0) { $output .= '