From a2b22bc484d42f996de947df0b5868779c3d82b8 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Fri, 8 Jan 2021 13:47:21 +0800 Subject: [PATCH] luci-app-passwall: server: add xray acceptProxyProtocol option --- .../model/cbi/passwall/server/api/xray.lua | 41 +++++++++++-------- .../luasrc/model/cbi/passwall/server/user.lua | 10 +++-- .../luci-app-passwall/po/zh_Hans/passwall.po | 7 +++- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/api/xray.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/api/xray.lua index 9c155db14f..d5779e0be5 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/api/xray.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/api/xray.lua @@ -14,9 +14,9 @@ function gen_config(user) for i = 1, #user.uuid do clients[i] = { id = user.uuid[i], - flow = (user.xtls and user.xtls == "1") and user.flow or nil, - level = tonumber(user.level), - alterId = tonumber(user.alter_id) + flow = ("1" == user.xtls) and user.flow or nil, + level = user.level and tonumber(user.level) or nil, + alterId = user.alter_id and tonumber(user.alter_id) or nil } end settings = { @@ -26,8 +26,8 @@ function gen_config(user) end elseif user.protocol == "socks" then settings = { - auth = (user.auth and user.auth == "1") and "password" or "noauth", - accounts = (user.auth and user.auth == "1") and { + auth = ("1" == user.auth) and "password" or "noauth", + accounts = ("1" == user.auth) and { { user = user.username, pass = user.password @@ -37,7 +37,7 @@ function gen_config(user) elseif user.protocol == "http" then settings = { allowTransparent = false, - accounts = (user.auth and user.auth == "1") and { + accounts = ("1" == user.auth) and { { user = user.username, pass = user.password @@ -50,7 +50,7 @@ function gen_config(user) settings = { method = user.method, password = user.password, - level = tonumber(user.level) or 1, + level = user.level and tonumber(user.level) or nil, network = user.ss_network or "TCP,UDP" } elseif user.protocol == "trojan" then @@ -58,9 +58,9 @@ function gen_config(user) local clients = {} for i = 1, #user.uuid do clients[i] = { - flow = (user.xtls and user.xtls == "1") and user.flow or nil, + flow = ("1" == user.xtls) and user.flow or nil, password = user.uuid[i], - level = tonumber(user.level) + level = user.level and tonumber(user.level) or nil, } end settings = { @@ -71,7 +71,7 @@ function gen_config(user) settings = { users = { { - level = tonumber(user.level) or 1, + level = user.level and tonumber(user.level) or nil, secret = (user.password == nil) and "" or user.password } } @@ -123,7 +123,7 @@ function gen_config(user) local config = { log = { -- error = "/var/etc/passwall_server/log/" .. user[".name"] .. ".log", - loglevel = (user.log and user.log == "1") and user.loglevel or "none" + loglevel = ("1" == user.log) and user.loglevel or "none" }, -- 传入连接 inbounds = { @@ -135,8 +135,11 @@ function gen_config(user) streamSettings = { network = user.transport, security = "none", - xtlsSettings = (user.tls and user.tls == "1" and user.xtls and user.xtls == "1") and { - alpn = {"http/1.1"}, + xtlsSettings = ("1" == user.tls and "1" == user.xtls) and { + alpn = { + "h2", + "http/1.1" + }, disableSystemRoot = false, certificates = { { @@ -145,8 +148,11 @@ function gen_config(user) } } } or nil, - tlsSettings = (user.tls and user.tls == "1") and { - alpn = {"http/1.1"}, + tlsSettings = ("1" == user.tls) and { + alpn = { + "h2", + "http/1.1" + }, disableSystemRoot = false, certificates = { { @@ -156,6 +162,7 @@ function gen_config(user) } } or nil, tcpSettings = (user.transport == "tcp") and { + acceptProxyProtocol = (user.acceptProxyProtocol and user.acceptProxyProtocol == "1") and true or false, header = { type = user.tcp_guise, request = (user.tcp_guise == "http") and { @@ -178,7 +185,7 @@ function gen_config(user) header = {type = user.mkcp_guise} } or nil, wsSettings = (user.transport == "ws") and { - acceptProxyProtocol = true, + acceptProxyProtocol = (user.acceptProxyProtocol and user.acceptProxyProtocol == "1") and true or false, headers = (user.ws_host) and {Host = user.ws_host} or nil, path = user.ws_path } or nil, @@ -201,7 +208,7 @@ function gen_config(user) routing = routing } - if user.tls and user.tls == "1" then + if "1" == user.tls then config.inbounds[1].streamSettings.security = "tls" if user.xtls and user.xtls == "1" then config.inbounds[1].streamSettings.security = "xtls" diff --git a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua index 2efd15eb86..863cc07131 100644 --- a/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua +++ b/package/lienol/luci-app-passwall/luasrc/model/cbi/passwall/server/user.lua @@ -258,12 +258,10 @@ uuid:depends("type", "Trojan-Go") uuid:depends("type", "Trojan-Plus") alter_id = s:option(Value, "alter_id", translate("Alter ID")) -alter_id.default = 16 alter_id:depends({ type = "Xray", protocol = "vmess" }) alter_id:depends({ type = "V2ray", protocol = "vmess" }) level = s:option(Value, "level", translate("User Level")) -level.default = 1 level:depends({ type = "Xray", protocol = "vmess" }) level:depends({ type = "Xray", protocol = "vless" }) level:depends({ type = "Xray", protocol = "shadowsocks" }) @@ -511,6 +509,12 @@ quic_guise = s:option(ListValue, "quic_guise", translate("Camouflage Type")) for a, t in ipairs(header_type_list) do quic_guise:value(t) end quic_guise:depends("transport", "quic") +acceptProxyProtocol = s:option(Flag, "acceptProxyProtocol", translate("acceptProxyProtocol"), translate("Whether to receive PROXY protocol, when this node want to be fallback or forwarded by proxy, it must be enable, otherwise it cannot be used.")) +acceptProxyProtocol:depends({ type = "Xray", transport = "tcp" }) +acceptProxyProtocol:depends({ type = "Xray", transport = "ws" }) +acceptProxyProtocol:depends({ type = "V2ray", transport = "tcp" }) +acceptProxyProtocol:depends({ type = "V2ray", transport = "ws" }) + -- [[ Fallback部分 ]]-- fallback = s:option(Flag, "fallback", translate("Fallback")) fallback:depends({ type = "Xray", protocol = "vless", transport = "tcp" }) @@ -573,7 +577,7 @@ remote_port.datatype = "port" remote_port.default = "80" remote_port:depends("remote_enable", 1) -bind_local = s:option(Flag, "bind_local", translate("Bind Local"), translate("When selected, it can only be accessed locally,It is recommended to turn on when using reverse proxies.")) +bind_local = s:option(Flag, "bind_local", translate("Bind Local"), translate("When selected, it can only be accessed locally, It is recommended to turn on when using reverse proxies or be fallback.")) bind_local.default = "0" bind_local:depends("type", "Xray") bind_local:depends("type", "V2ray") diff --git a/package/lienol/luci-app-passwall/po/zh_Hans/passwall.po b/package/lienol/luci-app-passwall/po/zh_Hans/passwall.po index 217e093cfe..792ad5da57 100644 --- a/package/lienol/luci-app-passwall/po/zh_Hans/passwall.po +++ b/package/lienol/luci-app-passwall/po/zh_Hans/passwall.po @@ -1075,14 +1075,17 @@ msgstr "当你隐藏后想再次显示,地址栏输入例:" msgid "The MTProto protocol must be 32 characters and can only contain characters from 0 to 9 and a to f." msgstr "MTProto 协议必须为 32 个字符,仅可包含 0 到 9 和 a 到 f 之间的字符。" +msgid "Whether to receive PROXY protocol, when this node want to be fallback or forwarded by proxy, it must be enable, otherwise it cannot be used." +msgstr "是否接收 PROXY protocol,当该节点要被回落或被代理转发时,必须启用,否则不能使用。" + msgid "transit node" msgstr "中转到此节点" msgid "Bind Local" msgstr "本机监听" -msgid "When selected, it can only be accessed locally,It is recommended to turn on when using reverse proxies." -msgstr "当勾选时,只能由本机访问此端口,当开启反向代理时建议勾选此项。" +msgid "When selected, it can only be accessed locally, It is recommended to turn on when using reverse proxies or be fallback." +msgstr "当勾选时,只能由本机访问此端口,当想被反向代理或被回落时建议勾选此项。" msgid "Accept LAN Access" msgstr "接受局域网访问"