From c2bdffed63ef29e91f8c166a52cac0a0ed09159a Mon Sep 17 00:00:00 2001 From: Mitchell Krog Date: Sat, 29 Jun 2019 11:49:07 +0200 Subject: [PATCH] ENABLE install & test nginx 3 --- .dev-tools/install-nginx-3.sh | 372 ++++++++++++++---------------- .dev-tools/test-nginx-3.sh | 412 ++++++++++++++++++++++++++++++++++ .travis.yml | 4 +- 3 files changed, 582 insertions(+), 206 deletions(-) create mode 100644 .dev-tools/test-nginx-3.sh diff --git a/.dev-tools/install-nginx-3.sh b/.dev-tools/install-nginx-3.sh index 9b73eef46..17b2b801b 100755 --- a/.dev-tools/install-nginx-3.sh +++ b/.dev-tools/install-nginx-3.sh @@ -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,266 +39,229 @@ # 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 +# ------------------------ -# ************************************** -# Make Sure We Cleanup From Nginx Test 2 -# ************************************** +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) -printf '\n%s\n%s\n%s\n\n' "###################################" " STARTING NGINX TEST 3" "###################################" -printf '\n%s\n%s\n%s\n\n' "###################################" "Cleaning up Files from Nginx Test 2" "###################################" +# --------- +# 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 +} + +cleanupNginx1 () { +echo "${bold}${yellow}-----------------------------------" +echo "${bold}${yellow}Removing Files from Install Nginx 2" +echo "${bold}${yellow}-----------------------------------" +printf "\n" sudo rm /etc/nginx/sites-available/default.vhost sudo rm /etc/nginx/sites-enabled/default.vhost sudo rm /var/www/html/* sudo rm /usr/local/nginx/conf.d/*.conf sudo rm /usr/local/nginx/bots.d/*.conf -printf '\n%s\n%s\n%s\n\n' "########################################" "Cleaning up Files from Nginx Test 2 DONE" "########################################" +} -# ******************************************************* -# Restore backup of the clean and default nginx.conf file -# ****************************************************** +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 +} -printf '\n%s\n%s\n%s\n\n' "#################################" "Restoring Default nginx.conf file" "#################################" -sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/_nginx_conf_backup/nginx.conf /etc/nginx/nginx.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 /usr/local/nginx/conf.d/ -printf '\n%s\n%s\n%s\n\n' "######################################################" "Confirming /usr/local/nginx/bots.d/ directory is EMPTY" "######################################################" -ls -la /usr/local/nginx/bots.d/ -printf '\n%s\n%s\n%s\n\n' "#########################################################" "Confirming /etc/nginx/sites-available/ directory is EMPTY" "#########################################################" +checkDirectories () { +ls -la /etc/nginx/myconf.d/ +ls -la /etc/nginx/mybots.d/ 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 2 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 3" "################################" +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 +sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/index.html /var/www/html/index.html +echo "${bold}${yellow}---------------------------------------------" +echo "${bold}${yellow}Activating default.vhost and linking to Nginx" +echo "${bold}${yellow}---------------------------------------------" +printf "\n" +} -# *********************************************************** -# Copy our index.php file into the default site's root folder -# *********************************************************** - -sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/index.php /var/www/html/index.php -printf '\n%s\n%s\n%s\n\n' "#####################################" "Finished Nginx Setup for Nginx Test 3" "#####################################" - -# *********************************************** -# Fetch our install-ngxblocker file from the repo -# *********************************************** - -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 -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d +} -# ************************************************** -# Set our install and setup scripts to be executable -# ************************************************** +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 -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d +} -printf '\n%s\n%s\n%s\n\n' "##########################################################" "Set our install, setup and update scripts to be executable" "##########################################################" +runupdatengxblocker () { +printf "\n" +echo "${bold}${magenta}-------------------------" +echo "${bold}${magenta}Execute update-ngxblocker" +echo "${bold}${magenta}-------------------------" +cd /usr/sbin +sudo bash ./update-ngxblocker -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d -n +} + +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" "####################" -cd /usr/sbin -sudo bash ./setup-ngxblocker -x -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d - -# ************************ -# 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 -# ****************************************************************************************** - -# **************************************************************************************** -# 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" "####################################################" +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 +} -# **************************************************************************************** -# 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 -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d -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/myconf.d/*.conf sudo rm /etc/nginx/mybots.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/myconf.d/ -printf '\n%s\n%s\n%s\n\n' "######################################################" "Confirming /usr/local/nginx/bots.d/ directory is EMPTY" "######################################################" ls -la /etc/nginx/mybots.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" "######################" -cd /usr/sbin -sudo bash ./update-ngxblocker -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d -n - -# **************************************************** -# List Directories to Confirm Downloaded Missing Files -# **************************************************** - -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/myconf.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/mybots.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" "####################################################" -sudo cp ${TRAVIS_BUILD_DIR}/.dev-tools/globalblacklist-dummy.conf /etc/nginx/myconf.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" "######################" -cd /usr/sbin -sudo bash ./update-ngxblocker -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d -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 -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d - -# ********************* -# 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" "##############################################################################" +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 +} -# ************************** -# Run setup-ngxblocker Again -# ************************** +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/mybots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/test3_conf_files/bots.d/ +sudo cp /etc/nginx/myconf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/test3_conf_files/conf.d/ +sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/test3_conf_files/default.vhost +sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/test3_conf_files/nginx.conf +} -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 -c /etc/nginx/myconf.d -b /etc/nginx/mybots.d +# Trigger Functions -# ********************* -# Force reload of Nginx -# ********************* +cleanupNginx1 +copyNginxConf +checkDirectories +activateVHost +getinstallngxblocker +runinstallngxblocker +makeScriptsExecutable +runsetupngxblocker1 +loadNginxConf +forceUpdateTest1 +runupdatengxblocker +reloadNginX +waitforReload +forceUpdateTest2 +runupdatengxblocker +checkDirectories +forceUpdateTest1 +runupdatengxblocker +runsetupngxblocker1 +reloadNginX +waitforReload +activateLatestBlacklist +runsetupngxblocker1 +reloadNginX +waitforReload -printf '\n%s\n%s\n%s\n\n' "########################" "Force Reloading of Nginx" "########################" -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_test3/ -sudo cp /etc/nginx/mybots.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test3/bots.d/ -sudo cp /etc/nginx/myconf.d/* ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test3/conf.d/ -sudo cp /etc/nginx/sites-available/default.vhost ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test3/default.vhost -sudo cp /etc/nginx/nginx.conf ${TRAVIS_BUILD_DIR}/.dev-tools/_conf_files_test3/nginx.conf - -# ***************************************************************************************** -# 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. \ No newline at end of file +# SOFTWARE. +# ------------------------------------------------------------------------------ diff --git a/.dev-tools/test-nginx-3.sh b/.dev-tools/test-nginx-3.sh new file mode 100644 index 000000000..69250fc20 --- /dev/null +++ b/.dev-tools/test-nginx-3.sh @@ -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/mybots.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. +# ------------------------------------------------------------------------------ + diff --git a/.travis.yml b/.travis.yml index 5f7d5005f..bbaac471c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,8 +47,8 @@ script: # HERE WE TEST update-ngxblocker setup-ngxblocker - DISABLED UNTIL FIXED - bash .dev-tools/install-nginx-2.sh - bash .dev-tools/test-nginx-2.sh - #- bash .dev-tools/install-nginx-3.sh - #- bash .dev-tools/test-blocker-quicker.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 # FROM HERE WE TEST ANY NEW CHANGES TO THE BLOCKER