Explorar el Código

luci-app-ssr-plus: Enable alpn and optimize code. (#1790)

Co-authored-by: zxlhhyccc <[email protected]>
zxl hhyccc hace 1 mes
padre
commit
ef1a45581e

+ 2 - 3
luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua

@@ -832,7 +832,7 @@ o:depends({type = "v2ray", v2ray_protocol = "http"})
 o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
 o:depends("transport", "raw")
 o:value("none", translate("None"))
-o:value("http", "HTTP")
+o:value("http", translate("HTTP"))
 o.rmempty = true
 
 -- HTTP域名
@@ -1277,8 +1277,8 @@ o:value("h3,h2")
 o:value("http/1.1")
 o:value("h2,http/1.1")
 o:value("h3,h2,http/1.1")
+o:depends("tls", true)
 o:depends({type = "hysteria2", tls = true})
-o:depends({transport = "xhttp", tls = true})
 
 -- TUIC ALPN
 o = s:option(ListValue, "tuic_alpn", translate("TUIC ALPN"))
@@ -1309,7 +1309,6 @@ o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls_flow
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "ws"})
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp"})
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "httpupgrade"})
-o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp"})
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "h2"})
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "quic"})
 o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "grpc"})

+ 16 - 19
luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm

@@ -307,7 +307,7 @@ function import_ssr_url(btn, urlname, sid) {
 			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
 			return false;
 		case "ssr":
-			var sstr = b64decsafe(ssu[1]);
+			var sstr = b64decsafe((ssu[1] || "").replace(/#.*/, "").trim());
 			var ploc = sstr.indexOf("/?");
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].value = ssu[0];
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].dispatchEvent(event);
@@ -375,9 +375,7 @@ function import_ssr_url(btn, urlname, sid) {
 				(params.get("type") || "raw")));
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.transport')[0].dispatchEvent(event);
 			if (params.get("security") === "tls") {
-				if (params.get("type") == "xhttp" || params.get("type") == "splithttp") {
-					document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_alpn')[0].value = params.get("alpn") || "";
-				}
+				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_alpn')[0].value = params.get("alpn") || "";
 				document.getElementsByName('cbid.shadowsocksr.' + sid + '.fingerprint')[0].value = params.get("fp") || "";
 			}
 			switch (params.get("type")) {
@@ -437,7 +435,7 @@ function import_ssr_url(btn, urlname, sid) {
 			s.innerHTML = "<font style=\'color:green\'><%:Import configuration information successfully.%></font>";
 			return false;
 		case "vmess":
-			var sstr = b64DecodeUnicode(ssu[1]);
+			var sstr = b64DecodeUnicode((ssu[1] || "").replace(/#.*/, "").trim());
 			var ploc = sstr.indexOf("/?");
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].value = "v2ray";
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].dispatchEvent(event);
@@ -455,18 +453,17 @@ function import_ssr_url(btn, urlname, sid) {
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.alter_id')[0].value = ssm.aid;
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.vmess_id')[0].value = ssm.id;
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.transport')[0].value = 
-				(ssm.net === "raw" || ssm.net === "tcp") ? "raw" : 
-				(ssm.net === "xhttp" || ssm.net === "splithttp") ? "xhttp" : ssm.net;
+				(["xhttp", "splithttp"].includes(ssm.net) ? "xhttp" : 
+				(["tcp", "raw"].includes(ssm.net) ? "raw" : 
+				(ssm.net || "raw")));
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.transport')[0].dispatchEvent(event);
 			if (ssm.net === "raw" || ssm.net === "tcp") {
-				if (ssm.type && ssm.type != "http") {
-					ssm.type = "none";
-				} else {
+				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].value = ssm.type;
+				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].dispatchEvent(event);
+				if (ssm.type === "http") {
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.http_host')[0].value = ssm.host;
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.http_path')[0].value = ssm.path;
 				}
-				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].value = ssm.type;
-				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tcp_guise')[0].dispatchEvent(event);
 			}
 			if (ssm.net == "ws") {
 				document.getElementsByName('cbid.shadowsocksr.' + sid + '.ws_host')[0].value = ssm.host;
@@ -503,20 +500,20 @@ function import_ssr_url(btn, urlname, sid) {
 				if (ssm.fp !== "" && ssm.fp !== undefined) {
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.fingerprint')[0].value = ssm.fp;
 				}
-				if (ssm.net == "xhttp" || ssm.net == "splithttp") {
+				if (ssm.alpn !== "" && ssm.alpn !== undefined) {
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_alpn')[0].value = ssm.alpn;
 				}
-				document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_host')[0].value = ssm.sni || ssm.host;
+				if (ssm.host !== "" && ssm.host !== undefined) {
+					document.getElementsByName('cbid.shadowsocksr.' + sid + '.tls_host')[0].value = ssm.sni || ssm.host;
+				}
 				if (ssm.ech !== "" && ssm.ech !== undefined) {
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.enable_ech')[0].checked = true; // 设置 enable_ech 为 true
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.enable_ech')[0].dispatchEvent(event); // 触发事件
 					document.getElementsByName('cbid.shadowsocksr.' + sid + '.ech_config')[0].value = ssm.ech;
 				}
-				if (((ssm.allowInsecure !== undefined) ? ssm.allowInsecure : ssm.allowlnsecure) === "true" ||
-				((ssm.allowInsecure !== undefined) ? ssm.allowInsecure : ssm.allowlnsecure) === "1") {
-					document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].checked = true; // 设置 insecure 为 true
-					document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].dispatchEvent(event); // 触发事件
-				}
+				document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].checked =
+					!!(ssm.allowInsecure ?? ssm.allowlnsecure ?? ssm['skip-cert-verify']); // 设置 insecure 为 true
+				document.getElementsByName('cbid.shadowsocksr.' + sid + '.insecure')[0].dispatchEvent(event); // 触发事件
 			}
 			if (ssm.mux !== undefined) {
 				document.getElementsByName('cbid.shadowsocksr.' + sid + '.mux')[0].checked = true;

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 190 - 177
luci-app-ssr-plus/po/templates/ssr-plus.pot


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 182 - 169
luci-app-ssr-plus/po/zh_Hans/ssr-plus.po


+ 26 - 21
luci-app-ssr-plus/root/usr/share/shadowsocksr/gen_config.lua

@@ -212,13 +212,11 @@ end
 				security = (server.xtls == '1') and "xtls" or (server.tls == '1') and "tls" or (server.reality == '1') and "reality" or nil,
 				tlsSettings = (server.tls == '1') and {
 					-- tls
-					alpn = (server.transport == "xhttp") and (function()
+					alpn = (server.tls_alpn and server.tls_alpn ~= "") and (function()
 						local alpn = {}
-						if server.tls_alpn and server.tls_alpn ~= "" then
-							string.gsub(server.tls_alpn, '[^,]+', function(w)
-								table.insert(alpn, w)
-							end)
-						end
+						string.gsub(server.tls_alpn, '[^,]+', function(w)
+							table.insert(alpn, w)
+						end)
 						if #alpn > 0 then
 							return alpn
 						else
@@ -226,7 +224,7 @@ end
 						end
 					end)() or nil,
 					fingerprint = server.fingerprint,
-					allowInsecure = (server.insecure == "1"),
+					allowInsecure = (server.insecure == "1" or server.insecure == true or server.insecure == "true"),
 					serverName = server.tls_host,
 					certificates = server.certificate and {
 						usage = "verify",
@@ -394,12 +392,23 @@ local trojan = {
 		cipher = cipher,
 		cipher_tls13 = cipher13,
 		sni = server.tls_host,
-		alpn = {"h2", "http/1.1"},
+		alpn = (server.tls == "1") and (function()
+			local alpn = {}
+			if server.tls_alpn and server.tls_alpn ~= "" then
+				string.gsub(server.tls_alpn, '[^,]+', function(w)
+					table.insert(alpn, w)
+				end)
+			end
+			if #alpn > 0 then
+				return alpn
+			else
+				return nil
+			end
+		end)() or {"h2", "http/1.1"},
 		curve = "",
 		reuse_session = true,
 		session_ticket = (server.tls_sessionTicket == "1") and true or false
 	},
-	udp_timeout = 60,
 	tcp = {
 		-- tcp
 		no_delay = true,
@@ -484,13 +493,11 @@ local hysteria2 = {
 	auth = server.hy2_auth,
 	tls = (server.tls_host and server.tls_host ~= "") and {
 		sni = server.tls_host,
-		alpn = (server.type == "hysteria2") and (function()
+		alpn = (server.tls_alpn and server.tls_alpn ~= "") and (function()
 			local alpn = {}
-			if server.tls_alpn and server.tls_alpn ~= "" then
-				string.gsub(server.tls_alpn, '[^,]+', function(w)
-					table.insert(alpn, w)
-				end)
-			end
+			string.gsub(server.tls_alpn, '[^,]+', function(w)
+				table.insert(alpn, w)
+			end)
 			if #alpn > 0 then
 				return alpn
 			else
@@ -613,13 +620,11 @@ local tuic = {
 			timeout = server.timeout and server.timeout .. "s" or nil,
 			gc_interval = server.gc_interval and server.gc_interval .. "s" or nil,
 			gc_lifetime = server.gc_lifetime and server.gc_lifetime .. "s" or nil,
-			alpn = (server.type == "tuic") and (function()
+			alpn = (server.tuic_alpn and server.tuic_alpn ~= "") and (function()
 				local alpn = {}
-				if server.tuic_alpn and server.tuic_alpn ~= "" then
-					string.gsub(server.tuic_alpn, '[^,]+', function(w)
-						table.insert(alpn, w)
-					end)
-				end
+				string.gsub(server.tuic_alpn, '[^,]+', function(w)
+					table.insert(alpn, w)
+				end)
 				if #alpn > 0 then
 					return alpn
 				else

+ 66 - 37
luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua

@@ -238,38 +238,62 @@ local function processData(szType, content)
 			result.pinsha256 = params.pinSHA256
 		end
 	elseif szType == 'ssr' then
-		local dat = split(content, "/%?")
-		local hostInfo = split(dat[1], ':')
+		-- 去掉前后空白和#注释
+		local link = trim(content:gsub("#.*$", ""))
+		local dat = split(link, "/%?")
+		local hostInfo = split(dat[1] or '', ':')
+
 		result.type = 'ssr'
-		result.server = hostInfo[1]
-		result.server_port = hostInfo[2]
-		result.protocol = hostInfo[3]
-		result.encrypt_method = hostInfo[4]
-		result.obfs = hostInfo[5]
-		result.password = base64Decode(hostInfo[6])
+		result.server = hostInfo[1] or ''
+		result.server_port = hostInfo[2] or ''
+		result.protocol = hostInfo[3] or ''
+		result.encrypt_method = hostInfo[4] or ''
+		result.obfs = hostInfo[5] or ''
+		result.password = base64Decode(hostInfo[6] or '')
+
 		local params = {}
-		for _, v in pairs(split(dat[2], '&')) do
-			local t = split(v, '=')
-			params[t[1]] = t[2]
+		if dat[2] and dat[2] ~= '' then
+            for _, v in pairs(split(dat[2], '&')) do
+                local t = split(v, '=')
+                if t[1] and t[2] then
+                    params[t[1]] = t[2]
+                end
+            end
 		end
-		result.obfs_param = base64Decode(params.obfsparam)
-		result.protocol_param = base64Decode(params.protoparam)
-		local group = base64Decode(params.group)
-		if group then
-			result.alias = "[" .. group .. "] "
+
+		result.obfs_param = base64Decode(params.obfsparam or '')
+		result.protocol_param = base64Decode(params.protoparam or '')
+
+		local group = base64Decode(params.group or '')
+		local remarks = base64Decode(params.remarks or '')
+
+		-- 拼接 alias
+		local alias = ""
+		if group ~= "" then
+			alias = "[" .. group .. "] "
 		end
-		result.alias = result.alias .. base64Decode(params.remarks)
+		alias = alias .. remarks
+		result.alias = alias
 	elseif szType == "vmess" then
+		-- 去掉前后空白和#注释
+		local link = trim(content:gsub("#.*$", ""))
+
 		-- 解析正常节点
-		local success, info = pcall(jsonParse, content)
+		local success, info = pcall(jsonParse, link)
 		if not success or type(info) ~= "table" then
 			return nil
 		end
-		-- 处理有效数据
+
+		-- 基本信息
 		result.type = 'v2ray'
 		result.v2ray_protocol = 'vmess'
 		result.server = info.add
 		result.server_port = info.port
+		result.alter_id = info.aid
+		result.vmess_id = info.id
+		result.alias = info.ps
+
+		-- 调整传输协议
 		if info.net == "tcp" then
 			info.net = "raw"
 		end
@@ -277,9 +301,7 @@ local function processData(szType, content)
 			info.net = "xhttp"
 		end
 		result.transport = info.net
-		result.alter_id = info.aid
-		result.vmess_id = info.id
-		result.alias = info.ps
+
 		-- result.mux = 1
 		-- result.concurrency = 8
 		if info.net == 'ws' then
@@ -298,11 +320,11 @@ local function processData(szType, content)
 			result.enable_xhttp_extra = (info.extra and info.extra ~= "") and "1" or nil
 			result.xhttp_extra = (info.extra and info.extra ~= "") and info.extra or nil
 			-- 尝试解析 JSON 数据
-			local success, Data = pcall(jsonParse, info.extra)
-			if success and Data then
+			local success, Data = pcall(jsonParse, info.extra or "")
+			if success and type(Data) == "table" then
 				local address = (Data.extra and Data.extra.downloadSettings and Data.extra.downloadSettings.address)
 					or (Data.downloadSettings and Data.downloadSettings.address)
-				result.download_address = address and address ~= "" and address or nil
+				result.download_address = (address and address ~= "") and address or nil
 			else
 				-- 如果解析失败,清空下载地址
 				result.download_address = nil
@@ -313,12 +335,11 @@ local function processData(szType, content)
 			result.h2_path = info.path
 		end
 		if info.net == 'raw' or info.net == 'tcp' then
-			if info.type and info.type ~= "http" then
-				info.type = "none"
+			result.tcp_guise = info.type or "none"
+			if result.tcp_guise == "http" then
+				result.http_host = info.host
+				result.http_path = info.path
 			end
-			result.tcp_guise = info.type
-			result.http_host = info.host
-			result.http_path = info.path
 		end
 		if info.net == 'kcp' then
 			result.kcp_guise = info.type
@@ -356,19 +377,27 @@ local function processData(szType, content)
 			end
 			if info.sni and info.sni ~= "" then
 				result.tls_host = info.sni
-			elseif info.host then
+			elseif info.host and info.host ~= "" then
 				result.tls_host = info.host
 			end
 			if info.ech and info.ech ~= "" then
 				result.enable_ech = "1"
 				result.ech_config = info.ech
 			end
-			if (info.allowInsecure or info.allowlnsecure) == "true" or (info.allowInsecure or info.allowlnsecure) == "1" then
-				result.insecure = "1"
+			-- 兼容 allowInsecure / allowlnsecure / skip-cert-verify
+			if info.allowInsecure or info.allowlnsecure or info["skip-cert-verify"] then
+				local insecure = info.allowInsecure or info.allowlnsecure or info["skip-cert-verify"]
+				if insecure == true or insecure == "1" or insecure == "true" then
+					result.insecure = "1"
+				end
 			end
 		else
 			result.tls = "0"
 		end
+		-- 其它可选安全字段
+		if info.security then
+			result.security = info.security
+		end
 	elseif szType == "ss" then
 		local idx_sp = content:find("#") or 0
 		local alias = ""
@@ -684,8 +713,8 @@ local function processData(szType, content)
 				result.enable_xhttp_extra = (params.extra and params.extra ~= "") and "1" or nil
 				result.xhttp_extra = (params.extra and params.extra ~= "") and params.extra or nil
 				-- 尝试解析 JSON 数据
-				local success, Data = pcall(jsonParse, params.extra)
-				if success and Data then
+				local success, Data = pcall(jsonParse, params.extra or "")
+				if success and type(Data) == "table" then
 					local address = (Data.extra and Data.extra.downloadSettings and Data.extra.downloadSettings.address)
 						or (Data.downloadSettings and Data.downloadSettings.address)
 					result.download_address = address and address ~= "" and address or nil
@@ -774,8 +803,8 @@ local function processData(szType, content)
 			result.enable_xhttp_extra = (params.extra and params.extra ~= "") and "1" or nil
 			result.xhttp_extra = (params.extra and params.extra ~= "") and params.extra or nil
 			-- 尝试解析 JSON 数据
-			local success, Data = pcall(jsonParse, params.extra)
-			if success and Data then
+			local success, Data = pcall(jsonParse, params.extra or "")
+			if success and type(Data) == "table" then
 				local address = (Data.extra and Data.extra.downloadSettings and Data.extra.downloadSettings.address)
 					or (Data.downloadSettings and Data.downloadSettings.address)
 				result.download_address = address and address ~= "" and address or nil

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio