-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-config.sh
More file actions
161 lines (141 loc) · 3.97 KB
/
Copy pathgenerate-config.sh
File metadata and controls
161 lines (141 loc) · 3.97 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
#!/bin/bash
# Script to generate V2Ray server and client configurations
# Function to generate a random UUID
generate_uuid() {
if command -v uuidgen &> /dev/null; then
uuidgen
else
# Fallback if uuidgen is not available
python3 -c 'import uuid; print(uuid.uuid4())'
fi
}
# Function to generate a random path
generate_path() {
# Generate a random string of 8 characters
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1
}
# Function to base64 encode
base64_encode() {
if [[ "$(uname)" == "Darwin" ]]; then
# macOS
echo -n "$1" | base64
else
# Linux
echo -n "$1" | base64 -w 0
fi
}
echo "====================================================="
echo "V2Ray Configuration Generator"
echo "====================================================="
echo
# Get or generate UUID
read -p "Enter UUID (leave blank to generate one): " UUID
if [ -z "$UUID" ]; then
UUID=$(generate_uuid)
echo "Generated UUID: $UUID"
fi
# Get or generate path
read -p "Enter WebSocket path (leave blank to generate one): " WS_PATH
if [ -z "$WS_PATH" ]; then
WS_PATH="/$(generate_path)"
echo "Generated path: $WS_PATH"
fi
# Get server domain or IP
read -p "Enter your server domain or IP: " SERVER_DOMAIN
if [ -z "$SERVER_DOMAIN" ]; then
echo "Error: Server domain or IP is required."
exit 1
fi
# Get server port
read -p "Enter server port (default: 10000): " SERVER_PORT
SERVER_PORT=${SERVER_PORT:-10000}
# Create server config directory if it doesn't exist
mkdir -p config
# Generate server configuration
cat > config/server_config.json << EOL
{
"inbounds": [
{
"port": ${SERVER_PORT},
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${UUID}",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "${WS_PATH}"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
EOL
echo "Server configuration saved to config/server_config.json"
# Generate Nginx configuration
cat > config/nginx_v2ray.conf << EOL
server {
listen 80;
server_name ${SERVER_DOMAIN};
location ${WS_PATH} {
proxy_redirect off;
proxy_pass http://127.0.0.1:${SERVER_PORT};
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOL
echo "Nginx configuration saved to config/nginx_v2ray.conf"
# Generate client configuration
CLIENT_CONFIG='{
"v": "2",
"ps": "V2Ray Server",
"add": "'${SERVER_DOMAIN}'",
"port": "80",
"id": "'${UUID}'",
"aid": "0",
"net": "ws",
"type": "none",
"host": "'${SERVER_DOMAIN}'",
"path": "'${WS_PATH}'",
"tls": ""
}'
# Base64 encode the client configuration
VMESS_LINK="vmess://$(base64_encode "$CLIENT_CONFIG")"
# Save client configuration
echo "$VMESS_LINK" > config/client_config.txt
echo "Client configuration saved to config/client_config.txt"
echo
echo "====================================================="
echo "Configuration Generation Complete!"
echo "====================================================="
echo
echo "Server Configuration: config/server_config.json"
echo "Nginx Configuration: config/nginx_v2ray.conf"
echo "Client Configuration: config/client_config.txt"
echo
echo "To use with Cloudflare Workers Proxy:"
echo "1. Install V2Ray on your server using the server configuration"
echo "2. Configure Nginx using the generated nginx configuration"
echo "3. Deploy the Cloudflare Workers proxy using setup.sh"
echo "4. Visit your Worker URL and paste the client configuration"
echo "5. Generate a proxied configuration and use it in your V2Ray client"
echo "====================================================="
# Make the script executable
chmod +x generate-config.sh