From 9a6e24450a510b5d7a00b8b09517f961196de6e7 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Mon, 17 May 2021 00:31:44 +0500 Subject: [PATCH 01/11] rewrite --- accounts.sh | 11 ------ addcontact-bml.sh | 47 ------------------------ addcontact-menu.sh | 40 --------------------- bml.sh | 33 ----------------- changepassword.sh | 90 ---------------------------------------------- contactsmenu.sh | 39 -------------------- deletecontact.sh | 17 --------- installer.sh | 10 ------ listcontacts.sh | 3 -- login.sh | 43 ---------------------- logout.sh | 5 --- mainmenu.sh | 57 ----------------------------- osdetect.sh | 26 -------------- readpass.sh | 32 ----------------- savepass.sh | 37 ------------------- settings-menu.sh | 34 ------------------ welcome.sh | 41 --------------------- 17 files changed, 565 deletions(-) delete mode 100644 accounts.sh delete mode 100644 addcontact-bml.sh delete mode 100644 addcontact-menu.sh delete mode 100755 bml.sh delete mode 100644 changepassword.sh delete mode 100644 contactsmenu.sh delete mode 100644 deletecontact.sh delete mode 100644 installer.sh delete mode 100644 listcontacts.sh delete mode 100644 login.sh delete mode 100644 logout.sh delete mode 100644 mainmenu.sh delete mode 100644 osdetect.sh delete mode 100644 readpass.sh delete mode 100644 savepass.sh delete mode 100644 settings-menu.sh delete mode 100644 welcome.sh diff --git a/accounts.sh b/accounts.sh deleted file mode 100644 index a924ca6..0000000 --- a/accounts.sh +++ /dev/null @@ -1,11 +0,0 @@ -curl -s -b $COOKIE $BML_URL/dashboard \ - | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' - -# | jq -r '["Account Number","Currency","Balance"], (.["payload"] | .["dashboard"] | .[0] | [.account | .currency | .availableBalance]) | @csv' -# ["==================================================================="], \ -# (.["payload"] | .["dashboard"] | .["customer"] | .[0] | [.account | .currency | .availableBalance]) | @csv' - - -# | jq -r payload.dashboard[0].availableBalance -# | jq -r '(.["payload"] | .["dashboard"] | .["0"] | [.account | .currency | .availableBalance]) | @tsv' -source mainmenu.sh diff --git a/addcontact-bml.sh b/addcontact-bml.sh deleted file mode 100644 index 7acc357..0000000 --- a/addcontact-bml.sh +++ /dev/null @@ -1,47 +0,0 @@ - - -printf 'Account Number: ' -read -r ACCOUNT_NUMBER -VALID_NUMBER=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ - | jq -r .success) - -if [ "$VALID_NUMBER" = "true" ] -then - - ACCOUNT_NAME=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ - | jq -r '.["payload"] | .name') - CURRENCY=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER \ - | jq -r '.["payload"] | .currency') - echo "Account Name: $ACCOUNT_NAME" - echo "Currency: $CURRENCY" - echo "" - printf 'Contact Name: ' - read -r CONTACT_NAME - if [ "$CONTACT_NAME" = "" ] - then - CONTACT_NAME=$ACCOUNT_NAME - else - : - fi - CONTACT_NAME=`echo "$CONTACT_NAME" | sed "s/ /%20/"` - ADDCONTACT=$(curl -s -b $COOKIE $BML_URL/contacts \ - --data-raw contact_type=IAT \ - --data-raw account=$ACCOUNT_NUMBER \ - --data-raw alias=$CONTACT_NAME \ - --compressed \ - | jq -r .success) - - if [ "$ADDCONTACT" = "true" ] - then - echo "Contact added successfully" - else - echo "${red}There was an error${reset}" - source contactsmenu.sh - fi -else - echo "${red}Invalid Account${reset}" 1>&2 - source contactsmenu.sh -fi - -source contactsmenu.sh - diff --git a/addcontact-menu.sh b/addcontact-menu.sh deleted file mode 100644 index 03540d4..0000000 --- a/addcontact-menu.sh +++ /dev/null @@ -1,40 +0,0 @@ -echo "" -echo "Add Contact" -echo "" -echo "1 - BML" -echo "2 - Domestic" -echo "3 - International" -echo "4 - BillPay" -echo "5 - Go back" -echo "6 - Exit" -echo "" -printf 'Select contact type[1]: ' -read -r CONTACT_TYPE - -if [ "$CONTACT_TYPE" = "1" ] || [ "$CONTACT_TYPE" = "" ] - then - source addcontact-bml.sh -elif [ "$CONTATC_TYPE" = "2" ] - then - echo "${red}WORK IN PROGRESS${reset}" - source addcontact-menu.sh -elif [ "$CONTATC_TYPE" = "3" ] - then - echo "${red}WORK IN PROGRESS${reset}" - source addcontact-manu.sh -elif [ "$CONTATC_TYPE" = "4" ] - then - echo "${red}WORK IN PROGRESS${reset}" - source addcontact-manu.sh -elif [ "$CONTATC_TYPE" = "5" ] - then - source contactsmenu.sh -elif [ "$CONTATC_TYPE" = "6" ] - then - rm $COOKIE - exit -else - clear - echo "${red}There was an error${reset}" 1>&2 - source contactsmenu.sh -fi diff --git a/bml.sh b/bml.sh deleted file mode 100755 index 94b77b4..0000000 --- a/bml.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -#Making cookie and credentials dir -mkdir -p ~/.config/bml-cli/ -mkdir -p ~/.cache/bml-cli/ - -#Setting intial variables -BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' -BML_RESETPASS='https://www.bankofmaldives.com.mv/internetbanking/forgot_password' -COOKIE=~/.cache/bml-cli/cookie -CREDENTIALS=~/.config/bml-cli/.env - -cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 - -#Setting terminal output colors -red=`tput setaf 1` -#errorred=`tput setaf 196` -#validgreen=`tput setaf 82` -green=`tput setaf 46` -brown=`tput setaf 3` -blue=`tput setaf 4` -pink=`tput setaf 5` -cyan=`tput setaf 39` -gray=`tput setaf 7` -darkgray=`tput setaf 8` -lightred=`tput setaf 9` -lightgreen=`tput setaf 10` -yellow=`tput setaf 11` -reset=`tput sgr0` - -source osdetect.sh - -source readpass.sh diff --git a/changepassword.sh b/changepassword.sh deleted file mode 100644 index a1df7ee..0000000 --- a/changepassword.sh +++ /dev/null @@ -1,90 +0,0 @@ -read -s -p 'Enter Current Password: ' OLD_PASSWORD -echo "" -echo "" - -while true; do -read -s -p 'Enter New Password: ' NEW_PASSWORD -echo "" -read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD -echo "" -if [ "$NEW_PASSWORD" = "$REPEAT_NEWPASSWORD" ] -then - sleep 0.2 - echo "" - break -else - echo "${red}Password do not match${reset}" - echo "Try again" - echo "" -fi -done - -while true; do -echo "Select OTP Method:" -echo "1 - Mobile" -echo "2 - Email" -echo "" -read -p "Please input: " OTPCHANNEL - -if [ "$OTPCHANNEL" = "1" ] || [ "$OTPCHANNEL" = "mobile" ] - then - OTPCHANNEL=mobile - break -elif [ "$OTPCHANNEL" = "2" ] || [ "$OTPCHANNEL" = "email" ] - then - OTPCHANNEL=email - break -else - echo "${red}Invalid Input${reset}" - echo "" -fi -done - -OLDPASSCHECHECK=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ - --data-raw currentPassword=$OLD_PASSWORD \ - --data-raw newPassword=$NEW_PASSWORD \ - --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ - --data-raw channel=$OTPCHANNEL \ - --compressed \ - | jq -r .success) - -if [ "$OLDPASSCHECHECK" != "true" ] - then - source changepassword.sh -else - : -fi - -if [ "$OTPCHANNEL" = "mobile" ] - then - ECHOOTPCHANNEL=$PHONE -elif [ "$OTPCHANNEL" = "email" ] - then - ECHOOTPCHANNEL=$EMAIL -fi - -echo "" -echo "${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset}" -read -p 'Enter OTP: ' OTP -echo "" -PASSCHANGED=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ - --data-raw currentPassword=$OLD_PASSWORD \ - --data-raw newPassword=$NEW_PASSWORD \ - --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ - --data-raw channel=$OTPCHANNEL \ - --data-raw otp=$OTP \ - --compressed \ - | jq -r .success) - -OLD_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) -NEW_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) -REPEAT_NEWPASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) - -if [ "$PASSCHANGED" != "true" ] - then - echo "${red}Failed to change password${reset}" -else - echo "${lightgreen}Password changed succesfully ${reset}" - rm $CREDENTIALS - source readpass.sh -fi diff --git a/contactsmenu.sh b/contactsmenu.sh deleted file mode 100644 index ed81d5d..0000000 --- a/contactsmenu.sh +++ /dev/null @@ -1,39 +0,0 @@ -echo "" -echo "Contacts" -echo "" -echo "1 - List Contacts" -echo "2 - Add Contact" -echo "3 - Delete Contact" -echo "4 - Go back" -echo "" -printf 'Please Input: ' -read -r CONTACTS - -if [ "$CONTACTS" = "1" ] -then - source listcontacts.sh -elif [ "$CONTACTS" = "2" ] -then - source addcontact-menu.sh -elif [ "$CONTACTS" = "3" ] -then - source deletecontact.sh -elif [ "$CONTACTS" = "4" ] || [ "$CONTACTS" = "back" ] -then - sleep 0.2 - source mainmenu.sh -elif [ "$CONTACTS" = "clear" ] -then - sleep 0.2 - clear - source contactsmenu.sh -elif [ "$CONTACTS" = "exit" ] -then - echo "Cleaning up.." - rm $COOKIE - sleep 0.2 - exit -else - echo ${red}Invalid input:${yellow} $CONTACTS ${reset} 1>&2 - source contactsmenu.sh -fi diff --git a/deletecontact.sh b/deletecontact.sh deleted file mode 100644 index e756199..0000000 --- a/deletecontact.sh +++ /dev/null @@ -1,17 +0,0 @@ - - -printf "Enter Contact ID: " -read -r CONATACT_ID -DELETESUCCESS=$(curl -s -b $COOKIE $BML_URL/contacts/$CONATACT_ID \ - --data-raw _method=delete \ - --compressed \ - | jq -r .code) - -if [ "$DELETESUCCESS" = "0" ] -then - echo Contact Deleted - source contactsmenu.sh -else - echo "${red}There was an error${reset}" - source contactsmenu.sh -fi diff --git a/installer.sh b/installer.sh deleted file mode 100644 index 998e1ca..0000000 --- a/installer.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -cd /tmp/ -git clone https://github.com/shihaamabr/bml-cli.git -mkdir -p /opt/sar/bml-cli/ -mv bml-cli/* /opt/sar/bml-cli/ -echo "#!/bin/bash" > /usr/bin/bml-cli -echo "source /opt/sar/bml-cli/bml.sh" >> /usr/bin/bml-cli -chmod 755 /usr/bin/bml-cli -rm -rf bml-cli/ -echo "Installation Complete" diff --git a/listcontacts.sh b/listcontacts.sh deleted file mode 100644 index ec58136..0000000 --- a/listcontacts.sh +++ /dev/null @@ -1,3 +0,0 @@ -curl -s -b $COOKIE $BML_URL/contacts \ -| jq -r '["ID","Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.id, .account, .currency, .name, .alias]) | @tsv' -source contactsmenu.sh diff --git a/login.sh b/login.sh deleted file mode 100644 index 19b1f0a..0000000 --- a/login.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -#login and generate cookie - -LOGIN=$(curl -s -c $COOKIE $BML_URL/login \ - --data-raw username=$BML_USERNAME \ - --data-raw password=${BML_PASSWORD} \ - --compressed \ - | jq -r .code) -#check if login was success -if [ "$LOGIN" = "0" ] - then - source savepass.sh -elif [ "$LOGIN" = "20" ] - then - echo "${red}Account Locked!${reset}" - echo "${lightred}Please reset password and login again.${reset}" - echo "" - if [ "$OS" = "macos" ] - then - open $BML_RESETPASS - elif [ "$OS" = "windows" ] - then - cmd.exe /C START $BML_RESETPASS - elif [ "$OS" = "android" ] - then - am start -a android.intent.action.VIEW -d $BML_RESETPASS - else - xdg-open $BML_RESETPASS - fi - source readpass.sh -elif [ "$LOGIN" = "2" ] - then - source readpass.sh -elif [ "$LOGIN" = "37" ] - then - echo "${red}Down for Maintenance${reset}" 1>&2 - echo "Try again later" - exit -else - echo "${red}Unknown Error${reset}" 1>&2 - exit -fi - diff --git a/logout.sh b/logout.sh deleted file mode 100644 index f35bba6..0000000 --- a/logout.sh +++ /dev/null @@ -1,5 +0,0 @@ -rm $CREDENTIALS -rm $COOKIE -echo "Cleaning up.." -sleep 0.4 -exit diff --git a/mainmenu.sh b/mainmenu.sh deleted file mode 100644 index fd630b4..0000000 --- a/mainmenu.sh +++ /dev/null @@ -1,57 +0,0 @@ -echo "Main Menu" -echo "" -echo "1 - Accounts" -echo "2 - Transfer" -echo "3 - Contacts" -echo "4 - Activities" -echo "5 - Services" -echo "6 - Settings" -echo "" -printf 'Please Input: ' -read -r MENU - -if [ "$MENU" = "1" ] - then - echo "WIP" - sleep 2 - #source mainmenu.sh - source accounts.sh -elif [ "$MENU" = "2" ] - then - echo "WIP" - sleep 2 - source mainmenu.sh - #source transfer.sh -elif [ "$MENU" = "3" ] - then - source contactsmenu.sh -elif [ "$MENU" = "4" ] - then - echo "WIP" - sleep 2 - source mainmenu.sh - source activities.sh -elif [ "$MENU" = "5" ] - then - echo "WIP" - sleep 2 - source mainmenu.sh - source services.sh -elif [ "$MENU" = "6" ] - then - source settings-menu.sh -elif [ "$MENU" = "clear" ] - then - clear - sleep 0.2 - source mainmenu.sh -elif [ "$MENU" = "exit" ] - then - echo "cleaning up..." - rm $COOKIE - sleep 0.2 - exit -else - echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2 - source mainmenu.sh -fi diff --git a/osdetect.sh b/osdetect.sh deleted file mode 100644 index 592ebb6..0000000 --- a/osdetect.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -WSL1=$(uname -r | grep -oE Microsoft) -WSL2=$(uname -r | grep -oE microsoft) -MAC=$(uname -a | grep -oE Darwin | tail -n1) -ANDROID=$(uname -a | grep -oE Android) - -if [ "$WSL1" = "Microsoft" ] || [ "$WSL2" = "microsoft" ] - then - OS=windows - #echo ${red}WSL Not Supported!${reset} 1>&2 - #exit -elif [ "$MAC" = "Darwin" ] - then - OS=macos - export PATH="/usr/local/opt/openssl@1.1/bin:$PATH" - #echo ${red}MacOS Not Supported!${reset} 1>&2 - #exit -elif [ "$ANDROID" = "Android" ] - then - OS=android -else - : -fi - -source readpass.sh - diff --git a/readpass.sh b/readpass.sh deleted file mode 100644 index dbe0e49..0000000 --- a/readpass.sh +++ /dev/null @@ -1,32 +0,0 @@ -if [ -f $CREDENTIALS ] -then - source $CREDENTIALS -# echo "Attempting to login with saved credentials" - read -s -p 'Enter Pin: ' PIN - echo "" - BML_USERNAME=$(echo ${BML_USERNAME} |openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2) - BML_PASSWORD=$(echo ${BML_PASSWORD} |openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2) - if [ "$LOGIN" = "2" ] - then - echo "${red}Login Required${reset}" - rm $CREDENTIALS 2> /dev/null - read -p 'Username: ' BML_USERNAME - read -s -p 'Password: ' BML_PASSWORD - echo "" - else - : - fi - - - -elif [ ! -f $CREDENTIALS ] -then - echo "${red}Login Required${reset}" - read -p 'Username: ' BML_USERNAME - read -s -p 'Password: ' BML_PASSWORD - echo "" -else - : -fi - -source login.sh diff --git a/savepass.sh b/savepass.sh deleted file mode 100644 index 5eb6d49..0000000 --- a/savepass.sh +++ /dev/null @@ -1,37 +0,0 @@ -if [ ! -f $CREDENTIALS ] -then - if [ "$LOGIN" = "0" ] - then - read -p 'Do you want to save login? [y/N] ' SAVE_LOGIN - if [ "$SAVE_LOGIN" = "Y" ] || [ "$SAVE_LOGIN" = "y" ] - then - read -s -p 'Enter Pin: ' PIN - echo "" - read -s -p 'Repeat Pin: ' REPEAT_PIN - if [ "$PIN" = "$REPEAT_PIN" ] - then - echo "" - echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" - BML_USERNAME=$(echo "${BML_USERNAME}" | openssl enc -e -des3 -base64 -pass pass:${PIN} -pbkdf2) - BML_PASSWORD=$(echo "${BML_PASSWORD}" | openssl enc -e -des3 -base64 -pass pass:${PIN} -pbkdf2) - echo "BML_USERNAME='${BML_USERNAME}'" > $CREDENTIALS - echo "BML_PASSWORD='${BML_PASSWORD}'" >> $CREDENTIALS - - else - echo "" - echo "${red}Pin do not match${reset}" - source savepass.sh - fi - else - : - fi - else - source readpass.sh - fi -else - : -fi - -BML_USERNAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) -BML_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) -source welcome.sh diff --git a/settings-menu.sh b/settings-menu.sh deleted file mode 100644 index 0b7d995..0000000 --- a/settings-menu.sh +++ /dev/null @@ -1,34 +0,0 @@ -echo "" -echo "Settings" -echo "" -echo "1 - Logout and Delete saved credentials" -echo "2 - Change Password" -echo "3 - Go Back" -echo "" -printf 'Please Input: ' -read -r SETTINGS - -if [ "$SETTINGS" = "1" ] -then - source logout.sh -elif [ "$SETTINGS" = "2" ] -then - source changepassword.sh -elif [ "$SETTINGS" = "3" ] || [ "$SETTINGS" = "back" ] -then - source mainmenu.sh -elif [ "$SETTINGS" = "clear" ] -then - sleep 0.2 - clear - source settings-menu.sh -elif [ "$SETTINGS" = "exit" ] -then - echo "Cleaning up.." - rm $COOKIE - sleep 0.2 - exit -else - echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2 - source settings-menu.sh -fi diff --git a/welcome.sh b/welcome.sh deleted file mode 100644 index 71b84d8..0000000 --- a/welcome.sh +++ /dev/null @@ -1,41 +0,0 @@ -#Requesting for User profile after login and regex to grap the Full name -REQPRO=$(curl -s -b $COOKIE $BML_URL/profile) -PERSONALPROFILE=$(echo $REQPRO \ - | jq -r '.payload | .profile | .[] | .profile' \ - | head -n 1) -curl -s -b $COOKIE $BML_URL/profile \ - --data-raw profile=$PERSONALPROFILE \ - --compressed > /dev/null - -USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo \ - | jq -r '.["payload"] | .["user"]') - -NAME=$(echo $USERINFO \ - | jq -r .fullname) -PHONE=$(echo $USERINFO \ - | jq -r .mobile_phone) -EMAIL=$(echo $USERINFO \ - | jq -r .email) -DOB=$(echo $USERINFO \ - | jq -r .birthdate \ - | cut -d 'T' -f 1) -IDCARD=$(echo $USERINFO \ - | jq -r .idcard) - -#display a Welcome message with fullname -echo "${red}" -echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" -echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" -echo "██████╦╝██╔████╔██║██║░░░░░  ██║░░╚═╝██║░░░░░██║" -echo "██╔══██╗██║╚██╔╝██║██║░░░░░  ██║░░██╗██║░░░░░██║" -echo "██████╦╝██║░╚═╝░██║███████╗  ╚█████╔╝███████╗██║" -echo "╚═════╝░╚═╝░░░░░╚═╝╚══════╝  ░╚════╝░╚══════╝╚═╝" -echo "${reset}" -echo ${green}Welcome ${reset}$NAME -echo "" -echo ${cyan}Phone${reset}: $PHONE -echo ${cyan}Email${reset}: $EMAIL -echo ${cyan}Birthday${reset}: $DOB -echo ${cyan}ID Card${reset}: $IDCARD -echo "" -source mainmenu.sh From 7091ad43cc80cfcf87c98f53834754f85895afbf Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Mon, 17 May 2021 06:37:29 +0500 Subject: [PATCH 02/11] pain --- bml-cli.sh | 397 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 397 insertions(+) create mode 100644 bml-cli.sh diff --git a/bml-cli.sh b/bml-cli.sh new file mode 100644 index 0000000..ca4acf3 --- /dev/null +++ b/bml-cli.sh @@ -0,0 +1,397 @@ +#!/bin/sh + +cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 +CONFIG=~/.config/bml-cli/config +CREDENTIALS=~/.config/bml-cli/.credentials +COOKIE=~/.cache/bml-cli/.cookie +BML_RESETPASS='https://www.bankofmaldives.com.mv/internetbanking/forgot_password' + +#Setting terminal output colors +red=`tput setaf 1` +#errorred=`tput setaf 196` +#validgreen=`tput setaf 82` +green=`tput setaf 46` +brown=`tput setaf 3` +blue=`tput setaf 4` +pink=`tput setaf 5` +cyan=`tput setaf 39` +gray=`tput setaf 7` +darkgray=`tput setaf 8` +lightred=`tput setaf 9` +lightgreen=`tput setaf 10` +yellow=`tput setaf 11` +reset=`tput sgr0` +# Colors +G='\e[01;32m' # GREEN TEXT +R='\e[01;31m' # RED TEXT +Y='\e[01;33m' # YELLOW TEXT +B='\e[01;34m' # BLUE TEXT +V='\e[01;35m' # VIOLET TEXT +Bl='\e[01;30m' # BLACK TEXT +C='\e[01;36m' # CYAN TEXT +W='\e[01;37m' # WHITE TEXT +BGBL='\e[1;30;47m' # Background W Text Bl +N='\e[0m' # How to use (example): echo "${G}example${N}" +loadBar=' ' # Load UI + +##Setting Up Funcations +initanimate(){ + PID=$! + h=0 + anim='⠋⠙⠴⠦' + while [ -d /proc/$PID ]; do + h=$(((h + 1) % 4)) + sleep 0.05 + printf "\r${@} [${anim:$h:1}]" + done + initbanner +} +animate(){ + PID=$! + h=0 + anim='⠋⠙⠴⠦' + while [ -d /proc/$PID ]; do + h=$(((h + 1) % 4)) + sleep 0.05 + printf "\r${@} [${anim:$h:1}]" + done + banner +} +initialize(){ + mkdir -p ~/.config/bml-cli/ + mkdir -p ~/.cache/bml-cli/ + echo "# DO NOT EDIT THIS MANUALLY!!" > $CREDENTIALS + echo "BML_USERNAME='' # Your encrypted BML Username" >> $CREDENTIALS + echo "BML_PASSWORD='' # Your encrypted BML Password" >> $CREDENTIALS + echo "# DO NOT EDIT THIS UNLESS NECESSARY!!" > $CONFIG + echo "I_AM_HYPOCRITE='false' # This is for MacOS Users ONLY" >> $CONFIG + echo "I_AM_SODU='false' # This is for WSL Users ONLY" >> $CONFIG + echo "" >> $CONFIG + echo "BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' # BML API URL " >> $CONFIG +} + +check_connection(){ + PING=$(ping www.bankofmaldives.com.mv -c 2 2> /dev/null | grep -oE 0%) + if [ "$PING" != "0%" ] ; then + echo ${red}Check your connection and try again.${reset} + exit + fi +} + +os_detect(){ + WSL1=$(uname -r | grep -oE Microsoft) + WSL2=$(uname -r | grep -oE microsoft) + MAC=$(uname -a | grep -oE Darwin | tail -n1) + ANDROID=$(uname -a | grep -oE Android) + if [ "$WSL1" = "Microsoft" ] || [ "$WSL2" = "microsoft" ] + then + OS=windows + if [ "$I_AM_SODU" != "true" ] + then + echo ${red}Please check $CONFIG and configure accordingly.${reset} + exit + fi + elif [ "$MAC" = "Darwin" ] + then + OS=macos + export PATH="/usr/local/opt/openssl@1.1/bin:$PATH" + if [ "$I_AM_HYPOCRITE" != "true" ] + then + echo ${red}Please check $CONFIG and configure accordingly.${reset} + exit + fi + elif [ "$ANDROID" = "Android" ] + then + OS=android + fi +} + +initbanner(){ +# clear + echo "${red}" + echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" + echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" + echo "██████╦╝██╔████╔██║██║░░░░░  ██║░░╚═╝██║░░░░░██║" + echo "██╔══██╗██║╚██╔╝██║██║░░░░░  ██║░░██╗██║░░░░░██║" + echo "██████╦╝██║░╚═╝░██║███████╗  ╚█████╔╝███████╗██║" + echo "╚═════╝░╚═╝░░░░░╚═╝╚══════╝  ░╚════╝░╚══════╝╚═╝" + echo "${reset}" +} + +banner(){ +# clear + echo "${red}" + echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" + echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" + echo "██████╦╝██╔████╔██║██║░░░░░  ██║░░╚═╝██║░░░░░██║" + echo "██╔══██╗██║╚██╔╝██║██║░░░░░  ██║░░██╗██║░░░░░██║" + echo "██████╦╝██║░╚═╝░██║███████╗  ╚█████╔╝███████╗██║" + echo "╚═════╝░╚═╝░░░░░╚═╝╚══════╝  ░╚════╝░╚══════╝╚═╝" + echo "${reset}" + echo ${green}Welcome ${reset}$NAME + echo "" + echo ${cyan}Phone${reset}: $PHONE + echo ${cyan}Email${reset}: $EMAIL + echo ${cyan}Birthday${reset}: $DOB + echo ${cyan}ID Card${reset}: $IDCARD + echo "" +} + +readpin(){ + read -s -p 'Enter Pin: ' PIN + echo "" + 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) + login +} +wipe_credentials(){ + sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='' # Your encrypted BML Username @" $CREDENTIALS + sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='' # Your encrypted BML Password @" $CREDENTIALS +} +urandom(){ + BML_USERNAME_UNSAFE=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + BML_PASSWORD_UNSAFE=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + BML_USERNAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + BML_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + REPEAT_PIN=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + PIN=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) +} +savepass(){ + if [ "$BML_USERNAME" = "" ] && [ "$BML_PASSWORD" = "" ] + then + read -p 'Do you want to save login? [y/N] ' SAVE_LOGIN + if [ "$SAVE_LOGIN" = "Y" ] || [ "$SAVE_LOGIN" = "y" ] + then + read -s -p 'Enter New Pin: ' NEW_PIN + echo "" + read -s -p 'Repeat Pin: ' REPEAT_PIN + if [ "$NEW_PIN" = "$REPEAT_PIN" ] + then + echo "" + BML_USERNAME=$(echo "${BML_USERNAME_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) + BML_PASSWORD=$(echo "${BML_PASSWORD_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) + echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" + sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='${BML_USERNAME}' # Your encrypted BML Username @" $CREDENTIALS + sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='${BML_PASSWORD}' # Your encrypted BML Password @" $CREDENTIALS + else + echo "" + echo ${R}Pin do not match${N} + savepass + fi + else + echo Password not saved. + fi + else + : + fi + echo ok + #urandom & animate "${G}Randomzing Credentials${N}" && select_profile +} +login(){ + LOGIN=$(curl -s -c $COOKIE $BML_URL/login \ + --data-raw username=$BML_USERNAME_UNSAFE \ + --data-raw password=${BML_PASSWORD_UNSAFE} \ + | jq -r .code) + if [ "$LOGIN" = "0" ] + then + echo Login success + savepass + elif [ "$LOGIN" = "20" ] + then + account_locked + elif [ "$LOGIN" = "2" ] + then + echo Password or Username Incorrect + wipe_credentials + enter_credentials + elif [ "$LOGIN" = "37" ] + then + echo "${red}Down for Maintenance${reset}" 1>&2 + echo "Try again later" + exit + else + echo "${red}Unknown Error${reset}" 1>&2 + exit + fi +} +account_locked(){ + echo "${red}Account Locked!${reset}" + echo "${lightred}Please reset password and login again.${reset}" + echo "" + if [ "$OS" = "macos" ] + then + open $BML_RESETPASS + elif [ "$OS" = "windows" ] + then + cmd.exe /C START $BML_RESETPASS + elif [ "$OS" = "android" ] + then + am start -a android.intent.action.VIEW -d $BML_RESETPASS + else + xdg-open $BML_RESETPASS + fi + enter_credentials +} + +enter_credentials(){ + #echo "" + read -p 'Username: ' BML_USERNAME_UNSAFE + read -s -p 'Password: ' BML_PASSWORD_UNSAFE + echo "" + login +} + +select_profile(){ +REQPRO=$(curl -s -b $COOKIE $BML_URL/profile) +PERSONALPROFILE=$(echo $REQPRO \ + | jq -r '.payload | .profile | .[] | .profile' \ + | head -n 1) +curl -s -b $COOKIE $BML_URL/profile \ + --data-raw profile=$PERSONALPROFILE \ + --compressed > /dev/null +} + +userinfo(){ +USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo | jq -r '.["payload"] | .["user"]') +NAME=$(echo $USERINFO | jq -r .fullname) +PHONE=$(echo $USERINFO | jq -r .mobile_phone) +EMAIL=$(echo $USERINFO | jq -r .email) +DOB=$(echo $USERINFO | jq -r .birthdate |cut -d 'T' -f 1) +IDCARD=$(echo $USERINFO | jq -r .idcard) +} +main_menu(){ +echo "Main Menu" +echo "" +echo "1 - Accounts" +echo "2 - Transfer" +echo "3 - Contacts" +echo "4 - Activities" +echo "5 - Services" +echo "6 - Settings" +echo "" +printf 'Please Input: ' +read -r MENU + +if [ "$MENU" = "1" ] + then + echo "WIP" + sleep 2 + #source mainmenu.sh + source accounts.sh +elif [ "$MENU" = "2" ] + then + echo "WIP" + sleep 2 + source mainmenu.sh + #source transfer.sh +elif [ "$MENU" = "3" ] + then + source contactsmenu.sh +elif [ "$MENU" = "4" ] + then + echo "WIP" + sleep 2 + source mainmenu.sh + source activities.sh +elif [ "$MENU" = "5" ] + then + echo "WIP" + sleep 2 + source mainmenu.sh + source services.sh +elif [ "$MENU" = "6" ] + then + banner && settings +elif [ "$MENU" = "clear" ] + then + clear + sleep 0.2 + source mainmenu.sh +elif [ "$MENU" = "exit" ] + then + echo "cleaning up..." + rm $COOKIE + sleep 0.2 + exit +else + echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2 + source mainmenu.sh +fi +} + +settings(){ + echo "" + echo "Settings" + echo "" + echo "1 - bml-cli Settings" + echo "2 - BML Account Settings" + echo "3 - Go Back" + echo "" + printf 'Please Input: ' + read -r SETTINGS + + if [ "$SETTINGS" = "1" ] + then + logout + elif [ "$SETTINGS" = "2" ] + then + source changepassword.sh + elif [ "$SETTINGS" = "3" ] || [ "$SETTINGS" = "back" ] + then + source mainmenu.sh + elif [ "$SETTINGS" = "clear" ] + then + sleep 0.2 + clear + source settings-menu.sh + elif [ "$SETTINGS" = "exit" ] + then + echo "Cleaning up.." + rm $COOKIE + sleep 0.2 + exit + else + echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2 + source settings-menu.sh + fi +} +bml-cli_settings(){ + echo "" + echo "bml-cli Settings" + echo "" + echo "1 - Logout" + echo "2 - Logout and reset configration" + echo "3 - Exit" + echo "" + printf 'Please Input: ' + read -r BML-CLI_SETTINGS + if [ "$BML-CLI_SETTINGS" = "1" ] + then + logout + echo "Exit.." + exit + elif [ "$BML-CLI_SETTINGS" = "2" ] + then + reset_config && exit + elif [ "$BML-CLI_SETTINGS" = "3" ] + then + exit + fi +} +if [ ! -f $CONFIG ] +then + initialize +fi + +check_connection #& initanimate "Checking Internet Connection" +os_detect # & initanimate "Detecting Operating System" +source $CONFIG +source $CREDENTIALS +if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] +then + readpin +else + enter_credentials +fi +#userinfo +#banner && main_menu From 3a27ebd51eab622e1de8d93f054fa9240c0db026 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Mon, 17 May 2021 07:11:13 +0500 Subject: [PATCH 03/11] can login --- bml-cli.sh | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) mode change 100644 => 100755 bml-cli.sh diff --git a/bml-cli.sh b/bml-cli.sh old mode 100644 new mode 100755 index ca4acf3..3aad361 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 CONFIG=~/.config/bml-cli/config @@ -44,7 +44,7 @@ initanimate(){ sleep 0.05 printf "\r${@} [${anim:$h:1}]" done - initbanner + #initbanner } animate(){ PID=$! @@ -107,7 +107,7 @@ os_detect(){ } initbanner(){ -# clear + clear echo "${red}" echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" @@ -119,7 +119,7 @@ initbanner(){ } banner(){ -# clear + clear echo "${red}" echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" @@ -140,10 +140,13 @@ banner(){ readpin(){ read -s -p 'Enter Pin: ' PIN echo "" +#} +#decrypt_pin(){ 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) login } + wipe_credentials(){ sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='' # Your encrypted BML Username @" $CREDENTIALS sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='' # Your encrypted BML Password @" $CREDENTIALS @@ -167,9 +170,12 @@ savepass(){ read -s -p 'Repeat Pin: ' REPEAT_PIN if [ "$NEW_PIN" = "$REPEAT_PIN" ] then + #encrypt & initanimate "Encrypting Credentials" echo "" BML_USERNAME=$(echo "${BML_USERNAME_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) BML_PASSWORD=$(echo "${BML_PASSWORD_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) + encrypt_user & initanimate "Encrypting Username" + encrypt_pass & initanimate "Encrypting Password" echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='${BML_USERNAME}' # Your encrypted BML Username @" $CREDENTIALS sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='${BML_PASSWORD}' # Your encrypted BML Password @" $CREDENTIALS @@ -184,9 +190,17 @@ savepass(){ else : fi - echo ok - #urandom & animate "${G}Randomzing Credentials${N}" && select_profile + #echo ok + urandom & animate "${G}Randomzing Credentials${N}" && select_profile } +#encrypt(){ +# sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='${BML_USERNAME}' # Your encrypted BML Username @" $CREDENTIALS +# sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='${BML_PASSWORD}' # Your encrypted BML Password @" $CREDENTIALS +# BML_USERNAME=$(echo "${BML_USERNAME_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) +# BML_PASSWORD=$(echo "${BML_PASSWORD_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) +# echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" +# savepass +#} login(){ LOGIN=$(curl -s -c $COOKIE $BML_URL/login \ --data-raw username=$BML_USERNAME_UNSAFE \ @@ -383,8 +397,8 @@ then initialize fi -check_connection #& initanimate "Checking Internet Connection" -os_detect # & initanimate "Detecting Operating System" +check_connection & initanimate "Checking Internet Connection" +os_detect & initanimate "Detecting Operating System" source $CONFIG source $CREDENTIALS if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] @@ -393,5 +407,5 @@ then else enter_credentials fi -#userinfo -#banner && main_menu +userinfo +banner && main_menu From f42ec3049dff7c0194f0031650ed736a45f7e537 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Mon, 17 May 2021 19:31:59 +0500 Subject: [PATCH 04/11] idekanymore --- bml-cli.sh | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index 3aad361..404cbb6 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -71,11 +71,21 @@ initialize(){ } check_connection(){ + initbanner PING=$(ping www.bankofmaldives.com.mv -c 2 2> /dev/null | grep -oE 0%) - if [ "$PING" != "0%" ] ; then + if [ "$PING" != "0%" ] + then echo ${red}Check your connection and try again.${reset} exit fi + DOS=$(curl -s https://www.bankofmaldives.com.mv/ | grep -oE "error code: 1020") + if [ "$DOS" = "error code: 1020" ] + then + echo ${red}Access denied${reset} + echo Try again later + exit + fi + initbanner } os_detect(){ @@ -140,8 +150,12 @@ banner(){ readpin(){ read -s -p 'Enter Pin: ' PIN echo "" -#} -#decrypt_pin(){ + CHECK_PIN=$(echo ${BML_USERNAME} | openssl enc -d -des3 -base64 -pass pass:${PIN} -pbkdf2 2>&1 | grep -oE bad) + if [ "$CHECK_PIN" = "bad bad" ] + then + echo ${R}Incorrect Pin${N} + readpin + fi 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) login @@ -346,13 +360,13 @@ settings(){ if [ "$SETTINGS" = "1" ] then - logout + banner && bml-cli_settings elif [ "$SETTINGS" = "2" ] then source changepassword.sh elif [ "$SETTINGS" = "3" ] || [ "$SETTINGS" = "back" ] then - source mainmenu.sh + banner && main_menu elif [ "$SETTINGS" = "clear" ] then sleep 0.2 @@ -375,21 +389,21 @@ bml-cli_settings(){ echo "" echo "1 - Logout" echo "2 - Logout and reset configration" - echo "3 - Exit" + echo "3 - Back" echo "" printf 'Please Input: ' - read -r BML-CLI_SETTINGS - if [ "$BML-CLI_SETTINGS" = "1" ] + read -r BML_CLI_SETTINGS + if [ "$BML_CLI_SETTINGS" = "1" ] then logout echo "Exit.." exit - elif [ "$BML-CLI_SETTINGS" = "2" ] + elif [ "$BML_CLI_SETTINGS" = "2" ] then reset_config && exit - elif [ "$BML-CLI_SETTINGS" = "3" ] + elif [ "$BML_CLI_SETTINGS" = "3" ] then - exit + banner && settings fi } if [ ! -f $CONFIG ] @@ -397,8 +411,8 @@ then initialize fi -check_connection & initanimate "Checking Internet Connection" -os_detect & initanimate "Detecting Operating System" +check_connection & initanimate "Checking Internet Connection" +os_detect #& initanimate "Detecting Operating System" source $CONFIG source $CREDENTIALS if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] From 731a5684dfba7c6a60a170001b49bcaf295a224d Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Wed, 19 May 2021 23:11:47 +0500 Subject: [PATCH 05/11] idk --- bml-cli.sh | 274 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 201 insertions(+), 73 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index 404cbb6..fe6a8d9 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -35,17 +35,6 @@ N='\e[0m' # How to use (example): echo "${G}example${N}" loadBar=' ' # Load UI ##Setting Up Funcations -initanimate(){ - PID=$! - h=0 - anim='⠋⠙⠴⠦' - while [ -d /proc/$PID ]; do - h=$(((h + 1) % 4)) - sleep 0.05 - printf "\r${@} [${anim:$h:1}]" - done - #initbanner -} animate(){ PID=$! h=0 @@ -55,7 +44,6 @@ animate(){ sleep 0.05 printf "\r${@} [${anim:$h:1}]" done - banner } initialize(){ mkdir -p ~/.config/bml-cli/ @@ -71,7 +59,6 @@ initialize(){ } check_connection(){ - initbanner PING=$(ping www.bankofmaldives.com.mv -c 2 2> /dev/null | grep -oE 0%) if [ "$PING" != "0%" ] then @@ -85,7 +72,6 @@ check_connection(){ echo Try again later exit fi - initbanner } os_detect(){ @@ -114,20 +100,9 @@ os_detect(){ then OS=android fi + banner } - -initbanner(){ - clear - echo "${red}" - echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" - echo "██╔══██╗████╗░████║██║░░░░░  ██╔══██╗██║░░░░░██║" - echo "██████╦╝██╔████╔██║██║░░░░░  ██║░░╚═╝██║░░░░░██║" - echo "██╔══██╗██║╚██╔╝██║██║░░░░░  ██║░░██╗██║░░░░░██║" - echo "██████╦╝██║░╚═╝░██║███████╗  ╚█████╔╝███████╗██║" - echo "╚═════╝░╚═╝░░░░░╚═╝╚══════╝  ░╚════╝░╚══════╝╚═╝" - echo "${reset}" -} - +################################################################## banner(){ clear echo "${red}" @@ -138,15 +113,20 @@ banner(){ echo "██████╦╝██║░╚═╝░██║███████╗  ╚█████╔╝███████╗██║" echo "╚═════╝░╚═╝░░░░░╚═╝╚══════╝  ░╚════╝░╚══════╝╚═╝" echo "${reset}" +} +display_welcome(){ + echo "" echo ${green}Welcome ${reset}$NAME echo "" +} +display_user_info(){ echo ${cyan}Phone${reset}: $PHONE echo ${cyan}Email${reset}: $EMAIL echo ${cyan}Birthday${reset}: $DOB echo ${cyan}ID Card${reset}: $IDCARD echo "" } - +#################################################################### readpin(){ read -s -p 'Enter Pin: ' PIN echo "" @@ -156,6 +136,7 @@ readpin(){ echo ${R}Incorrect Pin${N} readpin fi + banner 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) login @@ -184,12 +165,11 @@ savepass(){ read -s -p 'Repeat Pin: ' REPEAT_PIN if [ "$NEW_PIN" = "$REPEAT_PIN" ] then - #encrypt & initanimate "Encrypting Credentials" echo "" BML_USERNAME=$(echo "${BML_USERNAME_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) BML_PASSWORD=$(echo "${BML_PASSWORD_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) - encrypt_user & initanimate "Encrypting Username" - encrypt_pass & initanimate "Encrypting Password" + #encrypt_user #& initanimate "Encrypting Username" + #encrypt_pass #& initanimate "Encrypting Password" echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='${BML_USERNAME}' # Your encrypted BML Username @" $CREDENTIALS sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='${BML_PASSWORD}' # Your encrypted BML Password @" $CREDENTIALS @@ -204,17 +184,11 @@ savepass(){ else : fi - #echo ok - urandom & animate "${G}Randomzing Credentials${N}" && select_profile + urandom && select_profile } -#encrypt(){ -# sed -i "s@BML_USERNAME=.*\$@BML_USERNAME='${BML_USERNAME}' # Your encrypted BML Username @" $CREDENTIALS -# sed -i "s@BML_PASSWORD=.*\$@BML_PASSWORD='${BML_PASSWORD}' # Your encrypted BML Password @" $CREDENTIALS -# BML_USERNAME=$(echo "${BML_USERNAME_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) -# BML_PASSWORD=$(echo "${BML_PASSWORD_UNSAFE}" | openssl enc -e -des3 -base64 -pass pass:${NEW_PIN} -pbkdf2) -# echo "Your credentials are ${lightgreen}encrypted${reset} and saved in $CREDENTIALS" -# savepass -#} +################################################################################################ + +################################################################################################ login(){ LOGIN=$(curl -s -c $COOKIE $BML_URL/login \ --data-raw username=$BML_USERNAME_UNSAFE \ @@ -222,14 +196,15 @@ login(){ | jq -r .code) if [ "$LOGIN" = "0" ] then - echo Login success + echo ${lightgreen}Login success${reset} savepass elif [ "$LOGIN" = "20" ] then account_locked elif [ "$LOGIN" = "2" ] then - echo Password or Username Incorrect + banner + echo ${red}Password or Username Incorrect${reset} wipe_credentials enter_credentials elif [ "$LOGIN" = "37" ] @@ -242,6 +217,9 @@ login(){ exit fi } +################################################################################################ + +################################################################################################ account_locked(){ echo "${red}Account Locked!${reset}" echo "${lightred}Please reset password and login again.${reset}" @@ -260,7 +238,9 @@ account_locked(){ fi enter_credentials } +################################################################################################ +################################################################################################ enter_credentials(){ #echo "" read -p 'Username: ' BML_USERNAME_UNSAFE @@ -268,7 +248,9 @@ enter_credentials(){ echo "" login } +################################################################################################ +################################################################################################ select_profile(){ REQPRO=$(curl -s -b $COOKIE $BML_URL/profile) PERSONALPROFILE=$(echo $REQPRO \ @@ -278,7 +260,9 @@ curl -s -b $COOKIE $BML_URL/profile \ --data-raw profile=$PERSONALPROFILE \ --compressed > /dev/null } +################################################################################################ +################################################################################################ userinfo(){ USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo | jq -r '.["payload"] | .["user"]') NAME=$(echo $USERINFO | jq -r .fullname) @@ -287,6 +271,106 @@ EMAIL=$(echo $USERINFO | jq -r .email) DOB=$(echo $USERINFO | jq -r .birthdate |cut -d 'T' -f 1) IDCARD=$(echo $USERINFO | jq -r .idcard) } +################################################################################################ + +################################################################################################ +accounts(){ + banner + curl -s -b $COOKIE $BML_URL/dashboard \ + | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' +} +################################################################################################ + +################################################################################################ +list_contacts(){ + echo $API_CONATCTS | jq -r '["ID","Account Number","Currency","Account Name","Contact Name"], ["==================================================================="], (.["payload"] | .[] | [.id, .account, .currency, .name, .alias]) | @tsv' +} +################################################################################################ +api_contacts(){ + API_CONATCTS=$(curl -s -b $COOKIE $BML_URL/contacts) +} + +################################################################################################ +transfer(){ +# banner + accounts + echo "" + echo "Select debit account" + echo "Enter credit account" +} +################################################################################################ + +################################################################################################ +api_account(){ +API_ACCOUNT=$(curl -s -b $COOKIE $BML_URL/validate/account/$ACCOUNT_NUMBER) +} +################################################################################################ + +################################################################################################ +add_contact(){ +printf 'Account Number: ' +read -r ACCOUNT_NUMBER +api_account +VALID_NUMBER=$(echo $API_ACCOUNT | jq -r .success) + +if [ "$VALID_NUMBER" = "true" ] +then + + ACCOUNT_NAME=$(echo $API_ACCOUNT | jq -r '.["payload"] | .name') + CURRENCY=$(echo $API_ACCOUNT | jq -r '.["payload"] | .currency') + echo "Account Name: $ACCOUNT_NAME" + echo "Currency: $CURRENCY" + echo "" + printf 'Contact Name: ' + read -r CONTACT_NAME + if [ "$CONTACT_NAME" = "" ] + then + CONTACT_NAME=$ACCOUNT_NAME + else + : + fi + CONTACT_NAME=`echo "$CONTACT_NAME" | sed "s/ /%20/"` + ADDCONTACT=$(curl -s -b $COOKIE $BML_URL/contacts \ + --data-raw contact_type=IAT \ + --data-raw account=$ACCOUNT_NUMBER \ + --data-raw alias=$CONTACT_NAME \ + --compressed \ + | jq -r .success) + + if [ "$ADDCONTACT" = "true" ] + then + echo "Contact added successfully" + else + echo "${red}There was an error${reset}" + fi +else + echo "${red}Invalid Account${reset}" 1>&2 + add_contact +fi +} +################################################################################################ + +################################################################################################ +delete_contact(){ + printf "Enter Contact ID: " + read -r CONATACT_ID + DELETESUCCESS=$(curl -s -b $COOKIE $BML_URL/contacts/$CONATACT_ID \ + --data-raw _method=delete \ + --compressed \ + | jq -r .code) + + if [ "$DELETESUCCESS" = "0" ] + then + echo Contact Deleted + contacts_menu + else + echo "${red}There was an error${reset}" + delete_contact + fi +} +################################################################################################ + +################################################################################################ main_menu(){ echo "Main Menu" echo "" @@ -302,19 +386,17 @@ read -r MENU if [ "$MENU" = "1" ] then - echo "WIP" - sleep 2 - #source mainmenu.sh - source accounts.sh + banner + accounts #& animate "Fetching account details" +# display_user_info + accounts_menu elif [ "$MENU" = "2" ] then - echo "WIP" - sleep 2 - source mainmenu.sh - #source transfer.sh -elif [ "$MENU" = "3" ] + banner + transfer_menu +elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ] then - source contactsmenu.sh + banner && api_contacts && list_contacts && contacts_menu elif [ "$MENU" = "4" ] then echo "WIP" @@ -342,13 +424,69 @@ elif [ "$MENU" = "exit" ] sleep 0.2 exit else + banner echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2 - source mainmenu.sh + main_menu fi } - -settings(){ +############################################################################################## +accounts_menu(){ + echo "Work In Progress" + read -p "Press Anykey to go main menu" BRUH + banner && display_welcome && display_user_info && main_menu +} +################################################################################################ +contacts_menu(){ + echo "Contacts" echo "" + echo "1 - Transfer" + echo "2 - Add New Contact" + echo "3 - Delete Contact" + echo "x - Go back" + echo "" + printf 'Please Input: ' +read -r CONTACTS + +if [ "$CONTACTS" = "1" ] +then + banner + transfer_menu +elif [ "$CONTACTS" = "2" ] +then + banner + add_contact + contacts_menu +elif [ "$CONTACTS" = "3" ] +then + banner + list_contacts + delete_contact + api_contacts + contact_menu +elif [ "$CONTACTS" = "x" ] || [ "$CONTACTS" = "back" ] +then + sleep 0.2 + banner + main_menu +elif [ "$CONTACTS" = "exit" ] +then + echo "Cleaning up.." + rm $COOKIE + sleep 0.2 + exit +else + echo ${red}Invalid input:${yellow} $CONTACTS ${reset} 1>&2 + source contactsmenu.sh +fi +} +transfer_menu(){ + echo "Work In Progress" + read -p "Press Anykey to go main menu" BRUH + banner && display_user_info && main_menu +} + +################################################################################################ +settings(){ echo "Settings" echo "" echo "1 - bml-cli Settings" @@ -364,27 +502,17 @@ settings(){ elif [ "$SETTINGS" = "2" ] then source changepassword.sh - elif [ "$SETTINGS" = "3" ] || [ "$SETTINGS" = "back" ] + elif [ "$SETTINGS" = "x" ] || [ "$SETTINGS" = "back" ] then banner && main_menu - elif [ "$SETTINGS" = "clear" ] - then - sleep 0.2 - clear - source settings-menu.sh - elif [ "$SETTINGS" = "exit" ] - then - echo "Cleaning up.." - rm $COOKIE - sleep 0.2 - exit else + banner + display_user_info echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2 - source settings-menu.sh + settings fi } bml-cli_settings(){ - echo "" echo "bml-cli Settings" echo "" echo "1 - Logout" @@ -411,8 +539,8 @@ then initialize fi -check_connection & initanimate "Checking Internet Connection" -os_detect #& initanimate "Detecting Operating System" +banner && check_connection #& animate "Checking Internet Connection" +banner && os_detect #& animate "Detecting Operating System" source $CONFIG source $CREDENTIALS if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] @@ -422,4 +550,4 @@ else enter_credentials fi userinfo -banner && main_menu +banner && display_welcome && display_user_info && main_menu From 28afb928ddf690266496d346c66adc1f79383fa9 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Wed, 19 May 2021 23:32:03 +0500 Subject: [PATCH 06/11] promt to login if logged in from another app while using bml-cli --- bml-cli.sh | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index fe6a8d9..f70e2e4 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -152,7 +152,7 @@ urandom(){ BML_USERNAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) BML_PASSWORD=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) REPEAT_PIN=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) - PIN=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) + NEW_PIN=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5) } savepass(){ if [ "$BML_USERNAME" = "" ] && [ "$BML_PASSWORD" = "" ] @@ -184,7 +184,7 @@ savepass(){ else : fi - urandom && select_profile + select_profile # urandom && select_profile } ################################################################################################ @@ -283,11 +283,18 @@ accounts(){ ################################################################################################ list_contacts(){ - echo $API_CONATCTS | 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' } ################################################################################################ api_contacts(){ - API_CONATCTS=$(curl -s -b $COOKIE $BML_URL/contacts) + API_CONATACTS=$(curl -s -b $COOKIE $BML_URL/contacts) + SUCCESS=$(echo $API_CONATACTS | jq -r .success) + if [ "$SUCCESS" != "true" ] + then + echo "Login Required" + init_login + api_contacts + fi } ################################################################################################ @@ -539,15 +546,18 @@ then initialize fi -banner && check_connection #& animate "Checking Internet Connection" -banner && os_detect #& animate "Detecting Operating System" +init_login(){ + if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] + then + readpin + else + enter_credentials + fi +} +banner && check_connection & animate "Checking Internet Connection" +banner && os_detect & animate "Detecting Operating System" source $CONFIG source $CREDENTIALS -if [ "$BML_USERNAME" != "" ] && [ "$BML_PASSWORD" != "" ] -then - readpin -else - enter_credentials -fi +banner && init_login userinfo banner && display_welcome && display_user_info && main_menu From 1565c14aa8cd00a87c4eb812f29ff415de716656 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 20 May 2021 00:08:24 +0500 Subject: [PATCH 07/11] promt to login if logged in from another app while using bml-cli - dashboard --- bml-cli.sh | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index f70e2e4..8c17313 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -264,22 +264,41 @@ curl -s -b $COOKIE $BML_URL/profile \ ################################################################################################ userinfo(){ -USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo | jq -r '.["payload"] | .["user"]') -NAME=$(echo $USERINFO | jq -r .fullname) -PHONE=$(echo $USERINFO | jq -r .mobile_phone) -EMAIL=$(echo $USERINFO | jq -r .email) -DOB=$(echo $USERINFO | jq -r .birthdate |cut -d 'T' -f 1) -IDCARD=$(echo $USERINFO | jq -r .idcard) + USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo) + SUCCESS=$(echo $USERINFO | jq -r .success) + if [ "$SUCCESS" != "true" ] + then + echo "Login Required" + init_login + banner + userinfo + fi + USERINFO=$(echo $USERINFO | jq -r '.["payload"] | .["user"]') + NAME=$(echo $USERINFO | jq -r .fullname) + PHONE=$(echo $USERINFO | jq -r .mobile_phone) + EMAIL=$(echo $USERINFO | jq -r .email) + DOB=$(echo $USERINFO | jq -r .birthdate |cut -d 'T' -f 1) + IDCARD=$(echo $USERINFO | jq -r .idcard) } ################################################################################################ ################################################################################################ accounts(){ - banner curl -s -b $COOKIE $BML_URL/dashboard \ | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' } ################################################################################################ +api_dashboard(){ + API_DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard) + SUCCESS=$(echo $API_CONATACTS | jq -r .success) + if [ "$SUCCESS" != "true" + then + echo "Login Required" + init_login + banner + api_dashboard + fi +} ################################################################################################ list_contacts(){ @@ -293,6 +312,7 @@ api_contacts(){ then echo "Login Required" init_login + banner api_contacts fi } @@ -394,6 +414,7 @@ read -r MENU if [ "$MENU" = "1" ] then banner + api_dashboard accounts #& animate "Fetching account details" # display_user_info accounts_menu From 0799b0764fc26f4ab742664006739975183778fa Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 20 May 2021 00:44:47 +0500 Subject: [PATCH 08/11] promt to login if logged in from another app while using bml-cli - dashboard --- bml-cli.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index 8c17313..477a55e 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -200,7 +200,13 @@ login(){ savepass elif [ "$LOGIN" = "20" ] then + banner account_locked + sleep 1.5 + banner + echo "${red}Account Locked!${reset}" + echo "${lightred}Please reset password and login again.${reset}" + enter_credentials elif [ "$LOGIN" = "2" ] then banner @@ -221,9 +227,6 @@ login(){ ################################################################################################ account_locked(){ - echo "${red}Account Locked!${reset}" - echo "${lightred}Please reset password and login again.${reset}" - echo "" if [ "$OS" = "macos" ] then open $BML_RESETPASS @@ -236,7 +239,6 @@ account_locked(){ else xdg-open $BML_RESETPASS fi - enter_credentials } ################################################################################################ @@ -284,14 +286,14 @@ userinfo(){ ################################################################################################ accounts(){ - curl -s -b $COOKIE $BML_URL/dashboard \ + echo $API_DASHBOARD \ | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' } ################################################################################################ api_dashboard(){ API_DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard) - SUCCESS=$(echo $API_CONATACTS | jq -r .success) - if [ "$SUCCESS" != "true" + SUCCESS=$(echo $API_DASHBOARD | jq -r .success) + if [ "$SUCCESS" != "true" ] then echo "Login Required" init_login From ca2fa8c194cd01c807b33182b6c0245c79f5d5a8 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 20 May 2021 04:33:26 +0500 Subject: [PATCH 09/11] nice contacts --- a.out | 0 bml-cli.sh | 219 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 126 insertions(+), 93 deletions(-) create mode 100644 a.out diff --git a/a.out b/a.out new file mode 100644 index 0000000..e69de29 diff --git a/bml-cli.sh b/bml-cli.sh index 477a55e..08e1571 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -42,7 +42,7 @@ animate(){ while [ -d /proc/$PID ]; do h=$(((h + 1) % 4)) sleep 0.05 - printf "\r${@} [${anim:$h:1}]" + printf "\r${@} [${anim:$h:1}]" done } initialize(){ @@ -63,7 +63,7 @@ check_connection(){ if [ "$PING" != "0%" ] then echo ${red}Check your connection and try again.${reset} - exit + exit 1 fi DOS=$(curl -s https://www.bankofmaldives.com.mv/ | grep -oE "error code: 1020") if [ "$DOS" = "error code: 1020" ] @@ -85,7 +85,7 @@ os_detect(){ if [ "$I_AM_SODU" != "true" ] then echo ${red}Please check $CONFIG and configure accordingly.${reset} - exit + cexit fi elif [ "$MAC" = "Darwin" ] then @@ -94,7 +94,7 @@ os_detect(){ if [ "$I_AM_HYPOCRITE" != "true" ] then echo ${red}Please check $CONFIG and configure accordingly.${reset} - exit + cexit fi elif [ "$ANDROID" = "Android" ] then @@ -103,7 +103,7 @@ os_detect(){ banner } ################################################################## -banner(){ +display_banner(){ clear echo "${red}" echo "██████╗░███╗░░░███╗██╗░░░░░  ░█████╗░██╗░░░░░██╗" @@ -115,11 +115,14 @@ banner(){ echo "${reset}" } display_welcome(){ - echo "" echo ${green}Welcome ${reset}$NAME echo "" } -display_user_info(){ +display_name(){ + echo "" + echo ${cyan}Name${reset}: $NAME +} +display_userinfo(){ echo ${cyan}Phone${reset}: $PHONE echo ${cyan}Email${reset}: $EMAIL echo ${cyan}Birthday${reset}: $DOB @@ -127,6 +130,13 @@ display_user_info(){ echo "" } #################################################################### +cexit(){ + echo "Cleaning up.." + rm $COOKIE + sleep 0.2 + exit +} + readpin(){ read -s -p 'Enter Pin: ' PIN echo "" @@ -136,10 +146,11 @@ readpin(){ echo ${R}Incorrect Pin${N} readpin fi - banner + #banner 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) - login + #banner + login #& animate "Logging in" } wipe_credentials(){ @@ -184,7 +195,8 @@ savepass(){ else : fi - select_profile # urandom && select_profile + urandom + select_profile #& animate "Selecting Profile" # urandom && select_profile } ################################################################################################ @@ -196,20 +208,21 @@ login(){ | jq -r .code) if [ "$LOGIN" = "0" ] then + display_banner echo ${lightgreen}Login success${reset} savepass elif [ "$LOGIN" = "20" ] then - banner + display_banner account_locked sleep 1.5 - banner + display_banner echo "${red}Account Locked!${reset}" echo "${lightred}Please reset password and login again.${reset}" enter_credentials elif [ "$LOGIN" = "2" ] then - banner + display_banner echo ${red}Password or Username Incorrect${reset} wipe_credentials enter_credentials @@ -270,9 +283,9 @@ userinfo(){ SUCCESS=$(echo $USERINFO | jq -r .success) if [ "$SUCCESS" != "true" ] then - echo "Login Required" + echo ${red}Login Required${reset} init_login - banner + display_banner userinfo fi USERINFO=$(echo $USERINFO | jq -r '.["payload"] | .["user"]') @@ -286,35 +299,35 @@ userinfo(){ ################################################################################################ accounts(){ - echo $API_DASHBOARD \ - | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' + echo $DASHBOARD | jq -r '.payload | .dashboard |.[] | (.alias, .account, .currency, .availableBalance)' } ################################################################################################ api_dashboard(){ - API_DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard) - SUCCESS=$(echo $API_DASHBOARD | jq -r .success) + DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard) + SUCCESS=$(echo $DASHBOARD | jq -r .success) if [ "$SUCCESS" != "true" ] then - echo "Login Required" + echo ${red}Login Required${reset} init_login - banner + display_banner && display_name && display_userinfo api_dashboard fi } ################################################################################################ 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_CONATACTS=$(curl -s -b $COOKIE $BML_URL/contacts) - SUCCESS=$(echo $API_CONATACTS | jq -r .success) - if [ "$SUCCESS" != "true" ] + SUCCESS=$(echo $API_CONATACTS | jq -r .code) + if [ "$SUCCESS" = "17" ] then - echo "Login Required" + echo ${red}Login Required${reset} init_login - banner + display_banner && display_name && display_userinfo api_contacts fi } @@ -331,14 +344,34 @@ transfer(){ ################################################################################################ 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(){ -printf 'Account Number: ' -read -r ACCOUNT_NUMBER + printf '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 VALID_NUMBER=$(echo $API_ACCOUNT | jq -r .success) @@ -355,21 +388,26 @@ then if [ "$CONTACT_NAME" = "" ] then CONTACT_NAME=$ACCOUNT_NAME - else - : 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 \ --data-raw contact_type=IAT \ --data-raw account=$ACCOUNT_NUMBER \ - --data-raw alias=$CONTACT_NAME \ + --data-raw alias=$CONTACT_NAME_SED \ --compressed \ - | jq -r .success) + | jq -r .code) - if [ "$ADDCONTACT" = "true" ] + if [ "$ADDCONTACT" = "0" ] 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 + display_banner && display_name && display_userinfo echo "${red}There was an error${reset}" fi else @@ -415,46 +453,42 @@ read -r MENU if [ "$MENU" = "1" ] then - banner - api_dashboard - accounts #& animate "Fetching account details" -# display_user_info + display_banner + api_dashboard # & animate "Fetching account details" + display_banner + accounts accounts_menu elif [ "$MENU" = "2" ] then - banner + display_banner && display_name && display_userinfo transfer_menu elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ] 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" ] then echo "WIP" sleep 2 source mainmenu.sh source activities.sh -elif [ "$MENU" = "5" ] + elif [ "$MENU" = "5" ] then - echo "WIP" - sleep 2 - source mainmenu.sh - source services.sh -elif [ "$MENU" = "6" ] + echo "WIP" + sleep 2 + cexit + elif [ "$MENU" = "6" ] then - banner && settings -elif [ "$MENU" = "clear" ] + display_banner && display_name && display_userinfo + settings + elif [ "$MENU" = "exit" ] then - clear - sleep 0.2 - source mainmenu.sh -elif [ "$MENU" = "exit" ] - then - echo "cleaning up..." - rm $COOKIE - sleep 0.2 - exit -else - banner + cexit + else + display_banner && display_name && display_userinfo echo ${red}Invalid input:${yellow} $MENU ${reset} 1>&2 main_menu fi @@ -463,7 +497,8 @@ fi accounts_menu(){ echo "Work In Progress" 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(){ @@ -477,91 +512,89 @@ contacts_menu(){ printf 'Please Input: ' read -r CONTACTS -if [ "$CONTACTS" = "1" ] +if [ "$CONTACTS" = "1" ] || ["$CONTACTS" = "transfer" ] then - banner + display_banner && display_name && display_userinfo transfer_menu -elif [ "$CONTACTS" = "2" ] +elif [ "$CONTACTS" = "2" ] || ["$CONTACTS" = "add new contact" ] then - banner + display_banner && display_name && display_userinfo add_contact contacts_menu -elif [ "$CONTACTS" = "3" ] +elif [ "$CONTACTS" = "3" ] || ["$CONTACTS" = "delete contact" ] then - banner + display_banner && display_name && display_userinfo list_contacts delete_contact api_contacts contact_menu elif [ "$CONTACTS" = "x" ] || [ "$CONTACTS" = "back" ] then - sleep 0.2 - banner + display_banner && display_name && display_userinfo main_menu elif [ "$CONTACTS" = "exit" ] then - echo "Cleaning up.." - rm $COOKIE - sleep 0.2 - exit + cexit else + display_banner && display_name && display_userinfo echo ${red}Invalid input:${yellow} $CONTACTS ${reset} 1>&2 - source contactsmenu.sh + contacts_menu fi } transfer_menu(){ echo "Work In Progress" read -p "Press Anykey to go main menu" BRUH - banner && display_user_info && main_menu + display_banner && display_name && display_userinfo + main_menu } ################################################################################################ settings(){ echo "Settings" - echo "" echo "1 - bml-cli Settings" echo "2 - BML Account Settings" - echo "3 - Go Back" + echo "x - Go Back" echo "" printf 'Please Input: ' read -r SETTINGS if [ "$SETTINGS" = "1" ] then - banner && bml-cli_settings + display_banner && display_name && display_userinfo + bml-cli_settings elif [ "$SETTINGS" = "2" ] then source changepassword.sh elif [ "$SETTINGS" = "x" ] || [ "$SETTINGS" = "back" ] then - banner && main_menu + display_banner && display_name && display_userinfo + main_menu else - banner - display_user_info + display_banner && display_name && display_userinfo echo ${red}Invalid input:${yellow} $SETTINGS ${reset} 1>&2 settings fi } bml-cli_settings(){ echo "bml-cli Settings" - echo "" echo "1 - Logout" echo "2 - Logout and reset configration" - echo "3 - Back" + echo "x - Back" echo "" printf 'Please Input: ' read -r BML_CLI_SETTINGS if [ "$BML_CLI_SETTINGS" = "1" ] then logout - echo "Exit.." - exit + cexit elif [ "$BML_CLI_SETTINGS" = "2" ] then - reset_config && exit - elif [ "$BML_CLI_SETTINGS" = "3" ] + reset_config + cexit + elif [ "$BML_CLI_SETTINGS" = "x" ] || [ "$BML_CLI_SETTINGS" = "back" ] then - banner && settings + display_banner && display_name && display_userinfo + settings fi } if [ ! -f $CONFIG ] @@ -577,10 +610,10 @@ init_login(){ enter_credentials fi } -banner && check_connection & animate "Checking Internet Connection" -banner && os_detect & animate "Detecting Operating System" +display_banner && check_connection #& animate "Checking Internet Connection" +display_banner && os_detect # & animate "Detecting Operating System" source $CONFIG source $CREDENTIALS -banner && init_login +display_banner && init_login userinfo -banner && display_welcome && display_user_info && main_menu +display_banner && display_welcome && display_userinfo && main_menu From 094ffc86f3710417c73c478789dca235ab428020 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 20 May 2021 05:04:03 +0500 Subject: [PATCH 10/11] added password change --- bml-cli.sh | 130 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 102 insertions(+), 28 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index 08e1571..985f60f 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -547,24 +547,118 @@ transfer_menu(){ display_banner && display_name && display_userinfo main_menu } +########################################################################################### +change_password(){ + read -s -p 'Enter Current Password: ' OLD_PASSWORD + echo "" + echo "" + while true; do + read -s -p 'Enter New Password: ' NEW_PASSWORD + echo "" + read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD + echo "" + if [ "$NEW_PASSWORD" = "$REPEAT_NEWPASSWORD" ] + then + sleep 0.2 + echo "" + break + else + echo "${red}Password do not match${reset}" + echo "Try again" + echo "" + fi + done + + while true; do + echo "Select OTP Method:" + echo "1 - Mobile" + echo "2 - Email" + echo "" + read -p "Please input: " OTPCHANNEL + + if [ "$OTPCHANNEL" = "1" ] || [ "$OTPCHANNEL" = "mobile" ] + then + OTPCHANNEL=mobile + break + elif [ "$OTPCHANNEL" = "2" ] || [ "$OTPCHANNEL" = "email" ] + then + OTPCHANNEL=email + break + else + echo ${red}Invalid Input${reset} + echo "" + fi + done + + OLDPASSCHECHECK=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ + --data-raw currentPassword=$OLD_PASSWORD \ + --data-raw newPassword=$NEW_PASSWORD \ + --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ + --data-raw channel=$OTPCHANNEL \ + --compressed \ + | jq -r .code) + + if [ "$OLDPASSCHECHECK" = "17" ] + then + echo ${red}Login Required${reset} + init_login + display_banner && display_name && display_userinfo + change_password + fi + + if [ "$OTPCHANNEL" = "mobile" ] + then + ECHOOTPCHANNEL=$PHONE + elif [ "$OTPCHANNEL" = "email" ] + then + ECHOOTPCHANNEL=$EMAIL + fi + + echo "" + echo ${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset} + read -p 'Enter OTP: ' OTP + echo "" + PASSCHANGED=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ + --data-raw currentPassword=$OLD_PASSWORD \ + --data-raw newPassword=$NEW_PASSWORD \ + --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ + --data-raw channel=$OTPCHANNEL \ + --data-raw otp=$OTP \ + --compressed \ + | jq -r .code) + + if [ "$PASSCHANGED" = "0" ] + then + echo "${red}Failed to change password${reset}" + else + echo "${lightgreen}Password changed succesfully ${reset}" + fi +} +############################################################################################## + ################################################################################################ settings(){ echo "Settings" - echo "1 - bml-cli Settings" - echo "2 - BML Account Settings" - echo "x - Go Back" + echo "1 - Logout" + echo "2 - Logout and reset config" + echo "3 - Change Password" echo "" printf 'Please Input: ' read -r SETTINGS if [ "$SETTINGS" = "1" ] then - display_banner && display_name && display_userinfo - bml-cli_settings + display_banner + logout elif [ "$SETTINGS" = "2" ] then - source changepassword.sh + display_banner + reset_config + elif [ "$SETTINGS" = "3" ] + then + display_banner && display_name && display_userinfo + change_password elif [ "$SETTINGS" = "x" ] || [ "$SETTINGS" = "back" ] then display_banner && display_name && display_userinfo @@ -575,28 +669,8 @@ settings(){ settings fi } -bml-cli_settings(){ - echo "bml-cli Settings" - echo "1 - Logout" - echo "2 - Logout and reset configration" - echo "x - Back" - echo "" - printf 'Please Input: ' - read -r BML_CLI_SETTINGS - if [ "$BML_CLI_SETTINGS" = "1" ] - then - logout - cexit - elif [ "$BML_CLI_SETTINGS" = "2" ] - then - reset_config - cexit - elif [ "$BML_CLI_SETTINGS" = "x" ] || [ "$BML_CLI_SETTINGS" = "back" ] - then - display_banner && display_name && display_userinfo - settings - fi -} + + if [ ! -f $CONFIG ] then initialize From fce2ff1738cad08ae27b05afcc4802c73a366b36 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 20 May 2021 06:17:12 +0500 Subject: [PATCH 11/11] activites --- bml-cli.sh | 144 +++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/bml-cli.sh b/bml-cli.sh index 985f60f..3b8bcf4 100755 --- a/bml-cli.sh +++ b/bml-cli.sh @@ -436,7 +436,10 @@ delete_contact(){ fi } ################################################################################################ +activities(){ +curl -s -b $COOKIE $BML_URL/activities?page=1 | jq +} ################################################################################################ main_menu(){ echo "Main Menu" @@ -451,30 +454,27 @@ echo "" printf 'Please Input: ' read -r MENU -if [ "$MENU" = "1" ] + if [ "$MENU" = "1" ] then - display_banner - api_dashboard # & animate "Fetching account details" - display_banner - accounts - accounts_menu -elif [ "$MENU" = "2" ] + display_banner + api_dashboard # & animate "Fetching account details" + display_banner + accounts + accounts_menu + elif [ "$MENU" = "2" ] then - display_banner && display_name && display_userinfo - transfer_menu -elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ] + display_banner && display_name && display_userinfo + transfer_menu + elif [ "$MENU" = "3" ] || [ "$MENU" = "contacts" ] then - display_banner && display_name && display_userinfo - api_contacts #& animate "Fetching contacts" - #display_banner - list_contacts - contacts_menu -elif [ "$MENU" = "4" ] + display_banner && display_name && display_userinfo + api_contacts #& animate "Fetching contacts" + list_contacts + contacts_menu + elif [ "$MENU" = "4" ] then - echo "WIP" - sleep 2 - source mainmenu.sh - source activities.sh + display_banner && display_name && display_userinfo + activities elif [ "$MENU" = "5" ] then echo "WIP" @@ -549,26 +549,6 @@ transfer_menu(){ } ########################################################################################### change_password(){ - read -s -p 'Enter Current Password: ' OLD_PASSWORD - echo "" - echo "" - while true; do - read -s -p 'Enter New Password: ' NEW_PASSWORD - echo "" - read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD - echo "" - if [ "$NEW_PASSWORD" = "$REPEAT_NEWPASSWORD" ] - then - sleep 0.2 - echo "" - break - else - echo "${red}Password do not match${reset}" - echo "Try again" - echo "" - fi - done - while true; do echo "Select OTP Method:" echo "1 - Mobile" @@ -579,60 +559,81 @@ change_password(){ if [ "$OTPCHANNEL" = "1" ] || [ "$OTPCHANNEL" = "mobile" ] then OTPCHANNEL=mobile + ECHOOTPCHANNEL=$PHONE break elif [ "$OTPCHANNEL" = "2" ] || [ "$OTPCHANNEL" = "email" ] then OTPCHANNEL=email + ECHOOTPCHANNEL=$EMAIL break else + display_banner && display_name && display_userinfo echo ${red}Invalid Input${reset} - echo "" fi done - OLDPASSCHECHECK=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ - --data-raw currentPassword=$OLD_PASSWORD \ - --data-raw newPassword=$NEW_PASSWORD \ - --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ - --data-raw channel=$OTPCHANNEL \ - --compressed \ - | jq -r .code) - - if [ "$OLDPASSCHECHECK" = "17" ] - then - echo ${red}Login Required${reset} - init_login - display_banner && display_name && display_userinfo - change_password - fi - - if [ "$OTPCHANNEL" = "mobile" ] - then - ECHOOTPCHANNEL=$PHONE - elif [ "$OTPCHANNEL" = "email" ] - then - ECHOOTPCHANNEL=$EMAIL - fi + read -s -p 'Enter Current Password: ' OLD_PASSWORD echo "" + while true; do + read -s -p 'Enter New Password: ' NEW_PASSWORD + echo "" + read -s -p 'Repeat New Password: ' REPEAT_NEWPASSWORD + echo "" + if [ "$NEW_PASSWORD" != "$REPEAT_NEWPASSWORD" ] + then + display_banner && display_name && display_userinfo + echo "${red}Password do not match${reset}" + echo "Try again" + else + break + fi + done + + + curl -s -b $COOKIE $BML_URL/user/changepassword \ + --data-raw currentPassword=$OLD_PASSWORD \ + --data-raw newPassword=$NEW_PASSWORD \ + --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ + --data-raw channel=$OTPCHANNEL > /dev/null + echo ${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset} read -p 'Enter OTP: ' OTP - echo "" - PASSCHANGED=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ + CHANGEPASSWORD=$(curl -s -b $COOKIE $BML_URL/user/changepassword \ --data-raw currentPassword=$OLD_PASSWORD \ --data-raw newPassword=$NEW_PASSWORD \ --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ --data-raw channel=$OTPCHANNEL \ --data-raw otp=$OTP \ - --compressed \ | jq -r .code) - if [ "$PASSCHANGED" = "0" ] + if [ "$CHANGEPASSWORD" = "0" ] then - echo "${red}Failed to change password${reset}" + echo Password changed succesfully ${reset} + elif [ "$CHANGEPASSWORD" = "8" ] + then + display_banner && display_name && display_userinfo + echo ${red}Old Password is incorrect${reset} + echo failed to change password + change_password + elif [ "$CHANGEPASSWORD" = "24" ] + then + display_banner && display_name && display_userinfo + echo ${red}Invalid OTP${reset} + echo failed to change password + change_password + elif [ "$CHANGEPASSWORD" = "17" ] + then + echo ${red}Login Required${reset} + init_login + display_banner + change_password else - echo "${lightgreen}Password changed succesfully ${reset}" + echo unknown error + main_menu fi + + } ############################################################################################## @@ -650,7 +651,8 @@ settings(){ if [ "$SETTINGS" = "1" ] then display_banner - logout + wipe_credentials + cexit elif [ "$SETTINGS" = "2" ] then display_banner