-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.sh
executable file
·45 lines (40 loc) · 1.07 KB
/
remove.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
41
42
43
44
45
#!/usr/bin/env bash
ACCESS_TOKEN=$(echo "$REQUEST_BODY" | jq -r ".access_token")
PUBLIC_KEY=$(echo "$REQUEST_BODY" | jq -r ".public_key")
if [ "$ACCESS_TOKEN" == "null" ]
then
echo 'content-type: application/json'
echo 'status: 400'
echo ''
echo '{"message":"access token missing"}'
exit 0
fi
if [ "$PUBLIC_KEY" == "null" ]
then
echo 'content-type: application/json'
echo 'status: 400'
echo ''
echo '{"message":"public key missing"}'
exit 0
fi
USERNAME=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" "https://graph.microsoft.com/v1.0/me" | jq -r ".displayName")
if [ "$USERNAME" == "null" ]
then
echo 'status: 401'
echo 'content-type: text/plain'
echo 'cache-control: no-store'
echo ''
echo '{"message":"not authorized"}'
exit 0
fi
PEER_REMOVE_RESULT=$(wg set wg0 peer $PUBLIC_KEY remove)
if [ $? -ne 0 ]
then
echo 'status: 500'
echo ''
jq -n --arg details "$PEER_REMOVE_RESULT" '{"message": "unable to remove peer", "details": $details}'
else
echo 'status: 200'
echo ''
echo '{"message":"ok"}'
fi