From 0c3aa7b69eed2197c5a68c78d4d3731f7309e69f Mon Sep 17 00:00:00 2001 From: Samuel Huang Date: Mon, 30 Sep 2024 20:40:48 +1000 Subject: [PATCH] Codacy compliant --- README.md | 2 +- adduser.sh | 74 --------------------------------------------- addusertj.sh | 74 --------------------------------------------- fallback.sh | 79 ------------------------------------------------- run.sh | 3 +- server-lgp.sh | 12 ++++---- server-lgr.sh | 16 +++++----- server-lgt.sh | 16 +++++----- server-lsp.sh | 12 ++++---- server-lst.sh | 16 +++++----- server-ltr.sh | 16 +++++----- server-ltt.sh | 16 +++++----- server-lwp.sh | 14 ++++----- server-lwt.sh | 16 +++++----- server-mtt.sh | 16 +++++----- server-mwp.sh | 14 ++++----- server-mwt.sh | 16 +++++----- server-nginx.sh | 11 +++---- server-ttt.sh | 16 +++++----- server-twp.sh | 22 +++++++------- server-twt.sh | 28 +++++++++--------- 21 files changed, 130 insertions(+), 359 deletions(-) delete mode 100755 adduser.sh delete mode 100755 addusertj.sh delete mode 100755 fallback.sh diff --git a/README.md b/README.md index 6065349..33611ba 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ $ docker run --name server-xtls -p 80:80 -p 443:443 -d samuelhbne/server-xray \ ... ``` -** NOTE ** +**NOTE** - Port 80 exposure (-p 80:80) is necessary for Letsencrypt domain verification during cert requesting. diff --git a/adduser.sh b/adduser.sh deleted file mode 100755 index add5df2..0000000 --- a/adduser.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -usage() { - echo "Usage: adduser -p -u -c -f " >&2 -} - -TEMP=`getopt -o c:f:p:u: --long comment:flow:port:,user: -n "$0" -- $@` -if [ $? != 0 ] ; then usage; exit 1 ; fi - -eval set -- "$TEMP" -while true ; do - case "$1" in - -c|--comment) - comment="$2" - shift 2 - ;; - -f|flow) - flow="$2" - shift 2 - ;; - -p|--port) - port="$2" - shift 2 - ;; - -u|--user) - user="$2" - shift 2 - ;; - --) - shift - break - ;; - *) - echo "Unknown option: $1" >&2 - usage; - exit 1 - ;; - esac -done - -if [ -z "${port}" ]; then - echo "Error: port undefined." >&2 - usage - exit 1 ; -fi - -IFS=':' -uopt=(${user}) -uopt=(${uopt[@]}) - -uid="${uopt[0]}" -level="${uopt[1]}" -email="${uopt[2]}" - -if [ -z "${uid}" ]; then - echo "Error: Undefined UID \"$user\"" >&2 - echo "Correct user format: user=[:level:email]" >&2 - echo "Like: user=myid:0:me@g.cn" >&2 - echo "Like: user=myid::me@g.cn" >&2 - echo "Like: user=myid:0" >&2 - echo "Like: user=myid" >&2 - exit 1 -fi - -if [ -z "${level}" ]; then - level=0 -fi - -if [ -z "${email}" ]; then - email="${uid}@${comment}" -fi - -jq --arg port "${port}" --arg uid "${uid}" --arg level "${level}" --arg email "${email}" --arg flow "${flow}" \ -'( .inbounds[] | select(.port == ($port|tonumber)) | .settings.clients ) += [ {"id":$uid, "flow":$flow, "level":($level|tonumber), "email":$email} ] ' \ diff --git a/addusertj.sh b/addusertj.sh deleted file mode 100755 index 9ab77aa..0000000 --- a/addusertj.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -usage() { - echo "Usage: adduser -p -u -c -f " >&2 -} - -TEMP=`getopt -o c:f:p:u: --long comment:flow:port:,user: -n "$0" -- $@` -if [ $? != 0 ] ; then usage; exit 1 ; fi - -eval set -- "$TEMP" -while true ; do - case "$1" in - -c|--comment) - comment="$2" - shift 2 - ;; - -f|flow) - flow="$2" - shift 2 - ;; - -p|--port) - port="$2" - shift 2 - ;; - -u|--user) - user="$2" - shift 2 - ;; - --) - shift - break - ;; - *) - echo "Unknown option: $1" >&2 - usage; - exit 1 - ;; - esac -done - -if [ -z "${port}" ]; then - echo "Error: port undefined." >&2 - usage - exit 1 ; -fi - -IFS=':' -uopt=(${user}) -uopt=(${uopt[@]}) - -psw="${uopt[0]}" -level="${uopt[1]}" -email="${uopt[2]}" - -if [ -z "${psw}" ]; then - echo "Error: Undefined UID \"$user\"" >&2 - echo "Correct user format: user=[:level:email]" >&2 - echo "Like: user=mypw:0:me@g.cn" >&2 - echo "Like: user=mypw::me@g.cn" >&2 - echo "Like: user=mypw:0" >&2 - echo "Like: user=mypw" >&2 - exit 1 -fi - -if [ -z "${level}" ]; then - level=0 -fi - -if [ -z "${email}" ]; then - email="${psw}@${comment}" -fi - -jq --arg port "${port}" --arg psw "${psw}" --arg level "${level}" --arg email "${email}" --arg flow "${flow}" \ -'( .inbounds[] | select(.port == ($port|tonumber)) | .settings.clients ) += [ {"password":$psw, "flow":$flow, "level":($level|tonumber), "email":$email} ] ' \ diff --git a/fallback.sh b/fallback.sh deleted file mode 100755 index 90b87f3..0000000 --- a/fallback.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash - -usage() { - echo "Usage: fallback -p -f " >&2 -} - -TEMP=`getopt -o f:p: --long port:,fallback: -n "$0" -- $@` -if [ $? != 0 ] ; then usage; exit 1 ; fi - -eval set -- "$TEMP" -while true ; do - case "$1" in - -p|--port) - port="$2" - shift 2 - ;; - -f|--fallback) - fallback="$2" - shift 2 - ;; - --) - shift - break - ;; - *) - echo "Unknown option: $1" >&2 - usage; - exit 1 - ;; - esac -done - -if [ -z "${port}" ]; then - echo "Error: port undefined." >&2 - usage - exit 1 ; -fi - -if [ -z "${fallback}" ]; then - echo "Error: fallback undefined." >&2 - usage - exit 1 ; -fi - -IFS=':' -fopt=(${fallback}) -fopt=(${fopt[@]}) - -fhost="${fopt[0]}" -fport="${fopt[1]}" -fpath="${fopt[2]}" -fdest=$fhost:$fport - -if [ -z "${fport}" ]; then - echo "Incorrect fallback format: ${fallback}" - echo "Correct fallback: fallback=[host]<:port>[:path]" - echo "Like: fallback=baidu.com:443:/path" - echo "Like: fallback=:1443:/path" - echo "Like: fallback=:1443" - exit 1 -fi - -if [ -z "${fhost}" ]; then - if [ -z "${fpath}" ]; then - Jfallback=`echo '{}' |jq --arg fport "${fport}" --arg fpath "${fpath}" '. += {"dest":($fport|tonumber), "xver":1}'` - else - Jfallback=`echo '{}' |jq --arg fport "${fport}" --arg fpath "${fpath}" '. += {"dest":($fport|tonumber), "path":$fpath, "xver":1}'` - fi -else - if [ -z "${fpath}" ]; then - fdest="${fhost}:${fport}" - Jfallback=`echo '{}' |jq --arg fdest "${fdest}" --arg fpath "${fpath}" '. += {"dest":$fdest, "xver":1}'` - else - Jfallback=`echo '{}' |jq --arg fdest "${fdest}" --arg fpath "${fpath}" '. += {"dest":$fdest, "path":$fpath, "xver":1}'` - fi -fi - -jq --arg port "${port}" --argjson jfallback "$Jfallback" \ -'( .inbounds[] | select(.port == ($port|tonumber)) | .settings.fallbacks ) += [ $jfallback ] ' \ diff --git a/run.sh b/run.sh index 5889474..dacfb97 100755 --- a/run.sh +++ b/run.sh @@ -42,7 +42,7 @@ usage() { Jrules='{"rules":[]}' -TEMP=$(getopt -o u:k:r:c:j:di --long lgp:,lgr:,lgt:,lsp:,lst:,ltr:,ltrx:,ltt:,lttx:,lwp:,lwt:,mtt:,mwp:,mwt:,ttt:,twp:,twt:,user:,hook:,request-domain:,cert-home:,ip-block:,domain-block:,cn-block,ng-server:,ng-proxy:,st-server:,st-map:,json:,stdin,debug -n "$0" -- $@) +TEMP=$(getopt -o "u:k:r:c:j:di" --long "lgp:,lgr:,lgt:,lsp:,lst:,ltr:,ltrx:,ltt:,lttx:,lwp:,lwt:,mtt:,mwp:,mwt:,ttt:,twp:,twt:,user:,hook:,request-domain:,cert-home:,ip-block:,domain-block:,cn-block,ng-server:,ng-proxy:,st-server:,st-map:,json:,stdin,debug" -n "$0" -- $@) if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" @@ -245,4 +245,3 @@ jq -n "$Jroot" jq -n "$Jroot">$XCONF exec /usr/local/bin/xray -c $XCONF -fi diff --git a/server-lgp.sh b/server-lgp.sh index 4127a35..f09aa7b 100755 --- a/server-lgp.sh +++ b/server-lgp.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-GRPC-PLAIN server builder" - >&2 echo "Usage: server-lgp ,,,,...,[proxy_acpt],[fallback=host:port:path]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-GRPC-PLAIN server builder" + >&2 echo -e "Usage: server-lgp ,,,,...,[proxy_acpt],[fallback=host:port:path]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -66,7 +66,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgp.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -90,7 +90,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lgr.sh b/server-lgr.sh index 57c3212..525bcc1 100755 --- a/server-lgr.sh +++ b/server-lgr.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-GRPC-REALITY server builder" - >&2 echo "Usage: server-lgr ,,,,[pub=xx],[shortId=zz],,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-GRPC-REALITY server builder" + >&2 echo -e "Usage: server-lgr ,,,,[pub=xx],[shortId=zz],,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -64,11 +64,11 @@ if [ -z "${port}" ]; then fi if [ -z "${prvkey}" ]; then - >&2 echo "Warning: PrivateKey undefined, Generated new..." + >&2 echo -e "Warning: PrivateKey undefined, Generated new...\n" kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' ')) prvkey="${kv[0]}" pubkey="${kv[1]}" - >&2 echo "PublicKey: $pubkey" + >&2 echo -e "PublicKey: $pubkey\n" fi if [ -z "${serviceName}" ]; then @@ -92,7 +92,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgr.$dest"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -130,7 +130,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lgt.sh b/server-lgt.sh index e63cd8f..ab6d16f 100755 --- a/server-lgt.sh +++ b/server-lgt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-GRPC-TLS server builder" - >&2 echo "Usage: server-lgt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-GRPC-TLS server builder" + >&2 echo -e "Usage: server-lgt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -71,8 +71,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -85,7 +85,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lgt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -111,7 +111,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lsp.sh b/server-lsp.sh index 68f11a6..92eca70 100755 --- a/server-lsp.sh +++ b/server-lsp.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-SPLT-PLAIN server builder" - >&2 echo "Usage: server-lsp ,,,,...,[proxy_acpt],[fallback=host:port:path]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-SPLT-PLAIN server builder" + >&2 echo -e "Usage: server-lsp ,,,,...,[proxy_acpt],[fallback=host:port:path]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -66,7 +66,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lsp.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -90,7 +90,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lst.sh b/server-lst.sh index baed18e..6deffc3 100755 --- a/server-lst.sh +++ b/server-lst.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-SPLT-TLS server builder" - >&2 echo "Usage: server-lst ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-SPLT-TLS server builder" + >&2 echo -e "Usage: server-lst ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -71,8 +71,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -85,7 +85,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lst.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -111,7 +111,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-ltr.sh b/server-ltr.sh index b05f9b9..4cf0aab 100755 --- a/server-ltr.sh +++ b/server-ltr.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-TCP-REALITY server builder" - >&2 echo "Usage: server-ltr ,,[pub=xx],[shortId=zz],,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-TCP-REALITY server builder" + >&2 echo -e "Usage: server-ltr ,,[pub=xx],[shortId=zz],,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -61,11 +61,11 @@ if [ -z "${port}" ]; then fi if [ -z "${prvkey}" ]; then - >&2 echo "Warning: PrivateKey undefined, Generated new..." + >&2 echo -e "Warning: PrivateKey undefined, Generated new...\n" kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' ')) prvkey="${kv[0]}" pubkey="${kv[1]}" - >&2 echo "PublicKey: $pubkey" + >&2 echo -e "PublicKey: $pubkey\n" fi if [ -z "${xuser}" ]; then @@ -84,7 +84,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ltr.$dest"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -122,7 +122,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-ltt.sh b/server-ltt.sh index 0610c63..4c2b306 100755 --- a/server-ltt.sh +++ b/server-ltt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-TCP-TLS server builder" - >&2 echo "Usage: server-ltt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-TCP-TLS server builder" + >&2 echo -e "Usage: server-ltt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -63,8 +63,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -77,7 +77,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ltt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -103,7 +103,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lwp.sh b/server-lwp.sh index 57287d8..41e703e 100755 --- a/server-lwp.sh +++ b/server-lwp.sh @@ -1,12 +1,10 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { - >&2 echo "VLESS-WS-PLAIN server builder" - >&2 echo "Usage: server-lwp ,,,,...,[proxy_acpt],[fallback=host:port:path]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-WS-PLAIN server builder" + >&2 echo -e "Usage: server-lwp ,,,,...,[proxy_acpt],[fallback=host:port:path]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -66,7 +64,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lwp.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -90,7 +88,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-lwt.sh b/server-lwt.sh index 439e0ef..a02840c 100755 --- a/server-lwt.sh +++ b/server-lwt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VLESS-WS-TLS server builder" - >&2 echo "Usage: server-lwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VLESS-WS-TLS server builder" + >&2 echo -e "Usage: server-lwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -71,8 +71,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -85,7 +85,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@lwt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -111,7 +111,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-mtt.sh b/server-mtt.sh index 52d1d6c..04ebba3 100755 --- a/server-mtt.sh +++ b/server-mtt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VMESS-TCP-TLS server builder" - >&2 echo "Usage: server-mtt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VMESS-TCP-TLS server builder" + >&2 echo -e "Usage: server-mtt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -63,8 +63,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -77,7 +77,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mtt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -103,7 +103,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-mwp.sh b/server-mwp.sh index 10f1760..3887f29 100755 --- a/server-mwp.sh +++ b/server-mwp.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VMESS-WS-PLAIN server builder" - >&2 echo "Usage: server-mwp ,,,,...,[proxy_acpt],[fallback=host:port:path]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VMESS-WS-PLAIN server builder" + >&2 echo -e "Usage: server-mwp ,,,,...,[proxy_acpt],[fallback=host:port:path]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -55,7 +55,7 @@ if [ -z "${xuser}" ]; then usage; exit 1 fi -if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric.\n"; exit 1; fi +if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Port number must be numeric.\n"; exit 1; fi # inbound frame inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}') @@ -66,7 +66,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mwp.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -91,7 +91,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo "Incorrect fallback format: ${fallback}" + >&2 echo -e "Incorrect fallback format: ${fallback}\n" usage; exit 1 fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi diff --git a/server-mwt.sh b/server-mwt.sh index 43aa0b6..1ad2d73 100755 --- a/server-mwt.sh +++ b/server-mwt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "VMESS-WS-TLS server builder" - >&2 echo "Usage: server-mwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "VMESS-WS-TLS server builder" + >&2 echo -e "Usage: server-mwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -71,8 +71,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -85,7 +85,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@mwt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -112,7 +112,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo "Incorrect fallback format: ${fallback}" + >&2 echo -e "Incorrect fallback format: ${fallback}\n" usage; exit 1 fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi diff --git a/server-nginx.sh b/server-nginx.sh index f48aff1..cc26dc8 100755 --- a/server-nginx.sh +++ b/server-nginx.sh @@ -14,7 +14,7 @@ usage() { >&2 echo " --st-server [p=443],[proxy_pass]" } -TEMP=$(getopt -o m:n:p:s:x: --long ng-server:,ng-proxy:,st-server:,st-map: -n "$0" -- $@) +TEMP=$(getopt -o "m:n:p:s:x:" --long "ng-server:,ng-proxy:,st-server:,st-map:" -n "$0" -- $@) if [ $? != 0 ] ; then usage; exit 1 ; fi eval set -- "$TEMP" @@ -164,10 +164,11 @@ do # Generating default site config for every --ngserver invocation # to avoid domain name leaking against bot probing. default_domain="00_default_${port}" - mkdir "${certhome}/${default_domain}"; cd "${certhome}/${default_domain}" - # Generating self-signed cert for default domain. - openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "${default_domain}.key" -out fullchain.cer -subj "/C=US/ST=NV/L=Vegas/O=Internic/CN=localhost" - cd - + ( + mkdir "${certhome}/${default_domain}"; cd "${certhome}/${default_domain}" + # Generating self-signed cert for default domain. + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout "${default_domain}.key" -out fullchain.cer -subj "/C=US/ST=NV/L=Vegas/O=Internic/CN=localhost" + ) SITEDOMAINS+=("${default_domain}") # Generating site config files for each domain including default domain. for site_domain in "${SITEDOMAINS[@]}" diff --git a/server-ttt.sh b/server-ttt.sh index 4b6a1af..282f6ef 100755 --- a/server-ttt.sh +++ b/server-ttt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "TROJAN-TCP-TLS server builder" - >&2 echo "Usage: server-ttt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user|u=[:level:email]" + >&2 echo -e "TROJAN-TCP-TLS server builder" + >&2 echo -e "Usage: server-ttt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user|u=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -63,8 +63,8 @@ fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi @@ -77,7 +77,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@ttt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -103,7 +103,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi fdest="$fhost:$fport" Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}') diff --git a/server-twp.sh b/server-twp.sh index 3095f8e..4418a7d 100755 --- a/server-twp.sh +++ b/server-twp.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "TROJAN-WS-PLAIN server builder" - >&2 echo "Usage: server-twp ,,,,...,[proxy_acpt],[fallback=host:port:path]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user=[:level:email]" + >&2 echo -e "TROJAN-WS-PLAIN server builder" + >&2 echo -e "Usage: server-twp ,,,,...,[proxy_acpt],[fallback=host:port:path]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -36,26 +36,26 @@ do done if [ -z "${domain}" ]; then - >&2 echo "Error: Domain undefined." + >&2 echo -e "Error: Domain undefined.\n" usage; exit 1 fi if [ -z "${port}" ]; then - >&2 echo "Error: Port undefined." + >&2 echo -e "Error: Port undefined.\n" usage; exit 1 ; fi if [ -z "${wspath}" ]; then - >&2 echo "Error: wspath undefined." + >&2 echo -e "Error: wspath undefined.\n" usage; exit 1 fi if [ -z "${xuser}" ]; then - >&2 echo "Error: User undefined." + >&2 echo -e "Error: User undefined.\n" usage; exit 1 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 # inbound frame inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}') @@ -66,7 +66,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@twp.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -91,7 +91,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo "Incorrect fallback format: ${fallback}" + >&2 echo -e "Incorrect fallback format: ${fallback}\n" usage; exit 1 fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi diff --git a/server-twt.sh b/server-twt.sh index 4c57eaf..8c185fe 100755 --- a/server-twt.sh +++ b/server-twt.sh @@ -3,10 +3,10 @@ DIR=$(dirname $0) usage() { - >&2 echo "TROJAN-WS-TLS server builder" - >&2 echo "Usage: server-twt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" - >&2 echo "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" - >&2 echo "User format: user=[:level:email]" + >&2 echo -e "TROJAN-WS-TLS server builder" + >&2 echo -e "Usage: server-twt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" + >&2 echo -e "Fallback format: fallback=[host]<:port>[:/path] Like: 'baidu.com:443:/path', ':1443:/path', ':1443'" + >&2 echo -e "User format: user=[:level:email]" } options=($(echo $1 |tr ',' ' ')) @@ -45,36 +45,36 @@ do done if [ -z "${certhome}" ]; then - >&2 echo "Error: Certhome undefined." + >&2 echo -e "Error: Certhome undefined.\n" usage; exit 1 fi if [ -z "${domain}" ]; then - >&2 echo "Error: Domain undefined." + >&2 echo -e "Error: Domain undefined.\n" usage; exit 1 fi if [ -z "${port}" ]; then - >&2 echo "Error: Port undefined." + >&2 echo -e "Error: Port undefined.\n" usage; exit 1 ; fi if [ -z "${wspath}" ]; then - >&2 echo "Error: wspath undefined." + >&2 echo -e "Error: wspath undefined.\n" usage; exit 1 fi if [ -z "${xuser}" ]; then - >&2 echo "Error: User undefined." + >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi fullchain="${certhome}/${domain}/fullchain.cer" prvkey="${certhome}/${domain}/${domain}.key" -if [ ! -f "${fullchain}" ]; then >&2 echo "Warning, Fullchain not found: ${fullchain}"; fi -if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey}"; fi +if [ ! -f "${fullchain}" ]; then >&2 echo -e "Warning, Fullchain not found: ${fullchain}\n"; fi +if [ ! -f "${prvkey}" ]; then >&2 echo -e "Warning, Private key not found: ${prvkey}\n"; 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 # inbound frame inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}') @@ -85,7 +85,7 @@ do IFS=':'; uopt=(${user}); uopt=(${uopt[@]}) uid="${uopt[0]}"; level="${uopt[1]}"; email="${uopt[2]}" unset IFS - if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi + if [ -z "${uid}" ]; then >&2 echo -e "Incorrect user format: $user\n"; usage; exit 1; fi if [ -z "${level}" ]; then level=0; fi if [ -z "${email}" ]; then email="${uid}@twt.$domain"; fi inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \ @@ -112,7 +112,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo "Incorrect fallback format: ${fallback}" + >&2 echo -e "Incorrect fallback format: ${fallback}\n" usage; exit 1 fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi