From eefb42ec07a74366c47eacc1c1282782e5870192 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 27 Jun 2019 01:23:24 +1000 Subject: Merge checkHost() and forkIP() into checkRedirect() --- mirror-checker.lua | 47 ++++++++++++++++------------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/mirror-checker.lua b/mirror-checker.lua index 197e6c1..aada1e2 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -251,39 +251,24 @@ local execute = function (s) os.execute(s) end -forkIP = function (orig, host) - if nil == host then host = orig end - local po = url.parse("http://" .. orig, defaultURL) - local ph = url.parse("http://" .. host, defaultURL) - gatherIPs(ph.host) - for k, v in pairs(IP[ph.host]) do - D("DNS record " .. v .. " " .. k .. " for " .. ph.host) - if v == "A" then - if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. " " .. k .. " &") end - elseif v == "AAAA" then - if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. " [" .. k .. "] &") end - elseif v == "CNAME" then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. k .. " &") - forkIP(orig, k) -- Check the original as well as the CNAME, so they both get checked. - end - end -end - -checkHost = function (orig, host, path, ip) +checkRedirects = function (orig, host, path, ip) if nil == host then host = orig end if nil == path then path = "" end + local po = url.parse("http://" .. orig) + local ph = url.parse("http://" .. host) if nil ~= ip then - checkPaths(orig, ip, path) + checkPaths(po.host, ip, path) else - D("checkHost " .. orig .. " " .. host) - gatherIPs(host) - for k, v in pairs(IP[host]) do - D("DNS record " .. v .. " " .. k .. " for " .. host) + if orig == host then D("checkRedirects " .. orig) else D("checkRedirects " .. orig .. " " .. host) end + gatherIPs(ph.host) + for k, v in pairs(IP[ph.host]) do + D("DNS record " .. v .. " " .. ph.host .. " -> " .. k) if v == "A" then if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " &") end elseif v == "AAAA" then if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] &") end elseif v == "CNAME" then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. k .. path .. " &") - checkHost(orig, k, path) -- Check the original, with the DNS records from the CNAME, as well as the CNAME, so they both get checked. + checkRedirects(orig, k, path) -- Check the original, with the DNS records from the CNAME, as well as the CNAME, so they both get checked. end end end @@ -434,7 +419,7 @@ if 0 < #arg then checkExes("mirror-checker.lua " .. sendArgs) checkExes(downloadLock) end - checkHost(pu.host, pu.host, pu.path, arg[2]) + checkRedirects(pu.host, pu.host, pu.path, arg[2]) logFile:close() else if not keep then os.execute("rm -f results/*.log") end @@ -444,18 +429,18 @@ else execute("mkdir -p results") local mirrors = getMirrors() mirrors[options.referenceSite.value] = nil --- checkHost(options.referenceSite.value) - forkIP(options.referenceSite.value) --- checkHost("deb.devuan.org") - forkIP("deb.devuan.org") + checkRedirects(options.referenceSite.value) +-- forkIP(options.referenceSite.value) + checkRedirects("deb.devuan.org") +-- forkIP("deb.devuan.org") for k, m in pairs(mirrors) do if "/" == m.BaseURL:sub(-1, -1) then W("slash at end of BaseURL in mirror_list.txt! " .. m.BaseURL) m.BaseURL = m.BaseURL:sub(1, -2) end local pu = url.parse("http://" .. m.BaseURL, defaultURL) --- checkHost(pu.host) - forkIP(m.BaseURL) + checkRedirects(m.BaseURL) +-- forkIP(m.BaseURL) checkExes("mirror-checker.lua " .. sendArgs) if testing("Integrity") or testing("Updated") then checkExes(downloadLock) end end -- cgit v1.1