diff --git a/luci-app-passwall2/Makefile b/luci-app-passwall2/Makefile index 32c5404da..62d0a7b90 100644 --- a/luci-app-passwall2/Makefile +++ b/luci-app-passwall2/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall2 -PKG_VERSION:=1.20-10 +PKG_VERSION:=1.20-11 PKG_RELEASE:= PKG_CONFIG_DEPENDS:= \ diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria2.lua similarity index 67% rename from luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria.lua rename to luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria2.lua index 4f28e3ba7..a8fc17d66 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/type/hysteria2.lua @@ -6,22 +6,20 @@ if not api.finded_com("hysteria") then return end -local type_name = "Hysteria" +local type_name = "Hysteria2" -local option_prefix = "hysteria_" +local option_prefix = "hysteria2_" local function option_name(name) return option_prefix .. name end --- [[ Hysteria ]] +-- [[ Hysteria2 ]] -s.fields["type"]:value(type_name, translate("Hysteria")) +s.fields["type"]:value(type_name, "Hysteria2") o = s:option(ListValue, option_name("protocol"), translate("Protocol")) o:value("udp", "UDP") -o:value("faketcp", "faketcp") -o:value("wechat-video", "wechat-video") o = s:option(Value, option_name("address"), translate("Address (Support Domain Name)")) @@ -34,19 +32,8 @@ o.rewrite_option = o.option o = s:option(Value, option_name("obfs"), translate("Obfs Password")) o.rewrite_option = o.option -o = s:option(ListValue, option_name("auth_type"), translate("Auth Type")) -o:value("disable", translate("Disable")) -o:value("string", translate("STRING")) -o:value("base64", translate("BASE64")) -o.rewrite_option = o.option - o = s:option(Value, option_name("auth_password"), translate("Auth Password")) o.password = true -o:depends({ [option_name("auth_type")] = "string"}) -o:depends({ [option_name("auth_type")] = "base64"}) -o.rewrite_option = o.option - -o = s:option(Value, option_name("alpn"), translate("QUIC TLS ALPN")) o.rewrite_option = o.option o = s:option(Flag, option_name("fast_open"), translate("Fast Open")) @@ -58,11 +45,14 @@ o = s:option(Flag, option_name("tls_allowInsecure"), translate("allowInsecure"), o.default = "0" o = s:option(Value, option_name("up_mbps"), translate("Max upload Mbps")) -o.default = "10" +o.default = "100" o.rewrite_option = o.option o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps")) -o.default = "50" +o.default = "100" +o.rewrite_option = o.option + +o = s:option(Value, option_name("hop_interval"), translate("Hop Interval")) o.rewrite_option = o.option o = s:option(Value, option_name("recv_window_conn"), translate("QUIC stream receive window")) @@ -71,19 +61,11 @@ o.rewrite_option = o.option o = s:option(Value, option_name("recv_window"), translate("QUIC connection receive window")) o.rewrite_option = o.option -o = s:option(Value, option_name("handshake_timeout"), translate("Handshake Timeout")) -o.rewrite_option = o.option - o = s:option(Value, option_name("idle_timeout"), translate("Idle Timeout")) o.rewrite_option = o.option -o = s:option(Value, option_name("hop_interval"), translate("Hop Interval")) -o.rewrite_option = o.option - o = s:option(Flag, option_name("disable_mtu_discovery"), translate("Disable MTU detection")) -o.rewrite_option = o.option - -o = s:option(Flag, option_name("lazy_start"), translate("Lazy Start")) +o.default = "0" o.rewrite_option = o.option api.luci_types(arg[1], m, s, type_name, option_prefix) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria2.lua similarity index 52% rename from luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria.lua rename to luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria2.lua index ced902a29..ea4556a71 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/server/type/hysteria2.lua @@ -6,40 +6,26 @@ if not api.finded_com("hysteria") then return end -local type_name = "Hysteria" +local type_name = "Hysteria2" -local option_prefix = "hysteria_" +local option_prefix = "hysteria2_" local function option_name(name) return option_prefix .. name end --- [[ Hysteria ]] +-- [[ Hysteria2 ]] -s.fields["type"]:value(type_name, translate("Hysteria")) +s.fields["type"]:value(type_name, "Hysteria2") o = s:option(Value, option_name("port"), translate("Listen Port")) o.datatype = "port" -o = s:option(ListValue, option_name("protocol"), translate("Protocol")) -o:value("udp", "UDP") -o:value("faketcp", "faketcp") -o:value("wechat-video", "wechat-video") - o = s:option(Value, option_name("obfs"), translate("Obfs Password")) o.rewrite_option = o.option -o = s:option(ListValue, option_name("auth_type"), translate("Auth Type")) -o:value("disable", translate("Disable")) -o:value("string", translate("STRING")) -o.rewrite_option = o.option - o = s:option(Value, option_name("auth_password"), translate("Auth Password")) o.password = true -o:depends({ [option_name("auth_type")] = "string" }) -o.rewrite_option = o.option - -o = s:option(Value, option_name("alpn"), translate("QUIC TLS ALPN")) o.rewrite_option = o.option o = s:option(Flag, option_name("udp"), translate("UDP")) @@ -47,40 +33,19 @@ o.default = "1" o.rewrite_option = o.option o = s:option(Value, option_name("up_mbps"), translate("Max upload Mbps")) -o.default = "10" +o.default = "100" o.rewrite_option = o.option o = s:option(Value, option_name("down_mbps"), translate("Max download Mbps")) -o.default = "50" +o.default = "100" o.rewrite_option = o.option -o = s:option(Value, option_name("recv_window_conn"), translate("QUIC stream receive window")) +o = s:option(Flag, option_name("ignoreClientBandwidth"), translate("ignoreClientBandwidth")) +o.default = "0" o.rewrite_option = o.option -o = s:option(Value, option_name("recv_window"), translate("QUIC connection receive window")) -o.rewrite_option = o.option - -o = s:option(Flag, option_name("disable_mtu_discovery"), translate("Disable MTU detection")) -o.rewrite_option = o.option - -o = s:option(Flag, option_name("tls"), translate("TLS")) -o.default = 0 -o.validate = function(self, value, t) - if value then - if value == "1" then - local ca = s.fields[option_name("tls_certificateFile")]:formvalue(t) or "" - local key = s.fields[option_name("tls_keyFile")]:formvalue(t) or "" - if ca == "" or key == "" then - return nil, translate("Public key and Private key path can not be empty!") - end - end - return value - end -end - o = s:option(FileUpload, option_name("tls_certificateFile"), translate("Public key absolute path"), translate("as:") .. "/etc/ssl/fullchain.pem") o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem" -o:depends({ [option_name("tls")] = true }) o.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then @@ -94,7 +59,6 @@ end o = s:option(FileUpload, option_name("tls_keyFile"), translate("Private key absolute path"), translate("as:") .. "/etc/ssl/private.key") o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key" -o:depends({ [option_name("tls")] = true }) o.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then diff --git a/luci-app-passwall2/luasrc/passwall2/api.lua b/luci-app-passwall2/luasrc/passwall2/api.lua index f74f6770d..b5af55ac4 100644 --- a/luci-app-passwall2/luasrc/passwall2/api.lua +++ b/luci-app-passwall2/luasrc/passwall2/api.lua @@ -719,6 +719,9 @@ function to_check(arch, app_name) end local remote_version = json.tag_name + if com[app_name].remote_version_str_replace then + remote_version = remote_version:gsub(com[app_name].remote_version_str_replace, "") + end local has_update = compare_versions(local_version:match("[^v]+"), "<", remote_version:match("[^v]+")) if not has_update then diff --git a/luci-app-passwall2/luasrc/passwall2/com.lua b/luci-app-passwall2/luasrc/passwall2/com.lua index 61366cc38..e12b6ab00 100644 --- a/luci-app-passwall2/luasrc/passwall2/com.lua +++ b/luci-app-passwall2/luasrc/passwall2/com.lua @@ -23,7 +23,8 @@ _M.hysteria = { name = "Hysteria", repo = "HyNetwork/hysteria", get_url = gh_release_url, - cmd_version = "-v | awk '{print $3}'", + cmd_version = "version | awk '/^Version:/ {print $2}'", + remote_version_str_replace = "app/", zipped = false, default_path = "/usr/bin/hysteria", match_fmt_str = "linux%%-%s$", diff --git a/luci-app-passwall2/luasrc/passwall2/server_app.lua b/luci-app-passwall2/luasrc/passwall2/server_app.lua index 476cb1bad..d77a65d7a 100644 --- a/luci-app-passwall2/luasrc/passwall2/server_app.lua +++ b/luci-app-passwall2/luasrc/passwall2/server_app.lua @@ -159,8 +159,8 @@ local function start() brook_path_arg = " --path " .. brook_path end bin = ln_run(api.get_app_path("brook"), "brook_" .. id, string.format("--debug %s -l :%s -p %s%s", brook_protocol, port, brook_password, brook_path_arg), log_path) - elseif type == "Hysteria" then - config = require(require_dir .. "util_hysteria").gen_config_server(user) + elseif type == "Hysteria2" then + config = require(require_dir .. "util_hysteria2").gen_config_server(user) bin = ln_run(api.get_app_path("hysteria"), "hysteria", "-c " .. config_file .. " server", log_path) end diff --git a/luci-app-passwall2/luasrc/passwall2/util_hysteria.lua b/luci-app-passwall2/luasrc/passwall2/util_hysteria.lua deleted file mode 100644 index e55586427..000000000 --- a/luci-app-passwall2/luasrc/passwall2/util_hysteria.lua +++ /dev/null @@ -1,104 +0,0 @@ -module("luci.passwall2.util_hysteria", package.seeall) -local api = require "luci.passwall2.api" -local uci = api.uci -local jsonc = api.jsonc - -function gen_config_server(node) - local config = { - listen = ":" .. node.port, - protocol = node.protocol or "udp", - obfs = node.hysteria_obfs, - cert = node.tls_certificateFile, - key = node.tls_keyFile, - auth = (node.hysteria_auth_type == "string") and { - mode = "password", - config = { - password = node.hysteria_auth_password - } - } or nil, - disable_udp = (node.hysteria_udp == "0") and true or false, - alpn = node.hysteria_alpn or nil, - up_mbps = tonumber(node.hysteria_up_mbps) or 10, - down_mbps = tonumber(node.hysteria_down_mbps) or 50, - recv_window_conn = (node.hysteria_recv_window_conn) and tonumber(node.hysteria_recv_window_conn) or nil, - recv_window = (node.hysteria_recv_window) and tonumber(node.hysteria_recv_window) or nil, - disable_mtu_discovery = (node.hysteria_disable_mtu_discovery) and true or false - } - return config -end - -function gen_config(var) - local node_id = var["-node"] - if not node_id then - print("-node 不能为空") - return - end - local node = uci:get_all("passwall2", node_id) - local local_socks_address = var["-local_socks_address"] or "0.0.0.0" - local local_socks_port = var["-local_socks_port"] - local local_socks_username = var["-local_socks_username"] - local local_socks_password = var["-local_socks_password"] - local local_http_address = var["-local_http_address"] or "0.0.0.0" - local local_http_port = var["-local_http_port"] - local local_http_username = var["-local_http_username"] - local local_http_password = var["-local_http_password"] - local server_host = var["-server_host"] or node.address - local server_port = var["-server_port"] or node.port - - if api.is_ipv6(server_host) then - server_host = api.get_ipv6_full(server_host) - end - local server = server_host .. ":" .. server_port - - if (node.hysteria_hop) then - server = server .. "," .. node.hysteria_hop - end - - local config = { - server = server, - protocol = node.protocol or "udp", - obfs = node.hysteria_obfs, - auth = (node.hysteria_auth_type == "base64") and node.hysteria_auth_password or nil, - auth_str = (node.hysteria_auth_type == "string") and node.hysteria_auth_password or nil, - alpn = node.hysteria_alpn or nil, - server_name = node.tls_serverName, - insecure = (node.tls_allowInsecure == "1") and true or false, - up_mbps = tonumber(node.hysteria_up_mbps) or 10, - down_mbps = tonumber(node.hysteria_down_mbps) or 50, - retry = -1, - retry_interval = 5, - recv_window_conn = (node.hysteria_recv_window_conn) and tonumber(node.hysteria_recv_window_conn) or nil, - recv_window = (node.hysteria_recv_window) and tonumber(node.hysteria_recv_window) or nil, - handshake_timeout = (node.hysteria_handshake_timeout) and tonumber(node.hysteria_handshake_timeout) or nil, - idle_timeout = (node.hysteria_idle_timeout) and tonumber(node.hysteria_idle_timeout) or nil, - hop_interval = (node.hysteria_hop_interval) and tonumber(node.hysteria_hop_interval) or nil, - disable_mtu_discovery = (node.hysteria_disable_mtu_discovery) and true or false, - fast_open = (node.fast_open == "1") and true or false, - lazy_start = (node.hysteria_lazy_start) and true or false, - socks5 = (local_socks_address and local_socks_port) and { - listen = local_socks_address .. ":" .. local_socks_port, - timeout = 300, - disable_udp = false, - user = (local_socks_username and local_socks_password) and local_socks_username, - password = (local_socks_username and local_socks_password) and local_socks_password, - } or nil, - http = (local_http_address and local_http_port) and { - listen = local_http_address .. ":" .. local_http_port, - timeout = 300, - disable_udp = false, - user = (local_http_username and local_http_password) and local_http_username, - password = (local_http_username and local_http_password) and local_http_password, - } or nil - } - - return jsonc.stringify(config, 1) -end - -_G.gen_config = gen_config - -if arg[1] then - local func =_G[arg[1]] - if func then - print(func(api.get_function_args(arg))) - end -end diff --git a/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua b/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua new file mode 100644 index 000000000..8ae9b25f8 --- /dev/null +++ b/luci-app-passwall2/luasrc/passwall2/util_hysteria2.lua @@ -0,0 +1,115 @@ +module("luci.passwall2.util_hysteria2", package.seeall) +local api = require "luci.passwall2.api" +local uci = api.uci +local jsonc = api.jsonc + +function gen_config_server(node) + local config = { + listen = ":" .. node.port, + tls = { + cert = node.tls_certificateFile, + key = node.tls_keyFile, + }, + obfs = { + type = "salamander", + salamander = { + password = node.hysteria2_obfs + } + }, + auth = { + type = "password", + password = node.hysteria2_auth_password + }, + bandwidth = { + up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or "1 gbps", + down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or "1 gbps", + }, + ignoreClientBandwidth = (node.hysteria2_ignoreClientBandwidth == "1") and true or false, + disable_udp = (node.hysteria2_udp == "0") and true or false, + } + return config +end + +function gen_config(var) + local node_id = var["-node"] + if not node_id then + print("-node 不能为空") + return + end + local node = uci:get_all("passwall2", node_id) + local local_socks_address = var["-local_socks_address"] or "0.0.0.0" + local local_socks_port = var["-local_socks_port"] + local local_socks_username = var["-local_socks_username"] + local local_socks_password = var["-local_socks_password"] + local local_http_address = var["-local_http_address"] or "0.0.0.0" + local local_http_port = var["-local_http_port"] + local local_http_username = var["-local_http_username"] + local local_http_password = var["-local_http_password"] + local server_host = var["-server_host"] or node.address + local server_port = var["-server_port"] or node.port + + if api.is_ipv6(server_host) then + server_host = api.get_ipv6_full(server_host) + end + local server = server_host .. ":" .. server_port + + if (node.hysteria2_hop) then + server = server .. "," .. node.hysteria2_hop + end + + local config = { + server = server, + transport = { + type = node.protocol or "udp", + udp = { + hopInterval = node.hysteria2_hop_interval and node.hysteria2_hop_interval .. "s" or "30s" + } + }, + obfs = { + type = "salamander", + salamander = { + password = node.hysteria2_obfs + } + }, + auth = node.hysteria2_auth_password, + tls = { + sni = node.tls_serverName, + insecure = (node.tls_allowInsecure == "1") and true or false + }, + quic = { + initStreamReceiveWindow = (node.hysteria2_recv_window) and tonumber(node.hysteria2_recv_window) or nil, + initConnReceiveWindow = (node.hysteria2_recv_window_conn) and tonumber(node.hysteria2_recv_window_conn) or nil, + maxIdleTimeout = (node.hysteria2_idle_timeout) and tonumber(node.hysteria2_idle_timeout) or nil, + disablePathMTUDiscovery = (node.hysteria2_disable_mtu_discovery) and true or false, + }, + bandwidth = { + up = node.hysteria2_up_mbps and node.hysteria2_up_mbps .. " mbps" or "100 mbps", + down = node.hysteria2_down_mbps and node.hysteria2_down_mbps .. " mbps" or "100 mbps" + }, + fast_open = (node.fast_open == "1") and true or false, + lazy = true, + socks5 = (local_socks_address and local_socks_port) and { + listen = local_socks_address .. ":" .. local_socks_port, + username = (local_socks_username and local_socks_password) and local_socks_username or nil, + password = (local_socks_username and local_socks_password) and local_socks_password or nil, + disable_udp = false, + } or nil, + http = (local_http_address and local_http_port) and { + listen = local_http_address .. ":" .. local_http_port, + username = (local_http_username and local_http_password) and local_http_username or nil, + password = (local_http_username and local_http_password) and local_http_password or nil, + disable_udp = false, + } or nil + } + + return jsonc.stringify(config, 1) +end + +_G.gen_config = gen_config + +if arg[1] then + local func =_G[arg[1]] + if func then + print(func(api.get_function_args(arg))) + end +end diff --git a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua index 808b0e0b0..bb775ec39 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_sing-box.lua @@ -150,7 +150,7 @@ function gen_outbound(flag, node, tag, proxy_table) if node.transport == "grpc" then v2ray_transport = { type = "grpc", - serviceName = node.grpc_serviceName, + service_name = node.grpc_serviceName, idle_timeout = tonumber(node.grpc_idle_timeout) or nil, ping_timeout = tonumber(node.grpc_health_check_timeout) or nil, permit_without_stream = (node.grpc_permit_without_stream == "1") and true or nil, @@ -676,14 +676,17 @@ function gen_config(var) local local_http_username = var["-local_http_username"] local local_http_password = var["-local_http_password"] local dns_listen_port = var["-dns_listen_port"] - local direct_dns_port = var["-direct_dns_port"] local direct_dns_udp_server = var["-direct_dns_udp_server"] + local direct_dns_udp_port = var["-direct_dns_udp_port"] local direct_dns_query_strategy = var["-direct_dns_query_strategy"] - local remote_dns_port = var["-remote_dns_port"] local remote_dns_udp_server = var["-remote_dns_udp_server"] + local remote_dns_udp_port = var["-remote_dns_udp_port"] local remote_dns_tcp_server = var["-remote_dns_tcp_server"] + local remote_dns_tcp_port = var["-remote_dns_tcp_port"] local remote_dns_doh_url = var["-remote_dns_doh_url"] local remote_dns_doh_host = var["-remote_dns_doh_host"] + local remote_dns_doh_ip = var["-remote_dns_doh_ip"] + local remote_dns_doh_port = var["-remote_dns_doh_port"] local remote_dns_query_strategy = var["-remote_dns_query_strategy"] local remote_dns_fake = var["-remote_dns_fake"] local dns_cache = var["-dns_cache"] @@ -1088,109 +1091,105 @@ function gen_config(var) reverse_mapping = true, --在响应 DNS 查询后存储 IP 地址的反向映射以为路由目的提供域名。 fakeip = nil, } - - if true then - local dns_tag = "remote" - - local domain = {} - local domain_suffix = {} - local domain_keyword = {} - local domain_regex = {} - local geosite = {} - for index, value in ipairs(dns_remote_domains) do - if value:find("geosite:") == 1 then - table.insert(geosite, value:sub(1 + #"geosite:")) - elseif value:find("regexp:") == 1 then - table.insert(domain_regex, value:sub(1 + #"regexp:")) - elseif value:find("full:") == 1 then - table.insert(domain, value:sub(1 + #"full:")) - elseif value:find("domain:") == 1 then - table.insert(domain_keyword, value:sub(1 + #"domain:")) - else - table.insert(domain, value) - end + + local dns_tag = "remote" + + local domain = {} + local domain_suffix = {} + local domain_keyword = {} + local domain_regex = {} + local geosite = {} + for index, value in ipairs(dns_remote_domains) do + if value:find("geosite:") == 1 then + table.insert(geosite, value:sub(1 + #"geosite:")) + elseif value:find("regexp:") == 1 then + table.insert(domain_regex, value:sub(1 + #"regexp:")) + elseif value:find("full:") == 1 then + table.insert(domain, value:sub(1 + #"full:")) + elseif value:find("domain:") == 1 then + table.insert(domain_keyword, value:sub(1 + #"domain:")) + else + table.insert(domain, value) end - local remote_rule = { - server = dns_tag, - domain = #domain > 0 and domain or nil, - domain_suffix = #domain_suffix > 0 and domain_suffix or nil, - domain_keyword = #domain_keyword > 0 and domain_keyword or nil, - domain_regex = #domain_regex > 0 and domain_regex or nil, - geosite = #geosite > 0 and geosite or nil, - disable_cache = true, + end + local remote_rule = { + server = dns_tag, + domain = #domain > 0 and domain or nil, + domain_suffix = #domain_suffix > 0 and domain_suffix or nil, + domain_keyword = #domain_keyword > 0 and domain_keyword or nil, + domain_regex = #domain_regex > 0 and domain_regex or nil, + geosite = #geosite > 0 and geosite or nil, + disable_cache = true, + } + + local remote_strategy = "prefer_ipv6" + if remote_dns_query_strategy == "UseIPv4" then + remote_strategy = "ipv4_only" + elseif remote_dns_query_strategy == "UseIPv6" then + remote_strategy = "ipv6_only" + end + + local server = { + tag = dns_tag, + address_strategy = "prefer_ipv4", + strategy = remote_strategy, + address_resolver = "direct", + detour = dns_outTag, + } + + if remote_dns_udp_server then + local server_port = tonumber(remote_dns_udp_port) or 53 + server.address = "udp://" .. remote_dns_udp_server .. ":" .. server_port + end + + if remote_dns_tcp_server then + local server_port = tonumber(remote_dns_tcp_port) or 53 + server.address = "tcp://" .. remote_dns_tcp_server .. ":" .. server_port + end + + if remote_dns_doh_url then + server.address = remote_dns_doh_url + end + + if server.address then + table.insert(dns.servers, server) + end + + local fakedns_tag = dns_tag .. "_fakeip" + if remote_dns_fake then + dns.fakeip = { + enabled = true, + inet4_range = "198.18.0.0/16", + inet6_range = "fc00::/18", } - - local remote_strategy = "prefer_ipv6" - if remote_dns_query_strategy == "UseIPv4" then - remote_strategy = "ipv4_only" - elseif remote_dns_query_strategy == "UseIPv6" then - remote_strategy = "ipv6_only" - end - - local server = { - tag = dns_tag, - address_strategy = "prefer_ipv4", + + table.insert(dns.servers, { + tag = fakedns_tag, + address = "fakeip", strategy = remote_strategy, - address_resolver = "direct", - detour = dns_outTag, - } - - local rule_server = dns_tag - - if remote_dns_udp_server then - local server_port = tonumber(remote_dns_port) or 53 - server.address = "udp://" .. remote_dns_udp_server .. ":" .. server_port - end - - if remote_dns_tcp_server then - server.address = remote_dns_tcp_server - end - - if remote_dns_doh_url and remote_dns_doh_host then - server.address = remote_dns_doh_url - end - - if server.address then - table.insert(dns.servers, server) - end - - if remote_dns_fake then - dns.fakeip = { - enabled = true, - inet4_range = "198.18.0.0/16", - inet6_range = "fc00::/18", + }) + + if tags and tags:find("with_clash_api") then + if not experimental then + experimental = {} + end + experimental.clash_api = { + store_fakeip = true, + cache_file = "/tmp/singbox_passwall2_" .. flag .. ".db" } - - local fakedns_tag = dns_tag .. "_fakeip" - - if not server.address then - fakedns_tag = dns_tag - end - - table.insert(dns.servers, { - tag = fakedns_tag, - address = "fakeip", - strategy = remote_strategy, - }) - - rule_server = fakedns_tag - - if tags and tags:find("with_clash_api") then - if not experimental then - experimental = {} - end - experimental.clash_api = { - store_fakeip = true, - cache_file = "/tmp/singbox_passwall2_" .. flag .. ".db" - } - end end - - if remote_rule.domain or remote_rule.domain_suffix or remote_rule.domain_keyword or remote_rule.domain_regex or remote_rule.geosite then - local rule = api.clone(remote_rule) - rule.server = rule_server - table.insert(dns.rules, rule) + end + + if remote_rule.domain or remote_rule.domain_suffix or remote_rule.domain_keyword or remote_rule.domain_regex or remote_rule.geosite then + local rule = api.clone(remote_rule) + rule.server = dns_tag + if remote_dns_fake then + rule.query_type = { + "A", "AAAA" + } + rule.server = fakedns_tag end + table.insert(dns.rules, rule) end if direct_dns_udp_server then @@ -1221,14 +1220,16 @@ function gen_config(var) end local direct_rule = { server = dns_tag, - domain = domain, + domain = #domain > 0 and domain or nil, domain_suffix = #domain_suffix > 0 and domain_suffix or nil, domain_keyword = #domain_keyword > 0 and domain_keyword or nil, domain_regex = #domain_regex > 0 and domain_regex or nil, geosite = #geosite > 0 and geosite or nil, disable_cache = false, } - table.insert(dns.rules, direct_rule) + if direct_rule.domain or direct_rule.domain_suffix or direct_rule.domain_keyword or direct_rule.domain_regex or direct_rule.geosite then + table.insert(dns.rules, direct_rule) + end local direct_strategy = "prefer_ipv6" if direct_dns_query_strategy == "UseIPv4" then @@ -1237,7 +1238,7 @@ function gen_config(var) direct_strategy = "ipv6_only" end - local port = tonumber(direct_dns_port) or 53 + local port = tonumber(direct_dns_udp_port) or 53 table.insert(dns.servers, { tag = dns_tag, @@ -1252,6 +1253,18 @@ function gen_config(var) tag = "block", address = "rcode://refused", }) + + local default_dns_flag = "remote" + if node_id and redir_port then + local node = uci:get_all(appname, node_id) + if node.protocol == "_shunt" then + if node.default_node == "_direct" then + default_dns_flag = "direct" + end + end + else default_dns_flag = "direct" + end + dns.final = default_dns_flag table.insert(inbounds, { type = "direct", @@ -1271,18 +1284,6 @@ function gen_config(var) }, outbound = "dns-out" }) - - local default_dns_flag = "remote" - if node_id and redir_port then - local node = uci:get_all(appname, node_id) - if node.protocol == "_shunt" then - if node.default_node == "_direct" then - default_dns_flag = "direct" - end - end - else default_dns_flag = "direct" - end - dns.final = default_dns_flag end if inbounds or outbounds then @@ -1408,22 +1409,24 @@ function gen_dns_config(var) local dns_listen_port = var["-dns_listen_port"] local dns_query_strategy = var["-dns_query_strategy"] local dns_out_tag = var["-dns_out_tag"] - local dns_client_ip = var["-dns_client_ip"] - local direct_dns_server = var["-direct_dns_server"] - local direct_dns_port = var["-direct_dns_port"] local direct_dns_udp_server = var["-direct_dns_udp_server"] + local direct_dns_udp_port = var["-direct_dns_udp_port"] local direct_dns_tcp_server = var["-direct_dns_tcp_server"] + local direct_dns_tcp_port = var["-direct_dns_tcp_port"] local direct_dns_doh_url = var["-direct_dns_doh_url"] local direct_dns_doh_host = var["-direct_dns_doh_host"] - local remote_dns_server = var["-remote_dns_server"] - local remote_dns_port = var["-remote_dns_port"] + local direct_dns_doh_ip = var["-direct_dns_doh_ip"] + local direct_dns_doh_port = var["-direct_dns_doh_port"] local remote_dns_udp_server = var["-remote_dns_udp_server"] + local remote_dns_udp_port = var["-remote_dns_udp_port"] local remote_dns_tcp_server = var["-remote_dns_tcp_server"] + local remote_dns_tcp_port = var["-remote_dns_tcp_port"] local remote_dns_doh_url = var["-remote_dns_doh_url"] local remote_dns_doh_host = var["-remote_dns_doh_host"] + local remote_dns_doh_ip = var["-remote_dns_doh_ip"] + local remote_dns_doh_port = var["-remote_dns_doh_port"] local remote_dns_outbound_socks_address = var["-remote_dns_outbound_socks_address"] local remote_dns_outbound_socks_port = var["-remote_dns_outbound_socks_port"] - local remote_dns_fake = var["-remote_dns_fake"] local dns_cache = var["-dns_cache"] local log = var["-log"] or "0" local loglevel = var["-loglevel"] or "warn" @@ -1446,7 +1449,6 @@ function gen_dns_config(var) disable_expire = false, --禁用 DNS 缓存过期。 independent_cache = false, --使每个 DNS 服务器的缓存独立,以满足特殊目的。如果启用,将轻微降低性能。 reverse_mapping = true, --在响应 DNS 查询后存储 IP 地址的反向映射以为路由目的提供域名。 - fakeip = nil, } if dns_out_tag == "remote" then @@ -1456,26 +1458,18 @@ function gen_dns_config(var) strategy = (dns_query_strategy and dns_query_strategy ~= "UseIP") and "ipv4_only" or "prefer_ipv6", detour = "remote-out", } - - if remote_dns_fake then - server.address = "fakeip" - dns.fakeip = { - enabled = true, - inet4_range = "198.18.0.0/16", - inet6_range = "fc00::/18", - } - end if remote_dns_udp_server then - local server_port = tonumber(remote_dns_port) or 53 + local server_port = tonumber(remote_dns_udp_port) or 53 server.address = "udp://" .. remote_dns_udp_server .. ":" .. server_port end if remote_dns_tcp_server then - server.address = remote_dns_tcp_server + local server_port = tonumber(remote_dns_tcp_port) or 53 + server.address = "tcp://" .. remote_dns_tcp_server .. ":" .. server_port end - if remote_dns_doh_url and remote_dns_doh_host then + if remote_dns_doh_url then server.address = remote_dns_doh_url end @@ -1488,10 +1482,8 @@ function gen_dns_config(var) server_port = tonumber(remote_dns_outbound_socks_port), }) - table.insert(route.rules, { - network = {"tcp", "udp"}, - outbound = "remote-out" - }) + route.final = "remote-out" + elseif dns_out_tag == "direct" then local server = { tag = dns_out_tag, @@ -1501,17 +1493,16 @@ function gen_dns_config(var) } if direct_dns_udp_server then - local server_port = tonumber(direct_dns_port) or 53 + local server_port = tonumber(direct_dns_udp_port) or 53 server.address = "udp://" .. direct_dns_udp_server .. ":" .. server_port end if direct_dns_tcp_server then - local server_port = tonumber(direct_dns_port) or 53 - server.address = direct_dns_tcp_server .. ":" .. server_port + local server_port = tonumber(direct_dns_tcp_port) or 53 + server.address = "tcp://" .. direct_dns_tcp_server .. ":" .. server_port end - if direct_dns_doh_url and direct_dns_doh_host then - local server_port = tonumber(direct_dns_port) or 443 + if direct_dns_doh_url then server.address = direct_dns_doh_url end diff --git a/luci-app-passwall2/luasrc/passwall2/util_xray.lua b/luci-app-passwall2/luasrc/passwall2/util_xray.lua index e8e8e6a51..dafe89290 100644 --- a/luci-app-passwall2/luasrc/passwall2/util_xray.lua +++ b/luci-app-passwall2/luasrc/passwall2/util_xray.lua @@ -521,10 +521,10 @@ function gen_config(var) local local_http_password = var["-local_http_password"] local dns_listen_port = var["-dns_listen_port"] local dns_query_strategy = var["-dns_query_strategy"] - local direct_dns_port = var["-direct_dns_port"] local direct_dns_udp_server = var["-direct_dns_udp_server"] - local remote_dns_port = var["-remote_dns_port"] + local direct_dns_udp_port = var["-direct_dns_udp_port"] local remote_dns_udp_server = var["-remote_dns_udp_server"] + local remote_dns_udp_port = var["-remote_dns_udp_port"] local remote_dns_fake = var["-remote_dns_fake"] local remote_dns_fake_strategy = var["-remote_dns_fake_strategy"] local dns_cache = var["-dns_cache"] @@ -1034,56 +1034,54 @@ function gen_config(var) end) end - if true then - if remote_dns_udp_server then - local _remote_dns = { - _flag = "remote", - address = remote_dns_udp_server, - port = tonumber(remote_dns_port) or 53 - } - if not remote_dns_fake then - _remote_dns.domains = #dns_remote_domains > 0 and dns_remote_domains or nil - --_remote_dns.expectIPs = #dns_remote_expectIPs > 0 and dns_remote_expectIPs or nil - end - _remote_dns_proto = "udp" - table.insert(dns.servers, _remote_dns) - - table.insert(routing.rules, 1, { - type = "field", - ip = { - remote_dns_udp_server - }, - port = tonumber(remote_dns_port) or 53, - network = "udp", - outboundTag = "direct" - }) + if remote_dns_udp_server then + local _remote_dns = { + _flag = "remote", + address = remote_dns_udp_server, + port = tonumber(remote_dns_udp_port) or 53 + } + if not remote_dns_fake then + _remote_dns.domains = #dns_remote_domains > 0 and dns_remote_domains or nil + --_remote_dns.expectIPs = #dns_remote_expectIPs > 0 and dns_remote_expectIPs or nil end - if remote_dns_fake then - fakedns = {} - local fakedns4 = { - ipPool = "198.18.0.0/16", - poolSize = 65535 - } - local fakedns6 = { - ipPool = "fc00::/18", - poolSize = 65535 - } - if remote_dns_fake_strategy == "UseIP" then - table.insert(fakedns, fakedns4) - table.insert(fakedns, fakedns6) - elseif remote_dns_fake_strategy == "UseIPv4" then - table.insert(fakedns, fakedns4) - elseif remote_dns_fake_strategy == "UseIPv6" then - table.insert(fakedns, fakedns6) - end - local _remote_dns = { - _flag = "remote_fakedns", - address = "fakedns", - domains = #dns_remote_domains > 0 and dns_remote_domains or nil - --expectIPs = #dns_remote_expectIPs > 0 and dns_remote_expectIPs or nil - } - table.insert(dns.servers, _remote_dns) + _remote_dns_proto = "udp" + table.insert(dns.servers, _remote_dns) + + table.insert(routing.rules, 1, { + type = "field", + ip = { + remote_dns_udp_server + }, + port = tonumber(remote_dns_udp_port) or 53, + network = "udp", + outboundTag = "direct" + }) + end + if remote_dns_fake then + fakedns = {} + local fakedns4 = { + ipPool = "198.18.0.0/16", + poolSize = 65535 + } + local fakedns6 = { + ipPool = "fc00::/18", + poolSize = 65535 + } + if remote_dns_fake_strategy == "UseIP" then + table.insert(fakedns, fakedns4) + table.insert(fakedns, fakedns6) + elseif remote_dns_fake_strategy == "UseIPv4" then + table.insert(fakedns, fakedns4) + elseif remote_dns_fake_strategy == "UseIPv6" then + table.insert(fakedns, fakedns6) end + local _remote_dns = { + _flag = "remote_fakedns", + address = "fakedns", + domains = #dns_remote_domains > 0 and dns_remote_domains or nil + --expectIPs = #dns_remote_expectIPs > 0 and dns_remote_expectIPs or nil + } + table.insert(dns.servers, _remote_dns) end if true then @@ -1100,13 +1098,13 @@ function gen_config(var) if direct_dns_udp_server then _direct_dns.address = direct_dns_udp_server - _direct_dns.port = tonumber(direct_dns_port) or 53 + _direct_dns.port = tonumber(direct_dns_udp_port) or 53 table.insert(routing.rules, 1, { type = "field", ip = { direct_dns_udp_server }, - port = tonumber(direct_dns_port) or 53, + port = tonumber(direct_dns_udp_port) or 53, network = "udp", outboundTag = "direct" }) @@ -1130,8 +1128,9 @@ function gen_config(var) local direct_type_dns = { settings = { address = direct_dns_udp_server, - port = tonumber(direct_dns_port) or 53, - network = "udp" + port = tonumber(direct_dns_udp_port) or 53, + network = "udp", + nonIPQuery = "skip" }, proxySettings = { tag = "direct" @@ -1140,20 +1139,14 @@ function gen_config(var) local remote_type_dns = { settings = { address = remote_dns_udp_server, - port = tonumber(remote_dns_port) or 53, - network = _remote_dns_proto or "tcp" + port = tonumber(remote_dns_udp_port) or 53, + network = _remote_dns_proto or "tcp", + nonIPQuery = "skip" }, proxySettings = { tag = "direct" } } - local custom_type_dns = { - settings = { - address = "1.1.1.1", - port = 53, - network = "tcp", - } - } local type_dns = remote_type_dns table.insert(outbounds, { tag = "dns-out", @@ -1400,28 +1393,30 @@ function gen_dns_config(var) local dns_query_strategy = var["-dns_query_strategy"] local dns_out_tag = var["-dns_out_tag"] local dns_client_ip = var["-dns_client_ip"] - local direct_dns_server = var["-direct_dns_server"] - local direct_dns_port = var["-direct_dns_port"] local direct_dns_udp_server = var["-direct_dns_udp_server"] + local direct_dns_udp_port = var["-direct_dns_udp_port"] local direct_dns_tcp_server = var["-direct_dns_tcp_server"] + local direct_dns_tcp_port = var["-direct_dns_tcp_port"] local direct_dns_doh_url = var["-direct_dns_doh_url"] local direct_dns_doh_host = var["-direct_dns_doh_host"] - local remote_dns_server = var["-remote_dns_server"] - local remote_dns_port = var["-remote_dns_port"] + local direct_dns_doh_ip = var["-direct_dns_doh_ip"] + local direct_dns_doh_port = var["-direct_dns_doh_port"] local remote_dns_udp_server = var["-remote_dns_udp_server"] + local remote_dns_udp_port = var["-remote_dns_udp_port"] local remote_dns_tcp_server = var["-remote_dns_tcp_server"] + local remote_dns_tcp_port = var["-remote_dns_tcp_port"] local remote_dns_doh_url = var["-remote_dns_doh_url"] local remote_dns_doh_host = var["-remote_dns_doh_host"] + local remote_dns_doh_ip = var["-remote_dns_doh_ip"] + local remote_dns_doh_port = var["-remote_dns_doh_port"] local remote_dns_outbound_socks_address = var["-remote_dns_outbound_socks_address"] local remote_dns_outbound_socks_port = var["-remote_dns_outbound_socks_port"] - local remote_dns_fake = var["-remote_dns_fake"] local dns_cache = var["-dns_cache"] local loglevel = var["-loglevel"] or "warning" local inbounds = {} local outbounds = {} local dns = nil - local fakedns = nil local routing = nil if dns_listen_port then @@ -1447,46 +1442,31 @@ function gen_dns_config(var) local _remote_dns = { _flag = "remote" } - - if remote_dns_fake then - remote_dns_server = "1.1.1.1" - fakedns = {} - fakedns[#fakedns + 1] = { - ipPool = "198.18.0.0/16", - poolSize = 65535 - } - if dns_query_strategy == "UseIP" then - fakedns[#fakedns + 1] = { - ipPool = "fc00::/18", - poolSize = 65535 - } - end - _remote_dns.address = "fakedns" - end - - other_type_dns_port = tonumber(remote_dns_port) or 53 - other_type_dns_server = remote_dns_server if remote_dns_udp_server then _remote_dns.address = remote_dns_udp_server - _remote_dns.port = tonumber(remote_dns_port) or 53 + _remote_dns.port = tonumber(remote_dns_udp_port) or 53 + other_type_dns_proto = "udp" + other_type_dns_server = remote_dns_udp_server + other_type_dns_port = _remote_dns.port end if remote_dns_tcp_server then - _remote_dns.address = remote_dns_tcp_server - _remote_dns.port = tonumber(remote_dns_port) or 53 + _remote_dns.address = "tcp://" .. remote_dns_tcp_server + _remote_dns.port = tonumber(remote_dns_tcp_port) or 53 + other_type_dns_proto = "tcp" + other_type_dns_server = remote_dns_tcp_server + other_type_dns_port = _remote_dns.port end if remote_dns_doh_url and remote_dns_doh_host then - if remote_dns_server and remote_dns_doh_host ~= remote_dns_server and not api.is_ip(remote_dns_doh_host) then - dns.hosts[remote_dns_doh_host] = remote_dns_server + if remote_dns_doh_ip and remote_dns_doh_host ~= remote_dns_doh_ip and not api.is_ip(remote_dns_doh_host) then + dns.hosts[remote_dns_doh_host] = remote_dns_doh_ip end _remote_dns.address = remote_dns_doh_url - _remote_dns.port = tonumber(remote_dns_port) or 443 - other_type_dns_proto = "tcp" - other_type_dns_port = 53 + _remote_dns.port = tonumber(remote_dns_doh_port) or 443 end table.insert(dns.servers, _remote_dns) @@ -1510,44 +1490,40 @@ function gen_dns_config(var) local _direct_dns = { _flag = "direct" } - - other_type_dns_proto = tonumber(direct_dns_port) or 53 - other_type_dns_server = direct_dns_server if direct_dns_udp_server then _direct_dns.address = direct_dns_udp_server - _direct_dns.port = tonumber(direct_dns_port) or 53 + _direct_dns.port = tonumber(direct_dns_udp_port) or 53 table.insert(routing.rules, 1, { type = "field", ip = { direct_dns_udp_server }, - port = tonumber(direct_dns_port) or 53, + port = tonumber(direct_dns_udp_port) or 53, network = "udp", outboundTag = "direct" }) - end - if direct_dns_udp_server then - _direct_dns.address = direct_dns_udp_server - _direct_dns.port = tonumber(direct_dns_port) or 53 other_type_dns_proto = "udp" + other_type_dns_server = direct_dns_udp_server + other_type_dns_port = _direct_dns.port end if direct_dns_tcp_server then - _direct_dns.address = direct_dns_tcp_server:gsub("tcp://", "tcp+local://") - _direct_dns.port = tonumber(direct_dns_port) or 53 + _direct_dns.address = "tcp+local://" .. direct_dns_tcp_server + _direct_dns.port = tonumber(direct_dns_tcp_port) or 53 + other_type_dns_proto = "tcp" + other_type_dns_server = direct_dns_tcp_server + other_type_dns_port = _direct_dns.port end if direct_dns_doh_url and direct_dns_doh_host then - if direct_dns_server and direct_dns_doh_host ~= direct_dns_server and not api.is_ip(direct_dns_doh_host) then - dns.hosts[direct_dns_doh_host] = direct_dns_server + if direct_dns_doh_ip and direct_dns_doh_host ~= direct_dns_doh_ip and not api.is_ip(direct_dns_doh_host) then + dns.hosts[direct_dns_doh_host] = direct_dns_doh_ip end _direct_dns.address = direct_dns_doh_url:gsub("https://", "https+local://") - _direct_dns.port = tonumber(direct_dns_port) or 443 - other_type_dns_proto = "tcp" - other_type_dns_port = 53 + _direct_dns.port = tonumber(direct_dns_doh_port) or 443 end table.insert(dns.servers, _direct_dns) @@ -1597,6 +1573,7 @@ function gen_dns_config(var) address = other_type_dns_server or "1.1.1.1", port = other_type_dns_port or 53, network = other_type_dns_proto or "tcp", + nonIPQuery = "skip" } }) @@ -1625,7 +1602,6 @@ function gen_dns_config(var) }, -- DNS dns = dns, - fakedns = fakedns, -- 传入连接 inbounds = inbounds, -- 传出连接 diff --git a/luci-app-passwall2/luasrc/view/passwall2/global/faq.htm b/luci-app-passwall2/luasrc/view/passwall2/global/faq.htm index da3e0290d..1c96859cd 100644 --- a/luci-app-passwall2/luasrc/view/passwall2/global/faq.htm +++ b/luci-app-passwall2/luasrc/view/passwall2/global/faq.htm @@ -1,15 +1,48 @@ <% local api = require "luci.passwall2.api" -%> -