This repository was archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathcdn.sh
More file actions
225 lines (191 loc) · 4.35 KB
/
cdn.sh
File metadata and controls
225 lines (191 loc) · 4.35 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
#!/usr/bin/env bash
echo "enter a valid UUID"
read UUID
echo "enter your domain (*pointed to server ip)"
read DOMAIN_NAME
#updating and adding firewall rules
apt update
apt upgrade
apt purge iptables-persistent
apt install ufw
ufw allow 'OpenSSH'
ufw allow 443/tcp
ufw allow 80/tcp
ufw enable
#installing latest caddy
VERSION=$(curl --silent 'https://api.github.com/repos/caddyserver/caddy/releases/latest' | sed 'y/,/\n/' | grep 'tag_name' | awk -F '"' '{print $4}')
if [[ "$(uname)" == 'Linux' ]]; then
case "$(uname -m)" in
'amd64' | 'x86_64')
MACHINE='amd64'
;;
'armv8' | 'aarch64')
MACHINE='arm64'
;;
*)
echo "error: The architecture is not supported by the script"
exit 1
;;
esac
else
echo "error: This operating system is not supported."
exit 1
fi
VERSION_NO="${VERSION:1}"
DOWNLOAD_LINK="https://github.com/caddyserver/caddy/releases/download/"$VERSION"/caddy_"$VERSION_NO"_linux_"$MACHINE".tar.gz"
TARBALL="caddy_"$VERSION_NO"_linux_"$MACHINE".tar.gz"
curl -LJO $DOWNLOAD_LINK
tar -xvf $TARBALL
mv caddy /usr/local/bin
groupadd --system caddy
useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
cat << EOF > /etc/systemd/system/caddy.service
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
EOF
mkdir /etc/caddy
cat << EOF > /etc/caddy/Caddyfile
{
order reverse_proxy before route
admin off
log {
output file /var/log/caddy/access.log
level ERROR
}
}
:443, $DOMAIN_NAME {
tls {
ciphers TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
alpn http/1.1 h2
}
@vws {
path /iamtrazy
header Connection *Upgrade*
header Upgrade websocket
}
reverse_proxy @vws unix//dev/shm/vws.sock
@host {
host $DOMAIN_NAME
}
route @host {
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
file_server {
root /var/www/$DOMAIN_NAME/html
}
}
}
EOF
#Fake website
mkdir -p /var/www/$DOMAIN_NAME/html
cat << EOF > /var/www/$DOMAIN_NAME/html/index.html
<html>
<head>
<title>iamtrazy</title>
</head>
<body>
<h1>I LOVE TAYLOR SWIFT</h1>
</body>
</html>
EOF
chown -R $SUDO_USER:$SUDO_USER /var/www/$DOMAIN_NAME/html
chmod -R 755 /var/www/$DOMAIN_NAME
#installing xray-core
timedatectl set-timezone Asia/Colombo
timedatectl set-ntp true
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
#Adding a xray config json
rm -rf /usr/local/etc/xray/config.json
cat << EOF > /usr/local/etc/xray/config.json
{
"log": {
"loglevel": "warning",
"error": "/var/log/xray/error.log",
"access": "/var/log/xray/access.log"
},
"inbounds": [
{
"listen": "/dev/shm/vws.sock,666",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$UUID"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"path": "/iamtrazy"
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
}
],
"routing": {
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "blocked"
}
]
},
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"tag": "blocked",
"protocol": "blackhole",
"settings": {}
}
]
}
EOF
#installing bbr
wget -P /tmp https://raw.githubusercontent.com/teddysun/across/master/bbr.sh
chmod +x /tmp/bbr.sh
/tmp/bbr.sh
#starting caddy & xray
systemctl daemon-reload
systemctl enable caddy
systemctl enable xray
systemctl restart caddy
systemctl restart xray