Skip to content

Commit

Permalink
Relase 1.2.0
Browse files Browse the repository at this point in the history
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
jordantrizz committed May 26, 2023
1 parent 51972b9 commit 1dc1814
Show file tree
Hide file tree
Showing 9 changed files with 1,577 additions and 1,001 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Usage: cloudflare check zone <zone>
- curl
- php (php-cli) 5.x

# Code Stewardship
* Originally created by @bAndie91
* Taken over by @jordanttrizz on 01/26/2022

## DONATE

Support me to improve cloudflare-cli

<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KAXRPGK8YBRVG"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" /></a>

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.1
1 change: 1 addition & 0 deletions cf-cli
1 change: 1 addition & 0 deletions cf-domain-search
163 changes: 163 additions & 0 deletions cf-domain-search.sh
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


Loading

0 comments on commit 1dc1814

Please sign in to comment.