nice contacts

This commit is contained in:
Shihaam Abdul Rahman 2021-05-20 04:33:26 +05:00
parent 0799b0764f
commit ca2fa8c194
2 changed files with 126 additions and 93 deletions

0
a.out Normal file
View File

View File

@ -42,7 +42,7 @@ animate(){
while [ -d /proc/$PID ]; do while [ -d /proc/$PID ]; do
h=$(((h + 1) % 4)) h=$(((h + 1) % 4))
sleep 0.05 sleep 0.05
printf "\r${@} [${anim:$h:1}]" printf "\r${@} [${anim:$h:1}]"
done done
} }
initialize(){ initialize(){
@ -63,7 +63,7 @@ check_connection(){
if [ "$PING" != "0%" ] if [ "$PING" != "0%" ]
then then
echo ${red}Check your connection and try again.${reset} echo ${red}Check your connection and try again.${reset}
exit exit 1
fi fi
DOS=$(curl -s https://www.bankofmaldives.com.mv/ | grep -oE "error code: 1020") DOS=$(curl -s https://www.bankofmaldives.com.mv/ | grep -oE "error code: 1020")
if [ "$DOS" = "error code: 1020" ] if [ "$DOS" = "error code: 1020" ]
@ -85,7 +85,7 @@ os_detect(){
if [ "$I_AM_SODU" != "true" ] if [ "$I_AM_SODU" != "true" ]
then then
echo ${red}Please check $CONFIG and configure accordingly.${reset} echo ${red}Please check $CONFIG and configure accordingly.${reset}
exit cexit
fi fi
elif [ "$MAC" = "Darwin" ] elif [ "$MAC" = "Darwin" ]
then then
@ -94,7 +94,7 @@ os_detect(){
if [ "$I_AM_HYPOCRITE" != "true" ] if [ "$I_AM_HYPOCRITE" != "true" ]
then then
echo ${red}Please check $CONFIG and configure accordingly.${reset} echo ${red}Please check $CONFIG and configure accordingly.${reset}
exit cexit
fi fi
elif [ "$ANDROID" = "Android" ] elif [ "$ANDROID" = "Android" ]
then then
@ -103,7 +103,7 @@ os_detect(){
banner banner
} }
################################################################## ##################################################################
banner(){ display_banner(){
clear clear
echo "${red}" echo "${red}"
echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗"
@ -115,11 +115,14 @@ banner(){
echo "${reset}" echo "${reset}"
} }
display_welcome(){ display_welcome(){
echo ""
echo ${green}Welcome ${reset}$NAME echo ${green}Welcome ${reset}$NAME
echo "" echo ""
} }
display_user_info(){ display_name(){
echo ""
echo ${cyan}Name${reset}: $NAME
}
display_userinfo(){
echo ${cyan}Phone${reset}: $PHONE echo ${cyan}Phone${reset}: $PHONE
echo ${cyan}Email${reset}: $EMAIL echo ${cyan}Email${reset}: $EMAIL
echo ${cyan}Birthday${reset}: $DOB echo ${cyan}Birthday${reset}: $DOB
@ -127,6 +130,13 @@ display_user_info(){
echo "" echo ""
} }
#################################################################### ####################################################################
cexit(){
echo "Cleaning up.."
rm $COOKIE
sleep 0.2
exit
}
readpin(){ readpin(){
read -s -p 'Enter Pin: ' PIN read -s -p 'Enter Pin: ' PIN
echo "" echo ""
@ -136,10 +146,11 @@ readpin(){
echo ${R}Incorrect Pin${N} echo ${R}Incorrect Pin${N}
readpin readpin
fi fi
banner #banner
BML_USERNAME_UNSAFE=$(echo ${BML_USERNAME} | openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2) BML_USERNAME_UNSAFE=$(echo ${BML_USERNAME} | openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2)
BML_PASSWORD_UNSAFE=$(echo ${BML_PASSWORD} | openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2) BML_PASSWORD_UNSAFE=$(echo ${BML_PASSWORD} | openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2)
login #banner
login #& animate "Logging in"
} }
wipe_credentials(){ wipe_credentials(){
@ -184,7 +195,8 @@ savepass(){
else else
: :
fi fi
select_profile # urandom && select_profile urandom
select_profile #& animate "Selecting Profile" # urandom && select_profile
} }
################################################################################################ ################################################################################################
@ -196,20 +208,21 @@ login(){
| jq -r .code) | jq -r .code)
if [ "$LOGIN" = "0" ] if [ "$LOGIN" = "0" ]
then then
display_banner
echo ${lightgreen}Login success${reset} echo ${lightgreen}Login success${reset}
savepass savepass
elif [ "$LOGIN" = "20" ] elif [ "$LOGIN" = "20" ]
then then
banner display_banner
account_locked account_locked
sleep 1.5 sleep 1.5
banner display_banner
echo "${red}Account Locked!${reset}" echo "${red}Account Locked!${reset}"
echo "${lightred}Please reset password and login again.${reset}" echo "${lightred}Please reset password and login again.${reset}"
enter_credentials enter_credentials
elif [ "$LOGIN" = "2" ] elif [ "$LOGIN" = "2" ]
then then
banner display_banner
echo ${red}Password or Username Incorrect${reset} echo ${red}Password or Username Incorrect${reset}
wipe_credentials wipe_credentials
enter_credentials enter_credentials
@ -270,9 +283,9 @@ userinfo(){
SUCCESS=$(echo $USERINFO | jq -r .success) SUCCESS=$(echo $USERINFO | jq -r .success)
if [ "$SUCCESS" != "true" ] if [ "$SUCCESS" != "true" ]
then then
echo "Login Required" echo ${red}Login Required${reset}
init_login init_login
banner display_banner
userinfo userinfo
fi fi
USERINFO=$(echo $USERINFO | jq -r '.["payload"] | .["user"]') USERINFO=$(echo $USERINFO | jq -r '.["payload"] | .["user"]')
@ -286,35 +299,35 @@ userinfo(){
################################################################################################ ################################################################################################
accounts(){ accounts(){
echo $API_DASHBOARD \ echo $DASHBOARD | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)'
| jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)'
} }
################################################################################################ ################################################################################################
api_dashboard(){ api_dashboard(){
API_DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard) DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard)
SUCCESS=$(echo $API_DASHBOARD | jq -r .success) SUCCESS=$(echo $DASHBOARD | jq -r .success)
if [ "$SUCCESS" != "true" ] if [ "$SUCCESS" != "true" ]
then then
echo "Login Required" echo ${red}Login Required${reset}
init_login init_login
banner display_banner && display_name && display_userinfo
api_dashboard api_dashboard
fi fi
} }
################################################################################################ ################################################################################################
list_contacts(){ list_contacts(){
echo $API_CONATACTS | jq -r '["ID","Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.id, .account, .currency, .name, .alias]) | @tsv' echo $API_CONATACTS | jq -r '["ID","Account Number","Currency","Account Name","Contact Name"], ["===========","==============","========","=============================","============================="], (.["payload"] | .[] | [.id, .account, .currency, .name, .alias]) | @tsv' \
| perl -pe 's/((?<=\t)|(?<=^))\t/ \t/g;' "$@" | column -t -s $'\t' | exec less -F -S -X -K
} }
################################################################################################ ################################################################################################
api_contacts(){ api_contacts(){
API_CONATACTS=$(curl -s -b $COOKIE $BML_URL/contacts) API_CONATACTS=$(curl -s -b $COOKIE $BML_URL/contacts)
SUCCESS=$(echo $API_CONATACTS | jq -r .success) SUCCESS=$(echo $API_CONATACTS | jq -r .code)
if [ "$SUCCESS" != "true" ] if [ "$SUCCESS" = "17" ]
then then
echo "Login Required" echo ${red}Login Required${reset}
init_login init_login
banner display_banner && display_name && display_userinfo
api_contacts api_contacts
fi fi
} }
@ -331,14 +344,34 @@ transfer(){
################################################################################################ ################################################################################################
api_account(){ api_account(){
API_ACCOUNT=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER) API_ACCOUNT=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER)
SUCCESS=$(echo $API_ACCOUNT | jq -r .code)
if [ "$SUCCESS" = "17" ]
then
echo ${red}Login Required${reset}
init_login
display_banner && display_name && display_userinfo
fi
} }
################################################################################################ ################################################################################################
################################################################################################ ################################################################################################
add_contact(){ add_contact(){
printf 'Account Number: ' printf 'Account Number: '
read -r ACCOUNT_NUMBER read -r ACCOUNT_NUMBER
if [ "$ACCOUNT_NUMBER" = "x" ] || [ "$ACCOUNT_NUMBER" = "back" ]
then
display_banner && display_name && display_userinfo
contacts_menu
elif [ "$ACCOUNT_NUMBER" = "" ]
then
display_banner && display_name && display_userinfo
echo ${red}No input${reset}
echo Input account number or ${lightgreen}x${reset} to go back
add_contact
fi
api_account api_account
VALID_NUMBER=$(echo $API_ACCOUNT | jq -r .success) VALID_NUMBER=$(echo $API_ACCOUNT | jq -r .success)
@ -355,21 +388,26 @@ then
if [ "$CONTACT_NAME" = "" ] if [ "$CONTACT_NAME" = "" ]
then then
CONTACT_NAME=$ACCOUNT_NAME CONTACT_NAME=$ACCOUNT_NAME
else
:
fi fi
CONTACT_NAME=`echo "$CONTACT_NAME" | sed "s/ /%20/"` CONTACT_NAME_SED=`echo "$CONTACT_NAME" | sed "s/ /%20/g"`
ADDCONTACT=$(curl -s -b $COOKIE $BML_URL/contacts \ ADDCONTACT=$(curl -s -b $COOKIE $BML_URL/contacts \
--data-raw contact_type=IAT \ --data-raw contact_type=IAT \
--data-raw account=$ACCOUNT_NUMBER \ --data-raw account=$ACCOUNT_NUMBER \
--data-raw alias=$CONTACT_NAME \ --data-raw alias=$CONTACT_NAME_SED \
--compressed \ --compressed \
| jq -r .success) | jq -r .code)
if [ "$ADDCONTACT" = "true" ] if [ "$ADDCONTACT" = "0" ]
then then
echo "Contact added successfully" display_banner && display_name && display_userinfo
echo $ACCOUNT_NUMBER ${lightgreen}saved as ${reset} $CONTACT_NAME ${lightgreen}succesfully${reset}
elif [ "$ADDCONTACT" = "17" ]
then
echo ${red}Login Required ${reset}
init_login
add_contact
else else
display_banner && display_name && display_userinfo
echo "${red}There was an error${reset}" echo "${red}There was an error${reset}"
fi fi
else else
@ -415,46 +453,42 @@ read -r MENU
if [ "$MENU" = "1" ] if [ "$MENU" = "1" ]
then then
banner display_banner
api_dashboard api_dashboard # & animate "Fetching account details"
accounts #& animate "Fetching account details" display_banner
# display_user_info accounts
accounts_menu accounts_menu
elif [ "$MENU" = "2" ] elif [ "$MENU" = "2" ]
then then
banner display_banner && display_name && display_userinfo
transfer_menu transfer_menu
elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ] elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ]
then then
banner && api_contacts && list_contacts && contacts_menu display_banner && display_name && display_userinfo
api_contacts #& animate "Fetching contacts"
#display_banner
list_contacts
contacts_menu
elif [ "$MENU" = "4" ] elif [ "$MENU" = "4" ]
then then
echo "WIP" echo "WIP"
sleep 2 sleep 2
source mainmenu.sh source mainmenu.sh
source activities.sh source activities.sh
elif [ "$MENU" = "5" ] elif [ "$MENU" = "5" ]
then then
echo "WIP" echo "WIP"
sleep 2 sleep 2
source mainmenu.sh cexit
source services.sh elif [ "$MENU" = "6" ]
elif [ "$MENU" = "6" ]
then then
banner && settings display_banner && display_name && display_userinfo
elif [ "$MENU" = "clear" ] settings
elif [ "$MENU" = "exit" ]
then then
clear cexit
sleep 0.2 else
source mainmenu.sh display_banner && display_name && display_userinfo
elif [ "$MENU" = "exit" ]
then
echo "cleaning up..."
rm $COOKIE
sleep 0.2
exit
else
banner
echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2 echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2
main_menu main_menu
fi fi
@ -463,7 +497,8 @@ fi
accounts_menu(){ accounts_menu(){
echo "Work In Progress" echo "Work In Progress"
read -p "Press Anykey to go main menu" BRUH read -p "Press Anykey to go main menu" BRUH
banner && display_welcome && display_user_info && main_menu display_banner && display_name && display_userinfo
main_menu
} }
################################################################################################ ################################################################################################
contacts_menu(){ contacts_menu(){
@ -477,91 +512,89 @@ contacts_menu(){
printf 'Please Input: ' printf 'Please Input: '
read -r CONTACTS read -r CONTACTS
if [ "$CONTACTS" = "1" ] if [ "$CONTACTS" = "1" ] || ["$CONTACTS" = "transfer" ]
then then
banner display_banner && display_name && display_userinfo
transfer_menu transfer_menu
elif [ "$CONTACTS" = "2" ] elif [ "$CONTACTS" = "2" ] || ["$CONTACTS" = "add new contact" ]
then then
banner display_banner && display_name && display_userinfo
add_contact add_contact
contacts_menu contacts_menu
elif [ "$CONTACTS" = "3" ] elif [ "$CONTACTS" = "3" ] || ["$CONTACTS" = "delete contact" ]
then then
banner display_banner && display_name && display_userinfo
list_contacts list_contacts
delete_contact delete_contact
api_contacts api_contacts
contact_menu contact_menu
elif [ "$CONTACTS" = "x" ] || [ "$CONTACTS" = "back" ] elif [ "$CONTACTS" = "x" ] || [ "$CONTACTS" = "back" ]
then then
sleep 0.2 display_banner && display_name && display_userinfo
banner
main_menu main_menu
elif [ "$CONTACTS" = "exit" ] elif [ "$CONTACTS" = "exit" ]
then then
echo "Cleaning up.." cexit
rm $COOKIE
sleep 0.2
exit
else else
display_banner && display_name && display_userinfo
echo ${red}Invalid input:${yellow} $CONTACTS ${reset} 1>&2 echo ${red}Invalid input:${yellow} $CONTACTS ${reset} 1>&2
source contactsmenu.sh contacts_menu
fi fi
} }
transfer_menu(){ transfer_menu(){
echo "Work In Progress" echo "Work In Progress"
read -p "Press Anykey to go main menu" BRUH read -p "Press Anykey to go main menu" BRUH
banner && display_user_info && main_menu display_banner && display_name && display_userinfo
main_menu
} }
################################################################################################ ################################################################################################
settings(){ settings(){
echo "Settings" echo "Settings"
echo ""
echo "1 - bml-cli Settings" echo "1 - bml-cli Settings"
echo "2 - BML Account Settings" echo "2 - BML Account Settings"
echo "3 - Go Back" echo "x - Go Back"
echo "" echo ""
printf 'Please Input: ' printf 'Please Input: '
read -r SETTINGS read -r SETTINGS
if [ "$SETTINGS" = "1" ] if [ "$SETTINGS" = "1" ]
then then
banner && bml-cli_settings display_banner && display_name && display_userinfo
bml-cli_settings
elif [ "$SETTINGS" = "2" ] elif [ "$SETTINGS" = "2" ]
then then
source changepassword.sh source changepassword.sh
elif [ "$SETTINGS" = "x" ] || [ "$SETTINGS" = "back" ] elif [ "$SETTINGS" = "x" ] || [ "$SETTINGS" = "back" ]
then then
banner && main_menu display_banner && display_name && display_userinfo
main_menu
else else
banner display_banner && display_name && display_userinfo
display_user_info
echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2 echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2
settings settings
fi fi
} }
bml-cli_settings(){ bml-cli_settings(){
echo "bml-cli Settings" echo "bml-cli Settings"
echo ""
echo "1 - Logout" echo "1 - Logout"
echo "2 - Logout and reset configration" echo "2 - Logout and reset configration"
echo "3 - Back" echo "x - Back"
echo "" echo ""
printf 'Please Input: ' printf 'Please Input: '
read -r BML_CLI_SETTINGS read -r BML_CLI_SETTINGS
if [ "$BML_CLI_SETTINGS" = "1" ] if [ "$BML_CLI_SETTINGS" = "1" ]
then then
logout logout
echo "Exit.." cexit
exit
elif [ "$BML_CLI_SETTINGS" = "2" ] elif [ "$BML_CLI_SETTINGS" = "2" ]
then then
reset_config && exit reset_config
elif [ "$BML_CLI_SETTINGS" = "3" ] cexit
elif [ "$BML_CLI_SETTINGS" = "x" ] || [ "$BML_CLI_SETTINGS" = "back" ]
then then
banner && settings display_banner && display_name && display_userinfo
settings
fi fi
} }
if [ ! -f $CONFIG ] if [ ! -f $CONFIG ]
@ -577,10 +610,10 @@ init_login(){
enter_credentials enter_credentials
fi fi
} }
banner && check_connection & animate "Checking Internet Connection" display_banner && check_connection #& animate "Checking Internet Connection"
banner && os_detect & animate "Detecting Operating System" display_banner && os_detect # & animate "Detecting Operating System"
source $CONFIG source $CONFIG
source $CREDENTIALS source $CREDENTIALS
banner && init_login display_banner && init_login
userinfo userinfo
banner && display_welcome && display_user_info && main_menu display_banner && display_welcome && display_userinfo && main_menu