From ca1c2b567e9df1489c9061bf6788514df4972916 Mon Sep 17 00:00:00 2001 From: q3aql Date: Sat, 18 Jun 2022 17:06:41 +0200 Subject: [PATCH] Show error when type letters on search option (pwsh-vault-cli) --- pwsh-vault-cli.sh | 348 +++++++++++++++++++++++++++------------------- 1 file changed, 206 insertions(+), 142 deletions(-) diff --git a/pwsh-vault-cli.sh b/pwsh-vault-cli.sh index fbbc0bb..26a1c1d 100755 --- a/pwsh-vault-cli.sh +++ b/pwsh-vault-cli.sh @@ -1122,32 +1122,40 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} logins) - if [ ${corrupted_result} -eq 0 ] ; then - username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) - username_decrypt=$(vault_key_decrypt "${username_decrypt}") - password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) - password_decrypt=$(vault_key_decrypt "${password_decrypt}") - url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) - url_decrypt=$(vault_key_decrypt "${url_decrypt}") - otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) - otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") - if [ "${otp_decrypt}" == "None" ] ; then - otp_decrypt="None" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} logins) + if [ ${corrupted_result} -eq 0 ] ; then + username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) + username_decrypt=$(vault_key_decrypt "${username_decrypt}") + password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) + password_decrypt=$(vault_key_decrypt "${password_decrypt}") + url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) + url_decrypt=$(vault_key_decrypt "${url_decrypt}") + otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) + otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") + if [ "${otp_decrypt}" == "None" ] ; then + otp_decrypt="None" + else + otp_decrypt="Yes" + fi + echo "" + echo "* Name Entry: logins/${result}" + echo "* Login: ${username_decrypt}" + echo "* Password: ${password_decrypt}" + echo "* URL: ${url_decrypt}" + echo "* OTP: ${otp_decrypt}" + echo "" else - otp_decrypt="Yes" + echo "" + echo "# Entry logins/${result} CORRUPTED" + echo "" fi - echo "" - echo "* Name Entry: logins/${result}" - echo "* Login: ${username_decrypt}" - echo "* Password: ${password_decrypt}" - echo "* URL: ${url_decrypt}" - echo "* OTP: ${otp_decrypt}" - echo "" else echo "" - echo "# Entry logins/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1183,32 +1191,40 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} logins) - if [ ${corrupted_result} -eq 0 ] ; then - username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) - username_decrypt=$(vault_key_decrypt "${username_decrypt}") - password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) - password_decrypt=$(vault_key_decrypt "${password_decrypt}") - url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) - url_decrypt=$(vault_key_decrypt "${url_decrypt}") - otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) - otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") - if [ "${otp_decrypt}" == "None" ] ; then - otp_decrypt="None" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} logins) + if [ ${corrupted_result} -eq 0 ] ; then + username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) + username_decrypt=$(vault_key_decrypt "${username_decrypt}") + password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) + password_decrypt=$(vault_key_decrypt "${password_decrypt}") + url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) + url_decrypt=$(vault_key_decrypt "${url_decrypt}") + otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) + otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") + if [ "${otp_decrypt}" == "None" ] ; then + otp_decrypt="None" + else + otp_decrypt="Yes" + fi + echo "" + echo "* Name Entry: logins/${result}" + echo "* Login: ${username_decrypt}" + echo "* Password: ${password_decrypt}" + echo "* URL: ${url_decrypt}" + echo "* OTP: ${otp_decrypt}" + echo "" else - otp_decrypt="Yes" + echo "" + echo "# Entry logins/${result} CORRUPTED" + echo "" fi - echo "" - echo "* Name Entry: logins/${result}" - echo "* Login: ${username_decrypt}" - echo "* Password: ${password_decrypt}" - echo "* URL: ${url_decrypt}" - echo "* OTP: ${otp_decrypt}" - echo "" else echo "" - echo "# Entry logins/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1250,27 +1266,35 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} logins) - if [ ${corrupted_result} -eq 0 ] ; then - username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) - username_decrypt=$(vault_key_decrypt "${username_decrypt}") - password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) - password_decrypt=$(vault_key_decrypt "${password_decrypt}") - url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) - url_decrypt=$(vault_key_decrypt "${url_decrypt}") - otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) - otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") - echo "" - echo "* Name Entry: logins/${result}" - echo "* Login: ${username_decrypt}" - echo "* Password: ${password_decrypt}" - echo "* URL: ${url_decrypt}" - echo "* OTP: ${otp_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} logins) + if [ ${corrupted_result} -eq 0 ] ; then + username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) + username_decrypt=$(vault_key_decrypt "${username_decrypt}") + password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) + password_decrypt=$(vault_key_decrypt "${password_decrypt}") + url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) + url_decrypt=$(vault_key_decrypt "${url_decrypt}") + otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) + otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") + echo "" + echo "* Name Entry: logins/${result}" + echo "* Login: ${username_decrypt}" + echo "* Password: ${password_decrypt}" + echo "* URL: ${url_decrypt}" + echo "* OTP: ${otp_decrypt}" + echo "" + else + echo "" + echo "# Entry logins/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry logins/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1308,27 +1332,35 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} logins) - if [ ${corrupted_result} -eq 0 ] ; then - username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) - username_decrypt=$(vault_key_decrypt "${username_decrypt}") - password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) - password_decrypt=$(vault_key_decrypt "${password_decrypt}") - url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) - url_decrypt=$(vault_key_decrypt "${url_decrypt}") - otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) - otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") - echo "" - echo "* Name Entry: logins/${result}" - echo "* Login: ${username_decrypt}" - echo "* Password: ${password_decrypt}" - echo "* URL: ${url_decrypt}" - echo "* OTP: ${otp_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_logins} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} logins) + if [ ${corrupted_result} -eq 0 ] ; then + username_decrypt=$(cat logins/${result}/login | tail -1 | cut -d ";" -f 2) + username_decrypt=$(vault_key_decrypt "${username_decrypt}") + password_decrypt=$(cat logins/${result}/password | tail -1 | cut -d ";" -f 2) + password_decrypt=$(vault_key_decrypt "${password_decrypt}") + url_decrypt=$(cat logins/${result}/url | tail -1 | cut -d ";" -f 2) + url_decrypt=$(vault_key_decrypt "${url_decrypt}") + otp_decrypt=$(cat logins/${result}/otp | tail -1 | cut -d ";" -f 2) + otp_decrypt=$(vault_key_decrypt "${otp_decrypt}") + echo "" + echo "* Name Entry: logins/${result}" + echo "* Login: ${username_decrypt}" + echo "* Password: ${password_decrypt}" + echo "* URL: ${url_decrypt}" + echo "* OTP: ${otp_decrypt}" + echo "" + else + echo "" + echo "# Entry logins/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry logins/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1370,27 +1402,35 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_bcard} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} bcard) - if [ ${corrupted_result} -eq 0 ] ; then - owner_decrypt=$(cat bcard/${result}/owner | tail -1 | cut -d ";" -f 2) - owner_decrypt=$(vault_key_decrypt "${owner_decrypt}") - card_decrypt=$(cat bcard/${result}/card | tail -1 | cut -d ";" -f 2) - card_decrypt=$(vault_key_decrypt "${card_decrypt}") - expiry_decrypt=$(cat bcard/${result}/expiry | tail -1 | cut -d ";" -f 2) - expiry_decrypt=$(vault_key_decrypt "${expiry_decrypt}") - cvv_decrypt=$(cat bcard/${result}/cvv | tail -1 | cut -d ";" -f 2) - cvv_decrypt=$(vault_key_decrypt "${cvv_decrypt}") - echo "" - echo "* Name Entry: bcard/${result}" - echo "* Owner: ${owner_decrypt}" - echo "* Card: ${card_decrypt}" - echo "* Expiry: ${expiry_decrypt}" - echo "* CVV: ${cvv_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_bcard} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} bcard) + if [ ${corrupted_result} -eq 0 ] ; then + owner_decrypt=$(cat bcard/${result}/owner | tail -1 | cut -d ";" -f 2) + owner_decrypt=$(vault_key_decrypt "${owner_decrypt}") + card_decrypt=$(cat bcard/${result}/card | tail -1 | cut -d ";" -f 2) + card_decrypt=$(vault_key_decrypt "${card_decrypt}") + expiry_decrypt=$(cat bcard/${result}/expiry | tail -1 | cut -d ";" -f 2) + expiry_decrypt=$(vault_key_decrypt "${expiry_decrypt}") + cvv_decrypt=$(cat bcard/${result}/cvv | tail -1 | cut -d ";" -f 2) + cvv_decrypt=$(vault_key_decrypt "${cvv_decrypt}") + echo "" + echo "* Name Entry: bcard/${result}" + echo "* Owner: ${owner_decrypt}" + echo "* Card: ${card_decrypt}" + echo "* Expiry: ${expiry_decrypt}" + echo "* CVV: ${cvv_decrypt}" + echo "" + else + echo "" + echo "# Entry bcard/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry bcard/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1426,27 +1466,35 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_bcard} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} bcard) - if [ ${corrupted_result} -eq 0 ] ; then - owner_decrypt=$(cat bcard/${result}/owner | tail -1 | cut -d ";" -f 2) - owner_decrypt=$(vault_key_decrypt "${owner_decrypt}") - card_decrypt=$(cat bcard/${result}/card | tail -1 | cut -d ";" -f 2) - card_decrypt=$(vault_key_decrypt "${card_decrypt}") - expiry_decrypt=$(cat bcard/${result}/expiry | tail -1 | cut -d ";" -f 2) - expiry_decrypt=$(vault_key_decrypt "${expiry_decrypt}") - cvv_decrypt=$(cat bcard/${result}/cvv | tail -1 | cut -d ";" -f 2) - cvv_decrypt=$(vault_key_decrypt "${cvv_decrypt}") - echo "" - echo "* Name Entry: bcard/${result}" - echo "* Owner: ${owner_decrypt}" - echo "* Card: ${card_decrypt}" - echo "* Expiry: ${expiry_decrypt}" - echo "* CVV: ${cvv_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_bcard} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} bcard) + if [ ${corrupted_result} -eq 0 ] ; then + owner_decrypt=$(cat bcard/${result}/owner | tail -1 | cut -d ";" -f 2) + owner_decrypt=$(vault_key_decrypt "${owner_decrypt}") + card_decrypt=$(cat bcard/${result}/card | tail -1 | cut -d ";" -f 2) + card_decrypt=$(vault_key_decrypt "${card_decrypt}") + expiry_decrypt=$(cat bcard/${result}/expiry | tail -1 | cut -d ";" -f 2) + expiry_decrypt=$(vault_key_decrypt "${expiry_decrypt}") + cvv_decrypt=$(cat bcard/${result}/cvv | tail -1 | cut -d ";" -f 2) + cvv_decrypt=$(vault_key_decrypt "${cvv_decrypt}") + echo "" + echo "* Name Entry: bcard/${result}" + echo "* Owner: ${owner_decrypt}" + echo "* Card: ${card_decrypt}" + echo "* Expiry: ${expiry_decrypt}" + echo "* CVV: ${cvv_decrypt}" + echo "" + else + echo "" + echo "# Entry bcard/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry bcard/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1487,19 +1535,27 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_notes} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} notes) - if [ ${corrupted_result} -eq 0 ] ; then - note_decrypt=$(cat notes/${result}/note | tail -1 | cut -d ";" -f 2) - note_decrypt=$(vault_key_decrypt "${note_decrypt}") - note_decrypt=$(restoreSpaces "${note_decrypt}") - echo "" - echo "* Name Entry: notes/${result}" - echo "* Note: ${note_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_notes} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} notes) + if [ ${corrupted_result} -eq 0 ] ; then + note_decrypt=$(cat notes/${result}/note | tail -1 | cut -d ";" -f 2) + note_decrypt=$(vault_key_decrypt "${note_decrypt}") + note_decrypt=$(restoreSpaces "${note_decrypt}") + echo "" + echo "* Name Entry: notes/${result}" + echo "* Note: ${note_decrypt}" + echo "" + else + echo "" + echo "# Entry notes/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry notes/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi @@ -1535,19 +1591,27 @@ function search_entries_vault() { echo "# Invalid entry. Type number entry or 'b' option." echo "" else - result=$(cat ${pwsh_vault_cache_notes} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) - corrupted_result=$(check_corrupted_entry_vault ${result} notes) - if [ ${corrupted_result} -eq 0 ] ; then - note_decrypt=$(cat notes/${result}/note | tail -1 | cut -d ";" -f 2) - note_decrypt=$(vault_key_decrypt "${note_decrypt}") - note_decrypt=$(restoreSpaces "${note_decrypt}") - echo "" - echo "* Name Entry: notes/${result}" - echo "* Note: ${note_decrypt}" - echo "" + expr ${search_show_entry} + 1 &> /dev/null + error=$? + if [ ${error} -eq 0 ] ; then + result=$(cat ${pwsh_vault_cache_notes} | head -${search_show_entry} 2>/dev/null | tail -1 | cut -d "," -f 1 | cut -d "/" -f 2) + corrupted_result=$(check_corrupted_entry_vault ${result} notes) + if [ ${corrupted_result} -eq 0 ] ; then + note_decrypt=$(cat notes/${result}/note | tail -1 | cut -d ";" -f 2) + note_decrypt=$(vault_key_decrypt "${note_decrypt}") + note_decrypt=$(restoreSpaces "${note_decrypt}") + echo "" + echo "* Name Entry: notes/${result}" + echo "* Note: ${note_decrypt}" + echo "" + else + echo "" + echo "# Entry notes/${result} CORRUPTED" + echo "" + fi else echo "" - echo "# Entry notes/${result} CORRUPTED" + echo "# Invalid entry. Type number entry or 'b' option." echo "" fi fi