mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-01 18:19:55 +00:00
ENABLE install & test nginx 4 / ADD install-nginx-restore
This commit is contained in:
parent
ab215af0f6
commit
d152dda14d
7 changed files with 874 additions and 232 deletions
|
@ -6,8 +6,4 @@ server {
|
|||
charset UTF-8;
|
||||
index index.html;
|
||||
|
||||
# Bad Bot Blocker
|
||||
include /etc/nginx/bots.d/ddos.conf;
|
||||
include /etc/nginx/bots.d/blockbots.conf;
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to Nginx</title>
|
||||
<title>Welcome to NginX</title>
|
||||
</head>
|
||||
<body>
|
||||
<div align=center>
|
||||
<h1>Welcome to the Nginx Ultimate Bad Bot Blocker</h1>
|
||||
<h1>Welcome to the NginX Ultimate Bad Bot Blocker</h1>
|
||||
<p>This is merely used for testing !!!</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
echo "Welcome to Nginx\n";
|
||||
echo "This is the Travis Testing Environment for the Nginx Ultimate Bad Bot Blocker\n";
|
||||
echo "Visit https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker\n";
|
|
@ -16,21 +16,22 @@
|
|||
# #
|
||||
##############################################################################
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
|
@ -38,15 +39,44 @@
|
|||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# ***************************************************************
|
||||
# Start Getting Nginx Ready for Testing the Nginx Bad Bot Blocker
|
||||
# ***************************************************************
|
||||
# ------------------------
|
||||
# Set Terminal Font Colors
|
||||
# ------------------------
|
||||
|
||||
# ***********************************
|
||||
# Lets Uninstall Current Nginx 1.12.1
|
||||
# ***********************************
|
||||
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)
|
||||
|
||||
# ---------
|
||||
# FUNCTIONS
|
||||
# ---------
|
||||
|
||||
reloadNginX () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}---------------"
|
||||
echo "${bold}${green}Reloading Nginx"
|
||||
echo "${bold}${green}---------------"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
}
|
||||
|
||||
waitforReload () {
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Sleeping for 10 seconds to allow Nginx to Properly Reload inside Travis"
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sleep 10s
|
||||
}
|
||||
|
||||
|
||||
installNginxMainstream (){
|
||||
sudo rm -rfv /etc/nginx/mybots.d/
|
||||
sudo rm -rfv /etc/nginx/myconf.d/
|
||||
sudo rm /etc/nginx/conf.d/*.conf
|
||||
|
@ -54,36 +84,24 @@ sudo rm /etc/nginx/bots.d/*.conf
|
|||
sudo rm /etc/nginx/sites-available/default
|
||||
sudo rm /etc/nginx/nginx.conf
|
||||
ls -la /etc/nginx/
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/_nginx_conf_backup/nginx13.conf /etc/nginx/nginx.conf
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_backup_nginxconf/nginx13.conf /etc/nginx/nginx.conf
|
||||
ls -la /etc/nginx/
|
||||
sudo apt-get purge nginx-full
|
||||
sudo apt-get purge nginx-common
|
||||
sudo apt-get purge nginx*
|
||||
|
||||
# *****************************
|
||||
# Lets Install Mainstream Nginx
|
||||
# *****************************
|
||||
|
||||
mainstreamnginx=development
|
||||
sudo add-apt-repository -y ppa:nginx/${mainstreamnginx}
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --assume-yes nginx-full
|
||||
sudo nginx -V
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
}
|
||||
|
||||
# **************************************
|
||||
# Make Sure We Cleanup From Nginx Test 3
|
||||
# **************************************
|
||||
|
||||
printf '\n%s\n\n' "################################################################################################################"
|
||||
printf '\n%s\n\n' "################################################################################################################"
|
||||
printf '\n%s\n\n' "################################################################################################################"
|
||||
printf '\n%s\n%s\n%s\n\n' "###################################" " STARTING NGINX TEST 4" "###################################"
|
||||
printf '\n%s\n\n' "################################################################################################################"
|
||||
printf '\n%s\n\n' "################################################################################################################"
|
||||
printf '\n%s\n\n\n\n\n\n' "################################################################################################################"
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "###################################" "Cleaning up Files from Nginx Test 3" "###################################"
|
||||
cleanupNginx1 () {
|
||||
echo "${bold}${yellow}-----------------------------------"
|
||||
echo "${bold}${yellow}Removing Files from Install Nginx 3"
|
||||
echo "${bold}${yellow}-----------------------------------"
|
||||
printf "\n"
|
||||
sudo rm /etc/nginx/sites-available/default.vhost
|
||||
sudo rm /etc/nginx/sites-enabled/default.vhost
|
||||
sudo rm /etc/nginx/sites-available/*
|
||||
|
@ -91,253 +109,185 @@ sudo rm /etc/nginx/sites-enabled/*
|
|||
sudo rm /var/www/html/*
|
||||
sudo rm /etc/nginx/conf.d/*.conf
|
||||
sudo rm /etc/nginx/bots.d/*.conf
|
||||
printf '\n%s\n%s\n%s\n\n' "########################################" "Cleaning up Files from Nginx Test 3 DONE" "########################################"
|
||||
}
|
||||
|
||||
|
||||
# *************************************
|
||||
# List Directories to Confirm Deletions
|
||||
# *************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################################################" "Confirming /usr/local/nginx/conf.d/ directory is EMPTY" "######################################################"
|
||||
checkDirectories () {
|
||||
ls -la /etc/nginx/conf.d/
|
||||
printf '\n%s\n%s\n%s\n\n' "######################################################" "Confirming /usr/local/nginx/bots.d/ directory is EMPTY" "######################################################"
|
||||
ls -la /etc/nginx/bots.d/
|
||||
printf '\n%s\n%s\n%s\n\n' "#########################################################" "Confirming /etc/nginx/sites-available/ directory is EMPTY" "#########################################################"
|
||||
ls -la /etc/nginx/sites-available/
|
||||
printf '\n%s\n%s\n%s\n\n' "#######################################################" "Confirming /etc/nginx/sites-enabled/ directory is EMPTY" "#######################################################"
|
||||
ls -la /etc/nginx/sites-enabled/
|
||||
printf '\n%s\n%s\n%s\n\n' "############################################" "Confirming /var/www/html/ directory is EMPTY" "############################################"
|
||||
ls -la /var/www/html/
|
||||
printf '\n%s\n\n' " "
|
||||
echo "${bold}${yellow}-------------------------------------------------"
|
||||
echo "${bold}${yellow}Confirming Files from Install Nginx 3 are Removed"
|
||||
echo "${bold}${yellow}-------------------------------------------------"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# ********************************************************
|
||||
# Copy our default.vhost file into Nginx /sites-available/
|
||||
# ********************************************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "################################" "Get Nginx Setup for Nginx Test 4" "################################"
|
||||
activateVHost () {
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default.vhost /etc/nginx/sites-available/default.vhost
|
||||
|
||||
# **********************************************
|
||||
# Link the vhost file into Nginx /sites-enabled/
|
||||
# **********************************************
|
||||
|
||||
sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
|
||||
|
||||
# ***********************************************************
|
||||
# Copy our index.php file into the default site's root folder
|
||||
# ***********************************************************
|
||||
|
||||
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 4" "#####################################"
|
||||
echo "${bold}${yellow}---------------------------------------------"
|
||||
echo "${bold}${yellow}Activating default.vhost and linking to Nginx"
|
||||
echo "${bold}${yellow}---------------------------------------------"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
# ***********************************************
|
||||
# Fetch our install-ngxblocker file from the repo
|
||||
# ***********************************************
|
||||
activateVHost2 () {
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default-noincludes.vhost /etc/nginx/sites-available/default.vhost
|
||||
echo "${bold}${yellow}---------------------------------------------"
|
||||
echo "${bold}${yellow}Activating default.vhost and linking to Nginx"
|
||||
echo "${bold}${yellow}---------------------------------------------"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################################" "Fetch install-ngxblocker from the repo" "######################################"
|
||||
getinstallngxblocker () {
|
||||
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
|
||||
}
|
||||
|
||||
# **********************
|
||||
# Run Install-NgxBlocker
|
||||
# **********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "######################" "Run install-ngxblocker" "######################"
|
||||
runinstallngxblocker () {
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
echo "${bold}${magenta}Execute install-ngxblocker"
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./install-ngxblocker -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" "##########################################################"
|
||||
makeScriptsExecutable () {
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/setup-ngxblocker
|
||||
sudo chmod +x /usr/sbin/update-ngxblocker
|
||||
}
|
||||
|
||||
# ********************
|
||||
# Run setup-ngxblocker
|
||||
# ********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################" "Run setup-ngxblocker" "####################"
|
||||
runsetupngxblocker1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
printf "\n"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
}
|
||||
|
||||
# ************************
|
||||
# Load our Nginx.conf file
|
||||
# ************************
|
||||
|
||||
loadNginxConf () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}---------------"
|
||||
echo "${bold}${magenta}Load nginx.conf"
|
||||
echo "${bold}${magenta}---------------"
|
||||
sudo nginx -c /etc/nginx/nginx.conf
|
||||
}
|
||||
|
||||
# ******************************************************************************************
|
||||
# Run update-ngxblocker test which downloads latest globalblacklist.conf and reloads Nginx
|
||||
# This second test forces update-ngxblocker to re-write the Include location to non standard
|
||||
# location of /etc/nginx/mybots.d
|
||||
# ******************************************************************************************
|
||||
forceUpdateTest1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
echo "${bold}${yellow}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/myconf.d/globalblacklist.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" "####################################################"
|
||||
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" "######################"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
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" "####################################################################"
|
||||
forceUpdateTest2 () {
|
||||
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 /usr/local/nginx/conf.d/ directory is EMPTY" "######################################################"
|
||||
ls -la /etc/nginx/conf.d/
|
||||
printf '\n%s\n%s\n%s\n\n' "######################################################" "Confirming /usr/local/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" "######################"
|
||||
runupdatengxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
}
|
||||
|
||||
# ****************************************************
|
||||
# List Directories to Confirm Downloaded Missing Files
|
||||
# ****************************************************
|
||||
activateLatestBlacklist () {
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Make sure we test with latest generated globalblacklist.conf"
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/conf.d/globalblacklist.conf /etc/nginx/myconf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "#############################################################################################" "Confirming /etc/nginx/myconf.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/mybots.d/ directory has missing files replaced by update-ngxblocker" "#############################################################################################"
|
||||
ls -la /etc/nginx/bots.d/
|
||||
backupConfFiles () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}-------------------------------------------------------"
|
||||
echo "${bold}${green}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/test4_conf_files/bots.d/
|
||||
sudo cp /etc/nginx/conf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/test4_conf_files/conf.d/
|
||||
sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/test4_conf_files/default.vhost
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/test4_conf_files/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" "####################################################"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
installNginxMainstream
|
||||
cleanupNginx1
|
||||
checkDirectories
|
||||
activateVHost
|
||||
getinstallngxblocker
|
||||
makeScriptsExecutable
|
||||
runsetupngxblocker1
|
||||
loadNginxConf
|
||||
forceUpdateTest1
|
||||
runupdatengxblocker
|
||||
reloadNginX
|
||||
waitforReload
|
||||
forceUpdateTest2
|
||||
runupdatengxblocker
|
||||
checkDirectories
|
||||
forceUpdateTest1
|
||||
runupdatengxblocker
|
||||
runsetupngxblocker1
|
||||
reloadNginX
|
||||
waitforReload
|
||||
activateLatestBlacklist
|
||||
runsetupngxblocker1
|
||||
reloadNginX
|
||||
waitforReload
|
||||
activateVHost2
|
||||
reloadNginX
|
||||
waitforReload
|
||||
backupConfFiles
|
||||
|
||||
# *********************************************************************************************************
|
||||
# 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" "######################"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
|
||||
# **************************
|
||||
# Run setup-ngxblocker Again
|
||||
# **************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "####################" "Run setup-ngxblocker" "####################"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
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" "##############################################################################"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/conf.d/globalblacklist.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
|
||||
# **************************
|
||||
# Run setup-ngxblocker Again
|
||||
# **************************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "############################################################" "Run setup-ngxblocker to fix includes in globalblacklist.conf" "############################################################"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
|
||||
# *********************
|
||||
# Force reload of Nginx
|
||||
# *********************
|
||||
|
||||
printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default13.vhost /etc/nginx/sites-available/default.vhost
|
||||
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 3 to a folder for checking
|
||||
# ************************************************************
|
||||
|
||||
sudo chown -R travis:travis ${TRAVIS_BUILD_DIR}/
|
||||
sudo chown -R travis:travis ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test4/
|
||||
sudo cp /etc/nginx/bots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test4/bots.d/
|
||||
sudo cp /etc/nginx/conf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test4/conf.d/
|
||||
sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test4/default.vhost
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test4/nginx.conf
|
||||
ls -la /etc/nginx/sites-available/
|
||||
ls -la /var/www/
|
||||
sudo chown -R travis:travis ${TRAVIS_BUILD_DIR}/
|
||||
|
||||
###
|
||||
|
||||
# *****************************************************************************************
|
||||
# Travis now moves into running the rest of the tests in the script: section of .travis.yml
|
||||
# *****************************************************************************************
|
||||
|
||||
# **********************
|
||||
# ----------------------
|
||||
# Exit With Error Number
|
||||
# **********************
|
||||
# ----------------------
|
||||
|
||||
exit ${?}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
289
.dev-tools/install-nginx-restore.sh
Normal file
289
.dev-tools/install-nginx-restore.sh
Normal file
|
@ -0,0 +1,289 @@
|
|||
#!/bin/bash
|
||||
# Travis CI Generating and Building for the Nginx Ultimate Bad Bot Blocker
|
||||
# Created by: Mitchell Krog (mitchellkrog@gmail.com)
|
||||
# Copyright: Mitchell Krog - https://github.com/mitchellkrogza
|
||||
# Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
|
||||
|
||||
##############################################################################
|
||||
# _ __ _ #
|
||||
# / |/ /__ _(_)__ __ __ #
|
||||
# / / _ `/ / _ \\ \ / #
|
||||
# /_/|_/\_, /_/_//_/_\_\ #
|
||||
# __/___/ __ ___ __ ___ __ __ #
|
||||
# / _ )___ ____/ / / _ )___ / /_ / _ )/ /__ ____/ /_____ ____ #
|
||||
# / _ / _ `/ _ / / _ / _ \/ __/ / _ / / _ \/ __/ '_/ -_) __/ #
|
||||
# /____/\_,_/\_,_/ /____/\___/\__/ /____/_/\___/\__/_/\_\\__/_/ #
|
||||
# #
|
||||
##############################################################################
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# 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)
|
||||
|
||||
# ---------
|
||||
# FUNCTIONS
|
||||
# ---------
|
||||
|
||||
reloadNginX () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}---------------"
|
||||
echo "${bold}${green}Reloading Nginx"
|
||||
echo "${bold}${green}---------------"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
}
|
||||
|
||||
waitforReload () {
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Sleeping for 10 seconds to allow Nginx to Properly Reload inside Travis"
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sleep 10s
|
||||
}
|
||||
|
||||
installNginxStable (){
|
||||
sudo rm /etc/nginx/conf.d/*.conf
|
||||
sudo rm /etc/nginx/bots.d/*.conf
|
||||
sudo rm /etc/nginx/sites-available/*
|
||||
sudo rm /etc/nginx/nginx.conf
|
||||
ls -la /etc/nginx/
|
||||
sudo apt-get purge nginx-full
|
||||
sudo apt-get purge nginx-common
|
||||
sudo apt-get purge nginx*
|
||||
mainstreamnginx=development
|
||||
sudo add-apt-repository --remove ppa:nginx/${mainstreamnginx}
|
||||
sudo apt-get update
|
||||
stablenginx=stable
|
||||
sudo add-apt-repository -y ppa:nginx/${stable}
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --assume-yes nginx-extras
|
||||
sudo nginx -V
|
||||
}
|
||||
|
||||
backupNginxConf () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}---------------------------"
|
||||
echo "${bold}${yellow}Making backup of nginx.conf"
|
||||
echo "${bold}${yellow}---------------------------"
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_backup_nginxconf/nginx.conf
|
||||
}
|
||||
|
||||
prepareVhost () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}-------------------------------------------"
|
||||
echo "${bold}${yellow}Delete any default files installed by Nginx"
|
||||
echo "${bold}${yellow}-------------------------------------------"
|
||||
sudo rm /etc/nginx/sites-available/*
|
||||
sudo rm /etc/nginx/sites-enabled/*
|
||||
sudo rm /var/www/html/*
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}---------------------"
|
||||
echo "${bold}${yellow}Setup Vhost for Nginx"
|
||||
echo "${bold}${yellow}---------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/default.vhost /etc/nginx/sites-available/default.vhost
|
||||
sudo ln -s /etc/nginx/sites-available/default.vhost /etc/nginx/sites-enabled/default.vhost
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/index.html /var/www/html/index.html
|
||||
}
|
||||
|
||||
makeScriptsExecutable () {
|
||||
sudo chmod +x /usr/sbin/install-ngxblocker
|
||||
sudo chmod +x /usr/sbin/setup-ngxblocker
|
||||
sudo chmod +x /usr/sbin/update-ngxblocker
|
||||
}
|
||||
|
||||
getinstallngxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
echo "${bold}${magenta}Fetch install-ngxblocker from the repo"
|
||||
echo "${bold}${magenta}--------------------------------------"
|
||||
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
|
||||
}
|
||||
|
||||
runinstallngxblocker () {
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
echo "${bold}${magenta}Execute install-ngxblocker"
|
||||
echo "${bold}${magenta}--------------------------"
|
||||
cd /usr/sbin
|
||||
sudo bash ./install-ngxblocker -s /usr/sbin/ -x
|
||||
}
|
||||
|
||||
runsetupngxblocker1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -i /usr/sbin/install-ngxblocker -x
|
||||
}
|
||||
|
||||
runsetupngxblocker2 () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Execute setup-ngxblocker"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
cd /usr/sbin
|
||||
sudo bash ./setup-ngxblocker -x
|
||||
}
|
||||
|
||||
loadNginxConf () {
|
||||
sudo nginx -c /etc/nginx/nginx.conf
|
||||
}
|
||||
|
||||
forceUpdateTest1 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
echo "${bold}${yellow}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
forceUpdateTest2 () {
|
||||
echo "${bold}${yellow}--------------------------------------"
|
||||
echo "${bold}${yellow}Delete Files to test update-ngxblocker"
|
||||
echo "${bold}${yellow}--------------------------------------"
|
||||
sudo rm /etc/nginx/conf.d/*.conf
|
||||
sudo rm /etc/nginx/bots.d/*.conf
|
||||
ls -la /etc/nginx/conf.d/
|
||||
ls -la /etc/nginx/bots.d/
|
||||
}
|
||||
|
||||
forceUpdateTest3 () {
|
||||
printf "\n"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
echo "${bold}${yellow}Copy older globalblacklist.conf file to force update"
|
||||
echo "${bold}${yellow}----------------------------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
runupdatengxblocker () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
echo "${bold}${magenta}Execute update-ngxblocker"
|
||||
echo "${bold}${magenta}-------------------------"
|
||||
cd /usr/sbin
|
||||
sudo bash ./update-ngxblocker -n
|
||||
}
|
||||
|
||||
activateLatestBlacklist () {
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Make sure we test with latest generated globalblacklist.conf"
|
||||
echo "${bold}${yellow}------------------------------------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/conf.d/globalblacklist.conf /etc/nginx/conf.d/globalblacklist.conf
|
||||
}
|
||||
|
||||
backupConfFiles () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}-------------------------------------------------------"
|
||||
echo "${bold}${green}Backup all conf files and folders used during this test"
|
||||
echo "${bold}${green}-------------------------------------------------------"
|
||||
sudo cp /etc/nginx/bots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_files/bots.d/
|
||||
sudo cp /etc/nginx/conf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_files/conf.d/
|
||||
sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_files/default.vhost
|
||||
sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/test1_conf_files/nginx.conf
|
||||
}
|
||||
|
||||
copyNginxConf () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------------"
|
||||
echo "${bold}${magenta}Copy nginx.conf to /etc/nginx/"
|
||||
echo "${bold}${magenta}------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/nginx.conf-newformat /etc/nginx/nginx.conf
|
||||
}
|
||||
|
||||
# ------------------
|
||||
# Start Installation
|
||||
# ------------------
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${green}------------------"
|
||||
echo "${bold}${green}Start Nginx Test 1"
|
||||
echo "${bold}${green}------------------"
|
||||
|
||||
installNginxStable
|
||||
backupNginxConf
|
||||
copyNginxConf
|
||||
prepareVhost
|
||||
getinstallngxblocker
|
||||
runinstallngxblocker
|
||||
makeScriptsExecutable
|
||||
runsetupngxblocker1
|
||||
loadNginxConf
|
||||
forceUpdateTest1
|
||||
runupdatengxblocker
|
||||
reloadNginX
|
||||
waitforReload
|
||||
forceUpdateTest2
|
||||
runupdatengxblocker
|
||||
forceUpdateTest3
|
||||
runsetupngxblocker2
|
||||
reloadNginX
|
||||
waitforReload
|
||||
activateLatestBlacklist
|
||||
reloadNginX
|
||||
backupConfFiles
|
||||
|
||||
# ----------------------
|
||||
# Exit With Error Number
|
||||
# ----------------------
|
||||
|
||||
exit ${?}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
412
.dev-tools/test-nginx-4.sh
Normal file
412
.dev-tools/test-nginx-4.sh
Normal file
|
@ -0,0 +1,412 @@
|
|||
#!/bin/bash
|
||||
# Curl Testing Script for Nginx Ultimate Bad Bot Blocker
|
||||
# Created by: Mitchell Krog (mitchellkrog@gmail.com)
|
||||
# Copyright: Mitchell Krog - https://github.com/mitchellkrogza
|
||||
# Repo Url: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
|
||||
|
||||
##############################################################################
|
||||
# _ __ _ #
|
||||
# / |/ /__ _(_)__ __ __ #
|
||||
# / / _ `/ / _ \\ \ / #
|
||||
# /_/|_/\_, /_/_//_/_\_\ #
|
||||
# __/___/ __ ___ __ ___ __ __ #
|
||||
# / _ )___ ____/ / / _ )___ / /_ / _ )/ /__ ____/ /_____ ____ #
|
||||
# / _ / _ `/ _ / / _ / _ \/ __/ / _ / / _ \/ __/ '_/ -_) __/ #
|
||||
# /____/\_,_/\_,_/ /____/\___/\__/ /____/_/\___/\__/_/\_\\__/_/ #
|
||||
# #
|
||||
##############################################################################
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# 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)
|
||||
|
||||
# ---------
|
||||
# FUNCTIONS
|
||||
# ---------
|
||||
|
||||
|
||||
resetNginx () {
|
||||
echo "${bold}${green}------------------------------------------------"
|
||||
echo "${bold}${green}Disable any User Whitelisting and set to Default"
|
||||
echo "${bold}${green}------------------------------------------------"
|
||||
sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/blacklist-user-agents-none.conf /etc/nginx/bots.d/blacklist-user-agents.conf
|
||||
}
|
||||
|
||||
reloadNginX () {
|
||||
printf "\n"
|
||||
echo "${bold}${green}---------------"
|
||||
echo "${bold}${green}Reloading Nginx"
|
||||
echo "${bold}${green}---------------"
|
||||
sudo nginx -t && sudo nginx -s reload
|
||||
}
|
||||
|
||||
waitforReload () {
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
echo "${bold}${yellow}Sleeping for 10 seconds to allow Nginx to Properly Reload inside Travis"
|
||||
echo "${bold}${yellow}-----------------------------------------------------------------------"
|
||||
printf "\n"
|
||||
sleep 10s
|
||||
}
|
||||
|
||||
run_curltest1 () {
|
||||
if curl -v -A "80legs" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}80legs BAD BOT DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}80legs BAD BOT NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest2 () {
|
||||
if curl -v -A "Nutch" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}Nutch BAD BOT DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}Nutch BAD BOT NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest3 () {
|
||||
if curl -I http://localhost:9000 -e http://100dollars-seo.com 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}100dollars-seo.com BAD REFERRER DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}100dollars-seo.com BAD REFERRER NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest4 () {
|
||||
if curl -I http://localhost:9000 -e http://zx6.ru 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}zx6.ru BAD REFERRER DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}zx6.ru BAD REFERRER NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest5 () {
|
||||
if curl -v -A "GoogleBot" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}GoogleBot GOOD BOT ALLOWED THROUGH"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}GoogleBot GOOD BOT NOT ALLOWED THROUGH"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest6 () {
|
||||
if curl -v -A "BingBot" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}BingBot GOOD BOT ALLOWED THROUGH"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}BingBot GOOD BOT NOT ALLOWED THROUGH"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest7 () {
|
||||
if curl http://localhost:9000 -e http://google.com 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}google.com GOOD REFERRER DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}google.com GOOD REFERRER NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest8 () {
|
||||
if curl http://localhost:9000 -e http://bing.com 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${red}bing.com GOOD REFERRER DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}bing.com GOOD REFERRER NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest9 () {
|
||||
if curl -A "Googlebot/Nutch-1.7" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}Googlebot/Nutch-1.7 BAD BOT DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}Googlebot/Nutch-1.7 BAD BOT NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest10 () {
|
||||
if curl -A "Mozilla/5.0 (compatible; Googlebot/Nutch2.1; +http://www.google.com/bot.html)" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}Googlebot/Nutch2.1 BAD BOT DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}Googlebot/Nutch2.1 BAD BOT NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest11 () {
|
||||
if curl -A "Mozilla/5.0 (compatible; Googlebot/nutch/-2.1; +http://www.google.com/bot.html)" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}Googlebot/nutch/-2.1 BAD BOT DETECTED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - Googlebot/nutch/-2.1 BAD BOT NOT DETECTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest12 () {
|
||||
if curl -v -A "Mozilla/5.0 (compatible; Googlebot-Image/Snutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - NO FALSE POSITIVE on Googlebot-Image/Snutch\-/-2.1"
|
||||
else
|
||||
echo "${bold}${red}FAILED - FALSE POSITIVE FOUND on Googlebot-Image/Snutch\-/-2.1"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest13 () {
|
||||
if curl -v -A "SnutchMozilla/5.0 (compatible; Googlebot-Image/SMutch\-/-2.1; +http://www.google.com/bot.html)" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - NO FALSE POSITIVE on SnutchMozilla/5.0"
|
||||
else
|
||||
echo "${bold}${red}FAILED - FALSE POSITIVE FOUND on SnutchMozilla/5.0"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest14 () {
|
||||
if curl -v -A "Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - NO FALSE POSITIVE on Mozilla/5.0"
|
||||
else
|
||||
echo "${bold}${red}FAILED - FALSE POSITIVE FOUND on Mozilla/5.0"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_curltest15 () {
|
||||
if curl -v -A "Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - NO FALSE POSITIVE on Safari"
|
||||
else
|
||||
echo "${bold}${red}FAILED - FALSE POSITIVE FOUND on Safari"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
testBadUserAgents () {
|
||||
shuf -n 10 ${TRAVIS_BUILD_DIR}/_generator_lists/bad-user-agents.list > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.tmp
|
||||
sed 's/\\//g' ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.tmp > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.list
|
||||
sudo rm ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.tmp
|
||||
sort -u ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.list -o ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.list
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}---------------------------"
|
||||
echo "${bold}${magenta}Testing 10 Random Bad Bots"
|
||||
echo "${bold}${magenta}---------------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-bots-for-test-quick.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -v -A "${line}" http://localhost:9000 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}${line} was ${bold}${red}NOT BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
testGoodUserAgents () {
|
||||
sed 's/\\//g' ${TRAVIS_BUILD_DIR}/_generator_lists/good-user-agents.list > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/good-bots-for-test.list
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}---------------------"
|
||||
echo "${bold}${magenta}Testing All Good Bots"
|
||||
echo "${bold}${magenta}---------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/good-bots-for-test.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -v -A "${line}" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}${line} was ${bold}${green}ALLOWED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
testAllowedUserAgents () {
|
||||
sed 's/\\//g' ${TRAVIS_BUILD_DIR}/_generator_lists/allowed-user-agents.list > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/allowed-bots-for-test.list
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Testing All Allowed Bots"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/allowed-bots-for-test.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -v -A "${line}" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}${line} was ${bold}${green}ALLOWED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
testLimitedUserAgents () {
|
||||
sed 's/\\//g' ${TRAVIS_BUILD_DIR}/_generator_lists/limited-user-agents.list > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/limited-bots-for-test.list
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
echo "${bold}${magenta}Testing All Limited Bots"
|
||||
echo "${bold}${magenta}------------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/limited-bots-for-test.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -v -A "${line}" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}${line} was ${bold}${green}ALLOWED"
|
||||
else
|
||||
echo "${bold}${green}FAILED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
testRandomReferrers () {
|
||||
shuf -n 10 ${TRAVIS_BUILD_DIR}/_generator_lists/bad-referrers.list > ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-referrers-for-test-quick.list
|
||||
sort -u ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-referrers-for-test-quick.list -o ${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-referrers-for-test-quick.list
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}---------------------------------"
|
||||
echo "${bold}${magenta}Testing 10 Random Bad Referrers"
|
||||
echo "${bold}${magenta}---------------------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/random-referrers-for-test-quick.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -I http://localhost:9000 -e "http://${line}" 2>&1 | grep -i '(52)'; then
|
||||
echo "${bold}${green}PASSED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
else
|
||||
echo "${bold}${red}FAILED - ${red}${line} was ${bold}${red}NOT BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
testGoodReferrers () {
|
||||
printf "\n"
|
||||
echo "${bold}${magenta}----------------------"
|
||||
echo "${bold}${magenta}Testing Good Referrers"
|
||||
echo "${bold}${magenta}----------------------"
|
||||
IFS=$'\n'
|
||||
file=${TRAVIS_BUILD_DIR}/.dev-tools/test_units/good-referrers-for-test.list
|
||||
lines=$(cat ${file})
|
||||
for line in ${lines}; do
|
||||
if
|
||||
curl -v -A "${line}" http://localhost:9000 2>&1 | grep -i 'Welcome'; then
|
||||
echo "${bold}${green}PASSED - ${green}${line} was ${bold}${green}ALLOWED"
|
||||
else
|
||||
echo "${bold}${green}FAILED - ${red}${line} was ${bold}${red}BLOCKED"
|
||||
fi
|
||||
done
|
||||
IFS=""
|
||||
}
|
||||
|
||||
# -----------------
|
||||
# Trigger Functions
|
||||
# -----------------
|
||||
|
||||
echo "${bold}${green}--------------"
|
||||
echo "${bold}${green}Tests Starting"
|
||||
echo "${bold}${green}--------------"
|
||||
printf "\n"
|
||||
|
||||
resetNginx
|
||||
reloadNginX
|
||||
waitforReload
|
||||
run_curltest1
|
||||
run_curltest2
|
||||
run_curltest3
|
||||
run_curltest4
|
||||
run_curltest5
|
||||
run_curltest6
|
||||
run_curltest7
|
||||
run_curltest8
|
||||
run_curltest9
|
||||
run_curltest10
|
||||
run_curltest11
|
||||
run_curltest12
|
||||
run_curltest13
|
||||
run_curltest14
|
||||
run_curltest15
|
||||
testBadUserAgents
|
||||
testGoodUserAgents
|
||||
testAllowedUserAgents
|
||||
testLimitedUserAgents
|
||||
testRandomReferrers
|
||||
testGoodReferrers
|
||||
|
||||
printf "\n"
|
||||
echo "${bold}${cyan}Tests Completed"
|
||||
echo "${bold}${green}All Tests Passed"
|
||||
|
||||
# ----------------------
|
||||
# Exit With Error Number
|
||||
# ----------------------
|
||||
|
||||
exit ${?}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# MIT License
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2017 Mitchell Krog - mitchellkrog@gmail.com
|
||||
# https://github.com/mitchellkrogza
|
||||
# ------------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
# ------------------------------------------------------------------------------
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
# ------------------------------------------------------------------------------
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
@ -49,10 +49,10 @@ script:
|
|||
- bash .dev-tools/test-nginx-2.sh
|
||||
- bash .dev-tools/install-nginx-3.sh
|
||||
- bash .dev-tools/test-nginx-3.sh
|
||||
#- bash .dev-tools/install-nginx-4.sh
|
||||
#- bash .dev-tools/test-blocker-quicker.sh
|
||||
- bash .dev-tools/install-nginx-4.sh
|
||||
- bash .dev-tools/test-nginx-4.sh
|
||||
# FROM HERE WE TEST ANY NEW CHANGES TO THE BLOCKER
|
||||
- bash .dev-tools/install-nginx-1.sh
|
||||
- bash .dev-tools/install-nginx-restore.sh
|
||||
- bash .dev-tools/beta-install-nginx-testing-of-changes.sh
|
||||
- bash .dev-tools/beta-test-blocker.sh
|
||||
- bash .dev-tools/beta-test-blocker-badwords.sh
|
||||
|
|
Loading…
Add table
Reference in a new issue