mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-02 02:29:58 +00:00
Improve Commenting and Coloring of Nginx Test 1
This commit is contained in:
parent
16ae7ad788
commit
04c5a84c3a
1 changed files with 110 additions and 47 deletions
|
@ -39,35 +39,64 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
# ************************
|
||||
# Set Terminal Font Colors
|
||||
# ************************
|
||||
|
||||
bold=$(tput bold)
|
||||
red=$(tput setaf 1)
|
||||
green=$(tput setaf 2)
|
||||
yellow=$(tput setaf 3)
|
||||
blue=$(tput setaf 4)
|
||||
magenta=$(tput setaf 5)
|
||||
cyan=$(tput setaf 6)
|
||||
white=$(tput setaf 7)
|
||||
defaultcolor=$(tput setaf default)
|
||||
|
||||
# ***************************************************************
|
||||
# Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
|
||||
# ***************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "###################################" " STARTING NGINX TEST 1" "###################################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------"
|
||||
echo "${bold}${magenta}Start Nginx Test 1"
|
||||
echo "${bold}${magenta}------------------"
|
||||
printf "\n"
|
||||
|
||||
# ******************************************************
|
||||
# Make a backup of the clean and default nginx.conf file
|
||||
# Needed to run Nginx test 3
|
||||
# ******************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "###################################" "Making backup of default nginx.conf" "###################################"
|
||||
printf "\n"
|
||||
echo "${bold}${cyan}---------------------------"
|
||||
echo "${bold}${cyan}Making backup of nginx.conf"
|
||||
echo "${bold}${cyan}---------------------------"
|
||||
printf "\n"
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_nginx_conf_backup/nginx.conf
|
||||
|
||||
# *************************************************
|
||||
# Delete default site created by Nginx Installation
|
||||
# *************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "###########################################" "Delete any default files installed by Nginx" "###########################################"
|
||||
printf "\n"
|
||||
echo "${bold}${cyan}-------------------------------------------"
|
||||
echo "${bold}${cyan}Delete any default files installed by Nginx"
|
||||
echo "${bold}${cyan}-------------------------------------------"
|
||||
printf "\n"
|
||||
sudo rm /etc/nginx/sites-available/default
|
||||
sudo rm /etc/nginx/sites-enabled/default
|
||||
sudo rm /var/www/html/*
|
||||
printf '\n%s\n%s\n%s\n\n' "#######################################" "Nginx prepared for our Testing Sequence" "#######################################"
|
||||
|
||||
# ********************************************************
|
||||
# Copy our default.vhost file into Nginx /sites-available/
|
||||
# ********************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "################################" "Get Nginx Setup for Nginx Test 1" "################################"
|
||||
printf "\n"
|
||||
echo "${bold}${cyan}---------------------"
|
||||
echo "${bold}${cyan}Setup Vhost for Nginx"
|
||||
echo "${bold}${cyan}---------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default.vhost /etc/nginx/sites-available/default.vhost
|
||||
|
||||
# **********************************************
|
||||
|
@ -81,13 +110,17 @@ sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/def
|
|||
# ***********************************************************
|
||||
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/index.html /var/www/html/index.html
|
||||
printf '\n%s\n%s\n%s\n\n' "#####################################" "Finished Nginx Setup for Nginx Test 1" "#####################################"
|
||||
|
||||
# ***********************************************
|
||||
# Fetch our install-ngxblocker file from the repo
|
||||
# ***********************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################################" "Fetch install-ngxblocker from the repo" "######################################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
echo "${bold}${magenta}Fetch install-ngxblocker from the repo"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
printf "\n"
|
||||
|
||||
sudo wget https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/install-ngxblocker -O /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
|
||||
|
@ -95,7 +128,11 @@ sudo chmod +x /usr/sbin/install-ngxblocker
|
|||
# Run Install-NgxBlocker
|
||||
# **********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Run install-ngxblocker" "######################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
echo "${bold}${magenta}Execute install-ngxblocker"
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./install-ngxblocker -s /usr/sbin/ -x
|
||||
|
||||
|
@ -103,7 +140,6 @@ sudo bash ./install-ngxblocker -s /usr/sbin/ -x
|
|||
# Set our install and setup scripts to be executable
|
||||
# **************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "##########################################################" "Set our install, setup and update scripts to be executable" "##########################################################"
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/setup-ngxblocker
|
||||
sudo chmod +x /usr/sbin/update-ngxblocker
|
||||
|
@ -112,7 +148,11 @@ sudo chmod +x /usr/sbin/update-ngxblocker
|
|||
# Run setup-ngxblocker
|
||||
# ********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################" "Run setup-ngxblocker" "####################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -i /usr/sbin/install-ngxblocker -x
|
||||
|
||||
|
@ -126,14 +166,22 @@ sudo nginx -c /etc/nginx/nginx.conf
|
|||
# Copy a dummy version of globalblacklist.conf with an older version number to test update
|
||||
# ****************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################################################" "Copy older globalblacklist.conf file to force update" "####################################################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}----------------------------------------------------"
|
||||
echo "${bold}${magenta}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${magenta}----------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
|
||||
# ****************************************************************************************
|
||||
# Run update-ngxblocker test which downloads latest globalblacklist.conf and reloads Nginx
|
||||
# ****************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Run update-ngxblocker" "######################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
|
@ -141,55 +189,59 @@ sudo bash ./update-ngxblocker -n
|
|||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# *******************************************************************************************
|
||||
# Test that update-ngxblocker can install all missing required files by deleting some of them
|
||||
# *******************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################################################################" "Delete existing files to force update-ngxblocker to re-download them" "####################################################################"
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}--------------------------------------"
|
||||
echo "${bold}${yellow}Delete Files to test update-ngxblocker"
|
||||
echo "${bold}${yellow}--------------------------------------"
|
||||
printf "\n"
|
||||
sudo rm /etc/nginx/conf.d/*.conf
|
||||
sudo rm /etc/nginx/bots.d/*.conf
|
||||
|
||||
# *************************************
|
||||
# List Directories to Confirm Deletions
|
||||
# *************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "################################################" "Confirming /etc/nginx/conf.d/ directory is EMPTY" "################################################"
|
||||
ls -la /etc/nginx/conf.d/
|
||||
printf '\n%s\n%s\n%s\n\n' "################################################" "Confirming /etc/nginx/bots.d/ directory is EMPTY" "################################################"
|
||||
ls -la /etc/nginx/bots.d/
|
||||
|
||||
# *********************************************************************************************************
|
||||
# Run update-ngxblocker to test for missing files and download latest globalblacklist.conf and reload Nginx
|
||||
# *********************************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Run update-ngxblocker" "######################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
# ****************************************************
|
||||
# List Directories to Confirm Downloaded Missing Files
|
||||
# ****************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "#######################################################################################" "Confirming /etc/nginx/conf.d/ directory has missing files replaced by update-ngxblocker" "#######################################################################################"
|
||||
ls -la /etc/nginx/conf.d/
|
||||
printf '\n%s\n%s\n%s\n\n' "#######################################################################################" "Confirming /etc/nginx/bots.d/ directory has missing files replaced by update-ngxblocker" "#######################################################################################"
|
||||
ls -la /etc/nginx/bots.d/
|
||||
|
||||
# ****************************************************************************************
|
||||
# Copy a dummy version of globalblacklist.conf with an older version number to test update
|
||||
# ****************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################################################" "Copy older globalblacklist.conf file to force update" "####################################################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}----------------------------------------------------"
|
||||
echo "${bold}${magenta}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${magenta}----------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
|
||||
# *********************************************************************************************************
|
||||
# Run update-ngxblocker to test for missing files and download latest globalblacklist.conf and reload Nginx
|
||||
# *********************************************************************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Run update-ngxblocker" "######################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
|
@ -197,7 +249,11 @@ sudo bash ./update-ngxblocker -n
|
|||
# Run setup-ngxblocker again
|
||||
# **************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################" "Run setup-ngxblocker" "####################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
|
||||
|
@ -205,42 +261,49 @@ sudo bash ./setup-ngxblocker -x
|
|||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# *******************************************************
|
||||
# Make sure we test latest generated globalblacklist.conf
|
||||
# *******************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "##############################################################################" "Copy latest generated globalblacklist.conf file to test for any compile errors" "##############################################################################"
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------------------------------------------"
|
||||
echo "${bold}${magenta}Make sure we test with latest generated globalblacklist.conf"
|
||||
echo "${bold}${magenta}------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/conf.d/globalblacklist.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------"
|
||||
echo "${bold}${green}Reload Nginx"
|
||||
echo "${bold}${green}------------"
|
||||
printf "\n"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
# **********************
|
||||
# Now Run our Curl Tests
|
||||
# **********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Now Run our Curl Tests" "######################"
|
||||
|
||||
# ************************************************************
|
||||
# Copy all .conf files used in Test 1 to a folder for checking
|
||||
# ************************************************************
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------------------------------------------------------"
|
||||
echo "${bold}${green}Make Backup all conf files and folders used during this test"
|
||||
echo "${bold}${green}------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp /etc/nginx/bots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/bots.d/
|
||||
sudo cp /etc/nginx/conf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/conf.d/
|
||||
sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/default.vhost
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test1/nginx.conf
|
||||
|
||||
# *****************************************************************************************
|
||||
# Travis now moves into running the rest of the tests in the script: section of .travis.yml
|
||||
# *****************************************************************************************
|
||||
|
||||
# **********************
|
||||
# Exit With Error Number
|
||||
# **********************
|
||||
|
|
Loading…
Add table
Reference in a new issue