From b462cb9bb9cab2834a2e97d6fb8c582c93bf029a Mon Sep 17 00:00:00 2001 From: 233boy <31657650+233boy@users.noreply.github.com> Date: Wed, 8 May 2024 20:02:27 +0800 Subject: [PATCH] add dns set --- README.md | 1 + src/core.sh | 10 ++++++++- src/dns.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/help.sh | 1 + xray.sh | 2 +- 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/dns.sh diff --git a/README.md b/README.md index 15cbddb..70b9cb0 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Usage: xray [options]... [args]... web [name] [domain] 更改伪装网站 进阶: + dns [...] 设置 DNS dd, ddel [name...] 删除多个配置** fix [name] 修复一个配置 fix-all 修复全部配置 diff --git a/src/core.sh b/src/core.sh index b887122..50b7ccb 100644 --- a/src/core.sh +++ b/src/core.sh @@ -1695,7 +1695,7 @@ is_main_menu() { show_help ;; 9) - ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本" + ask list is_do_other "启用BBR 查看日志 查看错误日志 测试运行 重装脚本 设置DNS" case $REPLY in 1) load bbr.sh @@ -1713,6 +1713,10 @@ is_main_menu() { 5) get reinstall ;; + 6) + load dns.sh + dns_set + ;; esac ;; 10) @@ -1786,6 +1790,10 @@ main() { [[ $is_api_fail ]] && manage restart & [[ $is_del_host ]] && manage restart caddy & ;; + dns) + load dns.sh + dns_set ${@:2} + ;; debug) is_debug=1 get info $2 diff --git a/src/dns.sh b/src/dns.sh new file mode 100644 index 0000000..420ab3f --- /dev/null +++ b/src/dns.sh @@ -0,0 +1,58 @@ +is_dns_list=( + 1.1.1.1 + 8.8.8.8 + https://dns.google/dns-query + https://cloudflare-dns.com/dns-query + https://family.cloudflare-dns.com/dns-query + set + none +) +dns_set() { + if [[ $1 ]]; then + case ${1,,} in + 11 | 1111) + is_dns_use=${is_dns_list[0]} + ;; + 88 | 8888) + is_dns_use=${is_dns_list[1]} + ;; + gg | google) + is_dns_use=${is_dns_list[2]} + ;; + cf | cloudflare) + is_dns_use=${is_dns_list[3]} + ;; + nosex | family) + is_dns_use=${is_dns_list[4]} + ;; + set) + if [[ $2 ]]; then + is_dns_use=${2,,} + else + ask string is_dns_use "请输入 DNS: " + fi + ;; + none) + is_dns_use=none + ;; + *) + err "无法识别 DNS 参数: $@" + ;; + esac + else + is_tmp_list=(${is_dns_list[@]}) + ask list dns_pick + is_dns_use=${is_dns_list[$REPLY - 1]} + if [[ $is_dns_use == "set" ]]; then + ask string is_dns_use "请输入 DNS: " + fi + fi + is_new_dns=$(sed s/https/https+local/ <<<$is_dns_use) + if [[ $is_new_dns == "none" ]]; then + cat <<<$(jq '.dns={}' $is_config_json) >$is_config_json + else + cat <<<$(jq '.dns.servers=["'$is_new_dns'"]' $is_config_json) >$is_config_json + fi + manage restart & + msg "\n已更新 DNS 为: $(_green $is_new_dns)\n" +} \ No newline at end of file diff --git a/src/help.sh b/src/help.sh index 1255511..acf5a3d 100644 --- a/src/help.sh +++ b/src/help.sh @@ -40,6 +40,7 @@ show_help() { " new [name] [...] 更改协议" " web [name] [domain] 更改伪装网站\n" "进阶:" + " dns [...] 设置 DNS" " dd, ddel [name...] 删除多个配置**" " fix [name] 修复一个配置" " fix-all 修复全部配置" diff --git a/xray.sh b/xray.sh index 7cfbb55..c4ea355 100644 --- a/xray.sh +++ b/xray.sh @@ -1,6 +1,6 @@ #!/bin/bash args=$@ -is_sh_ver=v1.18 +is_sh_ver=v1.19 . /etc/xray/sh/src/init.sh \ No newline at end of file