Created
April 23, 2025 22:35
-
-
Save jasontucker/4c1bbd5846ddbe00a6730bfb3507d799 to your computer and use it in GitHub Desktop.
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 | |
NVR_ADDRESS="https://$1" | |
NVR_USERNAME="$2" | |
PASSWORD="$3" | |
CAMERA_ID="$4" | |
PRESET_NUMBER="$5" | |
echo "Controlling camera with ID: $CAMERA_ID and PTZ Preset Number: $PRESET_NUMBER" | |
COOKIE_TEMP=$(mktemp) | |
HEADERS_TEMP=$(mktemp) | |
function cleanup { | |
echo "Run cleanup of files" | |
rm -r $COOKIE_TEMP | |
rm -r $HEADERS_TEMP | |
} | |
trap cleanup EXIT | |
# Login and extract tokens | |
LOGIN_RESPONSE=$(curl -k -D $HEADERS_TEMP -c $COOKIE_TEMP -s -X POST \ | |
-H "Content-Type: application/json" \ | |
-d "{\"username\":\"$NVR_USERNAME\",\"password\":\"$PASSWORD\",\"rememberMe\": true,\"token\": \"\"}" \ | |
"$NVR_ADDRESS/api/auth/login") | |
TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.deviceToken') | |
CSRF_TOKEN=$(cat $HEADERS_TEMP | grep 'x-csrf-token:' | awk '{print $2}') | |
curl -k --location --request POST "$NVR_ADDRESS/proxy/protect/api/cameras/$CAMERA_ID/ptz/goto/$PRESET_NUMBER" \ | |
--header "TOKEN: $TOKEN" \ | |
--header "X-CSRF-Token: $CSRF_TOKEN" \ | |
-b $COOKIE_TEMP | |
</code> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment