From c7818a6946228f72c8b3d4c5112c6773e3d27625 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:09:26 +0800 Subject: [PATCH] luci: add Hysteria support to sing-box client --- .../cbi/passwall/client/type/sing-box.lua | 41 +++++++++++++++++++ .../luasrc/passwall/util_sing-box.lua | 23 +++++++++++ 2 files changed, 64 insertions(+) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua index 4aaec6aad..3403a201a 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/type/sing-box.lua @@ -67,6 +67,9 @@ o:value("trojan", "Trojan") if singbox_tags:find("with_wireguard") then o:value("wireguard", "WireGuard") end +if singbox_tags:find("with_quic") then + o:value("hysteria", "Hysteria") +end o:value("shadowtls", "ShadowTLS") o:value("vless", "VLESS") o:value("_shunt", translate("Shunt")) @@ -283,6 +286,42 @@ o:value("", translate("Disable")) o:value("xtls-rprx-vision") o:depends({ [option_name("protocol")] = "vless", [option_name("tls")] = true }) +if singbox_tags:find("with_quic") then + o = s:option(Value, option_name("hysteria_obfs"), translate("Obfs Password")) + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(ListValue, option_name("hysteria_auth_type"), translate("Auth Type")) + o:value("disable", translate("Disable")) + o:value("string", translate("STRING")) + o:value("base64", translate("BASE64")) + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Value, option_name("hysteria_auth_password"), translate("Auth Password")) + o.password = true + o:depends({ [option_name("protocol")] = "hysteria", [option_name("hysteria_auth_type")] = "string"}) + o:depends({ [option_name("protocol")] = "hysteria", [option_name("hysteria_auth_type")] = "base64"}) + + o = s:option(Value, option_name("hysteria_up_mbps"), translate("Max upload Mbps")) + o.default = "10" + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Value, option_name("hysteria_down_mbps"), translate("Max download Mbps")) + o.default = "50" + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Value, option_name("hysteria_recv_window_conn"), translate("QUIC stream receive window")) + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Value, option_name("hysteria_recv_window"), translate("QUIC connection receive window")) + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Flag, option_name("hysteria_disable_mtu_discovery"), translate("Disable MTU detection")) + o:depends({ [option_name("protocol")] = "hysteria" }) + + o = s:option(Value, option_name("hysteria_alpn"), translate("QUIC TLS ALPN")) + o:depends({ [option_name("protocol")] = "hysteria" }) +end + o = s:option(Flag, option_name("tls"), translate("TLS")) o.default = 0 o:depends({ [option_name("protocol")] = "vmess" }) @@ -315,10 +354,12 @@ o:depends({ [option_name("tls")] = true }) o = s:option(Value, option_name("tls_serverName"), translate("Domain")) o:depends({ [option_name("tls")] = true }) +o:depends({ [option_name("protocol")] = "hysteria"}) o = s:option(Flag, option_name("tls_allowInsecure"), translate("allowInsecure"), translate("Whether unsafe connections are allowed. When checked, Certificate validation will be skipped.")) o.default = "0" o:depends({ [option_name("tls")] = true }) +o:depends({ [option_name("protocol")] = "hysteria"}) if singbox_tags:find("with_utls") then o = s:option(Flag, option_name("utls"), translate("uTLS")) diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index ac760becb..ae2087d99 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -262,6 +262,29 @@ function gen_outbound(flag, node, tag, proxy_table) } end + if node.protocol == "hysteria" then + protocol_table = { + up = node.hysteria_up_mbps .. " Mbps", + down = node.hysteria_down_mbps .. " Mbps", + up_mbps = tonumber(node.hysteria_up_mbps), + down_mbps = tonumber(node.hysteria_down_mbps), + 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, + recv_window_conn = tonumber(node.hysteria_recv_window_conn), + recv_window = tonumber(node.hysteria_recv_window), + disable_mtu_discovery = (node.hysteria_disable_mtu_discovery == "1") and true or false, + tls = { + enabled = true, + server_name = node.tls_serverName, + insecure = (node.tls_allowInsecure == "1") and true or false, + alpn = (node.hysteria_alpn and node.hysteria_alpn ~= "") and { + node.hysteria_alpn + } or nil + } + } + end + if node.protocol == "shadowtls" then protocol_table = { version = tonumber(node.shadowtls_version),