From 0fbcb7de2eb302caa0f07a477163599e87fae68f Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:19:00 +0800 Subject: [PATCH] luci: add Hysteria2 support to sing-box server --- .../cbi/passwall/server/type/sing-box.lua | 29 +++++++++++++++++++ .../luasrc/passwall/util_sing-box.lua | 19 ++++++++++++ luci-app-passwall/po/zh-cn/passwall.po | 3 ++ 3 files changed, 51 insertions(+) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua index 44eefa99a..28b1bd885 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua @@ -62,6 +62,9 @@ end 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("direct", "Direct") o = s:option(Value, option_name("port"), translate("Listen Port")) @@ -151,6 +154,30 @@ if singbox_tags:find("with_quic") then o:depends({ [option_name("protocol")] = "tuic" }) end +if singbox_tags:find("with_quic") then + o = s:option(Flag, option_name("hysteria2_ignore_client_bandwidth"), translate("Commands the client to use the BBR flow control algorithm")) + o.default = 0 + o:depends({ [option_name("protocol")] = "hysteria2" }) + + o = s:option(Value, option_name("hysteria2_up_mbps"), translate("Max upload Mbps")) + o:depends({ [option_name("protocol")] = "hysteria2", [option_name("hysteria2_ignore_client_bandwidth")] = false }) + + o = s:option(Value, option_name("hysteria2_down_mbps"), translate("Max download Mbps")) + o:depends({ [option_name("protocol")] = "hysteria2", [option_name("hysteria2_ignore_client_bandwidth")] = false }) + + 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(ListValue, option_name("d_protocol"), translate("Destination protocol")) o:value("tcp", "TCP") o:value("udp", "UDP") @@ -223,6 +250,7 @@ o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg 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.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then @@ -239,6 +267,7 @@ o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. " 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.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index b90f67269..a8e155f66 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -540,6 +540,25 @@ function gen_config_server(node) } end + if node.protocol == "hysteria2" then + protocol_table = { + up_mbps = (node.hysteria2_ignore_client_bandwidth ~= "1" and node.hysteria2_up_mbps and tonumber(node.hysteria2_up_mbps)) and tonumber(node.hysteria2_up_mbps) or nil, + down_mbps = (node.hysteria2_ignore_client_bandwidth ~= "1" and 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 + }, + users = { + { + name = "user1", + password = node.hysteria2_auth_password or nil, + } + }, + ignore_client_bandwidth = (node.hysteria2_ignore_client_bandwidth == "1") and true or false, + tls = tls, + } + end + if node.protocol == "direct" then protocol_table = { network = (node.d_protocol ~= "TCP,UDP") and node.d_protocol or nil, diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index 884aa04c4..eff910ab5 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -493,6 +493,9 @@ msgstr "认证类型" msgid "Auth Password" msgstr "认证密码" +msgid "Commands the client to use the BBR flow control algorithm" +msgstr "命令客户端使用 BBR 流量控制算法" + msgid "Max upload Mbps" msgstr "最大上行(Mbps)"