luci: wireguard reserved support base64 string (#2511)

This commit is contained in:
Tianhe Y 2023-04-18 12:50:27 +08:00 committed by sbwml
parent 22940c0f9b
commit 2a0d4ed8a0
4 changed files with 15 additions and 4 deletions

View File

@ -749,7 +749,7 @@ wireguard_mtu.default = "1420"
wireguard_mtu:depends({ type = "Xray", protocol = "wireguard" }) wireguard_mtu:depends({ type = "Xray", protocol = "wireguard" })
if api.compare_versions(api.get_app_version("xray"), ">=", "1.8.0") then if api.compare_versions(api.get_app_version("xray"), ">=", "1.8.0") then
wireguard_reserved = s:option(Value, "wireguard_reserved", translate("Reserved")) wireguard_reserved = s:option(Value, "wireguard_reserved", translate("Reserved"), translate("Decimal numbers separated by \",\" or Base64-encoded strings."))
wireguard_reserved:depends({ type = "Xray", protocol = "wireguard" }) wireguard_reserved:depends({ type = "Xray", protocol = "wireguard" })
end end

View File

@ -1,5 +1,6 @@
module("luci.passwall.api", package.seeall) module("luci.passwall.api", package.seeall)
local com = require "luci.passwall.com" local com = require "luci.passwall.com"
bin = require "nixio".bin
fs = require "nixio.fs" fs = require "nixio.fs"
sys = require "luci.sys" sys = require "luci.sys"
uci = require"luci.model.uci".cursor() uci = require"luci.model.uci".cursor()

View File

@ -102,9 +102,16 @@ function gen_outbound(flag, node, tag, proxy_table)
if node.protocol == "wireguard" and node.wireguard_reserved then if node.protocol == "wireguard" and node.wireguard_reserved then
local bytes = {} local bytes = {}
node.wireguard_reserved:gsub("[^,]+", function(b) if not node.wireguard_reserved:match("[^%d,]+") then
bytes[#bytes+1] = tonumber(b) node.wireguard_reserved:gsub("%d+", function(b)
end) bytes[#bytes + 1] = tonumber(b)
end)
else
local result = api.bin.b64decode(node.wireguard_reserved)
for i = 1, #result do
bytes[i] = result:byte(i)
end
end
node.wireguard_reserved = #bytes > 0 and bytes or nil node.wireguard_reserved = #bytes > 0 and bytes or nil
end end

View File

@ -1117,6 +1117,9 @@ msgstr "额外的对称加密密钥"
msgid "Local Address" msgid "Local Address"
msgstr "本地地址" msgstr "本地地址"
msgid "Decimal numbers separated by \",\" or Base64-encoded strings."
msgstr "用“,”隔开的十进制数字或 Base64 编码字符串。"
msgid "Camouflage Type" msgid "Camouflage Type"
msgstr "伪装类型" msgstr "伪装类型"