From 9e1b79241270f3a13d7f6390794a4c4260663969 Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Wed, 25 Sep 2024 16:40:35 +1000 Subject: [PATCH] Rewrite with json stdout --- proxy-lgp.sh | 36 +++++------------ proxy-lgr.sh | 42 +++++-------------- proxy-lgt.sh | 40 ++++++------------- proxy-lsp.sh | 39 ++++++------------ proxy-lst.sh | 40 ++++++------------- proxy-ltr.sh | 42 +++++-------------- proxy-ltt.sh | 40 ++++++------------- proxy-lwp.sh | 39 ++++++------------ proxy-lwt.sh | 40 ++++++------------- proxy-mtt.sh | 40 ++++++------------- proxy-mwp.sh | 44 +++++++------------- proxy-mwt.sh | 42 ++++++------------- proxy-ttt.sh | 42 ++++++------------- proxy-twp.sh | 36 +++++------------ proxy-twt.sh | 42 ++++++------------- run.sh | 111 ++++++++++++++++++++------------------------------- 16 files changed, 224 insertions(+), 491 deletions(-) diff --git a/proxy-lgp.sh b/proxy-lgp.sh index 48870fb..486e37b 100755 --- a/proxy-lgp.sh +++ b/proxy-lgp.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-GRPC-PLAIN proxy builder" - >&2 echo "Usage: proxy-lgp " + >&2 echo -e "VLESS-GRPC-PLAIN proxy builder" + >&2 echo -e "Usage: proxy-lgp " } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:80:/svcpath @@ -19,30 +18,20 @@ host="${options[0]}" port="${options[1]}" path="${options[2]}" -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=80 -fi +if [ -z "${port}" ]; then port=80; fi -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings JstreamSettings=`jq -nc --arg path "${path}" \ @@ -50,11 +39,6 @@ JstreamSettings=`jq -nc --arg path "${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" +echo "$Jproxy" exit 0 diff --git a/proxy-lgr.sh b/proxy-lgr.sh index f1a7136..936a1e6 100755 --- a/proxy-lgr.sh +++ b/proxy-lgr.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-GRPC-TLS proxy builder" - >&2 echo "Usage: proxy-lgr ,pub=xxxx[,shortId=abcd][,fingerprint=safari]" + >&2 echo -e "VLESS-GRPC-TLS proxy builder" + >&2 echo -e "Usage: proxy-lgr ,pub=xxxx[,shortId=abcd][,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/svcpath,dest=yahoo.com,pub=xxxx,fingerprint=safari @@ -50,36 +49,22 @@ path="${options[2]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -fi +if [ -z "${publicKey}" ]; then >&2 echo -e "Error: publicKey undefined.\n"; usage; exit 1; fi -if [ -z "${publicKey}" ]; then - >&2 echo "Error: publicKey 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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" --arg flow "${flow}" '. += {"flow":$flow,"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"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}" \ @@ -87,11 +72,6 @@ JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg publicKey "${publ 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" +echo "$Jproxy" exit 0 diff --git a/proxy-lgt.sh b/proxy-lgt.sh index f9d3c16..f974376 100755 --- a/proxy-lgt.sh +++ b/proxy-lgt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-GRPC-TLS proxy builder" - >&2 echo "Usage: proxy-lgt [,fingerprint=safari][,alpn=h3]" + >&2 echo -e "VLESS-GRPC-TLS proxy builder" + >&2 echo -e "Usage: proxy-lgt [,fingerprint=safari][,alpn=h3]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/svcpath,fingerprint=safari @@ -38,43 +37,28 @@ path="${options[2]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"grpc","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn},"grpcSettings":{"serviceName":$path}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"grpc","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn},"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" +echo "$Jproxy" exit 0 diff --git a/proxy-lsp.sh b/proxy-lsp.sh index efbd196..7c7d819 100755 --- a/proxy-lsp.sh +++ b/proxy-lsp.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-SPLT-PLAIN proxy builder" - >&2 echo "Usage: proxy-lsp " + >&2 echo -e "VLESS-SPLT-PLAIN proxy builder" + >&2 echo -e "Usage: proxy-lsp " } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/webpath @@ -19,39 +18,27 @@ host="${options[0]}" port="${options[1]}" path="${options[2]}" -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=80 -fi +if [ -z "${port}" ]; then port=80; fi -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi +# User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` +# Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` +# Stream Settings JstreamSettings=`jq -nc --arg path "${path}" \ '. += {"network":"splithttp","security":"none","splithttpSettings":{"path":$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" +echo "$Jproxy" exit 0 diff --git a/proxy-lst.sh b/proxy-lst.sh index d0bd4e8..e889493 100755 --- a/proxy-lst.sh +++ b/proxy-lst.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-SPLT-TLS proxy builder" - >&2 echo "Usage: proxy-lst [,fingerprint=safari][,alpn=h3]" + >&2 echo -e "VLESS-SPLT-TLS proxy builder" + >&2 echo -e "Usage: proxy-lst [,fingerprint=safari][,alpn=h3]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/webpath,fingerprint=safari @@ -38,43 +37,28 @@ path="${options[2]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"splithttp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn},"splithttpSettings":{"path":$path}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"splithttp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn},"splithttpSettings":{"path":$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" +echo "$Jproxy" exit 0 diff --git a/proxy-ltr.sh b/proxy-ltr.sh index 8cc1a34..97b1661 100755 --- a/proxy-ltr.sh +++ b/proxy-ltr.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-TCP-REALITY proxy builder" - >&2 echo "Usage: proxy-ltr ,,pub=xxxx[,shortId=abcd][,xtls][,fingerprint=safari]" + >&2 echo -e "VLESS-TCP-REALITY proxy builder" + >&2 echo -e "Usage: proxy-ltr ,,pub=xxxx[,shortId=abcd][,xtls][,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443,dest=yaho.com,fingerprint=safari @@ -49,36 +48,22 @@ port="${options[1]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -fi +if [ -z "${publicKey}" ]; then >&2 echo -e "Error: publicKey undefined.\n"; usage; exit 1; fi -if [ -z "${publicKey}" ]; then - >&2 echo "Error: publicKey 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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" --arg flow "${flow}" '. += {"flow":$flow,"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg publicKey "${publicKey}" --arg shortId "${shortId}" --arg fingerprint "${fingerprint}" \ @@ -86,11 +71,6 @@ JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg publicKey "${publ 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" +echo "$Jproxy" exit 0 diff --git a/proxy-ltt.sh b/proxy-ltt.sh index 4a6a8c6..f412b46 100755 --- a/proxy-ltt.sh +++ b/proxy-ltt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-TCP-TLS proxy builder" - >&2 echo "Usage: proxy-ltt [,xtls][,fingerprint=safari]" + >&2 echo -e "VLESS-TCP-TLS proxy builder" + >&2 echo -e "Usage: proxy-ltt [,xtls][,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443,fingerprint=safari @@ -40,43 +39,28 @@ port="${options[1]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" --arg flow "${flow}" '. += {"flow":$flow,"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" \ -'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn}}' ` 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" +echo "$Jproxy" exit 0 diff --git a/proxy-lwp.sh b/proxy-lwp.sh index c3e5f5e..4ac5dec 100755 --- a/proxy-lwp.sh +++ b/proxy-lwp.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-WS-PLAIN proxy builder" - >&2 echo "Usage: proxy-lwp " + >&2 echo -e "VLESS-WS-PLAIN proxy builder" + >&2 echo -e "Usage: proxy-lwp " } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/websocket @@ -19,39 +18,27 @@ host="${options[0]}" port="${options[1]}" path="${options[2]}" -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=80 -fi +if [ -z "${port}" ]; then port=80; fi -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi +# User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` +# Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` +# Stream Settings JstreamSettings=`jq -nc --arg path "${path}" \ '. += {"network":"ws","security":"none","wsSettings":{"path":$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" +echo "$Jproxy" exit 0 diff --git a/proxy-lwt.sh b/proxy-lwt.sh index ec5dbc7..2cf598c 100755 --- a/proxy-lwt.sh +++ b/proxy-lwt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VLESS-WS-TLS proxy builder" - >&2 echo "Usage: proxy-lwt [,fingerprint=safari]" + >&2 echo -e "VLESS-WS-TLS proxy builder" + >&2 echo -e "Usage: proxy-lwt [,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/websocket,fingerprint=safari @@ -38,43 +37,28 @@ path="${options[2]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn},"wsSettings":{"path":$path}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn},"wsSettings":{"path":$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" +echo "$Jproxy" exit 0 diff --git a/proxy-mtt.sh b/proxy-mtt.sh index 9967378..fc4647c 100755 --- a/proxy-mtt.sh +++ b/proxy-mtt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VMESS-TCP-TLS proxy builder" - >&2 echo "Usage: proxy-mtt [,fingerprint=safari]" + >&2 echo -e "VMESS-TCP-TLS proxy builder" + >&2 echo -e "Usage: proxy-mtt [,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443,fingerprint=safari @@ -37,43 +36,28 @@ port="${options[1]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn}}' ` Jproxy=`jq -nc --arg host "${host}" --argjson jvnext "${Jvnext}" --argjson jstreamSettings "${JstreamSettings}" \ '. += { "tag":"proxy","protocol":"vmess","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" +echo "$Jproxy" exit 0 diff --git a/proxy-mwp.sh b/proxy-mwp.sh index 6d4b664..031f59b 100755 --- a/proxy-mwp.sh +++ b/proxy-mwp.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VMESS-WS-PLAIN proxy builder" - >&2 echo "Usage: proxy-mwp " + >&2 echo -e "VMESS-WS-PLAIN proxy builder" + >&2 echo -e "Usage: proxy-mwp " } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/websocket @@ -19,42 +18,27 @@ 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 -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${port}" ]; then port=80; 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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi +# User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` +# Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` +# Stream Settings JstreamSettings=`jq -nc --arg path "${path}" \ '. += {"network":"ws","security":"none","wsSettings":{"path":$path}}' ` Jproxy=`jq -nc --arg host "${host}" --argjson jvnext "${Jvnext}" --argjson jstreamSettings "${JstreamSettings}" \ -'. += { "tag": proxy","protocol":"vmess","settings":{"vnext":[$jvnext]},"streamSettings":$jstreamSettings}' ` -Jdirect='{"tag":"direct","protocol":"freedom","settings":{}}' -Jblocked='{"tag":"blocked","protocol":"blackhole","settings":{}}' +'. += { "tag":"proxy","protocol":"vmess","settings":{"vnext":[$jvnext]},"streamSettings":$jstreamSettings}' ` -jroot=`jq -n --argjson jproxy "${Jproxy}" --argjson jdirect "${Jdirect}" --argjson jblocked "${Jblocked}" \ -'. += {"log":{"loglevel":"warning"},"outbounds":[$jproxy,$jdirect,$jblocked]}' ` - -echo "$jroot" +echo "$Jproxy" exit 0 diff --git a/proxy-mwt.sh b/proxy-mwt.sh index 51cb2e9..cc76a70 100755 --- a/proxy-mwt.sh +++ b/proxy-mwt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "VMESS-WS-TLS proxy builder" - >&2 echo "Usage: proxy-mwt [,fingerprint=safari]" + >&2 echo -e "VMESS-WS-TLS proxy builder" + >&2 echo -e "Usage: proxy-mwt [,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # id@domain.com:443:/websocket,fingerprint=safari @@ -38,43 +37,28 @@ path="${options[2]}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${id}" ]; then - >&2 echo "Error: id undefined." - usage - exit 1 -fi +if [ -z "${id}" ]; then >&2 echo -e "Error: id undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jusers=`jq -nc --arg uuid "${id}" '. += {"id":$uuid,"encryption":"none","level":0}'` # Vnext settings Jvnext=`jq -nc --arg host "${host}" --arg port "${port}" --argjson juser "${Jusers}" \ -'. += {"address":$host,"port":($port | tonumber),"users":[$juser]}' ` +'. += {"address":$host,"port":($port|tonumber),"users":[$juser]}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn},"wsSettings":{"path":$path}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn},"wsSettings":{"path":$path}}' ` Jproxy=`jq -nc --arg host "${host}" --argjson jvnext "${Jvnext}" --argjson jstreamSettings "${JstreamSettings}" \ -'. += { "tag":"proxy","protocol":"vmess","settings":{"vnext":[$jvnext]},"streamSettings":$jstreamSettings }' ` -Jdirect='{"tag":"direct","protocol":"freedom","settings":{}}' -Jblocked='{"tag":"blocked","protocol":"blackhole","settings":{}}' +'. += { "tag":"proxy","protocol":"vmess","settings":{"vnext":[$jvnext]},"streamSettings":$jstreamSettings}' ` -jroot=`jq -n --argjson jproxy "${Jproxy}" --argjson jdirect "${Jdirect}" --argjson jblocked "${Jblocked}" \ -'. += {"log":{"loglevel":"warning"},"outbounds":[$jproxy,$jdirect,$jblocked]}' ` - -echo "$jroot" +echo "$Jproxy" exit 0 diff --git a/proxy-ttt.sh b/proxy-ttt.sh index 4a82b5e..cf5ee99 100755 --- a/proxy-ttt.sh +++ b/proxy-ttt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "TROJAN-TCP-TLS proxy builder" - >&2 echo "Usage: proxy-ttt [,fingerprint=safari]" + >&2 echo -e "TROJAN-TCP-TLS proxy builder" + >&2 echo -e "Usage: proxy-ttt [,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # password@domain.com:443,fingerprint=safari @@ -38,40 +37,25 @@ passwd="${id}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${passwd}" ]; then - >&2 echo "Error: password undefined." - usage - exit 1 -fi +if [ -z "${passwd}" ]; then >&2 echo -e "Error: password undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jservers=`jq -nc --arg host "${host}" --arg port "${port}" --arg passwd "${passwd}" \ -'. += {"address":$host,"port":($port | tonumber),"password":$passwd}' ` +'. += {"address":$host,"port":($port|tonumber),"password":$passwd}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"tcp","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn}}' ` Jproxy=`jq -nc --arg host "${host}" --argjson jservers "${Jservers}" --argjson jstreamSettings "${JstreamSettings}" \ -'. += { "tag":"proxy","protocol":"trojan","settings":{"servers":[$jservers]},"streamSettings":$jstreamSettings }' ` -Jdirect='{"tag":"direct","protocol":"freedom","settings":{}}' -Jblocked='{"tag":"blocked","protocol":"blackhole","settings":{}}' +'. += { "tag":"proxy","protocol":"trojan","settings":{"servers":[$jservers]},"streamSettings":$jstreamSettings}' ` -jroot=`jq -n --argjson jproxy "${Jproxy}" --argjson jdirect "${Jdirect}" --argjson jblocked "${Jblocked}" \ -'. += {"log":{"loglevel":"warning"},"outbounds":[$jproxy,$jdirect,$jblocked]}' ` - -echo "$jroot" +echo "$Jproxy" exit 0 diff --git a/proxy-twp.sh b/proxy-twp.sh index 9e9f6cb..b4f5839 100755 --- a/proxy-twp.sh +++ b/proxy-twp.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "TROJAN-WS-PLAIN proxy builder" - >&2 echo "Usage: proxy-twp " + >&2 echo -e "TROJAN-WS-PLAIN proxy builder" + >&2 echo -e "Usage: proxy-twp " } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # password@domain.com:443:/websocket @@ -20,27 +19,17 @@ port="${options[1]}" path="${options[2]}" passwd="${id}" -if [ -z "${passwd}" ]; then - >&2 echo "Error: password undefined." - usage - exit 1 -fi +if [ -z "${passwd}" ]; then >&2 echo -e "Error: password undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -fi +if [ -z "${port}" ]; then port=80; fi -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jservers=`jq -nc --arg host "${host}" --arg port "${port}" --arg passwd "${passwd}" \ -'. += {"address":$host,"port":($port | tonumber),"password":$passwd}' ` +'. += {"address":$host,"port":($port|tonumber),"password":$passwd}' ` # Stream Settings JstreamSettings=`jq -nc --arg path "${path}" \ @@ -48,11 +37,6 @@ JstreamSettings=`jq -nc --arg path "${path}" \ Jproxy=`jq -nc --arg host "${host}" --argjson jservers "${Jservers}" --argjson jstreamSettings "${JstreamSettings}" \ '. += { "tag":"proxy","protocol":"trojan","settings":{"servers":[$jservers]},"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" +echo "$Jproxy" exit 0 diff --git a/proxy-twt.sh b/proxy-twt.sh index 5c495f0..83267ba 100755 --- a/proxy-twt.sh +++ b/proxy-twt.sh @@ -1,14 +1,13 @@ #!/bin/bash usage() { - >&2 echo "TROJAN-WS-TLS proxy builder" - >&2 echo "Usage: proxy-twt [,fingerprint=safari]" + >&2 echo -e "TROJAN-WS-TLS proxy builder" + >&2 echo -e "Usage: proxy-twt [,fingerprint=safari]" } if [ -z "$1" ]; then - >&2 echo "Missing options" - usage - exit 1 + >&2 echo -e "Missing command options.\n" + usage; exit 1 fi # password@domain.com:443:/websocket,fingerprint=safari @@ -39,40 +38,25 @@ passwd="${id}" if [ -z "${fingerprint}" ]; then fingerprint="safari"; fi -if [ -z "${passwd}" ]; then - >&2 echo "Error: password undefined." - usage - exit 1 -fi +if [ -z "${passwd}" ]; then >&2 echo -e "Error: password undefined.\n"; usage; exit 1; fi -if [ -z "${host}" ]; then - >&2 echo "Error: destination host undefined." - usage - exit 1 -fi +if [ -z "${host}" ]; then >&2 echo -e "Error: destination host undefined.\n"; usage; exit 1; fi -if [ -z "${port}" ]; then - port=443 -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 +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # User settings Jservers=`jq -nc --arg host "${host}" --arg port "${port}" --arg passwd "${passwd}" \ -'. += {"address":$host,"port":($port | tonumber),"password":$passwd}' ` +'. += {"address":$host,"port":($port|tonumber),"password":$passwd}' ` # Stream Settings Jalpn=`printf '%s\n' "${ALPN[@]}"|jq -R|jq -sc` -JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson jalpn "${Jalpn}" \ -'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$jalpn},"wsSettings":{"path":$path}}' ` +JstreamSettings=`jq -nc --arg serverName "${serverName}" --arg fingerprint "${fingerprint}" --arg path "${path}" --argjson Jalpn "${Jalpn}" \ +'. += {"network":"ws","security":"tls","tlsSettings":{"serverName":$serverName,"fingerprint":$fingerprint,"alpn":$Jalpn},"wsSettings":{"path":$path}}' ` Jproxy=`jq -nc --arg host "${host}" --argjson jservers "${Jservers}" --argjson jstreamSettings "${JstreamSettings}" \ -'. += { "tag":"proxy","protocol":"trojan","settings":{"servers":[$jservers]},"streamSettings":$jstreamSettings }' ` -Jdirect='{"tag":"direct","protocol":"freedom","settings":{}}' -Jblocked='{"tag":"blocked","protocol":"blackhole","settings":{}}' +'. += { "tag":"proxy","protocol":"trojan","settings":{"servers":[$jservers]},"streamSettings":$jstreamSettings}' ` -jroot=`jq -n --argjson jproxy "${Jproxy}" --argjson jdirect "${Jdirect}" --argjson jblocked "${Jblocked}" \ -'. += {"log":{"loglevel":"warning"},"outbounds":[$jproxy,$jdirect,$jblocked]}' ` - -echo "$jroot" +echo "$Jproxy" exit 0 diff --git a/run.sh b/run.sh index bf306d7..9f44fc7 100755 --- a/run.sh +++ b/run.sh @@ -26,7 +26,7 @@ usage() { echo " --twt password@host:port:/wspath" echo " -d|--debug Start in debug mode with verbose output" echo " -i|--stdin Read config from stdin instead of auto generation" - echo " -j|--json Json snippet to merge into the config. Say '{"log":{"loglevel":"info"}'" + echo " -j|--json Json snippet to merge into the config. Say '{"log":{"loglevel":"info"}}'" echo " --dns Designated upstream DNS server IP, 1.1.1.1 will be applied by default" # echo " --dns-local Enable designated domain conf file. Like apple.china.conf" echo " --dns-local-cn Enable China-accessible domains to be resolved in China" @@ -50,39 +50,20 @@ while true ; do case "$1" in --lgp|--lgr|--lgt|--lsp|--lst|--ltr|--ltt|--lwp|--lwt|--mtt|--mwp|--mwt|--ttt|--twp|--twt) subcmd=`echo "$1"|tr -d "\-\-"` - $DIR/proxy-${subcmd}.sh $2 >$XCONF - if [ $? != 0 ]; then - echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" - exit 2 - else - XRAYCFG=1 - fi + PXCMD="$DIR/proxy-${subcmd}.sh $2" shift 2 ;; --ltrx|--lttx) # Alias of --ltr|ltt options subcmd=`echo $1|tr -d '\-\-'|tr -d x` - $DIR/proxy-${subcmd}.sh $2,xtls >$XCONF - if [ $? != 0 ]; then - echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" - exit 2 - else - XRAYCFG=1 - fi + PXCMD="$DIR/proxy-${subcmd}.sh $2,xtls" shift 2 ;; --lst3) # Alias of --lst options # splitHTTP is the only option for H3 support from Xray-Core so far. subcmd=`echo $1|tr -d '\-\-'|tr -d 3` - echo $subcmd - $DIR/proxy-${subcmd}.sh $2,alpn=h3 >$XCONF - if [ $? != 0 ]; then - echo "${subcmd} Config failed: $DIR/proxy-${subcmd}.sh $2" - exit 2 - else - XRAYCFG=1 - fi + PXCMD="$DIR/proxy-${subcmd}.sh $2,alpn=h3" shift 2 ;; --dns) @@ -152,8 +133,7 @@ while true ; do shift 2 ;; -i|--stdin) - STDINCONF=1 - XRAYCFG=1 + exec /usr/local/bin/xray shift 1 ;; -d|--debug) @@ -171,10 +151,42 @@ while true ; do esac done -if [ "${XRAYCFG}" != "1" ]; then - echo "Missing Xray connection option" - usage - exit 1 +if [ -z "${PXCMD}" ]; then >&2 echo -e "Missing Xray connection option.\n"; usage; exit 1; fi + +# Init root config +Jroot='{"outbounds":[{"tag":"direct","protocol":"freedom"},{"tag":"blocked","protocol":"blackhole"}]}' + +# Add outbounds config +Joutbound=`$PXCMD` +if [ $? != 0 ]; then >&2 echo -e "${subcmd} Config failed: $PXCMD\n"; exit 2; fi +Jroot=`echo $Jroot|jq --argjson Joutbound "${Joutbound}" '.outbounds += [$Joutbound]'` + +# Add inbounds config +if [ -z "${DNS}" ]; then DNS="1.1.1.1"; fi +JibDNS=`jq -nc --arg dns "${DNS}" \ +'. +={"tag":"dns-in","port":5353,"listen":"0.0.0.0","protocol":"dokodemo-door","settings":{"address":$dns,"port":53,"network":"tcp,udp"}}'` +JibSOCKS=`jq -nc '. +={"tag":"socks","port":1080,"listen":"0.0.0.0","protocol":"socks","settings":{"udp":true}}'` +JibHTTP=`jq -nc '. +={"tag":"http","port":8123,"listen":"0.0.0.0","protocol":"http"}'` +Jroot=`echo $Jroot|jq --argjson JibDNS "${JibDNS}" --argjson JibSOCKS "${JibSOCKS}" --argjson JibHTTP "${JibHTTP}" \ +'.inbounds += [$JibDNS,$JibSOCKS,$JibHTTP]'` + +# Add routing config +Jrouting='{"routing":{"domainStrategy":"AsIs"}}' +Jrouting=`echo "${Jrouting}" |jq --argjson jrules "${Jrules}" '.routing += $jrules'` +Jroot=`echo $Jroot|jq --argjson Jrouting "${Jrouting}" '.routing += $Jrouting'` + +# Add debug config +if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi +Jroot=`echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel'` + +# Merge injected json config +if [ -n "${INJECT}" ]; then + for JSON_IN in "${INJECT[@]}" + do + Jmerge=`jq -nc "${JSON_IN}"` + if [[ $? -ne 0 ]]; then echo "Invalid json ${JSON_IN}"; exit 1; fi + Jroot=`jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge'` + done fi if [ -n "${DNSLOCAL}" ]; then @@ -186,43 +198,6 @@ fi echo -e "no-resolv\nserver=127.0.0.1#5353" >/etc/dnsmasq.d/upstream.conf /usr/sbin/dnsmasq -if [ -z "${DNS}" ]; then - DNS="1.1.1.1" -fi - -# Add inbounds config -JibDKDEMO=`jq -nc --arg dns "${DNS}" \ -'. +={"tag":"dns-in","port":5353,"listen":"0.0.0.0","protocol":"dokodemo-door","settings":{"address":$dns,"port":53,"network":"tcp,udp"}}' ` -JibSOCKS=`jq -nc '. +={"tag":"socks","port":1080,"listen":"0.0.0.0","protocol":"socks","settings":{"udp":true}}' ` -JibHTTP=`jq -nc '. +={"tag":"http","port":8123,"listen":"0.0.0.0","protocol":"http"}' ` -cat $XCONF| jq --argjson jibdkdemo "${JibDKDEMO}" --argjson jibsocks "${JibSOCKS}" --argjson jibhttp "${JibHTTP}" \ -'. += {"inbounds":[$jibdkdemo, $jibsocks, $jibhttp]}' | sponge $XCONF - -# Add routing config -Jrouting='{"routing":{"domainStrategy":"AsIs"}}' -Jrouting=`echo "${Jrouting}" |jq --argjson jrules "${Jrules}" '.routing += $jrules'` -cat $XCONF| jq --argjson jrouting "${Jrouting}" '. += $jrouting' | sponge $XCONF - -if [ "${STDINCONF}" = "1" ]; then - exec /usr/local/bin/xray -fi - -if [ "${DEBUG}" = "1" ]; then - cat $XCONF |jq '.log.loglevel |="debug"' | sponge $XCONF - cat $XCONF -fi - - if [ -n "${INJECT}" ]; then - for JSON_IN in "${INJECT[@]}" - do - echo "${JSON_IN}"|jq -ec >/tmp/merge.json - if [[ $? -ne 0 ]]; then - echo "Invalid json ${JSON_IN}" - exit 1 - fi - jq -s '.[0] * .[1]' $XCONF /tmp/merge.json |sponge $XCONF - done - fi - +jq -n "$Jroot" +jq -n "$Jroot">$XCONF exec /usr/local/bin/xray -c $XCONF -