diff --git a/confs/global/map-referrer.conf b/confs/global/map-referrer.conf deleted file mode 100644 index d7e24d2..0000000 --- a/confs/global/map-referrer.conf +++ /dev/null @@ -1,5 +0,0 @@ -map $http_referer $bad_referrer { - hostnames; - default no; - %BLOCK_REFERRER% -} diff --git a/confs/global/map-user-agent.conf b/confs/global/map-user-agent.conf deleted file mode 100644 index 468c37c..0000000 --- a/confs/global/map-user-agent.conf +++ /dev/null @@ -1,4 +0,0 @@ -map $http_user_agent $bad_user_agent { - default no; - %BLOCK_USER_AGENT% -} diff --git a/scripts/referrers.sh b/scripts/referrers.sh index a49b987..f702913 100755 --- a/scripts/referrers.sh +++ b/scripts/referrers.sh @@ -1,5 +1,9 @@ #!/bin/sh +if [ ! -f "/etc/nginx/map-referrer.conf" ] ; then + echo "" > /etc/nginx/map-referrer.conf +fi + BLACKLIST="$(curl -s https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-referrers.list)" DATA="" IFS=$'\n' diff --git a/scripts/user-agents.sh b/scripts/user-agents.sh index f1c93c5..c3ac5fe 100755 --- a/scripts/user-agents.sh +++ b/scripts/user-agents.sh @@ -1,24 +1,18 @@ #!/bin/sh -# replace pattern in file -function replace_in_file() { - # escape slashes - pattern=$(echo "$2" | sed "s/\//\\\\\//g") - replace=$(echo "$3" | sed "s/\//\\\\\//g") - replace=$(echo "$replace" | sed "s/\\ /\\\\ /g") - sed -i "s/$pattern/$replace/g" "$1" -} +if [ ! -f "/etc/nginx/map-user-agent.conf" ] ; then + echo "" > /etc/nginx/map-user-agent.conf +fi BLACKLIST="$(curl -s https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-user-agents.list)" DATA="" IFS=$'\n' for ua in $BLACKLIST ; do - DATA="${DATA}~*(?:\\\\b)${ua}\(?:\\\\b) yes;\n" + DATA="${DATA}~*(?:\\\\b)${ua}(?:\\\\b) yes;\n" done DATA_ESCAPED=$(echo "$DATA" | sed 's: :\\\\ :g' | sed 's:\\\\ yes;: yes;:g' | sed 's:\\\\\\ :\\\\ :g') -cp /opt/confs/global/map-user-agent.conf /etc/nginx/map-user-agent.conf -replace_in_file "/etc/nginx/map-user-agent.conf" "%BLOCK_USER_AGENT%" "$DATA_ESCAPED" +echo -e "map \$http_user_agent \$bad_user_agent { default no; $DATA_ESCAPED }" > /etc/nginx/map-user-agent.conf cp /etc/nginx/map-user-agent.conf /cache if [ -f /tmp/nginx.pid ] ; then