Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d0196f645e | ||
|
7464c54c5e | ||
|
3e251a0429 | ||
|
a098bdd426 | ||
|
b9bb5db4e2 |
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)
|
||||
|
102
bml-tg-notify.sh
102
bml-tg-notify.sh
@ -1,18 +1,27 @@
|
||||
#!/bin/bash
|
||||
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 ""
|
||||
}
|
||||
|
||||
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(){
|
||||
@ -23,14 +32,28 @@ 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
|
||||
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 "Next check in $DELAY seconds"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
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(){
|
||||
@ -41,29 +64,36 @@ 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
|
||||
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
|
||||
@ -72,7 +102,13 @@ then
|
||||
echo "=============" ; echo NEW DAY ; echo "============="
|
||||
# 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,9 +131,15 @@ then
|
||||
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
|
||||
|
18
env.sample
18
env.sample
@ -1,12 +1,18 @@
|
||||
# EDIT THESE TO YOUR CONFIG
|
||||
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.
|
||||
# BML Config
|
||||
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.
|
||||
|
||||
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
|
||||
# Delays
|
||||
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
|
||||
COOKIE=.cache/cookie #No need to change
|
||||
COOKIE=.cache/cookie
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user