feat(脚本): 重构配置文件管理为接下来的多用户管理、ipv6人机验证做准备、重构账号查看

pull/534/merge
mack-a 2020-12-18 10:52:52 +08:00
parent 398d9f92b9
commit 927d8e491e
1 changed files with 192 additions and 568 deletions

View File

@ -1240,11 +1240,7 @@ installV2RayService(){
then then
rm -rf /etc/systemd/system/v2ray.service rm -rf /etc/systemd/system/v2ray.service
touch /etc/systemd/system/v2ray.service touch /etc/systemd/system/v2ray.service
execStart='/etc/v2ray-agent/v2ray/v2ray -config /etc/v2ray-agent/v2ray/config_full.json' execStart='/etc/v2ray-agent/v2ray/v2ray -confdir /etc/v2ray-agent/v2ray/conf'
if [[ ! -z ${selectCustomInstallType} ]]
then
execStart='/etc/v2ray-agent/v2ray/v2ray -confdir /etc/v2ray-agent/v2ray/conf'
fi
cat << EOF > /etc/systemd/system/v2ray.service cat << EOF > /etc/systemd/system/v2ray.service
[Unit] [Unit]
Description=V2Ray - A unified platform for anti-censorship Description=V2Ray - A unified platform for anti-censorship
@ -1472,18 +1468,16 @@ handleTrojanGo(){
# 初始化V2Ray 配置文件 # 初始化V2Ray 配置文件
initV2RayConfig(){ initV2RayConfig(){
echoContent skyBlue "\n进度 $2/${totalProgress} : 初始化V2Ray配置" echoContent skyBlue "\n进度 $2/${totalProgress} : 初始化V2Ray配置"
if [[ ! -z "${aaaaaaaaa}" ]] if [[ ! -z "${currentUUID}" ]]
then then
echo echo
read -p "读取到上次安装记录是否使用上次安装时的UUID [y/n]:" historyUUIDStatus read -p "读取到上次安装记录是否使用上次安装时的UUID [y/n]:" historyUUIDStatus
if [[ "${historyUUIDStatus}" = "y" ]] if [[ "${historyUUIDStatus}" = "y" ]]
then then
uuid=${aaaaaaaaa}
uuid=${currentUUID} uuid=${currentUUID}
fi fi
else else
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid` uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
fi fi
if [[ -z "${uuid}" ]] if [[ -z "${uuid}" ]]
then then
@ -1491,387 +1485,37 @@ initV2RayConfig(){
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid` uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
fi fi
if [[ -z "${uuid}" ]] && [[ "${selectCoreType}" = "3" ]]
then
echoContent red "\n ---> uuid XTLS-direct/XTLS-splice读取错误重新生成"
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
fi
if [[ "${uuid}" = "${uuid}" ]]
then
echoContent red "\n ---> uuid重复重新生成"
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
uuid=`/etc/v2ray-agent/v2ray/v2ctl uuid`
fi
echoContent green "\n ---> 使用成功"
rm -rf /etc/v2ray-agent/v2ray/conf/* rm -rf /etc/v2ray-agent/v2ray/conf/*
rm -rf /etc/v2ray-agent/v2ray/config_full.json rm -rf /etc/v2ray-agent/v2ray/config_full.json
if [[ "$1" = "all" ]] && [[ "${selectCoreType}" = "2" ]]
then cat << EOF > /etc/v2ray-agent/v2ray/conf/00_log.json
# default v2ray-core
cat << EOF > /etc/v2ray-agent/v2ray/config_full.json
{ {
"log": { "log": {
"error": "/etc/v2ray-agent/v2ray/v2ray_error.log", "error": "/etc/v2ray-agent/xray/xray_error.log",
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${uuid}",
"add": "${add}",
"email": "${domain}_VLESS_TLS_TCP"
}
],
"decryption": "none",
"fallbacks": [
{
"dest": 31296,
"xver": 0
},
{
"path": "/${customPath}",
"dest": 31299,
"xver": 1
},
{
"path": "/${customPath}tcp",
"dest": 31298,
"xver": 1
},
{
"path": "/${customPath}ws",
"dest": 31297,
"xver": 1
}
]
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"certificateFile": "/etc/v2ray-agent/tls/${domain}.crt",
"keyFile": "/etc/v2ray-agent/tls/${domain}.key"
}
]
}
}
},
{
"port": 31299,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${uuid}",
"alterId": 1,
"level": 0,
"email": "${domain}_vmess_ws"
}
]
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}"
}
}
},
{
"port": 31298,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${uuid}",
"level": 0,
"alterId": 1,
"email": "${domain}_vmess_tcp"
}
]
},
"streamSettings": {
"network": "tcp",
"security": "none",
"tcpSettings": {
"acceptProxyProtocol": true,
"header": {
"type": "http",
"request": {
"path": [
"/${customPath}tcp"
]
}
}
}
}
},
{
"port": 31297,
"listen": "127.0.0.1",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${uuid}",
"level": 0,
"email": "${domain}_vless_ws"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}ws"
}
}
}
],
"routing":{
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "blocked"
}
]
},
"outbounds": [
{
"tag":"direct",
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIPv4"
}
},
{
"tag": "blocked",
"protocol": "blackhole",
"settings": {}
}
],
"dns": {
"servers": [
"74.82.42.42",
"8.8.8.8",
"8.8.4.4",
"1.1.1.1",
"localhost"
]
}
}
EOF
elif [[ "$1" = "all" ]] && [[ "${selectCoreType}" = "3" ]]
then
# 需锁定4.32.1
cat << EOF > /etc/v2ray-agent/v2ray/config_full.json
{
"log": {
"error": "/etc/v2ray-agent/v2ray/v2ray_error.log",
"loglevel": "warning"
},
"inbounds": [
{
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${uuid}",
"add": "${add}",
"flow":"xtls-rprx-origin",
"email": "${domain}_VLESS_XTLS/TLS-origin_TCP"
},
{
"id": "${uuid}",
"flow":"xtls-rprx-direct",
"email": "${domain}_VLESS_XTLS/TLS-direct_TCP"
}
],
"decryption": "none",
"fallbacks": [
{
"dest": 31296,
"xver": 0
},
{
"path": "/${customPath}",
"dest": 31299,
"xver": 1
},
{
"path": "/${customPath}tcp",
"dest": 31298,
"xver": 1
},
{
"path": "/${customPath}ws",
"dest": 31297,
"xver": 1
}
]
},
"streamSettings": {
"network": "tcp",
"security": "xtls",
"xtlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"certificateFile": "/etc/v2ray-agent/tls/${domain}.crt",
"keyFile": "/etc/v2ray-agent/tls/${domain}.key"
}
]
}
}
},
{
"port": 31299,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${uuid}",
"alterId": 1,
"level": 0,
"email": "${domain}_vmess_ws"
}
]
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}"
}
}
},
{
"port": 31298,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${uuid}",
"level": 0,
"alterId": 1,
"email": "${domain}_vmess_tcp"
}
]
},
"streamSettings": {
"network": "tcp",
"security": "none",
"tcpSettings": {
"acceptProxyProtocol": true,
"header": {
"type": "http",
"request": {
"path": [
"/${customPath}tcp"
]
}
}
}
}
},
{
"port": 31297,
"listen": "127.0.0.1",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${uuid}",
"level": 0,
"email": "${domain}_vless_ws"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}ws"
}
}
}
],
"routing":{
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "blocked"
}
]
},
"outbounds": [
{
"tag":"direct",
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIPv4"
}
},
{
"tag": "blocked",
"protocol": "blackhole",
"settings": {}
}
],
"dns": {
"servers": [
"74.82.42.42",
"8.8.8.8",
"8.8.4.4",
"1.1.1.1",
"localhost"
]
}
}
EOF
elif [[ "$1" = "custom" ]]
then
# custom v2ray-core
cat << EOF > /etc/v2ray-agent/v2ray/conf/00_log.json
{
"log": {
"error": "/etc/v2ray-agent/v2ray/v2ray_error.log",
"loglevel": "warning" "loglevel": "warning"
} }
} }
EOF EOF
# outbounds # routing
cat << EOF > /etc/v2ray-agent/v2ray/conf/10_outbounds.json cat << EOF > /etc/v2ray-agent/v2ray/conf/09_routing.json
{
"routing":{
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "blocked"
}
]
}
}
EOF
# outbounds
cat << EOF > /etc/v2ray-agent/v2ray/conf/10_outbounds.json
{ {
"outbounds": [ "outbounds": [
{ {
@ -1888,24 +1532,9 @@ EOF
] ]
} }
EOF EOF
cat << EOF > /etc/v2ray-agent/v2ray/conf/09_routing.json
{ # dns
"routing":{ cat << EOF > /etc/v2ray-agent/v2ray/conf/11_dns.json
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"protocol": [
"bittorrent"
],
"outboundTag": "blocked"
}
]
}
}
EOF
# dns
cat << EOF > /etc/v2ray-agent/v2ray/conf/11_dns.json
{ {
"dns": { "dns": {
"servers": [ "servers": [
@ -1918,130 +1547,134 @@ EOF
} }
} }
EOF EOF
# VLESS_TCP_TLS/XTLS # VLESS_TCP_TLS/XTLS
# 没有path则回落到此端口 # 回落nginx
local fallbacksList='{"dest":31296,"xver":0}' local fallbacksList='{"dest":31296,"xver":0}'
if [[ -z `echo ${selectCustomInstallType}|grep 4` ]] if [[ -z `echo ${selectCustomInstallType}|grep 4` || "$1" = "all" ]]
then then
fallbacksList='{"dest":31300,"xver":0}' # 回落trojan-go
fi fallbacksList='{"dest":31300,"xver":0}'
fi
# VLESS_WS_TLS # VLESS_WS_TLS
if [[ ! -z `echo ${selectCustomInstallType}|grep 1` ]] if [[ ! -z `echo ${selectCustomInstallType}|grep 1` || "$1" = "all" ]]
then then
fallbacksList=${fallbacksList}',{"path":"/'${customPath}'ws","dest":31297,"xver":1}' fallbacksList=${fallbacksList}',{"path":"/'${customPath}'ws","dest":31297,"xver":1}'
cat << EOF > /etc/v2ray-agent/v2ray/conf/03_VLESS_WS_inbounds.json cat << EOF > /etc/v2ray-agent/v2ray/conf/03_VLESS_WS_inbounds.json
{
"inbounds":[
{
"port": 31297,
"listen": "127.0.0.1",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "${uuid}",
"level": 0,
"email": "${domain}_vless_ws"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}ws"
}
}
}
]
}
EOF
fi
# VMess_TCP
if [[ ! -z `echo ${selectCustomInstallType}|grep 2` ]]
then
fallbacksList=${fallbacksList}',{"path":"/'${customPath}'tcp","dest":31298,"xver":1}'
cat << EOF > /etc/v2ray-agent/v2ray/conf/04_VMess_TCP_inbounds.json
{ {
"inbounds":[ "inbounds":[
{ {
"port": 31298, "port": 31297,
"listen": "127.0.0.1", "listen": "127.0.0.1",
"protocol": "vmess", "protocol": "vless",
"tag":"VMessTCP", "settings": {
"settings": { "clients": [
"clients": [ {
{ "id": "${uuid}",
"id": "${uuid}", "level": 0,
"level": 0, "email": "${domain}_vless_ws"
"alterId": 1,
"email": "${domain}_vmess_tcp"
}
]
},
"streamSettings": {
"network": "tcp",
"security": "none",
"tcpSettings": {
"acceptProxyProtocol": true,
"header": {
"type": "http",
"request": {
"path": [
"/${customPath}tcp"
]
}
}
}
} }
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}ws"
} }
}
}
] ]
} }
EOF EOF
fi fi
# VMess_WS
if [[ ! -z `echo ${selectCustomInstallType}|grep 3` ]] # VMess_TCP
then if [[ ! -z `echo ${selectCustomInstallType}|grep 2` || "$1" = "all" ]]
fallbacksList=${fallbacksList}',{"path":"/'${customPath}'","dest":31299,"xver":1}' then
cat << EOF > /etc/v2ray-agent/v2ray/conf/05_VMess_WS_inbounds.json fallbacksList=${fallbacksList}',{"path":"/'${customPath}'tcp","dest":31298,"xver":1}'
cat << EOF > /etc/v2ray-agent/v2ray/conf/04_VMess_TCP_inbounds.json
{ {
"inbounds":[ "inbounds":[
{ {
"port": 31299, "port": 31298,
"protocol": "vmess", "listen": "127.0.0.1",
"tag":"VMessWS", "protocol": "vmess",
"settings": { "tag":"VMessTCP",
"clients": [ "settings": {
{ "clients": [
"id": "${uuid}", {
"alterId": 1, "id": "${uuid}",
"add": "${add}", "level": 0,
"level": 0, "alterId": 1,
"email": "${domain}_vmess_ws" "email": "${domain}_vmess_tcp"
} }
] ]
}, },
"streamSettings": { "streamSettings": {
"network": "ws", "network": "tcp",
"security": "none", "security": "none",
"wsSettings": { "tcpSettings": {
"acceptProxyProtocol": true, "acceptProxyProtocol": true,
"path": "/${customPath}" "header": {
"type": "http",
"request": {
"path": [
"/${customPath}tcp"
]
} }
} }
} }
}
}
] ]
} }
EOF EOF
fi fi
# VLESS_TCP
if [[ "${selectCoreType}" = "2" ]] # VMess_WS
then if [[ ! -z `echo ${selectCustomInstallType}|grep 3` || "$1" = "all" ]]
cat << EOF > /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json then
fallbacksList=${fallbacksList}',{"path":"/'${customPath}'","dest":31299,"xver":1}'
cat << EOF > /etc/v2ray-agent/v2ray/conf/05_VMess_WS_inbounds.json
{
"inbounds":[
{
"port": 31299,
"protocol": "vmess",
"tag":"VMessWS",
"settings": {
"clients": [
{
"id": "${uuid}",
"alterId": 1,
"add": "${add}",
"level": 0,
"email": "${domain}_vmess_ws"
}
]
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"acceptProxyProtocol": true,
"path": "/${customPath}"
}
}
}
]
}
EOF
fi
# VLESS_TCP
if [[ "${selectCoreType}" = "2" ]]
then
cat << EOF > /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json
{ {
"inbounds":[ "inbounds":[
{ {
@ -2080,56 +1713,48 @@ EOF
] ]
} }
EOF EOF
elif [[ "${selectCoreType}" = "3" ]] elif [[ "${selectCoreType}" = "3" ]]
then then
cat << EOF > /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json cat << EOF > /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json
{ {
"inbounds":[ "inbounds":[
{ {
"port": 443, "port": 443,
"protocol": "vless", "protocol": "vless",
"tag":"VLESSTCP", "tag":"VLESSTCP",
"settings": { "settings": {
"clients": [ "clients": [
{ {
"id": "${uuid}", "id": "${uuid}",
"add": "${add}", "add":"${add}",
"flow":"xtls-rprx-origin", "flow":"xtls-rprx-direct",
"email": "${domain}_VLESS_XTLS/TLS-origin_TCP" "email": "${domain}_VLESS_XTLS/TLS-direct_TCP"
},
{
"id": "${uuid}",
"flow":"xtls-rprx-direct",
"email": "${domain}_VLESS_XTLS/TLS-direct_TCP"
}
],
"decryption": "none",
"fallbacks": [
${fallbacksList}
]
},
"streamSettings": {
"network": "tcp",
"security": "xtls",
"xtlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"certificateFile": "/etc/v2ray-agent/tls/${domain}.crt",
"keyFile": "/etc/v2ray-agent/tls/${domain}.key"
}
]
}
} }
],
"decryption": "none",
"fallbacks": [
${fallbacksList}
]
},
"streamSettings": {
"network": "tcp",
"security": "xtls",
"xtlsSettings": {
"alpn": [
"http/1.1"
],
"certificates": [
{
"certificateFile": "/etc/v2ray-agent/tls/${domain}.crt",
"keyFile": "/etc/v2ray-agent/tls/${domain}.key"
}
]
} }
] }
}
]
} }
EOF EOF
fi
fi fi
} }
@ -2472,7 +2097,7 @@ defaultBase64Code(){
echo " vmess://${qrCodeBase64Default}" >> /etc/v2ray-agent/v2ray/usersv2ray.conf echo " vmess://${qrCodeBase64Default}" >> /etc/v2ray-agent/v2ray/usersv2ray.conf
echoContent yellow " ---> 通用json(VLESS+TCP+TLS)" echoContent yellow " ---> 通用json(VLESS+TCP+TLS)"
echoContent green ' {"port":"'${port}'","ps":'${ps}',"tls":"tls","id":'"${id}"',"host":"'${host}'","type":"none","net":"tcp","add":"'${host}'","allowInsecure":0,"method":"none","peer":""}\n' echoContent green ' {"port":"'${port}'","ps":'${ps}',"tls":"tls","id":'"${id}"',"host":"'${host}'","type":"none","net":"tcp","add":"'${host}'","allowInsecure":0,"method":"none","peer":""}\n'
echoContent green ' V2Ray v4.27.4+ 目前无通用订阅需要手动配置VLESS TCP、XTLS和TCP大部分一样其余内容不变请注意手动输入的流控flow类型v2ray-core v4.32.1之后不支持XTLSXray-core支持建议使用Xray-core\n' echoContent green ' V2Ray、Xray 目前无通用订阅需要手动配置VLESS TCP、XTLS和TCP大部分一样其余内容不变请注意手动输入的流控flow类型v2ray-core v4.32.1之后不支持XTLSXray-core支持建议使用Xray-core\n'
elif [[ "${type}" = "vmessws" ]] elif [[ "${type}" = "vmessws" ]]
then then
@ -2695,14 +2320,12 @@ updateV2RayCDN(){
if [[ ! -z ${setDomain} ]] if [[ ! -z ${setDomain} ]]
then then
# v2ray if [[ ! -z ${currentAdd} ]]
add=`echo ${currentAdd}|awk -F '["]' '{print $4}'`
if [[ ! -z ${add} ]]
then then
sed -i "s/\"${add}\"/\"${setDomain}\"/g" `grep "${add}" -rl ${configPath}` sed -i "s/\"${currentAdd}\"/\"${setDomain}\"/g" `grep "${currentAdd}" -rl ${configPath}02_VLESS_TCP_inbounds.json`
fi fi
if [[ `cat ${configPath}/02_VLESS_TCP_inbounds.json|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]] if [[ `cat ${configPath}02_VLESS_TCP_inbounds.json|grep -v grep|grep add|awk -F '["]' '{print $4}'` = ${setDomain} ]]
then then
echoContent green " ---> CDN修改成功" echoContent green " ---> CDN修改成功"
if [[ "${coreInstallType}" = "1" ]] if [[ "${coreInstallType}" = "1" ]]
@ -3293,7 +2916,7 @@ menu(){
cd cd
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.1.27" echoContent green "当前版本v2.2.0"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:七合一共存脚本" echoContent green "描述:七合一共存脚本"
echoContent red "==============================================================" echoContent red "=============================================================="
@ -3304,15 +2927,16 @@ menu(){
echoContent yellow "4.更换伪装站" echoContent yellow "4.更换伪装站"
echoContent yellow "5.更新证书" echoContent yellow "5.更新证书"
echoContent yellow "6.更换CDN节点" echoContent yellow "6.更换CDN节点"
echoContent yellow "7.重置uuid" echoContent yellow "7.多用户管理[todo]"
echoContent yellow "8.ipv6人机验证[todo]"
echoContent skyBlue "-------------------------版本管理-----------------------------" echoContent skyBlue "-------------------------版本管理-----------------------------"
echoContent yellow "8.core版本管理" echoContent yellow "9.core版本管理"
echoContent yellow "9.升级Trojan-Go" echoContent yellow "10.升级Trojan-Go"
echoContent yellow "10.升级脚本" echoContent yellow "11.升级脚本"
echoContent yellow "11.安装BBR" echoContent yellow "12.安装BBR"
echoContent skyBlue "-------------------------脚本管理-----------------------------" echoContent skyBlue "-------------------------脚本管理-----------------------------"
echoContent yellow "12.查看日志" echoContent yellow "13.查看日志"
echoContent yellow "13.卸载脚本" echoContent yellow "14.卸载脚本"
echoContent red "==============================================================" echoContent red "=============================================================="
mkdirTools mkdirTools
aliasInstall aliasInstall
@ -3339,22 +2963,22 @@ menu(){
#7) #7)
#resetUUID 1 #resetUUID 1
#;; #;;
8) 9)
coreVersionManageMenu 1 coreVersionManageMenu 1
;; ;;
9) 10)
updateTrojanGo 1 updateTrojanGo 1
;; ;;
10) 11)
updateV2RayAgent 1 updateV2RayAgent 1
;; ;;
11) 12)
bbrInstall bbrInstall
;; ;;
12) 13)
checkLog 1 checkLog 1
;; ;;
13) 14)
unInstall 1 unInstall 1
;; ;;
esac esac