-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetDpnMode.sh
40 lines (32 loc) · 1.33 KB
/
setDpnMode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
api_host="${DEEPER_API_HOST:-34.34.34.34}"
# Check if all three arguments are provided
if [ $# -lt 3 ]; then
echo "Usage: $0 <Mode> <username> <password> \n if mode is full specify tunnel code: $0 <Mode> <tunnelCode> <username> <password> \n Note: Killswitch is alsways false for now."
exit 1
fi
# Parse the arguments
mode=$1
if [ "$mode" == "full" ]; then
tunnel=$2
username=$3
password=$4
else
username=$2
password=$3
fi
# Run the getToken.sh script and store the output in a variable
token_output=$(/opt/getToken.sh $username $password)
# Extract the Bearer token using grep and cut
bearer_token=$(echo "$token_output" | grep -o '"token":"Bearer[^"]*' | cut -d '"' -f 4)
echo "Token: $bearer_token"
# Build the cURL request command
if [ "$mode" == "full" ]; then
curl_command="curl -k 'https://$api_host/api/smartRoute/setDpnMode' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '{\"dpnMode\":\"$mode\",\"tunnelCode\":\"$tunnel\",\"killSwitch\":false}' -H 'Content-Type: application/json'"
else
curl_command="curl -k 'https://$api_host/api/smartRoute/setDpnMode' -X 'POST' -H 'Authorization: $bearer_token' --data-binary '{\"dpnMode\":\"$mode\"}' -H 'Content-Type: application/json'"
fi
# Print the cURL command to console
echo "Executing cURL command: $curl_command"
# Execute the cURL command
eval "$curl_command"