Codacy compliant

This commit is contained in:
Samuel Huang
2024-09-30 19:49:06 +10:00
parent ec0e068eb7
commit ae8a1a469a
17 changed files with 227 additions and 307 deletions

42
run.sh
View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
DIR="$(cd $DIR; pwd)" DIR="$(cd $DIR; pwd)"
CERTHOME="/opt/cert" CERTHOME="/opt/cert"
XCONF=/tmp/server-xray.json XCONF=/tmp/server-xray.json
@@ -42,7 +42,7 @@ usage() {
Jrules='{"rules":[]}' 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 if [ $? != 0 ] ; then usage; exit 1 ; fi
eval set -- "$TEMP" eval set -- "$TEMP"
@@ -79,33 +79,33 @@ while true ; do
;; ;;
--lgp|--lgr|--lgt|--lsp|--lst|--ltr|--ltt|--lwp|--lwt|--mtt|--mwp|--mwt|--ttt|--twp|--twt) --lgp|--lgr|--lgt|--lsp|--lst|--ltr|--ltt|--lwp|--lwt|--mtt|--mwp|--mwt|--ttt|--twp|--twt)
# Alias options # Alias options
SVC=`echo $1|tr -d '\-\-'` SVC=$(echo $1|tr -d '\-\-')
SVCMD+=("${DIR}/server-${SVC}.sh $2") SVCMD+=("${DIR}/server-${SVC}.sh $2")
shift 2 shift 2
;; ;;
--ltrx|--lttx) --ltrx|--lttx)
# Alias options # Alias options
SVC=`echo $1|tr -d '\-\-'|tr -d x` SVC=$(echo $1|tr -d '\-\-'|tr -d x)
SVCMD+=("${DIR}/server-${SVC}.sh $2,xtls") SVCMD+=("${DIR}/server-${SVC}.sh $2,xtls")
shift 2 shift 2
;; ;;
--domain-block) --domain-block)
Jrules=`echo "${Jrules}" | jq --arg blkdomain "$2" \ Jrules=$(echo "${Jrules}" | jq --arg blkdomain "$2" \
'.rules += [{"type":"field","outboundTag":"blocked","domain":[$blkdomain]}]'` '.rules += [{"type":"field","outboundTag":"blocked","domain":[$blkdomain]}]')
shift 2 shift 2
;; ;;
--ip-block) --ip-block)
Jrules=`echo "${Jrules}" | jq --arg blkip "$2" \ Jrules=$(echo "${Jrules}" | jq --arg blkip "$2" \
'.rules += [{"type":"field","outboundTag":"blocked","ip":[$blkip]}]'` '.rules += [{"type":"field","outboundTag":"blocked","ip":[$blkip]}]')
shift 2 shift 2
;; ;;
--cn-block) --cn-block)
Jrules=`echo "${Jrules}" | jq --arg igndomain "geosite:geolocation-cn" \ Jrules=$(echo "${Jrules}" | jq --arg igndomain "geosite:geolocation-cn" \
'.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]'` '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]')
Jrules=`echo "${Jrules}" | jq --arg igndomain "geosite:cn" \ Jrules=$(echo "${Jrules}" | jq --arg igndomain "geosite:cn" \
'.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]'` '.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]')
Jrules=`echo "${Jrules}" | jq --arg ignip "geoip:cn" \ Jrules=$(echo "${Jrules}" | jq --arg ignip "geoip:cn" \
'.rules += [{"type":"field","outboundTag":"blocked","ip":[$ignip]}]'` '.rules += [{"type":"field","outboundTag":"blocked","ip":[$ignip]}]')
shift 1 shift 1
;; ;;
--ng-server) --ng-server)
@@ -214,30 +214,30 @@ Jroot='{"outbounds":[{"tag":"direct","protocol":"freedom"},{"tag":"blocked","pro
# Add routing config # Add routing config
Jrouting='{"routing":{"domainStrategy":"AsIs"}}' Jrouting='{"routing":{"domainStrategy":"AsIs"}}'
Jrouting=`echo $Jrouting |jq --argjson jrules "${Jrules}" '.routing += $jrules'` Jrouting=$(echo $Jrouting |jq --argjson jrules "${Jrules}" '.routing += $jrules')
Jroot=`echo $Jroot| jq --argjson jrouting "${Jrouting}" '. += $jrouting'` Jroot=$(echo $Jroot| jq --argjson jrouting "${Jrouting}" '. += $jrouting')
# Xray service config generation # Xray service config generation
for svcmd in "${SVCMD[@]}" for svcmd in "${SVCMD[@]}"
do do
Jsvc=`$svcmd,$xopt` Jsvc=$($svcmd,$xopt)
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Service creation command failed: $svcmd,$xopt" echo "Service creation command failed: $svcmd,$xopt"
exit 1 exit 1
fi fi
Jroot=`echo $Jroot| jq --argjson Jsvc "${Jsvc}" '.inbounds += [$Jsvc]'` Jroot=$(echo $Jroot| jq --argjson Jsvc "${Jsvc}" '.inbounds += [$Jsvc]')
done done
if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi
Jroot=`echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel'` Jroot=$(echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel')
if [ -n "${INJECT}" ]; then if [ -n "${INJECT}" ]; then
for JSON_IN in "${INJECT[@]}" for JSON_IN in "${INJECT[@]}"
do do
Jmerge=`jq -nc "${JSON_IN}"` Jmerge=$(jq -nc "${JSON_IN}")
if [[ $? -ne 0 ]]; then echo "Invalid json ${JSON_IN}"; exit 1; fi if [[ $? -ne 0 ]]; then echo "Invalid json ${JSON_IN}"; exit 1; fi
Jroot=`jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge'` Jroot=$(jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge')
done done
fi fi

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-GRPC-PLAIN server builder" >&2 echo "VLESS-GRPC-PLAIN server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
domain="${kv[1]}" domain="${kv[1]}"
@@ -58,7 +58,7 @@ fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -69,20 +69,20 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lgp.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -93,8 +93,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-GRPC-REALITY server builder" >&2 echo "VLESS-GRPC-REALITY server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|dest) d|dest)
dest="${kv[1]}" dest="${kv[1]}"
@@ -65,7 +65,7 @@ fi
if [ -z "${prvkey}" ]; then if [ -z "${prvkey}" ]; then
>&2 echo "Warning: PrivateKey undefined, Generated new..." >&2 echo "Warning: PrivateKey undefined, Generated new..."
kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`) kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '))
prvkey="${kv[0]}" prvkey="${kv[0]}"
pubkey="${kv[1]}" pubkey="${kv[1]}"
>&2 echo "PublicKey: $pubkey" >&2 echo "PublicKey: $pubkey"
@@ -84,7 +84,7 @@ fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -95,34 +95,34 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lgr.$dest"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"reality"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"reality"}')
# Reality settings # Reality settings
inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'` '.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}')
# serverNames settings # serverNames settings
if [ -n "${serverNames}" ]; then if [ -n "${serverNames}" ]; then
JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc` JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc)
inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames'` inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames')
fi fi
# shortIds settings # shortIds settings
JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc` JshortIds=$(printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc)
inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds'` inbound=$(echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -133,8 +133,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-GRPC-TLS server builder" >&2 echo "VLESS-GRPC-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -88,22 +88,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lgt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'` inbound=$(echo $inbound| jq -c --arg serviceName "${serviceName}" '.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -114,8 +114,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-SPLT-PLAIN server builder" >&2 echo "VLESS-SPLT-PLAIN server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
domain="${kv[1]}" domain="${kv[1]}"
@@ -58,7 +58,7 @@ fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -69,20 +69,20 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lsp.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'` inbound=$(echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -93,8 +93,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-SPLT-TLS server builder" >&2 echo "VLESS-SPLT-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -88,22 +88,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lst.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'` inbound=$(echo $inbound| jq -c --arg webpath "${webpath}" '.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -114,8 +114,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-TCP-REALITY server builder" >&2 echo "VLESS-TCP-REALITY server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|dest) d|dest)
dest="${kv[1]}" dest="${kv[1]}"
@@ -62,7 +62,7 @@ fi
if [ -z "${prvkey}" ]; then if [ -z "${prvkey}" ]; then
>&2 echo "Warning: PrivateKey undefined, Generated new..." >&2 echo "Warning: PrivateKey undefined, Generated new..."
kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`) kv=($(/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '))
prvkey="${kv[0]}" prvkey="${kv[0]}"
pubkey="${kv[1]}" pubkey="${kv[1]}"
>&2 echo "PublicKey: $pubkey" >&2 echo "PublicKey: $pubkey"
@@ -76,7 +76,7 @@ fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -87,34 +87,34 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@ltr.$dest"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"reality"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"reality"}')
# Reality settings # Reality settings
inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'` '.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}')
# serverNames settings # serverNames settings
if [ -n "${serverNames}" ]; then if [ -n "${serverNames}" ]; then
JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc` JserverNames=$(printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc)
inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames'` inbound=$(echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.streamSettings.realitySettings.serverNames += $JserverNames')
fi fi
# shortIds settings # shortIds settings
JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc` JshortIds=$(printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc)
inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds'` inbound=$(echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.streamSettings.realitySettings.shortIds += $JshortIds')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -125,8 +125,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-TCP-TLS server builder" >&2 echo "VLESS-TCP-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -80,22 +80,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@ltt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -106,8 +106,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-WS-PLAIN server builder" >&2 echo "VLESS-WS-PLAIN server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
domain="${kv[1]}" domain="${kv[1]}"
@@ -58,7 +58,7 @@ fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -69,20 +69,20 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lwp.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -93,8 +93,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VLESS-WS-TLS server builder" >&2 echo "VLESS-WS-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vless","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -88,22 +88,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@lwt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -114,8 +114,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VMESS-TCP-TLS server builder" >&2 echo "VMESS-TCP-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -80,22 +80,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@mtt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -106,8 +106,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VMESS-WS-PLAIN server builder" >&2 echo "VMESS-WS-PLAIN server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
domain="${kv[1]}" domain="${kv[1]}"
@@ -58,7 +58,7 @@ 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 "Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -69,20 +69,20 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@mwp.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -96,8 +96,8 @@ do
fi fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "VMESS-WS-TLS server builder" >&2 echo "VMESS-WS-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"vmess","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -88,22 +88,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@mwt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -117,8 +117,8 @@ do
fi fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
DIR="$(cd $DIR; pwd)" DIR="$(cd $DIR; pwd)"
SITE_TPL="nginx-site.tpl" SITE_TPL="nginx-site.tpl"
STREAM_TPL="nginx-stream.tpl" STREAM_TPL="nginx-stream.tpl"
@@ -14,7 +14,7 @@ usage() {
>&2 echo " --st-server [p=443],[proxy_pass]" >&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 if [ $? != 0 ] ; then usage; exit 1 ; fi
eval set -- "$TEMP" eval set -- "$TEMP"
@@ -71,10 +71,10 @@ sed -i '/\#STREAM_TAG/d' /etc/nginx/nginx.conf
# Generate Nginx Stream server configuration. # Generate Nginx Stream server configuration.
if [ -n "${STSVR}" ]; then if [ -n "${STSVR}" ]; then
options=(`echo $STSVR |tr ',' ' '`) options=($(echo $STSVR |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
p|port) p|port)
STPORT="${kv[1]}" STPORT="${kv[1]}"
@@ -92,10 +92,10 @@ options=(`echo $STSVR |tr ',' ' '`)
cat ${STREAM_TPL} >> /etc/nginx/nginx.conf cat ${STREAM_TPL} >> /etc/nginx/nginx.conf
for stmap in "${STMAP[@]}" for stmap in "${STMAP[@]}"
do do
options=(`echo $stmap |tr ',' ' '`) options=($(echo $stmap |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
sni) sni)
sni="${kv[1]}" sni="${kv[1]}"
@@ -106,7 +106,7 @@ options=(`echo $STSVR |tr ',' ' '`)
esac esac
done done
# Naming the upstream as yahoo_com_jp for SNI yahoo.com.jp # Naming the upstream as yahoo_com_jp for SNI yahoo.com.jp
upsname=`echo $sni|sed 's/\./_/g'` upsname=$(echo $sni|sed 's/\./_/g')
echo " $sni $upsname;" >>/tmp/stmap.conf echo " $sni $upsname;" >>/tmp/stmap.conf
echo " upstream $upsname {" >>/tmp/stups.conf echo " upstream $upsname {" >>/tmp/stups.conf
echo " server $upstream;" >>/tmp/stups.conf echo " server $upstream;" >>/tmp/stups.conf
@@ -134,10 +134,10 @@ do
unset certhome NGPROTOCOL unset certhome NGPROTOCOL
# removing site default config file if any. # removing site default config file if any.
rm -rf /etc/nginx/conf.d/00_default_*.conf rm -rf /etc/nginx/conf.d/00_default_*.conf
options=(`echo $ngsvr |tr ',' ' '`) options=($(echo $ngsvr |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -200,10 +200,10 @@ done
for ngproxy in "${NGPROXY[@]}" for ngproxy in "${NGPROXY[@]}"
do do
unset XDOMAINS xhost xport xlocation xnetwork unset XDOMAINS xhost xport xlocation xnetwork
options=(`echo $ngproxy |tr ',' ' '`) options=($(echo $ngproxy |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
XDOMAINS+=("${kv[1]}") XDOMAINS+=("${kv[1]}")

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "TROJAN-TCP-TLS server builder" >&2 echo "TROJAN-TCP-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user|u=<uid>[:level:email]" >&2 echo "User format: user|u=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -69,7 +69,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -80,22 +80,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@ttt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c '.streamSettings += {"network":"tcp"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"network":"tcp"}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -106,8 +106,8 @@ do
if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi if [ -z "${fport}" ]; then >&2 echo "Incorrect fallback format: ${fallback}"; usage; exit 1; fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "TROJAN-WS-PLAIN server builder" >&2 echo "TROJAN-WS-PLAIN server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user=<uid>[:level:email]" >&2 echo "User format: user=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
d|domain) d|domain)
domain="${kv[1]}" domain="${kv[1]}"
@@ -58,7 +58,7 @@ 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 "Port number must be numeric"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -69,20 +69,20 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@twp.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"none"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"none"}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -96,89 +96,9 @@ do
fi fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound
exit 0 exit 0
}
options=(`echo $1 |tr ',' ' '`)
for option in "${options[@]}"
do
kv=(`echo $option |tr '=' ' '`)
case "${kv[0]}" in
d|domain)
domain="${kv[1]}"
;;
p|port)
port="${kv[1]}"
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
esac
done
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
usage
exit 1
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
XCONF=$xconf
# Remove existing port number if existing.
cat $XCONF |jq --arg port "${port}" 'del( .inbounds[] | select(.port == ($port|tonumber)) )' |sponge $XCONF
# Add inbound element
cat $XCONF |jq --arg port "${port}" '.inbounds +=[{"port":($port|tonumber),"protocol":"trojan","settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# User settings
for xu in "${xuser[@]}"
do
cat $XCONF | ${DIR}/addusertj.sh -p $port -u ${xu} -c twp.$domain $flowopt | sponge $XCONF
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg wspath "${wspath}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"ws","wsSettings":{"path":$wspath}} ' \
|sponge $XCONF
# Plain settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \
|sponge $XCONF

View File

@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
DIR=`dirname $0` DIR=$(dirname $0)
usage() { usage() {
>&2 echo "TROJAN-WS-TLS server builder" >&2 echo "TROJAN-WS-TLS server builder"
@@ -9,10 +9,10 @@ usage() {
>&2 echo "User format: user=<uid>[:level:email]" >&2 echo "User format: user=<uid>[:level:email]"
} }
options=(`echo $1 |tr ',' ' '`) options=($(echo $1 |tr ',' ' '))
for option in "${options[@]}" for option in "${options[@]}"
do do
kv=(`echo $option |tr '=' ' '`) kv=($(echo $option |tr '=' ' '))
case "${kv[0]}" in case "${kv[0]}" in
c|certhome) c|certhome)
certhome="${kv[1]}" certhome="${kv[1]}"
@@ -77,7 +77,7 @@ if [ ! -f "${prvkey}" ]; then >&2 echo "Warning, Private key not found: ${prvkey
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 "Port number must be numeric"; exit 1; fi
# inbound frame # inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}'` inbound=$(jq -nc --arg port "${port}" '{"port":($port|tonumber),"protocol":"trojan","settings":{"decryption":"none"}}')
# User settings # User settings
for user in "${xuser[@]}" for user in "${xuser[@]}"
@@ -88,22 +88,22 @@ do
if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi if [ -z "${uid}" ]; then >&2 echo "Incorrect user format: $user"; usage; exit 1; fi
if [ -z "${level}" ]; then level=0; fi if [ -z "${level}" ]; then level=0; fi
if [ -z "${email}" ]; then email="${uid}@twt.$domain"; 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}" \ inbound=$(echo $inbound| jq -c --arg uid "${uid}" --arg flow "${flow}" --arg level "${level}" --arg email "${email}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'` '.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]')
done done
# StreamSettings # StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}'` inbound=$(echo $inbound| jq -c '.streamSettings.sockopt += {"acceptProxyProtocol":true}')
fi fi
# Network settings # Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'` inbound=$(echo $inbound| jq -c --arg wspath "${wspath}" '.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}')
# Security settings # Security settings
inbound=`echo $inbound| jq -c '.streamSettings += {"security":"tls"}'` inbound=$(echo $inbound| jq -c '.streamSettings += {"security":"tls"}')
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \ inbound=$(echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'` '.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}')
# Fallback settings # Fallback settings
for fb in "${fallback[@]}" for fb in "${fallback[@]}"
@@ -117,8 +117,8 @@ do
fi fi
if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi if [ -z "${fhost}" ]; then fhost="127.0.0.1"; fi
fdest="$fhost:$fport" fdest="$fhost:$fport"
Jfb=`jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}'` Jfb=$(jq -nc --arg fdest "${fdest}" --arg fpath "${fpath}" '. |= {"dest":$fdest,"path":$fpath,"xver":1}')
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'` inbound=$(echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]')
done done
echo $inbound echo $inbound