Last active
April 15, 2019 16:04
-
-
Save t0mtaylor/d36d482be8284fb4cc4866eb05d53d97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# StatusCake Auto IPs | |
# Author: @t0mtaylor, @HKirste | |
# Origin: https://github.com/hkirste/CloudFlare-auto-IPs | |
# Date: 25/10/2016 | |
# Version 0.2 | |
# wget -q https://gist.githubusercontent.com/t0mtaylor/d36d482be8284fb4cc4866eb05d53d97/raw/sc.sh -O sc.sh && chmod +x sc.sh && ./sc.sh | |
TYPE="allow" | |
CRON="/etc/cron.d/sc.cron" | |
LOCATION="/usr/local/sc" | |
CSF="1" | |
CSF_LOCATION="/usr/sbin/csf" | |
IPT_LOCATION="/sbin/iptables" | |
CURRENT=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")"); | |
addtocron() { | |
rm -f $CRON | |
sleep 1 | |
service crond restart | |
sleep 1 | |
echo "SHELL=/bin/sh" > $CRON | |
echo "0 0 * * * $LOCATION >/dev/null 2>&1" >> $CRON | |
service crond restart | |
} | |
install() { | |
if [ ! -f $LOCATION ]; | |
then | |
mv $CURRENT $LOCATION | |
fi | |
addtocron | |
echo 'SC auto IPs has been installed' | |
echo 'This script has been modified by @t0mtaylor, created by @HKirste' | |
} | |
showhelp() { | |
echo 'Usage: sc.sh [OPTIONS]' | |
echo 'OPTIONS:' | |
echo '-h | --help: Show this help screen' | |
echo '-i | --install: Installs this script' | |
echo '-c | --cron: Create cron job to run this script daily' | |
echo '-t | --type: Choose between denying or allowing SC ips. Default: Allow. Valid input: ALLOW - DENNY' | |
} | |
while [ $1 ]; do | |
case $1 in | |
'-h' | '--help' | '?') | |
showhelp | |
exit | |
;; | |
'-c' | '--cron' ) | |
addtocron | |
exit | |
;; | |
'--install' ) | |
install | |
exit | |
;; | |
'-t' | '--type' ) | |
TYPE = $1 | |
if [ "$TYPE" != "deny" -o "$TYPE" != "DENY" -o "$TYPE" != "allow" -o "$TYPE" != "ALLOW" ]; then | |
TYPE="allow" | |
fi | |
;; | |
* ) | |
showhelp | |
exit | |
;; | |
esac | |
shift | |
done | |
if [ ! -f $LOCATION ]; then | |
install | |
fi | |
# https://app.statuscake.com/Workfloor/Locations.php?format=txt | |
for line in `curl --silent -L https://www.statuscake.com/API/Locations/txt`;do | |
if [ "$TYPE" == "allow" -o "$TYPE" == "ALLOW" ]; then | |
if [ CSF ]; then | |
csf -a $line | |
else | |
$IPT -I INPUT -s $CURR_LINE_IP -j ALLOW | |
fi | |
elif [ "$TYPE" == "deny" -o "$TYPE" == "DENY" ]; then | |
if [ CSF ]; then | |
csf -d $line | |
else | |
$IPT -I INPUT -s $CURR_LINE_IP -j DROP | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment