-
Notifications
You must be signed in to change notification settings - Fork 47
/
FtTunnel.sh
287 lines (249 loc) · 8.98 KB
/
FtTunnel.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
root_access() {
# Check if the script is running as root
if [ "$EUID" -ne 0 ]; then
echo "This script requires root access. please run as root."
exit 1
fi
}
detect_distribution() {
# Detect the Linux distribution
local supported_distributions=("ubuntu" "debian" "centos" "fedora")
if [ -f /etc/os-release ]; then
source /etc/os-release
if [[ "${ID}" = "ubuntu" || "${ID}" = "debian" || "${ID}" = "centos" || "${ID}" = "fedora" ]]; then
package_manager="apt-get"
[ "${ID}" = "centos" ] && package_manager="yum"
[ "${ID}" = "fedora" ] && package_manager="dnf"
else
echo "Unsupported distribution!"
exit 1
fi
else
echo "Unsupported distribution!"
exit 1
fi
}
check_dependencies() {
detect_distribution
local dependencies=("wget" "lsof" "iptables" "unzip" "git" "curl" "tar")
for dep in "${dependencies[@]}"; do
if ! command -v "${dep}" &> /dev/null; then
echo "${dep} is not installed. Installing..."
sudo "${package_manager}" install "${dep}" -y
fi
done
}
#Check installed service
check_installed() {
if [ -f "/etc/systemd/system/faketunnel.service" ]; then
echo "The service is already installed."
exit 1
fi
}
#Check installed service
check_installed2() {
if [ -f "/etc/systemd/system/faketunnelsingle.service" ]; then
echo "The service is already installed."
exit 1
fi
}
# Function to download and install FTT
install_ftt() {
wget "https://raw.githubusercontent.com/radkesvat/FakeTlsTunnel/master/install.sh" -O install.sh && chmod +x install.sh && bash install.sh
}
# Function to configure arguments based on user's choice single port
configure_arguments2() {
read -p "Which server do you want to use? (Enter '1' for Iran(internal-server) or '2' for Kharej(external-server) ) : " server_choice
read -p "Please Enter Port (Please choose the same port on both servers): " port
read -p "Please Enter SNI (default : google.com): " sni
sni=${sni:-google.com}
if [ "$server_choice" == "2" ]; then
read -p "Please Enter Password (Please choose the same password on both servers): " password
arguments="--server --lport:443 --toip:127.0.0.1 --toport:$port --sni:$sni --password:$password --terminate:24"
elif [ "$server_choice" == "1" ]; then
read -p "Please Enter (Kharej IP(extrenal-server)) : " server_ip
read -p "Please Enter Password (Please choose the same password on both servers): " password
arguments="--tunnel --lport:$port --toip:$server_ip --toport:443 --sni:$sni --password:$password --terminate:24"
else
echo "Invalid choice. Please enter '1' or '2'."
exit 1
fi
echo "successfull . arguments: $arguments"
}
# Function to configure arguments based on user's choice Multiport
configure_arguments() {
read -p "Which server do you want to use? (Enter '1' for Iran(internal-server) or '2' for Kharej(external-server) ) : " server_choice
read -p "Please Enter SNI (default : splus.ir): " sni
sni=${sni:-google.com}
if [ "$server_choice" == "2" ]; then
read -p "Please Enter Password (Please choose the same password on both servers): " password
arguments="--server --lport:443 --toip:127.0.0.1 --toport:2000 --password:$password --multiport --sni:$sni --terminate:24"
elif [ "$server_choice" == "1" ]; then
read -p "Please Enter (Kharej IP(extrenal-server)) : " server_ip
read -p "Please Enter Password (Please choose the same password on both servers): " password
arguments="--tunnel --lport:23-65535 --toip:$server_ip --toport:443 --password:$password --sni:$sni --terminate:24"
else
echo "Invalid choice. Please enter '1' or '2'."
exit 1
fi
echo "successfull .arguments: $arguments"
}
# Function to handle installation single port
install_single() {
root_access
check_dependencies
check_installed2
install_ftt
# Change directory to /etc/systemd/system
cd /etc/systemd/system
configure_arguments2
# Create a new service file named faketunnel.service
cat <<EOL > faketunnelsingle.service
[Unit]
Description=fake tls tunnel service single
[Service]
User=root
WorkingDirectory=/root
ExecStart=/root/FTT $arguments
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# Reload systemctl daemon and start the service
sudo systemctl daemon-reload
sudo systemctl start faketunnelsingle.service
sudo systemctl enable faketunnelsingle.service
}
# Function to handle uninstallation single
uninstall_single() {
# Check if the service is installed
if [ ! -f "/etc/systemd/system/faketunnelsingle.service" ]; then
echo "The service is not installed."
return
fi
# Stop and disable the service
sudo systemctl stop faketunnelsingle.service
sudo systemctl disable faketunnelsingle.service
# Remove service file
sudo rm /etc/systemd/system/faketunnelsingle.service
sudo systemctl reset-failed
sudo rm FTT
sudo rm install.sh
echo "Uninstallation completed successfully."
}
# Function to handle installation
install_multi() {
root_access
check_dependencies
check_installed
install_ftt
# Change directory to /etc/systemd/system
cd /etc/systemd/system
configure_arguments
# Create a new service file named faketunnel.service
cat <<EOL > faketunnel.service
[Unit]
Description=fake tls tunnel service
[Service]
User=root
WorkingDirectory=/root
ExecStart=/root/FTT $arguments
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# Reload systemctl daemon and start the service
sudo systemctl daemon-reload
sudo systemctl start faketunnel.service
sudo systemctl enable faketunnel.service
}
# Function to handle uninstallation multi
uninstall_multi() {
# Check if the service is installed
if [ ! -f "/etc/systemd/system/faketunnel.service" ]; then
echo "The service is not installed."
return
fi
# Stop and disable the service
sudo systemctl stop faketunnel.service
sudo systemctl disable faketunnel.service
# Remove service file
sudo rm /etc/systemd/system/faketunnel.service
sudo systemctl reset-failed
sudo rm FTT
sudo rm install.sh
echo "Uninstallation completed successfully."
}
update_services() {
# Get the current installed version of FTT
installed_version=$(./FTT -v 2>&1 | grep -o '"[0-9.]*"')
# Fetch the latest version from GitHub releases
latest_version=$(curl -s https://api.github.com/repos/radkesvat/FakeTlsTunnel/releases/latest | grep -o '"tag_name": "[^"]*"' | cut -d":" -f2 | sed 's/["V ]//g' | sed 's/^/"/;s/$/"/')
# Compare the installed version with the latest version
if [[ "$latest_version" > "$installed_version" ]]; then
echo "Updating to $latest_version (Installed: $installed_version)..."
if sudo systemctl is-active --quiet faketunnel.service; then
echo "faketunnel.service is active, stopping..."
sudo systemctl stop faketunnel.service > /dev/null 2>&1
elif sudo systemctl is-active --quiet faketunnelsingle.service; then
echo "faketunnelsingle.service is active, stopping..."
sudo systemctl stop faketunnelsingle.service > /dev/null 2>&1
fi
# Download and run the installation script
wget "https://raw.githubusercontent.com/radkesvat/FakeTlsTunnel/master/install.sh" -O install.sh && chmod +x install.sh && bash install.sh
# Start the previously active service
if sudo systemctl is-active --quiet faketunnel.service; then
echo "Restarting faketunnel.service..."
sudo systemctl start faketunnel.service > /dev/null 2>&1
elif sudo systemctl is-active --quiet faketunnelsingle.service; then
echo "Restarting faketunnelsingle.service..."
sudo systemctl start faketunnelsingle.service > /dev/null 2>&1
fi
echo "Service updated and restarted successfully."
else
echo "You have the latest version ($installed_version)."
fi
}
#ip & version
myip=$(hostname -I | awk '{print $1}')
version=$(./FTT -v 2>&1 | grep -o 'version="[0-9.]*"')
# Main menu
clear
echo "By --> Peyman * Github.com/Ptechgithub * "
echo "Your IP is: ($myip) "
echo ""
echo " --------#- Fake Tls Tunnel -#--------"
echo "1) Install (Single port)"
echo "2) Uninstall (Single port)"
echo " ----------------------------"
echo "3) Install (Multi port)"
echo "4) Uninstall (Multi port)"
echo " ----------------------------"
echo "5) Update FTT"
echo "0) Exit"
echo " --------------$version--------------"
read -p "Please choose: " choice
case $choice in
1)
install_single
;;
2)
uninstall_single
;;
3)
install_multi
;;
4)
uninstall_multi
;;
5)
update_services
;;
0)
exit
;;
*)
echo "Invalid choice. Please try again."
;;
esac