luci: add TUIC support to sing-box server

This commit is contained in:
xiaorouji 2023-09-06 16:18:07 +08:00 committed by sbwml
parent bd5d6d1d1f
commit 292b2f746f
2 changed files with 41 additions and 0 deletions

View File

@ -59,6 +59,9 @@ o:value("naive", "Naive")
if singbox_tags:find("with_quic") then if singbox_tags:find("with_quic") then
o:value("hysteria", "Hysteria") o:value("hysteria", "Hysteria")
end end
if singbox_tags:find("with_quic") then
o:value("tuic", "TUIC")
end
o:value("direct", "Direct") o:value("direct", "Direct")
o = s:option(Value, option_name("port"), translate("Listen Port")) o = s:option(Value, option_name("port"), translate("Listen Port"))
@ -88,6 +91,7 @@ o.password = true
o:depends({ [option_name("auth")] = true }) o:depends({ [option_name("auth")] = true })
o:depends({ [option_name("protocol")] = "shadowsocks" }) o:depends({ [option_name("protocol")] = "shadowsocks" })
o:depends({ [option_name("protocol")] = "naive" }) o:depends({ [option_name("protocol")] = "naive" })
o:depends({ [option_name("protocol")] = "tuic" })
if singbox_tags:find("with_quic") then if singbox_tags:find("with_quic") then
o = s:option(Value, option_name("hysteria_up_mbps"), translate("Max upload Mbps")) o = s:option(Value, option_name("hysteria_up_mbps"), translate("Max upload Mbps"))
@ -129,6 +133,24 @@ if singbox_tags:find("with_quic") then
o:depends({ [option_name("protocol")] = "hysteria" }) o:depends({ [option_name("protocol")] = "hysteria" })
end end
if singbox_tags:find("with_quic") then
o = s:option(ListValue, option_name("tuic_congestion_control"), translate("Congestion control algorithm"))
o.default = "cubic"
o:value("bbr", translate("BBR"))
o:value("cubic", translate("CUBIC"))
o:value("new_reno", translate("New Reno"))
o:depends({ [option_name("protocol")] = "tuic" })
o = s:option(Flag, option_name("tuic_zero_rtt_handshake"), translate("Enable 0-RTT QUIC handshake"))
o.default = 0
o:depends({ [option_name("protocol")] = "tuic" })
o = s:option(Value, option_name("tuic_heartbeat"), translate("Heartbeat interval(second)"))
o.datatype = "uinteger"
o.default = "3"
o:depends({ [option_name("protocol")] = "tuic" })
end
o = s:option(ListValue, option_name("d_protocol"), translate("Destination protocol")) o = s:option(ListValue, option_name("d_protocol"), translate("Destination protocol"))
o:value("tcp", "TCP") o:value("tcp", "TCP")
o:value("udp", "UDP") o:value("udp", "UDP")
@ -166,6 +188,7 @@ end
o:depends({ [option_name("protocol")] = "vmess" }) o:depends({ [option_name("protocol")] = "vmess" })
o:depends({ [option_name("protocol")] = "vless" }) o:depends({ [option_name("protocol")] = "vless" })
o:depends({ [option_name("protocol")] = "trojan" }) o:depends({ [option_name("protocol")] = "trojan" })
o:depends({ [option_name("protocol")] = "tuic" })
o = s:option(ListValue, option_name("flow"), translate("flow")) o = s:option(ListValue, option_name("flow"), translate("flow"))
o.default = "" o.default = ""
@ -199,6 +222,7 @@ o = s:option(FileUpload, option_name("tls_certificateFile"), translate("Public k
o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem" o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem"
o:depends({ [option_name("tls")] = true }) o:depends({ [option_name("tls")] = true })
o:depends({ [option_name("protocol")] = "hysteria" }) o:depends({ [option_name("protocol")] = "hysteria" })
o:depends({ [option_name("protocol")] = "tuic" })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not nixio.fs.access(value) then
@ -214,6 +238,7 @@ o = s:option(FileUpload, option_name("tls_keyFile"), translate("Private key abso
o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key" o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key"
o:depends({ [option_name("tls")] = true }) o:depends({ [option_name("tls")] = true })
o:depends({ [option_name("protocol")] = "hysteria" }) o:depends({ [option_name("protocol")] = "hysteria" })
o:depends({ [option_name("protocol")] = "tuic" })
o.validate = function(self, value, t) o.validate = function(self, value, t)
if value and value ~= "" then if value and value ~= "" then
if not nixio.fs.access(value) then if not nixio.fs.access(value) then

View File

@ -524,6 +524,22 @@ function gen_config_server(node)
} }
end end
if node.protocol == "tuic" then
protocol_table = {
users = {
{
name = "user1",
uuid = node.uuid,
password = node.password
}
},
congestion_control = node.tuic_congestion_control or "cubic",
zero_rtt_handshake = (node.tuic_zero_rtt_handshake == "1") and true or false,
heartbeat = node.tuic_heartbeat .. "s",
tls = tls,
}
end
if node.protocol == "direct" then if node.protocol == "direct" then
protocol_table = { protocol_table = {
network = (node.d_protocol ~= "TCP,UDP") and node.d_protocol or nil, network = (node.d_protocol ~= "TCP,UDP") and node.d_protocol or nil,