ipset -exist create chnroute hash:net hashsize 64
sed -e "s/^/add chnroute /" /tmp/v2ray/chnroute.txt | ipset restore
echo ""
echo ""
echo "[setting iptables]"
iptables -t nat -N V2RAY
iptables -t nat -A V2RAY -d 0.0.0.0 -j RETURN
iptables -t nat -A V2RAY -d 127.0.0.1 -j RETURN
iptables -t nat -A V2RAY -d 192.168.0.0/16 -j RETURN


iptables -t nat -A V2RAY -m set --match-set chnroute dst -j RETURN

# Anything else should be redirected to Dokodemo-door's local port

iptables -t nat -A V2RAY -p tcp --dport 22:500 -j REDIRECT --to-ports 1234
#iptables -t nat -A V2RAY -p tcp --dport 22 -j REDIRECT --to-ports 1234
#iptables -t nat -A V2RAY -p tcp --dport 80 -j REDIRECT --to-ports 1234
#iptables -t nat -A V2RAY -p tcp --dport 443 -j REDIRECT --to-ports 1234
#iptables -t nat -A V2RAY -p tcp -j REDIRECT --to-ports 1234

iptables -t nat -A PREROUTING -p tcp -j V2RAY

cd /tmp/v2ray

SSL_CERT_FILE=./cacert.pem ./v2ray --config=/etc/storage/v2ray/config.json >/dev/null 2>&1 &
echo "[V2ray start]"
./v2ray-watchdog >/dev/null 2>&1 &