aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2019-10-01 22:18:50 +1000
committeronefang2019-10-01 22:18:50 +1000
commit5876d11bc03c5a8fa32af1c00caf03c02fc4bc68 (patch)
tree078687a51605ece5e791f38a930002897508fe6b
parentCheck original host name as well as IP in redirected locations. (diff)
downloadapt-panopticon-5876d11bc03c5a8fa32af1c00caf03c02fc4bc68.zip
apt-panopticon-5876d11bc03c5a8fa32af1c00caf03c02fc4bc68.tar.gz
apt-panopticon-5876d11bc03c5a8fa32af1c00caf03c02fc4bc68.tar.bz2
apt-panopticon-5876d11bc03c5a8fa32af1c00caf03c02fc4bc68.tar.xz
Add the name of the test to any log messages about that test.
And the original host as well.
-rwxr-xr-xmirror-checker.lua31
1 files changed, 18 insertions, 13 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua
index 71c9c34..ae1b9b9 100755
--- a/mirror-checker.lua
+++ b/mirror-checker.lua
@@ -123,9 +123,14 @@ dumpTableSub = function (table, space)
123 end 123 end
124 return r 124 return r
125end 125end
126 126local log = function(v, t, s, test, host)
127 127 local x = ""
128local log = function(v, t, s) 128 if nil ~= test then x = x .. test end
129 if nil ~= host then
130 if #x > 0 then x = x .. " " end
131 x = x .. host
132 end
133 if #x > 0 then t = t .. "(" .. x .. ")" end
129 if v <= verbosity then 134 if v <= verbosity then
130 if 3 <= verbosity then t = os.date() .. " " .. t end 135 if 3 <= verbosity then t = os.date() .. " " .. t end
131 print(t .. ": " .. s) 136 print(t .. ": " .. s)
@@ -137,8 +142,8 @@ local log = function(v, t, s)
137end 142end
138local D = function(s) log(3, "DEBUG ", s) end 143local D = function(s) log(3, "DEBUG ", s) end
139local I = function(s) log(2, "INFO ", s) end 144local I = function(s) log(2, "INFO ", s) end
140local W = function(s) log(1, "WARNING ", s) end 145local W = function(s, t, h) log(1, "WARNING ", s, t, h) end
141local E = function(s) log(0, "ERROR ", s) end 146local E = function(s, t, h) log(0, "ERROR ", s, t, h) end
142local C = function(s) log(-1, "CRITICAL", s) end 147local C = function(s) log(-1, "CRITICAL", s) end
143 148
144local mirrors = {} 149local mirrors = {}
@@ -201,6 +206,8 @@ checkHEAD = function (host, URL, r, retry)
201 if nil == r then r = 0 end 206 if nil == r then r = 0 end
202 if nil == retry then retry = 0 end 207 if nil == retry then retry = 0 end
203 local check = "Checking file" 208 local check = "Checking file"
209 local PU = url.parse(URL, defaultURL)
210 local pu = url.parse(PU.scheme .. "://" .. host, defaultURL)
204 if 0 < r then 211 if 0 < r then
205 check = "Redirecting to" 212 check = "Redirecting to"
206 end 213 end
@@ -209,15 +216,13 @@ checkHEAD = function (host, URL, r, retry)
209 check = "Retry " .. retry .. " " .. check 216 check = "Retry " .. retry .. " " .. check
210 end 217 end
211 if 20 < r then 218 if 20 < r then
212 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL) 219 E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
213 return 220 return
214 end 221 end
215 if 10 < retry then 222 if 10 < retry then
216 E("too many retries! " .. check .. " " .. host .. " -> " .. URL) 223 E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
217 return 224 return
218 end 225 end
219 local PU = url.parse(URL, defaultURL)
220 local pu = url.parse(PU.scheme .. "://" .. host, defaultURL)
221 D(PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL) 226 D(PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL)
222 if not testing(PU.scheme, host) then D("Not testing " .. PU.scheme .. " " .. host .. " -> " .. URL); return end 227 if not testing(PU.scheme, host) then D("Not testing " .. PU.scheme .. " " .. host .. " -> " .. URL); return end
223 -- TODO - Perhaps we should try it anyway, and mark it as a warning if it DOES work? 228 -- TODO - Perhaps we should try it anyway, and mark it as a warning if it DOES work?
@@ -232,13 +237,13 @@ checkHEAD = function (host, URL, r, retry)
232 local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"} 237 local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"}
233 if nil == s then s = "" end 238 if nil == s then s = "" end
234 if nil == p then 239 if nil == p then
235 E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL) 240 E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
236 -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. 241 -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth.
237 -- Might be worthwhile retrying those, some number of times. 242 -- Might be worthwhile retrying those, some number of times.
238 if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end 243 if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end
239 else 244 else
240 if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then 245 if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then
241 E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) 246 E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
242 else 247 else
243 I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) 248 I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL)
244 end 249 end
@@ -246,12 +251,12 @@ checkHEAD = function (host, URL, r, retry)
246 if nil ~= l then 251 if nil ~= l then
247 pu = url.parse(l, defaultURL) 252 pu = url.parse(l, defaultURL)
248 if (pu.scheme ~= PU.scheme) then 253 if (pu.scheme ~= PU.scheme) then
249 if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) end 254 if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l, PU.scheme, host) end
250 if (pu.host == host) and pu.path == PU.path then D("Not testing protocol change " .. URL .. " -> " .. l); return end 255 if (pu.host == host) and pu.path == PU.path then D("Not testing protocol change " .. URL .. " -> " .. l); return end
251 end 256 end
252 257
253 if l == URL then 258 if l == URL then
254 E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) 259 E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host)
255 elseif nil == pu.host then 260 elseif nil == pu.host then
256 I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) 261 I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l)
257 checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) 262 checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1)