-
Notifications
You must be signed in to change notification settings - Fork 355
/
mos_tls_tunnel_prepare.sh
349 lines (316 loc) · 9.49 KB
/
mos_tls_tunnel_prepare.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
improt_package "utils" "gen_certificates.sh"
# mos-tls-tunnel Transport mode
MTT_TRANSPORT_MODE=(
tls
wss
)
transport_mode_menu(){
while true
do
echo && echo -e "请为mos-tls-tunnel选择 Transport mode\n"
for ((i=1;i<=${#MTT_TRANSPORT_MODE[@]};i++ )); do
hint="${MTT_TRANSPORT_MODE[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认: ${MTT_TRANSPORT_MODE[0]}):" libev_mtt
[ -z "$libev_mtt" ] && libev_mtt=1
expr ${libev_mtt} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$libev_mtt" -lt 1 || "$libev_mtt" -gt ${#MTT_TRANSPORT_MODE[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#MTT_TRANSPORT_MODE[@]}] 之间"
echo
continue
fi
shadowsocklibev_mtt=${MTT_TRANSPORT_MODE[$libev_mtt-1]}
echo
echo -e "${Red} over = ${shadowsocklibev_mtt}${suffix}"
echo
break
done
}
Info_display_of_domain(){
domainType=$1
echo
echo -e "${Red} n = ${serverName}${suffix} ${Green}(${domainType})${suffix}"
echo
}
get_input_server_name(){
while true
do
echo
if [[ ${libev_mtt} = "1" ]]; then
echo -e "请输入一个域名(DNS-Only 或 Other)"
elif [[ ${libev_mtt} = "2" ]]; then
echo -e "请输入一个域名(CDN 或 DNS-Only 或 Other)"
fi
read -e -p "(默认: www.bing.com):" serverName
[ -z "$serverName" ] && serverName="www.bing.com"
if ! get_domain_ip ${serverName}; then
echo
echo -e "${Error} 请输入一个正确有效的域名."
echo
continue
fi
if [[ ${libev_mtt} = "1" ]]; then
if is_dns_only ${domain_ip}; then
Info_display_of_domain "DNS-Only"
break
else
Info_display_of_domain "Other"
break
fi
elif [[ ${libev_mtt} = "2" ]]; then
if is_cdn_proxied ${domain_ip}; then
Info_display_of_domain "CDN"
break
elif is_dns_only ${domain_ip}; then
Info_display_of_domain "DNS-Only"
break
else
Info_display_of_domain "Other"
break
fi
fi
done
}
get_input_wss_path(){
while true
do
echo
read -e -p "请输入你的WebSocket分流路径(默认:/mtt):" wssPath
[ -z "${wssPath}" ] && wssPath="/mtt"
if [[ $wssPath != /* ]]; then
echo
echo -e "${Error} 请输入以${Red} / ${suffix}开头的路径."
echo
continue
fi
echo
echo -e "${Red} wssPath = ${wssPath}${suffix}"
echo
break
done
}
get_input_mux_max_stream() {
while true
do
echo
echo -e "请输入一个实际TCP连接中的最大复用流数"
read -e -p "(默认: 4):" muxMaxStream
[ -z "${muxMaxStream}" ] && muxMaxStream=4
expr ${muxMaxStream} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个有效数字."
echo
continue
fi
if [ ${muxMaxStream:0:1} = 0 ]; then
echo
echo -e "${Error} 请输入一个非0开头的数字."
echo
continue
fi
if [ ${muxMaxStream} -lt 1 ] || [ ${muxMaxStream} -gt 16 ]; then
echo
echo -e "${Error} 请输入一个的数字在[1-16]之间."
echo
continue
fi
echo
echo -e "${Red} muxMaxStream = ${muxMaxStream}${suffix}"
echo
break
done
}
is_enable_mux(){
while true
do
echo
echo -e "是否启用多路复用(mux)"
read -p "(默认: n) [y/n]: " yn
[ -z "${yn}" ] && yn="N"
case "${yn:0:1}" in
y|Y)
isEnable=enable
;;
n|N)
isEnable=disable
;;
*)
echo
echo -e "${Error} 输入有误,请重新输入!"
echo
continue
;;
esac
echo
echo -e "${Red} mux = ${isEnable}${suffix}"
echo
break
done
if [[ ${isEnable} == enable ]]; then
get_input_mux_max_stream
fi
}
choose_nginx_version_menu(){
local NGINX_PACKAGES_V=(Stable Mainline)
while true
do
echo -e "请选择Nginx软件包版本\n"
for ((i=1;i<=${#NGINX_PACKAGES_V[@]};i++)); do
hint="${NGINX_PACKAGES_V[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认:${NGINX_PACKAGES_V[0]}):" pkg_flag
[ -z "$pkg_flag" ] && pkg_flag=1
expr ${pkg_flag} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$pkg_flag" -lt 1 || "$pkg_flag" -gt ${#NGINX_PACKAGES_V[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#NGINX_PACKAGES_V[@]}] 之间"
echo
continue
fi
echo
echo -e "${Red} version = ${NGINX_PACKAGES_V[$pkg_flag-1]}${suffix}"
echo
break
done
}
web_server_menu(){
local WEB_SERVER_STYLE=(caddy nginx)
while true
do
echo -e "请选择一个Web服务器\n"
for ((i=1;i<=${#WEB_SERVER_STYLE[@]};i++)); do
hint="${WEB_SERVER_STYLE[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认:${WEB_SERVER_STYLE[0]}):" web_flag
[ -z "$web_flag" ] && web_flag=1
expr ${web_flag} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$web_flag" -lt 1 || "$web_flag" -gt ${#WEB_SERVER_STYLE[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#WEB_SERVER_STYLE[@]}] 之间"
echo
continue
fi
web_server=${WEB_SERVER_STYLE[$web_flag-1]}
echo
echo -e "${Red} web = ${web_server}${suffix}"
echo
break
done
if [[ ${web_flag} = "2" ]]; then
choose_nginx_version_menu
fi
}
is_enable_web_server(){
while true
do
echo
echo -e "是否启用web服务器伪装"
read -p "(默认: n) [y/n]: " yn
[ -z "${yn}" ] && yn="N"
case "${yn:0:1}" in
y|Y)
isEnableWeb=enable
;;
n|N)
isEnableWeb=disable
;;
*)
echo
echo -e "${Error} 输入有误,请重新输入!"
echo
continue
;;
esac
echo
echo -e "${Red} web = ${isEnableWeb}${suffix}"
echo
break
done
if [[ ${isEnableWeb} == enable ]]; then
web_server_menu
fi
}
get_input_mirror_site(){
while true
do
echo
echo -e "${Tip} 该站点建议满足(位于海外、支持HTTPS协议、会用来传输大流量... )的条件,默认站点,随意找的,不建议使用"
read -e -p "请输入你需要镜像到的站点(默认:https://www.bostonusa.com):" mirror_site
[ -z "${mirror_site}" ] && mirror_site="https://www.bostonusa.com"
if [ -z "$(echo $mirror_site | grep -E ${HTTPS_DOMAIN_RE})" ]; then
echo
echo -e "${Error} 请输入以${Red} https:// ${suffix}开头,以${Red} 域名 ${suffix}结尾的URL."
echo
continue
fi
echo
echo -e "${Red} mirror_site = ${mirror_site}${suffix}"
echo
break
done
}
check_port_for_mtt(){
if check_port_occupy "443"; then
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
if [[ ${isEnableWeb} = enable ]]; then
check_ss_port ${shadowsocksport}
else
shadowsocksport=443
fi
}
install_prepare_libev_mos_tls_tunnel(){
transport_mode_menu
get_input_server_name
check_port_for_mtt
if [[ ${libev_mtt} = "1" ]]; then
if [[ ${domainType} = DNS-Only ]]; then
acme_get_certificate_by_force "${serverName}"
fi
is_enable_mux
elif [[ ${libev_mtt} = "2" ]]; then
get_input_wss_path
is_enable_mux
if [[ ${domainType} != Other ]]; then
is_enable_web_server
check_port_for_mtt
fi
if [[ ${domainType} = DNS-Only ]] && [[ ${isEnableWeb} = disable ]]; then
acme_get_certificate_by_force "${serverName}"
elif [[ ${domainType} = DNS-Only ]] && [[ ${isEnableWeb} = enable ]]; then
get_input_mirror_site
acme_get_certificate_by_force "${serverName}"
elif [[ ${domainType} = CDN ]] && [[ ${isEnableWeb} = disable ]]; then
acme_get_certificate_by_api_or_manual "${serverName}"
elif [[ ${domainType} = CDN ]] && [[ ${isEnableWeb} = enable ]]; then
get_input_mirror_site
acme_get_certificate_by_api_or_manual "${serverName}"
fi
fi
}