-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9e9685c Pulling in lmtca/cloudflare-cli code 83a8af6 Added comments and cleaned up code. Passed proxied as true when creating records. f0ed35f Automatically proxy all creations, will need to add a means to control this later on. Excluded TXT's from being set to proxied automatically 74123f0 Added checks for 127.0.0.0/8 proxying on A records. f4f0336 Cleaning up code 8858452 Added cf-cli to save fingers. de664e0 Updated usage text for TXT records to be contained in double quotes 67587c5 Improved code overall b1e60c9 More code documentation 4e93cd0 More code documentation and code cleanup eb8f014 Updated 58499cb Updated 3c9e180 Fixed help messaging by removing tabs and updated version number. ffdaa19 Start of refactoring 70a3b09 feat(domain-search): Create domain-search script for search domains on Cloudflare afb4a47 chore(tests): Added random domains to tests/domains.txt c373824 enhance(domain-search): Compeleted the development of domain-search.sh eaf3658 feat(cache): Added a caching mechanism for larger accounts a72a6d3 chore(rename): Renamed domain-search.sh to cf-domain-search.sh and setup symlink
- Loading branch information
1 parent
51972b9
commit 1dc1814
Showing
9 changed files
with
1,577 additions
and
1,001 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cloudflare.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cf-domain-search.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#!/bin/bash | ||
# -- A simple script to search for domains in your Cloudflare account | ||
# -- Requires jq (https://stedolan.github.io/jq/) | ||
# -- Usage: ./domain-search.sh <domain> | ||
# -- Example: ./domain-search.sh example.com or ./domain-search.sh -f domains.txt | ||
|
||
# -- Variables | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # -- Get current script directory | ||
CACHE_FILE="$HOME/.cf-domain-search.cache" | ||
|
||
# -- Check if jq is installed | ||
if ! [ -x "$(command -v jq)" ]; then | ||
echo 'Error: jq is not installed.' >&2 | ||
exit 1 | ||
fi | ||
|
||
# -- usage | ||
usage() { | ||
USAGE=\ | ||
"Usage: ./domain-search.sh (-f file.txt|<domain>) [-h] [-t] [-d] | ||
Example: ./domain-search.sh example.com or ./domain-search.sh -f domains.txt | ||
Options | ||
-h, --help Display this help and exit | ||
-f, --file File containing list of domains to search for | ||
-t, --test Test file containing list of domains to search for | ||
-d, --debug Enable debug mode | ||
-c, --cache Enable cache mode | ||
" | ||
echo "$USAGE" | ||
} | ||
|
||
# -- Debug | ||
_debug () { | ||
[[ $DEBUG ]] && echo "DEBUG: $1" | ||
} | ||
_success () { echo -e "\033[0;42m${*} \e[0m"; } | ||
_fail () { echo -e "\e[41m\e[97m${*} \e[0m"; } | ||
|
||
# -- All args | ||
ALL_ARGS="${*}" | ||
|
||
# -- Process arguments | ||
POSITIONAL=() | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
|
||
case $key in | ||
-h|--help) | ||
HELP=YES | ||
shift # past argument | ||
;; | ||
-t|--test) | ||
TEST="1" | ||
shift # past argument | ||
;; | ||
-f|--file) | ||
DOMAIN_FILE="$2" | ||
shift # past argument | ||
shift # past value | ||
;; | ||
-c|--cache) | ||
CACHE=1 | ||
shift # past argument | ||
;; | ||
-d|--debug) | ||
DEBUG="1" | ||
shift # past argument | ||
;; | ||
*) # unknown option | ||
POSITIONAL+=("$1") # save it in an array for later | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
set -- "${POSITIONAL[@]}" # restore positional parameters | ||
|
||
|
||
# -- All args | ||
_debug "ALL_ARGS: $ALL_ARGS" | ||
_debug "\$1: $1" | ||
_debug "TEST: $TEST" | ||
_debug "DOMAIN_FILE: $DOMAIN_FILE" | ||
_debug "DEBUG: $DEBUG" | ||
[[ -n $1 ]] && DOMAIN="$1" | ||
|
||
# -- Check if argument is passed | ||
if [[ -z "$DOMAIN" && -z $DOMAIN_FILE ]]; then | ||
usage | ||
echo "Error: No domain specified" | ||
exit 1 | ||
elif [[ $HELP ]]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
|
||
# -------------------- | ||
# -- Main | ||
# -------------------- | ||
|
||
echo "Getting list of domains using ./cloudflare" | ||
if [[ $TEST ]]; then | ||
CF_DOMAINS=$(cat $SCRIPT_DIR/tests/domains.txt) | ||
_debug "CF_DOMAINS: $CF_DOMAINS" | ||
else | ||
if [[ $CACHE ]]; then | ||
if [[ -f $CACHE_FILE ]]; then | ||
# -- Check if cache file is older than an hour | ||
if [[ $(find $CACHE_FILE -mmin +60) ]]; then | ||
echo "-- Cache file is older than an hour, deleting cache file and pulling in fresh cache" | ||
rm $CACHE_FILE | ||
CF_DOMAINS=$($SCRIPT_DIR/cloudflare list zones | awk '{print $1}') | ||
echo "-- Caching domains to $HOME/.cf-domain-search.cache" | ||
echo "$CF_DOMAINS" > $HOME/.cf-domain-search.cache | ||
else | ||
echo "-- Cache file is not older than an hour, using cache file" | ||
CF_DOMAINS=$(cat $CACHE_FILE) | ||
fi | ||
else | ||
echo "-- Cache file does not exist, pulling in fresh cache" | ||
CF_DOMAINS=$($SCRIPT_DIR/cloudflare list zones | awk '{print $1}') | ||
echo "-- Caching domains to $HOME/.cf-domain-search.cache" | ||
echo "$CF_DOMAINS" > $HOME/.cf-domain-search.cache | ||
fi | ||
else | ||
echo "-- Grabbing domains from Cloudflare API" | ||
CF_DOMAINS=$($SCRIPT_DIR/cloudflare list zones | awk '{print $1}') | ||
fi | ||
fi | ||
echo "" | ||
|
||
if [[ $DOMAIN_FILE ]]; then | ||
if [[ -f $DOMAIN_FILE ]]; then | ||
# -- Search for matching domains from $FILE in Cloudflare account | ||
echo "Search for matching domains from the file $DOMAIN_FILE in Cloudflare account" | ||
for domain in $(cat $DOMAIN_FILE); do | ||
SEARCH=$(grep '^'$domain'$' <<< "${CF_DOMAINS[@]}") | ||
if [[ $? == 0 ]]; then | ||
_success "$domain - FOUND" | ||
else | ||
_fail "$domain - NOTFOUND" | ||
fi | ||
done | ||
else | ||
echo "Error: $DOMAIN_FILE does not exist" | ||
exit 1 | ||
fi | ||
else | ||
# -- Search for matching domain from stdin in Cloudflare account | ||
echo "Search for matching domain $DOMAIN in Cloudflare account" | ||
SEARCH=$(echo "${CF_DOMAINS[@]}" | grep "$DOMAIN") | ||
if [[ $? == 0 ]]; then | ||
_success "$DOMAIN - FOUND" | ||
else | ||
_fail "$DOMAIN - NOTFOUND" | ||
fi | ||
fi | ||
|
||
|
Oops, something went wrong.