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-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

View File

@@ -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

View File

@@ -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

View File

@@ -25,6 +25,7 @@ proxy-xray --<ltx|ltt|lttw|mtt|mttw|ttt|tttw|ssa|sst|stdin> [options]
--ltx <VLESS-TCP-XTLS 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
--lttg <VLESS-TCP-TLS-GRPC option> uuid@xray-host:port:/svcpath
--mtt <VMESS-TCP-TLS option> uuid@xray-host:port
--mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath
--ttt <TROJAN-TCP-TLS option> password@xray-host:port

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

10
run.sh
View File

@@ -9,6 +9,7 @@ usage() {
echo " --ltx <VLESS-TCP-XTLS 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 " --lttg <VLESS-TCP-TLS-GRPC option> uuid@xray-host:port:/svcpath"
echo " --mtt <VMESS-TCP-TLS option> uuid@xray-host:port"
echo " --mttw <VMESS-TCP-TLS-WS option> uuid@xray-host:port:/webpath"
echo " --ttt <TROJAN-TCP-TLS option> password@xray-host:port"
@@ -18,15 +19,15 @@ usage() {
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

View File

@@ -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)