From bc3a38eaac5035dc41c2b6e874a0d23a14c7ffe7 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:03:12 +0800 Subject: [PATCH] luci: add SSR support to sing-box client The ShadowsocksR protocol is obsolete and unmaintained. This outbound is provided for compatibility only. --- .../cbi/passwall/client/type/sing-box.lua | 45 +++++++++++++++++++ .../luasrc/passwall/util_sing-box.lua | 11 +++++ 2 files changed, 56 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 5ebc6a196..358c8b82f 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 @@ -59,6 +59,9 @@ o = s:option(ListValue, option_name("protocol"), translate("Protocol")) o:value("socks", "Socks") o:value("http", "HTTP") o:value("shadowsocks", "Shadowsocks") +if singbox_tags:find("with_shadowsocksr") then + o:value("shadowsocksr", "ShadowsocksR") +end o:value("vmess", "Vmess") o:value("trojan", "Trojan") if singbox_tags:find("with_wireguard") then @@ -192,6 +195,7 @@ o.password = true o:depends({ [option_name("protocol")] = "http" }) o:depends({ [option_name("protocol")] = "socks" }) o:depends({ [option_name("protocol")] = "shadowsocks" }) +o:depends({ [option_name("protocol")] = "shadowsocksr" }) o:depends({ [option_name("protocol")] = "trojan" }) o = s:option(ListValue, option_name("security"), translate("Encrypt Method")) @@ -212,6 +216,47 @@ function o.write(self, section, value) end end +if singbox_tags:find("with_shadowsocksr") then + o = s:option(ListValue, option_name("ssr_method"), translate("Encrypt Method")) + o.not_rewrite = true + for a, t in ipairs(ss_method_old_list) do o:value(t) end + o:depends({ [option_name("protocol")] = "shadowsocksr" }) + function o.cfgvalue(self, section) + return m:get(section, "method") + end + function o.write(self, section, value) + if s.fields["type"]:formvalue(arg[1]) == type_name then + m:set(section, "method", value) + end + end + + local ssr_protocol_list = { + "origin", "verify_simple", "verify_deflate", "verify_sha1", "auth_simple", + "auth_sha1", "auth_sha1_v2", "auth_sha1_v4", "auth_aes128_md5", + "auth_aes128_sha1", "auth_chain_a", "auth_chain_b", "auth_chain_c", + "auth_chain_d", "auth_chain_e", "auth_chain_f" + } + + o = s:option(ListValue, option_name("ssr_protocol"), translate("Protocol")) + for a, t in ipairs(ssr_protocol_list) do o:value(t) end + o:depends({ [option_name("protocol")] = "shadowsocksr" }) + + o = s:option(Value, option_name("ssr_protocol_param"), translate("Protocol_param")) + o:depends({ [option_name("protocol")] = "shadowsocksr" }) + + local ssr_obfs_list = { + "plain", "http_simple", "http_post", "random_head", "tls_simple", + "tls1.0_session_auth", "tls1.2_ticket_auth" + } + + o = s:option(ListValue, option_name("ssr_obfs"), translate("Obfs")) + for a, t in ipairs(ssr_obfs_list) do o:value(t) end + o:depends({ [option_name("protocol")] = "shadowsocksr" }) + + o = s:option(Value, option_name("ssr_obfs_param"), translate("Obfs_param")) + o:depends({ [option_name("protocol")] = "shadowsocksr" }) +end + o = s:option(Flag, option_name("uot"), translate("UDP over TCP"), translate("Need Xray-core or sing-box as server side.")) o:depends({ [option_name("protocol")] = "shadowsocks", [option_name("ss_method")] = "2022-blake3-aes-128-gcm" }) o:depends({ [option_name("protocol")] = "shadowsocks", [option_name("ss_method")] = "2022-blake3-aes-256-gcm" }) diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index 6bfbb2e0b..348b0b27b 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -191,6 +191,17 @@ function gen_outbound(flag, node, tag, proxy_table) } end + if node.protocol == "shadowsocksr" then + protocol_table = { + method = node.method or nil, + password = node.password or "", + obfs = node.ssr_obfs, + obfs_param = node.ssr_obfs_param, + protocol = node.ssr_protocol, + protocol_param = node.ssr_protocol_param, + } + end + if node.protocol == "trojan" then protocol_table = { password = node.password,