intuitive credential store

This commit is contained in:
fbsanchez 2019-06-21 23:51:22 +02:00
parent e4f6a95a89
commit 5658b98f0b
4 changed files with 109 additions and 27 deletions

View File

@ -90,6 +90,8 @@ if (is_ajax()) {
foreach ($data as $key => $value) {
if ($key == 'identifier') {
$identifier = base64_decode($value);
} else if ($key == 'product') {
$product = base64_decode($value);
} else {
$values[$key] = base64_decode($value);
}
@ -99,6 +101,10 @@ if (is_ajax()) {
ajax_msg('error', __('identifier cannot be empty'));
}
if (empty($product)) {
ajax_msg('error', __('product cannot be empty'));
}
if (db_process_sql_update(
'tcredential_store',
$values,
@ -132,6 +138,10 @@ if (is_ajax()) {
ajax_msg('error', __('identifier cannot be empty'));
}
if (empty($values['product'])) {
ajax_msg('error', __('product cannot be empty'));
}
if (db_process_sql_insert('tcredential_store', $values) === false) {
ajax_msg('error', $config['dbconnection']->error);
} else {
@ -490,12 +500,40 @@ echo '</div>';
})
}
function calculate_inputs() {
if ($('#product :selected').val() == "CUSTOM") {
$('#div-username label').text('<?php echo __('Username'); ?>');
$('#div-password label').text('<?php echo __('Password'); ?>');
$('#div-extra_1 label').text('<?php echo __('Extra'); ?>');
$('#div-extra_2 label').text('<?php echo __('Extra (2)'); ?>');
$('#div-extra_1').show();
$('#div-extra_2').show();
} 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-extra_1').hide();
$('#div-extra_2').hide();
} else if ($('#product :selected').val() == "AZURE") {
$('#div-username label').text('<?php echo __('Account ID'); ?>');
$('#div-password label').text('<?php echo __('Password'); ?>');
$('#div-extra_1 label').text('<?php echo __('Tenant or domain name'); ?>');
$('#div-extra_2 label').text('<?php echo __('Subscription id'); ?>');
$('#div-extra_1').show();
$('#div-extra_2').show();
}
}
function add_key() {
// Clear form.
$('#form_new :input').each(function() {
$(this).val('')
});
$('#group').val(0);
$('#id_group').val(0);
$('#product').val('CUSTOM');
$('#product').on('change', function() {
calculate_inputs()
});
// Show form.
$('#new_key').dialog({

View File

@ -280,15 +280,52 @@ function print_inputs($values=null)
'label' => __('Product'),
'name' => 'product',
'input_class' => 'flex-row',
'type' => 'text',
'value' => $values['product'],
'type' => 'select',
'fields' => [
'CUSTOM' => __('Custom'),
'AWS' => __('Aws'),
'AZURE' => __('Azure'),
// 'GOOGLE' => __('Google'),
],
'selected' => $values['product'],
'disabled' => (bool) $values['product'],
'return' => true,
]
);
$user_label = __('Username');
$pass_label = __('Password');
$extra_1_label = __('Extra');
$extra_2_label = __('Extra (2)');
$extra1 = true;
$extra2 = true;
// Remember to update credential_store.php also.
switch ($values['product']) {
case 'AWS':
$user_label = __('Access key ID');
$pass_label = __('Secret access key');
$extra1 = false;
$extra2 = false;
break;
case 'AZURE':
$user_label = __('Account ID');
$pass_label = __('Password');
$extra_1_label = __('Tenant or domain name');
$extra_2_label = __('Subscription id');
break;
case 'GOOGLE':
// Need further investigation.
case 'CUSTOM':
default:
// Use defaults.
break;
}
$return .= html_print_input(
[
'label' => __('Username'),
'label' => $user_label,
'name' => 'username',
'input_class' => 'flex-row',
'type' => 'text',
@ -298,7 +335,7 @@ function print_inputs($values=null)
);
$return .= html_print_input(
[
'label' => __('Password'),
'label' => $pass_label,
'name' => 'password',
'input_class' => 'flex-row',
'type' => 'password',
@ -306,26 +343,32 @@ function print_inputs($values=null)
'return' => true,
]
);
$return .= html_print_input(
[
'label' => __('Extra'),
'name' => 'extra_1',
'input_class' => 'flex-row',
'type' => 'password',
'value' => $values['extra_1'],
'return' => true,
]
);
$return .= html_print_input(
[
'label' => __('Extra (2)'),
'name' => 'extra_2',
'input_class' => 'flex-row',
'type' => 'password',
'value' => $values['extra_2'],
'return' => true,
]
);
if ($extra1) {
$return .= html_print_input(
[
'label' => $extra_1_label,
'name' => 'extra_1',
'input_class' => 'flex-row',
'type' => 'password',
'value' => $values['extra_1'],
'return' => true,
]
);
}
if ($extra2) {
$return .= html_print_input(
[
'label' => $extra_2_label,
'name' => 'extra_2',
'input_class' => 'flex-row',
'type' => 'password',
'value' => $values['extra_2'],
'return' => true,
'display' => $extra2,
]
);
}
return $return;
}

View File

@ -3084,7 +3084,8 @@ function html_print_input($data)
$output = '';
if ($data['label']) {
$output = '<div class="'.$data['input_class'].'">';
$output = '<div id="div-'.$data['name'].'" ';
$output .= ' class="'.$data['input_class'].'">';
$output .= '<label class="'.$data['label_class'].'">';
$output .= $data['label'];
$output .= '</label>';

View File

@ -8,5 +8,5 @@
#info_key select,
#new_key input,
#new_key select {
width: 80%;
width: 60%;
}