From 186192d9685f5dc34660bc41ecd9cfd6e610ccb7 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 17 Aug 2019 23:54:28 +0200 Subject: [PATCH] nginx_ua_block_pleroma_rejects: Don't filter out wildcard domains. --- nginx_ua_block_pleroma_rejects.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nginx_ua_block_pleroma_rejects.sh b/nginx_ua_block_pleroma_rejects.sh index bbda118..14ffba5 100755 --- a/nginx_ua_block_pleroma_rejects.sh +++ b/nginx_ua_block_pleroma_rejects.sh @@ -4,10 +4,10 @@ # Save the output to a file and include it in an nginx configuration file. Then # add `if ($blockedagent) { return 403; }` to your server blocks. -# Version: 2019-08-17_2 +# Version: 2019-08-17_3 -function get_domains() # Outputs domains, separated by newline. +function get_domains() # Output domains, separated by newline. { local instance="${1}" local nodeinfo=$(curl -s "https://${instance}/nodeinfo/2.1.json") @@ -17,14 +17,15 @@ function get_domains() # Outputs domains, separated by newline. sed -e 's/\[//' -e 's/\]//' -e 's/"//g' -e 's/,/\n/g' <<<"${domains_json}" } -function print_entry() +function print_entry() # Output map entry. { local domain="${1}" - # Filter out wildcard domains. - if ! [[ "${domain}" =~ "\*" ]]; then - domain=$(sed 's/\./\\./g' <<<${domain}) - echo " ~*${domain} 1;" - fi + + # Transform strings to regular expressions. + domain=$(sed 's/\./\\./g' <<<${domain}) # . → \. + domain=$(sed 's/\*/.*/g' <<<${domain}) # * → .* + + echo " ~*${domain} 1;" } function main() @@ -33,7 +34,8 @@ function main() if [[ -z "${instance}" ]]; then echo "Usage: ${ZSH_ARGZERO} instance" >&2 - echo " ${ZSH_ARGZERO} instance > /etc/nginx/useragents_fedi.rules" + echo " ${ZSH_ARGZERO} instance" \ + "> /etc/nginx/useragents_fedi.rules" >&2 return 1 fi if ! command -v curl > /dev/null; then