Compare commits

...

5 Commits
main ... beta

Author SHA1 Message Date
Shihaam Abdul Rahman
d0196f645e partial doc update 2021-09-19 23:51:05 +05:00
Shihaam Abdul Rahman
7464c54c5e now delay from .env instead of separate file 2021-09-19 23:43:39 +05:00
Shihaam Abdul Rahman
3e251a0429 same as main 2021-09-19 23:41:50 +05:00
Shihaam Abdul Rahman
a098bdd426 del 2021-09-19 23:40:57 +05:00
Shihaam Abdul Rahman
b9bb5db4e2 i forgot 2021-09-19 20:14:44 +05:00
4 changed files with 101 additions and 48 deletions

View File

@ -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. - 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 - 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. 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, - 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! 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 - If you login to web or mobile app while script is running, It will pause for APP_NORMAL_DELAY seconds befor running again.
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)
## Getting started. ## Getting started.
### Requriements ### Requriements
@ -31,19 +27,16 @@ cd bml-tg-notify
chmod +x bml-tg-notify.sh chmod +x bml-tg-notify.sh
cp env.sample .env 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) - [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 ### Execute the script
``` ```
./bml-tg-notify.sh ./bml-tg-notify.sh
``` ```
- Maybe run in a screen to run in background? - 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 ## Bugs
- [You tell me :)](https://github.com/shihaamabr/bml-tg-notify/issues/new) - [You tell me :)](https://github.com/shihaamabr/bml-tg-notify/issues/new)

View File

@ -1,18 +1,27 @@
#!/bin/bash #!/bin/bash
source .env # import credentials, tg api, cookie path, bml api 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(){ 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 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 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 curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE # select Personal Profile
echo ""
echo ""
}
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(){ getaccountdetails(){
@ -23,14 +32,28 @@ CURRENCY=$(echo $REQACCOUNTDETAILS | jq -r .currency)
} }
send_tg(){ send_tg(){
TGTEXT=$(echo $DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram 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 curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT #send to telegram
echo "Next check in $DELAY seconds" echo ""
echo ""
} }
req_history(){ req_history(){
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 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 #LOGIN_STATUS=$(echo $REQ_HISTORY | jq -r .success) ; echo $LOGIN_STATUS
echo ""
echo ""
echo ===========
} }
check_diff(){ check_diff(){
@ -41,29 +64,36 @@ CHECKDIFF2=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF2 # check new history
} }
read_delay(){ 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 init
login login
getaccountdetails
loop(){ 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 for account in `cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'"`
do
if [ "$LOGIN_STATUS" != "true" ] accountid[$i]=$account;
then i=$(($i+1));
login BML_ACCOUNTID=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | head -n$i | tail -n1)
break & loop echo ""
fi echo $BML_ACCOUNTID Selected
echo ""
check_diff getaccountdetails
read_delay req_history
check_diff
read_delay
if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history
then then
@ -72,7 +102,13 @@ then
echo "=============" ; echo NEW DAY ; echo "=============" 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 else
echo ""
echo ""
echo ==============
echo History of $ACCOUNTTYPE - $ACCOUNTNUMBER
echo $HISTORY | jq echo $HISTORY | jq
echo ""
echo ""
DESCRIPTION=$(echo $HISTORY | jq -r .description | head -n1) ; echo $DESCRIPTION # get last trascation description 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 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 if [ "$DESCRIPTION" = "Transfer Credit" ] # if last trascation is description is Transfer Credit
@ -95,9 +131,15 @@ then
send_tg send_tg
fi fi
else else
echo_delay echo "Nothing new....Next check in $NORMAL_DELAY seconds"
fi fi
sleep $DELAY # initiate delay read from delay file
done done
} }
loop
infinite_loop(){
while true; do
loop
sleep $NORMAL_DELAY
done
}
infinite_loop

View File

@ -1,12 +1,18 @@
# EDIT THESE TO YOUR CONFIG # EDIT THESE TO YOUR CONFIG
BML_USERNAME='' #Your BML Username # BML Config
BML_PASSWORD='' #Your BML Password BML_USERNAME='' #Your BML Username
BML_ACCOUNTID='' #Your BML Account ID,NOT to be confused with account number, read the README.md on how to obtain this. 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.
TG_BOT_TOKEN='' #Your Telegram Bot API Token, Contact @BotFather on Telegram to obtain token # Delays
TG_CHATID='' #Your Telegram chat ID, This could be your user, group, supergroup or channel ID, add "-100" first if supergroup or channel 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
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 # DO NOT EDIT THESE UNLESS YOU KNOW WHAT YOURE DOING
COOKIE=.cache/cookie #No need to change COOKIE=.cache/cookie
TG_BOTAPI='https://api.telegram.org/bot' TG_BOTAPI='https://api.telegram.org/bot'
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'

12
readaccounts.sh Normal file
View 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