-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.sh
135 lines (123 loc) · 4.03 KB
/
script.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-s|--server)
SERVER="$2"
shift # past argument
shift # past value
;;
-p|--proxy)
PROXY="$2"
shift # past argument
shift # past value
;;
-a|--alireza)
ALIREZA="$2"
shift # past argument
shift # past value
;;
--iran)
IRAN=YES
shift # past argument
;;
--europe)
EUROPE=YES
shift # past argument
;;
-i|--install)
INSTALL=YES
shift # past argument
;;
-u|--update)
UPDATE=YES
shift # past argument
;;
-r|--restart)
RESTART=YES
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# Iran server, responsible for iptables nat ###################################
if [ "$IRAN" == "YES" ]; then
# Installing iptables -----------------------------------------------------
if [ "$INSTALL" == "YES" ]; then
echo "Installing on Iran server..."
sudo apt install -y netfilter-persistent
sudo apt install -y iptables-persistent
sudo ufw disable
sudo sysctl net.ipv4.ip_forward=1
sudo sh -c 'echo net.core.default_qdisc=fq >> /etc/sysctl.conf'
sudo sh -c 'echo net.ipv4.tcp_congestion_control=bbr >> /etc/sysctl.conf'
sudo sysctl -p
echo "Installation finished"
fi
# Updating europe server ip address ---------------------------------------
if [ "$UPDATE" == "YES" ] || [ "$INSTALL" == "YES" ]; then
# reset -------------------------------------
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo netfilter-persistent save 2> /dev/null
sudo netfilter-persistent reload 2> /dev/null
sudo service iptables restart
# accept ssh --------------------------------
sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j ACCEPT
# redirect alireza ports --------------------
if [ -v ALIREZA ]; then
sudo iptables -t nat -A PREROUTING -p tcp --dport 8050 -j DNAT --to-destination $ALIREZA:8050
sudo iptables -t nat -A PREROUTING -p tcp -m multiport --dports 1000:6000 -j DNAT --to-destination $ALIREZA
fi
# accept low ports --------------------------
sudo iptables -t nat -A PREROUTING -p tcp --dport 8050 -j ACCEPT
sudo iptables -t nat -A PREROUTING -p tcp -m multiport --dports 1000:6000 -j ACCEPT
# redirect proxy ports ----------------------
if [ -v PROXY ]; then
sudo iptables -t nat -A PREROUTING -p tcp -m multiport --dports 445,777 -j DNAT --to-destination $PROXY:445
fi
# redirect other ports ----------------------
sudo iptables -t nat -A PREROUTING -p all -j DNAT --to-destination $SERVER
# post-routing ------------------------------
sudo iptables -t nat -A POSTROUTING ! -o lo -j MASQUERADE
# save and reload ---------------------------
sudo netfilter-persistent save 2> /dev/null
sudo netfilter-persistent reload 2> /dev/null
sudo service iptables restart
echo "[INF] Iran server updated successfully"
fi
# Restarting iptables -----------------------------------------------------
if [ "$RESTART" == "YES" ]; then
sudo sysctl net.ipv4.ip_forward=1 1> /dev/null
sudo service iptables restart
echo "[INF] Iran server restarted successfully"
fi
fi
# Europe server, responsible for x-ui #########################################
if [ "$EUROPE" == "YES" ]; then
# Installing x-ui ---------------------------------------------------------
if [ "$INSTALL" == "YES" ]; then
echo "Installing on Europe server..."
bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)
echo "Installation finished"
fi
# Restarting x-ui ---------------------------------------------------------
if [ "$RESTART" == "YES" ]; then
x-ui restart
fi
fi