-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch-domains-list.bash
executable file
·136 lines (115 loc) · 4.34 KB
/
fetch-domains-list.bash
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
QUIET=false
while getopts ":hqd:" option; do
case $option in
h) # display Help
showHelp
exit 1;;
q) # quiet
QUIET=true;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
esac
done
#get all domains for token and populate a list
#cfcli zones -f csv | cut -d ',' -f1 > data/domains.list
function fetchDomainsList(){
local __resultvar=$1
if [ $QUIET = true ]; then
myDomainList="$(cfcli zones -f csv | cut -d ',' -f1 > data/domains.list)"
#exit 0
else
local myDomainList="$(cfcli zones -f csv | cut -d ',' -f1| tee data/domains.list)"
fi
if [[ "$__resultvar" ]]; then
eval $__resultvar="'$myDomainList'"
else
echo "$myDomainList"
fi
}
showhelp(){
# Display Help
echo "Hi! Please specify options."
echo
echo "Syntax: fetch-domains-list.bash [-q|h]"
echo "options:"
echo "-h --help Print this Help."
echo "-q --quiet Execute quietly."
echo
}
#fetchDomainsList domainList #function accessable through this method
#echo $domainList
domainList="$(fetchDomainsList)" #or function accessable through this method
if [ $QUIET = false ]; then echo "$domainList" || exit;fi
# using cloudflare-cli - install with `npm install cloudflare-cli`
# https://github.com/danielpigott/cloudflare-cli
# https://github.com/shakes80/cloudflare-cli
# cfcli - help for reference
# NAME
# cfcli - Interact with cloudflare from the command line
# SYNOPSIS
# cfcli [options] command [parameters]
# OPTIONS:
# -c --config Path to yml file with config defaults (defaults to ~/.cfcli.yml
# -e --email Email of your cloudflare account
# -k --token Token for your cloudflare account
# -u --account Choose one of your named cloudflare accounts from .cfcli.yml
# -d --domain Domain to operate on
# -a --activate Activate cloudflare after creating record (for addrecord)
# -f --format Format when printing records (csv,json or table)
# -t --type Type of record (for dns record functions)
# -p --priority Set priority when adding a record (MX or SRV)
# -q --query Comma separated filters to use when finding a record
# -l --ttl Set ttl on add or edit (120 - 86400 seconds, or 1 for auto)
# -h --help Display help
# COMMANDS:
# add <name> <content>
# Add a DNS record. Use -a to activate cf after creation
# always-use-https on|off
# Toggle Always Use HTTPS mode on/off
# devmode on|off
# Toggle development mode on/off
# disable <name> [content]
# Disable cloudflare caching for given record and optionally specific value
# edit <name> <content>
# Edit a DNS record.
# enable <name> [content]
# Enable cloudflare caching for given record and optionally specific value
# find <name> [content]
# Find a record with given name and optionally specific value
# ls
# List dns records for the domain
# purge [urls]
# Purge file at given urls (space separated) or all files if no url given
# rm <name> [content]
# Remove record with given name and optionally specific value
# zone-add <name>
# Add a zone for given name
# zones
# List domains in your cloudflare account
# Examples
# Add a new A record (mail) and activate cloudflare (-a)
# cfcli -a -t A add mail 8.8.8.8
# Edit a record (mail) and set the TTL
# cfcli --ttl 120 edit mail 8.8.8.8
# Add an SRV record (then 3 numbers are priority, weight and port respectively)
# cfcli -t SRV add _sip._tcp.example.com 1 1 1 example.com
# Find all records matching the content value test.com
# cfcli find -q content:test.com
# Remove all records with the name test
# cfcli rm test
# Remove record with name test, type of A and value 1.1.1.1
# cfcli rm test -q content:1.1.1.1,type:A
# Enable cloudflare for any records that match test
# cfcli enable test
# Enable cloudflare for a record test with the value test.com
# cfcli enable test test.com
# Export domain records for test.com to csv
# cfcli -d test.com -f csv listrecords > test.csv
# Purge a given files from cache
# cfcli -d test.com purge http://test.com/script.js http://test.com/styles.css
# Enable dev mode for test.com domain
# cfcli -d test.com devmode on
# Add the zone test.com
# cfcli zone-add test.com