This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dnstun
100 lines (79 loc) · 1.62 KB
/
dnstun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Update Firewall & Tunnel Configuration
#################
# Configuration #
#################
CFGDIR=/etc/dnstun
CFGURL=$1
DNSMASQ="/etc/dnsmasq.conf"
SNIPROXY="/etc/sniproxy.conf"
#IP=$(ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
IP=$(curl -s http://myip.enix.org/REMOTE_ADDR)
################
# Update Lists #
################
# Download Host List
wget -O $CFGDIR/host $CFGURL/host
# Download User List
wget -O $CFGDIR/user $CFGURL/user
################
# Update Hosts #
################
# Check Configuration
CONFCS="$(cksum $DNSMASQ)"
# Write Configuration
cat << EOF > $DNSMASQ
bogus-priv
domain-needed
no-poll
no-resolv
server=8.8.8.8
server=8.8.4.4
EOF
# Loop Over Host List
while read i; do
# Add Host To Configuration
echo "address=/$i/$IP" >> $DNSMASQ
done < $CFGDIR/host
# Check For Changes
if [ "$CONFCS" != "$(cksum $DNSMASQ)" ]; then
# Restart Service
service dnsmasq restart
fi
# Check Configuration
CONFCS="$(cksum $SNIPROXY)"
# Write Configuration
cat << EOF > $SNIPROXY
pidfile /var/tmp/sniproxy.pid
user daemon
listener 80 {
proto http
}
listener 443 {
proto tls
}
table {
EOF
# Loop Over Host List
while read i; do
# Add Host To Configuration
echo "$i *" >> $SNIPROXY
done < $CFGDIR/host
echo "}" >> $SNIPROXY
# Check For Changes
if [ "$CONFCS" != "$(cksum $SNIPROXY)" ]; then
# Stop Service
killall sniproxy
# Start Service
sniproxy
fi
################
# Update Users #
################
# Clear Firewall
iptables -F DYNAMIC
# Loop Over User List
while read i; do
# Add User To Firewall
iptables -A DYNAMIC -s "$i" -j ACCEPT
done < $CFGDIR/user