-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfbot.sh
85 lines (68 loc) · 3.15 KB
/
cfbot.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#####################################################
# Original script written by Spencer Anderson #
#####################################################
#
#####################################################
# Version History #
#####################################################
# -+- Version 0.1 - April 2017 -+- #
# Allows user to turn on or off developer mode for #
# a domain name in Cloudflare. #
# #
# -+- Version 0.2 - July 2017 -+- #
# Users now see which domains they have in their #
# Cloudflare account. #
#####################################################
echo "==============================================================";
echo "========+ Welcome to Cloudflare Settings Bot v0.2 +===========";
echo "==============================================================";
echo;
# This function prints current domains on the account and gives the user
# a choice for which one.
domainsList=($(curl -s -X GET "https://api.cloudflare.com/client/v4/zones"
-H "X-Auth-Email: EMAIL"
-H "X-Auth-Key: APIKEY"
-H "Content-Type: application/json" |
grep -Po '{*"name":"(.*?)"' | awk -F'[":]' '/\.[a-z].*/ { print $5 }'))
domainRequest()
{
C=1
for NUM in "${domainsList[@]}"
do
printf "%2d. %-20s\n" "$C" "$NUM"
((C=C+1))
done
}
printf "Choose which of the following domains: \n%-20s\n" "$(domainRequest)"
read domainNumber
grab_devmode=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/ZONEID/settings/development_mode" -H "X-Auth-Email: EMAIL" -H "X-Auth-Key: APIKEY" -H "Content-Type: application/json" |sed 's|[{"]||g' | awk -F'[:,]' '{ print $3 " is " $5 }');
echo "The current status of ${grab_devmode}";
dev_settings ()
{
echo "Would you like to turn DevMode On or Off?";
read settingsMode;
echo "You selected turn DevMode ${settingsMode}"; echo;
if [[ "$settingsMode" = on ]]; then
echo "Turning DevMode On";
devmode_ON=$(curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/ZONEID/settings/development_mode" \
-H "X-Auth-Email: EMAIL" \
-H "X-Auth-Key: APIKEY" \
-H "Content-Type: application/json" \
--data '{"value":"on"}');
devClean=($(echo "${devmode_ON}" | sed 's|[{"]||g' | awk -F'[:,]' '{ print $3 " is " $5 }'));
echo "${devClean[@]}, page results will no longer be cached.";
elif [[ "$settingsMode" = off ]]; then
echo "Turning DevMode Off"
devmode_OFF=$(curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/ZONEID/settings/development_mode" \
-H "X-Auth-Email: EMAIL" \
-H "X-Auth-Key: APIKEY" \
-H "Content-Type: application/json" \
--data '{"value":"off"}')
devClean=($(echo "${devmode_OFF}" | sed 's|[{"]||g' | awk -F'[:,]' '{ print $3 " is " $5 }'));
echo "${devClean[@]}, page results are being cached."
else
echo "You entered the wrong information, go back and try again.";
fi
}
dev_settings;