mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-02 10:40:36 +00:00
setup-ngxblocker: fix check_wildcard() / improve formatting
fixes https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/pull/45
This commit is contained in:
parent
fabf34e74a
commit
b102e561ea
1 changed files with 8 additions and 8 deletions
|
@ -79,7 +79,8 @@ whitelist_ips() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "WARN: dig binary missing => install bind-tools to whitelist external ip address"
|
printf "%-10s %-$(( $col_size -14 ))s %-s\n" \
|
||||||
|
"WARN:" "dig binary missing" "=> install bind-tools to whitelist external ip address"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ whitelist_domains() {
|
||||||
|
|
||||||
for domain in $domain_list; do
|
for domain in $domain_list; do
|
||||||
if ! grep "$domain" $conf >/dev/null 2>&1; then
|
if ! grep "$domain" $conf >/dev/null 2>&1; then
|
||||||
printf "%-s %-$(( $domain_len +2))s %s\n" "Whitelisting domain:" "$domain" "=> $conf"
|
printf "%-s %-$(( $domain_len +2))s %s\n" "Whitelist:" "$domain" "=> $conf"
|
||||||
if [ "$DRY_RUN" = "N" ]; then
|
if [ "$DRY_RUN" = "N" ]; then
|
||||||
printf "%-$(( $domain_len +8))s %s\n" "\"~*$domain\"" "0;" >> $conf
|
printf "%-$(( $domain_len +8))s %s\n" "\"~*$domain\"" "0;" >> $conf
|
||||||
fi
|
fi
|
||||||
|
@ -111,7 +112,7 @@ longest_str() {
|
||||||
|
|
||||||
check_wildcard() {
|
check_wildcard() {
|
||||||
local file=$1 dir=$(basename $2)
|
local file=$1 dir=$(basename $2)
|
||||||
local check=$(grep -E "include[[:alnum:] /]+$dir/\*;" $file)
|
local check="$(grep -E "include[[:alnum:] /]+$dir/\*" $file)"
|
||||||
echo $check
|
echo $check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +265,7 @@ check_online() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local include_url= file= line= file_list=
|
local include_url= file= line= file_list= col_size=
|
||||||
local CONF_FILES= VHOST_INCLUDES=
|
local CONF_FILES= VHOST_INCLUDES=
|
||||||
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
|
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
|
||||||
|
|
||||||
|
@ -305,6 +306,7 @@ main() {
|
||||||
# gather vhosts
|
# gather vhosts
|
||||||
file_list=$(find_vhosts)
|
file_list=$(find_vhosts)
|
||||||
check_config $file_list
|
check_config $file_list
|
||||||
|
col_size=$(( $(longest_str $file_list) + $(echo $BOTS_DIR | wc -m) ))
|
||||||
|
|
||||||
# by default do not change any files
|
# by default do not change any files
|
||||||
if [ -z "$DRY_RUN" ]; then
|
if [ -z "$DRY_RUN" ]; then
|
||||||
|
@ -317,8 +319,7 @@ main() {
|
||||||
for file in $file_list; do
|
for file in $file_list; do
|
||||||
line=$(find_includes $file include last server_ last location first )
|
line=$(find_includes $file include last server_ last location first )
|
||||||
if [ -n "$(check_wildcard $file $BOTS_DIR)" ]; then
|
if [ -n "$(check_wildcard $file $BOTS_DIR)" ]; then
|
||||||
local col_size=$(( $(longest_str $file_list) + $(echo $BOTS_DIR | wc -m) ))
|
printf "%-10s %-$(( $col_size -14 ))s %s\n" "WARN:" "$BOTS_DIR/* detected" "=> $file"
|
||||||
printf "%-10s %-$(( $col_size -19 ))s %s\n" "WARN:" "$BOTS_DIR/* detected" "=> $file"
|
|
||||||
else # don't use wildcards in vhost files
|
else # don't use wildcards in vhost files
|
||||||
add_includes $line $file $BOTS_DIR $VHOST_INCLUDES
|
add_includes $line $file $BOTS_DIR $VHOST_INCLUDES
|
||||||
fi
|
fi
|
||||||
|
@ -327,8 +328,7 @@ main() {
|
||||||
# update main config
|
# update main config
|
||||||
line=$(find_includes $MAIN_CONF include last http first '\}' last )
|
line=$(find_includes $MAIN_CONF include last http first '\}' last )
|
||||||
if [ -n "$(check_wildcard $MAIN_CONF $CONF_DIR)" ]; then
|
if [ -n "$(check_wildcard $MAIN_CONF $CONF_DIR)" ]; then
|
||||||
local col_size=$(( $(longest_str $file_list) + $(echo $CONF_DIR | wc -m) ))
|
printf "%-10s %-$(( $col_size -14 ))s %s\n" "INFO:" "$CONF_DIR/* detected" "=> $MAIN_CONF"
|
||||||
printf "%-10s %-$(( $col_size -19 ))s %s\n" "INFO:" "$CONF_DIR/* detected" "=> $MAIN_CONF"
|
|
||||||
else # wildcard conf.d ok in nginx.conf
|
else # wildcard conf.d ok in nginx.conf
|
||||||
add_includes $line $MAIN_CONF $CONF_DIR $CONF_FILES
|
add_includes $line $MAIN_CONF $CONF_DIR $CONF_FILES
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue