|
|
@ -6,12 +6,22 @@ _jqArch="linux32" |
|
|
|
if [[ $sys_bit == "x86_64" ]]; then |
|
|
|
if [[ $sys_bit == "x86_64" ]]; then |
|
|
|
_jqArch="linux64" |
|
|
|
_jqArch="linux64" |
|
|
|
fi |
|
|
|
fi |
|
|
|
_jqbin=${__dir}/../bin/jq-${_jqArch} |
|
|
|
|
|
|
|
[[ -e $_jqbin && ! -x $_jqbin ]] && chmod 755 $_jqbin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ ! -x $_jqbin ]]; then |
|
|
|
if ! ( command -v jq 2>&1>/dev/null ) ; then |
|
|
|
_red "jq not found" |
|
|
|
_green "检测到没有 jq 命令,正在自动安装..." |
|
|
|
exit 1 |
|
|
|
|
|
|
|
|
|
|
|
if command -v apt-get 2>&1>/dev/null; then |
|
|
|
|
|
|
|
apt-get install -y jq |
|
|
|
|
|
|
|
elif command -v dnf 2>&1>/dev/null; then |
|
|
|
|
|
|
|
dnf install -y jq |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
pushd /tmp |
|
|
|
|
|
|
|
if curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${_jqArch}; then |
|
|
|
|
|
|
|
install -m 755 jq /usr/local/bin/ |
|
|
|
|
|
|
|
rm -f jq |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
popd |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then |
|
|
|
if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then |
|
|
@ -24,10 +34,6 @@ if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; the |
|
|
|
exit 1 |
|
|
|
exit 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
_jq () { |
|
|
|
|
|
|
|
$_jqbin "$@" < /dev/stdin |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TMP_ORIG_JSON=$(mktemp --suffix=.json) |
|
|
|
TMP_ORIG_JSON=$(mktemp --suffix=.json) |
|
|
|
TMP_UPDT_JSON=$(mktemp --suffix=.json) |
|
|
|
TMP_UPDT_JSON=$(mktemp --suffix=.json) |
|
|
|
CMPATCH=$(mktemp --suffix=.patch) |
|
|
|
CMPATCH=$(mktemp --suffix=.patch) |
|
|
@ -51,20 +57,20 @@ jq_vmess_adduser () { |
|
|
|
local email=${3:-${uuid:30}@233} |
|
|
|
local email=${3:-${uuid:30}@233} |
|
|
|
local level=1 |
|
|
|
local level=1 |
|
|
|
local client='{"id":"'${uuid}'","level":'${level}',"alterId":'${alterId}',"email":"'${email}'"}' |
|
|
|
local client='{"id":"'${uuid}'","level":'${level}',"alterId":'${alterId}',"email":"'${email}'"}' |
|
|
|
local len_inbounds=$(_jq '(.inbounds|length) - 1' $TMP_ORIG_JSON) |
|
|
|
local len_inbounds=$(jq '(.inbounds|length) - 1' $TMP_ORIG_JSON) |
|
|
|
local _IDX |
|
|
|
local _IDX |
|
|
|
for _IDX in $(seq 0 ${len_inbounds}); do |
|
|
|
for _IDX in $(seq 0 ${len_inbounds}); do |
|
|
|
if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then |
|
|
|
if [[ $(jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then |
|
|
|
break |
|
|
|
break |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) != '"vmess"' ]]; then |
|
|
|
if [[ $(jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) != '"vmess"' ]]; then |
|
|
|
_red "vmess not found" |
|
|
|
_red "vmess not found" |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
_jq --tab ".inbounds[${_IDX}].settings.clients += [${client}]" $TMP_ORIG_JSON > $TMP_UPDT_JSON |
|
|
|
jq --tab ".inbounds[${_IDX}].settings.clients += [${client}]" $TMP_ORIG_JSON > $TMP_UPDT_JSON |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
jq_patchback () { |
|
|
|
jq_patchback () { |
|
|
@ -80,15 +86,14 @@ jq_printvmess() { |
|
|
|
local INPUT=$TMP_ORIG_JSON |
|
|
|
local INPUT=$TMP_ORIG_JSON |
|
|
|
[[ -s $TMP_UPDT_JSON ]] && INPUT=$TMP_UPDT_JSON |
|
|
|
[[ -s $TMP_UPDT_JSON ]] && INPUT=$TMP_UPDT_JSON |
|
|
|
|
|
|
|
|
|
|
|
local INBS=$(_jq -c '.inbounds[] | select(.protocol == "vmess" )' $INPUT) |
|
|
|
local INBS=$(jq -c '.inbounds[] | select(.protocol == "vmess" )' $INPUT) |
|
|
|
for IN in $INBS; do |
|
|
|
for IN in $INBS; do |
|
|
|
# echo $IN | _jq |
|
|
|
|
|
|
|
local _TYPE="\"none\"" |
|
|
|
local _TYPE="\"none\"" |
|
|
|
local _HOST=\"\" |
|
|
|
local _HOST=\"\" |
|
|
|
local _PATH=\"\" |
|
|
|
local _PATH=\"\" |
|
|
|
local _TLS=\"\" |
|
|
|
local _TLS=\"\" |
|
|
|
local _NET=$(echo $IN | _jq '.streamSettings.network') |
|
|
|
local _NET=$(echo $IN | jq '.streamSettings.network') |
|
|
|
local _PORT=$(echo $IN | _jq '.port') |
|
|
|
local _PORT=$(echo $IN | jq '.port') |
|
|
|
local _NETTRIM=${_NET//\"/} |
|
|
|
local _NETTRIM=${_NET//\"/} |
|
|
|
echo |
|
|
|
echo |
|
|
|
echo "-------------------------- Server: ${ADDRESS}:${_PORT}/${_NETTRIM} --------------------------" |
|
|
|
echo "-------------------------- Server: ${ADDRESS}:${_PORT}/${_NETTRIM} --------------------------" |
|
|
@ -110,12 +115,12 @@ jq_printvmess() { |
|
|
|
_TYPE='if .streamSettings.tcpSettings.header.type then .streamSettings.tcpSettings.header.type else "none" end' |
|
|
|
_TYPE='if .streamSettings.tcpSettings.header.type then .streamSettings.tcpSettings.header.type else "none" end' |
|
|
|
;; |
|
|
|
;; |
|
|
|
esac |
|
|
|
esac |
|
|
|
local CLTLEN=$(echo $IN | _jq '.settings.clients|length - 1') |
|
|
|
local CLTLEN=$(echo $IN | jq '.settings.clients|length - 1') |
|
|
|
for CLINTIDX in $( seq 0 $CLTLEN ); do |
|
|
|
for CLINTIDX in $( seq 0 $CLTLEN ); do |
|
|
|
local EMAIL=$(echo $IN | _jq 'if .settings.clients['${CLINTIDX}'].email then .settings.clients['${CLINTIDX}'].email else "DEFAULT" end') |
|
|
|
local EMAIL=$(echo $IN | jq 'if .settings.clients['${CLINTIDX}'].email then .settings.clients['${CLINTIDX}'].email else "DEFAULT" end') |
|
|
|
local _ps="${_MAKPREFIX}${ADDRESS}/${_NETTRIM}" |
|
|
|
local _ps="${_MAKPREFIX}${ADDRESS}/${_NETTRIM}" |
|
|
|
_green "${EMAIL//\"/} -- ${_ps}" |
|
|
|
_green "${EMAIL//\"/} -- ${_ps}" |
|
|
|
echo "vmess://"$(echo $IN | _jq -c '{"v":"2","ps":"'${_ps}'","add":"'${ADDRESS}'","port":.port,"id":.settings.clients['${CLINTIDX}'].id,"aid":.settings.clients['${CLINTIDX}'].alterId,"net":.streamSettings.network,"type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0) |
|
|
|
echo "vmess://"$(echo $IN | jq -c '{"v":"2","ps":"'${_ps}'","add":"'${ADDRESS}'","port":.port,"id":.settings.clients['${CLINTIDX}'].id,"aid":.settings.clients['${CLINTIDX}'].alterId,"net":.streamSettings.network,"type":'${_TYPE}',"host":'${_HOST}',"path":'${_PATH}',"tls":'${_TLS}'}' | base64 -w0) |
|
|
|
echo |
|
|
|
echo |
|
|
|
done |
|
|
|
done |
|
|
|
done |
|
|
|
done |
|
|
|