mirror of
https://github.com/juewuy/ShellCrash.git
synced 2026-03-10 23:41:22 +00:00
~增加ecs优化功能
This commit is contained in:
17
scripts/libs/get_ecsip.sh
Normal file
17
scripts/libs/get_ecsip.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
get_ecs_address() {
|
||||
ip=$(uci get network.wan.dns 2>/dev/null)
|
||||
[ -n "$ip" ] && return
|
||||
for f in /tmp/resolv.conf.auto /tmp/resolv.conf /tmp/resolv.conf.d/resolv.conf.auto; do
|
||||
[ -f "$f" ] || continue
|
||||
ip=$(grep -A2 "^# Interface wan" "$f" | grep nameserver | awk '{printf "%s ", $2}')
|
||||
[ -n "$ip" ] && return
|
||||
done
|
||||
. "$CRASHDIR"/libs/web_get_lite.sh
|
||||
for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do
|
||||
ip=$(web_get_lite "$web" 0)
|
||||
[ -n "$ip" ] && return
|
||||
done
|
||||
}
|
||||
get_ecs_address
|
||||
[ -n "$ip" ] && ecs_address="${ip%.*}.0/24"
|
||||
@@ -1,7 +1,7 @@
|
||||
. "$CRASHDIR"/libs/set_proxy.sh
|
||||
#$1:目标地址 $2:json字符串
|
||||
#$1:目标地址 $2:禁用proxy
|
||||
web_get_lite() {
|
||||
setproxy
|
||||
[ -z "$2" ] && setproxy
|
||||
if curl --version >/dev/null 2>&1; then
|
||||
curl -ksSl --connect-timeout 3 "$1" 2>/dev/null
|
||||
else
|
||||
|
||||
@@ -7,6 +7,7 @@ __IS_MODULE_DNS_LOADED=1
|
||||
set_dns_mod() { #DNS模式设置
|
||||
[ -z "$hosts_opt" ] && hosts_opt=ON
|
||||
[ -z "$dns_protect" ] && dns_protect=ON
|
||||
[ -z "$ecs_subnet" ] && ecs_subnet=OFF || ecs_subnet=ON
|
||||
echo "-----------------------------------------------"
|
||||
echo -e "当前DNS运行模式为:\033[47;30m $dns_mod \033[0m"
|
||||
echo -e "\033[33m切换模式后需要手动重启服务以生效!\033[0m"
|
||||
@@ -17,7 +18,8 @@ set_dns_mod() { #DNS模式设置
|
||||
echo "-----------------------------------------------"
|
||||
echo -e " 4 DNS防泄漏: \033[36m$dns_protect\033[0m ———启用时少量网站可能连接卡顿"
|
||||
echo -e " 5 Hosts优化: \033[36m$hosts_opt\033[0m ———调用本机hosts并劫持NTP服务"
|
||||
echo -e " 6 DNS劫持端口:\033[36m$dns_redir_port\033[0m ———用于兼容第三方DNS服务"
|
||||
echo -e " 6 ECS优化: \033[36m$ecs_subnet\033[0m ———解决CDN下载浪费流量等问题"
|
||||
echo -e " 7 DNS劫持端口:\033[36m$dns_redir_port\033[0m ———用于兼容第三方DNS服务"
|
||||
[ "$dns_mod" = "mix" ] &&
|
||||
echo -e " 8 管理MIX模式\033[33mFake-ip过滤列表\033[0m"
|
||||
echo -e " 9 修改\033[36mDNS服务器\033[0m"
|
||||
@@ -68,6 +70,11 @@ set_dns_mod() { #DNS模式设置
|
||||
set_dns_mod
|
||||
;;
|
||||
6)
|
||||
[ "$ecs_subnet" = "ON" ] && ecs_subnet=OFF || ecs_subnet=ON
|
||||
setconfig ecs_subnet "$ecs_subnet"
|
||||
set_dns_mod
|
||||
;;
|
||||
7)
|
||||
echo "-----------------------------------------------"
|
||||
echo -e "\033[31m仅限搭配第三方DNS服务(AdGuard、SmartDNS……)使用!\033[0m"
|
||||
echo -e "\033[33m设置为第三方DNS服务的监听端口即可修改防火墙劫持!\n建议在第三方DNS服务中将上游DNS指向【localhost:$dns_port】\033[0m"
|
||||
|
||||
@@ -16,6 +16,15 @@ modify_yaml() {
|
||||
#Meta内核专属配置
|
||||
[ "$crashcore" = 'meta' ] && {
|
||||
[ "$redir_mod" != "纯净模式" ] && [ -z "$(grep 'PROCESS' "$CRASHDIR"/yamls/*.yaml)" ] && find_process='find-process-mode: "off"'
|
||||
#ecs优化
|
||||
[ "$ecs_subnet" = ON ] && {
|
||||
. "$CRASHDIR"/libs/get_ecsip.sh
|
||||
if [ -n "$ecs_address" ];then
|
||||
dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||')
|
||||
else
|
||||
logger "自动获取ecs网段失败!"
|
||||
fi
|
||||
}
|
||||
}
|
||||
#dns配置
|
||||
[ -z "$(cat "$CRASHDIR"/yamls/user.yaml 2>/dev/null | grep '^dns:')" ] && {
|
||||
|
||||
@@ -63,8 +63,7 @@ modify_json() {
|
||||
EOF
|
||||
#生成add_hosts.json
|
||||
if [ "$hosts_opt" != "OFF" ]; then #本机hosts
|
||||
sys_hosts=/etc/hosts
|
||||
[ -s /data/etc/custom_hosts ] && sys_hosts=/data/etc/custom_hosts
|
||||
[ -s /data/etc/custom_hosts ] && custom_hosts='"/data/etc/custom_hosts",'
|
||||
#NTP劫持
|
||||
cat >"$TMPDIR"/jsons/add_hosts.json <<EOF
|
||||
{
|
||||
@@ -74,8 +73,9 @@ EOF
|
||||
"type": "hosts",
|
||||
"tag": "hosts",
|
||||
"path": [
|
||||
"$sys_hosts",
|
||||
"$HOME/.hosts"
|
||||
$custom_hosts
|
||||
"$HOME/.hosts",
|
||||
"/etc/hosts"
|
||||
],
|
||||
"predefined": {
|
||||
"localhost": [
|
||||
@@ -103,6 +103,8 @@ EOF
|
||||
[ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "urltest"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
|
||||
[ -z "$auto_detour" ] && auto_detour=$(grep -E '"type": "selector"' -A 1 "$TMPDIR"/jsons/outbounds.json | grep '"tag":' | head -n 1 | sed 's/^[[:space:]]*"tag": //;s/,$//')
|
||||
[ -z "$auto_detour" ] && auto_detour='"DIRECT"'
|
||||
#ecs优化
|
||||
[ "$ecs_subnet" = ON ] && . "$CRASHDIR"/libs/get_ecsip.sh
|
||||
#根据dns模式生成
|
||||
[ "$dns_mod" = "redir_host" ] && {
|
||||
global_dns=dns_proxy
|
||||
@@ -127,20 +129,25 @@ EOF
|
||||
#防泄露设置
|
||||
[ "$dns_protect" = "OFF" ] && sed -i 's/"server": "dns_proxy"/"server": "dns_direct"/g' "$TMPDIR"/jsons/route.json
|
||||
#生成add_rule_set.json
|
||||
[ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json &&
|
||||
[ "$dns_mod" = "mix" ] || [ "$dns_mod" = "route" ] && ! grep -Eq '"tag" *:[[:space:]]*"cn"' "$CRASHDIR"/jsons/*.json && {
|
||||
[ "$crashcore" = "singboxr" ] && srs_path='"path": "./ruleset/cn.srs",'
|
||||
cat >"$TMPDIR"/jsons/add_rule_set.json <<EOF
|
||||
{
|
||||
"route": {
|
||||
"rule_set": [
|
||||
{
|
||||
"tag": "cn",
|
||||
"type": "local",
|
||||
"path": "./ruleset/cn.srs"
|
||||
"type": "remote",
|
||||
"format": "binary",
|
||||
$srs_path
|
||||
"url": "https://testingcf.jsdelivr.net/gh/DustinWin/ruleset_geodata@sing-box-ruleset/cn.srs",
|
||||
"download_detour": "DIRECT"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
cat >"$TMPDIR"/jsons/dns.json <<EOF
|
||||
{
|
||||
"dns": {
|
||||
@@ -150,6 +157,7 @@ EOF
|
||||
$(parse_singbox_dns "$dns_fallback")
|
||||
"routing_mark": $routing_mark,
|
||||
"detour": $auto_detour,
|
||||
"client_subnet": "$ecs_address",
|
||||
"domain_resolver": "dns_resolver"
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user