automated DNS-based routing
This commit is contained in:
14
scripts/opt_bin/apply_unblock_rules.sh
Normal file
14
scripts/opt_bin/apply_unblock_rules.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/opt/bin/sh
|
||||
|
||||
set -o xtrace
|
||||
export PATH=/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
export HOME=/opt/root
|
||||
|
||||
ssh -i /opt/root/.ssg/id_dropbear dns@fb.megavenik.ru "dig a api.themoviedb.org +short" < /dev/zero | awk '/^[0-9]/{print "address=/api.themoviedb.org/"$1}' > /opt/etc/dnsmasq.themoviedb.conf
|
||||
echo "address=/api.themoviedb.org/::" >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
ssh -i /opt/root/.ssh/id_dropbear dns@fb.megavenik.ru "dig a image.tmdb.org +short" < /dev/zero | awk '/^[0-9]/{print "address=/image.tmdb.org/"$1}' >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
echo "address=/image.tmdb.org/::" >> /opt/etc/dnsmasq.themoviedb.conf
|
||||
/opt/bin/unblock_dnsmasq.sh
|
||||
/opt/etc/init.d/S56dnsmasq restart
|
||||
/opt/bin/unblock_ipset.sh
|
||||
|
||||
14
scripts/opt_bin/unblock_dnsmasq.sh
Normal file
14
scripts/opt_bin/unblock_dnsmasq.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
cat /dev/null > /opt/etc/unblock.dnsmasq
|
||||
|
||||
while read line || [ -n "$line" ]; do
|
||||
|
||||
[ -z "$line" ] && continue
|
||||
[ "${line:0:1}" = "#" ] && continue
|
||||
|
||||
echo $line | grep -Eq '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' && continue
|
||||
|
||||
echo "ipset=/$line/unblock" >> /opt/etc/unblock.dnsmasq
|
||||
|
||||
done < /opt/etc/unblock.txt
|
||||
33
scripts/opt_bin/unblock_ipset.sh
Normal file
33
scripts/opt_bin/unblock_ipset.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
until ADDRS=$(dig +short google.com @localhost) && [ -n "$ADDRS" ] > /dev/null 2>&1; do sleep 5; done
|
||||
|
||||
while read line || [ -n "$line" ]; do
|
||||
|
||||
[ -z "$line" ] && continue
|
||||
[ "${line:0:1}" = "#" ] && continue
|
||||
|
||||
cidr=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}')
|
||||
|
||||
if [ ! -z "$cidr" ]; then
|
||||
ipset -exist add unblock $cidr
|
||||
continue
|
||||
fi
|
||||
|
||||
range=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}-[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
|
||||
|
||||
if [ ! -z "$range" ]; then
|
||||
ipset -exist add unblock $range
|
||||
continue
|
||||
fi
|
||||
|
||||
addr=$(echo $line | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
|
||||
|
||||
if [ ! -z "$addr" ]; then
|
||||
ipset -exist add unblock $addr
|
||||
continue
|
||||
fi
|
||||
|
||||
dig +short $line @localhost | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{system("ipset -exist add unblock "$1)}'
|
||||
|
||||
done < /opt/etc/unblock.txt
|
||||
Reference in New Issue
Block a user