Skip to content

Commit

Permalink
Add validation for curl output of ips.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
yzdann committed Jan 21, 2021
1 parent 75706ee commit 1b7eb30
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions arvancloud-sync-ips.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/bin/bash

ARVANCLOUD_FILE_PATH=/etc/nginx/arvancloud
ARVANCLOUD_CDN_IPS_TXT_URL="https://www.arvancloud.com/fa/ips.txt"

VALID_IP_OCTET_REGEX="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
IP_WITH_SUBNET_REGEX="^$VALID_IP_OCTET_REGEX\.$VALID_IP_OCTET_REGEX\.$VALID_IP_OCTET_REGEX\.$VALID_IP_OCTET_REGEX\/[0-9]+$"
IP_ADDRS=$(curl -s -L $ARVANCLOUD_CDN_IPS_TXT_URL | grep -E -o "$IP_WITH_SUBNET_REGEX")

if [ -z "$IP_ADDRS" ];
then
echo "Couldn't extract CDN any ip address from $ARVANCLOUD_CDN_IPS_TXT_URL"
exit 1
fi

echo "#Arvan" > $ARVANCLOUD_FILE_PATH;
echo "" >> $ARVANCLOUD_FILE_PATH;

echo "# - IPv4" >> $ARVANCLOUD_FILE_PATH;
for i in `curl https://www.arvancloud.com/fa/ips.txt`; do
echo "set_real_ip_from $i;" >> $ARVANCLOUD_FILE_PATH;
for ip in $IP_ADDRS; do
echo "set_real_ip_from $ip;" >> $ARVANCLOUD_FILE_PATH;
done

echo "" >> $ARVANCLOUD_FILE_PATH;
Expand Down

0 comments on commit 1b7eb30

Please sign in to comment.