Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d0196f645e | ||
|
7464c54c5e | ||
|
3e251a0429 | ||
|
a098bdd426 | ||
|
b9bb5db4e2 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.env
|
||||
delay
|
||||
cookie
|
||||
.cache/cookie
|
||||
.cache/*
|
||||
|
10
Dockerfile
10
Dockerfile
@ -1,10 +0,0 @@
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
RUN apk update \
|
||||
&& apk add bash curl jq
|
||||
|
||||
COPY bml-tg-notify.sh .
|
||||
|
||||
CMD ["./bml-tg-notify.sh"]
|
17
README.md
17
README.md
@ -11,13 +11,9 @@ Anyone who has access (or gains access) to your server or computer can read .env
|
||||
- At the moment this script can only check 1 account from personal profile.
|
||||
- Script ONLY sends notification for last transaction, so if there more than 1 transacation
|
||||
when script checks for new transactions you will get notification for the last one only.
|
||||
### There's catch!
|
||||
- BML do NOT allow you to be logged in more than 1 session at a time,
|
||||
so when this script runs and if you were using mobile app or website you will be logged out!
|
||||
- You either get fast notification but with less time to use app
|
||||
OR take as much as time you want to use app but slow notifications.
|
||||
Which is why I have added a delay to change how often script logs into account,
|
||||
This can be delay can be configured later. [See how](#setting-delay---optional)
|
||||
- If you login to web or mobile app while script is running, It will pause for APP_NORMAL_DELAY seconds befor running again.
|
||||
|
||||
## Getting started.
|
||||
### Requriements
|
||||
@ -31,19 +27,16 @@ cd bml-tg-notify
|
||||
chmod +x bml-tg-notify.sh
|
||||
cp env.sample .env
|
||||
```
|
||||
- Edit the contents of .env to your config (`nano .env`)
|
||||
- Edit the content of .env to your config (`nano .env`)
|
||||
- [How to obtain BML_ACCOUNTID](https://raw.githubusercontent.com/shihaamabr/bml-tg-notify/main/how-to-obtain-BML_ACCOUNTID.png)
|
||||
### Notes
|
||||
- If the NORAML_DELAY value is less than a certain value (I think 15) your IP could get blocked by CloudFlare for DoS attack.
|
||||
|
||||
### Execute the script
|
||||
```
|
||||
./bml-tg-notify.sh
|
||||
```
|
||||
- Maybe run in a screen to run in background?
|
||||
## Setting Delay - Optional Configration
|
||||
In a different terminal seession run `echo XX > delay` where XX is the time in seconds you want to delay script logs into account [See why](#theres-catch)
|
||||
### Notes
|
||||
- Default value is 160.
|
||||
- If the XX value is less than a certain value (I think 15) your IP could get blocked by CloudFlare for DoS attack.
|
||||
- You do not need to restart script after changing delay.
|
||||
|
||||
## Bugs
|
||||
- [You tell me :)](https://github.com/shihaamabr/bml-tg-notify/issues/new)
|
||||
|
124
bml-tg-notify.sh
124
bml-tg-notify.sh
@ -1,82 +1,114 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
|
||||
|
||||
source .env # import credentials, tg api, cookie path, bml api
|
||||
|
||||
|
||||
init(){
|
||||
if [ ! -f delay ] # if delay file missing
|
||||
then
|
||||
echo 160 > delay # make delay file with 160 sec
|
||||
fi
|
||||
login(){
|
||||
echo ""
|
||||
echo ""
|
||||
echo ===========
|
||||
echo LOGGING IN
|
||||
curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} # attempt to login and generate cookie
|
||||
echo ""
|
||||
echo ""
|
||||
echo ===========
|
||||
echo SELECTING PROFILE
|
||||
PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1) ; echo $PROFILE # get Personal Profile
|
||||
curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE # select Personal Profile
|
||||
echo ""
|
||||
echo ""
|
||||
}
|
||||
|
||||
login(){
|
||||
$curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} # attempt to login and generate cookie
|
||||
PROFILE=$($curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1) ; echo $PROFILE # get Personal Profile
|
||||
$curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE # select Personal Profile
|
||||
getnumberofaccounts(){
|
||||
NUMBEROFACCOUNTS=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | wc -l)
|
||||
NUMBEROFACCOUNTS=$(expr $NUMBEROFACCOUNTS - 1)
|
||||
echo ""
|
||||
echo $NUMBEROFACCOUNTS Accounts loaded
|
||||
}
|
||||
|
||||
getaccountdetails(){
|
||||
REQACCOUNTDETAILS=$($curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID | jq -r .payload)
|
||||
REQACCOUNTDETAILS=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID | jq -r .payload)
|
||||
ACCOUNTTYPE=$(echo $REQACCOUNTDETAILS | jq -r .product)
|
||||
ACCOUNTNUMBER=$(echo $REQACCOUNTDETAILS | jq -r .accountNumber)
|
||||
CURRENCY=$(echo $REQACCOUNTDETAILS | jq -r .currency)
|
||||
}
|
||||
|
||||
send_tg(){
|
||||
TGTEXT=$(echo $DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram
|
||||
$curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT #send to telegram
|
||||
echo "Next check in $DELAY seconds"
|
||||
TGTEXT=$(echo $ACCOUNTTYPE%0A$ACCOUNTNUMBER%0A%0A$DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram
|
||||
echo ""
|
||||
echo ""
|
||||
echo SENDING TO TG
|
||||
|
||||
curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT #send to telegram
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
}
|
||||
|
||||
req_history(){
|
||||
REQ_HISTORY=$($curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today) ; echo $REQ_HISTORY
|
||||
LOGIN_STATUS=$(echo $REQ_HISTORY | jq -r .success) ; echo $LOGIN_STATUS
|
||||
echo ""
|
||||
echo ""
|
||||
echo ===========
|
||||
echo Requesting History for: $BML_ACCOUNTID
|
||||
REQ_HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today) ; echo $REQ_HISTORY
|
||||
#LOGIN_STATUS=$(echo $REQ_HISTORY | jq -r .success) ; echo $LOGIN_STATUS
|
||||
echo ""
|
||||
echo ""
|
||||
echo ===========
|
||||
|
||||
}
|
||||
|
||||
check_diff(){
|
||||
CHECKDIFF1=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF1 # check intial and previous history
|
||||
#HISTORY=$($curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]') ; echo $HISTORY # request history
|
||||
#HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]') ; echo $HISTORY # request history
|
||||
HISTORY=$(echo $REQ_HISTORY | jq -r '.payload | .history | .[]') ; echo $HISTORY
|
||||
CHECKDIFF2=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF2 # check new history
|
||||
}
|
||||
|
||||
read_delay(){
|
||||
DELAY=$(cat delay) ; echo $DELAY # read delay file and get value
|
||||
DELAY=$(cat delay) ; echo $NORMAL_DELAY # read delay file and get value
|
||||
}
|
||||
|
||||
echo_delay(){
|
||||
echo "Nothing new....Next check in $DELAY seconds"
|
||||
}
|
||||
|
||||
init
|
||||
login
|
||||
getaccountdetails
|
||||
loop(){
|
||||
while true; do
|
||||
i=0
|
||||
# if [ "$LOGIN_STATUS" != "true" ]
|
||||
# then
|
||||
# echo ""
|
||||
# echo ""
|
||||
# echo " LOGGED OUT - SLEEPING
|
||||
# sleep 200
|
||||
# login
|
||||
# infinite_loop
|
||||
# fi
|
||||
|
||||
req_history
|
||||
|
||||
if [ "$LOGIN_STATUS" != "true" ]
|
||||
then
|
||||
echo "Looks like app or web was opened... checking again in $APP_OPEN_DELAY"
|
||||
sleep $APP_OPEN_DELAY
|
||||
login
|
||||
break & loop
|
||||
fi
|
||||
|
||||
check_diff
|
||||
read_delay
|
||||
for account in `cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'"`
|
||||
do
|
||||
accountid[$i]=$account;
|
||||
i=$(($i+1));
|
||||
BML_ACCOUNTID=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | head -n$i | tail -n1)
|
||||
echo ""
|
||||
echo $BML_ACCOUNTID Selected
|
||||
echo ""
|
||||
getaccountdetails
|
||||
req_history
|
||||
check_diff
|
||||
read_delay
|
||||
|
||||
if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history
|
||||
then
|
||||
if [ "$CHECKDIFF2" = "1" ]
|
||||
then
|
||||
echo "=============" ; echo NEW DAY ; echo "============="
|
||||
# $curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=GO%20TO%20SLEEP%0AITS%0000
|
||||
# curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=GO%20TO%20SLEEP%0AITS%0000
|
||||
else
|
||||
echo ""
|
||||
echo ""
|
||||
echo ==============
|
||||
echo History of $ACCOUNTTYPE - $ACCOUNTNUMBER
|
||||
echo $HISTORY | jq
|
||||
echo ""
|
||||
echo ""
|
||||
DESCRIPTION=$(echo $HISTORY | jq -r .description | head -n1) ; echo $DESCRIPTION # get last trascation description
|
||||
AMOUNT=$(echo $HISTORY | jq -r .amount | head -n1) ; echo $AMOUNT # get last trascation amount
|
||||
if [ "$DESCRIPTION" = "Transfer Credit" ] # if last trascation is description is Transfer Credit
|
||||
@ -95,17 +127,19 @@ then
|
||||
then
|
||||
FROMTOAT=From
|
||||
ENTITY=$(echo $HISTORY | jq -r .narrative2 | head -n1) ; echo $ENTITY # get last trascation company name
|
||||
elif [ "$DESCRIPTION" = "Prepaid Top-Up" ] # if last trascation descripton is Prepaid Top-Up
|
||||
then
|
||||
FROMTOAT=To
|
||||
ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) ; echo $ENTITY # get name..idk
|
||||
fi
|
||||
send_tg
|
||||
fi
|
||||
else
|
||||
echo_delay
|
||||
echo "Nothing new....Next check in $NORMAL_DELAY seconds"
|
||||
fi
|
||||
sleep $DELAY # initiate delay read from delay file
|
||||
done
|
||||
}
|
||||
loop
|
||||
|
||||
infinite_loop(){
|
||||
while true; do
|
||||
loop
|
||||
sleep $NORMAL_DELAY
|
||||
done
|
||||
}
|
||||
infinite_loop
|
||||
|
@ -1,8 +0,0 @@
|
||||
version: '3.5'
|
||||
services:
|
||||
#########################
|
||||
app:
|
||||
build: .
|
||||
image: bml-tg-notify
|
||||
restart: always
|
||||
env_file: .env
|
24
env.sample
24
env.sample
@ -1,28 +1,18 @@
|
||||
# EDIT THESE TO YOUR CONFIG
|
||||
# BML Config
|
||||
# Your BML Username
|
||||
BML_USERNAME=''
|
||||
# Your BML Password
|
||||
BML_PASSWORD=''
|
||||
# Your BML Account ID,NOT to be confused with account number,
|
||||
# read the README.md on how to obtain this.
|
||||
BML_ACCOUNTID=''
|
||||
BML_USERNAME='' #Your BML Username
|
||||
BML_PASSWORD='' #Your BML Password
|
||||
BML_ACCOUNTID='' #Your BML Account ID,NOT to be confused with account number, read the README.md on how to obtain this.
|
||||
|
||||
# Delays
|
||||
# Delay in seconds for script to stop if logged in from another device
|
||||
APP_OPEN_DELAY='600'
|
||||
# Delay in seconds for script to check for new transactions
|
||||
NORMAL_DELAY='40'
|
||||
APP_OPEN_DELAY='600' # Delay in seconds for script to stop if logged in from another device
|
||||
NORMAL_DELAY='40' # Delay in seconds for script to check for new transactions
|
||||
|
||||
# Telegram Config
|
||||
# Your Telegram Bot API Token, Contact @BotFather on Telegram to obtain token
|
||||
TG_BOT_TOKEN=''
|
||||
# Your Telegram chat ID, This could be your user, group, supergroup or channel ID
|
||||
# add "-100" first if supergroup or channel
|
||||
TG_CHATID=''
|
||||
TG_BOT_TOKEN='' #Your Telegram Bot API Token, Contact @BotFather on Telegram to obtain token
|
||||
TG_CHATID='' #Your Telegram chat ID, This could be your user, group, supergroup or channel ID, add "-100" first if supergroup or channel
|
||||
|
||||
# DO NOT EDIT THESE UNLESS YOU KNOW WHAT YOURE DOING
|
||||
COOKIE=.cache/cookie
|
||||
curl='curl'
|
||||
TG_BOTAPI='https://api.telegram.org/bot'
|
||||
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'
|
||||
|
12
readaccounts.sh
Normal file
12
readaccounts.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
NUMBEROFACCOUNTS=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | wc -l)
|
||||
i=0;
|
||||
for account in `cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'"`
|
||||
do
|
||||
accountid[$i]=$account;
|
||||
i=$(($i+1));
|
||||
SELECT=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | head -n$i | tail -n1)
|
||||
echo $SELECT Selected
|
||||
sleep 1
|
||||
i=0
|
||||
done
|
@ -1,5 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
|
||||
SCREEN=$(basename $(pwd))
|
||||
screen -S $SCREEN -p 0 -X quit
|
||||
screen -S $SCREEN -U -m -d bash bml-tg-notify.sh
|
Loading…
x
Reference in New Issue
Block a user