From 8427564f4d67cb65b20593c8031b73ed62a5825c Mon Sep 17 00:00:00 2001 From: bunkerity Date: Sun, 29 Mar 2020 16:18:31 +0200 Subject: [PATCH] user-agents escape fix --- scripts/user-agents.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/user-agents.sh b/scripts/user-agents.sh index eeff2f3..7e8e784 100755 --- a/scripts/user-agents.sh +++ b/scripts/user-agents.sh @@ -5,7 +5,7 @@ function replace_in_file() { # escape slashes pattern=$(echo "$2" | sed "s/\//\\\\\//g") replace=$(echo "$3" | sed "s/\//\\\\\//g") - replace=$(echo "$replace" | sed "s/\\ /\\\\ /g") + replace=$(echo "$replace" | sed "s/\\ /\\\\ /g") sed -i "s/$pattern/$replace/g" "$1" } @@ -13,10 +13,13 @@ BLACKLIST="$(curl https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimat 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/map-user-agent.conf /etc/nginx/map-user-agent.conf -replace_in_file "/etc/nginx/map-user-agent.conf" "%BLOCK_USER_AGENT%" "$DATA" +replace_in_file "/etc/nginx/map-user-agent.conf" "%BLOCK_USER_AGENT%" "$DATA_ESCAPED" + if [ -f /run/nginx/nginx.pid ] ; then /usr/sbin/nginx -s reload fi