Browse Source

luci-app-ssr-plus: add v2ray ssr support

Signed-off-by: Tianling Shen <[email protected]>
Tianling Shen 3 years ago
parent
commit
545a7f118b

+ 8 - 1
luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua

@@ -186,6 +186,7 @@ o:value("vmess", translate("VMess"))
 o:value("trojan", translate("Trojan"))
 o:value("shadowsocks", translate("Shadowsocks"))
 if is_installed("sagernet-core") then
+	o:value("shadowsocksr", translate("ShadowsocksR"))
 	o:value("wireguard", translate("WireGuard"))
 end
 o:value("socks", translate("Socks"))
@@ -239,6 +240,7 @@ o:depends({type = "socks5", auth_enable = true})
 o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
 o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
 o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 o:depends({type = "v2ray", v2ray_protocol = "trojan"})
 
 o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
@@ -247,6 +249,7 @@ for _, v in ipairs(encrypt_methods) do
 end
 o.rmempty = true
 o:depends("type", "ssr")
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 
 o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
 for _, v in ipairs(encrypt_methods_ss) do
@@ -270,7 +273,7 @@ o.default = "1"
 -- Shadowsocks Plugin
 o = s:option(Value, "plugin", translate("Obfs"))
 o:value("none", translate("None"))
-if is_finded("obfs-local") then
+if is_finded("obfs-local") or is_installed("sagernet-core") then
 	o:value("obfs-local", translate("obfs-local"))
 end
 if is_finded("v2ray-plugin") or is_installed("sagernet-core") then
@@ -298,9 +301,11 @@ for _, v in ipairs(protocol) do
 end
 o.rmempty = true
 o:depends("type", "ssr")
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 
 o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
 o:depends("type", "ssr")
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 
 o = s:option(ListValue, "obfs", translate("Obfs"))
 for _, v in ipairs(obfs) do
@@ -308,9 +313,11 @@ for _, v in ipairs(obfs) do
 end
 o.rmempty = true
 o:depends("type", "ssr")
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 
 o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
 o:depends("type", "ssr")
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
 
 -- [[ Hysteria ]]--
 o = s:option(ListValue, "hysteria_protocol", translate("Protocol"))

+ 14 - 2
luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua

@@ -32,14 +32,21 @@ function vmess_vless()
 end
 function trojan_shadowsocks()
 	outbound_settings = {
-		plugin = (server.v2ray_protocol == "shadowsocks") and server.plugin ~= "none" and server.plugin or nil,
+		plugin = ((server.v2ray_protocol == "shadowsocks") and server.plugin ~= "none" and server.plugin) or (server.v2ray_protocol == "shadowsocksr" and "shadowsocksr") or nil,
 		pluginOpts = (server.v2ray_protocol == "shadowsocks") and server.plugin_opts or nil,
+		pluginArgs = (server.v2ray_protocol == "shadowsocksr") and {
+			"--protocol=" .. server.protocol,
+			"--protocol-param=" .. (server.protocol_param or ""),
+			"--obfs=" .. server.obfs,
+			"--obfs-param=" .. (server.obfs_param or "")
+		} or nil,
 		servers = {
 			{
 				address = server.server,
 				port = tonumber(server.server_port),
 				password = server.password,
 				method = (server.v2ray_protocol == "shadowsocks") and server.encrypt_method_ss or nil,
+				method = (server.v2ray_protocol == "shadowsocksr") and server.encrypt_method or nil,
 				uot = (server.v2ray_protocol == "shadowsocks") and (server.uot == '1') or nil,
 				ivCheck = (server.v2ray_protocol == "shadowsocks") and (server.ivCheck == '1') or nil,
 				flow = (server.v2ray_protocol == "trojan") and (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-splice") or nil
@@ -47,7 +54,9 @@ function trojan_shadowsocks()
 		}
 	}
 
-	if (server.v2ray_protocol == "shadowsocks") and (server.mux ~= "1") and (not (outbound_settings.plugin or server.transport ~= "tcp" or server.tls or server.xtls)) then
+	if server.v2ray_protocol == "shadowsocksr" then
+		server.v2ray_protocol = "shadowsocks"
+	elseif (server.v2ray_protocol == "shadowsocks") and (server.mux ~= "1") and (not (outbound_settings.plugin or server.transport ~= "tcp" or server.tls or server.xtls)) then
 		server.v2ray_protocol = "shadowsocks_sing"
 		outbound_settings = outbound_settings.servers[1]
 	elseif (server.v2ray_protocol == "trojan") and (server.tls and server.mux ~= "1") and (not (server.transport ~= "tcp" or server.xtls)) then
@@ -106,6 +115,9 @@ function outbound:handleIndex(index)
 		shadowsocks = function()
 			trojan_shadowsocks()
 		end,
+		shadowsocksr = function()
+			trojan_shadowsocks()
+		end,
 		socks = function()
 			socks_http()
 		end,

+ 3 - 0
luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua

@@ -28,6 +28,7 @@ local filter_words = ucic:get_first(name, 'server_subscribe', 'filter_words', '
 local save_words = ucic:get_first(name, 'server_subscribe', 'save_words', '')
 local packet_encoding = luci.model.ipkg.installed("sagernet-core") and ucic:get_first(name, 'global', 'default_packet_encoding', 'xudp') or nil
 local v2_ss = luci.sys.exec('type -t -p ss-redir sslocal') ~= "" and "ss" or "v2ray"
+local v2_ssr = luci.sys.exec('type -t -p ssr-redir') ~= "" and "ssr" or "v2ray"
 local v2_tj = luci.sys.exec('type -t -p trojan') ~= "" and "trojan" or "v2ray"
 local log = function(...)
 	print(os.date("%Y-%m-%d %H:%M:%S ") .. table.concat({...}, " "))
@@ -147,6 +148,8 @@ local function processData(szType, content)
 	if szType == 'ssr' then
 		local dat = split(content, "/%?")
 		local hostInfo = split(dat[1], ':')
+		result.type = v2_ssr
+		result.v2ray_protocol = (v2_ssr == "v2ray") and "shadowsocksr" or nil
 		result.server = hostInfo[1]
 		result.server_port = hostInfo[2]
 		result.protocol = hostInfo[3]