bml-cli/bml.sh

62 lines
1.5 KiB
Bash
Raw Normal View History

2021-04-25 14:59:31 +05:00
#!/bin/bash
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'
COOKIE=/tmp/bmlcookie
2021-04-25 22:50:50 +05:00
#Setting terminal output colors
2021-04-25 14:59:31 +05:00
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
2021-04-25 22:50:50 +05:00
#importing saved credentials
2021-04-25 20:18:35 +05:00
source .env 2> /dev/null
2021-04-25 19:38:07 +05:00
2021-04-25 22:50:50 +05:00
#what to do if credentials not saved
2021-04-25 20:05:48 +05:00
if [ "$BML_USERNAME" = "" ]
then
2021-04-25 22:08:09 +05:00
echo ${red}Credentials not found in .env file${reset}
2021-04-25 20:18:35 +05:00
echo ""
2021-04-25 20:05:48 +05:00
read -p 'Username: ' BML_USERNAME
read -s -p 'Password: ' BML_PASSWORD
2021-04-25 20:18:35 +05:00
echo ""
2021-04-25 22:08:09 +05:00
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
2021-04-25 20:18:35 +05:00
echo ""
2021-04-25 20:05:48 +05:00
else
:
fi
2021-04-25 22:50:50 +05:00
#login and generate cookie
2021-04-25 14:59:31 +05:00
LOGIN=$(curl -s -c $COOKIE $BML_URL/login \
--data-raw username=$BML_USERNAME \
2021-04-25 19:38:07 +05:00
--data-raw password=${BML_PASSWORD} \
2021-04-25 14:59:31 +05:00
--compressed \
| jq -r .success)
2021-04-25 22:50:50 +05:00
#check if login was success
2021-04-25 14:59:31 +05:00
if [ "$LOGIN" = "true" ]
then
2021-04-25 22:50:50 +05:00
#Requesting for User profile after login and regex to grap the Full name
2021-04-25 14:59:31 +05:00
NAME=$(curl -s -b $COOKIE $BML_URL/profile \
| awk -F 'fullname":"' '{print $2}' \
| cut -f1 -d '"')
2021-04-25 22:50:50 +05:00
#display a Welcome message with fullname
2021-04-25 14:59:31 +05:00
echo ""
echo ${green}Welcome ${reset}$NAME
# curl -s -b $COOKIE $BML_URL/userinfo
echo ""
2021-04-27 23:10:51 +05:00
source mainmenu.sh
2021-04-25 14:59:31 +05:00
else
2021-04-25 22:50:50 +05:00
#Display error if login was not succuessfull and delete cookie
2021-04-25 14:59:31 +05:00
echo "${red}An error occured, Please check Username and Password" 1>&2
rm $COOKIE 2> /dev/null
exit
fi