mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-04 11:40:22 +00:00
commit
82fd7905ad
1 changed files with 22 additions and 12 deletions
|
@ -82,13 +82,17 @@ check_config() {
|
|||
local files="$*"
|
||||
|
||||
if [ -z "$files" ]; then
|
||||
echo "no vhost files in: $VHOST_DIR/*.$VHOST_EXT => exiting."
|
||||
exit 1
|
||||
printf "${BOLDGREEN}using a file extension for vhost files allows multiple domains to be included with a single directive in nginx.conf:\n\n"
|
||||
printf "${BOLDWHITE}include /etc/nginx/sites-enabled/*.vhost;\n\n"
|
||||
printf "${BOLDYELLOW}see command line switches below: ${BOLDGREEN}-e ${RESET}to customise the vhost file extension\n\n"
|
||||
printf "${BOLDMAGENTA}no vhost files in:${RESET} [ $VHOST_DIR/*.$VHOST_EXT ] ${BOLDWHITE}=> exiting${RESET}.\n\n"
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ ! -f "$MAIN_CONF" ]; then
|
||||
echo "NGINX main configuration ('$MAIN_CONF') not found => exiting."
|
||||
exit 1
|
||||
printf "${BOLDYELLOW}see command line switches below: ${BOLDGREEN}-m ${RESET}to customise the location of ${BOLDWHITE}nginx.conf${RESET}\n\n"
|
||||
printf "${BOLDWHITE}NGINX main configuration${RESET} [ $MAIN_CONF ] ${BOLDMAGENTA}not found ${BOLDWHITE}=> exiting${RESET}.\n\n"
|
||||
usage
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -340,9 +344,13 @@ main() {
|
|||
get_options $@
|
||||
check_depends
|
||||
|
||||
include_url=$REPO/include_filelist.txt
|
||||
# check vhosts
|
||||
file_list=$(find_vhosts)
|
||||
check_config $file_list
|
||||
|
||||
# check repo is online & source includes
|
||||
include_url=$REPO/include_filelist.txt
|
||||
|
||||
printf "Checking url: $include_url\n"
|
||||
if [ -n "$(check_online $include_url)" ]; then
|
||||
local tmp=$(mktemp)
|
||||
|
@ -366,11 +374,6 @@ main() {
|
|||
n*|N*) VHOST_INCLUDES=$(echo $VHOST_INCLUDES | sed 's|ddos.conf||');;
|
||||
esac
|
||||
|
||||
# gather vhosts
|
||||
file_list=$(find_vhosts)
|
||||
check_config $file_list
|
||||
col_size=$(( $(longest_str $CONF_FILES) + $(echo $CONF_DIR | wc -m) + 10 ))
|
||||
|
||||
# by default do not change any files
|
||||
if [ -z "$DRY_RUN" ]; then
|
||||
printf "\n** Dry Run ** | not updating files | run as '$(basename $0) -x' to setup files.\n\n"
|
||||
|
@ -378,6 +381,9 @@ main() {
|
|||
printf "\n"
|
||||
fi
|
||||
|
||||
# calculate column size for better message printing
|
||||
col_size=$(( $(longest_str $CONF_FILES) + $(echo $CONF_DIR | wc -m) + 10 ))
|
||||
|
||||
# update main config
|
||||
line=$(find_includes $MAIN_CONF include last http first '\}' last )
|
||||
if [ -n "$(check_wildcard $MAIN_CONF $CONF_DIR)" ]; then # also recalculate column width
|
||||
|
@ -390,10 +396,14 @@ main() {
|
|||
# update vhosts
|
||||
for file in $file_list; do
|
||||
line=$(find_includes $file include last server_ last location first )
|
||||
|
||||
if [ -n "$(check_wildcard $file $BOTS_DIR)" ]; then
|
||||
# do not use wildcards in vhost files
|
||||
printf "%-10s %-${col_size}s %s\n" "WARN:" "$BOTS_DIR/* detected" "=> $file"
|
||||
else # don't use wildcards in vhost files
|
||||
add_includes $line $file $BOTS_DIR $col_size $VHOST_INCLUDES
|
||||
else # do not add includes to vhosts without root directive (i.e redirects)
|
||||
if grep -Ew [[:space:]]+root $file 1>/dev/null; then
|
||||
add_includes $line $file $BOTS_DIR $col_size $VHOST_INCLUDES
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue