mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-02 02:29:58 +00:00
setup-ngxblocker: add update_paths()
* check for & download includes * update hard coded bots.d path in globalblacklist.conf
This commit is contained in:
parent
130f1655cb
commit
4b012ef0ac
1 changed files with 94 additions and 48 deletions
|
@ -12,6 +12,7 @@ VHOST_DIR=/etc/nginx/sites-available
|
|||
BOTS_DIR=/etc/nginx/bots.d
|
||||
CONF_DIR=/etc/nginx/conf.d
|
||||
MAIN_CONF=/etc/nginx/nginx.conf
|
||||
INSTALLER=/usr/sbin/install-ngxblocker
|
||||
# setting Y / yes will whitelist only directories in $www
|
||||
# that look like domain.names
|
||||
DOT_NAMES="Y"
|
||||
|
@ -21,6 +22,13 @@ INC_DDOS="Y"
|
|||
|
||||
####### end user configuration ###########################
|
||||
|
||||
BOLDGREEN="\033[1m\033[32m"
|
||||
BOLDMAGENTA="\033[1m\033[35m"
|
||||
BOLDRED="\033[1m\033[31m"
|
||||
BOLDYELLOW="\033[1m\033[33m"
|
||||
BOLDWHITE="\033[1m\033[37m"
|
||||
RESET="\033[0m"
|
||||
|
||||
usage() {
|
||||
local script=$(basename $0)
|
||||
cat <<EOF
|
||||
|
@ -33,6 +41,7 @@ Usage: $script [OPTIONS]
|
|||
[ -b ] : Bot rules directory (default: $BOTS_DIR)
|
||||
[ -c ] : NGINX conf directory (default: $CONF_DIR)
|
||||
[ -m ] : NGINX main configuration (default: $MAIN_CONF)
|
||||
[ -i ] : Change installer path (default: $INSTALLER)
|
||||
[ -n ] : NO whitelist of .names only (default: $DOT_NAMES)
|
||||
[ -d ] : NO insert of DDOS rule (default: $INC_DDOS)
|
||||
[ -x ] : Actually change the files (default: don't change anything)
|
||||
|
@ -47,6 +56,28 @@ EOF
|
|||
exit 0
|
||||
}
|
||||
|
||||
update_paths() {
|
||||
# variables in nginx include files not currently possible
|
||||
# updates hard coded bots.d path in globalblacklist.conf
|
||||
local blacklist=$1 include_paths= dir= x=
|
||||
|
||||
if ! grep "$BOTS_DIR" $blacklist 1>/dev/null; then
|
||||
if [ -d $BOTS_DIR ]; then
|
||||
printf "${BOLDGREEN}Updating bots.d path${RESET}: ${BOLDWHITE}$BOTS_DIR => $blacklist${RESET}\n"
|
||||
include_paths=$(grep -E "include /.*.conf;$" $blacklist | awk '{print $2}' | tr -d ';')
|
||||
|
||||
for x in $include_paths; do
|
||||
dir=$(dirname $x)
|
||||
sed -i "s|$dir|$BOTS_DIR|" $blacklist
|
||||
done
|
||||
else
|
||||
printf "${BOLDRED}ERROR${RESET}: '$BOTS_DIR' does not exist => ${BOLDWHITE}running $INSTALLER${RESET}.\n"
|
||||
$INSTALL_INC
|
||||
update_paths $blacklist
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_config() {
|
||||
local files="$*"
|
||||
|
||||
|
@ -211,6 +242,11 @@ check_args() {
|
|||
exit 1
|
||||
fi
|
||||
;;
|
||||
script) if [ ! -x $arg ]; then
|
||||
printf "$msg '$arg' is not executable / does not exist.\n"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
none) printf "$msg argument.\n"; exit 1;;
|
||||
esac
|
||||
}
|
||||
|
@ -234,6 +270,7 @@ get_options() {
|
|||
b) BOTS_DIR=$arg; check_args $opts path $arg ;;
|
||||
c) CONF_DIR=$arg; check_args $opts path $arg ;;
|
||||
m) MAIN_CONF=$arg; check_args $opts path $arg ;;
|
||||
i) INSTALLER=$arg; check_args $opts script $arg ;;
|
||||
n) DOT_NAMES=N ;;
|
||||
d) INC_DDOS=N ;;
|
||||
x) DRY_RUN=N ;;
|
||||
|
@ -242,6 +279,8 @@ get_options() {
|
|||
:) check_args $OPTARG none none ;;
|
||||
esac
|
||||
done
|
||||
|
||||
INSTALL_INC="$INSTALLER -b $BOTS_DIR -c $CONF_DIR -x"
|
||||
}
|
||||
|
||||
wget_opts() {
|
||||
|
@ -266,7 +305,7 @@ check_online() {
|
|||
}
|
||||
|
||||
main() {
|
||||
local include_url= file= line= file_list= col_size=
|
||||
local include_url= file= line= file_list= col_size= blacklist=
|
||||
local CONF_FILES= VHOST_INCLUDES=
|
||||
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
|
||||
|
||||
|
@ -342,6 +381,13 @@ main() {
|
|||
else
|
||||
printf "\nWeb directory not found ('$WWW'): not whitelisting domains.\n"
|
||||
fi
|
||||
|
||||
# download new bots.d / conf.d files
|
||||
printf "\nChecking for missing includes:\n\n"
|
||||
$INSTALL_INC
|
||||
blacklist=$(find $CONF_DIR -type f -name globalblacklist.conf)
|
||||
# set custom bots.d path
|
||||
update_paths $blacklist
|
||||
}
|
||||
|
||||
## START ##
|
||||
|
|
Loading…
Add table
Reference in a new issue