From 4262fe42385a8c09a851a87a6252b11c5275ddf3 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:12:34 +0800 Subject: [PATCH] luci: add Hysteria2 support to sing-box client --- .../cbi/passwall/client/type/sing-box.lua | 25 +++++++++++++++++++ .../luasrc/passwall/util_sing-box.lua | 13 ++++++++++ luci-app-passwall/po/zh-cn/passwall.po | 3 +++ 3 files changed, 41 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 ca5e248ab..0d12290c9 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 @@ -75,6 +75,9 @@ o:value("vless", "VLESS") if singbox_tags:find("with_quic") then o:value("tuic", "TUIC") end +if singbox_tags:find("with_quic") then + o:value("hysteria2", "Hysteria2") +end o:value("_shunt", translate("Shunt")) o:value("_iface", translate("Custom Interface") .. " (Only Support Xray)") @@ -356,6 +359,26 @@ if singbox_tags:find("with_quic") then o:depends({ [option_name("protocol")] = "tuic" }) end +if singbox_tags:find("with_quic") then + o = s:option(Value, option_name("hysteria2_up_mbps"), translate("Max upload Mbps")) + o:depends({ [option_name("protocol")] = "hysteria2" }) + + o = s:option(Value, option_name("hysteria2_down_mbps"), translate("Max download Mbps")) + o:depends({ [option_name("protocol")] = "hysteria2" }) + + o = s:option(ListValue, option_name("hysteria2_obfs_type"), translate("Obfs Type")) + o:value("", translate("Disable")) + o:value("salamander") + o:depends({ [option_name("protocol")] = "hysteria2" }) + + o = s:option(Value, option_name("hysteria2_obfs_password"), translate("Obfs Password")) + o:depends({ [option_name("protocol")] = "hysteria2" }) + + o = s:option(Value, option_name("hysteria2_auth_password"), translate("Auth Password")) + o.password = true + o:depends({ [option_name("protocol")] = "hysteria2"}) +end + o = s:option(Flag, option_name("tls"), translate("TLS")) o.default = 0 o:depends({ [option_name("protocol")] = "vmess" }) @@ -390,12 +413,14 @@ o = s:option(Value, option_name("tls_serverName"), translate("Domain")) o:depends({ [option_name("tls")] = true }) o:depends({ [option_name("protocol")] = "hysteria"}) o:depends({ [option_name("protocol")] = "tuic" }) +o:depends({ [option_name("protocol")] = "hysteria2" }) 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"}) o:depends({ [option_name("protocol")] = "tuic" }) +o:depends({ [option_name("protocol")] = "hysteria2" }) 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 800ad9516..d17326887 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -306,6 +306,19 @@ function gen_outbound(flag, node, tag, proxy_table) } end + if node.protocol == "hysteria2" then + protocol_table = { + up_mbps = (node.hysteria2_up_mbps and tonumber(node.hysteria2_up_mbps)) and tonumber(node.hysteria2_up_mbps) or nil, + down_mbps = (node.hysteria2_down_mbps and tonumber(node.hysteria2_down_mbps)) and tonumber(node.hysteria2_down_mbps) or nil, + obfs = { + type = node.hysteria2_obfs_type, + password = node.hysteria2_obfs_password + }, + password = node.hysteria2_auth_password or nil, + tls = tls, + } + end + if protocol_table then for key, value in pairs(protocol_table) do result[key] = value diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index 8d77f61b0..df0d597d5 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -481,6 +481,9 @@ msgstr "传输层插件" msgid "Shadowsocks secondary encryption" msgstr "Shadowsocks 二次加密" +msgid "Obfs Type" +msgstr "混淆类型" + msgid "Obfs Password" msgstr "混淆密码"