41 lines
1.1 KiB
Bash
Executable File
41 lines
1.1 KiB
Bash
Executable File
#!/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%?}
|
|
|
|
# Combine timestamp with the keep-alive response
|
|
echo "$KEEP_ALIVE_MODIFIED, \"timestamp\":\"$CURRENT_TIME\"}"
|
|
|
|
# Sleep for the specified duration
|
|
sleep $SLEEP
|
|
done
|