From 46424c86ee46ef10ca9bc3a39f1cc2252b6eee3b Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Wed, 28 Apr 2021 01:46:14 +0500 Subject: [PATCH] separated password.sh and login.sh --- bml.sh | 56 +++++------------------------------------------------ login.sh | 28 +++++++++++++++++++++++++++ mainmenu.sh | 2 +- password.sh | 34 ++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 login.sh create mode 100644 password.sh diff --git a/bml.sh b/bml.sh index 785858a..e687e3e 100755 --- a/bml.sh +++ b/bml.sh @@ -1,4 +1,8 @@ #!/bin/bash + + + +#Setting intial variables BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' COOKIE=/tmp/bmlcookie @@ -7,55 +11,5 @@ red=`tput setaf 1` green=`tput setaf 2` reset=`tput sgr0` -#importing saved credentials -source .env 2> /dev/null - -#what to do if credentials not saved -if [ "$BML_USERNAME" = "" ] -then - echo ${red}Credentials not found in .env file${reset} - echo "" - read -p 'Username: ' BML_USERNAME - read -s -p 'Password: ' BML_PASSWORD - echo "" - read -p 'Do you want to save login? [Y/N] ' SAVE_LOGIN - - if [ "$SAVE_LOGIN" = "Y" ] - then - echo BML_USERNAME=$BML_USERNAME > .env - echo BML_PASSWORD=$BML_PASSWORD >> .env - else - : - fi - echo "" -else - : -fi - -#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) -#check if login was success -if [ "$LOGIN" = "true" ] - 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 -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 -fi - +source password.sh diff --git a/login.sh b/login.sh new file mode 100644 index 0000000..58c7d0c --- /dev/null +++ b/login.sh @@ -0,0 +1,28 @@ +#!/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) +#check if login was success +if [ "$LOGIN" = "true" ] + 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 +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 +fi + + diff --git a/mainmenu.sh b/mainmenu.sh index bf63e80..f5ee665 100644 --- a/mainmenu.sh +++ b/mainmenu.sh @@ -1,4 +1,4 @@ -echo "Menu" +echo "Main Menu" echo "" echo "1 - Accounts" echo "2 - Transfer" diff --git a/password.sh b/password.sh new file mode 100644 index 0000000..d1f65ea --- /dev/null +++ b/password.sh @@ -0,0 +1,34 @@ +#!/bin/bash + + +#importing saved credentials +source .env 2> /dev/null + +#what to do if credentials not saved +if [ "$BML_USERNAME" = "" ] +then + echo ${red}Credentials not found in .env file${reset} + echo "" + read -p 'Username: ' BML_USERNAME + read -s -p 'Password: ' BML_PASSWORD + echo "" + echo "Do ${red}NOT${reset} save password if password contain '|' '^' '$' '&' ';' ':' '(' ')' " + read -p 'Do you want to save login? [y/N] ' SAVE_LOGIN + + if [ "$SAVE_LOGIN" = "Y" ] + then + echo BML_USERNAME=$BML_USERNAME > .env + echo BML_PASSWORD=$BML_PASSWORD >> .env + elif [ "$SAVE_LOGIN" = "y" ] + then + echo BML_USERNAME=$BML_USERNAME > .env + echo BML_PASSWORD=$BML_PASSWORD >> .env + else + : + fi + echo "" +else + : +fi + +source login.sh