Skip to content

Instantly share code, notes, and snippets.

@PatelUtkarsh
Last active August 16, 2023 08:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatelUtkarsh/6725a466dbe9205dfb95 to your computer and use it in GitHub Desktop.
Save PatelUtkarsh/6725a466dbe9205dfb95 to your computer and use it in GitHub Desktop.
Attendence Login or logout to greythr
#!/bin/bash
#set login & password or this will ask everytime
#login=
#password=
#comment this if you set login password on top!
read -p "User name or email: " login
echo -n Password:
read -s password
function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}
curl --silent -c ./.mrgray 'https://rtcamp.greythr.com/j_spring_security_check' -H 'Pragma: no-cache' -H 'Origin: https://rtcamp.greythr.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,gu;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://rtcamp.greythr.com/login.do?view=logout-panel' --data "j_username=$login&j_password=$password" --compressed
# we got the cookie let's eat it.
if [ "$1" == "login" ]; then
#login request
maybe_sucess=$(curl -s -b ./.mrgray 'https://rtcamp.greythr.com/v2/attendance/employee/SignIn' -X POST -H 'Pragma: no-cache' -H 'Origin: https://rtcamp.greythr.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,gu;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Accept: application/json, text/javascript' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://rtcamp.greythr.com/home.do' -H 'Content-Length: 0' --compressed | jsonValue _page-message)
elif [ "$1" == "logout" ]; then
#logout request
maybe_sucess=$(curl -s -b ./.mrgray 'https://rtcamp.greythr.com/v2/attendance/employee/SignOut' -X POST -H 'Pragma: no-cache' -H 'Origin: https://rtcamp.greythr.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,gu;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Accept: application/json, text/javascript' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://rtcamp.greythr.com/home.do' -H 'Content-Length: 0' --compressed | jsonValue _page-message)
elif [ "$1" == "status" ]; then
#status
maybe_sucess=$(curl -s -b ./.mrgray 'https://rtcamp.greythr.com/v2/employee/home/tab/attendance2' -H 'Pragma: no-cache' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,gu;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Accept: application/json, text/javascript' -H 'Referer: https://rtcamp.greythr.com/home.do' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Cache-Control: no-cache' --compressed | sed -n '/table-striped swipeDetails"*/,/<\/tr>/p' | grep 'td' | sed -e 's/<[^>]*>//g')
fi
#print message which ment to display on front end.
echo $maybe_sucess
exit
@PatelUtkarsh
Copy link
Author

Version 1.1

Usage:

bash greythr.sh login
bash greythr.sh status
bash greythr.sh logout

@vipulbhj
Copy link

will you be making something for version 3 ?

@PatelUtkarsh
Copy link
Author

Hey @vipulbhj, No, as I no longer have access to greythr and company no longer ask for attendance.

@M4abrams
Copy link

M4abrams commented Aug 16, 2023

Hi @PatelUtkarsh ,

I know I am 8 years late. But this is awesome.

I would like to repurpose the above code for my company's GreytHR portal.
Could you assist me with info on how to get the urls listed out in line#18 for my use-case? Where do I get these urls?

curl --silent -c ./.mrgray 'https://rtcamp.greythr.com/j_spring_security_check' -H 'Pragma: no-cache' -H 'Origin: https://rtcamp.greythr.com' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,gu;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: application/json, text/javascript' -H 'Cache-Control: no-cache' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://rtcamp.greythr.com/login.do?view=logout-panel' --data "j_username=$login&j_password=$password" --compressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment