Merge branch 'ent-4231-crear-plugin-para-google-cloud-y-anadirlo-a-discovery' into 'develop'

discovery.cloud.gcp

See merge request artica/pandorafms!3479
This commit is contained in:
Daniel Rodriguez 2020-12-09 13:54:25 +01:00
commit 4b51e26086
12 changed files with 180 additions and 55 deletions

View File

@ -1202,7 +1202,10 @@ class DiscoveryTaskList extends HTML
$output = ''; $output = '';
// Header information. // 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( $output .= ui_print_info_message(
__('This task has never executed'), __('This task has never executed'),
'', '',
@ -1250,6 +1253,17 @@ class DiscoveryTaskList extends HTML
], ],
] ]
); );
if (count($map->nodes) <= 1) {
// No nodes detected in current task definition.
$task = db_get_row('trecon_task', 'id_rt', $id_task);
if ((int) $task['type'] === DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE) {
ui_print_info_message(
__('Please ensure instances or regions are being monitorized and \'scan and general monitoring\' is enabled.')
);
}
}
$map->printMap(); $map->printMap();
} }

View File

@ -1427,7 +1427,7 @@ class HostDevices extends Wizard
include_once $config['homedir'].'/include/class/CredentialStore.class.php'; include_once $config['homedir'].'/include/class/CredentialStore.class.php';
$available_keys = CredentialStore::getKeys('CUSTOM'); $available_keys = CredentialStore::getKeys('CUSTOM');
if (check_acl($config['id_user'], 0, 'PM')) { if (check_acl($config['id_user'], 0, 'UM')) {
$link_to_cs = '<a class="ext_link" href="'.ui_get_full_url( $link_to_cs = '<a class="ext_link" href="'.ui_get_full_url(
'index.php?sec=gmodules&sec2=godmode/groups/group_list&tab=credbox' 'index.php?sec=gmodules&sec2=godmode/groups/group_list&tab=credbox'
).'" >'; ).'" >';

View File

@ -385,6 +385,8 @@ class CredentialStore extends Wizard
// Decrypt content. // Decrypt content.
$key['username'] = io_output_password($key['username']); $key['username'] = io_output_password($key['username']);
$key['password'] = io_output_password($key['password']); $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; return $key;
} }
@ -425,6 +427,8 @@ class CredentialStore extends Wizard
function ($carry, $item) { function ($carry, $item) {
$item['username'] = io_output_password($item['username']); $item['username'] = io_output_password($item['username']);
$item['password'] = io_output_password($item['password']); $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']; $carry[$item['identifier']] = $item['identifier'];
return $carry; return $carry;
} }
@ -573,13 +577,28 @@ class CredentialStore extends Wizard
$extra_1 = get_parameter('extra_1', null); $extra_1 = get_parameter('extra_1', null);
$extra_2 = get_parameter('extra_2', 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'); $error = __('Key identifier is required');
} else if ($id_group === null) { } else if ($id_group === null) {
$error = __('You must select a group where store this key!'); $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'); $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'); $error = __('You must specify a username and/or password');
} }
@ -593,10 +612,10 @@ class CredentialStore extends Wizard
'identifier' => $identifier, 'identifier' => $identifier,
'id_group' => $id_group, 'id_group' => $id_group,
'product' => $product, 'product' => $product,
'username' => io_input_password($username), 'username' => io_input_password(io_safe_output($username)),
'password' => io_input_password($password), 'password' => io_input_password(io_safe_output($password)),
'extra_1' => $extra_1, 'extra_1' => io_input_password(io_safe_output($extra_1)),
'extra_2' => $extra_2, 'extra_2' => io_input_password(io_safe_output($extra_2)),
]; ];
// Spaces are not allowed. // Spaces are not allowed.
@ -887,7 +906,7 @@ class CredentialStore extends Wizard
'AWS' => __('Aws'), 'AWS' => __('Aws'),
'AZURE' => __('Azure'), 'AZURE' => __('Azure'),
'SAP' => __('SAP'), 'SAP' => __('SAP'),
// 'GOOGLE' => __('Google'), 'GOOGLE' => __('Google'),
], ],
'selected' => (isset($values['product']) ? $values['product'] : 'CUSTOM'), 'selected' => (isset($values['product']) ? $values['product'] : 'CUSTOM'),
'disabled' => (bool) $values['product'], 'disabled' => (bool) $values['product'],
@ -899,6 +918,9 @@ class CredentialStore extends Wizard
$pass_label = __('Password'); $pass_label = __('Password');
$extra_1_label = __('Extra'); $extra_1_label = __('Extra');
$extra_2_label = __('Extra (2)'); $extra_2_label = __('Extra (2)');
$extra1_type = 'text';
$user = true;
$pass = true;
$extra1 = true; $extra1 = true;
$extra2 = true; $extra2 = true;
@ -919,7 +941,14 @@ class CredentialStore extends Wizard
break; break;
case 'GOOGLE': 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 'CUSTOM':
case 'SAP': case 'SAP':
$user_label = __('Account ID'); $user_label = __('Account ID');
@ -931,6 +960,7 @@ class CredentialStore extends Wizard
break; break;
} }
if ($user) {
$inputs[] = [ $inputs[] = [
'label' => $user_label, 'label' => $user_label,
'id' => 'div-username', 'id' => 'div-username',
@ -942,7 +972,9 @@ class CredentialStore extends Wizard
'return' => true, 'return' => true,
], ],
]; ];
}
if ($pass) {
$inputs[] = [ $inputs[] = [
'label' => $pass_label, 'label' => $pass_label,
'id' => 'div-password', 'id' => 'div-password',
@ -954,6 +986,7 @@ class CredentialStore extends Wizard
'return' => true, 'return' => true,
], ],
]; ];
}
if ($extra1) { if ($extra1) {
$inputs[] = [ $inputs[] = [
@ -961,8 +994,9 @@ class CredentialStore extends Wizard
'id' => 'div-extra_1', 'id' => 'div-extra_1',
'arguments' => [ 'arguments' => [
'name' => 'extra_1', 'name' => 'extra_1',
'id' => 'text-extra_1',
'input_class' => 'flex-row', 'input_class' => 'flex-row',
'type' => 'text', 'type' => $extra1_type,
'value' => $values['extra_1'], 'value' => $values['extra_1'],
'return' => true, 'return' => true,
], ],
@ -1043,14 +1077,30 @@ class CredentialStore extends Wizard
* Handles inputs visibility based on selected product. * Handles inputs visibility based on selected product.
*/ */
function calculate_inputs() { 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(
$('<input type="text" name="extra_1" id="text-extra_1" size="50" value="'+val+'"></input>')
);
}
if ($('#product :selected').val() == "CUSTOM") { if ($('#product :selected').val() == "CUSTOM") {
$('#div-username label').text('<?php echo __('User'); ?>'); $('#div-username label').text('<?php echo __('User'); ?>');
$('#div-password label').text('<?php echo __('Password'); ?>'); $('#div-password label').text('<?php echo __('Password'); ?>');
$('#div-username').show();
$('#div-password').show();
$('#div-extra_1').hide(); $('#div-extra_1').hide();
$('#div-extra_2').hide(); $('#div-extra_2').hide();
} else if ($('#product :selected').val() == "AWS") { } else if ($('#product :selected').val() == "AWS") {
$('#div-username label').text('<?php echo __('Access key ID'); ?>'); $('#div-username label').text('<?php echo __('Access key ID'); ?>');
$('#div-password label').text('<?php echo __('Secret access key'); ?>'); $('#div-password label').text('<?php echo __('Secret access key'); ?>');
$('#div-username').show();
$('#div-password').show();
$('#div-extra_1').hide(); $('#div-extra_1').hide();
$('#div-extra_2').hide(); $('#div-extra_2').hide();
} else if ($('#product :selected').val() == "AZURE") { } else if ($('#product :selected').val() == "AZURE") {
@ -1058,13 +1108,32 @@ class CredentialStore extends Wizard
$('#div-password label').text('<?php echo __('Application secret'); ?>'); $('#div-password label').text('<?php echo __('Application secret'); ?>');
$('#div-extra_1 label').text('<?php echo __('Tenant or domain name'); ?>'); $('#div-extra_1 label').text('<?php echo __('Tenant or domain name'); ?>');
$('#div-extra_2 label').text('<?php echo __('Subscription id'); ?>'); $('#div-extra_2 label').text('<?php echo __('Subscription id'); ?>');
$('#div-username').show();
$('#div-password').show();
$('#div-extra_1').show(); $('#div-extra_1').show();
$('#div-extra_2').show(); $('#div-extra_2').show();
} else if ($('#product :selected').val() == "SAP") { } else if ($('#product :selected').val() == "SAP") {
$('#div-username label').text('<?php echo __('Account ID.'); ?>'); $('#div-username label').text('<?php echo __('Account ID.'); ?>');
$('#div-password label').text('<?php echo __('Password'); ?>'); $('#div-password label').text('<?php echo __('Password'); ?>');
$('#div-username').show();
$('#div-password').show();
$('#div-extra_1').hide(); $('#div-extra_1').hide();
$('#div-extra_2').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('<?php echo __('Auth JSON'); ?>');
var val = $('#text-extra_1').val();
if(typeof val == 'undefined') {
val = '';
}
$('#text-extra_1').remove();
$('#div-extra_1').append(
$('<textarea name="extra_1" id="text-extra_1">'+val+'</textarea>')
);
$('#div-extra_1').show();
} }
} }

View File

@ -622,7 +622,8 @@ define('DISCOVERY_CLOUD_AZURE_COMPUTE', 8);
define('DISCOVERY_DEPLOY_AGENTS', 9); define('DISCOVERY_DEPLOY_AGENTS', 9);
define('DISCOVERY_APP_SAP', 10); define('DISCOVERY_APP_SAP', 10);
define('DISCOVERY_APP_DB2', 11); define('DISCOVERY_APP_DB2', 11);
define('DISCOVERY_APP_MICROSOFT_SQL_SERVER', 12);
define('DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE', 13);
// Force task build tmp results. // Force task build tmp results.
define('DISCOVERY_REVIEW', 0); define('DISCOVERY_REVIEW', 0);
@ -641,6 +642,7 @@ define('DISCOVERY_SCRIPT_IPMI_RECON', 4);
// Discovery task descriptions. // Discovery task descriptions.
define('CLOUDWIZARD_AZURE_DESCRIPTION', 'Discovery.Cloud.Azure.Compute'); define('CLOUDWIZARD_AZURE_DESCRIPTION', 'Discovery.Cloud.Azure.Compute');
define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2'); define('CLOUDWIZARD_AWS_DESCRIPTION', 'Discovery.Cloud.AWS.EC2');
define('CLOUDWIZARD_GOOGLE_DESCRIPTION', 'Discovery.Cloud.GCP');
define('CLOUDWIZARD_VMWARE_DESCRIPTION', 'Discovery.App.VMware'); define('CLOUDWIZARD_VMWARE_DESCRIPTION', 'Discovery.App.VMware');
// Background options. // Background options.

View File

@ -1772,7 +1772,7 @@ function html_print_extended_select_for_time(
ob_start(); ob_start();
// Use the no_meta parameter because this image is only in the base console. // Use the no_meta parameter because this image is only in the base console.
echo '<div id="'.$uniq_name.'_default" style="width:100%;display:inline">'; echo '<div id="'.$uniq_name.'_default" style="width:auto;display:inline">';
html_print_select( html_print_select(
$fields, $fields,
$uniq_name.'_select', $uniq_name.'_select',
@ -2910,13 +2910,17 @@ function html_print_textarea(
$attributes='', $attributes='',
$return=false, $return=false,
$class='', $class='',
$disable=false $disable=false,
$id=false
) { ) {
$disabled = ($disable) ? 'disabled' : ''; $disabled = ($disable) ? 'disabled' : '';
$output = '<textarea id="textarea_'.$name.'" name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.' class="'.$class.'" '.$disabled.'>'; if ($id === false) {
$id = 'textarea_'.$name;
}
$output = '<textarea id="'.$id.'" name="'.$name.'" cols="'.$columns.'" rows="'.$rows.'" '.$attributes.' class="'.$class.'" '.$disabled.'>';
$output .= ($value); $output .= ($value);
$output .= '</textarea>'; $output .= '</textarea>';
if ($return) { if ($return) {
return $output; return $output;
} }
@ -4602,7 +4606,8 @@ function html_print_input($data, $wrapper='div', $input_only=false)
((isset($data['attributes']) === true) ? $data['attributes'] : ''), ((isset($data['attributes']) === true) ? $data['attributes'] : ''),
((isset($data['return']) === true) ? $data['return'] : false), ((isset($data['return']) === true) ? $data['return'] : false),
((isset($data['class']) === true) ? $data['class'] : ''), ((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; break;

View File

@ -86,6 +86,7 @@ function snmp_browser_get_html_tree(
$count = 0; $count = 0;
$total = (count(array_keys($tree['__LEAVES__'])) - 1); $total = (count(array_keys($tree['__LEAVES__'])) - 1);
$last_array[$depth] = $last; $last_array[$depth] = $last;
$class = 'item_'.$depth;
if ($depth > 0) { if ($depth > 0) {
$output .= '<ul id="ul_'.$id.'" style="margin: 0; padding: 0; display: none;">'; $output .= '<ul id="ul_'.$id.'" style="margin: 0; padding: 0; display: none;">';
@ -97,7 +98,7 @@ function snmp_browser_get_html_tree(
// Id used to expand leafs. // Id used to expand leafs.
$sub_id = time().rand(0, getrandmax()); $sub_id = time().rand(0, getrandmax());
// Display the branch. // Display the branch.
$output .= '<li id="li_'.$sub_id.'" style="margin: 0; padding: 0;">'; $output .= '<li id="li_'.$sub_id.'" class="'.$class.'" style="margin: 0; padding: 0;">';
// Indent sub branches. // Indent sub branches.
for ($i = 1; $i <= $depth; $i++) { for ($i = 1; $i <= $depth; $i++) {

View File

@ -249,7 +249,8 @@ function load_modal(settings) {
}); });
} else { } else {
settings.form.forEach(function(element) { settings.form.forEach(function(element) {
$("#" + element + " :input").each(function() { $("#" + element + " :input, #" + element + " textarea").each(
function() {
// TODO VALIDATE ALL INPUTS. // TODO VALIDATE ALL INPUTS.
if (this.type == "file") { if (this.type == "file") {
if ($(this).prop("files")[0]) { if ($(this).prop("files")[0]) {
@ -264,7 +265,8 @@ function load_modal(settings) {
formdata.append(this.name, $(this).val()); formdata.append(this.name, $(this).val());
} }
} }
}); }
);
}); });
} }

View File

@ -24,7 +24,7 @@ ul.wizard li {
margin-right: 1em; margin-right: 1em;
} }
form.modal ul.wizard li { form#modal_form ul.wizard li {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 90%; width: 90%;
@ -32,7 +32,7 @@ form.modal ul.wizard li {
justify-items: center; justify-items: center;
} }
form.modal ul.wizard li * { form#modal_form ul.wizard li * {
flex: 1; flex: 1;
} }
@ -40,3 +40,10 @@ ul.wizard li.flex-indep {
flex: 1; flex: 1;
margin: 0; 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;
}

View File

@ -619,6 +619,13 @@ select:-internal-list-box {
align-items: flex-end; align-items: flex-end;
} }
.flex-row-start {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
}
.flex-space-around { .flex-space-around {
justify-content: space-around; justify-content: space-around;
} }

View File

@ -3360,6 +3360,14 @@ sub pandora_get_credential ($$$) {
$pa_config, $pa_config,
safe_output($key->{'password'}) 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; return $key;
} }

View File

@ -38,9 +38,11 @@ use constant {
DISCOVERY_CLOUD_AWS_EC2 => 6, DISCOVERY_CLOUD_AWS_EC2 => 6,
DISCOVERY_CLOUD_AWS_RDS => 7, DISCOVERY_CLOUD_AWS_RDS => 7,
DISCOVERY_CLOUD_AZURE_COMPUTE => 8, DISCOVERY_CLOUD_AZURE_COMPUTE => 8,
DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE => 13,
DISCOVERY_DEPLOY_AGENTS => 9, DISCOVERY_DEPLOY_AGENTS => 9,
DISCOVERY_APP_SAP => 10, DISCOVERY_APP_SAP => 10,
DISCOVERY_APP_DB2 => 11, DISCOVERY_APP_DB2 => 11,
DISCOVERY_APP_MICROSOFT_SQL_SERVER => 12,
DISCOVERY_REVIEW => 0, DISCOVERY_REVIEW => 0,
DISCOVERY_STANDARD => 1, DISCOVERY_STANDARD => 1,
DISCOVERY_RESULTS => 2, DISCOVERY_RESULTS => 2,

View File

@ -88,6 +88,10 @@ our @EXPORT = qw(
DISCOVERY_CLOUD_AWS_RDS DISCOVERY_CLOUD_AWS_RDS
DISCOVERY_CLOUD_AZURE_COMPUTE DISCOVERY_CLOUD_AZURE_COMPUTE
DISCOVERY_DEPLOY_AGENTS DISCOVERY_DEPLOY_AGENTS
DISCOVERY_APP_SAP
DISCOVERY_APP_DB2
DISCOVERY_APP_MICROSOFT_SQL_SERVER
DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE
$DEVNULL $DEVNULL
$OS $OS
$OS_VERSION $OS_VERSION
@ -212,6 +216,10 @@ use constant DISCOVERY_CLOUD_AWS_EC2 => 6;
use constant DISCOVERY_CLOUD_AWS_RDS => 7; use constant DISCOVERY_CLOUD_AWS_RDS => 7;
use constant DISCOVERY_CLOUD_AZURE_COMPUTE => 8; use constant DISCOVERY_CLOUD_AZURE_COMPUTE => 8;
use constant DISCOVERY_DEPLOY_AGENTS => 9; 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 # Set OS, OS version and /dev/null
our $OS = $^O; our $OS = $^O;