Last active
March 20, 2019 21:03
-
-
Save Diederikjh/80701717989cfce6bfaaa2e4c2b921a1 to your computer and use it in GitHub Desktop.
Get valid cookie from camera and set it on tinyproxy config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# gets cookie for camera, and sets it for reverse proxy for ZM | |
read -sp "Please enter camera http login password\ | |
" PASSWORD | |
USER=diederik | |
# Do login | |
curl -v 'http://192.168.0.11/login.cgi' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0' -H 'Accept: */*' -H 'Accept-Language: en-ZA,en-GB;q=0.8,en-US;q=0.5,en;q=0.3' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' --data "username=$USER&password=$PASSWORD" --cookie-jar cookies.txt | |
cookie=$(tail -n 1 cookies.txt | grep -E -o '\s(\w+)$') | |
# strips whitespace | |
cookie=$(echo $cookie | xargs) | |
echo "Found cookie value 1 $cookie" | |
# NOTE, post value of cookie again, as new param (for some reason) | |
curl -v 'http://192.168.0.11/login.cgi' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0' -H 'Accept: */*' -H 'Accept-Language: en-ZA,en-GB;q=0.8,en-US;q=0.5,en;q=0.3' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' --data "username=$USER&password=$PASSWORD&AIROS_SESSIONID=$cookie" --cookie-jar cookies.txt -b cookies.txt | |
cookie=$(tail -n 1 cookies.txt | grep -E -o '\s(\w+)$') | |
cookie=$(echo $cookie | xargs) | |
echo "Found cookie value 2 $cookie" | |
# get / as this updates the cookie to be valid (finally) | |
curl -v 'http://192.168.0.11/index.cgi' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0' -H 'Accept: */*' -H 'Accept-Language: en-ZA,en-GB;q=0.8,en-US;q=0.5,en;q=0.3' --compressed --cookie-jar cookies.txt -b cookies.txt | |
cookie=$(tail -n 1 cookies.txt | grep -E -o '\s(\w+)$') | |
cookie=$(echo $cookie | xargs) | |
echo "Found cookie value 3 $cookie" | |
#Put value of cookie in tinyproxy config file | |
sudo sed -i -e "s/AIROS_SESSIONID=.*/AIROS_SESSIONID=$cookie\"/g" /etc/tinyproxy/tinyproxy.conf | |
sudo service tinyproxy restart | |
#Note: to test go to: http://127.0.0.1:8888/cam/snapshot.cgi | |
#cleanup | |
rm cookies.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment