diff options
| author | onefang | 2019-09-29 12:25:45 +1000 |
|---|---|---|
| committer | onefang | 2019-09-29 12:25:45 +1000 |
| commit | e14629329f64f01073383398aac311ea27fbe32f (patch) | |
| tree | d92eba30763f668380f7769fac3be9ae2554521b | |
| parent | Oops, read the "redir" logic incorrectly, and wrote the theory section wrong. (diff) | |
| download | apt-panopticon-e14629329f64f01073383398aac311ea27fbe32f.zip apt-panopticon-e14629329f64f01073383398aac311ea27fbe32f.tar.gz apt-panopticon-e14629329f64f01073383398aac311ea27fbe32f.tar.bz2 apt-panopticon-e14629329f64f01073383398aac311ea27fbe32f.tar.xz | |
checkURL -> checkHEAD
| -rw-r--r-- | README.md | 6 | ||||
| -rwxr-xr-x | mirror-checker.lua | 22 |
2 files changed, 14 insertions, 14 deletions
| @@ -246,13 +246,13 @@ includes the IP this time. The inclusion of the IP causes | |||
| 246 | checkRedirects() to call checkPaths(). | 246 | checkRedirects() to call checkPaths(). |
| 247 | 247 | ||
| 248 | 248 | ||
| 249 | checkPaths() will call checkURL() for each of the reference files. | 249 | checkPaths() will call checkHEAD() for each of the reference files. |
| 250 | 250 | ||
| 251 | 251 | ||
| 252 | checkURL() uses LuaSocket (or LuaSec for HTTPS) to send a HEAD request to | 252 | checkHEAD() uses LuaSocket (or LuaSec for HTTPS) to send a HEAD request to |
| 253 | the IP, with a Host header set to the original host name. Redirects will | 253 | the IP, with a Host header set to the original host name. Redirects will |
| 254 | not be followed by that request. If the request returns a redirect, then | 254 | not be followed by that request. If the request returns a redirect, then |
| 255 | checkURL() is called recursively. If the redirect is to some host we are | 255 | checkHEAD() is called recursively. If the redirect is to some host we are |
| 256 | not already checking, we call checkRedirects() on it, with an IP of | 256 | not already checking, we call checkRedirects() on it, with an IP of |
| 257 | "redir". This causes checkRedirects() to bypass the test that would | 257 | "redir". This causes checkRedirects() to bypass the test that would |
| 258 | otherwise call checkPaths(), instead gathering the IPs and fork as usual. | 258 | otherwise call checkPaths(), instead gathering the IPs and fork as usual. |
diff --git a/mirror-checker.lua b/mirror-checker.lua index b2d1cc7..23c7e33 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua | |||
| @@ -197,7 +197,7 @@ local nlst = function (u) | |||
| 197 | return r and table.concat(t), e | 197 | return r and table.concat(t), e |
| 198 | end | 198 | end |
| 199 | 199 | ||
| 200 | checkURL = function (host, URL, r, retry) | 200 | checkHEAD = function (host, URL, r, retry) |
| 201 | if nil == r then r = 0 end | 201 | if nil == r then r = 0 end |
| 202 | if nil == retry then retry = 0 end | 202 | if nil == retry then retry = 0 end |
| 203 | local check = "Checking file" | 203 | local check = "Checking file" |
| @@ -249,7 +249,7 @@ checkURL = function (host, URL, r, retry) | |||
| 249 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL) | 249 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL) |
| 250 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. | 250 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. |
| 251 | -- Might be worthwhile retrying those, some number of times. | 251 | -- Might be worthwhile retrying those, some number of times. |
| 252 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkURL(host, URL, r, retry + 1) end | 252 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end |
| 253 | else | 253 | else |
| 254 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then | 254 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then |
| 255 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) | 255 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) |
| @@ -267,9 +267,9 @@ checkURL = function (host, URL, r, retry) | |||
| 267 | E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) | 267 | E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) |
| 268 | elseif nil == pu.host then | 268 | elseif nil == pu.host then |
| 269 | W(" no location host! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) | 269 | W(" no location host! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) |
| 270 | checkURL(host, PU.scheme .. "://" .. PU.host .. l, r + 1) | 270 | checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) |
| 271 | else | 271 | else |
| 272 | checkURL(pu.host, l, r + 1) | 272 | checkHEAD(pu.host, l, r + 1) |
| 273 | end | 273 | end |
| 274 | end | 274 | end |
| 275 | end | 275 | end |
| @@ -279,20 +279,20 @@ local checkPaths = function (host, ip, path, file) | |||
| 279 | if nil ~= file then | 279 | if nil ~= file then |
| 280 | if "redirect" == ip then ip = host end | 280 | if "redirect" == ip then ip = host end |
| 281 | I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) | 281 | I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) |
| 282 | if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/" .. file) end | 282 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. file) end |
| 283 | if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/" .. file) end | 283 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. file) end |
| 284 | else | 284 | else |
| 285 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) | 285 | I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) |
| 286 | for i, s in pairs(referenceDevs) do | 286 | for i, s in pairs(referenceDevs) do |
| 287 | if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/" .. s) end | 287 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end |
| 288 | if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/" .. s) end | 288 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end |
| 289 | end | 289 | end |
| 290 | 290 | ||
| 291 | for i, s in pairs(releases) do | 291 | for i, s in pairs(releases) do |
| 292 | for j, k in pairs(releaseFiles) do | 292 | for j, k in pairs(releaseFiles) do |
| 293 | if repoExists(s .. k) then | 293 | if repoExists(s .. k) then |
| 294 | if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 294 | if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end |
| 295 | if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end | 295 | if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end |
| 296 | end | 296 | end |
| 297 | end | 297 | end |
| 298 | end | 298 | end |
| @@ -308,9 +308,9 @@ checkRedirects = function (orig, host, path, ip, file) | |||
| 308 | if nil == host then host = orig end | 308 | if nil == host then host = orig end |
| 309 | if nil == path then path = "" end | 309 | if nil == path then path = "" end |
| 310 | if nil == file then file = "" end | 310 | if nil == file then file = "" end |
| 311 | local po = url.parse("http://" .. orig) | ||
| 312 | local ph = url.parse("http://" .. host) | 311 | local ph = url.parse("http://" .. host) |
| 313 | if (nil ~= ip) and ("redir" ~= ip) then | 312 | if (nil ~= ip) and ("redir" ~= ip) then |
| 313 | local po = url.parse("http://" .. orig) | ||
| 314 | if "" ~= file then | 314 | if "" ~= file then |
| 315 | D("checking redirected file " .. po.host .. " " .. file) | 315 | D("checking redirected file " .. po.host .. " " .. file) |
| 316 | checkPaths(po.host, ip, path, file) | 316 | checkPaths(po.host, ip, path, file) |
