From fd0452962097e177ee9182a9dc6a56744f732a4b Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Wed, 28 Apr 2021 06:24:11 +0500 Subject: [PATCH] Added Account locked, more detailed errors --- bml.sh | 3 ++- login.sh | 29 +++++++++++++---------------- readpass.sh | 29 +++++++++++++++++++++++++++++ savepass.sh | 27 +++++++++++++++++++++++++++ welcome.sh | 11 +++++++++++ 5 files changed, 82 insertions(+), 17 deletions(-) create mode 100644 readpass.sh create mode 100644 savepass.sh create mode 100644 welcome.sh diff --git a/bml.sh b/bml.sh index e687e3e..cf5b5eb 100755 --- a/bml.sh +++ b/bml.sh @@ -5,6 +5,7 @@ #Setting intial variables BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' COOKIE=/tmp/bmlcookie +CREDENTIALS=.env #Setting terminal output colors red=`tput setaf 1` @@ -12,4 +13,4 @@ green=`tput setaf 2` reset=`tput sgr0` -source password.sh +source readpass.sh diff --git a/login.sh b/login.sh index 58c7d0c..8d8a54d 100644 --- a/login.sh +++ b/login.sh @@ -1,28 +1,25 @@ #!/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 .success) + | jq -r .code) #check if login was success -if [ "$LOGIN" = "true" ] +if [ "$LOGIN" = "0" ] then - #Requesting for User profile after login and regex to grap the Full name - NAME=$(curl -s -b $COOKIE $BML_URL/profile \ - | awk -F 'fullname":"' '{print $2}' \ - | cut -f1 -d '"') - #display a Welcome message with fullname - echo "" - echo ${green}Welcome ${reset}$NAME -# curl -s -b $COOKIE $BML_URL/userinfo - echo "" - source mainmenu.sh + source savepass.sh +elif [ "$LOGIN" = "20" ] + then + echo "${red}Account Locked!${reset}" + exit +elif [ "$LOGIN" = "2" ] + then + source readpass.sh else - #Display error if login was not succuessfull and delete cookie - echo "${red}An error occured, Please check Username and Password" 1>&2 - rm $COOKIE 2> /dev/null - exit + echo "${red}Unknown Error${reset}" 1>&2 + exit fi diff --git a/readpass.sh b/readpass.sh new file mode 100644 index 0000000..1354fa6 --- /dev/null +++ b/readpass.sh @@ -0,0 +1,29 @@ + +if [ -f $CREDENTIALS ] +then + source $CREDENTIALS +elif [ "$LOGIN" = "2" ] +then + if [ -f $CREDENTIALS ] + then + echo "${red}Saved Credentials has been changed${reset}" + rm $CREDENTIALS + else + echo "${red}Username or Password incorrect${reset}" + fi + read -p 'Username: ' BML_USERNAME + read -s -p 'Password: ' BML_PASSWORD + echo "" + +elif [ ! -f $CREDENTIALS ] +then + echo "${red}Password file not found in $CREDENTIALS${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 new file mode 100644 index 0000000..15e1d09 --- /dev/null +++ b/savepass.sh @@ -0,0 +1,27 @@ +#echo "Do ${red}NOT${reset} save password if password contain '|' '^' '$' '&' ';' ':' '(' ')' " + +if [ ! -f $CREDENTIALS ] +then + if [ "$LOGIN" = "0" ] + then + read -p 'Do you want to save login? [y/N] ' SAVE_LOGIN + if [ "$SAVE_LOGIN" = "Y" ] + then + echo BML_USERNAME=''${BML_USERNAME}'' > $CREDENTIALS + echo BML_PASSWORD=''${BML_PASSWORD}'' >> $CREDENTIALS + + elif [ "$SAVE_LOGIN" = "y" ] + then + echo BML_USERNAME=''${BML_USERNAME}'' > $CREDENTIALS + echo BML_PASSWORD=''${BML_PASSWORD}'' >> $CREDENTIALS + else + : + fi + else + source readpass.sh + fi +else + : +fi + +source welcome.sh diff --git a/welcome.sh b/welcome.sh new file mode 100644 index 0000000..e18bfc7 --- /dev/null +++ b/welcome.sh @@ -0,0 +1,11 @@ +#Requesting for User profile after login and regex to grap the Full name +NAME=$(curl -s -b $COOKIE $BML_URL/profile \ + | awk -F 'fullname":"' '{print $2}' \ + | cut -f1 -d '"') + +#display a Welcome message with fullname +echo "" +echo ${green}Welcome ${reset}$NAME +#curl -s -b $COOKIE $BML_URL/userinfo +echo "" +source mainmenu.sh