Merge pull request #145 from cutelua/adduser

jq add user
pull/156/head
233boy 6 years ago committed by GitHub
commit 6546ee790b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      bin/jq-linux32
  2. BIN
      bin/jq-linux64
  3. 1
      config/server/dynamic/http.json
  4. 1
      config/server/dynamic/kcp.json
  5. 1
      config/server/dynamic/quic.json
  6. 1
      config/server/dynamic/tcp.json
  7. 1
      config/server/dynamic/ws.json
  8. 1
      config/server/h2.json
  9. 1
      config/server/http.json
  10. 1
      config/server/kcp.json
  11. 1
      config/server/quic.json
  12. 1
      config/server/tcp.json
  13. 1
      config/server/ws.json
  14. 4
      install.sh
  15. 22
      src/init.sh
  16. 122
      src/jqcmd.sh
  17. 58
      v2ray.sh

Binary file not shown.

Binary file not shown.

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -46,6 +46,7 @@
"settings": {
"clients": [
{
"email":"default@233.com",
"id": "__VMUSERID__",
"level": 1,
"alterId": __VMALTID__

@ -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

@ -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"

@ -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
}

@ -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

Loading…
Cancel
Save