diff --git a/pandora_console/godmode/groups/credential_store.php b/pandora_console/godmode/groups/credential_store.php index bd08fd4df2..729a2ff7bd 100644 --- a/pandora_console/godmode/groups/credential_store.php +++ b/pandora_console/godmode/groups/credential_store.php @@ -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 ''; }) } + function calculate_inputs() { + if ($('#product :selected').val() == "CUSTOM") { + $('#div-username label').text(''); + $('#div-password label').text(''); + $('#div-extra_1 label').text(''); + $('#div-extra_2 label').text(''); + $('#div-extra_1').show(); + $('#div-extra_2').show(); + } else if ($('#product :selected').val() == "AWS") { + $('#div-username label').text(''); + $('#div-password label').text(''); + $('#div-extra_1').hide(); + $('#div-extra_2').hide(); + } else if ($('#product :selected').val() == "AZURE") { + $('#div-username label').text(''); + $('#div-password label').text(''); + $('#div-extra_1 label').text(''); + $('#div-extra_2 label').text(''); + $('#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({ diff --git a/pandora_console/include/functions_credential_store.php b/pandora_console/include/functions_credential_store.php index 09d1ce100c..1a1f69a7ec 100644 --- a/pandora_console/include/functions_credential_store.php +++ b/pandora_console/include/functions_credential_store.php @@ -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; } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 0ead67b3ea..533822f069 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3084,7 +3084,8 @@ function html_print_input($data) $output = ''; if ($data['label']) { - $output = '