-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interaction.sh
executable file
·58 lines (41 loc) · 1.17 KB
/
interaction.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
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
check_signature(){
local pub=$1
local sig=$2
local timestamp=$3
local file=$4
# Need a way to not use php here...
echo $timestamp | cat - $file | tr -d '\n' | php verify.php $pub $sig 2> /dev/null
if [[ $? -gt 0 ]]; then
return 1
else
return 0
fi
}
PUBLIC_KEY=$(jq .public_key credentials.json -r)
REQUEST_BODY=$(mktemp)
cat > "$REQUEST_BODY"
check_signature $PUBLIC_KEY $HTTP_X_SIGNATURE_ED25519 $HTTP_X_SIGNATURE_TIMESTAMP "$REQUEST_BODY"
if [[ $? -eq 1 ]]; then
echo -e "Content-Type: application/json"
echo "Status: 401 Unauthorized"
echo
echo '{"message":"Signature verification failed"}'
exit 0
fi
REQ_TYPE=$(jq '.type' "$REQUEST_BODY" -r )
if [[ $REQ_TYPE -eq 1 ]]; then
# Ping!
echo -e "Content-Type: application/json"
echo "Status: 200 OK"
echo
echo '{"type": 1}'
elif [[ $REQ_TYPE -eq 2 ]]; then
# Interaction!
bash commands-$(jq '.data.name' "$REQUEST_BODY" -r).sh "$REQUEST_BODY"
elif [[ $REQ_TYPE -eq 3 ]]; then
bash component-$(jq '.data.custom_id' "$REQUEST_BODY" -r).sh "$REQUEST_BODY"
elif [[ $REQ_TYPE -eq 5 ]]; then
bash modal-$(jq '.data.custom_id' "$REQUEST_BODY" -r).sh "$REQUEST_BODY"
fi
rm "$REQUEST_BODY"