-
Notifications
You must be signed in to change notification settings - Fork 6
/
proxy-lgr.sh
executable file
·98 lines (83 loc) · 2.86 KB
/
proxy-lgr.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
#!/bin/bash
usage() {
>&2 echo "VLESS-GRPC-TLS proxy builder"
>&2 echo "Usage: proxy-lgt <[email protected]:443:/svcpath>[,serverName=x.org][,fingerprint=safari]"
}
if [ -z "$1" ]; then
>&2 echo "Missing options"
usage
exit 1
fi
# [email protected]:443:/svcpath,serverName=x.org,fingerprint=safari
args=(`echo $1 |tr ',' ' '`)
dest="${args[0]}"
for ext_opt in "${args[@]}"
do
kv=(`echo $ext_opt |tr '=' ' '`)
case "${kv[0]}" in
d|dest)
serverName="${kv[1]}"
;;
f|fingerprint)
fingerprint="${kv[1]}"
;;
flow)
flow="${kv[1]}"
;;
pub|publicKey)
publicKey="${kv[1]}"
;;
s|serverName)
serverName="${kv[1]}"
;;
shortId)
shortId="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
esac
done
options=(`echo $dest |tr '@' ' '`)
id="${options[0]}"
options=(`echo ${options[1]} |tr ':' ' '`)
host="${options[0]}"
port="${options[1]}"
path="${options[2]}"
if [ -z "${serverName}" ]; then serverName=${host}; fi
if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi
if [ -z "${id}" ]; then
>&2 echo "Error: id undefined."
usage
exit 1
fi
if [ -z "${host}" ]; then
>&2 echo "Error: destination host undefined."
usage
exit 1
fi
if [ -z "${port}" ]; then
port=443
fi
if [ -z "${publicKey}" ]; then
>&2 echo "Error: publicKey undefined."
usage
exit 1
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
# User settings
Jusers=`jq -nc --arg uuid "${id}" --arg flow "${flow}" '. += {"id":$uuid, "flow":$flow, "encryption":"none", "level":0}'`
# Vnest settings
Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \
'. += {"address":$host, "port":($port | tonumber), "users":[$juser]}' `
# Stream Settings
JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg publicKey "${publicKey}" --arg shortId "${shortId}" --arg fingerprint "${fingerprint}" --arg path "${path}" \
'. += {"network":"grpc", "security":"reality","realitySettings":{"publicKey":$publicKey,"serverName":$serverName,"shortId":$shortId,"fingerprint":$fingerprint},"grpcSettings":{"serviceName":$path}}' `
Jproxy=`jq -nc --arg host "${host}" --argjson jvnext "${Jvnext}" --argjson jstreamSettings "${JstreamSettings}" \
'. += { "tag": "proxy", "protocol":"vless", "settings":{"vnext":[$jvnext]}, "streamSettings":$jstreamSettings }' `
Jdirect='{"tag": "direct", "protocol": "freedom", "settings": {}}'
Jblocked='{"tag": "blocked", "protocol": "blackhole", "settings": {}}'
jroot=`jq -n --argjson jproxy "${Jproxy}" --argjson jdirect "${Jdirect}" --argjson jblocked "${Jblocked}" \
'. += {"log":{"loglevel":"warning"}, "outbounds":[$jproxy, $jdirect, $jblocked]}' `
echo "$jroot"
exit 0