Rewrite with json stdout

This commit is contained in:
Samuel Huang
2024-09-24 11:32:50 +10:00
parent 839488436c
commit 5562f3c0ce
18 changed files with 965 additions and 887 deletions

View File

@@ -56,9 +56,6 @@ ADD server-ttt.sh /server-ttt.sh
ADD server-twt.sh /server-twt.sh
ADD server-nginx.sh /server-nginx.sh
ADD fallback.sh /fallback.sh
ADD addusertj.sh /addusertj.sh
ADD adduser.sh /adduser.sh
ADD run.sh /run.sh

85
run.sh
View File

@@ -2,7 +2,7 @@
DIR=`dirname $0`
DIR="$(cd $DIR; pwd)"
CERTHOME="/root/.acme.sh"
CERTHOME="/opt/cert"
XCONF=/tmp/server-xray.json
usage() {
@@ -36,7 +36,7 @@ usage() {
echo " -r|--request-domain <domain-name> Domain name to request for letsencrypt cert"
echo " -c|--cert-home <cert-home-dir> Reading TLS certs from folder <cert-home-dir>/<domain-name>/"
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"
}
@@ -61,7 +61,8 @@ while true ; do
shift 2
;;
-i|--stdin)
STDINCONF=1
# Read Xray config from STDIN. Run Xray only.
exec /usr/local/bin/xray
shift 1
;;
-d|--debug)
@@ -77,33 +78,34 @@ while true ; do
shift 2
;;
--lgp|--lgr|--lgt|--lsp|--lst|--ltr|--ltt|--lwp|--lwt|--mtt|--mwp|--mwt|--ttt|--twp|--twt)
# Alias options
SVC=`echo $1|tr -d '\-\-'`
SVCMD+=("${DIR}/server-${SVC}.sh $2")
shift 2
;;
# Alias options
--ltrx|--lttx)
# Alias options
SVC=`echo $1|tr -d '\-\-'|tr -d x`
SVCMD+=("${DIR}/server-${SVC}.sh $2,xtls")
shift 2
;;
--domain-block)
Jrules=`echo "${Jrules}" | jq --arg blkdomain "$2" \
'.rules += [{"type":"field", "outboundTag":"blocked", "domain":[$blkdomain]}]'`
'.rules += [{"type":"field","outboundTag":"blocked","domain":[$blkdomain]}]'`
shift 2
;;
--ip-block)
Jrules=`echo "${Jrules}" | jq --arg blkip "$2" \
'.rules += [{"type":"field", "outboundTag":"blocked", "ip":[$blkip]}]'`
'.rules += [{"type":"field","outboundTag":"blocked","ip":[$blkip]}]'`
shift 2
;;
--cn-block)
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" \
'.rules += [{"type":"field", "outboundTag":"blocked", "domain":[$igndomain]}]'`
'.rules += [{"type":"field","outboundTag":"blocked","domain":[$igndomain]}]'`
Jrules=`echo "${Jrules}" | jq --arg ignip "geoip:cn" \
'.rules += [{"type":"field", "outboundTag":"blocked", "ip":[$ignip]}]'`
'.rules += [{"type":"field","outboundTag":"blocked","ip":[$ignip]}]'`
shift 1
;;
--ng-server)
@@ -165,29 +167,12 @@ if [ -n "${CERTDOMAIN}" ]; then
done
fi
echo '{"log":{"loglevel":"warning"},"inbounds":[],"outbounds":[{"tag":"direct","protocol":"freedom"},{"tag":"blocked","protocol":"blackhole"}]}' |jq .|sponge $XCONF
xopt="xconf=$XCONF"
xopt="$xopt,certhome=$CERTHOME"
for uopt in "${UOPT[@]}"
do
xopt="$xopt,$uopt"
done
# Add routing config
Jrouting='{"routing": {"domainStrategy":"AsIs"}}'
Jrouting=`echo "${Jrouting}" |jq --argjson jrules "${Jrules}" '.routing += $jrules'`
cat $XCONF| jq --argjson jrouting "${Jrouting}" '. += $jrouting' | sponge $XCONF
# Run Xray only. Read Xray config from STDIN
if [ "${STDINCONF}" = "1" ]; then
exec /usr/local/bin/xray
fi
xopt="certhome=$CERTHOME"
for uopt in "${UOPT[@]}"; do xopt="$xopt,$uopt"; done
if [ -z "${SVCMD}" ]; then
echo "No Xray service creation found. Quit."
usage;
exit 1
echo -e "No Xray service creation found. Quit.\n"
usage; exit 1
fi
# Start Nginx if necessary
@@ -214,46 +199,48 @@ if [ -n "${NGOPT}" ]; then
ngcmd="${DIR}/server-nginx.sh $NGOPT"
$ngcmd
ret=$?; if [ $ret != 0 ]; then
echo ""
echo "Nginx config generation failed from the following cmd:\n$ngcmd";
echo "Please check log for details"
echo -e "\nNginx config generation failed from the following cmd:\n$ngcmd";
echo -e "Please check log for details.\n"
exit $ret;
fi
killall nginx
nginx;
fi
# Add root config
Jroot='{"outbounds":[{"tag":"direct","protocol":"freedom"},{"tag":"blocked","protocol":"blackhole"}]}'
# Add routing config
Jrouting='{"routing":{"domainStrategy":"AsIs"}}'
Jrouting=`echo $Jrouting |jq --argjson jrules "${Jrules}" '.routing += $jrules'`
Jroot=`echo $Jroot| jq --argjson jrouting "${Jrouting}" '. += $jrouting'`
# Xray service config generation
for svcmd in "${SVCMD[@]}"
do
svcmd="$svcmd,$xopt"
$svcmd
Jsvc=`$svcmd,$xopt`
if [[ $? -ne 0 ]]; then
echo
echo "Service creation command failed: $svcmd"
echo "Service creation command failed: $svcmd,$xopt"
exit 1
fi
Jroot=`echo $Jroot| jq --argjson Jsvc "${Jsvc}" '.inbounds += [$Jsvc]'`
done
if [ "${DEBUG}" = "1" ]; then
cat $XCONF |jq '.log.loglevel |="debug"' |sponge $XCONF
echo
fi
if [ -n "${DEBUG}" ]; then loglevel="debug"; else loglevel="warning"; fi
Jroot=`echo $Jroot| jq --arg loglevel "${loglevel}" '.log.loglevel |= $loglevel'`
if [ -n "${INJECT}" ]; then
for JSON_IN in "${INJECT[@]}"
do
echo "${JSON_IN}"|jq -ec >/tmp/merge.json
if [[ $? -ne 0 ]]; then
echo "Invalid json ${JSON_IN}"
exit 1
fi
jq -s '.[0] * .[1]' $XCONF /tmp/merge.json |sponge $XCONF
Jmerge=`jq -nc "${JSON_IN}"`
if [[ $? -ne 0 ]]; then echo "Invalid json ${JSON_IN}"; exit 1; fi
Jroot=`jq -n --argjson Jroot "${Jroot}" --argjson Jmerge "${Jmerge}" '$Jroot + $Jmerge'`
done
fi
cat $XCONF
echo
jq -n "$Jroot"
jq -n "$Jroot">$XCONF
exec /usr/local/bin/xray -c $XCONF
fi

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-GRPC-PLAIN server builder"
echo "Usage: server-lgp <x=xray-config-file>,<p=listen-port>,<s=svcname>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-GRPC-PLAIN server builder"
>&2 echo "Usage: server-lgp <s=svcname>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -15,67 +17,85 @@ do
d|domain)
domain="${kv[1]}"
;;
f|fallback)
fallback+=("${kv[1]}")
;;
p|port)
port="${kv[1]}"
;;
s|service)
service="${kv[1]}"
proxy_acpt)
acceptProxyProtocol=true
;;
s|serviceName)
serviceName="${kv[1]}"
;;
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
esac
done
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
if [ -z "${domain}" ]; then
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${service}" ]; then
echo "Error: service undefined."
usage
exit 1
if [ -z "${port}" ]; then
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${serviceName}" ]; then
>&2 echo -e "Error: serviceName undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
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 -e "Error: Port number must be numeric.\n"; 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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lgp.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg service "${service}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"grpc","grpcSettings":{"serviceName":$service} } ' \
|sponge $XCONF
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Plain settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \
|sponge $XCONF
# Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.settings.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"none"}'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-GRPC-REALITY server builder"
echo "Usage: server-lgr <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<s=svcname>,[xtls],<d=dest.com>,[pub=xx,prv=yy,shortId=zz],<u=id0>,<u=id1>..."
>&2 echo "VLESS-GRPC-REALITY server builder"
>&2 echo "Usage: server-lgr ,<s=svcname>,<d=dest.com>,<prv=yy>,[pub=xx],[shortId=zz],<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -12,9 +14,6 @@ for option in "${options[@]}"
do
kv=(`echo $option |tr '=' ' '`)
case "${kv[0]}" in
c|certhome)
certhome="${kv[1]}"
;;
d|dest)
dest="${kv[1]}"
;;
@@ -27,10 +26,16 @@ do
p|port)
port="${kv[1]}"
;;
s|service)
service="${kv[1]}"
proxy_acpt)
acceptProxyProtocol=true
;;
shortId)
svnm|serverName)
serverNames+=("${kv[1]}")
;;
s|serviceName)
serviceName="${kv[1]}"
;;
sid|shortId)
shortIds+=("${kv[1]}")
;;
prv|privateKey)
@@ -42,9 +47,6 @@ do
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -52,83 +54,88 @@ do
done
if [ -z "${dest}" ]; then
echo "Error: dest undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Fake Destination undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
fi
if [ -z "${service}" ]; then
echo "Error: service 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
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${prvkey}" ]; then
echo "Warning: PrivateKey undefined, Generated new..."
>&2 echo "Warning: PrivateKey undefined, Generated new..."
kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`)
prvkey="${kv[0]}"
pubkey="${kv[1]}"
echo "PublicKey: $pubkey"
>&2 echo "PublicKey: $pubkey"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
if [ -z "${serviceName}" ]; then
>&2 echo -e "Error: serviceName undefined.\n"
usage; 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
if [ -z "${xuser}" ]; then
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
# Add inbound element
cat $XCONF |jq --arg port "${port}" '.inbounds +=[{"port":($port|tonumber), "protocol":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lgr.$dest $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.settings.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"reality"}'`
# Reality settings
inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'`
# serverNames settings
if [ -n "${serverNames}" ]; then
JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc`
inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.settings.streamSettings.realitySettings.serverNames += $JserverNames'`
fi
# shortIds settings
JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc`
inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.settings.streamSettings.realitySettings.shortIds += $JshortIds'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg service "${service}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"grpc","grpcSettings":{"serviceName":$service} } ' \
|sponge $XCONF
# Reality settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"reality"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"realitySettings":{"show":true,"dest":"\($dest):443","serverNames":[$dest,""],"privateKey":$prvkey,"publicKey":$pubkey,"shortIds":[""]} } ' \
|sponge $XCONF
cat $XCONF |jq '( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.realitySettings.shortIds ) +=$ARGS.positional' \
--arg port "${port}" --args ${shortIds[@]} \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-GRPC-TLS server builder"
echo "Usage: server-lgt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<s=svcname>,[xtls],<d=domain.com>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-GRPC-TLS server builder"
>&2 echo "Usage: server-lgt <s=svcname>,<c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,15 +29,15 @@ do
p|port)
port="${kv[1]}"
;;
s|service)
service="${kv[1]}"
proxy_acpt)
acceptProxyProtocol=true
;;
s|serviceName)
serviceName="${kv[1]}"
;;
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,92 +45,78 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${service}" ]; then
echo "Error: service undefined."
usage
exit 1
if [ -z "${serviceName}" ]; then
>&2 echo -e "Error: serviceName undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lgt.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg serviceName "${serviceName}" '.settings.streamSettings += {"network":"grpc","grpcSettings":{"serviceName":$serviceName}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg service "${service}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"grpc","grpcSettings":{"serviceName":$service} } ' \
|sponge $XCONF
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-SPLT-PLAIN server builder"
echo "Usage: server-lsp <x=xray-config-file>,<p=listen-port>,<w=webpath>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-SPLT-PLAIN server builder"
>&2 echo "Usage: server-lsp <w=webpath>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -15,67 +17,85 @@ do
d|domain)
domain="${kv[1]}"
;;
f|fallback)
fallback+=("${kv[1]}")
;;
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
webpath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
esac
done
if [ -z "${domain}" ]; then
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${webpath}" ]; then
echo "Error: webpath undefined."
usage
exit 1
>&2 echo -e "Error: webpath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
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 -e "Error: Port number must be numeric.\n"; 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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lsp.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg webpath "${webpath}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"splithttp","splithttpSettings":{"path":$webpath}} ' \
|sponge $XCONF
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Plain settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \
|sponge $XCONF
# Network settings
inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.settings.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"none"}'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-SPLT-TLS server builder"
echo "Usage: server-lst <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<w=webpath>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-SPLT-TLS server builder"
>&2 echo "Usage: server-lst <w=webpath>,<c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,15 +29,15 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
webpath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,92 +45,78 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${webpath}" ]; then
echo "Error: webpath undefined."
usage
exit 1
>&2 echo -e "Error: webpath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lst.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg webpath "${webpath}" '.settings.streamSettings += {"network":"splithttp","splithttpSettings":{"path":$webpath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" --arg webpath "${webpath}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"splithttp","splithttpSettings":{"path":$webpath}} ' \
|sponge $XCONF
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-TCP-REALITY server builder"
echo "Usage: server-ltr <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,[xtls],[proxy_acpt],<d=dest.com>,[pub=xx,prv=yy,shortId=zz],<u=id0>,<u=id1>..."
>&2 echo "VLESS-TCP-REALITY server builder"
>&2 echo "Usage: server-ltr <d=dest.com>,<prv=yy>,[pub=xx],[shortId=zz],<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -12,9 +14,6 @@ for option in "${options[@]}"
do
kv=(`echo $option |tr '=' ' '`)
case "${kv[0]}" in
c|certhome)
certhome="${kv[1]}"
;;
d|dest)
dest="${kv[1]}"
;;
@@ -30,7 +29,10 @@ do
proxy_acpt)
acceptProxyProtocol=true
;;
shortId)
svnm|serverName)
serverNames+=("${kv[1]}")
;;
sid|shortId)
shortIds+=("${kv[1]}")
;;
prv|privateKey)
@@ -42,9 +44,6 @@ do
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -52,84 +51,83 @@ do
done
if [ -z "${dest}" ]; then
echo "Error: dest undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Fake Destination undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port 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
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${prvkey}" ]; then
echo "Warning: PrivateKey undefined, Generated new..."
>&2 echo "Warning: PrivateKey undefined, Generated new..."
kv=(`/usr/local/bin/xray x25519|cut -d ' ' -f3|tr ' '`)
prvkey="${kv[0]}"
pubkey="${kv[1]}"
echo "PublicKey: $pubkey"
>&2 echo "PublicKey: $pubkey"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
if [ -z "${xuser}" ]; then
>&2 echo -e "Error: User undefined.\n"
usage; 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
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
# Add inbound element
cat $XCONF |jq --arg port "${port}" '.inbounds +=[{"port":($port|tonumber), "protocol":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c ltr.$dest $flowopt | sponge $XCONF
done
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"sockopt":{"acceptProxyProtocol":true}} ' \
|sponge $XCONF
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"tcp"} ' \
|sponge $XCONF
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"network":"tcp"}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"reality"}'`
# Reality settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"reality"} ' \
|sponge $XCONF
inbound=`echo $inbound| jq -c --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.realitySettings += {"show":true,"dest":"\($dest):443","serverNames":[$dest],"privateKey":$prvkey,"publicKey":$pubkey}'`
cat $XCONF |jq --arg port "${port}" --arg dest "${dest}" --arg pubkey "${pubkey}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"realitySettings":{"show":true,"dest":"\($dest):443","serverNames":[$dest,""],"privateKey":$prvkey,"publicKey":$pubkey,"shortIds":[""]} } ' \
|sponge $XCONF
# serverNames settings
if [ -n "${serverNames}" ]; then
JserverNames=`printf '%s\n' "${serverNames[@]}"|jq -R|jq -sc`
inbound=`echo $inbound| jq -c --argjson JserverNames "${JserverNames}" '.settings.streamSettings.realitySettings.serverNames += $JserverNames'`
fi
cat $XCONF |jq '( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.realitySettings.shortIds ) +=$ARGS.positional' \
--arg port "${port}" --args ${shortIds[@]} \
|sponge $XCONF
# shortIds settings
JshortIds=`printf '%s\n' "${shortIds[@]}"|jq -R|jq -sc`
inbound=`echo $inbound| jq -c --argjson JshortIds "${JshortIds}" '.settings.streamSettings.realitySettings.shortIds += $JshortIds'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-TCP-TLS server builder"
echo "Usage: server-ltt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,[xtls],[proxy_acpt],<d=domain.com>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-TCP-TLS server builder"
>&2 echo "Usage: server-ltt <c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -33,9 +35,6 @@ do
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,93 +42,73 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c ltt.$dest $flowopt | sponge $XCONF
done
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"sockopt":{"acceptProxyProtocol":true}} ' \
|sponge $XCONF
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"tcp"} ' \
|sponge $XCONF
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"network":"tcp"}'`
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-WS-PLAIN server builder"
echo "Usage: server-lwp <x=xray-config-file>,<p=listen-port>,<w=wskpath>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-WS-PLAIN server builder"
>&2 echo "Usage: server-lwp <w=wskpath>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -15,67 +17,85 @@ do
d|domain)
domain="${kv[1]}"
;;
f|fallback)
fallback+=("${kv[1]}")
;;
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
esac
done
if [ -z "${domain}" ]; then
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
>&2 echo -e "Error: wspath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
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 -e "Error: Port number must be numeric.\n"; 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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lwp.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
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
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Plain settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \
|sponge $XCONF
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"none"}'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VLESS-WS-TLS server builder"
echo "Usage: server-lwt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<w=wskpath>,<u=id0>,<u=id1>..."
>&2 echo "VLESS-WS-TLS server builder"
>&2 echo "Usage: server-lwt <w=wskpath>,<c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,15 +29,15 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,92 +45,78 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
>&2 echo -e "Error: wspath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vless", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vless","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c lwt.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
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
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VMESS-TCP-TLS server builder"
echo "Usage: server-mtt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<u=id0>,<u=id1>..."
>&2 echo "VMESS-TCP-TLS server builder"
>&2 echo "Usage: server-mtt <c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,12 +29,12 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -40,86 +42,73 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vmess", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vmess","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c mtt.$dest $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"network":"tcp"}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"tcp"} ' \
|sponge $XCONF
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VMESS-WS-PLAIN server builder"
echo "Usage: server-mwp <x=xray-config-file>,<p=listen-port>,<w=wskpath>,<u=id0>,<u=id1>..."
>&2 echo "VMESS-WS-PLAIN server builder"
>&2 echo "Usage: server-mwp <w=wskpath>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -15,67 +17,88 @@ do
d|domain)
domain="${kv[1]}"
;;
f|fallback)
fallback+=("${kv[1]}")
;;
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
esac
done
if [ -z "${domain}" ]; then
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
>&2 echo -e "Error: wspath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
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.\n"; 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":"vmess", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vmess","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c mwp.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
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
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Plain settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"none" } ' \
|sponge $XCONF
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"none"}'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "VMESS-WS-TLS server builder"
echo "Usage: server-mwt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<w=wskpath>,<u=id0>,<u=id1>..."
>&2 echo "VMESS-WS-TLS server builder"
>&2 echo "Usage: server-mwt <w=wskpath>,<c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,15 +29,15 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,92 +45,81 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
>&2 echo -e "Error: wspath undefined.\n"
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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":"vmess", "settings":{"clients":[]}}]' |sponge $XCONF
cat $XCONF |jq --arg port "${port}" '( .inbounds[] | select(.port == ($port|tonumber)) | .settings.decryption ) += "none" ' |sponge $XCONF
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"vmess","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/adduser.sh -p $port -u ${xu} -c mwt.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"id":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
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
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -20,23 +20,23 @@ if [ $? != 0 ] ; then usage; exit 1 ; fi
eval set -- "$TEMP"
while true ; do
case "$1" in
# Multiple Nginx domain servers Allowed
-n|--ng-server)
# Multiple Nginx domain servers Allowed
NGSVR+=("$2")
shift 2
;;
# Multiple Nginx proxy locations Allowed
-x|--ng-proxy)
# Multiple Nginx proxy locations Allowed
NGPROXY+=("$2")
shift 2
;;
# Only SINGLE Stream server Allowed
-s|--st-server)
# Only SINGLE Stream server Allowed
STSVR="$2"
shift 2
;;
# Multiple Nginx SNI map items Allowed
-m|--st-map)
# Multiple Nginx SNI map items Allowed
STMAP+=("$2")
shift 2
;;

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "TROJAN-TCP-TLS server builder"
echo "Usage: server-ttt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<u=pw0>,<u=pw1>..."
>&2 echo "TROJAN-TCP-TLS server builder"
>&2 echo "Usage: server-ttt <c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,12 +29,12 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -40,86 +42,73 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo -e "Error: Certhome undefined.\n"
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo -e "Error: Domain undefined.\n"
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo -e "Error: Port undefined.\n"
usage; exit 1 ;
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo -e "Error: User undefined.\n"
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
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 "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo -e "Error: Port number must be numeric.\n"; exit 1; fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"trojan","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/addusertj.sh -p $port -u ${xu} -c ttt.$dest $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"network":"tcp"}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
# Network settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"network":"tcp"} ' \
|sponge $XCONF
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0

View File

@@ -3,8 +3,111 @@
DIR=`dirname $0`
usage() {
echo "TROJAN-WS-PLAIN server builder"
echo "Usage: server-twp <x=xray-config-file>,<p=listen-port>,<w=wskpath>,<u=pw0>,<u=pw1>..."
>&2 echo "TROJAN-WS-PLAIN server builder"
>&2 echo "Usage: server-twp <w=wskpath>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
for option in "${options[@]}"
do
kv=(`echo $option |tr '=' ' '`)
case "${kv[0]}" in
d|domain)
domain="${kv[1]}"
;;
f|fallback)
fallback+=("${kv[1]}")
;;
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
esac
done
if [ -z "${domain}" ]; then
>&2 echo "Error: Domain undefined."
usage; exit 1
fi
if [ -z "${port}" ]; then
>&2 echo "Error: Port undefined."
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
>&2 echo "Error: wspath undefined."
usage; exit 1
fi
if [ -z "${xuser}" ]; then
>&2 echo "Error: User undefined."
usage; exit 1
fi
if ! [ "${port}" -eq "${port}" ] 2>/dev/null; then >&2 echo "Port number must be numeric"; exit 1; fi
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"trojan","settings":{"decryption":"none"}}'`
# User settings
for user in "${xuser[@]}"
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 "${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}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"none"}'`
# Fallback settings
for fb in "${fallback[@]}"
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
done
echo $inbound
exit 0
}
options=(`echo $1 |tr ',' ' '`)
@@ -61,7 +164,7 @@ XCONF=$xconf
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 +=[{"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

View File

@@ -3,8 +3,10 @@
DIR=`dirname $0`
usage() {
echo "TROJAN-WS-TLS server builder"
echo "Usage: server-twt <x=xray-config-file>,<c=cert-home-dir>,<p=listen-port>,<d=domain.com>,<w=wskpath>,<u=pw0>,<u=pw1>..."
>&2 echo "TROJAN-WS-TLS server builder"
>&2 echo "Usage: server-twt <w=wskpath>,<c=certhome-dir>,<d=domain.com>,<p=listen-port>,<u=id0>,<u=id1>...,[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=<uid>[:level:email]"
}
options=(`echo $1 |tr ',' ' '`)
@@ -27,15 +29,15 @@ do
p|port)
port="${kv[1]}"
;;
proxy_acpt)
acceptProxyProtocol=true
;;
u|user)
xuser+=("${kv[1]}")
;;
w|wpath)
wspath="${kv[1]}"
;;
x|xconf)
xconf="${kv[1]}"
;;
xtls)
flow="xtls-rprx-vision"
;;
@@ -43,92 +45,81 @@ do
done
if [ -z "${certhome}" ]; then
echo "Error: certhome undefined."
usage
exit 1
>&2 echo "Error: Certhome undefined."
usage; exit 1
fi
if [ -z "${domain}" ]; then
echo "Error: domain undefined."
usage
exit 1
fi
if [ -n "${flow}" ]; then
flowopt="-f ${flow}"
>&2 echo "Error: Domain undefined."
usage; exit 1
fi
if [ -z "${port}" ]; then
echo "Error: port undefined."
usage
exit 1 ;
>&2 echo "Error: Port undefined."
usage; exit 1 ;
fi
if [ -z "${wspath}" ]; then
echo "Error: wspath undefined."
usage
exit 1
>&2 echo "Error: wspath undefined."
usage; exit 1
fi
if [ -z "${xuser}" ]; then
echo "Error: user undefined."
usage
exit 1
>&2 echo "Error: User undefined."
usage; exit 1
fi
if [ -z "${xconf}" ]; then
echo "Error: xconf undefined."
usage
exit 1
fi
if [ -f "${certhome}/${domain}/fullchain.cer" ] && [ -f "${certhome}/${domain}/${domain}.key" ]; then
fullchain="${certhome}/${domain}/fullchain.cer"
prvkey="${certhome}/${domain}/${domain}.key"
fi
if [ ! -f "${fullchain}" ] || [ ! -f "${prvkey}" ]; then
echo "TLS cert missing?"
echo "Abort."
exit 2
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 ! [ "${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
# inbound frame
inbound=`jq -nc --arg port "${port}" '{"port":$port,"protocol":"trojan","settings":{"decryption":"none"}}'`
# User settings
for xu in "${xuser[@]}"
for user in "${xuser[@]}"
do
cat $XCONF | ${DIR}/addusertj.sh -p $port -u ${xu} -c twt.$domain $flowopt | sponge $XCONF
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 "${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}" \
'.settings.clients += [{"password":$uid,"level":($level|tonumber),"email":$email,"flow":$flow}]'`
done
# StreamSettings
if [ -n "${acceptProxyProtocol}" ]; then
inbound=`echo $inbound| jq -c '.settings.streamSettings.sockopt += {"acceptProxyProtocol":true}'`
fi
# Network settings
inbound=`echo $inbound| jq -c --arg wspath "${wspath}" '.settings.streamSettings += {"network":"ws","wsSettings":{"path":$wspath}}'`
# Security settings
inbound=`echo $inbound| jq -c '.settings.streamSettings += {"security":"tls"}'`
inbound=`echo $inbound| jq -c --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'.settings.streamSettings.tlsSettings += {"certificates":[{"certificateFile":$fullchain,"keyFile":$prvkey}]}'`
# Fallback settings
for fb in "${fallback[@]}"
do
cat $XCONF |${DIR}/fallback.sh -p $port -f ${fb} | sponge $XCONF
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 "${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}'`
inbound=`echo $inbound| jq -c --argjson Jfb "${Jfb}" '.settings.fallbacks += [$Jfb]'`
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
# TLS settings
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"security":"tls"} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings ) += {"tlsSettings":{}} ' \
|sponge $XCONF
cat $XCONF |jq --arg port "${port}" --arg fullchain "${fullchain}" --arg prvkey "${prvkey}" \
'( .inbounds[] | select(.port == ($port|tonumber)) | .streamSettings.tlsSettings ) += {"certificates":[{"certificateFile":$fullchain, "keyFile":$prvkey}]} ' \
|sponge $XCONF
echo $inbound
exit 0