Bläddra i källkod

V2Ray/XRay: allow protocol selection

kuma 4 år sedan
förälder
incheckning
20c36ba4ff

+ 49 - 20
luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/client-config.lua

@@ -70,6 +70,14 @@ local encrypt_methods_ss = {
 "chacha20-ietf",
 }
 
+local encrypt_methods_v2ray_ss = {
+-- aead
+"aes-128-gcm",
+"aes-256-gcm",
+"chacha20-ietf-poly1305",
+"none"
+}
+
 local protocol = {
 "origin",
 "verify_deflate",
@@ -131,8 +139,7 @@ if nixio.fs.access("/usr/bin/ss-redir") then
 o:value("ss", translate("Shadowsocks New Version"))
 end
 if nixio.fs.access("/usr/bin/xray") or nixio.fs.access("/usr/bin/xray/xray") or nixio.fs.access("/usr/bin/v2ray/v2ray") or nixio.fs.access("/usr/bin/v2ray") then
-o:value("vmess", translate("Vmess"))
-o:value("vless", translate("VLESS"))
+o:value("v2ray", translate("V2Ray/XRay"))
 end
 if nixio.fs.access("/usr/sbin/trojan") then
 o:value("trojan", translate("Trojan"))
@@ -153,13 +160,21 @@ for _, e in ipairs(luci.sys.net.devices()) do if e ~= "lo" then o:value(e) end e
 o:depends("type", "tun")
 o.description = translate("Redirect traffic to this network interface")
 
+o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
+o:value("vmess", translate("Vmess"))
+o:value("vless", translate("VLESS"))
+o:value("http", translate("HTTP"))
+o:value("socks", translate("Socks"))
+o:value("shadowsocks", translate("Shadowsocks"))
+o:value("trojan", translate("Trojan"))
+o:depends("type", "v2ray")
+
 o = s:option(Value, "server", translate("Server Address"))
 o.datatype = "host"
 o.rmempty = false
 o:depends("type", "ssr")
 o:depends("type", "ss")
-o:depends("type", "vmess")
-o:depends("type", "vless")
+o:depends("type", "v2ray")
 o:depends("type", "trojan")
 o:depends("type", "naiveproxy")
 o:depends("type", "socks5")
@@ -169,8 +184,7 @@ o.datatype = "port"
 o.rmempty = false
 o:depends("type", "ssr")
 o:depends("type", "ss")
-o:depends("type", "vmess")
-o:depends("type", "vless")
+o:depends("type", "v2ray")
 o:depends("type", "trojan")
 o:depends("type", "naiveproxy")
 o:depends("type", "socks5")
@@ -179,11 +193,15 @@ o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
 o.rmempty = false
 o.default = "0"
 o:depends("type", "socks5")
+o:depends({type = "v2ray", v2ray_protocol = "http"})
+o:depends({type = "v2ray", v2ray_protocol = "socks"})
 
 o = s:option(Value, "username", translate("Username"))
 o.rmempty = true
 o:depends("type", "naiveproxy")
 o:depends({type = "socks5", auth_enable = true})
+o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
+o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
 
 o = s:option(Value, "password", translate("Password"))
 o.password = true
@@ -193,6 +211,10 @@ o:depends("type", "ss")
 o:depends("type", "trojan")
 o:depends("type", "naiveproxy")
 o:depends({type = "socks5", auth_enable = true})
+o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
+o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
+o:depends({type = "v2ray", v2ray_protocol = "trojan"})
 
 o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
 for _, v in ipairs(encrypt_methods) do o:value(v) end
@@ -204,6 +226,11 @@ for _, v in ipairs(encrypt_methods_ss) do o:value(v) end
 o.rmempty = true
 o:depends("type", "ss")
 
+o = s:option(ListValue, "encrypt_method_v2ray_ss", translate("Encrypt Method"))
+for _, v in ipairs(encrypt_methods_v2ray_ss) do o:value(v) end
+o.rmempty = true
+o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
+
 -- Shadowsocks Plugin
 o = s:option(Value, "plugin", translate("Plugin"))
 o.rmempty = true
@@ -234,26 +261,26 @@ o = s:option(Value, "alter_id", translate("AlterId"))
 o.datatype = "port"
 o.default = 16
 o.rmempty = true
-o:depends("type", "vmess")
+o:depends({type = "v2ray", v2ray_protocol = "vmess"})
 
 -- VmessId
 o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
 o.rmempty = true
 o.default = uuid
-o:depends("type", "vmess")
-o:depends("type", "vless")
+o:depends({type = "v2ray", v2ray_protocol = "vmess"})
+o:depends({type = "v2ray", v2ray_protocol = "vless"})
 
 -- VLESS Encryption
 o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
 o.rmempty = true
 o.default = "none"
-o:depends("type", "vless")
+o:depends({type = "v2ray", v2ray_protocol = "vless"})
 
 -- 加密方式
 o = s:option(ListValue, "security", translate("Encrypt Method"))
 for _, v in ipairs(securitys) do o:value(v, v:upper()) end
 o.rmempty = true
-o:depends("type", "vmess")
+o:depends({type = "v2ray", v2ray_protocol = "vmess"})
 
 -- 传输协议
 o = s:option(ListValue, "transport", translate("Transport"))
@@ -263,8 +290,7 @@ o:value("ws", "WebSocket")
 o:value("h2", "HTTP/2")
 o:value("quic", "QUIC")
 o.rmempty = true
-o:depends("type", "vmess")
-o:depends("type", "vless")
+o:depends("type", "v2ray")
 
 -- [[ TCP部分 ]]--
 
@@ -392,8 +418,8 @@ o.rmempty = true
 o = s:option(Flag, "tls", translate("TLS"))
 o.rmempty = true
 o.default = "0"
-o:depends("type", "vmess")
-o:depends({type = "vless", xtls = false})
+o:depends({type = "v2ray", xtls = false})
+-- o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = false})
 o:depends("type", "trojan")
 
 -- XTLS
@@ -401,7 +427,12 @@ if nixio.fs.access("/usr/bin/xray") or nixio.fs.access("/usr/bin/xray/xray") the
 o = s:option(Flag, "xtls", translate("XTLS"))
 o.rmempty = true
 o.default = "0"
-o:depends({type = "vless", transport = "tcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "vmess", transport = "tcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "vmess", transport = "kcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "tcp", tls = false})
+o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "kcp", tls = false})
 end
 
 -- Flow
@@ -427,8 +458,7 @@ o.description = translate("If true, allowss insecure connection at TLS client, e
 -- [[ Mux ]]--
 o = s:option(Flag, "mux", translate("Mux"))
 o.rmempty = false
-o:depends("type", "vmess")
-o:depends({type = "vless", xtls = false})
+o:depends({type = "v2ray", xtls = false})
 
 o = s:option(Value, "concurrency", translate("Concurrency"))
 o.datatype = "uinteger"
@@ -441,8 +471,7 @@ o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
 o.rmempty = true
 o.default = "0"
 o:depends("type", "trojan")
-o:depends("type", "vmess")
-o:depends("type", "vless")
+o:depends("type", "v2ray")
 o.description = translate("If you have a self-signed certificate,please check the box")
 
 o = s:option(DummyValue, "upload", translate("Upload"))

+ 3 - 1
luci-app-ssr-plus/luasrc/view/shadowsocksr/ssrurl.htm

@@ -246,8 +246,10 @@
 		} else if (ssu[0] == "vmess") {
 			var sstr = b64DecodeUnicode(ssu[1]);
 			var ploc = sstr.indexOf("/?");
-			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].value = "vmess";
+			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].value = "v2ray";
 			document.getElementsByName('cbid.shadowsocksr.' + sid + '.type')[0].dispatchEvent(event);
+			document.getElementsByName('cbid.shadowsocksr.' + sid + '.v2ray_protocol')[0].value = "vmess";
+			document.getElementsByName('cbid.shadowsocksr.' + sid + '.v2ray_protocol')[0].dispatchEvent(event);
 			var url0, param = "";
 			if (ploc > 0) {
 				url0 = sstr.substr(0, ploc);

+ 3 - 0
luci-app-ssr-plus/po/zh-cn/ssr-plus.po

@@ -690,3 +690,6 @@ msgstr "混淆密码(可选)"
 
 msgid "Select the interface that needs to transmit data. If unchecked, all interfaces will pass data by default!"
 msgstr "选择需要传递数据的接口。如果未选择,则默认情况下所有接口都将传递数据!"
+
+msgid "V2Ray/XRay protocol"
+msgstr "V2Ray/XRay 协议"

+ 6 - 6
luci-app-ssr-plus/root/etc/init.d/shadowsocksr

@@ -109,7 +109,7 @@ find_bin() {
 	ssr) ret="/usr/bin/ssr-redir" ;;
 	ssr-local) ret="/usr/bin/ssr-local" ;;
 	ssr-server) ret="/usr/bin/ssr-server" ;;
-	vmess | vless)
+	v2ray)
 	ret="/usr/bin/xray"
 	[ ! -f "$ret" ] && ret="/usr/bin/xray/xray"
 	[ ! -f "$ret" ] && ret="/usr/bin/v2ray"
@@ -185,7 +185,7 @@ gen_config_file() {
 			}
 		EOF
 		;;
-	vmess | vless)
+	v2ray)
 		lua /usr/share/shadowsocksr/genv2config.lua $GLOBAL_SERVER tcp $(uci_get_by_name $1 local_port) >/var/etc/v2-ssr-retcp.json
 		sed -i 's/\\//g' /var/etc/v2-ssr-retcp.json
 		;;
@@ -355,7 +355,7 @@ start_redir_tcp() {
 		done
 		echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$name $threads Threads Started!" >>/tmp/ssrplus.log
 		;;
-	vmess | vless)
+	v2ray)
 		$bin -config /var/etc/v2-ssr-retcp.json >/dev/null 2>&1 &
 		echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
 		;;
@@ -408,7 +408,7 @@ start_redir_udp() {
 			$bin -c $last_config_file $ARG_OTA -U -f /var/run/ssr-reudp.pid >/dev/null 2>&1
 			echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$name Started!" >>/tmp/ssrplus.log
 			;;
-		vmess | vless)
+		v2ray)
 			lua /usr/share/shadowsocksr/genv2config.lua $UDP_RELAY_SERVER udp $(uci_get_by_name $UDP_RELAY_SERVER local_port) >/var/etc/v2-ssr-reudp.json
 			sed -i 's/\\//g' /var/etc/v2-ssr-reudp.json
 			$bin -config /var/etc/v2-ssr-reudp.json >/dev/null 2>&1 &
@@ -459,7 +459,7 @@ start_shunt() {
 			dns2socks 127.0.0.1:1088 8.8.8.8:53 127.0.0.1:5555 -q >/dev/null 2>&1 &
 			echo "$(date "+%Y-%m-%d %H:%M:%S") Netflix shunt:$name Started!" >>/tmp/ssrplus.log
 			;;
-		vmess | vless)
+		v2ray)
 			lua /usr/share/shadowsocksr/genv2config.lua $NETFLIX_SERVER tcp 4321 1088 >/var/etc/v2-ssr-netflix.json
 			sed -i 's/\\//g' /var/etc/v2-ssr-netflix.json
 			$bin -config /var/etc/v2-ssr-netflix.json >/dev/null 2>&1 &
@@ -522,7 +522,7 @@ start_local() {
 		$bin -c $CONFIG_SOCK5_FILE -u -f /var/run/ssr-local.pid >/dev/null 2>&1
 		echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$name Started!" >>/tmp/ssrplus.log
 		;;
-	vmess | vless)
+	v2ray)
 		lua /usr/share/shadowsocksr/genv2config.lua $local_server tcp 0 $(uci_get_by_type socks5_proxy local_port 1080) >/var/etc/v2-ssr-local.json
 		sed -i 's/\\//g' /var/etc/v2-ssr-local.json
 		$bin -config /var/etc/v2-ssr-local.json >/dev/null 2>&1 &

+ 0 - 1
luci-app-ssr-plus/root/etc/uci-defaults/luci-ssr-plus

@@ -65,6 +65,5 @@ set shadowsocksr.@server_global[0].enable_server='0'
 commit shadowsocksr
 EOF
 fi
-sed -i "s/type 'v2ray'"/"type 'vmess'/g" /etc/config/shadowsocksr
 rm -rf /tmp/luci-modulecache /tmp/luci-indexcache
 exit 0

+ 56 - 18
luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua

@@ -5,6 +5,60 @@ local proto = arg[2]
 local local_port = arg[3] or "0"
 local socks_port = arg[4] or "0"
 local server = ucursor:get_all("shadowsocksr", server_section)
+
+local outbound_settings = nil
+if (server.v2ray_protocol == "vmess" or server.v2ray_protocol == "vless")
+then
+	outbound_settings = {
+		vnext = {
+			{
+				address = server.server,
+				port = tonumber(server.server_port),
+				users = {
+					{
+						id = server.vmess_id,
+						alterId = (server.v2ray_protocol == "vmess") and tonumber(server.alter_id) or nil,
+						security = (server.v2ray_protocol == "vmess") and server.security or nil,
+						encryption = (server.v2ray_protocol == "vless") and server.vless_encryption or nil,
+						flow = (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-splice") or nil,
+					}
+				}
+			}
+		}
+	}
+
+elseif (server.v2ray_protocol == "trojan" or server.v2ray_protocol == "shadowsocks")
+then
+	outbound_settings = {
+		servers = {
+			{
+				address = server.server,
+				port = tonumber(server.server_port),
+				password = server.password,
+				method = (server.v2ray_protocol == "shadowsocks") and server.encrypt_method_v2ray_ss or nil,
+			}
+		}
+	}
+
+elseif (server.v2ray_protocol == "socks" or server.v2ray_protocol == "http")
+then
+	outbound_settings = {
+		servers = {
+			{
+				address = server.server,
+				port = tonumber(server.server_port),
+				users = (server.auth_enable == "1") and {
+					{
+						user = server.username,
+						pass = server.password,
+					}
+				} or nil,
+			}
+		}
+	}
+end
+
+
 local Xray = {
 log = {
 -- error = "/var/ssrplus.log",
@@ -36,24 +90,8 @@ inboundDetour = (proto == "tcp" and socks_port ~= "0") and {
 } or nil,
 -- 传出连接
 outbound = {
-	protocol = server.type,
-	settings = {
-		vnext = {
-			{
-				address = server.server,
-				port = tonumber(server.server_port),
-				users = {
-					{
-						id = server.vmess_id,
-						alterId = (server.type == "vmess") and tonumber(server.alter_id) or nil,
-						security = (server.type == "vmess") and server.security or nil,
-						encryption = (server.type == "vless") and server.vless_encryption or nil,
-						flow = (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-splice") or nil,
-					}
-				}
-			}
-		}
-	},
+	protocol = server.v2ray_protocol,
+	settings = outbound_settings,
 -- 底层传输配置
 	streamSettings = {
 		network = server.transport,

+ 2 - 1
luci-app-ssr-plus/root/usr/share/shadowsocksr/subscribe.lua

@@ -122,7 +122,8 @@ local function processData(szType, content)
 		result.alias = result.alias .. base64Decode(params.remarks)
 	elseif szType == 'vmess' then
 		local info = jsonParse(content)
-		result.type = 'vmess'
+		result.type = 'v2ray'
+		result.v2ray_protocol = 'vmess'
 		result.server = info.add
 		result.server_port = info.port
 		result.transport = info.net