WIP GCP
This commit is contained in:
parent
4ceeb61c87
commit
9ce54213b6
|
@ -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(
|
||||
$('<input type="text" name="extra_1" id="text-extra_1" size="50" value="'+val+'"></input>')
|
||||
);
|
||||
}
|
||||
|
||||
if ($('#product :selected').val() == "CUSTOM") {
|
||||
$('#div-username label').text('<?php echo __('User'); ?>');
|
||||
$('#div-password label').text('<?php echo __('Password'); ?>');
|
||||
$('#div-username').show();
|
||||
$('#div-password').show();
|
||||
$('#div-extra_1').hide();
|
||||
$('#div-extra_2').hide();
|
||||
} else if ($('#product :selected').val() == "AWS") {
|
||||
$('#div-username label').text('<?php echo __('Access key ID'); ?>');
|
||||
$('#div-password label').text('<?php echo __('Secret access key'); ?>');
|
||||
$('#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('<?php echo __('Application secret'); ?>');
|
||||
$('#div-extra_1 label').text('<?php echo __('Tenant or domain name'); ?>');
|
||||
$('#div-extra_2 label').text('<?php echo __('Subscription id'); ?>');
|
||||
$('#div-username').show();
|
||||
$('#div-password').show();
|
||||
$('#div-extra_1').show();
|
||||
$('#div-extra_2').show();
|
||||
} else if ($('#product :selected').val() == "SAP") {
|
||||
$('#div-username label').text('<?php echo __('Account ID.'); ?>');
|
||||
$('#div-password label').text('<?php echo __('Password'); ?>');
|
||||
$('#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('<?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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2681,13 +2681,17 @@ function html_print_textarea(
|
|||
$attributes='',
|
||||
$return=false,
|
||||
$class='',
|
||||
$disable=false
|
||||
$disable=false,
|
||||
$id=false
|
||||
) {
|
||||
$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 .= '</textarea>';
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue