Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created November 10, 2019 18:51
Show Gist options
  • Select an option

  • Save saswata-dutta/fb1742f930d82bdabd01a1b1ad7c5d1a to your computer and use it in GitHub Desktop.

Select an option

Save saswata-dutta/fb1742f930d82bdabd01a1b1ad7c5d1a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -xv
user=$1
pass=$2
# get token
pass_md5="$(echo -n "$pass" | md5)"
pass_sha512="$(echo -n "${pass}"'ewor88493GVHBMe@' | sha512sum | cut -f1 -d' ')"
enc_pass="${pass_md5},${pass_sha512}"
udid=$(uuidgen)
# $(echo `printf "$RANDOM%0.s" {1..16}` | cut -c1-16)
auth_payload="{\"username\": \"${user}\", \"password\": \"${enc_pass}\", \"enc\": 1, \"UDID\": \"${udid}\"}"
echo ; echo " auth_payload " $auth_payload ; echo
auth_response=$(curl -X POST \
https://rivigo.darwinbox.in/Mobileapi/auth \
-H 'Content-Type: application/json' \
-d "${auth_payload}")
echo ; echo " auth_response " $auth_response ; echo
token=$(echo -n $auth_response | jq -r ".token")
# verify previous check-in
checkin_list_response=$(curl -X GET "https://rivigo.darwinbox.in/Mobileapi/checkInData?token=${token}")
today=$(date +%d-%b)
jq_query=".checkin_details[\"${today}\"][].checkin_status"
already_checked_in=$(echo -n $checkin_list_response | jq "${jq_query}" | sort -nr | uniq | head -n 1)
if [ 1 -eq $already_checked_in ]
then
echo "[ERROR] Already checked in for today"
exit 1
fi
# do check-in
location=$(echo -n "F32C+JF Gurugram, Haryana, India" | base64)
latlng="28.4515875,77.07123828125"
checkin_payload="{\"location\": \"${location}\", \"latlng\": \"${latlng}\", \"message\": \"in office\", \"in_out\": 1}"
echo ; echo " checkin_payload " $checkin_payload ; echo
checkin_response=$(curl -X POST \
"https://rivigo.darwinbox.in/Mobileapi/CheckInPost?token=${token}" \
-H 'Content-Type: application/json' \
-d "${checkin_payload}")
echo ; echo " checkin_response " $checkin_response ; echo
checkin_response_status=$(echo -n "${checkin_response}" | jq -r ".status")
if [ 1 -ne $checkin_response_status ]
then
echo "[ERROR] Bad status response from checkin"
exit 1
fi
# verify current check-in
checkin_list_response=$(curl -X GET "https://rivigo.darwinbox.in/Mobileapi/checkInData?token=${token}")
already_checked_in=$(echo -n $checkin_list_response | jq "${jq_query}" | sort -n | uniq)
if [ 1 -ne $already_checked_in ]
then
echo "[ERROR] No checkin for today"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment