diff --git a/README.md b/README.md index 33611ba..1c6c0b0 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ server-xray -r|--request-domain Domain name to request for letsencrypt cert -c|--cert-home Reading TLS certs from folder // -i|--stdin Read config from STDIN instead of auto generation - -j|--json Json snippet to merge into the config. Say '{log:{loglevel:info}}' + -j|--json Json snippet to merge into the config. Say '{"log":{"loglevel":"info"}}' -d|--debug Start in debug mode with verbose output ``` diff --git a/run.sh b/run.sh index dacfb97..b8c2bce 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,6 @@ #!/bin/bash DIR=$(dirname $0) -DIR="$(cd $DIR; pwd)" CERTHOME="/opt/cert" XCONF=/tmp/server-xray.json @@ -36,7 +35,7 @@ usage() { echo " -r|--request-domain Domain name to request for letsencrypt cert" echo " -c|--cert-home Reading TLS certs from folder //" 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 " -d|--debug Start in debug mode with verbose output" } @@ -232,7 +231,7 @@ done if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi Jroot=$(echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel') -if [ -n "${INJECT}" ]; then +if [ -n "${INJECT[@]}" ]; then for JSON_IN in "${INJECT[@]}" do Jmerge=$(jq -nc "${JSON_IN}") diff --git a/server-lgp.sh b/server-lgp.sh index f09aa7b..2501ca5 100755 --- a/server-lgp.sh +++ b/server-lgp.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-GRPC-PLAIN server builder" >&2 echo -e "Usage: server-lgp ,,,,...,[proxy_acpt],[fallback=host:port:path]" @@ -50,7 +48,7 @@ if [ -z "${serviceName}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -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 -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 525bcc1..42ea2a7 100755 --- a/server-lgr.sh +++ b/server-lgr.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&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]" @@ -76,7 +74,7 @@ if [ -z "${serviceName}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -115,7 +113,7 @@ inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --a '.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}') # serverNames settings -if [ -n "${serverNames}" ]; then +if [ -n "${serverNames[@]}" ]; then JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc) inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames') fi @@ -130,7 +128,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 ab6d16f..9a18c14 100755 --- a/server-lgt.sh +++ b/server-lgt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-GRPC-TLS server builder" >&2 echo -e "Usage: server-lgt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -64,7 +62,7 @@ if [ -z "${serviceName}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -111,7 +109,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 92eca70..b589a65 100755 --- a/server-lsp.sh +++ b/server-lsp.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-SPLT-PLAIN server builder" >&2 echo -e "Usage: server-lsp ,,,,...,[proxy_acpt],[fallback=host:port:path]" @@ -50,7 +48,7 @@ if [ -z "${webpath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -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 -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 6deffc3..b94e563 100755 --- a/server-lst.sh +++ b/server-lst.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-SPLT-TLS server builder" >&2 echo -e "Usage: server-lst ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -64,7 +62,7 @@ if [ -z "${webpath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -111,7 +109,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 4cf0aab..764cb1b 100755 --- a/server-ltr.sh +++ b/server-ltr.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&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]" @@ -68,7 +66,7 @@ if [ -z "${prvkey}" ]; then >&2 echo -e "PublicKey: $pubkey\n" fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -107,7 +105,7 @@ inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --a '.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}') # serverNames settings -if [ -n "${serverNames}" ]; then +if [ -n "${serverNames[@]}" ]; then JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc) inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames') fi @@ -122,7 +120,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 4c2b306..c9d6c8e 100755 --- a/server-ltt.sh +++ b/server-ltt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-TCP-TLS server builder" >&2 echo -e "Usage: server-ltt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -56,7 +54,7 @@ if [ -z "${port}" ]; then usage; exit 1 ; fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -103,7 +101,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 41e703e..ae9c94d 100755 --- a/server-lwp.sh +++ b/server-lwp.sh @@ -48,7 +48,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -88,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 -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 a02840c..43e85cb 100755 --- a/server-lwt.sh +++ b/server-lwt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VLESS-WS-TLS server builder" >&2 echo -e "Usage: server-lwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -64,7 +62,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -111,7 +109,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 04ebba3..ce76219 100755 --- a/server-mtt.sh +++ b/server-mtt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VMESS-TCP-TLS server builder" >&2 echo -e "Usage: server-mtt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -56,7 +54,7 @@ if [ -z "${port}" ]; then usage; exit 1 ; fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -103,7 +101,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 3887f29..9da3874 100755 --- a/server-mwp.sh +++ b/server-mwp.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VMESS-WS-PLAIN server builder" >&2 echo -e "Usage: server-mwp ,,,,...,[proxy_acpt],[fallback=host:port:path]" @@ -50,7 +48,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -91,7 +89,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo -e "Incorrect fallback format: ${fallback}\n" + >&2 echo -e "Incorrect fallback format: $fb\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 1ad2d73..a240938 100755 --- a/server-mwt.sh +++ b/server-mwt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "VMESS-WS-TLS server builder" >&2 echo -e "Usage: server-mwt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -64,7 +62,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -112,7 +110,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo -e "Incorrect fallback format: ${fallback}\n" + >&2 echo -e "Incorrect fallback format: $fb\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 cc26dc8..75ffc66 100755 --- a/server-nginx.sh +++ b/server-nginx.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) -DIR="$(cd $DIR; pwd)" SITE_TPL="nginx-site.tpl" STREAM_TPL="nginx-stream.tpl" NGCONF="/etc/nginx/nginx.conf" @@ -106,7 +104,7 @@ options=($(echo $STSVR |tr ',' ' ')) esac done # Naming the upstream as yahoo_com_jp for SNI yahoo.com.jp - upsname=$(echo $sni|sed 's/\./_/g') + upsname=$(echo "${sni//\./_}") echo " $sni $upsname;" >>/tmp/stmap.conf echo " upstream $upsname {" >>/tmp/stups.conf echo " server $upstream;" >>/tmp/stups.conf diff --git a/server-ttt.sh b/server-ttt.sh index 282f6ef..b6f7f60 100755 --- a/server-ttt.sh +++ b/server-ttt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "TROJAN-TCP-TLS server builder" >&2 echo -e "Usage: server-ttt ,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -56,7 +54,7 @@ if [ -z "${port}" ]; then usage; exit 1 ; fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -103,7 +101,7 @@ do IFS=':'; fopt=(${fb}); fopt=(${fopt[@]}) fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS - if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: ${fallback}\n"; usage; exit 1; fi + if [ -z "${fport}" ]; then >&2 echo -e "Incorrect fallback format: $fb\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 4418a7d..fde1e87 100755 --- a/server-twp.sh +++ b/server-twp.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "TROJAN-WS-PLAIN server builder" >&2 echo -e "Usage: server-twp ,,,,...,[proxy_acpt],[fallback=host:port:path]" @@ -50,7 +48,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -91,7 +89,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo -e "Incorrect fallback format: ${fallback}\n" + >&2 echo -e "Incorrect fallback format: $fb\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 8c185fe..5424faa 100755 --- a/server-twt.sh +++ b/server-twt.sh @@ -1,7 +1,5 @@ #!/bin/bash -DIR=$(dirname $0) - usage() { >&2 echo -e "TROJAN-WS-TLS server builder" >&2 echo -e "Usage: server-twt ,,,,,...,[proxy_acpt],[fallback=host:port:path],[xtls]" @@ -64,7 +62,7 @@ if [ -z "${wspath}" ]; then usage; exit 1 fi -if [ -z "${xuser}" ]; then +if [ -z "${xuser[@]}" ]; then >&2 echo -e "Error: User undefined.\n" usage; exit 1 fi @@ -112,7 +110,7 @@ do fhost="${fopt[0]}"; fport="${fopt[1]}"; fpath="${fopt[2]}" unset IFS if [ -z "${fport}" ]; then - >&2 echo -e "Incorrect fallback format: ${fallback}\n" + >&2 echo -e "Incorrect fallback format: $fb\n" usage; exit 1 fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi