-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReality.sh
More file actions
332 lines (246 loc) · 7.98 KB
/
Reality.sh
File metadata and controls
332 lines (246 loc) · 7.98 KB
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
Check_Domain_Resolve () {
# Identify the primary network interface (regardless of wg status)
PRIMARY_NETWORK_INTERFACE=$(ip route | grep default | awk '{print $5}')
# Get the authentic public IP by querying Cloudflare's DNS server 1.1.1.1
IPV4=$(dig @1.1.1.1 whoami.cloudflare ch txt +short -b $(ip -4 addr show $PRIMARY_NETWORK_INTERFACE | grep -oP '(?<=inet\s)\d+(\.\d+){3}') | tr -d '"')
# Identify the primary network interface (regardless of wg status)
PRIMARY_NETWORK_INTERFACE_ipv6=$(ip -6 route | grep default | awk '{print $5}'|head -1)
# Get all available IPv6 addresses for the interface
IPV6_ADDRESSES=$(ip -6 addr show $PRIMARY_NETWORK_INTERFACE_ipv6 | grep -oP '(?<=inet6\s)[0-9a-fA-F:]+')
# Get the authentic public IPv6 by querying Cloudflare's DNS server using available IPv6 addresses
for IPV6_ADDRESS in $IPV6_ADDRESSES; do
IPV6=$(dig @2606:4700:4700::1111 whoami.cloudflare ch txt +short -b $IPV6_ADDRESS | tr -d '"')
if [ ! -z "$IPV6" ]; then
break
fi
done
#IPV4=$(dig +time=1 +tries=2 @1.1.1.1 +short txt ch whoami.cloudflare |tr -d \")
#IPV6=$(dig +time=1 +tries=2 +short @2606:4700:4700::1111 -6 ch txt whoami.cloudflare|tr -d \")
resolve4="$(dig +time=1 +tries=2 A +short ${Domain} @1.1.1.1)"
resolve6="$(dig +time=1 +tries=2 AAAA +short ${Domain} @1.1.1.1)"
res4=`echo -n ${resolve4} | grep $IPV4`
res6=`echo -n ${resolve6} | grep $IPV6`
res=`echo $res4$res6`
echo "======"
echo "$res"
IP=`echo $res4$res6`
echo "${Domain} points to: $res"
if [[ -z "${res}" ]]; then
echo " ${Domain} 解析结果:${res}"
echo -e " ${RED}伪装域名未解析到当前服务器IP $IPV4$IPV6 !${PLAIN}"
exit 1
else
echo "$Domain successfully resolved to $res "
fi
}
Acme_Get(){
apt install socat -y
curl -sL https://get.acme.sh | sh -s [email protected]
source ~/.bashrc
~/.acme.sh/acme.sh --upgrade --auto-upgrade
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d $Domain --keylength ec-256 --force --standalone --listen-v6
}
Get_Key_Path(){
echo "如果~/.acme.sh下没有正确域名 ,请确保80端口没有被占用,脚本自动获取域名"
read -p "请正确输入域名: " Domain
#echo "输入的域名为:$Domain"
Check_Domain_Resolve
#cer_path=/root/.acme.sh/${Domain}_ecc/${Domain}.cer
cer_path=/root/.acme.sh/${Domain}_ecc/fullchain.cer
key_path=/root/.acme.sh/${Domain}_ecc/${Domain}.key
if [[ -f $cer_path ]] && [[ -f $key_path ]] ; then
echo $cer_path
echo $key_path
else
Acme_Get
#cer_path=/root/.acme.sh/${Domain}_ecc/${Domain}.cer
#key_path=/root/.acme.sh/${Domain}_ecc/${Domain}.key
if [[ -f $cer_path ]] && [[ -f $key_path ]] ; then
echo $cer_path
echo $key_path
else
echo "/root/.acme.sh/${Domain}_ecc/ 不存在cer key"
exit 1
fi
fi
}
RED="\033[31m" # Error message
GREEN="\033[32m" # Success message
YELLOW="\033[33m" # Warning message
BLUE="\033[36m" # Info message
PLAIN='\033[0m'
function echoColor() {
case $1 in
# 红色
"red")
echo -e "\033[31m${printN}$2 \033[0m"
;;
# 天蓝色
"skyBlue")
echo -e "\033[1;36m${printN}$2 \033[0m"
;;
# 绿色
"green")
echo -e "\033[32m${printN}$2 \033[0m"
;;
# 白色
"white")
echo -e "\033[37m${printN}$2 \033[0m"
;;
"magenta")
echo -e "\033[31m${printN}$2 \033[0m"
;;
# 黄色
"yellow")
echo -e "\033[33m${printN}$2 \033[0m"
;;
# 紫色
"purple")
echo -e "\033[1;;35m${printN}$2 \033[0m"
;;
#
"yellowBlack")
# 黑底黄字
echo -e "\033[1;33;40m${printN}$2 \033[0m"
;;
"greenWhite")
# 绿底白字
echo -e "\033[42;37m${printN}$2 \033[0m"
;;
esac
}
Xray_Reality() {
mkdir -p /etc/Reality/
#Get_Key_Path
read -p "Port default: 60001: " Port
if [[ -z "$Port" ]]; then
Port=60001
fi
#read -p "input serviceName sni : www.cloudflare.com " ServiceName
# if [[ -z "$ServiceName" ]]; then
# ServiceName="www.cloudflare.com"
# fi
cat <<EOF > /etc/Reality/config.yaml
---
log:
# loglevel: debug
loglevel: none
inbounds:
- port: $Port
protocol: vless
settings:
clients:
- id: 12345678-1234-1234-1234-123456789012
flow: xtls-rprx-vision
decryption: none
streamSettings:
network: tcp
security: reality
realitySettings:
dest: www.cloudflare.com:443
serverNames:
- www.cloudflare.com
privateKey: YAjoKYIZ601zDTrYJKGoibA0bNTKCboCJNGUH7wgdn4
shortIds:
- ''
sniffing:
enabled: true
destOverride:
- http
- tls
- quic
routeOnly: true
outbounds:
- protocol: freedom
tag: direct
EOF
}
function DownloadxrayRealityCore(){
version=`wget -qO- -t1 -T2 --no-check-certificate "https://api.github.com/repos/XTLS/xray-core/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'`
wget -qO- -t1 -T2 --no-check-certificate "https://api.github.com/repos/XTLS/xray-core/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'
echo -e "The Latest xray version:"`echoColor red "${version}"`"\nDownload..."
get_arch=`arch`
#https://github.com/XTLS/xray-core/releases/download/v1.6.1/xray-linux-64.zip
temp_f=$(mktemp)
temp_d=$(mktemp -d)
if [ $get_arch = "x86_64" ];then
wget -q -O $temp_f --no-check-certificate https://github.com/XTLS/xray-core/releases/download/${version}/xray-linux-64.zip
#echo https://github.com/XTLS/xray-core/releases/download/${version}/xray-linux-64.zip
unzip $temp_f -d $temp_d/
mv -fv $temp_d/xray /usr/bin/xrayReality
mv -fv $temp_d/* /usr/bin/
elif [ $get_arch = "aarch64" ];then
wget -q -O $temp_f --no-check-certificate https://github.com/XTLS/xray-core/releases/download/${version}/Xray-linux-arm64-v8a.zip
unzip $temp_f -d $temp_d/
mv -fv $temp_d/xray /usr/bin/xrayReality
mv -fv $temp_d/* /usr/bin/
else
echoColor yellowBlack "Error[OS Message]:${get_arch}\nPlease open a issue to https://github.com/XTLS/xray-core/releases/"
exit
fi
if [ -f "/usr/bin/xrayReality" ]; then
chmod 755 /usr/bin/xrayReality
echoColor purple "\nDownload completed."
else
echoColor red "Network Error: Can't connect to Github!"
fi
cat <<EOF > /etc/systemd/system/xrayReality.service
[Unit]
Description=xrayReality Service
Documentation=https://github.com/XTLS/xray-core/
After=network.target nss-lookup.target
[Service]
User=root
#User=nobody
#CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/bin/xrayReality -c /etc/Reality/config.yaml
Restart=on-failure
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
EOF
#apt update -y
#apt upgrade -y
#apt install -y nginx
#sed -i 's/include \/etc\/nginx\/sites-enabled.*/#include \/etc\/nginx\/sites-enabled\/\*;/g' /etc/nginx/nginx.conf
#
#systemctl stop nginx
#systemctl enable nginx
}
start(){
netstat -lptnu |grep $Port
echo "/etc/Reality/config.yaml"
cat "/etc/Reality/config.yaml"
systemctl daemon-reload
systemctl enable xrayReality
systemctl start xrayReality
systemctl restart xrayReality
systemctl status xrayReality
}
echo -e " ${GREEN}1.${PLAIN} 安装 ${BLUE}xrayReality${PLAIN}"
echo -e " ${GREEN}2.${PLAIN} 查看 ${BLUE}config${PLAIN}"
echo -e " ${GREEN}3.${PLAIN} restart ${BLUE}config${PLAIN}"
echo -e " ${GREEN}00.${PLAIN} ${BLUE}exit${PLAIN}"
read -p " 选择:" answer
case $answer in
1)
Xray_Reality
DownloadxrayRealityCore
start
;;
2)
echo "/etc/Reality/config.yaml"
cat "/etc/Reality/config.yaml"
systemctl status xrayReality
;;
3)
systemctl restart xrayReality
systemctl status xrayReality
;;
00)
exit
;;
esac