diff --git a/README.md b/README.md index c32852d..37f9c59 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,43 @@ # UnblockDomains -Scripts for unblock domains +OpenWRT scripts for unblock domains + +# How to use +Few steps + +## 1. Install OpenVPN +Install OpenVPN into OpenWRT device + +## 2. Install package bind-hos +```sh +opkg update +opkg install bind-host +``` + +## 3. Copy scripts into router +From host mashine +```sh +scp unblocker.sh /etc/openvpn/unblocker.sh +``` + +### Set executable flag +In router +```sh +chmod +x unblocker.sh +``` + + +## 4. Add settings and domain configuration files +Run in folder with scripts +```sh +echo TUN=`ifconfig | grep tun | awk '{print $1}'` > settings.conf +touch domains.conf +``` + +## 5. Add domains +Add list of domains into `domains.conf` + +## 6. Run script +```sh +./unblocker.sh +``` + diff --git a/unblocker.sh b/unblocker.sh index 1d9fd9c..dda6d95 100755 --- a/unblocker.sh +++ b/unblocker.sh @@ -1,7 +1,7 @@ -#!/bin/bash +#!/bin/sh ## Intial settings -SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +SCRIPT_DIR=`pwd` CONFIG_PATH="$SCRIPT_DIR/settings.conf" DOMAINS_PATH="$SCRIPT_DIR/domains.conf" @@ -25,17 +25,22 @@ if [ ! -f "$DOMAINS_PATH" ]; then exit 1 fi +## Add Google DNS into route table +route add 8.8.8.8/32 dev $TUN; +route add 8.8.4.4/32 dev $TUN; +route add 77.88.8.8/32 dev $TUN; + ## Process domains while read -r DOMAIN do echo "Start to process domain [$DOMAIN]..." >&2 - DOMAIN_IPS="$(host -t a "$DOMAIN" | awk '{print $4}' | egrep ^[1-9] | sort | uniq)" + DOMAIN_IPS="$(host -t a "$DOMAIN" | awk '{print $4}' | egrep ^[1-9] | awk -F. '{print $1"."$2"."$3".0/24"}' | sort | uniq)" - for IP in ${DOMAIN_IPS[*]} + for IP in ${DOMAIN_IPS} do echo " * Adding route for IP [$IP]" - #route add -net "$IP" dev "$TUN" + route add -net "$IP" dev "$TUN" done echo "End of process domain [$DOMAIN]" >&2