diff --git a/fetchname.sh b/fetchname.sh index 9788fcf..ff035f2 100755 --- a/fetchname.sh +++ b/fetchname.sh @@ -4,6 +4,10 @@ source .env 2> /dev/null accountNo=$1 +COOKIE=$(curl -s $COOKIE_SERVER/getcookie) +IBSID=$(echo $COOKIE | jq -r .IBSID) +QL_0=$(echo $COOKIE | jq -r .ql_0) + curl -s 'https://faisanet.mib.com.mv/ajaxBeneficiary/getAccountName' \ -H "cookie: ql_0=${QL_0}; IBSID=${IBSID}" \ --data-raw "accountNo=${accountNo}" diff --git a/keepalive.sh b/keepalive.sh index 74839b0..85eaa5a 100755 --- a/keepalive.sh +++ b/keepalive.sh @@ -1,15 +1,34 @@ #!/bin/bash + +request_new_cookie(){ +curl -s $COOKIE_SERVER/newcookie > /dev/null +} + while true; do source .env 2> /dev/null # Get current date and time CURRENT_TIME=$(date -u '+%Y-%m-%dT%H:%M:%S.%3NZ') + COOKIE=$(curl -s $COOKIE_SERVER/getcookie) + IBSID=$(echo $COOKIE | jq -r .IBSID) + QL_0=$(echo $COOKIE | jq -r .ql_0) + # Make the keep-alive request KEEP_ALIVE=$(curl -s 'https://faisanet.mib.com.mv/aProfile/keepAlive' \ -X 'POST' \ -H "cookie: ql_0=${QL_0}; IBSID=${IBSID}") + # Check for session expiration + SUCCESS=$(echo "$KEEP_ALIVE" | jq -r .success) + RESPONSE_CODE=$(echo "$KEEP_ALIVE" | jq -r .responseCode) + + if [[ "$SUCCESS" == "false" && "$RESPONSE_CODE" == "3" ]]; then + echo "Session expired. Requesting new cookie..." + request_new_cookie + continue # Restart the loop + fi + # Remove the last closing brace from KEEP_ALIVE KEEP_ALIVE_MODIFIED=${KEEP_ALIVE%?} diff --git a/tx.sh b/tx.sh index 113c84b..ef0fdb8 100755 --- a/tx.sh +++ b/tx.sh @@ -2,6 +2,10 @@ source .env 2> /dev/null +COOKIE=$(curl -s $COOKIE_SERVER/getcookie) +IBSID=$(echo $COOKIE | jq -r .IBSID) +QL_0=$(echo $COOKIE | jq -r .ql_0) + curl 'https://faisanet.mib.com.mv/ajaxAccounts/trxHistory' \ -H "cookie: ql_0=${QL_0}; IBSID=${IBSID}" \ --data-raw "accountNo=${ACCOUNT_NUMBER}&trxNo=&trxType=0&sortTrx=date&sortDir=desc&fromDate=&toDate=&start=1&end=20&includeCount=1" -s \