Преглед на файлове

Add v2ray VLESS support.

Shimin Xiong преди 5 години
родител
ревизия
fab1d7c721

+ 1 - 1
luci-app-ssr-plus/Makefile

@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=luci-app-ssr-plus
 PKG_VERSION:=180
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 include $(INCLUDE_DIR)/package.mk
 

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

@@ -123,6 +123,7 @@ o:value("ss", translate("Shadowsocks New Version"))
 end
 if nixio.fs.access("/usr/bin/v2ray/v2ray") or nixio.fs.access("/usr/bin/v2ray") then
 o:value("v2ray", translate("V2Ray"))
+o:value("vless", translate("VLESS"))
 end
 if nixio.fs.access("/usr/sbin/trojan") then
 o:value("trojan", translate("Trojan"))
@@ -148,6 +149,7 @@ o.rmempty = false
 o:depends("type", "ssr")
 o:depends("type", "ss")
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 o:depends("type", "trojan")
 o:depends("type", "socks5")
 
@@ -157,6 +159,7 @@ o.rmempty = false
 o:depends("type", "ssr")
 o:depends("type", "ss")
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 o:depends("type", "trojan")
 o:depends("type", "socks5")
 
@@ -220,10 +223,17 @@ o.rmempty = true
 o:depends("type", "v2ray")
 
 -- VmessId
-o = s:option(Value, "vmess_id", translate("VmessId (UUID)"))
+o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
 o.rmempty = true
 o.default = uuid
 o:depends("type", "v2ray")
+o:depends("type", "vless")
+
+-- VLESS Encryption
+o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
+o.rmempty = true
+o.default = "none"
+o:depends("type", "vless")
 
 -- 加密方式
 o = s:option(ListValue, "security", translate("Encrypt Method"))
@@ -240,6 +250,7 @@ o:value("h2", "HTTP/2")
 o:value("quic", "QUIC")
 o.rmempty = true
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 
 -- [[ TCP部分 ]]--
 
@@ -363,6 +374,7 @@ o.rmempty = true
 o = s:option(Flag, "insecure", translate("allowInsecure"))
 o.rmempty = false
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 o:depends("type", "trojan")
 o.default = "1"
 o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
@@ -371,6 +383,7 @@ o = s:option(Flag, "tls", translate("TLS"))
 o.rmempty = true
 o.default = "0"
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 o:depends("type", "trojan")
 
 o = s:option(Value, "tls_host", translate("TLS Host"))
@@ -383,6 +396,7 @@ o = s:option(Flag, "mux", translate("Mux"))
 o.rmempty = true
 o.default = "0"
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 
 o = s:option(Value, "concurrency", translate("Concurrency"))
 o.datatype = "uinteger"
@@ -396,6 +410,7 @@ o.rmempty = true
 o.default = "0"
 o:depends("type", "trojan")
 o:depends("type", "v2ray")
+o:depends("type", "vless")
 o.description = translate("If you have a self-signed certificate,please check the box")
 
 o = s:option(DummyValue, "upload", translate("Upload"))

+ 1 - 1
luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/servers.lua

@@ -92,7 +92,7 @@ end
 
 o = s:option(DummyValue, "type", translate("Type"))
 function o.cfgvalue(...)
-	return Value.cfgvalue(...) or ""
+	return (Value.cfgvalue(...) == "vless") and "VLESS" or Value.cfgvalue(...)
 end
 
 o = s:option(DummyValue, "alias", translate("Alias"))

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

@@ -61,6 +61,9 @@ msgstr "密码"
 msgid "Encrypt Method"
 msgstr "加密方式"
 
+msgid "VLESS Encryption"
+msgstr "VLESS 加密"
+
 msgid "Transport"
 msgstr "传输协议"
 

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

@@ -114,7 +114,7 @@ find_bin() {
 	ssr) ret="/usr/bin/ssr-redir" ;;
 	ssr-local) ret="/usr/bin/ssr-local" ;;
 	ssr-server) ret="/usr/bin/ssr-server" ;;
-	v2ray) ret="/usr/bin/v2ray/v2ray" && [ ! -f "$ret" ] && ret="/usr/bin/v2ray" ;;
+	v2ray | vless) ret="/usr/bin/v2ray/v2ray" && [ ! -f "$ret" ] && ret="/usr/bin/v2ray" ;;
 	trojan) ret="/usr/sbin/trojan" ;;
 	socks5 | tun) ret="/usr/sbin/redsocks2" ;;
 	esac
@@ -185,8 +185,8 @@ gen_config_file() {
 			}
 		EOF
 		;;
-	v2ray)
-		lua /usr/share/shadowsocksr/genv2config.lua $GLOBAL_SERVER tcp $(uci_get_by_name $1 local_port) >/var/etc/v2-ssr-retcp.json
+	v2ray | vless)
+		lua /usr/share/shadowsocksr/gen${type}config.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
 		;;
 	trojan)
@@ -343,7 +343,7 @@ start_redir_tcp() {
 		done
 		echo "$(date "+%Y-%m-%d %H:%M:%S") Main node:$name $threads Threads Started!" >>/tmp/ssrplus.log
 		;;
-	v2ray)
+	v2ray | vless)
 		$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
 		;;
@@ -392,8 +392,8 @@ 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
 			;;
-		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
+		v2ray | vless)
+			lua /usr/share/shadowsocksr/gen${type}config.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 &
 			echo "$(date "+%Y-%m-%d %H:%M:%S") UDP TPROXY Relay:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
@@ -439,8 +439,9 @@ 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
 			;;
-		v2ray)
-			lua /usr/share/shadowsocksr/genv2config.lua $NETFLIX_SERVER tcp 4321 1088 >/var/etc/v2-ssr-netflix.json
+		v2ray | vless)
+			lua /usr/share/shadowsocksr/gen${type}config.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 &
 			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:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log
@@ -493,8 +494,8 @@ 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
 		;;
-	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
+	v2ray | vless)
+		lua /usr/share/shadowsocksr/gen${type}config.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 &
 		echo "$(date "+%Y-%m-%d %H:%M:%S") Global_Socks5:$($bin -version | head -1) Started!" >>/tmp/ssrplus.log

+ 0 - 0
luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2config.lua → luci-app-ssr-plus/root/usr/share/shadowsocksr/genv2rayconfig.lua


+ 114 - 0
luci-app-ssr-plus/root/usr/share/shadowsocksr/genvlessconfig.lua

@@ -0,0 +1,114 @@
+local ucursor = require "luci.model.uci".cursor()
+local json = require "luci.jsonc"
+local server_section = arg[1]
+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 vless = {
+log = {
+-- error = "/var/ssrplus.log",
+loglevel = "warning"
+},
+-- 传入连接
+inbound = (local_port ~= "0") and {
+	port = local_port,
+	protocol = "dokodemo-door",
+	settings = {
+		network = proto,
+		followRedirect = true
+	},
+	sniffing = {
+		enabled = true,
+		destOverride = { "http", "tls" }
+	}
+} or nil,
+-- 开启 socks 代理
+inboundDetour = (proto == "tcp" and socks_port ~= "0") and {
+	{
+	protocol = "socks",
+	port = socks_port,
+		settings = {
+			auth = "noauth",
+			udp = true
+		}
+	}
+} or nil,
+-- 传出连接
+outbound = {
+	protocol = "vless",
+	settings = {
+		vnext = {
+			{
+				address = server.server,
+				port = tonumber(server.server_port),
+				users = {
+					{
+						id = server.vmess_id,
+						encryption = server.vless_encryption
+					}
+				}
+			}
+		}
+	},
+	-- 底层传输配置
+	streamSettings = {
+		network = server.transport,
+		security = (server.tls == '1') and "tls" or "none",
+		tlsSettings = {allowInsecure = (server.insecure ~= "0") and true or false,serverName=server.tls_host,},
+		tcpSettings = (server.transport == "tcp") and {
+			header = {
+				type = server.tcp_guise,
+				request = {
+					path = server.http_path or {"/"},
+					headers = {
+						Host = server.http_host or {}
+					}
+				} or {}
+			}
+		} or nil,
+		kcpSettings = (server.transport == "kcp") and {
+			mtu = tonumber(server.mtu),
+			tti = tonumber(server.tti),
+			uplinkCapacity = tonumber(server.uplink_capacity),
+			downlinkCapacity = tonumber(server.downlink_capacity),
+			congestion = (server.congestion == "1") and true or false,
+			readBufferSize = tonumber(server.read_buffer_size),
+			writeBufferSize = tonumber(server.write_buffer_size),
+			header = {
+				type = server.kcp_guise
+			}
+		} or nil,
+		wsSettings = (server.transport == "ws") and (server.ws_path ~= nil or server.ws_host ~= nil) and {
+			path = server.ws_path,
+			headers = (server.ws_host ~= nil) and {
+				Host = server.ws_host
+			} or nil,
+		} or nil,
+		httpSettings = (server.transport == "h2") and {
+			path = server.h2_path,
+			host = server.h2_host,
+		} or nil,
+		quicSettings = (server.transport == "quic") and {
+			security = server.quic_security,
+			key = server.quic_key,
+			header = {
+				type = server.quic_guise
+			}
+		} or nil
+	},
+	mux = {
+		enabled = (server.mux == "1") and true or false,
+		concurrency = tonumber(server.concurrency)
+	}
+},
+-- 额外传出连接
+outboundDetour = {
+		{
+			protocol = "freedom",
+			tag = "direct",
+			settings = { keep = "" }
+		}
+	}
+}
+print(json.stringify(vless, 1))