diff options
author | onefang | 2019-11-05 02:53:00 +1000 |
---|---|---|
committer | onefang | 2019-11-05 02:53:00 +1000 |
commit | 2c86739c4bd465525b9181b96628542ed0de5601 (patch) | |
tree | 90320d267a9ba5d44aceb9da53b7445b8a1bd023 | |
parent | TODO minor tweaks. (diff) | |
download | apt-panopticon-2c86739c4bd465525b9181b96628542ed0de5601.zip apt-panopticon-2c86739c4bd465525b9181b96628542ed0de5601.tar.gz apt-panopticon-2c86739c4bd465525b9181b96628542ed0de5601.tar.bz2 apt-panopticon-2c86739c4bd465525b9181b96628542ed0de5601.tar.xz |
Create a persistant table with the results.
Diffstat (limited to '')
-rwxr-xr-x | mirror-checker.lua | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/mirror-checker.lua b/mirror-checker.lua index aea816e..01082d9 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua | |||
@@ -130,14 +130,28 @@ dumpTableSub = function (table, space) | |||
130 | end | 130 | end |
131 | return r | 131 | return r |
132 | end | 132 | end |
133 | local log = function(v, t, s, test, host) | 133 | |
134 | local ip = "" | ||
135 | local results = {} | ||
136 | |||
137 | local log = function(v, t, s, prot, test, host) | ||
134 | local x = "" | 138 | local x = "" |
135 | if nil ~= test then x = x .. test end | 139 | if nil == prot then prot = "" end |
140 | if nil ~= test then x = x .. test else test = "" end | ||
136 | if nil ~= host then | 141 | if nil ~= host then |
137 | if #x > 0 then x = x .. " " end | 142 | if #x > 0 then x = x .. " " end |
138 | x = x .. host | 143 | x = x .. host |
139 | end | 144 | end |
140 | if #x > 0 then t = t .. "(" .. x .. ")" end | 145 | if #x > 0 then |
146 | t = t .. "(" .. x .. ")" | ||
147 | if "" == test then | ||
148 | if v == 0 then results[prot].errors = results[prot].errors + 1 end | ||
149 | if v == 1 then results[prot].warnings = results[prot].warnings + 1 end | ||
150 | else | ||
151 | if v == 0 then results[prot][test].errors = results[prot][test].errors + 1 end | ||
152 | if v == 1 then results[prot][test].warnings = results[prot][test].warnings + 1 end | ||
153 | end | ||
154 | end | ||
141 | if v <= verbosity then | 155 | if v <= verbosity then |
142 | if 3 <= verbosity then t = os.date() .. " " .. t end | 156 | if 3 <= verbosity then t = os.date() .. " " .. t end |
143 | print(t .. ": " .. s) | 157 | print(t .. ": " .. s) |
@@ -149,8 +163,8 @@ local log = function(v, t, s, test, host) | |||
149 | end | 163 | end |
150 | local D = function(s) log(3, "DEBUG ", s) end | 164 | local D = function(s) log(3, "DEBUG ", s) end |
151 | local I = function(s) log(2, "INFO ", s) end | 165 | local I = function(s) log(2, "INFO ", s) end |
152 | local W = function(s, t, h) log(1, "WARNING ", s, t, h) end | 166 | local W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end |
153 | local E = function(s, t, h) log(0, "ERROR ", s, t, h) end | 167 | local E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end |
154 | local C = function(s) log(-1, "CRITICAL", s) end | 168 | local C = function(s) log(-1, "CRITICAL", s) end |
155 | 169 | ||
156 | local mirrors = {} | 170 | local mirrors = {} |
@@ -231,15 +245,15 @@ checkHEAD = function (host, URL, r, retry) | |||
231 | check = "Retry " .. retry .. " " .. check | 245 | check = "Retry " .. retry .. " " .. check |
232 | end | 246 | end |
233 | if 3 < timeouts then | 247 | if 3 < timeouts then |
234 | E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 248 | E("too many timeouts! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
235 | return | 249 | return |
236 | end | 250 | end |
237 | if 20 < r then | 251 | if 20 < r then |
238 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 252 | E("too many redirects! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
239 | return | 253 | return |
240 | end | 254 | end |
241 | if 4 < retry then | 255 | if 4 < retry then |
242 | E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 256 | E("too many retries! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
243 | return | 257 | return |
244 | end | 258 | end |
245 | D(PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL) | 259 | D(PU.scheme .. " :// " .. check .. " " .. host .. " -> " .. URL) |
@@ -256,13 +270,13 @@ checkHEAD = function (host, URL, r, retry) | |||
256 | local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"} | 270 | local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"} |
257 | if nil == s then s = "" end | 271 | if nil == s then s = "" end |
258 | if nil == p then | 272 | if nil == p then |
259 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 273 | E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
260 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. | 274 | -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. |
261 | if "timeout" == c then timeouts = timeouts + 1 end | 275 | if "timeout" == c then timeouts = timeouts + 1 end |
262 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1, timeouts) end | 276 | if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1, timeouts) end |
263 | else | 277 | else |
264 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then | 278 | if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then |
265 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 279 | E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL, PU.scheme, "", host) |
266 | else | 280 | else |
267 | I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) | 281 | I(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) |
268 | timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through. | 282 | timeouts = timeouts - 1 -- Backoff the timeouts count if we managed to get through. |
@@ -271,12 +285,12 @@ checkHEAD = function (host, URL, r, retry) | |||
271 | if nil ~= l then | 285 | if nil ~= l then |
272 | pu = url.parse(l, defaultURL) | 286 | pu = url.parse(l, defaultURL) |
273 | if (pu.scheme ~= PU.scheme) then | 287 | if (pu.scheme ~= PU.scheme) then |
274 | if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l, PU.scheme, host) end | 288 | if testing("Protocol") then W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l, PU.scheme, "Protocol", host) end |
275 | if (pu.host == host) and pu.path == PU.path then D("Not testing protocol change " .. URL .. " -> " .. l); return end | 289 | if (pu.host == host) and pu.path == PU.path then D("Not testing protocol change " .. URL .. " -> " .. l); return end |
276 | end | 290 | end |
277 | 291 | ||
278 | if l == URL then | 292 | if l == URL then |
279 | E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, host) | 293 | E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL, PU.scheme, PU.scheme, host) |
280 | elseif nil == pu.host then | 294 | elseif nil == pu.host then |
281 | I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) | 295 | I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) |
282 | checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) | 296 | checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) |
@@ -541,15 +555,27 @@ if 0 < #arg then | |||
541 | end | 555 | end |
542 | local pu = url.parse("http://" .. arg[1]) | 556 | local pu = url.parse("http://" .. arg[1]) |
543 | if nil ~= arg[2] then | 557 | if nil ~= arg[2] then |
544 | logFile, e = io.open("results/mirror-checker-lua_" .. pu.host .. "_" .. arg[2] .. ".log", "a+") | 558 | logFile, e = io.open("results/" .. pu.host .. "_" .. arg[2] .. ".log", "a+") |
545 | else | 559 | else |
546 | logFile, e = io.open("results/mirror-checker-lua_" .. pu.host .. ".log", "a+") | 560 | logFile, e = io.open("results/" .. pu.host .. ".log", "a+") |
547 | end | 561 | end |
548 | if nil == logFile then C("opening log file - " .. e); return end | 562 | if nil == logFile then C("opening log file - " .. e); return end |
549 | I("Starting tests for " ..arg[1] .. " with these tests - " .. table.concat(options.tests.value, ", ")) | 563 | I("Starting tests for " ..arg[1] .. " with these tests - " .. table.concat(options.tests.value, ", ")) |
550 | mirrors = loadfile("results/mirrors.lua")() | 564 | mirrors = loadfile("results/mirrors.lua")() |
551 | if nil ~= arg[2] then I(" Using IP " .. arg[2]) end | 565 | if nil ~= arg[2] then I(" Using IP " .. arg[2]); ip = arg[2] end |
552 | if nil ~= arg[3] then I(" Using file " .. arg[3]); end | 566 | if nil ~= arg[3] then I(" Using file " .. arg[3]); end |
567 | |||
568 | for k, v in pairs{"ftp", "http", "https", "rsync"} do | ||
569 | if testing(v) then | ||
570 | local tests = {errors = 0; warnings = 0} | ||
571 | if testing("Integrity") then tests.Integrity = {errors = 0; warnings = 0} end | ||
572 | if testing("Protocol") then tests.Protocol = {errors = 0; warnings = 0} end | ||
573 | if testing("Updated") then tests.Updated = {errors = 0; warnings = 0} end | ||
574 | if testing("URL-Sanity") then tests.URL_Sanity = {errors = 0; warnings = 0} end | ||
575 | results[v] = tests | ||
576 | end | ||
577 | end | ||
578 | |||
553 | if testing("Integrity") or testing("Updated") then | 579 | if testing("Integrity") or testing("Updated") then |
554 | if nil == arg[3] then | 580 | if nil == arg[3] then |
555 | if not keep then execute("rm -fr results/" .. pu.host) end | 581 | if not keep then execute("rm -fr results/" .. pu.host) end |
@@ -568,6 +594,11 @@ if 0 < #arg then | |||
568 | checkHost(pu.host, pu.host, pu.path, arg[2], arg[3]) | 594 | checkHost(pu.host, pu.host, pu.path, arg[2], arg[3]) |
569 | end | 595 | end |
570 | logFile:close() | 596 | logFile:close() |
597 | local rfile, e = io.open("results/" .. pu.host .. "_" .. ip .. ".lua", "w+") | ||
598 | if nil == rfile then C("opening results file - " .. e) else | ||
599 | rfile:write(dumpTable(results, "", "results") .. "\nreturn results\n") | ||
600 | rfile:close() | ||
601 | end | ||
571 | else | 602 | else |
572 | if not keep then os.execute("rm -f results/*.log") end | 603 | if not keep then os.execute("rm -f results/*.log") end |
573 | os.execute("rm -f results/*.check") | 604 | os.execute("rm -f results/*.check") |