vpn-policy-routing: custom user scripts improvements 14889/head
authorStan Grishin <stangri@melmac.net>
Wed, 24 Feb 2021 19:44:26 +0000 (19:44 +0000)
committerStan Grishin <stangri@melmac.net>
Wed, 24 Feb 2021 19:44:26 +0000 (19:44 +0000)
Signed-off-by: Stan Grishin <stangri@melmac.net>
net/vpn-policy-routing/Makefile
net/vpn-policy-routing/files/vpn-policy-routing.aws.user
net/vpn-policy-routing/files/vpn-policy-routing.netflix.user

index 5f86ae9dacc60012548082f575402cf7a8ef8ad4..a1e049ba98131c9dd7494f3a9c4075ef55858162 100644 (file)
@@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=vpn-policy-routing
 PKG_VERSION:=0.3.2
-PKG_RELEASE:=12
+PKG_RELEASE:=14
 PKG_LICENSE:=GPL-3.0-or-later
 PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
 
index 788dc7c841e28fafca23d3961d0a9f4a72d1f8d9..a00770be75c0641f3fa5cd61f0f74af8aa92c224 100644 (file)
@@ -4,8 +4,16 @@
 TARGET_IPSET='wan'
 
 TARGET_URL="https://ip-ranges.amazonaws.com/ip-ranges.json"
-TARGET_FNAME="/var/tmp_aws_ip_ranges"
+TARGET_FNAME="/var/vpn-policy-routing_tmp_aws_ip_ranges"
 
-curl "$TARGET_URL" 2>/dev/null | grep "ip_prefix" | sed 's/^.*\"ip_prefix\": \"//; s/\",//' > "$TARGET_FNAME"
-awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -!
+_ret=1
+
+if [ ! -s "$TARGET_FNAME" ]; then
+       curl "$TARGET_URL" 2>/dev/null | grep "ip_prefix" | sed 's/^.*\"ip_prefix\": \"//; s/\",//' > "$TARGET_FNAME"
+fi
+if [ -s "$TARGET_FNAME" ]; then
+       awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -! && _ret=0
+fi
 rm -f "$TARGET_FNAME"
+
+return $_ret
index d2fd6acc11048183e41242a897a319bfe09d8c95..bffb6a6d153691587e6b5b50f2ced78a2a2beb4e 100644 (file)
@@ -5,28 +5,31 @@
 
 TARGET_IPSET='wan'
 TARGET_ASN='2906'
-TARGET_FNAME="/var/tmp_AS${TARGET_ASN}"
+TARGET_FNAME="/var/vpn-policy-routing_tmp_AS${TARGET_ASN}"
 #DB_SOURCE='ipinfo.io'
 #DB_SOURCE='api.hackertarget.com'
 DB_SOURCE='api.bgpview.io'
 
 _ret=1
-if [ "$DB_SOURCE" = "ipinfo.io" ]; then
-       TARGET_URL="https://ipinfo.io/AS${TARGET_ASN}"
-       curl "$TARGET_URL" 2>/dev/null | grep -E "a href.*${TARGET_ASN}\/" | grep -v ":" | sed "s/^.*<a href=\"\/AS${TARGET_ASN}\///; s/\" >//" > "$TARGET_FNAME"
-fi
 
-if [ "$DB_SOURCE" = "api.hackertarget.com" ]; then
-       TARGET_URL="https://api.hackertarget.com/aslookup/?q=AS${TARGET_ASN}"
-       curl "$TARGET_URL" 2>/dev/null | sed '1d' > "$TARGET_FNAME"
-fi
+if [ ! -s "$TARGET_FNAME" ]; then
+       if [ "$DB_SOURCE" = "ipinfo.io" ]; then
+               TARGET_URL="https://ipinfo.io/AS${TARGET_ASN}"
+               curl "$TARGET_URL" 2>/dev/null | grep -E "a href.*${TARGET_ASN}\/" | grep -v ":" | sed "s/^.*<a href=\"\/AS${TARGET_ASN}\///; s/\" >//" > "$TARGET_FNAME"
+       fi
+
+       if [ "$DB_SOURCE" = "api.hackertarget.com" ]; then
+               TARGET_URL="https://api.hackertarget.com/aslookup/?q=AS${TARGET_ASN}"
+               curl "$TARGET_URL" 2>/dev/null | sed '1d' > "$TARGET_FNAME"
+       fi
 
-if [ "$DB_SOURCE" = "api.bgpview.io" ]; then
-       TARGET_URL="https://api.bgpview.io/asn/${TARGET_ASN}/prefixes"
-       if command -v jq >/dev/null 2>&1; then
-               curl -s "$TARGET_URL" 2>/dev/null | jq -r '.data.ipv4_prefixes[].prefix' > "$TARGET_FNAME"
-       else
-               curl -s "$TARGET_URL" 2>/dev/null | sed -ne 's/.*"ipv4_prefixes":\(.*\),"ipv6_prefixes":.*/\1\n/g; s/\}\},/&\n/g; s/"parent":{"prefix":/"parent":{"parent_prefix":/gp' | sed -ne 's/.*"prefix":"\(.\{0,20\}\)",".*/\1/g; s/\\//gp' > "$TARGET_FNAME"
+       if [ "$DB_SOURCE" = "api.bgpview.io" ]; then
+               TARGET_URL="https://api.bgpview.io/asn/${TARGET_ASN}/prefixes"
+               if command -v jq >/dev/null 2>&1; then
+                       curl -s "$TARGET_URL" 2>/dev/null | jq -r '.data.ipv4_prefixes[].prefix' > "$TARGET_FNAME"
+               else
+                       curl -s "$TARGET_URL" 2>/dev/null | sed -ne 's/.*"ipv4_prefixes":\(.*\),"ipv6_prefixes":.*/\1\n/g; s/\}\},/&\n/g; s/"parent":{"prefix":/"parent":{"parent_prefix":/gp' | sed -ne 's/.*"prefix":"\(.\{0,20\}\)",".*/\1/g; s/\\//gp' > "$TARGET_FNAME"
+               fi
        fi
 fi