mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
user-agents escape fix
This commit is contained in:
parent
c56bde4f0c
commit
8427564f4d
1 changed files with 6 additions and 3 deletions
|
@ -5,7 +5,7 @@ function replace_in_file() {
|
||||||
# escape slashes
|
# escape slashes
|
||||||
pattern=$(echo "$2" | sed "s/\//\\\\\//g")
|
pattern=$(echo "$2" | sed "s/\//\\\\\//g")
|
||||||
replace=$(echo "$3" | 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"
|
sed -i "s/$pattern/$replace/g" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,10 +13,13 @@ BLACKLIST="$(curl https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimat
|
||||||
DATA=""
|
DATA=""
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for ua in $BLACKLIST ; do
|
for ua in $BLACKLIST ; do
|
||||||
DATA="${DATA}~*(?:\b)${ua}\(?:\b) yes;\n"
|
DATA="${DATA}~*(?:\\\\b)${ua}\(?:\\\\b) yes;\n"
|
||||||
done
|
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
|
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
|
if [ -f /run/nginx/nginx.pid ] ; then
|
||||||
/usr/sbin/nginx -s reload
|
/usr/sbin/nginx -s reload
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue