Support for dynamic ip ranges from urls

- Adds ipranges command to fetch ip ranges from Cloudfront and Cloudflare
- Write the ipranges file on docker start
- Support disabling ipv4 as well as ipv6 now
- Prevent disabling both
This commit is contained in:
Jamie Curnow
2023-05-12 09:40:45 +10:00
parent f43e41d7d0
commit ab772d645b
18 changed files with 265 additions and 60 deletions

View File

@ -5,11 +5,9 @@ set -e
log_info 'Dynamic resolvers ...'
DISABLE_IPV6=$(echo "${DISABLE_IPV6:-}" | tr '[:upper:]' '[:lower:]')
# Dynamically generate resolvers file, if resolver is IPv6, enclose in `[]`
# thanks @tfmm
if [ "$(is_true "$DISABLE_IPV6")" = '1' ]; then
if [ "$(is_true "$NPM_DISABLE_IPV6")" = '1' ]; then
echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" { sub(/%.*$/,"",$2); print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf) ipv6=off valid=10s;" > /etc/nginx/conf.d/include/resolvers.conf
else
echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" { sub(/%.*$/,"",$2); print ($2 ~ ":")? "["$2"]": $2}' /etc/resolv.conf) valid=10s;" > /etc/nginx/conf.d/include/resolvers.conf
@ -17,3 +15,20 @@ fi
# Fire off acme.sh wrapper script to "install" itself if required
acme.sh -h > /dev/null 2>&1
# Generate IP Ranges from online CDN services
# continue on error, as this could be due to network errors
# and can be attempted again with a docker restart
rm -rf /etc/nginx/conf.d/include/ipranges.conf
set +e
RC=0
if [ "$(is_true "$DEVELOPMENT")" = '1' ]; then
echo '# ignored in development mode' > /etc/nginx/conf.d/include/ipranges.conf
else
/app/bin/ipranges > /etc/nginx/conf.d/include/ipranges.conf
RC=$?
fi
if [ "$RC" != '0' ]; then
log_warn 'Generation of IP Ranges file has an error. Check output of /etc/nginx/conf.d/include/ipranges.conf for more information.'
fi
set -e