added support for bml api proxy

This commit is contained in:
Shihaam Abdul Rahman 2022-08-08 01:07:02 +05:00
parent cd677157f2
commit d054bc0ee5
Signed by: shihaam
GPG Key ID: 16ADCF6871CB2A56

42
bml-cli
View File

@ -3,7 +3,7 @@
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
CONFIG=~/.config/bml-cli/config CONFIG=~/.config/bml-cli/config
CREDENTIALS=~/.config/bml-cli/.credentials CREDENTIALS=~/.config/bml-cli/.credentials
COOKIE=cookie #~/.cache/bml-cli/.cookie COOKIE=~/.cache/bml-cli/.cookie
BML_RESETPASS='https://www.bankofmaldives.com.mv/internetbanking/forgot_password' BML_RESETPASS='https://www.bankofmaldives.com.mv/internetbanking/forgot_password'
#Setting terminal output colors #Setting terminal output colors
@ -76,13 +76,13 @@ check_connection(){
echo ${red}Check your connection and try again.${reset} echo ${red}Check your connection and try again.${reset}
exit 1 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" ]
then # then
echo ${red}Access denied${reset} # echo ${red}Access denied${reset}
echo Try again later # echo Try again later
exit # exit
fi # fi
} }
os_detect(){ os_detect(){
@ -228,7 +228,7 @@ savepass(){
################################################################################################ ################################################################################################
login(){ login(){
LOGIN=$($curl -s -c $COOKIE $BML_URL/login \ LOGIN=$(curl -s -c $COOKIE $BML_URL/login \
--data-raw username=$BML_USERNAME_UNSAFE \ --data-raw username=$BML_USERNAME_UNSAFE \
--data-raw password=${BML_PASSWORD_UNSAFE} \ --data-raw password=${BML_PASSWORD_UNSAFE} \
| jq -r .code) | jq -r .code)
@ -293,11 +293,11 @@ enter_credentials(){
################################################################################################ ################################################################################################
select_profile(){ select_profile(){
REQPRO=$($curl -s -b $COOKIE $BML_URL/profile) REQPRO=$(curl -s -b $COOKIE $BML_URL/profile)
PERSONALPROFILE=$(echo $REQPRO \ PERSONALPROFILE=$(echo $REQPRO \
| jq -r '.payload | .profile | .[] | .profile' \ | jq -r '.payload | .profile | .[] | .profile' \
| head -n 1) | head -n 1)
$curl -s -b $COOKIE $BML_URL/profile \ curl -s -b $COOKIE $BML_URL/profile \
--data-raw profile=$PERSONALPROFILE \ --data-raw profile=$PERSONALPROFILE \
--compressed > /dev/null --compressed > /dev/null
} }
@ -305,7 +305,7 @@ $curl -s -b $COOKIE $BML_URL/profile \
################################################################################################ ################################################################################################
userinfo(){ userinfo(){
USERINFO=$($curl -s -b $COOKIE $BML_URL/userinfo) USERINFO=$(curl -s -b $COOKIE $BML_URL/userinfo)
SUCCESS=$(echo $USERINFO | jq -r .success) SUCCESS=$(echo $USERINFO | jq -r .success)
if [ "$SUCCESS" != "true" ] if [ "$SUCCESS" != "true" ]
then then
@ -331,7 +331,7 @@ accounts(){
} }
################################################################################################ ################################################################################################
api_dashboard(){ api_dashboard(){
DASHBOARD=$($curl -s -b $COOKIE $BML_URL/dashboard) DASHBOARD=$(curl -s -b $COOKIE $BML_URL/dashboard)
SUCCESS=$(echo $DASHBOARD | jq -r .success) SUCCESS=$(echo $DASHBOARD | jq -r .success)
if [ "$SUCCESS" != "true" ] if [ "$SUCCESS" != "true" ]
then then
@ -349,7 +349,7 @@ list_contacts(){
} }
################################################################################################ ################################################################################################
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 .code) SUCCESS=$(echo $API_CONATACTS | jq -r .code)
if [ "$SUCCESS" = "17" ] if [ "$SUCCESS" = "17" ]
then then
@ -372,7 +372,7 @@ 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) SUCCESS=$(echo $API_ACCOUNT | jq -r .code)
if [ "$SUCCESS" = "17" ] if [ "$SUCCESS" = "17" ]
then then
@ -418,7 +418,7 @@ then
CONTACT_NAME=$ACCOUNT_NAME CONTACT_NAME=$ACCOUNT_NAME
fi fi
CONTACT_NAME_SED=`echo "$CONTACT_NAME" | sed "s/ /%20/g"` 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_SED \ --data-raw alias=$CONTACT_NAME_SED \
@ -452,7 +452,7 @@ fi
delete_contact(){ delete_contact(){
printf "Enter Contact ID: " printf "Enter Contact ID: "
read -r CONATACT_ID read -r CONATACT_ID
DELETESUCCESS=$($curl -s -b $COOKIE $BML_URL/contacts/$CONATACT_ID \ DELETESUCCESS=$(curl -s -b $COOKIE $BML_URL/contacts/$CONATACT_ID \
--data-raw _method=delete \ --data-raw _method=delete \
--compressed \ --compressed \
| jq -r .code) | jq -r .code)
@ -468,7 +468,7 @@ delete_contact(){
} }
################################# #################################
api_activites(){ api_activites(){
API_ACTIVITES=$($curl -s -b $COOKIE $BML_URL/activities) API_ACTIVITES=$(curl -s -b $COOKIE $BML_URL/activities)
SUCCESS=$(echo $API_ACTIVITES | jq -r .code) SUCCESS=$(echo $API_ACTIVITES | jq -r .code)
if [ "$SUCCESS" = "17" ] if [ "$SUCCESS" = "17" ]
then then
@ -497,7 +497,7 @@ activities(){
then then
display_banner && display_name && display_userinfo display_banner && display_name && display_userinfo
echo Current Page: $PAGENO echo Current Page: $PAGENO
$curl -s -b $COOKIE $BML_URL/activities?page=$PAGENO \ curl -s -b $COOKIE $BML_URL/activities?page=$PAGENO \
| jq -r '["Type","Date","Time","Contact","Amount","Remarks","Status"], ["====","==========","=========","==========================","============","==================","==========="],(.payload | .content | .data | .[] | [.type, .datetime, .creditName, .formattedAmount, .message, .status]) | @tsv' \ | jq -r '["Type","Date","Time","Contact","Amount","Remarks","Status"], ["====","==========","=========","==========================","============","==================","==========="],(.payload | .content | .data | .[] | [.type, .datetime, .creditName, .formattedAmount, .message, .status]) | @tsv' \
| sed "s/+05:00//g" \ | sed "s/+05:00//g" \
| sed 's/\([0-9]\{4\}-[0-9][0-9]-[0-9][0-9]\)T\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)/\1 \2/g' \ | sed 's/\([0-9]\{4\}-[0-9][0-9]-[0-9][0-9]\)T\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)/\1 \2/g' \
@ -681,7 +681,7 @@ change_password(){
done done
$curl -s -b $COOKIE $BML_URL/user/changepassword \ curl -s -b $COOKIE $BML_URL/user/changepassword \
--data-raw currentPassword=$OLD_PASSWORD \ --data-raw currentPassword=$OLD_PASSWORD \
--data-raw newPassword=$NEW_PASSWORD \ --data-raw newPassword=$NEW_PASSWORD \
--data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \
@ -689,7 +689,7 @@ change_password(){
echo ${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset} echo ${lightgreen}OTP sent to ${yellow}${ECHOOTPCHANNEL}${reset}
read -n 6 -p 'Enter OTP: ' OTP read -n 6 -p 'Enter OTP: ' OTP
CHANGEPASSWORD=$($curl -s -b $COOKIE $BML_URL/user/changepassword \ CHANGEPASSWORD=$(curl -s -b $COOKIE $BML_URL/user/changepassword \
--data-raw currentPassword=$OLD_PASSWORD \ --data-raw currentPassword=$OLD_PASSWORD \
--data-raw newPassword=$NEW_PASSWORD \ --data-raw newPassword=$NEW_PASSWORD \
--data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \ --data-raw newPasswordConfirmation=$REPEAT_NEWPASSWORD \