#!/bin/bash IPT="/sbin/iptables" # Modified, Customized, and Finalized by CCNA HUB - Imad Daou - emaddaou@gmail.com # Tested and verified to be working fine with Single VPS as Hosting Hub Solution. # Fore more information about the Progress Bar: https://raw.githubusercontent.com/haikieu/shell-progressbar/master/progressbar.sh function delay() { sleep 0.2; } # # Description : print out executing progress # CURRENT_PROGRESS=0 function progress() { PARAM_PROGRESS=$1; PARAM_STATUS=$2; if [ $CURRENT_PROGRESS -le 0 -a $PARAM_PROGRESS -ge 0 ] ; then echo -ne "[.....................................................] (0%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 5 -a $PARAM_PROGRESS -ge 5 ] ; then echo -ne "[###..................................................] (5%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 10 -a $PARAM_PROGRESS -ge 10 ]; then echo -ne "[######...............................................] (10%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 15 -a $PARAM_PROGRESS -ge 15 ]; then echo -ne "[########.............................................] (15%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 20 -a $PARAM_PROGRESS -ge 20 ]; then echo -ne "[###########..........................................] (20%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 25 -a $PARAM_PROGRESS -ge 25 ]; then echo -ne "[#############........................................] (25%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 30 -a $PARAM_PROGRESS -ge 30 ]; then echo -ne "[################.....................................] (30%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 35 -a $PARAM_PROGRESS -ge 35 ]; then echo -ne "[###################..................................] (35%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 40 -a $PARAM_PROGRESS -ge 40 ]; then echo -ne "[######################...............................] (40%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 45 -a $PARAM_PROGRESS -ge 45 ]; then echo -ne "[########################.............................] (45%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 50 -a $PARAM_PROGRESS -ge 50 ]; then echo -ne "[###########################..........................] (50%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 55 -a $PARAM_PROGRESS -ge 55 ]; then echo -ne "[##############################.......................] (55%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 60 -a $PARAM_PROGRESS -ge 60 ]; then echo -ne "[#################################....................] (60%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 65 -a $PARAM_PROGRESS -ge 65 ]; then echo -ne "[####################################.................] (65%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 70 -a $PARAM_PROGRESS -ge 70 ]; then echo -ne "[#######################################..............] (70%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 75 -a $PARAM_PROGRESS -ge 75 ]; then echo -ne "[##########################################...........] (75%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 80 -a $PARAM_PROGRESS -ge 80 ]; then echo -ne "[##############################################.......] (80%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 85 -a $PARAM_PROGRESS -ge 85 ]; then echo -ne "[##################################################...] (90%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 90 -a $PARAM_PROGRESS -ge 90 ]; then echo -ne "[#####################################################] (100%) $PARAM_PHASE \r" ; delay; fi; if [ $CURRENT_PROGRESS -le 100 -a $PARAM_PROGRESS -ge 100 ];then echo -ne '\x1B[01;92m Done! \x1B[0m \n' ; delay; fi; CURRENT_PROGRESS=$PARAM_PROGRESS; } echo echo -e "\x1B[01;93m#### ####\x1B[0m" echo -e "\x1B[01;92m# Preparing Custom Admin White-list Loader Script for IPtables #\x1B[0m" echo -e "\x1B[01;92m# Please be patient. The process might take few minutes #\x1B[0m" echo -e "\x1B[01;93m#### ####\x1B[0m" echo sleep 5 ################################################################################################################################# echo -e "\x1B[01;93m-----------------------------------------------------\x1B[0m" echo -e "\x1B[01;92m [+]\x1B[0m loading Custom Admin White-listed IPs..." echo -e "\x1B[01;93m-----------------------------------------------------\x1B[0m" sleep 5 mkdir -p /etc/network/iptables/whitelists/ WHITELIST="CUSTOM-ADMIN-WHITELIST" ALLOWIPMSG="ALLOWING WHITELISTED IPS:" ALLOWEDIPS="/etc/network/iptables/whitelists/custom-admin-allow.ips" sed --in-place '/:/d' $ALLOWEDIPS echo awk '/^[0-9]/{for(i=1;i<=NF;i++)if(a[$i]++==1) print "\x1B[01;93m Duplicate IP : \x1B[0m",$i;}' $ALLOWEDIPS [ -f $ALLOWEDIPS ] && GOODIPS=$(egrep -v -E "^#|^$" $ALLOWEDIPS) if [ -f $ALLOWEDIPS ]; then # If exit, flush and delete the Chain $IPT -F $WHITELIST >/dev/null 2>&1 $IPT -X $WHITELIST >/dev/null 2>&1 # Create the IPtables Chain $IPT -N $WHITELIST >/dev/null 2>&1 sleep 2 echo -e "\x1B[01;92m [+]\x1B[0m Loading `wc -l $ALLOWEDIPS | cut -d' ' -f1` White-listed IP Addresses. Please be patient..." echo echo -e "\x1B[01;93m Estimate Time:\x1B[0m is based on Hardware Resources. 4000 IP Addresses will take roughly 2 to 7 Minutes to load inside the Memory." echo echo -e "\x1B[01;92m Elapsed Time: \x1B[0m" echo for ipallow in $GOODIPS do #$IPT -A $WHITELIST -s $ipallow -j LOG --log-level 7 --log-prefix "$ALLOWIPMSG" $IPT -A $WHITELIST -p tcp -m multiport --dport 80,443 -s $ipallow -j ACCEPT done|pv -t $IPT -I INPUT -j $WHITELIST $IPT -I OUTPUT -j $WHITELIST $IPT -I FORWARD -j $WHITELIST fi echo progress 100 "Done " echo exit 0