From 288f8df5892f5d3662d5b35c2b150fc9a8259de7 Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Tue, 17 Aug 2021 12:12:06 +1000 Subject: [PATCH] Initial gRPC support --- Dockerfile.amd64 | 1 + Dockerfile.arm | 1 + Dockerfile.arm64 | 1 + README.md | 17 +++++++------- proxy-lttg.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ run.sh | 30 ++++++++++++------------ status.sh | 2 ++ 7 files changed, 88 insertions(+), 23 deletions(-) create mode 100755 proxy-lttg.sh diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 index 7a73882..4429685 100644 --- a/Dockerfile.amd64 +++ b/Dockerfile.amd64 @@ -30,6 +30,7 @@ ADD run.sh /run.sh ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-lttw.sh /proxy-lttw.sh +ADD proxy-lttg.sh /proxy-lttg.sh ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-ttt.sh /proxy-ttt.sh diff --git a/Dockerfile.arm b/Dockerfile.arm index 9bca3bb..0432c60 100644 --- a/Dockerfile.arm +++ b/Dockerfile.arm @@ -30,6 +30,7 @@ ADD run.sh /run.sh ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-lttw.sh /proxy-lttw.sh +ADD proxy-lttg.sh /proxy-lttg.sh ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-ttt.sh /proxy-ttt.sh diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index cfe03ab..6c870f2 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -30,6 +30,7 @@ ADD run.sh /run.sh ADD proxy-ltx.sh /proxy-ltx.sh ADD proxy-ltt.sh /proxy-ltt.sh ADD proxy-lttw.sh /proxy-lttw.sh +ADD proxy-lttg.sh /proxy-lttg.sh ADD proxy-mtt.sh /proxy-mtt.sh ADD proxy-mttw.sh /proxy-mttw.sh ADD proxy-ttt.sh /proxy-ttt.sh diff --git a/README.md b/README.md index 2dbcc68..5f97c73 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,15 @@ $ docker build -t samuelhbne/proxy-xray:amd64 -f Dockerfile.amd64 . ```shell $ docker run --rm -it samuelhbne/proxy-xray:amd64 proxy-xray -- [options] - --ltx uuid@xray-host:port - --ltt uuid@xray-host:port - --lttw uuid@xray-host:port:/webpath - --mtt uuid@xray-host:port - --mttw uuid@xray-host:port:/webpath - --ttt password@xray-host:port - --tttw password@xray-host:port:/webpath - --stdin Read XRay config from stdin instead of auto generation + --ltx uuid@xray-host:port + --ltt uuid@xray-host:port + --lttw uuid@xray-host:port:/webpath + --lttg uuid@xray-host:port:/svcpath + --mtt uuid@xray-host:port + --mttw uuid@xray-host:port:/webpath + --ttt password@xray-host:port + --tttw 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 ... diff --git a/proxy-lttg.sh b/proxy-lttg.sh new file mode 100755 index 0000000..f4dff66 --- /dev/null +++ b/proxy-lttg.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +usage() { + >&2 echo "Usage: proxy-lttg " +} + +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 diff --git a/run.sh b/run.sh index de595d9..a45b6e8 100755 --- a/run.sh +++ b/run.sh @@ -6,27 +6,28 @@ XCONF=/tmp/proxy-xray.json usage() { echo "proxy-xray -- [options]" - echo " --ltx uuid@xray-host:port" - echo " --ltt uuid@xray-host:port" - echo " --lttw uuid@xray-host:port:/webpath" - echo " --mtt uuid@xray-host:port" - echo " --mttw uuid@xray-host:port:/webpath" - echo " --ttt password@xray-host:port" - echo " --tttw password@xray-host:port:/webpath" -# echo " --ssa password:method@xray-host:port" -# echo " --sst password:method@xray-host:port" - echo " --stdin Read XRay config from stdin instead of auto generation" + echo " --ltx uuid@xray-host:port" + echo " --ltt uuid@xray-host:port" + echo " --lttw uuid@xray-host:port:/webpath" + echo " --lttg uuid@xray-host:port:/svcpath" + echo " --mtt uuid@xray-host:port" + echo " --mttw uuid@xray-host:port:/webpath" + echo " --ttt password@xray-host:port" + echo " --tttw password@xray-host:port:/webpath" +# echo " --ssa password:method@xray-host:port" +# echo " --sst 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 eval set -- "$TEMP" while true ; do 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 "\-\-"` - echo "$DIR/proxy-${subcmd}.sh $2 >$XCONF" + echo "${DIR}proxy-${subcmd}.sh $2 >$XCONF" $DIR/proxy-${subcmd}.sh $2 >$XCONF if [ $? != 0 ]; then echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" @@ -55,8 +56,6 @@ while true ; do esac done -/usr/bin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml & - if [ "${STDINCONF}" = "1" ]; then exec /usr/local/bin/xray else @@ -67,6 +66,7 @@ else cat $XCONF echo fi + /usr/bin/dnscrypt-proxy -config /etc/dnscrypt-proxy/dnscrypt-proxy.toml & exec /usr/local/bin/xray -c $XCONF else usage diff --git a/status.sh b/status.sh index d4b7099..fb35465 100755 --- a/status.sh +++ b/status.sh @@ -23,6 +23,7 @@ case "${PROTOCOL}" in XHOST=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].address'` XPORT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].port'` 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'` XENCRYPT=`cat $XCONF | jq -r '.outbounds[0].settings.vnext[0].users[0].encryption'` 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}" if [ "${XFLOW}" != "null" ]; then XURL="${XURL}&flow=${XFLOW}"; 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}" ;; vmess)