diff --git a/bin/jq-linux32 b/bin/jq-linux32 new file mode 100755 index 0000000..42d47bf Binary files /dev/null and b/bin/jq-linux32 differ diff --git a/bin/jq-linux64 b/bin/jq-linux64 new file mode 100755 index 0000000..f48b0ca Binary files /dev/null and b/bin/jq-linux64 differ diff --git a/config/server/dynamic/http.json b/config/server/dynamic/http.json index 0965531..c722f4b 100644 --- a/config/server/dynamic/http.json +++ b/config/server/dynamic/http.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/dynamic/kcp.json b/config/server/dynamic/kcp.json index f2533c9..8a38823 100644 --- a/config/server/dynamic/kcp.json +++ b/config/server/dynamic/kcp.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/dynamic/quic.json b/config/server/dynamic/quic.json index 0f854ca..3ef33e2 100644 --- a/config/server/dynamic/quic.json +++ b/config/server/dynamic/quic.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/dynamic/tcp.json b/config/server/dynamic/tcp.json index fa6c603..46a9c83 100644 --- a/config/server/dynamic/tcp.json +++ b/config/server/dynamic/tcp.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/dynamic/ws.json b/config/server/dynamic/ws.json index 805ec2e..b809adb 100644 --- a/config/server/dynamic/ws.json +++ b/config/server/dynamic/ws.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/h2.json b/config/server/h2.json index 4ef95d0..f42112f 100644 --- a/config/server/h2.json +++ b/config/server/h2.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/http.json b/config/server/http.json index c1009b3..ea0dc8c 100644 --- a/config/server/http.json +++ b/config/server/http.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/kcp.json b/config/server/kcp.json index 6478c3d..a8efa30 100644 --- a/config/server/kcp.json +++ b/config/server/kcp.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/quic.json b/config/server/quic.json index 9e0e44c..9adcf64 100644 --- a/config/server/quic.json +++ b/config/server/quic.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/tcp.json b/config/server/tcp.json index c297a0a..a7d6186 100644 --- a/config/server/tcp.json +++ b/config/server/tcp.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/config/server/ws.json b/config/server/ws.json index e19e5dd..1cea0ff 100644 --- a/config/server/ws.json +++ b/config/server/ws.json @@ -46,6 +46,7 @@ "settings": { "clients": [ { + "email":"default@233.com", "id": "__VMUSERID__", "level": 1, "alterId": __VMALTID__ diff --git a/install.sh b/install.sh index e4b4212..8b48e3c 100644 --- a/install.sh +++ b/install.sh @@ -733,10 +733,10 @@ install_v2ray() { echo if [[ $cmd == "apt-get" ]]; then $cmd update -y - $cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin + $cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap2-bin patch else # $cmd install -y lrzsz git zip unzip curl wget qrencode libcap iptables-services - $cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap + $cmd install -y socat lrzsz git zip unzip curl wget qrencode libcap patch fi ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [ -d /etc/v2ray ] && rm -rf /etc/v2ray diff --git a/src/init.sh b/src/init.sh index 1261ba0..d961317 100644 --- a/src/init.sh +++ b/src/init.sh @@ -1,11 +1,17 @@ -_black() { echo -e "$(tput setaf 0)$*$(tput setaf 9)"; } -_red() { echo -e "$(tput setaf 1)$*$(tput setaf 9)"; } -_green() { echo -e "$(tput setaf 2)$*$(tput setaf 9)"; } -_yellow() { echo -e "$(tput setaf 3)$*$(tput setaf 9)"; } -_blue() { echo -e "$(tput setaf 4)$*$(tput setaf 9)"; } -_magenta() { echo -e "$(tput setaf 5)$*$(tput setaf 9)"; } -_cyan() { echo -e "$(tput setaf 6)$*$(tput setaf 9)"; } -_white() { echo -e "$(tput setaf 7)$*$(tput setaf 9)"; } + +red='\e[91m' +green='\e[92m' +yellow='\e[93m' +magenta='\e[95m' +cyan='\e[96m' +none='\e[0m' + +_red() { echo -e ${red}$*${none}; } +_green() { echo -e ${green}$*${none}; } +_yellow() { echo -e ${yellow}$*${none}; } +_magenta() { echo -e ${magenta}$*${none}; } +_cyan() { echo -e ${cyan}$*${none}; } + _addtocron () { local PROG="$1" diff --git a/src/jqcmd.sh b/src/jqcmd.sh new file mode 100644 index 0000000..1d0f823 --- /dev/null +++ b/src/jqcmd.sh @@ -0,0 +1,122 @@ +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__file="${__dir}/$(basename "${BASH_SOURCE[0]}")" +__base="$(basename ${__file} .sh)" + +_jqArch="linux32" +if [[ $sys_bit == "x86_64" ]]; then + _jqArch="linux64" +fi +_jqbin=${__dir}/../bin/jq-${_jqArch} +[[ -e $_jqbin && ! -x $_jqbin ]] && chmod 755 $_jqbin + +if [[ ! -x $_jqbin ]]; then + _red "jq not found" + exit 1 +fi + +if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then + _green "检测到没有patch命令,正在自动安装..." + $cmd install -y patch diff +fi + +if ! ( command -v patch 2>&1>/dev/null && command -v diff 2>&1>/dev/null) ; then + _red "diff/patch not found" + exit 1 +fi + +_jq () { + $_jqbin "$@" < /dev/stdin +} + +TMP_ORIG_JSON=$(mktemp --suffix=.json) +TMP_UPDT_JSON=$(mktemp --suffix=.json) +CMPATCH=$(mktemp --suffix=.patch) + +jq_gen_json() { + sed '/ *\/\//d' $v2ray_server_config > $TMP_ORIG_JSON +} + +jq_gen_jsonpatch() { + jq_gen_json + diff -u $TMP_ORIG_JSON $v2ray_server_config > $CMPATCH +} + +jq_clear_tmp() { + rm -f $TMP_ORIG_JSON $TMP_UPDT_JSON $CMPATCH +} + +jq_vmess_adduser () { + local uuid=$1 + local alterId=${2:-64} + local email=${3:-${uuid:30}@233} + local level=1 + local client='{"id":"'${uuid}'","level":'${level}',"alterId":'${alterId}',"email":"'${email}'"}' + local len_inbounds=$(_jq '(.inbounds|length) - 1' $TMP_ORIG_JSON) + local _IDX + for _IDX in $(seq 0 ${len_inbounds}); do + if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) == '"vmess"' ]]; then + break + fi + done + + if [[ $(_jq ".inbounds[${_IDX}].protocol" $TMP_ORIG_JSON) != '"vmess"' ]]; then + _red "vmess not found" + return 1 + fi + + _jq --tab ".inbounds[${_IDX}].settings.clients += [${client}]" $TMP_ORIG_JSON > $TMP_UPDT_JSON +} + +jq_patchback () { + if patch --ignore-whitespace $TMP_UPDT_JSON < $CMPATCH; then + mv $v2ray_server_config "${v2ray_server_config}.bak.${RANDOM}" + install -m 644 $TMP_UPDT_JSON $v2ray_server_config + fi +} + +jq_printvmess() { + local ADDRESS=${1:-SERVER_IP} + local _MAKPREFIX=${2:-233} + local INPUT=$TMP_ORIG_JSON + [[ -s $TMP_UPDT_JSON ]] && INPUT=$TMP_UPDT_JSON + + local INBS=$(_jq -c '.inbounds[] | select(.protocol == "vmess" )' $INPUT) + for IN in $INBS; do + # echo $IN | _jq + local _TYPE="\"none\"" + local _HOST=\"\" + local _PATH=\"\" + local _TLS=\"\" + local _NET=$(echo $IN | _jq '.streamSettings.network') + local _PORT=$(echo $IN | _jq '.port') + local _NETTRIM=${_NET//\"/} + echo + echo "-------------------------- Server: ${ADDRESS}:${_PORT}/${_NETTRIM} --------------------------" + echo + case $_NETTRIM in + kcp) + _TYPE='.streamSettings.kcpSettings.header.type' + ;; + ws) + _HOST='.streamSettings.wsSettings.headers.Host' + _PATH='.streamSettings.wsSettings.path' + ;; + h2|http) + _HOST='.streamSettings.httpSettings.host|join(,)' + _PATH='.streamSettings.httpSettings.path' + _TLS="tls" + ;; + tcp) + _TYPE='if .streamSettings.tcpSettings.header.type then .streamSettings.tcpSettings.header.type else "none" end' + ;; + esac + local CLTLEN=$(echo $IN | _jq '.settings.clients|length - 1') + 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 _ps="${_MAKPREFIX}${ADDRESS}/${_NETTRIM}" + _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 + done + done +} diff --git a/v2ray.sh b/v2ray.sh index 456adbc..de7db53 100644 --- a/v2ray.sh +++ b/v2ray.sh @@ -926,6 +926,7 @@ change_v2ray_config() { "修改 伪装的网址 (如果可以)" "关闭 网站伪装 和 路径分流 (如果可以)" "开启 / 关闭 广告拦截" + "增加 V2ray 用户" ) while :; do for ((i = 1; i <= ${#_menu[*]}; i++)); do @@ -979,6 +980,10 @@ change_v2ray_config() { blocked_hosts break ;; + 10) + change_vmess_user + break + ;; [aA][Ii][aA][Ii] | [Dd][Dd]) custom_uuid break @@ -994,6 +999,46 @@ change_v2ray_config() { fi done } + +change_vmess_user () { + echo + echo + + local uuid=$(cat /proc/sys/kernel/random/uuid) + local randomemail=${3:-${uuid:30}@233.com} + while :; do + echo -e "请输入 "$yellow"新用户AlterId$none (0~65535 整数)" + read -p "[默认:64]" new_alterId + [[ -z $new_alterId ]] && new_alterId=64 + if [[ $new_alterId =~ ^[0-9]+$ ]]; then + break; + else + _red "$new_alterId 是啥???" + fi + done + + echo -e "请输入 "$yellow"新用户 Email"$none"(任意字符,仅作统计识别)" + read -p "[默认:${randomemail}]" new_email + [[ -z $new_email ]] && new_email=$randomemail + + echo + echo + _load jqcmd.sh + jq_gen_jsonpatch + jq_vmess_adduser $uuid $new_alterId $new_email + jq_printvmess $ip "[233]" + [[ $v6ip ]] && jq_printvmess $v6ip "[233]" + jq_patchback + jq_clear_tmp + echo + echo + _yellow " ---- 搞定了。" + _yellow " ---- 翻查多用户的vmess link请用v2ray url查看。" + echo + echo + +} + change_v2ray_port() { if [[ $v2ray_transport == 4 ]]; then echo @@ -2587,6 +2632,16 @@ get_v2ray_config_qr_link() { rm -rf /etc/v2ray/vmess.txt } get_v2ray_vmess_URL_link() { + + echo "---------- V2Ray vmess URL / V2RayNG v0.4.1+ / V2RayN v2.1+ / 仅适合部分客户端 -------------" + get_ip + _load jqcmd.sh + jq_gen_json + jq_printvmess $ip "[233]" + [[ $v6ip ]] && jq_printvmess $v6ip "[233]" + + return + create_vmess_URL_config local vmess="vmess://$(cat /etc/v2ray/vmess_qr.json | base64 -w 0)" echo @@ -2879,6 +2934,7 @@ menu() { case $choose in 1) view_v2ray_config_info + _yellow " ---- 翻查多用户的vmess link请用v2ray url查看。" break ;; 2) @@ -2942,6 +2998,8 @@ menu) ;; i | info) view_v2ray_config_info + _yellow " ---- 翻查多用户的vmess link请用v2ray url查看。" + echo ;; c | config) change_v2ray_config