⛄ Sync 2026-10-22 00:07:59

This commit is contained in:
github-actions[bot] committed 2026-10-22 00:07:59 +08:00
1 parent 31748c050e
commit d047be4ede
22 files changed
+379 -173

No files matched your search

+43 -2
View File
@@ -307,6 +307,16 @@ function md5_string(str)
return md5
end
-- Verify the SHA256 hash of a file.
function verify_sha256(file, digest)
if type(digest) ~= "string" then return false end
local expected = digest:match("^sha256:(%x+)$")
if not expected or #expected ~= 64 then return false end
local code, output = exec_call("sha256sum " .. util.shellquote(file))
local actual = output:match("^(%x+)%s")
return code == 0 and actual ~= nil and actual:lower() == expected:lower()
end
-- Extract the domain name and port from the URL (no IP address).
function get_domain_port_from_url(url)
local scheme, domain, port = string.match(url, "^(https?)://([%w%.%-]+):?(%d*)")
@@ -328,9 +338,14 @@ function resolve_domain(domain, dns)
address = (address or dns):gsub("^%[(.-)%]$", "%1")
port = port or "53"
local server = datatypes.ip6addr(address) and ("[" .. address .. "]") or address
local dns_servers = {server .. ":" .. port, address .. "#" .. port, "223.5.5.5"}
local version = sys.exec("LC_ALL=C busybox nslookup -v 2>&1"):match("BusyBox v(%d+%.%d+%.%d+)")
if version and compare_versions(version, "<", "1.35.0") then
dns_servers[1], dns_servers[2] = dns_servers[2], dns_servers[1]
end
local rc, result
for _, dns_server in ipairs({server .. ":" .. port, address .. "#" .. port, "223.5.5.5"}) do
rc, result = exec_call_as_gid("LC_ALL=C nslookup " .. util.shellquote(domain) .. " " .. util.shellquote(dns_server), DIRECT_GID)
for _, dns_server in ipairs(dns_servers) do
rc, result = exec_call_as_gid("LC_ALL=C busybox nslookup " .. util.shellquote(domain) .. " " .. util.shellquote(dns_server), DIRECT_GID)
local ips, seen, answer = {}, {}, false
for line in result:gmatch("[^\r\n]+") do
if line:match("^%s*Name:") then answer = true end
@@ -1224,6 +1239,17 @@ local function check_path(app_name)
}
end
local function cache_update_digests(app_name, assets)
local digests = {}
for _, asset in ipairs(assets) do
if asset.browser_download_url and type(asset.digest) == "string" then
digests[asset.browser_download_url] = asset.digest
end
end
fs.mkdirr(CACHE_PATH)
fs.writefile(CACHE_PATH .. "/update_" .. app_name .. ".json", jsonc.stringify(digests))
end
function to_check(arch, app_name)
local result = check_path(app_name)
if result.code ~= 0 then
@@ -1288,6 +1314,7 @@ function to_check(arch, app_name)
}
end
cache_update_digests(app_name, {asset})
return {
code = 0,
has_update = has_update,
@@ -1308,6 +1335,12 @@ function to_download(app_name, url, size, task_id, keep_files)
return {code = 1, error = i18n.translate("Download url is required.")}
end
local digests = jsonc.parse(fs.readfile(CACHE_PATH .. "/update_" .. app_name .. ".json") or "{}")
local digest = type(digests) == "table" and digests[url]
if type(digest) ~= "string" then
return {code = 1, error = i18n.translate("File verification failed.")}
end
if not keep_files then sys.call("/bin/rm -f /tmp/".. app_name .."_download.*") end
local tmp_file
@@ -1346,6 +1379,11 @@ function to_download(app_name, url, size, task_id, keep_files)
}
end
if not verify_sha256(tmp_file, digest) then
exec("/bin/rm", {"-f", tmp_file})
return {code = 1, error = i18n.translate("File verification failed.")}
end
return {code = 0, file = tmp_file, zip = com[app_name].zipped }
end
@@ -1586,6 +1624,9 @@ function to_check_self()
selected[#selected + 1] = found[code]
end
if not main then return {code = 1, error = i18n.translate("Get remote version info failed.")} end
local assets = {main}
for _, asset in ipairs(selected) do assets[#assets + 1] = asset end
cache_update_digests(appname, assets)
return {
code = 0, has_update = compare_versions(local_version, "<", remote_version),
local_version = local_version, remote_version = remote_version, html_url = release.html_url,