From 4a1763099ece00cf0d462a3caca4421cf0a14bc4 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 5 Nov 2019 00:07:43 +1000 Subject: Gather the IPs and stuff them into mirrors.lua before forking. --- mirror-checker.lua | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'mirror-checker.lua') diff --git a/mirror-checker.lua b/mirror-checker.lua index f4b5142..6580190 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -182,7 +182,7 @@ local repoExists = function (r) end local IP = {} -local gatherIPs = function (host) +gatherIPs = function (host) if nil == IP[host] then local IPs local dig = io.popen('dig +keepopen +noall +nottlid +answer ' .. host .. ' A ' .. host .. ' AAAA ' .. host .. ' CNAME ' .. host .. ' SRV | sort -r | uniq') @@ -193,6 +193,13 @@ local gatherIPs = function (host) if "." == v:sub(-1, -1) then v = v:sub(1, -2) end if nil == IP[k] then IP[k] = {} end IP[k][v] = t + D(" DNS record " .. host .. " == " .. k .. " type " .. t .. " -> " .. v) + if t == "CNAME" then + gatherIPs(v) + IP[k][v] = IP[v] + elseif v == "SRV" then + print("SVR record found, now what do we do?") + end end end until nil == IPs @@ -349,17 +356,23 @@ checkHost = function (orig, host, path, ip, file) D("checkHost " .. orig .. "" .. file) if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " -o " .. orig .. path .. " " .. file .." &") end else D("checkHost " .. 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 .. " " .. file .." &") end - elseif v == "AAAA" then - if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file .. " &") end - elseif v == "CNAME" then - checkHost(orig, k, path, ip, file) -- Check the original, with the DNS records from the CNAME. Do not check the CNAME, it's just a source of IPs. - elseif v == "SRV" then - print("SVR record found, now what do we do?") + local h = mirrors[ph.host] + if nil == h then return end + for k, v in pairs(h.IPs) do + if "table" == type(v) then + for k1, v1 in pairs(v) do + if v1 == "A" then + if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k1 .. " " .. file .." &") end + elseif v1 == "AAAA" then + if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k1 .. "] " .. file .. " &") end + end + end + else + if v == "A" then + if testing("IPv4") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " " .. file .." &") end + elseif v == "AAAA" then + if testing("IPv6") then execute("ionice -c3 ./mirror-checker.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file .. " &") end + end end end end @@ -410,6 +423,8 @@ local getMirrors = function () end host = d m[t] = d + gatherIPs(host) + m["IPs"] = IP[host] elseif "Protocols" == t then local prot = {} for w in d:gmatch("(%w+)") do -- cgit v1.1