aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apt-panopticommon.lua
diff options
context:
space:
mode:
authoronefang2019-12-23 13:01:05 +1000
committeronefang2019-12-23 13:01:05 +1000
commit5e8b0adf2a39debac8354fd98ca7d5b729580ff7 (patch)
tree73b9c3666a89bbf52adb714c712209a09d48deb0 /apt-panopticommon.lua
parentMove the declaration of the APT.tests table to where APT.protocols is. (diff)
downloadapt-panopticon-5e8b0adf2a39debac8354fd98ca7d5b729580ff7.zip
apt-panopticon-5e8b0adf2a39debac8354fd98ca7d5b729580ff7.tar.gz
apt-panopticon-5e8b0adf2a39debac8354fd98ca7d5b729580ff7.tar.bz2
apt-panopticon-5e8b0adf2a39debac8354fd98ca7d5b729580ff7.tar.xz
Major refactor, especially of the downloading and processing code.
Make the code more readable, less scattered. Use a coroutine to multitask better. Plugable functions for parsing the download results, and figuring out what to download next. Track timeouts at a finer level. Dig for IPs in the forked apt-panopticons, not all at once at the beginning. Various cleanups and tweaks.
Diffstat (limited to 'apt-panopticommon.lua')
-rw-r--r--apt-panopticommon.lua56
1 files changed, 42 insertions, 14 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index 8d6de05..4b0be8b 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -53,7 +53,19 @@ APT.options =
53 { 53 {
54 typ = "number", 54 typ = "number",
55 help = "", 55 help = "",
56 value = 15, 56 value = 5,
57 },
58 timeouts =
59 {
60 typ = "number",
61 help = "",
62 value = 3,
63 },
64 retries =
65 {
66 typ = "number",
67 help = "",
68 value = 3,
57 }, 69 },
58 reports = 70 reports =
59 { 71 {
@@ -290,14 +302,16 @@ local log = function(v, t, s, prot, test, host)
290 t = t .. "(" .. x .. ")" 302 t = t .. "(" .. x .. ")"
291 if "" ~= prot then 303 if "" ~= prot then
292 if "" == test then 304 if "" == test then
293 if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0} end 305 if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0; timeouts = 0} end
294 if v == 0 then APT.results[prot].errors = APT.results[prot].errors + 1 end 306 if v == 0 then APT.results[prot].errors = APT.results[prot].errors + 1 end
295 if v == 1 then APT.results[prot].warnings = APT.results[prot].warnings + 1 end 307 if v == 1 then APT.results[prot].warnings = APT.results[prot].warnings + 1 end
308 if v == 2 then APT.results[prot].timeouts = APT.results[prot].timeouts + 1 end
296 else 309 else
297 if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0} end 310 if nil == APT.results[prot] then APT.results[prot] = {errors = 0; warnings = 0; timeouts = 0} end
298 if nil == APT.results[prot][test] then APT.results[prot][test] = {errors = 0; warnings = 0} end 311 if nil == APT.results[prot][test] then APT.results[prot][test] = {errors = 0; warnings = 0; timeouts = 0} end
299 if v == 0 then APT.results[prot][test].errors = APT.results[prot][test].errors + 1 end 312 if v == 0 then APT.results[prot][test].errors = APT.results[prot][test].errors + 1 end
300 if v == 1 then APT.results[prot][test].warnings = APT.results[prot][test].warnings + 1 end 313 if v == 1 then APT.results[prot][test].warnings = APT.results[prot][test].warnings + 1 end
314 if v == 2 then APT.results[prot][test].timeouts = APT.results[prot][test].timeouts + 1 end
301 end 315 end
302 end 316 end
303 end 317 end
@@ -311,8 +325,9 @@ local log = function(v, t, s, prot, test, host)
311 if -1 == v then colour = "fuchsia" end -- CRITICAL 325 if -1 == v then colour = "fuchsia" end -- CRITICAL
312 if 0 == v then colour = "red " end -- ERROR 326 if 0 == v then colour = "red " end -- ERROR
313 if 1 == v then colour = "yellow " end -- WARNING 327 if 1 == v then colour = "yellow " end -- WARNING
314 if 2 == v then colour = "white " end -- INFO 328 if 2 == v then colour = "blue " end -- TIMEOUT
315 if 3 == v then colour = "gray " end -- DEBUG 329 if 3 == v then colour = "white " end -- INFO
330 if 4 == v then colour = "gray " end -- DEBUG
316 APT.logFile:write(os.date() .. " <font color='" .. colour .. "'><b>" .. t .. "</b></font>: " .. s .. "</br>\n") 331 APT.logFile:write(os.date() .. " <font color='" .. colour .. "'><b>" .. t .. "</b></font>: " .. s .. "</br>\n")
317 else 332 else
318 APT.logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n") 333 APT.logFile:write(os.date() .. " " .. t .. ": " .. s .. "\n")
@@ -320,13 +335,15 @@ local log = function(v, t, s, prot, test, host)
320 APT.logFile:flush() 335 APT.logFile:flush()
321 end 336 end
322end 337end
323APT.D = function(s) log(3, "DEBUG ", s) end 338APT.D = function(s) log(4, "DEBUG ", s) end
324APT.I = function(s) log(2, "INFO ", s) end 339APT.I = function(s) log(3, "INFO ", s) end
340APT.T = function(s, p, t, h) log(2, "TIMEOUT ", s, p, t, h) end
325APT.W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end 341APT.W = function(s, p, t, h) log(1, "WARNING ", s, p, t, h) end
326APT.E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end 342APT.E = function(s, p, t, h) log(0, "ERROR ", s, p, t, h) end
327APT.C = function(s) log(-1, "CRITICAL", s) end 343APT.C = function(s) log(-1, "CRITICAL", s) end
328local D = APT.D 344local D = APT.D
329local I = APT.I 345local I = APT.I
346local T = APT.T
330local W = APT.W 347local W = APT.W
331local E = APT.E 348local E = APT.E
332local C = APT.C 349local C = APT.C
@@ -380,7 +397,7 @@ APT.checkFile = function(f)
380 if nil == h then return false else h:close(); return true end 397 if nil == h then return false else h:close(); return true end
381end 398end
382 399
383APT.plurals = function(e, w) 400APT.plurals = function(e, w, t)
384 local result = "" 401 local result = ""
385 if 1 == e then 402 if 1 == e then
386 result = e .. " error" 403 result = e .. " error"
@@ -397,18 +414,29 @@ APT.plurals = function(e, w)
397 end 414 end
398 if ("" ~= result) and APT.html then result = "<font color='yellow'><b>" .. result .. "</b></font>" end 415 if ("" ~= result) and APT.html then result = "<font color='yellow'><b>" .. result .. "</b></font>" end
399 end 416 end
417 if 0 < t then
418 if (0 < e) or (0 < w) then result = result .. ", " end
419 if 1 == t then
420 result = result .. t .. " timeout"
421 else
422 result = result .. t .. " timeouts"
423 end
424 if ("" ~= result) and APT.html then result = "<font color='blue'><b>" .. result .. "</b></font>" end
425 end
400 if "" ~= result then result = " (" .. result .. ")" end 426 if "" ~= result then result = " (" .. result .. ")" end
401 return result 427 return result
402end 428end
403 429
404APT.padResults = function(results) 430APT.padResults = function(results)
431 local c = 0
432 if nil == results then results = {}; c = 999 end
405 for k, v in pairs(APT.protocols) do 433 for k, v in pairs(APT.protocols) do
406 tests = results[v] 434 tests = results[v]
407 if nil == tests then tests = {errors = 0; warnings = 0} end 435 if nil == tests then tests = {errors = c; warnings = c; timeouts = c} end
408 if nil == tests.Integrity then tests.Integrity = {errors = 0; warnings = 0} end 436 if nil == tests.Integrity then tests.Integrity = {errors = c; warnings = c; timeouts = c} end
409 if nil == tests.Protocol then tests.Protocol = {errors = 0; warnings = 0} end 437 if nil == tests.Protocol then tests.Protocol = {errors = c; warnings = c; timeouts = c} end
410 if nil == tests.Updated then tests.Updated = {errors = 0; warnings = 0} end 438 if nil == tests.Updated then tests.Updated = {errors = c; warnings = c; timeouts = c} end
411 if nil == tests.URLSanity then tests.URLSanity = {errors = 0; warnings = 0} end 439 if nil == tests.URLSanity then tests.URLSanity = {errors = c; warnings = c; timeouts = c} end
412 results[v] = tests 440 results[v] = tests
413 end 441 end
414 if nil == results.timeout then results.timeout = false end 442 if nil == results.timeout then results.timeout = false end