intuitive credential store
This commit is contained in:
parent
e4f6a95a89
commit
5658b98f0b
|
@ -90,6 +90,8 @@ if (is_ajax()) {
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if ($key == 'identifier') {
|
if ($key == 'identifier') {
|
||||||
$identifier = base64_decode($value);
|
$identifier = base64_decode($value);
|
||||||
|
} else if ($key == 'product') {
|
||||||
|
$product = base64_decode($value);
|
||||||
} else {
|
} else {
|
||||||
$values[$key] = base64_decode($value);
|
$values[$key] = base64_decode($value);
|
||||||
}
|
}
|
||||||
|
@ -99,6 +101,10 @@ if (is_ajax()) {
|
||||||
ajax_msg('error', __('identifier cannot be empty'));
|
ajax_msg('error', __('identifier cannot be empty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($product)) {
|
||||||
|
ajax_msg('error', __('product cannot be empty'));
|
||||||
|
}
|
||||||
|
|
||||||
if (db_process_sql_update(
|
if (db_process_sql_update(
|
||||||
'tcredential_store',
|
'tcredential_store',
|
||||||
$values,
|
$values,
|
||||||
|
@ -132,6 +138,10 @@ if (is_ajax()) {
|
||||||
ajax_msg('error', __('identifier cannot be empty'));
|
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) {
|
if (db_process_sql_insert('tcredential_store', $values) === false) {
|
||||||
ajax_msg('error', $config['dbconnection']->error);
|
ajax_msg('error', $config['dbconnection']->error);
|
||||||
} else {
|
} 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() {
|
function add_key() {
|
||||||
// Clear form.
|
// Clear form.
|
||||||
$('#form_new :input').each(function() {
|
$('#form_new :input').each(function() {
|
||||||
$(this).val('')
|
$(this).val('')
|
||||||
});
|
});
|
||||||
$('#group').val(0);
|
$('#id_group').val(0);
|
||||||
|
$('#product').val('CUSTOM');
|
||||||
|
|
||||||
|
$('#product').on('change', function() {
|
||||||
|
calculate_inputs()
|
||||||
|
});
|
||||||
|
|
||||||
// Show form.
|
// Show form.
|
||||||
$('#new_key').dialog({
|
$('#new_key').dialog({
|
||||||
|
|
|
@ -280,15 +280,52 @@ function print_inputs($values=null)
|
||||||
'label' => __('Product'),
|
'label' => __('Product'),
|
||||||
'name' => 'product',
|
'name' => 'product',
|
||||||
'input_class' => 'flex-row',
|
'input_class' => 'flex-row',
|
||||||
'type' => 'text',
|
'type' => 'select',
|
||||||
'value' => $values['product'],
|
'fields' => [
|
||||||
|
'CUSTOM' => __('Custom'),
|
||||||
|
'AWS' => __('Aws'),
|
||||||
|
'AZURE' => __('Azure'),
|
||||||
|
// 'GOOGLE' => __('Google'),
|
||||||
|
],
|
||||||
|
'selected' => $values['product'],
|
||||||
'disabled' => (bool) $values['product'],
|
'disabled' => (bool) $values['product'],
|
||||||
'return' => true,
|
'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(
|
$return .= html_print_input(
|
||||||
[
|
[
|
||||||
'label' => __('Username'),
|
'label' => $user_label,
|
||||||
'name' => 'username',
|
'name' => 'username',
|
||||||
'input_class' => 'flex-row',
|
'input_class' => 'flex-row',
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
|
@ -298,7 +335,7 @@ function print_inputs($values=null)
|
||||||
);
|
);
|
||||||
$return .= html_print_input(
|
$return .= html_print_input(
|
||||||
[
|
[
|
||||||
'label' => __('Password'),
|
'label' => $pass_label,
|
||||||
'name' => 'password',
|
'name' => 'password',
|
||||||
'input_class' => 'flex-row',
|
'input_class' => 'flex-row',
|
||||||
'type' => 'password',
|
'type' => 'password',
|
||||||
|
@ -306,26 +343,32 @@ function print_inputs($values=null)
|
||||||
'return' => true,
|
'return' => true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$return .= html_print_input(
|
if ($extra1) {
|
||||||
[
|
$return .= html_print_input(
|
||||||
'label' => __('Extra'),
|
[
|
||||||
'name' => 'extra_1',
|
'label' => $extra_1_label,
|
||||||
'input_class' => 'flex-row',
|
'name' => 'extra_1',
|
||||||
'type' => 'password',
|
'input_class' => 'flex-row',
|
||||||
'value' => $values['extra_1'],
|
'type' => 'password',
|
||||||
'return' => true,
|
'value' => $values['extra_1'],
|
||||||
]
|
'return' => true,
|
||||||
);
|
]
|
||||||
$return .= html_print_input(
|
);
|
||||||
[
|
}
|
||||||
'label' => __('Extra (2)'),
|
|
||||||
'name' => 'extra_2',
|
if ($extra2) {
|
||||||
'input_class' => 'flex-row',
|
$return .= html_print_input(
|
||||||
'type' => 'password',
|
[
|
||||||
'value' => $values['extra_2'],
|
'label' => $extra_2_label,
|
||||||
'return' => true,
|
'name' => 'extra_2',
|
||||||
]
|
'input_class' => 'flex-row',
|
||||||
);
|
'type' => 'password',
|
||||||
|
'value' => $values['extra_2'],
|
||||||
|
'return' => true,
|
||||||
|
'display' => $extra2,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3084,7 +3084,8 @@ function html_print_input($data)
|
||||||
$output = '';
|
$output = '';
|
||||||
|
|
||||||
if ($data['label']) {
|
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 .= '<label class="'.$data['label_class'].'">';
|
||||||
$output .= $data['label'];
|
$output .= $data['label'];
|
||||||
$output .= '</label>';
|
$output .= '</label>';
|
||||||
|
|
|
@ -8,5 +8,5 @@
|
||||||
#info_key select,
|
#info_key select,
|
||||||
#new_key input,
|
#new_key input,
|
||||||
#new_key select {
|
#new_key select {
|
||||||
width: 80%;
|
width: 60%;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue