Initial gRPC support

This commit is contained in:
Samuel Huang
2021-08-17 12:12:06 +10:00
parent 89696dda90
commit 288f8df589
7 changed files with 88 additions and 23 deletions

View File

@@ -30,6 +30,7 @@ ADD run.sh /run.sh
ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltx.sh /proxy-ltx.sh
ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-ltt.sh /proxy-ltt.sh
ADD proxy-lttw.sh /proxy-lttw.sh ADD proxy-lttw.sh /proxy-lttw.sh
ADD proxy-lttg.sh /proxy-lttg.sh
ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mtt.sh /proxy-mtt.sh
ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-mttw.sh /proxy-mttw.sh
ADD proxy-ttt.sh /proxy-ttt.sh ADD proxy-ttt.sh /proxy-ttt.sh

View File

@@ -30,6 +30,7 @@ ADD run.sh /run.sh
ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltx.sh /proxy-ltx.sh
ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-ltt.sh /proxy-ltt.sh
ADD proxy-lttw.sh /proxy-lttw.sh ADD proxy-lttw.sh /proxy-lttw.sh
ADD proxy-lttg.sh /proxy-lttg.sh
ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mtt.sh /proxy-mtt.sh
ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-mttw.sh /proxy-mttw.sh
ADD proxy-ttt.sh /proxy-ttt.sh ADD proxy-ttt.sh /proxy-ttt.sh

View File

@@ -30,6 +30,7 @@ ADD run.sh /run.sh
ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltx.sh /proxy-ltx.sh
ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-ltt.sh /proxy-ltt.sh
ADD proxy-lttw.sh /proxy-lttw.sh ADD proxy-lttw.sh /proxy-lttw.sh
ADD proxy-lttg.sh /proxy-lttg.sh
ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mtt.sh /proxy-mtt.sh
ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-mttw.sh /proxy-mttw.sh
ADD proxy-ttt.sh /proxy-ttt.sh ADD proxy-ttt.sh /proxy-ttt.sh

View File

@@ -22,14 +22,15 @@ $ docker build -t samuelhbne/proxy-xray:amd64 -f Dockerfile.amd64 .
```shell ```shell
$ docker run --rm -it samuelhbne/proxy-xray:amd64 $ docker run --rm -it samuelhbne/proxy-xray:amd64
proxy-xray --<ltx|ltt|lttw|mtt|mttw|ttt|tttw|ssa|sst|stdin> [options] proxy-xray --<ltx|ltt|lttw|mtt|mttw|ttt|tttw|ssa|sst|stdin> [options]
--ltx <VLESS-TCP-XTLS option> uuid@xray-host:port --ltx <VLESS-TCP-XTLS option> uuid@xray-host:port
--ltt <VLESS-TCP-TLS option> uuid@xray-host:port --ltt <VLESS-TCP-TLS option> uuid@xray-host:port
--lttw <VLESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath --lttw <VLESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath
--mtt <VMESS-TCP-TLS option> uuid@xray-host:port --lttg <VLESS-TCP-TLS-GRPC option> uuid@xray-host:port:/svcpath
--mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath --mtt <VMESS-TCP-TLS option> uuid@xray-host:port
--ttt <TROJAN-TCP-TLS option> password@xray-host:port --mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath
--tttw <TROJAN-TCP-TLS-WS option> password@xray-host:port:/webpath --ttt <TROJAN-TCP-TLS option> password@xray-host:port
--stdin Read XRay config from stdin instead of auto generation --tttw <TROJAN-TCP-TLS-WS option> password@xray-host:port:/webpath
--stdin Read XRay config from stdin instead of auto generation
$ docker run --name proxy-xray -p 21080:1080 -p 65353:53/udp -p 28123:8123 -d samuelhbne/proxy-xray:amd64 --ltx bec24d96-410f-4723-8b3b-46987a1d9ed8@mydomain.duckdns.org:443 $ docker run --name proxy-xray -p 21080:1080 -p 65353:53/udp -p 28123:8123 -d samuelhbne/proxy-xray:amd64 --ltx bec24d96-410f-4723-8b3b-46987a1d9ed8@mydomain.duckdns.org:443
... ...

59
proxy-lttg.sh Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/bash
usage() {
>&2 echo "Usage: proxy-lttg <uuid@domain0.com:443:/svcpath>"
}
if [ -z "$1" ]; then
>&2 echo "Missing options"
usage
exit 1
fi
# uuid@domain0.com:443:/svcpath
temp=$1
options=(`echo $temp |tr '@' ' '`)
id="${options[0]}"
temp="${options[1]}"
options=(`echo $temp |tr ':' ' '`)
host="${options[0]}"
port="${options[1]}"
path="${options[2]}"
if [ -z "${id}" ]; then
>&2 echo "Error: uuid 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 ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
Jusers=`echo '{}' |jq --arg uuid "${id}" '. += {"id":$uuid, "encryption":"none", "level":0}'`
Jvnext=`echo '{}' | jq --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \
'. += {"address":$host, "port":($port | tonumber), "users":[$juser]}' `
JstreamSettings=`echo '{}' | jq --arg host "${host}" --arg path "${path}" \
'. += {"network":"grpc", "security":"tls", "tlsSettings":{"serverName":$host}, "grpcSettings":{"serviceName":$path}}' `
Joutbounds=`echo '{}' | jq --arg host "${host}" --argjson jvnext "${Jvnext}" --argjson jstreamSettings "${JstreamSettings}" \
'. += { "protocol":"vless", "settings":{"vnext":[$jvnext]}, "streamSettings":$jstreamSettings }' `
JibSOCKS=`echo '{}' | jq '. +={"port":1080, "listen":"0.0.0.0", "protocol":"socks", "settings":{"udp":true}}' `
JibHTTP=`echo '{}' | jq '. +={"port":8123, "listen":"0.0.0.0", "protocol":"http"}' `
jroot=`echo '{}' | jq --argjson jibsocks "${JibSOCKS}" --argjson jibhttp "${JibHTTP}" --argjson joutbounds "${Joutbounds}" \
'. += {"log":{"loglevel":"warning"}, "inbounds":[$jibsocks, $jibhttp], "outbounds":[$joutbounds]}' `
echo "$jroot"
exit 0

30
run.sh
View File

@@ -6,27 +6,28 @@ XCONF=/tmp/proxy-xray.json
usage() { usage() {
echo "proxy-xray --<ltx|ltt|lttw|mtt|mttw|ttt|tttw|ssa|sst|stdin> [options]" echo "proxy-xray --<ltx|ltt|lttw|mtt|mttw|ttt|tttw|ssa|sst|stdin> [options]"
echo " --ltx <VLESS-TCP-XTLS option> uuid@xray-host:port" echo " --ltx <VLESS-TCP-XTLS option> uuid@xray-host:port"
echo " --ltt <VLESS-TCP-TLS option> uuid@xray-host:port" echo " --ltt <VLESS-TCP-TLS option> uuid@xray-host:port"
echo " --lttw <VLESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath" echo " --lttw <VLESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath"
echo " --mtt <VMESS-TCP-TLS option> uuid@xray-host:port" echo " --lttg <VLESS-TCP-TLS-GRPC option> uuid@xray-host:port:/svcpath"
echo " --mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath" echo " --mtt <VMESS-TCP-TLS option> uuid@xray-host:port"
echo " --ttt <TROJAN-TCP-TLS option> password@xray-host:port" echo " --mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath"
echo " --tttw <TROJAN-TCP-TLS-WS option> password@xray-host:port:/webpath" echo " --ttt <TROJAN-TCP-TLS option> password@xray-host:port"
# echo " --ssa <Shadowsocks-AEAD option> password:method@xray-host:port" echo " --tttw <TROJAN-TCP-TLS-WS option> password@xray-host:port:/webpath"
# echo " --sst <Shadowsocks-TCP option> password:method@xray-host:port" # echo " --ssa <Shadowsocks-AEAD option> password:method@xray-host:port"
echo " --stdin Read XRay config from stdin instead of auto generation" # echo " --sst <Shadowsocks-TCP option> password:method@xray-host:port"
echo " --stdin Read XRay config from stdin instead of auto generation"
} }
TEMP=`getopt -o d --long ltx:,ltt:,lttw:,mtt:,mttw:,ttt:,tttw:,ssa:,sst:stdin,debug -n "$0" -- $@` TEMP=`getopt -o d --long ltx:,ltt:,lttw:,lttg:,mtt:,mttw:,ttt:,tttw:,ssa:,sst:stdin,debug -n "$0" -- $@`
if [ $? != 0 ] ; then usage; exit 1 ; fi if [ $? != 0 ] ; then usage; exit 1 ; fi
eval set -- "$TEMP" eval set -- "$TEMP"
while true ; do while true ; do
case "$1" in case "$1" in
--ltx|--ltt|--lttw|--mtt|--mttw|--ttt|--tttw|--ssa|--sst) --ltx|--ltt|--lttw|--lttg|--mtt|--mttw|--ttt|--tttw|--ssa|--sst)
subcmd=`echo "$1"|tr -d "\-\-"` subcmd=`echo "$1"|tr -d "\-\-"`
echo "$DIR/proxy-${subcmd}.sh $2 >$XCONF" echo "${DIR}proxy-${subcmd}.sh $2 >$XCONF"
$DIR/proxy-${subcmd}.sh $2 >$XCONF $DIR/proxy-${subcmd}.sh $2 >$XCONF
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2"
@@ -55,8 +56,6 @@ while true ; do
esac esac
done done
/usr/bin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml &
if [ "${STDINCONF}" = "1" ]; then if [ "${STDINCONF}" = "1" ]; then
exec /usr/local/bin/xray exec /usr/local/bin/xray
else else
@@ -67,6 +66,7 @@ else
cat $XCONF cat $XCONF
echo echo
fi fi
/usr/bin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml &
exec /usr/local/bin/xray -c $XCONF exec /usr/local/bin/xray -c $XCONF
else else
usage usage

View File

@@ -23,6 +23,7 @@ case "${PROTOCOL}" in
XHOST=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].address'` XHOST=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].address'`
XPORT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].port'` XPORT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].port'`
WPATH=`cat $XCONF | jq -r '.outbounds[0].streamSettings.wsSettings.path'` WPATH=`cat $XCONF | jq -r '.outbounds[0].streamSettings.wsSettings.path'`
SVCNAME=`cat $XCONF | jq -r '.outbounds[0].streamSettings.grpcSettings.serviceName'`
UUID=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].users[0].id'` UUID=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].users[0].id'`
XENCRYPT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].users[0].encryption'` XENCRYPT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].users[0].encryption'`
XSEC=`cat $XCONF | jq -r '.outbounds[0].streamSettings.security'` XSEC=`cat $XCONF | jq -r '.outbounds[0].streamSettings.security'`
@@ -31,6 +32,7 @@ case "${PROTOCOL}" in
XURL="${PROTOCOL}://${UUID}@${XHOST}:${XPORT}?security=${XSEC}&type=${XNETWORK}" XURL="${PROTOCOL}://${UUID}@${XHOST}:${XPORT}?security=${XSEC}&type=${XNETWORK}"
if [ "${XFLOW}" != "null" ]; then XURL="${XURL}&flow=${XFLOW}"; fi if [ "${XFLOW}" != "null" ]; then XURL="${XURL}&flow=${XFLOW}"; fi
if [ "${WPATH}" != "null" ]; then XURL="${XURL}&path=$(urlencode ${WPATH})"; fi if [ "${WPATH}" != "null" ]; then XURL="${XURL}&path=$(urlencode ${WPATH})"; fi
if [ "${SVCNAME}" != "null" ]; then XURL="${XURL}&serviceName=${SVCNAME}&mode=gun"; fi
XURL="${XURL}#${XHOST}:${XPORT}" XURL="${XURL}#${XHOST}:${XPORT}"
;; ;;
vmess) vmess)