-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathproxy.sh
executable file
·51 lines (44 loc) · 1.27 KB
/
proxy.sh
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
#!/bin/bash
die() { echo "$@" 1>&2 ; exit 1; }
ctn_id=`docker-compose ps -q | head -n 1`
[ -z "$ctn_id" ] && die "No container seems to be deployed. Abort!"
net_name=$(docker inspect \
--format='{{range $p, $conf := .NetworkSettings.Networks}} {{$p}} {{end}}' \
$ctn_id)
[ -z "$net_name" ] && die "Network name not found. Abort!"
net_id=$(docker network ls -f driver=bridge | grep $net_name | cut -f 1 -d " ")
[ -z "$net_id" ] && die "Network ID not found. Abort!"
##########################
# Setup the Firewall rules
##########################
fw_setup() {
echo -n "Add pre-routing rule for interface: br-$net_id ... "
sudo iptables -t nat -A PREROUTING -i br-$net_id -p tcp -j REDSOCKS
echo "done."
}
##########################
# Clear the Firewall rules
##########################
fw_clear() {
echo -n "Remove pre-routing rule for interface: br-$net_id ... "
sudo iptables -t nat -D PREROUTING -i br-$net_id -p tcp -j REDSOCKS
echo "done."
}
case "$1" in
start)
echo "Setting REDSOCKS firewall rules..."
fw_clear
fw_setup
echo "done."
;;
stop)
echo "Cleaning REDSOCKS firewall rules..."
fw_clear
echo "done."
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac
exit 0